void ScreenOverlayGraphicsItem::setProjection( const ViewportParams *viewport )
{
    ScreenGraphicsItem::setProjection( viewport );
    /** @todo: take overlayXY into account */
    setPosition( QPointF( pixelValue( m_screenOverlay->screenXY().xunit(),
                                      viewport->width(),
                                      size().width(),
                                      m_screenOverlay->screenXY().x() ),
       viewport->height()-pixelValue( m_screenOverlay->screenXY().yunit(),
                                      viewport->height(),
                                      size().height(),
                                      m_screenOverlay->screenXY().y() ) ) );
}
static void
writeRow ( Image* img, GifPixelType* rowBuf, GifColorType* cm, int row )
{
  int             idx, col;
  jint            rgb;
  unsigned long   pix;

  for ( col=0; col < img->width; col++ ) {
	idx = rowBuf[col];
	if ( img->xMask && (idx == img->trans) ) {
	  pix = 0;
	  XPutPixel( img->xMask, col, row, 0);
	}
	else {
	  rgb = (cm[idx].Red << 16) | (cm[idx].Green << 8) | (cm[idx].Blue);
	  pix = pixelValue( X, rgb);
	}
	XPutPixel( img->xImg, col, row, pix);
  }
}
Esempio n. 3
0
/**
 * Converts an image buffer back from a qpixel-representation to normal, i.e.
 * shrinks the whole image both horizontally and vertically by factor 2
 * (leading to a factor 4 decrease in total).
 * buf must have been allocated before with 1/4-times amount of memory as
 * qpixelBuf.
 */
void convertFromQPixels(struct IMAGE* qpixelImage, struct IMAGE* image) {
    int x;
    int y;
    
    for (y = 0; y < image->height; y++) {
        const int yy = y*2;
        for (x = 0; x < image->width; x++) {
            const int xx = x*2;

            const int a = getPixel(xx, yy, qpixelImage);
            const int b = getPixel(xx+1, yy, qpixelImage);
            const int c = getPixel(xx, yy+1, qpixelImage);
            const int d = getPixel(xx+1, yy+1, qpixelImage);

            const int r = (red(a) + red(b) + red(c) + red(d)) / 4;
            const int g = (green(a) + green(b) + green(c) + green(d)) / 4;
            const int bl = (blue(a) + blue(b) + blue(c) + blue(d)) / 4;

            const int pixel = pixelValue(r, g, bl);

            setPixel(pixel, x, y, image);
        }
    }
}
Esempio n. 4
0
/**
 * Stretches the image so that the resulting image has a new size.
 *
 * @param w the new width to stretch to
 * @param h the new height to stretch to
 */
void stretch(int w, int h, struct IMAGE* image) {
    struct IMAGE newimage;
    int x;
    int y;
    int matrixX;
    int matrixY;
    int matrixWidth;
    int matrixHeight;
    int blockWidth;
    int blockHeight;
    int blockWidthRest;
    int blockHeightRest;
    int fillIndexWidth;
    int fillIndexHeight;
    int fill;
    int xx;
    int yy;
    int sum;
    int sumR;
    int sumG;
    int sumB;
    int sumCount;
    int pixel;

    if (verbose >= VERBOSE_MORE) {
        printf("stretching %dx%d -> %dx%d\n", image->width, image->height, w, h);
    }

    // allocate new buffer's memory
    initImage(&newimage, w, h, image->bitdepth, image->color, WHITE);
    
    blockWidth = image->width / w; // (0 if enlarging, i.e. w > image->width)
    blockHeight = image->height / h;

    if (w <= image->width) {
        blockWidthRest = (image->width) % w;
    } else { // modulo-operator doesn't work as expected: (3680 % 7360)==3680 ! (not 7360 as expected)
             // shouldn't always be a % b = b if a < b ?
        blockWidthRest = w;
    }

    if (h <= image->height) {
        blockHeightRest = (image->height) % h;
    } else {
        blockHeightRest = h;
    }

    // for each new pixel, get a matrix of pixels from which the new pixel should be derived
    // (when enlarging, this matrix is always of size 1x1)
    matrixY = 0;
    fillIndexHeight = 0;
    for (y = 0; y < h; y++) {
        fillIndexWidth = 0;
        matrixX = 0;
        if ( ( (y * blockHeightRest) / h ) == fillIndexHeight ) { // next fill index?
            // (If our optimizer is cool, the above "* blockHeightRest / h" will disappear
            // when images are enlarged, because in that case blockHeightRest = h has been set before,
            // thus we're in a Kripke-branch where blockHeightRest and h are the same variable.
            // No idea if gcc's optimizer does this...) (See again below.)
            fillIndexHeight++;
            fill = 1;
        } else {
            fill = 0;
        }
        matrixHeight = blockHeight + fill;
        for (x = 0; x < w; x++) {
            if ( ( (x * blockWidthRest) / w ) == fillIndexWidth ) { // next fill index?
                fillIndexWidth++;
                fill = 1;
            } else {
                fill = 0;
            }
            matrixWidth = blockWidth + fill;
            // if enlarging, map corrdinates directly
            if (blockWidth == 0) { // enlarging
                matrixX = (x * image->width) / w;
            }
            if (blockHeight == 0) { // enlarging
                matrixY = (y * image->height) / h;
            }
            
            // calculate average pixel value in source matrix
            if ((matrixWidth == 1) && (matrixHeight == 1)) { // optimization: quick version
                pixel = getPixel(matrixX, matrixY, image);
            } else {
                sumCount = 0;
                if (!image->color) {
                    sum = 0;
                    for (yy = 0; yy < matrixHeight; yy++) {
                        for (xx = 0; xx < matrixWidth; xx++) {
                            sum += getPixelGrayscale(matrixX + xx, matrixY + yy, image);
                            sumCount++;
                        }
                    }
                    sum = sum / sumCount;
                    pixel = pixelGrayscaleValue(sum);
                } else { // color
                    sumR = 0;
                    sumG = 0;
                    sumB = 0;
                    for (yy = 0; yy < matrixHeight; yy++) {
                        for (xx = 0; xx < matrixWidth; xx++) {
                            pixel = getPixel(matrixX + xx, matrixY + yy, image);
                            sumR += (pixel >> 16) & 0xff;
                            sumG += (pixel >> 8) & 0xff;
                            sumB += pixel & 0xff;
                            //sumR += getPixelComponent(matrixX + xx, matrixY + yy, RED, image);
                            //sumG += getPixelComponent(matrixX + xx, matrixY + yy, GREEN, image);
                            //sumB += getPixelComponent(matrixX + xx, matrixY + yy, BLUE, image);
                            sumCount++;
                        }
                    }
                    pixel = pixelValue( sumR/sumCount, sumG/sumCount, sumB/sumCount );
                }
            }
            setPixel(pixel, x, y, &newimage);
            
            // pixel may have resulted in a gray value, which will be converted to 1-bit
            // when the file gets saved, if .pbm format requested. black-threshold will apply.
            
            if (blockWidth > 0) { // shrinking
                matrixX += matrixWidth;
            }
        }
        if (blockHeight > 0) { // shrinking
            matrixY += matrixHeight;
        }
    }
    replaceImage(image, &newimage);
}