rubyquartz 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYRIGHT +24 -0
- data/History.txt +9 -0
- data/Manifest.txt +95 -0
- data/README.txt +71 -0
- data/Rakefile +51 -0
- data/ext/ExportedSymbols.txt +1 -0
- data/ext/bitmap.c +129 -0
- data/ext/bitmap.h +38 -0
- data/ext/bitmap_context.c +67 -0
- data/ext/bitmap_context.h +31 -0
- data/ext/color.c +145 -0
- data/ext/color.h +34 -0
- data/ext/colorspace.c +94 -0
- data/ext/colorspace.h +33 -0
- data/ext/context.c +393 -0
- data/ext/context.h +33 -0
- data/ext/extconf.rb +48 -0
- data/ext/font.c +148 -0
- data/ext/font.h +32 -0
- data/ext/function.c +124 -0
- data/ext/function.h +32 -0
- data/ext/image.c +140 -0
- data/ext/image.h +31 -0
- data/ext/image_source.c +143 -0
- data/ext/image_source.h +31 -0
- data/ext/pdf_document.c +91 -0
- data/ext/pdf_document.h +31 -0
- data/ext/pdf_page.c +79 -0
- data/ext/pdf_page.h +31 -0
- data/ext/point.c +42 -0
- data/ext/point.h +32 -0
- data/ext/rect.c +45 -0
- data/ext/rect.h +32 -0
- data/ext/rubyquartz.c +80 -0
- data/ext/rubyquartz.h +29 -0
- data/ext/rubyquartz_prefix.h +45 -0
- data/ext/shading.c +68 -0
- data/ext/shading.h +32 -0
- data/ext/size.c +42 -0
- data/ext/size.h +32 -0
- data/ext/text.c +258 -0
- data/ext/text.h +39 -0
- data/ext/utilities.c +181 -0
- data/ext/utilities.h +43 -0
- data/lib/rubyquartz.rb +59 -0
- data/lib/rubyquartz/bitmap.rb +62 -0
- data/lib/rubyquartz/bitmap_context.rb +50 -0
- data/lib/rubyquartz/color.rb +68 -0
- data/lib/rubyquartz/colorspace.rb +42 -0
- data/lib/rubyquartz/context.rb +116 -0
- data/lib/rubyquartz/font.rb +48 -0
- data/lib/rubyquartz/function.rb +57 -0
- data/lib/rubyquartz/image.rb +48 -0
- data/lib/rubyquartz/image_source.rb +50 -0
- data/lib/rubyquartz/pdf_document.rb +47 -0
- data/lib/rubyquartz/pdf_page.rb +54 -0
- data/lib/rubyquartz/point.rb +63 -0
- data/lib/rubyquartz/rect.rb +127 -0
- data/lib/rubyquartz/shading.rb +48 -0
- data/lib/rubyquartz/size.rb +39 -0
- data/lib/rubyquartz/text.rb +50 -0
- data/test/images/TestContext.test_begin_path.png +0 -0
- data/test/images/TestContext.test_draw_image.png +0 -0
- data/test/images/TestContext.test_draw_path.png +0 -0
- data/test/images/TestContext.test_draw_pdf.png +0 -0
- data/test/images/TestContext.test_draw_shading_axial.png +0 -0
- data/test/images/TestContext.test_draw_text.png +0 -0
- data/test/images/TestContext.test_draw_text_baseline_aligned.png +0 -0
- data/test/images/TestContext.test_draw_text_flipped.png +0 -0
- data/test/images/TestContext.test_draw_text_flipped_non_zero_point.png +0 -0
- data/test/images/TestContext.test_draw_text_non_zero_point.png +0 -0
- data/test/images/TestContext.test_fill.png +0 -0
- data/test/images/TestContext.test_gsave.png +0 -0
- data/test/images/TestContext.test_gsave_block.png +0 -0
- data/test/images/TestContext.test_line_width.png +0 -0
- data/test/images/TestContext.test_lineto.png +0 -0
- data/test/images/TestContext.test_rotate.png +0 -0
- data/test/images/TestContext.test_rounded_rect.png +0 -0
- data/test/images/TestContext.test_scale.png +0 -0
- data/test/images/TestContext.test_set_line_dash.png +0 -0
- data/test/images/TestContext.test_shadow.png +0 -0
- data/test/images/TestContext.test_stroke_rect.png +0 -0
- data/test/images/TestContext.test_text_bounds.png +0 -0
- data/test/images/TestContext.test_translate.png +0 -0
- data/test/inputs/circle.pdf +0 -0
- data/test/inputs/wash.png +0 -0
- data/test/rubyquartz_test.rb +51 -0
- data/test/tc_bitmap_context.rb +43 -0
- data/test/tc_color.rb +43 -0
- data/test/tc_context.rb +315 -0
- data/test/tc_font.rb +54 -0
- data/test/tc_image_source.rb +69 -0
- data/test/tc_pdf_document.rb +63 -0
- data/test/tc_pdf_page.rb +53 -0
- data/test/tc_text.rb +39 -0
- metadata +156 -0
data/COPYRIGHT
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
|
2
|
+
|
3
|
+
OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
|
4
|
+
|
5
|
+
Omni Source Code software is available from The Omni Group on their web
|
6
|
+
site at www.omnigroup.com.
|
7
|
+
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
9
|
+
copy of this software and associated documentation files (the "Software"),
|
10
|
+
to deal in the Software without restriction, including without limitation
|
11
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
12
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
13
|
+
Software is furnished to do so, subject to the following conditions:
|
14
|
+
|
15
|
+
Any original copyright notices and this permission notice shall be included
|
16
|
+
in all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
23
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
24
|
+
DEALINGS IN THE SOFTWARE.
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
COPYRIGHT
|
2
|
+
History.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
ext/ExportedSymbols.txt
|
7
|
+
ext/bitmap.c
|
8
|
+
ext/bitmap.h
|
9
|
+
ext/bitmap_context.c
|
10
|
+
ext/bitmap_context.h
|
11
|
+
ext/color.c
|
12
|
+
ext/color.h
|
13
|
+
ext/colorspace.c
|
14
|
+
ext/colorspace.h
|
15
|
+
ext/context.c
|
16
|
+
ext/context.h
|
17
|
+
ext/extconf.rb
|
18
|
+
ext/font.c
|
19
|
+
ext/font.h
|
20
|
+
ext/function.c
|
21
|
+
ext/function.h
|
22
|
+
ext/image.c
|
23
|
+
ext/image.h
|
24
|
+
ext/image_source.c
|
25
|
+
ext/image_source.h
|
26
|
+
ext/pdf_document.c
|
27
|
+
ext/pdf_document.h
|
28
|
+
ext/pdf_page.c
|
29
|
+
ext/pdf_page.h
|
30
|
+
ext/point.c
|
31
|
+
ext/point.h
|
32
|
+
ext/rect.c
|
33
|
+
ext/rect.h
|
34
|
+
ext/rubyquartz.c
|
35
|
+
ext/rubyquartz.h
|
36
|
+
ext/rubyquartz_prefix.h
|
37
|
+
ext/shading.c
|
38
|
+
ext/shading.h
|
39
|
+
ext/size.c
|
40
|
+
ext/size.h
|
41
|
+
ext/text.c
|
42
|
+
ext/text.h
|
43
|
+
ext/utilities.c
|
44
|
+
ext/utilities.h
|
45
|
+
lib/rubyquartz.rb
|
46
|
+
lib/rubyquartz/bitmap.rb
|
47
|
+
lib/rubyquartz/bitmap_context.rb
|
48
|
+
lib/rubyquartz/color.rb
|
49
|
+
lib/rubyquartz/colorspace.rb
|
50
|
+
lib/rubyquartz/context.rb
|
51
|
+
lib/rubyquartz/font.rb
|
52
|
+
lib/rubyquartz/function.rb
|
53
|
+
lib/rubyquartz/image.rb
|
54
|
+
lib/rubyquartz/image_source.rb
|
55
|
+
lib/rubyquartz/pdf_document.rb
|
56
|
+
lib/rubyquartz/pdf_page.rb
|
57
|
+
lib/rubyquartz/point.rb
|
58
|
+
lib/rubyquartz/rect.rb
|
59
|
+
lib/rubyquartz/shading.rb
|
60
|
+
lib/rubyquartz/size.rb
|
61
|
+
lib/rubyquartz/text.rb
|
62
|
+
test/images/TestContext.test_begin_path.png
|
63
|
+
test/images/TestContext.test_draw_image.png
|
64
|
+
test/images/TestContext.test_draw_path.png
|
65
|
+
test/images/TestContext.test_draw_pdf.png
|
66
|
+
test/images/TestContext.test_draw_shading_axial.png
|
67
|
+
test/images/TestContext.test_draw_text.png
|
68
|
+
test/images/TestContext.test_draw_text_baseline_aligned.png
|
69
|
+
test/images/TestContext.test_draw_text_flipped.png
|
70
|
+
test/images/TestContext.test_draw_text_flipped_non_zero_point.png
|
71
|
+
test/images/TestContext.test_draw_text_non_zero_point.png
|
72
|
+
test/images/TestContext.test_fill.png
|
73
|
+
test/images/TestContext.test_gsave.png
|
74
|
+
test/images/TestContext.test_gsave_block.png
|
75
|
+
test/images/TestContext.test_line_width.png
|
76
|
+
test/images/TestContext.test_lineto.png
|
77
|
+
test/images/TestContext.test_rotate.png
|
78
|
+
test/images/TestContext.test_rounded_rect.png
|
79
|
+
test/images/TestContext.test_scale.png
|
80
|
+
test/images/TestContext.test_set_line_dash.png
|
81
|
+
test/images/TestContext.test_shadow.png
|
82
|
+
test/images/TestContext.test_stroke_rect.png
|
83
|
+
test/images/TestContext.test_text_bounds.png
|
84
|
+
test/images/TestContext.test_translate.png
|
85
|
+
test/inputs/circle.pdf
|
86
|
+
test/inputs/wash.png
|
87
|
+
test/rubyquartz_test.rb
|
88
|
+
test/tc_bitmap_context.rb
|
89
|
+
test/tc_color.rb
|
90
|
+
test/tc_context.rb
|
91
|
+
test/tc_font.rb
|
92
|
+
test/tc_image_source.rb
|
93
|
+
test/tc_pdf_document.rb
|
94
|
+
test/tc_pdf_page.rb
|
95
|
+
test/tc_text.rb
|
data/README.txt
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
rubyquartz
|
2
|
+
http://rubyquartz.rubyforge.org/
|
3
|
+
http://rubyforge.org/projects/rubyquartz/
|
4
|
+
|
5
|
+
|
6
|
+
== DESCRIPTION:
|
7
|
+
|
8
|
+
Ruby Quartz is a bridge that allows Ruby programs to access the Mac OS X Quartz
|
9
|
+
graphics libraries.
|
10
|
+
|
11
|
+
Ruby Quartz is licensied under a BSD license, see the COPYRIGHT file for more
|
12
|
+
information.
|
13
|
+
|
14
|
+
More information on the project home page: http://rubyquartz.rubyforge.org.
|
15
|
+
|
16
|
+
== FEATURES/PROBLEMS:
|
17
|
+
|
18
|
+
Wraps some of the CoreGraphics layer of Quartz as well as some of the Cocoa text
|
19
|
+
layout system.
|
20
|
+
|
21
|
+
Doesn't currently cover all of the API, and it may never cover some of it.
|
22
|
+
Doesn't yet cover CoreImage or PDFKit, but these are obvious additions.
|
23
|
+
|
24
|
+
== SYNOPSYS:
|
25
|
+
|
26
|
+
require 'rubyquartz'
|
27
|
+
|
28
|
+
rgb = Quartz::ColorSpace.new(:name => ColorSpace::GENERIC_RGB)
|
29
|
+
ctx = Quartz::BitmapContext.new(100, 100, :colorspace => @rgb, :alpha => Bitmap::ALPHA_PREMULTIPLIED_FIRST)
|
30
|
+
# drawing commands
|
31
|
+
ctx.copy_image.png_data # or other extraction API
|
32
|
+
|
33
|
+
== REQUIREMENTS:
|
34
|
+
|
35
|
+
Mac OS X 10.4.X or greater
|
36
|
+
ruby 1.8.X or greater
|
37
|
+
|
38
|
+
== INSTALL:
|
39
|
+
|
40
|
+
$ ruby extconf.rb
|
41
|
+
$ make
|
42
|
+
$ sudo make install
|
43
|
+
|
44
|
+
== LICENSE:
|
45
|
+
|
46
|
+
(based on the MIT License)
|
47
|
+
|
48
|
+
Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
|
49
|
+
|
50
|
+
OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
|
51
|
+
|
52
|
+
Omni Source Code software is available from The Omni Group on their web
|
53
|
+
site at www.omnigroup.com.
|
54
|
+
|
55
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
56
|
+
copy of this software and associated documentation files (the "Software"),
|
57
|
+
to deal in the Software without restriction, including without limitation
|
58
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
59
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
60
|
+
Software is furnished to do so, subject to the following conditions:
|
61
|
+
|
62
|
+
Any original copyright notices and this permission notice shall be included
|
63
|
+
in all copies or substantial portions of the Software.
|
64
|
+
|
65
|
+
THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
66
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
67
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
68
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
69
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
70
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
71
|
+
DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
|
2
|
+
#
|
3
|
+
# OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
|
4
|
+
#
|
5
|
+
# Omni Source Code software is available from The Omni Group on their web
|
6
|
+
# site at www.omnigroup.com.
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
9
|
+
# copy of this software and associated documentation files (the "Software"),
|
10
|
+
# to deal in the Software without restriction, including without limitation
|
11
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
12
|
+
# and/or sell copies of the Software, and to permit persons to whom the
|
13
|
+
# Software is furnished to do so, subject to the following conditions:
|
14
|
+
#
|
15
|
+
# Any original copyright notices and this permission notice shall be included
|
16
|
+
# in all copies or substantial portions of the Software.
|
17
|
+
#
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
23
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
24
|
+
# DEALINGS IN THE SOFTWARE.
|
25
|
+
# -*- ruby -*-
|
26
|
+
|
27
|
+
require 'rubygems'
|
28
|
+
require 'hoe'
|
29
|
+
|
30
|
+
$: << './lib'
|
31
|
+
$: << './ext'
|
32
|
+
require 'rubyquartz'
|
33
|
+
|
34
|
+
Hoe.new('rubyquartz', Quartz::VERSION) do |p|
|
35
|
+
p.rubyforge_name = 'rubyquartz'
|
36
|
+
p.summary = 'Ruby Quartz is a bridge that allows Ruby programs to access the Mac OS X Quartz graphics libraries.'
|
37
|
+
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
38
|
+
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1].collect {|u| u.strip }
|
39
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
40
|
+
p.author = "Timothy J. Wood"
|
41
|
+
p.email = "tjw@omnigroup.com"
|
42
|
+
p.clean_globs = %w(diff diff.txt email.txt ri *.gem **/*~ **/*.o **/*.bundle ext/Makefile .gdb_history)
|
43
|
+
p.test_globs = ['test/**/tc_*.rb']
|
44
|
+
|
45
|
+
p.spec_extras = {
|
46
|
+
:extensions => ["ext/extconf.rb"],
|
47
|
+
:test_files => Dir[*p.test_globs]
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
# vim: syntax=Ruby
|
@@ -0,0 +1 @@
|
|
1
|
+
_Init_rubyquartz_api
|
data/ext/bitmap.c
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
|
3
|
+
|
4
|
+
OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
|
5
|
+
|
6
|
+
Omni Source Code software is available from The Omni Group on their web
|
7
|
+
site at www.omnigroup.com.
|
8
|
+
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
10
|
+
copy of this software and associated documentation files (the "Software"),
|
11
|
+
to deal in the Software without restriction, including without limitation
|
12
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
13
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
14
|
+
Software is furnished to do so, subject to the following conditions:
|
15
|
+
|
16
|
+
Any original copyright notices and this permission notice shall be included
|
17
|
+
in all copies or substantial portions of the Software.
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
25
|
+
DEALINGS IN THE SOFTWARE.
|
26
|
+
*/
|
27
|
+
|
28
|
+
#include "bitmap.h"
|
29
|
+
|
30
|
+
const char *BitmapClassName = "Bitmap";
|
31
|
+
|
32
|
+
VALUE bitmap_class;
|
33
|
+
|
34
|
+
|
35
|
+
static void _bitmap_free(QuartzBitmap *qb)
|
36
|
+
{
|
37
|
+
if (qb) {
|
38
|
+
if (qb->pixels)
|
39
|
+
free(qb->pixels);
|
40
|
+
free(qb);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
VALUE _bitmap_alloc(VALUE klass)
|
45
|
+
{
|
46
|
+
QuartzBitmap *bitmap = calloc(1, sizeof(*bitmap));
|
47
|
+
return Data_Wrap_Struct(klass, NULL, _bitmap_free, bitmap);
|
48
|
+
}
|
49
|
+
|
50
|
+
QuartzBitmap *bitmap_get(VALUE bitmap)
|
51
|
+
{
|
52
|
+
if (CLASS_OF(bitmap) != bitmap_class)
|
53
|
+
rb_raise(rb_eArgError, "Argument must be a Bitmap");
|
54
|
+
|
55
|
+
QuartzBitmap *qb;
|
56
|
+
Data_Get_Struct(bitmap, QuartzBitmap, qb);
|
57
|
+
|
58
|
+
if (!qb)
|
59
|
+
rb_raise(rb_eArgError, "Bitmap has no internal bitmap");
|
60
|
+
|
61
|
+
return qb;
|
62
|
+
}
|
63
|
+
|
64
|
+
static VALUE bitmap_init(VALUE self, VALUE Width, VALUE Height, VALUE BitsPerComponent, VALUE BytesPerRow, VALUE alpha_info, VALUE float_pixels, VALUE byte_order)
|
65
|
+
{
|
66
|
+
QuartzBitmap *qb = bitmap_get(self);
|
67
|
+
|
68
|
+
qb->width = NUM2INT(Width);
|
69
|
+
if (qb->width <= 0)
|
70
|
+
rb_raise(rb_eArgError, "Width must be greater than zero");
|
71
|
+
|
72
|
+
qb->height = NUM2INT(Height);
|
73
|
+
if (qb->height <= 0)
|
74
|
+
rb_raise(rb_eArgError, "Height must be greater than zero");
|
75
|
+
|
76
|
+
qb->bitsPerComponent = NUM2INT(BitsPerComponent);
|
77
|
+
if (qb->bitsPerComponent <= 0)
|
78
|
+
rb_raise(rb_eArgError, "Bits per component must be greater than zero");
|
79
|
+
|
80
|
+
qb->bytesPerRow = NUM2INT(BytesPerRow);
|
81
|
+
if (qb->bytesPerRow <= 0)
|
82
|
+
rb_raise(rb_eArgError, "Bytes per row must be greater than zero");
|
83
|
+
|
84
|
+
// We rely on CG to check the validity of the mask built up this way. We'll do enough checking to see that the components don't leak out the edges of their masks
|
85
|
+
unsigned int byteOrder = NUM2INT(byte_order);
|
86
|
+
if (byteOrder & ~kCGBitmapByteOrderMask)
|
87
|
+
rb_raise(rb_eArgError, "Out of range value for byte order");
|
88
|
+
|
89
|
+
unsigned int alphaInfo = NUM2INT(alpha_info);
|
90
|
+
if (alphaInfo & ~kCGBitmapAlphaInfoMask)
|
91
|
+
rb_raise(rb_eArgError, "Out of range value (0x%x) for alpha info", alphaInfo);
|
92
|
+
|
93
|
+
qb->bitmapInfo = (alphaInfo | byteOrder);
|
94
|
+
|
95
|
+
int floatPixelsType = TYPE(float_pixels);
|
96
|
+
if (floatPixelsType != T_NIL && floatPixelsType != T_FALSE)
|
97
|
+
qb->bitmapInfo |= kCGBitmapFloatComponents;
|
98
|
+
|
99
|
+
// Clear this for security. Starts as black/alpha.
|
100
|
+
size_t byteCount = qb->height * qb->bytesPerRow;
|
101
|
+
qb->pixels = calloc(1, byteCount);
|
102
|
+
|
103
|
+
return self;
|
104
|
+
}
|
105
|
+
|
106
|
+
|
107
|
+
void Init_bitmap()
|
108
|
+
{
|
109
|
+
bitmap_class = rb_define_class_under(module, BitmapClassName, rb_cObject);
|
110
|
+
rb_define_alloc_func(bitmap_class, _bitmap_alloc);
|
111
|
+
|
112
|
+
rb_define_private_method(bitmap_class, "_initialize", bitmap_init, 7);
|
113
|
+
|
114
|
+
// CGBitmapInfo-related constants
|
115
|
+
rb_define_const(bitmap_class, "ALPHA_NONE", INT2FIX(kCGImageAlphaNone));
|
116
|
+
rb_define_const(bitmap_class, "ALPHA_PREMULTIPLIED_LAST", INT2FIX(kCGImageAlphaPremultipliedLast));
|
117
|
+
rb_define_const(bitmap_class, "ALPHA_PREMULTIPLIED_FIRST", INT2FIX(kCGImageAlphaPremultipliedFirst));
|
118
|
+
rb_define_const(bitmap_class, "ALPHA_LAST", INT2FIX(kCGImageAlphaLast));
|
119
|
+
rb_define_const(bitmap_class, "ALPHA_FIRST", INT2FIX(kCGImageAlphaFirst));
|
120
|
+
rb_define_const(bitmap_class, "ALPHA_NONE_SKIP_LAST", INT2FIX(kCGImageAlphaNoneSkipLast));
|
121
|
+
rb_define_const(bitmap_class, "ALPHA_NONE_SKIP_FIRST", INT2FIX(kCGImageAlphaNoneSkipFirst));
|
122
|
+
rb_define_const(bitmap_class, "ALPHA_ONLY", INT2FIX(kCGImageAlphaOnly));
|
123
|
+
|
124
|
+
rb_define_const(bitmap_class, "BYTE_ORDER_DEFAULT", INT2FIX(kCGBitmapByteOrderDefault));
|
125
|
+
rb_define_const(bitmap_class, "BYTE_ORDER_16_LITTLE", INT2FIX(kCGBitmapByteOrder16Little));
|
126
|
+
rb_define_const(bitmap_class, "BYTE_ORDER_32_LITTLE", INT2FIX(kCGBitmapByteOrder32Little));
|
127
|
+
rb_define_const(bitmap_class, "BYTE_ORDER_16_BIG", INT2FIX(kCGBitmapByteOrder16Big));
|
128
|
+
rb_define_const(bitmap_class, "BYTE_ORDER_32_BIG", INT2FIX(kCGBitmapByteOrder32Big));
|
129
|
+
}
|
data/ext/bitmap.h
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
|
3
|
+
|
4
|
+
OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
|
5
|
+
|
6
|
+
Omni Source Code software is available from The Omni Group on their web
|
7
|
+
site at www.omnigroup.com.
|
8
|
+
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
10
|
+
copy of this software and associated documentation files (the "Software"),
|
11
|
+
to deal in the Software without restriction, including without limitation
|
12
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
13
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
14
|
+
Software is furnished to do so, subject to the following conditions:
|
15
|
+
|
16
|
+
Any original copyright notices and this permission notice shall be included
|
17
|
+
in all copies or substantial portions of the Software.
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
25
|
+
DEALINGS IN THE SOFTWARE.
|
26
|
+
*/
|
27
|
+
|
28
|
+
typedef struct _QuartzBitmap {
|
29
|
+
size_t width, height;
|
30
|
+
size_t bitsPerComponent;
|
31
|
+
size_t bytesPerRow;
|
32
|
+
CGBitmapInfo bitmapInfo;
|
33
|
+
void *pixels;
|
34
|
+
} QuartzBitmap;
|
35
|
+
|
36
|
+
extern void Init_bitmap(void);
|
37
|
+
extern VALUE bitmap_class;
|
38
|
+
extern QuartzBitmap *bitmap_get(VALUE bitmap);
|
@@ -0,0 +1,67 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2006, The Omni Group, Inc. All rights reserved.
|
3
|
+
|
4
|
+
OPEN PERMISSION TO USE AND REPRODUCE OMNI SOURCE CODE SOFTWARE
|
5
|
+
|
6
|
+
Omni Source Code software is available from The Omni Group on their web
|
7
|
+
site at www.omnigroup.com.
|
8
|
+
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
10
|
+
copy of this software and associated documentation files (the "Software"),
|
11
|
+
to deal in the Software without restriction, including without limitation
|
12
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
13
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
14
|
+
Software is furnished to do so, subject to the following conditions:
|
15
|
+
|
16
|
+
Any original copyright notices and this permission notice shall be included
|
17
|
+
in all copies or substantial portions of the Software.
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
25
|
+
DEALINGS IN THE SOFTWARE.
|
26
|
+
*/
|
27
|
+
|
28
|
+
#include "context.h"
|
29
|
+
|
30
|
+
#include "colorspace.h"
|
31
|
+
#include "bitmap.h"
|
32
|
+
|
33
|
+
const char *BitmapContextClassName = "BitmapContext";
|
34
|
+
|
35
|
+
VALUE bitmap_context_class;
|
36
|
+
|
37
|
+
|
38
|
+
CGContextRef bitmap_context_get(VALUE self)
|
39
|
+
{
|
40
|
+
// CGBitmapContext doesn't have its own CFTypeID.
|
41
|
+
// TODO: Subclassability?
|
42
|
+
if (CLASS_OF(self) != bitmap_context_class)
|
43
|
+
rb_raise(rb_eArgError, "Argument must be a BitmapContext");
|
44
|
+
|
45
|
+
return context_get(self);
|
46
|
+
}
|
47
|
+
|
48
|
+
// TODO: Make color space optional (default to generic rgb)?
|
49
|
+
static VALUE bitmap_context_init(VALUE self, VALUE bitmap, VALUE colorSpace)
|
50
|
+
{
|
51
|
+
CGContextRef *ctx;
|
52
|
+
Data_Get_Struct(self, CGContextRef, ctx);
|
53
|
+
if (!ctx)
|
54
|
+
rb_raise(rb_eException, "Context not initialized correctly");
|
55
|
+
|
56
|
+
CGColorSpaceRef cs = colorspace_get(colorSpace);
|
57
|
+
QuartzBitmap *qb = bitmap_get(bitmap);
|
58
|
+
|
59
|
+
*ctx = CGBitmapContextCreate(qb->pixels, qb->width, qb->height, qb->bitsPerComponent, qb->bytesPerRow, cs, qb->bitmapInfo);
|
60
|
+
return self;
|
61
|
+
}
|
62
|
+
|
63
|
+
void Init_bitmap_context()
|
64
|
+
{
|
65
|
+
bitmap_context_class = rb_define_class_under(module, BitmapContextClassName, context_class);
|
66
|
+
rb_define_private_method(bitmap_context_class, "_initialize", bitmap_context_init, 2);
|
67
|
+
}
|