rays 0.3.16 → 0.4.0

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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/rays/bitmap.cpp +1 -1
  3. data/.doc/ext/rays/bounds.cpp +1 -4
  4. data/.doc/ext/rays/camera.cpp +10 -2
  5. data/.doc/ext/rays/color.cpp +1 -3
  6. data/.doc/ext/rays/color_space.cpp +3 -3
  7. data/.doc/ext/rays/font.cpp +1 -4
  8. data/.doc/ext/rays/image.cpp +4 -3
  9. data/.doc/ext/rays/matrix.cpp +1 -4
  10. data/.doc/ext/rays/painter.cpp +8 -0
  11. data/.doc/ext/rays/point.cpp +1 -4
  12. data/.doc/ext/rays/polygon.cpp +11 -3
  13. data/.doc/ext/rays/polyline.cpp +13 -8
  14. data/.doc/ext/rays/rays.cpp +10 -6
  15. data/.doc/ext/rays/shader.cpp +13 -5
  16. data/.github/workflows/release-gem.yml +10 -1
  17. data/.github/workflows/test.yml +9 -0
  18. data/ChangeLog.md +10 -0
  19. data/VERSION +1 -1
  20. data/ext/rays/bitmap.cpp +1 -1
  21. data/ext/rays/bounds.cpp +1 -4
  22. data/ext/rays/camera.cpp +11 -2
  23. data/ext/rays/color.cpp +1 -3
  24. data/ext/rays/color_space.cpp +3 -3
  25. data/ext/rays/font.cpp +1 -4
  26. data/ext/rays/image.cpp +4 -3
  27. data/ext/rays/matrix.cpp +1 -4
  28. data/ext/rays/painter.cpp +9 -0
  29. data/ext/rays/point.cpp +1 -4
  30. data/ext/rays/polygon.cpp +12 -3
  31. data/ext/rays/polyline.cpp +14 -8
  32. data/ext/rays/rays.cpp +10 -6
  33. data/ext/rays/shader.cpp +14 -5
  34. data/include/rays/bitmap.h +1 -1
  35. data/include/rays/color_space.h +6 -2
  36. data/include/rays/defs.h +14 -4
  37. data/include/rays/image.h +2 -2
  38. data/lib/rays/camera.rb +1 -1
  39. data/lib/rays/extension.rb +1 -1
  40. data/lib/rays/image.rb +2 -2
  41. data/lib/rays/polygon.rb +1 -1
  42. data/lib/rays/polyline.rb +1 -1
  43. data/lib/rays/shader.rb +1 -1
  44. data/rays.gemspec +2 -2
  45. data/src/color_space.cpp +5 -5
  46. data/src/image.cpp +2 -2
  47. data/src/ios/bitmap.mm +3 -3
  48. data/src/ios/font.mm +3 -3
  49. data/src/opengl/bitmap.cpp +1 -1
  50. data/src/opengl/color_space.cpp +11 -2
  51. data/src/opengl/color_space.h +1 -1
  52. data/src/opengl/texture.cpp +5 -5
  53. data/src/osx/bitmap.mm +14 -3
  54. data/src/osx/font.mm +3 -3
  55. data/src/sdl/bitmap.cpp +28 -9
  56. data/src/texture.h +1 -1
  57. data/src/win32/bitmap.cpp +73 -35
  58. metadata +6 -6
@@ -42,7 +42,7 @@ namespace Rays
42
42
  height =
43
43
  width_pow2 =
44
44
  height_pow2 = 0;
45
- color_space = COLORSPACE_UNKNOWN;
45
+ color_space = COLORSPACE_NONE;
46
46
  smooth = false;
47
47
  modified = false;
48
48
  }
@@ -194,14 +194,14 @@ namespace Rays
194
194
  glTexParameteri(
195
195
  GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, smooth ? GL_LINEAR : GL_NEAREST);
196
196
 
197
- GLenum format, type;
198
- ColorSpace_get_gl_format_and_type(&format, &type, cs);
197
+ GLenum internalformat, format, type;
198
+ ColorSpace_get_gl_format_and_type(&internalformat, &format, &type, cs);
199
199
 
