Skip to content

Commit 2ab1c95

Browse files
authored
Merge pull request #23 from Bob-Rust/feature/bug-fixes
feature: Fix some color issues
2 parents 973980b + d189a47 commit 2ab1c95

File tree

9 files changed

+70
-84
lines changed

9 files changed

+70
-84
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ jobs:
77
runs-on: windows-latest
88

99
steps:
10-
- uses: actions/checkout@v2
10+
- uses: actions/checkout@v3
1111
- name: Cache Gradle packages
12-
uses: actions/cache@v2
12+
uses: actions/cache@v3
1313
with:
1414
path: ~/.gradle/caches
1515
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
1616
restore-keys: ${{ runner.os }}-gradle
1717
- name: Set up JDK 16
18-
uses: actions/setup-java@v2
18+
uses: actions/setup-java@v3
1919
with:
2020
distribution: 'adopt'
2121
java-version: 16
2222
- name: Package
2323
run: ./gradlew jpackage
24-
- uses: actions/upload-artifact@v2
24+
- uses: actions/upload-artifact@v3
2525
with:
2626
name: Win-installer
2727
path: build/distributions/*

src/main/java/com/bobrust/generator/BorstCore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static BorstColor computeColor(BorstImage target, BorstImage current, int alpha,
4040
bsum_2 += (cc ) & 0xff;
4141
}
4242

43-
count += (line.x2 - line.x1 + 1);
43+
count += (xe - xs + 1);
4444
}
4545

4646
int pd = 65280 / alpha; // (255 << 8) / alpha;

src/main/java/com/bobrust/generator/BorstGenerator.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.ArrayList;
55
import java.util.List;
66
import java.util.Objects;
7-
import java.util.concurrent.ExecutorService;
87
import java.util.function.Consumer;
98

109
import com.bobrust.generator.sorter.Blob;
@@ -62,7 +61,6 @@ public synchronized boolean start(Model previous, BufferedImage inputImage, int
6261
data.blobs.clear();
6362
data.blobs.addAll(generateDebugDrawList());
6463
data.index = data.blobs.size();
65-
data.alpha = 0;
6664
callback.accept(data);
6765
}
6866

@@ -209,7 +207,6 @@ private List<Blob> generateDebugDrawList() {
209207
*/
210208
public static class BorstData {
211209
private final List<Blob> blobs;
212-
private int alpha;
213210
private int index;
214211

215212
private BorstData() {
@@ -218,7 +215,6 @@ private BorstData() {
218215

219216
private synchronized void update(Model model, int index) {
220217
this.index = index;
221-
this.alpha = model.alpha;
222218

223219
// For all new elements
224220
var shapes = model.shapes;
@@ -238,7 +234,6 @@ private synchronized void update(Model model, int index) {
238234
}
239235

240236
private void clear() {
241-
this.alpha = 0;
242237
this.index = 0;
243238
this.blobs.clear();
244239
}
@@ -247,10 +242,6 @@ public List<Blob> getBlobs() {
247242
return blobs;
248243
}
249244

250-
public int getAlpha() {
251-
return alpha;
252-
}
253-
254245
public int getIndex() {
255246
return index;
256247
}

src/main/java/com/bobrust/generator/BorstSettings.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/main/java/com/bobrust/gui/render/ShapeRender.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import com.bobrust.generator.BorstGenerator;
44
import com.bobrust.generator.BorstUtils;
5+
import com.bobrust.generator.sorter.BlobList;
6+
import com.bobrust.generator.sorter.BorstSorter;
57

68
import java.awt.*;
79
import java.awt.image.BufferedImage;
810
import java.awt.image.DataBufferByte;
911
import java.util.ArrayList;
1012
import java.util.List;
13+
import java.util.Random;
1114

1215
/**
1316
* Optimized class for rendering many circles
@@ -49,11 +52,64 @@ public synchronized void createCanvas(int width, int height, int background) {
4952
pixelBufferCache.add(canvasPixels.clone());
5053
}
5154

55+
private BufferedImage createTest(BorstGenerator.BorstData data, int shapes) {
56+
System.arraycopy(pixelBufferCache.get(0), 0, canvasPixels, 0, canvasPixels.length);
57+
58+
Random random = new Random(34);
59+
60+
BlobList sorted = new BlobList(data.getBlobs());
61+
sorted = BorstSorter.sort(sorted);
62+
63+
Graphics2D g = canvas.createGraphics();
64+
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
65+
66+
double failRate = 0;
67+
int cd = sorted.get(0).size;
68+
int is = cd;
69+
70+
int pc = sorted.get(0).color;
71+
int ps = pc;
72+
73+
for (int i = 0; i < shapes; i++) {
74+
var blob = sorted.get(i);
75+
int alpha = BorstUtils.ALPHAS[blob.alphaIndex];
76+
77+
if (is != blob.size) {
78+
is = blob.size;
79+
if (random.nextDouble() > failRate) {
80+
cd = is;
81+
}
82+
}
83+
84+
if (ps != blob.color) {
85+
ps = blob.color;
86+
if (random.nextDouble() > failRate) {
87+
pc = ps;
88+
}
89+
}
90+
91+
g.setColor(new Color(pc | (alpha << 24), true));
92+
if (blob.shapeIndex == 3) {
93+
cd *= 1.25;
94+
g.fillRect(blob.x - cd / 2, blob.y - cd / 2, cd, cd);
95+
} else {
96+
g.fillOval(blob.x - cd / 2, blob.y - cd / 2, cd, cd);
97+
}
98+
}
99+
g.dispose();
100+
101+
return canvas;
102+
}
103+
52104
public synchronized BufferedImage getImage(BorstGenerator.BorstData data, int shapes) {
53105
if (pixelBufferCache.isEmpty()) {
54106
return null;
55107
}
56108

109+
//if (true) {
110+
// return createTest(data, shapes);
111+
//}
112+
57113
int cacheIndex = shapes / cacheInterval;
58114

59115
// The pixel buffer of the closest image

src/main/java/com/bobrust/main/Main.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ public static void main(String[] args) {
3131
LOGGER.info(" AppVersion : {}", AppConstants.VERSION);
3232
LOGGER.info("");
3333

34-
// TODO: Do not draw outside the image region +- the radius of the largest shape
35-
3634
// Setup settings
3735
File CONFIG_FILE = new File("bobrust.properties");
3836
Settings.InternalSettings.init(CONFIG_FILE);
@@ -53,22 +51,5 @@ public static void main(String[] args) {
5351
// Make application window visible
5452
new ApplicationWindow().setVisible(true);
5553
});
56-
57-
/*
58-
Thread aliveThread = new Thread(() -> {
59-
while (true) {
60-
try {
61-
Thread.sleep(10000);
62-
} catch (InterruptedException ignored) {
63-
Thread.currentThread().interrupt();
64-
break;
65-
}
66-
67-
System.out.println("Alive");
68-
}
69-
}, "Alive thread");
70-
aliveThread.setDaemon(true);
71-
aliveThread.start();
72-
*/
7354
}
7455
}

src/main/java/com/bobrust/robot/BobRustPainter.java

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,8 @@ public boolean startDrawing(GraphicsConfiguration monitor, Rectangle canvasArea,
109109
}
110110

111111
// Change the color
112-
if (lastColor != blob.colorIndex) {
113-
if (!clickColor(robot, palette.getColorButton(BorstUtils.getClosestColor(blob.color)), 8, autoDelay)) {
114-
// LOGGER.warn("Potentially failed to change color! Will still keep try drawing");
115-
}
116-
112+
if (lastColor != blob.colorIndex) { // Without 20 here it will not work
113+
clickColor(robot, palette.getColorButton(BorstUtils.getClosestColor(blob.color)), 20, autoDelay);
117114
lastColor = blob.colorIndex;
118115
actions++;
119116
}
@@ -145,7 +142,7 @@ public boolean startDrawing(GraphicsConfiguration monitor, Rectangle canvasArea,
145142
int sy = (int) ty + displayY;
146143

147144
lastPoint.setLocation(sx, sy);
148-
clickPointScaled(robot, lastPoint, autoDelay);
145+
clickPointScaledDrawColor(robot, lastPoint, autoDelay);
149146

150147
if ((i % autosaveInterval) == 0) {
151148
clickPoint(robot, palette.getSaveButton(), autoDelay);
@@ -179,7 +176,7 @@ private void clickPoint(Robot robot, Point point, int times, double delay) throw
179176
/**
180177
* Click a point on the screen with a scaled point
181178
*/
182-
private void clickPointScaled(Robot robot, Point point, double delay) throws PaintingInterrupted {
179+
private void clickPointScaledDrawColor(Robot robot, Point point, double delay) throws PaintingInterrupted {
183180
double time = System.nanoTime() / 1000000.0;
184181

185182
robot.mouseMove(point.x, point.y);
@@ -246,7 +243,7 @@ private void clickSize(Robot robot, Point point, int maxAttempts, double delay)
246243
}
247244
}
248245

249-
private boolean clickColor(Robot robot, Point point, int maxAttempts, double delay) throws PaintingInterrupted {
246+
private void clickColor(Robot robot, Point point, int maxAttempts, double delay) throws PaintingInterrupted {
250247
Point colorPreview = palette.getColorPreview();
251248
Color before = robot.getPixelColor(colorPreview.x, colorPreview.y);
252249

@@ -256,28 +253,9 @@ private boolean clickColor(Robot robot, Point point, int maxAttempts, double del
256253

257254
Color after = robot.getPixelColor(colorPreview.x, colorPreview.y);
258255
if (!before.equals(after)) {
259-
return true;
260-
}
261-
}
262-
263-
return false;
264-
}
265-
266-
private boolean clickColorTest(Robot robot, Point point, int maxAttempts, double delay) throws PaintingInterrupted {
267-
Point colorPreview = palette.getColorPreview();
268-
Color before = robot.getPixelColor(colorPreview.x, colorPreview.y);
269-
270-
// Make sure that we press the size
271-
while (maxAttempts-- > 0) {
272-
clickPointScaled(robot, point, delay);
273-
274-
Color after = robot.getPixelColor(colorPreview.x, colorPreview.y);
275-
if (!before.equals(after)) {
276-
return true;
256+
return;
277257
}
278258
}
279-
280-
return false;
281259
}
282260

283261
/**

src/main/resources/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.64
1+
0.4.67

version.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#Mon Jul 17 12:24:45 CEST 2023
2-
build_id=64
1+
#Fri Jul 21 13:35:02 CEST 2023
2+
build_id=68

0 commit comments

Comments
 (0)