Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- byte[] gWidths = new byte[this.end - this.start + 1];
- for (int i: gWidths) {
- BufferedImage sheet = this.sheets.get(i / 128);
- for (int j = 0; j < 256; j++) {
- // for each individual glyph...
- int width = -1;
- //You could set width to -1 if the possibility exists that the glyph is completely black
- //with that you could find out if the width is actually column 0 or non-existant.
- for (int k = 0; k < 64; k++) {
- // for each individual pixel...
- int x = (j % 16) * 8 + (k % 8);
- int y = (j / 16) * 8 + (k / 8);
- //if you want to go through them by line and not by column, like this:
- //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
- //17 18 19 20…
- //
- //use this code instead:
- //
- // int x = Math.floor(j / 8) * 8 + (k%8)
- // int y = (j % 8) * 8 + Math.floor(k/8)
- // Util.log(x + "|" + y);
- // Util.log(this.sheets.get(0).getSource());
- // Util.log(this.sheets.get(0).getWidth());
- // Util.log(this.sheets.get(0).getHeight());
- boolean isWhite = sheet.getRGB(x, y) == (new Color(0xff, 0xff, 0xff)).getRGB(); // I don't trust any of this
- //I merged the two for loops since it's not necessary to go reverse.
- //Because of that we don't have a need to write isWhite into an array
- //and can just define the boolean inside the loop.
- if(isWhite && (k % 8 > width)){
- //Now we know the pixel is white and the position in line is bigger than the previous value in width.
- //We need to know this because if width is, for example, currently 5, and this pixel is positioned
- //at 3, width should stay at 5 and not get overwritten by 3.
- width = k % 8;
- }
- }
- gWidths[i] = (byte) width;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement