rays 0.1.12 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
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 +171 -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 +23 -81
  25. data/ext/rays/bounds.cpp +100 -128
  26. data/ext/rays/camera.cpp +186 -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 +74 -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 +24 -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 +23 -0
  107. data/src/ios/bitmap.mm +133 -110
  108. data/src/ios/camera.mm +510 -0
  109. data/src/ios/font.mm +50 -62
  110. data/src/ios/helper.h +4 -4
  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 +23 -0
  119. data/src/osx/bitmap.mm +133 -110
  120. data/src/osx/camera.mm +451 -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
@@ -7,15 +7,23 @@
7
7
  #include <rays/defs.h>
8
8
  #include <rays/rays.h>
9
9
  #include <rays/exception.h>
10
+ #include <rays/debug.h>
11
+
12
+ #include <rays/coord.h>
10
13
  #include <rays/point.h>
14
+ #include <rays/bounds.h>
15
+ #include <rays/color.h>
11
16
  #include <rays/color_space.h>
17
+ #include <rays/matrix.h>
18
+
19
+ #include <rays/polyline.h>
20
+ #include <rays/polygon.h>
12
21
  #include <rays/bitmap.h>
13
- #include <rays/texture.h>
14
22
  #include <rays/image.h>
15
23
  #include <rays/font.h>
16
24
  #include <rays/shader.h>
25
+
17
26
  #include <rays/painter.h>
18
- #include <rays/opengl.h>
19
27
 
20
28
 
21
29
  #endif//EOH
@@ -14,9 +14,6 @@ namespace Rays
14
14
  {
15
15
 
16
16
 
17
- class Texture;
18
-
19
-
20
17
  class Bitmap
21
18
  {
22
19
 
@@ -30,11 +27,9 @@ namespace Rays
30
27
  int width, int height, const ColorSpace& cs = RGBA,
31
28
  const void* pixels = NULL);
32
29
 
33
- Bitmap (const Texture& texture);
34
-
35
30
  ~Bitmap ();
36
31
 
37
- Bitmap copy () const;
32
+ Bitmap dup () const;
38
33
 
39
34
  int width () const;
40
35
 
@@ -50,19 +45,9 @@ namespace Rays
50
45
 
51
46
  const void* pixels () const;
52
47
 
53
- template <typename T> T* at (int x, int y)
54
- {
55
- return (T*) (((char*) pixels()) + pitch() * y + x * color_space().Bpp());
56
- }
57
-
58
- template <typename T> const T* at (int x, int y) const
59
- {
60
- return const_cast<This*>(this)->at<T>(x, y);
61
- }
62
-
63
- bool dirty () const;
48
+ template <typename T> T* at (int x, int y);
64
49
 
65
- void set_dirty (bool b = true);
50
+ template <typename T> const T* at (int x, int y) const;
66
51
 
67
52
  operator bool () const;
68
53
 
@@ -70,19 +55,22 @@ namespace Rays
70
55
 
71
56
  struct Data;
72
57
 
73
- Xot::PImpl<Data, true> self;
58
+ Xot::PSharedImpl<Data> self;
74
59
 
75
60
  };// Bitmap
76
61
 
77
62
 
78
- Bitmap load_bitmap (const char* path);
79
-
80
- void save_bitmap (const Bitmap& bitmap, const char* path);
81
-
63
+ template <typename T> T*
64
+ Bitmap::at (int x, int y)
65
+ {
66
+ return (T*) (((char*) pixels()) + pitch() * y + x * color_space().Bpp());
67
+ }
82
68
 
83
- void draw_string (
84
- Bitmap* bitmap, const char* str,
85
- coord x = 0, coord y = 0, const Font& font = default_font());
69
+ template <typename T> const T*
70
+ Bitmap::at (int x, int y) const
71
+ {
72
+ return const_cast<This*>(this)->at<T>(x, y);
73
+ }
86
74
 
87
75
 
88
76
  }// Rays
@@ -107,20 +107,28 @@ namespace Rays
107
107
 
