aslakhellesoy-png 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +18 -0
- data/Manifest.txt +13 -0
- data/README.txt +65 -0
- data/Rakefile +19 -0
- data/example/lines.rb +20 -0
- data/example/profile.rb +16 -0
- data/example/profile_lines.rb +37 -0
- data/lib/png.rb +584 -0
- data/lib/png/default_font.png +0 -0
- data/lib/png/font.rb +73 -0
- data/lib/png/pie.rb +47 -0
- data/lib/png/reader.rb +139 -0
- data/test/test_png.rb +529 -0
- data/test/test_png_font.rb +77 -0
- data/test/test_png_reader.rb +87 -0
- metadata +94 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
require 'png/font'
|
5
|
+
|
6
|
+
class TestPngFont < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@font = PNG::Font.default
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_height
|
13
|
+
assert_equal 6, @font.height
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_width
|
17
|
+
assert_equal 6, @font.width
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_coordinates
|
21
|
+
assert_equal [ 0, 0, 5, 5], @font.coordinates('(')
|
22
|
+
assert_equal [ 0, 6, 5, 11], @font.coordinates('0')
|
23
|
+
assert_equal [ 0, 12, 5, 17], @font.coordinates('a')
|
24
|
+
assert_equal [ 0, 18, 5, 23], @font.coordinates('A')
|
25
|
+
|
26
|
+
assert_equal [42, 12, 47, 17], @font.coordinates('h')
|
27
|
+
assert_equal [42, 18, 47, 23], @font.coordinates('H')
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_index
|
31
|
+
expected = "
|
32
|
+
0000....0000
|
33
|
+
00..0000..00
|
34
|
+
00..0000..00
|
35
|
+
00........00
|
36
|
+
00..0000..00
|
37
|
+
000000000000
|
38
|
+
".strip + "\n"
|
39
|
+
|
40
|
+
assert_equal expected, @font['A'].to_s
|
41
|
+
|
42
|
+
expected = "
|
43
|
+
00000000..00
|
44
|
+
00000000..00
|
45
|
+
00000000..00
|
46
|
+
00000000..00
|
47
|
+
00000000..00
|
48
|
+
000000000000
|
49
|
+
".strip + "\n"
|
50
|
+
|
51
|
+
assert_equal expected, @font['l'].to_s
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_index_identity
|
55
|
+
assert_same @font['A'], @font['A']
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_annotate
|
59
|
+
canvas = PNG::Canvas.new 30, 6, PNG::Color::White
|
60
|
+
canvas.annotate "hello", 0, 0
|
61
|
+
|
62
|
+
expected = "
|
63
|
+
00..0000000000000000000000000000..0000000000..00000000000000
|
64
|
+
00......000000......000000000000..0000000000..000000....0000
|
65
|
+
00..0000..00..0000....0000000000..0000000000..0000..0000..00
|
66
|
+
00..0000..00..00..00000000000000..0000000000..0000..0000..00
|
67
|
+
00..0000..0000......000000000000..0000000000..000000....0000
|
68
|
+
000000000000000000000000000000000000000000000000000000000000
|
69
|
+
".strip + "\n"
|
70
|
+
|
71
|
+
assert_equal expected, canvas.to_s
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_identity
|
75
|
+
assert_same PNG::Font.default, PNG::Font.default
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
require 'png/reader'
|
5
|
+
|
6
|
+
class TestPngReader < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@canvas = PNG::Canvas.new 5, 10, PNG::Color::White
|
10
|
+
@png = PNG.new @canvas
|
11
|
+
|
12
|
+
@IHDR_length = "\000\000\000\r"
|
13
|
+
@IHDR_crc = "\2152\317\275"
|
14
|
+
@IHDR_crc_value = @IHDR_crc.unpack('N').first
|
15
|
+
@IHDR_data = "\000\000\000\n\000\000\000\n\b\006\000\000\000"
|
16
|
+
@IHDR_chunk = "#{@IHDR_length}IHDR#{@IHDR_data}#{@IHDR_crc}"
|
17
|
+
|
18
|
+
@blob = <<-EOF.unpack('m*').first
|
19
|
+
iVBORw0KGgoAAAANSUhEUgAAAAUAAAAKCAYAAAB8OZQwAAAAD0lEQVR4nGP4
|
20
|
+
jwUwDGVBALuJxzlQugpEAAAAAElFTkSuQmCC
|
21
|
+
EOF
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_class_check_crc
|
25
|
+
assert PNG.check_crc('IHDR', @IHDR_data, @IHDR_crc_value)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_class_check_crc_exception
|
29
|
+
begin
|
30
|
+
PNG.check_crc('IHDR', @IHDR_data, @IHDR_crc_value + 1)
|
31
|
+
rescue ArgumentError => e
|
32
|
+
assert_equal "Invalid CRC encountered in IHDR chunk", e.message
|
33
|
+
else
|
34
|
+
flunk "exception wasn't raised"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_class_read_chunk
|
39
|
+
data = PNG.read_chunk 'IHDR', @IHDR_chunk
|
40
|
+
|
41
|
+
assert_equal @IHDR_data, data
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_class_read_IDAT
|
45
|
+
canvas = PNG::Canvas.new 5, 10, PNG::Color::White
|
46
|
+
|
47
|
+
data = ([ 0, [255] * (4*5) ] * 10)
|
48
|
+
data = data.flatten.map { |n| n.chr }.join
|
49
|
+
data = Zlib::Deflate.deflate(data)
|
50
|
+
|
51
|
+
PNG.read_IDAT data, 8, PNG::RGBA, canvas
|
52
|
+
|
53
|
+
assert_equal @blob, PNG.new(canvas).to_blob
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_class_read_IHDR
|
57
|
+
bit_depth, color_type, width, height = PNG.read_IHDR @IHDR_data
|
58
|
+
assert_equal 10, width
|
59
|
+
assert_equal 10, height
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_class_load_metadata
|
63
|
+
png, canvas = util_png
|
64
|
+
|
65
|
+
width, height, bit_depth = PNG.load(png.to_blob, :metadata)
|
66
|
+
|
67
|
+
assert_equal 2, width
|
68
|
+
assert_equal 2, height
|
69
|
+
assert_equal 8, bit_depth
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_class_load
|
73
|
+
png, canvas = util_png
|
74
|
+
|
75
|
+
new_png = PNG.load(png.to_blob)
|
76
|
+
|
77
|
+
assert_equal canvas.data, new_png.data
|
78
|
+
end
|
79
|
+
|
80
|
+
def util_png
|
81
|
+
canvas = PNG::Canvas.new 2, 2
|
82
|
+
canvas[0, 0] = PNG::Color::Black
|
83
|
+
canvas[1, 1] = PNG::Color::Black
|
84
|
+
png = PNG.new canvas
|
85
|
+
return png, canvas
|
86
|
+
end
|
87
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aslakhellesoy-png
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Davis
|
8
|
+
- Eric Hodel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-06-22 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: RubyInline
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 3.5.0
|
25
|
+
version:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: hoe
|
28
|
+
type: :development
|
29
|
+
version_requirement:
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.12.2
|
35
|
+
version:
|
36
|
+
description: PNG is an almost-pure-ruby PNG library. It lets you write a PNG without any C libraries.
|
37
|
+
email:
|
38
|
+
- ryand-ruby@zenspider.com
|
39
|
+
- drbrain@segment7.net
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- History.txt
|
46
|
+
- Manifest.txt
|
47
|
+
- README.txt
|
48
|
+
files:
|
49
|
+
- History.txt
|
50
|
+
- Manifest.txt
|
51
|
+
- README.txt
|
52
|
+
- Rakefile
|
53
|
+
- example/lines.rb
|
54
|
+
- example/profile.rb
|
55
|
+
- example/profile_lines.rb
|
56
|
+
- lib/png.rb
|
57
|
+
- lib/png/default_font.png
|
58
|
+
- lib/png/font.rb
|
59
|
+
- lib/png/pie.rb
|
60
|
+
- lib/png/reader.rb
|
61
|
+
- test/test_png.rb
|
62
|
+
- test/test_png_font.rb
|
63
|
+
- test/test_png_reader.rb
|
64
|
+
has_rdoc: false
|
65
|
+
homepage: http://seattlerb.rubyforge.org/
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options:
|
68
|
+
- --main
|
69
|
+
- README.txt
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
version:
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project: seattlerb
|
87
|
+
rubygems_version: 1.2.0
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: PNG is an almost-pure-ruby PNG library
|
91
|
+
test_files:
|
92
|
+
- test/test_png.rb
|
93
|
+
- test/test_png_font.rb
|
94
|
+
- test/test_png_reader.rb
|