1 /*----------------------------------------------------------------------
\r
4 ; Implements function to generate a Video bitmap (VBM) from a linear bitmap
\r
11 ; Based on "CreateMaskedAlignedImage" published in Dr Dobbs Journal
\r
12 ; by Michael Abrash (Jul - Aug 1991)
\r
14 ; ****** XLIB - Mode X graphics library ****************
\r
15 ; ****** ****************
\r
16 ; ****** Written By Themie Gouthas ****************
\r
17 ; ****** Aeronautical Research Laboratory ****************
\r
18 ; ****** Defence Science and Technology Organisation ****************
\r
19 ; ****** Australia ****************
\r
21 ; egg@dstos3.dsto.gov.au
\r
22 ; teg@bart.dsto.gov.au
\r
23 ;-----------------------------------------------------------------------*/
\r
25 Here is an outline of the XLIB image formats
\r
31 Planar bitmaps as used by these functions have the following structure:
\r
33 BYTE 0 The bitmap width in bytes (4 pixel groups) range 1..255
\r
34 BYTE 1 The bitmap height in rows range 1..255
\r
35 BYTE 2..n1 The plane 0 pixels width*height bytes
\r
36 BYTE n1..n2 The plane 1 pixels width*height bytes
\r
37 BYTE n2..n3 The plane 2 pixels width*height bytes
\r
38 BYTE n3..n4 The plane 3 pixels width*height bytes
\r
43 Linear bitmaps have the following structure:
\r
45 BYTE 0 The bitmap width in pixels range 1..255
\r
46 BYTE 1 The bitmap height in rows range 1..255
\r
47 BYTE 2..n The width*height bytes of the bitmap
\r
53 WORD 0 Size Total size of this VBM structure in bytes
\r
54 WORD 1 ImageWidth Width in bytes of the image (for all alignments)
\r
55 WORD 2 ImageHeight Height in scan lines of the image
\r
57 WORD 3 Alignment 0 ImagePtr Offset in VidRAM of this aligned image
\r
58 +--WORD 4 MaskPtr Offset (within this structure's DS) of
\r
62 | WORD 9 Alignment 3 ImagePtr Offset in VidRAM of this aligned image
\r
63 +|--WORD 10 MaskPtr Offset (within this structure's DS) of
\r
66 |+->BYTE 21 (WORD 11) -------+-- Image masks for alignment 0
\r
69 | BYTE 21 + ImageWidth*ImageHeight -----+
\r
72 | . (similaly for alignments 1 - 2 )
\r
75 +-->BYTE 21 + 3*ImageWidth*ImageHeight + 1-+-- Image masks for alignment 3
\r
78 BYTE 21 + 4*(ImageWidth*ImageHeight) --+
\r
82 << Similarly for alignments 2 and 3 >>
\r
85 BYTE 21 + 4*(ImageWidth*ImageHeight)
\r
88 (And dont forget the corresponding data in video ram)
\r
98 /* function to store the linear bitmap in the required video RAM offset */
\r
99 /* and in the required alignment */
\r
101 extern unsigned int x_store_vbm_image(unsigned int, int, char far *);
\r
104 /* Alignment structures, 4 of which make up the header section of the */
\r
109 unsigned int ImageWidth;
\r
110 unsigned int ImageHeight;
\r
112 unsigned int ImagePtr;
\r
113 unsigned int MaskPtr;
\r
115 } alignment_header;
\r
117 /* Structure to extract width/height frol LBM (linear bit map) */
\r
120 unsigned char width;
\r
121 unsigned char height;
\r
125 /*************************************************************************/
\r
127 /* Generates all four possible mode X image/mask alignments, stores */
\r
128 /* image alignments in display memory, allocates memory for and generates*/
\r
129 /* mask alignments, and fills out a VBM aligned masked image structure. */
\r
130 /* Each non-zero byte in source bitmap corresponds to image pixel to be */
\r
132 /* On success returns a far pointer to the new VBM structure otherwise */
\r
133 /* it returns NULL */
\r
135 /* Source Language: C */
\r
138 /* lbm pointer to linear bitmap */
\r
139 /* vramStart contains the next available video offset which is */
\r
140 /* also updated after calling this function */
\r
142 /*************************************************************************/
\r
144 char far *x_make_vbm(char far *lbm, unsigned int *VramStart)
\r
147 lbm_header far *lbm_headr;
\r
148 alignment_header far *vbm_headr;
\r
149 char far *vbm_mask_ptr,*p;
\r
150 char far *lbm_pixel_ptr;
\r
151 int align,BitNum,TempImageWidth;
\r
152 unsigned int TempWidth,TempHeight,TempSize,MaskSize,VramOffs,MaskSpace=0;
\r
154 unsigned char MaskTemp;
\r
156 VramOffs = *VramStart;
\r
157 lbm_headr = (lbm_header far *) lbm;
\r
159 TempWidth = (lbm_headr->width+3)/4+1;
\r
160 TempHeight = lbm_headr->height;
\r
161 TempSize = TempWidth*TempHeight;
\r
163 vbm_headr = (alignment_header far *) farmalloc(22+TempSize*4);
\r
164 if (!vbm_headr) return NULL;
\r
168 vbm_headr->ImageWidth = TempWidth;
\r
169 vbm_headr->ImageHeight = TempHeight;
\r
170 vbm_headr->size = 22+TempSize*4;
\r
171 for (align=0;align<4;align++){
\r
172 vbm_headr->alignments[align].ImagePtr = VramOffs;
\r
173 x_store_vbm_image(VramOffs,align,lbm);
\r
174 MaskSpace+=TempSize;
\r
175 VramOffs+=TempSize;
\r
179 vbm_mask_ptr = (char far *)vbm_headr+22;
\r
181 for (align=0;align<4;align++){
\r
182 lbm_pixel_ptr = lbm + 2;
\r
183 vbm_headr->alignments[align].MaskPtr = FP_OFF(vbm_mask_ptr);
\r
184 for (scanline=0;scanline<TempHeight;scanline++){
\r
187 TempImageWidth=lbm_headr->width;
\r
189 MaskTemp |= (*lbm_pixel_ptr++ !=0) << BitNum;
\r
190 if (++BitNum > 3) {
\r
191 *vbm_mask_ptr++=MaskTemp;
\r
194 } while (--TempImageWidth);
\r
195 *vbm_mask_ptr++=(BitNum != 0)?MaskTemp:0;
\r
200 *VramStart=VramOffs;
\r
201 return (char far *) vbm_headr;
\r