rays 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- 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/frame_buffer.h
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
#include <xot/pimpl.h>
|
8
8
|
#include <rays/defs.h>
|
9
|
-
#include
|
9
|
+
#include "opengl.h"
|
10
10
|
|
11
11
|
|
12
12
|
namespace Rays
|
@@ -45,7 +45,7 @@ namespace Rays
|
|
45
45
|
|
46
46
|
struct Data;
|
47
47
|
|
48
|
-
Xot::
|
48
|
+
Xot::PSharedImpl<Data> self;
|
49
49
|
|
50
50
|
};// FrameBuffer
|
51
51
|
|
@@ -68,9 +68,9 @@ namespace Rays
|
|
68
68
|
};// FrameBufferBinder
|
69
69
|
|
70
70
|
|
71
|
-
void
|
71
|
+
void FrameBuffer_bind (GLuint id);
|
72
72
|
|
73
|
-
void
|
73
|
+
void FrameBuffer_unbind ();
|
74
74
|
|
75
75
|
|
76
76
|
}// Rays
|
data/src/image.cpp
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
#include "rays/image.h"
|
2
2
|
|
3
3
|
|
4
|
+
#include <math.h>
|
5
|
+
#include <assert.h>
|
4
6
|
#include "rays/exception.h"
|
5
|
-
#include "rays/
|
6
|
-
#include "
|
7
|
+
#include "rays/debug.h"
|
8
|
+
#include "opengl.h"
|
9
|
+
#include "bitmap.h"
|
10
|
+
#include "texture.h"
|
7
11
|
|
8
12
|
|
9
13
|
namespace Rays
|
@@ -13,171 +17,241 @@ namespace Rays
|
|
13
17
|
struct Image::Data
|
14
18
|
{
|
15
19
|
|
16
|
-
int width, height;
|
20
|
+
int width = 0, height = 0;
|
17
21
|
|
18
22
|
ColorSpace color_space;
|
19
23
|
|
20
|
-
|
24
|
+
float pixel_density = 1;
|
21
25
|
|
22
26
|
mutable Bitmap bitmap;
|
23
27
|
|
24
28
|
mutable Texture texture;
|
25
29
|
|
26
|
-
Data ()
|
27
|
-
: width(0), height(0), alpha_only(false)
|
28
|
-
{
|
29
|
-
}
|
30
|
-
|
31
30
|
};// Image::Data
|
32
31
|
|
33
32
|
|
34
|
-
|
33
|
+
static void
|
34
|
+
invalidate_texture (Image* image)
|
35
35
|
{
|
36
|
+
image->bitmap();// update bitmap
|
37
|
+
image->self->texture = Texture();
|
36
38
|
}
|
37
39
|
|
38
|
-
|
40
|
+
static void
|
41
|
+
invalidate_texture_for_another_context (Image* image)
|
39
42
|
{
|
40
|
-
|
41
|
-
self->height = height;
|
42
|
-
self->color_space = cs;
|
43
|
-
self->alpha_only = alpha_only;
|
44
|
-
}
|
43
|
+
assert(image);
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
self->width = bitmap.width();
|
49
|
-
self->height = bitmap.height();
|
50
|
-
self->color_space = bitmap.color_space();
|
51
|
-
self->alpha_only = alpha_only;
|
52
|
-
self->bitmap = bitmap;
|
53
|
-
}
|
45
|
+
const Texture& tex = image->self->texture;
|
46
|
+
if (!tex) return;
|
54
47
|
|
55
|
-
|
56
|
-
|
57
|
-
}
|
48
|
+
Context tex_context = tex.context();
|
49
|
+
if (!tex_context) return;
|
58
50
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
return Image(width(), height(), color_space(), alpha_only());
|
63
|
-
}
|
51
|
+
Context current_context = OpenGL_get_context();
|
52
|
+
if (tex_context == current_context)
|
53
|
+
return;
|
64
54
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
Painter p;
|
69
|
-
p.bind(texture());
|
70
|
-
return p;
|
71
|
-
}
|
72
|
-
|
73
|
-
int
|
74
|
-
Image::width () const
|
75
|
-
{
|
76
|
-
return self->width;
|
55
|
+
OpenGL_set_context(tex_context);
|
56
|
+
invalidate_texture(image);
|
57
|
+
OpenGL_set_context(current_context);
|
77
58
|
}
|
78
59
|
|
79
|
-
|
80
|
-
Image
|
60
|
+
static Bitmap&
|
61
|
+
get_bitmap (Image& image)
|
81
62
|
{
|
82
|
-
|
83
|
-
}
|
63
|
+
Image::Data* self = image.self.get();
|
84
64
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
bool
|
92
|
-
Image::alpha_only () const
|
93
|
-
{
|
94
|
-
return self->alpha_only;
|
95
|
-
}
|
65
|
+
if (!image)
|
66
|
+
{
|
67
|
+
assert(!self->bitmap);
|
68
|
+
return self->bitmap;
|
69
|
+
}
|
96
70
|
|
97
|
-
Bitmap&
|
98
|
-
Image::bitmap ()
|
99
|
-
{
|
100
71
|
if (!self->bitmap)
|
101
72
|
{
|
102
73
|
if (self->texture)
|
103
|
-
self->bitmap =
|
74
|
+
self->bitmap = Bitmap_from(self->texture);
|
104
75
|
else
|
105
76
|
self->bitmap = Bitmap(self->width, self->height, self->color_space);
|
106
77
|
}
|
107
|
-
else if (
|
108
|
-
self->
|
78
|
+
else if (
|
79
|
+
self->texture &&
|
80
|
+
self->texture.modified() &&
|
81
|
+
!Bitmap_get_modified(self->bitmap))
|
82
|
+
{
|
83
|
+
self->bitmap = Bitmap_from(self->texture);
|
84
|
+
}
|
109
85
|
|
110
|
-
if (self->bitmap) self->bitmap
|
111
|
-
if (self->texture) self->texture.
|
86
|
+
if (self->bitmap) Bitmap_set_modified(&self->bitmap, false);
|
87
|
+
if (self->texture) self->texture.set_modified(false);
|
112
88
|
|
113
89
|
return self->bitmap;
|
114
90
|
}
|
115
91
|
|
116
|
-
const Bitmap&
|
117
|
-
Image::bitmap () const
|
118
|
-
{
|
119
|
-
return const_cast<This*>(this)->bitmap();
|
120
|
-
}
|
121
|
-
|
122
92
|
Texture&
|
123
|
-
Image
|
93
|
+
Image_get_texture (Image& image)
|
124
94
|
{
|
95
|
+
Image::Data* self = image.self.get();
|
96
|
+
|
97
|
+
if (!image)
|
98
|
+
{
|
99
|
+
assert(!self->texture);
|
100
|
+
return self->texture;
|
101
|
+
}
|
102
|
+
|
103
|
+
invalidate_texture_for_another_context(&image);
|
104
|
+
|
125
105
|
if (!self->texture)
|
126
106
|
{
|
127
107
|
if (self->bitmap)
|
128
|
-
self->texture = Texture(self->bitmap
|
108
|
+
self->texture = Texture(self->bitmap);
|
129
109
|
else
|
130
110
|
{
|
131
|
-
self->texture = Texture(
|
132
|
-
self->width, self->height, self->color_space, self->alpha_only);
|
111
|
+
self->texture = Texture(self->width, self->height, self->color_space);
|
133
112
|
|
134
|
-
Painter p;
|
135
|
-
p.bind(self->texture);
|
113
|
+
Painter p = image.painter();
|
136
114
|
p.begin();
|
137
115
|
p.clear();
|
138
116
|
p.end();
|
139
117
|
}
|
140
118
|
}
|
141
|
-
else if (
|
142
|
-
self->
|
119
|
+
else if (
|
120
|
+
self->bitmap &&
|
121
|
+
Bitmap_get_modified(self->bitmap) &&
|
122
|
+
!self->texture.modified())
|
123
|
+
{
|
124
|
+
self->texture = Texture(self->bitmap);
|
125
|
+
}
|
143
126
|
|
144
|
-
if (self->bitmap) self->bitmap
|
145
|
-
if (self->texture) self->texture.
|
127
|
+
if (self->bitmap) Bitmap_set_modified(&self->bitmap, false);
|
128
|
+
if (self->texture) self->texture.set_modified(false);
|
146
129
|
|
147
130
|
return self->texture;
|
148
131
|
}
|
149
132
|
|
150
133
|
const Texture&
|
151
|
-
Image
|
134
|
+
Image_get_texture (const Image& image)
|
152
135
|
{
|
153
|
-
return const_cast<
|
136
|
+
return Image_get_texture(const_cast<Image&>(image));
|
154
137
|
}
|
155
138
|
|
156
|
-
|
139
|
+
void
|
140
|
+
save_image (const Image& image, const char* path)
|
157
141
|
{
|
158
|
-
|
142
|
+
if (!image)
|
143
|
+
argument_error(__FILE__, __LINE__);
|
144
|
+
|
145
|
+
return Bitmap_save(image.bitmap(), path);
|
159
146
|
}
|
160
147
|
|
161
|
-
|
162
|
-
|
148
|
+
Image
|
149
|
+
load_image (const char* path)
|
150
|
+
{
|
151
|
+
return Image(Bitmap_load(path));
|
152
|
+
}
|
153
|
+
|
154
|
+
|
155
|
+
Image::Image ()
|
163
156
|
{
|
164
|
-
return !operator bool();
|
165
157
|
}
|
166
158
|
|
159
|
+
Image::Image (
|
160
|
+
int width, int height, const ColorSpace& cs, float pixel_density)
|
161
|
+
{
|
162
|
+
if (pixel_density <= 0)
|
163
|
+
argument_error(__FILE__, __LINE__, "invalid pixel_density.");
|
164
|
+
|
165
|
+
coord w = width * pixel_density;
|
166
|
+
coord h = height * pixel_density;
|
167
|
+
if ((w - (int) w) != 0 || (h - (int) h) != 0)
|
168
|
+
argument_error(__FILE__, __LINE__, "invalid size for image.");
|
169
|
+
|
170
|
+
self->width = w;
|
171
|
+
self->height = h;
|
172
|
+
self->color_space = cs;
|
173
|
+
self->pixel_density = pixel_density;
|
174
|
+
}
|
175
|
+
|
176
|
+
Image::Image (const Bitmap& bitmap, float pixel_density)
|
177
|
+
{
|
178
|
+
if (pixel_density <= 0)
|
179
|
+
argument_error(__FILE__, __LINE__, "invalid pixel_density.");
|
180
|
+
|
181
|
+
self->bitmap = bitmap;
|
182
|
+
self->width = bitmap.width();
|
183
|
+
self->height = bitmap.height();
|
184
|
+
self->color_space = bitmap.color_space();
|
185
|
+
self->pixel_density = pixel_density;
|
186
|
+
}
|
187
|
+
|
188
|
+
Image::~Image ()
|
189
|
+
{
|
190
|
+
}
|
167
191
|
|
168
192
|
Image
|
169
|
-
|
193
|
+
Image::dup () const
|
170
194
|
{
|
171
|
-
return Image(
|
195
|
+
return Image(bitmap().dup(), pixel_density());
|
172
196
|
}
|
173
197
|
|
174
|
-
|
175
|
-
|
198
|
+
coord
|
199
|
+
Image::width () const
|
176
200
|
{
|
177
|
-
|
178
|
-
|
201
|
+
return self->width / self->pixel_density;
|
202
|
+
}
|
179
203
|
|
180
|
-
|
204
|
+
coord
|
205
|
+
Image::height () const
|
206
|
+
{
|
207
|
+
return self->height / self->pixel_density;
|
208
|
+
}
|
209
|
+
|
210
|
+
const ColorSpace&
|
211
|
+
Image::color_space () const
|
212
|
+
{
|
213
|
+
return self->color_space;
|
214
|
+
}
|
215
|
+
|
216
|
+
float
|
217
|
+
Image::pixel_density () const
|
218
|
+
{
|
219
|
+
return self->pixel_density;
|
220
|
+
}
|
221
|
+
|
222
|
+
Painter
|
223
|
+
Image::painter ()
|
224
|
+
{
|
225
|
+
Painter p;
|
226
|
+
p.bind(*this);
|
227
|
+
return p;
|
228
|
+
}
|
229
|
+
|
230
|
+
Bitmap&
|
231
|
+
Image::bitmap ()
|
232
|
+
{
|
233
|
+
return get_bitmap(*this);
|
234
|
+
}
|
235
|
+
|
236
|
+
const Bitmap&
|
237
|
+
Image::bitmap () const
|
238
|
+
{
|
239
|
+
return get_bitmap(const_cast<Image&>(*this));
|
240
|
+
}
|
241
|
+
|
242
|
+
Image::operator bool () const
|
243
|
+
{
|
244
|
+
return
|
245
|
+
self->width > 0 &&
|
246
|
+
self->height > 0 &&
|
247
|
+
self->pixel_density > 0 &&
|
248
|
+
self->color_space;
|
249
|
+
}
|
250
|
+
|
251
|
+
bool
|
252
|
+
Image::operator ! () const
|
253
|
+
{
|
254
|
+
return !operator bool();
|
181
255
|
}
|
182
256
|
|
183
257
|
|
data/src/image.h
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RAYS_SRC_IMAGE_H__
|
4
|
+
#define __RAYS_SRC_IMAGE_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <rays/image.h>
|
8
|
+
|
9
|
+
|
10
|
+
namespace Rays
|
11
|
+
{
|
12
|
+
|
13
|
+
|
14
|
+
class Texture;
|
15
|
+
|
16
|
+
|
17
|
+
Texture& Image_get_texture ( Image& image);
|
18
|
+
|
19
|
+
const Texture& Image_get_texture (const Image& image);
|
20
|
+
|
21
|
+
|
22
|
+
}// Rays
|
23
|
+
|
24
|
+
|
25
|
+
#endif//EOH
|
data/src/ios/bitmap.mm
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
// -*- objc -*-
|
2
|
-
#import "
|
2
|
+
#import "../bitmap.h"
|
3
3
|
|
4
4
|
|
5
|
-
#
|
6
|
-
#include <boost/scoped_array.hpp>
|
7
|
-
#import <ImageIO/ImageIO.h>
|
5
|
+
#import <ImageIO/CGImageDestination.h>
|
8
6
|
#import <MobileCoreServices/UTCoreTypes.h>
|
9
7
|
#include "rays/exception.h"
|
10
|
-
#include "
|
8
|
+
#include "../color_space.h"
|
9
|
+
#include "../font.h"
|
10
|
+
#include "../texture.h"
|
11
11
|
#include "../frame_buffer.h"
|
12
12
|
#include "helper.h"
|
13
13
|
|
@@ -60,14 +60,13 @@ namespace Rays
|
|
60
60
|
|
61
61
|
ColorSpace color_space;
|
62
62
|
|
63
|
-
void* pixels;
|
63
|
+
void* pixels = NULL;
|
64
64
|
|
65
|
-
CGContextRef context;
|
65
|
+
CGContextRef context = NULL;
|
66
66
|
|
67
|
-
bool
|
67
|
+
bool modified;
|
68
68
|
|
69
69
|
Data ()
|
70
|
-
: pixels(NULL), context(NULL)
|
71
70
|
{
|
72
71
|
clear();
|
73
72
|
}
|
@@ -86,7 +85,7 @@ namespace Rays
|
|
86
85
|
if (bpc <= 0 || pitch <= 0) return NULL;
|
87
86
|
|
88
87
|
CGColorSpaceRef cgcs = NULL;
|
89
|
-
if (color_space.is_gray())
|
88
|
+
if (color_space.is_gray() || color_space.is_alpha())
|
90
89
|
cgcs = CGColorSpaceCreateDeviceGray();
|
91
90
|
else if (color_space.is_rgb() || color_space.is_bgr())
|
92
91
|
cgcs = CGColorSpaceCreateDeviceRGB();
|
@@ -115,7 +114,7 @@ namespace Rays
|
|
115
114
|
color_space = COLORSPACE_UNKNOWN;
|
116
115
|
pixels = NULL;
|
117
116
|
context = NULL;
|
118
|
-
|
117
|
+
modified = false;
|
119
118
|
}
|
120
119
|
|
121
120
|
};// Bitmap::Data
|
@@ -135,7 +134,7 @@ namespace Rays
|
|
135
134
|
this_->self->width = w;
|
136
135
|
this_->self->height = h;
|
137
136
|
this_->self->color_space = cs;
|
138
|
-
this_->self->
|
137
|
+
this_->self->modified = true;
|
139
138
|
|
140
139
|
size_t size = w * h * cs.Bpp();
|
141
140
|
this_->self->pixels = new uchar[size];
|
@@ -152,16 +151,108 @@ namespace Rays
|
|
152
151
|
if (!this_ || !tex)
|
153
152
|
argument_error(__FILE__, __LINE__);
|
154
153
|
|
155
|
-
setup_bitmap(
|
154
|
+
setup_bitmap(
|
155
|
+
this_, tex.width(), tex.height(), tex.color_space(), NULL, false);
|
156
156
|
|
157
157
|
GLenum format, type;
|
158
|
-
|
158
|
+
ColorSpace_get_gl_format_and_type(&format, &type, tex.color_space());
|
159
159
|
|
160
160
|
FrameBuffer fb(tex);
|
161
161
|
FrameBufferBinder binder(fb.id());
|
162
162
|
|
163
163
|
for (int y = 0; y < this_->height(); ++y)
|
164
|
-
|
164
|
+
{
|
165
|
+
GLvoid* ptr = (GLvoid*) this_->at<uchar>(0, y);
|
166
|
+
glReadPixels(0, y, this_->width(), 1, format, type, ptr);
|
167
|
+
}
|
168
|
+
}
|
169
|
+
|
170
|
+
Bitmap
|
171
|
+
Bitmap_from (const Texture& texture)
|
172
|
+
{
|
173
|
+
Bitmap bmp;
|
174
|
+
setup_bitmap(&bmp, texture);
|
175
|
+
return bmp;
|
176
|
+
}
|
177
|
+
|
178
|
+
void
|
179
|
+
Bitmap_draw_string (
|
180
|
+
Bitmap* bitmap, const RawFont& font, const char* str, coord x, coord y)
|
181
|
+
{
|
182
|
+
if (!bitmap || !*bitmap || !font || !str)
|
183
|
+
argument_error(__FILE__, __LINE__);
|
184
|
+
|
185
|
+
if (*str == '\0') return;
|
186
|
+
|
187
|
+
font.draw_string(bitmap->self->get_context(), bitmap->height(), str, x, y);
|
188
|
+
Bitmap_set_modified(bitmap);
|
189
|
+
}
|
190
|
+
|
191
|
+
void
|
192
|
+
Bitmap_set_modified (Bitmap* bitmap, bool modified)
|
193
|
+
{
|
194
|
+
assert(bitmap);
|
195
|
+
|
196
|
+
bitmap->self->modified = modified;
|
197
|
+
}
|
198
|
+
|
199
|
+
bool
|
200
|
+
Bitmap_get_modified (const Bitmap& bitmap)
|
201
|
+
{
|
202
|
+
return bitmap.self->modified;
|
203
|
+
}
|
204
|
+
|
205
|
+
void
|
206
|
+
Bitmap_save (const Bitmap& bmp, const char* path_)
|
207
|
+
{
|
208
|
+
std::shared_ptr<CGImage> img(bmp.self->get_image(), CGImageRelease);
|
209
|
+
if (!img)
|
210
|
+
rays_error(__FILE__, __LINE__, "getting CGImage failed.");
|
211
|
+
|
212
|
+
NSString* path = [NSString stringWithUTF8String: path_];
|
213
|
+
NSURL* url = [NSURL fileURLWithPath: path];
|
214
|
+
if (!url)
|
215
|
+
rays_error(__FILE__, __LINE__, "creating NSURL failed.");
|
216
|
+
|
217
|
+
std::shared_ptr<CGImageDestination> dest(
|
218
|
+
CGImageDestinationCreateWithURL((CFURLRef) url, kUTTypePNG, 1, NULL),
|
219
|
+
safe_cfrelease);
|
220
|
+
if (!dest)
|
221
|
+
rays_error(__FILE__, __LINE__, "CGImageDestinationCreateWithURL() failed.");
|
222
|
+
|
223
|
+
CGImageDestinationAddImage(dest.get(), img.get(), NULL);
|
224
|
+
if (!CGImageDestinationFinalize(dest.get()))
|
225
|
+
rays_error(__FILE__, __LINE__, "CGImageDestinationFinalize() failed.");
|
226
|
+
}
|
227
|
+
|
228
|
+
Bitmap
|
229
|
+
Bitmap_load (const char* path_)
|
230
|
+
{
|
231
|
+
if (!path_ || path_[0] == '\0')
|
232
|
+
argument_error(__FILE__, __LINE__);
|
233
|
+
|
234
|
+
NSString* path = [NSString stringWithUTF8String: path_];
|
235
|
+
UIImage* uiimage = [UIImage imageWithContentsOfFile: path];
|
236
|
+
if (!uiimage)
|
237
|
+
rays_error(__FILE__, __LINE__, "[UIImage imageWithContentsOfFile:] failed.");
|
238
|
+
|
239
|
+
CGImageRef image = [uiimage 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;
|
165
256
|
}
|
166
257
|
|
167
258
|
|
@@ -175,17 +266,12 @@ namespace Rays
|
|
175
266
|
setup_bitmap(this, width, height, color_space, pixels);
|
176
267
|
}
|
177
268
|
|
178
|
-
Bitmap::Bitmap (const Texture& texture)
|
179
|
-
{
|
180
|
-
setup_bitmap(this, texture);
|
181
|
-
}
|
182
|
-
|
183
269
|
Bitmap::~Bitmap ()
|
184
270
|
{
|
185
271
|
}
|
186
272
|
|
187
273
|
Bitmap
|
188
|
-
Bitmap::
|
274
|
+
Bitmap::dup () const
|
189
275
|
{
|
190
276
|
return Bitmap(width(), height(), color_space(), pixels());
|
191
277
|
}
|
@@ -240,18 +326,6 @@ namespace Rays
|
|
240
326
|
return const_cast<This*>(this)->pixels();
|
241
327
|
}
|
242
328
|
|
243
|
-
bool
|
244
|
-
Bitmap::dirty () const
|
245
|
-
{
|
246
|
-
return self->dirty;
|
247
|
-
}
|
248
|
-
|
249
|
-
void
|
250
|
-
Bitmap::set_dirty (bool b)
|
251
|
-
{
|
252
|
-
self->dirty = b;
|
253
|
-
}
|
254
|
-
|
255
329
|
Bitmap::operator bool () const
|
256
330
|
{
|
257
331
|
return
|
@@ -265,76 +339,4 @@ namespace Rays
|
|
265
339
|
}
|
266
340
|
|
267
341
|
|
268
|
-
Bitmap
|
269
|
-
load_bitmap (const char* path_)
|
270
|
-
{
|
271
|
-
if (!path_ || path_[0] == '\0')
|
272
|
-
argument_error(__FILE__, __LINE__);
|
273
|
-
|
274
|
-
NSString* path = [NSString stringWithUTF8String: path_];
|
275
|
-
UIImage* uiimage = [UIImage imageWithContentsOfFile: path];
|
276
|
-
if (!uiimage)
|
277
|
-
rays_error(__FILE__, __LINE__, "[UIImage imageWithContentsOfFile:] failed.");
|
278
|
-
|
279
|
-
CGImageRef image = [uiimage 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
342
|
}// Rays
|