amberbit-prawn-fast-png 0.1.3 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/prawn/images/png_patch.rb +12 -2
  2. metadata +1 -1
@@ -22,8 +22,18 @@ module Prawn
22
22
  # get only one color value per pixel (Intensity) for grayscale+alpha images
23
23
  format = color_type == 4 ? 'I' : 'RGB'
24
24
 
25
- img_data = img.export_pixels_to_str(0, 0, width, height, format)
26
- alpha_channel = img.export_pixels_to_str(0, 0, width, height, 'A')
25
+ case bits
26
+ when 8
27
+ img_data = img.export_pixels_to_str(0, 0, width, height, format)
28
+ alpha_channel = img.export_pixels_to_str(0, 0, width, height, 'A')
29
+ when 16
30
+ # export_pixels_to_str returns little-endian data, but we need big-endian
31
+ # so it's usually more efficient to use export_pixels and pack
32
+ img_data = img.export_pixels(0, 0, width, height, format).pack('n*')
33
+ alpha_channel = img.export_pixels(0, 0, width, height, 'A').pack('n*')
34
+ else
35
+ raise Errors::UnsupportedImageType, "Can't handle #{img.depth}-bit PNG images"
36
+ end
27
37
 
28
38
  @img_data = Zlib::Deflate.deflate(img_data)
29
39
  @alpha_channel = Zlib::Deflate.deflate(alpha_channel)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amberbit-prawn-fast-png
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wojciech Piekutowski