Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

tga.h 2.9KB

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