Created
August 28, 2009 12:35
-
-
Save practicingruby/176967 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def build_jpg_object(data, jpg) | |
| color_space = case jpg.channels | |
| when 1 | |
| :DeviceGray | |
| when 3 | |
| :DeviceRGB | |
| when 4 | |
| :DeviceCMYK | |
| else | |
| raise ArgumentError, 'JPG uses an unsupported number of channels' | |
| end | |
| obj = ref( | |
| :Type => :XObject, | |
| :Subtype => :Image, | |
| :Filter => :DCTDecode, | |
| :ColorSpace => color_space, | |
| :BitsPerComponent => jpg.bits, | |
| :Width => jpg.width, | |
| :Height => jpg.height, | |
| :Length => data.size ) | |
| # add extra decode params for CMYK images. By swapping the | |
| # min and max values from the default, we invert the colours. See | |
| # section 4.8.4 of the spec. | |
| if color_space == :DeviceCMYK | |
| obj.data[:Decode] = [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] | |
| end | |
| obj << data | |
| return obj | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment