Open Source Tomb Raider Engine
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

tga.h 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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;
  32. 9 Colormapped RLE; 10 Unmapped RLE */
  33. unsigned short colormap_index; /*!< Index of first color map entry */
  34. unsigned short colormap_lenght; /*!< Number of color map entries */
  35. unsigned char colormap_bbp; /*!< 16, 24, or 32 bits per pixel format */
  36. unsigned short origin_x; /*!< X coor of lower-left corner */
  37. unsigned short origin_y; /*!< Y coor of lower-left corner */
  38. unsigned short width; /*!< Width in pixels */
  39. unsigned short height; /*!< Height in pixels */
  40. unsigned char bpp; /*!< Number of bits in a pixel index */
  41. unsigned char desc_flags; /*!< Various magic bits */
  42. } tga_t;
  43. /*!
  44. * \brief Check if a file is a valid TGA image
  45. * \param f file to be checked
  46. * \returns 0 if valid, else error condition
  47. */
  48. int tga_check(FILE *f);
  49. /*!
  50. * \brief Load a TGA image from file
  51. * \param f valid image file
  52. * \param image Where the pixmap will be stored (or NULL)
  53. * \param width where the width will be stored
  54. * \param height where the height will be stored
  55. * \param type where the type will be stored (tga_type_t)
  56. * \returns 0 on success, else error condition
  57. */
  58. int tga_load(FILE *f, unsigned char **image,
  59. unsigned int *width, unsigned int *height, char *type);
  60. /*!
  61. * \brief Save a pixel buffer into a file on disk
  62. * \param f file in which image will be saved
  63. * \param image pixmap to be stored
  64. * \param width width of pixmap/image
  65. * \param height height of pixmap/image
  66. * \param type tga_type_t to use
  67. * \returns 0 on success, else error condition
  68. */
  69. int tga_save(FILE *f, unsigned char *image,
  70. unsigned int width, unsigned int height, char type);
  71. /*!
  72. * \brief Save a pixel buffer into a file on disk
  73. * \param image pixmap to be stored
  74. * \param width width of pixmap/image
  75. * \param height height of pixmap/image
  76. * \param type tga_type_t to use
  77. * \param s format string for file path/name
  78. * \returns 0 on success, else error condition
  79. */
  80. int tga_save_filename(unsigned char *image,
  81. unsigned int width, unsigned int height,
  82. char type,
  83. char *s, ...);
  84. #endif