tga.h 2.5 KB

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