1 ;-----------------------------------------------------------------------
\r
4 ; Bitmap conversion / manipulation tools
\r
10 ; ****** XLIB - Mode X graphics library ****************
\r
11 ; ****** ****************
\r
12 ; ****** Written By Themie Gouthas ****************
\r
14 ; egg@dstos3.dsto.gov.au
\r
15 ; teg@bart.dsto.gov.au
\r
16 ;-----------------------------------------------------------------------
\r
19 This module implements a set of functions to manipulate both planar
\r
20 bitmaps and linear bitmaps (as used by x_compile_bitmap):
\r
24 Planar bitmaps as used by these functions have the following structure:
\r
26 BYTE 0 The bitmap width in bytes (4 pixel groups) range 1..255
\r
27 BYTE 1 The bitmap height in rows range 1..255
\r
28 BYTE 2..n1 The plane 0 pixels width*height bytes
\r
29 BYTE n1..n2 The plane 1 pixels width*height bytes
\r
30 BYTE n2..n3 The plane 2 pixels width*height bytes
\r
31 BYTE n3..n4 The plane 3 pixels width*height bytes
\r
35 Linear bitmaps have the following structure:
\r
37 BYTE 0 The bitmap width in pixels range 1..255
\r
38 BYTE 1 The bitmap height in rows range 1..255
\r
39 BYTE 2..n The width*height bytes of the bitmap
\r
49 include xbmtools.inc
\r
55 ;-----------------------------------------------------------------------
\r
58 ; This function converts a bitmap in the planar format to the linear format
\r
59 ; as used by x_compile_bitmap.
\r
61 ; WARNING: the source and destination bitmaps must be pre - allocated
\r
63 ; NOTE: This function can only convert planar bitmaps that are suitable.
\r
64 ; If the source planar bitmap's width (per plane) is >= 256/4
\r
65 ; it cannot be converted. In this situation an error code
\r
66 ; BM_WIDTH_ERROR. On successful conversion 0 is returned.
\r
69 ; int x_pbm_to_bm(char far * source_pbm, char far * dest_bm);
\r
71 ; Written By Themie Gouthas
\r
74 ARG src_pbm:dword,dest_bm:dword
\r
75 push bp ; Preserve caller's stack frame
\r
81 les di,[dest_bm] ; es:di -> destination bitmap
\r
82 lds si,[src_pbm] ; ds:si -> source planar bitmap
\r
83 lodsb ; load AL with source pbm pixel width per plane
\r
84 mov bl,al ; save in CL
\r
85 xor ah,ah ; convert to word
\r
86 shl ax,2 ; mult by 4 giving source image width
\r
87 cmp ax,255 ; if the result > 255 then we have exceeded
\r
88 ja @@WidthError ; the max width of linear bm.
\r
90 stosb ; write do dest_bm
\r
92 lodsb ; tranfer source pbm height in pixels to
\r
95 xor ah,ah ; convert to word
\r
96 mul bl ; AX = AX * BL ie. total no. pixels per plane
\r
97 mov dx,di ; save DI, the pointer to the destination bm
\r
98 mov bl,3 ; set plane loop counter (BL)
\r
101 mov cx,ax ; set CX to total number of pixels per plane
\r
104 movsb ; transfer pixel
\r
105 add di,3 ; increment destination to compensate for plane
\r
108 inc dx ; increment original di for next pixel plane
\r
109 mov di,dx ; and restore di from incremented original
\r
110 dec bl ; decrement plane counter
\r
111 jns @@PlaneLoop ; loop if more planes left
\r
121 pop bp ;restore caller's stack frame
\r
126 ;-----------------------------------------------------------------------
\r
129 ; This function converts a bitmap in the linear format as used by
\r
130 ; x_compile_bitmap to the planar formap.
\r
132 ; WARNING: the source and destination bitmaps must be pre - allocated
\r
134 ; NOTE: This function can only convert linear bitmaps that are suitable.
\r
135 ; If the source linear bitmap's width is not a multiple of 4
\r
136 ; it cannot be converted. In this situation an error code
\r
137 ; BM_WIDTH_ERROR. On successful conversion 0 is returned.
\r
141 ; int x_bm_to_pbm(char far * source_pbm, char far * dest_bm);
\r
143 ; Written By Themie Gouthas
\r
146 ARG src_bm:dword,dest_pbm:dword
\r
147 push bp ; Preserve caller's stack frame
\r
153 les di,[dest_pbm] ; es:di -> destination planar bitmap
\r
154 lds si,[src_bm] ; ds:si -> source bitmap
\r
155 lodsb ; load AX with source bitmap width
\r
156 test al,03h ; Check that width is a multiple of 4
\r
157 jnz @@WidthIncompatible
\r
158 shr al,2 ; divide by 4 giving width of plane
\r
159 stosb ; store destination planar bitmap width
\r
160 mov bl,al ; and copy to bl
\r
162 stosb ; Transfer source bitmap height to dest pbm
\r
163 xor ah,ah ; Conver height to word
\r
164 mul bl ; calculate the total no. of pixels / plane
\r
165 mov dx,si ; save source offset
\r
169 mov cx,ax ; set CX to total number of pixels per plane
\r
172 movsb ; transfer pixel
\r
173 add si,3 ; increment src offset to compensate for plane
\r
176 inc dx ; increment original si for next pixel plane
\r
177 mov si,dx ; and restore si from incremented original
\r
178 dec bl ; decrement plane counter
\r
179 jns @@PlaneLoop ; loop if more planes left
\r
182 @@WidthIncompatible:
\r
189 pop bp ;restore caller's stack frame
\r