tga.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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_TGA_H
  9. #define IGL_TGA_H
  10. #ifndef IGL_NO_OPENGL
  11. #include "igl_inline.h"
  12. // See license in tga.cpp
  13. /* tga.h - interface for TrueVision (TGA) image file loader */
  14. #include <stdio.h>
  15. #ifdef _WIN32
  16. #include <windows.h>
  17. #endif
  18. #include "OpenGL_convenience.h"
  19. namespace igl
  20. {
  21. typedef struct {
  22. GLsizei width;
  23. GLsizei height;
  24. GLint components;
  25. GLenum format;
  26. GLsizei cmapEntries;
  27. GLenum cmapFormat;
  28. GLubyte *cmap;
  29. GLubyte *pixels;
  30. } gliGenericImage;
  31. typedef struct {
  32. unsigned char idLength;
  33. unsigned char colorMapType;
  34. /* The image type. */
  35. #define TGA_TYPE_MAPPED 1
  36. #define TGA_TYPE_COLOR 2
  37. #define TGA_TYPE_GRAY 3
  38. #define TGA_TYPE_MAPPED_RLE 9
  39. #define TGA_TYPE_COLOR_RLE 10
  40. #define TGA_TYPE_GRAY_RLE 11
  41. unsigned char imageType;
  42. /* Color Map Specification. */
  43. /* We need to separately specify high and low bytes to avoid endianness
  44. and alignment problems. */
  45. unsigned char colorMapIndexLo, colorMapIndexHi;
  46. unsigned char colorMapLengthLo, colorMapLengthHi;
  47. unsigned char colorMapSize;
  48. /* Image Specification. */
  49. unsigned char xOriginLo, xOriginHi;
  50. unsigned char yOriginLo, yOriginHi;
  51. unsigned char widthLo, widthHi;
  52. unsigned char heightLo, heightHi;
  53. unsigned char bpp;
  54. /* Image descriptor.
  55. 3-0: attribute bpp
  56. 4: left-to-right ordering
  57. 5: top-to-bottom ordering
  58. 7-6: zero
  59. */
  60. #define TGA_DESC_ABITS 0x0f
  61. #define TGA_DESC_HORIZONTAL 0x10
  62. #define TGA_DESC_VERTICAL 0x20
  63. unsigned char descriptor;
  64. } TgaHeader;
  65. typedef struct {
  66. unsigned int extensionAreaOffset;
  67. unsigned int developerDirectoryOffset;
  68. #define TGA_SIGNATURE "TRUEVISION-XFILE"
  69. char signature[16];
  70. char dot;
  71. char null;
  72. } TgaFooter;
  73. IGL_INLINE extern gliGenericImage *gliReadTGA(FILE *fp, char *name, int hflip, int vflip);
  74. IGL_INLINE int gli_verbose(int new_verbose);
  75. IGL_INLINE extern int gliVerbose(int newVerbose);
  76. IGL_INLINE void writeTGA( gliGenericImage* image, FILE *fp);
  77. } // end of igl namespace
  78. #ifndef IGL_STATIC_LIBRARY
  79. # include "tga.cpp"
  80. #endif
  81. #endif
  82. #endif