I am having trouble applying color changes to the pixels of an image. It has to be done through a calculation, for example this is the code I'm using for grayscale, which works fine:
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
int pixel = pixelReader.getArgb(x, y);
int alpha = ((pixel >> 24) & 0xff);
int red = ((pixel >> 16) & 0xff);
int green = ((pixel >> 8) & 0xff);
int blue = (pixel & 0xff);
int avg = (int)(red + green + blue) / 3;
pixel = (alpha << 24) | (avg << 16) | (avg << 8) | avg;
writer.setArgb(x, y, pixel);
}
}
kittenImage.setImage(newImage);
Like I said, that works fine. I also have to change the picture to red, green, and blue, and I've played around with that code to adjust it. Here is the code for the red filter:
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
int pixel = pixelReader.getArgb(x, y);
int alpha = ((pixel >> 24) & 0xff);
int red = ((pixel >> 16) & 0xff);
int green = ((pixel >> 8) & 0xff);
int blue = (pixel & 0xff);
int redLevel = (0 << 24) | (red << 16) | (0 << 8) | 0;
writer.setArgb(x, y, -redLevel);
}
}
kittenImage.setImage(newImage);
I had hoped that I could just change around what color was the most prominent, but that code only gets me a negative looking red image, which is not what I need.
I'm not able to post pictures on this apparently, so I gotta figure out how to do that to show what I mean. I've been researching this and found plenty on the grayscale, but everything on the red, blue, and green seems to point to built in functions or methods which is not what I'm looking for.
This is only my second question so let me know if I need to include additional information.
EDIT: This is where I got the grayscale from, which I modified with another version that used Argb instead of RGB. (I'm not using a buffered image). convert a RGB image to grayscale Image reducing the memory in java
This is the Argb version: http://skrb.hatenablog.com/entry/2013/01/07/171901