Why image bits are ouf of range?

Started by
1 comment, last by KonstantinGorskov 12 years, 9 months ago
With FreeImage.NET library, I can read EXR 32bit/c file.

And get pointer to image bits.


IntPtr input = FreeImage.GetBits(dib);
byte* ptr = (byte*)input.ToPointer();


What is want to do next, is reconstruct first channel value and store it as float;



for (int i2 = 0; i2 < _width; i2++)
{
for (int k = 0; k < _height; k++)
{
byte[] nn = new byte[4];
nn[0] = ptr[(pix * 32)];
nn[1] = ptr[(pix * 32)+ 1];
nn[2] = ptr[(pix * 32)+ 2];
nn[3] = ptr[(pix * 32)+ 3];
float depth = BitConverter.ToInt32(nn,0);


But using this loop, I get out of bit range.

Why?

If channel has 32 bits, I can safely loop through all bits within _width*_height_*32 range?
Pixel bit0per0channel is 96.

Where I might be wrong?
Advertisement

With FreeImage.NET library, I can read EXR 32bit/c file.

And get pointer to image bits.


IntPtr input = FreeImage.GetBits(dib);
byte* ptr = (byte*)input.ToPointer();


What is want to do next, is reconstruct first channel value and store it as float;



for (int i2 = 0; i2 < _width; i2++)
{
for (int k = 0; k < _height; k++)
{
byte[] nn = new byte[4];
nn[0] = ptr[(pix * 32)];
nn[1] = ptr[(pix * 32)+ 1];
nn[2] = ptr[(pix * 32)+ 2];
nn[3] = ptr[(pix * 32)+ 3];
float depth = BitConverter.ToInt32(nn,0);


But using this loop, I get out of bit range.

Why?

If channel has 32 bits, I can safely loop through all bits within _width*_height_*32 range?
Pixel bit0per0channel is 96.

Where I might be wrong?


32 bits = 4 bytes

replace pix * 32 with pix * 4; (assuming pix is (k*width+i2) )
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
Oh... thank you! Pretty stupid of me to confuse that.

This topic is closed to new replies.

Advertisement