-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from cerus/feature-filters
Add filters
- Loading branch information
Showing
8 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package dev.cerus.mcheadrender.filter; | ||
|
||
import java.awt.image.BufferedImage; | ||
|
||
/** | ||
* Applies some sort of visual effect onto the final image | ||
*/ | ||
public abstract class Filter { | ||
|
||
/** | ||
* Apply the filter | ||
* | ||
* @param img The image that should be filtered | ||
*/ | ||
public abstract void apply(BufferedImage img); | ||
|
||
public abstract String id(); | ||
|
||
@Override | ||
public int hashCode() { | ||
return this.id().hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object obj) { | ||
if (!(obj instanceof Filter)) { | ||
return false; | ||
} | ||
return obj == this || ((Filter) obj).id().equals(this.id()); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/dev/cerus/mcheadrender/filter/GrayscaleFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dev.cerus.mcheadrender.filter; | ||
|
||
import java.awt.Color; | ||
import java.awt.image.BufferedImage; | ||
|
||
/** | ||
* Grayscales an image | ||
*/ | ||
public class GrayscaleFilter extends Filter { | ||
|
||
@Override | ||
public void apply(final BufferedImage img) { | ||
for (int x = 0; x < img.getWidth(); x++) { | ||
for (int y = 0; y < img.getHeight(); y++) { | ||
final int pixel = img.getRGB(x, y); | ||
final Color color = new Color(pixel, true); | ||
final int avg = (color.getRed() + color.getGreen() + color.getBlue()) / 3; | ||
img.setRGB(x, y, new Color(avg, avg, avg, color.getAlpha()).getRGB()); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String id() { | ||
return "grayscale"; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/dev/cerus/mcheadrender/filter/InvertFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package dev.cerus.mcheadrender.filter; | ||
|
||
import java.awt.Color; | ||
import java.awt.image.BufferedImage; | ||
|
||
/** | ||
* Inverts an image | ||
*/ | ||
public class InvertFilter extends Filter { | ||
|
||
@Override | ||
public void apply(final BufferedImage img) { | ||
for (int x = 0; x < img.getWidth(); x++) { | ||
for (int y = 0; y < img.getHeight(); y++) { | ||
final int pixel = img.getRGB(x, y); | ||
final Color color = new Color(pixel, true); | ||
img.setRGB(x, y, new Color( | ||
255 - color.getRed(), | ||
255 - color.getGreen(), | ||
255 - color.getBlue(), | ||
color.getAlpha() | ||
).getRGB()); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String id() { | ||
return "invert"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters