Skip to content

Commit e8615e9

Browse files
committed
Bugfix: height and width swapped
1 parent b767f43 commit e8615e9

File tree

8 files changed

+37
-49
lines changed

8 files changed

+37
-49
lines changed

src/milchreis/imageprocessing/Comparison.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public static float howDifferent(PImage img1, PImage img2) {
1414

1515
long diff = 0L;
1616

17-
for (int y = 0; y < img1.width; y++) {
18-
for (int x = 0; x < img1.height; x++) {
17+
for (int y = 0; y < img1.height; y++) {
18+
for (int x = 0; x < img1.width; x++) {
1919

2020
int[] rgb1 = Tools.getRGB(img1.get(x, y));
2121
int[] rgb2 = Tools.getRGB(img2.get(x, y));
@@ -39,8 +39,8 @@ public static PImage calculateDifferenceImage(PImage img1, PImage img2) {
3939

4040
PImage output = Tools.createBlankImageLike(img1);
4141

42-
for (int y = 0; y < img1.width; y++) {
43-
for (int x = 0; x < img1.height; x++) {
42+
for (int y = 0; y < img1.height; y++) {
43+
for (int x = 0; x < img1.width; x++) {
4444

4545
int[] rgb1 = Tools.getRGB(img1.get(x, y));
4646
int[] rgb2 = Tools.getRGB(img2.get(x, y));

src/milchreis/imageprocessing/Contrast.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,35 @@ public static PImage apply(PImage image, float intensity) {
2020
PImage output = image.copy();
2121

2222
int contrastIntensity = (int) map(intensity, -1.0f, 1.0f, -255, 255);
23-
24-
float contrastCorrectionFactor =
25-
(259.f * (contrastIntensity + 255))
26-
/
27-
(255f * (259 - contrastIntensity));
23+
float contrastCorrectionFactor = getContrasCorrectionFactor(contrastIntensity);
2824

2925
for(int x=0; x < image.width; x++) {
3026
for(int y=0; y < image.height; y++) {
3127

3228
int[] rgb = Tools.getColors(image, x, y);
33-
34-
rgb[0] = (int)constrain(contrastCorrectionFactor * (rgb[0] - 128) + 128, 0, 255);
35-
rgb[1] = (int)constrain(contrastCorrectionFactor * (rgb[1] - 128) + 128, 0, 255);
36-
rgb[2] = (int)constrain(contrastCorrectionFactor * (rgb[2] - 128) + 128, 0, 255);
37-
29+
contrastPixel(rgb, contrastCorrectionFactor);
3830
Tools.set(output, x, y, rgb[0], rgb[1], rgb[2]);
3931
}
4032
}
41-
33+
4234
return output;
4335
}
4436

37+
/**
38+
*
39+
* @param contrastIntensity value between -255 and 255
40+
* @return
41+
*/
42+
static float getContrasCorrectionFactor(int contrastIntensity) {
43+
return (259.f * (contrastIntensity + 255))
44+
/
45+
(255f * (259 - contrastIntensity));
46+
}
47+
48+
static void contrastPixel(int[] rgb, float contrastCorrectionFactor) {
49+
rgb[0] = (int)constrain(contrastCorrectionFactor * (rgb[0] - 128) + 128, 0, 255);
50+
rgb[1] = (int)constrain(contrastCorrectionFactor * (rgb[1] - 128) + 128, 0, 255);
51+
rgb[2] = (int)constrain(contrastCorrectionFactor * (rgb[2] - 128) + 128, 0, 255);
52+
}
4553

46-
4754
}

src/milchreis/imageprocessing/Halftone.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public static PImage apply(PImage image, int dotsize, int foreground, int backgr
4747

4848
int xOffset = 0;
4949

50-
for (int y = 0; y < canvas.width; y += dotsize + spacing) {
51-
for (int x = xOffset; x < canvas.height; x += dotsize + spacing) {
50+
for (int y = 0; y < canvas.height; y += dotsize + spacing) {
51+
for (int x = xOffset; x < canvas.width; x += dotsize + spacing) {
5252

5353
int color = image.get(x+dotsize/2, y+dotsize/2);
5454

src/milchreis/imageprocessing/Intensity.java

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

src/milchreis/imageprocessing/Saturation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public static PImage apply(PImage image, float intensity) {
1717

1818
PImage out = image.copy();
1919

20-
for (int y = 0; y < image.width; y++) {
21-
for (int x = 0; x < image.height; x++) {
20+
for (int y = 0; y < image.height; y++) {
21+
for (int x = 0; x < image.width; x++) {
2222

2323
int rgb = image.get(x, y);
2424
float[] hsb = Tools.rgbToHsb(rgb);

src/milchreis/imageprocessing/SplitToning.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public static PImage apply(PImage image, int highlightColor, float highlightInte
2020
int[] highlightTone = Tools.getRGB(highlightColor);
2121
int[] shadowTone = Tools.getRGB(shadowsColor);
2222

23-
for (int y = 0; y < image.width; y++) {
24-
for (int x = 0; x < image.height; x++) {
23+
for (int y = 0; y < image.height; y++) {
24+
for (int x = 0; x < image.width; x++) {
2525

2626
int color = image.get(x, y);
2727
int[] rgb = Tools.getRGB(color);

src/milchreis/imageprocessing/Toning.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public static PImage apply(PImage image, int color, float intensity) {
1818
PImage output = Tools.createBlankImageLike(image);
1919
int[] tone = Tools.getRGB(color);
2020

21-
for (int y = 0; y < image.width; y++) {
22-
for (int x = 0; x < image.height; x++) {
21+
for (int y = 0; y < image.height; y++) {
22+
for (int x = 0; x < image.width; x++) {
2323

2424
int[] rgb = Tools.getRGB(image.get(x, y));
2525
tonePixel(rgb, tone, intensity);

src/milchreis/imageprocessing/utils/Tools.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,13 @@ public static int getRGB(int red, int green, int blue) {
102102
* @return
103103
*/
104104
public static float[] rgbToHsb(int rgb) {
105-
int[] arrRGB = getRGB(rgb);
106-
return rgbToHsb(arrRGB[0], arrRGB[1], arrRGB[2]);
105+
return rgbToHsb(getRGB(rgb));
107106
}
108-
107+
108+
public static float[] rgbToHsb(int[] rgb) {
109+
return rgbToHsb(rgb[0], rgb[1], rgb[2]);
110+
}
111+
109112
/**
110113
* Returns an array for hue, saturation and brightness
111114
* in range:

0 commit comments

Comments
 (0)