tga.h 2.0 KB

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