rays 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/ChangeLog +8 -0
  2. data/README +4 -0
  3. data/Rakefile +72 -0
  4. data/VERSION +1 -0
  5. data/ext/rays/bitmap.cpp +322 -0
  6. data/ext/rays/extconf.rb +61 -0
  7. data/ext/rays/font.cpp +125 -0
  8. data/ext/rays/image.cpp +166 -0
  9. data/ext/rays/native.cpp +24 -0
  10. data/ext/rays/painter.cpp +573 -0
  11. data/ext/rays/rays.cpp +61 -0
  12. data/ext/rays/rays.h +39 -0
  13. data/ext/rays/texture.cpp +130 -0
  14. data/include/rays.h +20 -0
  15. data/include/rays/bitmap.h +80 -0
  16. data/include/rays/colorspace.h +101 -0
  17. data/include/rays/defs.h +33 -0
  18. data/include/rays/font.h +49 -0
  19. data/include/rays/helpers.h +37 -0
  20. data/include/rays/image.h +68 -0
  21. data/include/rays/opengl.h +15 -0
  22. data/include/rays/painter.h +179 -0
  23. data/include/rays/rays.h +19 -0
  24. data/include/rays/ruby.h +15 -0
  25. data/include/rays/ruby/bitmap.h +39 -0
  26. data/include/rays/ruby/font.h +39 -0
  27. data/include/rays/ruby/image.h +39 -0
  28. data/include/rays/ruby/painter.h +39 -0
  29. data/include/rays/ruby/rays.h +21 -0
  30. data/include/rays/ruby/texture.h +39 -0
  31. data/include/rays/texture.h +56 -0
  32. data/include/rays/transform.h +35 -0
  33. data/lib/rays.rb +9 -0
  34. data/lib/rays/autoinit.rb +10 -0
  35. data/lib/rays/bitmap.rb +25 -0
  36. data/lib/rays/image.rb +15 -0
  37. data/lib/rays/module.rb +30 -0
  38. data/lib/rays/painter.rb +99 -0
  39. data/lib/rays/texture.rb +15 -0
  40. data/rays.gemspec +54 -0
  41. data/src/cocoa/bitmap.mm +286 -0
  42. data/src/cocoa/font.mm +193 -0
  43. data/src/cocoa/helpers.h +26 -0
  44. data/src/cocoa/helpers.mm +25 -0
  45. data/src/cocoa/rays.mm +40 -0
  46. data/src/colorspace.cpp +183 -0
  47. data/src/helpers.cpp +22 -0
  48. data/src/image.cpp +133 -0
  49. data/src/painter.cpp +769 -0
  50. data/src/texture.cpp +360 -0
  51. data/src/transform.cpp +88 -0
  52. data/src/win32/bitmap.cpp +212 -0
  53. data/src/win32/font.cpp +99 -0
  54. data/src/win32/gdi.cpp +771 -0
  55. data/src/win32/gdi.h +226 -0
  56. data/src/win32/rays.cpp +36 -0
  57. data/support.rb +58 -0
  58. data/task/ext.rake +41 -0
  59. data/task/gem.rake +33 -0
  60. data/task/git.rake +22 -0
  61. data/task/lib.rake +54 -0
  62. data/test/helpers.rb +15 -0
  63. data/test/test_painter.rb +11 -0
  64. data/test/test_rays.rb +19 -0
  65. data/test/test_texture.rb +11 -0
  66. metadata +153 -0
