rays 0.1.12 → 0.1.17
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/camera.cpp +171 -0
- data/.doc/ext/rays/color.cpp +223 -45
- data/.doc/ext/rays/color_space.cpp +146 -46
- data/.doc/ext/rays/defs.cpp +183 -0
- data/.doc/ext/rays/font.cpp +69 -21
- data/.doc/ext/rays/image.cpp +26 -37
- data/.doc/ext/rays/matrix.cpp +186 -29
- data/.doc/ext/rays/native.cpp +14 -8
- data/.doc/ext/rays/noise.cpp +53 -0
- data/.doc/ext/rays/painter.cpp +187 -292
- data/.doc/ext/rays/point.cpp +96 -77
- data/.doc/ext/rays/polygon.cpp +313 -0
- data/.doc/ext/rays/polygon_line.cpp +96 -0
- data/.doc/ext/rays/polyline.cpp +167 -0
- data/.doc/ext/rays/rays.cpp +103 -12
- data/.doc/ext/rays/shader.cpp +83 -9
- data/LICENSE +21 -0
- data/README.md +1 -1
- data/Rakefile +24 -9
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +23 -81
- data/ext/rays/bounds.cpp +100 -128
- data/ext/rays/camera.cpp +186 -0
- data/ext/rays/color.cpp +231 -51
- data/ext/rays/color_space.cpp +149 -47
- data/ext/rays/defs.cpp +183 -0
- data/ext/rays/defs.h +26 -2
- data/ext/rays/extconf.rb +2 -3
- data/ext/rays/font.cpp +74 -24
- data/ext/rays/image.cpp +28 -40
- data/ext/rays/matrix.cpp +198 -30
- data/ext/rays/native.cpp +14 -8
- data/ext/rays/noise.cpp +55 -0
- data/ext/rays/painter.cpp +203 -298
- data/ext/rays/point.cpp +105 -81
- data/ext/rays/polygon.cpp +329 -0
- data/ext/rays/polygon_line.cpp +99 -0
- data/ext/rays/polyline.cpp +176 -0
- data/ext/rays/rays.cpp +103 -13
- 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/camera.h +74 -0
- data/include/rays/color.h +25 -14
- data/include/rays/color_space.h +15 -10
- data/include/rays/coord.h +114 -0
- data/include/rays/debug.h +22 -0
- data/include/rays/defs.h +36 -0
- data/include/rays/exception.h +6 -2
- data/include/rays/font.h +4 -4
- data/include/rays/image.h +12 -18
- 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 +89 -93
- data/include/rays/point.h +44 -51
- data/include/rays/polygon.h +198 -0
- data/include/rays/polyline.h +71 -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/camera.h +41 -0
- 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/rays.h +8 -0
- data/include/rays/ruby/shader.h +1 -1
- data/include/rays/shader.h +36 -8
- data/lib/rays.rb +7 -2
- data/lib/rays/bitmap.rb +0 -15
- data/lib/rays/bounds.rb +17 -23
- data/lib/rays/camera.rb +24 -0
- data/lib/rays/color.rb +20 -47
- data/lib/rays/color_space.rb +13 -13
- data/lib/rays/image.rb +3 -7
- data/lib/rays/matrix.rb +28 -0
- data/lib/rays/module.rb +4 -19
- data/lib/rays/painter.rb +78 -93
- data/lib/rays/point.rb +13 -21
- data/lib/rays/polygon.rb +58 -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 +52 -34
- 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 +172 -98
- data/src/image.h +25 -0
- data/src/ios/bitmap.h +23 -0
- data/src/ios/bitmap.mm +133 -110
- data/src/ios/camera.mm +510 -0
- data/src/ios/font.mm +50 -62
- data/src/ios/helper.h +4 -4
- 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.h +23 -0
- data/src/osx/bitmap.mm +133 -110
- data/src/osx/camera.mm +451 -0
- data/src/osx/font.mm +49 -62
- 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 +845 -671
- data/src/painter.h +24 -0
- data/src/point.cpp +140 -119
- data/src/polygon.cpp +1266 -0
- data/src/polygon.h +32 -0
- data/src/polyline.cpp +160 -0
- data/src/polyline.h +69 -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_font.rb +5 -0
- data/test/test_image.rb +24 -20
- data/test/test_matrix.rb +106 -0
- data/test/test_painter.rb +157 -51
- data/test/test_painter_shape.rb +102 -0
- data/test/test_point.rb +29 -0
- data/test/test_polygon.rb +234 -0
- data/test/test_polygon_line.rb +167 -0
- data/test/test_polyline.rb +171 -0
- data/test/test_shader.rb +9 -9
- metadata +102 -70
- 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/matrix.h
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RAYS_SRC_MATRIX_H__
|
4
|
+
#define __RAYS_SRC_MATRIX_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <glm/mat4x4.hpp>
|
8
|
+
#include <rays/matrix.h>
|
9
|
+
|
10
|
+
|
11
|
+
namespace Rays
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
typedef glm::tmat4x4<coord> Mat4;
|
16
|
+
|
17
|
+
|
18
|
+
inline Mat4& to_glm ( Matrix& val) {return *( Mat4*) &val;}
|
19
|
+
|
20
|
+
inline const Mat4& to_glm (const Matrix& val) {return *(const Mat4*) &val;}
|
21
|
+
|
22
|
+
inline Matrix& to_rays ( Mat4& val) {return *( Matrix*) &val;}
|
23
|
+
|
24
|
+
inline const Matrix& to_rays (const Mat4& val) {return *(const Matrix*) &val;}
|
25
|
+
|
26
|
+
|
27
|
+
}// Rays
|
28
|
+
|
29
|
+
|
30
|
+
#endif//EOH
|
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.h
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
// -*- mode: c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RAYS_SRC_OSX_BITMAP_H__
|
4
|
+
#define __RAYS_SRC_OSX_BITMAP_H__
|
5
|
+
|
6
|
+
|
7
|
+
#import <CoreGraphics/CGImage.h>
|
8
|
+
#include "../bitmap.h"
|
9
|
+
|
10
|
+
|
11
|
+
namespace Rays
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
void Bitmap_draw_image (
|
16
|
+
Bitmap* bitmap, CGImageRef image,
|
17
|
+
coord x = 0, coord y = 0, coord width = -1, coord height = -1);
|
18
|
+
|
19
|
+
|
20
|
+
}// Rays
|
21
|
+
|
22
|
+
|
23
|
+
#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
|
|
@@ -26,14 +26,14 @@ namespace Rays
|
|
26
26
|
if (cs.is_alpha_first())
|
27
27
|
{
|
28
28
|
info |= cs.is_premult()
|
29
|
-
?
|
30
|
-
:
|
29
|
+
? kCGImageAlphaPremultipliedFirst
|
30
|
+
: kCGImageAlphaFirst;
|
31
31
|
}
|
32
32
|
else if (cs.is_alpha_last())
|
33
33
|
{
|
34
34
|
info |= cs.is_premult()
|
35
|
-
?
|
36
|
-
:
|
35
|
+
? kCGImageAlphaPremultipliedLast
|
36
|
+
: kCGImageAlphaLast;
|
37
37
|
}
|
38
38
|
else if (cs.is_skip_first())
|
39
39
|
info |= kCGImageAlphaNoneSkipFirst;
|
@@ -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,127 @@ 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_image (
|
179
|
+
Bitmap* bitmap, CGImageRef image,
|
180
|
+
coord x, coord y, coord width, coord height)
|
181
|
+
{
|
182
|
+
if (width == 0 || height == 0) return;
|
183
|
+
|
184
|
+
if (!bitmap || !image)
|
185
|
+
argument_error(__FILE__, __LINE__);
|
186
|
+
|
187
|
+
CGContextRef context = bitmap->self->get_context();
|
188
|
+
if (!context)
|
189
|
+
rays_error(__FILE__, __LINE__, "getting CGContext failed.");
|
190
|
+
|
191
|
+
if (width < 0) width = (coord) CGImageGetWidth(image);
|
192
|
+
if (height < 0) height = (coord) CGImageGetHeight(image);
|
193
|
+
CGContextDrawImage(context, CGRectMake(x, y, width, height), image);
|
194
|
+
|
195
|
+
Bitmap_set_modified(bitmap);
|
196
|
+
}
|
197
|
+
|
198
|
+
void
|
199
|
+
Bitmap_draw_string (
|
200
|
+
Bitmap* bitmap, const RawFont& font, const char* str, coord x, coord y)
|
201
|
+
{
|
202
|
+
if (!bitmap || !*bitmap || !font || !str)
|
203
|
+
argument_error(__FILE__, __LINE__);
|
204
|
+
|
205
|
+
if (*str == '\0') return;
|
206
|
+
|
207
|
+
font.draw_string(bitmap->self->get_context(), bitmap->height(), str, x, y);
|
208
|
+
|
209
|
+
Bitmap_set_modified(bitmap);
|
210
|
+
}
|
211
|
+
|
212
|
+
void
|
213
|
+
Bitmap_set_modified (Bitmap* bitmap, bool modified)
|
214
|
+
{
|
215
|
+
assert(bitmap);
|
216
|
+
|
217
|
+
bitmap->self->modified = modified;
|
218
|
+
}
|
219
|
+
|
220
|
+
bool
|
221
|
+
Bitmap_get_modified (const Bitmap& bitmap)
|
222
|
+
{
|
223
|
+
return bitmap.self->modified;
|
224
|
+
}
|
225
|
+
|
226
|
+
void
|
227
|
+
Bitmap_save (const Bitmap& bmp, const char* path_)
|
228
|
+
{
|
229
|
+
std::shared_ptr<CGImage> img(bmp.self->get_image(), CGImageRelease);
|
230
|
+
if (!img)
|
231
|
+
rays_error(__FILE__, __LINE__, "getting CGImage failed.");
|
232
|
+
|
233
|
+
NSString* path = [NSString stringWithUTF8String: path_];
|
234
|
+
NSURL* url = [NSURL fileURLWithPath: path];
|
235
|
+
if (!url)
|
236
|
+
rays_error(__FILE__, __LINE__, "creating NSURL failed.");
|
237
|
+
|
238
|
+
std::shared_ptr<CGImageDestination> dest(
|
239
|
+
CGImageDestinationCreateWithURL((CFURLRef) url, kUTTypePNG, 1, NULL),
|
240
|
+
safe_cfrelease);
|
241
|
+
if (!dest)
|
242
|
+
rays_error(__FILE__, __LINE__, "CGImageDestinationCreateWithURL() failed.");
|
243
|
+
|
244
|
+
CGImageDestinationAddImage(dest.get(), img.get(), NULL);
|
245
|
+
if (!CGImageDestinationFinalize(dest.get()))
|
246
|
+
rays_error(__FILE__, __LINE__, "CGImageDestinationFinalize() failed.");
|
247
|
+
}
|
248
|
+
|
249
|
+
Bitmap
|
250
|
+
Bitmap_load (const char* path_)
|
251
|
+
{
|
252
|
+
if (!path_ || path_[0] == '\0')
|
253
|
+
argument_error(__FILE__, __LINE__);
|
254
|
+
|
255
|
+
NSString* path = [NSString stringWithUTF8String: path_];
|
256
|
+
NSBitmapImageRep* imagerep =
|
257
|
+
[NSBitmapImageRep imageRepWithContentsOfFile: path];
|
258
|
+
if (!imagerep)
|
259
|
+
rays_error(__FILE__, __LINE__, "[NSBitmapImageRep imageRepWithContentsOfFile] failed.");
|
260
|
+
|
261
|
+
CGImageRef image = [imagerep CGImage];
|
262
|
+
if (!image)
|
263
|
+
rays_error(__FILE__, __LINE__, "[imagerep CGImage] failed.");
|
264
|
+
|
265
|
+
size_t width = CGImageGetWidth(image);
|
266
|
+
size_t height = CGImageGetHeight(image);
|
267
|
+
|
268
|
+
Bitmap bmp((int) width, (int) height, RGBA);
|
269
|
+
if (!bmp)
|
270
|
+
rays_error(__FILE__, __LINE__, "invalid bitmap.");
|
271
|
+
|
272
|
+
Bitmap_draw_image(&bmp, image);
|
273
|
+
return bmp;
|
164
274
|
}
|
165
275
|
|
166
276
|
|
@@ -174,17 +284,12 @@ namespace Rays
|
|
174
284
|
setup_bitmap(this, width, height, color_space, pixels);
|
175
285
|
}
|
176
286
|
|
177
|
-
Bitmap::Bitmap (const Texture& texture)
|
178
|
-
{
|
179
|
-
setup_bitmap(this, texture);
|
180
|
-
}
|
181
|
-
|
182
287
|
Bitmap::~Bitmap ()
|
183
288
|
{
|
184
289
|
}
|
185
290
|
|
186
291
|
Bitmap
|
187
|
-
Bitmap::
|
292
|
+
Bitmap::dup () const
|
188
293
|
{
|
189
294
|
return Bitmap(width(), height(), color_space(), pixels());
|
190
295
|
}
|
@@ -239,22 +344,13 @@ namespace Rays
|
|
239
344
|
return const_cast<This*>(this)->pixels();
|
240
345
|
}
|
241
346
|
|
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
347
|
Bitmap::operator bool () const
|
255
348
|
{
|
256
349
|
return
|
257
|
-
self->width
|
350
|
+
self->width > 0 &&
|
351
|
+
self->height > 0 &&
|
352
|
+
self->color_space &&
|
353
|
+
self->pixels;
|
258
354
|
}
|
259
355
|
|
260
356
|
bool
|
@@ -264,77 +360,4 @@ namespace Rays
|
|
264
360
|
}
|
265
361
|
|
266
362
|
|
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
363
|
}// Rays
|