tga.h 2.0 KB

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