From 7ddd099489ce1e951c63d25053b6f8ec6d8ad5dd Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sun, 5 May 2024 15:09:02 -0300 Subject: [PATCH 01/13] test pixel --- apps/projectGenerator | 2 +- libs/openFrameworks/graphics/ofPixels.cpp | 48 ++++------------------- libs/openFrameworks/graphics/ofPixels.h | 2 +- 3 files changed, 9 insertions(+), 43 deletions(-) diff --git a/apps/projectGenerator b/apps/projectGenerator index 67f29fb2b56..22db54d0c4f 160000 --- a/apps/projectGenerator +++ b/apps/projectGenerator @@ -1 +1 @@ -Subproject commit 67f29fb2b5638cc727afda8e97b211d4634f69b8 +Subproject commit 22db54d0c4f84ae71a6f09e876c592c5f8779b93 diff --git a/libs/openFrameworks/graphics/ofPixels.cpp b/libs/openFrameworks/graphics/ofPixels.cpp index 2aaaed2fa7f..d89748e2969 100644 --- a/libs/openFrameworks/graphics/ofPixels.cpp +++ b/libs/openFrameworks/graphics/ofPixels.cpp @@ -21,42 +21,8 @@ static ofImageType getImageTypeFromChannels(size_t channels){ } template -size_t ofPixels_::pixelBitsFromPixelFormat(ofPixelFormat format){ - switch(format){ - case OF_PIXELS_RGB: - case OF_PIXELS_BGR: - return 3 * sizeof(PixelType) * 8; - - case OF_PIXELS_RGBA: - case OF_PIXELS_BGRA: - return 4 * sizeof(PixelType) * 8; - - case OF_PIXELS_GRAY: - case OF_PIXELS_Y: - case OF_PIXELS_U: - case OF_PIXELS_V: - return 1 * sizeof(PixelType) * 8; - - case OF_PIXELS_NV12: - case OF_PIXELS_NV21: - case OF_PIXELS_YV12: - case OF_PIXELS_I420: - return 12; - - case OF_PIXELS_UV: - case OF_PIXELS_VU: - case OF_PIXELS_GRAY_ALPHA: - return 2 * sizeof(PixelType) * 8; - - case OF_PIXELS_YUY2: - case OF_PIXELS_UYVY: - case OF_PIXELS_RGB565: - return 16; - break; - default: - return 0; - } - +size_t ofPixels_::getBytesFromPixelFormat(ofPixelFormat format){ + return channelsFromPixelFormat(format) * sizeof(PixelType); } template<> @@ -131,7 +97,7 @@ std::string ofToString(const ofPixelFormat & p) { template size_t ofPixels_::bytesFromPixelFormat(size_t w, size_t h, ofPixelFormat format){ - return w * h * pixelBitsFromPixelFormat(format) / 8; + return w * h * getBytesFromPixelFormat(format); } static size_t channelsFromPixelFormat(ofPixelFormat format){ @@ -423,7 +389,7 @@ void ofPixels_::setFromAlignedPixels(const PixelType * newPixels, siz return; } allocate(width, height, _pixelFormat); - size_t dstStride = width * pixelBitsFromPixelFormat(_pixelFormat)/8; + size_t dstStride = width * getBytesFromPixelFormat(_pixelFormat); const unsigned char* src = (unsigned char*) newPixels; unsigned char* dst = (unsigned char*) pixels; for(size_t i = 0; i < height; i++) { @@ -808,12 +774,12 @@ size_t ofPixels_::getHeight() const{ template size_t ofPixels_::getBytesPerPixel() const{ - return pixelBitsFromPixelFormat(pixelFormat)/8; + return getBytesFromPixelFormat(pixelFormat); } template size_t ofPixels_::getBitsPerPixel() const{ - return pixelBitsFromPixelFormat(pixelFormat); + return getBytesFromPixelFormat(pixelFormat) * 8; } template @@ -828,7 +794,7 @@ size_t ofPixels_::getBitsPerChannel() const{ template size_t ofPixels_::getBytesStride() const{ - return pixelBitsFromPixelFormat(pixelFormat) * width / 8; + return getBytesFromPixelFormat(pixelFormat) * width; } template diff --git a/libs/openFrameworks/graphics/ofPixels.h b/libs/openFrameworks/graphics/ofPixels.h index fdd79e46a4b..c3b00028849 100644 --- a/libs/openFrameworks/graphics/ofPixels.h +++ b/libs/openFrameworks/graphics/ofPixels.h @@ -443,7 +443,7 @@ class ofPixels_ { void setNumChannels(size_t numChannels); - static size_t pixelBitsFromPixelFormat(ofPixelFormat format); + static size_t getBytesFromPixelFormat(ofPixelFormat format); static size_t bytesFromPixelFormat(size_t w, size_t h, ofPixelFormat format); /// \} From 84b85e328c8f21d4e82c8a305926e51f3b97eba4 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sun, 5 May 2024 15:15:16 -0300 Subject: [PATCH 02/13] up --- libs/openFrameworks/graphics/ofPixels.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libs/openFrameworks/graphics/ofPixels.cpp b/libs/openFrameworks/graphics/ofPixels.cpp index d89748e2969..ee9c9420c42 100644 --- a/libs/openFrameworks/graphics/ofPixels.cpp +++ b/libs/openFrameworks/graphics/ofPixels.cpp @@ -20,10 +20,6 @@ static ofImageType getImageTypeFromChannels(size_t channels){ } } -template -size_t ofPixels_::getBytesFromPixelFormat(ofPixelFormat format){ - return channelsFromPixelFormat(format) * sizeof(PixelType); -} template<> std::string ofToString(const ofPixelFormat & p) { @@ -142,6 +138,12 @@ static size_t channelsFromPixelFormat(ofPixelFormat format){ } } + +template +size_t ofPixels_::getBytesFromPixelFormat(ofPixelFormat format){ + return channelsFromPixelFormat(format) * sizeof(PixelType); +} + static ofPixelFormat ofPixelFormatFromImageType(ofImageType type){ switch(type){ case OF_IMAGE_GRAYSCALE: From 3d7bd63689cd41c4bd8a2ea5b79c1e26613322a1 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sun, 5 May 2024 15:49:56 -0300 Subject: [PATCH 03/13] memcpy --- libs/openFrameworks/graphics/ofPixels.cpp | 36 ++++++++++++++++++----- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/libs/openFrameworks/graphics/ofPixels.cpp b/libs/openFrameworks/graphics/ofPixels.cpp index ee9c9420c42..f0eda86606a 100644 --- a/libs/openFrameworks/graphics/ofPixels.cpp +++ b/libs/openFrameworks/graphics/ofPixels.cpp @@ -791,6 +791,14 @@ size_t ofPixels_::getBytesPerChannel() const{ template size_t ofPixels_::getBitsPerChannel() const{ +// FIXME: Still wrong here because of 12 bits formats + // TODO: A Switch case with exception + //case OF_PIXELS_NV12: + //case OF_PIXELS_NV21: + //case OF_PIXELS_YV12: + //case OF_PIXELS_I420: + // return 12; + return getBytesPerChannel() * 8; } @@ -1313,7 +1321,18 @@ bool ofPixels_::resizeTo(ofPixels_& dst, ofInterpolationMe size_t dstWidth = dst.getWidth(); size_t dstHeight = dst.getHeight(); size_t bytesPerPixel = getBytesPerPixel(); - + + using std::cout; + using std::endl; + cout << srcWidth << ":" << srcHeight << endl; + cout << dstWidth << ":" << dstHeight << endl; + std::cout << "bytesPerPixel " << bytesPerPixel << std::endl; + +// std::cout << sizeof(float) << std::endl; +// std::cout << sizeof(PixelType) << std::endl; +// std::cout << getNumChannels() << std::endl; + std::cout << "-----" << std::endl; + std::cout << "px " << sizeof(pixels) << std::endl; PixelType * dstPixels = dst.getData(); @@ -1329,12 +1348,15 @@ bool ofPixels_::resizeTo(ofPixels_& dst, ofInterpolationMe float srcx = 0.5; size_t srcIndex = static_cast(srcy) * srcWidth; for (size_t dstx=0; dstx(srcIndex + srcx) * bytesPerPixel; - for (size_t k=0; k Date: Sun, 5 May 2024 18:26:42 -0300 Subject: [PATCH 04/13] update --- libs/openFrameworks/graphics/ofBitmapFont.cpp | 14 ++--- libs/openFrameworks/graphics/ofBitmapFont.h | 2 +- libs/openFrameworks/graphics/ofPixels.cpp | 52 ++++++++----------- 3 files changed, 29 insertions(+), 39 deletions(-) diff --git a/libs/openFrameworks/graphics/ofBitmapFont.cpp b/libs/openFrameworks/graphics/ofBitmapFont.cpp index e4f31082c98..ed70d3a252d 100644 --- a/libs/openFrameworks/graphics/ofBitmapFont.cpp +++ b/libs/openFrameworks/graphics/ofBitmapFont.cpp @@ -328,22 +328,22 @@ static const unsigned char* bmpChar_8x13_Map[] = { bmpChar_8x13_000,bmpChar_8x13 #include "ofTexture.h" static const float widthTex = 8.0f/256.0f; static const float heightTex = 14.0f/256.0f; -ofPixels ofBitmapFont::pixels; +ofPixels ofBitmapFont::pixelsBitmapFont; using std::numeric_limits; using std::string; void ofBitmapFont::init(){ - if(pixels.isAllocated()) return; - pixels.allocate(16*16, 16*16, OF_PIXELS_GRAY_ALPHA); // letter size:8x14pixels, texture size:16x8letters, gl_r: 1bytes/1pixel - pixels.set(0); + if(pixelsBitmapFont.isAllocated()) return; + pixelsBitmapFont.allocate(16*16, 16*16, OF_PIXELS_GRAY_ALPHA); // letter size:8x14pixels, texture size:16x8letters, gl_r: 1bytes/1pixel + pixelsBitmapFont.set(0); for (size_t i = 0; i < 256; i++) { const unsigned char * face = bmpChar_8x13_Map[i]; for (size_t j = 1; j < 15; j++){ for (size_t k = 0; k < 8; k++){ if ( ((face[15-j] << k) & (128)) > 0 ){ - pixels[(((i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*2] = 255; - pixels[(((i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*2+1] = 255; + pixelsBitmapFont[(((i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*2] = 255; + pixelsBitmapFont[(((i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*2+1] = 255; } } } @@ -471,7 +471,7 @@ void ofBitmapFont::unloadTexture(){ const ofTexture & ofBitmapFont::getTexture() const{ if(!texture.isAllocated()){ ofBitmapFont::init(); - texture.allocate(pixels,false); + texture.allocate(pixelsBitmapFont,false); texture.setTextureMinMagFilter(GL_LINEAR,GL_NEAREST); } return texture; diff --git a/libs/openFrameworks/graphics/ofBitmapFont.h b/libs/openFrameworks/graphics/ofBitmapFont.h index 55f4432dabf..2d3fc88d6f0 100644 --- a/libs/openFrameworks/graphics/ofBitmapFont.h +++ b/libs/openFrameworks/graphics/ofBitmapFont.h @@ -25,7 +25,7 @@ class ofBitmapFont{ ofRectangle getBoundingBox(const std::string & text, int x, int y, ofDrawBitmapMode mode = ofGetStyle().drawBitmapMode, bool vFlipped = ofIsVFlipped()) const; private: static void init(); - static ofPixels pixels; + static ofPixels pixelsBitmapFont; void unloadTexture(); mutable ofTexture texture; }; diff --git a/libs/openFrameworks/graphics/ofPixels.cpp b/libs/openFrameworks/graphics/ofPixels.cpp index f0eda86606a..b73922a98cd 100644 --- a/libs/openFrameworks/graphics/ofPixels.cpp +++ b/libs/openFrameworks/graphics/ofPixels.cpp @@ -369,8 +369,11 @@ void ofPixels_::setFromExternalPixels(PixelType * newPixels, size_t w width= w; height = h; - pixelsSize = bytesFromPixelFormat(w,h,_pixelFormat) / sizeof(PixelType); - + // THIS DOESNT MAKES SENSE +// pixelsSize = bytesFromPixelFormat(w,h,_pixelFormat) / sizeof(PixelType); + // XAXA + pixelsSize = w * h * channelsFromPixelFormat(pixelFormat); + pixels = newPixels; pixelsOwner = false; bAllocated = true; @@ -488,6 +491,13 @@ void ofPixels_::allocate(size_t w, size_t h, ofPixelFormat format){ size_t newSize = bytesFromPixelFormat(w,h,format); size_t oldSize = getTotalBytes(); + +// using std::cout; +// using std::endl; +// cout << " newSize " << newSize << endl; +// cout << " oldSize " << oldSize << endl; +// +// cout << ofToString(format) << endl; //we check if we are already allocated at the right size if(bAllocated && newSize==oldSize){ pixelFormat = format; @@ -503,7 +513,8 @@ void ofPixels_::allocate(size_t w, size_t h, ofPixelFormat format){ width = w; height = h; - pixelsSize = newSize / sizeof(PixelType); + pixelsSize = w * h * getBytesFromPixelFormat(format); + pixels = new PixelType[pixelsSize]; bAllocated = true; @@ -1321,45 +1332,24 @@ bool ofPixels_::resizeTo(ofPixels_& dst, ofInterpolationMe size_t dstWidth = dst.getWidth(); size_t dstHeight = dst.getHeight(); size_t bytesPerPixel = getBytesPerPixel(); - - using std::cout; - using std::endl; - cout << srcWidth << ":" << srcHeight << endl; - cout << dstWidth << ":" << dstHeight << endl; - std::cout << "bytesPerPixel " << bytesPerPixel << std::endl; - -// std::cout << sizeof(float) << std::endl; -// std::cout << sizeof(PixelType) << std::endl; -// std::cout << getNumChannels() << std::endl; - std::cout << "-----" << std::endl; - std::cout << "px " << sizeof(pixels) << std::endl; - PixelType * dstPixels = dst.getData(); + auto dstPixels = dst.getData(); switch (interpMethod){ - //---------------------------------------- case OF_INTERPOLATE_NEAREST_NEIGHBOR:{ size_t dstIndex = 0; float srcxFactor = (float)srcWidth/dstWidth; float srcyFactor = (float)srcHeight/dstHeight; - float srcy = 0.5; for (size_t dsty=0; dsty(srcy) * srcWidth; + size_t srcIndex = static_cast(dsty * srcyFactor * srcWidth); for (size_t dstx=0; dstx(srcIndex + dstx * srcxFactor) * bytesPerPixel; + + memcpy(&pixels[pixelIndex], + &dstPixels[dstIndex], + bytesPerPixel); } - srcy+=srcyFactor; } }break; From d261e80f133a03b539c6385fe553004d81e2908e Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sun, 5 May 2024 18:31:32 -0300 Subject: [PATCH 05/13] more fixes --- libs/openFrameworks/graphics/ofPixels.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/libs/openFrameworks/graphics/ofPixels.cpp b/libs/openFrameworks/graphics/ofPixels.cpp index b73922a98cd..a4461433b6f 100644 --- a/libs/openFrameworks/graphics/ofPixels.cpp +++ b/libs/openFrameworks/graphics/ofPixels.cpp @@ -792,7 +792,8 @@ size_t ofPixels_::getBytesPerPixel() const{ template size_t ofPixels_::getBitsPerPixel() const{ - return getBytesFromPixelFormat(pixelFormat) * 8; + return getBitsPerChannel() * getNumChannels(); +// return getBytesFromPixelFormat(pixelFormat) * 8; } template @@ -802,15 +803,15 @@ size_t ofPixels_::getBytesPerChannel() const{ template size_t ofPixels_::getBitsPerChannel() const{ -// FIXME: Still wrong here because of 12 bits formats - // TODO: A Switch case with exception - //case OF_PIXELS_NV12: - //case OF_PIXELS_NV21: - //case OF_PIXELS_YV12: - //case OF_PIXELS_I420: - // return 12; - - return getBytesPerChannel() * 8; + switch(format){ + case OF_PIXELS_NV12: + case OF_PIXELS_NV21: + case OF_PIXELS_YV12: + case OF_PIXELS_I420: + return 12; + break; + default: + return getBytesPerChannel() * 8; } template From d9fd2325ab08bdaddfd000f34e1f2cd40fae4209 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sun, 5 May 2024 18:34:12 -0300 Subject: [PATCH 06/13] updates --- libs/openFrameworks/graphics/ofPixels.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/libs/openFrameworks/graphics/ofPixels.cpp b/libs/openFrameworks/graphics/ofPixels.cpp index a4461433b6f..efe1b4fddd8 100644 --- a/libs/openFrameworks/graphics/ofPixels.cpp +++ b/libs/openFrameworks/graphics/ofPixels.cpp @@ -369,9 +369,6 @@ void ofPixels_::setFromExternalPixels(PixelType * newPixels, size_t w width= w; height = h; - // THIS DOESNT MAKES SENSE -// pixelsSize = bytesFromPixelFormat(w,h,_pixelFormat) / sizeof(PixelType); - // XAXA pixelsSize = w * h * channelsFromPixelFormat(pixelFormat); pixels = newPixels; @@ -492,12 +489,6 @@ void ofPixels_::allocate(size_t w, size_t h, ofPixelFormat format){ size_t newSize = bytesFromPixelFormat(w,h,format); size_t oldSize = getTotalBytes(); -// using std::cout; -// using std::endl; -// cout << " newSize " << newSize << endl; -// cout << " oldSize " << oldSize << endl; -// -// cout << ofToString(format) << endl; //we check if we are already allocated at the right size if(bAllocated && newSize==oldSize){ pixelFormat = format; @@ -515,7 +506,6 @@ void ofPixels_::allocate(size_t w, size_t h, ofPixelFormat format){ pixelsSize = w * h * getBytesFromPixelFormat(format); - pixels = new PixelType[pixelsSize]; bAllocated = true; pixelsOwner = true; From eda1066516fd1751f314e77ebae1e6fe4165f400 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sun, 5 May 2024 19:26:39 -0300 Subject: [PATCH 07/13] ok now --- libs/openFrameworks/graphics/ofPixels.cpp | 85 +++++++++++++++++++++-- libs/openFrameworks/graphics/ofPixels.h | 3 + 2 files changed, 83 insertions(+), 5 deletions(-) diff --git a/libs/openFrameworks/graphics/ofPixels.cpp b/libs/openFrameworks/graphics/ofPixels.cpp index efe1b4fddd8..865a683145d 100644 --- a/libs/openFrameworks/graphics/ofPixels.cpp +++ b/libs/openFrameworks/graphics/ofPixels.cpp @@ -20,6 +20,58 @@ static ofImageType getImageTypeFromChannels(size_t channels){ } } +template +static size_t numChannelsFromPixelFormat(ofPixelFormat format) { + std::unordered_map pixelFormatChannels { + { OF_PIXELS_RGB, 3 }, + { OF_PIXELS_BGR, 3 }, + { OF_PIXELS_RGBA, 4 }, + { OF_PIXELS_RGBA, 4 }, + { OF_PIXELS_GRAY, 1 }, + { OF_PIXELS_Y, 1 }, + { OF_PIXELS_U, 1 }, + { OF_PIXELS_V, 1 }, + { OF_PIXELS_UV, 2 }, + { OF_PIXELS_VU, 2 }, + { OF_PIXELS_GRAY_ALPHA, 2 }, + }; + return pixelFormatChannels[format]; +} + +template +size_t ofPixels_::pixelBitsFromPixelFormat(ofPixelFormat format){ + switch(format){ + case OF_PIXELS_NV12: + case OF_PIXELS_NV21: + case OF_PIXELS_YV12: + case OF_PIXELS_I420: + return 12; + break; + + case OF_PIXELS_YUY2: + case OF_PIXELS_UYVY: + case OF_PIXELS_RGB565: + return 16; + break; + default: + + return + std::unordered_map { + { OF_PIXELS_RGB, 3 }, + { OF_PIXELS_BGR, 3 }, + { OF_PIXELS_RGBA, 4 }, + { OF_PIXELS_RGBA, 4 }, + { OF_PIXELS_GRAY, 1 }, + { OF_PIXELS_Y, 1 }, + { OF_PIXELS_U, 1 }, + { OF_PIXELS_V, 1 }, + { OF_PIXELS_UV, 2 }, + { OF_PIXELS_VU, 2 }, + { OF_PIXELS_GRAY_ALPHA, 2 }, + }[format] * sizeof(PixelType) * 8; +// return numChannelsFromPixelFormat(format) * sizeof(PixelType) * 8; + } +} template<> std::string ofToString(const ofPixelFormat & p) { @@ -93,7 +145,7 @@ std::string ofToString(const ofPixelFormat & p) { template size_t ofPixels_::bytesFromPixelFormat(size_t w, size_t h, ofPixelFormat format){ - return w * h * getBytesFromPixelFormat(format); + return w * h * pixelBitsFromPixelFormat(format)/8; } static size_t channelsFromPixelFormat(ofPixelFormat format){ @@ -133,7 +185,7 @@ static size_t channelsFromPixelFormat(ofPixelFormat format){ return 2; break; default: - ofLog(OF_LOG_ERROR,"ofPixels: format doesn't support channels"); + ofLog(OF_LOG_ERROR, "ofPixels: format doesn't support channels " + ofToString(format) ); return 1; } } @@ -783,7 +835,6 @@ size_t ofPixels_::getBytesPerPixel() const{ template size_t ofPixels_::getBitsPerPixel() const{ return getBitsPerChannel() * getNumChannels(); -// return getBytesFromPixelFormat(pixelFormat) * 8; } template @@ -793,15 +844,21 @@ size_t ofPixels_::getBytesPerChannel() const{ template size_t ofPixels_::getBitsPerChannel() const{ - switch(format){ + switch(getPixelFormat()){ case OF_PIXELS_NV12: case OF_PIXELS_NV21: case OF_PIXELS_YV12: case OF_PIXELS_I420: return 12; break; + case OF_PIXELS_YUY2: + case OF_PIXELS_UYVY: + case OF_PIXELS_RGB565: + return 16; + break; default: - return getBytesPerChannel() * 8; + return sizeof(PixelType); + } } template @@ -1329,6 +1386,24 @@ bool ofPixels_::resizeTo(ofPixels_& dst, ofInterpolationMe switch (interpMethod){ //---------------------------------------- case OF_INTERPOLATE_NEAREST_NEIGHBOR:{ +// size_t dstIndex = 0; +// float srcxFactor = (float)srcWidth/dstWidth; +// float srcyFactor = (float)srcHeight/dstHeight; +// float srcy = 0.5; +// for (size_t dsty=0; dsty(srcy) * srcWidth; +// for (size_t dstx=0; dstx(srcIndex + srcx) * bytesPerPixel; +// for (size_t k=0; k Date: Sun, 5 May 2024 19:31:00 -0300 Subject: [PATCH 08/13] unordered_map --- libs/openFrameworks/graphics/ofPixels.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openFrameworks/graphics/ofPixels.cpp b/libs/openFrameworks/graphics/ofPixels.cpp index 865a683145d..b14e77652ac 100644 --- a/libs/openFrameworks/graphics/ofPixels.cpp +++ b/libs/openFrameworks/graphics/ofPixels.cpp @@ -6,6 +6,7 @@ #define GLM_ENABLE_EXPERIMENTAL #include #include +#include static ofImageType getImageTypeFromChannels(size_t channels){ switch(channels){ From f1ec1e1f112c1145c1d1cb6e1354937149b08b8e Mon Sep 17 00:00:00 2001 From: Dimitre Date: Mon, 6 May 2024 12:43:26 -0300 Subject: [PATCH 09/13] up --- libs/openFrameworks/graphics/ofPixels.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/libs/openFrameworks/graphics/ofPixels.cpp b/libs/openFrameworks/graphics/ofPixels.cpp index b14e77652ac..70af0fd2f4b 100644 --- a/libs/openFrameworks/graphics/ofPixels.cpp +++ b/libs/openFrameworks/graphics/ofPixels.cpp @@ -197,6 +197,12 @@ size_t ofPixels_::getBytesFromPixelFormat(ofPixelFormat format){ return channelsFromPixelFormat(format) * sizeof(PixelType); } +//static unordered_map imageType2pixelFormat { +// { OF_IMAGE_GRAYSCALE, OF_PIXELS_GRAY }, +// { OF_IMAGE_COLOR, OF_PIXELS_RGB }, +// { OF_IMAGE_COLOR_ALPHA, OF_PIXELS_RGBA }, +//}; + static ofPixelFormat ofPixelFormatFromImageType(ofImageType type){ switch(type){ case OF_IMAGE_GRAYSCALE: @@ -419,7 +425,7 @@ template void ofPixels_::setFromExternalPixels(PixelType * newPixels, size_t w, size_t h, ofPixelFormat _pixelFormat){ clear(); pixelFormat = _pixelFormat; - width= w; + width = w; height = h; pixelsSize = w * h * channelsFromPixelFormat(pixelFormat); @@ -533,6 +539,11 @@ void ofPixels_::allocate(size_t w, size_t h, size_t _channels){ allocate(w,h,pixelFormatFromNumChannels(_channels)); } +template +void ofPixels_::allocate(size_t w, size_t h, ofImageType type){ + allocate(w,h,ofPixelFormatFromImageType(type)); +} + template void ofPixels_::allocate(size_t w, size_t h, ofPixelFormat format){ if (w == 0 || h == 0 || format == OF_PIXELS_UNKNOWN) { @@ -564,11 +575,6 @@ void ofPixels_::allocate(size_t w, size_t h, ofPixelFormat format){ pixelsOwner = true; } -template -void ofPixels_::allocate(size_t w, size_t h, ofImageType type){ - allocate(w,h,ofPixelFormatFromImageType(type)); -} - template void ofPixels_::swapRgb(){ switch(pixelFormat){ @@ -1201,7 +1207,7 @@ void ofPixels_::rotate90(int nClockwiseRotations){ ofPixels_ newPixels; rotate90To(newPixels,nClockwiseRotations); - std::swap(newPixels.pixels,pixels); + std::swap(newPixels.pixels, pixels); width = newPixels.width; height = newPixels.height; pixelsSize = newPixels.size(); From aa584ed5bdae1ec3e54fb4b6d31dde849a1fdeb3 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Mon, 6 May 2024 13:53:38 -0300 Subject: [PATCH 10/13] updates --- libs/openFrameworks/graphics/ofPixels.cpp | 166 ++++++++-------------- libs/openFrameworks/graphics/ofPixels.h | 58 ++++---- 2 files changed, 92 insertions(+), 132 deletions(-) diff --git a/libs/openFrameworks/graphics/ofPixels.cpp b/libs/openFrameworks/graphics/ofPixels.cpp index 70af0fd2f4b..c7f15a10676 100644 --- a/libs/openFrameworks/graphics/ofPixels.cpp +++ b/libs/openFrameworks/graphics/ofPixels.cpp @@ -22,7 +22,7 @@ static ofImageType getImageTypeFromChannels(size_t channels){ } template -static size_t numChannelsFromPixelFormat(ofPixelFormat format) { +static size_t numChannelsFromPixelFormat(ofPixelFormat _pixelFormat) { std::unordered_map pixelFormatChannels { { OF_PIXELS_RGB, 3 }, { OF_PIXELS_BGR, 3 }, @@ -36,12 +36,12 @@ static size_t numChannelsFromPixelFormat(ofPixelFormat format) { { OF_PIXELS_VU, 2 }, { OF_PIXELS_GRAY_ALPHA, 2 }, }; - return pixelFormatChannels[format]; + return pixelFormatChannels[_pixelFormat]; } template -size_t ofPixels_::pixelBitsFromPixelFormat(ofPixelFormat format){ - switch(format){ +size_t ofPixels_::pixelBitsFromPixelFormat(ofPixelFormat _pixelFormat){ + switch(_pixelFormat){ case OF_PIXELS_NV12: case OF_PIXELS_NV21: case OF_PIXELS_YV12: @@ -69,88 +69,45 @@ size_t ofPixels_::pixelBitsFromPixelFormat(ofPixelFormat format){ { OF_PIXELS_UV, 2 }, { OF_PIXELS_VU, 2 }, { OF_PIXELS_GRAY_ALPHA, 2 }, - }[format] * sizeof(PixelType) * 8; + }[_pixelFormat] * sizeof(PixelType) * 8; // return numChannelsFromPixelFormat(format) * sizeof(PixelType) * 8; } } template<> -std::string ofToString(const ofPixelFormat & p) { - switch (p){ - case OF_PIXELS_GRAY: - return "OF_PIXELS_GRAY"; - break; - case OF_PIXELS_GRAY_ALPHA: - return "OF_PIXELS_GRAY_ALPHA"; - break; - case OF_PIXELS_RGB: - return "OF_PIXELS_RGB"; - break; - case OF_PIXELS_BGR: - return "OF_PIXELS_BGR"; - break; - case OF_PIXELS_RGBA: - return "OF_PIXELS_RGBA"; - break; - case OF_PIXELS_BGRA: - return "OF_PIXELS_BGRA"; - break; - case OF_PIXELS_RGB565: - return "OF_PIXELS_RGB565"; - break; - case OF_PIXELS_NV12: - return "OF_PIXELS_NV12"; - break; - case OF_PIXELS_NV21: - return "OF_PIXELS_NV21"; - break; - case OF_PIXELS_YV12: - return "OF_PIXELS_YV12"; - break; - case OF_PIXELS_I420: - return "OF_PIXELS_I420"; - break; - case OF_PIXELS_YUY2: - return "OF_PIXELS_YUY2"; - break; - case OF_PIXELS_UYVY: - return "OF_PIXELS_UYVY"; - break; - case OF_PIXELS_Y: - return "OF_PIXELS_Y"; - break; - case OF_PIXELS_U: - return "OF_PIXELS_U"; - break; - case OF_PIXELS_V: - return "OF_PIXELS_V"; - break; - case OF_PIXELS_UV: - return "OF_PIXELS_UV"; - break; - case OF_PIXELS_VU: - return "OF_PIXELS_VU"; - break; - case OF_PIXELS_NUM_FORMATS: - return "OF_PIXELS_NUM_FORMATS"; - break; - case OF_PIXELS_UNKNOWN: - return "OF_PIXELS_UNKNOWN"; - break; - case OF_PIXELS_NATIVE: - return "OF_PIXELS_NATIVE"; - break; - } - return "OF_PIXELS_UNKNOWN"; -} - -template -size_t ofPixels_::bytesFromPixelFormat(size_t w, size_t h, ofPixelFormat format){ - return w * h * pixelBitsFromPixelFormat(format)/8; -} - -static size_t channelsFromPixelFormat(ofPixelFormat format){ - switch(format){ +std::string ofToString(const ofPixelFormat & _pixelFormat) { + return + std::unordered_map { + { OF_PIXELS_GRAY, "OF_PIXELS_GRAY" }, + { OF_PIXELS_GRAY_ALPHA, "OF_PIXELS_GRAY_ALPHA" }, + { OF_PIXELS_RGB, "OF_PIXELS_RGB" }, + { OF_PIXELS_BGR, "OF_PIXELS_BGR" }, + { OF_PIXELS_RGBA, "OF_PIXELS_RGBA" }, + { OF_PIXELS_BGRA, "OF_PIXELS_BGRA" }, + { OF_PIXELS_RGB565, "OF_PIXELS_RGB565" }, + { OF_PIXELS_NV12, "OF_PIXELS_NV12" }, + { OF_PIXELS_NV21, "OF_PIXELS_NV21" }, + { OF_PIXELS_YV12, "OF_PIXELS_YV12" }, + { OF_PIXELS_YUY2, "OF_PIXELS_YUY2" }, + { OF_PIXELS_UYVY, "OF_PIXELS_UYVY" }, + { OF_PIXELS_Y, "OF_PIXELS_Y" }, + { OF_PIXELS_U, "OF_PIXELS_U" }, + { OF_PIXELS_V, "OF_PIXELS_V" }, + { OF_PIXELS_UV, "OF_PIXELS_UV" }, + { OF_PIXELS_VU, "OF_PIXELS_VU" }, + { OF_PIXELS_NUM_FORMATS, "OF_PIXELS_NUM_FORMATS" }, + { OF_PIXELS_UNKNOWN, "OF_PIXELS_UNKNOWN" }, + { OF_PIXELS_NATIVE, "OF_PIXELS_NATIVE" }, + }[_pixelFormat]; +} + +template +size_t ofPixels_::bytesFromPixelFormat(size_t w, size_t h, ofPixelFormat _pixelFormat){ + return w * h * pixelBitsFromPixelFormat(_pixelFormat)/8; +} + +static size_t channelsFromPixelFormat(ofPixelFormat _pixelFormat){ + switch(_pixelFormat){ case OF_PIXELS_RGB: case OF_PIXELS_BGR: return 3; @@ -186,15 +143,15 @@ static size_t channelsFromPixelFormat(ofPixelFormat format){ return 2; break; default: - ofLog(OF_LOG_ERROR, "ofPixels: format doesn't support channels " + ofToString(format) ); + ofLog(OF_LOG_ERROR, "ofPixels: format doesn't support channels " + ofToString(_pixelFormat) ); return 1; } } template -size_t ofPixels_::getBytesFromPixelFormat(ofPixelFormat format){ - return channelsFromPixelFormat(format) * sizeof(PixelType); +size_t ofPixels_::getBytesFromPixelFormat(ofPixelFormat _pixelFormat){ + return channelsFromPixelFormat(_pixelFormat) * sizeof(PixelType); } //static unordered_map imageType2pixelFormat { @@ -220,8 +177,8 @@ static ofPixelFormat ofPixelFormatFromImageType(ofImageType type){ } } -static ofImageType ofImageTypeFromPixelFormat(ofPixelFormat pixelFormat){ - switch(pixelFormat){ +static ofImageType ofImageTypeFromPixelFormat(ofPixelFormat _pixelFormat){ + switch(_pixelFormat){ case OF_PIXELS_GRAY: return OF_IMAGE_GRAYSCALE; break; @@ -242,8 +199,8 @@ static ofImageType ofImageTypeFromPixelFormat(ofPixelFormat pixelFormat){ } } -std::string ofToString(ofPixelFormat pixelFormat){ - switch(pixelFormat){ +std::string ofToString(ofPixelFormat _pixelFormat){ + switch(_pixelFormat){ case OF_PIXELS_RGB: return "RGB"; case OF_PIXELS_BGR: @@ -410,8 +367,8 @@ void ofPixels_::setFromPixels(const PixelType * newPixels, size_t w, } template -void ofPixels_::setFromPixels(const PixelType * newPixels, size_t w, size_t h, ofPixelFormat format){ - allocate(w,h,format); +void ofPixels_::setFromPixels(const PixelType * newPixels, size_t w, size_t h, ofPixelFormat _pixelFormat){ + allocate(w,h,_pixelFormat); memcpy(pixels, newPixels, getTotalBytes()); } @@ -428,7 +385,7 @@ void ofPixels_::setFromExternalPixels(PixelType * newPixels, size_t w width = w; height = h; - pixelsSize = w * h * channelsFromPixelFormat(pixelFormat); + pixelsSize = bytesFromPixelFormat(w, h, _pixelFormat); pixels = newPixels; pixelsOwner = false; @@ -564,11 +521,11 @@ void ofPixels_::allocate(size_t w, size_t h, ofPixelFormat format){ //we do need to allocate, clear the data clear(); - pixelFormat = format; - width = w; - height = h; + pixelFormat = format; + width = w; + height = h; - pixelsSize = w * h * getBytesFromPixelFormat(format); + pixelsSize = bytesFromPixelFormat(w, h, pixelFormat); pixels = new PixelType[pixelsSize]; bAllocated = true; @@ -616,11 +573,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 @@ -1208,9 +1165,12 @@ void ofPixels_::rotate90(int nClockwiseRotations){ ofPixels_ newPixels; rotate90To(newPixels,nClockwiseRotations); std::swap(newPixels.pixels, pixels); - width = newPixels.width; - height = newPixels.height; - pixelsSize = newPixels.size(); + std::swap(newPixels.width, width); + std::swap(newPixels.height, height); +// width = newPixels.width; +// height = newPixels.height; + // not needed really because w*h = h*w +// pixelsSize = newPixels.size(); } diff --git a/libs/openFrameworks/graphics/ofPixels.h b/libs/openFrameworks/graphics/ofPixels.h index 6d23476101c..0160f472d6f 100644 --- a/libs/openFrameworks/graphics/ofPixels.h +++ b/libs/openFrameworks/graphics/ofPixels.h @@ -160,7 +160,7 @@ enum ofPixelFormat: short{ template std::string ofToString(const T & v); template<> -std::string ofToString(const ofPixelFormat & pixelType); +std::string ofToString(const ofPixelFormat & _pixelFormat); enum ofImageType: short; @@ -198,7 +198,7 @@ class ofPixels_ { /// \param w Width of pixel array /// \param h Height of pixel array /// \param pixelFormat ofPixelFormat defining number of channels per pixel - void allocate(size_t w, size_t h, ofPixelFormat pixelFormat); + void allocate(size_t w, size_t h, ofPixelFormat _pixelFormat); /// \brief Allocates space for pixel data /// @@ -237,14 +237,14 @@ class ofPixels_ { void set(PixelType val); void set(size_t channel,PixelType val); void setFromPixels(const PixelType * newPixels,size_t w, size_t h, size_t channels); - void setFromPixels(const PixelType * newPixels,size_t w, size_t h, ofPixelFormat pixelFormat); + void setFromPixels(const PixelType * newPixels,size_t w, size_t h, ofPixelFormat _pixelFormat); void setFromPixels(const PixelType * newPixels,size_t w, size_t h, ofImageType type); void setFromExternalPixels(PixelType * newPixels,size_t w, size_t h, size_t channels); - void setFromExternalPixels(PixelType * newPixels,size_t w, size_t h, ofPixelFormat pixelFormat); + void setFromExternalPixels(PixelType * newPixels,size_t w, size_t h, ofPixelFormat _pixelFormat); void setFromAlignedPixels(const PixelType * newPixels, size_t width, size_t height, size_t channels, size_t stride); - void setFromAlignedPixels(const PixelType * newPixels, size_t width, size_t height, ofPixelFormat pixelFormat, size_t stride); + void setFromAlignedPixels(const PixelType * newPixels, size_t width, size_t height, ofPixelFormat _pixelFormat, size_t stride); /// \brief used to copy i420 pixels from gstreamer when (width % 4) != 0 - void setFromAlignedPixels(const PixelType * newPixels, size_t width, size_t height, ofPixelFormat pixelFormat, std::vector strides); + void setFromAlignedPixels(const PixelType * newPixels, size_t width, size_t height, ofPixelFormat _pixelFormat, std::vector strides); void swap(ofPixels_ & pix); @@ -443,11 +443,11 @@ class ofPixels_ { void setNumChannels(size_t numChannels); - static size_t pixelBitsFromPixelFormat(ofPixelFormat format); + static size_t pixelBitsFromPixelFormat(ofPixelFormat _pixelFormat); - static size_t getBytesFromPixelFormat(ofPixelFormat format); - static size_t bytesFromPixelFormat(size_t w, size_t h, ofPixelFormat format); - static size_t numChannelsFromPixelFormat(ofPixelFormat format); + static size_t getBytesFromPixelFormat(ofPixelFormat _pixelFormat); + static size_t bytesFromPixelFormat(size_t w, size_t h, ofPixelFormat _pixelFormat); + static size_t numChannelsFromPixelFormat(ofPixelFormat _pixelFormat); /// \} /// \name Iterator @@ -471,7 +471,7 @@ class ofPixels_ { /// \cond INTERNAL struct ConstPixel{ - ConstPixel(const PixelType * pixel, size_t bytesPerPixel, ofPixelFormat pixelFormat); + ConstPixel(const PixelType * pixel, size_t bytesPerPixel, ofPixelFormat _pixelFormat); const ConstPixel& operator*() const; const ConstPixel* operator->() const; ConstPixel& operator++(); @@ -500,7 +500,7 @@ class ofPixels_ { }; struct Pixel { - Pixel(PixelType * pixel, size_t bytesPerPixel, ofPixelFormat pixelFormat); + Pixel(PixelType * pixel, size_t bytesPerPixel, ofPixelFormat _pixelFormat); const Pixel& operator*() const; const Pixel* operator->() const; Pixel& operator++(); @@ -533,7 +533,7 @@ class ofPixels_ { }; struct Pixels{ - Pixels(PixelType * begin, PixelType * end, size_t componentsPerPixel, ofPixelFormat pixelFormat); + Pixels(PixelType * begin, PixelType * end, size_t componentsPerPixel, ofPixelFormat _pixelFormat); Pixels(Pixel begin, Pixel end); Pixel begin(); Pixel end(); @@ -545,7 +545,7 @@ class ofPixels_ { }; struct Line { - Line(PixelType * _begin, size_t stride, size_t componentsPerPixel, size_t lineNum, ofPixelFormat pixelFormat); + Line(PixelType * _begin, size_t stride, size_t componentsPerPixel, size_t lineNum, ofPixelFormat _pixelFormat); const Line& operator*() const; const Line* operator->() const; Line& operator++(); @@ -586,7 +586,7 @@ class ofPixels_ { }; struct Lines{ - Lines(PixelType * _begin, PixelType * _end, size_t stride, size_t componentsPerPixel, size_t lines, ofPixelFormat pixelFormat); + Lines(PixelType * _begin, PixelType * _end, size_t stride, size_t componentsPerPixel, size_t lines, ofPixelFormat _pixelFormat); Line begin(); @@ -603,7 +603,7 @@ class ofPixels_ { }; struct ConstPixels{ - ConstPixels(const PixelType * begin, const PixelType * end, size_t componentsPerPixel, ofPixelFormat pixelFormat); + ConstPixels(const PixelType * begin, const PixelType * end, size_t componentsPerPixel, ofPixelFormat _pixelFormat); ConstPixels(const ConstPixel & begin, const ConstPixel & end); ConstPixel begin() const; ConstPixel end() const; @@ -615,7 +615,7 @@ class ofPixels_ { }; struct ConstLine { - ConstLine(const PixelType * _begin, size_t stride, size_t componentsPerPixel, size_t lineNum, ofPixelFormat pixelFormat); + ConstLine(const PixelType * _begin, size_t stride, size_t componentsPerPixel, size_t lineNum, ofPixelFormat _pixelFormat); const ConstLine& operator*() const; const ConstLine* operator->() const; ConstLine& operator++(); @@ -648,7 +648,7 @@ class ofPixels_ { }; struct ConstLines{ - ConstLines(const PixelType * _begin, const PixelType * _end, size_t stride, size_t componentsPerPixel, size_t lines, ofPixelFormat pixelFormat); + ConstLines(const PixelType * _begin, const PixelType * _end, size_t stride, size_t componentsPerPixel, size_t lines, ofPixelFormat _pixelFormat); ConstLine begin() const; @@ -804,10 +804,10 @@ inline typename ofPixels_::const_reverse_iterator ofPixels_ -inline ofPixels_::Pixel::Pixel(PixelType * pixel, size_t componentsPerPixel, ofPixelFormat pixelFormat) -:pixel(pixel) -,componentsPerPixel(componentsPerPixel) -,pixelFormat(pixelFormat){ +inline ofPixels_::Pixel::Pixel(PixelType * _pixel, size_t _componentsPerPixel, ofPixelFormat _pixelFormat) +:pixel(_pixel) +,componentsPerPixel(_componentsPerPixel) +,pixelFormat(_pixelFormat){ } @@ -973,7 +973,7 @@ ofColor_ ofPixels_::Pixel::getColor() const{ //---------------------------------------------------------------------- template -inline ofPixels_::Pixels::Pixels(PixelType * begin, PixelType * end, size_t componentsPerPixel, ofPixelFormat pixelFormat) +inline ofPixels_::Pixels::Pixels(PixelType * begin, PixelType * end, size_t componentsPerPixel, ofPixelFormat _pixelFormat) :_begin(begin) ,_end(end) ,componentsPerPixel(componentsPerPixel) @@ -1002,7 +1002,7 @@ inline typename ofPixels_::Pixel ofPixels_::Pixels::end(){ //---------------------------------------------------------------------- template -inline ofPixels_::Line::Line(PixelType * _begin, size_t stride, size_t componentsPerPixel, size_t lineNum, ofPixelFormat pixelFormat) +inline ofPixels_::Line::Line(PixelType * _begin, size_t stride, size_t componentsPerPixel, size_t lineNum, ofPixelFormat _pixelFormat) :_begin(_begin) ,_end(_begin+stride) ,stride(stride) @@ -1167,7 +1167,7 @@ inline typename ofPixels_::Pixels ofPixels_::Line::getPixe //---------------------------------------------------------------------- template -inline ofPixels_::Lines::Lines(PixelType * _begin, PixelType * _end, size_t stride, size_t componentsPerPixel, size_t lines, ofPixelFormat pixelFormat) +inline ofPixels_::Lines::Lines(PixelType * _begin, PixelType * _end, size_t stride, size_t componentsPerPixel, size_t lines, ofPixelFormat _pixelFormat) :_begin(_begin) ,_end(_end) ,stride(stride) @@ -1214,7 +1214,7 @@ inline typename ofPixels_::Pixels ofPixels_::getPixelsIter //---------------------------------------------------------------------- template -inline ofPixels_::ConstPixel::ConstPixel(const PixelType * pixel, size_t componentsPerPixel, ofPixelFormat pixelFormat) +inline ofPixels_::ConstPixel::ConstPixel(const PixelType * pixel, size_t componentsPerPixel, ofPixelFormat _pixelFormat) :pixel(pixel) ,componentsPerPixel(componentsPerPixel) ,pixelFormat(pixelFormat){ @@ -1344,7 +1344,7 @@ ofColor_ ofPixels_::ConstPixel::getColor() const{ //---------------------------------------------------------------------- template -inline ofPixels_::ConstPixels::ConstPixels(const PixelType * begin, const PixelType * end, size_t componentsPerPixel, ofPixelFormat pixelFormat) +inline ofPixels_::ConstPixels::ConstPixels(const PixelType * begin, const PixelType * end, size_t componentsPerPixel, ofPixelFormat _pixelFormat) :_begin(begin) ,_end(end) ,componentsPerPixel(componentsPerPixel) @@ -1372,7 +1372,7 @@ inline typename ofPixels_::ConstPixel ofPixels_::ConstPixe //---------------------------------------------------------------------- template -inline ofPixels_::ConstLine::ConstLine(const PixelType * _begin, size_t stride, size_t componentsPerPixel, size_t lineNum, ofPixelFormat pixelFormat) +inline ofPixels_::ConstLine::ConstLine(const PixelType * _begin, size_t stride, size_t componentsPerPixel, size_t lineNum, ofPixelFormat _pixelFormat) :_begin(_begin) ,_end(_begin+stride) ,stride(stride) @@ -1480,7 +1480,7 @@ inline typename ofPixels_::ConstPixels ofPixels_::ConstLin //---------------------------------------------------------------------- template -inline ofPixels_::ConstLines::ConstLines(const PixelType * _begin, const PixelType * _end, size_t stride, size_t componentsPerPixel, size_t lines, ofPixelFormat pixelFormat) +inline ofPixels_::ConstLines::ConstLines(const PixelType * _begin, const PixelType * _end, size_t stride, size_t componentsPerPixel, size_t lines, ofPixelFormat _pixelFormat) :_begin(_begin) ,_end(_end) ,stride(stride) From 7b54ec9c022dcf7a791cce87c3822bd7d7d9c015 Mon Sep 17 00:00:00 2001 From: Dimitre Date: Tue, 7 May 2024 11:35:50 -0300 Subject: [PATCH 11/13] fix --- addons/ofxUnitTests/src/ofxUnitTests.h | 12 +++++++----- libs/openFrameworks/graphics/ofPixels.cpp | 22 ++++------------------ 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/addons/ofxUnitTests/src/ofxUnitTests.h b/addons/ofxUnitTests/src/ofxUnitTests.h index 4b236babde4..5fc72581b85 100644 --- a/addons/ofxUnitTests/src/ofxUnitTests.h +++ b/addons/ofxUnitTests/src/ofxUnitTests.h @@ -153,15 +153,17 @@ class ofxUnitTestsApp: public ofBaseApp{ bool do_test_eq(T1 t1, T2 t2, const std::string & v1, const std::string & v2, const std::string & testName, const std::string & msg, const std::string & file, int line){ numTestsTotal++; if(t1==t2){ - ofLogNotice() << testName << " passed"; + // ofLogNotice() << testName << " passed"; numTestsPassed++; return true; }else{ ofLogError() << testName << " failed " << msg; - ofLogError() << "test_eq(" << v1 << ", " << v2 << ")"; - ofLogError() << "value1: " << v1 << " is " << ofToString(t1); - ofLogError() << "value2: " << v2 << " is " << ofToString(t2); - ofLogError() << file << ": " << line; + // ofLogError() << "test_eq(" << v1 << ", " << v2 << ")"; + ofLogError() << "expected: " <::pixelBitsFromPixelFormat(ofPixelFormat _pixelFormat { OF_PIXELS_RGB, 3 }, { OF_PIXELS_BGR, 3 }, { OF_PIXELS_RGBA, 4 }, - { OF_PIXELS_RGBA, 4 }, + { OF_PIXELS_BGRA, 4 }, { OF_PIXELS_GRAY, 1 }, { OF_PIXELS_Y, 1 }, { OF_PIXELS_U, 1 }, @@ -798,7 +798,7 @@ size_t ofPixels_::getBytesPerPixel() const{ template size_t ofPixels_::getBitsPerPixel() const{ - return getBitsPerChannel() * getNumChannels(); + return pixelBitsFromPixelFormat(pixelFormat); } template @@ -808,26 +808,12 @@ size_t ofPixels_::getBytesPerChannel() const{ template size_t ofPixels_::getBitsPerChannel() const{ - switch(getPixelFormat()){ - case OF_PIXELS_NV12: - case OF_PIXELS_NV21: - case OF_PIXELS_YV12: - case OF_PIXELS_I420: - return 12; - break; - case OF_PIXELS_YUY2: - case OF_PIXELS_UYVY: - case OF_PIXELS_RGB565: - return 16; - break; - default: - return sizeof(PixelType); - } + return getBytesPerChannel() * 8; } template size_t ofPixels_::getBytesStride() const{ - return getBytesFromPixelFormat(pixelFormat) * width; + return pixelBitsFromPixelFormat(pixelFormat) * width / 8; } template From eaa2b614e11412a5ba3a8692ce5bfff3c917166f Mon Sep 17 00:00:00 2001 From: Dimitre Date: Tue, 7 May 2024 11:43:10 -0300 Subject: [PATCH 12/13] test github actions [group] [endgroup] --- scripts/ci/linuxrpi/install.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/ci/linuxrpi/install.sh b/scripts/ci/linuxrpi/install.sh index f236fd122a7..93ec8f967d1 100755 --- a/scripts/ci/linuxrpi/install.sh +++ b/scripts/ci/linuxrpi/install.sh @@ -25,10 +25,14 @@ ROOT=$( cd "$(dirname "$0")" ; pwd -P ) echo $ROOT cd $ROOT +echo "##[group] Setup Multistrap ${MULTISTRAP_ARCH}" mkdir -p raspbian/etc/apt/apt.conf.d/ echo 'Acquire::AllowInsecureRepositories "true";' | sudo tee raspbian/etc/apt/apt.conf.d/90insecure multistrap -a ${MULTISTRAP_ARCH} -d raspbian -f multistrap.conf +echo "##[endgroup]" if [ ${MULTISTRAP_ARCH} = "armhf" ]; then +echo "##[group] Clone Userland" git clone https://github.com/raspberrypi/userland --depth 1 raspbian/userland +echo "##[endgroup]" fi From f4ff0287ee3adc9b1f994017dc493338ee751b1a Mon Sep 17 00:00:00 2001 From: Dimitre Date: Sat, 11 May 2024 16:03:35 -0300 Subject: [PATCH 13/13] up --- libs/openFrameworks/graphics/ofPixels.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/openFrameworks/graphics/ofPixels.cpp b/libs/openFrameworks/graphics/ofPixels.cpp index f4824c5227d..42a678f8c92 100644 --- a/libs/openFrameworks/graphics/ofPixels.cpp +++ b/libs/openFrameworks/graphics/ofPixels.cpp @@ -1,6 +1,7 @@ #include "ofGraphicsConstants.h" #include "ofPixels.h" #include "ofColor.h" +#include static ofImageType getImageTypeFromChannels(size_t channels){ switch(channels){