rays 0.1.12 → 0.1.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.doc/ext/rays/bitmap.cpp +22 -76
- data/.doc/ext/rays/bounds.cpp +95 -125
- data/.doc/ext/rays/camera.cpp +171 -0
- data/.doc/ext/rays/color.cpp +223 -45
- data/.doc/ext/rays/color_space.cpp +146 -46
- data/.doc/ext/rays/defs.cpp +183 -0
- data/.doc/ext/rays/font.cpp +69 -21
- data/.doc/ext/rays/image.cpp +26 -37
- data/.doc/ext/rays/matrix.cpp +186 -29
- data/.doc/ext/rays/native.cpp +14 -8
- data/.doc/ext/rays/noise.cpp +53 -0
- data/.doc/ext/rays/painter.cpp +187 -292
- data/.doc/ext/rays/point.cpp +96 -77
- data/.doc/ext/rays/polygon.cpp +313 -0
- data/.doc/ext/rays/polygon_line.cpp +96 -0
- data/.doc/ext/rays/polyline.cpp +167 -0
- data/.doc/ext/rays/rays.cpp +103 -12
- data/.doc/ext/rays/shader.cpp +83 -9
- data/LICENSE +21 -0
- data/README.md +1 -1
- data/Rakefile +24 -9
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +23 -81
- data/ext/rays/bounds.cpp +100 -128
- data/ext/rays/camera.cpp +186 -0
- data/ext/rays/color.cpp +231 -51
- data/ext/rays/color_space.cpp +149 -47
- data/ext/rays/defs.cpp +183 -0
- data/ext/rays/defs.h +26 -2
- data/ext/rays/extconf.rb +2 -3
- data/ext/rays/font.cpp +74 -24
- data/ext/rays/image.cpp +28 -40
- data/ext/rays/matrix.cpp +198 -30
- data/ext/rays/native.cpp +14 -8
- data/ext/rays/noise.cpp +55 -0
- data/ext/rays/painter.cpp +203 -298
- data/ext/rays/point.cpp +105 -81
- data/ext/rays/polygon.cpp +329 -0
- data/ext/rays/polygon_line.cpp +99 -0
- data/ext/rays/polyline.cpp +176 -0
- data/ext/rays/rays.cpp +103 -13
- data/ext/rays/shader.cpp +84 -9
- data/include/rays.h +10 -2
- data/include/rays/bitmap.h +14 -26
- data/include/rays/bounds.h +21 -4
- data/include/rays/camera.h +74 -0
- data/include/rays/color.h +25 -14
- data/include/rays/color_space.h +15 -10
- data/include/rays/coord.h +114 -0
- data/include/rays/debug.h +22 -0
- data/include/rays/defs.h +36 -0
- data/include/rays/exception.h +6 -2
- data/include/rays/font.h +4 -4
- data/include/rays/image.h +12 -18
- data/include/rays/matrix.h +50 -24
- data/include/rays/noise.h +42 -0
- data/include/rays/opengl.h +2 -50
- data/include/rays/painter.h +89 -93
- data/include/rays/point.h +44 -51
- data/include/rays/polygon.h +198 -0
- data/include/rays/polyline.h +71 -0
- data/include/rays/rays.h +3 -0
- data/include/rays/ruby.h +7 -1
- data/include/rays/ruby/bounds.h +1 -1
- data/include/rays/ruby/camera.h +41 -0
- data/include/rays/ruby/color.h +1 -1
- data/include/rays/ruby/color_space.h +1 -1
- data/include/rays/ruby/font.h +1 -1
- data/include/rays/ruby/matrix.h +1 -1
- data/include/rays/ruby/point.h +1 -1
- data/include/rays/ruby/polygon.h +52 -0
- data/include/rays/ruby/polyline.h +41 -0
- data/include/rays/ruby/rays.h +8 -0
- data/include/rays/ruby/shader.h +1 -1
- data/include/rays/shader.h +36 -8
- data/lib/rays.rb +7 -2
- data/lib/rays/bitmap.rb +0 -15
- data/lib/rays/bounds.rb +17 -23
- data/lib/rays/camera.rb +24 -0
- data/lib/rays/color.rb +20 -47
- data/lib/rays/color_space.rb +13 -13
- data/lib/rays/image.rb +3 -7
- data/lib/rays/matrix.rb +28 -0
- data/lib/rays/module.rb +4 -19
- data/lib/rays/painter.rb +78 -93
- data/lib/rays/point.rb +13 -21
- data/lib/rays/polygon.rb +58 -0
- data/lib/rays/polygon_line.rb +36 -0
- data/lib/rays/polyline.rb +32 -0
- data/lib/rays/shader.rb +20 -1
- data/rays.gemspec +5 -7
- data/src/bitmap.h +36 -0
- data/src/bounds.cpp +74 -11
- data/src/color.cpp +58 -23
- data/src/color_space.cpp +52 -34
- data/src/color_space.h +22 -0
- data/src/coord.cpp +170 -0
- data/src/coord.h +35 -0
- data/src/font.cpp +118 -0
- data/src/font.h +64 -0
- data/src/frame_buffer.cpp +37 -71
- data/src/frame_buffer.h +4 -4
- data/src/image.cpp +172 -98
- data/src/image.h +25 -0
- data/src/ios/bitmap.h +23 -0
- data/src/ios/bitmap.mm +133 -110
- data/src/ios/camera.mm +510 -0
- data/src/ios/font.mm +50 -62
- data/src/ios/helper.h +4 -4
- data/src/ios/opengl.mm +19 -4
- data/src/ios/rays.mm +3 -0
- data/src/matrix.cpp +111 -26
- data/src/matrix.h +30 -0
- data/src/noise.cpp +74 -0
- data/src/opengl.cpp +9 -27
- data/src/opengl.h +37 -0
- data/src/osx/bitmap.h +23 -0
- data/src/osx/bitmap.mm +133 -110
- data/src/osx/camera.mm +451 -0
- data/src/osx/font.mm +49 -62
- data/src/osx/helper.h +2 -2
- data/src/osx/opengl.mm +19 -83
- data/src/osx/rays.mm +3 -0
- data/src/painter.cpp +845 -671
- data/src/painter.h +24 -0
- data/src/point.cpp +140 -119
- data/src/polygon.cpp +1266 -0
- data/src/polygon.h +32 -0
- data/src/polyline.cpp +160 -0
- data/src/polyline.h +69 -0
- data/src/render_buffer.cpp +11 -4
- data/src/render_buffer.h +2 -2
- data/src/shader.cpp +163 -106
- data/src/shader.h +38 -0
- data/src/shader_program.cpp +533 -0
- data/src/{program.h → shader_program.h} +28 -16
- data/src/shader_source.cpp +140 -0
- data/src/shader_source.h +52 -0
- data/src/texture.cpp +136 -160
- data/src/texture.h +65 -0
- data/src/win32/bitmap.cpp +62 -52
- data/src/win32/font.cpp +11 -13
- data/src/win32/font.h +24 -0
- data/src/win32/gdi.h +6 -6
- data/test/helper.rb +0 -3
- data/test/test_bitmap.rb +31 -7
- data/test/test_bounds.rb +36 -0
- data/test/test_color.rb +59 -19
- data/test/test_color_space.rb +95 -0
- data/test/test_font.rb +5 -0
- data/test/test_image.rb +24 -20
- data/test/test_matrix.rb +106 -0
- data/test/test_painter.rb +157 -51
- data/test/test_painter_shape.rb +102 -0
- data/test/test_point.rb +29 -0
- data/test/test_polygon.rb +234 -0
- data/test/test_polygon_line.rb +167 -0
- data/test/test_polyline.rb +171 -0
- data/test/test_shader.rb +9 -9
- metadata +102 -70
- data/.doc/ext/rays/texture.cpp +0 -138
- data/ext/rays/texture.cpp +0 -149
- data/include/rays/ruby/texture.h +0 -41
- data/include/rays/texture.h +0 -71
- data/lib/rays/texture.rb +0 -24
- data/src/program.cpp +0 -648
- data/test/test_texture.rb +0 -27
data/lib/rays/point.rb
CHANGED
@@ -10,6 +10,7 @@ module Rays
|
|
10
10
|
class Point
|
11
11
|
|
12
12
|
include Comparable
|
13
|
+
include Enumerable
|
13
14
|
|
14
15
|
def move_to (*args)
|
15
16
|
dup.move_to! *args
|
@@ -19,6 +20,14 @@ module Rays
|
|
19
20
|
dup.move_by! *args
|
20
21
|
end
|
21
22
|
|
23
|
+
def zero? ()
|
24
|
+
length == 0
|
25
|
+
end
|
26
|
+
|
27
|
+
def each (&block)
|
28
|
+
to_a.each &block
|
29
|
+
end
|
30
|
+
|
22
31
|
def to_a (dimension = 2)
|
23
32
|
case dimension
|
24
33
|
when 1 then [x]
|
@@ -28,20 +37,8 @@ module Rays
|
|
28
37
|
end
|
29
38
|
end
|
30
39
|
|
31
|
-
def
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
def - (*args)
|
36
|
-
op_sub Point.from(*args)
|
37
|
-
end
|
38
|
-
|
39
|
-
def * (*args)
|
40
|
-
op_mult Point.from(*args)
|
41
|
-
end
|
42
|
-
|
43
|
-
def / (*args)
|
44
|
-
op_div Point.from(*args)
|
40
|
+
def to_s (dimension = 2)
|
41
|
+
to_a(dimension).to_s
|
45
42
|
end
|
46
43
|
|
47
44
|
def <=> (o)
|
@@ -50,13 +47,8 @@ module Rays
|
|
50
47
|
z <=> o.z
|
51
48
|
end
|
52
49
|
|
53
|
-
def
|
54
|
-
|
55
|
-
when Point then arg0
|
56
|
-
when Array then Point.new *arg0
|
57
|
-
when Numeric then Point.new arg0, arg0, arg0
|
58
|
-
else raise ArgumentError
|
59
|
-
end
|
50
|
+
def inspect ()
|
51
|
+
"#<Rays::Point #{to_a(3).join ', '}>"
|
60
52
|
end
|
61
53
|
|
62
54
|
end# Point
|
data/lib/rays/polygon.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require 'rays/ext'
|
5
|
+
require 'rays/polyline'
|
6
|
+
|
7
|
+
|
8
|
+
module Rays
|
9
|
+
|
10
|
+
|
11
|
+
class Polygon
|
12
|
+
|
13
|
+
include Enumerable
|
14
|
+
|
15
|
+
def initialize (*args, loop: true)
|
16
|
+
setup args, loop
|
17
|
+
end
|
18
|
+
|
19
|
+
def transform (matrix = nil, &block)
|
20
|
+
lines = to_a
|
21
|
+
lines = lines.map {|line| line.transform matrix} if matrix
|
22
|
+
lines = block.call lines if block
|
23
|
+
self.class.new *lines
|
24
|
+
end
|
25
|
+
|
26
|
+
def intersects (obj)
|
27
|
+
!(self & obj).empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.line (*args, loop: false)
|
31
|
+
new *args, loop: loop
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.rect (
|
35
|
+
*args, round: nil, lt: nil, rt: nil, lb: nil, rb: nil, nsegment: nil)
|
36
|
+
|
37
|
+
create_rect args, round, lt, rt, lb, rb, nsegment
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.ellipse (
|
41
|
+
*args, center: nil, radius: nil, hole: nil, from: nil, to: nil,
|
42
|
+
nsegment: nil)
|
43
|
+
|
44
|
+
create_ellipse args, center, radius, hole, from, to, nsegment
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.curve (*args, loop: false)
|
48
|
+
create_curve args, loop
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.bezier (*args, loop: false)
|
52
|
+
create_bezier args, loop
|
53
|
+
end
|
54
|
+
|
55
|
+
end# Polygon
|
56
|
+
|
57
|
+
|
58
|
+
end# Rays
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require 'rays/ext'
|
5
|
+
|
6
|
+
|
7
|
+
module Rays
|
8
|
+
|
9
|
+
|
10
|
+
class Polygon
|
11
|
+
|
12
|
+
|
13
|
+
class Line < Polyline
|
14
|
+
|
15
|
+
def initialize (*points, loop: true, hole: false)
|
16
|
+
setup points, loop, hole
|
17
|
+
end
|
18
|
+
|
19
|
+
def transform (matrix = nil, loop: loop?, hole: hole?, &block)
|
20
|
+
points = to_a
|
21
|
+
points = points.map {|point| matrix * point} if matrix
|
22
|
+
points = block.call points if block
|
23
|
+
self.class.new *points, loop: loop, hole: hole
|
24
|
+
end
|
25
|
+
|
26
|
+
def inspect ()
|
27
|
+
"#<Rays::Polygon::Line #{to_a.join ', '}, loop: #{loop?}, hole: #{hole?}>"
|
28
|
+
end
|
29
|
+
|
30
|
+
end# Line
|
31
|
+
|
32
|
+
|
33
|
+
end# Polygon
|
34
|
+
|
35
|
+
|
36
|
+
end# Rays
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require 'rays/ext'
|
5
|
+
|
6
|
+
|
7
|
+
module Rays
|
8
|
+
|
9
|
+
|
10
|
+
class Polyline
|
11
|
+
|
12
|
+
include Enumerable
|
13
|
+
|
14
|
+
def initialize (*points, loop: false)
|
15
|
+
setup points, loop
|
16
|
+
end
|
17
|
+
|
18
|
+
def transform (matrix = nil, loop: loop?, &block)
|
19
|
+
points = to_a
|
20
|
+
points = points.map {|point| matrix * point} if matrix
|
21
|
+
points = block.call points if block
|
22
|
+
self.class.new *points, loop: loop
|
23
|
+
end
|
24
|
+
|
25
|
+
def inspect ()
|
26
|
+
"#<Rays::Polyline #{to_a.join ', '}, loop: #{loop?}>"
|
27
|
+
end
|
28
|
+
|
29
|
+
end# Polyline
|
30
|
+
|
31
|
+
|
32
|
+
end# Rays
|
data/lib/rays/shader.rb
CHANGED
@@ -1,13 +1,32 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
|
4
|
+
require 'xot/block_util'
|
4
5
|
require 'rays/ext'
|
5
6
|
|
6
7
|
|
7
8
|
module Rays
|
8
9
|
|
9
10
|
|
10
|
-
|
11
|
+
class Shader
|
12
|
+
|
13
|
+
def initialize (source = nil, **uniforms, &block)
|
14
|
+
if source
|
15
|
+
setup source
|
16
|
+
uniform **uniforms unless uniforms.empty?
|
17
|
+
end
|
18
|
+
|
19
|
+
Xot::BlockUtil.instance_eval_or_block_call self, &block if block
|
20
|
+
end
|
21
|
+
|
22
|
+
def uniform (name = nil, *args, **uniforms)
|
23
|
+
set_uniform name, *args if name
|
24
|
+
uniforms.each do |key, value|
|
25
|
+
set_uniform key, value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end# Shader
|
11
30
|
|
12
31
|
|
13
32
|
end# Rays
|
data/rays.gemspec
CHANGED
@@ -21,17 +21,15 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.description = 'This library helps you to develop graphics application with OpenGL.'
|
22
22
|
s.version = mod.version
|
23
23
|
|
24
|
-
s.authors = %w[
|
25
|
-
s.email = '
|
24
|
+
s.authors = %w[xordog]
|
25
|
+
s.email = 'xordog@gmail.com'
|
26
26
|
s.homepage = "https://github.com/xord/rays"
|
27
27
|
|
28
28
|
s.platform = Gem::Platform::RUBY
|
29
|
-
s.required_ruby_version = '
|
29
|
+
s.required_ruby_version = '~> 2'
|
30
30
|
|
31
|
-
s.add_runtime_dependency '
|
32
|
-
s.add_runtime_dependency '
|
33
|
-
s.add_runtime_dependency 'rucy'
|
34
|
-
s.add_development_dependency 'gemcutter'
|
31
|
+
s.add_runtime_dependency 'xot', '~> 0.1.16'
|
32
|
+
s.add_runtime_dependency 'rucy', '~> 0.1.16'
|
35
33
|
|
36
34
|
s.files = `git ls-files`.split $/
|
37
35
|
s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
|
data/src/bitmap.h
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RAYS_SRC_BITMAP_H__
|
4
|
+
#define __RAYS_SRC_BITMAP_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <rays/bitmap.h>
|
8
|
+
|
9
|
+
|
10
|
+
namespace Rays
|
11
|
+
{
|
12
|
+
|
13
|
+
|
14
|
+
class Texture;
|
15
|
+
|
16
|
+
class RawFont;
|
17
|
+
|
18
|
+
|
19
|
+
Bitmap Bitmap_from (const Texture& texture);
|
20
|
+
|
21
|
+
void Bitmap_draw_string (
|
22
|
+
Bitmap* bitmap, const RawFont& font, const char* str, coord x, coord y);
|
23
|
+
|
24
|
+
void Bitmap_set_modified (Bitmap* bitmap, bool modified = true);
|
25
|
+
|
26
|
+
bool Bitmap_get_modified (const Bitmap& bitmap);
|
27
|
+
|
28
|
+
void Bitmap_save (const Bitmap& bitmap, const char* path);
|
29
|
+
|
30
|
+
Bitmap Bitmap_load (const char* path);
|
31
|
+
|
32
|
+
|
33
|
+
}// Rays
|
34
|
+
|
35
|
+
|
36
|
+
#endif//EOH
|
data/src/bounds.cpp
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#include "rays/bounds.h"
|
2
2
|
|
3
3
|
|
4
|
+
#include <float.h>
|
4
5
|
#include <algorithm>
|
5
6
|
#include "rays/exception.h"
|
6
7
|
|
@@ -293,6 +294,22 @@ namespace Rays
|
|
293
294
|
return z + d - 1;
|
294
295
|
}
|
295
296
|
|
297
|
+
void
|
298
|
+
Bounds::set_position (coord x, coord y, coord z)
|
299
|
+
{
|
300
|
+
this->x = x;
|
301
|
+
this->y = y;
|
302
|
+
this->z = z;
|
303
|
+
}
|
304
|
+
|
305
|
+
void
|
306
|
+
Bounds::set_position (const Point& position)
|
307
|
+
{
|
308
|
+
x = position.x;
|
309
|
+
y = position.y;
|
310
|
+
z = position.z;
|
311
|
+
}
|
312
|
+
|
296
313
|
Point&
|
297
314
|
Bounds::position ()
|
298
315
|
{
|
@@ -305,6 +322,20 @@ namespace Rays
|
|
305
322
|
return const_cast<This*>(this)->position();
|
306
323
|
}
|
307
324
|
|
325
|
+
void
|
326
|
+
Bounds::set_size (coord width, coord height, coord depth)
|
327
|
+
{
|
328
|
+
w = width;
|
329
|
+
h = height;
|
330
|
+
d = depth;
|
331
|
+
}
|
332
|
+
|
333
|
+
void
|
334
|
+
Bounds::set_size (const Point& size)
|
335
|
+
{
|
336
|
+
set_size(size.x, size.y, size.z);
|
337
|
+
}
|
338
|
+
|
308
339
|
Point&
|
309
340
|
Bounds::size ()
|
310
341
|
{
|
@@ -326,9 +357,9 @@ namespace Rays
|
|
326
357
|
}
|
327
358
|
|
328
359
|
void
|
329
|
-
Bounds::set_center (const Point&
|
360
|
+
Bounds::set_center (const Point& center)
|
330
361
|
{
|
331
|
-
set_center(
|
362
|
+
set_center(center.x, center.y, center.z);
|
332
363
|
}
|
333
364
|
|
334
365
|
Point
|
@@ -372,12 +403,15 @@ namespace Rays
|
|
372
403
|
Bounds&
|
373
404
|
Bounds::operator &= (const Bounds& rhs)
|
374
405
|
{
|
375
|
-
if (
|
406
|
+
if (!rhs)
|
376
407
|
argument_error(__FILE__, __LINE__);
|
377
408
|
|
378
|
-
|
379
|
-
|
380
|
-
|
409
|
+
if (!*this)
|
410
|
+
invalid_state_error(__FILE__, __LINE__);
|
411
|
+
|
412
|
+
coord x = std::max(this->x, rhs.x);
|
413
|
+
coord y = std::max(this->y, rhs.y);
|
414
|
+
coord z = std::max(this->z, rhs.z);
|
381
415
|
coord w = std::min(this->x + this->w, rhs.x + rhs.w) - x;
|
382
416
|
coord h = std::min(this->y + this->h, rhs.y + rhs.h) - y;
|
383
417
|
coord d = std::min(this->z + this->d, rhs.z + rhs.d) - z;
|
@@ -392,12 +426,11 @@ namespace Rays
|
|
392
426
|
Bounds&
|
393
427
|
Bounds::operator |= (const Bounds& rhs)
|
394
428
|
{
|
395
|
-
if (
|
396
|
-
argument_error(__FILE__, __LINE__);
|
429
|
+
if (!rhs) return *this;
|
397
430
|
|
398
|
-
coord x = std::min(this->x,
|
399
|
-
coord y = std::min(this->y,
|
400
|
-
coord z = std::min(this->z,
|
431
|
+
coord x = std::min(this->x, rhs.x);
|
432
|
+
coord y = std::min(this->y, rhs.y);
|
433
|
+
coord z = std::min(this->z, rhs.z);
|
401
434
|
coord w = std::max(this->x + this->w, rhs.x + rhs.w) - x;
|
402
435
|
coord h = std::max(this->y + this->h, rhs.y + rhs.h) - y;
|
403
436
|
coord d = std::max(this->z + this->d, rhs.z + rhs.d) - z;
|
@@ -405,6 +438,19 @@ namespace Rays
|
|
405
438
|
return reset(x, y, z, w, h, d);
|
406
439
|
}
|
407
440
|
|
441
|
+
Bounds&
|
442
|
+
Bounds::operator |= (const Point& rhs)
|
443
|
+
{
|
444
|
+
coord x = std::min(this->x, rhs.x);
|
445
|
+
coord y = std::min(this->y, rhs.y);
|
446
|
+
coord z = std::min(this->z, rhs.z);
|
447
|
+
coord w = std::max(this->x + this->w, rhs.x) - x;
|
448
|
+
coord h = std::max(this->y + this->h, rhs.y) - y;
|
449
|
+
coord d = std::max(this->z + this->d, rhs.z) - z;
|
450
|
+
|
451
|
+
return reset(x, y, z, w, h, d);
|
452
|
+
}
|
453
|
+
|
408
454
|
bool
|
409
455
|
operator == (const Bounds& lhs, const Bounds& rhs)
|
410
456
|
{
|
@@ -439,5 +485,22 @@ namespace Rays
|
|
439
485
|
return t;
|
440
486
|
}
|
441
487
|
|
488
|
+
Bounds
|
489
|
+
operator | (const Bounds& lhs, const Point& rhs)
|
490
|
+
{
|
491
|
+
Bounds t = lhs;
|
492
|
+
t |= rhs;
|
493
|
+
return t;
|
494
|
+
}
|
495
|
+
|
496
|
+
|
497
|
+
Bounds
|
498
|
+
invalid_bounds ()
|
499
|
+
{
|
500
|
+
coord max = FLT_MAX / 2;
|
501
|
+
coord size = -FLT_MAX;
|
502
|
+
return Bounds(max, max, max, size, size, size);
|
503
|
+
}
|
504
|
+
|
442
505
|
|
443
506
|
}// Rays
|
data/src/color.cpp
CHANGED
@@ -2,44 +2,69 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
#include <limits.h>
|
5
|
+
#include <glm/gtx/color_space.hpp>
|
5
6
|
#include <xot/util.h>
|
6
7
|
#include "rays/exception.h"
|
7
8
|
#include "rays/color_space.h"
|
9
|
+
#include "coord.h"
|
8
10
|
|
9
11
|
|
10
12
|
namespace Rays
|
11
13
|
{
|
12
14
|
|
13
15
|
|
14
|
-
Color
|
16
|
+
Color
|
17
|
+
gray (float gray, float alpha)
|
15
18
|
{
|
16
|
-
|
19
|
+
return Color(gray, alpha);
|
17
20
|
}
|
18
21
|
|
19
|
-
Color
|
22
|
+
Color
|
23
|
+
gray8 (int gray, int alpha)
|
20
24
|
{
|
21
|
-
|
25
|
+
Color c;
|
26
|
+
c.reset8(gray, alpha);
|
27
|
+
return c;
|
22
28
|
}
|
23
29
|
|
24
|
-
Color
|
30
|
+
Color
|
31
|
+
rgb (float red, float green, float blue, float alpha)
|
25
32
|
{
|
26
|
-
|
33
|
+
return Color(red, green, blue, alpha);
|
27
34
|
}
|
28
35
|
|
29
36
|
Color
|
30
|
-
|
37
|
+
rgb8 (int red, int green, int blue, int alpha)
|
31
38
|
{
|
32
39
|
Color c;
|
33
|
-
c.reset8(
|
40
|
+
c.reset8(red, green, blue, alpha);
|
34
41
|
return c;
|
35
42
|
}
|
36
43
|
|
37
44
|
Color
|
38
|
-
|
45
|
+
hsv (float hue, float saturation, float value, float alpha)
|
39
46
|
{
|
40
|
-
|
41
|
-
|
42
|
-
|
47
|
+
hue = fmod(hue, 1.f);
|
48
|
+
if (hue < 0) hue += 1.f;
|
49
|
+
|
50
|
+
auto c = glm::rgbColor(Vec3(hue * 360.f, saturation, value));
|
51
|
+
return Color(c[0], c[1], c[2], alpha);
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
Color::Color (float gray, float alpha)
|
56
|
+
{
|
57
|
+
reset(gray, alpha);
|
58
|
+
}
|
59
|
+
|
60
|
+
Color::Color (float red, float green, float blue, float alpha)
|
61
|
+
{
|
62
|
+
reset(red, green, blue, alpha);
|
63
|
+
}
|
64
|
+
|
65
|
+
Color::Color (void* pixel, const ColorSpace& cs)
|
66
|
+
{
|
67
|
+
reset(pixel, cs);
|
43
68
|
}
|
44
69
|
|
45
70
|
Color
|
@@ -57,15 +82,12 @@ namespace Rays
|
|
57
82
|
Color&
|
58
83
|
Color::reset (float red, float green, float blue, float alpha)
|
59
84
|
{
|
60
|
-
|
61
|
-
this->green = green;
|
62
|
-
this->blue = blue;
|
63
|
-
this->alpha = alpha;
|
85
|
+
Super::reset(red, green, blue, alpha);
|
64
86
|
return *this;
|
65
87
|
}
|
66
88
|
|
67
89
|
Color&
|
68
|
-
Color::reset8 (
|
90
|
+
Color::reset8 (int gray, int alpha)
|
69
91
|
{
|
70
92
|
float g = uchar2float(gray);
|
71
93
|
float a = uchar2float(alpha);
|
@@ -73,12 +95,13 @@ namespace Rays
|
|
73
95
|
}
|
74
96
|
|
75
97
|
Color&
|
76
|
-
Color::reset8 (
|
98
|
+
Color::reset8 (int red, int green, int blue, int alpha)
|
77
99
|
{
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
100
|
+
Super::reset(
|
101
|
+
uchar2float(red),
|
102
|
+
uchar2float(green),
|
103
|
+
uchar2float(blue),
|
104
|
+
uchar2float(alpha));
|
82
105
|
return *this;
|
83
106
|
}
|
84
107
|
|
@@ -211,7 +234,7 @@ namespace Rays
|
|
211
234
|
|
212
235
|
Color::operator bool () const
|
213
236
|
{
|
214
|
-
return
|
237
|
+
return alpha > 0;
|
215
238
|
}
|
216
239
|
|
217
240
|
bool
|
@@ -220,5 +243,17 @@ namespace Rays
|
|
220
243
|
return !operator bool();
|
221
244
|
}
|
222
245
|
|
246
|
+
bool
|
247
|
+
operator == (const Color& lhs, const Color& rhs)
|
248
|
+
{
|
249
|
+
return lhs.r == rhs.r && lhs.g == rhs.g && lhs.b == rhs.b && lhs.a == rhs.a;
|
250
|
+
}
|
251
|
+
|
252
|
+
bool
|
253
|
+
operator != (const Color& lhs, const Color& rhs)
|
254
|
+
{
|
255
|
+
return !operator==(lhs, rhs);
|
256
|
+
}
|
257
|
+
|
223
258
|
|
224
259
|
}// Rays
|