2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
16 * Graphical routines for manipulating grs_bitmaps.
39 void gr_set_bitmap_data (grs_bitmap *bm, unsigned char *data)
42 // if (bm->bm_data!=data)
43 ogl_freebmtexture(bm);
48 grs_bitmap *gr_create_bitmap(int w, int h )
50 return gr_create_bitmap_raw (w, h, d_malloc( MAX_BMP_SIZE(w, h) ));
53 grs_bitmap *gr_create_bitmap_raw(int w, int h, unsigned char * raw_data )
57 new = (grs_bitmap *)d_malloc( sizeof(grs_bitmap) );
58 gr_init_bitmap (new, 0, 0, 0, w, h, w, raw_data);
64 void gr_init_bitmap( grs_bitmap *bm, int mode, int x, int y, int w, int h, int bytesperline, unsigned char * data ) // TODO: virtualize
72 bm->bm_rowsize = bytesperline;
76 bm->bm_parent=NULL;bm->gltexture=NULL;
80 gr_set_bitmap_data (bm, data);
83 gr_set_bitmap_data (bm, d_malloc( MAX_BMP_SIZE(w, h) ));
86 #ifdef BITMAP_SELECTOR
91 void gr_init_bitmap_alloc( grs_bitmap *bm, int mode, int x, int y, int w, int h, int bytesperline)
93 gr_init_bitmap(bm, mode, x, y, w, h, bytesperline, 0);
94 gr_set_bitmap_data(bm, d_malloc( MAX_BMP_SIZE(w, h) ));
97 void gr_init_bitmap_data (grs_bitmap *bm) // TODO: virtulize
101 // ogl_freebmtexture(bm);//not what we want here.
102 bm->bm_parent=NULL;bm->gltexture=NULL;
106 grs_bitmap *gr_create_sub_bitmap(grs_bitmap *bm, int x, int y, int w, int h )
110 new = (grs_bitmap *)d_malloc( sizeof(grs_bitmap) );
111 gr_init_sub_bitmap (new, bm, x, y, w, h);
116 void gr_free_bitmap(grs_bitmap *bm )
118 gr_free_bitmap_data (bm);
123 void gr_free_sub_bitmap(grs_bitmap *bm )
132 void gr_free_bitmap_data (grs_bitmap *bm) // TODO: virtulize
135 ogl_freebmtexture(bm);
137 if (bm->bm_data != NULL)
138 d_free (bm->bm_data);
142 void gr_init_sub_bitmap (grs_bitmap *bm, grs_bitmap *bmParent, int x, int y, int w, int h ) // TODO: virtualize
144 bm->bm_x = x + bmParent->bm_x;
145 bm->bm_y = y + bmParent->bm_y;
148 bm->bm_flags = bmParent->bm_flags;
149 bm->bm_type = bmParent->bm_type;
150 bm->bm_rowsize = bmParent->bm_rowsize;
153 bm->gltexture=bmParent->gltexture;
154 bm->bm_parent=bmParent;
157 bm->bm_data = bmParent->bm_data+(unsigned int)((y*bmParent->bm_rowsize)+x);
162 void decode_data_asm(ubyte *data, int num_pixels, ubyte * colormap, int * count );
164 #if !defined(NO_ASM) && defined(__WATCOMC__)
166 #pragma aux decode_data_asm parm [esi] [ecx] [edi] [ebx] modify exact [esi edi eax ebx ecx] = \
170 "inc dword ptr [ebx+eax*4]" \
177 #elif !defined(NO_ASM) && defined(__GNUC__)
179 inline void decode_data_asm(ubyte *data, int num_pixels, ubyte * colormap, int * count ) {
181 __asm__ __volatile__ (
184 "movb (%%esi), %%al;"
185 "incl (%%ebx, %%eax, 4);"
186 "movb (%%edi, %%eax), %%al;"
187 "movb %%al, (%%esi);"
191 : "=S" (dummy[0]), "=c" (dummy[1]), "=D" (dummy[2]), "=b" (dummy[3])
192 : "0" (data), "1" (num_pixels), "2" (colormap), "3" (count)
196 #elif !defined(NO_ASM) && defined(_MSC_VER)
198 __inline void decode_data_asm(ubyte *data, int num_pixels, ubyte * colormap, int * count )
208 inc dword ptr [ebx+eax*4]
217 #else // NO_ASM or unknown compiler
219 void decode_data_asm(ubyte *data, int num_pixels, ubyte *colormap, int *count)
224 for (i = 0; i < num_pixels; i++) {
227 *data = colormap[mapped];
234 void gr_set_bitmap_flags (grs_bitmap *pbm, int flags)
236 pbm->bm_flags = flags;
239 void gr_set_transparent (grs_bitmap *pbm, int bTransparent)
243 gr_set_bitmap_flags (pbm, pbm->bm_flags | BM_FLAG_TRANSPARENT);
247 gr_set_bitmap_flags (pbm, pbm->bm_flags & ~BM_FLAG_TRANSPARENT);
251 void gr_set_super_transparent (grs_bitmap *pbm, int bTransparent)
255 gr_set_bitmap_flags (pbm, pbm->bm_flags & ~BM_FLAG_SUPER_TRANSPARENT);
259 gr_set_bitmap_flags (pbm, pbm->bm_flags | BM_FLAG_SUPER_TRANSPARENT);
263 void build_colormap_good( ubyte * palette, ubyte * colormap, int * freq )
267 for (i=0; i<256; i++ ) {
271 *colormap++ = gr_find_closest_color( r, g, b );
276 void gr_remap_bitmap( grs_bitmap * bmp, ubyte * palette, int transparent_color, int super_transparent_color )
281 if (bmp->bm_type != BM_LINEAR)
282 return; //can't do it
284 // This should be build_colormap_asm, but we're not using invert table, so...
285 build_colormap_good( palette, colormap, freq );
287 if ( (super_transparent_color>=0) && (super_transparent_color<=255))
288 colormap[super_transparent_color] = 254;
290 if ( (transparent_color>=0) && (transparent_color<=255))
291 colormap[transparent_color] = TRANSPARENCY_COLOR;
293 decode_data_asm(bmp->bm_data, bmp->bm_w * bmp->bm_h, colormap, freq );
295 if ( (transparent_color>=0) && (transparent_color<=255) && (freq[transparent_color]>0) )
296 gr_set_transparent (bmp, 1);
298 if ( (super_transparent_color>=0) && (super_transparent_color<=255) && (freq[super_transparent_color]>0) )
299 gr_set_super_transparent (bmp, 0);
302 void gr_remap_bitmap_good( grs_bitmap * bmp, ubyte * palette, int transparent_color, int super_transparent_color )
306 build_colormap_good( palette, colormap, freq );
308 if ( (super_transparent_color>=0) && (super_transparent_color<=255))
309 colormap[super_transparent_color] = 254;
311 if ( (transparent_color>=0) && (transparent_color<=255))
312 colormap[transparent_color] = TRANSPARENCY_COLOR;
314 if (bmp->bm_w == bmp->bm_rowsize)
315 decode_data_asm(bmp->bm_data, bmp->bm_w * bmp->bm_h, colormap, freq );
318 ubyte *p = bmp->bm_data;
319 for (y=0;y<bmp->bm_h;y++,p+=bmp->bm_rowsize)
320 decode_data_asm(p, bmp->bm_w, colormap, freq );
323 if ( (transparent_color>=0) && (transparent_color<=255) && (freq[transparent_color]>0) )
324 gr_set_transparent (bmp, 1);
326 if ( (super_transparent_color>=0) && (super_transparent_color<=255) && (freq[super_transparent_color]>0) )
327 gr_set_super_transparent (bmp, 1);
330 #ifdef BITMAP_SELECTOR
331 int gr_bitmap_assign_selector( grs_bitmap * bmp )
333 if (!dpmi_allocate_selector( bmp->bm_data, bmp->bm_w*bmp->bm_h, &bmp->bm_selector )) {
334 bmp->bm_selector = 0;
341 void gr_bitmap_check_transparency( grs_bitmap * bmp )
348 for (y=0; y<bmp->bm_h; y++ ) {
349 for (x=0; x<bmp->bm_w; x++ ) {
350 if (*data++ == TRANSPARENCY_COLOR ) {
351 gr_set_transparent (bmp, 1);
355 data += bmp->bm_rowsize - bmp->bm_w;