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.
34 void build_colormap_good( ubyte * palette, ubyte * colormap, int * freq );
36 void gr_set_bitmap_data (grs_bitmap *bm, unsigned char *data)
39 // if (bm->bm_data!=data)
40 ogl_freebmtexture(bm);
44 Assert (bm->iMagic == BM_MAGIC_NUMBER);
45 Win32_SetTextureBits (bm, data, bm->bm_flags & BM_FLAG_RLE);
49 void gr_init_bitmap( grs_bitmap *bm, int mode, int x, int y, int w, int h, int bytesperline, unsigned char * data ) // TODO: virtualize
52 Assert (bm->iMagic != BM_MAGIC_NUMBER || bm->pvSurface == NULL);
61 bm->bm_rowsize = bytesperline;
65 bm->iMagic = BM_MAGIC_NUMBER;
70 Win32_CreateTexture (bm);
73 bm->bm_parent=NULL;bm->gltexture=NULL;
77 gr_set_bitmap_data (bm, data);
80 gr_set_bitmap_data (bm, d_malloc (w * h));
83 #ifdef BITMAP_SELECTOR
88 void gr_init_bitmap_alloc( grs_bitmap *bm, int mode, int x, int y, int w, int h, int bytesperline)
90 gr_init_bitmap(bm, mode, x, y, w, h, bytesperline, 0);
91 gr_set_bitmap_data(bm, d_malloc(w * h));
94 void gr_init_bitmap_data (grs_bitmap *bm) // TODO: virtulize
98 Assert (bm->iMagic != BM_MAGIC_NUMBER);
99 bm->iMagic = BM_MAGIC_NUMBER;
100 bm->pvSurface = NULL;
103 // ogl_freebmtexture(bm);//not what we want here.
104 bm->bm_parent=NULL;bm->gltexture=NULL;
108 void gr_free_bitmap(grs_bitmap *bm )
110 gr_free_bitmap_data (bm);
115 void gr_free_bitmap_data (grs_bitmap *bm) // TODO: virtulize
118 Assert (bm->iMagic == BM_MAGIC_NUMBER);
120 Win32_FreeTexture (bm);
122 if (bm->bm_data == BM_D3D_RENDER)
126 ogl_freebmtexture(bm);
128 if (bm->bm_data != NULL)
129 d_free (bm->bm_data);
133 void gr_init_sub_bitmap (grs_bitmap *bm, grs_bitmap *bmParent, int x, int y, int w, int h ) // TODO: virtualize
135 bm->bm_x = x + bmParent->bm_x;
136 bm->bm_y = y + bmParent->bm_y;
139 bm->bm_flags = bmParent->bm_flags;
140 bm->bm_type = bmParent->bm_type;
141 bm->bm_rowsize = bmParent->bm_rowsize;
144 bm->gltexture=bmParent->gltexture;
145 bm->bm_parent=bmParent;
148 Assert (bmParent->iMagic == BM_MAGIC_NUMBER);
149 bm->iMagic = BM_MAGIC_NUMBER;
150 bm->pvSurface = bmParent->pvSurface;
151 if (bm->bm_type == BM_DIRECTX)
153 bm->bm_data = bmParent->bm_data;
158 bm->bm_data = bmParent->bm_data+(unsigned int)((y*bmParent->bm_rowsize)+x);
163 void gr_free_sub_bitmap(grs_bitmap *bm )
175 grs_bitmap *gr_create_bitmap(int w, int h )
177 return gr_create_bitmap_raw (w, h, d_malloc(w * h));
180 grs_bitmap *gr_create_bitmap_raw(int w, int h, unsigned char * raw_data )
184 new = (grs_bitmap *)d_malloc( sizeof(grs_bitmap) );
185 gr_init_bitmap (new, 0, 0, 0, w, h, w, raw_data);
191 grs_bitmap *gr_create_sub_bitmap(grs_bitmap *bm, int x, int y, int w, int h )
195 new = (grs_bitmap *)d_malloc( sizeof(grs_bitmap) );
196 gr_init_sub_bitmap (new, bm, x, y, w, h);
201 void gr_set_bitmap_flags (grs_bitmap *pbm, int flags)
204 Assert (pbm->iMagic == BM_MAGIC_NUMBER);
208 if ((flags & BM_FLAG_TRANSPARENT) != (pbm->bm_flags & BM_FLAG_TRANSPARENT))
210 Win32_SetTransparent (pbm->pvSurface, flags & BM_FLAG_TRANSPARENT);
214 pbm->bm_flags = flags;
217 void gr_set_transparent (grs_bitmap *pbm, int bTransparent)
221 gr_set_bitmap_flags (pbm, pbm->bm_flags | BM_FLAG_TRANSPARENT);
225 gr_set_bitmap_flags (pbm, pbm->bm_flags & ~BM_FLAG_TRANSPARENT);
229 void gr_set_super_transparent (grs_bitmap *pbm, int bTransparent)
233 gr_set_bitmap_flags (pbm, pbm->bm_flags & ~BM_FLAG_SUPER_TRANSPARENT);
237 gr_set_bitmap_flags (pbm, pbm->bm_flags | BM_FLAG_SUPER_TRANSPARENT);
241 void gr_remap_bitmap( grs_bitmap * bmp, ubyte * palette, int transparent_color, int super_transparent_color )
246 // This should be build_colormap_asm, but we're not using invert table, so...
247 build_colormap_good( palette, colormap, freq );
249 if ( (super_transparent_color>=0) && (super_transparent_color<=255))
250 colormap[super_transparent_color] = 254;
252 if ( (transparent_color>=0) && (transparent_color<=255))
253 colormap[transparent_color] = 255;
255 decode_data_asm(bmp->bm_data, bmp->bm_w * bmp->bm_h, colormap, freq );
257 if ( (transparent_color>=0) && (transparent_color<=255) && (freq[transparent_color]>0) )
258 gr_set_transparent (bmp, 1);
260 if ( (super_transparent_color>=0) && (super_transparent_color<=255) && (freq[super_transparent_color]>0) )
261 gr_set_super_transparent (bmp, 0);
264 void build_colormap_good( ubyte * palette, ubyte * colormap, int * freq )
268 for (i=0; i<256; i++ ) {
272 *colormap++ = gr_find_closest_color( r, g, b );
278 void gr_remap_bitmap_good( grs_bitmap * bmp, ubyte * palette, int transparent_color, int super_transparent_color )
283 build_colormap_good( palette, colormap, freq );
285 if ( (super_transparent_color>=0) && (super_transparent_color<=255))
286 colormap[super_transparent_color] = 254;
288 if ( (transparent_color>=0) && (transparent_color<=255))
289 colormap[transparent_color] = 255;
291 decode_data_asm(bmp->bm_data, bmp->bm_w * bmp->bm_h, colormap, freq );
293 if ( (transparent_color>=0) && (transparent_color<=255) && (freq[transparent_color]>0) )
294 gr_set_transparent (bmp, 1);
296 if ( (super_transparent_color>=0) && (super_transparent_color<=255) && (freq[super_transparent_color]>0) )
297 gr_set_super_transparent (bmp, 1);
300 #ifdef BITMAP_SELECTOR
301 int gr_bitmap_assign_selector( grs_bitmap * bmp )
303 if (!dpmi_allocate_selector( bmp->bm_data, bmp->bm_w*bmp->bm_h, &bmp->bm_selector )) {
304 bmp->bm_selector = 0;
311 void gr_bitmap_check_transparency( grs_bitmap * bmp )
318 for (y=0; y<bmp->bm_h; y++ ) {
319 for (x=0; x<bmp->bm_w; x++ ) {
320 if (*data++ == 255 ) {
321 gr_set_transparent (bmp, 1);
325 data += bmp->bm_rowsize - bmp->bm_w;