 |
|
|
|
 |
LIBRARY :
BITMAP.ZIP
Drawing Bitmaps With Assembly Language
Here is some information and examples about drawing
bitmaps with pure assembly language.
Comments about bitmap demo files:
Bmp2 : Draws C:\Par2.bmp 1-bit bitmap with a size of less than 64k using VESA
Bmp4 : Draws C:\Par16.bmp 4-bit bitmap with a size of less than 64k using VESA
Bmp8 : Draws C:\Par256.bmp 8-bit bitmap with a size of less than 64k using VESA
Bmp24: Draws C:\Splash.bmp 24-bit bitmap with a size of less than 64k using VESA
Draw1: Draws any bitmap with a size of less than 64k using VESA
Vga2 : Draws C:\Par2.bmp 1-bit bitmap with a size of less than 64k using VGA
Vga16: Draws C:\Sp16.bmp 4-bit bitmap with a size of less than 64k using VGA
Vga256: Draws C:\Sp257.bmp 8-bit bitmap with a size of less than 64k using VGA
Bmp24x3: Draws a 24-bit bitmap with any size(even MByte bitmaps in real mode)
using VESA
Invert: Inverts colors of C:\Splash.bmp with a size of less than 64k using VESA
Mirror: Mirrors C:\Splash1.bmp with a size of less than 64k using VESA
Rotl : Rotates C:\Par16.bmp left with a size of less than 64k using VESA
RotR : Rotates C:\Par2.bmp right with a size of less than 64k using VESA
UpDown: Turns C:\Par2.bmp upside down with a size of less than 64k using VESA
RepCol: Replaces a color in C:\Splash.bmp (24 bit) with a size of less
than 64k using VESA
ShiftB: Shifts all colors in C:\Splash.bmp (24 bit) to blue with a size of less
than 64k using VESA
ShiftG: Shifts all colors in C:\Splash.bmp (24 bit) to green with a size of less
than 64k using VESA
ShiftR: Shifts all colors in C:\Splash.bmp (24 bit) to red with a size of less
than 64k using VESA
BMP graphic files explained
The BMP file was
originated in 1991 when Microsoft had Windows 3.0 as the latest Windoze
platform. BMP is a Microsoft Device Independent Bitmap file and can
contain images that are 1, 4, 8, or 24 bits/pixel. The 1-, 4- and 8-bit
images have color maps while the 24-bit images are direct color
(RGB).
BMP files store the Lo byte first, i.e. they use Intel
conventions. Each file contains a file header, a bitmap header, a color
map (not in 24-bit) and the image data. Some BMP files can be compressed
using the RLE scheme. (See my description on PCX files for more info on
RLE)
THE HEADER(s):
Offset Size Contents Meaning
---------------------------------------------------------------------
00 02 "BM" Microsofts' BMP ID byte
02 04 varies Size in bytes of the file
06 04 00,00 Reserved
10 04 varies Offset in file where image starts
14 04 40 Size of bitmap header
18 04 varies Width in pixels
22 04 varies Height in pixels
26 02 1 Number of image planes (only one)
28 02 varies Bits per pixel (1,4,8, or 24)
30 04 varies Compression type
34 04 varies Size of compressed image (or zero)
38 04 varies Horizontal Res. in pixels/meter
42 04 varies Vertical Res. in pixels/meter
46 04 varies Number of colors used
50 04 varies Number of 'important' colors
54 04* varies Color Map
* The length of the Color Map is 4 bytes plus the difference to
the end of the bitmap header.
The Color Map sizes are normally 2 ,16, or 256 entries,
but can be smaller if the image does not need a full set of colors. If the
value at offset 46 in the header above is nonzero, it contains the number
of colors used, which is also the number of entries in the color map. If
the entry is zero then the color map is full size.
Please
Note: Because the VGA provides only 64 levels of R,G, and B, the Color
Map values must be divided by four (shr 2 times) when reading the BMP file
for VGA display.
If the display device can not display all the
colors available in the image, then BMP files put the 'important' color
values at the front of the color map for better display.
Color
map entries are four bytes each:
offset Description
---------------------------------
00 Blue value
01 Green value
02 Red value
03 zero (reserved)
The bitmap image follows the color map. If the data
is a 4- or an 8-bit image then it can be compressed using the RLE
compression scheme.
Bits are stored a row at a time. Each row is
padded to a 4-byte boundary with zero bytes. Rows are stored in order
from the bottom of the image to the top.
Monochrome
images (1-bit images): Each pixel is a single bit. The hi-order bit is
the leftmost pixel.
Uncompressed 16 color images (4-bit
images): These images are packed two pixels per byte, with the hi-nibble
being the leftmost pixel.
Compressed 16 color images (4-bit
images): These images are compressed using the RLE encoding scheme and
consist of a sequence of groups. There are 3 kinds of groups: repeating,
literal, and special. A repeating group is 2 bytes, with the
first byte as a pixel count and the second byte is a pair of
pixels. For example: 05h 16h translates to five pixels long of 01h 06h
01h 06h 01h. Notice you don't use the lo-order of the pixels byte if the
count is odd. A literal group is a zero byte, a byte with the
pixel count, and the literal pixels. The pixel count must be at least 3.
The literal pixels are padded out with zeros to an even number of
bytes. For example: 00h 05h 12h 34h 50h 00h translates to 01h 02h 03h
04h 05. A special sequence of 00h 00h represents the end of a
row. The special sequence of 00h 01h represents the end of the bitmap. The
special sequence 00h 02h xx yy represents a position delta, saying to
continue the image xx pixels to the right and yy pixels
down.
Uncompressed 256 color images (8-bit images): These
images are packed one pixel to a byte, with each row padded to a 4 byte
boundary.
Compressed 256 color images (8-bit images): These
images are packed using the RLE encoding scheme, consisting of a sequence
of groups. There are three kinds of groups. (See compressed 4-bit color
scheme above)
24-bits/pixel scheme consist of three bytes
per pixel. The first byte being BLUE, the second GREEN, and the third
being RED. Each row is zero padded to a 4-byte boundary.
If you
have any other questions or see a mistake that I made, please e-mail me
and I will do my best to help out.
All rights reserved Legal
Notice Copyright © 1984-2001 Forever Young Software
; /////////////////////////////////////////////////
; /////////////////////////////////////////////////
; /////////////////////////////////////////////////
; here is binary code of a 1-bit black and white bitmap file
; with width = 9 and height = 3
42 4D ; BM
4A 00 00 00 ; SIZE
00 00 00 00 ; RESERVED
3E 00 00 00 ; OFFSET
28 00 00 00 ; SIZE OF HEADER
09 00 00 00 ; WIDTH IN PIXELS
03 00 00 00 ; HEIGHT IN PIXELS
01 00 ; Number of image planes (only one
01 00 ; Bits per pixel (1,4,8, or 24)
00 00 00 00 ; Compression type
0C 00 00 00 ; Size of compressed image (or zero)
C4 0E 00 00 ; Horizontal Res. in pixels/meter
C4 0E 00 00 ; Vertical Res. in pixels/meter
00 00 00 00 ; Number of colors used
00 00 00 00 ; Number of 'important' colors
; color map starts here
00 00 00 00 ; color zero black
FF FF FF 00 ; color one white
; DATA SECTION STARTS HERE FROM BOTTOM UP
; ONE BIT FOR EACH PIXEL
01 00 00 00 ; row 3 00000001 00000000 00000000 00000000
05 00 00 00 ; row 2 00000101 00000000 00000000 00000000
15 00 00 00 ; row 1 00010101 00000000 00000000 00000000
ROWS IN DATA SECTION ARE ZERO PADDED TO THE NEAREST 4-BYTE VALUE
WIDTH = 9 , THEN 9*(1/8) MEANS 1+ BYTES,PADDED TO 4 BYTES FOR EACH ROW
IF WIDTH = 33,THEN 33*(1/8) MEANS 4+ BYTES,PADDED TO 8 BYTES
IF WIDTH = 65,THEN 65*(1/8) MEANS 8+ BYTES,PADDED TO 12 BYTES AND SO ON...
THIS IS VALID FOR 1-BIT BITMAPS
ROW FORMAT :
1 2 3 4 5 6 7 8 9 ; ROW 1 IN BITMAP
10 11 12 13 14 15 16 17 18 ; ROW 2 IN BITMAP
19 20 21 22 23 24 25 26 27 ; ROW 3 IN BITMAP
ROW FORMAT IN DATA SECTION :
0 0 0 1 0 1 0 1 0 ; ROW 3 IN BITMAP
0 0 0 0 0 1 0 1 0 ; ROW 2 IN BITMAP
0 0 0 0 0 0 0 1 0 ; ROW 1 IN BITMAP
0 AND 1 SHOW INDEX OF THE COLOR IN THE COLOR MAP NOT THE COLOR ITSELF
0 MEANS COLOR ZERO= 00 00 00 00 IN COLOR MAP
1 MEANS COLOR ONE = FF FF FF 00 IN COLOR MAP
; /////////////////////////////////////////////////
; /////////////////////////////////////////////////
; /////////////////////////////////////////////////
; HERE IS A BINARY CODE OF A 4-BIT 16-COLOR BITMAP FILE
; WITH WIDTH=9 AND HEIGHT=3
42 4D ; BM
8E 00 00 00 ; SIZE
00 00 00 00 ; RESERVED
76 00 00 00 ; OFFSET
28 00 00 00 ; SIZE OF HEADER
09 00 00 00 ; WIDTH IN PIXELS
03 00 00 00 ; HEIGHT IN PIXELS
01 00 ; Number of image planes (only one)
04 00 ; Bits per pixel (1,4,8, or 24)
00 00 00 00 ; Compression type
18 00 00 00 ; Size of compressed image (or zero)
C4 0E 00 00 ; Horizontal Res. in pixels/meter
C4 0E 00 00 ; Vertical Res. in pixels/meter
00 00 00 00 ; Number of colors used
00 00 00 00 ; Number of 'important' colors
; color map starts here 16 COLORS IN TOTAL
00 00 00 00
FF FF FF 00
00 00 01 00
00 00 00 00
00 00 EF 00
FC 83 6F 00
00 00 E0 00
56 00 26 00
F7 BF 00 00
00 00 78 00
40 00 0C 00
F9 BF B8 00
F7 BF 1C 00
00 00 E4 00
56 00 6D 00
F7 BF EF 00
; DATA SECTION STARTS HERE FROM BOTTOM UP
; HALF BYTE FOR EACH PIXEL
11 11 11 11 10 00 00 00 ; ROW 3
0001 0001 0001 0001 0001 0001 0001 0001 0001 0000
; 0000 0000 0000 0000 0000 0000
77 77 77 77 70 00 00 00 ; ROW 2
0111 0111 0111 0111 0111 0111 0111 0111 0111 0000
; 0000 0000 0000 0000 0000 0000
44 44 44 44 40 00 00 00 ; ROW 1
0100 0100 0100 0100 0100 0100 0100 0100 0100 0000
; 0000 0000 0000 0000 0000 0000
ROWS IN DATA SECTION ARE ZERO PADDED TO THE NEAREST 4-BYTE VALUE
WIDTH = 9 , THEN 9*(4/8) MEANS 4+ BYTES,PADDED TO 8 BYTES FOR EACH ROW
IF WIDTH = 23,THEN 23*(4/8) MEANS 11+ BYTES,PADDED TO 12 BYTES
IF WIDTH = 45,THEN 45*(4/8) MEANS 22+ BYTES,PADDED TO 24 BYTES AND SO ON...
THIS IS VALID FOR 4-BIT BITMAPS
ROW FORMAT :
1 2 3 4 5 6 7 8 9 ; ROW 1 IN BITMAP
10 11 12 13 14 15 16 17 18 ; ROW 2 IN BITMAP
19 20 21 22 23 24 25 26 27 ; ROW 3 IN BITMAP
ROW FORMAT IN DATA SECTION :
0001 0001 0001 0001 0001 0001 0001 0001 0001 ; ROW 3 IN BITMAP
0111 0111 0111 0111 0111 0111 0111 0111 0111 ; ROW 2 IN BITMAP
0100 0100 0100 0100 0100 0100 0100 0100 0100 ; ROW 1 IN BITMAP
0 AND 1 SHOW INDEX OF THE COLOR IN THE COLOR MAP NOT THE COLOR ITSELF
0 MEANS COLOR ZERO= 00 00 00 00 IN COLOR MAP
1 MEANS COLOR ONE = FF FF FF 00 IN COLOR MAP
2 MEANS COLOR TWO = 00 00 01 00 IN COLOR MAP
3 MEANS COLOR THREE = 00 00 EF 00 IN COLOR MAP
; /////////////////////////////////////////////////
; /////////////////////////////////////////////////
; /////////////////////////////////////////////////
; here is binary code of a 8-bit 256 COLOR bitmap file
; with width = 9 and height = 3
42 4D ; BM
5A 04 00 00 ; SIZE
00 00 00 00 ; RESERVED
36 04 00 00 ; OFFSET
28 00 00 00 ; SIZE OF HEADER
09 00 00 00 ; WIDTH IN PIXELS
03 00 00 00 ; HEIGHT IN PIXELS
01 00 ; Number of image planes (only one)
08 00 ; Bits per pixel (1,4,8, or 24)
00 00 00 00 ; Compression type
24 00 00 00 ; Size of compressed image (or zero)
C4 0E 00 00 ; Horizontal Res. in pixels/meter
C4 0E 00 00 ; Vertical Res. in pixels/meter
00 00 00 00 ; Number of colors used
00 00 00 00 ; Number of 'important' colors
; color map starts here 256 COLORS and
; 1024 BYTES IN TOTAL
00 00 00 00
FF FF FF 00
00 00 00 00
00 00 00 00
00 EF 00 FC
83 6F 00 00
00 E0 00 56
00 26 00 F7 BF 00 00 00 00 78 00 40 00
0C 00 F9 BF B8 00 F7 BF 1C 00 00 00 E4 00 56 00
6D 00 F7 BF EF 00 FC 83 00 00 00 00 FC 83 47 35
00 00 00 00 46 02 00 00 5A 84 02 00 AA 3C 00 00
D7 16 00 00 37 27 57 01 00 00 47 35 37 27 57 01
60 84 76 3D F7 16 04 00 00 00 00 00 00 00 96 19
40 5F 00 00 00 00 01 00 00 00 0A 00 00 00 76 3D
10 00 00 00 00 00 00 00 4C 84 64 7A FF FF 47 35
60 84 BD 3D F7 16 FF FF 47 35 00 00 00 00 47 35
6F 01 2C 6A 9C 84 00 00 03 00 96 19 40 5F 9D 9E
CF 17 00 00 00 00 00 00 01 00 0A 00 CC 05 6F 01
00 00 08 00 00 00 D7 16 FC 60 A5 97 CF 17 6F 01
BF 0F 00 00 6F 01 00 00 C5 B9 F7 BF 00 0C 93 81
78 00 4D 5F 03 21 40 5F 88 00 4D 5F 40 00 00 00
03 00 00 00 AC F8 56 00 AC F8 56 00 78 00 4D 5F
A8 F4 56 00 04 F5 56 00 33 2D 49 5F AC F6 56 00
AC F6 56 00 EC F4 56 00 E3 3E 49 5F 00 00 00 00
F8 F4 56 00 67 18 40 5F AC F6 56 00 AC F6 56 00
08 F5 56 00 B5 2D 49 5F FF FF FF FF 14 F5 56 00
07 5D 40 5F 01 00 00 00 AC F6 56 00 E4 F8 56 00
C5 37 49 5F FF FF FF FF F0 F8 56 00 B8 EC 01 01
38 CE 03 01 C0 0A 69 00 00 00 00 00 41 64 73 FD
7A 00 56 00 17 23 F7 BF 00 00 00 00 02 00 00 00
80 31 48 4B 88 85 5F 34 F7 3F F7 16 5C 06 00 00
00 02 00 00 00 00 00 00 13 00 45 00 19 A3 14 00
98 F8 56 00 6D 18 F7 BF C7 0F 00 00 00 00 02 00
82 3C F5 BF 82 3C F5 BF 00 00 C2 06 C2 06 00 02
CA 85 16 40 13 00 45 00 00 00 00 00 00 02 5C 06
5C 06 00 00 00 02 00 00 00 00 00 00 13 00 45 00
19 A3 14 00 4E 00 00 00 71 00 82 3C F5 BF 00 00
71 00 B6 85 64 7A FF FF 5F 34 CA 85 F7 3E F7 16
FF FF 5F 34 00 00 00 00 5F 34 0A 81 4A 20 F0 85
0D 00 03 00 E7 15 00 60 2A 6D CF 17 28 86 5F 34
02 00 00 00 D7 16 80 31 0A 81 02 00 4A 20 02 00
CF 0F 00 00 08 86 1C 0C CF 17 28 86 5F 34 02 00
00 00 00 00 34 1E D7 16 00 00 CF 0F 54 86 7E 9E
AF 17 00 00 01 00 02 00 00 00 00 02 00 02 00 00
00 00 28 86 5F 34 2C 6A 64 1E 68 00 5C 06 00 02
50 6F 72 74 61 62 6C 65 20 4E 65 74 77 6F 72 6B
20 47 72 61 70 68 69 63 73 00 61 74 00 00 34 1E
64 1E 5C 86 5C 86 3C AA 00 00 2C 6A 00 00 CF 0F
4A 87 7E 49 C7 17 01 00 12 01 00 00 0C 00 68 00
64 1E 0C 00 68 00 12 00 00 00 00 00 60 BF A8 86
39 4D 7E 07 00 00 7E 07 02 00 02 00 9E 86 3A 64
7E 07 26 02 DA F3 4D 4F BF 05 00 00 44 01 02 00
BF 05 AE 86 22 10 00 00 C8 02 00 00 00 00 DA F3
68 BA 49 5F 01 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 BF 05 DC 87 BF 15 87 05 57 00 00 00
BF 05 1A FC 6F 01 00 00 00 00 00 00 1C 94 55 80
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
05 70 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 A0 11 00 00 B8 11
00 00 1C 87 DF 7F 47 01 E2 7F B8 11 01 00 5F 01
5E 87 E9 4A 47 01 64 13 5F 01 A0 11 00 00 B8 11
00 00 5E 87 56 00 46 87 56 00 00 00 00 00 01 00
51 80 01 00 00 00 B8 11 00 00 67 02 5F 01 F7 00
00 00 A0 9A 5E 87 5C 87 00 00 0C 00 00 00 BC 11
9C F7 56 00 5C D4 0E 00 54 27 59 00 54 04 00 00
A0 A3 F7 BF 00 00 8E 09 5A 00 E6 8C 00 00 00 00
92 87 3A 64 8E 09 26 02 46 E9 4D 4F A7 11 01 00
8A E8 00 00 BF 05 A8 87 48 8C 4F 04 8E 09 00 00
56 20 CA 8B E2 9C
E6 8C E6 8C
BF 05 E4 87
99 13 5F 04
9A 07 36 1B
; DATA SECTION STARTS HERE FROM BOTTOM UP
; ONE BYTE FOR EACH PIXEL
01 01 01 01 01 01 01 01 01 00 00 00 ; ROW 3
07 07 07 07 07 07 07 07 07 00 00 00 ; ROW 2
04 04 04 04 04 04 04 04 04 00 00 00 ; ROW 1
ROWS IN DATA SECTION ARE ZERO PADDED TO THE NEAREST 4-BYTE VALUE
WIDTH = 9 , THEN 9*(8/8) MEANS 9 BYTES,PADDED TO 12 BYTES FOR EACH ROW
IF WIDTH = 23,THEN 23*(8/8) MEANS 23 BYTES,PADDED TO 24 BYTES
IF WIDTH = 45,THEN 45*(8/8) MEANS 45 BYTES,PADDED TO 48 BYTES AND SO ON...
THIS IS VALID FOR 8-BIT BITMAPS
ROW FORMAT :
1 2 3 4 5 6 7 8 9 ; ROW 1 IN BITMAP
10 11 12 13 14 15 16 17 18 ; ROW 2 IN BITMAP
19 20 21 22 23 24 25 26 27 ; ROW 3 IN BITMAP
ROW FORMAT IN DATA SECTION :
1 1 1 1 1 1 1 1 1 ; ROW 3 IN BITMAP
7 7 7 7 7 7 7 7 7 ; ROW 2 IN BITMAP
4 4 4 4 4 4 4 4 4 ; ROW 1 IN BITMAP
0 AND 1 SHOW INDEX OF THE COLOR IN THE COLOR MAP NOT THE COLOR ITSELF
0 MEANS COLOR ZERO= 00 00 00 00 IN COLOR MAP
1 MEANS COLOR ONE = FF FF FF 00 IN COLOR MAP
2 MEANS COLOR TWO = 00 00 00 00 IN COLOR MAP
3 MEANS COLOR THREE = 00 00 00 00 IN COLOR MAP
; /////////////////////////////////////////////////
; /////////////////////////////////////////////////
; /////////////////////////////////////////////////
; here is binary code of a 24-bit bitmap file
; with width = 9 and height = 3
42 4D ; BM
8A 00 00 00 ; SIZE
00 00 00 00 ; RESERVED
36 00 00 00 ; OFFSET
28 00 00 00 ; SIZE OF HEADER
09 00 00 00 ; WIDTH IN PIXELS
03 00 00 00 ; HEIGHT IN PIXELS
01 00 ; Number of image planes (only one)
18 00 ; Bits per pixel (1,4,8, or 24)
00 00 00 00 ; Compression type
54 00 00 00 ; Size of compressed image (or zero)
C4 0E 00 00 ; Horizontal Res. in pixels/meter
C4 0E 00 00 ; Vertical Res. in pixels/meter
00 00 00 00 ; Number of colors used
00 00 00 00 ; Number of 'important' colors
; NO COLOR MAP IN 24 BIT BITMAPS
; DATA SECTION STARTS IMMEDIATELY AFTER HEADER
; THREE BYTES FOR EACH PIXEL
FF FF FF - FF FF FF - FF FF FF - FF FF FF - FF FF FF - FF FF FF
- FF FF FF - FF FF FF - FF FF FF - 00 ; ROW 3
56 00 26 - 56 00 26 - 56 00 26 - 56 00 26 - 56 00 26 - 56 00 26
- 56 00 26 - 56 00 26 - 56 00 26 - 00 ; ROW 2
00 00 EF - 00 00 EF - 00 00 EF - 00 00 EF - 00 00 EF - 00 00 EF
- 00 00 EF - 00 00 EF - 00 00 EF - 00 ; ROW 1
ROWS IN DATA SECTION ARE ZERO PADDED TO THE NEAREST 4-BYTE VALUE
WIDTH = 9 , THEN 9*(24/8) MEANS 27 BYTES,PADDED TO 28 BYTES FOR EACH ROW
IF WIDTH = 23,THEN 23*(24/8) MEANS 69 BYTES,PADDED TO 72 BYTES
IF WIDTH = 45,THEN 45*(24/8) MEANS 135 BYTES,PADDED TO 136 BYTES AND SO ON...
THIS IS VALID FOR 24-BIT BITMAPS
ROW FORMAT :
1 2 3 4 5 6 7 8 9 ; ROW 1 IN BITMAP
10 11 12 13 14 15 16 17 18 ; ROW 2 IN BITMAP
19 20 21 22 23 24 25 26 27 ; ROW 3 IN BITMAP
ROW FORMAT IN DATA SECTION :
FF FF FF - FF FF FF - FF FF FF - FF FF FF - FF FF FF - FF FF FF
- FF FF FF - FF FF FF - FF FF FF ; ROW 3 IN BITMAP
56 00 26 - 56 00 26 - 56 00 26 - 56 00 26 - 56 00 26 - 56 00 26
- 56 00 26 - 56 00 26 - 56 00 26 ; ROW 2 IN BITMAP
00 00 EF - 00 00 EF - 00 00 EF - 00 00 EF - 00 00 EF - 00 00 EF
- 00 00 EF - 00 00 EF - 00 00 EF ; ROW 11 IN BITMAP
|
 | | |
|