Skip to content

Commit ac1310b

Browse files
committed
small improvements
1 parent 0d625b8 commit ac1310b

36 files changed

Lines changed: 370 additions & 258 deletions

src/main/java/com/jhlabs/image/BrushedMetalFilter.java

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import net.jafama.FastMath;
2020

2121
import java.awt.image.BufferedImage;
22-
import java.util.SplittableRandom;
22+
import java.util.random.RandomGenerator;
2323

2424
/**
2525
* A filter which produces an image simulating brushed metal.
@@ -29,8 +29,7 @@ public class BrushedMetalFilter extends AbstractBufferedImageOp {
2929
private float amount = 0.1f;
3030
private int color = 0xff888888;
3131
private float shine = 0.1f;
32-
private boolean monochrome = true;
33-
private SplittableRandom random;
32+
private RandomGenerator random;
3433

3534
/**
3635
* Constructs a BrushedMetalFilter object.
@@ -42,19 +41,17 @@ public BrushedMetalFilter(String filterName) {
4241
/**
4342
* Constructs a BrushedMetalFilter object.
4443
*
45-
* @param color an int specifying the metal color
46-
* @param radius an int specifying the blur size
47-
* @param amount a float specifying the amount of texture
48-
* @param monochrome a boolean -- true for monochrome texture
49-
* @param shine a float specifying the shine to add
44+
* @param color an int specifying the metal color
45+
* @param radius an int specifying the blur size
46+
* @param amount a float specifying the amount of texture
47+
* @param shine a float specifying the shine to add
5048
*/
51-
public BrushedMetalFilter(int color, int radius, float amount, boolean monochrome, float shine, String filterName) {
49+
public BrushedMetalFilter(int color, int radius, float amount, float shine, String filterName) {
5250
super(filterName);
5351

5452
this.color = color;
5553
this.radius = radius;
5654
this.amount = amount;
57-
this.monochrome = monochrome;
5855
this.shine = shine;
5956
}
6057

@@ -97,12 +94,8 @@ public BufferedImage filter(BufferedImage src, BufferedImage dst) {
9794
tg += f;
9895
tb += f;
9996
}
100-
if (monochrome) {
101-
int n = (int) (255 * (2 * random.nextDouble() - 1) * amount);
102-
inPixels[x] = a | (clamp(tr + n) << 16) | (clamp(tg + n) << 8) | clamp(tb + n);
103-
} else {
104-
inPixels[x] = a | (random(tr) << 16) | (random(tg) << 8) | random(tb);
105-
}
97+
int n = (int) (255 * (2 * random.nextDouble() - 1) * amount);
98+
inPixels[x] = a | (clamp(tr + n) << 16) | (clamp(tg + n) << 8) | clamp(tb + n);
10699
}
107100

