Debian Codegraph @

bitmap/bitmain.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/bitmap/bitmain.cpp $
21 * $Revision: 70 $
22 * $Date: 5/10/00 5:09p $
23 * $Author: Matt $
24 *
25 * Bitmap handling functions
26 *
27 * $Log: /DescentIII/Main/bitmap/bitmain.cpp $
28 *
29 * 70 5/10/00 5:09p Matt
30 * Added casts so code would compile under Visual C++.
31 *
32 * 69 5/10/00 4:34p Jeff
33 * handle buggy tablefile editors that put the full path name to a
34 * primative instead of just the filename
35 *
36 * 68 4/19/00 5:29p Matt
37 * From Duane for 1.4
38 * Added Mac-only error handling
39 * Added checks & asserts for error return values
40 *
41 * 67 4/04/00 6:09p Matt
42 * Fixed two problems in the hash code: the hash values were
43 * case-sensitive, which caused misses with mixed-case filenames, and hash
44 * table nodes were not freed when a bitmap was freed.
45 *
46 * 66 3/20/00 12:23p Matt
47 * Merge of Duane's post-1.3 changes.
48 * Small optimization
49 * Error check
50 *
51 * 65 2/06/00 3:41a Jason
52 * fixed memory overrun error in bm_ChangeEndName function
53 *
54 * 64 10/21/99 9:27p Jeff
55 * B.A. Macintosh code merge
56 *
57 * 63 8/10/99 5:10p Jeff
58 * delete the hash table on bitmap lib shutdown...just to be clean
59 *
60 * 62 7/28/99 5:18p Kevin
61 * Mac merge fixes
62 *
63 * 61 7/28/99 3:37p Kevin
64 * Mac!
65 *
66 * 60 4/29/99 4:59p Jason
67 * fixed some preuploaded texture problems
68 *
69 * 59 4/23/99 10:45p Jeff
70 * fixed crash with freeing hash table, set it to NULL to prevent double
71 * free
72 *
73 * 58 4/21/99 11:05a Kevin
74 * new ps_rand and ps_srand to replace rand & srand
75 *
76 * 57 4/16/99 11:51p Jeff
77 * renamed strcmpi to stricmp to be linux nice
78 *
79 * 56 4/15/99 2:56p Kevin
80 * Removed unneeded mprintf and unused variable
81 *
82 * 55 4/15/99 12:36p Kevin
83 * Changed bm_FindBitmapName to use a hash table.
84 *
85 * 54 4/14/99 1:07a Jeff
86 * fixed case mismatched #includes
87 *
88 * 53 3/23/99 10:24a Samir
89 * NULL pointer in bm_DestroyChunkedBitmap.
90 *
91 * 52 2/12/99 12:14p Jason
92 * fixed memory scaling problem
93 *
94 * 51 1/19/99 11:17a Jason
95 * fixed another scaling problem
96 *
97 * 50 1/14/99 2:26p Jason
98 * made data tracking more reliable
99 *
100 * 49 1/04/99 6:19p Jason
101 * fixed bitmap format problem
102 *
103 * 48 12/21/98 11:47a Jason
104 * fixed bitmap problem with 4444 mipping
105 *
106 * 47 12/21/98 11:21a Josh
107 * FROM JASON: Fixed format/mip problem
108 *
109 * 46 11/30/98 5:50p Jason
110 * added 4444 bitmap support
111 *
112 * 45 10/21/98 4:36p Jason
113 * more changes for renderering speedups
114 *
115 * 44 10/19/98 4:22p Jason
116 * more fixes for Beta5
117 *
118 * 43 10/08/98 2:27p Jason
119 * sped up table file loading
120 *
121 * 42 9/25/98 12:01p Samir
122 * for ndebug builds, removed the return immediately case in
123 * bm_AllocLoadFileBitmap.
124 *
125 * 41 8/21/98 5:14p Jason
126 * made better memory use of primitives
127 *
128 * 40 7/14/98 10:58a Jason
129 * fixed transparency bug in error texture
130 *
131 * 39 5/27/98 5:17p Jason
132 * fixed some bugs for the E3 Demo
133 *
134 * 38 5/20/98 5:43p Jason
135 * incremental checkin for bumpmapping
136 *
137 * 37 5/07/98 3:30p Jeff
138 * optimized CreateChunkBitmap a bit
139 *
140 * 36 5/05/98 1:01p Jeff
141 * improved on Chunk bitmaps
142 *
143 * 35 4/23/98 6:38p Jason
144 * made bitmaps use 1555 format
145 *
146 * 34 4/22/98 12:10p Chris
147 * Fixed path length problems
148 *
149 * 33 4/03/98 12:23p Jason
150 * dealt with overlay types being loaded from disk more than once
151 *
152 * 32 3/31/98 3:48p Jason
153 * added memory lib
154 *
155 * 31 3/23/98 4:42p Jason
156 * took out dumb ifdef
157 *
158 * 30 3/19/98 3:18p Samir
159 * enforce constant char* arguments when needed. done in CFILE and bitmap
160 * libraries as well as ddio.
161 *
162 * 29 3/17/98 4:33p Jason
163 * Added size changing to bitmaps/textures
164 *
165 * 28 2/17/98 4:57p Jason
166 * upped bitmap counts
167 *
168 * 27 2/13/98 7:23p Brent
169 * fixed mipping bug
170 *
171 * 26 2/12/98 1:32p Jason
172 * got mipmapping working
173 *
174 * 25 2/11/98 7:08p Jason
175 * took out dumb mprintf
176 *
177 * 24 2/09/98 3:38p Jason
178 * fixed potential problem with overlay bitmaps
179 *
180 * 23 2/06/98 7:20p Jason
181 * made duplicate bitmaps replace themselves in memory
182 *
183 * 22 1/26/98 4:32p Jason
184 * took out some goofy mprintfs
185 *
186 * 21 1/16/98 3:14p Samir
187 * Now store pixel width and height of chunked bitmap.
188 *
189 * 20 1/16/98 11:46a Samir
190 * Added functions to allocate and destroy chunked bitmaps.
191 *
192 * 19 1/14/98 12:45p Jeff
193 * Added a 'clear bitmap' function. Clears to transparent color.
194 *
195 * 18 12/23/97 6:32p Mark
196 * fixed problem with trying to save a bitmap that hasn't been paged in.
197 *
198 * 17 12/19/97 5:59p Jason
199 * sped up bitmap loading
200 *
201 * 16 12/19/97 3:36p Jason
202 * bug fixes for bitmap paging stuff
203 *
204 * 15 12/19/97 2:46p Jason
205 * implemented bitmap paging routines
206 *
207 * 14 12/18/97 4:03p Jason
208 * added error checking for bitmaps initting
209 *
210 * 13 11/11/97 1:07p Jason
211 * fixed multiple names problem in bitmap naming
212 *
213 * 12 11/10/97 4:53p Jason
214 * added warning for names that are too long
215 *
216 * 11 10/16/97 4:55p Jason
217 * fixed stupid off-by-one bug
218 *
219 * 10 10/16/97 10:48a Jason
220 * added bm_set_priority
221 *
222 * 9 10/15/97 5:20p Jason
223 * did a HUGE overhaul of the bitmap system
224 *
225 * 8 9/17/97 10:48a Jason
226 * added cache_slot variable
227 *
228 * 7 9/16/97 5:04p Matt
229 * Changed conditional for debug code
230 *
231 * 6 9/12/97 6:06p Samir
232 * Added function to get bitmap pixel.
233 *
234 * 5 9/10/97 12:13p Samir
235 * Added function to check if a pixel is transparent.
236 *
237 * 4 9/02/97 11:18a Jason
238 * got rid of compiler warnings
239 *
240 * 3 8/29/97 1:22p Jason
241 * added tga screenshots
242 *
243 * 2 8/05/97 10:18a Jason
244 * added lightmap system
245 *
246 * 46 6/24/97 12:41p Jason
247 * checked in for safety
248 *
249 * 45 6/06/97 3:57p Jason
250 * implemented changes for small textures and automatic tmap2 recognition
251 *
252 * 44 6/03/97 12:19p Jason
253 * cleaned up the bitmap library a bit
254 *
255 * 43 5/19/97 5:10p Jason
256 * changes for our new abstracted renderer code
257 *
258 * 42 5/12/97 11:41a Jason
259 * made game work (default) to 16bit no mip maps mode
260 * Saves us alot of memory
261 *
262 * 41 5/08/97 1:16p Jason
263 * made ChangeEndName work with device independant calls
264 *
265 * 40 5/02/97 5:22p Jason
266 * added bm_rowsize to return bytes per row
267 *
268 * 39 5/01/97 4:37p Jason
269 * made bitmaps clear their settings when alloced (bug fixed)
270 *
271 * 38 4/30/97 3:15p Jason
272 * changes to support both 8bit and 16bit rendering in software
273 *
274 * 37 4/25/97 3:31p Jason
275 * implemented better memory management for vclips and bitmaps
276 *
277 * 36 4/8/97 5:23 PM Jeremy
278 * #ifdef editor around calls to decrement bitmap_memory_used by checking
279 * _msize of an array location. _msize is microsoft specific, not cross
280 * platform, but this is only used by the editor anyway, thus the ifdef
281 * editor.
282 *
283 * 35 3/31/97 7:18p Jason
284 * made bitmaps easier on memory if not in editor mode
285 *
286 * 34 3/28/97 12:22p Jason
287 * implemented memory sharing scheme between 8 bit bitmaps
288 *
289 * 33 3/13/97 1:05p Matt
290 * Fixed extra-stupid bug
291 *
292 * 32 3/13/97 12:35p Matt
293 * Look for error1.ogf in current directory (explicitely)
294 *
295 * 31 3/03/97 6:20p Matt
296 * Changed cfile functions to use D3 naming convention
297 *
298 * $NoKeywords: $
299 */
300
301 #include <algorithm>
302 #include <cstdlib>
303 #include <cstring>
304 #include <cctype>
305 #include <filesystem>
306
307 #include "cfile.h"cxx . . $ `<file>/cfile/cfile.h`/
308 #include "bitmap.h"cxx . . $ `<file>/lib/bitmap.h`/
309 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
310 #include "mono.h"cxx . . $ `<file>/ddebug/mono.h`/
311 #include "iff.h"cxx . . $ `<file>/bitmap/iff.h`/
312 #include "ddio.h"cxx . . $ `<file>/ddio/ddio.h`/
313 #include "lightmap.h"cxx . . $ `<file>/lib/lightmap.h`/
314 #include "bumpmap.h"cxx . . $ `<file>/lib/bumpmap.h`/
315 #include "mem.h"cxx . . $ `<file>/mem/mem.h`/
316 #include "psrand.h"cxx . . $ `<file>/misc/psrand.h`/
317 #include "grdefs.h"cxx . . $ `<file>/lib/grdefs.h`/
318
319 #define BM_FILETYPE_TGAcxx . . $ `bitmap/bitmain.cpp:319:9`! 1
320 #define BM_FILETYPE_PCXcxx . . $ `bitmap/bitmain.cpp:320:9`! 2
321 #define BM_FILETYPE_IFFcxx . . $ `bitmap/bitmain.cpp:321:9`! 3
322 int Num_of_bitmapscxx . . $ Num_of_bitmaps. = 0;
323 bms_bitmapcxx . . $ bms_bitmap# GameBitmapscxx . . $ GameBitmaps.[MAX_BITMAPScxx . . $ `lib/bitmap.h:30:9`!];
324 uint32_tcxx . . $ uint32_t# Bitmap_memory_usedcxx . . $ Bitmap_memory_used. = 0;
325 uint8_tcxx . . $ uint8_t# Bitmaps_inittedcxx . . $ Bitmaps_initted. = 0;
326 /* modify these lines to establish data type */
327 typedef bms_bitmapcxx . . $ bms_bitmap# *bm_Tcxx . . $ bm_T#; /* type of item to be stored */
328 typedef int bm_hashTableIndexcxx . . $ bm_hashTableIndex#; /* index into hash table */
329 #define compEQcxx . . $ `bitmap/bitmain.cpp:329:9`!(a, b) (stricmpcxx . . $ `linux/linux_fix.h:43:9`!((a)->name, (b)->name) == 0)
330 struct bm_Nodecxx . . $ bm_Node# {
331 struct bm_Nodecxx . . $ bm_Node# *nextcxx . . $ bm_Node#next.; /* next bm_Node */
332 bm_Tcxx . . $ bm_T# datacxx . . $ bm_Node#data.; /* data stored in bm_Node */
333 };
334 static bm_Nodecxx . . $ bm_Node# *bm_findNodecxx . . $ bm_findNode(2fafcbd0a0e7b2ca).(bm_Tcxx . . $ bm_T# data);
335 static void bm_deleteNodecxx . . $ bm_deleteNode(3371e6f0f32bdfa2).(bm_Tcxx . . $ bm_T# data);
336 static bm_Nodecxx . . $ bm_Node# *bm_insertNodecxx . . $ bm_insertNode(2fafcbd0a0e7b2ca).(bm_Tcxx . . $ bm_T# data);
337 static bm_hashTableIndexcxx . . $ bm_hashTableIndex# bm_hashcxx . . $ bm_hash(a7214f900f7fccd8).(bm_Tcxx . . $ bm_T# data);
338 static bm_Nodecxx . . $ bm_Node# **bm_hashTablecxx . . $ bm_hashTable. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
339 static const int bm_hashTableSizecxx . . $ bm_hashTableSize. = (MAX_BITMAPScxx . . $ `lib/bitmap.h:30:9`! / 2);
340 static void bm_InitHashTablecxx . . $ bm_InitHashTable(49f6e7a06ebc5aa8).();
341 static void bm_DeleteHashTablecxx . . $ bm_DeleteHashTable(49f6e7a06ebc5aa8).();
342 static int bm_TestNamecxx . . $ bm_TestName(5c4306d8553b3696).(const char *src);
343
344 void bm_InitHashTablecxx . . $ bm_InitHashTable(49f6e7a06ebc5aa8).() {
345 bm_hashTablecxx . . $ bm_hashTable. = (bm_Nodecxx . . $ bm_Node# **)mem_malloccxx . . $ `mem/mem.h:79:9`!(bm_hashTableSize * sizeof(bm_Node *));
346 for (int a = 0; a < bm_hashTableSizecxx . . $ bm_hashTableSize.; a++) {
347 bm_hashTablecxx . . $ bm_hashTable.[a] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
348 }
349 }
350 void bm_DeleteHashTablecxx . . $ bm_DeleteHashTable(49f6e7a06ebc5aa8).() {
351 if (bm_hashTablecxx . . $ bm_hashTable.) {
352 int idx;
353 for (idx = 0; idx < bm_hashTableSizecxx . . $ bm_hashTableSize.; idx++) {
354 if (bm_hashTablecxx . . $ bm_hashTable.[idx]) {
355 bm_Nodecxx . . $ bm_Node# *curr, *next;
356 curr = bm_hashTablecxx . . $ bm_hashTable.[idx];
357 while (curr) {
358 next = curr->nextcxx . . $ bm_Node#next.;
359 mem_freecxx . . $ `mem/mem.h:80:9`!(curr);
360 curr = next;
361 }
362 bm_hashTablecxx . . $ bm_hashTable.[idx] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
363 }
364 }
365
366 mem_freecxx . . $ `mem/mem.h:80:9`!(bm_hashTable);
367 bm_hashTablecxx . . $ bm_hashTable. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
368 }
369 }
370
371 bm_hashTableIndexcxx . . $ bm_hashTableIndex# bm_hashcxx . . $ bm_hash(a7214f900f7fccd8).(bm_Tcxx . . $ bm_T# data) {
372 /***********************************
373 * hash function applied to data *
374 ***********************************/
375 char *p = data->namecxx . . $ bms_bitmap#name.;
376 uint32_tcxx . . $ uint32_t# hval = strlen(p);
377
378 while (*p) {
379 hval += tolower(*p);
380 p++;
381 }
382
383 return (hval % (MAX_BITMAPScxx . . $ `lib/bitmap.h:30:9`! / 2));
384 }
385 bm_Nodecxx . . $ bm_Node# *bm_insertNodecxx . . $ bm_insertNode(2fafcbd0a0e7b2ca).(bm_Tcxx . . $ bm_T# data) {
386 bm_Nodecxx . . $ bm_Node# *p, *p0;
387 bm_hashTableIndexcxx . . $ bm_hashTableIndex# bucket;
388 /************************************************
389 * allocate bm_Node for data and insert in table *
390 ************************************************/
391 /* insert bm_Node at beginning of list */
392 bucket = bm_hashcxx . . $ bm_hash(a7214f900f7fccd8).(data);
393 if ((p = (bm_Nodecxx . . $ bm_Node# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(sizeof(bm_Node))) == 0) {
394 exit(1);
395 }
396 p0 = bm_hashTablecxx . . $ bm_hashTable.[bucket];
397 bm_hashTablecxx . . $ bm_hashTable.[bucket] = p;
398 p->nextcxx . . $ bm_Node#next. = p0;
399 p->datacxx . . $ bm_Node#data. = data;
400 return p;
401 }
402 void bm_deleteNodecxx . . $ bm_deleteNode(3371e6f0f32bdfa2).(bm_Tcxx . . $ bm_T# data) {
403 bm_Nodecxx . . $ bm_Node# *p0, *p;
404 bm_hashTableIndexcxx . . $ bm_hashTableIndex# bucket;
405 /********************************************
406 * delete bm_Node containing data from table *
407 ********************************************/
408 /* find bm_Node */
409 p0 = 0;
410 bucket = bm_hashcxx . . $ bm_hash(a7214f900f7fccd8).(data);
411 p = bm_hashTablecxx . . $ bm_hashTable.[bucket];
412 while (p && !compEQcxx . . $ `bitmap/bitmain.cpp:329:9`!(p->data, data)) {
413 p0 = p;
414 p = p->nextcxx . . $ bm_Node#next.;
415 }
416 if (!p)
417 return;
418 /* p designates bm_Node to delete, remove it from list */
419 if (p0)
420 /* not first bm_Node, p0 points to previous bm_Node */
421 p0->nextcxx . . $ bm_Node#next. = p->nextcxx . . $ bm_Node#next.;
422 else
423 /* first bm_Node on chain */
424 bm_hashTablecxx . . $ bm_hashTable.[bucket] = p->nextcxx . . $ bm_Node#next.;
425 mem_freecxx . . $ `mem/mem.h:80:9`!(p);
426 }
427 bm_Nodecxx . . $ bm_Node# *bm_findNodecxx . . $ bm_findNode(2fafcbd0a0e7b2ca).(bm_Tcxx . . $ bm_T# data) {
428 bm_Nodecxx . . $ bm_Node# *p;
429 if (!bm_hashTablecxx . . $ bm_hashTable.)
430 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
431 /*******************************
432 * find bm_Node containing data *
433 *******************************/
434 p = bm_hashTablecxx . . $ bm_hashTable.[bm_hashcxx . . $ bm_hash(a7214f900f7fccd8).(data)];
435 while (p && !compEQcxx . . $ `bitmap/bitmain.cpp:329:9`!(p->data, data))
436 p = p->nextcxx . . $ bm_Node#next.;
437 return p;
438 }
439 // simply frees up a bitmap
440 void bm_FreeBitmapMaincxx . . $ bm_FreeBitmapMain(d4f767463ce0a6b3).(int handle);
441 // Sets all the bitmaps to unused
442 void bm_InitBitmapscxx . . $ bm_InitBitmaps(49f6e7a06ebc5aa8).() {
443 int i, ret;
444 bm_InitHashTablecxx . . $ bm_InitHashTable(49f6e7a06ebc5aa8).();
445 Bitmaps_inittedcxx . . $ Bitmaps_initted. = 1;
446 for (i = 0; i < MAX_BITMAPScxx . . $ `lib/bitmap.h:30:9`!; i++) {
447 GameBitmapscxx . . $ GameBitmaps.[i].usedcxx . . $ bms_bitmap#used. = 0;
448 GameBitmapscxx . . $ GameBitmaps.[i].data16cxx . . $ bms_bitmap#data16. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
449 GameBitmapscxx . . $ GameBitmaps.[i].formatcxx . . $ bms_bitmap#format. = BITMAP_FORMAT_STANDARDcxx . . $ `lib/bitmap.h:55:9`!;
450 GameBitmapscxx . . $ GameBitmaps.[i].cache_slotcxx . . $ bms_bitmap#cache_slot. = -1;
451 GameBitmapscxx . . $ GameBitmaps.[i].flagscxx . . $ bms_bitmap#flags. = 0;
452 }
453 int bm = bm_AllocBitmapcxx . . $ bm_AllocBitmap(2326284602b0bb2d).(128, 128, 0);
454 ASSERTcxx . . $ `misc/pserror.h:246:9`!(bm == BAD_BITMAP_HANDLEcxx . . $ `lib/bitmap.h:42:9`!);
455 if (cfexistcxx . . $ cfexist(293b0826c8d9cb54).(".\\error1.ogf"cxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).))
456 ret = bm_AllocLoadFileBitmapcxx . . $ bm_AllocLoadFileBitmap(1163be050dbfff7).(".\\error1.ogf", 0);
457 else
458 ret = -1;
459 if (ret == -1)
460 bm_MakeBadcxx . . $ bm_MakeBad(d4f767463ce0a6b3).(bm);
461 else {
462 bm_ScaleBitmapToBitmapcxx . . $ bm_ScaleBitmapToBitmap(3e454b8ccf442868).(bm, ret);
463 bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(ret);
464 }
465
466 // bm_GenerateMipMaps (bm);
467 atexit(bm_ShutdownBitmapscxx . . $ bm_ShutdownBitmaps(49f6e7a06ebc5aa8).);
468 // Initialize lightmaps and bumpmaps
469 lm_InitLightmapscxx . . $ lm_InitLightmaps(49f6e7a06ebc5aa8).();
470 bump_InitBumpmapscxx . . $ bump_InitBumpmaps(49f6e7a06ebc5aa8).();
471 }
472 void bm_ShutdownBitmapscxx . . $ bm_ShutdownBitmaps(49f6e7a06ebc5aa8).(void) {
473 int i;
474 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Freeing all bitmap memory.\n");
475 bm_FreeBitmapMaincxx . . $ bm_FreeBitmapMain(d4f767463ce0a6b3).(0);
476 for (i = 0; i < MAX_BITMAPScxx . . $ `lib/bitmap.h:30:9`!; i++) {
477 while (GameBitmapscxx . . $ GameBitmaps.[i].usedcxx . . $ bms_bitmap#used. > 0)
478 bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(i);
479 }
480 bm_DeleteHashTablecxx . . $ bm_DeleteHashTable(49f6e7a06ebc5aa8).();
481 }
482 int bm_AllocateMemoryForIndexcxx . . $ bm_AllocateMemoryForIndex(d4c1ccc1fe1a56c0).(int n, int w, int h, int add_mem) {
483 // If no go on the malloc, bail out with -1
484
485 int size = (w * h * 2) + (add_mem) + 2;
486 GameBitmapscxx . . $ GameBitmaps.[n].data16cxx . . $ bms_bitmap#data16. = (uint16_tcxx . . $ uint16_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(size);
487 if (!GameBitmapscxx . . $ GameBitmaps.[n].data16cxx . . $ bms_bitmap#data16.) {
488 Int3cxx . . $ `misc/pserror.h:247:9`!(); // Ran out of memory!
489 return -1;
490 }
491 Bitmap_memory_usedcxx . . $ Bitmap_memory_used. += (size);
492 memset(GameBitmapscxx . . $ GameBitmaps.[n].data16cxx . . $ bms_bitmap#data16., 0xAA, size);
493
494 GameBitmapscxx . . $ GameBitmaps.[n].formatcxx . . $ bms_bitmap#format. = BITMAP_FORMAT_STANDARDcxx . . $ `lib/bitmap.h:55:9`!;
495 GameBitmapscxx . . $ GameBitmaps.[n].widthcxx . . $ bms_bitmap#width. = w;
496 GameBitmapscxx . . $ GameBitmaps.[n].heightcxx . . $ bms_bitmap#height. = h;
497 GameBitmapscxx . . $ GameBitmaps.[n].flagscxx . . $ bms_bitmap#flags. = BF_CHANGEDcxx . . $ `lib/bitmap.h:46:9`! | BF_BRAND_NEWcxx . . $ `lib/bitmap.h:51:9`!;
498
499 #ifdef USE_OPENGL
500 for (int tmp = w; tmp > 0; tmp = tmp >> 1)
501 GameBitmaps[n].mip_levels++;
502 #else
503 GameBitmapscxx . . $ GameBitmaps.[n].mip_levelscxx . . $ bms_bitmap#mip_levels. = NUM_MIP_LEVELScxx . . $ `lib/bitmap.h:31:9`!;
504 #endif
505
506 Num_of_bitmapscxx . . $ Num_of_bitmaps.++;
507 return n;
508 }
509 // Allocs a bitmap of w x h size
510 // If add_mem is nonzero, adds that to the amount alloced
511 // Returns bitmap handle if successful, -1 if otherwise
512 int bm_AllocBitmapcxx . . $ bm_AllocBitmap(2326284602b0bb2d).(int w, int h, int add_mem) {
513 int n = 0, i;
514 if (!Bitmaps_inittedcxx . . $ Bitmaps_initted.) {
515 Int3cxx . . $ `misc/pserror.h:247:9`!();
516 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Bitmaps not initted!!!\n");
517 return -1;
518 }
519
520 for (i = 0; i < MAX_BITMAPScxx . . $ `lib/bitmap.h:30:9`!; i++) {
521 if (GameBitmapscxx . . $ GameBitmaps.[i].usedcxx . . $ bms_bitmap#used. == 0) {
522 n = i;
523 break;
524 }
525 }
526 // If we can't find a free slot in which to alloc, bail out
527 if (i == MAX_BITMAPScxx . . $ `lib/bitmap.h:30:9`!) {
528 Int3cxx . . $ `misc/pserror.h:247:9`!();
529 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "ERROR! Couldn't find a free bitmap to alloc!\n");
530 return -1;
531 }
532 memset(&GameBitmapscxx . . $ GameBitmaps.[n], 0, sizeof(bms_bitmapcxx . . $ bms_bitmap#));
533 int ret = bm_AllocateMemoryForIndexcxx . . $ bm_AllocateMemoryForIndex(d4c1ccc1fe1a56c0).(n, w, h, add_mem);
534 if (ret >= 0) {
535 GameBitmapscxx . . $ GameBitmaps.[n].usedcxx . . $ bms_bitmap#used. = 1;
536 GameBitmapscxx . . $ GameBitmaps.[n].cache_slotcxx . . $ bms_bitmap#cache_slot. = -1;
537 }
538 return ret;
539 }
540 // Just like bm_AllocBitmap but doesn't actually allocate memory. Useful for paging!
541 int bm_AllocNoMemBitmapcxx . . $ bm_AllocNoMemBitmap(9b79fb6aee4c0440).(int w, int h) {
542 int n = 0, i;
543 if (!Bitmaps_inittedcxx . . $ Bitmaps_initted.) {
544 Int3cxx . . $ `misc/pserror.h:247:9`!();
545 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Bitmaps not initted!!!\n");
546 return -1;
547 }
548
549 for (i = 0; i < MAX_BITMAPScxx . . $ `lib/bitmap.h:30:9`!; i++) {
550 if (GameBitmapscxx . . $ GameBitmaps.[i].usedcxx . . $ bms_bitmap#used. == 0) {
551 n = i;
552 break;
553 }
554 }
555 // If we can't find a free slot in which to alloc, bail out
556 if (i == MAX_BITMAPScxx . . $ `lib/bitmap.h:30:9`!) {
557 Int3cxx . . $ `misc/pserror.h:247:9`!();
558 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "ERROR! Couldn't find a free bitmap to alloc!\n");
559 return -1;
560 }
561 // If no go on the malloc, bail out with -1
562
563 memset(&GameBitmapscxx . . $ GameBitmaps.[n], 0, sizeof(bms_bitmapcxx . . $ bms_bitmap#));
564
565 GameBitmapscxx . . $ GameBitmaps.[n].widthcxx . . $ bms_bitmap#width. = w;
566 GameBitmapscxx . . $ GameBitmaps.[n].heightcxx . . $ bms_bitmap#height. = h;
567 GameBitmapscxx . . $ GameBitmaps.[n].usedcxx . . $ bms_bitmap#used. = 1;
568 GameBitmapscxx . . $ GameBitmaps.[n].formatcxx . . $ bms_bitmap#format. = BITMAP_FORMAT_STANDARDcxx . . $ `lib/bitmap.h:55:9`!;
569 GameBitmapscxx . . $ GameBitmaps.[n].flagscxx . . $ bms_bitmap#flags. = BF_NOT_RESIDENTcxx . . $ `lib/bitmap.h:48:9`! | BF_CHANGEDcxx . . $ `lib/bitmap.h:46:9`! | BF_BRAND_NEWcxx . . $ `lib/bitmap.h:51:9`!;
570 GameBitmapscxx . . $ GameBitmaps.[n].cache_slotcxx . . $ bms_bitmap#cache_slot. = -1;
571
572 Num_of_bitmapscxx . . $ Num_of_bitmaps.++;
573 return n;
574 }
575 // Searches thru all bitmaps for a specific name, returns -1 if not found
576 // or index of bitmap with name
577 int bm_FindBitmapNamecxx . . $ bm_FindBitmapName(5c4306d8553b3696).(const char *name) {
578 int num_counted = 0;
579
580 bms_bitmapcxx . . $ bms_bitmap# fbmp;
581 strcpy(fbmp.namecxx . . $ bms_bitmap#name., name);
582 bm_Nodecxx . . $ bm_Node# *fnode = bm_findNodecxx . . $ bm_findNode(2fafcbd0a0e7b2ca).(&fbmp);
583 if (fnode) {
584 // mprintf(0,"Hash table found bitmap %d\n",fnode->data - GameBitmaps);
585 return fnode->datacxx . . $ bm_Node#data. - GameBitmapscxx . . $ GameBitmaps.;
586 } else
587 return -1;
588 }
589 // Given a handle, frees the bitmap memory and flags this bitmap as unused
590 void bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(int handle) {
591 if (!Bitmaps_inittedcxx . . $ Bitmaps_initted.) {
592 Int3cxx . . $ `misc/pserror.h:247:9`!();
593 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Bitmaps not initted!!!\n");
594 return;
595 }
596 if (handle == BAD_BITMAP_HANDLEcxx . . $ `lib/bitmap.h:42:9`!)
597 return;
598 if (GameBitmapscxx . . $ GameBitmaps.[handle].usedcxx . . $ bms_bitmap#used. < 1)
599 return;
600 GameBitmapscxx . . $ GameBitmaps.[handle].usedcxx . . $ bms_bitmap#used.--;
601 if (GameBitmapscxx . . $ GameBitmaps.[handle].usedcxx . . $ bms_bitmap#used. == 0) {
602 bm_FreeBitmapMaincxx . . $ bm_FreeBitmapMain(d4f767463ce0a6b3).(handle);
603 }
604 }
605 // simply frees up a bitmap
606 void bm_FreeBitmapDatacxx . . $ bm_FreeBitmapData(d4f767463ce0a6b3).(int handle) {
607 if (GameBitmapscxx . . $ GameBitmaps.[handle].data16cxx . . $ bms_bitmap#data16. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! && !(GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. & BF_NOT_RESIDENTcxx . . $ `lib/bitmap.h:48:9`!)) {
608 if (!(GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. & BF_NOT_RESIDENTcxx . . $ `lib/bitmap.h:48:9`!)) {
609 int mem_used = (GameBitmapscxx . . $ GameBitmaps.[handle].widthcxx . . $ bms_bitmap#width. * GameBitmapscxx . . $ GameBitmaps.[handle].heightcxx . . $ bms_bitmap#height. * 2);
610 Bitmap_memory_usedcxx . . $ Bitmap_memory_used. -= mem_used;
611 if (GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. & BF_MIPMAPPEDcxx . . $ `lib/bitmap.h:47:9`!)
612 Bitmap_memory_usedcxx . . $ Bitmap_memory_used. -= (mem_used / 3);
613 }
614 mem_freecxx . . $ `mem/mem.h:80:9`!(GameBitmaps[handle].data16);
615 }
616 GameBitmapscxx . . $ GameBitmaps.[handle].cache_slotcxx . . $ bms_bitmap#cache_slot. = -1;
617 GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. |= BF_NOT_RESIDENTcxx . . $ `lib/bitmap.h:48:9`!;
618 if (GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. & BF_MIPMAPPEDcxx . . $ `lib/bitmap.h:47:9`!)
619 GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. |= BF_WANTS_MIPcxx . . $ `lib/bitmap.h:49:9`!;
620 GameBitmapscxx . . $ GameBitmaps.[handle].data16cxx . . $ bms_bitmap#data16. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
621 }
622 // simply frees up a bitmap
623 void bm_FreeBitmapMaincxx . . $ bm_FreeBitmapMain(d4f767463ce0a6b3).(int handle) {
624 bm_deleteNodecxx . . $ bm_deleteNode(3371e6f0f32bdfa2).(&GameBitmapscxx . . $ GameBitmaps.[handle]);
625 bm_FreeBitmapDatacxx . . $ bm_FreeBitmapData(d4f767463ce0a6b3).(handle);
626 GameBitmapscxx . . $ GameBitmaps.[handle].data16cxx . . $ bms_bitmap#data16. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
627 GameBitmapscxx . . $ GameBitmaps.[handle].cache_slotcxx . . $ bms_bitmap#cache_slot. = -1;
628 GameBitmapscxx . . $ GameBitmaps.[handle].usedcxx . . $ bms_bitmap#used. = 0;
629 Num_of_bitmapscxx . . $ Num_of_bitmaps.--;
630 }
631 // Returns -1 if this name is not already in use, else index of bitmap that is using name
632 int bm_TestNamecxx . . $ bm_TestName(5c4306d8553b3696).(const char *src) {
633 uint32_tcxx . . $ uint32_t# i, limit;
634
635 char namedest[256];
636 char path[256], ext[256], filename[256];
637
638 ddio_SplitPathcxx . . $ ddio_SplitPath(b05ba7ab99603c07).(src, path, filename, ext);
639 limit = BITMAP_NAME_LENcxx . . $ `lib/bitmap.h:41:9`! - 7;
640 // Make sure we don't go over our name length limit
641 strncpy(namedest, filename, limit);
642 namedest[limit] = 0;
643
644 int cur_len = strlen(namedest);
645
646 // Now, make sure there are no other bitmaps with this name
647 strcat(namedest, ".ogf");
648 if ((i = bm_FindBitmapNamecxx . . $ bm_FindBitmapName(5c4306d8553b3696).(namedest)) == -1)
649 return -1;
650 return i;
651 }
652 // gets the filename from a path, plus appends our .ogf extension
653 void bm_ChangeEndNamecxx . . $ bm_ChangeEndName(611124a97efc52dd).(const char *src, char *dest) {
654 uint32_tcxx . . $ uint32_t# i, limit;
655 int last = -1;
656 int curnum = -1;
657 char namedest[256 + 16];
658 char path[256], ext[256], filename[256];
659
660 ddio_SplitPathcxx . . $ ddio_SplitPath(b05ba7ab99603c07).(src, path, filename, ext);
661 limit = BITMAP_NAME_LENcxx . . $ `lib/bitmap.h:41:9`! - 7;
662 // Make sure we don't go over our name length limit
663 filename[limit] = 0;
664 Start:
665 if (curnum != -1)
666 snprintf(namedest, sizeof(namedest), "%s%d", filename, curnum);
667 else
668 strcpy(namedest, filename);
669 // Now, make sure there are no other bitmaps with this name
670 strcat(namedest, ".ogf");
671 if ((i = bm_FindBitmapNamecxx . . $ bm_FindBitmapName(5c4306d8553b3696).(namedest)) != -1) {
672 curnum++;
673 // This name is already taken. Try same name with different number
674 // appended
675 goto Start;
676 }
677 strcpy(dest, namedest);
678 }
679 // Checks to see if this file is a kind we can read
680 int bm_GetFileTypecxx . . $ bm_GetFileType(643e1411966bd56c).(CFILEcxx . . $ CFILE# *infile, const char *dest) {
681 char iffcheck[4];
682 int i;
683 // First, check if its a pcx
684 i = strlen(dest);
685 if (dest[i - 4] == '.' && (dest[i - 3] == 'p' || dest[i - 3] == 'P') && (dest[i - 2] == 'c' || dest[i - 2] == 'C') &&
686 (dest[i - 1] == 'x' || dest[i - 1] == 'X'))
687 return BM_FILETYPE_PCXcxx . . $ `bitmap/bitmain.cpp:320:9`!;
688 // How about an IFF?
689 for (i = 0; i < 4; i++)
690 iffcheck[i] = cf_ReadBytecxx . . $ cf_ReadByte(dcbbf0b0e13758ec).(infile);
691 cfseekcxx . . $ cfseek(f9992d249f032805).(infile, 0, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`!);
692 if (!strncmp("FORM", iffcheck, 4))
693 return BM_FILETYPE_IFFcxx . . $ `bitmap/bitmain.cpp:321:9`!;
694 // Lastly, just default to possible TGA or OGF
695 return BM_FILETYPE_TGAcxx . . $ `bitmap/bitmain.cpp:319:9`!;
696 }
697 // Allocs and loads a bitmap
698 // Returns the handle of the loaded bitmap
699 // Returns -1 if something is wrong
700 // If mipped is non-zero, allocs extra space for mips and computes them
701 int bm_AllocLoadFileBitmapcxx . . $ bm_AllocLoadFileBitmap(1163be050dbfff7).(const char *fname, int mipped, int format) {
702 CFILEcxx . . $ CFILE# *infile;
703 if (!Bitmaps_inittedcxx . . $ Bitmaps_initted.) {
704 Int3cxx . . $ `misc/pserror.h:247:9`!();
705 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Bitmaps not initted!!!\n");
706 return -1;
707 }
708
709 char name[BITMAP_NAME_LENcxx . . $ `lib/bitmap.h:41:9`!];
710 int n, src_bm = 0;
711 int old_used;
712 int overlay = 0;
713
714 char *filename = (char *)fname;
715
716 // due to a bug in some people's tablefile editors, we got to make sure there is
717 // no path if there shouldn't be
718 if (!cfexistcxx . . $ cfexist(293b0826c8d9cb54).(filenamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).)) {
719 // generate a possible new filename
720 char *end_ptr, *start_ptr;
721 start_ptr = (char *)fname;
722 end_ptr = start_ptr + strlen(start_ptr) - 1;
723 while ((end_ptr >= start_ptr) && (*end_ptr != '\\'))
724 end_ptr--;
725 if (end_ptr < start_ptr) {
726 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Unable to find bitmap %s\n", fname);
727 return -1;
728 }
729 ASSERTcxx . . $ `misc/pserror.h:246:9`!(*end_ptr == '\\');
730 end_ptr++;
731 filename = end_ptr;
732 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Couldn't find %s, so gonna try %s\n", fname, filename);
733 }
734
735 // Check to see if this bitmap is already in memory, if so, just return that
736 // bitmaps handle
737 if ((n = bm_TestNamecxx . . $ bm_TestName(5c4306d8553b3696).(filename)) != -1) {
738 mprintfcxx . . $ `ddebug/mono.h:82:9`!(1, "Found duplicate bitmap %s.\n", GameBitmaps[n].name);
739 old_used = GameBitmapscxx . . $ GameBitmaps.[n].usedcxx . . $ bms_bitmap#used.;
740 GameBitmapscxx . . $ GameBitmaps.[n].usedcxx . . $ bms_bitmap#used. = 1;
741 bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(n);
742 GameBitmapscxx . . $ GameBitmaps.[n].usedcxx . . $ bms_bitmap#used. = old_used + 1;
743
744 overlay = 1;
745 }
746 if (!overlay)
747 bm_ChangeEndNamecxx . . $ bm_ChangeEndName(611124a97efc52dd).(filename, name);
748 else {
749 strcpy(name, GameBitmapscxx . . $ GameBitmaps.[n].namecxx . . $ bms_bitmap#name.);
750 }
751 if (strlen(name) > 33) {
752 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "ERROR!! This bitmaps name is too long, try shortening it and retry!\n");
753 return -1;
754 }
755 // Try to open the file. If we can't load it from the network if possible
756 infile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(filenamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., "rb");
757 if (!infile) {
758 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "bm_AllocLoadFileBitmap: Can't open file named %s.\n", filename);
759
760 return BAD_BITMAP_HANDLEcxx . . $ `lib/bitmap.h:42:9`!; // return the bad texture
761 }
762 // Check to see if this is IFF. If so, call the IFF reader. If not,
763 // rewind the file and read as a TGA
764
765 int filetype = bm_GetFileTypecxx . . $ bm_GetFileType(643e1411966bd56c).(infile, filename);
766
767 switch (filetype) {
768 case BM_FILETYPE_IFFcxx . . $ `bitmap/bitmain.cpp:321:9`!:
769 src_bm = bm_iff_alloc_filecxx . . $ bm_iff_alloc_file(413716a422df0036).(infile);
770 break;
771 case BM_FILETYPE_TGAcxx . . $ `bitmap/bitmain.cpp:319:9`!:
772 // reads a tga or an outrage graphics file (ogf)
773 src_bm = bm_tga_alloc_filecxx . . $ bm_tga_alloc_file(3b86680ef84cac7b).(infile, name, format);
774 break;
775 case BM_FILETYPE_PCXcxx . . $ `bitmap/bitmain.cpp:320:9`!:
776 src_bm = bm_pcx_alloc_filecxx . . $ bm_pcx_alloc_file(413716a422df0036).(infile);
777 break;
778 default:
779 Int3cxx . . $ `misc/pserror.h:247:9`!(); // Can't read this type
780 break;
781 }
782 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
783 if (src_bm < 0) {
784 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Couldn't load %s.", filename);
785 return -1;
786 }
787
788 // Allocate space for our bitmap.
789 if (mipped) {
790 if ((bm_mippedcxx . . $ bm_mipped(7864480464b09eea).(src_bm)) == 0) // If we want a mipped but we don't have one
791 {
792 int w = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(src_bm, 0);
793 int h = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(src_bm, 0);
794
795 if (overlay) {
796 bm_AllocateMemoryForIndexcxx . . $ bm_AllocateMemoryForIndex(d4c1ccc1fe1a56c0).(n, w, h, mipped * (((w * h * 2) / 3)));
797 GameBitmapscxx . . $ GameBitmaps.[n].formatcxx . . $ bms_bitmap#format. = GameBitmapscxx . . $ GameBitmaps.[src_bm].formatcxx . . $ bms_bitmap#format.;
798 } else {
799 n = bm_AllocBitmapcxx . . $ bm_AllocBitmap(2326284602b0bb2d).(w, h, mipped * (((w * h * 2) / 3)));
800 GameBitmapscxx . . $ GameBitmaps.[n].formatcxx . . $ bms_bitmap#format. = GameBitmapscxx . . $ GameBitmaps.[src_bm].formatcxx . . $ bms_bitmap#format.;
801 }
802
803 ASSERTcxx . . $ `misc/pserror.h:246:9`!(n >= 0);
804 bm_ScaleBitmapToBitmapcxx . . $ bm_ScaleBitmapToBitmap(3e454b8ccf442868).(n, src_bm);
805 bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(src_bm);
806
807 bm_GenerateMipMapscxx . . $ bm_GenerateMipMaps(d4f767463ce0a6b3).(n);
808 } else {
809 if (!overlay)
810 n = src_bm;
811 else {
812 int w = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(src_bm, 0);
813 int h = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(src_bm, 0);
814 bm_AllocateMemoryForIndexcxx . . $ bm_AllocateMemoryForIndex(d4c1ccc1fe1a56c0).(n, w, h, mipped * (((w * h * 2) / 3)));
815 GameBitmapscxx . . $ GameBitmaps.[n].flagscxx . . $ bms_bitmap#flags. |= BF_MIPMAPPEDcxx . . $ `lib/bitmap.h:47:9`!;
816 GameBitmapscxx . . $ GameBitmaps.[n].formatcxx . . $ bms_bitmap#format. = GameBitmapscxx . . $ GameBitmaps.[src_bm].formatcxx . . $ bms_bitmap#format.;
817 bm_ScaleBitmapToBitmapcxx . . $ bm_ScaleBitmapToBitmap(3e454b8ccf442868).(n, src_bm);
818 bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(src_bm);
819 }
820 }
821 } else // If we don't want a mipped
822 {
823 if ((bm_mippedcxx . . $ bm_mipped(7864480464b09eea).(src_bm)) == 0) {
824 if (!overlay)
825 n = src_bm;
826 else {
827 int w = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(src_bm, 0);
828 int h = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(src_bm, 0);
829 bm_AllocateMemoryForIndexcxx . . $ bm_AllocateMemoryForIndex(d4c1ccc1fe1a56c0).(n, w, h, mipped * (((w * h * 2) / 3)));
830 GameBitmapscxx . . $ GameBitmaps.[n].formatcxx . . $ bms_bitmap#format. = GameBitmapscxx . . $ GameBitmaps.[src_bm].formatcxx . . $ bms_bitmap#format.;
831 bm_ScaleBitmapToBitmapcxx . . $ bm_ScaleBitmapToBitmap(3e454b8ccf442868).(n, src_bm);
832 bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(src_bm);
833 }
834 } else // And this is already mipped
835 {
836 int w = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(src_bm, 0);
837 int h = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(src_bm, 0);
838 uint16_tcxx . . $ uint16_t# *src_data, *dest_data;
839
840 if (overlay) {
841 bm_AllocateMemoryForIndexcxx . . $ bm_AllocateMemoryForIndex(d4c1ccc1fe1a56c0).(n, w, h, mipped * (((w * h * 2) / 3)));
842 GameBitmapscxx . . $ GameBitmaps.[n].formatcxx . . $ bms_bitmap#format. = GameBitmapscxx . . $ GameBitmaps.[src_bm].formatcxx . . $ bms_bitmap#format.;
843 } else {
844 n = bm_AllocBitmapcxx . . $ bm_AllocBitmap(2326284602b0bb2d).(w, h, mipped * (((w * h * 2) / 3)));
845 GameBitmapscxx . . $ GameBitmaps.[n].formatcxx . . $ bms_bitmap#format. = GameBitmapscxx . . $ GameBitmaps.[src_bm].formatcxx . . $ bms_bitmap#format.;
846 }
847 ASSERTcxx . . $ `misc/pserror.h:246:9`!(n >= 0);
848 src_data = (uint16_tcxx . . $ uint16_t# *)bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(src_bm, 0);
849 dest_data = (uint16_tcxx . . $ uint16_t# *)bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(n, 0);
850 memcpy(dest_data, src_data, w * h * 2);
851
852 bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(src_bm);
853 }
854 }
855
856 strcpy(GameBitmapscxx . . $ GameBitmaps.[n].namecxx . . $ bms_bitmap#name., name);
857
858 // Insert into the hash table!
859 bm_insertNodecxx . . $ bm_insertNode(2fafcbd0a0e7b2ca).(&GameBitmapscxx . . $ GameBitmaps.[n]);
860 return n; // We made it!
861 }
862 // Allocs and loads a bitmap but doesn't actually load texel data!
863 // Returns the handle of the loaded bitmap
864 // Returns -1 if something is wrong
865 int bm_AllocLoadFileNoMemBitmapcxx . . $ bm_AllocLoadFileNoMemBitmap(1163be050dbfff7).(const char *fname, int mipped, int format) {
866 if (!Bitmaps_inittedcxx . . $ Bitmaps_initted.) {
867 Int3cxx . . $ `misc/pserror.h:247:9`!();
868 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Bitmaps not initted!!!\n");
869 return -1;
870 }
871
872 char name[BITMAP_NAME_LENcxx . . $ `lib/bitmap.h:41:9`!];
873 int n;
874 char *filename = (char *)fname;
875
876 // due to a bug in some people's tablefile editors, we got to make sure there is
877 // no path if there shouldn't be
878 if (!cfexistcxx . . $ cfexist(293b0826c8d9cb54).(filenamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).)) {
879 // generate a possible new filename
880 char *end_ptr, *start_ptr;
881 start_ptr = (char *)fname;
882 end_ptr = start_ptr + strlen(start_ptr) - 1;
883 while ((end_ptr >= start_ptr) && (*end_ptr != '\\'))
884 end_ptr--;
885 if (end_ptr < start_ptr) {
886 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Unable to find bitmap %s\n", fname);
887 return -1;
888 }
889 ASSERTcxx . . $ `misc/pserror.h:246:9`!(*end_ptr == '\\');
890 end_ptr++;
891 filename = end_ptr;
892 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Couldn't find %s, so gonna try %s\n", fname, filename);
893 }
894
895 // Check to see if this bitmap is already in memory, if so, just return that
896 // bitmaps handle
897 if ((n = bm_TestNamecxx . . $ bm_TestName(5c4306d8553b3696).(filename)) != -1) {
898 GameBitmapscxx . . $ GameBitmaps.[n].usedcxx . . $ bms_bitmap#used.++;
899 mprintfcxx . . $ `ddebug/mono.h:82:9`!(1, "Found duplicate bitmap %s.\n", GameBitmaps[n].name);
900 return n;
901 }
902
903 bm_ChangeEndNamecxx . . $ bm_ChangeEndName(611124a97efc52dd).(filename, name);
904 if (strlen(name) > 33) {
905 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "ERROR!! This bitmaps name is too long, try shortening it and retry!\n");
906 return -1;
907 }
908 n = bm_AllocNoMemBitmapcxx . . $ bm_AllocNoMemBitmap(9b79fb6aee4c0440).(1, 1);
909 strcpy(GameBitmapscxx . . $ GameBitmaps.[n].namecxx . . $ bms_bitmap#name., name);
910 if (mipped)
911 GameBitmapscxx . . $ GameBitmaps.[n].flagscxx . . $ bms_bitmap#flags. |= BF_WANTS_MIPcxx . . $ `lib/bitmap.h:49:9`!;
912 if (format == BITMAP_FORMAT_4444cxx . . $ `lib/bitmap.h:57:9`!)
913 GameBitmapscxx . . $ GameBitmaps.[n].flagscxx . . $ bms_bitmap#flags. |= BF_WANTS_4444cxx . . $ `lib/bitmap.h:50:9`!;
914
915 return n; // We made it!
916 }
917 // Allocs and loads a bitmap from an open file
918 // Returns the handle of the loaded bitmap
919 // Returns -1 if something is wrong
920 // If mipped is non-zero, allocs extra space for mips and computes them
921 int bm_AllocLoadBitmapcxx . . $ bm_AllocLoadBitmap(9615a1d56f56ba5b).(CFILEcxx . . $ CFILE# *infile, int mipped, int format) {
922 char name[BITMAP_NAME_LENcxx . . $ `lib/bitmap.h:41:9`!];
923 int n, src_bm;
924 if (!Bitmaps_inittedcxx . . $ Bitmaps_initted.) {
925 Int3cxx . . $ `misc/pserror.h:247:9`!();
926 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Bitmaps not initted!!!\n");
927 return -1;
928 }
929
930 // Assume this is an ogf
931
932 src_bm = bm_tga_alloc_filecxx . . $ bm_tga_alloc_file(3b86680ef84cac7b).(infile, name, format);
933 if (src_bm < 0) {
934 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Couldn't load %s.", name);
935 return -1;
936 }
937
938 // Allocate space for our bitmap
939 if (mipped) {
940 if ((bm_mippedcxx . . $ bm_mipped(7864480464b09eea).(src_bm)) == 0) // If we want a mipped but we don't have one
941 {
942 int w = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(src_bm, 0);
943 int h = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(src_bm, 0);
944
945 n = bm_AllocBitmapcxx . . $ bm_AllocBitmap(2326284602b0bb2d).(w, h, mipped * (((w * h * 2) / 3)));
946
947 ASSERTcxx . . $ `misc/pserror.h:246:9`!(n >= 0);
948 GameBitmapscxx . . $ GameBitmaps.[n].formatcxx . . $ bms_bitmap#format. = GameBitmapscxx . . $ GameBitmaps.[src_bm].formatcxx . . $ bms_bitmap#format.;
949 bm_ScaleBitmapToBitmapcxx . . $ bm_ScaleBitmapToBitmap(3e454b8ccf442868).(n, src_bm);
950 bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(src_bm);
951
952 bm_GenerateMipMapscxx . . $ bm_GenerateMipMaps(d4f767463ce0a6b3).(n);
953 } else
954 n = src_bm;
955 } else // If we don't want a mipped
956 {
957 if ((bm_mippedcxx . . $ bm_mipped(7864480464b09eea).(src_bm)) == 0)
958 n = src_bm;
959 else // And this is already mipped
960 {
961 int w = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(src_bm, 0);
962 int h = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(src_bm, 0);
963 uint16_tcxx . . $ uint16_t# *src_data, *dest_data;
964
965 n = bm_AllocBitmapcxx . . $ bm_AllocBitmap(2326284602b0bb2d).(w, h, mipped * (((w * h * 2) / 3)));
966 ASSERTcxx . . $ `misc/pserror.h:246:9`!(n >= 0);
967 src_data = (uint16_tcxx . . $ uint16_t# *)bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(src_bm, 0);
968 dest_data = (uint16_tcxx . . $ uint16_t# *)bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(n, 0);
969 memcpy(dest_data, src_data, w * h * 2);
970
971 bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(src_bm);
972 }
973 }
974 strcpy(GameBitmapscxx . . $ GameBitmaps.[n].namecxx . . $ bms_bitmap#name., name);
975 return n; // We made it!
976 }
977 // Given a handle, makes a big random shape to let you know you are screwed.
978 void bm_MakeBadcxx . . $ bm_MakeBad(d4f767463ce0a6b3).(int handle) {
979 int i, t, limit;
980 uint16_tcxx . . $ uint16_t# *dest;
981 ASSERTcxx . . $ `misc/pserror.h:246:9`!(GameBitmaps[handle].used);
982 if (handle != BAD_BITMAP_HANDLEcxx . . $ `lib/bitmap.h:42:9`!)
983 Int3cxx . . $ `misc/pserror.h:247:9`!(); // hmm, you're assigning a random bitmap to something other than
984 // the default.
985 if (bm_mippedcxx . . $ bm_mipped(7864480464b09eea).(handle))
986 limit = bm_miplevelscxx . . $ bm_miplevels(7864480464b09eea).(handle);
987 else
988 limit = 1;
989 for (i = 0; i < limit; i++) {
990 dest = bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(handle, i);
991
992 for (t = 0; t < bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(handle, i) * bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(handle, i); t++)
993 *dest++ = (OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`! | ps_randcxx . . $ ps_rand(b126dc7c1de90089).());
994 }
995 }
996
997 // Saves a bitmap to an open file. Saves the bitmap as an OUTRAGE_COMPRESSED_OGF.
998 // Returns -1 if something is wrong.
999 int bm_SaveBitmapcxx . . $ bm_SaveBitmap(3041dee38160abc0).(CFILEcxx . . $ CFILE# *fp, int handle) {
1000 uint8_tcxx . . $ uint8_t# dumbbyte = 0, image_type = OUTRAGE_1555_COMPRESSED_MIPPEDcxx . . $ `lib/bitmap.h:35:9`!, pixsize = 32, desc = 8 + 32;
1001 int i, done = 0;
1002 int num_mips;
1003 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Saving bitmap %s...\n", GameBitmaps[handle].name);
1004 if (!GameBitmapscxx . . $ GameBitmaps.[handle].usedcxx . . $ bms_bitmap#used.) {
1005 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "bm_SaveBitmap: Trying to save a bitmap that isn't used!\n");
1006 Int3cxx . . $ `misc/pserror.h:247:9`!();
1007 return -1;
1008 }
1009 if (handle == BAD_BITMAP_HANDLEcxx . . $ `lib/bitmap.h:42:9`!) {
1010 Int3cxx . . $ `misc/pserror.h:247:9`!(); // Hey, you shouldn't be saving this bitmap!
1011 return -1;
1012 }
1013 if (GameBitmapscxx . . $ GameBitmaps.[handle].formatcxx . . $ bms_bitmap#format. == BITMAP_FORMAT_4444cxx . . $ `lib/bitmap.h:57:9`!)
1014 image_type = OUTRAGE_4444_COMPRESSED_MIPPEDcxx . . $ `lib/bitmap.h:34:9`!;
1015 if (!fp) {
1016 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "bm_SaveBitmap: Trying to save a bitmap to a closed file!\n");
1017 Int3cxx . . $ `misc/pserror.h:247:9`!();
1018 return -1;
1019 }
1020 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, dumbbyte);
1021 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, dumbbyte);
1022 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, image_type);
1023 cf_WriteStringcxx . . $ cf_WriteString(643e1411966bd56c).(fp, GameBitmapscxx . . $ GameBitmaps.[handle].namecxx . . $ bms_bitmap#name.);
1024
1025 if ((bm_mippedcxx . . $ bm_mipped(7864480464b09eea).(handle)))
1026 num_mips = bm_miplevelscxx . . $ bm_miplevels(7864480464b09eea).(handle);
1027 else
1028 num_mips = 1;
1029 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, num_mips);
1030 for (i = 0; i < 9; i++)
1031 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, 0);
1032 cf_WriteShortcxx . . $ cf_WriteShort(d7cf1a05aca96fe5).(fp, GameBitmapscxx . . $ GameBitmaps.[handle].widthcxx . . $ bms_bitmap#width.);
1033 cf_WriteShortcxx . . $ cf_WriteShort(d7cf1a05aca96fe5).(fp, GameBitmapscxx . . $ GameBitmaps.[handle].heightcxx . . $ bms_bitmap#height.);
1034 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, pixsize);
1035 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, desc);
1036
1037 // write compressed info
1038 for (int m = 0; m < num_mips; m++) {
1039 int curptr = 0;
1040 int total = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(handle, m) * bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(handle, m);
1041 uint16_tcxx . . $ uint16_t# *src_data = (uint16_tcxx . . $ uint16_t# *)bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(handle, m);
1042 done = 0;
1043 while (!done) {
1044 if (curptr == total) {
1045 done = 1;
1046 continue;
1047 }
1048 ASSERTcxx . . $ `misc/pserror.h:246:9`!(curptr < total);
1049 uint16_tcxx . . $ uint16_t# curpix = src_data[curptr];
1050 uint8_tcxx . . $ uint8_t# count = 1;
1051 while (src_data[curptr + count] == curpix && count < 250 && (curptr + count) < total)
1052 count++;
1053 if (count == 1) {
1054 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, 0);
1055 cf_WriteShortcxx . . $ cf_WriteShort(d7cf1a05aca96fe5).(fp, curpix);
1056 } else {
1057 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, count);
1058 cf_WriteShortcxx . . $ cf_WriteShort(d7cf1a05aca96fe5).(fp, curpix);
1059 }
1060 curptr += count;
1061 }
1062 }
1063
1064 return 1;
1065 }
1066 // Makes sure a bitmap is in memory...if not it attempts to page it in
1067 int bm_MakeBitmapResidentcxx . . $ bm_MakeBitmapResident(7864480464b09eea).(int handle) {
1068 if (GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. & BF_NOT_RESIDENTcxx . . $ `lib/bitmap.h:48:9`!) {
1069 if (bm_page_in_filecxx . . $ bm_page_in_file(7864480464b09eea).(handle) > 0) // DAJ -1FIX
1070 {
1071 GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. &= ~BF_NOT_RESIDENTcxx . . $ `lib/bitmap.h:48:9`!;
1072 GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. |= BF_CHANGEDcxx . . $ `lib/bitmap.h:46:9`! | BF_BRAND_NEWcxx . . $ `lib/bitmap.h:51:9`!;
1073 } else {
1074 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Error paging in bitmap %s!\n", GameBitmaps[handle].name);
1075 return 0;
1076 }
1077 }
1078 return 1;
1079 }
1080 // Saves a bitmap to a file. Saves the bitmap as an OUTRAGE_COMPRESSED_OGF.
1081 // Returns -1 if something is wrong.
1082 int bm_SaveFileBitmapcxx . . $ bm_SaveFileBitmap(220e687f58daa9be).(const stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# &filename, int handle) {
1083 int ret;
1084 CFILEcxx . . $ CFILE# *fp;
1085 if (!GameBitmapscxx . . $ GameBitmaps.[handle].usedcxx . . $ bms_bitmap#used.) {
1086 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "bm_SaveBitmap: Trying to save a bitmap that isn't used!\n");
1087 Int3cxx . . $ `misc/pserror.h:247:9`!();
1088 return -1;
1089 }
1090 if (handle == BAD_BITMAP_HANDLEcxx . . $ `lib/bitmap.h:42:9`!) {
1091 Int3cxx . . $ `misc/pserror.h:247:9`!(); // Hey, you shouldn't be saving this bitmap!
1092 return -1;
1093 }
1094 if (!bm_MakeBitmapResidentcxx . . $ bm_MakeBitmapResident(7864480464b09eea).(handle)) {
1095 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "There was a problem paging this bitmap in!\n");
1096 return -1;
1097 }
1098 fp = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(filename, "wb");
1099
1100 if (!fp) {
1101 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "bm_SaveBitmap: Trying to save a bitmap to a closed file!\n");
1102 Int3cxx . . $ `misc/pserror.h:247:9`!();
1103 return -1;
1104 }
1105 ret = bm_SaveBitmapcxx . . $ bm_SaveBitmap(3041dee38160abc0).(fp, handle);
1106
1107 cfclosecxx . . $ cfclose(3639e799710acb68).(fp);
1108 return ret;
1109 }
1110 // returns a bitmaps width (based on miplevel), else -1 if something is wrong
1111 int bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(int handle, int miplevel) {
1112 int w;
1113 if (!GameBitmapscxx . . $ GameBitmaps.[handle].usedcxx . . $ bms_bitmap#used.) {
1114 Int3cxx . . $ `misc/pserror.h:247:9`!();
1115 return -1;
1116 }
1117 if (GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. & BF_NOT_RESIDENTcxx . . $ `lib/bitmap.h:48:9`!)
1118 if (!bm_MakeBitmapResidentcxx . . $ bm_MakeBitmapResident(7864480464b09eea).(handle))
1119 return 0;
1120 if (!(GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. & BF_MIPMAPPEDcxx . . $ `lib/bitmap.h:47:9`!))
1121 miplevel = 0;
1122 w = GameBitmapscxx . . $ GameBitmaps.[handle].widthcxx . . $ bms_bitmap#width.;
1123 w >>= miplevel;
1124 return (w);
1125 }
1126 // returns a bitmaps height (based on miplevel), else -1 if something is wrong
1127 int bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(int handle, int miplevel) {
1128 int h;
1129 if (!GameBitmapscxx . . $ GameBitmaps.[handle].usedcxx . . $ bms_bitmap#used.) {
1130 Int3cxx . . $ `misc/pserror.h:247:9`!();
1131 return -1;
1132 }
1133 // If this bitmap is not page in, do so!
1134 if (GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. & BF_NOT_RESIDENTcxx . . $ `lib/bitmap.h:48:9`!)
1135 if (!bm_MakeBitmapResidentcxx . . $ bm_MakeBitmapResident(7864480464b09eea).(handle))
1136 return 0;
1137 if (!(GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. & BF_MIPMAPPEDcxx . . $ `lib/bitmap.h:47:9`!))
1138 miplevel = 0;
1139 h = GameBitmapscxx . . $ GameBitmaps.[handle].heightcxx . . $ bms_bitmap#height.;
1140 h >>= miplevel;
1141 return (h);
1142 }
1143
1144 // returns the number of levels of mips a bitmap should have
1145 int bm_miplevelscxx . . $ bm_miplevels(7864480464b09eea).(int handle) {
1146 int levels = 0;
1147 if (!GameBitmapscxx . . $ GameBitmaps.[handle].usedcxx . . $ bms_bitmap#used.) {
1148 Int3cxx . . $ `misc/pserror.h:247:9`!();
1149 return -1;
1150 }
1151 if (GameBitmapscxx . . $ GameBitmaps.[handle].mip_levelscxx . . $ bms_bitmap#mip_levels.)
1152 return GameBitmapscxx . . $ GameBitmaps.[handle].mip_levelscxx . . $ bms_bitmap#mip_levels.;
1153
1154 // If this bitmap is not page in, do so!
1155 if (GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. & BF_NOT_RESIDENTcxx . . $ `lib/bitmap.h:48:9`!)
1156 if (!bm_MakeBitmapResidentcxx . . $ bm_MakeBitmapResident(7864480464b09eea).(handle))
1157 return 0;
1158 if (GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. & BF_MIPMAPPEDcxx . . $ `lib/bitmap.h:47:9`!) {
1159 for (int tmp = GameBitmapscxx . . $ GameBitmaps.[handle].widthcxx . . $ bms_bitmap#width.; tmp > 0; tmp = tmp >> 1) {
1160 levels++;
1161 }
1162 return levels;
1163 }
1164 return 0;
1165 }
1166
1167 // returns a bitmaps mipped status, else -1 if something is wrong
1168 int bm_mippedcxx . . $ bm_mipped(7864480464b09eea).(int handle) {
1169 if (!GameBitmapscxx . . $ GameBitmaps.[handle].usedcxx . . $ bms_bitmap#used.) {
1170 Int3cxx . . $ `misc/pserror.h:247:9`!();
1171 return -1;
1172 }
1173 // If this bitmap is not page in, do so!
1174 if (GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. & BF_NOT_RESIDENTcxx . . $ `lib/bitmap.h:48:9`!)
1175 if (!bm_MakeBitmapResidentcxx . . $ bm_MakeBitmapResident(7864480464b09eea).(handle))
1176 return 0;
1177 if (GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. & BF_MIPMAPPEDcxx . . $ `lib/bitmap.h:47:9`!)
1178 return 1;
1179 return 0;
1180 }
1181 // returns a bitmaps data (based on given miplevel), else NULL if something is wrong
1182 uint16_tcxx . . $ uint16_t# *bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(int handle, int miplevel) {
1183 uint16_tcxx . . $ uint16_t# *d;
1184 int i;
1185 if (!GameBitmapscxx . . $ GameBitmaps.[handle].usedcxx . . $ bms_bitmap#used.) {
1186 Int3cxx . . $ `misc/pserror.h:247:9`!();
1187 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
1188 }
1189
1190 // If this bitmap is not page in, do so!
1191 if (GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. & BF_NOT_RESIDENTcxx . . $ `lib/bitmap.h:48:9`!)
1192 if (!bm_MakeBitmapResidentcxx . . $ bm_MakeBitmapResident(7864480464b09eea).(handle))
1193 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
1194
1195 d = GameBitmapscxx . . $ GameBitmaps.[handle].data16cxx . . $ bms_bitmap#data16.;
1196 for (i = 0; i < miplevel; i++) {
1197 d += (GameBitmapscxx . . $ GameBitmaps.[handle].widthcxx . . $ bms_bitmap#width. >> i) * (GameBitmapscxx . . $ GameBitmaps.[handle].heightcxx . . $ bms_bitmap#height. >> i);
1198 }
1199 return (d);
1200 }
1201 // Given a source bitmap, generates mipmaps for it
1202 void bm_GenerateMipMapscxx . . $ bm_GenerateMipMaps(d4f767463ce0a6b3).(int handle) {
1203 int width = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(handle, 0);
1204 int height = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(handle, 0);
1205 int jump = 2; // how many pixels to jump in x and y on source
1206
1207 // mprintf(0,"We got a mipper! %d \n",handle);
1208
1209 ASSERTcxx . . $ `misc/pserror.h:246:9`!(GameBitmaps[handle].used);
1210 GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. |= BF_MIPMAPPEDcxx . . $ `lib/bitmap.h:47:9`!;
1211
1212 int levels = bm_miplevelscxx . . $ bm_miplevels(7864480464b09eea).(handle);
1213
1214 uint16_tcxx . . $ uint16_t# *destdata;
1215 for (int miplevel = 1; miplevel < levels; miplevel++) {
1216 width /= 2;
1217 height /= 2;
1218
1219 for (int i = 0; i < height; i++) {
1220 int adjheight = (i * jump) * bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(handle, miplevel - 1); // find our y offset
1221
1222 for (int t = 0; t < width; t++) {
1223 int adjwidth = (t * jump); // find our x offset
1224 uint16_tcxx . . $ uint16_t# *srcptr = bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(handle, miplevel - 1);
1225 srcptr += (adjheight + adjwidth);
1226
1227 int rsum, gsum, bsum, asum;
1228 rsum = gsum = bsum = asum = 0;
1229 uint16_tcxx . . $ uint16_t# destpix = 0;
1230 if (GameBitmapscxx . . $ GameBitmaps.[handle].formatcxx . . $ bms_bitmap#format. == BITMAP_FORMAT_1555cxx . . $ `lib/bitmap.h:56:9`!) {
1231 for (int y = 0; y < 2; y++)
1232 for (int x = 0; x < 2; x++) {
1233 uint16_tcxx . . $ uint16_t# pix = srcptr[y * bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(handle, miplevel - 1) + x];
1234 int r = (pix >> 10) & 0x1f;
1235 int g = (pix >> 5) & 0x1f;
1236 int b = (pix & 0x1f);
1237
1238 if (!(pix & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!))
1239 asum++;
1240 else {
1241 rsum += r;
1242 gsum += g;
1243 bsum += b;
1244 }
1245 }
1246 // Average our source pixels
1247 rsum /= 4;
1248 gsum /= 4;
1249 bsum /= 4;
1250 destpix = OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`! | (rsum << 10) | (gsum << 5) | bsum;
1251
1252 if (asum > 2)
1253 destpix = NEW_TRANSPARENT_COLORcxx . . $ `lib/grdefs.h:71:9`!;
1254 } else if (GameBitmapscxx . . $ GameBitmaps.[handle].formatcxx . . $ bms_bitmap#format. == BITMAP_FORMAT_4444cxx . . $ `lib/bitmap.h:57:9`!) {
1255 for (int y = 0; y < 2; y++)
1256 for (int x = 0; x < 2; x++) {
1257 uint16_tcxx . . $ uint16_t# pix = srcptr[y * bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(handle, miplevel - 1) + x];
1258 int a = (pix >> 12) & 0x0f;
1259 int r = (pix >> 8) & 0x0f;
1260 int g = (pix >> 4) & 0x0f;
1261 int b = (pix & 0x0f);
1262
1263 asum += a;
1264 rsum += r;
1265 gsum += g;
1266 bsum += b;
1267 }
1268 // Average our source pixels
1269 rsum /= 4;
1270 gsum /= 4;
1271 bsum /= 4;
1272 asum /= 4;
1273 destpix = (asum << 12) | (rsum << 8) | (gsum << 4) | bsum;
1274 } else {
1275 Int3cxx . . $ `misc/pserror.h:247:9`!();
1276 }
1277 destdata = bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(handle, miplevel);
1278 int sw = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(handle, miplevel);
1279 destdata[(i * sw) + t] = destpix;
1280 }
1281 }
1282 }
1283 }
1284 // Gets bits per pixel for a particular bitmap
1285 // As of 12/30/96 always returns 16
1286 int bm_bppcxx . . $ bm_bpp(7864480464b09eea).(int handle) { return BPP_16cxx . . $ `lib/grdefs.h:61:9`!; }
1287 // Given two bitmaps, scales the data from src to the size of dest
1288 // Not a particularly fast implementation
1289 void bm_ScaleBitmapToBitmapcxx . . $ bm_ScaleBitmapToBitmap(3e454b8ccf442868).(int dest, int src) {
1290 uint16_tcxx . . $ uint16_t# *dp = bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(dest, 0);
1291 uint16_tcxx . . $ uint16_t# *sp = bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(src, 0);
1292 ASSERTcxx . . $ `misc/pserror.h:246:9`!(GameBitmaps[dest].used && dp);
1293 ASSERTcxx . . $ `misc/pserror.h:246:9`!(GameBitmaps[src].used && sp);
1294 int smipped = bm_mippedcxx . . $ bm_mipped(7864480464b09eea).(src);
1295 int dmipped = bm_mippedcxx . . $ bm_mipped(7864480464b09eea).(dest);
1296 int limit;
1297 ASSERTcxx . . $ `misc/pserror.h:246:9`!(smipped == dmipped);
1298 ASSERTcxx . . $ `misc/pserror.h:246:9`!(GameBitmaps[dest].format == GameBitmaps[src].format);
1299
1300 int sw = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(src, 0);
1301 int sh = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(src, 0);
1302 int dw = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(dest, 0);
1303 int dh = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(dest, 0);
1304 int i, t;
1305 uint16_tcxx . . $ uint16_t# *sdata;
1306 uint16_tcxx . . $ uint16_t# *ddata;
1307 if (sw == dw && sh == dh) {
1308 if (smipped)
1309 limit = bm_miplevelscxx . . $ bm_miplevels(7864480464b09eea).(src);
1310 else
1311 limit = 1;
1312 for (i = 0; i < limit; i++) {
1313 sdata = (uint16_tcxx . . $ uint16_t# *)bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(src, i);
1314 ddata = (uint16_tcxx . . $ uint16_t# *)bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(dest, i);
1315 dw = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(dest, i);
1316 dh = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(dest, i);
1317 memcpy(ddata, sdata, dw * dh * sizeof(uint16_tcxx . . $ uint16_t#));
1318 }
1319 return;
1320 }
1321 if (smipped)
1322 limit = bm_miplevelscxx . . $ bm_miplevels(7864480464b09eea).(src);
1323 else
1324 limit = 1;
1325 for (int m = 0; m < limit; m++) {
1326 sw = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(src, m);
1327 sh = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(src, m);
1328 dw = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(dest, m);
1329 dh = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(dest, m);
1330
1331 sdata = (uint16_tcxx . . $ uint16_t# *)bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(src, m);
1332 ddata = (uint16_tcxx . . $ uint16_t# *)bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(dest, m);
1333 // These are our interpolant variables
1334 float xstep = (float)sw / (float)dw;
1335 float ystep = (float)sh / (float)dh;
1336 float xoff = 0;
1337 float yoff = 0;
1338 for (i = 0; i < dh; i++, yoff += ystep) {
1339 for (xoff = 0, t = 0; t < dw; t++, xoff += xstep) {
1340 ddata[i * dw + t] = sdata[(int)yoff * sw + (int)xoff];
1341 }
1342 }
1343 }
1344 GameBitmapscxx . . $ GameBitmaps.[dest].flagscxx . . $ bms_bitmap#flags. |= BF_CHANGEDcxx . . $ `lib/bitmap.h:46:9`!;
1345 }
1346 // given a handle and a miplevel, returns the bytes per bitmap row
1347 int bm_rowsizecxx . . $ bm_rowsize(9b79fb6aee4c0440).(int handle, int miplevel) {
1348 int w;
1349 ASSERTcxx . . $ `misc/pserror.h:246:9`!(GameBitmaps[handle].used > 0);
1350 w = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(handle, miplevel);
1351 w *= 2;
1352 return w;
1353 }
1354 // a function to determine if a pixel in a bitmap is transparent
1355 bool bm_pixel_transparentcxx . . $ bm_pixel_transparent(1432650661211742).(int bm_handle, int x, int y) {
1356 if ((bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(bm_handle, 0)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
1357 return 0; // only check 16bit stuff
1358 uint16_tcxx . . $ uint16_t# *data = bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(bm_handle, 0);
1359 data = data + (bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(bm_handle, 0) * y) + x;
1360 if (GameBitmapscxx . . $ GameBitmaps.[bm_handle].formatcxx . . $ bms_bitmap#format. == BITMAP_FORMAT_4444cxx . . $ `lib/bitmap.h:57:9`!) {
1361 int pix = *data;
1362 if (!(pix >> 12))
1363 return true;
1364 } else {
1365 if (!(*data & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!))
1366 return true;
1367 }
1368 return false;
1369 }
1370 // a function to determine if a pixel in a bitmap is transparent
1371 uint16_tcxx . . $ uint16_t# bm_pixelcxx . . $ bm_pixel(6461fafb79bad5b9).(int bm_handle, int x, int y) {
1372 if ((bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(bm_handle, 0)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
1373 return 0; // only check 16bit stuff
1374 uint16_tcxx . . $ uint16_t# *data = bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(bm_handle, 0);
1375 data = data + (bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(bm_handle, 0) * y) + x;
1376 return *data;
1377 }
1378 // Goes through the bitmap and sees if there is any transparency...if so, flag it!
1379 int bm_SetBitmapIfTransparentcxx . . $ bm_SetBitmapIfTransparent(7864480464b09eea).(int handle) {
1380 if ((bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(handle, 0)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
1381 return 0; // only check 16bit stuff
1382 int w = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(handle, 0);
1383 int h = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(handle, 0);
1384 uint16_tcxx . . $ uint16_t# *data = bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(handle, 0);
1385 if (GameBitmapscxx . . $ GameBitmaps.[handle].formatcxx . . $ bms_bitmap#format. == BITMAP_FORMAT_4444cxx . . $ `lib/bitmap.h:57:9`!) {
1386 for (int i = 0; i < w * h; i++) {
1387 int pix = data[i] >> 12;
1388 if (!pix) {
1389 GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. |= BF_TRANSPARENTcxx . . $ `lib/bitmap.h:45:9`!;
1390 return 1;
1391 }
1392 }
1393 } else {
1394 for (int i = 0; i < w * h; i++) {
1395 if (!(data[i] & OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`!)) {
1396 GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. |= BF_TRANSPARENTcxx . . $ `lib/bitmap.h:45:9`!;
1397 return 1;
1398 }
1399 }
1400 }
1401 return 0;
1402 }
1403
1404 // clears bitmap
1405 void bm_ClearBitmapcxx . . $ bm_ClearBitmap(d4f767463ce0a6b3).(int handle) {
1406 int dx, dy;
1407 // DAJ int rowsize_w = bm_rowsize(handle,0) >> 1;
1408 uint16_tcxx . . $ uint16_t# *bmpdata = bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(handle, 0);
1409 int w = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(handle, 0);
1410 int h = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(handle, 0);
1411 for (dy = 0; dy < h; dy++) {
1412 for (dx = 0; dx < w; dx++)
1413 bmpdata[dx] = NEW_TRANSPARENT_COLORcxx . . $ `lib/grdefs.h:71:9`!;
1414
1415 bmpdata += w;
1416 }
1417 }
1418 // Given a bitmap handle, breaks a bitmap into smaller pieces.
1419 // Note, this routine isn't terrible fast or efficient, and you
1420 // must free the bitmaps returned to you in the bm_array
1421 bool bm_CreateChunkedBitmapcxx . . $ bm_CreateChunkedBitmap(b9fa1b176cbdfaf1).(int bm_handle, chunked_bitmapcxx . . $ chunked_bitmap# *chunk) {
1422 int i;
1423 int *bm_array;
1424 int bw = bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(bm_handle, 0);
1425 int bh = bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(bm_handle, 0);
1426 // determine optimal size of the square bitmaps
1427 float fopt = 128.0f;
1428 int iopt;
1429 // find the smallest dimension and base off that
1430 int smallest = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(bw, bh);
1431 if (smallest <= 32)
1432 fopt = 32;
1433 else if (smallest <= 64)
1434 fopt = 64;
1435 else
1436 fopt = 128;
1437 iopt = (int)fopt;
1438 // Get how many pieces we need across and down
1439 float temp = bw / fopt;
1440 int how_many_across = temp;
1441 if ((temp - how_many_across) > 0)
1442 how_many_across++;
1443 temp = bh / fopt;
1444 int how_many_down = temp;
1445 if ((temp - how_many_down) > 0)
1446 how_many_down++;
1447 ASSERTcxx . . $ `misc/pserror.h:246:9`!(how_many_across > 0);
1448 ASSERTcxx . . $ `misc/pserror.h:246:9`!(how_many_down > 0);
1449 // Allocate memory to hold our list of pieces
1450 bm_array = (int *)mem_malloccxx . . $ `mem/mem.h:79:9`!(how_many_down * how_many_across * sizeof(int));
1451 ASSERTcxx . . $ `misc/pserror.h:246:9`!(bm_array);
1452 for (i = 0; i < how_many_down * how_many_across; i++) {
1453 bm_array[i] = bm_AllocBitmapcxx . . $ bm_AllocBitmap(2326284602b0bb2d).(iopt, iopt, 0);
1454 ASSERTcxx . . $ `misc/pserror.h:246:9`!(bm_array[i] > -1);
1455 // Fill our new pieces with transparency
1456 bm_ClearBitmapcxx . . $ bm_ClearBitmap(d4f767463ce0a6b3).(bm_array[i]);
1457 }
1458 // Now go through our big bitmap and partition it into pieces
1459 uint16_tcxx . . $ uint16_t# *src_data = bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(bm_handle, 0);
1460 uint16_tcxx . . $ uint16_t# *sdata;
1461 uint16_tcxx . . $ uint16_t# *ddata;
1462 int shift;
1463 switch (iopt) {
1464 case 32:
1465 shift = 5;
1466 break;
1467 case 64:
1468 shift = 6;
1469 break;
1470 case 128:
1471 shift = 7;
1472 break;
1473 default:
1474 Int3cxx . . $ `misc/pserror.h:247:9`!(); // Get Jeff
1475 break;
1476 }
1477 int maxx, maxy;
1478 int windex, hindex;
1479 int s_y, s_x, d_y, d_x;
1480 for (hindex = 0; hindex < how_many_down; hindex++) {
1481 for (windex = 0; windex < how_many_across; windex++) {
1482 // loop through the chunks
1483 // find end x and y
1484 if (windex < how_many_across - 1)
1485 maxx = iopt;
1486 else
1487 maxx = bw - (windex << shift);
1488 if (hindex < how_many_down - 1)
1489 maxy = iopt;
1490 else
1491 maxy = bh - (hindex << shift);
1492 // find the starting source x and y
1493 s_x = (windex << shift);
1494 s_y = (hindex << shift);
1495 // get the pointers pointing to the right spot
1496 ddata = bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(bm_array[hindex * how_many_across + windex], 0);
1497 sdata = &src_data[s_y * bw + s_x];
1498 // copy the data
1499 for (d_y = 0; d_y < maxy; d_y++) {
1500 for (d_x = 0; d_x < maxx; d_x++) {
1501 ddata[d_x] = sdata[d_x];
1502 } // end for d_x
1503 sdata += bw;
1504 ddata += iopt;
1505 } // end for d_y
1506 } // end for windex
1507 } // end for hindex
1508 // Sirrah, we're done!
1509 // Tell the calling function how many pieces we have in x and y
1510 chunk->pwcxx . . $ chunked_bitmap#pw. = bw;
1511 chunk->phcxx . . $ chunked_bitmap#ph. = bh;
1512 chunk->wcxx . . $ chunked_bitmap#w. = how_many_across;
1513 chunk->hcxx . . $ chunked_bitmap#h. = how_many_down;
1514 chunk->bm_arraycxx . . $ chunked_bitmap#bm_array. = bm_array;
1515 return true;
1516 }
1517 // destroys a chunked bitmap.
1518 void bm_DestroyChunkedBitmapcxx . . $ bm_DestroyChunkedBitmap(1635f60f4d3c1317).(chunked_bitmapcxx . . $ chunked_bitmap# *chunk) {
1519 int i, num_bmps = chunk->wcxx . . $ chunked_bitmap#w. * chunk->hcxx . . $ chunked_bitmap#h.;
1520 for (i = 0; i < num_bmps; i++)
1521 bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(chunk->bm_arraycxx . . $ chunked_bitmap#bm_array.[i]);
1522 mem_freecxx . . $ `mem/mem.h:80:9`!(chunk->bm_array);
1523 chunk->bm_arraycxx . . $ chunked_bitmap#bm_array. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
1524 }
1525 // Changes the size of a bitmap to a new size
1526 void bm_ChangeSizecxx . . $ bm_ChangeSize(b1146eedae1e1d0b).(int handle, int new_w, int new_h) {
1527 int mipped = bm_mippedcxx . . $ bm_mipped(7864480464b09eea).(handle);
1528 int n;
1529 int mem_used = (GameBitmapscxx . . $ GameBitmaps.[handle].widthcxx . . $ bms_bitmap#width. * GameBitmapscxx . . $ GameBitmaps.[handle].heightcxx . . $ bms_bitmap#height. * 2);
1530 n = bm_AllocBitmapcxx . . $ bm_AllocBitmap(2326284602b0bb2d).(new_w, new_h, mipped * ((new_w * new_h * 2) / 3));
1531 ASSERTcxx . . $ `misc/pserror.h:246:9`!(n >= 0);
1532 if (mipped)
1533 GameBitmapscxx . . $ GameBitmaps.[n].flagscxx . . $ bms_bitmap#flags. |= BF_MIPMAPPEDcxx . . $ `lib/bitmap.h:47:9`!;
1534 if (GameBitmapscxx . . $ GameBitmaps.[handle].formatcxx . . $ bms_bitmap#format. == BITMAP_FORMAT_4444cxx . . $ `lib/bitmap.h:57:9`!)
1535 GameBitmapscxx . . $ GameBitmaps.[n].formatcxx . . $ bms_bitmap#format. = BITMAP_FORMAT_4444cxx . . $ `lib/bitmap.h:57:9`!;
1536
1537 bm_ScaleBitmapToBitmapcxx . . $ bm_ScaleBitmapToBitmap(3e454b8ccf442868).(n, handle);
1538 Bitmap_memory_usedcxx . . $ Bitmap_memory_used. -= mem_used + (mipped * (mem_used / 3));
1539 mem_freecxx . . $ `mem/mem.h:80:9`!(GameBitmaps[handle].data16);
1540 GameBitmapscxx . . $ GameBitmaps.[handle].data16cxx . . $ bms_bitmap#data16. = GameBitmapscxx . . $ GameBitmaps.[n].data16cxx . . $ bms_bitmap#data16.;
1541 GameBitmapscxx . . $ GameBitmaps.[handle].widthcxx . . $ bms_bitmap#width. = new_w;
1542 GameBitmapscxx . . $ GameBitmaps.[handle].heightcxx . . $ bms_bitmap#height. = new_h;
1543 GameBitmapscxx . . $ GameBitmaps.[n].usedcxx . . $ bms_bitmap#used. = 0;
1544 Num_of_bitmapscxx . . $ Num_of_bitmaps.--;
1545 }
1546 // Returns the format of this bitmap
1547 int bm_formatcxx . . $ bm_format(7864480464b09eea).(int handle) {
1548 if (!GameBitmapscxx . . $ GameBitmaps.[handle].usedcxx . . $ bms_bitmap#used.) {
1549 Int3cxx . . $ `misc/pserror.h:247:9`!();
1550 return -1;
1551 }
1552 if (GameBitmapscxx . . $ GameBitmaps.[handle].flagscxx . . $ bms_bitmap#flags. & BF_NOT_RESIDENTcxx . . $ `lib/bitmap.h:48:9`!)
1553 if (!bm_MakeBitmapResidentcxx . . $ bm_MakeBitmapResident(7864480464b09eea).(handle))
1554 return 0;
1555 return (GameBitmapscxx . . $ GameBitmaps.[handle].formatcxx . . $ bms_bitmap#format.);
1556 }