示例#1
0
bool rx_load_png(Image& img, std::string filename, bool datapath) {
  
  PNG png;

  if(!png.load(filename, datapath)) {
    return false;
  }
  
  switch(png.getColorType()) {
    case PNG_COLOR_TYPE_GRAY: {
      img.setPixelFormat(RX_FMT_GRAY8);
      break;
    }
    case PNG_COLOR_TYPE_RGB: {
      img.setPixelFormat(RX_FMT_RGB24);
      break;
    }
    case PNG_COLOR_TYPE_RGB_ALPHA: {
      img.setPixelFormat(RX_FMT_RGBA32);
      break;
    }
    default: {
      RX_ERROR(PNG_ERR_UNSUPPORTED_FORMAT);
      return false;
    }
  }

  img.setWidth(png.getWidth());
  img.setHeight(png.getHeight());

  return img.copyPixels(png.getPixels(), png.getWidth(), png.getHeight(), img.getPixelFormat());
}
示例#2
0
void
ImageSearch::search(PNG& srchImg) {
    const PNGHelper subImageHelper(srchImg);
    const int maxRow = mainImage.getHeight() - srchImg.getHeight();
    const int maxCol = mainImage.getWidth()  - srchImg.getWidth();
    const int pixMatchNeeded = srchImg.getBufferSize() * matchPercent / 400;
    for(int col = 0; (col <= maxCol); col++) {
	for(int row = 0; (row <= maxRow); row++) {
	    const MatchedRect srchRegion(row, col, srchImg.getWidth(),
					 srchImg.getHeight());
	    if (mrl.isMatched(srchRegion)) {
		// Current search rgion is already part of a region
		// matched earlier in this method (same as thread).
		continue;
	    }
	    // Search for a match between sub-images.
	    PNGHelper mainImgHelper(mainImage, row, col);
	    int pixMatch = getMatchingPixelCount(isMask, mainImgHelper, subImageHelper,
						 srchImg.getHeight(),
						 srchImg.getWidth(), tolerance);
	    if (pixMatch > pixMatchNeeded) {
		// Found a matching region.
		mrl += srchRegion;
	    }
	}
    }
}
示例#3
0
PNG
ImageSearch::rotate90(PNG& png) {
    PNG retImg;
    retImg.create(png.getHeight(), png.getWidth());
    PNGHelper ret(retImg), src(png);
    for(int row = 0; (row < png.getHeight()); row++) {
        for(int col = 0; (col < png.getWidth()); col++) {
	    ret(col, png.getHeight() - row - 1) = src(row, col);
        }
    }
    return retImg;
}
示例#4
0
PNG
ImageSearch::flipVertical(PNG& png) { 
    const int height = png.getHeight(), width = png.getWidth();   
    PNG retImg;
    retImg.create(width, height);
    PNGHelper ret(retImg), src(png);

    for(int row = 0; (row < height); row++) {
        for(int col = 0; (col < width); col++) {
	    ret(height - row - 1, col) = src(row, col);
        }
    }
    return retImg;
}