MCPcopy Create free account
hub / github.com/Scobalula/Greyhound / FlatStream_LoadBitmap

Function FlatStream_LoadBitmap

src/External/CascLib/src/common/FileStream.cpp:1132–1194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1130}
1131
1132static bool FlatStream_LoadBitmap(TBlockStream * pStream)
1133{
1134 FILE_BITMAP_FOOTER Footer;
1135 ULONGLONG ByteOffset;
1136 LPBYTE FileBitmap;
1137 DWORD BlockCount;
1138 DWORD BitmapSize;
1139
1140 // Do not load the bitmap if we should not have to
1141 if(!(pStream->dwFlags & STREAM_FLAG_USE_BITMAP))
1142 return false;
1143
1144 // Only if the size is greater than size of bitmap footer
1145 if(pStream->Base.File.FileSize > sizeof(FILE_BITMAP_FOOTER))
1146 {
1147 // Load the bitmap footer
1148 ByteOffset = pStream->Base.File.FileSize - sizeof(FILE_BITMAP_FOOTER);
1149 if(pStream->BaseRead(pStream, &ByteOffset, &Footer, sizeof(FILE_BITMAP_FOOTER)))
1150 {
1151 // Make sure that the array is properly BSWAP-ed
1152 BSWAP_ARRAY32_UNSIGNED((PDWORD)(&Footer), sizeof(FILE_BITMAP_FOOTER));
1153
1154 // Verify if there is actually a footer
1155 if(Footer.Signature == ID_FILE_BITMAP_FOOTER && Footer.Version == 0x03)
1156 {
1157 // Get the offset of the bitmap, number of blocks and size of the bitmap
1158 ByteOffset = MAKE_OFFSET64(Footer.MapOffsetHi, Footer.MapOffsetLo);
1159 BlockCount = (DWORD)(((ByteOffset - 1) / Footer.BlockSize) + 1);
1160 BitmapSize = ((BlockCount + 7) / 8);
1161
1162 // Check if the sizes match
1163 if(ByteOffset + BitmapSize + sizeof(FILE_BITMAP_FOOTER) == pStream->Base.File.FileSize)
1164 {
1165 // Allocate space for the bitmap
1166 FileBitmap = CASC_ALLOC<BYTE>(BitmapSize);
1167 if(FileBitmap != NULL)
1168 {
1169 // Load the bitmap bits
1170 if(!pStream->BaseRead(pStream, &ByteOffset, FileBitmap, BitmapSize))
1171 {
1172 CASC_FREE(FileBitmap);
1173 return false;
1174 }
1175
1176 // Update the stream size
1177 pStream->BuildNumber = Footer.BuildNumber;
1178 pStream->StreamSize = ByteOffset;
1179
1180 // Fill the bitmap information
1181 pStream->FileBitmap = FileBitmap;
1182 pStream->BitmapSize = BitmapSize;
1183 pStream->BlockSize = Footer.BlockSize;
1184 pStream->BlockCount = BlockCount;
1185 pStream->IsComplete = FlatStream_CheckFile(pStream);
1186 return true;
1187 }
1188 }
1189 }

Callers 2

FlatStream_CreateMirrorFunction · 0.85
FlatStream_OpenFunction · 0.85

Calls 2

CASC_FREEFunction · 0.85
FlatStream_CheckFileFunction · 0.85

Tested by

no test coverage detected