Skip to content

Commit d9f1ec9

Browse files
committed
Major clean up. Fixed java path. made Color read only. Java doc updates
1 parent c29dac1 commit d9f1ec9

40 files changed

+531
-501
lines changed

build.gradle

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
apply plugin: 'java'
22
apply plugin: 'maven'
33

4-
group 'org.java-lcw'
5-
version="0.5."+"git rev-list HEAD --count".execute().in.text.trim()
4+
group 'me.lcw'
5+
version="0.6."+"git rev-list HEAD --count".execute().in.text.trim()
66

77
sourceCompatibility = 1.6
88
targetCompatibility = 1.6
@@ -15,11 +15,9 @@ repositories {
1515

1616
dependencies {
1717
compile (
18-
'org.eclipse.swt:org.eclipse.swt.gtk.linux.x86_64:4.3'
1918
)
2019

2120
testCompile (
22-
'org.eclipse.swt:org.eclipse.swt.gtk.linux.x86_64:4.3',
2321
'junit:junit:4.11'
2422
)
2523

src/main/java/org/java_lcw/jil/AWTImage.java renamed to src/main/java/me/lcw/jil/AWTImage.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.java_lcw.jil;
1+
package me.lcw.jil;
22

33
import java.awt.AlphaComposite;
44
import java.awt.BasicStroke;
@@ -178,7 +178,7 @@ public void save(String filename, ImageType type) throws IOException, ImageExcep
178178

179179

180180
@Override
181-
public JilImage toJavaImage() {
181+
public JilImage toJilImage() {
182182
return JilImage.fromBufferedImage(bi);
183183
}
184184

@@ -275,7 +275,7 @@ public void paste(int x, int y, Image img) {
275275
if(img instanceof AWTImage) {
276276
bi2 = ((AWTImage)img).bi;
277277
} else {
278-
bi2 = AWTImage.fromJavaImage(img.toJavaImage()).bi;
278+
bi2 = AWTImage.fromJavaImage(img.toJilImage()).bi;
279279
}
280280
Graphics2D gi = bi.createGraphics();
281281
try{
@@ -293,7 +293,7 @@ public void merge(int x, int y, Image img) {
293293
if(img instanceof AWTImage) {
294294
bi2 = ((AWTImage)img).bi;
295295
} else {
296-
bi2 = AWTImage.fromJavaImage(img.toJavaImage()).bi;
296+
bi2 = AWTImage.fromJavaImage(img.toJilImage()).bi;
297297
}
298298
Graphics2D gi = bi.createGraphics();
299299
try {
@@ -412,9 +412,9 @@ public void floodFill(int x, int y, Color c, Color edge, boolean keepAlpha) {
412412
ce = pl.poll();
413413
Color tmpC = ai.getPixel(ce[0], ce[1]);
414414
if(tmpC!=null && tmpC.equalsNoAlpha(OC)) {
415-
Color nc = c.copy();
415+
Color nc = c;
416416
if(keepAlpha) {
417-
nc.setAlpha(tmpC.getAlpha());
417+
nc = c.changeAlpha(tmpC.getAlpha());
418418
}
419419
ai.setPixel(ce[0], ce[1], nc);
420420
if(ce[0]+1 < ai.getWidth()) {
@@ -435,12 +435,11 @@ public void floodFill(int x, int y, Color c, Color edge, boolean keepAlpha) {
435435
while(pl.size() > 0) {
436436
ce = pl.poll();
437437
Color tmpC = ai.getPixel(ce[0], ce[1]);
438-
Color nc = c.copy();
438+
Color nc = c;
439439
if(keepAlpha) {
440-
nc.setAlpha(tmpC.getAlpha());
440+
nc = c.changeAlpha(tmpC.getAlpha());
441441
}
442442
if(!tmpC.equals(edge) && !tmpC.equals(nc)) {
443-
444443
ai.setPixel(ce[0], ce[1], nc);
445444
if(ce[0]+1 < ai.getWidth()) {
446445
pl.add(new Integer[]{ce[0]+1, ce[1]});
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
package me.lcw.jil;
2+
3+
/**
4+
* This class is how colors are passed around to/from the Image Object.
5+
*
6+
* Colors are technically *read-only*. There are methods to make a duplicate
7+
* color with a changed color channel.
8+
*
9+
*/
10+
public class Color implements Comparable<Color> {
11+
public static final byte MAX_BYTE = (byte)255;
12+
public static final byte EMPTY_BYTE = (byte)0;
13+
14+
public static final Color BLACK = new Color(EMPTY_BYTE);
15+
public static final Color WHITE = new Color(MAX_BYTE);
16+
public static final Color GREY = new Color((byte)127);
17+
public static final Color RED = new Color(MAX_BYTE, EMPTY_BYTE, EMPTY_BYTE);
18+
public static final Color GREEN = new Color(EMPTY_BYTE, MAX_BYTE, EMPTY_BYTE);
19+
public static final Color BLUE = new Color(EMPTY_BYTE, EMPTY_BYTE, MAX_BYTE);
20+
public static final Color ALPHA = new Color(EMPTY_BYTE, EMPTY_BYTE, EMPTY_BYTE, EMPTY_BYTE);
21+
22+
private final byte green;
23+
private final byte red;
24+
private final byte blue;
25+
private final byte grey;
26+
private final byte alpha;
27+
28+
29+
/**
30+
* Construct a Grey color. Alpha is set to max value.
31+
*
32+
* @param grey grey color level.
33+
*/
34+
public Color(byte grey) {
35+
this.red = grey;
36+
this.green = grey;
37+
this.blue = grey;
38+
this.alpha = MAX_BYTE;
39+
this.grey = grey;
40+
}
41+
42+
/**
43+
* Construct the color with RGB values set. Alpha will be max value.
44+
*
45+
* @param red red color level
46+
* @param green green color level
47+
* @param blue blue color level
48+
*/
49+
public Color(byte red, byte green, byte blue) {
50+
this(red, green, blue, MAX_BYTE);
51+
}
52+
53+
/**
54+
* Construct the color with RGBA values set.
55+
*
56+
* @param red red color level
57+
* @param green green color level
58+
* @param blue blue color level
59+
* @param alpha alpha level
60+
*/
61+
public Color(byte red, byte green, byte blue, byte alpha) {
62+
this.red = red;
63+
this.green = green;
64+
this.blue = blue;
65+
this.alpha = alpha;
66+
this.grey = Utils.colorsToGrey(red, green, blue);
67+
}
68+
69+
/**
70+
* Creates a duplicate of this color with the BlueChannel changed.
71+
*
72+
* @param lblue value to set the blue color of the new color too.
73+
*/
74+
public Color changeBlue(byte lblue) {
75+
return new Color(red, green, lblue, alpha);
76+
}
77+
78+
/**
79+
*
80+
* @return the value of the blue channel for this color.
81+
*/
82+
public byte getBlue() {
83+
return blue;
84+
}
85+
86+
/**
87+
* Creates a duplicate of this color with the RedChannel changed.
88+
*
89+
* @param lred value to set the blue color of the new color too.
90+
*/
91+
public Color changeRed(byte lred) {
92+
return new Color(lred, green, blue, alpha);
93+
}
94+
95+
/**
96+
*
97+
* @return the value of the red channel for this color.
98+
*/
99+
public byte getRed() {
100+
return red;
101+
}
102+
103+
/**
104+
* Creates a duplicate of this color with the GreenChannel changed.
105+
*
106+
* @param lgreen value to set the blue color of the new color too.
107+
*/
108+
public Color changeGreen(byte lgreen) {
109+
return new Color(red, lgreen, blue, alpha);
110+
}
111+
112+
/**
113+
*
114+
* @return the value of the green channel for this color.
115+
*/
116+
public byte getGreen() {
117+
return green;
118+
}
119+
120+
/**
121+
* Creates a duplicate of this color with the AlphaChannel changed.
122+
*
123+
* @param lalpha value to set the alpha color of the new color too.
124+
*/
125+
public Color changeAlpha(byte lalpha) {
126+
return new Color(red, green, blue, lalpha);
127+
}
128+
129+
/**
130+
*
131+
* @return the value of the Alpha channel for this color.
132+
*/
133+
public byte getAlpha() {
134+
return alpha;
135+
}
136+
137+
/**
138+
* Creates a duplicate of this color with the GreyChannel changed.
139+
*
140+
* @param lgrey value to set the grey color of the new color too.
141+
*/
142+
public Color changeGrey(byte lgrey) {
143+
return new Color(lgrey);
144+
}
145+
146+
/**
147+
*
148+
* @return the value of the Grey channel for this color.
149+
*/
150+
public byte getGrey() {
151+
return grey;
152+
}
153+
154+
public int getARGB() {
155+
return alpha<<24 & 0xff000000 | red<<16 & 0xff0000 | green<<8 & 0xff00 | blue & 0xff;
156+
}
157+
158+
public int getRGBA() {
159+
return red<<24 & 0xff000000 | green<<16 & 0xff0000 | blue<<8 & 0xff00 |alpha & 0xff;
160+
}
161+
162+
public int getRGB() {
163+
return red<<16 & 0xff0000 | green<<8 & 0xff00 | blue & 0xff;
164+
}
165+
166+
@Override
167+
public String toString() {
168+
return "Colors: R:"+red+" G:"+green+" B:"+blue+" Alpha:"+alpha+" grey:"+grey;
169+
}
170+
171+
@Override
172+
public int hashCode() {
173+
return getARGB();
174+
}
175+
176+
@Override
177+
public boolean equals(Object o) {
178+
if(!(o instanceof Color)) {
179+
return false;
180+
}
181+
182+
Color c = (Color) o;
183+
long t = getARGB() & 0xffffffffL;
184+
long ot = c.getARGB() & 0xffffffffL;
185+
if (t == ot){
186+
return true;
187+
}
188+
return false;
189+
}
190+
191+
public boolean equalsNoAlpha(Object o) {
192+
if(!(o instanceof Color)) {
193+
return false;
194+
}
195+
Color c = (Color) o;
196+
long t = getRGB() & 0xffffffffL;
197+
long ot = c.getRGB() & 0xffffffffL;
198+
if (t == ot){
199+
return true;
200+
}
201+
return false;
202+
}
203+
204+
@Override
205+
public int compareTo(Color o) {
206+
long t = getARGB() & (long)0xffffffffL;
207+
long ot = o.getARGB() & (long)0xffffffffL;
208+
if(t > ot) {
209+
return 1;
210+
} else if (t < ot) {
211+
return -1;
212+
}
213+
return 0;
214+
}
215+
216+
}
217+
218+
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
package org.java_lcw.jil;
2-
1+
package me.lcw.jil;
32

3+
/**
4+
* The generic Draw Interface. These are the basic draw functions needed by any image implementing a "Drawer".
5+
*
6+
*/
47
public interface Draw {
58

69
/**
@@ -28,6 +31,7 @@ public interface Draw {
2831

2932
/**
3033
* Change the color at the set position to the specified color.
34+
*
3135
* @param x the x position to use.
3236
* @param y the y position to use.
3337
* @param c the color to set.
@@ -36,6 +40,7 @@ public interface Draw {
3640

3741
/**
3842
* Draw a circle at set position.
43+
*
3944
* @param cx the x position for the center of the circle.
4045
* @param cy the y position for the center of the circle.
4146
* @param size the diameter of the circle.
@@ -58,8 +63,6 @@ public interface Draw {
5863
*/
5964
public void drawLine(int startX, int startY, int endX, int endY, Color c, int lineWidth, boolean alphaMerge);
6065

61-
62-
6366
}
6467

6568

0 commit comments

Comments
 (0)