108
108
  coord front () const;
109
109
 
110
- void set_center (coord x, coord y, coord z = 0);
111
-
112
- void set_center (const Point& point);
110
+ void set_position (coord x, coord y, coord z = 0);
113
111
 
114
- Point center () const;
112
+ void set_position (const Point& position);
115
113
 
116
114
  Point& position ();
117
115
 
118
116
  const Point& position () const;
119
117
 
118
+ void set_size (coord width, coord height, coord depth = 0);
119
+
120
+ void set_size (const Point& size);
121
+
120
122
  Point& size ();
121
123
 
122
124
  const Point& size () const;
123
125
 
126
+ void set_center (coord x, coord y, coord z = 0);
127
+
128
+ void set_center (const Point& center);
129
+
130
+ Point center () const;
131
+
124
132
  String inspect () const;
125
133
 
126
134
  Point& operator [] (size_t index);
@@ -135,6 +143,8 @@ namespace Rays
135
143
 
136
144
  Bounds& operator |= (const Bounds& rhs);
137
145
 
146
+ Bounds& operator |= (const Point& rhs);
147
+
138
148
  friend bool operator == (const Bounds& lhs, const Bounds& rhs);
139
149
 
140
150
  friend bool operator != (const Bounds& lhs, const Bounds& rhs);
@@ -143,9 +153,16 @@ namespace Rays
143
153
 
144
154
  friend Bounds operator | (const Bounds& lhs, const Bounds& rhs);
145
155
 
156
+ friend Bounds operator | (const Bounds& lhs, const Point& rhs);
157
+
158
+ friend Bounds operator | (const Point& lhs, const Bounds& rhs);
159
+
146
160
  };// Bounds
147
161
 
148
162
 
163
+ Bounds invalid_bounds ();
164
+
165
+
149
166
  }// Rays
150
167
 
151
168
 
@@ -0,0 +1,74 @@
1
+ // -*- mode: c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_CAMERA_H__
4
+ #define __RAYS_CAMERA_H__
5
+
6
+
7
+ #include <vector>
8
+ #include <xot/pimpl.h>
9
+ #include <rays/defs.h>
10
+ #include <rays/image.h>
11
+
12
+
13
+ namespace Rays
14
+ {
15
+
16
+
17
+ class Camera
18
+ {
19
+
20
+ typedef Camera This;
21
+
22
+ public:
23
+
24
+ Camera (
25
+ const char* device_name = NULL,
26
+ int min_width = -1,
27
+ int min_height = -1,
28
+ bool resize = true,
29
+ bool crop = true);
30
+
31
+ ~Camera ();
32
+
33
+ bool start ();
34
+
35
+ void stop ();
36
+
37
+ bool is_active () const;
38
+
39
+ void set_min_width (int width);
40
+
41
+ int min_width () const;
42
+
43
+ void set_min_height (int height);
44
+
45
+ int min_height () const;
46
+
47
+ void set_resize (bool resize = true);
48
+
49
+ bool is_resize () const;
50
+
51
+ void set_crop (bool crop = true);
52
+
53
+ bool is_crop () const;
54
+
55
+ const Image* image () const;
56
+
57
+ operator bool () const;
58
+
59
+ bool operator ! () const;
60
+
61
+ struct Data;
62
+
63
+ Xot::PSharedImpl<Data> self;
64
+
65
+ };// Camera
66
+
67
+
68
+ std::vector<String> get_camera_device_names ();
69
+
70
+
71
+ }// Rays
72
+
73
+
74
+ #endif//EOH
@@ -6,7 +6,7 @@
6
6
 
7
7
  #include <xot/util.h>
8
8
  #include <rays/defs.h>
9
- #include <rays/point.h>
9
+ #include <rays/coord.h>
10
10
 
11
11
 
12
12
  namespace Rays
@@ -16,17 +16,12 @@ namespace Rays
16
16
  class ColorSpace;
17
17
 
18
18
 
