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

40
LINES

< > BotCompany Repo | #1032151 // IIPureQuad - pure = square & width/height is a power of two, quad = consists of 2*2 same-size sub-blocks [dev.]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Compilation Failed (4177L/23K).

sclass IIPureQuad extends Meta implements IIntegralImage {
  int imageSizeInBits; // e.g. 8 = 256*256
  int[] pixelSumsByChannel; // average color of whole image stored as pixel sum
  IIntegralImage[] quadrants = new[4]; // in scan line order
  
  int imageSize() { ret 1 << imageSizeInBits; }
  int halfSize() { ret 1 << (imageSizeInBits-1); }
  public int getWidth() { ret imageSize(); }
  public int getHeight() { ret imageSize(); }
  int pixelCount() { ret 1 << (imageSizeInBits*2); }

  public double getIntegralValue(int x, int y, int channel) {
    int quadX = x >> (imageSizeInBits-1);  // 0 or 1
    int quadY = y >> (imageSizeInBits-1);  // 0 or 1
    int quadrant = quadX | (quadY << 1); // 0 to 3
    int xLo = x & ~halfSize(); // clear topmost bit
    int yLo = y & ~halfSize(); // clear topmost bit
    
    // first query quadrant we landed in
    
    double pixelSum = quadrants[quadrant].getIntegralValue(xLo, yLo, channel);
    
    // add quadrant to the left
    
    if (quadX != 0)
      pixelSum += quadrants[quadrant-1].getIntegralValue(halfSize(), yLo, channel);
      
    // add quadrant above
      
    if (quadY != 0)
      pixelSum += quadrants[quadrant-2].getIntegralValue(xLo, halfSize(), channel);
      
    // add full top left quadrant
    
    if (quadrant == 3)
      pixelSum += quadrants[0].getIntegralValue(halfSize(), halfSize(), channel);
      
    ret pixelSum;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1032151
Snippet name: IIPureQuad - pure = square & width/height is a power of two, quad = consists of 2*2 same-size sub-blocks [dev.]
Eternal ID of this version: #1032151/6
Text MD5: 2cc54b6869e9c523e89e08afc7202196
Transpilation MD5: 464cc32bd4b24b24eb982c197fb42714
Author: stefan
Category: javax / integral imaging
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-15 00:47:43
Source code size: 1453 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 114 / 449
Version history: 5 change(s)
Referenced in: [show references]