1 // This file is part of libigl, a simple c++ geometry processing library. 2 // 3 // Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com> 4 // 5 // This Source Code Form is subject to the terms of the Mozilla Public License 6 // v. 2.0. If a copy of the MPL was not distributed with this file, You can 7 // obtain one at http://mozilla.org/MPL/2.0/. 8 #ifndef IGL_OPENGL_TGA_H 9 #define IGL_OPENGL_TGA_H 10 #include "../../igl_inline.h" 11 12 #include "../../opengl2/gl.h" 13 // See license in tga.cpp 14 /* tga.h - interface for TrueVision (TGA) image file loader */ 15 #include <stdio.h> 16 #ifdef _WIN32 17 #include <windows.h> 18 #endif 19 20 namespace igl 21 { 22 namespace opengl 23 { 24 25 typedef struct { 26 27 GLsizei width; 28 GLsizei height; 29 GLint components; 30 GLenum format; 31 32 GLsizei cmapEntries; 33 GLenum cmapFormat; 34 GLubyte *cmap; 35 36 GLubyte *pixels; 37 38 } gliGenericImage; 39 40 typedef struct { 41 unsigned char idLength; 42 unsigned char colorMapType; 43 44 /* The image type. */ 45 #define TGA_TYPE_MAPPED 1 46 #define TGA_TYPE_COLOR 2 47 #define TGA_TYPE_GRAY 3 48 #define TGA_TYPE_MAPPED_RLE 9 49 #define TGA_TYPE_COLOR_RLE 10 50 #define TGA_TYPE_GRAY_RLE 11 51 unsigned char imageType; 52 53 /* Color Map Specification. */ 54 /* We need to separately specify high and low bytes to avoid endianness 55 and alignment problems. */ 56 unsigned char colorMapIndexLo, colorMapIndexHi; 57 unsigned char colorMapLengthLo, colorMapLengthHi; 58 unsigned char colorMapSize; 59 60 /* Image Specification. */ 61 unsigned char xOriginLo, xOriginHi; 62 unsigned char yOriginLo, yOriginHi; 63 64 unsigned char widthLo, widthHi; 65 unsigned char heightLo, heightHi; 66 67 unsigned char bpp; 68 69 /* Image descriptor. 70 3-0: attribute bpp 71 4: left-to-right ordering 72 5: top-to-bottom ordering 73 7-6: zero 74 */ 75 #define TGA_DESC_ABITS 0x0f 76 #define TGA_DESC_HORIZONTAL 0x10 77 #define TGA_DESC_VERTICAL 0x20 78 unsigned char descriptor; 79 80 } TgaHeader; 81 82 typedef struct { 83 unsigned int extensionAreaOffset; 84 unsigned int developerDirectoryOffset; 85 #define TGA_SIGNATURE "TRUEVISION-XFILE" 86 char signature[16]; 87 char dot; 88 char null; 89 } TgaFooter; 90 91 IGL_INLINE extern gliGenericImage *gliReadTGA(FILE *fp, char *name, int hflip, int vflip); 92 IGL_INLINE int gli_verbose(int new_verbose); 93 IGL_INLINE extern int gliVerbose(int newVerbose); 94 95 IGL_INLINE void writeTGA( gliGenericImage* image, FILE *fp); 96 97 98 99 } // end of igl namespace 100 } 101 102 #ifndef IGL_STATIC_LIBRARY 103 # include "tga.cpp" 104 #endif 105 106 #endif 107