| 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 | |
| 19 | #ifndef PSBITMAP_H |
| 20 | #define PSBITMAP_Hcxx . . $ `lib/bitmap.h:20:9`! |
| 21 | |
| 22 | #include <filesystem> |
| 23 | |
| 24 | #include "cfile.h"cxx . . $ `<file>/cfile/cfile.h`/ |
| 25 | |
| 26 | #if defined(POSIXcxx . . $ `<built-in>:480:9`!) |
| 27 | #include "linux_fix.h"cxx . . $ `<file>/linux/linux_fix.h`/ //needed for stricmp's throughout bitmap lib |
| 28 | #endif |
| 29 | |
| 30 | #define MAX_BITMAPScxx . . $ `lib/bitmap.h:30:9`! 5000 |
| 31 | #define NUM_MIP_LEVELScxx . . $ `lib/bitmap.h:31:9`! 5 |
| 32 | |
| 33 | // It really doesn't matter what these are, as long as its above 10 |
| 34 | #define OUTRAGE_4444_COMPRESSED_MIPPEDcxx . . $ `lib/bitmap.h:34:9`! 121 |
| 35 | #define OUTRAGE_1555_COMPRESSED_MIPPEDcxx . . $ `lib/bitmap.h:35:9`! 122 |
| 36 | #define OUTRAGE_NEW_COMPRESSED_MIPPEDcxx . . $ `lib/bitmap.h:36:9`! 123 |
| 37 | #define OUTRAGE_COMPRESSED_MIPPEDcxx . . $ `lib/bitmap.h:37:9`! 124 |
| 38 | #define OUTRAGE_COMPRESSED_OGF_8BITcxx . . $ `lib/bitmap.h:38:9`! 125 |
| 39 | #define OUTRAGE_TGA_TYPEcxx . . $ `lib/bitmap.h:39:9`! 126 |
| 40 | #define OUTRAGE_COMPRESSED_OGFcxx . . $ `lib/bitmap.h:40:9`! 127 |
| 41 | #define BITMAP_NAME_LENcxx . . $ `lib/bitmap.h:41:9`! 35 |
| 42 | #define BAD_BITMAP_HANDLEcxx . . $ `lib/bitmap.h:42:9`! 0 |
| 43 | |
| 44 | // Bitmap flags |
| 45 | #define BF_TRANSPARENTcxx . . $ `lib/bitmap.h:45:9`! 1 |
| 46 | #define BF_CHANGEDcxx . . $ `lib/bitmap.h:46:9`! 2 // this bitmap has changed since last frame (useful for hardware cacheing) |
| 47 | #define BF_MIPMAPPEDcxx . . $ `lib/bitmap.h:47:9`! 4 // This bitmap has mip levels |
| 48 | #define BF_NOT_RESIDENTcxx . . $ `lib/bitmap.h:48:9`! 8 // This bitmap is not paged in |
| 49 | #define BF_WANTS_MIPcxx . . $ `lib/bitmap.h:49:9`! 16 // Calculate mip levels when this bitmap is paged in |
| 50 | #define BF_WANTS_4444cxx . . $ `lib/bitmap.h:50:9`! 32 // Read data as 4444 when this bitmap is paged in |
| 51 | #define BF_BRAND_NEWcxx . . $ `lib/bitmap.h:51:9`! 64 // This bitmap was just allocated and hasn't been to the video card |
| 52 | #define BF_COMPRESSABLEcxx . . $ `lib/bitmap.h:52:9`! 128 // This bitmap is compressable for 3dhardware that supports it |
| 53 | |
| 54 | // Bitmap priorities |
| 55 | #define BITMAP_FORMAT_STANDARDcxx . . $ `lib/bitmap.h:55:9`! 0 |
| 56 | #define BITMAP_FORMAT_1555cxx . . $ `lib/bitmap.h:56:9`! 0 |
| 57 | #define BITMAP_FORMAT_4444cxx . . $ `lib/bitmap.h:57:9`! 1 |
| 58 | |
| 59 | struct bms_bitmapcxx . . $ bms_bitmap# { |
| 60 | uint16_tcxx . . $ uint16_t# *data16cxx . . $ bms_bitmap#data16.; // 16bit data |
| 61 | uint16_tcxx . . $ uint16_t# widthcxx . . $ bms_bitmap#width., heightcxx . . $ bms_bitmap#height.; // Width and height in pixels |
| 62 | uint16_tcxx . . $ uint16_t# usedcxx . . $ bms_bitmap#used.; // Is this bitmap free to be allocated? |
| 63 | |
| 64 | int16_tcxx . . $ int16_t# cache_slotcxx . . $ bms_bitmap#cache_slot.; // For use by the rendering lib |
| 65 | uint8_tcxx . . $ uint8_t# mip_levelscxx . . $ bms_bitmap#mip_levels.; |
| 66 | uint8_tcxx . . $ uint8_t# flagscxx . . $ bms_bitmap#flags.; |
| 67 | |
| 68 | uint8_tcxx . . $ uint8_t# formatcxx . . $ bms_bitmap#format.; // See bitmap format types above |
| 69 | char namecxx . . $ bms_bitmap#name.[BITMAP_NAME_LENcxx . . $ `lib/bitmap.h:41:9`!]; // Whats the name of this bitmap? (ie SteelWall) |
| 70 | }; |
| 71 | |
| 72 | struct chunked_bitmapcxx . . $ chunked_bitmap# { |
| 73 | int pwcxx . . $ chunked_bitmap#pw., phcxx . . $ chunked_bitmap#ph.; // pixel width and height |
| 74 | int wcxx . . $ chunked_bitmap#w., hcxx . . $ chunked_bitmap#h.; // width and height in square bitmaps. |
| 75 | int *bm_arraycxx . . $ chunked_bitmap#bm_array.; // array of bitmap handles. |
| 76 | }; |
| 77 | extern bms_bitmapcxx . . $ bms_bitmap# GameBitmapscxx . . $ GameBitmaps.[MAX_BITMAPScxx . . $ `lib/bitmap.h:30:9`!]; |
| 78 | extern uint32_tcxx . . $ uint32_t# Bitmap_memory_usedcxx . . $ Bitmap_memory_used.; |
| 79 | |
| 80 | // Sets all the bitmaps to unused |
| 81 | void bm_InitBitmapscxx . . $ bm_InitBitmaps(49f6e7a06ebc5aa8).(); |
| 82 | // Frees up all memory used by bitmaps |
| 83 | void bm_ShutdownBitmapscxx . . $ bm_ShutdownBitmaps(49f6e7a06ebc5aa8).(void); |
| 84 | // Allocs a bitmap of w x h size |
| 85 | // If add_mem is nonzero, adds that to the amount alloced |
| 86 | // (added due to the way the tmapper works) |
| 87 | // Returns bitmap handle if successful, -1 if otherwise |
| 88 | int bm_AllocBitmapcxx . . $ bm_AllocBitmap(2326284602b0bb2d).(int w, int h, int add_mem); |
| 89 | // Given a handle, frees the bitmap memory and flags this bitmap as unused |
| 90 | void bm_FreeBitmapcxx . . $ bm_FreeBitmap(d4f767463ce0a6b3).(int handle); |
| 91 | // Allocs and loads a bitmap |
| 92 | // Loads either regular TGAs or OUTRAGE_TGA_TYPEs |
| 93 | // Returns the handle of the loaded bitmap |
| 94 | // Returns -1 if something is wrong |
| 95 | int bm_AllocLoadFileBitmapcxx . . $ bm_AllocLoadFileBitmap(1163be050dbfff7).(const char *filename, int mipped, int format = BITMAP_FORMAT_1555cxx . . $ `lib/bitmap.h:56:9`!); |
| 96 | // Allocs and loads a bitmap from an open file |
| 97 | // Returns the handle of the loaded bitmap |
| 98 | // Returns -1 if something is wrong |
| 99 | // If mipped is non-zero, allocs extra space for mips and computes them |
| 100 | int bm_AllocLoadBitmapcxx . . $ bm_AllocLoadBitmap(9615a1d56f56ba5b).(CFILEcxx . . $ CFILE# *infile, int mipped, int format = BITMAP_FORMAT_1555cxx . . $ `lib/bitmap.h:56:9`!); |
| 101 | // Given a handle, makes a big random shape to let you know you are screwed. |
| 102 | void bm_MakeBadcxx . . $ bm_MakeBad(d4f767463ce0a6b3).(int handle); |
| 103 | // Searches thru all bitmaps for a specific name, returns -1 if not found |
| 104 | // or index of bitmap with name |
| 105 | int bm_FindBitmapNamecxx . . $ bm_FindBitmapName(5c4306d8553b3696).(const char *name); |
| 106 | // Saves a bitmap as an OUTRAGE_TGA_TYPE to an open file |
| 107 | // Returns -1 if something is wrong. |
| 108 | int bm_SaveBitmapcxx . . $ bm_SaveBitmap(3041dee38160abc0).(CFILEcxx . . $ CFILE# *fp, int handle); |
| 109 | // Saves a bitmap to a file. Saves the bitmap as an OUTRAGE_TGA_TYPE. |
| 110 | // Returns -1 if something is wrong. |
| 111 | int bm_SaveFileBitmapcxx . . $ bm_SaveFileBitmap(220e687f58daa9be).(const stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path#& filename, int handle); |
| 112 | // given a handle to a bitmap, returns its width, or -1 if handle is invalid |
| 113 | int bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(int handle, int miplevel); |
| 114 | // given a handle to a bitmap, returns its height, or -1 if handle is invalid |
| 115 | int bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(int handle, int miplevel); |
| 116 | // given a handle to a bitmap, returns mipped status, or -1 if handle is invalid |
| 117 | int bm_mippedcxx . . $ bm_mipped(7864480464b09eea).(int handle); |
| 118 | // a function to determine if a pixel in a bitmap is transparent |
| 119 | bool bm_pixel_transparentcxx . . $ bm_pixel_transparent(1432650661211742).(int bm_handle, int x, int y); |
| 120 | // a function to determine if a pixel in a bitmap is transparent |
| 121 | uint16_tcxx . . $ uint16_t# bm_pixelcxx . . $ bm_pixel(6461fafb79bad5b9).(int bm_handle, int x, int y); |
| 122 | // given a handle to a bitmap, returns a pointer to its data, or NULL if handle is invalid |
| 123 | uint16_tcxx . . $ uint16_t# *bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(int handle, int miplevel); |
| 124 | // Gets bits per pixel for a particular bitmap |
| 125 | // As of 12/30/96 always returns 16 |
| 126 | int bm_bppcxx . . $ bm_bpp(7864480464b09eea).(int handle); |
| 127 | // Given a source bitmap, generates mipmaps for it |
| 128 | void bm_GenerateMipMapscxx . . $ bm_GenerateMipMaps(d4f767463ce0a6b3).(int handle); |
| 129 | // Given two bitmaps, scales the data from src to the size of dest |
| 130 | void bm_ScaleBitmapToBitmapcxx . . $ bm_ScaleBitmapToBitmap(3e454b8ccf442868).(int dest, int src); |
| 131 | // given a handle and a miplevel, returns the bytes per bitmap row |
| 132 | int bm_rowsizecxx . . $ bm_rowsize(9b79fb6aee4c0440).(int handle, int miplevel); |
| 133 | // Goes through the bitmap and sees if there is any transparency...if so, flag it! |
| 134 | int bm_SetBitmapIfTransparentcxx . . $ bm_SetBitmapIfTransparent(7864480464b09eea).(int handle); |
| 135 | // Allocs and loads a bitmap but doesn't actually load texel data! |
| 136 | // Returns the handle of the loaded bitmap |
| 137 | // Returns -1 if something is wrong |
| 138 | int bm_AllocLoadFileNoMemBitmapcxx . . $ bm_AllocLoadFileNoMemBitmap(1163be050dbfff7).(const char *filename, int mipped, int format = BITMAP_FORMAT_1555cxx . . $ `lib/bitmap.h:56:9`!); |
| 139 | // Just like bm_AllocBitmap but doesn't actually allocate memory. Useful for paging! |
| 140 | int bm_AllocNoMemBitmapcxx . . $ bm_AllocNoMemBitmap(9b79fb6aee4c0440).(int w, int h); |
| 141 | // clears bitmap |
| 142 | void bm_ClearBitmapcxx . . $ bm_ClearBitmap(d4f767463ce0a6b3).(int handle); |
| 143 | // Changes the size of a bitmap to a new size |
| 144 | void bm_ChangeSizecxx . . $ bm_ChangeSize(b1146eedae1e1d0b).(int handle, int new_w, int new_h); |
| 145 | void bm_ChangeEndNamecxx . . $ bm_ChangeEndName(611124a97efc52dd).(const char *src, char *dest); |
| 146 | // takes a large static bitmap and breaks it into smaller managable bitmaps |
| 147 | bool bm_CreateChunkedBitmapcxx . . $ bm_CreateChunkedBitmap(b9fa1b176cbdfaf1).(int bm_handle, chunked_bitmapcxx . . $ chunked_bitmap# *chunk); |
| 148 | // destroys a chunked bitmap. |
| 149 | void bm_DestroyChunkedBitmapcxx . . $ bm_DestroyChunkedBitmap(1635f60f4d3c1317).(chunked_bitmapcxx . . $ chunked_bitmap# *chunk); |
| 150 | // simply frees up a bitmap |
| 151 | void bm_FreeBitmapDatacxx . . $ bm_FreeBitmapData(d4f767463ce0a6b3).(int handle); |
| 152 | // Returns the format of this bitmap |
| 153 | int bm_formatcxx . . $ bm_format(7864480464b09eea).(int handle); |
| 154 | // Returns the number of mipmap levels |
| 155 | int bm_miplevelscxx . . $ bm_miplevels(7864480464b09eea).(int handle); |
| 156 | |
| 157 | #endif |