axon 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/.gemtest +0 -0
  2. data/CHANGELOG.rdoc +3 -0
  3. data/README.rdoc +104 -0
  4. data/Rakefile +30 -0
  5. data/TODO.rdoc +12 -0
  6. data/ext/axon/axon.c +20 -0
  7. data/ext/axon/bilinear_interpolation.c +115 -0
  8. data/ext/axon/extconf.rb +21 -0
  9. data/ext/axon/iccjpeg.c +248 -0
  10. data/ext/axon/iccjpeg.h +73 -0
  11. data/ext/axon/interpolation.h +7 -0
  12. data/ext/axon/jpeg_common.c +118 -0
  13. data/ext/axon/jpeg_common.h +37 -0
  14. data/ext/axon/jpeg_native_writer.c +248 -0
  15. data/ext/axon/jpeg_reader.c +774 -0
  16. data/ext/axon/nearest_neighbor_interpolation.c +50 -0
  17. data/ext/axon/png_common.c +21 -0
  18. data/ext/axon/png_common.h +18 -0
  19. data/ext/axon/png_native_writer.c +166 -0
  20. data/ext/axon/png_reader.c +381 -0
  21. data/lib/axon/axon.so +0 -0
  22. data/lib/axon/bilinear_scaler.rb +60 -0
  23. data/lib/axon/cropper.rb +35 -0
  24. data/lib/axon/fit.rb +67 -0
  25. data/lib/axon/jpeg_writer.rb +41 -0
  26. data/lib/axon/nearest_neighbor_scaler.rb +39 -0
  27. data/lib/axon/png_writer.rb +35 -0
  28. data/lib/axon/scaler.rb +41 -0
  29. data/lib/axon/solid.rb +23 -0
  30. data/lib/axon.rb +45 -0
  31. data/test/_test_readme.rb +34 -0
  32. data/test/helper.rb +17 -0
  33. data/test/reader_tests.rb +115 -0
  34. data/test/stress_tests.rb +71 -0
  35. data/test/test_bilinear_scaler.rb +9 -0
  36. data/test/test_cropper.rb +9 -0
  37. data/test/test_exif.rb +39 -0
  38. data/test/test_generator.rb +10 -0
  39. data/test/test_icc.rb +18 -0
  40. data/test/test_jpeg.rb +9 -0
  41. data/test/test_jpeg_reader.rb +109 -0
  42. data/test/test_jpeg_writer.rb +26 -0
  43. data/test/test_nearest_neighbor_scaler.rb +13 -0
  44. data/test/test_png.rb +9 -0
  45. data/test/test_png_reader.rb +15 -0
  46. data/test/test_png_writer.rb +13 -0
  47. data/test/writer_tests.rb +179 -0
  48. metadata +148 -0
