rays 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) 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/color.cpp +224 -45
  5. data/.doc/ext/rays/color_space.cpp +137 -45
  6. data/.doc/ext/rays/defs.cpp +183 -0
  7. data/.doc/ext/rays/font.cpp +39 -21
  8. data/.doc/ext/rays/image.cpp +26 -37
  9. data/.doc/ext/rays/matrix.cpp +186 -29
  10. data/.doc/ext/rays/native.cpp +12 -6
  11. data/.doc/ext/rays/noise.cpp +53 -0
  12. data/.doc/ext/rays/painter.cpp +120 -308
  13. data/.doc/ext/rays/point.cpp +82 -77
  14. data/.doc/ext/rays/polygon.cpp +287 -0
  15. data/.doc/ext/rays/polygon_line.cpp +96 -0
  16. data/.doc/ext/rays/polyline.cpp +161 -0
  17. data/.doc/ext/rays/rays.cpp +0 -13
  18. data/.doc/ext/rays/shader.cpp +83 -9
  19. data/README.md +1 -1
  20. data/Rakefile +21 -9
  21. data/VERSION +1 -1
  22. data/ext/rays/bitmap.cpp +22 -80
  23. data/ext/rays/bounds.cpp +100 -128
  24. data/ext/rays/color.cpp +232 -51
  25. data/ext/rays/color_space.cpp +140 -46
  26. data/ext/rays/defs.cpp +183 -0
  27. data/ext/rays/defs.h +26 -2
  28. data/ext/rays/extconf.rb +1 -2
  29. data/ext/rays/font.cpp +39 -22
  30. data/ext/rays/image.cpp +27 -39
  31. data/ext/rays/matrix.cpp +198 -30
  32. data/ext/rays/native.cpp +12 -6
  33. data/ext/rays/noise.cpp +55 -0
  34. data/ext/rays/painter.cpp +129 -315
  35. data/ext/rays/point.cpp +89 -81
  36. data/ext/rays/polygon.cpp +301 -0
  37. data/ext/rays/polygon_line.cpp +99 -0
  38. data/ext/rays/polyline.cpp +170 -0
  39. data/ext/rays/rays.cpp +0 -14
  40. data/ext/rays/shader.cpp +84 -9
  41. data/include/rays.h +10 -2
  42. data/include/rays/bitmap.h +14 -26
  43. data/include/rays/bounds.h +21 -4
  44. data/include/rays/color.h +25 -14
  45. data/include/rays/color_space.h +11 -8
  46. data/include/rays/coord.h +114 -0
  47. data/include/rays/debug.h +22 -0
  48. data/include/rays/defs.h +3 -0
  49. data/include/rays/font.h +4 -4
  50. data/include/rays/image.h +11 -17
  51. data/include/rays/matrix.h +50 -24
  52. data/include/rays/noise.h +42 -0
  53. data/include/rays/opengl.h +2 -50
  54. data/include/rays/painter.h +57 -99
  55. data/include/rays/point.h +44 -51
  56. data/include/rays/polygon.h +164 -0
  57. data/include/rays/polyline.h +65 -0
  58. data/include/rays/rays.h +3 -0
  59. data/include/rays/ruby.h +7 -1
  60. data/include/rays/ruby/bounds.h +1 -1
  61. data/include/rays/ruby/color.h +1 -1
  62. data/include/rays/ruby/color_space.h +1 -1
  63. data/include/rays/ruby/font.h +1 -1
  64. data/include/rays/ruby/matrix.h +1 -1
  65. data/include/rays/ruby/point.h +1 -1
  66. data/include/rays/ruby/polygon.h +52 -0
  67. data/include/rays/ruby/polyline.h +41 -0
  68. data/include/rays/ruby/shader.h +1 -1
  69. data/include/rays/shader.h +36 -8
  70. data/lib/rays.rb +6 -1
  71. data/lib/rays/bitmap.rb +0 -15
  72. data/lib/rays/bounds.rb +17 -23
  73. data/lib/rays/color.rb +20 -47
  74. data/lib/rays/color_space.rb +13 -13
  75. data/lib/rays/image.rb +2 -6
  76. data/lib/rays/matrix.rb +28 -0
  77. data/lib/rays/module.rb +4 -19
  78. data/lib/rays/painter.rb +60 -97
  79. data/lib/rays/point.rb +13 -21
  80. data/lib/rays/polygon.rb +50 -0
  81. data/lib/rays/polygon_line.rb +36 -0
  82. data/lib/rays/polyline.rb +32 -0
  83. data/lib/rays/shader.rb +20 -1
  84. data/rays.gemspec +5 -7
  85. data/src/bitmap.h +36 -0
  86. data/src/bounds.cpp +74 -11
  87. data/src/color.cpp +58 -23
  88. data/src/color_space.cpp +50 -32
  89. data/src/color_space.h +22 -0
  90. data/src/coord.cpp +170 -0
  91. data/src/coord.h +35 -0
  92. data/src/font.cpp +118 -0
  93. data/src/font.h +64 -0
  94. data/src/frame_buffer.cpp +37 -71
  95. data/src/frame_buffer.h +4 -4
  96. data/src/image.cpp +171 -97
  97. data/src/image.h +25 -0
  98. data/src/ios/bitmap.mm +107 -105
  99. data/src/ios/font.mm +48 -60
  100. data/src/ios/helper.h +2 -2
  101. data/src/ios/opengl.mm +19 -4
  102. data/src/ios/rays.mm +3 -0
  103. data/src/matrix.cpp +111 -26
  104. data/src/matrix.h +30 -0
  105. data/src/noise.cpp +74 -0
  106. data/src/opengl.cpp +9 -27
  107. data/src/opengl.h +37 -0
  108. data/src/osx/bitmap.mm +111 -106
  109. data/src/osx/font.mm +48 -61
  110. data/src/osx/helper.h +2 -2
  111. data/src/osx/opengl.mm +19 -83
  112. data/src/osx/rays.mm +3 -0
  113. data/src/painter.cpp +780 -696
  114. data/src/painter.h +24 -0
  115. data/src/point.cpp +140 -119
  116. data/src/polygon.cpp +1100 -0
  117. data/src/polygon.h +32 -0
  118. data/src/polyline.cpp +158 -0
  119. data/src/polyline.h +67 -0
  120. data/src/render_buffer.cpp +11 -4
  121. data/src/render_buffer.h +2 -2
  122. data/src/shader.cpp +163 -106
  123. data/src/shader.h +38 -0
  124. data/src/shader_program.cpp +533 -0
  125. data/src/{program.h → shader_program.h} +28 -16
  126. data/src/shader_source.cpp +140 -0
  127. data/src/shader_source.h +52 -0
  128. data/src/texture.cpp +136 -160
  129. data/src/texture.h +65 -0
  130. data/src/win32/bitmap.cpp +62 -52
  131. data/src/win32/font.cpp +11 -13
  132. data/src/win32/font.h +24 -0
  133. data/src/win32/gdi.h +6 -6
  134. data/test/helper.rb +0 -3
  135. data/test/test_bitmap.rb +31 -7
  136. data/test/test_bounds.rb +36 -0
  137. data/test/test_color.rb +59 -19
  138. data/test/test_color_space.rb +95 -0
  139. data/test/test_image.rb +24 -20
  140. data/test/test_matrix.rb +106 -0
  141. data/test/test_painter.rb +92 -46
  142. data/test/test_painter_shape.rb +57 -0
  143. data/test/test_point.rb +21 -0
  144. data/test/test_polygon.rb +234 -0
  145. data/test/test_polygon_line.rb +167 -0
  146. data/test/test_polyline.rb +145 -0
  147. data/test/test_shader.rb +9 -9
  148. metadata +88 -67
  149. data/.doc/ext/rays/texture.cpp +0 -138
  150. data/ext/rays/texture.cpp +0 -149
  151. data/include/rays/ruby/texture.h +0 -41
  152. data/include/rays/texture.h +0 -71
  153. data/lib/rays/texture.rb +0 -24
  154. data/src/program.cpp +0 -648
  155. data/test/test_texture.rb +0 -27
