AuthorTopic: Photoshop BMP saved not correctly?  (Read 1895 times)

Offline ErikGelfat

  • 0001
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile

Photoshop BMP saved not correctly?

on: September 07, 2019, 01:54:11 pm
So I am making a program for DOS (don't question why), and I am using BMP files to print stuff on the screen, the thing is that the size of the file is very important to me because I am decoding every single byte, that's why I am using BMP.
Now, by default, for an 8 bit BMP, it should have 54 bytes for the header of the file, 256 * 4 bytes for the palette, and the reset is every single byte for every pixel of the picture for example if the picture is 40 by 40, the bytes of the files should be 54 + 256 * 4 + 40 * 40 which will be 2678 bytes.54 + 256 * 4 + 40 * 40

 

BUT for some reason photoshop save these files in two bytes more then they should, I guess they add something in the header, but I can fix it by opening the file in MS paint and saving it again, but the problem is now I have a file which is a 75*176 8 bit BMP file, which is 14,454 bytes, when it should be 14,278, and even MS paint can't fix it, I could copy the image from psd to ms paint and it saves correctly, but then the pallete is not whole which means I have a file which is less than 14,278 bytes.

 

What should I do?

 

 

Thanks, Erik

Offline yrizoud

  • 0010
  • *
  • Posts: 326
  • Karma: +0/-0
    • View Profile

Re: Photoshop BMP saved not correctly?

Reply #1 on: September 09, 2019, 08:50:24 am
I doubt it could be a 56-byte header, there's nothing in the BMP specification that allows it.
Check the 4-byte number at position 10, it indicates where the pixel data starts (from the beginning of the file).
Don't forget that rows need to be rounded up to a multiple of 4 bytes.
What language / libs are you using ? There may be some existing file-loading code that you can use.

edit :
Quote
I have a file which is a 75*176 8 bit BMP file, which is 14,454 bytes
This is the correct size. 75 needs to be rounded up to 76 (multiple of 4)
76*176 + 54 (header) + 1024 (palette) = 14454
« Last Edit: September 09, 2019, 08:56:32 am by yrizoud »