sandal (owner)

Revisions

  • e20519 Fri Aug 28 05:43:40 -0700 2009
  • 0447d1 Fri Aug 28 05:37:17 -0700 2009
  • 14c5ff Fri Aug 28 05:35:55 -0700 2009
gist: 176967 Download_button fork
public
Public Clone URL: git://gist.github.com/176967.git
Embed All Files: show embed
jpeg.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    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