Skip to content

Commit 638a6cb

Browse files
authored
Update ofPixels.cpp (#7989)
Fixes ofPixels_<PixelType>::resizeTo for float pixels (and hopefully every type of pixels) simply replacing bytesPerPixel by channelsFromPixelFormat(pixelFormat) to find indices.
1 parent efdaddf commit 638a6cb

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

libs/openFrameworks/graphics/ofPixels.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,8 +1359,8 @@ bool ofPixels_<PixelType>::resizeTo(ofPixels_<PixelType>& dst, ofInterpolationMe
13591359
float srcx = 0.5;
13601360
size_t srcIndex = static_cast<size_t>(srcy) * srcWidth;
13611361
for (size_t dstx=0; dstx<dstWidth; dstx++){
1362-
size_t pixelIndex = static_cast<size_t>(srcIndex + srcx) * bytesPerPixel;
1363-
for (size_t k=0; k<bytesPerPixel; k++){
1362+
size_t pixelIndex = static_cast<size_t>(srcIndex + srcx) * channelsFromPixelFormat(pixelFormat);
1363+
for (size_t k=0; k< channelsFromPixelFormat(pixelFormat); k++){
13641364
dstPixels[dstIndex] = pixels[pixelIndex];
13651365
dstIndex++;
13661366
pixelIndex++;
@@ -1389,19 +1389,19 @@ bool ofPixels_<PixelType>::resizeTo(ofPixels_<PixelType>& dst, ofInterpolationMe
13891389
size_t patchIndex;
13901390
float patch[16];
13911391

1392-
size_t srcRowBytes = srcWidth*bytesPerPixel;
1392+
size_t srcRowBytes = srcWidth*channelsFromPixelFormat(pixelFormat);
13931393
size_t loIndex = (srcRowBytes)+1;
1394-
size_t hiIndex = (srcWidth*srcHeight*bytesPerPixel)-(srcRowBytes)-1;
1394+
size_t hiIndex = (srcWidth*srcHeight*channelsFromPixelFormat(pixelFormat))-(srcRowBytes)-1;
13951395

13961396
for (size_t dsty=0; dsty<dstHeight; dsty++){
13971397
for (size_t dstx=0; dstx<dstWidth; dstx++){
13981398

1399-
size_t dstIndex0 = (dsty*dstWidth + dstx) * bytesPerPixel;
1399+
size_t dstIndex0 = (dsty*dstWidth + dstx) * channelsFromPixelFormat(pixelFormat);
14001400
float srcxf = srcWidth * (float)dstx/(float)dstWidth;
14011401
float srcyf = srcHeight * (float)dsty/(float)dstHeight;
14021402
size_t srcx = static_cast<size_t>(std::min(srcWidth-1, static_cast<size_t>(srcxf)));
14031403
size_t srcy = static_cast<size_t>(std::min(srcHeight-1, static_cast<size_t>(srcyf)));
1404-
size_t srcIndex0 = (srcy*srcWidth + srcx) * bytesPerPixel;
1404+
size_t srcIndex0 = (srcy*srcWidth + srcx) * channelsFromPixelFormat(pixelFormat);
14051405

14061406
px1 = srcxf - srcx;
14071407
py1 = srcyf - srcy;
@@ -1410,14 +1410,14 @@ bool ofPixels_<PixelType>::resizeTo(ofPixels_<PixelType>& dst, ofInterpolationMe
14101410
py2 = py1 * py1;
14111411
py3 = py2 * py1;
14121412

1413-
for (size_t k=0; k<bytesPerPixel; k++){
1413+
for (size_t k=0; k<channelsFromPixelFormat(pixelFormat); k++){
14141414
size_t dstIndex = dstIndex0+k;
14151415
size_t srcIndex = srcIndex0+k;
14161416

14171417
for (size_t dy=0; dy<4; dy++) {
14181418
patchRow = srcIndex + ((dy-1)*srcRowBytes);
14191419
for (size_t dx=0; dx<4; dx++) {
1420-
patchIndex = patchRow + (dx-1)*bytesPerPixel;
1420+
patchIndex = patchRow + (dx-1)*channelsFromPixelFormat(pixelFormat);
14211421
if ((patchIndex >= loIndex) && (patchIndex < hiIndex)) {
14221422
srcColor = pixels[patchIndex];
14231423
}

0 commit comments

Comments
 (0)