Re: Storing/Saving a BMP in ASM



As Mr. Robert's said, you're out of luck it it was a 3 hour deadline.
However, I'll post this in case someone else needs it.

To save a BMP in any language, assuming you have access to the pixel's
values on screen (you can read the bitmap from screen), all you need to do
is to store the bitmap as "scan lines" onto disk with a .BMP header built
into it. Info on how to store the lines and what the header should
include is available on descriptions for the .BMP file format which is
available around on the internet.

I had the same trouble once and looked up some "official" documentation.
It was very cryptic and cumbersome, so I sort of "transcribed" into
layman's terms and put it on the web for anyone to use. Use this link:

http://www.geocities.com/yssmlp

and save the text. That description of the .BMP file format isn't
thorough, but it's a good start.

Once you know just what the header needs all you need to do is follow
these steps:

1- Build onto memory (or disk) a scratch .BMP header
2- Read the RGB values from the video card.
2-a: Use ports 03C7, 03C8, 03C9:
03C7 -> set to 0 [OUT DX,AL] (initial index value to read)
03C8 -> set the same as 03C7 [DX=03C8 AL=0 -> OUT DX,AL]

2-b: then use 03C9 to read three bytes one byte at a
time.
One byte for the RED component, one byte for
the BLUE
and one byte for the GREEN.

3- Repeat 2-b 256 times. Each time you read the three bytes, store them
in an area
you may call the RGB table (actually the B-G-R-0 table). Don't forget
to store
4 bytes for each entry (last byte 0).

4- Next, read the pixel values off the screen (pixel values are COLOR
indexes) and store them in an area you may call the BITMAP. Store them as
scan lines according to what the .BMP format says (I think it's reading
from down upwards, from right to left, 4 byte aligned, don't remember
right now).

5- Finally, fix the numbers in the scratch header you built and save the
data in this order onto disk:

HEADER
RGB TABLE
BITMAP

I think that's pretty much it. Of course, this are very simplified
instructions on how to do it, but it's a start.


Rodrigo wrote:

> Hello guys, i'm new to these forums. I just find the resource. I have
> 3 hours to deliver a project which I haven't finished yet. The purpose
> of the project is to draw with the mouse anything, as you move the
> mouse it paints its trail. this is stopped by pressing the right mouse
> button and start again with the left one. When I press 'L' a BMP file
> is opened, which is 'last.bmp'. What i haven't achieved is SAVING the
> BMP. I mean, I draw whatever and would like to save the screen as
> 'last.bmp' but I haven't figured out how to save!!!!
>
> Please can someone help me out. I just have 3 hours left and I need to
> keep coding. Thanks a lot. Greetings from Mexico.
>
> Rodrigo,
>
> i can be found online right now at messenger. Anyways, i'll have this
> page refreshing in order to see your kind answers, please help me.
>
> igo81@xxxxxxx
> rbifano@xxxxxxxxxxx

.



Relevant Pages

  • Re: BMP
    ... That's definitely not a bmp header. ... about a bitmap after it's loaded. ...  4 | data offset ...
    (comp.graphics.algorithms)
  • Re: BMP pixel array
    ... Is this a .BMP file or a Bitmap data array? ... is it using some kind of compression such as RLE or Bit-fields or is the data uncompressed? ... > files with an Info Header of 40 byte. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: copy image to windows clipboard?
    ... Your assumption about lacks in the Img BMP parser are correct. ... I've implemented the missing 16 and 32 bit format parser ... the offset to the bitmap was the offset to the bitmap header. ...
    (comp.lang.tcl)
  • Re: BMP
    ... now my query is that if this is a complete header for bmp file then ... That's definitely not a bmp header. ... about a bitmap after it's loaded. ... | data offset ...
    (comp.graphics.algorithms)
  • Re: PING > dawzaG
    ... >> happening in the Org header and, would you believe, in the date ... ventilation; avoid extreme temperatures and store in a cool, ... away from open flames, naked flames and old flames; avoid inhaling fumes; ...
    (alt.os.windows-xp)