Subversion Repositories gelsvn

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
555 jrf 1
#ifndef STBI_INCLUDE_STB_IMAGE_H
2
#define STBI_INCLUDE_STB_IMAGE_H
3
 
4
// To get a header file for this, either cut and paste the header,
5
// or create stb_image.h, #define STBI_HEADER_FILE_ONLY, and
6
// then include stb_image.c from it.
7
 
8
////   begin header file  ////////////////////////////////////////////////////
9
//
10
// Limitations:
11
//    - no jpeg progressive support
12
//    - non-HDR formats support 8-bit samples only (jpeg, png)
13
//    - no delayed line count (jpeg) -- IJG doesn't support either
14
//    - no 1-bit BMP
15
//    - GIF always returns *comp=4
16
//
17
// Basic usage (see HDR discussion below):
18
//    int x,y,n;
19
//    unsigned char *data = stbi_load(filename, &x, &y, &n, 0);
20
//    // ... process data if not NULL ... 
21
//    // ... x = width, y = height, n = # 8-bit components per pixel ...
22
//    // ... replace '0' with '1'..'4' to force that many components per pixel
23
//    stbi_image_free(data)
24
//
25
// Standard parameters:
26
//    int *x       -- outputs image width in pixels
27
//    int *y       -- outputs image height in pixels
28
//    int *comp    -- outputs # of image components in image file
29
//    int req_comp -- if non-zero, # of image components requested in result
30
//
31
// The return value from an image loader is an 'unsigned char *' which points
32
// to the pixel data. The pixel data consists of *y scanlines of *x pixels,
33
// with each pixel consisting of N interleaved 8-bit components; the first
34
// pixel pointed to is top-left-most in the image. There is no padding between
35
// image scanlines or between pixels, regardless of format. The number of
36
// components N is 'req_comp' if req_comp is non-zero, or *comp otherwise.
37
// If req_comp is non-zero, *comp has the number of components that _would_
38
// have been output otherwise. E.g. if you set req_comp to 4, you will always
39
// get RGBA output, but you can check *comp to easily see if it's opaque.
40
//
41
// An output image with N components has the following components interleaved
42
// in this order in each pixel:
43
//
44
//     N=#comp     components
45
//       1           grey
46
//       2           grey, alpha
47
//       3           red, green, blue
48
//       4           red, green, blue, alpha
49
//
50
// If image loading fails for any reason, the return value will be NULL,
51
// and *x, *y, *comp will be unchanged. The function stbi_failure_reason()
52
// can be queried for an extremely brief, end-user unfriendly explanation
53
// of why the load failed. Define STBI_NO_FAILURE_STRINGS to avoid
54
// compiling these strings at all, and STBI_FAILURE_USERMSG to get slightly
55
// more user-friendly ones.
56
//
57
// Paletted PNG, BMP, GIF, and PIC images are automatically depalettized.
58
//
59
// ===========================================================================
60
//
61
// iPhone PNG support:
62
//
63
// By default we convert iphone-formatted PNGs back to RGB; nominally they
64
// would silently load as BGR, except the existing code should have just
65
// failed on such iPhone PNGs. But you can disable this conversion by
66
// by calling stbi_convert_iphone_png_to_rgb(0), in which case
67
// you will always just get the native iphone "format" through.
68
//
69
// Call stbi_set_unpremultiply_on_load(1) as well to force a divide per
70
// pixel to remove any premultiplied alpha *only* if the image file explicitly
71
// says there's premultiplied data (currently only happens in iPhone images,
72
// and only if iPhone convert-to-rgb processing is on).
73
//
74
// ===========================================================================
75
//
76
// HDR image support   (disable by defining STBI_NO_HDR)
77
//
78
// stb_image now supports loading HDR images in general, and currently
79
// the Radiance .HDR file format, although the support is provided
80
// generically. You can still load any file through the existing interface;
81
// if you attempt to load an HDR file, it will be automatically remapped to
82
// LDR, assuming gamma 2.2 and an arbitrary scale factor defaulting to 1;
83
// both of these constants can be reconfigured through this interface:
84
//
85
//     stbi_hdr_to_ldr_gamma(2.2f);
86
//     stbi_hdr_to_ldr_scale(1.0f);
87
//
88
// (note, do not use _inverse_ constants; stbi_image will invert them
89
// appropriately).
90
//
91
// Additionally, there is a new, parallel interface for loading files as
92
// (linear) floats to preserve the full dynamic range:
93
//
94
//    float *data = stbi_loadf(filename, &x, &y, &n, 0);
95
// 
96
// If you load LDR images through this interface, those images will
97
// be promoted to floating point values, run through the inverse of
98
// constants corresponding to the above:
99
//
100
//     stbi_ldr_to_hdr_scale(1.0f);
101
//     stbi_ldr_to_hdr_gamma(2.2f);
102
//
103
// Finally, given a filename (or an open file or memory block--see header
104
// file for details) containing image data, you can query for the "most
105
// appropriate" interface to use (that is, whether the image is HDR or
106
// not), using:
107
//
108
//     stbi_is_hdr(char *filename);
109
 
