comparison layer/Colour3DPlotRenderer.cpp @ 1531:084c591622c5

Slightly streamline image scaling
author Chris Cannam
date Wed, 09 Oct 2019 11:17:26 +0100
parents 62aad7969f8b
children 14a162f6870f
comparison
equal deleted inserted replaced
1530:34311e135695 1531:084c591622c5
777 Qt::IgnoreAspectRatio, 777 Qt::IgnoreAspectRatio,
778 Qt::SmoothTransformation); 778 Qt::SmoothTransformation);
779 } 779 }
780 780
781 // Same format as the target cache 781 // Same format as the target cache
782 QImage target(targetWidth, targetHeight, QImage::Format_ARGB32_Premultiplied); 782 QImage target(targetWidth, targetHeight,
783 QImage::Format_ARGB32_Premultiplied);
783 784
784 for (int y = 0; y < targetHeight; ++y) { 785 for (int y = 0; y < targetHeight; ++y) {
785 786
786 QRgb *targetLine = reinterpret_cast<QRgb *>(target.scanLine(y)); 787 QRgb *targetLine = reinterpret_cast<QRgb *>(target.scanLine(y));
787 788
788 int sy = int((uint64_t(y) * sourceHeight) / targetHeight); 789 int sy = int((uint64_t(y) * sourceHeight) / targetHeight);
789 if (sy == sourceHeight) --sy; 790 if (sy == sourceHeight) --sy;
790 791
792 // The source image is 8-bit indexed
793 const uchar *sourceLine = image.constScanLine(sy);
794
791 for (int x = 0; x < targetWidth; ++x) { 795 for (int x = 0; x < targetWidth; ++x) {
792 796
793 int sx = int((uint64_t(x) * sourceWidth) / targetWidth); 797 int sx = int((uint64_t(x) * sourceWidth) / targetWidth);
794 if (sx == sourceWidth) --sx; 798 if (sx == sourceWidth) --sx;
795 799
796 targetLine[x] = image.pixel(sx, sy); 800 targetLine[x] = image.color(sourceLine[sx]);
797 } 801 }
798 } 802 }
799 803
800 return target; 804 return target;
801 } 805 }