Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions libs/openFrameworks/graphics/ofPixels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -393,10 +395,10 @@ template<typename PixelType>
void ofPixels_<PixelType>::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;
Expand Down Expand Up @@ -513,8 +515,8 @@ void ofPixels_<PixelType>::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;
Expand All @@ -530,9 +532,12 @@ void ofPixels_<PixelType>::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;
}
Expand Down Expand Up @@ -583,11 +588,11 @@ void ofPixels_<PixelType>::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<typename PixelType>
Expand Down
4 changes: 2 additions & 2 deletions libs/openFrameworks/graphics/ofPixels.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ class ofPixels_ {
void copyFrom( const ofPixels_<SrcType>& 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;
Expand Down
2 changes: 1 addition & 1 deletion scripts/apothecary
Submodule apothecary updated 252 files