rays 0.1.27 → 0.1.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.doc/ext/rays/painter.cpp +7 -2
- data/VERSION +1 -1
- data/ext/rays/painter.cpp +7 -2
- data/rays.gemspec +2 -2
- data/src/ios/bitmap.mm +18 -1
- data/src/osx/bitmap.mm +18 -1
- data/test/test_image.rb +45 -10
- data/test/test_painter.rb +26 -4
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38052c848aef75871de813ae9cc59a956672b1c6b8db25b55916f041ae0df976
|
4
|
+
data.tar.gz: d1f462fce0b73364a015fa1826eef17c3d1a4ac0b4378590f20438d87ce8e1cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e01828d4ac2ad4749a9d050d3890669be7e35dd057cc92b0dae23f645954b44bf7f3775d193ef36d9590d10879175a7937b28ceddf0bf9fd29a84723f0cfdbe
|
7
|
+
data.tar.gz: da8b670d9e704d4cc48070d5d252ec504e433f00222160a5c42ccf7a036eabc1a31580b6318da59672bc8576b0dddf84fce635ce9194f4a462eebfc8d4e03451
|
data/.doc/ext/rays/painter.cpp
CHANGED
@@ -479,7 +479,10 @@ VALUE set_shader(VALUE self)
|
|
479
479
|
CHECK;
|
480
480
|
check_arg_count(__FILE__, __LINE__, "Painter#set_shader", argc, 1);
|
481
481
|
|
482
|
-
|
482
|
+
if (argc >= 1 && !argv[0])
|
483
|
+
THIS->no_shader();
|
484
|
+
else
|
485
|
+
THIS->set_shader(to<Rays::Shader>(argc, argv));
|
483
486
|
return self;
|
484
487
|
}
|
485
488
|
|
@@ -487,7 +490,9 @@ static
|
|
487
490
|
VALUE get_shader(VALUE self)
|
488
491
|
{
|
489
492
|
CHECK;
|
490
|
-
|
493
|
+
|
494
|
+
const Rays::Shader& shader = THIS->shader();
|
495
|
+
return shader ? value(shader) : nil();
|
491
496
|
}
|
492
497
|
|
493
498
|
static
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.28
|
data/ext/rays/painter.cpp
CHANGED
@@ -521,7 +521,10 @@ RUCY_DEFN(set_shader)
|
|
521
521
|
CHECK;
|
522
522
|
check_arg_count(__FILE__, __LINE__, "Painter#set_shader", argc, 1);
|
523
523
|
|
524
|
-
|
524
|
+
if (argc >= 1 && !argv[0])
|
525
|
+
THIS->no_shader();
|
526
|
+
else
|
527
|
+
THIS->set_shader(to<Rays::Shader>(argc, argv));
|
525
528
|
return self;
|
526
529
|
}
|
527
530
|
RUCY_END
|
@@ -530,7 +533,9 @@ static
|
|
530
533
|
RUCY_DEF0(get_shader)
|
531
534
|
{
|
532
535
|
CHECK;
|
533
|
-
|
536
|
+
|
537
|
+
const Rays::Shader& shader = THIS->shader();
|
538
|
+
return shader ? value(shader) : nil();
|
534
539
|
}
|
535
540
|
RUCY_END
|
536
541
|
|
data/rays.gemspec
CHANGED
@@ -28,8 +28,8 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.platform = Gem::Platform::RUBY
|
29
29
|
s.required_ruby_version = '>= 2.6.0'
|
30
30
|
|
31
|
-
s.add_runtime_dependency 'xot', '~> 0.1.
|
32
|
-
s.add_runtime_dependency 'rucy', '~> 0.1.
|
31
|
+
s.add_runtime_dependency 'xot', '~> 0.1.28'
|
32
|
+
s.add_runtime_dependency 'rucy', '~> 0.1.28'
|
33
33
|
|
34
34
|
s.files = `git ls-files`.split $/
|
35
35
|
s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
|
data/src/ios/bitmap.mm
CHANGED
@@ -224,9 +224,26 @@ namespace Rays
|
|
224
224
|
return bitmap.self->modified;
|
225
225
|
}
|
226
226
|
|
227
|
+
static CFStringRef
|
228
|
+
get_bitmap_type (const char* path_)
|
229
|
+
{
|
230
|
+
String path = path_;
|
231
|
+
path = path.downcase();
|
232
|
+
if (path.ends_with(".png")) return kUTTypePNG;
|
233
|
+
if (path.ends_with(".gif")) return kUTTypeGIF;
|
234
|
+
if (path.ends_with(".bmp")) return kUTTypeBMP;
|
235
|
+
if (path.ends_with(".jpg") || path.ends_with(".jpeg")) return kUTTypeJPEG;
|
236
|
+
if (path.ends_with(".tif") || path.ends_with(".tiff")) return kUTTypeTIFF;
|
237
|
+
return nil;
|
238
|
+
}
|
239
|
+
|
227
240
|
void
|
228
241
|
Bitmap_save (const Bitmap& bmp, const char* path_)
|
229
242
|
{
|
243
|
+
const CFStringRef type = get_bitmap_type(path_);
|
244
|
+
if (!type)
|
245
|
+
argument_error(__FILE__, __LINE__, "unknown image file type");
|
246
|
+
|
230
247
|
std::shared_ptr<CGImage> img(bmp.self->get_image(), CGImageRelease);
|
231
248
|
if (!img)
|
232
249
|
rays_error(__FILE__, __LINE__, "getting CGImage failed.");
|
@@ -237,7 +254,7 @@ namespace Rays
|
|
237
254
|
rays_error(__FILE__, __LINE__, "creating NSURL failed.");
|
238
255
|
|
239
256
|
std::shared_ptr<CGImageDestination> dest(
|
240
|
-
CGImageDestinationCreateWithURL((CFURLRef) url,
|
257
|
+
CGImageDestinationCreateWithURL((CFURLRef) url, type, 1, NULL),
|
241
258
|
safe_cfrelease);
|
242
259
|
if (!dest)
|
243
260
|
rays_error(__FILE__, __LINE__, "CGImageDestinationCreateWithURL() failed.");
|
data/src/osx/bitmap.mm
CHANGED
@@ -223,9 +223,26 @@ namespace Rays
|
|
223
223
|
return bitmap.self->modified;
|
224
224
|
}
|
225
225
|
|
226
|
+
static CFStringRef
|
227
|
+
get_bitmap_type (const char* path_)
|
228
|
+
{
|
229
|
+
String path = path_;
|
230
|
+
path = path.downcase();
|
231
|
+
if (path.ends_with(".png")) return kUTTypePNG;
|
232
|
+
if (path.ends_with(".gif")) return kUTTypeGIF;
|
233
|
+
if (path.ends_with(".bmp")) return kUTTypeBMP;
|
234
|
+
if (path.ends_with(".jpg") || path.ends_with(".jpeg")) return kUTTypeJPEG;
|
235
|
+
if (path.ends_with(".tif") || path.ends_with(".tiff")) return kUTTypeTIFF;
|
236
|
+
return nil;
|
237
|
+
}
|
238
|
+
|
226
239
|
void
|
227
240
|
Bitmap_save (const Bitmap& bmp, const char* path_)
|
228
241
|
{
|
242
|
+
const CFStringRef type = get_bitmap_type(path_);
|
243
|
+
if (!type)
|
244
|
+
argument_error(__FILE__, __LINE__, "unknown image file type");
|
245
|
+
|
229
246
|
std::shared_ptr<CGImage> img(bmp.self->get_image(), CGImageRelease);
|
230
247
|
if (!img)
|
231
248
|
rays_error(__FILE__, __LINE__, "getting CGImage failed.");
|
@@ -236,7 +253,7 @@ namespace Rays
|
|
236
253
|
rays_error(__FILE__, __LINE__, "creating NSURL failed.");
|
237
254
|
|
238
255
|
std::shared_ptr<CGImageDestination> dest(
|
239
|
-
CGImageDestinationCreateWithURL((CFURLRef) url,
|
256
|
+
CGImageDestinationCreateWithURL((CFURLRef) url, type, 1, NULL),
|
240
257
|
safe_cfrelease);
|
241
258
|
if (!dest)
|
242
259
|
rays_error(__FILE__, __LINE__, "CGImageDestinationCreateWithURL() failed.");
|
data/test/test_image.rb
CHANGED
@@ -6,11 +6,12 @@ require_relative 'helper'
|
|
6
6
|
|
7
7
|
class TestImage < Test::Unit::TestCase
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
def image(*args)
|
10
|
+
Rays::Image.new(*args)
|
11
|
+
end
|
11
12
|
|
12
|
-
def
|
13
|
-
Rays::Image.
|
13
|
+
def load(path)
|
14
|
+
Rays::Image.load path
|
14
15
|
end
|
15
16
|
|
16
17
|
def color(r = 0, g = 0, b = 0, a = 0)
|
@@ -22,12 +23,12 @@ class TestImage < Test::Unit::TestCase
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def test_initialize()
|
25
|
-
assert_equal
|
26
|
-
assert_equal
|
26
|
+
assert_equal 10, image(10, 20).width
|
27
|
+
assert_equal 10, image(20, 10).height
|
27
28
|
end
|
28
29
|
|
29
30
|
def test_dup()
|
30
|
-
o = image
|
31
|
+
o = image 10, 10
|
31
32
|
assert_equal color(0, 0, 0, 0), o[0, 0]
|
32
33
|
o[0, 0] = color(1, 0, 0, 0)
|
33
34
|
assert_equal color(1, 0, 0, 0), o[0, 0]
|
@@ -39,12 +40,12 @@ class TestImage < Test::Unit::TestCase
|
|
39
40
|
end
|
40
41
|
|
41
42
|
def test_bitmap()
|
42
|
-
assert_equal
|
43
|
-
assert_equal
|
43
|
+
assert_equal 10, image(10, 20).bitmap.width
|
44
|
+
assert_equal 10, image(20, 10).bitmap.height
|
44
45
|
end
|
45
46
|
|
46
47
|
def test_painter()
|
47
|
-
pa = image.painter
|
48
|
+
pa = image(10, 10).painter
|
48
49
|
assert_equal color(0, 0, 0, 0), pa.background
|
49
50
|
assert_equal color(1, 1, 1, 1), pa.fill
|
50
51
|
assert_equal color(1, 1, 1, 0), pa.stroke
|
@@ -73,4 +74,38 @@ class TestImage < Test::Unit::TestCase
|
|
73
74
|
assert drawn {|p| p.text "a"}
|
74
75
|
end
|
75
76
|
|
77
|
+
def test_save_load()
|
78
|
+
def get_image_type(filename)
|
79
|
+
`file #{filename}`.match(/#{filename}: ([^,]+),/)[1]
|
80
|
+
end
|
81
|
+
|
82
|
+
img = image(10, 10).paint {fill 1, 0, 0; ellipse 0, 0, 10}
|
83
|
+
pixels = img.bitmap.to_a
|
84
|
+
paths = %w[png jpg jpeg gif bmp tif tiff].map {|ext| "#{__dir__}/testimage.#{ext}"}
|
85
|
+
|
86
|
+
png, jpg, jpeg, gif, bmp, tif, tiff = paths
|
87
|
+
|
88
|
+
paths.each {|path| img.save path}
|
89
|
+
|
90
|
+
assert_equal 'PNG image data', get_image_type(png)
|
91
|
+
assert_equal 'JPEG image data', get_image_type(jpg)
|
92
|
+
assert_equal 'JPEG image data', get_image_type(jpeg)
|
93
|
+
assert_equal 'GIF image data', get_image_type(gif)
|
94
|
+
assert_equal 'PC bitmap', get_image_type(bmp)
|
95
|
+
assert_equal 'TIFF image data', get_image_type(tif)
|
96
|
+
assert_equal 'TIFF image data', get_image_type(tiff)
|
97
|
+
|
98
|
+
assert_equal pixels, load(png) .then {|o| o.bitmap.to_a}
|
99
|
+
assert_equal [10, 10], load(jpg) .then {|o| [o.width, o.height]}
|
100
|
+
assert_equal [10, 10], load(jpeg).then {|o| [o.width, o.height]}
|
101
|
+
assert_equal pixels, load(gif) .then {|o| o.bitmap.to_a}
|
102
|
+
assert_equal [10, 10], load(bmp) .then {|o| [o.width, o.height]}
|
103
|
+
assert_equal pixels, load(tif) .then {|o| o.bitmap.to_a}
|
104
|
+
assert_equal pixels, load(tiff).then {|o| o.bitmap.to_a}
|
105
|
+
|
106
|
+
paths.each {|path| File.delete path}
|
107
|
+
|
108
|
+
assert_raise(ArgumentError) {img.save 'testimage.unknown'}
|
109
|
+
end
|
110
|
+
|
76
111
|
end# TestImage
|
data/test/test_painter.rb
CHANGED
@@ -19,18 +19,24 @@ class TestPainter < Test::Unit::TestCase
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def image(w = 16, h = 16, bg: 0, &block)
|
22
|
-
Rays::Image.new(w, h)
|
22
|
+
Rays::Image.new(w, h)
|
23
|
+
.paint {background bg}
|
24
|
+
.tap {|img| img.paint(&block) if block}
|
25
|
+
end
|
26
|
+
|
27
|
+
def assert_gray(expected, actual)
|
28
|
+
assert_in_epsilon expected, actual, 0.02
|
23
29
|
end
|
24
30
|
|
25
31
|
def assert_rgb(expected, actual)
|
26
32
|
(0..2).each do |i|
|
27
|
-
|
33
|
+
assert_gray expected[i], actual[i]
|
28
34
|
end
|
29
35
|
end
|
30
36
|
|
31
37
|
def assert_rgba(expected, actual)
|
32
38
|
(0..3).each do |i|
|
33
|
-
|
39
|
+
assert_gray expected[i], actual[i]
|
34
40
|
end
|
35
41
|
end
|
36
42
|
|
@@ -369,7 +375,23 @@ class TestPainter < Test::Unit::TestCase
|
|
369
375
|
end
|
370
376
|
|
371
377
|
def test_shader()
|
372
|
-
|
378
|
+
image.paint do |pa|
|
379
|
+
assert_nil pa.shader
|
380
|
+
|
381
|
+
pa.shader = Rays::Shader.new "void main() {gl_FragColor = vec4(0.0);}"
|
382
|
+
assert_instance_of Rays::Shader, pa.shader
|
383
|
+
|
384
|
+
pa.shader = nil
|
385
|
+
assert_nil pa.shader
|
386
|
+
|
387
|
+
pa.shader = "void main() {gl_FragColor = vec4(0.0);}"
|
388
|
+
assert_instance_of Rays::Shader, pa.shader
|
389
|
+
|
390
|
+
pa.no_shader
|
391
|
+
assert_nil pa.shader
|
392
|
+
end
|
393
|
+
|
394
|
+
img = image.paint {
|
373
395
|
shader "void main() {gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);}"
|
374
396
|
fill 1, 0, 0
|
375
397
|
rect bounds
|
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.1.
|
4
|
+
version: 0.1.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xordog
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-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.1.
|
19
|
+
version: 0.1.28
|
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.1.
|
26
|
+
version: 0.1.28
|
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.1.
|
33
|
+
version: 0.1.28
|
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.1.
|
40
|
+
version: 0.1.28
|
41
41
|
description: This library helps you to develop graphics application with OpenGL.
|
42
42
|
email: xordog@gmail.com
|
43
43
|
executables: []
|