200
200
  if (npot)
201
201
  {
202
202
  // create non-power-of-two texture
203
203
  glTexImage2D(
204
- GL_TEXTURE_2D, 0, format, width, height, 0, format, type,
204
+ GL_TEXTURE_2D, 0, internalformat, width, height, 0, format, type,
205
205
  bitmap ? bitmap->pixels() : NULL);
206
206
  npot = OpenGL_has_error();
207
207
  }
@@ -274,7 +274,7 @@ namespace Rays
274
274
  argument_error(__FILE__, __LINE__, "the height of bitmap does not match");
275
275
 
276
276
  GLenum format, type;
277
- ColorSpace_get_gl_format_and_type(&format, &type, bitmap.color_space());
277
+ ColorSpace_get_gl_format_and_type(NULL, &format, &type, bitmap.color_space());
278
278
 
279
279
  glBindTexture(GL_TEXTURE_2D, self->id);
280
280
  glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, format, type, bitmap.pixels());
data/src/osx/bitmap.mm CHANGED
@@ -119,7 +119,7 @@ namespace Rays
119
119
  if (pixels) delete [] (uchar*) pixels;
120
120
 
121
121
  width = height = 0;
122
- color_space = COLORSPACE_UNKNOWN;
122
+ color_space = COLORSPACE_NONE;
123
123
  pixels = NULL;
124
124
  context = NULL;
125
125
  modified = false;
@@ -282,6 +282,17 @@ namespace Rays
282
282
  return bmp;
283
283
  }
284
284
 
285
+ NSImage*
286
+ Bitmap_get_nsimage (const Bitmap& bmp)
287
+ {
288
+ if (!bmp) return NULL;
289
+
290
+ std::shared_ptr<CGImage> cgimage(bmp.self->get_image(), CGImageRelease);
291
+ return [[[NSImage alloc]
292
+ initWithCGImage: cgimage.get() size: NSZeroSize]
293
+ autorelease];
294
+ }
295
+
285
296
 
286
297
  Bitmap::Bitmap ()
287
298
  {
@@ -322,8 +333,8 @@ namespace Rays
322
333
  {
323
334
  if (!*this)
324
335
  {
325
- static const ColorSpace UNKNOWN = COLORSPACE_UNKNOWN;
326
- return UNKNOWN;
336
+ static const ColorSpace NONE = COLORSPACE_NONE;
337
+ return NONE;
327
338
  }
328
339
  return self->color_space;
329
340
  }
data/src/osx/font.mm CHANGED
@@ -66,7 +66,7 @@ namespace Rays
66
66
  CFRelease);
67
67
 
68
68
  CFAttributedStringPtr attrstr(
69
- CFAttributedStringCreate(NULL, Xot::cfstring(str).get(), attr.get()),
69
+ CFAttributedStringCreate(NULL, Xot::String(str).to_cfstr().get(), attr.get()),
70
70
  CFRelease);
71
71
 
72
72
  return CTLinePtr(
@@ -130,7 +130,7 @@ namespace Rays
130
130
  RawFont::RawFont (const char* name, coord size)
131
131
  {
132
132
  self->font = name
133
- ? CTFontCreateWithName(Xot::cfstring(name).get(), size, NULL)
133
+ ? CTFontCreateWithName(Xot::String(name).to_cfstr().get(), size, NULL)
134
134
  : CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, size, NULL);
135
135
  }
136
136
 
@@ -140,7 +140,7 @@ namespace Rays
140
140
  if (path)
141
141
  *this = RawFont_load(path, size);
142
142
  else
143
- self->font = CTFontCreateWithName(Xot::cfstring(obj.name()).get(), size, NULL);
143
+ self->font = CTFontCreateWithName(obj.name().to_cfstr().get(), size, NULL);
144
144
  }
145
145
 
146
146
  RawFont::~RawFont ()
data/src/sdl/bitmap.cpp CHANGED
@@ -9,6 +9,8 @@
9
9
  #include <SDL.h>
10
10
  #include <xot/util.h>
11
11
  #include "rays/exception.h"
