MCPcopy Create free account
hub / github.com/beefytech/Beef / WriteToFile

Method WriteToFile

BeefySysLib/img/BMPData.cpp:476–531  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

474}
475
476bool BMPData::WriteToFile(const StringImpl& path)
477{
478 FILE* file;
479 int16_t magic_number;
480 bmp_file_header_t file_header;
481 bmp_bitmap_info_header_t info_header;
482 unsigned char sample[3], * p;
483 int i, j;
484
485 file = fopen(path.c_str(), "wb");
486 if (!file)
487 {
488 return false;
489 }
490
491 magic_number = BITMAP_MAGIC_NUMBER;
492
493 file_header.size = mWidth * mHeight * 4 + 54;
494 file_header.app_id = 0;
495 file_header.offset = 54;
496
497 info_header.header_size = 40;
498 info_header.width = mWidth;
499 info_header.height = mHeight;
500 info_header.num_planes = 1;
501 info_header.bpp = 24;
502 info_header.compression = 0;
503 info_header.image_size = mWidth * mHeight * 4;
504 info_header.horizontal_resolution = 0;
505 info_header.vertical_resolution = 0;
506 info_header.colors_used = 0;
507 info_header.colors_important = 0;
508
509 fwrite(&magic_number, sizeof(magic_number), 1, file);
510 fwrite(&file_header, sizeof(bmp_file_header_t), 1, file);
511 fwrite(&info_header, sizeof(bmp_bitmap_info_header_t), 1, file);
512
513 p = (unsigned char*)mBits;
514 for (i = 0; i < mHeight; i++)
515 {
516 for (j = 0; j < mWidth; j++)
517 {
518 /* convert RGBA to BGR */
519 sample[2] = *p; p++;
520 sample[1] = *p; p++;
521 sample[0] = *p; p++;
522 p++;
523
524 fwrite(sample, 3, 1, file);
525 }
526 }
527
528 fclose(file);
529
530 return 0;
531}

Callers 3

ConvImageFunction · 0.45
mainFunction · 0.45
Res_WritePNGFunction · 0.45

Calls 1

c_strMethod · 0.45

Tested by

no test coverage detected