rays 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.doc/ext/rays/bitmap.cpp +22 -76
- data/.doc/ext/rays/bounds.cpp +95 -125
- data/.doc/ext/rays/color.cpp +224 -45
- data/.doc/ext/rays/color_space.cpp +137 -45
- data/.doc/ext/rays/defs.cpp +183 -0
- data/.doc/ext/rays/font.cpp +39 -21
- data/.doc/ext/rays/image.cpp +26 -37
- data/.doc/ext/rays/matrix.cpp +186 -29
- data/.doc/ext/rays/native.cpp +12 -6
- data/.doc/ext/rays/noise.cpp +53 -0
- data/.doc/ext/rays/painter.cpp +120 -308
- data/.doc/ext/rays/point.cpp +82 -77
- data/.doc/ext/rays/polygon.cpp +287 -0
- data/.doc/ext/rays/polygon_line.cpp +96 -0
- data/.doc/ext/rays/polyline.cpp +161 -0
- data/.doc/ext/rays/rays.cpp +0 -13
- data/.doc/ext/rays/shader.cpp +83 -9
- data/README.md +1 -1
- data/Rakefile +21 -9
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +22 -80
- data/ext/rays/bounds.cpp +100 -128
- data/ext/rays/color.cpp +232 -51
- data/ext/rays/color_space.cpp +140 -46
- data/ext/rays/defs.cpp +183 -0
- data/ext/rays/defs.h +26 -2
- data/ext/rays/extconf.rb +1 -2
- data/ext/rays/font.cpp +39 -22
- data/ext/rays/image.cpp +27 -39
- data/ext/rays/matrix.cpp +198 -30
- data/ext/rays/native.cpp +12 -6
- data/ext/rays/noise.cpp +55 -0
- data/ext/rays/painter.cpp +129 -315
- data/ext/rays/point.cpp +89 -81
- data/ext/rays/polygon.cpp +301 -0
- data/ext/rays/polygon_line.cpp +99 -0
- data/ext/rays/polyline.cpp +170 -0
- data/ext/rays/rays.cpp +0 -14
- data/ext/rays/shader.cpp +84 -9
- data/include/rays.h +10 -2
- data/include/rays/bitmap.h +14 -26
- data/include/rays/bounds.h +21 -4
- data/include/rays/color.h +25 -14
- data/include/rays/color_space.h +11 -8
- data/include/rays/coord.h +114 -0
- data/include/rays/debug.h +22 -0
- data/include/rays/defs.h +3 -0
- data/include/rays/font.h +4 -4
- data/include/rays/image.h +11 -17
- data/include/rays/matrix.h +50 -24
- data/include/rays/noise.h +42 -0
- data/include/rays/opengl.h +2 -50
- data/include/rays/painter.h +57 -99
- data/include/rays/point.h +44 -51
- data/include/rays/polygon.h +164 -0
- data/include/rays/polyline.h +65 -0
- data/include/rays/rays.h +3 -0
- data/include/rays/ruby.h +7 -1
- data/include/rays/ruby/bounds.h +1 -1
- data/include/rays/ruby/color.h +1 -1
- data/include/rays/ruby/color_space.h +1 -1
- data/include/rays/ruby/font.h +1 -1
- data/include/rays/ruby/matrix.h +1 -1
- data/include/rays/ruby/point.h +1 -1
- data/include/rays/ruby/polygon.h +52 -0
- data/include/rays/ruby/polyline.h +41 -0
- data/include/rays/ruby/shader.h +1 -1
- data/include/rays/shader.h +36 -8
- data/lib/rays.rb +6 -1
- data/lib/rays/bitmap.rb +0 -15
- data/lib/rays/bounds.rb +17 -23
- data/lib/rays/color.rb +20 -47
- data/lib/rays/color_space.rb +13 -13
- data/lib/rays/image.rb +2 -6
- data/lib/rays/matrix.rb +28 -0
- data/lib/rays/module.rb +4 -19
- data/lib/rays/painter.rb +60 -97
- data/lib/rays/point.rb +13 -21
- data/lib/rays/polygon.rb +50 -0
- data/lib/rays/polygon_line.rb +36 -0
- data/lib/rays/polyline.rb +32 -0
- data/lib/rays/shader.rb +20 -1
- data/rays.gemspec +5 -7
- data/src/bitmap.h +36 -0
- data/src/bounds.cpp +74 -11
- data/src/color.cpp +58 -23
- data/src/color_space.cpp +50 -32
- data/src/color_space.h +22 -0
- data/src/coord.cpp +170 -0
- data/src/coord.h +35 -0
- data/src/font.cpp +118 -0
- data/src/font.h +64 -0
- data/src/frame_buffer.cpp +37 -71
- data/src/frame_buffer.h +4 -4
- data/src/image.cpp +171 -97
- data/src/image.h +25 -0
- data/src/ios/bitmap.mm +107 -105
- data/src/ios/font.mm +48 -60
- data/src/ios/helper.h +2 -2
- data/src/ios/opengl.mm +19 -4
- data/src/ios/rays.mm +3 -0
- data/src/matrix.cpp +111 -26
- data/src/matrix.h +30 -0
- data/src/noise.cpp +74 -0
- data/src/opengl.cpp +9 -27
- data/src/opengl.h +37 -0
- data/src/osx/bitmap.mm +111 -106
- data/src/osx/font.mm +48 -61
- data/src/osx/helper.h +2 -2
- data/src/osx/opengl.mm +19 -83
- data/src/osx/rays.mm +3 -0
- data/src/painter.cpp +780 -696
- data/src/painter.h +24 -0
- data/src/point.cpp +140 -119
- data/src/polygon.cpp +1100 -0
- data/src/polygon.h +32 -0
- data/src/polyline.cpp +158 -0
- data/src/polyline.h +67 -0
- data/src/render_buffer.cpp +11 -4
- data/src/render_buffer.h +2 -2
- data/src/shader.cpp +163 -106
- data/src/shader.h +38 -0
- data/src/shader_program.cpp +533 -0
- data/src/{program.h → shader_program.h} +28 -16
- data/src/shader_source.cpp +140 -0
- data/src/shader_source.h +52 -0
- data/src/texture.cpp +136 -160
- data/src/texture.h +65 -0
- data/src/win32/bitmap.cpp +62 -52
- data/src/win32/font.cpp +11 -13
- data/src/win32/font.h +24 -0
- data/src/win32/gdi.h +6 -6
- data/test/helper.rb +0 -3
- data/test/test_bitmap.rb +31 -7
- data/test/test_bounds.rb +36 -0
- data/test/test_color.rb +59 -19
- data/test/test_color_space.rb +95 -0
- data/test/test_image.rb +24 -20
- data/test/test_matrix.rb +106 -0
- data/test/test_painter.rb +92 -46
- data/test/test_painter_shape.rb +57 -0
- data/test/test_point.rb +21 -0
- data/test/test_polygon.rb +234 -0
- data/test/test_polygon_line.rb +167 -0
- data/test/test_polyline.rb +145 -0
- data/test/test_shader.rb +9 -9
- metadata +88 -67
- data/.doc/ext/rays/texture.cpp +0 -138
- data/ext/rays/texture.cpp +0 -149
- data/include/rays/ruby/texture.h +0 -41
- data/include/rays/texture.h +0 -71
- data/lib/rays/texture.rb +0 -24
- data/src/program.cpp +0 -648
- data/test/test_texture.rb +0 -27
data/src/noise.cpp
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#include "rays/noise.h"
|
2
|
+
|
3
|
+
|
4
|
+
#include <glm/gtc/noise.hpp>
|
5
|
+
#include "coord.h"
|
6
|
+
|
7
|
+
|
8
|
+
namespace Rays
|
9
|
+
{
|
10
|
+
|
11
|
+
|
12
|
+
coord
|
13
|
+
perlin (coord x)
|
14
|
+
{
|
15
|
+
return (coord) glm::perlin(glm::vec2(x, 0));
|
16
|
+
}
|
17
|
+
|
18
|
+
coord
|
19
|
+
perlin (coord x, coord y)
|
20
|
+
{
|
21
|
+
return (coord) glm::perlin(glm::vec2(x, y));
|
22
|
+
}
|
23
|
+
|
24
|
+
coord
|
25
|
+
perlin (coord x, coord y, coord z)
|
26
|
+
{
|
27
|
+
return (coord) glm::perlin(glm::vec3(x, y, z));
|
28
|
+
}
|
29
|
+
|
30
|
+
coord
|
31
|
+
perlin (coord x, coord y, coord z, coord w)
|
32
|
+
{
|
33
|
+
return (coord) glm::perlin(glm::vec4(x, y, z, w));
|
34
|
+
}
|
35
|
+
|
36
|
+
coord
|
37
|
+
perlin (const Coord3& position)
|
38
|
+
{
|
39
|
+
return (coord) glm::perlin(to_glm(position));
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
coord
|
44
|
+
simplex (coord x)
|
45
|
+
{
|
46
|
+
return (coord) glm::simplex(glm::vec2(x, 0));
|
47
|
+
}
|
48
|
+
|
49
|
+
coord
|
50
|
+
simplex (coord x, coord y)
|
51
|
+
{
|
52
|
+
return (coord) glm::simplex(glm::vec2(x, y));
|
53
|
+
}
|
54
|
+
|
55
|
+
coord
|
56
|
+
simplex (coord x, coord y, coord z)
|
57
|
+
{
|
58
|
+
return (coord) glm::simplex(glm::vec3(x, y, z));
|
59
|
+
}
|
60
|
+
|
61
|
+
coord
|
62
|
+
simplex (coord x, coord y, coord z, coord w)
|
63
|
+
{
|
64
|
+
return (coord) glm::simplex(glm::vec4(x, y, z, w));
|
65
|
+
}
|
66
|
+
|
67
|
+
coord
|
68
|
+
simplex (const Coord3& position)
|
69
|
+
{
|
70
|
+
return (coord) glm::simplex(to_glm(position));
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
}// Rays
|
data/src/opengl.cpp
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#include "
|
1
|
+
#include "opengl.h"
|
2
2
|
|
3
3
|
|
4
4
|
#include "rays/exception.h"
|
@@ -9,23 +9,11 @@ namespace Rays
|
|
9
9
|
|
10
10
|
|
11
11
|
GLenum
|
12
|
-
|
12
|
+
OpenGL_get_error ()
|
13
13
|
{
|
14
14
|
return glGetError();
|
15
15
|
}
|
16
16
|
|
17
|
-
bool
|
18
|
-
no_error ()
|
19
|
-
{
|
20
|
-
return get_error() == GL_NO_ERROR;
|
21
|
-
}
|
22
|
-
|
23
|
-
bool
|
24
|
-
is_error (GLenum err)
|
25
|
-
{
|
26
|
-
return get_error() == err;
|
27
|
-
}
|
28
|
-
|
29
17
|
static String
|
30
18
|
get_error_name (GLenum error)
|
31
19
|
{
|
@@ -35,30 +23,24 @@ namespace Rays
|
|
35
23
|
case GL_INVALID_ENUM: return "GL_INVALID_ENUM";
|
36
24
|
case GL_INVALID_VALUE: return "GL_INVALID_VALUE";
|
37
25
|
case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION";
|
38
|
-
#ifndef IOS
|
39
|
-
case GL_STACK_OVERFLOW: return "GL_STACK_OVERFLOW";
|
40
|
-
case GL_STACK_UNDERFLOW: return "GL_STACK_UNDERFLOW";
|
41
|
-
#endif
|
42
26
|
case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY";
|
27
|
+
#ifndef IOS
|
28
|
+
case GL_STACK_OVERFLOW: return "GL_STACK_OVERFLOW";
|
29
|
+
case GL_STACK_UNDERFLOW: return "GL_STACK_UNDERFLOW";
|
30
|
+
#endif
|
43
31
|
case 0x506: return "GL_INVALID_FRAMEBUFFER_OPERATION";
|
44
32
|
case 0x8031: return "GL_TABLE_TOO_LARGE";
|
33
|
+
default: return "UNKNOWN ERROR";
|
45
34
|
}
|
46
|
-
return "UNKNOWN ERROR";
|
47
35
|
}
|
48
36
|
|
49
37
|
void
|
50
|
-
|
38
|
+
OpenGL_check_error (const char* file, int line)
|
51
39
|
{
|
52
|
-
GLenum e =
|
40
|
+
GLenum e = OpenGL_get_error();
|
53
41
|
if (e != GL_NO_ERROR)
|
54
42
|
opengl_error(file, line, "OpenGL error %s", get_error_name(e).c_str());
|
55
43
|
}
|
56
44
|
|
57
|
-
void
|
58
|
-
clear_error ()
|
59
|
-
{
|
60
|
-
get_error();
|
61
|
-
}
|
62
|
-
|
63
45
|
|
64
46
|
}// Rays
|
data/src/opengl.h
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RAYS_SRC_OPENGL_H__
|
4
|
+
#define __RAYS_SRC_OPENGL_H__
|
5
|
+
|
6
|
+
|
7
|
+
#if defined(OSX)
|
8
|
+
#include <OpenGL/gl.h>
|
9
|
+
#include <OpenGL/glext.h>
|
10
|
+
#elif defined(IOS)
|
11
|
+
#include <OpenGLES/ES3/gl.h>
|
12
|
+
#include <OpenGLES/ES3/glext.h>
|
13
|
+
#elif defined(WIN32)
|
14
|
+
#include <GL/gl.h>
|
15
|
+
#include <GL/glext.h>
|
16
|
+
#endif
|
17
|
+
|
18
|
+
#include <rays/opengl.h>
|
19
|
+
|
20
|
+
|
21
|
+
namespace Rays
|
22
|
+
{
|
23
|
+
|
24
|
+
|
25
|
+
void OpenGL_set_context (Context context);
|
26
|
+
|
27
|
+
Context OpenGL_get_context ();
|
28
|
+
|
29
|
+
GLenum OpenGL_get_error ();
|
30
|
+
|
31
|
+
void OpenGL_check_error (const char* file, int line);
|
32
|
+
|
33
|
+
|
34
|
+
}// Rays
|
35
|
+
|
36
|
+
|
37
|
+
#endif//EOH
|
data/src/osx/bitmap.mm
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
// -*- objc -*-
|
2
|
-
#import "
|
2
|
+
#import "../bitmap.h"
|
3
3
|
|
4
4
|
|
5
|
-
#include <assert.h>
|
6
|
-
#include <boost/scoped_array.hpp>
|
7
5
|
#import <Cocoa/Cocoa.h>
|
8
6
|
#include "rays/exception.h"
|
9
|
-
#include "
|
7
|
+
#include "../color_space.h"
|
8
|
+
#include "../font.h"
|
9
|
+
#include "../texture.h"
|
10
10
|
#include "../frame_buffer.h"
|
11
11
|
#include "helper.h"
|
12
12
|
|
@@ -59,14 +59,13 @@ namespace Rays
|
|
59
59
|
|
60
60
|
ColorSpace color_space;
|
61
61
|
|
62
|
-
void* pixels;
|
62
|
+
void* pixels = NULL;
|
63
63
|
|
64
|
-
CGContextRef context;
|
64
|
+
CGContextRef context = NULL;
|
65
65
|
|
66
|
-
bool
|
66
|
+
bool modified;
|
67
67
|
|
68
68
|
Data ()
|
69
|
-
: pixels(NULL), context(NULL)
|
70
69
|
{
|
71
70
|
clear();
|
72
71
|
}
|
@@ -85,7 +84,7 @@ namespace Rays
|
|
85
84
|
if (bpc <= 0 || pitch <= 0) return NULL;
|
86
85
|
|
87
86
|
CGColorSpaceRef cgcs = NULL;
|
88
|
-
if (color_space.is_gray())
|
87
|
+
if (color_space.is_gray() || color_space.is_alpha())
|
89
88
|
cgcs = CGColorSpaceCreateDeviceGray();
|
90
89
|
else if (color_space.is_rgb() || color_space.is_bgr())
|
91
90
|
cgcs = CGColorSpaceCreateDeviceRGB();
|
@@ -114,7 +113,7 @@ namespace Rays
|
|
114
113
|
color_space = COLORSPACE_UNKNOWN;
|
115
114
|
pixels = NULL;
|
116
115
|
context = NULL;
|
117
|
-
|
116
|
+
modified = false;
|
118
117
|
}
|
119
118
|
|
120
119
|
};// Bitmap::Data
|
@@ -134,7 +133,7 @@ namespace Rays
|
|
134
133
|
this_->self->width = w;
|
135
134
|
this_->self->height = h;
|
136
135
|
this_->self->color_space = cs;
|
137
|
-
this_->self->
|
136
|
+
this_->self->modified = true;
|
138
137
|
|
139
138
|
size_t size = w * h * cs.Bpp();
|
140
139
|
this_->self->pixels = new uchar[size];
|
@@ -151,16 +150,109 @@ namespace Rays
|
|
151
150
|
if (!this_ || !tex)
|
152
151
|
argument_error(__FILE__, __LINE__);
|
153
152
|
|
154
|
-
setup_bitmap(
|
153
|
+
setup_bitmap(
|
154
|
+
this_, tex.width(), tex.height(), tex.color_space(), NULL, false);
|
155
155
|
|
156
156
|
GLenum format, type;
|
157
|
-
|
157
|
+
ColorSpace_get_gl_format_and_type(&format, &type, tex.color_space());
|
158
158
|
|
159
159
|
FrameBuffer fb(tex);
|
160
160
|
FrameBufferBinder binder(fb.id());
|
161
161
|
|
162
162
|
for (int y = 0; y < this_->height(); ++y)
|
163
|
-
|
163
|
+
{
|
164
|
+
GLvoid* ptr = (GLvoid*) this_->at<uchar>(0, y);
|
165
|
+
glReadPixels(0, y, this_->width(), 1, format, type, ptr);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
Bitmap
|
170
|
+
Bitmap_from (const Texture& texture)
|
171
|
+
{
|
172
|
+
Bitmap bmp;
|
173
|
+
setup_bitmap(&bmp, texture);
|
174
|
+
return bmp;
|
175
|
+
}
|
176
|
+
|
177
|
+
void
|
178
|
+
Bitmap_draw_string (
|
179
|
+
Bitmap* bitmap, const RawFont& font, const char* str, coord x, coord y)
|
180
|
+
{
|
181
|
+
if (!bitmap || !*bitmap || !font || !str)
|
182
|
+
argument_error(__FILE__, __LINE__);
|
183
|
+
|
184
|
+
if (*str == '\0') return;
|
185
|
+
|
186
|
+
font.draw_string(bitmap->self->get_context(), bitmap->height(), str, x, y);
|
187
|
+
Bitmap_set_modified(bitmap);
|
188
|
+
}
|
189
|
+
|
190
|
+
void
|
191
|
+
Bitmap_set_modified (Bitmap* bitmap, bool modified)
|
192
|
+
{
|
193
|
+
assert(bitmap);
|
194
|
+
|
195
|
+
bitmap->self->modified = modified;
|
196
|
+
}
|
197
|
+
|
198
|
+
bool
|
199
|
+
Bitmap_get_modified (const Bitmap& bitmap)
|
200
|
+
{
|
201
|
+
return bitmap.self->modified;
|
202
|
+
}
|
203
|
+
|
204
|
+
void
|
205
|
+
Bitmap_save (const Bitmap& bmp, const char* path_)
|
206
|
+
{
|
207
|
+
std::shared_ptr<CGImage> img(bmp.self->get_image(), CGImageRelease);
|
208
|
+
if (!img)
|
209
|
+
rays_error(__FILE__, __LINE__, "getting CGImage failed.");
|
210
|
+
|
211
|
+
NSString* path = [NSString stringWithUTF8String: path_];
|
212
|
+
NSURL* url = [NSURL fileURLWithPath: path];
|
213
|
+
if (!url)
|
214
|
+
rays_error(__FILE__, __LINE__, "creating NSURL failed.");
|
215
|
+
|
216
|
+
std::shared_ptr<CGImageDestination> dest(
|
217
|
+
CGImageDestinationCreateWithURL((CFURLRef) url, kUTTypePNG, 1, NULL),
|
218
|
+
safe_cfrelease);
|
219
|
+
if (!dest)
|
220
|
+
rays_error(__FILE__, __LINE__, "CGImageDestinationCreateWithURL() failed.");
|
221
|
+
|
222
|
+
CGImageDestinationAddImage(dest.get(), img.get(), NULL);
|
223
|
+
if (!CGImageDestinationFinalize(dest.get()))
|
224
|
+
rays_error(__FILE__, __LINE__, "CGImageDestinationFinalize() failed.");
|
225
|
+
}
|
226
|
+
|
227
|
+
Bitmap
|
228
|
+
Bitmap_load (const char* path_)
|
229
|
+
{
|
230
|
+
if (!path_ || path_[0] == '\0')
|
231
|
+
argument_error(__FILE__, __LINE__);
|
232
|
+
|
233
|
+
NSString* path = [NSString stringWithUTF8String: path_];
|
234
|
+
NSBitmapImageRep* imagerep =
|
235
|
+
[NSBitmapImageRep imageRepWithContentsOfFile: path];
|
236
|
+
if (!imagerep)
|
237
|
+
rays_error(__FILE__, __LINE__, "[NSBitmapImageRep imageRepWithContentsOfFile] failed.");
|
238
|
+
|
239
|
+
CGImageRef image = [imagerep CGImage];
|
240
|
+
if (!image)
|
241
|
+
rays_error(__FILE__, __LINE__, "[imagerep CGImage] failed.");
|
242
|
+
|
243
|
+
size_t width = CGImageGetWidth(image);
|
244
|
+
size_t height = CGImageGetHeight(image);
|
245
|
+
|
246
|
+
Bitmap bmp((int) width, (int) height, RGBA);
|
247
|
+
if (!bmp)
|
248
|
+
rays_error(__FILE__, __LINE__, "invalid bitmap.");
|
249
|
+
|
250
|
+
CGContextRef context = bmp.self->get_context();
|
251
|
+
if (!context)
|
252
|
+
rays_error(__FILE__, __LINE__, "creating CGContext failed.");
|
253
|
+
|
254
|
+
CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);
|
255
|
+
return bmp;
|
164
256
|
}
|
165
257
|
|
166
258
|
|
@@ -174,17 +266,12 @@ namespace Rays
|
|
174
266
|
setup_bitmap(this, width, height, color_space, pixels);
|
175
267
|
}
|
176
268
|
|
177
|
-
Bitmap::Bitmap (const Texture& texture)
|
178
|
-
{
|
179
|
-
setup_bitmap(this, texture);
|
180
|
-
}
|
181
|
-
|
182
269
|
Bitmap::~Bitmap ()
|
183
270
|
{
|
184
271
|
}
|
185
272
|
|
186
273
|
Bitmap
|
187
|
-
Bitmap::
|
274
|
+
Bitmap::dup () const
|
188
275
|
{
|
189
276
|
return Bitmap(width(), height(), color_space(), pixels());
|
190
277
|
}
|
@@ -239,22 +326,13 @@ namespace Rays
|
|
239
326
|
return const_cast<This*>(this)->pixels();
|
240
327
|
}
|
241
328
|
|
242
|
-
bool
|
243
|
-
Bitmap::dirty () const
|
244
|
-
{
|
245
|
-
return self->dirty;
|
246
|
-
}
|
247
|
-
|
248
|
-
void
|
249
|
-
Bitmap::set_dirty (bool b)
|
250
|
-
{
|
251
|
-
self->dirty = b;
|
252
|
-
}
|
253
|
-
|
254
329
|
Bitmap::operator bool () const
|
255
330
|
{
|
256
331
|
return
|
257
|
-
self->width
|
332
|
+
self->width > 0 &&
|
333
|
+
self->height > 0 &&
|
334
|
+
self->color_space &&
|
335
|
+
self->pixels;
|
258
336
|
}
|
259
337
|
|
260
338
|
bool
|
@@ -264,77 +342,4 @@ namespace Rays
|
|
264
342
|
}
|
265
343
|
|
266
344
|
|
267
|
-
Bitmap
|
268
|
-
load_bitmap (const char* path_)
|
269
|
-
{
|
270
|
-
if (!path_ || path_[0] == '\0')
|
271
|
-
argument_error(__FILE__, __LINE__);
|
272
|
-
|
273
|
-
NSString* path = [NSString stringWithUTF8String: path_];
|
274
|
-
NSBitmapImageRep* imagerep =
|
275
|
-
[NSBitmapImageRep imageRepWithContentsOfFile: path];
|
276
|
-
if (!imagerep)
|
277
|
-
rays_error(__FILE__, __LINE__, "[NSBitmapImageRep imageRepWithContentsOfFile] failed.");
|
278
|
-
|
279
|
-
CGImageRef image = [imagerep CGImage];
|
280
|
-
if (!image)
|
281
|
-
rays_error(__FILE__, __LINE__, "[imagerep CGImage] failed.");
|
282
|
-
|
283
|
-
size_t width = CGImageGetWidth(image);
|
284
|
-
size_t height = CGImageGetHeight(image);
|
285
|
-
|
286
|
-
Bitmap bmp((int) width, (int) height, RGBA);
|
287
|
-
if (!bmp)
|
288
|
-
rays_error(__FILE__, __LINE__, "invalid bitmap.");
|
289
|
-
|
290
|
-
CGContextRef context = bmp.self->get_context();
|
291
|
-
if (!context)
|
292
|
-
rays_error(__FILE__, __LINE__, "creating CGContext failed.");
|
293
|
-
|
294
|
-
CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);
|
295
|
-
return bmp;
|
296
|
-
}
|
297
|
-
|
298
|
-
void
|
299
|
-
save_bitmap (const Bitmap& bmp, const char* path_)
|
300
|
-
{
|
301
|
-
boost::shared_ptr<CGImage> img(
|
302
|
-
bmp.self->get_image(), CGImageRelease);
|
303
|
-
if (!img)
|
304
|
-
rays_error(__FILE__, __LINE__, "getting CGImage failed.");
|
305
|
-
|
306
|
-
NSString* path = [NSString stringWithUTF8String: path_];
|
307
|
-
NSURL* url = [NSURL fileURLWithPath: path];
|
308
|
-
if (!url)
|
309
|
-
rays_error(__FILE__, __LINE__, "creating NSURL failed.");
|
310
|
-
|
311
|
-
boost::shared_ptr<CGImageDestination> dest(
|
312
|
-
CGImageDestinationCreateWithURL((CFURLRef) url, kUTTypePNG, 1, NULL),
|
313
|
-
safe_cfrelease);
|
314
|
-
if (!dest)
|
315
|
-
rays_error(__FILE__, __LINE__, "CGImageDestinationCreateWithURL() failed.");
|
316
|
-
|
317
|
-
CGImageDestinationAddImage(dest.get(), img.get(), NULL);
|
318
|
-
if (!CGImageDestinationFinalize(dest.get()))
|
319
|
-
rays_error(__FILE__, __LINE__, "CGImageDestinationFinalize() failed.");
|
320
|
-
}
|
321
|
-
|
322
|
-
|
323
|
-
void draw_string (
|
324
|
-
CGContextRef, coord, const char*, coord, coord, const Font&);
|
325
|
-
|
326
|
-
void
|
327
|
-
draw_string (
|
328
|
-
Bitmap* bmp, const char* str, coord x, coord y, const Font& font)
|
329
|
-
{
|
330
|
-
if (!bmp || !*bmp || !str || !font)
|
331
|
-
argument_error(__FILE__, __LINE__);
|
332
|
-
|
333
|
-
if (*str == '\0') return;
|
334
|
-
|
335
|
-
draw_string(bmp->self->get_context(), bmp->height(), str, x, y, font);
|
336
|
-
bmp->set_dirty();
|
337
|
-
}
|
338
|
-
|
339
|
-
|
340
345
|
}// Rays
|