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

Function bm_AllocLoadFileBitmap

bitmap/bitmain.cpp:701–861  ·  view source on GitHub ↗

Allocs and loads a bitmap 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

699// Returns -1 if something is wrong
700// If mipped is non-zero, allocs extra space for mips and computes them
701int bm_AllocLoadFileBitmap(const char *fname, int mipped, int format) {
702 CFILE *infile;
703 if (!Bitmaps_initted) {
704 Int3();
705 mprintf(0, "Bitmaps not initted!!!\n");
706 return -1;
707 }
708
709 char name[BITMAP_NAME_LEN];
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 (!cfexist(filename)) {
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 mprintf(0, "Unable to find bitmap %s\n", fname);
727 return -1;
728 }
729 ASSERT(*end_ptr == '\\');
730 end_ptr++;
731 filename = end_ptr;
732 mprintf(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_TestName(filename)) != -1) {
738 mprintf(1, "Found duplicate bitmap %s.\n", GameBitmaps[n].name);
739 old_used = GameBitmaps[n].used;
740 GameBitmaps[n].used = 1;
741 bm_FreeBitmap(n);
742 GameBitmaps[n].used = old_used + 1;
743
744 overlay = 1;
745 }
746 if (!overlay)
747 bm_ChangeEndName(filename, name);
748 else {
749 strcpy(name, GameBitmaps[n].name);
750 }
751 if (strlen(name) > 33) {
752 mprintf(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 = (CFILE *)cfopen(filename, "rb");
757 if (!infile) {
758 mprintf(0, "bm_AllocLoadFileBitmap: Can't open file named %s.\n", filename);

Callers 15

d3d_LoadEnvironmentMapFunction · 0.85
FontKernFunction · 0.85
FontCreateFunction · 0.85
OnImportTinyMethod · 0.85
OnImportSkyMethod · 0.85
OnImportSkyBandMethod · 0.85
ResaveBitmapFunction · 0.85
OnNewMethod · 0.85
CBriefEditMethod · 0.85
SetLayoutBitmapMethod · 0.85

Calls 15

cfexistFunction · 0.85
bm_TestNameFunction · 0.85
bm_FreeBitmapFunction · 0.85
bm_ChangeEndNameFunction · 0.85
cfopenFunction · 0.85
bm_GetFileTypeFunction · 0.85
bm_iff_alloc_fileFunction · 0.85
bm_tga_alloc_fileFunction · 0.85
bm_pcx_alloc_fileFunction · 0.85
cfcloseFunction · 0.85
bm_mippedFunction · 0.85
bm_wFunction · 0.85

Tested by

no test coverage detected