| 1 | /**************************************************************************/ | 
|---|
| 2 | /*  image_loader_tga.h                                                    */ | 
|---|
| 3 | /**************************************************************************/ | 
|---|
| 4 | /*                         This file is part of:                          */ | 
|---|
| 5 | /*                             GODOT ENGINE                               */ | 
|---|
| 6 | /*                        https://godotengine.org                         */ | 
|---|
| 7 | /**************************************************************************/ | 
|---|
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | 
|---|
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */ | 
|---|
| 10 | /*                                                                        */ | 
|---|
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining  */ | 
|---|
| 12 | /* a copy of this software and associated documentation files (the        */ | 
|---|
| 13 | /* "Software"), to deal in the Software without restriction, including    */ | 
|---|
| 14 | /* without limitation the rights to use, copy, modify, merge, publish,    */ | 
|---|
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to     */ | 
|---|
| 16 | /* permit persons to whom the Software is furnished to do so, subject to  */ | 
|---|
| 17 | /* the following conditions:                                              */ | 
|---|
| 18 | /*                                                                        */ | 
|---|
| 19 | /* The above copyright notice and this permission notice shall be         */ | 
|---|
| 20 | /* included in all copies or substantial portions of the Software.        */ | 
|---|
| 21 | /*                                                                        */ | 
|---|
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */ | 
|---|
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */ | 
|---|
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | 
|---|
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */ | 
|---|
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */ | 
|---|
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */ | 
|---|
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */ | 
|---|
| 29 | /**************************************************************************/ | 
|---|
| 30 |  | 
|---|
| 31 | #ifndef IMAGE_LOADER_TGA_H | 
|---|
| 32 | #define IMAGE_LOADER_TGA_H | 
|---|
| 33 |  | 
|---|
| 34 | #include "core/io/image_loader.h" | 
|---|
| 35 |  | 
|---|
| 36 | #define TGA_IMAGE_DESCRIPTOR_ALPHA_MASK 0xf | 
|---|
| 37 |  | 
|---|
| 38 | class ImageLoaderTGA : public ImageFormatLoader { | 
|---|
| 39 | enum tga_type_e { | 
|---|
| 40 | TGA_TYPE_NO_DATA = 0, | 
|---|
| 41 | TGA_TYPE_INDEXED = 1, | 
|---|
| 42 | TGA_TYPE_RGB = 2, | 
|---|
| 43 | TGA_TYPE_MONOCHROME = 3, | 
|---|
| 44 | TGA_TYPE_RLE_INDEXED = 9, | 
|---|
| 45 | TGA_TYPE_RLE_RGB = 10, | 
|---|
| 46 | TGA_TYPE_RLE_MONOCHROME = 11 | 
|---|
| 47 | }; | 
|---|
| 48 |  | 
|---|
| 49 | enum tga_origin_e { | 
|---|
| 50 | TGA_ORIGIN_BOTTOM_LEFT = 0x00, | 
|---|
| 51 | TGA_ORIGIN_BOTTOM_RIGHT = 0x01, | 
|---|
| 52 | TGA_ORIGIN_TOP_LEFT = 0x02, | 
|---|
| 53 | TGA_ORIGIN_TOP_RIGHT = 0x03, | 
|---|
| 54 | TGA_ORIGIN_SHIFT = 0x04, | 
|---|
| 55 | TGA_ORIGIN_MASK = 0x30 | 
|---|
| 56 | }; | 
|---|
| 57 |  | 
|---|
| 58 | struct  { | 
|---|
| 59 | uint8_t  = 0; | 
|---|
| 60 | uint8_t  = 0; | 
|---|
| 61 | tga_type_e ; | 
|---|
| 62 |  | 
|---|
| 63 | uint16_t  = 0; | 
|---|
| 64 | uint16_t  = 0; | 
|---|
| 65 | uint8_t  = 0; | 
|---|
| 66 |  | 
|---|
| 67 | uint16_t  = 0; | 
|---|
| 68 | uint16_t  = 0; | 
|---|
| 69 | uint16_t  = 0; | 
|---|
| 70 | uint16_t  = 0; | 
|---|
| 71 | uint8_t  = 0; | 
|---|
| 72 | uint8_t  = 0; | 
|---|
| 73 | }; | 
|---|
| 74 | static Error decode_tga_rle(const uint8_t *p_compressed_buffer, size_t p_pixel_size, uint8_t *p_uncompressed_buffer, size_t p_output_size, size_t p_input_size); | 
|---|
| 75 | static Error (Ref<Image> p_image, const uint8_t *p_buffer, const tga_header_s &, const uint8_t *p_palette, const bool p_is_monochrome, size_t p_input_size); | 
|---|
| 76 |  | 
|---|
| 77 | public: | 
|---|
| 78 | virtual Error load_image(Ref<Image> p_image, Ref<FileAccess> f, BitField<ImageFormatLoader::LoaderFlags> p_flags, float p_scale); | 
|---|
| 79 | virtual void get_recognized_extensions(List<String> *p_extensions) const; | 
|---|
| 80 | ImageLoaderTGA(); | 
|---|
| 81 | }; | 
|---|
| 82 |  | 
|---|
| 83 | #endif // IMAGE_LOADER_TGA_H | 
|---|
| 84 |  | 
|---|