void ZLEwlImageData::copyFrom(const ZLImageData &source, unsigned int targetX __UNUSED__, unsigned int targetY __UNUSED__) { int sW = source.width(); int sH = source.height(); ZLEwlImageData *source_image = (ZLEwlImageData *)&source; memcpy(myImageData, source_image->getImageData(), sW * sH); }
void ZLGtkImageData::copyFrom(const ZLImageData &source, unsigned int targetX, unsigned int targetY) { gdk_pixbuf_copy_area( ((const ZLGtkImageData&)source).myPixbuf, 0, 0, source.width(), source.height(), myPixbuf, targetX, targetY ); }
void ZLWin32PaintContext::drawImage(int x, int y, const ZLImageData &image) { ZLWin32ImageData &win32Image = (ZLWin32ImageData&)image; const BYTE *pixels = win32Image.pixels(myBackgroundColor); if (pixels != 0) { const int width = image.width(); const int height = image.height(); StretchDIBits(myDisplayContext, x, y - height, width, height, 0, 0, width, height, pixels, win32Image.info(), DIB_RGB_COLORS, SRCCOPY); } }
void ZLWin32ImageData::copyFrom(const ZLImageData &source, unsigned int targetX, unsigned int targetY) { ZLWin32ImageData &win32source = (ZLWin32ImageData&)source; if ((myArray == 0) || (win32source.myArray == 0)) { return; } int height = source.height(); int bytes = source.width() * myBytesPerPixel; BYTE *src = win32source.myArray + win32source.myBytesPerLine * (win32source.myHeight - 1); BYTE *dst = myArray + (myHeight - targetY - 1) * myBytesPerLine + targetX * myBytesPerPixel; for (int i = 0; i < height; ++i) { memcpy(dst, src, bytes); dst -= myBytesPerLine; src -= win32source.myBytesPerLine; } }
int ZLPaintContext::imageHeight(const ZLImageData &image, int width, int height, ScalingType type) const { const int origWidth = image.width(); const int origHeight = image.height(); if (origWidth == 0 || origHeight == 0) { return 0; } if ((origWidth <= width) && (origHeight <= height)) { if (type == SCALE_REDUCE_SIZE) { return origHeight; } } else { width = std::min(width, origWidth); height = std::min(height, origHeight); } if (origWidth * height > origHeight * width) { return (origHeight * width + origWidth / 2) / origWidth; } return height; }
void floyd_steinberg_dither(ZLImageData &data) { ZLEwlImageData &i = (ZLEwlImageData&)data; int w = data.width(); int h = data.height(); unsigned char *c = (unsigned char*)i.getImageData(); int xi; unsigned char *x; int oldpixel, newpixel; int quant_error; extern int xcb_pal_colours; int factor = 255 / (xcb_pal_colours - 1); int factor_half = factor>>1; for(int j = 0; j < h; j++) for(int i = 0; i < w; i++) { x = c + j * w + i; oldpixel = *x; newpixel = (oldpixel + factor_half) / factor; newpixel *= factor; if(newpixel > 255) newpixel = 255; if(newpixel < 0) newpixel = 0; *x = newpixel; quant_error = oldpixel - newpixel; if(i < w - 1) { x++; xi = *x; xi = xi + 7 * quant_error / 16; if(xi <= 0) *x = 0; else if (xi >= 255) *x = 255; else *x = xi; } x = c + (j+1) * w + i - 1; if(j < h - 1) { if(i > 0) { xi = *x; xi = xi + 3 * quant_error / 16; if(xi <= 0) *x = 0; else if (xi >= 255) *x = 255; else *x = xi; } x++; xi = *x; xi = xi + 5 * quant_error / 16; if(xi <= 0) *x = 0; else if (xi >= 255) *x = 255; else *x = xi; if(i < w - 1) { x++; xi = *x; xi = xi + quant_error / 16; if(xi <= 0) *x = 0; else if (xi >= 255) *x = 255; else *x = xi; } } } }