0

I am using the MiniLibX for a Raytracer school project. I want to take snapshots of my Raytracer and store them into ".bmp" bitmap files.

I am following a very useful guide i found on the net : http://ricardolovelace.com/creating-bitmap-images-with-c-on-windows.html

Everything seems to work fine except for the offset setting.

If I put it to 0 in the header, the first 18 pixels of the image are random, and I get a stripe from the right side on the left (18 pxl wide). If i put an offset at 54 bytes (the correct amount of byte that should be offset), the file is corrupt (no software will open it).

here's an example (see the shadow one the left): raytracer example with unwanted strip on the left

So I found another resource to help me print the actual header that was recorded in the file and check for errors (see at https://gist.github.com/j-marjanovic/5319384ad6606d6fd6d6). I find that if I set the offset to 1, the bitmap records an offset of 65536, when i set it to 54 it gives me 65536 * 54.

I am lost on what could change drastically the offset I write to such a huge value, and curious to know how bitmaps are read by the different softwares. I have read many topics on stack overflow and throughout the web, but could not find this exact problem. This posts resembles it, but the source of the problem seems different to me (i can't relate with my issue): Directshow & .Net - Bitmap shows stripe from right on left side of image?

My only guess is it could be related to the color table, but I'm not sure I understand when this is neccesary.

Anyway, if you want a look at my code i'll upload it, and thank you for any leads you may have on that issue !

  • In this code sample offset_bits should be `sizeof(bitmap_file_header) + sizeof(bitmap_image_header)`. If color palette is used, offset_bits should include also palette size. – Alex F Jun 25 '18 at 13:21
  • Some programs are able to open .bmp file with invalid offset_bits. However, this means that they parse .bmp format incorrectly, probably ignoring palette data. Look at this code, it shows both cases: with and without color palette: https://gist.github.com/thinkhy/783914/3beb1451604cc26b478989e8a946491d787ce26e – Alex F Jun 25 '18 at 13:23
  • Thank you for the reference, i'll look into it! For the offset, even though I tried to give the offset that value (size of (file header + image header)), it seems my function writes something else instead ... – Jonathan strayer Jun 25 '18 at 16:14

0 Answers0