utils.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include "video_core/utils.h"
  7. namespace VideoCore {
  8. /**
  9. * Dumps a texture to TGA
  10. * @param filename String filename to dump texture to
  11. * @param width Width of texture in pixels
  12. * @param height Height of texture in pixels
  13. * @param raw_data Raw RGBA8 texture data to dump
  14. * @todo This should be moved to some general purpose/common code
  15. */
  16. void DumpTGA(std::string filename, short width, short height, u8* raw_data) {
  17. TGAHeader hdr = {0, 0, 2, 0, 0, 0, 0, width, height, 24, 0};
  18. FILE* fout = fopen(filename.c_str(), "wb");
  19. fwrite(&hdr, sizeof(TGAHeader), 1, fout);
  20. for (int y = 0; y < height; y++) {
  21. for (int x = 0; x < width; x++) {
  22. putc(raw_data[(3 * (y * width)) + (3 * x) + 0], fout); // b
  23. putc(raw_data[(3 * (y * width)) + (3 * x) + 1], fout); // g
  24. putc(raw_data[(3 * (y * width)) + (3 * x) + 2], fout); // r
  25. }
  26. }
  27. fclose(fout);
  28. }
  29. } // namespace