oily_png 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oily_png (0.0.7)
4
+ oily_png (0.0.8)
5
5
  chunky_png (~> 0.10.2)
6
6
 
7
7
  GEM
@@ -3,11 +3,15 @@
3
3
  ///// Pixel encoding functions //////////////////////////////////////////
4
4
 
5
5
  void oily_png_encode_pixel_grayscale(PIXEL pixel, BYTE* bytes, int pos, VALUE palette) {
6
- bytes[pos] = R_BYTE(pixel);
6
+ // Assume R == G == B. ChunkyPNG uses the B byte fot performance reasons.
7
+ // We'll uses the same to reomain compatible with ChunkyPNG.
8
+ bytes[pos] = B_BYTE(pixel);
7
9
  }
8
10
 
9
11
  void oily_png_encode_pixel_grayscale_alpha(PIXEL pixel, BYTE* bytes, int pos, VALUE palette) {
10
- bytes[pos + 0] = R_BYTE(pixel);
12
+ // Assume R == G == B. ChunkyPNG uses the B byte fot performance reasons.
13
+ // We'll uses the same to reomain compatible with ChunkyPNG.
14
+ bytes[pos + 0] = B_BYTE(pixel);
11
15
  bytes[pos + 1] = A_BYTE(pixel);
12
16
  }
13
17
 
