gosu 0.11.1.pre1 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gosu/Math.hpp +1 -1
- data/Gosu/Window.hpp +8 -4
- data/lib/gosu/patches.rb +5 -2
- data/rdoc/gosu.rb +130 -134
- data/src/Bitmap.cpp +1 -1
- data/src/Graphics.cpp +1 -1
- data/src/RubyGosu.cxx +15 -14
- data/src/TextWin.cpp +2 -2
- data/src/Window.cpp +42 -14
- data/src/WindowUIKit.cpp +4 -0
- data/src/stb_image.h +173 -384
- metadata +4 -4
data/src/Bitmap.cpp
CHANGED
@@ -118,7 +118,7 @@ void Gosu::unapply_color_key(Bitmap& bitmap, Color color)
|
|
118
118
|
void Gosu::apply_border_flags(Bitmap& dest, const Bitmap& source, unsigned src_x, unsigned src_y,
|
119
119
|
unsigned src_width, unsigned src_height, unsigned image_flags)
|
120
120
|
{
|
121
|
-
//
|
121
|
+
// Backward compatibility: This used to be 'bool tileable'.
|
122
122
|
if (image_flags == 1)
|
123
123
|
image_flags = IF_TILEABLE;
|
124
124
|
|
data/src/Graphics.cpp
CHANGED
@@ -393,7 +393,7 @@ std::unique_ptr<Gosu::ImageData> Gosu::Graphics::create_image(const Bitmap& src,
|
|
393
393
|
{
|
394
394
|
static const unsigned max_size = MAX_TEXTURE_SIZE;
|
395
395
|
|
396
|
-
//
|
396
|
+
// Backward compatibility: This used to be 'bool tileable'.
|
397
397
|
if (flags == 1) flags = IF_TILEABLE;
|
398
398
|
|
399
399
|
bool wants_retro = (flags & IF_RETRO);
|
data/src/RubyGosu.cxx
CHANGED
@@ -2506,9 +2506,6 @@ SWIG_From_unsigned_SS_long (unsigned long value)
|
|
2506
2506
|
}
|
2507
2507
|
|
2508
2508
|
|
2509
|
-
#define SWIG_From_double rb_float_new
|
2510
|
-
|
2511
|
-
|
2512
2509
|
SWIGINTERN VALUE
|
2513
2510
|
SWIG_ruby_failed(void)
|
2514
2511
|
{
|
@@ -2545,6 +2542,9 @@ SWIG_AsVal_double (VALUE obj, double *val)
|
|
2545
2542
|
}
|
2546
2543
|
|
2547
2544
|
|
2545
|
+
#define SWIG_From_double rb_float_new
|
2546
|
+
|
2547
|
+
|
2548
2548
|
SWIGINTERNINLINE VALUE
|
2549
2549
|
SWIG_From_unsigned_SS_int (unsigned int value)
|
2550
2550
|
{
|
@@ -2667,7 +2667,9 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size)
|
|
2667
2667
|
SWIGINTERNINLINE VALUE
|
2668
2668
|
SWIG_From_std_string (const std::string& s)
|
2669
2669
|
{
|
2670
|
-
|
2670
|
+
VALUE string = SWIG_FromCharPtrAndSize(s.data(), s.size());
|
2671
|
+
ENFORCE_UTF8(string);
|
2672
|
+
return string;
|
2671
2673
|
}
|
2672
2674
|
|
2673
2675
|
SWIGINTERN bool Gosu_Color_operator_Se__Se_(Gosu::Color const *self,VALUE other){
|
@@ -3247,14 +3249,14 @@ bool SwigDirector_Window::tick() {
|
|
3247
3249
|
void SwigDirector_Window::update() {
|
3248
3250
|
VALUE SWIGUNUSED result;
|
3249
3251
|
|
3250
|
-
result = rb_funcall(swig_get_self(), rb_intern("
|
3252
|
+
result = rb_funcall(swig_get_self(), rb_intern("protected_update"), 0, NULL);
|
3251
3253
|
}
|
3252
3254
|
|
3253
3255
|
|
3254
3256
|
void SwigDirector_Window::draw() {
|
3255
3257
|
VALUE SWIGUNUSED result;
|
3256
3258
|
|
3257
|
-
result = rb_funcall(swig_get_self(), rb_intern("
|
3259
|
+
result = rb_funcall(swig_get_self(), rb_intern("protected_draw_2"), 0, NULL);
|
3258
3260
|
}
|
3259
3261
|
|
3260
3262
|
|
@@ -3262,7 +3264,7 @@ bool SwigDirector_Window::needs_redraw() const {
|
|
3262
3264
|
bool c_result ;
|
3263
3265
|
VALUE SWIGUNUSED result;
|
3264
3266
|
|
3265
|
-
result = rb_funcall(swig_get_self(), rb_intern("
|
3267
|
+
result = rb_funcall(swig_get_self(), rb_intern("protected_needs_redraw?"), 0, NULL);
|
3266
3268
|
bool swig_val;
|
3267
3269
|
int swig_res = SWIG_AsVal_bool(result, &swig_val);
|
3268
3270
|
if (!SWIG_IsOK(swig_res)) {
|
@@ -3277,7 +3279,7 @@ bool SwigDirector_Window::needs_cursor() const {
|
|
3277
3279
|
bool c_result ;
|
3278
3280
|
VALUE SWIGUNUSED result;
|
3279
3281
|
|
3280
|
-
result = rb_funcall(swig_get_self(), rb_intern("
|
3282
|
+
result = rb_funcall(swig_get_self(), rb_intern("protected_needs_cursor?"), 0, NULL);
|
3281
3283
|
bool swig_val;
|
3282
3284
|
int swig_res = SWIG_AsVal_bool(result, &swig_val);
|
3283
3285
|
if (!SWIG_IsOK(swig_res)) {
|
@@ -3291,7 +3293,7 @@ bool SwigDirector_Window::needs_cursor() const {
|
|
3291
3293
|
void SwigDirector_Window::lose_focus() {
|
3292
3294
|
VALUE SWIGUNUSED result;
|
3293
3295
|
|
3294
|
-
result = rb_funcall(swig_get_self(), rb_intern("
|
3296
|
+
result = rb_funcall(swig_get_self(), rb_intern("protected_lose_focus"), 0, NULL);
|
3295
3297
|
}
|
3296
3298
|
|
3297
3299
|
|
@@ -3309,7 +3311,7 @@ void SwigDirector_Window::button_down(Gosu::Button arg0) {
|
|
3309
3311
|
{
|
3310
3312
|
obj0 = arg0 == Gosu::NO_BUTTON ? Qnil : LONG2NUM((&arg0)->id());
|
3311
3313
|
}
|
3312
|
-
result = rb_funcall(swig_get_self(), rb_intern("
|
3314
|
+
result = rb_funcall(swig_get_self(), rb_intern("protected_button_down"), 1,obj0);
|
3313
3315
|
}
|
3314
3316
|
|
3315
3317
|
|
@@ -3320,7 +3322,7 @@ void SwigDirector_Window::button_up(Gosu::Button arg0) {
|
|
3320
3322
|
{
|
3321
3323
|
obj0 = arg0 == Gosu::NO_BUTTON ? Qnil : LONG2NUM((&arg0)->id());
|
3322
3324
|
}
|
3323
|
-
result = rb_funcall(swig_get_self(), rb_intern("
|
3325
|
+
result = rb_funcall(swig_get_self(), rb_intern("protected_button_up"), 1,obj0);
|
3324
3326
|
}
|
3325
3327
|
|
3326
3328
|
|
@@ -11511,13 +11513,12 @@ SWIGEXPORT void Init_gosu(void) {
|
|
11511
11513
|
}
|
11512
11514
|
|
11513
11515
|
SWIG_RubyInitializeTrackings();
|
11514
|
-
rb_define_const(mGosu, "VERSION",
|
11515
|
-
rb_define_const(mGosu, "LICENSES",
|
11516
|
+
rb_define_const(mGosu, "VERSION", SWIG_From_std_string(static_cast< std::string >(Gosu::VERSION)));
|
11517
|
+
rb_define_const(mGosu, "LICENSES", SWIG_From_std_string(static_cast< std::string >(Gosu::LICENSES)));
|
11516
11518
|
rb_define_const(mGosu, "MAJOR_VERSION", SWIG_From_int(static_cast< int >(0)));
|
11517
11519
|
rb_define_const(mGosu, "MINOR_VERSION", SWIG_From_int(static_cast< int >(11)));
|
11518
11520
|
rb_define_const(mGosu, "POINT_VERSION", SWIG_From_int(static_cast< int >(1)));
|
11519
11521
|
rb_define_module_function(mGosu, "milliseconds", VALUEFUNC(_wrap_milliseconds), -1);
|
11520
|
-
rb_define_const(mGosu, "M_PI", SWIG_From_double(static_cast< double >(3.14159265358979323846264338327950288)));
|
11521
11522
|
rb_define_module_function(mGosu, "random", VALUEFUNC(_wrap_random), -1);
|
11522
11523
|
rb_define_module_function(mGosu, "degrees_to_radians", VALUEFUNC(_wrap_degrees_to_radians), -1);
|
11523
11524
|
rb_define_module_function(mGosu, "radians_to_degrees", VALUEFUNC(_wrap_radians_to_degrees), -1);
|
data/src/TextWin.cpp
CHANGED
@@ -149,7 +149,7 @@ unsigned Gosu::text_width(const std::string& text, const std::string& font_name,
|
|
149
149
|
|
150
150
|
std::wstring wtext = utf8_to_wstring(text);
|
151
151
|
SIZE size;
|
152
|
-
winapi_check(GetTextExtentPoint32W(helper.context(), wtext.c_str(),
|
152
|
+
winapi_check(GetTextExtentPoint32W(helper.context(), wtext.c_str(), wtext.length(), &size),
|
153
153
|
"calculating the width of a text");
|
154
154
|
|
155
155
|
return size.cx;
|
@@ -174,7 +174,7 @@ void Gosu::draw_text(Bitmap& bitmap, const std::string& text, int x, int y, Colo
|
|
174
174
|
"setting a bitmap's background mode to TRANSPARENT");
|
175
175
|
|
176
176
|
std::wstring wtext = utf8_to_wstring(text);
|
177
|
-
ExtTextOutW(helper.context(), 0, 0, 0, 0, wtext.c_str(),
|
177
|
+
ExtTextOutW(helper.context(), 0, 0, 0, 0, wtext.c_str(), wtext.length(), 0);
|
178
178
|
|
179
179
|
for (unsigned rel_y = 0; rel_y < font_height; ++rel_y)
|
180
180
|
for (unsigned rel_x = 0; rel_x < width; ++rel_x) {
|
data/src/Window.cpp
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
#include <Gosu/Gosu.hpp>
|
5
5
|
#include <SDL.h>
|
6
6
|
#include <cstdlib>
|
7
|
-
#include <
|
7
|
+
#include <algorithm>
|
8
8
|
#include <stdexcept>
|
9
9
|
|
10
10
|
namespace Gosu
|
@@ -13,16 +13,16 @@ namespace Gosu
|
|
13
13
|
{
|
14
14
|
void register_frame();
|
15
15
|
}
|
16
|
-
|
17
|
-
void throw_sdl_error(const std::string& operation)
|
16
|
+
|
17
|
+
static void throw_sdl_error(const std::string& operation)
|
18
18
|
{
|
19
19
|
const char* error = SDL_GetError();
|
20
20
|
throw std::runtime_error(operation + ": " + (error ? error : "(unknown error)"));
|
21
21
|
}
|
22
22
|
|
23
|
-
void cleanup();
|
23
|
+
static void cleanup();
|
24
24
|
|
25
|
-
SDL_Window* shared_window()
|
25
|
+
static SDL_Window* shared_window()
|
26
26
|
{
|
27
27
|
static SDL_Window* window = nullptr;
|
28
28
|
if (window == nullptr) {
|
@@ -46,8 +46,8 @@ namespace Gosu
|
|
46
46
|
}
|
47
47
|
return window;
|
48
48
|
}
|
49
|
-
|
50
|
-
SDL_GLContext shared_gl_context()
|
49
|
+
|
50
|
+
static SDL_GLContext shared_gl_context()
|
51
51
|
{
|
52
52
|
static SDL_GLContext context = nullptr;
|
53
53
|
if (context == nullptr) {
|
@@ -70,7 +70,7 @@ namespace Gosu
|
|
70
70
|
SDL_GL_MakeCurrent(shared_window(), shared_gl_context());
|
71
71
|
}
|
72
72
|
|
73
|
-
void cleanup()
|
73
|
+
static void cleanup()
|
74
74
|
{
|
75
75
|
SDL_GL_DeleteContext(shared_gl_context());
|
76
76
|
SDL_DestroyWindow(shared_window());
|
@@ -90,19 +90,21 @@ struct Gosu::Window::Impl
|
|
90
90
|
Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen, double update_interval)
|
91
91
|
: pimpl(new Impl)
|
92
92
|
{
|
93
|
+
// Even in fullscreen mode, temporarily show the window in windowed mode to centre it.
|
94
|
+
// This ensures that the window will be centred correctly when exiting fullscreen mode.
|
95
|
+
// Fixes https://github.com/gosu/gosu/issues/369
|
96
|
+
resize(width, height, false);
|
97
|
+
SDL_SetWindowPosition(shared_window(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
98
|
+
|
93
99
|
// This will implicitly create graphics() and input(), and make the OpenGL context current.
|
94
100
|
resize(width, height, fullscreen);
|
95
101
|
|
96
102
|
SDL_GL_SetSwapInterval(1);
|
97
103
|
|
98
104
|
pimpl->update_interval = update_interval;
|
99
|
-
|
100
|
-
if (!fullscreen) {
|
101
|
-
SDL_SetWindowPosition(shared_window(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
102
|
-
}
|
103
105
|
|
104
|
-
input().on_button_down = [this](
|
105
|
-
input().on_button_up = [this](
|
106
|
+
input().on_button_down = [this](Button button) { button_down(button); };
|
107
|
+
input().on_button_up = [this](Button button) { button_up(button); };
|
106
108
|
}
|
107
109
|
|
108
110
|
Gosu::Window::~Window()
|
@@ -274,6 +276,32 @@ void Gosu::Window::close()
|
|
274
276
|
SDL_PushEvent(&e);
|
275
277
|
}
|
276
278
|
|
279
|
+
void Gosu::Window::button_down(Button button)
|
280
|
+
{
|
281
|
+
bool toggle_fullscreen;
|
282
|
+
|
283
|
+
// Default shortcuts for toggling fullscreen mode, see: https://github.com/gosu/gosu/issues/361
|
284
|
+
|
285
|
+
#ifdef GOSU_IS_MAC
|
286
|
+
// cmd+F and cmd+ctrl+F are both common shortcuts for toggling fullscreen mode on macOS.
|
287
|
+
toggle_fullscreen = button == KB_F &&
|
288
|
+
(Input::down(KB_LEFT_META) || Input::down(KB_RIGHT_META)) &&
|
289
|
+
!Input::down(KB_LEFT_SHIFT) && !Input::down(KB_RIGHT_SHIFT) &&
|
290
|
+
!Input::down(KB_LEFT_ALT) && !Input::down(KB_RIGHT_ALT);
|
291
|
+
#else
|
292
|
+
// alt+enter and alt+return toggle fullscreen mode on all other platforms.
|
293
|
+
toggle_fullscreen = (button == KB_RETURN || button == KB_ENTER) &&
|
294
|
+
(Input::down(KB_LEFT_ALT) || Input::down(KB_RIGHT_ALT)) &&
|
295
|
+
!Input::down(KB_LEFT_CONTROL) && !Input::down(KB_RIGHT_CONTROL) &&
|
296
|
+
!Input::down(KB_LEFT_META) && !Input::down(KB_RIGHT_META) &&
|
297
|
+
!Input::down(KB_LEFT_SHIFT) && !Input::down(KB_RIGHT_SHIFT);
|
298
|
+
#endif
|
299
|
+
|
300
|
+
if (toggle_fullscreen) {
|
301
|
+
resize(width(), height(), !fullscreen());
|
302
|
+
}
|
303
|
+
}
|
304
|
+
|
277
305
|
const Gosu::Graphics& Gosu::Window::graphics() const
|
278
306
|
{
|
279
307
|
return *pimpl->graphics;
|
data/src/WindowUIKit.cpp
CHANGED
@@ -147,6 +147,10 @@ void Gosu::Window::close()
|
|
147
147
|
throw std::logic_error("Cannot close windows manually on iOS");
|
148
148
|
}
|
149
149
|
|
150
|
+
void Gosu::Window::button_down(Button button)
|
151
|
+
{
|
152
|
+
}
|
153
|
+
|
150
154
|
void* Gosu::Window::UIWindow() const
|
151
155
|
{
|
152
156
|
return (__bridge void*) pimpl->window;
|
data/src/stb_image.h
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* stb_image - v2.
|
1
|
+
/* stb_image - v2.12 with fixes from https://github.com/nothings/stb/pull/343 - public domain image loader - http://nothings.org/stb_image.h
|
2
2
|
no warranty implied; use at your own risk
|
3
3
|
|
4
4
|
Do this:
|
@@ -146,7 +146,6 @@
|
|
146
146
|
|
147
147
|
|
148
148
|
Latest revision history:
|
149
|
-
2.13 (2016-12-04) experimental 16-bit API, only for PNG so far; fixes
|
150
149
|
2.12 (2016-04-02) fix typo in 2.11 PSD fix that caused crashes
|
151
150
|
2.11 (2016-04-02) 16-bit PNGS; enable SSE2 in non-gcc x64
|
152
151
|
RGB-format JPEG; remove white matting in PSD;
|
@@ -158,6 +157,21 @@
|
|
158
157
|
2.07 (2015-09-13) partial animated GIF support
|
159
158
|
limited 16-bit PSD support
|
160
159
|
minor bugs, code cleanup, and compiler warnings
|
160
|
+
2.06 (2015-04-19) fix bug where PSD returns wrong '*comp' value
|
161
|
+
2.05 (2015-04-19) fix bug in progressive JPEG handling, fix warning
|
162
|
+
2.04 (2015-04-15) try to re-enable SIMD on MinGW 64-bit
|
163
|
+
2.03 (2015-04-12) additional corruption checking
|
164
|
+
stbi_set_flip_vertically_on_load
|
165
|
+
fix NEON support; fix mingw support
|
166
|
+
2.02 (2015-01-19) fix incorrect assert, fix warning
|
167
|
+
2.01 (2015-01-17) fix various warnings
|
168
|
+
2.00b (2014-12-25) fix STBI_MALLOC in progressive JPEG
|
169
|
+
2.00 (2014-12-25) optimize JPEG, including x86 SSE2 & ARM NEON SIMD
|
170
|
+
progressive JPEG
|
171
|
+
PGM/PPM support
|
172
|
+
STBI_MALLOC,STBI_REALLOC,STBI_FREE
|
173
|
+
STBI_NO_*, STBI_ONLY_*
|
174
|
+
GIF bugfix
|
161
175
|
|
162
176
|
See end of file for full revision history.
|
163
177
|
|
@@ -190,9 +204,8 @@
|
|
190
204
|
Laurent Gomila Cort Stratton Sergio Gonzalez romigrou@github
|
191
205
|
Aruelien Pocheville Thibault Reuille Cass Everitt Matthew Gregan
|
192
206
|
Ryamond Barbiero Paul Du Bois Engin Manap snagar@github
|
193
|
-
Michaelangel007@github Oriol Ferrer Mesia socks-the-fox
|
194
|
-
|
195
|
-
Blazej Dariusz Roszkowski
|
207
|
+
Michaelangel007@github Oriol Ferrer Mesia socks-the-fox
|
208
|
+
Blazej Dariusz Roszkowski
|
196
209
|
|
197
210
|
|
198
211
|
LICENSE
|
@@ -225,10 +238,10 @@ publish, and distribute this file as you see fit.
|
|
225
238
|
// stbi_image_free(data)
|
226
239
|
//
|
227
240
|
// Standard parameters:
|
228
|
-
// int *x
|
229
|
-
// int *y
|
230
|
-
// int *
|
231
|
-
// int
|
241
|
+
// int *x -- outputs image width in pixels
|
242
|
+
// int *y -- outputs image height in pixels
|
243
|
+
// int *comp -- outputs # of image components in image file
|
244
|
+
// int req_comp -- if non-zero, # of image components requested in result
|
232
245
|
//
|
233
246
|
// The return value from an image loader is an 'unsigned char *' which points
|
234
247
|
// to the pixel data, or NULL on an allocation failure or if the image is
|
@@ -393,7 +406,6 @@ enum
|
|
393
406
|
};
|
394
407
|
|
395
408
|
typedef unsigned char stbi_uc;
|
396
|
-
typedef unsigned short stbi_us;
|
397
409
|
|
398
410
|
#ifdef __cplusplus
|
399
411
|
extern "C" {
|
@@ -421,42 +433,22 @@ typedef struct
|
|
421
433
|
int (*eof) (void *user); // returns nonzero if we are at end of file/data
|
422
434
|
} stbi_io_callbacks;
|
423
435
|
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
//
|
428
|
-
|
429
|
-
STBIDEF stbi_uc *stbi_load (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);
|
430
|
-
STBIDEF stbi_uc *stbi_load_from_memory (stbi_uc const *buffer, int len , int *x, int *y, int *channels_in_file, int desired_channels);
|
431
|
-
STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk , void *user, int *x, int *y, int *channels_in_file, int desired_channels);
|
436
|
+
STBIDEF stbi_uc *stbi_load (char const *filename, int *x, int *y, int *comp, int req_comp);
|
437
|
+
STBIDEF stbi_uc *stbi_load_from_memory (stbi_uc const *buffer, int len , int *x, int *y, int *comp, int req_comp);
|
438
|
+
STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk , void *user, int *x, int *y, int *comp, int req_comp);
|
432
439
|
|
433
440
|
#ifndef STBI_NO_STDIO
|
434
|
-
STBIDEF stbi_uc *stbi_load_from_file
|
441
|
+
STBIDEF stbi_uc *stbi_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp);
|
435
442
|
// for stbi_load_from_file, file pointer is left pointing immediately after image
|
436
443
|
#endif
|
437
444
|
|
438
|
-
////////////////////////////////////
|
439
|
-
//
|
440
|
-
// 16-bits-per-channel interface
|
441
|
-
//
|
442
|
-
|
443
|
-
STBIDEF stbi_us *stbi_load_16(char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);
|
444
|
-
#ifndef STBI_NO_STDIO
|
445
|
-
STBIDEF stbi_us *stbi_load_from_file_16(FILE *f, int *x, int *y, int *channels_in_file, int desired_channels);
|
446
|
-
#endif
|
447
|
-
// @TODO the other variants
|
448
|
-
|
449
|
-
////////////////////////////////////
|
450
|
-
//
|
451
|
-
// float-per-channel interface
|
452
|
-
//
|
453
445
|
#ifndef STBI_NO_LINEAR
|
454
|
-
STBIDEF float *stbi_loadf (char const *filename, int *x, int *y, int *
|
455
|
-
STBIDEF float *stbi_loadf_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *
|
456
|
-
STBIDEF float *stbi_loadf_from_callbacks (stbi_io_callbacks const *clbk, void *user, int *x, int *y,
|
446
|
+
STBIDEF float *stbi_loadf (char const *filename, int *x, int *y, int *comp, int req_comp);
|
447
|
+
STBIDEF float *stbi_loadf_from_memory (stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
|
448
|
+
STBIDEF float *stbi_loadf_from_callbacks (stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp);
|
457
449
|
|
458
450
|
#ifndef STBI_NO_STDIO
|
459
|
-
STBIDEF float *stbi_loadf_from_file (FILE *f,
|
451
|
+
STBIDEF float *stbi_loadf_from_file (FILE *f, int *x, int *y, int *comp, int req_comp);
|
460
452
|
#endif
|
461
453
|
#endif
|
462
454
|
|
@@ -836,70 +828,57 @@ static void stbi__rewind(stbi__context *s)
|
|
836
828
|
s->img_buffer_end = s->img_buffer_original_end;
|
837
829
|
}
|
838
830
|
|
839
|
-
enum
|
840
|
-
{
|
841
|
-
STBI_ORDER_RGB,
|
842
|
-
STBI_ORDER_BGR
|
843
|
-
};
|
844
|
-
|
845
|
-
typedef struct
|
846
|
-
{
|
847
|
-
int bits_per_channel;
|
848
|
-
int num_channels;
|
849
|
-
int channel_order;
|
850
|
-
} stbi__result_info;
|
851
|
-
|
852
831
|
#ifndef STBI_NO_JPEG
|
853
832
|
static int stbi__jpeg_test(stbi__context *s);
|
854
|
-
static
|
833
|
+
static stbi_uc *stbi__jpeg_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
|
855
834
|
static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp);
|
856
835
|
#endif
|
857
836
|
|
858
837
|
#ifndef STBI_NO_PNG
|
859
838
|
static int stbi__png_test(stbi__context *s);
|
860
|
-
static
|
839
|
+
static stbi_uc *stbi__png_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
|
861
840
|
static int stbi__png_info(stbi__context *s, int *x, int *y, int *comp);
|
862
841
|
#endif
|
863
842
|
|
864
843
|
#ifndef STBI_NO_BMP
|
865
844
|
static int stbi__bmp_test(stbi__context *s);
|
866
|
-
static
|
845
|
+
static stbi_uc *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
|
867
846
|
static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp);
|
868
847
|
#endif
|
869
848
|
|
870
849
|
#ifndef STBI_NO_TGA
|
871
850
|
static int stbi__tga_test(stbi__context *s);
|
872
|
-
static
|
851
|
+
static stbi_uc *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
|
873
852
|
static int stbi__tga_info(stbi__context *s, int *x, int *y, int *comp);
|
874
853
|
#endif
|
875
854
|
|
876
855
|
#ifndef STBI_NO_PSD
|
877
856
|
static int stbi__psd_test(stbi__context *s);
|
878
|
-
static
|
857
|
+
static stbi_uc *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
|
879
858
|
static int stbi__psd_info(stbi__context *s, int *x, int *y, int *comp);
|
880
859
|
#endif
|
881
860
|
|
882
861
|
#ifndef STBI_NO_HDR
|
883
862
|
static int stbi__hdr_test(stbi__context *s);
|
884
|
-
static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int req_comp
|
863
|
+
static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
|
885
864
|
static int stbi__hdr_info(stbi__context *s, int *x, int *y, int *comp);
|
886
865
|
#endif
|
887
866
|
|
888
867
|
#ifndef STBI_NO_PIC
|
889
868
|
static int stbi__pic_test(stbi__context *s);
|
890
|
-
static
|
869
|
+
static stbi_uc *stbi__pic_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
|
891
870
|
static int stbi__pic_info(stbi__context *s, int *x, int *y, int *comp);
|
892
871
|
#endif
|
893
872
|
|
894
873
|
#ifndef STBI_NO_GIF
|
895
874
|
static int stbi__gif_test(stbi__context *s);
|
896
|
-
static
|
875
|
+
static stbi_uc *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
|
897
876
|
static int stbi__gif_info(stbi__context *s, int *x, int *y, int *comp);
|
898
877
|
#endif
|
899
878
|
|
900
879
|
#ifndef STBI_NO_PNM
|
901
880
|
static int stbi__pnm_test(stbi__context *s);
|
902
|
-
static
|
881
|
+
static stbi_uc *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp);
|
903
882
|
static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp);
|
904
883
|
#endif
|
905
884
|
|
@@ -1028,38 +1007,33 @@ STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip)
|
|
1028
1007
|
stbi__vertically_flip_on_load = flag_true_if_should_flip;
|
1029
1008
|
}
|
1030
1009
|
|
1031
|
-
static
|
1010
|
+
static unsigned char *stbi__load_main(stbi__context *s, int *x, int *y, int *comp, int req_comp)
|
1032
1011
|
{
|
1033
|
-
memset(ri, 0, sizeof(*ri)); // make sure it's initialized if we add new fields
|
1034
|
-
ri->bits_per_channel = 8; // default is 8 so most paths don't have to be changed
|
1035
|
-
ri->channel_order = STBI_ORDER_RGB; // all current input & output are this, but this is here so we can add BGR order
|
1036
|
-
ri->num_channels = 0;
|
1037
|
-
|
1038
1012
|
#ifndef STBI_NO_JPEG
|
1039
|
-
if (stbi__jpeg_test(s)) return stbi__jpeg_load(s,x,y,comp,req_comp
|
1013
|
+
if (stbi__jpeg_test(s)) return stbi__jpeg_load(s,x,y,comp,req_comp);
|
1040
1014
|
#endif
|
1041
1015
|
#ifndef STBI_NO_PNG
|
1042
|
-
if (stbi__png_test(s)) return stbi__png_load(s,x,y,comp,req_comp
|
1016
|
+
if (stbi__png_test(s)) return stbi__png_load(s,x,y,comp,req_comp);
|
1043
1017
|
#endif
|
1044
1018
|
#ifndef STBI_NO_BMP
|
1045
|
-
if (stbi__bmp_test(s)) return stbi__bmp_load(s,x,y,comp,req_comp
|
1019
|
+
if (stbi__bmp_test(s)) return stbi__bmp_load(s,x,y,comp,req_comp);
|
1046
1020
|
#endif
|
1047
1021
|
#ifndef STBI_NO_GIF
|
1048
|
-
if (stbi__gif_test(s)) return stbi__gif_load(s,x,y,comp,req_comp
|
1022
|
+
if (stbi__gif_test(s)) return stbi__gif_load(s,x,y,comp,req_comp);
|
1049
1023
|
#endif
|
1050
1024
|
#ifndef STBI_NO_PSD
|
1051
|
-
if (stbi__psd_test(s)) return stbi__psd_load(s,x,y,comp,req_comp
|
1025
|
+
if (stbi__psd_test(s)) return stbi__psd_load(s,x,y,comp,req_comp);
|
1052
1026
|
#endif
|
1053
1027
|
#ifndef STBI_NO_PIC
|
1054
|
-
if (stbi__pic_test(s)) return stbi__pic_load(s,x,y,comp,req_comp
|
1028
|
+
if (stbi__pic_test(s)) return stbi__pic_load(s,x,y,comp,req_comp);
|
1055
1029
|
#endif
|
1056
1030
|
#ifndef STBI_NO_PNM
|
1057
|
-
if (stbi__pnm_test(s)) return stbi__pnm_load(s,x,y,comp,req_comp
|
1031
|
+
if (stbi__pnm_test(s)) return stbi__pnm_load(s,x,y,comp,req_comp);
|
1058
1032
|
#endif
|
1059
1033
|
|
1060
1034
|
#ifndef STBI_NO_HDR
|
1061
1035
|
if (stbi__hdr_test(s)) {
|
1062
|
-
float *hdr = stbi__hdr_load(s, x,y,comp,req_comp
|
1036
|
+
float *hdr = stbi__hdr_load(s, x,y,comp,req_comp);
|
1063
1037
|
return stbi__hdr_to_ldr(hdr, *x, *y, req_comp ? req_comp : *comp);
|
1064
1038
|
}
|
1065
1039
|
#endif
|
@@ -1067,117 +1041,35 @@ static void *stbi__load_main(stbi__context *s, int *x, int *y, int *comp, int re
|
|
1067
1041
|
#ifndef STBI_NO_TGA
|
1068
1042
|
// test tga last because it's a crappy test!
|
1069
1043
|
if (stbi__tga_test(s))
|
1070
|
-
return stbi__tga_load(s,x,y,comp,req_comp
|
1044
|
+
return stbi__tga_load(s,x,y,comp,req_comp);
|
1071
1045
|
#endif
|
1072
1046
|
|
1073
1047
|
return stbi__errpuc("unknown image type", "Image not of any known type, or corrupt");
|
1074
1048
|
}
|
1075
1049
|
|
1076
|
-
static
|
1077
|
-
{
|
1078
|
-
int i;
|
1079
|
-
int img_len = w * h * channels;
|
1080
|
-
stbi_uc *reduced;
|
1081
|
-
|
1082
|
-
reduced = (stbi_uc *) stbi__malloc(img_len);
|
1083
|
-
if (reduced == NULL) return stbi__errpuc("outofmem", "Out of memory");
|
1084
|
-
|
1085
|
-
for (i = 0; i < img_len; ++i)
|
1086
|
-
reduced[i] = (stbi_uc)((orig[i] >> 8) & 0xFF); // top half of each byte is sufficient approx of 16->8 bit scaling
|
1087
|
-
|
1088
|
-
STBI_FREE(orig);
|
1089
|
-
return reduced;
|
1090
|
-
}
|
1091
|
-
|
1092
|
-
static stbi__uint16 *stbi__convert_8_to_16(stbi_uc *orig, int w, int h, int channels)
|
1093
|
-
{
|
1094
|
-
int i;
|
1095
|
-
int img_len = w * h * channels;
|
1096
|
-
stbi__uint16 *enlarged;
|
1097
|
-
|
1098
|
-
enlarged = (stbi__uint16 *) stbi__malloc(img_len*2);
|
1099
|
-
if (enlarged == NULL) return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory");
|
1100
|
-
|
1101
|
-
for (i = 0; i < img_len; ++i)
|
1102
|
-
enlarged[i] = (stbi__uint16)((orig[i] << 8) + orig[i]); // replicate to high and low byte, maps 0->0, 255->0xffff
|
1103
|
-
|
1104
|
-
STBI_FREE(orig);
|
1105
|
-
return enlarged;
|
1106
|
-
}
|
1107
|
-
|
1108
|
-
static unsigned char *stbi__load_and_postprocess_8bit(stbi__context *s, int *x, int *y, int *comp, int req_comp)
|
1109
|
-
{
|
1110
|
-
stbi__result_info ri;
|
1111
|
-
void *result = stbi__load_main(s, x, y, comp, req_comp, &ri, 8);
|
1112
|
-
|
1113
|
-
if (result == NULL)
|
1114
|
-
return NULL;
|
1115
|
-
|
1116
|
-
if (ri.bits_per_channel != 8) {
|
1117
|
-
STBI_ASSERT(ri.bits_per_channel == 16);
|
1118
|
-
result = stbi__convert_16_to_8((stbi__uint16 *) result, *x, *y, req_comp == 0 ? *comp : req_comp);
|
1119
|
-
ri.bits_per_channel = 8;
|
1120
|
-
}
|
1121
|
-
|
1122
|
-
// @TODO: move stbi__convert_format to here
|
1123
|
-
|
1124
|
-
if (stbi__vertically_flip_on_load) {
|
1125
|
-
int w = *x, h = *y;
|
1126
|
-
int channels = req_comp ? req_comp : *comp;
|
1127
|
-
int row,col,z;
|
1128
|
-
stbi_uc *image = (stbi_uc *) result;
|
1129
|
-
|
1130
|
-
// @OPTIMIZE: use a bigger temp buffer and memcpy multiple pixels at once
|
1131
|
-
for (row = 0; row < (h>>1); row++) {
|
1132
|
-
for (col = 0; col < w; col++) {
|
1133
|
-
for (z = 0; z < channels; z++) {
|
1134
|
-
stbi_uc temp = image[(row * w + col) * channels + z];
|
1135
|
-
image[(row * w + col) * channels + z] = image[((h - row - 1) * w + col) * channels + z];
|
1136
|
-
image[((h - row - 1) * w + col) * channels + z] = temp;
|
1137
|
-
}
|
1138
|
-
}
|
1139
|
-
}
|
1140
|
-
}
|
1141
|
-
|
1142
|
-
return (unsigned char *) result;
|
1143
|
-
}
|
1144
|
-
|
1145
|
-
static stbi__uint16 *stbi__load_and_postprocess_16bit(stbi__context *s, int *x, int *y, int *comp, int req_comp)
|
1050
|
+
static unsigned char *stbi__load_flip(stbi__context *s, int *x, int *y, int *comp, int req_comp)
|
1146
1051
|
{
|
1147
|
-
|
1148
|
-
void *result = stbi__load_main(s, x, y, comp, req_comp, &ri, 16);
|
1149
|
-
|
1150
|
-
if (result == NULL)
|
1151
|
-
return NULL;
|
1152
|
-
|
1153
|
-
if (ri.bits_per_channel != 16) {
|
1154
|
-
STBI_ASSERT(ri.bits_per_channel == 8);
|
1155
|
-
result = stbi__convert_8_to_16((stbi_uc *) result, *x, *y, req_comp == 0 ? *comp : req_comp);
|
1156
|
-
ri.bits_per_channel = 16;
|
1157
|
-
}
|
1052
|
+
unsigned char *result = stbi__load_main(s, x, y, comp, req_comp);
|
1158
1053
|
|
1159
|
-
|
1160
|
-
// @TODO: special case RGB-to-Y (and RGBA-to-YA) for 8-bit-to-16-bit case to keep more precision
|
1161
|
-
|
1162
|
-
if (stbi__vertically_flip_on_load) {
|
1054
|
+
if (stbi__vertically_flip_on_load && result != NULL) {
|
1163
1055
|
int w = *x, h = *y;
|
1164
|
-
int
|
1056
|
+
int depth = req_comp ? req_comp : *comp;
|
1165
1057
|
int row,col,z;
|
1166
|
-
|
1058
|
+
stbi_uc temp;
|
1167
1059
|
|
1168
1060
|
// @OPTIMIZE: use a bigger temp buffer and memcpy multiple pixels at once
|
1169
1061
|
for (row = 0; row < (h>>1); row++) {
|
1170
1062
|
for (col = 0; col < w; col++) {
|
1171
|
-
for (z = 0; z <
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1063
|
+
for (z = 0; z < depth; z++) {
|
1064
|
+
temp = result[(row * w + col) * depth + z];
|
1065
|
+
result[(row * w + col) * depth + z] = result[((h - row - 1) * w + col) * depth + z];
|
1066
|
+
result[((h - row - 1) * w + col) * depth + z] = temp;
|
1175
1067
|
}
|
1176
1068
|
}
|
1177
1069
|
}
|
1178
1070
|
}
|
1179
1071
|
|
1180
|
-
return
|
1072
|
+
return result;
|
1181
1073
|
}
|
1182
1074
|
|
1183
1075
|
#ifndef STBI_NO_HDR
|
@@ -1233,52 +1125,27 @@ STBIDEF stbi_uc *stbi_load_from_file(FILE *f, int *x, int *y, int *comp, int req
|
|
1233
1125
|
unsigned char *result;
|
1234
1126
|
stbi__context s;
|
1235
1127
|
stbi__start_file(&s,f);
|
1236
|
-
result =
|
1237
|
-
if (result) {
|
1238
|
-
// need to 'unget' all the characters in the IO buffer
|
1239
|
-
fseek(f, - (int) (s.img_buffer_end - s.img_buffer), SEEK_CUR);
|
1240
|
-
}
|
1241
|
-
return result;
|
1242
|
-
}
|
1243
|
-
|
1244
|
-
STBIDEF stbi__uint16 *stbi_load_from_file_16(FILE *f, int *x, int *y, int *comp, int req_comp)
|
1245
|
-
{
|
1246
|
-
stbi__uint16 *result;
|
1247
|
-
stbi__context s;
|
1248
|
-
stbi__start_file(&s,f);
|
1249
|
-
result = stbi__load_and_postprocess_16bit(&s,x,y,comp,req_comp);
|
1128
|
+
result = stbi__load_flip(&s,x,y,comp,req_comp);
|
1250
1129
|
if (result) {
|
1251
1130
|
// need to 'unget' all the characters in the IO buffer
|
1252
1131
|
fseek(f, - (int) (s.img_buffer_end - s.img_buffer), SEEK_CUR);
|
1253
1132
|
}
|
1254
1133
|
return result;
|
1255
1134
|
}
|
1256
|
-
|
1257
|
-
STBIDEF stbi_us *stbi_load_16(char const *filename, int *x, int *y, int *comp, int req_comp)
|
1258
|
-
{
|
1259
|
-
FILE *f = stbi__fopen(filename, "rb");
|
1260
|
-
stbi__uint16 *result;
|
1261
|
-
if (!f) return (stbi_us *) stbi__errpuc("can't fopen", "Unable to open file");
|
1262
|
-
result = stbi_load_from_file_16(f,x,y,comp,req_comp);
|
1263
|
-
fclose(f);
|
1264
|
-
return result;
|
1265
|
-
}
|
1266
|
-
|
1267
|
-
|
1268
1135
|
#endif //!STBI_NO_STDIO
|
1269
1136
|
|
1270
1137
|
STBIDEF stbi_uc *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp)
|
1271
1138
|
{
|
1272
1139
|
stbi__context s;
|
1273
1140
|
stbi__start_mem(&s,buffer,len);
|
1274
|
-
return
|
1141
|
+
return stbi__load_flip(&s,x,y,comp,req_comp);
|
1275
1142
|
}
|
1276
1143
|
|
1277
1144
|
STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp)
|
1278
1145
|
{
|
1279
1146
|
stbi__context s;
|
1280
1147
|
stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user);
|
1281
|
-
return
|
1148
|
+
return stbi__load_flip(&s,x,y,comp,req_comp);
|
1282
1149
|
}
|
1283
1150
|
|
1284
1151
|
#ifndef STBI_NO_LINEAR
|
@@ -1287,14 +1154,13 @@ static float *stbi__loadf_main(stbi__context *s, int *x, int *y, int *comp, int
|
|
1287
1154
|
unsigned char *data;
|
1288
1155
|
#ifndef STBI_NO_HDR
|
1289
1156
|
if (stbi__hdr_test(s)) {
|
1290
|
-
|
1291
|
-
float *hdr_data = stbi__hdr_load(s,x,y,comp,req_comp, &ri);
|
1157
|
+
float *hdr_data = stbi__hdr_load(s,x,y,comp,req_comp);
|
1292
1158
|
if (hdr_data)
|
1293
1159
|
stbi__float_postprocess(hdr_data,x,y,comp,req_comp);
|
1294
1160
|
return hdr_data;
|
1295
1161
|
}
|
1296
1162
|
#endif
|
1297
|
-
data =
|
1163
|
+
data = stbi__load_flip(s, x, y, comp, req_comp);
|
1298
1164
|
if (data)
|
1299
1165
|
return stbi__ldr_to_hdr(data, *x, *y, req_comp ? req_comp : *comp);
|
1300
1166
|
return stbi__errpf("unknown image type", "Image not of any known type, or corrupt");
|
@@ -1562,75 +1428,26 @@ static unsigned char *stbi__convert_format(unsigned char *data, int img_n, int r
|
|
1562
1428
|
unsigned char *src = data + j * x * img_n ;
|
1563
1429
|
unsigned char *dest = good + j * x * req_comp;
|
1564
1430
|
|
1565
|
-
#define
|
1566
|
-
#define
|
1567
|
-
// convert source image with img_n components to one with req_comp components;
|
1568
|
-
// avoid switch per pixel, so use switch per scanline and massive macros
|
1569
|
-
switch (STBI__COMBO(img_n, req_comp)) {
|
1570
|
-
STBI__CASE(1,2) { dest[0]=src[0], dest[1]=255; } break;
|
1571
|
-
STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
|
1572
|
-
STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=255; } break;
|
1573
|
-
STBI__CASE(2,1) { dest[0]=src[0]; } break;
|
1574
|
-
STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
|
1575
|
-
STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=src[1]; } break;
|
1576
|
-
STBI__CASE(3,4) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2],dest[3]=255; } break;
|
1577
|
-
STBI__CASE(3,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break;
|
1578
|
-
STBI__CASE(3,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]), dest[1] = 255; } break;
|
1579
|
-
STBI__CASE(4,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break;
|
1580
|
-
STBI__CASE(4,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]), dest[1] = src[3]; } break;
|
1581
|
-
STBI__CASE(4,3) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2]; } break;
|
1582
|
-
default: STBI_ASSERT(0);
|
1583
|
-
}
|
1584
|
-
#undef STBI__CASE
|
1585
|
-
}
|
1586
|
-
|
1587
|
-
STBI_FREE(data);
|
1588
|
-
return good;
|
1589
|
-
}
|
1590
|
-
|
1591
|
-
static stbi__uint16 stbi__compute_y_16(int r, int g, int b)
|
1592
|
-
{
|
1593
|
-
return (stbi__uint16) (((r*77) + (g*150) + (29*b)) >> 8);
|
1594
|
-
}
|
1595
|
-
|
1596
|
-
static stbi__uint16 *stbi__convert_format16(stbi__uint16 *data, int img_n, int req_comp, unsigned int x, unsigned int y)
|
1597
|
-
{
|
1598
|
-
int i,j;
|
1599
|
-
stbi__uint16 *good;
|
1600
|
-
|
1601
|
-
if (req_comp == img_n) return data;
|
1602
|
-
STBI_ASSERT(req_comp >= 1 && req_comp <= 4);
|
1603
|
-
|
1604
|
-
good = (stbi__uint16 *) stbi__malloc(req_comp * x * y * 2);
|
1605
|
-
if (good == NULL) {
|
1606
|
-
STBI_FREE(data);
|
1607
|
-
return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory");
|
1608
|
-
}
|
1609
|
-
|
1610
|
-
for (j=0; j < (int) y; ++j) {
|
1611
|
-
stbi__uint16 *src = data + j * x * img_n ;
|
1612
|
-
stbi__uint16 *dest = good + j * x * req_comp;
|
1613
|
-
|
1614
|
-
#define STBI__COMBO(a,b) ((a)*8+(b))
|
1615
|
-
#define STBI__CASE(a,b) case STBI__COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b)
|
1431
|
+
#define COMBO(a,b) ((a)*8+(b))
|
1432
|
+
#define CASE(a,b) case COMBO(a,b): for(i=x-1; i >= 0; --i, src += a, dest += b)
|
1616
1433
|
// convert source image with img_n components to one with req_comp components;
|
1617
1434
|
// avoid switch per pixel, so use switch per scanline and massive macros
|
1618
|
-
switch (
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1435
|
+
switch (COMBO(img_n, req_comp)) {
|
1436
|
+
CASE(1,2) dest[0]=src[0], dest[1]=255; break;
|
1437
|
+
CASE(1,3) dest[0]=dest[1]=dest[2]=src[0]; break;
|
1438
|
+
CASE(1,4) dest[0]=dest[1]=dest[2]=src[0], dest[3]=255; break;
|
1439
|
+
CASE(2,1) dest[0]=src[0]; break;
|
1440
|
+
CASE(2,3) dest[0]=dest[1]=dest[2]=src[0]; break;
|
1441
|
+
CASE(2,4) dest[0]=dest[1]=dest[2]=src[0], dest[3]=src[1]; break;
|
1442
|
+
CASE(3,4) dest[0]=src[0],dest[1]=src[1],dest[2]=src[2],dest[3]=255; break;
|
1443
|
+
CASE(3,1) dest[0]=stbi__compute_y(src[0],src[1],src[2]); break;
|
1444
|
+
CASE(3,2) dest[0]=stbi__compute_y(src[0],src[1],src[2]), dest[1] = 255; break;
|
1445
|
+
CASE(4,1) dest[0]=stbi__compute_y(src[0],src[1],src[2]); break;
|
1446
|
+
CASE(4,2) dest[0]=stbi__compute_y(src[0],src[1],src[2]), dest[1] = src[3]; break;
|
1447
|
+
CASE(4,3) dest[0]=src[0],dest[1]=src[1],dest[2]=src[2]; break;
|
1631
1448
|
default: STBI_ASSERT(0);
|
1632
1449
|
}
|
1633
|
-
#undef
|
1450
|
+
#undef CASE
|
1634
1451
|
}
|
1635
1452
|
|
1636
1453
|
STBI_FREE(data);
|
@@ -3689,7 +3506,7 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp
|
|
3689
3506
|
}
|
3690
3507
|
}
|
3691
3508
|
|
3692
|
-
static
|
3509
|
+
static unsigned char *stbi__jpeg_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
|
3693
3510
|
{
|
3694
3511
|
unsigned char* result;
|
3695
3512
|
stbi__jpeg* j = (stbi__jpeg*) stbi__malloc(sizeof(stbi__jpeg));
|
@@ -4349,37 +4166,37 @@ static int stbi__create_png_image_raw(stbi__png *a, stbi_uc *raw, stbi__uint32 r
|
|
4349
4166
|
// this is a little gross, so that we don't switch per-pixel or per-component
|
4350
4167
|
if (depth < 8 || img_n == out_n) {
|
4351
4168
|
int nk = (width - 1)*filter_bytes;
|
4352
|
-
#define
|
4169
|
+
#define CASE(f) \
|
4353
4170
|
case f: \
|
4354
4171
|
for (k=0; k < nk; ++k)
|
4355
4172
|
switch (filter) {
|
4356
4173
|
// "none" filter turns into a memcpy here; make that explicit.
|
4357
4174
|
case STBI__F_none: memcpy(cur, raw, nk); break;
|
4358
|
-
|
4359
|
-
|
4360
|
-
|
4361
|
-
|
4362
|
-
|
4363
|
-
|
4175
|
+
CASE(STBI__F_sub) cur[k] = STBI__BYTECAST(raw[k] + cur[k-filter_bytes]); break;
|
4176
|
+
CASE(STBI__F_up) cur[k] = STBI__BYTECAST(raw[k] + prior[k]); break;
|
4177
|
+
CASE(STBI__F_avg) cur[k] = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k-filter_bytes])>>1)); break;
|
4178
|
+
CASE(STBI__F_paeth) cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k-filter_bytes],prior[k],prior[k-filter_bytes])); break;
|
4179
|
+
CASE(STBI__F_avg_first) cur[k] = STBI__BYTECAST(raw[k] + (cur[k-filter_bytes] >> 1)); break;
|
4180
|
+
CASE(STBI__F_paeth_first) cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k-filter_bytes],0,0)); break;
|
4364
4181
|
}
|
4365
|
-
#undef
|
4182
|
+
#undef CASE
|
4366
4183
|
raw += nk;
|
4367
4184
|
} else {
|
4368
4185
|
STBI_ASSERT(img_n+1 == out_n);
|
4369
|
-
#define
|
4186
|
+
#define CASE(f) \
|
4370
4187
|
case f: \
|
4371
4188
|
for (i=x-1; i >= 1; --i, cur[filter_bytes]=255,raw+=filter_bytes,cur+=output_bytes,prior+=output_bytes) \
|
4372
4189
|
for (k=0; k < filter_bytes; ++k)
|
4373
4190
|
switch (filter) {
|
4374
|
-
|
4375
|
-
|
4376
|
-
|
4377
|
-
|
4378
|
-
|
4379
|
-
|
4380
|
-
|
4191
|
+
CASE(STBI__F_none) cur[k] = raw[k]; break;
|
4192
|
+
CASE(STBI__F_sub) cur[k] = STBI__BYTECAST(raw[k] + cur[k- output_bytes]); break;
|
4193
|
+
CASE(STBI__F_up) cur[k] = STBI__BYTECAST(raw[k] + prior[k]); break;
|
4194
|
+
CASE(STBI__F_avg) cur[k] = STBI__BYTECAST(raw[k] + ((prior[k] + cur[k- output_bytes])>>1)); break;
|
4195
|
+
CASE(STBI__F_paeth) cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k- output_bytes],prior[k],prior[k- output_bytes])); break;
|
4196
|
+
CASE(STBI__F_avg_first) cur[k] = STBI__BYTECAST(raw[k] + (cur[k- output_bytes] >> 1)); break;
|
4197
|
+
CASE(STBI__F_paeth_first) cur[k] = STBI__BYTECAST(raw[k] + stbi__paeth(cur[k- output_bytes],0,0)); break;
|
4381
4198
|
}
|
4382
|
-
#undef
|
4199
|
+
#undef CASE
|
4383
4200
|
|
4384
4201
|
// the loop above sets the high byte of the pixels' alpha, but for
|
4385
4202
|
// 16 bit png files we also need the low byte set. we'll do that here.
|
@@ -4611,6 +4428,27 @@ static int stbi__expand_png_palette(stbi__png *a, stbi_uc *palette, int len, int
|
|
4611
4428
|
return 1;
|
4612
4429
|
}
|
4613
4430
|
|
4431
|
+
static int stbi__reduce_png(stbi__png *p)
|
4432
|
+
{
|
4433
|
+
int i;
|
4434
|
+
int img_len = p->s->img_x * p->s->img_y * p->s->img_out_n;
|
4435
|
+
stbi_uc *reduced;
|
4436
|
+
stbi__uint16 *orig = (stbi__uint16*)p->out;
|
4437
|
+
|
4438
|
+
if (p->depth != 16) return 1; // don't need to do anything if not 16-bit data
|
4439
|
+
|
4440
|
+
reduced = (stbi_uc *)stbi__malloc(img_len);
|
4441
|
+
if (reduced == NULL) return stbi__err("outofmem", "Out of memory");
|
4442
|
+
|
4443
|
+
for (i = 0; i < img_len; ++i)
|
4444
|
+
reduced[i] = (stbi_uc)((orig[i] >> 8) & 0xFF); // top half of each byte is a decent approx of 16->8 bit scaling
|
4445
|
+
|
4446
|
+
p->out = reduced;
|
4447
|
+
STBI_FREE(orig);
|
4448
|
+
|
4449
|
+
return 1;
|
4450
|
+
}
|
4451
|
+
|
4614
4452
|
static int stbi__unpremultiply_on_load = 0;
|
4615
4453
|
static int stbi__de_iphone_flag = 0;
|
4616
4454
|
|
@@ -4750,7 +4588,7 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp)
|
|
4750
4588
|
if (c.length != (stbi__uint32) s->img_n*2) return stbi__err("bad tRNS len","Corrupt PNG");
|
4751
4589
|
has_trans = 1;
|
4752
4590
|
if (z->depth == 16) {
|
4753
|
-
for (k = 0; k < s->img_n; ++k) tc16[k] =
|
4591
|
+
for (k = 0; k < s->img_n; ++k) tc16[k] = stbi__get16be(s); // copy the values as-is
|
4754
4592
|
} else {
|
4755
4593
|
for (k = 0; k < s->img_n; ++k) tc[k] = (stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z->depth]; // non 8-bit images will be larger
|
4756
4594
|
}
|
@@ -4837,19 +4675,20 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp)
|
|
4837
4675
|
}
|
4838
4676
|
}
|
4839
4677
|
|
4840
|
-
static
|
4678
|
+
static unsigned char *stbi__do_png(stbi__png *p, int *x, int *y, int *n, int req_comp)
|
4841
4679
|
{
|
4842
|
-
|
4680
|
+
unsigned char *result=NULL;
|
4843
4681
|
if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error");
|
4844
4682
|
if (stbi__parse_png_file(p, STBI__SCAN_load, req_comp)) {
|
4845
|
-
|
4683
|
+
if (p->depth == 16) {
|
4684
|
+
if (!stbi__reduce_png(p)) {
|
4685
|
+
return result;
|
4686
|
+
}
|
4687
|
+
}
|
4846
4688
|
result = p->out;
|
4847
4689
|
p->out = NULL;
|
4848
4690
|
if (req_comp && req_comp != p->s->img_out_n) {
|
4849
|
-
|
4850
|
-
result = stbi__convert_format((unsigned char *) result, p->s->img_out_n, req_comp, p->s->img_x, p->s->img_y);
|
4851
|
-
else
|
4852
|
-
result = stbi__convert_format16((stbi__uint16 *) result, p->s->img_out_n, req_comp, p->s->img_x, p->s->img_y);
|
4691
|
+
result = stbi__convert_format(result, p->s->img_out_n, req_comp, p->s->img_x, p->s->img_y);
|
4853
4692
|
p->s->img_out_n = req_comp;
|
4854
4693
|
if (result == NULL) return result;
|
4855
4694
|
}
|
@@ -4864,11 +4703,11 @@ static void *stbi__do_png(stbi__png *p, int *x, int *y, int *n, int req_comp, st
|
|
4864
4703
|
return result;
|
4865
4704
|
}
|
4866
4705
|
|
4867
|
-
static
|
4706
|
+
static unsigned char *stbi__png_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
|
4868
4707
|
{
|
4869
4708
|
stbi__png p;
|
4870
4709
|
p.s = s;
|
4871
|
-
return stbi__do_png(&p, x,y,comp,req_comp
|
4710
|
+
return stbi__do_png(&p, x,y,comp,req_comp);
|
4872
4711
|
}
|
4873
4712
|
|
4874
4713
|
static int stbi__png_test(stbi__context *s)
|
@@ -5056,7 +4895,7 @@ static void *stbi__bmp_parse_header(stbi__context *s, stbi__bmp_data *info)
|
|
5056
4895
|
}
|
5057
4896
|
|
5058
4897
|
|
5059
|
-
static
|
4898
|
+
static stbi_uc *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
|
5060
4899
|
{
|
5061
4900
|
stbi_uc *out;
|
5062
4901
|
unsigned int mr=0,mg=0,mb=0,ma=0, all_a;
|
@@ -5064,7 +4903,6 @@ static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req
|
|
5064
4903
|
int psize=0,i,j,width;
|
5065
4904
|
int flip_vertically, pad, target;
|
5066
4905
|
stbi__bmp_data info;
|
5067
|
-
STBI_NOTUSED(ri);
|
5068
4906
|
|
5069
4907
|
info.all_a = 255;
|
5070
4908
|
if (stbi__bmp_parse_header(s, &info) == NULL)
|
@@ -5331,18 +5169,18 @@ errorEnd:
|
|
5331
5169
|
}
|
5332
5170
|
|
5333
5171
|
// read 16bit value and convert to 24bit RGB
|
5334
|
-
|
5172
|
+
void stbi__tga_read_rgb16(stbi__context *s, stbi_uc* out)
|
5335
5173
|
{
|
5336
|
-
stbi__uint16 px =
|
5174
|
+
stbi__uint16 px = stbi__get16le(s);
|
5337
5175
|
stbi__uint16 fiveBitMask = 31;
|
5338
5176
|
// we have 3 channels with 5bits each
|
5339
5177
|
int r = (px >> 10) & fiveBitMask;
|
5340
5178
|
int g = (px >> 5) & fiveBitMask;
|
5341
5179
|
int b = px & fiveBitMask;
|
5342
5180
|
// Note that this saves the data in RGB(A) order, so it doesn't need to be swapped later
|
5343
|
-
out[0] = (
|
5344
|
-
out[1] = (
|
5345
|
-
out[2] = (
|
5181
|
+
out[0] = (r * 255)/31;
|
5182
|
+
out[1] = (g * 255)/31;
|
5183
|
+
out[2] = (b * 255)/31;
|
5346
5184
|
|
5347
5185
|
// some people claim that the most significant bit might be used for alpha
|
5348
5186
|
// (possibly if an alpha-bit is set in the "image descriptor byte")
|
@@ -5350,7 +5188,7 @@ static void stbi__tga_read_rgb16(stbi__context *s, stbi_uc* out)
|
|
5350
5188
|
// so let's treat all 15 and 16bit TGAs as RGB with no alpha.
|
5351
5189
|
}
|
5352
5190
|
|
5353
|
-
static
|
5191
|
+
static stbi_uc *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
|
5354
5192
|
{
|
5355
5193
|
// read in the TGA header stuff
|
5356
5194
|
int tga_offset = stbi__get8(s);
|
@@ -5376,7 +5214,6 @@ static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req
|
|
5376
5214
|
int RLE_count = 0;
|
5377
5215
|
int RLE_repeating = 0;
|
5378
5216
|
int read_next_pixel = 1;
|
5379
|
-
STBI_NOTUSED(ri);
|
5380
5217
|
|
5381
5218
|
// do a tiny bit of precessing
|
5382
5219
|
if ( tga_image_type >= 8 )
|
@@ -5594,7 +5431,7 @@ static int stbi__psd_decode_rle(stbi__context *s, stbi_uc *p, int pixelCount)
|
|
5594
5431
|
return 1;
|
5595
5432
|
}
|
5596
5433
|
|
5597
|
-
static
|
5434
|
+
static stbi_uc *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
|
5598
5435
|
{
|
5599
5436
|
int pixelCount;
|
5600
5437
|
int channelCount, compression;
|
@@ -5602,7 +5439,6 @@ static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req
|
|
5602
5439
|
int bitdepth;
|
5603
5440
|
int w,h;
|
5604
5441
|
stbi_uc *out;
|
5605
|
-
STBI_NOTUSED(ri);
|
5606
5442
|
|
5607
5443
|
// Check identifier
|
5608
5444
|
if (stbi__get32be(s) != 0x38425053) // "8BPS"
|
@@ -5664,13 +5500,7 @@ static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req
|
|
5664
5500
|
return stbi__errpuc("too large", "Corrupt PSD");
|
5665
5501
|
|
5666
5502
|
// Create the destination image.
|
5667
|
-
|
5668
|
-
if (!compression && bitdepth == 16 && bpc == 16) {
|
5669
|
-
out = (stbi_uc *) stbi__malloc_mad3(8, w, h, 0);
|
5670
|
-
ri->bits_per_channel = 16;
|
5671
|
-
} else
|
5672
|
-
out = (stbi_uc *) stbi__malloc(4 * w*h);
|
5673
|
-
|
5503
|
+
out = (stbi_uc *) stbi__malloc_mad3(4, w, h, 0);
|
5674
5504
|
if (!out) return stbi__errpuc("outofmem", "Out of memory");
|
5675
5505
|
pixelCount = w*h;
|
5676
5506
|
|
@@ -5711,77 +5541,48 @@ static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req
|
|
5711
5541
|
|
5712
5542
|
} else {
|
5713
5543
|
// We're at the raw image data. It's each channel in order (Red, Green, Blue, Alpha, ...)
|
5714
|
-
// where each channel consists of an 8-bit
|
5544
|
+
// where each channel consists of an 8-bit value for each pixel in the image.
|
5715
5545
|
|
5716
5546
|
// Read the data by channel.
|
5717
5547
|
for (channel = 0; channel < 4; channel++) {
|
5548
|
+
stbi_uc *p;
|
5549
|
+
|
5550
|
+
p = out + channel;
|
5718
5551
|
if (channel >= channelCount) {
|
5719
5552
|
// Fill this channel with default data.
|
5720
|
-
|
5721
|
-
|
5722
|
-
|
5723
|
-
for (i = 0; i < pixelCount; i++, q += 4)
|
5724
|
-
*q = val;
|
5725
|
-
} else {
|
5726
|
-
stbi_uc *p = out+channel;
|
5727
|
-
stbi_uc val = channel == 3 ? 255 : 0;
|
5728
|
-
for (i = 0; i < pixelCount; i++, p += 4)
|
5729
|
-
*p = val;
|
5730
|
-
}
|
5553
|
+
stbi_uc val = channel == 3 ? 255 : 0;
|
5554
|
+
for (i = 0; i < pixelCount; i++, p += 4)
|
5555
|
+
*p = val;
|
5731
5556
|
} else {
|
5732
|
-
|
5733
|
-
|
5734
|
-
for (i = 0; i < pixelCount; i++,
|
5735
|
-
*
|
5557
|
+
// Read the data.
|
5558
|
+
if (bitdepth == 16) {
|
5559
|
+
for (i = 0; i < pixelCount; i++, p += 4)
|
5560
|
+
*p = (stbi_uc) (stbi__get16be(s) >> 8);
|
5736
5561
|
} else {
|
5737
|
-
|
5738
|
-
|
5739
|
-
for (i = 0; i < pixelCount; i++, p += 4)
|
5740
|
-
*p = (stbi_uc) (stbi__get16be(s) >> 8);
|
5741
|
-
} else {
|
5742
|
-
for (i = 0; i < pixelCount; i++, p += 4)
|
5743
|
-
*p = stbi__get8(s);
|
5744
|
-
}
|
5562
|
+
for (i = 0; i < pixelCount; i++, p += 4)
|
5563
|
+
*p = stbi__get8(s);
|
5745
5564
|
}
|
5746
5565
|
}
|
5747
5566
|
}
|
5748
5567
|
}
|
5749
5568
|
|
5750
|
-
// remove weird white matte from PSD
|
5751
5569
|
if (channelCount >= 4) {
|
5752
|
-
|
5753
|
-
|
5754
|
-
|
5755
|
-
|
5756
|
-
|
5757
|
-
|
5758
|
-
|
5759
|
-
|
5760
|
-
|
5761
|
-
|
5762
|
-
}
|
5763
|
-
}
|
5764
|
-
} else {
|
5765
|
-
for (i=0; i < w*h; ++i) {
|
5766
|
-
unsigned char *pixel = out + 4*i;
|
5767
|
-
if (pixel[3] != 0 && pixel[3] != 255) {
|
5768
|
-
float a = pixel[3] / 255.0f;
|
5769
|
-
float ra = 1.0f / a;
|
5770
|
-
float inv_a = 255.0f * (1 - ra);
|
5771
|
-
pixel[0] = (unsigned char) (pixel[0]*ra + inv_a);
|
5772
|
-
pixel[1] = (unsigned char) (pixel[1]*ra + inv_a);
|
5773
|
-
pixel[2] = (unsigned char) (pixel[2]*ra + inv_a);
|
5774
|
-
}
|
5570
|
+
for (i=0; i < w*h; ++i) {
|
5571
|
+
unsigned char *pixel = out + 4*i;
|
5572
|
+
if (pixel[3] != 0 && pixel[3] != 255) {
|
5573
|
+
// remove weird white matte from PSD
|
5574
|
+
float a = pixel[3] / 255.0f;
|
5575
|
+
float ra = 1.0f / a;
|
5576
|
+
float inv_a = 255.0f * (1 - ra);
|
5577
|
+
pixel[0] = (unsigned char) (pixel[0]*ra + inv_a);
|
5578
|
+
pixel[1] = (unsigned char) (pixel[1]*ra + inv_a);
|
5579
|
+
pixel[2] = (unsigned char) (pixel[2]*ra + inv_a);
|
5775
5580
|
}
|
5776
5581
|
}
|
5777
5582
|
}
|
5778
5583
|
|
5779
|
-
// convert to desired output format
|
5780
5584
|
if (req_comp && req_comp != 4) {
|
5781
|
-
|
5782
|
-
out = (stbi_uc *) stbi__convert_format16((stbi__uint16 *) out, 4, req_comp, w, h);
|
5783
|
-
else
|
5784
|
-
out = stbi__convert_format(out, 4, req_comp, w, h);
|
5585
|
+
out = stbi__convert_format(out, 4, req_comp, w, h);
|
5785
5586
|
if (out == NULL) return out; // stbi__convert_format frees input on failure
|
5786
5587
|
}
|
5787
5588
|
|
@@ -5965,11 +5766,10 @@ static stbi_uc *stbi__pic_load_core(stbi__context *s,int width,int height,int *c
|
|
5965
5766
|
return result;
|
5966
5767
|
}
|
5967
5768
|
|
5968
|
-
static
|
5769
|
+
static stbi_uc *stbi__pic_load(stbi__context *s,int *px,int *py,int *comp,int req_comp)
|
5969
5770
|
{
|
5970
5771
|
stbi_uc *result;
|
5971
5772
|
int i, x,y;
|
5972
|
-
STBI_NOTUSED(ri);
|
5973
5773
|
|
5974
5774
|
for (i=0; i<92; ++i)
|
5975
5775
|
stbi__get8(s);
|
@@ -6354,12 +6154,11 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i
|
|
6354
6154
|
STBI_NOTUSED(req_comp);
|
6355
6155
|
}
|
6356
6156
|
|
6357
|
-
static
|
6157
|
+
static stbi_uc *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
|
6358
6158
|
{
|
6359
6159
|
stbi_uc *u = 0;
|
6360
6160
|
stbi__gif* g = (stbi__gif*) stbi__malloc(sizeof(stbi__gif));
|
6361
6161
|
memset(g, 0, sizeof(*g));
|
6362
|
-
STBI_NOTUSED(ri);
|
6363
6162
|
|
6364
6163
|
u = stbi__gif_load_next(s, g, comp, req_comp);
|
6365
6164
|
if (u == (stbi_uc *) s) u = 0; // end of animated gif marker
|
@@ -6385,24 +6184,20 @@ static int stbi__gif_info(stbi__context *s, int *x, int *y, int *comp)
|
|
6385
6184
|
// Radiance RGBE HDR loader
|
6386
6185
|
// originally by Nicolas Schulz
|
6387
6186
|
#ifndef STBI_NO_HDR
|
6388
|
-
static int stbi__hdr_test_core(stbi__context *s
|
6187
|
+
static int stbi__hdr_test_core(stbi__context *s)
|
6389
6188
|
{
|
6189
|
+
const char *signature = "#?RADIANCE\n";
|
6390
6190
|
int i;
|
6391
6191
|
for (i=0; signature[i]; ++i)
|
6392
6192
|
if (stbi__get8(s) != signature[i])
|
6393
|
-
|
6394
|
-
stbi__rewind(s);
|
6193
|
+
return 0;
|
6395
6194
|
return 1;
|
6396
6195
|
}
|
6397
6196
|
|
6398
6197
|
static int stbi__hdr_test(stbi__context* s)
|
6399
6198
|
{
|
6400
|
-
int r = stbi__hdr_test_core(s
|
6199
|
+
int r = stbi__hdr_test_core(s);
|
6401
6200
|
stbi__rewind(s);
|
6402
|
-
if(!r) {
|
6403
|
-
r = stbi__hdr_test_core(s, "#?RGBE\n");
|
6404
|
-
stbi__rewind(s);
|
6405
|
-
}
|
6406
6201
|
return r;
|
6407
6202
|
}
|
6408
6203
|
|
@@ -6456,7 +6251,7 @@ static void stbi__hdr_convert(float *output, stbi_uc *input, int req_comp)
|
|
6456
6251
|
}
|
6457
6252
|
}
|
6458
6253
|
|
6459
|
-
static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int req_comp
|
6254
|
+
static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
|
6460
6255
|
{
|
6461
6256
|
char buffer[STBI__HDR_BUFLEN];
|
6462
6257
|
char *token;
|
@@ -6467,12 +6262,10 @@ static float *stbi__hdr_load(stbi__context *s, int *x, int *y, int *comp, int re
|
|
6467
6262
|
int len;
|
6468
6263
|
unsigned char count, value;
|
6469
6264
|
int i, j, k, c1,c2, z;
|
6470
|
-
|
6471
|
-
STBI_NOTUSED(ri);
|
6265
|
+
|
6472
6266
|
|
6473
6267
|
// Check identifier
|
6474
|
-
|
6475
|
-
if (strcmp(headerToken, "#?RADIANCE") != 0 && strcmp(headerToken, "#?RGBE") != 0)
|
6268
|
+
if (strcmp(stbi__hdr_gettoken(s,buffer), "#?RADIANCE") != 0)
|
6476
6269
|
return stbi__errpf("not HDR", "Corrupt HDR image");
|
6477
6270
|
|
6478
6271
|
// Parse header
|
@@ -6756,14 +6549,11 @@ static int stbi__pnm_test(stbi__context *s)
|
|
6756
6549
|
return 1;
|
6757
6550
|
}
|
6758
6551
|
|
6759
|
-
static
|
6552
|
+
static stbi_uc *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp)
|
6760
6553
|
{
|
6761
6554
|
stbi_uc *out;
|
6762
|
-
STBI_NOTUSED(ri);
|
6763
|
-
|
6764
6555
|
if (!stbi__pnm_info(s, (int *)&s->img_x, (int *)&s->img_y, (int *)&s->img_n))
|
6765
6556
|
return 0;
|
6766
|
-
|
6767
6557
|
*x = s->img_x;
|
6768
6558
|
*y = s->img_y;
|
6769
6559
|
*comp = s->img_n;
|
@@ -6936,7 +6726,6 @@ STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const *c, void *user, int
|
|
6936
6726
|
|
6937
6727
|
/*
|
6938
6728
|
revision history:
|
6939
|
-
2.13 (2016-11-29) add 16-bit API, only supported for PNG right now
|
6940
6729
|
2.12 (2016-04-02) fix typo in 2.11 PSD fix that caused crashes
|
6941
6730
|
2.11 (2016-04-02) allocate large structures on the stack
|
6942
6731
|
remove white matting for transparent PSD
|