rays 0.1.11 → 0.1.16

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.
Files changed (168) hide show
  1. checksums.yaml +5 -5
  2. data/.doc/ext/rays/bitmap.cpp +22 -76
  3. data/.doc/ext/rays/bounds.cpp +95 -125
  4. data/.doc/ext/rays/camera.cpp +88 -0
  5. data/.doc/ext/rays/color.cpp +223 -45
  6. data/.doc/ext/rays/color_space.cpp +146 -46
  7. data/.doc/ext/rays/defs.cpp +183 -0
  8. data/.doc/ext/rays/font.cpp +69 -21
  9. data/.doc/ext/rays/image.cpp +26 -37
  10. data/.doc/ext/rays/matrix.cpp +186 -29
  11. data/.doc/ext/rays/native.cpp +14 -8
  12. data/.doc/ext/rays/noise.cpp +53 -0
  13. data/.doc/ext/rays/painter.cpp +187 -292
  14. data/.doc/ext/rays/point.cpp +96 -77
  15. data/.doc/ext/rays/polygon.cpp +313 -0
  16. data/.doc/ext/rays/polygon_line.cpp +96 -0
  17. data/.doc/ext/rays/polyline.cpp +167 -0
  18. data/.doc/ext/rays/rays.cpp +103 -12
  19. data/.doc/ext/rays/shader.cpp +83 -9
  20. data/LICENSE +21 -0
  21. data/README.md +1 -1
  22. data/Rakefile +24 -9
  23. data/VERSION +1 -1
  24. data/ext/rays/bitmap.cpp +22 -80
  25. data/ext/rays/bounds.cpp +100 -128
  26. data/ext/rays/camera.cpp +94 -0
  27. data/ext/rays/color.cpp +231 -51
  28. data/ext/rays/color_space.cpp +149 -47
  29. data/ext/rays/defs.cpp +183 -0
  30. data/ext/rays/defs.h +26 -2
  31. data/ext/rays/extconf.rb +2 -3
  32. data/ext/rays/font.cpp +74 -24
  33. data/ext/rays/image.cpp +28 -40
  34. data/ext/rays/matrix.cpp +198 -30
  35. data/ext/rays/native.cpp +14 -8
  36. data/ext/rays/noise.cpp +55 -0
  37. data/ext/rays/painter.cpp +203 -298
  38. data/ext/rays/point.cpp +105 -81
  39. data/ext/rays/polygon.cpp +329 -0
  40. data/ext/rays/polygon_line.cpp +99 -0
  41. data/ext/rays/polyline.cpp +176 -0
  42. data/ext/rays/rays.cpp +103 -13
  43. data/ext/rays/shader.cpp +84 -9
  44. data/include/rays.h +10 -2
  45. data/include/rays/bitmap.h +14 -26
  46. data/include/rays/bounds.h +21 -4
  47. data/include/rays/camera.h +49 -0
  48. data/include/rays/color.h +25 -14
  49. data/include/rays/color_space.h +15 -10
  50. data/include/rays/coord.h +114 -0
  51. data/include/rays/debug.h +22 -0
  52. data/include/rays/defs.h +36 -0
  53. data/include/rays/exception.h +6 -2
  54. data/include/rays/font.h +4 -4
  55. data/include/rays/image.h +12 -18
  56. data/include/rays/matrix.h +50 -24
  57. data/include/rays/noise.h +42 -0
  58. data/include/rays/opengl.h +2 -50
  59. data/include/rays/painter.h +89 -93
  60. data/include/rays/point.h +44 -51
  61. data/include/rays/polygon.h +198 -0
  62. data/include/rays/polyline.h +71 -0
  63. data/include/rays/rays.h +3 -0
  64. data/include/rays/ruby.h +7 -1
  65. data/include/rays/ruby/bounds.h +1 -1
  66. data/include/rays/ruby/camera.h +41 -0
  67. data/include/rays/ruby/color.h +1 -1
  68. data/include/rays/ruby/color_space.h +1 -1
  69. data/include/rays/ruby/font.h +1 -1
  70. data/include/rays/ruby/matrix.h +1 -1
  71. data/include/rays/ruby/point.h +1 -1
  72. data/include/rays/ruby/polygon.h +52 -0
  73. data/include/rays/ruby/polyline.h +41 -0
  74. data/include/rays/ruby/rays.h +8 -0
  75. data/include/rays/ruby/shader.h +1 -1
  76. data/include/rays/shader.h +36 -8
  77. data/lib/rays.rb +7 -2
  78. data/lib/rays/bitmap.rb +0 -15
  79. data/lib/rays/bounds.rb +17 -23
  80. data/lib/rays/camera.rb +21 -0
  81. data/lib/rays/color.rb +20 -47
  82. data/lib/rays/color_space.rb +13 -13
  83. data/lib/rays/image.rb +3 -7
  84. data/lib/rays/matrix.rb +28 -0
  85. data/lib/rays/module.rb +4 -19
  86. data/lib/rays/painter.rb +78 -93
  87. data/lib/rays/point.rb +13 -21
  88. data/lib/rays/polygon.rb +58 -0
  89. data/lib/rays/polygon_line.rb +36 -0
  90. data/lib/rays/polyline.rb +32 -0
  91. data/lib/rays/shader.rb +20 -1
  92. data/rays.gemspec +5 -7
  93. data/src/bitmap.h +36 -0
  94. data/src/bounds.cpp +74 -11
  95. data/src/color.cpp +58 -23
  96. data/src/color_space.cpp +52 -34
  97. data/src/color_space.h +22 -0
  98. data/src/coord.cpp +170 -0
  99. data/src/coord.h +35 -0
  100. data/src/font.cpp +118 -0
  101. data/src/font.h +64 -0
  102. data/src/frame_buffer.cpp +37 -71
  103. data/src/frame_buffer.h +4 -4
  104. data/src/image.cpp +172 -98
  105. data/src/image.h +25 -0
  106. data/src/ios/bitmap.h +21 -0
  107. data/src/ios/bitmap.mm +129 -110
  108. data/src/ios/camera.mm +236 -0
  109. data/src/ios/font.mm +50 -62
  110. data/src/ios/helper.h +2 -2
  111. data/src/ios/opengl.mm +19 -4
  112. data/src/ios/rays.mm +3 -0
  113. data/src/matrix.cpp +111 -26
  114. data/src/matrix.h +30 -0
  115. data/src/noise.cpp +74 -0
  116. data/src/opengl.cpp +9 -27
  117. data/src/opengl.h +37 -0
  118. data/src/osx/bitmap.h +21 -0
  119. data/src/osx/bitmap.mm +129 -110
  120. data/src/osx/camera.mm +236 -0
  121. data/src/osx/font.mm +49 -62
  122. data/src/osx/helper.h +2 -2
  123. data/src/osx/opengl.mm +19 -83
  124. data/src/osx/rays.mm +3 -0
  125. data/src/painter.cpp +845 -671
  126. data/src/painter.h +24 -0
  127. data/src/point.cpp +140 -119
  128. data/src/polygon.cpp +1266 -0
  129. data/src/polygon.h +32 -0
  130. data/src/polyline.cpp +160 -0
  131. data/src/polyline.h +69 -0
  132. data/src/render_buffer.cpp +11 -4
  133. data/src/render_buffer.h +2 -2
  134. data/src/shader.cpp +163 -106
  135. data/src/shader.h +38 -0
  136. data/src/shader_program.cpp +533 -0
  137. data/src/{program.h → shader_program.h} +28 -16
  138. data/src/shader_source.cpp +140 -0
  139. data/src/shader_source.h +52 -0
  140. data/src/texture.cpp +136 -160
  141. data/src/texture.h +65 -0
  142. data/src/win32/bitmap.cpp +62 -52
  143. data/src/win32/font.cpp +11 -13
  144. data/src/win32/font.h +24 -0
  145. data/src/win32/gdi.h +6 -6
  146. data/test/helper.rb +0 -3
  147. data/test/test_bitmap.rb +31 -7
  148. data/test/test_bounds.rb +36 -0
  149. data/test/test_color.rb +59 -19
  150. data/test/test_color_space.rb +95 -0
  151. data/test/test_font.rb +5 -0
  152. data/test/test_image.rb +24 -20
  153. data/test/test_matrix.rb +106 -0
  154. data/test/test_painter.rb +157 -51
  155. data/test/test_painter_shape.rb +102 -0
  156. data/test/test_point.rb +29 -0
  157. data/test/test_polygon.rb +234 -0
  158. data/test/test_polygon_line.rb +167 -0
  159. data/test/test_polyline.rb +171 -0
  160. data/test/test_shader.rb +9 -9
  161. metadata +102 -70
  162. data/.doc/ext/rays/texture.cpp +0 -138
  163. data/ext/rays/texture.cpp +0 -149
  164. data/include/rays/ruby/texture.h +0 -41
  165. data/include/rays/texture.h +0 -71
  166. data/lib/rays/texture.rb +0 -24
  167. data/src/program.cpp +0 -648
  168. data/test/test_texture.rb +0 -27