data/ext/rays/rays.cpp ADDED
@@ -0,0 +1,61 @@
1
+ #include <rucy.h>
2
+ #include <rays/rays.h>
3
+ #include "rays.h"
4
+
5
+
6
+ using namespace Rucy;
7
+
8
+
9
+ namespace Rays
10
+ {
11
+
12
+
13
+ Module
14
+ rays_module ()
15
+ {
16
+ static Module m = define_module("Rays");
17
+ return m;
18
+ }
19
+
20
+ Class
21
+ rays_error_class ()
22
+ {
23
+ static Class c =
24
+ rays_module().define_class("RaysError", native_error_class());
25
+ return c;
26
+ }
27
+
28
+
29
+ }// Rays
30
+
31
+
32
+ static
33
+ RUBY_DEF0(init)
34
+ {
35
+ if (!Rays::init())
36
+ error("Rays::init() failed.");
37
+
38
+ return self;
39
+ }
40
+ RUBY_END
41
+
42
+ static
43
+ RUBY_DEF0(fin)
44
+ {
45
+ if (!Rays::fin())
46
+ error("Rays::fin() failed.");
47
+
48
+ return self;
49
+ }
50
+ RUBY_END
51
+
52
+
53
+ void
54
+ Init_rays ()
55
+ {
56
+ Rays::rays_error_class();
57
+
58
+ Rays::rays_module()
59
+ .define_singleton_method("init!", init)
60
+ .define_singleton_method("fin!", fin);
61
+ }
data/ext/rays/rays.h ADDED
@@ -0,0 +1,39 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_EXT_RAYS_H__
4
+ #define __RAYS_EXT_RAYS_H__
5
+
6
+
7
+ #include <rucy/class.h>
8
+ #include "rays/ruby/rays.h"
9
+
10
+
11
+ namespace Rays
12
+ {
13
+
14
+
15
+ Rucy::Class rays_error_class ();
16
+ // class Rays::RaysError < Rucy::NativeError
17
+
18
+
19
+ }// Rays
20
+
21
+
22
+ #define CHECK_OBJ(obj, type, klass) \
23
+ do \
24
+ { \
25
+ type* p = Rucy::get_type<type>(obj, klass); \
26
+ if (!p) Rucy::invalid_object_error(); \
27
+ } \
28
+ while(0)
29
+
30
+ #define CHECK_OBJECT(obj, type, klass) \
31
+ do \
32
+ { \
33
+ type* p = Rucy::get_type<type>(obj, klass); \
34
+ if (!p || !*p) Rucy::invalid_object_error(); \
35
+ } \
36
+ while(0)
37
+
38
+
39
+ #endif//EOH
@@ -0,0 +1,130 @@
1
+ #include "rays/ruby/texture.h"
2
+
3
+
4
+ #include <rucy.h>
5
+ #include "rays.h"
6
+ #include "rays/ruby/bitmap.h"
7
+
8
+
9
+ using namespace Rucy;
10
+
11
+ using Rays::coord;
12
+
13
+
14
+ namespace Rays
15
+ {
16
+
17
+
18
+ Class
19
+ texture_class ()
20
+ {
21
+ static Class c = rays_module().define_class("Texture");
22
+ return c;
23
+ }
24
+
25
+
26
+ }// Rays
27
+
28
+
29
+ namespace Rucy
30
+ {
31
+
32
+
33
+ Value
34
+ value (const Rays::Texture& texture)
35
+ {
36
+ return new_type<Rays::Texture>(
37
+ Rays::texture_class(), new Rays::Texture(texture));
38
+ }
39
+
40
+
41
+ }// Rucy
42
+
43
+
44
+ #define this to<Rays::Texture*>(self)
45
+
46
+ #define CHECK CHECK_OBJECT(self, Rays::Texture, Rays::texture_class())
47
+
48
+
49
+ static
50
+ RUBY_DEF_ALLOC(alloc, klass)
51
+ {
52
+ return new_type<Rays::Texture>(klass, new Rays::Texture);
53
+ }
54
+ RUBY_END
55
+
56
+ static
57
+ RUBY_DEFN(initialize)
58
+ {
59
+ CHECK_OBJ(self, Rays::Texture, Rays::texture_class());
60
+ if (argc != 1 && argc != 2) arg_count_error("Texture#initialize", argc, 1, 2);
61
+
62
+ Rays::Bitmap* bitmap = to<Rays::Bitmap*>(argv[0]);
63
+ bool alphaonly = (argc == 2) ? to<bool>(argv[1]) : false;
64
+
65
+ if (!bitmap)
66
+ argument_error("%s is not a Bitmap object.", argv[0].inspect().c_str());
67
+
68
+ *this = Rays::Texture(*bitmap, alphaonly);
69
+ return self;
70
+ }
71
+ RUBY_END
72
+
73
+ static
74
+ RUBY_DEF0(width)
75
+ {
76
+ CHECK;
77
+
78
+ return value(this->width());
79
+ }
80
+ RUBY_END
81
+
82
+ static
83
+ RUBY_DEF0(height)
84
+ {
85
+ CHECK;
86
+
87
+ return value(this->height());
88
+ }
89
+ RUBY_END
90
+
91
+ static
92
+ RUBY_DEF0(s_max)
93
+ {
94
+ CHECK;
95
+
96
+ return value(this->s_max());
97
+ }
98
+ RUBY_END
99
+
100
+ static
101
+ RUBY_DEF0(t_max)
102
+ {
103
+ CHECK;
104
+
105
+ return value(this->t_max());
106
+ }
107
+ RUBY_END
108
+
109
+ static
110
+ RUBY_DEF0(bitmap)
111
+ {
112
+ CHECK;
113
+
114
+ return value(this->bitmap());
115
+ }
116
+ RUBY_END
117
+
118
+
119
+ void
120
+ Init_texture ()
121
+ {
122
+ Rays::texture_class()
123
+ .define_alloc_func(alloc)
124
+ .define_method("initialize", initialize)
125
+ .define_method("width", width)
126
+ .define_method("height", height)
127
+ .define_method("s_max", s_max)
128
+ .define_method("t_max", t_max)
129
+ .define_method("bitmap", bitmap);
130
+ }
data/include/rays.h ADDED
@@ -0,0 +1,20 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_H__
4
+ #define __RAYS_H__
5
+
6
+
7
+ #include <rays/defs.h>
8
+ #include <rays/rays.h>
9
+ #include <rays/colorspace.h>
10
+ #include <rays/bitmap.h>
11
+ #include <rays/texture.h>
12
+ #include <rays/image.h>
13
+ #include <rays/font.h>
14
+ #include <rays/transform.h>
15
+ #include <rays/painter.h>
16
+ #include <rays/helpers.h>
17
+ #include <rays/opengl.h>
18
+
19
+
20
+ #endif//EOH
@@ -0,0 +1,80 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_BITMAP_H__
4
+ #define __RAYS_BITMAP_H__
5
+
6
+
7
+ #include <rays/defs.h>
8
+ #include <rays/colorspace.h>
9
+ #include <rays/font.h>
10
+ #include <rays/helpers.h>
11
+
12
+
13
+ namespace Rays
14
+ {
15
+
16
+
17
+ class Bitmap
18
+ {
19
+
20
+ public:
21
+
22
+ Bitmap ();
23
+
24
+ Bitmap (int width, int height, const ColorSpace& cs = RGBA);
25
+
26
+ ~Bitmap ();
27
+
28
+ int width () const;
29
+
30
+ int height () const;
31
+
32
+ const ColorSpace& color_space () const;
33
+
34
+ int pitch () const;
35
+
36
+ size_t size () const;
37
+
38
+ bool dirty () const;
39
+
40
+ void set_dirty (bool b = true);
41
+
42
+ void* data ();
43
+
44
+ const void* data () const;
45
+
46
+ template <typename T> T* at (int x, int y)
47
+ {
48
+ return (T*) (((char*) data()) + pitch() * y + x * color_space().Bpp());
49
+ }
50
+
51
+ template <typename T> const T* at (int x, int y) const
52
+ {
53
+ return const_cast<Bitmap*>(this)->at<T>(x, y);
54
+ }
55
+
56
+ operator bool () const;
57
+
58
+ bool operator ! () const;
59
+
60
+ struct Data;
61
+
62
+ Impl<Data> self;
63
+
64
+ };// Bitmap
65
+
66
+
67
+ bool load_bitmap (Bitmap* bitmap, const char* path);
68
+
69
+ bool save_bitmap (const Bitmap& bitmap, const char* path);
70
+
71
+
72
+ bool draw_string (
73
+ Bitmap* bitmap, const char* str,
74
+ coord x = 0, coord y = 0, const Font& font = default_font());
75
+
76
+
77
+ }// Rays
78
+
79
+
80
+ #endif//EOH
@@ -0,0 +1,101 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_COLOR_H__
4
+ #define __RAYS_COLOR_H__
5
+
6
+
7
+ #include <rays/defs.h>
8
+
9
+
10
+ namespace Rays
11
+ {
12
+
13
+
14
+ enum ColorSpaceType
15
+ {
16
+
17
+ COLORSPACE_UNKNOWN = UNKNOWN,
18
+
19
+ GRAY_8, GRAY_16, GRAY_24, GRAY_32, GRAY_float,
20
+
21
+ RGB_888, RGBA_8888, RGBX_8888, ARGB_8888, XRGB_8888,
22
+
23
+ BGR_888, BGRA_8888, BGRX_8888, ABGR_8888, XBGR_8888,
24
+
25
+ RGB_float, RGBA_float, ARGB_float,
26
+
27
+ BGR_float, BGRA_float, ABGR_float,
28
+
29
+ COLORSPACE_LAST,
30
+
31
+ GRAY = GRAY_8,
32
+
33
+ RGB = RGB_888, BGR = BGR_888,
34
+
35
+ RGBA = RGBA_8888, RGBX = RGBX_8888, ARGB = ARGB_8888, XRGB = XRGB_8888,
36
+
37
+ BGRA = BGRA_8888, BGRX = BGRX_8888, ABGR = ABGR_8888, XBGR = XBGR_8888,
38
+
39
+ };// ColorSpaceType
40
+
41
+
42
+ class ColorSpace
43
+ {
44
+
45
+ public:
46
+
47
+ ColorSpace ();
48
+
49
+ ColorSpace (ColorSpaceType type, bool premultiplied = false);
50
+
51
+ ColorSpaceType type () const;
52
+
53
+ int bpc () const;
54
+
55
+ int Bpc () const;
56
+
57
+ int bpp () const;
58
+
59
+ int Bpp () const;
60
+
61
+ int alpha_pos () const;
62
+
63
+ bool is_gray () const;
64
+
65
+ bool is_rgb () const;
66
+
67
+ bool is_bgr () const;
68
+
69
+ bool is_float () const;
70
+
71
+ bool has_alpha () const;
72
+
73
+ bool has_skip () const;
74
+
75
+ bool is_alpha_first () const;
76
+
77
+ bool is_alpha_last () const;
78
+
79
+ bool is_skip_first () const;
80
+
81
+ bool is_skip_last () const;
82
+
83
+ bool is_premult () const;
84
+
85
+ operator bool () const;
86
+
87
+ bool operator ! () const;
88
+
89
+ private:
90
+
91
+ ColorSpaceType type_;
92
+
93
+ bool premult;
94
+
95
+ };// ColorSpace
96
+
97
+
98
+ }// Rays
99
+
100
+
101
+ #endif//EOH
@@ -0,0 +1,33 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_DEFS_H__
4
+ #define __RAYS_DEFS_H__
5
+
6
+
7
+ #include <string>
8
+
9
+
10
+ namespace Rays
11
+ {
12
+
13
+
14
+ typedef unsigned char uchar;
15
+
16
+ typedef unsigned short ushort;
17
+
18
+ typedef unsigned int uint;
19
+
20
+ typedef unsigned long ulong;
21
+
22
+ typedef float coord;
23
+
24
+ typedef std::string String;
25
+
26
+
27
+ enum {UNKNOWN = 0};
28
+
29
+
30
+ }// Rays
31
+
32
+
33
+ #endif//EOH