Tuesday, December 6, 2011

ReadPixelsFromLevel fails with error...

I've got a problem with certain calls to ReadPixelsFromLevel failing with an error code 'MRAP'. This error is not declared anywhere in the SDK headers. Has anyone seen this before and knows what it means?



The error only happens in one situation: the image must be in 16-bit mode (any color space), and I request a quite small image pyramid level (bounds in the order of 100x100 to 1000x1000 pixels). But although it's a small level, it's not the smallest available, so that is not the trigger either.
ReadPixelsFromLevel fails with error...
MRAP is PARM backwards - this is a byte swap issue.



Re the actual error, I've found the channel op suite to function somewhat

differently in 16 bit mode. Make sure the source rect does not extend

outside the image rectangle.
ReadPixelsFromLevel fails with error...
AH! Well spotted. Thanks, Curvemeister.



Going to hunt this little bugger down now.

This is plain weird. ReadPixelsFromLevel on 16 bit images fails for all levels but level 0. I'm quite certain that PixelMemoryDesc is set correctly, and the bounds I ask for are coming directly from GetDataBounds() for the respective level.



This all works wonderfully in 8bit and 32bit modes. Only 16bit seems to behave badly.



Example:



An image of 640x513 returns for level 1 bounds (0, 0, 320, 257).



ReadPixelsFromLevel is called with these parameters for this case:

PixelMemoryDesc=(rowBits=5120, colBits=16, depth=16, bitOffset=0)

buffer of size 164480 bytes (640 bytes per row)

bounds=(t=0,r=320,b=257,l=0)

level=1



And it returns PARM error. I don't get what I'm doing wrong here.

I found the solution myself. The key is that the image pyramid can even change bit depth for lower levels. Turns out for my 16 bit images, only level 0 had a depth of 16 bit, all others only 8 bit.



Note to self: always call GetDepth() even if you think you know what the depth should be.

No comments:

Post a Comment