MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / bm_AllocLoadBitmap

Function bm_AllocLoadBitmap

bitmap/bitmain.cpp:921–976  ·  view source on GitHub ↗

Allocs and loads a bitmap from an open file Returns the handle of the loaded bitmap Returns -1 if something is wrong If mipped is non-zero, allocs extra space for mips and computes them

Source from the content-addressed store, hash-verified

919// Returns -1 if something is wrong
920// If mipped is non-zero, allocs extra space for mips and computes them
921int bm_AllocLoadBitmap(CFILE *infile, int mipped, int format) {
922 char name[BITMAP_NAME_LEN];
923 int n, src_bm;
924 if (!Bitmaps_initted) {
925 Int3();
926 mprintf(0, "Bitmaps not initted!!!\n");
927 return -1;
928 }
929
930 // Assume this is an ogf
931
932 src_bm = bm_tga_alloc_file(infile, name, format);
933 if (src_bm < 0) {
934 mprintf(0, "Couldn't load %s.", name);
935 return -1;
936 }
937
938 // Allocate space for our bitmap
939 if (mipped) {
940 if ((bm_mipped(src_bm)) == 0) // If we want a mipped but we don't have one
941 {
942 int w = bm_w(src_bm, 0);
943 int h = bm_h(src_bm, 0);
944
945 n = bm_AllocBitmap(w, h, mipped * (((w * h * 2) / 3)));
946
947 ASSERT(n >= 0);
948 GameBitmaps[n].format = GameBitmaps[src_bm].format;
949 bm_ScaleBitmapToBitmap(n, src_bm);
950 bm_FreeBitmap(src_bm);
951
952 bm_GenerateMipMaps(n);
953 } else
954 n = src_bm;
955 } else // If we don't want a mipped
956 {
957 if ((bm_mipped(src_bm)) == 0)
958 n = src_bm;
959 else // And this is already mipped
960 {
961 int w = bm_w(src_bm, 0);
962 int h = bm_h(src_bm, 0);
963 uint16_t *src_data, *dest_data;
964
965 n = bm_AllocBitmap(w, h, mipped * (((w * h * 2) / 3)));
966 ASSERT(n >= 0);
967 src_data = (uint16_t *)bm_data(src_bm, 0);
968 dest_data = (uint16_t *)bm_data(n, 0);
969 memcpy(dest_data, src_data, w * h * 2);
970
971 bm_FreeBitmap(src_bm);
972 }
973 }
974 strcpy(GameBitmaps[n].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.
978void bm_MakeBad(int handle) {

Callers 2

PageInVClipFunction · 0.85
LGSSnapshotFunction · 0.85

Calls 9

bm_tga_alloc_fileFunction · 0.85
bm_mippedFunction · 0.85
bm_wFunction · 0.85
bm_hFunction · 0.85
bm_AllocBitmapFunction · 0.85
bm_ScaleBitmapToBitmapFunction · 0.85
bm_FreeBitmapFunction · 0.85
bm_GenerateMipMapsFunction · 0.85
bm_dataFunction · 0.85

Tested by

no test coverage detected