static QRgb getSubpixel(const QImage &img, double x, double y) { int fx = fixedfraction(x); int fy = fixedfraction(y); int px = (int)x; int py = (int)y; QRgb p1; QRgb p2; QRgb p3; QRgb p4; int right = 1; int below = 1; if (py >= img.height() - 1 ) { // We are partially outside the image, do our best here. below = 0; } if (px >= img.width() - 1) { // We are partially outside the image, do our best here. right = 0; } p1 = weighpixel(img.pixel(px, py), (FIXEDPOINT_MULTIPLIER-fx)*(FIXEDPOINT_MULTIPLIER-fy)); p2 = weighpixel(img.pixel(px+right, py), fx*(FIXEDPOINT_MULTIPLIER-fy)); p3 = weighpixel(img.pixel(px, py+below), (FIXEDPOINT_MULTIPLIER-fx)*fy); p4 = weighpixel(img.pixel(px+right, py+below), fx*fy); return qRgb((qRed(p1) + qRed(p2) + qRed(p3) + qRed(p4)), (qGreen(p1) + qGreen(p2) + qGreen(p3) + qGreen(p4)), (qBlue(p1) + qBlue(p2) + qBlue(p3) + qBlue(p4))); }
/* * Gets a pixel at a floating-point coordinate, thus causing it to take into * accountance neighbour pixels if one of the coordinates have a fractional part * * The function will calculate the pixel value by calculating all areas the * pixel occupies in each neighbouring pixel. */ static QRgb getPixel(const QImage &img, double x, double y) { int fx = fixedfraction(x); int fy = fixedfraction(y); int px = (int) x; int py = (int) y; int right = 1; if (px >= img.width() - 1) { right = 0; } int below = 1; if (py >= img.height() - 1) { below = 0; } QRgb p1 = weighpixel(img.pixel(px, py), (FIXEDPOINT_MULTIPLIER - fx) * (FIXEDPOINT_MULTIPLIER - fy)); QRgb p2 = weighpixel(img.pixel(px + right, py), fx * (FIXEDPOINT_MULTIPLIER - fy)); QRgb p3 = weighpixel(img.pixel(px, py + below), (FIXEDPOINT_MULTIPLIER - fx) * fy); QRgb p4 = weighpixel(img.pixel(px + right, py + below), fx * fy); return qRgb((qRed(p1) + qRed(p2) + qRed(p3) + qRed(p4)), (qGreen(p1) + qGreen(p2) + qGreen(p3) + qGreen(p4)), (qBlue(p1) + qBlue(p2) + qBlue(p3) + qBlue(p4))); }