@@ -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
 
@@ -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
@@ -17,7 +16,9 @@ namespace Rays
17
16
 
18
17
  COLORSPACE_UNKNOWN = Xot::UNKNOWN,
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
 
@@ -29,13 +30,15 @@ namespace Rays
29
30
 
30
31
  COLORSPACE_LAST,
31
32
 
32
- GRAY = GRAY_8,
33
+ GRAY = GRAY_8,
34
+
35
+ ALPHA = ALPHA_8,
33
36
 
34
- RGB = RGB_888, BGR = BGR_888,
37
+ RGB = RGB_888, BGR = BGR_888,
35
38
 
36
- RGBA = RGBA_8888, RGBX = RGBX_8888, ARGB = ARGB_8888, XRGB = XRGB_8888,
39
+ RGBA = RGBA_8888, RGBX = RGBX_8888, ARGB = ARGB_8888, XRGB = XRGB_8888,
37
40
 
38
- BGRA = BGRA_8888, BGRX = BGRX_8888, ABGR = ABGR_8888, XBGR = XBGR_8888,
41
+ BGRA = BGRA_8888, BGRX = BGRX_8888, ABGR = ABGR_8888, XBGR = XBGR_8888,
39
42
 
40
43
  };// ColorSpaceType
41
44
 
@@ -63,6 +66,8 @@ namespace Rays
63
66
 