@@ -80,7 +84,7 @@ VALUE oily_png_encode_png_image_pass_to_stream(VALUE self, VALUE stream, VALUE c
80
84
  if (RARRAY_LEN(pixels) != width * height) {
81
85
  rb_raise(rb_eRuntimeError, "The number of pixels does not match the canvas dimensions.");
82
86
  }
83
-
87
+
84
88
  // Get the encoding palette if we're encoding to an indexed bytestream.
85
89
  VALUE palette = Qnil;
86
90
  if (FIX2INT(color_mode) == OILY_PNG_COLOR_INDEXED) {
@@ -109,10 +113,10 @@ VALUE oily_png_encode_png_image_pass_to_stream(VALUE self, VALUE stream, VALUE c
109
113
  PIXEL pixel;
110
114
  int x, y, pos;
111
115
  for (y = 0; y < height; y++) {
112
- bytes[line_size * y] = FIX2INT(filtering);
116
+ bytes[line_size * y] = (BYTE) FIX2INT(filtering);
113
117
 
114
118
  for (x = 0; x < width; x++) {
115
- pixel = NUM2UINT(rb_ary_entry(pixels, y * height + x));
119
+ pixel = NUM2UINT(rb_ary_entry(pixels, y * width + x));
116
120
  pos = (line_size * y) + (pixel_size * x) + 1;
117
121
  pixel_encoder(pixel, bytes, pos, palette);
118
122
  }
@@ -1,10 +1,10 @@
1
1
  #ifndef PNG_ENCODING_H
2
2
  #define PNG_ENCODING_H
3
3
 
4
- #define R_BYTE(pixel) ((BYTE) ((pixel & (PIXEL) 0xff000000) >> 24))
5
- #define G_BYTE(pixel) ((BYTE) ((pixel & (PIXEL) 0x00ff0000) >> 16))
6
- #define B_BYTE(pixel) ((BYTE) ((pixel & (PIXEL) 0x0000ff00) >> 8))
7
- #define A_BYTE(pixel) ((BYTE) ((pixel & (PIXEL) 0x000000ff)))
4
+ #define R_BYTE(pixel) ((BYTE) (((pixel) & (PIXEL) 0xff000000) >> 24))
5
+ #define G_BYTE(pixel) ((BYTE) (((pixel) & (PIXEL) 0x00ff0000) >> 16))
6
+ #define B_BYTE(pixel) ((BYTE) (((pixel) & (PIXEL) 0x0000ff00) >> 8))
7
+ #define A_BYTE(pixel) ((BYTE) (((pixel) & (PIXEL) 0x000000ff)))
8
8
 
9
9
  #define FILTER_BYTE(byte, adjustment) byte = (BYTE) (((byte) - (adjustment)) & 0x000000ff)
10
10
 
data/lib/oily_png.rb CHANGED
@@ -2,7 +2,7 @@ require 'chunky_png'
2
2
 
3
3
  module OilyPNG
4
4
 
5
- VERSION = "0.0.7"
5
+ VERSION = "0.0.8"
6
6
 
7
7
  def self.included(base)
8
8
  base::Canvas.send(:extend, OilyPNG::PNGDecoding)
data/oily_png.gemspec CHANGED
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
4
4
 
5
5
  # Do not change the version and date fields by hand. This will be done
6
6
  # automatically by the gem release script.
7
- s.version = "0.0.7"
8
- s.date = "2010-10-07"
7
+ s.version = "0.0.8"
8
+ s.date = "2010-10-08"
9
9
 
10
10
  s.summary = "Native mixin to speed up ChunkyPNG"
11
11
  s.description = <<-EOT
@@ -29,6 +29,6 @@ Gem::Specification.new do |s|
29
29
 
30
30
  # Do not change the files and test_files fields by hand. This will be done
31
31
  # automatically by the gem release script.
32
- s.files = %w(.gitignore Gemfile Gemfile.lock LICENSE README.rdoc Rakefile ext/oily_png/extconf.rb ext/oily_png/oily_png_ext.c ext/oily_png/oily_png_ext.h ext/oily_png/png_decoding.c ext/oily_png/png_decoding.h ext/oily_png/png_encoding.c ext/oily_png/png_encoding.h lib/oily_png.rb oily_png.gemspec spec/decoding_spec.rb spec/encoding_spec.rb spec/resources/gray.png spec/resources/interlaced.png spec/resources/operations.png spec/spec_helper.rb tasks/github-gem.rake)
32
+ s.files = %w(.gitignore Gemfile Gemfile.lock LICENSE README.rdoc Rakefile ext/oily_png/extconf.rb ext/oily_png/oily_png_ext.c ext/oily_png/oily_png_ext.h ext/oily_png/png_decoding.c ext/oily_png/png_decoding.h ext/oily_png/png_encoding.c ext/oily_png/png_encoding.h lib/oily_png.rb oily_png.gemspec spec/decoding_spec.rb spec/encoding_spec.rb spec/resources/gray.png spec/resources/interlaced.png spec/resources/nonsquare.png spec/resources/square.png spec/spec_helper.rb tasks/github-gem.rake tasks/testing.rake)
33
33
  s.test_files = %w(spec/decoding_spec.rb spec/encoding_spec.rb)
34
34
  end
@@ -4,12 +4,12 @@ describe OilyPNG::PNGDecoding do
4
4
 
5
5
  it "should call Color.bytesize in the pure ruby version" do
6
6
  ChunkyPNG::Color.should_receive(:bytesize).and_return(3)
7
- ChunkyPNG::Canvas.from_file(resource_file('operations.png'))
7
+ ChunkyPNG::Canvas.from_file(resource_file('square.png'))
8
8
  end
9
9
 
10
10
  it "should not call Color.bytesize in the native version" do
11
11
  ChunkyPNG::Color.should_not_receive(:bytesize)
12
- OilyCanvas.from_file(resource_file('operations.png'))
12
+ OilyCanvas.from_file(resource_file('square.png'))
13
13
  end
14
14
 
15
15
  it "should decode an interlaced image correctly" do
@@ -19,7 +19,7 @@ describe OilyPNG::PNGDecoding do
19
19
  end
20
20
 
21
21
  context 'decoding different filtering methods' do
22
- before(:all) { @reference = ChunkyPNG::Canvas.from_file(resource_file('operations.png'))}
22
+ before(:all) { @reference = ChunkyPNG::Canvas.from_file(resource_file('nonsquare.png'))}
23
23
 
24
24
  it "should decode NONE filtering exactly the same as ChunkyPNG" do
25
25
  filtered_data = @reference.to_blob(:filtering => ChunkyPNG::FILTER_NONE)
@@ -46,7 +46,7 @@ describe OilyPNG::PNGEncoding do
46
46
 
47
47
  context 'encoding different filters' do
48
48
  before do
49
- @canvas = ChunkyPNG::Canvas.from_file(resource_file('operations.png'))
49
+ @canvas = ChunkyPNG::Canvas.from_file(resource_file('nonsquare.png'))
50
50
  @oily_canvas = OilyCanvas.from_canvas(@canvas)
51
51
  end
52
52
 
Binary file
File without changes
@@ -0,0 +1,51 @@
1
+ task(:verify, :png_file) do |task, args|
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ Bundler.setup
5
+
6
+ require 'chunky_png'
7
+ require 'oily_png/oily_png_ext'
8
+
9
+ class OilyPNG::Canvas < ChunkyPNG::Canvas
10
+ extend OilyPNG::PNGDecoding
11
+ include OilyPNG::PNGEncoding
12
+ end
13
+
14
+ file = args[:png_file] || ENV['PNG_FILE']
15
+ raise "Please specify a valid PNG file to verify!" unless File.exist?(file.to_s)
16
+
17
+ decoding_reference = ChunkyPNG::Canvas.from_file(file)
18
+ decoding_oily_png = OilyPNG::Canvas.from_file(file)
19
+
20
+ if decoding_reference == decoding_oily_png
21
+ puts "Decoding test succeeded!"
22
+ else
23
+ puts "Decoding test FAILED!"
24
+ end
25
+
26
+ oily_png = OilyPNG::Canvas.from_canvas(decoding_reference)
27
+
28
+ [ChunkyPNG::FILTER_NONE, ChunkyPNG::FILTER_SUB, ChunkyPNG::FILTER_UP, ChunkyPNG::FILTER_AVERAGE, ChunkyPNG::FILTER_PAETH].each do |filter_method|
29
+
30
+ encoding_reference = decoding_reference.to_blob(:filtering => filter_method, :color_mode => ChunkyPNG::COLOR_TRUECOLOR_ALPHA)
31
+ encoding_oily_png = oily_png.to_blob(:filtering => filter_method, :color_mode => ChunkyPNG::COLOR_TRUECOLOR_ALPHA)
32
+
33
+ if encoding_reference == encoding_oily_png
34
+ puts "Encoding test succeeded for filter method #{filter_method}!"
35
+ else
36
+ puts "Encoding test FAILED for filter method #{filter_method}!"
37
+ end
38
+ end
39
+
40
+ [ChunkyPNG::COLOR_GRAYSCALE, ChunkyPNG::COLOR_GRAYSCALE_ALPHA, ChunkyPNG::COLOR_INDEXED, ChunkyPNG::COLOR_TRUECOLOR, ChunkyPNG::COLOR_TRUECOLOR_ALPHA].each do |color_mode|
41
+
42
+ encoding_reference = decoding_reference.to_blob(:filtering => ChunkyPNG::FILTER_NONE, :color_mode => color_mode)
43
+ encoding_oily_png = oily_png.to_blob(:filtering => ChunkyPNG::FILTER_NONE, :color_mode => color_mode)
44
+
45
+ if encoding_reference == encoding_oily_png
46
+ puts "Encoding test succeeded for color mode #{color_mode}!"
47
+ else
48
+ puts "Decoding test FAILED for color mode #{color_mode}!"
49
+ end
50
+ end
51
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oily_png
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Willem van Bergen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-07 00:00:00 +02:00
18
+ date: 2010-10-08 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -92,9 +92,11 @@ files:
92
92
  - spec/encoding_spec.rb
93
93
  - spec/resources/gray.png
94
94
  - spec/resources/interlaced.png
95
- - spec/resources/operations.png
95
+ - spec/resources/nonsquare.png
96
+ - spec/resources/square.png
96
97
  - spec/spec_helper.rb
97
98
  - tasks/github-gem.rake
99
+ - tasks/testing.rake
98
100
  has_rdoc: true
99
101
  homepage: http://wiki.github.com/wvanbergen/oily_png
100
102
  licenses: []