19
- struct Color
19
+ struct Color : public Coord4
20
20
  {
21
21
 
22
22
  typedef Color This;
23
23
 
24
- union
25
- {
26
- struct {float red, green, blue, alpha;};
27
- struct {float r, g, b, a;};
28
- float array[4];
29
- };
24
+ typedef Coord4 Super;
30
25
 
31
26
  Color (float gray = 0, float alpha = 1);
32
27
 
@@ -40,9 +35,9 @@ namespace Rays
40
35
 
41
36
  Color& reset (float red, float green, float blue, float alpha = 1);
42
37
 
43
- Color& reset8 (uchar gray = 0, uchar alpha = 255);
38
+ Color& reset8 (int gray = 0, int alpha = 255);
44
39
 
45
- Color& reset8 (uchar red, uchar green, uchar blue, uchar alpha = 255);
40
+ Color& reset8 (int red, int green, int blue, int alpha = 255);
46
41
 
47
42
  Color& reset (const void* pixel, const ColorSpace& cs);
48
43
 
@@ -52,16 +47,32 @@ namespace Rays
52
47
 
53
48
  bool operator ! () const;
54
49
 
55
- static uchar float2uchar (float value) {return (uchar) Xot::clip(0.f, 255.f, value * 255);}
50
+ friend bool operator == (const This& lhs, const This& rhs);
51
+
52
+ friend bool operator != (const This& lhs, const This& rhs);
53
+
54
+ static uchar float2uchar (float value)
55
+ {
56
+ return (uchar) Xot::clip(0.f, 255.f, value * 255);
57
+ }
56
58
 
57
- static float uchar2float (uchar value) {return value / 255.f;}
59
+ static float uchar2float (int value)
60
+ {
61
+ return value / 255.f;
62
+ }
58
63
 
59
64
  };// Color
60
65
 
61
66
 
62
- Color Color8 (uchar gray = 0, uchar alpha = 255);
67
+ Color gray (float gray, float alpha = 1);
68
+
69
+ Color gray8 (int gray, int alpha = 255);
70
+
71
+ Color rgb (float red, float green, float blue, float alpha = 1);
72
+
73
+ Color rgb8 (int red, int green, int blue, int alpha = 255);
63
74
 
64
- Color Color8 (uchar red, uchar green, uchar blue, uchar alpha = 255);
75
+ Color hsv (float hue, float saturation, float value, float alpha = 1);
65
76
 
66
77
 
67
78
  }// Rays
@@ -5,7 +5,6 @@
5
5
 
6
6
 
7
7
  #include <rays/defs.h>
8
- #include <rays/opengl.h>
9
8
 
10
9
 
11
10
  namespace Rays
@@ -15,9 +14,11 @@ namespace Rays
15
14
  enum ColorSpaceType
16
15
  {
17
16
 
18
- COLORSPACE_UNKNOWN = Xot::UNKNOWN,
17
+ COLORSPACE_UNKNOWN = 0,
19
18
 
20
- GRAY_8, GRAY_16, GRAY_24, GRAY_32, GRAY_float,
19
+ GRAY_8, GRAY_16, GRAY_24, GRAY_32, GRAY_float,
20
+
21
+ ALPHA_8, ALPHA_16, ALPHA_24, ALPHA_32, ALPHA_float,
21
22
 
22
23
  RGB_888, RGBA_8888, RGBX_8888, ARGB_8888, XRGB_8888,
23
24
 
@@ -27,15 +28,19 @@ namespace Rays
27
28
 
28
29
  BGR_float, BGRA_float, ABGR_float,
29
30
 
30
- COLORSPACE_LAST,
31
+ COLORSPACE_MAX,
32
+
33
+ GRAY = GRAY_8,
34
+
35
+ ALPHA = ALPHA_8,
31
36
 
32
- GRAY = GRAY_8,
37
+ RGB = RGB_888, BGR = BGR_888,
33
38
 
34
- RGB = RGB_888, BGR = BGR_888,
39
+ RGBA = RGBA_8888, RGBX = RGBX_8888, ARGB = ARGB_8888, XRGB = XRGB_8888,
35
40
 
36
- RGBA = RGBA_8888, RGBX = RGBX_8888, ARGB = ARGB_8888, XRGB = XRGB_8888,
41
+ BGRA = BGRA_8888, BGRX = BGRX_8888, ABGR = ABGR_8888, XBGR = XBGR_8888,
37
42
 
38
- BGRA = BGRA_8888, BGRX = BGRX_8888, ABGR = ABGR_8888, XBGR = XBGR_8888,
43
+ DEFAULT_COLOR_SPACE = RGBA
39
44
 
40
45
  };// ColorSpaceType
