555 |
jrf |
1 |
/* stbiw-0.92 - 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 |
|
|
|
5 |
|
|
|
6 |
ABOUT:
|
|
|
7 |
|
|
|
8 |
This header file is a library for writing images to C stdio. It could be
|
|
|
9 |
adapted to write to memory or a general streaming interface; let me know.
|
|
|
10 |
|
|
|
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 |
|
|
|
16 |
USAGE:
|
|
|
17 |
|
|
|
18 |
There are three functions, one for each image file format:
|
|
|
19 |
|
|
|
20 |
int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
|
|
|
21 |
int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
|
|
|
22 |
int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
|
|
|
23 |
|
|
|
24 |
Each function returns 0 on failure and non-0 on success.
|
|
|
25 |
|
|
|
26 |
The functions create an image file defined by the parameters. The image
|
|
|
27 |
is a rectangle of pixels stored from left-to-right, top-to-bottom.
|
|
|
28 |
Each pixel contains 'comp' channels of data stored interleaved with 8-bits
|
|
|
29 |
per channel, in the following order: 1=Y, 2=YA, 3=RGB, 4=RGBA. (Y is
|
|
|
30 |
monochrome color.) The rectangle is 'w' pixels wide and 'h' pixels tall.
|
|
|
31 |
The *data pointer points to the first byte of the top-left-most pixel.
|
|
|
32 |
For PNG, "stride_in_bytes" is the distance in bytes from the first byte of
|
|
|
33 |
a row of pixels to the first byte of the next row of pixels.
|
|
|
34 |
|
|
|
35 |
PNG creates output files with the same number of components as the input.
|
|
|
36 |
The BMP and TGA formats expand Y to RGB in the file format. BMP does not
|
|
|
37 |
output alpha.
|
|
|
38 |
|
|
|
39 |
PNG supports writing rectangles of data even when the bytes storing rows of
|
|
|
40 |
data are not consecutive in memory (e.g. sub-rectangles of a larger image),
|
|
|
41 |
by supplying the stride between the beginning of adjacent rows. The other
|
|
|
42 |
formats do not. (Thus you cannot write a native-format BMP through the BMP
|
|
|
43 |
writer, both because it is in BGR order and because it may have padding
|
|
|
44 |
at the end of the line.)
|
|
|
45 |
*/
|
|
|
46 |
|
|
|
47 |
#ifndef INCLUDE_STB_IMAGE_WRITE_H
|
|
|
48 |
#define INCLUDE_STB_IMAGE_WRITE_H
|
|
|
49 |
|
|
|
50 |
#ifdef __cplusplus
|
|
|
51 |
extern "C" {
|
|
|
52 |
#endif
|
|
|
53 |
|
|
|
54 |
extern int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
|
|
|
55 |
extern int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
|
|
|
56 |
extern int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
|
|
|
57 |
|
|
|
58 |
#ifdef __cplusplus
|
|
|
59 |
}
|
|
|
60 |
#endif
|
|
|
61 |
|
|
|
62 |
#endif//INCLUDE_STB_IMAGE_WRITE_H
|
|
|
63 |
|
|
|
64 |
/* Revision history
|
|
|
65 |
|
|
|
66 |
0.92 (2010-08-01)
|
|
|
67 |
casts to unsigned char to fix warnings
|
|
|
68 |
0.91 (2010-07-17)
|
|
|
69 |
first public release
|
|
|
70 |
0.90 first internal release
|
|
|
71 |
*/
|