stb_image_write.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* stb_image_write - v0.98 - public domain - http://nothings.org/stb/stb_image_write.h
  2. writes out PNG/BMP/TGA images to C stdio - Sean Barrett 2010
  3. no warranty implied; use at your own risk
  4. Before #including,
  5. #define STB_IMAGE_WRITE_IMPLEMENTATION
  6. in the file that you want to have the implementation.
  7. Will probably not work correctly with strict-aliasing optimizations.
  8. ABOUT:
  9. This header file is a library for writing images to C stdio. It could be
  10. adapted to write to memory or a general streaming interface; let me know.
  11. The PNG output is not optimal; it is 20-50% larger than the file
  12. written by a decent optimizing implementation. This library is designed
  13. for source code compactness and simplicitly, not optimal image file size
  14. or run-time performance.
  15. BUILDING:
  16. You can #define STBIW_ASSERT(x) before the #include to avoid using assert.h.
  17. You can #define STBIW_MALLOC(), STBIW_REALLOC(), and STBIW_FREE() to replace
  18. malloc,realloc,free.
  19. You can define STBIW_MEMMOVE() to replace memmove()
  20. USAGE:
  21. There are four functions, one for each image file format:
  22. int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
  23. int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
  24. int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
  25. int stbi_write_hdr(char const *filename, int w, int h, int comp, const void *data);
  26. Each function returns 0 on failure and non-0 on success.
  27. The functions create an image file defined by the parameters. The image
  28. is a rectangle of pixels stored from left-to-right, top-to-bottom.
  29. Each pixel contains 'comp' channels of data stored interleaved with 8-bits
  30. per channel, in the following order: 1=Y, 2=YA, 3=RGB, 4=RGBA. (Y is
  31. monochrome color.) The rectangle is 'w' pixels wide and 'h' pixels tall.
  32. The *data pointer points to the first byte of the top-left-most pixel.
  33. For PNG, "stride_in_bytes" is the distance in bytes from the first byte of
  34. a row of pixels to the first byte of the next row of pixels.
  35. PNG creates output files with the same number of components as the input.
  36. The BMP format expands Y to RGB in the file format and does not
  37. output alpha.
  38. PNG supports writing rectangles of data even when the bytes storing rows of
  39. data are not consecutive in memory (e.g. sub-rectangles of a larger image),
  40. by supplying the stride between the beginning of adjacent rows. The other
  41. formats do not. (Thus you cannot write a native-format BMP through the BMP
  42. writer, both because it is in BGR order and because it may have padding
  43. at the end of the line.)
  44. HDR expects linear float data. Since the format is always 32-bit rgb(e)
  45. data, alpha (if provided) is discarded, and for monochrome data it is
  46. replicated across all three channels.
  47. CREDITS:
  48. PNG/BMP/TGA
  49. Sean Barrett
  50. HDR
  51. Baldur Karlsson
  52. TGA monochrome:
  53. Jean-Sebastien Guay
  54. misc enhancements:
  55. Tim Kelsey
  56. bugfixes:
  57. github:Chribba
  58. */
  59. #ifndef INCLUDE_STB_IMAGE_WRITE_H
  60. #define INCLUDE_STB_IMAGE_WRITE_H
  61. #ifdef __cplusplus
  62. extern "C" {
  63. #endif
  64. extern int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
  65. extern int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
  66. extern int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
  67. extern int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
  68. #ifdef __cplusplus
  69. }
  70. #endif
  71. #endif//INCLUDE_STB_IMAGE_WRITE_H