Skip to content

Commit

Permalink
small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalazscs committed Jan 16, 2025
1 parent 9c6c0bf commit b8a9ada
Show file tree
Hide file tree
Showing 32 changed files with 195 additions and 141 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/jhlabs/image/CheckFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void setPhase(double phase) {
}

@Override
public int filterRGB(int x, int y, int rgb) {
public int processPixel(int x, int y, int rgb) {
float nx = (m00 * x + m01 * y) / xScale;
float ny = (m10 * x + m11 * y) / yScale;
if (distortion > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jhlabs/image/DitherFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void initialize() {
// In orderd dithering each pixel is processed independently based
// on its position relative to the tiling of the threshold matrix.
@Override
public int filterRGB(int x, int y, int rgb) {
public int processPixel(int x, int y, int rgb) {
int a = rgb & 0xff000000;
int r = (rgb >> 16) & 0xff;
int g = (rgb >> 8) & 0xff;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jhlabs/image/FourColorFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private static float septic(float a, float b, float ratio) {
}

@Override
public int filterRGB(int x, int y, int rgb) {
public int processPixel(int x, int y, int rgb) {
// calculate normalized x and y coordinates (0.0 to 1.0)
float fx = (float) x / width;
float fy = (float) y / height;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jhlabs/image/InvertAlphaFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public InvertAlphaFilter(String filterName) {
}

@Override
public int filterRGB(int x, int y, int rgb) {
public int processPixel(int x, int y, int rgb) {
return rgb ^ 0xff000000;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/jhlabs/image/PointFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public BufferedImage filter(BufferedImage src, BufferedImage dst) {
Runnable rowTask = () -> {
for (int x = 0; x < width; x++) {
int index = finalY * width + x;
outPixels[index] = filterRGB(x, finalY, inPixels[index]);
outPixels[index] = processPixel(x, finalY, inPixels[index]);
}
};
rowFutures[y] = ThreadPool.submit(rowTask);
Expand All @@ -80,7 +80,7 @@ public BufferedImage grayFilter(BufferedImage src, BufferedImage dst) {
int[] inPixels = new int[width];
src.getRGB(0, finalY, width, 1, inPixels, 0, width);
for (int x = 0; x < width; x++) {
inPixels[x] = filterRGB(x, finalY, inPixels[x]);
inPixels[x] = processPixel(x, finalY, inPixels[x]);
}
dst.setRGB(0, finalY, width, 1, inPixels, 0, width);
};
Expand All @@ -95,5 +95,5 @@ public BufferedImage grayFilter(BufferedImage src, BufferedImage dst) {
public void setDimensions(int width, int height) {
}

public abstract int filterRGB(int x, int y, int rgb);
public abstract int processPixel(int x, int y, int rgb);
}
2 changes: 1 addition & 1 deletion src/main/java/com/jhlabs/image/SparkleFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void setDimensions(int width, int height) {
}

@Override
public int filterRGB(int x, int y, int rgb) {
public int processPixel(int x, int y, int rgb) {
float dx = x - centerX;
float dy = y - centerY;
float distance = dx * dx + dy * dy;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jhlabs/image/StampFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public BufferedImage filter(BufferedImage src, BufferedImage dst) {
}

@Override
public int filterRGB(int x, int y, int rgb) {
public int processPixel(int x, int y, int rgb) {
// int a = rgb & 0xff000000;
int r = (rgb >> 16) & 0xff;
int g = (rgb >> 8) & 0xff;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/jhlabs/image/TransferFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected TransferFilter(String filterName) {
}

@Override
public int filterRGB(int x, int y, int rgb) {
public int processPixel(int x, int y, int rgb) {
int a = rgb & 0xff000000;
int r = (rgb >> 16) & 0xff;
int g = (rgb >> 8) & 0xff;
Expand Down Expand Up @@ -69,7 +69,7 @@ public int[] getLUT() {
}
int[] lut = new int[256];
for (int i = 0; i < 256; i++) {
lut[i] = filterRGB(0, 0, (i << 24) | (i << 16) | (i << 8) | i);
lut[i] = processPixel(0, 0, (i << 24) | (i << 16) | (i << 8) | i);
}
return lut;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jhlabs/image/TritoneFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public BufferedImage filter(BufferedImage src, BufferedImage dst) {
}

@Override
public int filterRGB(int x, int y, int rgb) {
public int processPixel(int x, int y, int rgb) {
return lut[PixelUtils.brightness(rgb)];
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jhlabs/image/WeaveFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void setShadeCrossings(boolean shadeCrossings) {
}

@Override
public int filterRGB(int x, int y, int rgb) {
public int processPixel(int x, int y, int rgb) {
x = (int) (x + (xWidth + xGap / 2));
y = (int) (y + (yWidth + yGap / 2));
float nx = ImageMath.mod(x, xWidth + xGap);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jhlabs/image/WoodFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void setColormap(Colormap colormap) {
}

@Override
public int filterRGB(int x, int y, int rgb) {
public int processPixel(int x, int y, int rgb) {
float nx = m00 * x + m01 * y;
float ny = m10 * x + m11 * y;
nx /= scale;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/pixelitor/filters/BlurredShapeTester.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Laszlo Balazs-Csiki and Contributors
* Copyright 2025 Laszlo Balazs-Csiki and Contributors
*
* This file is part of Pixelitor. Pixelitor is free software: you
* can redistribute it and/or modify it under the terms of the GNU
Expand Down Expand Up @@ -95,7 +95,7 @@ public Impl() {
}

@Override
public int filterRGB(int x, int y, int rgb) {
public int processPixel(int x, int y, int rgb) {
double outside = shape.isOutside(x, y);
if (outside == 1.0) {
return RGB_BLACK;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pixelitor/filters/ChannelToTransparency.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected ChannelToTransparencyFilter(boolean invert, boolean keep) {
}

@Override
public int filterRGB(int x, int y, int argb) {
public int processPixel(int x, int y, int argb) {
int v = getChannelValue(argb);
int alpha;
if (invert) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/pixelitor/filters/ColorWheel.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public BufferedImage transform(BufferedImage src, BufferedImage dest) {

ColorSpaceType space = type.getSelected();

int cx = (int) (width * center.getRelativeX());
int cy = (int) (height * center.getRelativeY());
double cx = width * center.getRelativeX();
double cy = height * center.getRelativeY();

double hueRot = hueRotParam.getValueInRadians();
double sat = satParam.getPercentage();
Expand All @@ -104,11 +104,11 @@ public BufferedImage transform(BufferedImage src, BufferedImage dest) {
}

private static void processRow(int[] destPixels, int width, int y,
int cx, int cy, double hueRot,
double cx, double cy, double hueRot,
double saturation, double brightness, ColorSpaceType model) {
for (int x = 0; x < width; x++) {
int yDiff = cy - y;
int xDiff = x - cx;
double yDiff = cy - y;
double xDiff = x - cx;
double angle = FastMath.atan2(yDiff, xDiff) + hueRot;
double hue = angle / (2 * Math.PI);

Expand Down
64 changes: 26 additions & 38 deletions src/main/java/pixelitor/filters/ConcentricShapes.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import pixelitor.Views;
import pixelitor.colors.Colors;
import pixelitor.filters.gui.*;
import pixelitor.filters.util.ShapeWithColor;
import pixelitor.io.FileIO;
import pixelitor.utils.Geometry;
import pixelitor.utils.ImageUtils;
Expand Down Expand Up @@ -77,7 +78,6 @@ Shape createShape(double cx, double cy, double r, int n, double tuning) {
Shape createShape(double cx, double cy, double r, int n, double tuning) {
return Shapes.createCircumscribedPolygon(n, cx, cy, r, tuning);
}
// the number of rings multiplier corresponds to the max/min radius ratio
}, STARS("Stars", true, true, 2.0, 2.0) {
@Override
Shape createShape(double cx, double cy, double r, int n, double tuning) {
Expand Down Expand Up @@ -153,15 +153,14 @@ public String toString() {
private final GroupedRangeParam scale = new GroupedRangeParam("Scale (%)", 1, 100, 500, false);
private final AngleParam rotate = new AngleParam("Rotate", 0);

private record ColoredShape(Color color, Shape shape) {
}

public ConcentricShapes() {
super(false);

FilterButtonModel reseedAction = paramSet.createReseedAction("", "Reseed Randomness");

shapeTypeParam.setupEnableOtherIf(sides, ConcentricShapeType::hasSides);
shapeTypeParam.setupEnableOtherIf(tuning, ConcentricShapeType::hasTuning);
randomnessParam.setupEnableOtherIfNotZero(reseedAction);

setParams(
arrangementParam,
Expand All @@ -172,11 +171,7 @@ public ConcentricShapes() {
colorsParam,
new DialogParam("Transform", center, scale, rotate),
randomnessParam.withAction(reseedAction)
).withAction(new FilterButtonModel("Export SVG...", this::exportSVG,
null, "Export the current image to an SVG file",
null, false));

randomnessParam.setupEnableOtherIfNotZero(reseedAction);
).withAction(FilterButtonModel.createExportSvg(this::exportSVG));
}

@Override
Expand All @@ -192,10 +187,10 @@ public BufferedImage transform(BufferedImage src, BufferedImage dest) {
g.fillRect(0, 0, width, height);
g.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);

List<ColoredShape> shapes = createShapes(width, height, random,
List<ShapeWithColor> shapes = createShapes(width, height, random,
tuning.getPercentage(), arrangementParam.getSelected());

for (ColoredShape shape : shapes) {
for (ShapeWithColor shape : shapes) {
g.setColor(shape.color());
g.fill(shape.shape());
}
Expand All @@ -204,13 +199,13 @@ public BufferedImage transform(BufferedImage src, BufferedImage dest) {
return dest;
}

private List<ColoredShape> createShapes(int width, int height, Random rng, double tuning, Arrangement arrangement) {
private List<ShapeWithColor> createShapes(int width, int height, Random rng, double tuning, Arrangement arrangement) {
return arrangement == Arrangement.NESTED
? createNestedShapes(width, height, rng, tuning)
: createRingedShapes(width, height, rng, tuning);
}

private List<ColoredShape> createNestedShapes(int width, int height, Random rng, double tuning) {
private List<ShapeWithColor> createNestedShapes(int width, int height, Random rng, double tuning) {
double cx = width * center.getRelativeX();
double cy = height * center.getRelativeY();

Expand All @@ -223,26 +218,23 @@ private List<ColoredShape> createNestedShapes(int width, int height, Random rng,

double distance = distanceParam.getValueAsDouble();
int numRings = (int) (shapeType.getRingsMultiplier() * (1 + (maxDist / distance)));

distance *= shapeType.getDistMultiplier();

Color[] colors = colorsParam.getColors();
List<ColoredShape> retVal = new ArrayList<>(numRings);

int numSides = sides.getValue();

AffineTransform at = createTransform(cx, cy);

List<ShapeWithColor> shapes = new ArrayList<>(numRings);
for (int ring = numRings; ring > 0; ring--) {
double r = ring * distance;
Color color = colorsParam.getColor((ring - 1) % colors.length);
Shape shape = createShape(shapeType, cx, cy, rng, tuning, r, numSides, randomness, rndMultiplier, at);
retVal.add(new ColoredShape(color, shape));
shapes.add(new ShapeWithColor(shape, color));
}
return retVal;
return shapes;
}

private List<ColoredShape> createRingedShapes(int width, int height, Random rng, double tuning) {
private List<ShapeWithColor> createRingedShapes(int width, int height, Random rng, double tuning) {
double cx = width * center.getRelativeX();
double cy = height * center.getRelativeY();

Expand All @@ -252,18 +244,15 @@ private List<ColoredShape> createRingedShapes(int width, int height, Random rng,
Color[] colors = colorsParam.getColors();

double maxDist = Math.sqrt(width * width + height + height) / 2.0;
int numRings = (int) (maxDist / (2 * r));
List<ColoredShape> retVal = new ArrayList<>(numRings);

int randomness = randomnessParam.getValue();


AffineTransform at = createTransform(cx, cy);
int numRings = (int) (maxDist / (2 * r));
List<ShapeWithColor> shapes = new ArrayList<>(numRings);

// add a shape at the center
Shape shape = createShape(shapeType, cx, cy, rng, tuning, r, numSides, randomness, randomness / 400.0, at);
Color color = selectColor(colors, 0);
retVal.add(new ColoredShape(color, shape));
shapes.add(new ShapeWithColor(shape, color));

// add concentric rings of shapes
int shapeCount = 1;
Expand All @@ -279,11 +268,11 @@ private List<ColoredShape> createRingedShapes(int width, int height, Random rng,
shape = createShape(shapeType, x, y, rng, tuning, r, numSides, randomness, randomness / 400.0, at);
shapeCount++;
color = selectColor(colors, shapeCount);
retVal.add(new ColoredShape(color, shape));
shapes.add(new ShapeWithColor(shape, color));
}
}

return retVal;
return shapes;
}

// the shapes are transformed using this transform, instead of transforming
Expand All @@ -305,7 +294,9 @@ private AffineTransform createTransform(double cx, double cy) {
return at;
}

private static Shape createShape(ConcentricShapeType shapeType, double x, double y, Random rng, double tuning, double r, int numSides, int randomness, double rndMultiplier, AffineTransform at) {
private static Shape createShape(ConcentricShapeType shapeType, double x, double y,
Random rng, double tuning, double r, int numSides,
int randomness, double rndMultiplier, AffineTransform at) {
Shape shape = shapeType.createShape(x, y, r, numSides, tuning);
if (randomness > 0) {
shape = Shapes.randomize(shape, rng, rndMultiplier * r);
Expand All @@ -324,17 +315,14 @@ private Color selectColor(Color[] colors, int shapeCount) {

private void exportSVG() {
Canvas canvas = Views.getActiveComp().getCanvas();
StringBuilder content = new StringBuilder();
content.append(canvas.createSVGElement());
content.append("\n");
StringBuilder content = new StringBuilder()
.append(canvas.createSVGElement())
.append("\n");

List<ColoredShape> coloredShapes = createShapes(canvas.getWidth(), canvas.getHeight(),
List<ShapeWithColor> shapes = createShapes(canvas.getWidth(), canvas.getHeight(),
paramSet.getLastSeedRandom(), tuning.getPercentage(), arrangementParam.getSelected());
for (ColoredShape coloredShape : coloredShapes) {
String svgPath = Shapes.toSvgPath(coloredShape.shape());
String svgColor = Colors.toHTMLHex(coloredShape.color(), false);
content.append("<path d=\"%s\" fill=\"#%s\"/>\n".formatted(svgPath, svgColor));
}

ShapeWithColor.appendSvgPaths(shapes, content);
content.append("</svg>");

FileIO.saveSVG(content.toString(), "concentric.svg");
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/pixelitor/filters/CurveFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ protected CurveFilter() {
new DialogParam("Transform", distortType, distortAmount, center, rotate, scale),
strokeParam.withStrokeWidth(2),
effectsParam
).withAction(new FilterButtonModel("Export SVG...", this::exportSVG,
null, "Export the current shape to an SVG file",
null, false));
).withAction(FilterButtonModel.createExportSvg(this::exportSVG));

// disable foreground and background if watermarking is selected
waterMark.setupDisableOtherIfChecked(foreground);
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/pixelitor/filters/Fill.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ public BufferedImage transform(BufferedImage src, BufferedImage dest) {
/**
* Fills the BufferedImage with the specified color
*/
public static void fillImage(BufferedImage img, Color c) {
public static void fillImage(BufferedImage img, Color color) {
int[] pixels = ImageUtils.getPixels(img);

int fillColor = c.getRGB();

Arrays.fill(pixels, fillColor);
Arrays.fill(pixels, color.getRGB());
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pixelitor/filters/Flashlight.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public Impl() {
}

@Override
public int filterRGB(int x, int y, int rgb) {
public int processPixel(int x, int y, int rgb) {
double outside = shape.isOutside(x, y);
if (invert) {
outside = 1.0 - outside;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pixelitor/filters/HueSat.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected Impl(float hueRot, float satShift, float briShift) {
}

@Override
public int filterRGB(int x, int y, int rgb) {
public int processPixel(int x, int y, int rgb) {
int a = rgb & 0xFF_00_00_00;
int r = (rgb >>> 16) & 0xFF;
int g = (rgb >>> 8) & 0xFF;
Expand Down
Loading

0 comments on commit b8a9ada

Please sign in to comment.