tga.h 2.1 KB

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