Пример #1
0
void RawImage::downsampleInPlace(unsigned int downsampleX, unsigned int downsampleY)
{
  RawImage* tmp = downsample(this, downsampleX, downsampleY);

  deletePixels();
  _type = tmp->getType();
  _bytesPerPixel = tmp->getBytesPerPixel();
  _width = tmp->getWidth();
  _height = tmp->getHeight();
  _pixels = tmp->takePixels();

  delete tmp;
}
Пример #2
0
RawImage* downsample(RawImage* src, unsigned int downsampleX, unsigned int downsampleY)
{
  RawImage* result = new RawImage(src->getType(), src->getBytesPerPixel(),
      src->getWidth() / downsampleX, src->getHeight() / downsampleY);
  
  size_t bpp = result->getBytesPerPixel();
  size_t xStride = (downsampleX - 1) * bpp;
  for (size_t y = 0; y < result->getHeight(); ++y) {
    size_t from = y * downsampleY * src->getWidth() * bpp;
    size_t to = y * result->getWidth() * bpp;
    for (size_t x = 0; x < result->getWidth(); ++x) {
      for (size_t b = 0; b < bpp; ++b) {
        result->getPixels()[to] = src->getPixels()[from];
        ++to;
        ++from;
      }
      from += xStride;
    }
  }

  return result;
}