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.
- data/lib/prawn/images/png_patch.rb +12 -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
|
-
|
26
|
-
|
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)
|