tga.h 2.1 KB

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