64
67
  bool is_gray () const;
65
68
 
69
+ bool is_alpha () const;
70
+
66
71
  bool is_rgb () const;
67
72
 
68
73
  bool is_bgr () const;
@@ -83,8 +88,6 @@ namespace Rays
83
88
 
84
89
  bool is_premult () const;
85
90
 
86
- void get_gl_enums (GLenum* format, GLenum* type, bool alpha_only) const;
87
-
88
91
  operator bool () const;
89
92
 
90
93
  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
@@ -0,0 +1,22 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_DEBUG_H__
4
+ #define __RAYS_DEBUG_H__
5
+
6
+
7
+ #include <xot/debug.h>
8
+
9
+
10
+ namespace Rays
11
+ {
12
+
13
+
14
+ using Xot::dout;
15
+
16
+ using Xot::doutln;
17
+
18
+
19
+ }// Rays
20
+
21
+
22
+ #endif//EOH
@@ -4,6 +4,9 @@
4
4
  #define __RAYS_DEFS_H__
5
5
 
6
6
 
7
+ #define GLM_FORCE_CXX03
8
+
9
+
7
10
  #include <xot/defs.h>
8
11
  #include <xot/string.h>
9
12
 
@@ -23,8 +23,6 @@ namespace Rays
23
23
 
24
24
  ~Font ();
25
25
 
26
- Font copy () const;
27
-
28
26
  String name () const;
29
27
 
30
28
  coord size () const;
@@ -32,7 +30,9 @@ namespace Rays
32
30
  coord get_width (const char* str) const;
33
31
 
34
32
  coord get_height (
35
- coord* ascent = NULL, coord* descent = NULL, coord* leading = NULL) const;
33
+ coord* ascent = NULL,
34
+ coord* descent = NULL,
35
+ coord* leading = NULL) const;
36
36
 
37
37
  operator bool () const;
38
38
 
@@ -40,7 +40,7 @@ namespace Rays
40
40
 
41
41
  struct Data;
42
42
 
43
- Xot::PImpl<Data, true> self;
43
+ Xot::PSharedImpl<Data> self;
44
44
 
45
45
  };// Font
46
46
 
@@ -15,8 +15,6 @@ namespace Rays
15
15
 
16
16
  class Bitmap;
17
17
 
18
- class Texture;
19
-
20
18
 
21
19
  class Image
22
20
  {
@@ -29,47 +27,43 @@ namespace Rays
29
27
 
30
28
  Image (
31
29
  int width, int height, const ColorSpace& cs = RGBA,
32
- bool alpha_only = false);
30
+ float pixel_density = 1);
33
31
 
34
- Image (const Bitmap& bitmap, bool alpha_only = false);
32
+ Image (const Bitmap& bitmap, float pixel_density = 1);
35
33
 
36
34
  ~Image ();
37
35
 
38
- Image copy () const;
39
-
40
- Painter painter ();
36
+ Image dup () const;
41
37
 
42
- int width () const;
38
+ coord width () const;
43
39
 
44
- int height () const;
40
+ coord height () const;
45
41
 
46
42
  const ColorSpace& color_space () const;
47
43
 
48
- bool alpha_only () const;
44
+ float pixel_density () const;
45
+
46
+ Painter painter ();
49
47
 
50
48
  Bitmap& bitmap ();
51
49
 
52
50
  const Bitmap& bitmap () const;
53
51
 
54
- Texture& texture ();
55
-
56
- const Texture& texture () const;
57
-
58
52
  operator bool () const;
59
53
 
60
54
  bool operator ! () const;
61
55
 
62
56
  struct Data;
63
57
 
64
- Xot::PImpl<Data, true> self;
58
+ Xot::PSharedImpl<Data> self;
65
59
 
66
60
  };// Image
67
61
 
68
62
 
69
- Image load_image (const char* path, bool alphatexture = false);
70
-
71
63
  void save_image (const Image& image, const char* path);
72
64
 
65
+ Image load_image (const char* path);
66
+
73
67
 
74
68
  }// Rays
75
69