diff --git a/libs/openFrameworks/graphics/ofPixels.cpp b/libs/openFrameworks/graphics/ofPixels.cpp index de5d1847b6f..134b40ef8cf 100644 --- a/libs/openFrameworks/graphics/ofPixels.cpp +++ b/libs/openFrameworks/graphics/ofPixels.cpp @@ -143,6 +143,8 @@ static size_t channelsFromPixelFormat(ofPixelFormat format){ return 1; break; case OF_PIXELS_GRAY_ALPHA: + + // FIXME: this is not true for OF_PIXELS_RGB565. it has 3 channels and 2 bytes. case OF_PIXELS_RGB565: return 2; break; @@ -393,10 +395,10 @@ template void ofPixels_::setFromExternalPixels(PixelType * newPixels, size_t w, size_t h, ofPixelFormat _pixelFormat){ clear(); pixelFormat = _pixelFormat; - width= w; + width = w; height = h; - pixelsSize = bytesFromPixelFormat(w,h,_pixelFormat); + pixelsSize = w * h * getNumChannels(); pixels = newPixels; pixelsOwner = false; @@ -513,8 +515,8 @@ void ofPixels_::allocate(size_t w, size_t h, ofPixelFormat format){ return; } - size_t newSize = bytesFromPixelFormat(w,h,format); - size_t oldSize = getTotalBytes(); + size_t newSize = w * h * pixelBitsFromPixelFormat(format); + size_t oldSize = width * height * pixelBitsFromPixelFormat(pixelFormat); //we check if we are already allocated at the right size if(bAllocated && newSize==oldSize){ pixelFormat = format; @@ -530,9 +532,12 @@ void ofPixels_::allocate(size_t w, size_t h, ofPixelFormat format){ width = w; height = h; - pixelsSize = newSize; + pixelsSize = w * h * getNumChannels(); + // we have some incongruence here, if we use PixelType + // we are not able to use RGB565 format pixels = new PixelType[pixelsSize]; +// pixels = new uint8_t[newSize]; bAllocated = true; pixelsOwner = true; } @@ -583,11 +588,11 @@ void ofPixels_::clear(){ pixels = nullptr; } - width = 0; - height = 0; - pixelFormat = OF_PIXELS_UNKNOWN; - pixelsSize = 0; - bAllocated = false; + width = 0; + height = 0; + pixelFormat = OF_PIXELS_UNKNOWN; + pixelsSize = 0; + bAllocated = false; } template diff --git a/libs/openFrameworks/graphics/ofPixels.h b/libs/openFrameworks/graphics/ofPixels.h index 0d28f8f0ef6..06f15f69193 100644 --- a/libs/openFrameworks/graphics/ofPixels.h +++ b/libs/openFrameworks/graphics/ofPixels.h @@ -679,8 +679,8 @@ class ofPixels_ { void copyFrom( const ofPixels_& mom ); PixelType * pixels = nullptr; - size_t width = 0; - size_t height = 0; + size_t width = 0; + size_t height = 0; //int channels; // 1, 3, 4 channels per pixel (grayscale, rgb, rgba) size_t pixelsSize = 0; diff --git a/scripts/apothecary b/scripts/apothecary index 2d2f7ad685a..2ba90dc7e8e 160000 --- a/scripts/apothecary +++ b/scripts/apothecary @@ -1 +1 @@ -Subproject commit 2d2f7ad685abb329363a82955779f26c4cd1d39b +Subproject commit 2ba90dc7e8e3fea3c7577890117d858455a3c422