News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Bitmap file modification

Started by HSE, December 20, 2023, 05:20:56 AM

Previous topic - Next topic

HSE

Hi all!

Somebody know how to change one color for another inside a 24 bits Bitmap.

I have a little problem to understand pixel array  :biggrin:

Test is after an AW27 code.

Thanks in advance, HSE
Equations in Assembly: SmplMath

NoCforMe

Sure. The things you need to know about how bitmaps are formatted are these:

  • All lines of bitmap data must align to a 32-bit boundary, so there might be padding (zeros) on each line
  • 24-bit bitmap data is just that: each pixel is 3 bytes, plus whatever padding is needed to bring the line to a 32-bit boundary. The pixel data is packed (no padding between pixels).

A 24-bit bitmap will have no palette, so you don't need to mess what that.

In your case, since your bitmap is 10x10, each line is 30 bytes of data, so there are 2 bytes of padding on each line. As they say, I leave it as "an exercise for the reader" to determine programmatically how much padding, if any, there is.

To change a color in a bitmap, locate the bitmap array, cruise through it line-by-line, looking at each pixel (3 bytes) and replacing them as you wish. Be sure to take the padding into account. Probably the easiest way is to calculate the "stride", which is the actual distance from the beginning of one line to the beginning of the next line.

Is this enough to get you started? I've been playing with bitmaps quite a bit recently, so may be able to help you further.
Assembly language programming should be fun. That's why I do it.

HSE

Thanks, NoC!

Quote from: NoCforMe on December 20, 2023, 07:15:53 AMAll lines of bitmap data must align to a 32-bit boundary, so there might be padding (zeros) on each line

That was the strange thing  :thumbsup:

Equations in Assembly: SmplMath