@@ -0,0 +1,109 @@
1
+ require 'helper'
2
+
3
+ module Axon
4
+ class TestJPEGReader < AxonTestCase
5
+ include ReaderTests
6
+
7
+ def setup
8
+ super
9
+ @readerclass = JPEGReader
10
+ @data = @image.to_jpeg.data
11
+ @io_in = StringIO.new @data
12
+ @reader = @readerclass.new(@io_in)
13
+ end
14
+
15
+ def test_in_color_model
16
+ assert_equal :YCbCr, @reader.in_color_model
17
+ end
18
+
19
+ def test_set_in_color_model
20
+ @reader.in_color_model = :RGB
21
+ assert_equal :RGB, @reader.in_color_model
22
+
23
+ assert_raises(RuntimeError){ @reader.in_color_model = "foobar" }
24
+ end
25
+
26
+ def test_set_out_color_model
27
+ @reader.color_model = :YCbCr
28
+ assert_equal :YCbCr, @reader.color_model
29
+
30
+ assert_raises(RuntimeError){ @reader.color_model = "foobar" }
31
+ end
32
+
33
+ def test_scale_num
34
+ assert @reader.scale_num > 0
35
+ end
36
+
37
+ def test_set_scale_num
38
+ @reader.scale_num = 5
39
+ assert_equal 5, @reader.scale_num
40
+ end
41
+
42
+ def test_scale_denom
43
+ assert @reader.scale_denom > 0
44
+ end
45
+
46
+ def test_set_scale_denom
47
+ @reader.scale_denom = 8
48
+
49
+ assert_equal 8, @reader.scale_denom
50
+ end
51
+
52
+ def test_scale_denom_affects_image_size
53
+ pre_width = @reader.width
54
+ pre_height = @reader.height
55
+
56
+ @reader.scale_denom = 2
57
+
58
+ assert @reader.width < pre_width
59
+ assert @reader.height < pre_height
60
+ end
61
+
62
+ def test_scale_denom_affects_written_image
63
+ pre_width = @reader.width
64
+ pre_height = @reader.height
65
+
66
+ writer = JPEGWriter.new(@reader)
67
+ @reader.scale_denom = 2
68
+
69
+ new_velvet_io = StringIO.new(writer.data)
70
+
71
+ new_velvet_reader = JPEGReader.new(new_velvet_io)
72
+
73
+ assert new_velvet_reader.width < pre_width
74
+ assert new_velvet_reader.height < pre_height
75
+ end
76
+
77
+ def test_dct_method
78
+ assert_equal JPEGReader::DEFAULT_DCT, @reader.dct_method
79
+ end
80
+
81
+ def test_set_dct_method
82
+ @reader.dct_method = :IFAST
83
+
84
+ assert_equal :IFAST, @reader.dct_method
85
+ end
86
+
87
+ def test_markers_read_by_default
88
+ refute_empty @reader[:APP0]
89
+ end
90
+
91
+ def test_empty_marker_prevents_reads
92
+ @io_in.rewind
93
+ r = JPEGReader.new @io_in, []
94
+ assert_empty r[:APP0]
95
+ end
96
+
97
+ def test_marker_read
98
+ assert_match(/^JFIF/, @reader[:APP0].first)
99
+ end
100
+
101
+ def test_no_configuration_after_initiated
102
+ @reader.each do |sl|
103
+ assert_raises(RuntimeError) { @reader.dct_method = :IFAST }
104
+ assert_raises(RuntimeError) { @reader.scale_denom = 4 }
105
+ break
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,26 @@
1
+ require 'helper'
2
+
3
+ module Axon
4
+ class TestJPEGWriter < AxonTestCase
5
+ include WriterTests
6
+
7
+ def setup
8
+ super
9
+ @writerclass = JPEGWriter
10
+ @writer = @image.to_jpeg
11
+ end
12
+
13
+ def test_output_has_jpeg_header
14
+ string = @writer.data
15
+
16
+ assert_equal "\xFF\xD8\xFF\xE0", string[0..3]
17
+ assert_equal "JFIF\x00", string[6..10]
18
+ end
19
+
20
+ def test_bad_bufsize
21
+ assert_raises RuntimeError do
22
+ @writer.write(@io_out, 0)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ require 'helper'
2
+
3
+ module Axon
4
+ class TestNearestNeighborScaler < AxonTestCase
5
+ def test_resize_ratio
6
+ @image.scale_nearest_neighbor(0.9).write_jpeg(@io_out)
7
+ end
8
+
9
+ def test_resize_dimensions
10
+ @image.scale_nearest_neighbor(100, 200).write_jpeg(@io_out)
11
+ end
12
+ end
13
+ end
data/test/test_png.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "helper"
2
+
3
+ module Axon
4
+ class TestPNG < AxonTestCase
5
+ def test_version
6
+ assert PNG_LIB_VERSION >= 10200
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ require 'helper'
2
+
3
+ module Axon
4
+ class TestPNGReader < AxonTestCase
5
+ include ReaderTests
6
+
7
+ def setup
8
+ super
9
+ @readerclass = PNGReader
10
+ @data = @image.to_png.data
11
+ @io_in = StringIO.new @data
12
+ @reader = PNGReader.new(@io_in)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ require 'helper'
2
+
3
+ module Axon
4
+ class TestPNGWriter < AxonTestCase
5
+ include WriterTests
6
+
7
+ def setup
8
+ super
9
+ @writerclass = PNGWriter
10
+ @writer = @image.to_png
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,179 @@
1
+ module Axon
2
+ module WriterTests
3
+ def test_writes_something
4
+ @writer.write(@io_out)
5
+ refute @io_out.string.empty?
6
+ end
7
+
8
+ class ZeroHeightImage < Solid
9
+ def height; 0; end
10
+ end
11
+
12
+ class NegativeHeightImage < Solid
13
+ def height; -1; end
14
+ end
15
+
16
+ class NilHeightImage < Solid
17
+ def height; nil; end
18
+ end
19
+
20
+ def test_bad_dimension
21
+ i = ZeroHeightImage.new 10, 15, @velvet
22
+ writer = @writerclass.new(i)
23
+
24
+ assert_raises RuntimeError do
25
+ writer.write(@io_out)
26
+ end
27
+
28
+ i = NegativeHeightImage.new 10, 15, @velvet
29
+ writer = @writerclass.new(i)
30
+
31
+ assert_raises RuntimeError do
32
+ writer.write(@io_out)
33
+ end
34
+
35
+ i = NilHeightImage.new 10, 15, @velvet
36
+ writer = @writerclass.new(i)
37
+
38
+ assert_raises TypeError do
39
+ writer.write(@io_out)
40
+ end
41
+ end
42
+
43
+ class NilColorModelImage < Solid
44
+ def color_model; nil; end
45
+ end
46
+
47
+ def test_bad_color_model
48
+ i = NilColorModelImage.new 10, 15, @velvet
49
+ writer = @writerclass.new(i)
50
+
51
+ assert_raises RuntimeError do
52
+ writer.write(@io_out)
53
+ end
54
+ end
55
+
56
+ class TooManyComponentsImage < Solid
57
+ def components; 15; end
58
+ end
59
+
60
+ class ZeroComponentsImage < Solid
61
+ def components; 0; end
62
+ end
63
+
64
+ class NilComponentsImage < Solid
65
+ def components; nil; end
66
+ end
67
+
68
+ def test_bad_components
69
+ i = NilComponentsImage.new 10, 15, @velvet
70
+ writer = @writerclass.new(i)
71
+
72
+ assert_raises TypeError do
73
+ writer.write(@io_out)
74
+ end
75
+
76
+ i = TooManyComponentsImage.new 10, 15, @velvet
77
+ writer = @writerclass.new(i)
78
+
79
+ assert_raises RuntimeError do
80
+ writer.write(@io_out)
81
+ end
82
+
83
+ i = ZeroComponentsImage.new 10, 15, @velvet
84
+ writer = @writerclass.new(i)
85
+
86
+ assert_raises RuntimeError do
87
+ writer.write(@io_out)
88
+ end
89
+ end
90
+
91
+ class RaisingIO
92
+ def write(data)
93
+ raise 'hell'
94
+ end
95
+ end
96
+
97
+ def test_io_raises_exception
98
+ io = RaisingIO.new
99
+
100
+ assert_raises RuntimeError do
101
+ @writer.write(io)
102
+ end
103
+ end
104
+
105
+ class NilImage < Solid
106
+ def each
107
+ 10.times{ yield nil }
108
+ end
109
+ end
110
+
111
+ def test_image_scanlines_yield_nil
112
+ image = NilImage.new(10, 15, @velvet)
113
+ writer = @writerclass.new(image)
114
+
115
+ assert_raises RuntimeError do
116
+ writer.write(@io_out)
117
+ end
118
+ end
119
+
120
+ class TooManyScanLinesImage < Solid
121
+ def each
122
+ super
123
+ yield(@color * width)
124
+ end
125
+ end
126
+
127
+ def test_image_yields_too_many_scanlines
128
+ image = TooManyScanLinesImage.new 10, 15, @velvet
129
+ writer = @writerclass.new(image)
130
+ writer.write(@io_out)
131
+ end
132
+
133
+ class TooFewScanLinesImage < Solid
134
+ def each
135
+ yield(@color * width)
136
+ end
137
+ end
138
+
139
+ def test_image_yields_too_few_scanlines
140
+ image = TooFewScanLinesImage.new 10, 15, @velvet
141
+ writer = @writerclass.new(image)
142
+
143
+ assert_raises RuntimeError do
144
+ writer.write(@io_out)
145
+ end
146
+ end
147
+
148
+ class RaisingImage < Solid
149
+ def each
150
+ raise 'chickens'
151
+ end
152
+ end
153
+
154
+ def test_image_scanlines_raises_exception
155
+ image = RaisingImage.new(10, 15, @velvet)
156
+ writer = @writerclass.new(image)
157
+
158
+ assert_raises RuntimeError do
159
+ writer.write(@io_out)
160
+ end
161
+ end
162
+
163
+ class BigWidthImage < Solid
164
+ def each
165
+ sl = @color * width * 10
166
+ height.times { yield sl }
167
+ end
168
+ end
169
+
170
+ def test_image_scanlines_returns_too_much
171
+ image = BigWidthImage.new(10, 15, @velvet)
172
+ writer = @writerclass.new(image)
173
+
174
+ assert_raises RuntimeError do
175
+ writer.write(@io_out)
176
+ end
177
+ end
178
+ end
179
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: axon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Timothy Elliott
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-16 00:00:00.000000000 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake-compiler
17
+ requirement: &8982100 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *8982100
26
+ - !ruby/object:Gem::Dependency
27
+ name: hoe
28
+ requirement: &8981560 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *8981560
37
+ description: ! 'Axon is a library for streaming and manipulating JPEG and PNG images.
38
+ It scales
39
+
40
+ and crops images along the way.
41
+
42
+
43
+ By limiting its functionality, Axon is able to depend on two ubiquitous
44
+
45
+ libraries: libjpeg and libpng. Axon can be installed anywhere those libraries
46
+
47
+ are available.
48
+
49
+
50
+ Axon never stores an entire image in memory. All images and operations are
51
+
52
+ streamed from an input to an output. As a result, memory requirements and
53
+
54
+ latency are low.'
55
+ email:
56
+ - tle@holymonkey.com
57
+ executables: []
58
+ extensions:
59
+ - ext/axon/extconf.rb
60
+ extra_rdoc_files: []
61
+ files:
62
+ - CHANGELOG.rdoc
63
+ - README.rdoc
64
+ - Rakefile
65
+ - TODO.rdoc
66
+ - ext/axon/bilinear_interpolation.c
67
+ - ext/axon/extconf.rb
68
+ - ext/axon/iccjpeg.c
69
+ - ext/axon/iccjpeg.h
70
+ - ext/axon/interpolation.h
71
+ - ext/axon/jpeg_common.c
72
+ - ext/axon/jpeg_common.h
73
+ - ext/axon/jpeg_native_writer.c
74
+ - ext/axon/jpeg_reader.c
75
+ - ext/axon/axon.c
76
+ - ext/axon/nearest_neighbor_interpolation.c
77
+ - ext/axon/png_common.c
78
+ - ext/axon/png_common.h
79
+ - ext/axon/png_native_writer.c
80
+ - ext/axon/png_reader.c
81
+ - lib/axon.rb
82
+ - lib/axon/bilinear_scaler.rb
83
+ - lib/axon/cropper.rb
84
+ - lib/axon/fit.rb
85
+ - lib/axon/jpeg_writer.rb
86
+ - lib/axon/axon.so
87
+ - lib/axon/nearest_neighbor_scaler.rb
88
+ - lib/axon/png_writer.rb
89
+ - lib/axon/scaler.rb
90
+ - lib/axon/solid.rb
91
+ - test/_test_readme.rb
92
+ - test/helper.rb
93
+ - test/reader_tests.rb
94
+ - test/stress_tests.rb
95
+ - test/test_bilinear_scaler.rb
96
+ - test/test_cropper.rb
97
+ - test/test_exif.rb
98
+ - test/test_generator.rb
99
+ - test/test_icc.rb
100
+ - test/test_jpeg.rb
101
+ - test/test_jpeg_reader.rb
102
+ - test/test_jpeg_writer.rb
103
+ - test/test_nearest_neighbor_scaler.rb
104
+ - test/test_png.rb
105
+ - test/test_png_reader.rb
106
+ - test/test_png_writer.rb
107
+ - test/writer_tests.rb
108
+ - .gemtest
109
+ has_rdoc: true
110
+ homepage: http://github.com/ender672/axon
111
+ licenses: []
112
+ post_install_message:
113
+ rdoc_options:
114
+ - --main
115
+ - README.rdoc
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project: axon
132
+ rubygems_version: 1.6.2
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: Axon is a library for streaming and manipulating JPEG and PNG images
136
+ test_files:
137
+ - test/test_jpeg.rb
138
+ - test/test_png_reader.rb
139
+ - test/test_nearest_neighbor_scaler.rb
140
+ - test/test_jpeg_reader.rb
141
+ - test/test_exif.rb
142
+ - test/test_icc.rb
143
+ - test/test_jpeg_writer.rb
144
+ - test/test_cropper.rb
145
+ - test/test_png_writer.rb
146
+ - test/test_generator.rb
147
+ - test/test_bilinear_scaler.rb
148
+ - test/test_png.rb