use of org.jwildfire.transform.HSLTransformer in project JWildfire by thargor6.
the class RGBPalette method transformColors.
private void transformColors() {
int startIdx = selectionProvider.getFrom();
int endIdx = selectionProvider.getTo();
if (modified) {
for (int i = 0; i < transformedColors.length; i++) {
transformedColors[i] = null;
}
for (int i = 0; i < PALETTE_SIZE; i++) {
RGBColor color = getRawColor(i);
int idx = i + modShift;
if (idx < 0) {
idx += PALETTE_SIZE;
} else if (idx >= PALETTE_SIZE) {
idx -= PALETTE_SIZE;
}
transformedColors[idx] = new RGBColor(color.getRed(), color.getGreen(), color.getBlue());
}
if (modFrequency > 1) {
RGBColor[] newTransformedColors = new RGBColor[PALETTE_SIZE];
System.arraycopy(transformedColors, 0, newTransformedColors, 0, PALETTE_SIZE);
int n = PALETTE_SIZE / modFrequency;
for (int j = 0; j < modFrequency; j++) {
for (int i = 0; i < n; i++) {
int idx = i + j * n;
if (idx < PALETTE_SIZE) {
newTransformedColors[idx] = transformedColors[i * modFrequency];
}
}
}
System.arraycopy(newTransformedColors, 0, transformedColors, 0, PALETTE_SIZE);
newTransformedColors = null;
}
if (modBlur > 0) {
RGBColor[] newTransformedColors = new RGBColor[PALETTE_SIZE];
System.arraycopy(transformedColors, 0, newTransformedColors, 0, PALETTE_SIZE);
for (int i = 0; i < PALETTE_SIZE; i++) {
int r = 0;
int g = 0;
int b = 0;
int n = -1;
for (int j = i - modBlur; j <= i + modBlur; j++) {
n++;
int k = (PALETTE_SIZE + j) % PALETTE_SIZE;
if (k != i) {
RGBColor color = transformedColors[k];
r += color.getRed();
g += color.getGreen();
b += color.getBlue();
}
}
if (n != 0) {
RGBColor color = new RGBColor(Tools.limitColor(r / n), Tools.limitColor(g / n), Tools.limitColor(b / n));
newTransformedColors[i] = color;
}
}
System.arraycopy(newTransformedColors, 0, transformedColors, 0, PALETTE_SIZE);
newTransformedColors = null;
}
SimpleImage img = new RGBPaletteRenderer().renderHorizPalette(transformedColors, PALETTE_SIZE, 1);
if (modRed != 0 || modGreen != 0 || modBlue != 0 || modContrast != 0 || modGamma != 0 || modBrightness != 0 || modSaturation != 0) {
BalancingTransformer bT = new BalancingTransformer();
bT.setRed(modRed);
bT.setGreen(modGreen);
bT.setBlue(modBlue);
bT.setContrast(modContrast);
bT.setGamma(modGamma);
bT.setBrightness(modBrightness);
bT.setSaturation(modSaturation);
bT.transformImage(img);
}
if (modHue != 0) {
HSLTransformer hT = new HSLTransformer();
hT.setHue(modHue);
hT.transformImage(img);
}
if (modSwapRGB != 0) {
SwapRGBTransformer sT = new SwapRGBTransformer();
int maxValues = Mode.values().length;
int idx = (int) ((double) Math.abs(modSwapRGB) / (double) 255.0 * (double) (maxValues - 1));
sT.setMode(Mode.values()[idx]);
sT.transformImage(img);
}
Pixel pixel = new Pixel();
for (int i = startIdx; i <= endIdx; i++) {
RGBColor color = transformedColors[i];
pixel.setARGBValue(img.getARGBValue(i, 0));
color.setRed(pixel.r);
color.setGreen(pixel.g);
color.setBlue(pixel.b);
}
modified = false;
}
}
Aggregations