ray 0.1.0.pre1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +235 -32
- data/Rakefile +20 -49
- data/ext/audio.c +68 -0
- data/ext/audio_source.c +197 -0
- data/ext/buffer_renderer.c +130 -0
- data/ext/color.c +179 -0
- data/ext/drawable.c +446 -0
- data/ext/event.c +337 -0
- data/ext/extconf.rb +80 -6
- data/ext/font.c +97 -0
- data/ext/gl.c +114 -0
- data/ext/gl_buffer.c +224 -0
- data/ext/gl_index_buffer.c +202 -0
- data/ext/gl_int_array.c +139 -0
- data/ext/gl_vertex.c +157 -0
- data/ext/image.c +263 -0
- data/ext/image_target.c +84 -0
- data/ext/input.c +53 -0
- data/ext/matrix.c +374 -0
- data/ext/music.c +113 -0
- data/ext/polygon.c +426 -0
- data/ext/ray.c +59 -0
- data/ext/ray.h +168 -0
- data/ext/rect.c +255 -0
- data/ext/say.h +31 -0
- data/ext/say_all.h +77 -0
- data/ext/say_arial.h +14689 -0
- data/ext/say_array.c +124 -0
- data/ext/say_array.h +34 -0
- data/ext/say_audio.c +64 -0
- data/ext/say_audio.h +170 -0
- data/ext/say_audio_context.c +40 -0
- data/ext/say_audio_source.c +96 -0
- data/ext/say_basic_type.c +17 -0
- data/ext/say_basic_type.h +47 -0
- data/ext/say_buffer.c +277 -0
- data/ext/say_buffer.h +37 -0
- data/ext/say_buffer_renderer.c +121 -0
- data/ext/say_buffer_renderer.h +33 -0
- data/ext/say_buffer_slice.c +247 -0
- data/ext/say_buffer_slice.h +29 -0
- data/ext/say_clean_up.c +14 -0
- data/ext/say_context.c +163 -0
- data/ext/say_context.h +26 -0
- data/ext/say_drawable.c +350 -0
- data/ext/say_drawable.h +100 -0
- data/ext/say_error.c +27 -0
- data/ext/say_event.h +213 -0
- data/ext/say_font.c +335 -0
- data/ext/say_font.h +51 -0
- data/ext/say_image.c +283 -0
- data/ext/say_image.h +52 -0
- data/ext/say_image_target.c +134 -0
- data/ext/say_image_target.h +25 -0
- data/ext/say_imp.h +70 -0
- data/ext/say_index_buffer.c +90 -0
- data/ext/say_index_buffer.h +29 -0
- data/ext/say_index_buffer_slice.c +227 -0
- data/ext/say_index_buffer_slice.h +28 -0
- data/ext/say_input.c +35 -0
- data/ext/say_matrix.c +314 -0
- data/ext/say_matrix.h +55 -0
- data/ext/say_music.c +225 -0
- data/ext/say_osx.h +62 -0
- data/ext/say_osx_context.h +98 -0
- data/ext/say_osx_window.h +766 -0
- data/ext/say_polygon.c +358 -0
- data/ext/say_polygon.h +62 -0
- data/ext/say_renderer.c +42 -0
- data/ext/say_renderer.h +22 -0
- data/ext/say_shader.c +375 -0
- data/ext/say_shader.h +91 -0
- data/ext/say_sound.c +67 -0
- data/ext/say_sound_buffer.c +96 -0
- data/ext/say_sprite.c +273 -0
- data/ext/say_sprite.h +53 -0
- data/ext/say_string.c +9 -0
- data/ext/say_table.c +86 -0
- data/ext/say_table.h +24 -0
- data/ext/say_target.c +264 -0
- data/ext/say_target.h +67 -0
- data/ext/say_text.c +441 -0
- data/ext/say_text.h +56 -0
- data/ext/say_thread.c +46 -0
- data/ext/say_thread.h +39 -0
- data/ext/say_thread_variable.c +44 -0
- data/ext/say_utf.c +62 -0
- data/ext/say_vertex_type.c +113 -0
- data/ext/say_vertex_type.h +40 -0
- data/ext/say_vfile.c +57 -0
- data/ext/say_view.c +150 -0
- data/ext/say_view.h +44 -0
- data/ext/say_win.h +24 -0
- data/ext/say_win_context.h +91 -0
- data/ext/say_win_window.h +670 -0
- data/ext/say_window.c +155 -0
- data/ext/say_window.h +43 -0
- data/ext/say_x11.h +41 -0
- data/ext/say_x11_context.h +96 -0
- data/ext/say_x11_window.h +818 -0
- data/ext/shader.c +302 -0
- data/ext/sound.c +118 -0
- data/ext/sound_buffer.c +75 -0
- data/ext/sprite.c +241 -0
- data/ext/stb_image.h +4971 -0
- data/ext/stb_image_write.h +511 -0
- data/ext/target.c +184 -0
- data/ext/text.c +162 -0
- data/ext/utils.c +10 -0
- data/ext/vector.c +261 -0
- data/ext/vendor/freetype/bin/freetype6.dll +0 -0
- data/ext/vendor/freetype/bin/zlib1.dll +0 -0
- data/ext/vendor/freetype/include/freetype2/freetype/config/ftconfig.h +350 -0
- data/ext/vendor/freetype/include/freetype2/freetype/config/ftheader.h +729 -0
- data/ext/vendor/freetype/include/freetype2/freetype/config/ftmodule.h +22 -0
- data/ext/vendor/freetype/include/freetype2/freetype/config/ftoption.h +695 -0
- data/ext/vendor/freetype/include/freetype2/freetype/config/ftstdlib.h +180 -0
- data/ext/vendor/freetype/include/freetype2/freetype/freetype.h +3434 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftbbox.h +94 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftbdf.h +200 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftbitmap.h +206 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftcache.h +1110 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftchapters.h +100 -0
- data/ext/vendor/freetype/include/freetype2/freetype/fterrdef.h +239 -0
- data/ext/vendor/freetype/include/freetype2/freetype/fterrors.h +206 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftgasp.h +113 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftglyph.h +575 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftgxval.h +358 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftgzip.h +102 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftimage.h +1237 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftincrem.h +331 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftlcdfil.h +166 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftlist.h +273 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftlzw.h +99 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftmac.h +272 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftmm.h +378 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftmodapi.h +406 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftmoderr.h +155 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftotval.h +198 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftoutln.h +526 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftpfr.h +172 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftrender.h +229 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftsizes.h +159 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftsnames.h +170 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftstroke.h +716 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftsynth.h +73 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftsystem.h +346 -0
- data/ext/vendor/freetype/include/freetype2/freetype/fttrigon.h +350 -0
- data/ext/vendor/freetype/include/freetype2/freetype/fttypes.h +583 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftwinfnt.h +263 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ftxf86.h +80 -0
- data/ext/vendor/freetype/include/freetype2/freetype/t1tables.h +450 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ttnameid.h +1132 -0
- data/ext/vendor/freetype/include/freetype2/freetype/tttables.h +756 -0
- data/ext/vendor/freetype/include/freetype2/freetype/tttags.h +99 -0
- data/ext/vendor/freetype/include/freetype2/freetype/ttunpat.h +59 -0
- data/ext/vendor/freetype/include/ft2build.h +61 -0
- data/ext/vendor/freetype/lib/freetype-bcc.lib +0 -0
- data/ext/vendor/freetype/lib/freetype6.def +249 -0
- data/ext/vendor/freetype/lib/libfreetype.dll.a +0 -0
- data/ext/vendor/freetype/lib/tmp.freetype.lib +0 -0
- data/ext/vendor/glew/LICENSE.txt +73 -0
- data/ext/vendor/glew/README.txt +18 -0
- data/ext/vendor/glew/include/GL/glew.h +15507 -0
- data/ext/vendor/glew/include/GL/glxew.h +1568 -0
- data/ext/vendor/glew/include/GL/wglew.h +1361 -0
- data/ext/vendor/glew/lib/glew32.dll +0 -0
- data/ext/vendor/glew/lib/glew32mx.dll +0 -0
- data/ext/vendor/glew/lib/libglew32.a +0 -0
- data/ext/vendor/glew/lib/libglew32.dll.a +0 -0
- data/ext/vendor/glew/lib/libglew32mx.a +0 -0
- data/ext/vendor/glew/lib/libglew32mx.dll.a +0 -0
- data/ext/vendor/openal/COPYING +484 -0
- data/ext/vendor/openal/Win32/soft_oal.dll +0 -0
- data/ext/vendor/openal/include/AL/al.h +724 -0
- data/ext/vendor/openal/include/AL/alc.h +277 -0
- data/ext/vendor/openal/include/AL/alext.h +165 -0
- data/ext/vendor/openal/include/AL/efx-creative.h +3 -0
- data/ext/vendor/openal/include/AL/efx.h +758 -0
- data/ext/vendor/openal/lib/libOpenAL32.dll.a +0 -0
- data/ext/vendor/sndfile/bin/libsndfile-1.dll +0 -0
- data/ext/vendor/sndfile/include/sndfile.h +666 -0
- data/ext/vendor/sndfile/include/sndfile.hh +422 -0
- data/ext/vendor/sndfile/lib/libsndfile-1.def +41 -0
- data/ext/vendor/sndfile/lib/libsndfile-1.lib +0 -0
- data/ext/vertex.c +96 -0
- data/ext/view.c +131 -0
- data/ext/window.c +183 -0
- data/lib/ray/animation.rb +248 -0
- data/lib/ray/animation/block_animation.rb +36 -0
- data/lib/ray/animation/circular_motion.rb +57 -0
- data/lib/ray/animation/color_variation.rb +102 -0
- data/lib/ray/animation/combination.rb +71 -0
- data/lib/ray/animation/float_variation.rb +76 -0
- data/lib/ray/animation/sequence.rb +65 -0
- data/lib/ray/animation/sprite_animation.rb +68 -0
- data/lib/ray/animation/vector_variation.rb +111 -0
- data/lib/ray/animation_list.rb +50 -0
- data/lib/ray/audio.rb +4 -7
- data/lib/ray/buffer_renderer.rb +9 -0
- data/lib/ray/color.rb +41 -6
- data/lib/ray/drawable.rb +34 -9
- data/lib/ray/dsl.rb +6 -0
- data/lib/ray/dsl/event.rb +1 -1
- data/lib/ray/dsl/event_listener.rb +14 -10
- data/lib/ray/dsl/event_raiser.rb +5 -2
- data/lib/ray/dsl/event_runner.rb +4 -10
- data/lib/ray/dsl/event_translator.rb +67 -99
- data/lib/ray/dsl/handler.rb +1 -1
- data/lib/ray/dsl/matcher.rb +40 -27
- data/lib/ray/event.rb +22 -0
- data/lib/ray/font.rb +0 -42
- data/lib/ray/font_set.rb +3 -7
- data/lib/ray/game.rb +33 -73
- data/lib/ray/gl/int_array.rb +24 -0
- data/lib/ray/gl/vertex.rb +106 -0
- data/lib/ray/helper.rb +25 -11
- data/lib/ray/image.rb +9 -154
- data/lib/ray/image_set.rb +3 -8
- data/lib/ray/image_target.rb +12 -0
- data/lib/ray/matrix.rb +90 -0
- data/lib/ray/music.rb +12 -0
- data/lib/ray/polygon.rb +77 -0
- data/lib/ray/ray.rb +45 -13
- data/lib/ray/rect.rb +14 -3
- data/lib/ray/resource_set.rb +18 -35
- data/lib/ray/scene.rb +43 -81
- data/lib/ray/scene_list.rb +12 -5
- data/lib/ray/shader.rb +82 -0
- data/lib/ray/sound.rb +18 -0
- data/lib/ray/sound_buffer.rb +6 -0
- data/lib/ray/sound_buffer_set.rb +32 -0
- data/lib/ray/sprite.rb +111 -97
- data/lib/ray/target.rb +18 -0
- data/lib/ray/text.rb +80 -58
- data/lib/ray/text_helper.rb +21 -27
- data/lib/ray/turtle.rb +49 -38
- data/lib/ray/vector.rb +76 -1
- data/lib/ray/vertex.rb +24 -0
- data/lib/ray/view.rb +47 -0
- data/lib/ray/window.rb +23 -0
- data/samples/_media/Beep.wav +0 -0
- data/samples/_media/CptnRuby Gem.png +0 -0
- data/samples/_media/CptnRuby Map.txt +25 -0
- data/samples/_media/CptnRuby Tileset.png +0 -0
- data/samples/_media/CptnRuby.png +0 -0
- data/samples/_media/Space.png +0 -0
- data/samples/_media/Star.png +0 -0
- data/samples/_media/Starfighter.png +0 -0
- data/samples/animation/chain.rb +33 -0
- data/samples/animation/circle.rb +38 -0
- data/samples/animation/color.rb +18 -0
- data/samples/animation/rotation.rb +17 -0
- data/samples/animation/sequence.rb +33 -0
- data/samples/animation/shader.rb +65 -0
- data/samples/animation/sprite_motion.rb +103 -0
- data/samples/animation/translation.rb +23 -0
- data/samples/audio/spacial.rb +25 -11
- data/samples/buffer/buffer.rb +28 -0
- data/samples/buffer/index_buffer.rb +36 -0
- data/samples/buffer/renderer.rb +27 -0
- data/samples/cptn_ruby/cptn_ruby.rb +279 -0
- data/samples/hello_world/hello.rb +2 -2
- data/samples/hello_world/hello_dsl.rb +3 -3
- data/samples/hello_world/text.rb +2 -2
- data/samples/opengl/cube.rb +124 -0
- data/samples/opengl/image.rb +36 -16
- data/samples/opengl/obj_loader.rb +99 -0
- data/samples/opengl/opengl.rb +24 -18
- data/samples/opengl/shader.rb +36 -26
- data/samples/pong/pong.rb +41 -39
- data/samples/{run_scene.rb → scenes/run_scene.rb} +21 -7
- data/samples/shaders/geometry.rb +98 -0
- data/samples/shaders/scene.rb +19 -12
- data/samples/shaders/shaders.rb +34 -17
- data/samples/shaders/shape.rb +12 -7
- data/samples/sokoban/level_1 +11 -7
- data/samples/sokoban/sokoban.rb +36 -63
- data/samples/starfighter/starfighter.rb +159 -0
- data/samples/test/actual_scene.rb +3 -3
- data/samples/test/scene_riot.rb +4 -4
- data/samples/test/scene_spec.rb +3 -3
- data/samples/test/scene_test_unit.rb +1 -1
- data/samples/turtle/byzantium.rb +10 -5
- data/samples/turtle/hilbert.rb +16 -11
- data/samples/turtle/koch.rb +16 -11
- data/samples/turtle/mandala.rb +43 -38
- data/samples/turtle/tree.rb +13 -8
- data/samples/view/resize.rb +26 -0
- data/samples/view/view.rb +35 -0
- data/samples/window/all_events.rb +44 -0
- data/samples/window/change_title.rb +16 -0
- data/samples/window/fullscreen.rb +18 -0
- data/samples/window/get_pixel.rb +29 -0
- data/samples/window/icon.rb +88 -0
- data/samples/window/input.rb +27 -0
- data/samples/window/no_border.rb +16 -0
- data/samples/window/resize.rb +24 -0
- data/test/animation/color_variation_test.rb +64 -0
- data/test/animation/combination_test.rb +35 -0
- data/test/animation/float_variation_test.rb +75 -0
- data/test/animation/vector_variation_test.rb +123 -0
- data/test/animation_list_test.rb +122 -0
- data/test/animation_test.rb +83 -0
- data/test/audio_test.rb +88 -33
- data/test/buffer_renderer_test.rb +38 -0
- data/test/color_test.rb +31 -22
- data/test/drawable_test.rb +207 -7
- data/test/dsl_test.rb +25 -7
- data/test/font_test.rb +6 -40
- data/test/game_test.rb +76 -0
- data/test/gl_buffer_test.rb +26 -0
- data/test/gl_index_buffer_test.rb +17 -0
- data/test/gl_vertex_test.rb +117 -0
- data/test/helpers.rb +45 -5
- data/test/image_target_test.rb +19 -0
- data/test/image_test.rb +73 -53
- data/test/int_array_test.rb +64 -0
- data/test/matrix_test.rb +134 -0
- data/test/polygon_test.rb +126 -0
- data/test/rect_test.rb +6 -8
- data/test/res/frag.c +14 -0
- data/test/res/frag3d.c +10 -0
- data/test/res/frag_gray.c +17 -0
- data/test/res/frag_light3d.c +20 -0
- data/test/res/light3d.c +20 -0
- data/test/res/sprite.png +0 -0
- data/test/res/teapot.obj +12831 -0
- data/test/res/vert.c +17 -0
- data/test/res/vertex3d.c +14 -0
- data/test/resource_set_test.rb +8 -45
- data/test/run_all.rb +1 -1
- data/test/scene_list_test.rb +79 -0
- data/test/scene_test.rb +168 -0
- data/test/shader_test.rb +58 -0
- data/test/sprite_test.rb +46 -41
- data/test/target_test.rb +34 -0
- data/test/text_test.rb +20 -31
- data/test/turtle_test.rb +35 -20
- data/test/vector_test.rb +61 -19
- data/test/vertex_test.rb +43 -0
- data/test/view_test.rb +61 -0
- metadata +347 -126
- data/.yardopts +0 -4
- data/VERSION +0 -1
- data/ext/audio.cpp +0 -723
- data/ext/color.cpp +0 -159
- data/ext/drawable.cpp +0 -91
- data/ext/event.cpp +0 -460
- data/ext/font.cpp +0 -190
- data/ext/image.cpp +0 -733
- data/ext/input.cpp +0 -74
- data/ext/ray.cpp +0 -168
- data/ext/ray.hpp +0 -356
- data/ext/rect.cpp +0 -245
- data/ext/shader.cpp +0 -169
- data/ext/shape.cpp +0 -409
- data/ext/sprite.cpp +0 -306
- data/ext/text.cpp +0 -181
- data/ext/vector.cpp +0 -215
- data/guide.md +0 -619
- data/lib/ray/input.rb +0 -10
- data/lib/ray/music_set.rb +0 -37
- data/lib/ray/rmagick.rb +0 -41
- data/lib/ray/shape.rb +0 -132
- data/lib/ray/sound_set.rb +0 -37
- data/samples/opengl/binding.rb +0 -38
- data/test/ray_test.rb +0 -25
- data/test/shape_test.rb +0 -101
- data/yard_ext.rb +0 -63
@@ -0,0 +1,511 @@
|
|
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
|
+
Before including,
|
7
|
+
|
8
|
+
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
9
|
+
|
10
|
+
in the file that you want to have the implementation.
|
11
|
+
|
12
|
+
|
13
|
+
ABOUT:
|
14
|
+
|
15
|
+
This header file is a library for writing images to C stdio. It could be
|
16
|
+
adapted to write to memory or a general streaming interface; let me know.
|
17
|
+
|
18
|
+
The PNG output is not optimal; it is 20-50% larger than the file
|
19
|
+
written by a decent optimizing implementation. This library is designed
|
20
|
+
for source code compactness and simplicitly, not optimal image file size
|
21
|
+
or run-time performance.
|
22
|
+
|
23
|
+
USAGE:
|
24
|
+
|
25
|
+
There are three functions, one for each image file format:
|
26
|
+
|
27
|
+
int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
|
28
|
+
int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
|
29
|
+
int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
|
30
|
+
|
31
|
+
Each function returns 0 on failure and non-0 on success.
|
32
|
+
|
33
|
+
The functions create an image file defined by the parameters. The image
|
34
|
+
is a rectangle of pixels stored from left-to-right, top-to-bottom.
|
35
|
+
Each pixel contains 'comp' channels of data stored interleaved with 8-bits
|
36
|
+
per channel, in the following order: 1=Y, 2=YA, 3=RGB, 4=RGBA. (Y is
|
37
|
+
monochrome color.) The rectangle is 'w' pixels wide and 'h' pixels tall.
|
38
|
+
The *data pointer points to the first byte of the top-left-most pixel.
|
39
|
+
For PNG, "stride_in_bytes" is the distance in bytes from the first byte of
|
40
|
+
a row of pixels to the first byte of the next row of pixels.
|
41
|
+
|
42
|
+
PNG creates output files with the same number of components as the input.
|
43
|
+
The BMP and TGA formats expand Y to RGB in the file format. BMP does not
|
44
|
+
output alpha.
|
45
|
+
|
46
|
+
PNG supports writing rectangles of data even when the bytes storing rows of
|
47
|
+
data are not consecutive in memory (e.g. sub-rectangles of a larger image),
|
48
|
+
by supplying the stride between the beginning of adjacent rows. The other
|
49
|
+
formats do not. (Thus you cannot write a native-format BMP through the BMP
|
50
|
+
writer, both because it is in BGR order and because it may have padding
|
51
|
+
at the end of the line.)
|
52
|
+
*/
|
53
|
+
|
54
|
+
#ifndef INCLUDE_STB_IMAGE_WRITE_H
|
55
|
+
#define INCLUDE_STB_IMAGE_WRITE_H
|
56
|
+
|
57
|
+
#ifdef __cplusplus
|
58
|
+
extern "C" {
|
59
|
+
#endif
|
60
|
+
|
61
|
+
extern int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
|
62
|
+
extern int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
|
63
|
+
extern int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
|
64
|
+
|
65
|
+
#ifdef __cplusplus
|
66
|
+
}
|
67
|
+
#endif
|
68
|
+
|
69
|
+
#endif//INCLUDE_STB_IMAGE_WRITE_H
|
70
|
+
|
71
|
+
#ifdef STB_IMAGE_WRITE_IMPLEMENTATION
|
72
|
+
|
73
|
+
#include <stdarg.h>
|
74
|
+
#include <stdlib.h>
|
75
|
+
#include <stdio.h>
|
76
|
+
#include <string.h>
|
77
|
+
#include <assert.h>
|
78
|
+
|
79
|
+
typedef unsigned int stbiw_uint32;
|
80
|
+
typedef int stb_image_write_test[sizeof(stbiw_uint32)==4 ? 1 : -1];
|
81
|
+
|
82
|
+
static void writefv(FILE *f, const char *fmt, va_list v)
|
83
|
+
{
|
84
|
+
while (*fmt) {
|
85
|
+
switch (*fmt++) {
|
86
|
+
case ' ': break;
|
87
|
+
case '1': { unsigned char x = (unsigned char) va_arg(v, int); fputc(x,f); break; }
|
88
|
+
case '2': { int x = va_arg(v,int); unsigned char b[2];
|
89
|
+
b[0] = (unsigned char) x; b[1] = (unsigned char) (x>>8);
|
90
|
+
fwrite(b,2,1,f); break; }
|
91
|
+
case '4': { stbiw_uint32 x = va_arg(v,int); unsigned char b[4];
|
92
|
+
b[0]=(unsigned char)x; b[1]=(unsigned char)(x>>8);
|
93
|
+
b[2]=(unsigned char)(x>>16); b[3]=(unsigned char)(x>>24);
|
94
|
+
fwrite(b,4,1,f); break; }
|
95
|
+
default:
|
96
|
+
assert(0);
|
97
|
+
return;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
static void write3(FILE *f, unsigned char a, unsigned char b, unsigned char c)
|
103
|
+
{
|
104
|
+
unsigned char arr[3];
|
105
|
+
arr[0] = a, arr[1] = b, arr[2] = c;
|
106
|
+
fwrite(arr, 3, 1, f);
|
107
|
+
}
|
108
|
+
|
109
|
+
static void write_pixels(FILE *f, int rgb_dir, int vdir, int x, int y, int comp, void *data, int write_alpha, int scanline_pad)
|
110
|
+
{
|
111
|
+
unsigned char bg[3] = { 255, 0, 255}, px[3];
|
112
|
+
stbiw_uint32 zero = 0;
|
113
|
+
int i,j,k, j_end;
|
114
|
+
|
115
|
+
if (y <= 0)
|
116
|
+
return;
|
117
|
+
|
118
|
+
if (vdir < 0)
|
119
|
+
j_end = -1, j = y-1;
|
120
|
+
else
|
121
|
+
j_end = y, j = 0;
|
122
|
+
|
123
|
+
for (; j != j_end; j += vdir) {
|
124
|
+
for (i=0; i < x; ++i) {
|
125
|
+
unsigned char *d = (unsigned char *) data + (j*x+i)*comp;
|
126
|
+
if (write_alpha < 0)
|
127
|
+
fwrite(&d[comp-1], 1, 1, f);
|
128
|
+
switch (comp) {
|
129
|
+
case 1:
|
130
|
+
case 2: write3(f, d[0],d[0],d[0]);
|
131
|
+
break;
|
132
|
+
case 4:
|
133
|
+
if (!write_alpha) {
|
134
|
+
// composite against pink background
|
135
|
+
for (k=0; k < 3; ++k)
|
136
|
+
px[k] = bg[k] + ((d[k] - bg[k]) * d[3])/255;
|
137
|
+
write3(f, px[1-rgb_dir],px[1],px[1+rgb_dir]);
|
138
|
+
break;
|
139
|
+
}
|
140
|
+
/* FALLTHROUGH */
|
141
|
+
case 3:
|
142
|
+
write3(f, d[1-rgb_dir],d[1],d[1+rgb_dir]);
|
143
|
+
break;
|
144
|
+
}
|
145
|
+
if (write_alpha > 0)
|
146
|
+
fwrite(&d[comp-1], 1, 1, f);
|
147
|
+
}
|
148
|
+
fwrite(&zero,scanline_pad,1,f);
|
149
|
+
}
|
150
|
+
}
|
151
|
+
|
152
|
+
static int outfile(char const *filename, int rgb_dir, int vdir, int x, int y, int comp, void *data, int alpha, int pad, const char *fmt, ...)
|
153
|
+
{
|
154
|
+
FILE *f;
|
155
|
+
if (y < 0 || x < 0) return 0;
|
156
|
+
f = fopen(filename, "wb");
|
157
|
+
if (f) {
|
158
|
+
va_list v;
|
159
|
+
va_start(v, fmt);
|
160
|
+
writefv(f, fmt, v);
|
161
|
+
va_end(v);
|
162
|
+
write_pixels(f,rgb_dir,vdir,x,y,comp,data,alpha,pad);
|
163
|
+
fclose(f);
|
164
|
+
}
|
165
|
+
return f != NULL;
|
166
|
+
}
|
167
|
+
|
168
|
+
int stbi_write_bmp(char const *filename, int x, int y, int comp, const void *data)
|
169
|
+
{
|
170
|
+
int pad = (-x*3) & 3;
|
171
|
+
return outfile(filename,-1,-1,x,y,comp,(void *) data,0,pad,
|
172
|
+
"11 4 22 4" "4 44 22 444444",
|
173
|
+
'B', 'M', 14+40+(x*3+pad)*y, 0,0, 14+40, // file header
|
174
|
+
40, x,y, 1,24, 0,0,0,0,0,0); // bitmap header
|
175
|
+
}
|
176
|
+
|
177
|
+
int stbi_write_tga(char const *filename, int x, int y, int comp, const void *data)
|
178
|
+
{
|
179
|
+
int has_alpha = !(comp & 1);
|
180
|
+
return outfile(filename, -1,-1, x, y, comp, (void *) data, has_alpha, 0,
|
181
|
+
"111 221 2222 11", 0,0,2, 0,0,0, 0,0,x,y, 24+8*has_alpha, 8*has_alpha);
|
182
|
+
}
|
183
|
+
|
184
|
+
// stretchy buffer; stbi__sbpush() == vector<>::push_back() -- stbi__sbcount() == vector<>::size()
|
185
|
+
#define stbi__sbraw(a) ((int *) (a) - 2)
|
186
|
+
#define stbi__sbm(a) stbi__sbraw(a)[0]
|
187
|
+
#define stbi__sbn(a) stbi__sbraw(a)[1]
|
188
|
+
|
189
|
+
#define stbi__sbneedgrow(a,n) ((a)==0 || stbi__sbn(a)+n >= stbi__sbm(a))
|
190
|
+
#define stbi__sbmaybegrow(a,n) (stbi__sbneedgrow(a,(n)) ? stbi__sbgrow(a,n) : 0)
|
191
|
+
#define stbi__sbgrow(a,n) stbi__sbgrowf((void **) &(a), (n), sizeof(*(a)))
|
192
|
+
|
193
|
+
#define stbi__sbpush(a, v) (stbi__sbmaybegrow(a,1), (a)[stbi__sbn(a)++] = (v))
|
194
|
+
#define stbi__sbcount(a) ((a) ? stbi__sbn(a) : 0)
|
195
|
+
#define stbi__sbfree(a) ((a) ? free(stbi__sbraw(a)),0 : 0)
|
196
|
+
|
197
|
+
static void *stbi__sbgrowf(void **arr, int increment, int itemsize)
|
198
|
+
{
|
199
|
+
int m = *arr ? 2*stbi__sbm(*arr)+increment : increment+1;
|
200
|
+
void *p = realloc(*arr ? stbi__sbraw(*arr) : 0, itemsize * m + sizeof(int)*2);
|
201
|
+
assert(p);
|
202
|
+
if (p) {
|
203
|
+
if (!*arr) ((int *) p)[1] = 0;
|
204
|
+
*arr = (void *) ((int *) p + 2);
|
205
|
+
stbi__sbm(*arr) = m;
|
206
|
+
}
|
207
|
+
return *arr;
|
208
|
+
}
|
209
|
+
|
210
|
+
static unsigned char *stbi__zlib_flushf(unsigned char *data, unsigned int *bitbuffer, int *bitcount)
|
211
|
+
{
|
212
|
+
while (*bitcount >= 8) {
|
213
|
+
stbi__sbpush(data, (unsigned char) *bitbuffer);
|
214
|
+
*bitbuffer >>= 8;
|
215
|
+
*bitcount -= 8;
|
216
|
+
}
|
217
|
+
return data;
|
218
|
+
}
|
219
|
+
|
220
|
+
static int stbi__zlib_bitrev(int code, int codebits)
|
221
|
+
{
|
222
|
+
int res=0;
|
223
|
+
while (codebits--) {
|
224
|
+
res = (res << 1) | (code & 1);
|
225
|
+
code >>= 1;
|
226
|
+
}
|
227
|
+
return res;
|
228
|
+
}
|
229
|
+
|
230
|
+
static unsigned int stbi__zlib_countm(unsigned char *a, unsigned char *b, int limit)
|
231
|
+
{
|
232
|
+
int i;
|
233
|
+
for (i=0; i < limit && i < 258; ++i)
|
234
|
+
if (a[i] != b[i]) break;
|
235
|
+
return i;
|
236
|
+
}
|
237
|
+
|
238
|
+
static unsigned int stbi__zhash(unsigned char *data)
|
239
|
+
{
|
240
|
+
stbiw_uint32 hash = data[0] + (data[1] << 8) + (data[2] << 16);
|
241
|
+
hash ^= hash << 3;
|
242
|
+
hash += hash >> 5;
|
243
|
+
hash ^= hash << 4;
|
244
|
+
hash += hash >> 17;
|
245
|
+
hash ^= hash << 25;
|
246
|
+
hash += hash >> 6;
|
247
|
+
return hash;
|
248
|
+
}
|
249
|
+
|
250
|
+
#define stbi__zlib_flush() (out = stbi__zlib_flushf(out, &bitbuf, &bitcount))
|
251
|
+
#define stbi__zlib_add(code,codebits) \
|
252
|
+
(bitbuf |= (code) << bitcount, bitcount += (codebits), stbi__zlib_flush())
|
253
|
+
#define stbi__zlib_huffa(b,c) stbi__zlib_add(stbi__zlib_bitrev(b,c),c)
|
254
|
+
// default huffman tables
|
255
|
+
#define stbi__zlib_huff1(n) stbi__zlib_huffa(0x30 + (n), 8)
|
256
|
+
#define stbi__zlib_huff2(n) stbi__zlib_huffa(0x190 + (n)-144, 9)
|
257
|
+
#define stbi__zlib_huff3(n) stbi__zlib_huffa(0 + (n)-256,7)
|
258
|
+
#define stbi__zlib_huff4(n) stbi__zlib_huffa(0xc0 + (n)-280,8)
|
259
|
+
#define stbi__zlib_huff(n) ((n) <= 143 ? stbi__zlib_huff1(n) : (n) <= 255 ? stbi__zlib_huff2(n) : (n) <= 279 ? stbi__zlib_huff3(n) : stbi__zlib_huff4(n))
|
260
|
+
#define stbi__zlib_huffb(n) ((n) <= 143 ? stbi__zlib_huff1(n) : stbi__zlib_huff2(n))
|
261
|
+
|
262
|
+
#define stbi__ZHASH 16384
|
263
|
+
|
264
|
+
unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_len, int quality)
|
265
|
+
{
|
266
|
+
static unsigned short lengthc[] = { 3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258, 259 };
|
267
|
+
static unsigned char lengtheb[]= { 0,0,0,0,0,0,0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0 };
|
268
|
+
static unsigned short distc[] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577, 32768 };
|
269
|
+
static unsigned char disteb[] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13 };
|
270
|
+
unsigned int bitbuf=0;
|
271
|
+
int i,j, bitcount=0;
|
272
|
+
unsigned char *out = NULL;
|
273
|
+
unsigned char **hash_table[stbi__ZHASH]; // 64KB on the stack!
|
274
|
+
if (quality < 5) quality = 5;
|
275
|
+
|
276
|
+
stbi__sbpush(out, 0x78); // DEFLATE 32K window
|
277
|
+
stbi__sbpush(out, 0x5e); // FLEVEL = 1
|
278
|
+
stbi__zlib_add(1,1); // BFINAL = 1
|
279
|
+
stbi__zlib_add(1,2); // BTYPE = 1 -- fixed huffman
|
280
|
+
|
281
|
+
for (i=0; i < stbi__ZHASH; ++i)
|
282
|
+
hash_table[i] = NULL;
|
283
|
+
|
284
|
+
i=0;
|
285
|
+
while (i < data_len-3) {
|
286
|
+
// hash next 3 bytes of data to be compressed
|
287
|
+
int h = stbi__zhash(data+i)&(stbi__ZHASH-1), best=3;
|
288
|
+
unsigned char *bestloc = 0;
|
289
|
+
unsigned char **hlist = hash_table[h];
|
290
|
+
int n = stbi__sbcount(hlist);
|
291
|
+
for (j=0; j < n; ++j) {
|
292
|
+
if (hlist[j]-data > i-32768) { // if entry lies within window
|
293
|
+
int d = stbi__zlib_countm(hlist[j], data+i, data_len-i);
|
294
|
+
if (d >= best) best=d,bestloc=hlist[j];
|
295
|
+
}
|
296
|
+
}
|
297
|
+
// when hash table entry is too long, delete half the entries
|
298
|
+
if (hash_table[h] && stbi__sbn(hash_table[h]) == 2*quality) {
|
299
|
+
memcpy(hash_table[h], hash_table[h]+quality, sizeof(hash_table[h][0])*quality);
|
300
|
+
stbi__sbn(hash_table[h]) = quality;
|
301
|
+
}
|
302
|
+
stbi__sbpush(hash_table[h],data+i);
|
303
|
+
|
304
|
+
if (bestloc) {
|
305
|
+
// "lazy matching" - check match at *next* byte, and if it's better, do cur byte as literal
|
306
|
+
h = stbi__zhash(data+i+1)&(stbi__ZHASH-1);
|
307
|
+
hlist = hash_table[h];
|
308
|
+
n = stbi__sbcount(hlist);
|
309
|
+
for (j=0; j < n; ++j) {
|
310
|
+
if (hlist[j]-data > i-32767) {
|
311
|
+
int e = stbi__zlib_countm(hlist[j], data+i+1, data_len-i-1);
|
312
|
+
if (e > best) { // if next match is better, bail on current match
|
313
|
+
bestloc = NULL;
|
314
|
+
break;
|
315
|
+
}
|
316
|
+
}
|
317
|
+
}
|
318
|
+
}
|
319
|
+
|
320
|
+
if (bestloc) {
|
321
|
+
int d = data+i - bestloc; // distance back
|
322
|
+
assert(d <= 32767 && best <= 258);
|
323
|
+
for (j=0; best > lengthc[j+1]-1; ++j);
|
324
|
+
stbi__zlib_huff(j+257);
|
325
|
+
if (lengtheb[j]) stbi__zlib_add(best - lengthc[j], lengtheb[j]);
|
326
|
+
for (j=0; d > distc[j+1]-1; ++j);
|
327
|
+
stbi__zlib_add(stbi__zlib_bitrev(j,5),5);
|
328
|
+
if (disteb[j]) stbi__zlib_add(d - distc[j], disteb[j]);
|
329
|
+
i += best;
|
330
|
+
} else {
|
331
|
+
stbi__zlib_huffb(data[i]);
|
332
|
+
++i;
|
333
|
+
}
|
334
|
+
}
|
335
|
+
// write out final bytes
|
336
|
+
for (;i < data_len; ++i)
|
337
|
+
stbi__zlib_huffb(data[i]);
|
338
|
+
stbi__zlib_huff(256); // end of block
|
339
|
+
// pad with 0 bits to byte boundary
|
340
|
+
while (bitcount)
|
341
|
+
stbi__zlib_add(0,1);
|
342
|
+
|
343
|
+
for (i=0; i < stbi__ZHASH; ++i)
|
344
|
+
(void) stbi__sbfree(hash_table[i]);
|
345
|
+
|
346
|
+
{
|
347
|
+
// compute adler32 on input
|
348
|
+
unsigned int i=0, s1=1, s2=0, blocklen = data_len % 5552;
|
349
|
+
int j=0;
|
350
|
+
while (j < data_len) {
|
351
|
+
for (i=0; i < blocklen; ++i) s1 += data[j+i], s2 += s1;
|
352
|
+
s1 %= 65521, s2 %= 65521;
|
353
|
+
j += blocklen;
|
354
|
+
blocklen = 5552;
|
355
|
+
}
|
356
|
+
stbi__sbpush(out, (unsigned char) (s2 >> 8));
|
357
|
+
stbi__sbpush(out, (unsigned char) s2);
|
358
|
+
stbi__sbpush(out, (unsigned char) (s1 >> 8));
|
359
|
+
stbi__sbpush(out, (unsigned char) s1);
|
360
|
+
}
|
361
|
+
*out_len = stbi__sbn(out);
|
362
|
+
// make returned pointer freeable
|
363
|
+
memmove(stbi__sbraw(out), out, *out_len);
|
364
|
+
return (unsigned char *) stbi__sbraw(out);
|
365
|
+
}
|
366
|
+
|
367
|
+
unsigned int stbi__crc32(unsigned char *buffer, int len)
|
368
|
+
{
|
369
|
+
static unsigned int crc_table[256];
|
370
|
+
unsigned int crc = ~0u;
|
371
|
+
int i,j;
|
372
|
+
if (crc_table[1] == 0)
|
373
|
+
for(i=0; i < 256; i++)
|
374
|
+
for (crc_table[i]=i, j=0; j < 8; ++j)
|
375
|
+
crc_table[i] = (crc_table[i] >> 1) ^ (crc_table[i] & 1 ? 0xedb88320 : 0);
|
376
|
+
for (i=0; i < len; ++i)
|
377
|
+
crc = (crc >> 8) ^ crc_table[buffer[i] ^ (crc & 0xff)];
|
378
|
+
return ~crc;
|
379
|
+
}
|
380
|
+
|
381
|
+
#define stbi__wpng4(o,a,b,c,d) ((o)[0]=(unsigned char)(a),(o)[1]=(unsigned char)(b),(o)[2]=(unsigned char)(c),(o)[3]=(unsigned char)(d),(o)+=4)
|
382
|
+
#define stbi__wp32(data,v) stbi__wpng4(data, (v)>>24,(v)>>16,(v)>>8,(v));
|
383
|
+
#define stbi__wptag(data,s) stbi__wpng4(data, s[0],s[1],s[2],s[3])
|
384
|
+
|
385
|
+
static void stbi__wpcrc(unsigned char **data, int len)
|
386
|
+
{
|
387
|
+
unsigned int crc = stbi__crc32(*data - len - 4, len+4);
|
388
|
+
stbi__wp32(*data, crc);
|
389
|
+
}
|
390
|
+
|
391
|
+
static unsigned char stbi__paeth(int a, int b, int c)
|
392
|
+
{
|
393
|
+
int p = a + b - c, pa = abs(p-a), pb = abs(p-b), pc = abs(p-c);
|
394
|
+
if (pa <= pb && pa <= pc) return (unsigned char) a;
|
395
|
+
if (pb <= pc) return (unsigned char) b;
|
396
|
+
return (unsigned char) c;
|
397
|
+
}
|
398
|
+
|
399
|
+
unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len)
|
400
|
+
{
|
401
|
+
int ctype[5] = { -1, 0, 4, 2, 6 };
|
402
|
+
unsigned char sig[8] = { 137,80,78,71,13,10,26,10 };
|
403
|
+
unsigned char *out,*o, *filt, *zlib;
|
404
|
+
signed char *line_buffer;
|
405
|
+
int i,j,k,p,zlen;
|
406
|
+
|
407
|
+
if (stride_bytes == 0)
|
408
|
+
stride_bytes = x * n;
|
409
|
+
|
410
|
+
filt = (unsigned char *) malloc((x*n+1) * y); if (!filt) return 0;
|
411
|
+
line_buffer = (signed char *) malloc(x * n); if (!line_buffer) { free(filt); return 0; }
|
412
|
+
for (j=0; j < y; ++j) {
|
413
|
+
static int mapping[] = { 0,1,2,3,4 };
|
414
|
+
static int firstmap[] = { 0,1,0,5,6 };
|
415
|
+
int *mymap = j ? mapping : firstmap;
|
416
|
+
int best = 0, bestval = 0x7fffffff;
|
417
|
+
for (p=0; p < 2; ++p) {
|
418
|
+
for (k= p?best:0; k < 5; ++k) {
|
419
|
+
int type = mymap[k],est=0;
|
420
|
+
unsigned char *z = pixels + stride_bytes*j;
|
421
|
+
for (i=0; i < n; ++i)
|
422
|
+
switch (type) {
|
423
|
+
case 0: line_buffer[i] = z[i]; break;
|
424
|
+
case 1: line_buffer[i] = z[i]; break;
|
425
|
+
case 2: line_buffer[i] = z[i] - z[i-stride_bytes]; break;
|
426
|
+
case 3: line_buffer[i] = z[i] - (z[i-stride_bytes]>>1); break;
|
427
|
+
case 4: line_buffer[i] = (signed char) (z[i] - stbi__paeth(0,z[i-stride_bytes],0)); break;
|
428
|
+
case 5: line_buffer[i] = z[i]; break;
|
429
|
+
case 6: line_buffer[i] = z[i]; break;
|
430
|
+
}
|
431
|
+
for (i=n; i < x*n; ++i) {
|
432
|
+
switch (type) {
|
433
|
+
case 0: line_buffer[i] = z[i]; break;
|
434
|
+
case 1: line_buffer[i] = z[i] - z[i-n]; break;
|
435
|
+
case 2: line_buffer[i] = z[i] - z[i-stride_bytes]; break;
|
436
|
+
case 3: line_buffer[i] = z[i] - ((z[i-n] + z[i-stride_bytes])>>1); break;
|
437
|
+
case 4: line_buffer[i] = z[i] - stbi__paeth(z[i-n], z[i-stride_bytes], z[i-stride_bytes-n]); break;
|
438
|
+
case 5: line_buffer[i] = z[i] - (z[i-n]>>1); break;
|
439
|
+
case 6: line_buffer[i] = z[i] - stbi__paeth(z[i-n], 0,0); break;
|
440
|
+
}
|
441
|
+
}
|
442
|
+
if (p) break;
|
443
|
+
for (i=0; i < x*n; ++i)
|
444
|
+
est += abs((signed char) line_buffer[i]);
|
445
|
+
if (est < bestval) { bestval = est; best = k; }
|
446
|
+
}
|
447
|
+
}
|
448
|
+
// when we get here, best contains the filter type, and line_buffer contains the data
|
449
|
+
filt[j*(x*n+1)] = (unsigned char) best;
|
450
|
+
memcpy(filt+j*(x*n+1)+1, line_buffer, x*n);
|
451
|
+
}
|
452
|
+
free(line_buffer);
|
453
|
+
zlib = stbi_zlib_compress(filt, y*( x*n+1), &zlen, 8); // increase 8 to get smaller but use more memory
|
454
|
+
free(filt);
|
455
|
+
if (!zlib) return 0;
|
456
|
+
|
457
|
+
// each tag requires 12 bytes of overhead
|
458
|
+
out = (unsigned char *) malloc(8 + 12+13 + 12+zlen + 12);
|
459
|
+
if (!out) return 0;
|
460
|
+
*out_len = 8 + 12+13 + 12+zlen + 12;
|
461
|
+
|
462
|
+
o=out;
|
463
|
+
memcpy(o,sig,8); o+= 8;
|
464
|
+
stbi__wp32(o, 13); // header length
|
465
|
+
stbi__wptag(o, "IHDR");
|
466
|
+
stbi__wp32(o, x);
|
467
|
+
stbi__wp32(o, y);
|
468
|
+
*o++ = 8;
|
469
|
+
*o++ = (unsigned char) ctype[n];
|
470
|
+
*o++ = 0;
|
471
|
+
*o++ = 0;
|
472
|
+
*o++ = 0;
|
473
|
+
stbi__wpcrc(&o,13);
|
474
|
+
|
475
|
+
stbi__wp32(o, zlen);
|
476
|
+
stbi__wptag(o, "IDAT");
|
477
|
+
memcpy(o, zlib, zlen); o += zlen; free(zlib);
|
478
|
+
stbi__wpcrc(&o, zlen);
|
479
|
+
|
480
|
+
stbi__wp32(o,0);
|
481
|
+
stbi__wptag(o, "IEND");
|
482
|
+
stbi__wpcrc(&o,0);
|
483
|
+
|
484
|
+
assert(o == out + *out_len);
|
485
|
+
|
486
|
+
return out;
|
487
|
+
}
|
488
|
+
|
489
|
+
int stbi_write_png(char const *filename, int x, int y, int comp, const void *data, int stride_bytes)
|
490
|
+
{
|
491
|
+
FILE *f;
|
492
|
+
int len;
|
493
|
+
unsigned char *png = stbi_write_png_to_mem((unsigned char *) data, stride_bytes, x, y, comp, &len);
|
494
|
+
if (!png) return 0;
|
495
|
+
f = fopen(filename, "wb");
|
496
|
+
if (!f) { free(png); return 0; }
|
497
|
+
fwrite(png, 1, len, f);
|
498
|
+
fclose(f);
|
499
|
+
free(png);
|
500
|
+
return 1;
|
501
|
+
}
|
502
|
+
#endif // STB_IMAGE_WRITE_IMPLEMENTATION
|
503
|
+
|
504
|
+
/* Revision history
|
505
|
+
|
506
|
+
0.92 (2010-08-01)
|
507
|
+
casts to unsigned char to fix warnings
|
508
|
+
0.91 (2010-07-17)
|
509
|
+
first public release
|
510
|
+
0.90 first internal release
|
511
|
+
*/
|