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

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