@@ -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
@@ -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
@@ -1,4 +1,4 @@
1
- #include "rays/opengl.h"
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
- get_error ()
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
- check_error (const char* file, int line)
38
+ OpenGL_check_error (const char* file, int line)
51
39
  {
52
- GLenum e = get_error();
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
@@ -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
@@ -0,0 +1,21 @@
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_copy_pixels (Bitmap* bitmap, CGImageRef image);
16
+
17
+
18
+ }// Rays
19
+
20
+
21
+ #endif//EOH
@@ -1,12 +1,12 @@
1
1
  // -*- objc -*-
2
- #import "rays/bitmap.h"
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 "rays/texture.h"
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
- ? kCGImageAlphaPremultipliedFirst
30
- : kCGImageAlphaFirst;
29
+ ? kCGImageAlphaPremultipliedFirst
30
+ : kCGImageAlphaFirst;
31
31
  }
32
32
  else if (cs.is_alpha_last())
33
33
  {
34
34
  info |= cs.is_premult()
35
- ? kCGImageAlphaPremultipliedLast
36
- : kCGImageAlphaLast;
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 dirty;
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
- dirty = false;
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->dirty = true;
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,123 @@ namespace Rays
151
150
  if (!this_ || !tex)
152
151
  argument_error(__FILE__, __LINE__);
153
152
 
154
- setup_bitmap(this_, tex.width(), tex.height(), tex.color_space(), NULL, false);
153
+ setup_bitmap(
154
+ this_, tex.width(), tex.height(), tex.color_space(), NULL, false);
155
155
 
156
156
  GLenum format, type;
157
- tex.color_space().get_gl_enums(&format, &type, tex.alpha_only());
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
- glReadPixels(0, y, this_->width(), 1, format, type, (GLvoid*) this_->at<uchar>(0, y));
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_copy_pixels (Bitmap* bitmap, CGImageRef image)
179
+ {
180
+ if (!bitmap || !image)
181
+ argument_error(__FILE__, __LINE__);
182
+
183
+ CGContextRef context = bitmap->self->get_context();
184
+ if (!context)
185
+ rays_error(__FILE__, __LINE__, "getting CGContext failed.");
186
+
187
+ size_t width = CGImageGetWidth(image);
188
+ size_t height = CGImageGetHeight(image);
189
+ CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);
190
+
191
+ Bitmap_set_modified(bitmap);
192
+ }
193
+
194
+ void
195
+ Bitmap_draw_string (
196
+ Bitmap* bitmap, const RawFont& font, const char* str, coord x, coord y)
197
+ {
198
+ if (!bitmap || !*bitmap || !font || !str)
199
+ argument_error(__FILE__, __LINE__);
200
+
201
+ if (*str == '\0') return;
202
+
203
+ font.draw_string(bitmap->self->get_context(), bitmap->height(), str, x, y);
204
+
205
+ Bitmap_set_modified(bitmap);
206
+ }
207
+
208
+ void
209
+ Bitmap_set_modified (Bitmap* bitmap, bool modified)
210
+ {
211
+ assert(bitmap);
212
+
213
+ bitmap->self->modified = modified;
214
+ }
215
+
216
+ bool
217
+ Bitmap_get_modified (const Bitmap& bitmap)
218
+ {
219
+ return bitmap.self->modified;
220
+ }
221
+
222
+ void
223
+ Bitmap_save (const Bitmap& bmp, const char* path_)
224
+ {
225
+ std::shared_ptr<CGImage> img(bmp.self->get_image(), CGImageRelease);
226
+ if (!img)
227
+ rays_error(__FILE__, __LINE__, "getting CGImage failed.");
228
+
229
+ NSString* path = [NSString stringWithUTF8String: path_];
230
+ NSURL* url = [NSURL fileURLWithPath: path];
231
+ if (!url)
232
+ rays_error(__FILE__, __LINE__, "creating NSURL failed.");
233
+
234
+ std::shared_ptr<CGImageDestination> dest(
235
+ CGImageDestinationCreateWithURL((CFURLRef) url, kUTTypePNG, 1, NULL),
236
+ safe_cfrelease);
237
+ if (!dest)
238
+ rays_error(__FILE__, __LINE__, "CGImageDestinationCreateWithURL() failed.");
239
+
240
+ CGImageDestinationAddImage(dest.get(), img.get(), NULL);
241
+ if (!CGImageDestinationFinalize(dest.get()))
242
+ rays_error(__FILE__, __LINE__, "CGImageDestinationFinalize() failed.");
243
+ }
244
+
245
+ Bitmap
246
+ Bitmap_load (const char* path_)
247
+ {
248
+ if (!path_ || path_[0] == '\0')
249
+ argument_error(__FILE__, __LINE__);
250
+
251
+ NSString* path = [NSString stringWithUTF8String: path_];
252
+ NSBitmapImageRep* imagerep =
253
+ [NSBitmapImageRep imageRepWithContentsOfFile: path];
254
+ if (!imagerep)
255
+ rays_error(__FILE__, __LINE__, "[NSBitmapImageRep imageRepWithContentsOfFile] failed.");
256
+
257
+ CGImageRef image = [imagerep CGImage];
258
+ if (!image)
259
+ rays_error(__FILE__, __LINE__, "[imagerep CGImage] failed.");
260
+
261
+ size_t width = CGImageGetWidth(image);
262
+ size_t height = CGImageGetHeight(image);
263
+
264
+ Bitmap bmp((int) width, (int) height, RGBA);
265
+ if (!bmp)
266
+ rays_error(__FILE__, __LINE__, "invalid bitmap.");
267
+
268
+ Bitmap_copy_pixels(&bmp, image);
269
+ return bmp;
164
270
  }
165
271
 
166
272
 
@@ -174,17 +280,12 @@ namespace Rays
174
280
  setup_bitmap(this, width, height, color_space, pixels);
175
281
  }
176
282
 
177
- Bitmap::Bitmap (const Texture& texture)
178
- {
179
- setup_bitmap(this, texture);
180
- }
181
-
182
283
  Bitmap::~Bitmap ()
183
284
  {
184
285
  }
185
286
 
186
287
  Bitmap
187
- Bitmap::copy () const
288
+ Bitmap::dup () const
188
289
  {
189
290
  return Bitmap(width(), height(), color_space(), pixels());
190
291
  }
@@ -239,22 +340,13 @@ namespace Rays
239
340
  return const_cast<This*>(this)->pixels();
240
341
  }
241
342
 
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
343
  Bitmap::operator bool () const
255
344
  {
256
345
  return
257
- self->width > 0 && self->height > 0 && self->color_space && self->pixels;
346
+ self->width > 0 &&
347
+ self->height > 0 &&
348
+ self->color_space &&
349
+ self->pixels;
258
350
  }
259
351
 
260
352
  bool
@@ -264,77 +356,4 @@ namespace Rays
264
356
  }
265
357
 
266
358
 
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
359
  }// Rays