12
+ #include "rays/image.h"
13
+ #include "rays/painter.h"
12
14
  #include "../font.h"
13
15
  #include "../texture.h"
14
16
 
@@ -41,7 +43,7 @@ namespace Rays
41
43
  if (surface) SDL_FreeSurface(surface);
42
44
 
43
45
  surface = NULL;
44
- color_space = COLORSPACE_UNKNOWN;
46
+ color_space = COLORSPACE_NONE;
45
47
  modified = false;
46
48
  }
47
49
 
@@ -142,8 +144,8 @@ namespace Rays
142
144
  return strrchr(path, '.');
143
145
  }
144
146
 
145
- void
146
- Bitmap_save (const Bitmap& bmp, const char* path)
147
+ static void
148
+ save_bitmap (const Bitmap& bitmap, const char* path)
147
149
  {
148
150
  const char* extension = get_ext(path);
149
151
  if (!extension)
@@ -152,14 +154,14 @@ namespace Rays
152
154
  __FILE__, __LINE__, "invalid image file extension: '%s'", path);
153
155
  }
154
156
 
155
- const auto& cs = bmp.color_space();
156
- int w = bmp.width();
157
- int h = bmp.height();
157
+ const auto& cs = bitmap.color_space();
158
+ int w = bitmap.width();
159
+ int h = bitmap.height();
158
160
  int pitch = w * cs.Bpp();
159
161
 
160
162
  std::unique_ptr<uchar[]> pixels(new uchar[h * pitch]);
161
163
  for (int y = 0; y < h; ++y)
162
- memcpy(pixels.get() + pitch * y, bmp.at<uchar>(0, y), pitch);
164
+ memcpy(pixels.get() + pitch * y, bitmap.at<uchar>(0, y), pitch);
163
165
 
164
166
  String ext = extension;
165
167
  ext.downcase();
@@ -180,6 +182,23 @@ namespace Rays
180
182
  rays_error(__FILE__, __LINE__, "failed to save: '%s'", path);
181
183
  }
182
184
 
185
+ void
186
+ Bitmap_save (const Bitmap& bitmap, const char* path)
187
+ {
188
+ Bitmap bmp = bitmap;
189
+ ColorSpace cs = bmp.color_space();
190
+ if (!cs.is_rgb() || (cs.has_alpha() && !cs.is_alpha_last()))
191
+ {
192
+ Image img(bmp.width(), bmp.height(), cs.has_alpha() ? RGBA : RGB);
193
+ Painter p = img.painter();
194
+ p.begin();
195
+ p.image(Image(bmp));
196
+ p.end();
197
+ bmp = img.bitmap();
198
+ }
199
+ save_bitmap(bmp, path);
200
+ }
201
+
183
202
  Bitmap
184
203
  Bitmap_load (const char* path)
185
204
  {
@@ -252,8 +271,8 @@ namespace Rays
252
271
  {
253
272
  if (!*this)
254
273
  {
255
- static const ColorSpace UNKNOWN = COLORSPACE_UNKNOWN;
256
- return UNKNOWN;
274
+ static const ColorSpace NONE = COLORSPACE_NONE;
275
+ return NONE;
257
276
  }
258
277
  return self->color_space;
259
278
  }
data/src/texture.h CHANGED
@@ -26,7 +26,7 @@ namespace Rays
26
26
  Texture ();
27
27
 
28
28
  Texture (
29
- int width, int height, const ColorSpace& cs = RGBA,
29
+ int width, int height, const ColorSpace& cs = DEFAULT_COLORSPACE,
30
30
  bool smooth = false);
31
31
 
32
32
  Texture (const Bitmap& bitmap, bool smooth = false);
data/src/win32/bitmap.cpp CHANGED
@@ -7,6 +7,8 @@
7
7
  #include <stb_image_write.h>
8
8
 
9
9
  #include "rays/exception.h"
10
+ #include "rays/image.h"
11
+ #include "rays/painter.h"
10
12
  #include "../font.h"
11
13
  #include "../texture.h"
12
14
  #include "gdi.h"
@@ -44,7 +46,7 @@ namespace Rays
44
46
  if (memdc) memdc = Win32::MemoryDC();
45
47
 
46
48
  width = height = pitch = 0;
47
- color_space = COLORSPACE_UNKNOWN;
49
+ color_space = COLORSPACE_NONE;
48
50
  pixels = NULL;
49
51
  modified = false;
50
52
  }