108101
if (radius != 0) {
@@ -230,16 +223,7 @@ public void setColor(int color) {
230223
this.color = color;
231224
}
232225

233-
/**
234-
* Set the type of noise to add.
235-
*
236-
* @param monochrome true for monochrome noise
237-
*/
238-
public void setMonochrome(boolean monochrome) {
239-
this.monochrome = monochrome;
240-
}
241-
242-
public void setRandom(SplittableRandom random) {
226+
public void setRandom(RandomGenerator random) {
243227
this.random = random;
244228
}
245229

src/main/java/pixelitor/filters/AbstractLights.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public String toString() {
9999
public AbstractLights() {
100100
super(false);
101101

102-
// disable hue variation when complexity is 1 (single particle)
102+
// disable hue variation when complexity is 1 (two particles)
103103
complexityParam.setupDisableOtherIf(hueRandomnessParam, value -> value == 1);
104104

105105
// disable hue controls when fully white blend is selected
@@ -197,8 +197,7 @@ private List<Particle> createParticles(int width, int height, Random random, flo
197197
int x = random.nextInt(width);
198198
int y = random.nextInt(height);
199199
Color color = generateParticleColor(random, bri, baseHue, hueRandomness);
200-
double rnd = random.nextDouble();
201-
double angle = 2 * rnd * Math.PI;
200+
double angle = 2 * random.nextDouble() * Math.PI;
202201

203202
switch (type) {
204203
case CHAOS, STAR -> particles.add(new Particle(x, y, speed, angle, color, bounce));
@@ -228,13 +227,13 @@ private void connectParticles(List<Particle> particles, int width, int height) {
228227
}
229228

230229
/**
231-
* Connects each particle to the previous one in the list, forming a chain.
230+
* Connects particles in a closed chain, where each particle is linked to the previous one.
232231
*/
233232
private static void connectInChain(List<Particle> particles) {
234233
int numParticles = particles.size();
235234
for (int i = 0; i < numParticles; i++) {
236-
int siblingIndex = (i > 0) ? i - 1 : numParticles - 1;
237-
particles.get(i).sibling = particles.get(siblingIndex);
235+
int prevIndex = (i > 0) ? i - 1 : numParticles - 1;
236+
particles.get(i).sibling = particles.get(prevIndex);
238237
}
239238
}
240239

src/main/java/pixelitor/filters/AddNoise.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import java.awt.Color;
2828
import java.awt.image.BufferedImage;
2929
import java.io.Serial;
30-
import java.util.SplittableRandom;
30+
import java.util.random.RandomGenerator;
3131

3232
import static pixelitor.gui.GUIText.OPACITY;
3333
import static pixelitor.utils.ImageUtils.isGrayscale;
@@ -69,18 +69,15 @@ public AddNoise() {
6969

7070
@Override
7171
public BufferedImage transform(BufferedImage src, BufferedImage dest) {
72-
SplittableRandom rand = paramSet.getLastSeedSRandom();
72+
RandomGenerator rand = paramSet.getLastSeedSRandom();
7373

74-
if (isGrayscale(src)) {
75-
return addNoiseToGray(src, dest, rand);
76-
}
77-
78-
boolean coverageAnim = method.getValue() == METHOD_COVERAGE_ANIM;
79-
return addNoiseToRGB(src, dest, coverageAnim, rand);
74+
return isGrayscale(src)
75+
? addNoiseToGray(src, dest, rand)
76+
: addNoiseToRGB(src, dest, rand);
8077
}
8178

82-
private BufferedImage addNoiseToRGB(BufferedImage src, BufferedImage dest,
83-
boolean coverageAnim, SplittableRandom rand) {
79+
private BufferedImage addNoiseToRGB(BufferedImage src, BufferedImage dest, RandomGenerator rand) {
80+
boolean coverageAnim = method.getValue() == METHOD_COVERAGE_ANIM;
8481
int[] srcPixels = ImageUtils.getPixels(src);
8582
int[] destPixels = ImageUtils.getPixels(dest);
8683
int numPixels = destPixels.length;
@@ -124,8 +121,8 @@ private BufferedImage addNoiseToRGB(BufferedImage src, BufferedImage dest,
124121
}
125122

126123
if (!coverageAnim) {
127-
// If coverage animation isn't a requirement, then it is faster
128-
// to generate the random values only here, for the covered pixels.
124+
// if coverage animation isn't a requirement, then it is faster
125+
// to generate the random values only here, for the covered pixels
129126
randomInt = rand.nextInt();
130127
}
131128

@@ -135,11 +132,11 @@ private BufferedImage addNoiseToRGB(BufferedImage src, BufferedImage dest,
135132

136133
if (fullOpacity) {
137134
// if we have full saturation (the default), then we can
138-
// just use the random pixel as it is - if the opacity is also 100.
135+
// just use the random pixel as it is - if the opacity is also 100
139136
destPixels[i] = randomInt;
140137
} else {
141-
// ...or mix the random pixel with the source according to
142-
// the opacity
138+
// ...or mix the random pixel with the source
139+
// according to the opacity
143140
destPixels[i] = ImageMath.mixColors(opacity, srcRGB, randomInt);
144141
}
145142
} else { // desaturate the random pixel
@@ -167,7 +164,7 @@ private BufferedImage addNoiseToRGB(BufferedImage src, BufferedImage dest,
167164
}
168165

169166
private BufferedImage addNoiseToGray(BufferedImage src, BufferedImage dest,
170-
SplittableRandom rand) {
167+
RandomGenerator rand) {
171168
byte[] srcPixels = ImageUtils.getGrayPixels(src);
172169
byte[] destPixels = ImageUtils.getGrayPixels(dest);
173170

src/main/java/pixelitor/filters/Canny.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import pd.CannyEdgeDetector;
2121
import pixelitor.filters.gui.BooleanParam;
22+
import pixelitor.filters.gui.Help;
2223
import pixelitor.filters.gui.RangeParam;
2324
import pixelitor.utils.MemoryInfo;
2425
import pixelitor.utils.Messages;
@@ -64,7 +65,7 @@ public Canny() {
6465
);
6566
highThreshold.ensureHigherValueThan(lowThreshold);
6667

67-
helpURL = "https://en.wikipedia.org/wiki/Canny_edge_detector";
68+
help = Help.fromWikiURL("https://en.wikipedia.org/wiki/Canny_edge_detector");
6869
}
6970

7071
@Override

0 commit comments

Comments
 (0)