110
#ifndef STBI_NO_STDIO
111
#include <stdio.h>
112
#endif
113
 
114
#define STBI_VERSION 1
115
 
116
enum
117
{
118
   STBI_default = 0, // only used for req_comp
119
 
120
   STBI_grey       = 1,
121
   STBI_grey_alpha = 2,
122
   STBI_rgb        = 3,
123
   STBI_rgb_alpha  = 4
124
};
125
 
126
typedef unsigned char stbi_uc;
127
 
128
#ifdef __cplusplus
129
extern "C" {
130
#endif
131
 
132
// PRIMARY API - works on images of any type
133
 
134
// load image by filename, open file, or memory buffer
135
extern stbi_uc *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
136
 
137
#ifndef STBI_NO_STDIO
138
extern stbi_uc *stbi_load            (char const *filename,     int *x, int *y, int *comp, int req_comp);
139
extern stbi_uc *stbi_load_from_file  (FILE *f,                  int *x, int *y, int *comp, int req_comp);
140
// for stbi_load_from_file, file pointer is left pointing immediately after image
141
#endif
142
 
143
#ifndef STBI_NO_HDR
144
   extern float *stbi_loadf_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
145
 
146
   #ifndef STBI_NO_STDIO
147
   extern float *stbi_loadf            (char const *filename,   int *x, int *y, int *comp, int req_comp);
148
   extern float *stbi_loadf_from_file  (FILE *f,                int *x, int *y, int *comp, int req_comp);
149
   #endif
150
 
151
   extern void   stbi_hdr_to_ldr_gamma(float gamma);
152
   extern void   stbi_hdr_to_ldr_scale(float scale);
153
 
154
   extern void   stbi_ldr_to_hdr_gamma(float gamma);
155
   extern void   stbi_ldr_to_hdr_scale(float scale);
156
#endif // STBI_NO_HDR
157
 
158
// get a VERY brief reason for failure
159
// NOT THREADSAFE
160
extern const char *stbi_failure_reason  (void); 
161
 
162
// free the loaded image -- this is just free()
163
extern void     stbi_image_free      (void *retval_from_stbi_load);
164
 
165
// get image dimensions & components without fully decoding
166
extern int      stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp);
167
extern int      stbi_is_hdr_from_memory(stbi_uc const *buffer, int len);
168
 
169
#ifndef STBI_NO_STDIO
170
extern int      stbi_info            (char const *filename,     int *x, int *y, int *comp);
171
extern int      stbi_info_from_file  (FILE *f,                  int *x, int *y, int *comp);
172
 
173
extern int      stbi_is_hdr          (char const *filename);
174
extern int      stbi_is_hdr_from_file(FILE *f);
175
#endif
176
 
177
// for image formats that explicitly notate that they have premultiplied alpha,
178
// we just return the colors as stored in the file. set this flag to force
179
// unpremultiplication. results are undefined if the unpremultiply overflow.
180
extern void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply);
181
 
182
// indicate whether we should process iphone images back to canonical format,
183
// or just pass them through "as-is"
184
extern void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert);
185
 
186
 