@@ -52,6 +54,26 @@ namespace Rays
52
54
  };// Bitmap::Data
53
55
 
54
56
 
57
+ static HBITMAP
58
+ create_hbitmap (const Bitmap& bitmap, const Win32::DC& dc, void** pixels)
59
+ {
60
+ Bitmap::Data* self = bitmap.self.get();
61
+
62
+ BITMAPINFO bmpinfo;
63
+ memset(&bmpinfo, 0, sizeof(bmpinfo));
64
+
65
+ BITMAPINFOHEADER& header = bmpinfo.bmiHeader;
66
+ header.biSize = sizeof(BITMAPINFOHEADER);
67
+ header.biWidth = self->width;
68
+ header.biHeight = -self->height;
69
+ header.biPlanes = 1;
70
+ header.biBitCount = self->color_space.bpp();
71
+ header.biCompression = BI_RGB;
72
+
73
+ return CreateDIBSection(
74
+ dc.handle(), &bmpinfo, DIB_RGB_COLORS, pixels, NULL, 0);
75
+ }
76
+
55
77
  void
56
78
  Bitmap_setup (
57
79
  Bitmap* bitmap, int w, int h, const ColorSpace& cs,
@@ -77,21 +99,8 @@ namespace Rays
77
99
  int padding = 4 - self->pitch % 4;
78
100
  if (padding < 4) self->pitch += padding;
79
101
 
80
- BITMAPINFO bmpinfo;
81
- memset(&bmpinfo, 0, sizeof(bmpinfo));
82
-
83
- BITMAPINFOHEADER& header = bmpinfo.bmiHeader;
84
- header.biSize = sizeof(BITMAPINFOHEADER);
85
- header.biWidth = self->width;
86
- header.biHeight = -self->height;
87
- header.biPlanes = 1;
88
- header.biBitCount = self->color_space.bpp();
89
- header.biCompression = BI_RGB;
90
-
91
102
  Win32::DC dc = Win32::screen_dc();
92
-
93
- HBITMAP hbmp = CreateDIBSection(
94
- dc.handle(), &bmpinfo, DIB_RGB_COLORS, (void**) &self->pixels, NULL, 0);
103
+ HBITMAP hbmp = create_hbitmap(*bitmap, dc, (void**) &self->pixels);
95
104
  if (!hbmp)
96
105
  rays_error(__FILE__, __LINE__);
97
106
 
@@ -99,11 +108,10 @@ namespace Rays
99
108
  if (!self->memdc)
100
109
  rays_error(__FILE__, __LINE__);
101
110
 
102
- size_t size = self->pitch * self->height;
103
111
  if (pixels)
104
- memcpy(self->pixels, pixels, size);
112
+ memcpy(self->pixels, pixels, bitmap->size());
105
113
  else if (clear_pixels)
106
- memset(self->pixels, 0, size);
114
+ memset(self->pixels, 0, bitmap->size());
107
115
  }
108
116
 
109
117
  void
@@ -147,36 +155,36 @@ namespace Rays
147
155
  return strrchr(path, '.');
148
156
  }
149
157
 
