Skip to content

Commit e728d6e

Browse files
committed
CF 1.4
Color filtering optimized.
1 parent cbc8f4a commit e728d6e

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

Catalano.Image/nbproject/private/private.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
33
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
44
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
5-
<group>
6-
<file>file:/C:/Users/Diego/Desktop/Git%20Hub%20Projects/Catalano-Framework/Catalano.Image/src/Catalano/Imaging/Filters/Exp.java</file>
7-
</group>
5+
<group/>
86
</open-files>
97
</project-private>

Catalano.Image/src/Catalano/Imaging/Filters/ColorFiltering.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,22 @@
3131
/**
3232
* Color filtering.
3333
* <p> The filter filters pixels inside/outside of specified RGB color range - it keeps pixels with colors inside/outside of specified range and fills the rest with specified color</p>.
34+
*
35+
* Supported types: RGB.
36+
* Coordinate System: Independent.
37+
*
3438
* @author Diego Catalano
3539
*/
3640
public class ColorFiltering implements IBaseInPlace{
3741
private IntRange red, green, blue;
3842

3943
/**
40-
* Initialize a new instance of the BottomHat class.
44+
* Initialize a new instance of the ColorFiltering class.
4145
*/
4246
public ColorFiltering() {}
4347

4448
/**
45-
* Initialize a new instance of the BottomHat class.
49+
* Initialize a new instance of the ColorFiltering class.
4650
* @param red Range of red color component.
4751
* @param green Range of green color component.
4852
* @param blue Range of blue color component.
@@ -55,30 +59,29 @@ public ColorFiltering(IntRange red, IntRange green, IntRange blue) {
5559

5660
@Override
5761
public void applyInPlace(FastBitmap fastBitmap){
58-
int width = fastBitmap.getWidth();
59-
int height = fastBitmap.getHeight();
60-
int r,g,b;
6162

62-
63-
for (int x = 0; x < height; x++) {
64-
for (int y = 0; y < width; y++) {
65-
r = fastBitmap.getRed(x, y);
66-
g = fastBitmap.getGreen(x, y);
67-
b = fastBitmap.getBlue(x, y);
68-
63+
if(fastBitmap.isRGB()){
64+
int r,g,b;
65+
int[] pixels = fastBitmap.getRGBData();
66+
for (int i = 0; i < pixels.length; i++) {
67+
r = pixels[i] >> 16 & 0xFF;
68+
g = pixels[i] >> 8 & 0xFF;
69+
b = pixels[i] & 0xFF;
70+
6971
if (
7072
(r >= red.getMin()) && (r <= red.getMax()) &&
7173
(g >= green.getMin()) && (g <= green.getMax()) &&
7274
(b >= blue.getMin()) && (b <= blue.getMax())
7375
){
74-
fastBitmap.setRGB(x, y, r, g, b);
76+
pixels[i] = r << 16 | g << 8 | b;
7577
}
7678
else{
77-
fastBitmap.setRGB(x, y, 0, 0, 0);
79+
pixels[i] = 0;
7880
}
79-
8081
}
8182
}
83+
else{
84+
throw new IllegalArgumentException("Color filtering only works in RGB images.");
85+
}
8286
}
83-
84-
}
87+
}

0 commit comments

Comments
 (0)