187
// ZLIB client - used by PNG, available for other purposes
188
 
189
extern char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen);
190
extern char *stbi_zlib_decode_malloc(const char *buffer, int len, int *outlen);
191
extern int   stbi_zlib_decode_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);
192
 
193
extern char *stbi_zlib_decode_noheader_malloc(const char *buffer, int len, int *outlen);
194
extern int   stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);
195
 
196
// define new loaders
197
typedef struct
198
{
199
   int       (*test_memory)(stbi_uc const *buffer, int len);
200
   stbi_uc * (*load_from_memory)(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
201
   #ifndef STBI_NO_STDIO
202
   int       (*test_file)(FILE *f);
203
   stbi_uc * (*load_from_file)(FILE *f, int *x, int *y, int *comp, int req_comp);
204
   #endif
205
} stbi_loader;
206
 
207
// register a loader by filling out the above structure (you must define ALL functions)
208
// returns 1 if added or already added, 0 if not added (too many loaders)
209
// NOT THREADSAFE
210
extern int stbi_register_loader(stbi_loader *loader);
211
 
212
// define faster low-level operations (typically SIMD support)
213
#ifdef STBI_SIMD
214
typedef void (*stbi_idct_8x8)(stbi_uc *out, int out_stride, short data[64], unsigned short *dequantize);
215
// compute an integer IDCT on "input"
216
//     input[x] = data[x] * dequantize[x]
217
//     write results to 'out': 64 samples, each run of 8 spaced by 'out_stride'
218
//                             CLAMP results to 0..255
219
typedef void (*stbi_YCbCr_to_RGB_run)(stbi_uc *output, stbi_uc const  *y, stbi_uc const *cb, stbi_uc const *cr, int count, int step);
220
// compute a conversion from YCbCr to RGB
221
//     'count' pixels
222
//     write pixels to 'output'; each pixel is 'step' bytes (either 3 or 4; if 4, write '255' as 4th), order R,G,B
223
//     y: Y input channel
224
//     cb: Cb input channel; scale/biased to be 0..255
225
//     cr: Cr input channel; scale/biased to be 0..255
226
 
227
extern void stbi_install_idct(stbi_idct_8x8 func);
228
extern void stbi_install_YCbCr_to_RGB(stbi_YCbCr_to_RGB_run func);
229
#endif // STBI_SIMD
230
 
231
 
232
 
233
 
234
// TYPE-SPECIFIC ACCESS
235
 
236
// is it a jpeg?
237
extern int      stbi_jpeg_test_memory     (stbi_uc const *buffer, int len);
238
extern stbi_uc *stbi_jpeg_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
239
extern int      stbi_jpeg_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp);
240
 
241
#ifndef STBI_NO_STDIO
242
extern stbi_uc *stbi_jpeg_load            (char const *filename,     int *x, int *y, int *comp, int req_comp);
243
extern int      stbi_jpeg_test_file       (FILE *f);
244
extern stbi_uc *stbi_jpeg_load_from_file  (FILE *f,                  int *x, int *y, int *comp, int req_comp);
245
 
246
extern int      stbi_jpeg_info            (char const *filename,     int *x, int *y, int *comp);
247
extern int      stbi_jpeg_info_from_file  (FILE *f,                  int *x, int *y, int *comp);
248
#endif
249
 
250
// is it a png?
251
extern int      stbi_png_test_memory      (stbi_uc const *buffer, int len);
252
extern stbi_uc *stbi_png_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
253
extern int      stbi_png_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp);
254
 
255
#ifndef STBI_NO_STDIO
256
extern stbi_uc *stbi_png_load             (char const *filename,     int *x, int *y, int *comp, int req_comp);
257
extern int      stbi_png_info             (char const *filename,     int *x, int *y, int *comp);
258
extern int      stbi_png_test_file        (FILE *f);
259
extern stbi_uc *stbi_png_load_from_file   (FILE *f,                  int *x, int *y, int *comp, int req_comp);
260
extern int      stbi_png_info_from_file   (FILE *f,                  int *x, int *y, int *comp);
261
#endif
262
 