150
- void
151
- Bitmap_save (const Bitmap& bmp, const char* path)
158
+ static void
159
+ save_bitmap (const Bitmap& bitmap, const char* path)
152
160
  {
153
- const char* ext = get_ext(path);
154
- if (!ext)
161
+ const char* extension = get_ext(path);
162
+ if (!extension)
155
163
  {
156
164
  argument_error(
157
165
  __FILE__, __LINE__, "invalid image file extension: '%s'", path);
158
166
  }
159
167
 
160
- const auto& cs = bmp.color_space();
161
- size_t w = bmp.width();
162
- size_t h = bmp.height();
168
+ const auto& cs = bitmap.color_space();
169
+ size_t w = bitmap.width();
170
+ size_t h = bitmap.height();
163
171
  size_t pitch = w * cs.Bpp();
164
172
 
165
173
  std::unique_ptr<uchar[]> pixels(new uchar[h * pitch]);
166
174
  for (size_t y = 0; y < h; ++y)
167
- memcpy(pixels.get() + pitch * y, bmp.at<uchar>(0, y), pitch);
175
+ memcpy(pixels.get() + pitch * y, bitmap.at<uchar>(0, y), pitch);
176
+
177
+ String ext = extension;
178
+ ext.downcase();
168
179
 
169
180
  int ret = 0;
170
- if (stricmp(ext, ".bmp") == 0)
181
+ if (ext == ".bmp")
171
182
  ret = stbi_write_bmp(path, w, h, cs.Bpp(), pixels.get());
172
- else
173
- if (stricmp(ext, ".png") == 0)
183
+ else if (ext == ".png")
174
184
  ret = stbi_write_png(path, w, h, cs.Bpp(), pixels.get(), 0);
175
- else
176
- if (stricmp(ext, ".jpg") == 0 || stricmp(ext, ".jpeg") == 0)
185
+ else if (ext == ".jpg" || ext == ".jpeg")
177
186
  ret = stbi_write_jpg(path, w, h, cs.Bpp(), pixels.get(), 90);
178
- else
179
- if (stricmp(ext, ".tga") == 0)
187
+ else if (ext == ".tga")
180
188
  ret = stbi_write_tga(path, w, h, cs.Bpp(), pixels.get());
181
189
  else
182
190
  argument_error(__FILE__, __LINE__, "unknown image file type");
@@ -185,6 +193,23 @@ namespace Rays
185
193
  rays_error(__FILE__, __LINE__, "failed to save: '%s'", path);
186
194
  }
187
195
 
196
+ void
197
+ Bitmap_save (const Bitmap& bitmap, const char* path)
198
+ {
199
+ Bitmap bmp = bitmap;
200
+ ColorSpace cs = bmp.color_space();
201
+ if (!cs.is_rgb() || (cs.has_alpha() && !cs.is_alpha_last()))
202
+ {
203
+ Image img(bmp.width(), bmp.height(), cs.has_alpha() ? RGBA : RGB);
204
+ Painter p = img.painter();
205
+ p.begin();
206
+ p.image(Image(bmp));
207
+ p.end();
208
+ bmp = img.bitmap();
209
+ }
210
+ save_bitmap(bmp, path);
211
+ }
212
+
188
213
  Bitmap
189
214
  Bitmap_load (const char* path)
190
215
  {
@@ -217,6 +242,19 @@ namespace Rays
217
242
  return bmp;
218
243
  }
219
244
 
245
+ HBITMAP
246
+ Bitmap_get_hbitmap (const Bitmap& bmp)
247
+ {
248
+ if (!bmp) return NULL;
249
+
250
+ void* pixels = NULL;
251
+ HBITMAP hbmp = create_hbitmap(bmp, Win32::screen_dc(), &pixels);
252
+ if (!hbmp) return NULL;
253
+
254
+ memcpy(pixels, bmp.pixels(), bmp.size());
255
+ return hbmp;
256
+ }
257
+
220
258
 
221
259
  Bitmap::Bitmap ()
222
260
  {
@@ -257,8 +295,8 @@ namespace Rays
257
295
  {
258
296
  if (!*this)
259
297
  {
260
- static const ColorSpace UNKNOWN = COLORSPACE_UNKNOWN;
261
- return UNKNOWN;
298
+ static const ColorSpace NONE = COLORSPACE_NONE;
299
+ return NONE;
262
300
  }
263
301
  return self->color_space;
264
302
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rays
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.16
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-06-22 00:00:00.000000000 Z
11
+ date: 2026-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xot
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.15
19
+ version: 0.4.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.3.15
26
+ version: 0.4.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rucy
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.3.15
33
+ version: 0.4.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.3.15
40
+ version: 0.4.0
41
41
  description: This library helps you to develop graphics application with OpenGL.
42
42
  email: xordog@gmail.com
43
43
  executables: []