diff options
Diffstat (limited to 'src/video_core/utils.cpp')
| -rw-r--r-- | src/video_core/utils.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/video_core/utils.cpp b/src/video_core/utils.cpp new file mode 100644 index 000000000..a6dd1e02c --- /dev/null +++ b/src/video_core/utils.cpp | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <stdio.h> | ||
| 6 | #include <string.h> | ||
| 7 | |||
| 8 | #include "utils.h" | ||
| 9 | |||
| 10 | namespace VideoCore { | ||
| 11 | |||
| 12 | /** | ||
| 13 | * Dumps a texture to TGA | ||
| 14 | * @param filename String filename to dump texture to | ||
| 15 | * @param width Width of texture in pixels | ||
| 16 | * @param height Height of texture in pixels | ||
| 17 | * @param raw_data Raw RGBA8 texture data to dump | ||
| 18 | * @todo This should be moved to some general purpose/common code | ||
| 19 | */ | ||
| 20 | void DumpTGA(std::string filename, int width, int height, u8* raw_data) { | ||
| 21 | TGAHeader hdr; | ||
| 22 | FILE* fout; | ||
| 23 | u8 r, g, b; | ||
| 24 | |||
| 25 | memset(&hdr, 0, sizeof(hdr)); | ||
| 26 | hdr.datatypecode = 2; // uncompressed RGB | ||
| 27 | hdr.bitsperpixel = 24; // 24 bpp | ||
| 28 | hdr.width = width; | ||
| 29 | hdr.height = height; | ||
| 30 | |||
| 31 | fout = fopen(filename.c_str(), "wb"); | ||
| 32 | fwrite(&hdr, sizeof(TGAHeader), 1, fout); | ||
| 33 | for (int i = 0; i < height; i++) { | ||
| 34 | for (int j = 0; j < width; j++) { | ||
| 35 | r = raw_data[(4 * (i * width)) + (4 * j) + 0]; | ||
| 36 | g = raw_data[(4 * (i * width)) + (4 * j) + 1]; | ||
| 37 | b = raw_data[(4 * (i * width)) + (4 * j) + 2]; | ||
| 38 | putc(b, fout); | ||
| 39 | putc(g, fout); | ||
| 40 | putc(r, fout); | ||
| 41 | } | ||
| 42 | } | ||
| 43 | fclose(fout); | ||
| 44 | } | ||
| 45 | |||
| 46 | } // namespace | ||