1

Well, I'm a newbie in C++, and it's been two days since I'm looking for examples, explanations, I try different libraries, but I can not do it, so I just ask for help.

I have a picture in .bmp, I know the height and length, I would like to use in my program as a 2D array.

So I found this code, but it does not work. The problem is that my image is 64 bpp, although visually monochrome.

I have read the documentation, but I do not understand, due to my poor skills in C++ and everything related to the low-level programming.

Do you think it is possible to adapt the previous code for bmp image of 64 bits per pixel?

Community
  • 1
  • 1

1 Answers1

1

To my knowledge the bitmap file format does not support 64 bits per component. I'm not aware of any file format that allows such a format (Though id be surprised if one did not exist).

I find it hard to understand why you would need such a VAST range for an image format component.

Edit: Given your comment then yes it is absoloutely possible to adapt that code. Though its worth noting that 0..63 (64 colour levels) is 6-bit. I assume 2 bits are wasted, though.

Its quite simple if it is grayscale and the component is 8bpp. Basically the storage you need is width * height bytes.

char* pBitmap = malloc( bmp.width * bmp.height );

You can then fread the pixels directly into the char buffer above with a single width * height read.

Edit 2:

Ok for 16 bit per component with 4 components you need a struct like this:

struct Pixel16RGBA
{
    unsigned short r;
    unsigned short g;
    unsigned short b;
    unsigned short a;
};

and then you'd allocate as follows:

Pixel16RGBA* pBitmap = (Pixel16RGBA)malloc( bmp.width * bmp.height * 4 * sizeof( unsigned short ) );

You would then fread the whole image in, as before, using the size calcluated in the malloc above.

Goz
  • 61,365
  • 24
  • 124
  • 204
  • You point the finger at something that I must have misunderstood. Because I think I was mistaken. My image has a color depth of 64, that means she is 64/8 = 8 bits per pixel, 8 bpp and not 64 as I said, is not it? – user2772576 Sep 12 '13 at 12:51
  • In fact, the color depth IS the number of bits per pixel. It is therefore a 64 bpp image that I try to open. According to research, there are four channels of 65,536 shades of color. But the documentation on this subject is not abundant. – user2772576 Sep 12 '13 at 22:08
  • @user2772576: 65536 shades is 2^16 and hence 16-bit per channel ... so yes its a 64bpp image but its 16-bit per pixel. As its grayscale, though, you could easily store it as 1 16-bit channel. – Goz Sep 13 '13 at 08:22
  • oops I mean 16-bit per component not pixel – Goz Sep 13 '13 at 15:01