tga.h 2.3 KB

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