MCPcopy Create free account
hub / github.com/diasurgical/devilution / SBmpLoadImage

Function SBmpLoadImage

SourceX/storm/storm.cpp:194–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192}
193
194BOOL SBmpLoadImage(const char *pszFileName, SDL_Color *pPalette, BYTE *pBuffer, DWORD dwBuffersize, DWORD *pdwWidth, DWORD *dwHeight, DWORD *pdwBpp)
195{
196 HANDLE hFile;
197 size_t size;
198 PCXHEADER pcxhdr;
199 BYTE paldata[256][3];
200 BYTE *dataPtr, *fileBuffer;
201 BYTE byte;
202
203 if (pdwWidth)
204 *pdwWidth = 0;
205 if (dwHeight)
206 *dwHeight = 0;
207 if (pdwBpp)
208 *pdwBpp = 0;
209
210 if (!pszFileName || !*pszFileName) {
211 return false;
212 }
213
214 if (pBuffer && !dwBuffersize) {
215 return false;
216 }
217
218 if (!pPalette && !pBuffer && !pdwWidth && !dwHeight) {
219 return false;
220 }
221
222 if (!SFileOpenFile(pszFileName, &hFile)) {
223 return false;
224 }
225
226 while (strchr(pszFileName, 92))
227 pszFileName = strchr(pszFileName, 92) + 1;
228
229 while (strchr(pszFileName + 1, 46))
230 pszFileName = strchr(pszFileName, 46);
231
232 // omit all types except PCX
233 if (!pszFileName || strcasecmp(pszFileName, ".pcx")) {
234 return false;
235 }
236
237 if (!SFileReadFile(hFile, &pcxhdr, 128, 0, 0)) {
238 SFileCloseFile(hFile);
239 return false;
240 }
241
242 int width = SDL_SwapLE16(pcxhdr.Xmax) - SDL_SwapLE16(pcxhdr.Xmin) + 1;
243 int height = SDL_SwapLE16(pcxhdr.Ymax) - SDL_SwapLE16(pcxhdr.Ymin) + 1;
244
245 // If the given buffer is larger than width * height, assume the extra data
246 // is scanline padding.
247 //
248 // This is useful because in SDL the pitch size is often slightly larger
249 // than image width for efficiency.
250 const int x_skip = dwBuffersize / height - width;
251

Callers 1

LoadArtFunction · 0.85

Calls 5

SFileOpenFileFunction · 0.85
SFileReadFileFunction · 0.85
SFileCloseFileFunction · 0.85
SFileSetFilePointerFunction · 0.85
SFileGetFileSizeFunction · 0.85

Tested by

no test coverage detected