utils.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <string>
  6. #include "common/common_types.h"
  7. namespace FormatPrecision {
  8. /// Adjust RGBA8 color with RGBA6 precision
  9. static inline u32 rgba8_with_rgba6(u32 src) {
  10. u32 color = src;
  11. color &= 0xFCFCFCFC;
  12. color |= (color >> 6) & 0x03030303;
  13. return color;
  14. }
  15. /// Adjust RGBA8 color with RGB565 precision
  16. static inline u32 rgba8_with_rgb565(u32 src) {
  17. u32 color = (src & 0xF8FCF8);
  18. color |= (color >> 5) & 0x070007;
  19. color |= (color >> 6) & 0x000300;
  20. color |= 0xFF000000;
  21. return color;
  22. }
  23. /// Adjust Z24 depth value with Z16 precision
  24. static inline u32 z24_with_z16(u32 src) {
  25. return (src & 0xFFFF00) | (src >> 16);
  26. }
  27. } // namespace
  28. namespace VideoCore {
  29. /// Structure for the TGA texture format (for dumping)
  30. struct TGAHeader {
  31. char idlength;
  32. char colourmaptype;
  33. char datatypecode;
  34. short int colourmaporigin;
  35. short int colourmaplength;
  36. short int x_origin;
  37. short int y_origin;
  38. short width;
  39. short height;
  40. char bitsperpixel;
  41. char imagedescriptor;
  42. };
  43. /**
  44. * Dumps a texture to TGA
  45. * @param filename String filename to dump texture to
  46. * @param width Width of texture in pixels
  47. * @param height Height of texture in pixels
  48. * @param raw_data Raw RGBA8 texture data to dump
  49. * @todo This should be moved to some general purpose/common code
  50. */
  51. void DumpTGA(std::string filename, short width, short height, u8* raw_data);
  52. } // namespace