tBitmapIndex PiggyRegisterBitmap (grsBitmap *bmP, const char *name, int bInFile) { tBitmapIndex temp; Assert (gameData.pig.tex.nBitmaps [gameStates.app.bD1Data] < MAX_BITMAP_FILES); if (strstr (name, "door13")) name = name; temp.index = gameData.pig.tex.nBitmaps [gameStates.app.bD1Data]; if (!bInFile) { #ifdef EDITOR if (FindArg ("-macdata")) swap_0_255 (bmP); #endif if (!bBigPig) gr_bitmap_rle_compress (bmP); nBitmapFilesNew++; } strncpy (gameData.pig.tex.pBitmapFiles [gameData.pig.tex.nBitmaps [gameStates.app.bD1Data]].name, name, 12); HashTableInsert (bitmapNames + gameStates.app.bD1Mission, gameData.pig.tex.pBitmapFiles[gameData.pig.tex.nBitmaps [gameStates.app.bD1Data]].name, gameData.pig.tex.nBitmaps [gameStates.app.bD1Data]); gameData.pig.tex.pBitmaps [gameData.pig.tex.nBitmaps [gameStates.app.bD1Data]] = *bmP; if (!bInFile) { bitmapOffsets [gameStates.app.bD1Data][gameData.pig.tex.nBitmaps [gameStates.app.bD1Data]] = 0; gameData.pig.tex.bitmapFlags [gameStates.app.bD1Data][gameData.pig.tex.nBitmaps [gameStates.app.bD1Data]] = bmP->bmProps.flags; } gameData.pig.tex.nBitmaps [gameStates.app.bD1Data]++; return temp; }
void PiggyBitmapReadD1 ( CFile &cf, grsBitmap *bmP, /* read into this bmP */ int nBmDataOffs, /* specific to file */ tPIGBitmapHeader *bmh, /* header info for bmP */ ubyte **pNextBmP, /* where to write it (if 0, use (ubyte *) D2_ALLOC) */ ubyte *palette, /* what palette the bmP has */ ubyte *colorMap) /* how to translate bmP's colors */ { int zSize, bSwap0255; memset (bmP, 0, sizeof (grsBitmap)); bmP->bmProps.w = bmP->bmProps.rowSize = bmh->width + ((short) (bmh->wh_extra&0x0f)<<8); bmP->bmProps.h = bmh->height + ((short) (bmh->wh_extra&0xf0)<<4); bmP->bmAvgColor = bmh->bmAvgColor; bmP->bmProps.flags |= bmh->flags & BM_FLAGS_TO_COPY; cf.Seek (nBmDataOffs + bmh->offset, SEEK_SET); if (bmh->flags & BM_FLAG_RLE) { zSize = cf.ReadInt (); cf.Seek (-4, SEEK_CUR); } else zSize = bmP->bmProps.h * bmP->bmProps.w; if (pNextBmP) { bmP->bmTexBuf = *pNextBmP; *pNextBmP += zSize; } else { bmP->bmTexBuf = (ubyte *) D2_ALLOC (bmP->bmProps.h * bmP->bmProps.rowSize); UseBitmapCache (bmP, (int) bmP->bmProps.h * (int) bmP->bmProps.rowSize); } cf.Read (bmP->bmTexBuf, 1, zSize); bSwap0255 = 0; switch (cf.Length ()) { case D1_MAC_PIGSIZE: case D1_MAC_SHARE_PIGSIZE: if (bmh->flags & BM_FLAG_RLE) bSwap0255 = 1; else swap_0_255 (bmP); } if (bmh->flags & BM_FLAG_RLE) rle_expand (bmP, NULL, bSwap0255); GrRemapBitmapGood (bmP, d1Palette, TRANSPARENCY_COLOR, -1); }
void piggy_bitmap_page_in( bitmap_index bitmap ) { grs_bitmap * bmp; int i,org_i; org_i = 0; i = bitmap.index; Assert( i >= 0 ); Assert( i < MAX_BITMAP_FILES ); Assert( i < Num_bitmap_files ); Assert( Piggy_bitmap_cache_size > 0 ); if ( i < 1 ) return; if ( i >= MAX_BITMAP_FILES ) return; if ( i >= Num_bitmap_files ) return; if ( GameBitmapOffset[i] == 0 ) return; // A read-from-disk bitmap!!! if ( GameArg.SysLowMem ) { org_i = i; i = GameBitmapXlat[i]; // Xlat for low-memory settings! } bmp = &GameBitmaps[i]; if ( bmp->bm_flags & BM_FLAG_PAGED_OUT ) { stop_time(); ReDoIt: descent_critical_error = 0; PHYSFSX_fseek( Piggy_fp, GameBitmapOffset[i], SEEK_SET ); if ( descent_critical_error ) { piggy_critical_error(); goto ReDoIt; } gr_set_bitmap_flags (bmp, GameBitmapFlags[i]); gr_set_bitmap_data (bmp, &Piggy_bitmap_cache_data [Piggy_bitmap_cache_next]); if ( bmp->bm_flags & BM_FLAG_RLE ) { int zsize = 0; descent_critical_error = 0; zsize = PHYSFSX_readInt(Piggy_fp); if ( descent_critical_error ) { piggy_critical_error(); goto ReDoIt; } // GET JOHN NOW IF YOU GET THIS ASSERT!!! Assert( Piggy_bitmap_cache_next+zsize < Piggy_bitmap_cache_size ); if ( Piggy_bitmap_cache_next+zsize >= Piggy_bitmap_cache_size ) { piggy_bitmap_page_out_all(); goto ReDoIt; } memcpy( &Piggy_bitmap_cache_data[Piggy_bitmap_cache_next], &zsize, sizeof(int) ); Piggy_bitmap_cache_next += sizeof(int); descent_critical_error = 0; PHYSFS_read( Piggy_fp, &Piggy_bitmap_cache_data[Piggy_bitmap_cache_next], 1, zsize-4 ); if ( descent_critical_error ) { piggy_critical_error(); goto ReDoIt; } if (MacPig) { rle_swap_0_255(bmp); memcpy(&zsize, bmp->bm_data, 4); } Piggy_bitmap_cache_next += zsize-4; } else { // GET JOHN NOW IF YOU GET THIS ASSERT!!! Assert( Piggy_bitmap_cache_next+(bmp->bm_h*bmp->bm_w) < Piggy_bitmap_cache_size ); if ( Piggy_bitmap_cache_next+(bmp->bm_h*bmp->bm_w) >= Piggy_bitmap_cache_size ) { piggy_bitmap_page_out_all(); goto ReDoIt; } descent_critical_error = 0; PHYSFS_read( Piggy_fp, &Piggy_bitmap_cache_data[Piggy_bitmap_cache_next], 1, bmp->bm_h*bmp->bm_w ); if ( descent_critical_error ) { piggy_critical_error(); goto ReDoIt; } if (MacPig) swap_0_255(bmp); Piggy_bitmap_cache_next+=bmp->bm_h*bmp->bm_w; } #ifdef BITMAP_SELECTOR if ( bmp->bm_selector ) { if (!dpmi_modify_selector_base( bmp->bm_selector, bmp->bm_data )) Error( "Error modifying selector base in piggy.c\n" ); } #endif compute_average_rgb(bmp, bmp->avg_color_rgb); start_time(); } if ( GameArg.SysLowMem ) { if ( org_i != i ) GameBitmaps[org_i] = GameBitmaps[i]; } }