Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

18
LINES

< > BotCompany Repo | #1004605 // imageToUtf

JavaX fragment (include)

1  
static S imageToUtf(BWImage img) {
2  
  int w = img.getWidth(), h = img.getHeight();
3  
  if (h < 12) null;
4  
  
5  
  byte[] data = new byte[w-2];
6  
  for (int x = 1; x < w-1; x++) {
7  
    int b = 0;
8  
    if (img.getPixel(x, 0) != 0
9  
      || img.getPixel(x, 11) != 0)
10  
      fail("not an utf8 image");
11  
      
12  
    for (int y = 2; y < 2+8; y++)
13  
      b = b << 1 | (img.getPixel(x, y) > .5f ? 0 : 1);
14  
      
15  
    data[x-1] = (byte) b;
16  
  }
17  
  ret fromUtf8(data);
18  
}

Author comment

Began life as a copy of #1004602

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004605
Snippet name: imageToUtf
Eternal ID of this version: #1004605/1
Text MD5: 6b13107240ef737221d9cb5579aa0d3c
Author: stefan
Category: javax / images
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-23 22:02:02
Source code size: 458 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 593 / 562
Referenced in: [show references]