Re: Storing/Saving a BMP in ASM
- From: CII <spamtrap@xxxxxxxxxx>
- Date: Mon, 25 Apr 2005 00:00:34 +0000 (UTC)
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
.
- Follow-Ups:
- Re: Storing/Saving a BMP in ASM
- From: Markus Humm
- Re: Storing/Saving a BMP in ASM
- References:
- Storing/Saving a BMP in ASM
- From: Rodrigo
- Storing/Saving a BMP in ASM
- Prev by Date: Re: Integrate Assembler-Code into C?
- Next by Date: Re: Address wraparound on newer processors
- Previous by thread: Re: Storing/Saving a BMP in ASM
- Next by thread: Re: Storing/Saving a BMP in ASM
- Index(es):
Relevant Pages
|