-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
ofPixels memory allocation size fix #8226
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
Conversation
|
This one will need tests updated because pixelSize represented a different thing in the past. |
|
Don't we want a simple revert of: Looking at this PR I am not sure if it's actually reverting and might be changing behavior even more. I'll note in the lines what I mean. |
| height = h; | ||
|
|
||
| pixelsSize = bytesFromPixelFormat(w,h,_pixelFormat); | ||
| pixelsSize = w * h; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pixels size used to be:
pixelsSize = bytesFromPixelFormat(w,h,_pixelFormat) / sizeof(PixelType);
bytesFromPixelFormat is effectively: w * h * 24 / 8 ( for RGB )
so: newSize = w * h * 3; for RGB
size_t ofPixels_<PixelType>::bytesFromPixelFormat(size_t w, size_t h, ofPixelFormat format){
return w * h * pixelBitsFromPixelFormat(format) / 8; <-- pixelBitsFromPixelFormat for rgb is 24
}
a simpler fix would be:
pixelsSize = w*h * getNumChannels()
But maybe safer to first revert the commit where the regression was introduced and then do a PR with the bit depth support after?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of the problem (historical ofPixels problem) is we have two different units
one is PixelType (it can be char, float, etc)
and the other are formats that doesn't have an uniform number of bytes per channel like RGB565 (5 + 6 + 5 total 16 bits) or NV12 (12 bits per channel)
but the array that stores pixel information will be always a PixelType (so we consider an "uncompressed" pixel type, to be worked on shaders).
we can go one way or another.
if we support all the images format I suggest changing the Pixels array to uint8_t instead of PixelType and allocate everything following "bytesPerPixel"
Or keep everything as it is, and comment out all image types that doesn't follow PixelType bit depth.
makes sense?
| height = h; | ||
|
|
||
| pixelsSize = newSize; | ||
| pixelsSize = w * h; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again good to note that pixelsSize is not w*h but w*h * getNumChannels();
pixelsSize is what ofPixels::size() returns and if you look here, it needs to represent the total number of bytes not just w*h.
void ofPixels_<PixelType>::copyFrom(const ofPixels_<SrcType> & mom){
if(mom.isAllocated()){
allocate(mom.getWidth(),mom.getHeight(),mom.getNumChannels());
const float srcMax = ( (sizeof(SrcType) == sizeof(float) ) ? 1.f : std::numeric_limits<SrcType>::max() );
const float dstMax = ( (sizeof(PixelType) == sizeof(float) ) ? 1.f : std::numeric_limits<PixelType>::max() );
const float factor = dstMax / srcMax;
if(sizeof(SrcType) == sizeof(float)) {
// coming from float we need a special case to clamp the values
for(size_t i = 0; i < mom.size(); i++){
pixels[i] = ofClamp(mom[i], 0, 1) * factor;
}
} else{
// everything else is a straight scaling
for(size_t i = 0; i < mom.size(); i++){
pixels[i] = mom[i] * factor;
}
}
```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose we gave more thought and try to solve incongruences that always existed in ofPixels instead of reverting last PR. When you say the total number of bytes it is not true, it is the total number of channels, each of them can be one byte (as it always supported) or more.
I'll take a look soon at this PR. so size() is back to original behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look again and see the difference. it is now not based in bytes for pixels allocation.
|
I reverted size to the behavior it always was, and changed the PR title. |
|
Awesome thanks @dimitre ! |
* commit '5630d2034d835e81225a225355e97f4144b21179': (446 commits) Restore target build dir behavior for Xcode. Closes #8321 (#8340) of script updates (#8339) _OBJC_CLASS_$_AVFoundationVideoPlayer fix (#8337) poco mk (#8336) relative locations rabbit (#8335) fix(ofParameter): better default init() handling of non-comparable/non-copyable objects and containers (#8325) path to string conversion on Windows fix. (#8333) iOS template add ofxiOS group ref (#8330) Xcode iOS Target Project Fixes (#8328) chore(iOS): remove iosNativeARCExample (#8324) ofxGui fix for apple targets (#8320) assimp ios addon_config (#8319) chore(iOS): remove GLKit example (#8317) fix(iOS): adjustments to layout of Location example + deprecations updates (#8311) fix(iOS): update to CoreLocation authorization request (#8309) remove boost from android. (#8307) Remove boost from linux scripts, download_libs (#8306) ofPixels memory allocation size fix (#8226) remove boost references from CoreOF.xcconfig and config.*.default.mk for macOS and osx. (#8304) Fix to json scripts (#8301) ... # Conflicts: # .gitignore # libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp # libs/openFrameworks/gl/ofGLUtils.h # libs/openFrameworks/gl/ofShader.cpp # libs/openFrameworks/gl/ofTexture.h # libs/openFrameworks/graphics/ofTrueTypeFont.cpp # libs/openFrameworks/graphics/ofTrueTypeFont.h # libs/openFrameworks/sound/ofAVEngineSoundPlayer.h # libs/openFrameworks/sound/ofSoundBaseTypes.cpp # libs/openFrameworks/sound/ofSoundBaseTypes.h # libs/openFrameworks/sound/ofSoundStream.cpp # libs/openFrameworks/utils/ofConstants.h # libs/openFrameworks/utils/ofThread.h # libs/openFrameworks/utils/ofURLFileLoader.cpp # libs/openFrameworks/utils/ofUtils.h # libs/openFrameworks/utils/ofXml.h # libs/openFrameworksCompiled/project/android/build.gradle # libs/openFrameworksCompiled/project/android/common-functions.gradle
This one will need the tests updated to reflect what pixelSize represents now.
closes #8225