void JB2Dict::JB2Codec::Decode::code_absolute_mark_size(GBitmap &bm, int border) { int xsize=CodeNum(0, BIGPOSITIVE, abs_size_x); int ysize=CodeNum(0, BIGPOSITIVE, abs_size_y); if ((xsize!=(unsigned short)xsize) || (ysize!=(unsigned short)ysize)) G_THROW( ERR_MSG("JB2Image.bad_number") ); bm.init(ysize, xsize, border); }
void JB2Dict::JB2Codec::Decode::code_relative_mark_size(GBitmap &bm, int cw, int ch, int border) { int xdiff=CodeNum(BIGNEGATIVE, BIGPOSITIVE, rel_size_x); int ydiff=CodeNum(BIGNEGATIVE, BIGPOSITIVE, rel_size_y); int xsize = cw + xdiff; int ysize = ch + ydiff; if ((xsize!=(unsigned short)xsize) || (ysize!=(unsigned short)ysize)) G_THROW( ERR_MSG("JB2Image.bad_number") ); bm.init(ysize, xsize, border); }
static void maskedSubsample(const GPixmap* img, const GBitmap *p_mask, GPixmap& subsampled_image, GBitmap& subsampled_mask, int gridwidth, int inverted_mask, int minpixels=1 ) { const GPixmap& image= *img; const GBitmap& mask = *p_mask; int imageheight = image.rows(); int imagewidth = image.columns(); // compute the size of the resulting subsampled image int subheight = imageheight/gridwidth; if(imageheight%gridwidth) subheight++; int subwidth = imagewidth/gridwidth; if(imagewidth%gridwidth) subwidth++; // set the sizes unless in incremental mode subsampled_image.init(subheight, subwidth); subsampled_mask.init(subheight, subwidth); // go subsampling int row, col; // row and col in the subsampled image int posx, posxend, posy, posyend; // corresponding square in the original image for(row=0, posy=0; row<subheight; row++, posy+=gridwidth) { GPixel* subsampled_image_row = subsampled_image[row]; // row row of subsampled image unsigned char* subsampled_mask_row = subsampled_mask[row]; // row row of subsampled mask posyend = posy+gridwidth; if(posyend>imageheight) posyend = imageheight; for(col=0, posx=0; col<subwidth; col++, posx+=gridwidth) { posxend = posx+gridwidth; if(posxend>imagewidth) posxend = imagewidth; int count = 0; int r = 0; int g = 0; int b = 0; for(int y=posy; y<posyend; y++) { const unsigned char* mask_y = mask[y]; // Row y of the mask for(int x=posx; x<posxend; x++) { unsigned char masked = (inverted_mask ? !mask_y[x] :mask_y[x]); if(!masked) { GPixel p = image[y][x]; r += p.r; g += p.g; b += p.b; count ++; } } } /* minpixels pixels are enough to give the color */ /* so set it, and do not mask this point */ if(count >= minpixels) { GPixel p; p.r = r/count; p.g = g/count; p.b = b/count; subsampled_image_row[col] = p; subsampled_mask_row[col] = 0; } else /* make it bright red and masked */ { subsampled_image_row[col] = GPixel::RED; subsampled_mask_row[col] = 1; } } } }