First initial detection system for DDR scores using pixel checking algorithm (#1)
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>main
parent
8eb9edb71a
commit
0f3c03be58
@ -1,7 +1,63 @@ |
|||||||
package readers.fonts; |
package readers.fonts; |
||||||
|
|
||||||
|
import java.awt.image.BufferedImage; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.awt.Color; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
public class Glyph { |
public class Glyph { |
||||||
|
final static int TRANSPARENT = new Color(0,0,0,0).getRGB(); |
||||||
int width=0; |
int width=0; |
||||||
int height=0; |
int height=0; |
||||||
boolean[] data = new boolean[]{}; |
boolean[] data = new boolean[]{}; |
||||||
|
|
||||||
|
public static List<Glyph> split(BufferedImage img) { |
||||||
|
int startX=-1; |
||||||
|
int endX=-1; |
||||||
|
List<Glyph> glyphs = new ArrayList<>(); |
||||||
|
outer: |
||||||
|
for (int x=0;x<img.getWidth();x++) { |
||||||
|
for (int y=0;y<img.getHeight();y++) { |
||||||
|
if (img.getRGB(x, y)!=TRANSPARENT) { |
||||||
|
if (startX==-1) { |
||||||
|
startX=x; |
||||||
|
} |
||||||
|
continue outer; |
||||||
|
} |
||||||
|
} |
||||||
|
//If we got to here it means we found transparent on everything.
|
||||||
|
if (startX!=-1) { |
||||||
|
endX=x; |
||||||
|
//Create a Glyph out of this.
|
||||||
|
Glyph g = new Glyph(); |
||||||
|
g.width=endX-startX; |
||||||
|
g.height=img.getHeight(); |
||||||
|
int[] arr = img.getRGB(startX,0,g.width,g.height,null,0,g.width); |
||||||
|
//Find the min and max Y.
|
||||||
|
int startY=g.height; |
||||||
|
int endY=0; |
||||||
|
for (int X=0;X<g.width;X++) { |
||||||
|
for (int Y=0;Y<g.height;Y++) { |
||||||
|
if (arr[Y*g.width+X]!=TRANSPARENT&&Y<startY) { |
||||||
|
startY=Y; |
||||||
|
} |
||||||
|
if (arr[Y*g.width+X]!=TRANSPARENT&&Y>endY) { |
||||||
|
endY=Y; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
g.height=endY-startY; |
||||||
|
g.data = new boolean[g.width*g.height]; |
||||||
|
for (int X=0;X<g.width;X++) { |
||||||
|
for (int Y=0;Y<g.height;Y++) { |
||||||
|
g.data[Y*g.width+X]=arr[(Y+startY)*g.width+X]!=TRANSPARENT; |
||||||
|
} |
||||||
|
} |
||||||
|
glyphs.add(g); |
||||||
|
startX=-1; |
||||||
|
endX=-1; |
||||||
|
} |
||||||
|
} |
||||||
|
return glyphs; |
||||||
|
} |
||||||
} |
} |
||||||
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 160 KiB |
Loading…
Reference in new issue