MCPcopy Create free account
hub / github.com/OpenNFS/OpenNFS / SaveImage

Function SaveImage

src/Util/Utils.cpp:289–330  ·  view source on GitHub ↗

lpBits stand for long pointer bits szPathName : Specifies the pathname -> the file path to save the image lpBits : Specifies the bitmap bits -> the buffer (content of the) image w : Specifies the image width h : Specifies the image height

Source from the content-addressed store, hash-verified

287 // w : Specifies the image width
288 // h : Specifies the image height
289 bool SaveImage(const char *szPathName, void *lpBits, uint16_t w, uint16_t h) {
290 // Create a new file for writing
291 FILE *pFile = fopen(szPathName, "wb"); // wb -> w: writable b: binary, open as writable and binary
292 if (pFile == NULL) {
293 return false;
294 }
295
296 CP_BITMAPINFOHEADER BMIH; // BMP header
297 BMIH.biSize = sizeof(CP_BITMAPINFOHEADER);
298 BMIH.biSizeImage = w * h * 4;
299 // Create the bitmap for this OpenGL context
300 BMIH.biSize = sizeof(CP_BITMAPINFOHEADER);
301 BMIH.biWidth = w;
302 BMIH.biHeight = h;
303 BMIH.biPlanes = 1;
304 BMIH.biBitCount = 32;
305 BMIH.biCompression = CP_BI_RGB;
306
307
308 CP_BITMAPFILEHEADER bmfh; // Other BMP header
309 int nBitsOffset = sizeof(CP_BITMAPFILEHEADER) + BMIH.biSize;
310 int32_t lImageSize = BMIH.biSizeImage;
311 int32_t lFileSize = nBitsOffset + lImageSize;
312 bmfh.bfType = 'B' + ('M' << 8);
313 bmfh.bfOffBits = nBitsOffset;
314 bmfh.bfSize = lFileSize;
315 bmfh.bfReserved1 = bmfh.bfReserved2 = 0;
316
317 // Write the bitmap file header // Saving the first header to file
318 size_t nWrittenFileHeaderSize = fwrite(&bmfh, 1, sizeof(CP_BITMAPFILEHEADER), pFile);
319
320 // And then the bitmap info header // Saving the second header to file
321 size_t nWrittenInfoHeaderSize = fwrite(&BMIH, 1, sizeof(CP_BITMAPINFOHEADER), pFile);
322
323 // Finally, write the image data itself
324 //-- the data represents our drawing // Saving the file content in lpBits to file
325 size_t nWrittenDIBDataSize = fwrite(lpBits, 1, lImageSize, pFile);
326 fclose(pFile); // closing the file.
327
328
329 return true;
330 }
331
332 bool ExtractQFS(const std::string &qfs_input, const std::string &output_dir) {
333 LOG(INFO) << "Extracting QFS file: " << qfs_input << " to " << output_dir;

Callers 1

ExtractPSHFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected