tga.h 2.1 KB

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