Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tga.h 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*!
  2. * \file include/utils/tga.h
  3. * \brief TGA image reader/writer
  4. *
  5. * \author Mongoose
  6. * \author xythobuz
  7. */
  8. #ifndef _UTILS_TGA_H
  9. #define _UTILS_TGA_H
  10. #ifdef WIN32
  11. #define __attribute__(x)
  12. #endif
  13. /*!
  14. * \brief Possible TGA image types
  15. */
  16. typedef enum {
  17. TGA_TYPE__NO_DATA = 0,
  18. TGA_TYPE__MAPPED = 1,
  19. TGA_TYPE__COLOR = 2,
  20. TGA_TYPE__GREYSCALE = 3,
  21. TGA_TYPE__MAPPED_RLE = 9,
  22. TGA_TYPE__COLOR_RLE = 10
  23. // TGA_TYPE__GREYSCALE_COMPRESSED = 11,
  24. // TGA_TYPE__COLOR_HUFFMAN_DELTA_RLE = 32,
  25. // TGA_TYPE__COLOR_HUFFMAN_DELTA_RLE_4PASS = 33
  26. } tga_type_t;
  27. /*!
  28. * \brief Data structure representing TGA file header
  29. */
  30. typedef struct {
  31. unsigned char comment_lenght; //!< Number of bytes in comment
  32. unsigned char colormap_type; //!< 0 No colormap; 1 Has colormap
  33. unsigned char image_type; //!< 1 Colormapped; 2 Unmapped; 9 Colormapped RLE; 10 Unmapped RLE
  34. unsigned short colormap_index; //!< Index of first color map entry
  35. unsigned short colormap_lenght; //!< Number of color map entries
  36. unsigned char colormap_bbp; //!< 16, 24, or 32 bits per pixel format
  37. unsigned short origin_x; //!< X coor of lower-left corner
  38. unsigned short origin_y; //!< Y coor of lower-left corner
  39. unsigned short width; //!< Width in pixels
  40. unsigned short height; //!< Height in pixels
  41. unsigned char bpp; //!< Number of bits in a pixel index
  42. unsigned char desc_flags; //!< Various magic bits
  43. } tga_t;
  44. /*!
  45. * \brief Check if a file is a valid TGA image
  46. * \param f file to be checked
  47. * \returns 0 if valid, else error condition
  48. */
  49. int tgaCheck(FILE *f);
  50. /*!
  51. * \brief Load a TGA image from file
  52. * \param f valid image file
  53. * \param image Where the pixmap will be stored (or NULL)
  54. * \param width where the width will be stored
  55. * \param height where the height will be stored
  56. * \param type where the type will be stored (tga_type_t)
  57. * \returns 0 on success, else error condition
  58. */
  59. int tgaLoad(FILE *f, unsigned char **image,
  60. unsigned int *width, unsigned int *height, char *type);
  61. /*!
  62. * \brief Save a pixel buffer into a file on disk
  63. * \param f file in which image will be saved
  64. * \param image pixmap to be stored
  65. * \param width width of pixmap/image
  66. * \param height height of pixmap/image
  67. * \param type tga type to use
  68. * \returns 0 on success, else error condition
  69. */
  70. int tgaSave(FILE *f, unsigned char *image,
  71. unsigned int width, unsigned int height, char type);
  72. /*!
  73. * \brief Save a pixel buffer into a file on disk
  74. * \param image pixmap to be stored
  75. * \param width width of pixmap/image
  76. * \param height height of pixmap/image
  77. * \param type tga type to use
  78. * \param s format string for file path/name
  79. * \returns 0 on success, else error condition
  80. */
  81. int tgaSaveFilename(unsigned char *image,
  82. unsigned int width, unsigned int height,
  83. char type, const char *s, ...)
  84. __attribute__((format(printf, 5, 6)));
  85. #endif