TextureCompiler.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #pragma once
  24. #include "Compiler.h"
  25. #include "TextureResource.h"
  26. namespace crown
  27. {
  28. struct TGAHeader
  29. {
  30. char id_length; // 00h Size of Image ID field
  31. char color_map_type; // 01h Color map type
  32. char image_type; // 02h Image type code
  33. char c_map_spec[5]; // 03h Color map origin 05h Color map length 07h Depth of color map entries
  34. uint16_t x_offset; // 08h X origin of image
  35. uint16_t y_offset; // 0Ah Y origin of image
  36. uint16_t width; // 0Ch Width of image
  37. uint16_t height; // 0Eh Height of image
  38. char pixel_depth; // 10h Image pixel size
  39. char image_descriptor; // 11h Image descriptor byte
  40. };
  41. class CE_EXPORT TextureCompiler : public Compiler
  42. {
  43. public:
  44. TextureCompiler();
  45. ~TextureCompiler();
  46. size_t compile_impl(Filesystem& fs, const char* resource_path);
  47. void write_impl(File* out_file);
  48. private:
  49. void load_uncompressed(File* in_file);
  50. void load_compressed(File* in_file);
  51. void swap_red_blue();
  52. private:
  53. TGAHeader m_tga_header;
  54. uint32_t m_tga_channels;
  55. uint32_t m_tga_size;
  56. TextureHeader m_texture_header;
  57. size_t m_texture_data_size;
  58. uint8_t* m_texture_data;
  59. };
  60. } // namespace crown