263
// is it a bmp?
264
extern int      stbi_bmp_test_memory      (stbi_uc const *buffer, int len);
265
 
266
extern stbi_uc *stbi_bmp_load             (char const *filename,     int *x, int *y, int *comp, int req_comp);
267
extern stbi_uc *stbi_bmp_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
268
#ifndef STBI_NO_STDIO
269
extern int      stbi_bmp_test_file        (FILE *f);
270
extern stbi_uc *stbi_bmp_load_from_file   (FILE *f,                  int *x, int *y, int *comp, int req_comp);
271
#endif
272
 
273
// is it a tga?
274
extern int      stbi_tga_test_memory      (stbi_uc const *buffer, int len);
275
 
276
extern stbi_uc *stbi_tga_load             (char const *filename,     int *x, int *y, int *comp, int req_comp);
277
extern stbi_uc *stbi_tga_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
278
#ifndef STBI_NO_STDIO
279
extern int      stbi_tga_test_file        (FILE *f);
280
extern stbi_uc *stbi_tga_load_from_file   (FILE *f,                  int *x, int *y, int *comp, int req_comp);
281
#endif
282
 
283
// is it a psd?
284
extern int      stbi_psd_test_memory      (stbi_uc const *buffer, int len);
285
 
286
extern stbi_uc *stbi_psd_load             (char const *filename,     int *x, int *y, int *comp, int req_comp);
287
extern stbi_uc *stbi_psd_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
288
#ifndef STBI_NO_STDIO
289
extern int      stbi_psd_test_file        (FILE *f);
290
extern stbi_uc *stbi_psd_load_from_file   (FILE *f,                  int *x, int *y, int *comp, int req_comp);
291
#endif
292
 
293
// is it an hdr?
294
extern int      stbi_hdr_test_memory      (stbi_uc const *buffer, int len);
295
 
296
extern float *  stbi_hdr_load             (char const *filename,     int *x, int *y, int *comp, int req_comp);
297
extern float *  stbi_hdr_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
298
extern stbi_uc *stbi_hdr_load_rgbe        (char const *filename,           int *x, int *y, int *comp, int req_comp);
299
#ifndef STBI_NO_STDIO
300
extern int      stbi_hdr_test_file        (FILE *f);
301
extern float *  stbi_hdr_load_from_file   (FILE *f,                  int *x, int *y, int *comp, int req_comp);
302
extern stbi_uc *stbi_hdr_load_rgbe_file   (FILE *f,                  int *x, int *y, int *comp, int req_comp);
303
#endif
304
 
305
// is it a pic?
306
extern int      stbi_pic_test_memory      (stbi_uc const *buffer, int len);
307
 
308
extern stbi_uc *stbi_pic_load             (char const *filename,     int *x, int *y, int *comp, int req_comp);
309
extern stbi_uc *stbi_pic_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
310
#ifndef STBI_NO_STDIO
311
extern int      stbi_pic_test_file        (FILE *f);
312
extern stbi_uc *stbi_pic_load_from_file   (FILE *f,                  int *x, int *y, int *comp, int req_comp);
313
#endif
314
 
315
// is it a gif?
316
extern int      stbi_gif_test_memory      (stbi_uc const *buffer, int len);
317
 
318
extern stbi_uc *stbi_gif_load             (char const *filename,     int *x, int *y, int *comp, int req_comp);
319
extern stbi_uc *stbi_gif_load_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
320
extern int      stbi_gif_info_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp);
321
 
322
#ifndef STBI_NO_STDIO
323
extern int      stbi_gif_test_file        (FILE *f);
324
extern stbi_uc *stbi_gif_load_from_file   (FILE *f,                  int *x, int *y, int *comp, int req_comp);
325
extern int      stbi_gif_info             (char const *filename,     int *x, int *y, int *comp);
326
extern int      stbi_gif_info_from_file   (FILE *f,                  int *x, int *y, int *comp);
327
#endif
328
 
329
 
330
#ifdef __cplusplus
331
}
332
#endif
333
 
334
//
335
//
336
////   end header file   /////////////////////////////////////////////////////
337
#endif // STBI_INCLUDE_STB_IMAGE_H