Open Source Tomb Raider Engine
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

tga.h 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*!
  2. * \file include/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,
  82. char *s, ...);
  83. #endif