Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ofPixels pixelSize reflection number of pixels instead of bytes #8226

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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: 14 additions & 11 deletions libs/openFrameworks/graphics/ofPixels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,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;

pixels = newPixels;
pixelsOwner = false;
Expand Down Expand Up @@ -513,8 +513,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 = size() * pixelBitsFromPixelFormat(pixelFormat);
//we check if we are already allocated at the right size
if(bAllocated && newSize==oldSize){
pixelFormat = format;
Expand All @@ -530,9 +530,12 @@ void ofPixels_<PixelType>::allocate(size_t w, size_t h, ofPixelFormat format){
width = w;
height = h;

pixelsSize = newSize;
pixelsSize = w * h;

pixels = new PixelType[pixelsSize];
// we have some incongruence here, if we use PixelType
// we are not able to use RGB565 format
pixels = new PixelType[pixelsSize * getNumChannels()];
// pixels = new uint8_t[newSize];
bAllocated = true;
pixelsOwner = true;
}
Expand Down Expand Up @@ -583,11 +586,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
Loading