1 /* $Id: bitmap.c,v 1.3 2002-07-17 21:55:19 bradleyb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
35 void build_colormap_good( ubyte * palette, ubyte * colormap, int * freq );
37 void gr_set_bitmap_data (grs_bitmap *bm, unsigned char *data)
40 // if (bm->bm_data!=data)
41 ogl_freebmtexture(bm);
45 Assert (bm->iMagic == BM_MAGIC_NUMBER);
46 Win32_SetTextureBits (bm, data, bm->bm_flags & BM_FLAG_RLE);
50 void gr_init_bitmap( grs_bitmap *bm, int mode, int x, int y, int w, int h, int bytesperline, unsigned char * data ) // TODO: virtualize
53 Assert (bm->iMagic != BM_MAGIC_NUMBER || bm->pvSurface == NULL);
62 bm->bm_rowsize = bytesperline;
66 bm->iMagic = BM_MAGIC_NUMBER;
71 Win32_CreateTexture (bm);
74 bm->bm_parent=NULL;bm->gltexture=NULL;
78 gr_set_bitmap_data (bm, data);
81 gr_set_bitmap_data (bm, d_malloc (w * h));
84 #ifdef BITMAP_SELECTOR
89 void gr_init_bitmap_alloc( grs_bitmap *bm, int mode, int x, int y, int w, int h, int bytesperline)
91 gr_init_bitmap(bm, mode, x, y, w, h, bytesperline, 0);
92 gr_set_bitmap_data(bm, d_malloc(w * h));
95 void gr_init_bitmap_data (grs_bitmap *bm) // TODO: virtulize
99 Assert (bm->iMagic != BM_MAGIC_NUMBER);
100 bm->iMagic = BM_MAGIC_NUMBER;
101 bm->pvSurface = NULL;
104 // ogl_freebmtexture(bm);//not what we want here.
105 bm->bm_parent=NULL;bm->gltexture=NULL;
109 void gr_free_bitmap(grs_bitmap *bm )
111 gr_free_bitmap_data (bm);
116 void gr_free_bitmap_data (grs_bitmap *bm) // TODO: virtulize
119 Assert (bm->iMagic == BM_MAGIC_NUMBER);
121 Win32_FreeTexture (bm);
123 if (bm->bm_data == BM_D3D_RENDER)
127 ogl_freebmtexture(bm);
129 if (bm->bm_data != NULL)
130 d_free (bm->bm_data);
134 void gr_init_sub_bitmap (grs_bitmap *bm, grs_bitmap *bmParent, int x, int y, int w, int h ) // TODO: virtualize
136 bm->bm_x = x + bmParent->bm_x;
137 bm->bm_y = y + bmParent->bm_y;
140 bm->bm_flags = bmParent->bm_flags;
141 bm->bm_type = bmParent->bm_type;
142 bm->bm_rowsize = bmParent->bm_rowsize;
145 bm->gltexture=bmParent->gltexture;
146 bm->bm_parent=bmParent;
149 Assert (bmParent->iMagic == BM_MAGIC_NUMBER);
150 bm->iMagic = BM_MAGIC_NUMBER;
151 bm->pvSurface = bmParent->pvSurface;
152 if (bm->bm_type == BM_DIRECTX)
154 bm->bm_data = bmParent->bm_data;
159 bm->bm_data = bmParent->bm_data+(unsigned int)((y*bmParent->bm_rowsize)+x);
164 void gr_free_sub_bitmap(grs_bitmap *bm )
176 grs_bitmap *gr_create_bitmap(int w, int h )
178 return gr_create_bitmap_raw (w, h, d_malloc(w * h));
181 grs_bitmap *gr_create_bitmap_raw(int w, int h, unsigned char * raw_data )
185 new = (grs_bitmap *)d_malloc( sizeof(grs_bitmap) );
186 gr_init_bitmap (new, 0, 0, 0, w, h, w, raw_data);
192 grs_bitmap *gr_create_sub_bitmap(grs_bitmap *bm, int x, int y, int w, int h )
196 new = (grs_bitmap *)d_malloc( sizeof(grs_bitmap) );
197 gr_init_sub_bitmap (new, bm, x, y, w, h);
202 void gr_set_bitmap_flags (grs_bitmap *pbm, int flags)
205 Assert (pbm->iMagic == BM_MAGIC_NUMBER);
209 if ((flags & BM_FLAG_TRANSPARENT) != (pbm->bm_flags & BM_FLAG_TRANSPARENT))
211 Win32_SetTransparent (pbm->pvSurface, flags & BM_FLAG_TRANSPARENT);
215 pbm->bm_flags = flags;
218 void gr_set_transparent (grs_bitmap *pbm, int bTransparent)
222 gr_set_bitmap_flags (pbm, pbm->bm_flags | BM_FLAG_TRANSPARENT);
226 gr_set_bitmap_flags (pbm, pbm->bm_flags & ~BM_FLAG_TRANSPARENT);
230 void gr_set_super_transparent (grs_bitmap *pbm, int bTransparent)
234 gr_set_bitmap_flags (pbm, pbm->bm_flags & ~BM_FLAG_SUPER_TRANSPARENT);
238 gr_set_bitmap_flags (pbm, pbm->bm_flags | BM_FLAG_SUPER_TRANSPARENT);
242 void gr_remap_bitmap( grs_bitmap * bmp, ubyte * palette, int transparent_color, int super_transparent_color )
247 // This should be build_colormap_asm, but we're not using invert table, so...
248 build_colormap_good( palette, colormap, freq );
250 if ( (super_transparent_color>=0) && (super_transparent_color<=255))
251 colormap[super_transparent_color] = 254;
253 if ( (transparent_color>=0) && (transparent_color<=255))
254 colormap[transparent_color] = 255;
256 decode_data_asm(bmp->bm_data, bmp->bm_w * bmp->bm_h, colormap, freq );
258 if ( (transparent_color>=0) && (transparent_color<=255) && (freq[transparent_color]>0) )
259 gr_set_transparent (bmp, 1);
261 if ( (super_transparent_color>=0) && (super_transparent_color<=255) && (freq[super_transparent_color]>0) )
262 gr_set_super_transparent (bmp, 0);
265 void build_colormap_good( ubyte * palette, ubyte * colormap, int * freq )
269 for (i=0; i<256; i++ ) {
273 *colormap++ = gr_find_closest_color( r, g, b );
279 void gr_remap_bitmap_good( grs_bitmap * bmp, ubyte * palette, int transparent_color, int super_transparent_color )
284 build_colormap_good( palette, colormap, freq );
286 if ( (super_transparent_color>=0) && (super_transparent_color<=255))
287 colormap[super_transparent_color] = 254;
289 if ( (transparent_color>=0) && (transparent_color<=255))
290 colormap[transparent_color] = 255;
292 decode_data_asm(bmp->bm_data, bmp->bm_w * bmp->bm_h, colormap, freq );
294 if ( (transparent_color>=0) && (transparent_color<=255) && (freq[transparent_color]>0) )
295 gr_set_transparent (bmp, 1);
297 if ( (super_transparent_color>=0) && (super_transparent_color<=255) && (freq[super_transparent_color]>0) )
298 gr_set_super_transparent (bmp, 1);
301 #ifdef BITMAP_SELECTOR
302 int gr_bitmap_assign_selector( grs_bitmap * bmp )
304 if (!dpmi_allocate_selector( bmp->bm_data, bmp->bm_w*bmp->bm_h, &bmp->bm_selector )) {
305 bmp->bm_selector = 0;
312 void gr_bitmap_check_transparency( grs_bitmap * bmp )
319 for (y=0; y<bmp->bm_h; y++ ) {
320 for (x=0; x<bmp->bm_w; x++ ) {
321 if (*data++ == 255 ) {
322 gr_set_transparent (bmp, 1);
326 data += bmp->bm_rowsize - bmp->bm_w;