carray-cairo 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +11 -0
- data/carray-cairo.gemspec +23 -0
- data/carray_cairo.c +70 -0
- data/extconf.rb +45 -0
- data/lib/autoload/autoload_graphics_cairo.rb +9 -0
- data/lib/carray-cairo.rb +3 -0
- data/lib/graphics/cairo.rb +49 -0
- data/test/test.rb +16 -0
- data/test/test2.rb +17 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 279bfa2faf50a3ad0f9d6cb3a43ad5293c16f667
|
4
|
+
data.tar.gz: 2be766d74ae1f946d62a279904d2537c90ea6dc1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3b6c40efb05d5c9dfadd727da7a19eac70b77aba719af0bab37fd691a10df827c0adab7af799fb4a34217a3499e2a92ad1a217d9cdded51d78c5c4e12e2181b2
|
7
|
+
data.tar.gz: c0e0d618cb4a16dc1899cbac2eeb4d37a8b65c63a0b56f6fc61003c975a98e182a37d43b6f46493adc78c3d382d049d8c6e4af8c2c81ca586f126046af4e30c1
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
Gem::Specification::new do |s|
|
3
|
+
version = "1.0.0"
|
4
|
+
|
5
|
+
files = Dir.glob("**/*") - [
|
6
|
+
Dir.glob("carray*.gem"),
|
7
|
+
].flatten
|
8
|
+
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.name = "carray-cairo"
|
11
|
+
s.summary = "Extension for converting Cairo::ImageSurface to/from CArray"
|
12
|
+
s.description = <<-HERE
|
13
|
+
Extension for converting Cairo::ImageSurface to/from CArray
|
14
|
+
HERE
|
15
|
+
s.version = version
|
16
|
+
s.author = "Hiroki Motoyoshi"
|
17
|
+
s.email = ""
|
18
|
+
s.homepage = 'https://github.com/himotoyoshi/carray-cairo'
|
19
|
+
s.files = files
|
20
|
+
s.extensions = [ "extconf.rb" ]
|
21
|
+
s.has_rdoc = false
|
22
|
+
s.required_ruby_version = ">= 1.8.1"
|
23
|
+
end
|
data/carray_cairo.c
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
/* ---------------------------------------------------------------------------
|
2
|
+
|
3
|
+
carray/carray_cairo.c
|
4
|
+
|
5
|
+
This file is part of Ruby/CArray extension library.
|
6
|
+
You can redistribute it and/or modify it under the terms of
|
7
|
+
the Ruby Licence.
|
8
|
+
|
9
|
+
Copyright (C) 2005-2008 Hiroki Motoyoshi
|
10
|
+
|
11
|
+
---------------------------------------------------------------------------- */
|
12
|
+
|
13
|
+
#include "ruby.h"
|
14
|
+
#include <cairo.h>
|
15
|
+
|
16
|
+
static VALUE rb_mCairo, rb_cImageSurface;
|
17
|
+
|
18
|
+
#include "carray.h"
|
19
|
+
|
20
|
+
static VALUE
|
21
|
+
cr_image_surface_ca (VALUE self)
|
22
|
+
{
|
23
|
+
volatile VALUE obj;
|
24
|
+
int32_t dim[3];
|
25
|
+
int format, width, height, width0;
|
26
|
+
unsigned char *data;
|
27
|
+
cairo_surface_t *surface;
|
28
|
+
|
29
|
+
Data_Get_Struct (self, cairo_surface_t, surface);
|
30
|
+
|
31
|
+
format = cairo_image_surface_get_format(surface);
|
32
|
+
width = cairo_image_surface_get_width(surface);
|
33
|
+
height = cairo_image_surface_get_height(surface);
|
34
|
+
data = cairo_image_surface_get_data(surface);
|
35
|
+
|
36
|
+
switch ( format ) {
|
37
|
+
case CAIRO_FORMAT_ARGB32:
|
38
|
+
case CAIRO_FORMAT_RGB24:
|
39
|
+
dim[0] = height;
|
40
|
+
dim[1] = width;
|
41
|
+
dim[2] = 4;
|
42
|
+
obj = rb_carray_wrap_ptr(CA_UINT8, 3, dim, 0, NULL, (char *)data, self);
|
43
|
+
if ( ca_endian == CA_LITTLE_ENDIAN ) {
|
44
|
+
obj = rb_funcall(obj, rb_intern("[]"), 2,
|
45
|
+
Qfalse,
|
46
|
+
rb_range_new(INT2FIX(-1),INT2FIX(0),0));
|
47
|
+
}
|
48
|
+
break;
|
49
|
+
case CAIRO_FORMAT_A8:
|
50
|
+
width0 = width + (CA_ALIGN_VOIDP - width % CA_ALIGN_VOIDP);
|
51
|
+
dim[0] = height;
|
52
|
+
dim[1] = width0;
|
53
|
+
obj = rb_carray_wrap_ptr(CA_UINT8, 2, dim, 0, NULL, (char *)data, self);
|
54
|
+
obj = rb_funcall(obj, rb_intern("[]"), 2,
|
55
|
+
Qnil,
|
56
|
+
rb_range_new(INT2FIX(0),INT2NUM(width), 1));
|
57
|
+
break;
|
58
|
+
case CAIRO_FORMAT_A1:
|
59
|
+
rb_raise(rb_eRuntimeError, "can't wrap CAIRO_FORMAT_A1 data by CArray");
|
60
|
+
}
|
61
|
+
return obj;
|
62
|
+
}
|
63
|
+
|
64
|
+
void
|
65
|
+
Init_carray_cairo ()
|
66
|
+
{
|
67
|
+
rb_mCairo = rb_const_get(rb_cObject, rb_intern("Cairo"));
|
68
|
+
rb_cImageSurface = rb_const_get(rb_mCairo, rb_intern("ImageSurface"));
|
69
|
+
rb_define_method(rb_cImageSurface, "ca", cr_image_surface_ca, 0);
|
70
|
+
}
|
data/extconf.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require "mkmf"
|
2
|
+
require "carray/mkmf"
|
3
|
+
|
4
|
+
ENV["PKG_CONFIG_PATH"] = (ENV["PKG_CONFIG_PATH"]||"") + ":/opt/X11/lib/pkgconfig"
|
5
|
+
|
6
|
+
if /cygwin|mingw/ =~ RUBY_PLATFORM
|
7
|
+
open("Makefile", "w") { |io|
|
8
|
+
io << "all:" << "\n"
|
9
|
+
io << "install:" << "\n"
|
10
|
+
io << "clean:" << "\n"
|
11
|
+
io << "distclean:" << "\n"
|
12
|
+
io << "\trm -rf mkmf.log Makefile" << "\n"
|
13
|
+
}
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
begin
|
18
|
+
have_image_cairo = true
|
19
|
+
$CPPFLAGS << " " << `pkg-config --cflags cairo`.chomp
|
20
|
+
$LDFLAGS << " " << `pkg-config --libs cairo`.chomp
|
21
|
+
`pkg-config --libs cairo`.chomp.split(/\s+/).uniq.each do |opt|
|
22
|
+
case opt
|
23
|
+
when /\-l(.*)/
|
24
|
+
unless have_library($1)
|
25
|
+
have_image_cairo = false
|
26
|
+
break
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
rescue
|
31
|
+
end
|
32
|
+
|
33
|
+
if have_carray()
|
34
|
+
if have_header("cairo.h") and have_image_cairo
|
35
|
+
create_makefile("carray/carray_cairo")
|
36
|
+
else
|
37
|
+
open("Makefile", "w") { |io|
|
38
|
+
io << "all:" << "\n"
|
39
|
+
io << "install:" << "\n"
|
40
|
+
io << "clean:" << "\n"
|
41
|
+
io << "distclean:" << "\n"
|
42
|
+
io << "\trm -rf mkmf.log Makefile" << "\n"
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
data/lib/carray-cairo.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# carray/graphics/cairo.rb
|
4
|
+
#
|
5
|
+
# This file is part of Ruby/CArray extension library.
|
6
|
+
# You can redistribute it and/or modify it under the terms of
|
7
|
+
# the Ruby Licence.
|
8
|
+
#
|
9
|
+
# Copyright (C) 2005-2008 Hiroki Motoyoshi
|
10
|
+
#
|
11
|
+
# ----------------------------------------------------------------------------
|
12
|
+
|
13
|
+
require "cairo"
|
14
|
+
require "carray/carray_cairo"
|
15
|
+
|
16
|
+
class Cairo::ImageSurface
|
17
|
+
|
18
|
+
def self.new_from_ca (ca)
|
19
|
+
|
20
|
+
if ca.data_type != CA_UINT8
|
21
|
+
raise "invalid data_type for Cairo::ImageSurface"
|
22
|
+
end
|
23
|
+
|
24
|
+
case true
|
25
|
+
when ( ca.rank == 2 ),
|
26
|
+
( ( ca.rank == 3 ) and ( ca.dim2 == 1 ) )
|
27
|
+
image_type = Cairo::FORMAT_A8
|
28
|
+
img = Cairo::ImageSurface.new(image_type, ca.dim1, ca.dim0)
|
29
|
+
img.ca[] = ca
|
30
|
+
when ( ca.data_type == CA_UINT8 and ca.rank == 3 and ca.dim2 == 3 )
|
31
|
+
image_type = Cairo::FORMAT_RGB24
|
32
|
+
img = Cairo::ImageSurface.new(image_type, ca.dim1, ca.dim0)
|
33
|
+
img.ca[] = ca
|
34
|
+
when ( ca.data_type == CA_UINT8 and ca.rank == 3 and ca.dim2 == 4 )
|
35
|
+
image_type = Cairo::FORMAT_ARGB32
|
36
|
+
img = Cairo::ImageSurface.new(image_type, ca.dim1, ca.dim0)
|
37
|
+
img.ca[] = ca
|
38
|
+
else
|
39
|
+
raise "invalid shape of carray to create Cairo::ImageSurface"
|
40
|
+
end
|
41
|
+
|
42
|
+
return img
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_ca
|
46
|
+
return ca.to_ca
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/test/test.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "cairo"
|
2
|
+
require "carray"
|
3
|
+
require "G"
|
4
|
+
|
5
|
+
img = Cairo::ImageSurface.new(:rgb24, 100, 100)
|
6
|
+
#p Cairo::ImageSurface.new(:a8, 50, 100).ca
|
7
|
+
data = img.ca
|
8
|
+
data[nil,nil,1].random!(255)
|
9
|
+
p img
|
10
|
+
p img.ca
|
11
|
+
p img.format
|
12
|
+
G.open(100,100)
|
13
|
+
G { render(img) }
|
14
|
+
G.update
|
15
|
+
G.listen()
|
16
|
+
|
data/test/test2.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "carray"
|
2
|
+
require "G"
|
3
|
+
|
4
|
+
ca = CArray.uint8(100, 100, 4) { 255 }
|
5
|
+
|
6
|
+
img = Cairo::ImageSurface.new_from_ca(ca)
|
7
|
+
p Cairo::FORMAT_ARGB32
|
8
|
+
p img
|
9
|
+
img.ca[false, 3] = 255
|
10
|
+
img.ca[false, 0] = 255
|
11
|
+
p img.ca
|
12
|
+
p img.format
|
13
|
+
|
14
|
+
G.open(100,100)
|
15
|
+
G { render(img, 0.5) }
|
16
|
+
G.update
|
17
|
+
G.listen()
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carray-cairo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hiroki Motoyoshi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-06 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |2
|
14
|
+
Extension for converting Cairo::ImageSurface to/from CArray
|
15
|
+
email: ''
|
16
|
+
executables: []
|
17
|
+
extensions:
|
18
|
+
- extconf.rb
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- README.md
|
22
|
+
- carray-cairo.gemspec
|
23
|
+
- carray_cairo.c
|
24
|
+
- extconf.rb
|
25
|
+
- lib/autoload/autoload_graphics_cairo.rb
|
26
|
+
- lib/carray-cairo.rb
|
27
|
+
- lib/graphics/cairo.rb
|
28
|
+
- test/test.rb
|
29
|
+
- test/test2.rb
|
30
|
+
homepage: https://github.com/himotoyoshi/carray-cairo
|
31
|
+
licenses: []
|
32
|
+
metadata: {}
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.8.1
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 2.6.4
|
50
|
+
signing_key:
|
51
|
+
specification_version: 4
|
52
|
+
summary: Extension for converting Cairo::ImageSurface to/from CArray
|
53
|
+
test_files: []
|
54
|
+
has_rdoc: false
|