summaryrefslogtreecommitdiff
path: root/externals/stb/stb_image_write.h
diff options
context:
space:
mode:
Diffstat (limited to 'externals/stb/stb_image_write.h')
-rw-r--r--externals/stb/stb_image_write.h297
1 files changed, 297 insertions, 0 deletions
diff --git a/externals/stb/stb_image_write.h b/externals/stb/stb_image_write.h
new file mode 100644
index 000000000..b81082bba
--- /dev/null
+++ b/externals/stb/stb_image_write.h
@@ -0,0 +1,297 @@
1// SPDX-FileCopyrightText: stb http://nothings.org/stb
2// SPDX-License-Identifier: MIT
3
4/* stb_image_write - v1.16 - public domain - http://nothings.org/stb
5 writes out PNG/BMP/TGA/JPEG/HDR images to C stdio - Sean Barrett 2010-2015
6 no warranty implied; use at your own risk
7
8 Before #including,
9
10 #define STB_IMAGE_WRITE_IMPLEMENTATION
11
12 in the file that you want to have the implementation.
13
14 Will probably not work correctly with strict-aliasing optimizations.
15
16ABOUT:
17
18 This header file is a library for writing images to C stdio or a callback.
19
20 The PNG output is not optimal; it is 20-50% larger than the file
21 written by a decent optimizing implementation; though providing a custom
22 zlib compress function (see STBIW_ZLIB_COMPRESS) can mitigate that.
23 This library is designed for source code compactness and simplicity,
24 not optimal image file size or run-time performance.
25
26BUILDING:
27
28 You can #define STBIW_ASSERT(x) before the #include to avoid using assert.h.
29 You can #define STBIW_MALLOC(), STBIW_REALLOC(), and STBIW_FREE() to replace
30 malloc,realloc,free.
31 You can #define STBIW_MEMMOVE() to replace memmove()
32 You can #define STBIW_ZLIB_COMPRESS to use a custom zlib-style compress function
33 for PNG compression (instead of the builtin one), it must have the following signature:
34 unsigned char * my_compress(unsigned char *data, int data_len, int *out_len, int quality);
35 The returned data will be freed with STBIW_FREE() (free() by default),
36 so it must be heap allocated with STBIW_MALLOC() (malloc() by default),
37
38UNICODE:
39
40 If compiling for Windows and you wish to use Unicode filenames, compile
41 with
42 #define STBIW_WINDOWS_UTF8
43 and pass utf8-encoded filenames. Call stbiw_convert_wchar_to_utf8 to convert
44 Windows wchar_t filenames to utf8.
45
46USAGE:
47
48 There are five functions, one for each image file format:
49
50 int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
51 int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
52 int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
53 int stbi_write_jpg(char const *filename, int w, int h, int comp, const void *data, int quality);
54 int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
55
56 void stbi_flip_vertically_on_write(int flag); // flag is non-zero to flip data vertically
57
58 There are also five equivalent functions that use an arbitrary write function. You are
59 expected to open/close your file-equivalent before and after calling these:
60
61 int stbi_write_png_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data, int stride_in_bytes);
62 int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data);
63 int stbi_write_tga_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data);
64 int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const float *data);
65 int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality);
66
67 where the callback is:
68 void stbi_write_func(void *context, void *data, int size);
69
70 You can configure it with these global variables:
71 int stbi_write_tga_with_rle; // defaults to true; set to 0 to disable RLE
72 int stbi_write_png_compression_level; // defaults to 8; set to higher for more compression
73 int stbi_write_force_png_filter; // defaults to -1; set to 0..5 to force a filter mode
74
75
76 You can define STBI_WRITE_NO_STDIO to disable the file variant of these
77 functions, so the library will not use stdio.h at all. However, this will
78 also disable HDR writing, because it requires stdio for formatted output.
79
80 Each function returns 0 on failure and non-0 on success.
81
82 The functions create an image file defined by the parameters. The image
83 is a rectangle of pixels stored from left-to-right, top-to-bottom.
84 Each pixel contains 'comp' channels of data stored interleaved with 8-bits
85 per channel, in the following order: 1=Y, 2=YA, 3=RGB, 4=RGBA. (Y is
86 monochrome color.) The rectangle is 'w' pixels wide and 'h' pixels tall.
87 The *data pointer points to the first byte of the top-left-most pixel.
88 For PNG, "stride_in_bytes" is the distance in bytes from the first byte of
89 a row of pixels to the first byte of the next row of pixels.
90
91 PNG creates output files with the same number of components as the input.
92 The BMP format expands Y to RGB in the file format and does not
93 output alpha.
94
95 PNG supports writing rectangles of data even when the bytes storing rows of
96 data are not consecutive in memory (e.g. sub-rectangles of a larger image),
97 by supplying the stride between the beginning of adjacent rows. The other
98 formats do not. (Thus you cannot write a native-format BMP through the BMP
99 writer, both because it is in BGR order and because it may have padding
100 at the end of the line.)
101
102 PNG allows you to set the deflate compression level by setting the global
103 variable 'stbi_write_png_compression_level' (it defaults to 8).
104
105 HDR expects linear float data. Since the format is always 32-bit rgb(e)
106 data, alpha (if provided) is discarded, and for monochrome data it is
107 replicated across all three channels.
108
109 TGA supports RLE or non-RLE compressed data. To use non-RLE-compressed
110 data, set the global variable 'stbi_write_tga_with_rle' to 0.
111
112 JPEG does ignore alpha channels in input data; quality is between 1 and 100.
113 Higher quality looks better but results in a bigger image.
114 JPEG baseline (no JPEG progressive).
115
116CREDITS:
117
118
119 Sean Barrett - PNG/BMP/TGA
120 Baldur Karlsson - HDR
121 Jean-Sebastien Guay - TGA monochrome
122 Tim Kelsey - misc enhancements
123 Alan Hickman - TGA RLE
124 Emmanuel Julien - initial file IO callback implementation
125 Jon Olick - original jo_jpeg.cpp code
126 Daniel Gibson - integrate JPEG, allow external zlib
127 Aarni Koskela - allow choosing PNG filter
128
129 bugfixes:
130 github:Chribba
131 Guillaume Chereau
132 github:jry2
133 github:romigrou
134 Sergio Gonzalez
135 Jonas Karlsson
136 Filip Wasil
137 Thatcher Ulrich
138 github:poppolopoppo
139 Patrick Boettcher
140 github:xeekworx
141 Cap Petschulat
142 Simon Rodriguez
143 Ivan Tikhonov
144 github:ignotion
145 Adam Schackart
146 Andrew Kensler
147
148LICENSE
149
150 See end of file for license information.
151
152*/
153
154#ifndef INCLUDE_STB_IMAGE_WRITE_H
155#define INCLUDE_STB_IMAGE_WRITE_H
156
157#include <stdlib.h>
158
159// if STB_IMAGE_WRITE_STATIC causes problems, try defining STBIWDEF to 'inline' or 'static inline'
160#ifndef STBIWDEF
161#ifdef STB_IMAGE_WRITE_STATIC
162#define STBIWDEF static
163#else
164#ifdef __cplusplus
165#define STBIWDEF extern "C"
166#else
167#define STBIWDEF extern
168#endif
169#endif
170#endif
171
172#ifndef STB_IMAGE_WRITE_STATIC // C++ forbids static forward declarations
173STBIWDEF int stbi_write_tga_with_rle;
174STBIWDEF int stbi_write_png_compression_level;
175STBIWDEF int stbi_write_force_png_filter;
176#endif
177
178#ifndef STBI_WRITE_NO_STDIO
179STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
180STBIWDEF int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
181STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
182STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
183STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality);
184
185#ifdef STBIW_WINDOWS_UTF8
186STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input);
187#endif
188#endif
189
190typedef void stbi_write_func(void *context, void *data, int size);
191
192STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data, int stride_in_bytes);
193STBIWDEF int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data);
194STBIWDEF int stbi_write_tga_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data);
195STBIWDEF int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const float *data);
196STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality);
197STBIWDEF unsigned char *stbi_write_png_to_mem(const unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len);
198
199STBIWDEF void stbi_flip_vertically_on_write(int flip_boolean);
200
201#endif//INCLUDE_STB_IMAGE_WRITE_H
202
203/* Revision history
204 1.16 (2021-07-11)
205 make Deflate code emit uncompressed blocks when it would otherwise expand
206 support writing BMPs with alpha channel
207 1.15 (2020-07-13) unknown
208 1.14 (2020-02-02) updated JPEG writer to downsample chroma channels
209 1.13
210 1.12
211 1.11 (2019-08-11)
212
213 1.10 (2019-02-07)
214 support utf8 filenames in Windows; fix warnings and platform ifdefs
215 1.09 (2018-02-11)
216 fix typo in zlib quality API, improve STB_I_W_STATIC in C++
217 1.08 (2018-01-29)
218 add stbi__flip_vertically_on_write, external zlib, zlib quality, choose PNG filter
219 1.07 (2017-07-24)
220 doc fix
221 1.06 (2017-07-23)
222 writing JPEG (using Jon Olick's code)
223 1.05 ???
224 1.04 (2017-03-03)
225 monochrome BMP expansion
226 1.03 ???
227 1.02 (2016-04-02)
228 avoid allocating large structures on the stack
229 1.01 (2016-01-16)
230 STBIW_REALLOC_SIZED: support allocators with no realloc support
231 avoid race-condition in crc initialization
232 minor compile issues
233 1.00 (2015-09-14)
234 installable file IO function
235 0.99 (2015-09-13)
236 warning fixes; TGA rle support
237 0.98 (2015-04-08)
238 added STBIW_MALLOC, STBIW_ASSERT etc
239 0.97 (2015-01-18)
240 fixed HDR asserts, rewrote HDR rle logic
241 0.96 (2015-01-17)
242 add HDR output
243 fix monochrome BMP
244 0.95 (2014-08-17)
245 add monochrome TGA output
246 0.94 (2014-05-31)
247 rename private functions to avoid conflicts with stb_image.h
248 0.93 (2014-05-27)
249 warning fixes
250 0.92 (2010-08-01)
251 casts to unsigned char to fix warnings
252 0.91 (2010-07-17)
253 first public release
254 0.90 first internal release
255*/
256
257/*
258------------------------------------------------------------------------------
259This software is available under 2 licenses -- choose whichever you prefer.
260------------------------------------------------------------------------------
261ALTERNATIVE A - MIT License
262Copyright (c) 2017 Sean Barrett
263Permission is hereby granted, free of charge, to any person obtaining a copy of
264this software and associated documentation files (the "Software"), to deal in
265the Software without restriction, including without limitation the rights to
266use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
267of the Software, and to permit persons to whom the Software is furnished to do
268so, subject to the following conditions:
269The above copyright notice and this permission notice shall be included in all
270copies or substantial portions of the Software.
271THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
272IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
273FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
274AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
275LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
276OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
277SOFTWARE.
278------------------------------------------------------------------------------
279ALTERNATIVE B - Public Domain (www.unlicense.org)
280This is free and unencumbered software released into the public domain.
281Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
282software, either in source code form or as a compiled binary, for any purpose,
283commercial or non-commercial, and by any means.
284In jurisdictions that recognize copyright laws, the author or authors of this
285software dedicate any and all copyright interest in the software to the public
286domain. We make this dedication for the benefit of the public at large and to
287the detriment of our heirs and successors. We intend this dedication to be an
288overt act of relinquishment in perpetuity of all present and future rights to
289this software under copyright law.
290THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
291IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
292FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
293AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
294ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
295WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
296------------------------------------------------------------------------------
297*/