41
46
 
@@ -63,6 +68,8 @@ namespace Rays
63
68
 
64
69
  bool is_gray () const;
65
70
 
71
+ bool is_alpha () const;
72
+
66
73
  bool is_rgb () const;
67
74
 
68
75
  bool is_bgr () const;
@@ -83,8 +90,6 @@ namespace Rays
83
90
 
84
91
  bool is_premult () const;
85
92
 
86
- void get_gl_enums (GLenum* format, GLenum* type, bool alpha_only) const;
87
-
88
93
  operator bool () const;
89
94
 
90
95
  bool operator ! () const;
@@ -0,0 +1,114 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_COORD_H__
4
+ #define __RAYS_COORD_H__
5
+
6
+
7
+ #include <rays/defs.h>
8
+
9
+
10
+ namespace Rays
11
+ {
12
+
13
+
14
+ struct Coord2
15
+ {
16
+
17
+ typedef Coord2 This;
18
+
19
+ enum {SIZE = 2};
20
+
21
+ union
22
+ {
23
+ struct {coord x, y;};
24
+ struct {coord s, t;};
25
+ coord array[SIZE];
26
+ };
27
+
28
+ Coord2& reset (coord value = 0);
29
+
30
+ Coord2& reset (coord x, coord y);
31
+
32
+ size_t size () const;
33
+
34
+ String inspect () const;
35
+
36
+ coord& operator [] (size_t index);
37
+
38
+ const coord& operator [] (size_t index) const;
39
+
40
+ };// Coord2
41
+
42
+
43
+ struct Coord3
44
+ {
45
+
46
+ typedef Coord3 This;
47
+
48
+ enum {SIZE = 3};
49
+
50
+ union
51
+ {
52
+ struct {coord x, y, z;};
53
+ struct {coord s, t, p;};
54
+ struct {coord r, g, b;};
55
+ struct {coord red, green, blue;};
56
+ coord array[SIZE];
57
+ };
58
+
59
+ This& operator = (const Coord2& rhs);
60
+
61
+ Coord3& reset (coord value = 0);
62
+
63
+ Coord3& reset (coord x, coord y, coord z = 0);
64
+
65
+ size_t size () const;
66
+
67
+ String inspect () const;
68
+
69
+ coord& operator [] (size_t index);
70
+
71
+ const coord& operator [] (size_t index) const;
72
+
73
+ };// Coord3
74
+
75
+
76
+ struct Coord4
77
+ {
78
+
79
+ typedef Coord4 This;
80
+
81
+ enum {SIZE = 4};
82
+
83
+ union
84
+ {
85
+ struct {coord x, y, z, w;};
86
+ struct {coord s, t, p, q;};
87
+ struct {coord r, g, b, a;};
88
+ struct {coord red, green, blue, alpha;};
89
+ coord array[SIZE];
90
+ };
91
+
92
+ This& operator = (const Coord2& rhs);
93
+
94
+ This& operator = (const Coord3& rhs);
95
+
96
+ Coord4& reset (coord value = 0);
97
+
98
+ Coord4& reset (coord x, coord y, coord z = 0, coord w = 1);
99
+
100
+ size_t size () const;
101
+
102
+ String inspect () const;
103
+
104
+ coord& operator [] (size_t index);
105
+
106
+ const coord& operator [] (size_t index) const;
107
+
108
+ };// Coord4
109
+
110
+
111
+ }// Rays
112
+
113
+
114
+ #endif//EOH