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.
31 void build_colormap_good( ubyte * palette, ubyte * colormap, int * freq );
33 void gr_set_bitmap_data (grs_bitmap *bm, unsigned char *data)
36 // if (bm->bm_data!=data)
37 ogl_freebmtexture(bm);
41 Assert (bm->iMagic == BM_MAGIC_NUMBER);
42 Win32_SetTextureBits (bm, data, bm->bm_flags & BM_FLAG_RLE);
46 void gr_init_bitmap( grs_bitmap *bm, int mode, int x, int y, int w, int h, int bytesperline, unsigned char * data ) // TODO: virtualize
49 Assert (bm->iMagic != BM_MAGIC_NUMBER || bm->pvSurface == NULL);
58 bm->bm_rowsize = bytesperline;
62 bm->iMagic = BM_MAGIC_NUMBER;
67 Win32_CreateTexture (bm);
70 bm->bm_parent=NULL;bm->gltexture=NULL;
74 gr_set_bitmap_data (bm, data);
77 gr_set_bitmap_data (bm, d_malloc (w * h));
80 #ifdef BITMAP_SELECTOR
85 void gr_init_bitmap_alloc( grs_bitmap *bm, int mode, int x, int y, int w, int h, int bytesperline)
87 gr_init_bitmap(bm, mode, x, y, w, h, bytesperline, 0);
88 gr_set_bitmap_data(bm, d_malloc(w * h));
91 void gr_init_bitmap_data (grs_bitmap *bm) // TODO: virtulize
95 Assert (bm->iMagic != BM_MAGIC_NUMBER);
96 bm->iMagic = BM_MAGIC_NUMBER;
100 // ogl_freebmtexture(bm);//not what we want here.
101 bm->bm_parent=NULL;bm->gltexture=NULL;
105 void gr_free_bitmap(grs_bitmap *bm )
107 gr_free_bitmap_data (bm);
112 void gr_free_bitmap_data (grs_bitmap *bm) // TODO: virtulize
115 Assert (bm->iMagic == BM_MAGIC_NUMBER);
117 Win32_FreeTexture (bm);
119 if (bm->bm_data == BM_D3D_RENDER)
123 ogl_freebmtexture(bm);
125 if (bm->bm_data != NULL)
126 d_free (bm->bm_data);
130 void gr_init_sub_bitmap (grs_bitmap *bm, grs_bitmap *bmParent, int x, int y, int w, int h ) // TODO: virtualize
132 bm->bm_x = x + bmParent->bm_x;
133 bm->bm_y = y + bmParent->bm_y;
136 bm->bm_flags = bmParent->bm_flags;
137 bm->bm_type = bmParent->bm_type;
138 bm->bm_rowsize = bmParent->bm_rowsize;
141 bm->gltexture=bmParent->gltexture;
142 bm->bm_parent=bmParent;
145 Assert (bmParent->iMagic == BM_MAGIC_NUMBER);
146 bm->iMagic = BM_MAGIC_NUMBER;
147 bm->pvSurface = bmParent->pvSurface;
148 if (bm->bm_type == BM_DIRECTX)
150 bm->bm_data = bmParent->bm_data;
155 bm->bm_data = bmParent->bm_data+(unsigned int)((y*bmParent->bm_rowsize)+x);
160 void gr_free_sub_bitmap(grs_bitmap *bm )
172 grs_bitmap *gr_create_bitmap(int w, int h )
174 return gr_create_bitmap_raw (w, h, d_malloc(w * h));
177 grs_bitmap *gr_create_bitmap_raw(int w, int h, unsigned char * raw_data )
181 new = (grs_bitmap *)d_malloc( sizeof(grs_bitmap) );
182 gr_init_bitmap (new, 0, 0, 0, w, h, w, raw_data);
188 grs_bitmap *gr_create_sub_bitmap(grs_bitmap *bm, int x, int y, int w, int h )
192 new = (grs_bitmap *)d_malloc( sizeof(grs_bitmap) );
193 gr_init_sub_bitmap (new, bm, x, y, w, h);
198 void gr_set_bitmap_flags (grs_bitmap *pbm, int flags)
201 Assert (pbm->iMagic == BM_MAGIC_NUMBER);
205 if ((flags & BM_FLAG_TRANSPARENT) != (pbm->bm_flags & BM_FLAG_TRANSPARENT))
207 Win32_SetTransparent (pbm->pvSurface, flags & BM_FLAG_TRANSPARENT);
211 pbm->bm_flags = flags;
214 void gr_set_transparent (grs_bitmap *pbm, int bTransparent)
218 gr_set_bitmap_flags (pbm, pbm->bm_flags | BM_FLAG_TRANSPARENT);
222 gr_set_bitmap_flags (pbm, pbm->bm_flags & ~BM_FLAG_TRANSPARENT);
226 void gr_set_super_transparent (grs_bitmap *pbm, int bTransparent)
230 gr_set_bitmap_flags (pbm, pbm->bm_flags & ~BM_FLAG_SUPER_TRANSPARENT);
234 gr_set_bitmap_flags (pbm, pbm->bm_flags | BM_FLAG_SUPER_TRANSPARENT);
238 void gr_remap_bitmap( grs_bitmap * bmp, ubyte * palette, int transparent_color, int super_transparent_color )
243 // This should be build_colormap_asm, but we're not using invert table, so...
244 build_colormap_good( palette, colormap, freq );
246 if ( (super_transparent_color>=0) && (super_transparent_color<=255))
247 colormap[super_transparent_color] = 254;
249 if ( (transparent_color>=0) && (transparent_color<=255))
250 colormap[transparent_color] = 255;
252 decode_data_asm(bmp->bm_data, bmp->bm_w * bmp->bm_h, colormap, freq );
254 if ( (transparent_color>=0) && (transparent_color<=255) && (freq[transparent_color]>0) )
255 gr_set_transparent (bmp, 1);
257 if ( (super_transparent_color>=0) && (super_transparent_color<=255) && (freq[super_transparent_color]>0) )
258 gr_set_super_transparent (bmp, 0);
261 void build_colormap_good( ubyte * palette, ubyte * colormap, int * freq )
265 for (i=0; i<256; i++ ) {
269 *colormap++ = gr_find_closest_color( r, g, b );
275 void gr_remap_bitmap_good( grs_bitmap * bmp, ubyte * palette, int transparent_color, int super_transparent_color )
280 build_colormap_good( palette, colormap, freq );
282 if ( (super_transparent_color>=0) && (super_transparent_color<=255))
283 colormap[super_transparent_color] = 254;
285 if ( (transparent_color>=0) && (transparent_color<=255))
286 colormap[transparent_color] = 255;
288 decode_data_asm(bmp->bm_data, bmp->bm_w * bmp->bm_h, colormap, freq );
290 if ( (transparent_color>=0) && (transparent_color<=255) && (freq[transparent_color]>0) )
291 gr_set_transparent (bmp, 1);
293 if ( (super_transparent_color>=0) && (super_transparent_color<=255) && (freq[super_transparent_color]>0) )
294 gr_set_super_transparent (bmp, 1);
297 #ifdef BITMAP_SELECTOR
298 int gr_bitmap_assign_selector( grs_bitmap * bmp )
300 if (!dpmi_allocate_selector( bmp->bm_data, bmp->bm_w*bmp->bm_h, &bmp->bm_selector )) {
301 bmp->bm_selector = 0;
308 void gr_bitmap_check_transparency( grs_bitmap * bmp )
315 for (y=0; y<bmp->bm_h; y++ ) {
316 for (x=0; x<bmp->bm_w; x++ ) {
317 if (*data++ == 255 ) {
318 gr_set_transparent (bmp, 1);
322 data += bmp->bm_rowsize - bmp->bm_w;