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