stb_image.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #ifndef STBI_INCLUDE_STB_IMAGE_H
  2. #define STBI_INCLUDE_STB_IMAGE_H
  3. #ifndef STBI_NO_STDIO
  4. #include <stdio.h>
  5. #endif // STBI_NO_STDIO
  6. #define STBI_VERSION 1
  7. enum
  8. {
  9. STBI_default = 0, // only used for req_comp
  10. STBI_grey = 1,
  11. STBI_grey_alpha = 2,
  12. STBI_rgb = 3,
  13. STBI_rgb_alpha = 4
  14. };
  15. typedef unsigned char stbi_uc;
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #ifdef STB_IMAGE_STATIC
  20. #define STBIDEF static
  21. #else
  22. #define STBIDEF extern
  23. #endif
  24. //////////////////////////////////////////////////////////////////////////////
  25. //
  26. // PRIMARY API - works on images of any type
  27. //
  28. //
  29. // load image by filename, open file, or memory buffer
  30. //
  31. typedef struct
  32. {
  33. int (*read) (void *user,char *data,int size); // fill 'data' with 'size' bytes. return number of bytes actually read
  34. void (*skip) (void *user,int n); // skip the next 'n' bytes, or 'unget' the last -n bytes if negative
  35. int (*eof) (void *user); // returns nonzero if we are at end of file/data
  36. } stbi_io_callbacks;
  37. STBIDEF stbi_uc *stbi_load (char const *filename, int *x, int *y, int *comp, int req_comp);
  38. STBIDEF stbi_uc *stbi_load_from_memory (stbi_uc const *buffer, int len , int *x, int *y, int *comp, int req_comp);
  39. STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk , void *user, int *x, int *y, int *comp, int req_comp);
  40. #ifndef STBI_NO_STDIO
  41. STBIDEF stbi_uc *stbi_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp);
  42. // for stbi_load_from_file, file pointer is left pointing immediately after image
  43. #endif
  44. #ifndef STBI_NO_LINEAR
  45. STBIDEF float *stbi_loadf (char const *filename, int *x, int *y, int *comp, int req_comp);
  46. STBIDEF float *stbi_loadf_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
  47. STBIDEF float *stbi_loadf_from_callbacks (stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp);
  48. #ifndef STBI_NO_STDIO
  49. STBIDEF float *stbi_loadf_from_file (FILE *f, int *x, int *y, int *comp, int req_comp);
  50. #endif
  51. #endif
  52. #ifndef STBI_NO_HDR
  53. STBIDEF void stbi_hdr_to_ldr_gamma(float gamma);
  54. STBIDEF void stbi_hdr_to_ldr_scale(float scale);
  55. #endif
  56. #ifndef STBI_NO_LINEAR
  57. STBIDEF void stbi_ldr_to_hdr_gamma(float gamma);
  58. STBIDEF void stbi_ldr_to_hdr_scale(float scale);
  59. #endif // STBI_NO_HDR
  60. // stbi_is_hdr is always defined, but always returns false if STBI_NO_HDR
  61. STBIDEF int stbi_is_hdr_from_callbacks(stbi_io_callbacks const *clbk, void *user);
  62. STBIDEF int stbi_is_hdr_from_memory(stbi_uc const *buffer, int len);
  63. #ifndef STBI_NO_STDIO
  64. STBIDEF int stbi_is_hdr (char const *filename);
  65. STBIDEF int stbi_is_hdr_from_file(FILE *f);
  66. #endif // STBI_NO_STDIO
  67. // get a VERY brief reason for failure
  68. // NOT THREADSAFE
  69. STBIDEF const char *stbi_failure_reason (void);
  70. // free the loaded image -- this is just free()
  71. STBIDEF void stbi_image_free (void *retval_from_stbi_load);
  72. // get image dimensions & components without fully decoding
  73. STBIDEF int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp);
  74. STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp);
  75. #ifndef STBI_NO_STDIO
  76. STBIDEF int stbi_info (char const *filename, int *x, int *y, int *comp);
  77. STBIDEF int stbi_info_from_file (FILE *f, int *x, int *y, int *comp);
  78. #endif
  79. // for image formats that explicitly notate that they have premultiplied alpha,
  80. // we just return the colors as stored in the file. set this flag to force
  81. // unpremultiplication. results are undefined if the unpremultiply overflow.
  82. STBIDEF void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply);
  83. // indicate whether we should process iphone images back to canonical format,
  84. // or just pass them through "as-is"
  85. STBIDEF void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert);
  86. // flip the image vertically, so the first pixel in the output array is the bottom left
  87. STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip);
  88. // ZLIB client - used by PNG, available for other purposes
  89. STBIDEF char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen);
  90. STBIDEF char *stbi_zlib_decode_malloc_guesssize_headerflag(const char *buffer, int len, int initial_size, int *outlen, int parse_header);
  91. STBIDEF char *stbi_zlib_decode_malloc(const char *buffer, int len, int *outlen);
  92. STBIDEF int stbi_zlib_decode_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);
  93. STBIDEF char *stbi_zlib_decode_noheader_malloc(const char *buffer, int len, int *outlen);
  94. STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);
  95. #ifdef __cplusplus
  96. }
  97. #endif
  98. //
  99. //
  100. //// end header file /////////////////////////////////////////////////////
  101. #endif // STBI_INCLUDE_STB_IMAGE_H