Sha256: 3127fa9fcd13543cb1a35e5b380b915c1d5d22e39bb6b98c5278e55f2d9058c7

Contents?: true

Size: 1.43 KB

Versions: 20

Compression:

Stored size: 1.43 KB

Contents

require 'open3'

module Ddr
  module Derivatives
    class PtifGenerator < Generator

      def self.output_mime_type
        "image/tiff"
      end

      def generate
        case source_depth.strip
        when '16'
          Dir.mktmpdir do |dir|
            temp_8_bit = make_8_bit(dir)
            run_generator(temp_8_bit)
          end
        when '8'
          run_generator(source)
        else
          raise Ddr::Models::DerivativeGenerationFailure,
                  "Unexpected depth -- #{source_depth} -- for source file #{Ddr::Utils.file_path(source)}"
        end
      end

      private

      def run_generator(source_to_use)
        command = "vips im_vips2tiff #{Ddr::Utils.file_path(source_to_use)} #{Ddr::Utils.file_path(output)}:#{options}"
        out, err, s = Open3.capture3(command)
        GeneratorResult.new(out, err, s)
      end

      def make_8_bit(tempdir)
        temp_8_bit = File.new(File.join(tempdir, "temp_8_bit.v"), 'wb')
        command = "vips im_msb #{Ddr::Utils.file_path(source)} #{Ddr::Utils::file_path(temp_8_bit)}"
        out, err, s = Open3.capture3(command)
        if s.success?
          return temp_8_bit
        else
          raise Ddr::Models::DerivativeGenerationFailure,
                  "Error converting #{Ddr::Utils.file_path(source)} to 8-bit: #{err}"
        end
      end

      def source_depth
        `identify -format '%[depth]' #{Ddr::Utils.file_path(source)}`
      end

    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ddr-models-2.4.3 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.4.2 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.4.1 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.4.0 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.4.0.rc6 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.4.0.rc5 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.4.0.rc4 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.4.0.rc3 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.4.0.rc2 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.4.0.rc1 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.3.2 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.3.1 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.3.0 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.2.0 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.1.3 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.1.2 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.1.1 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.1.0 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.1.0.rc2 lib/ddr/derivatives/ptif_generator.rb
ddr-models-2.1.0.rc1 lib/ddr/derivatives/ptif_generator.rb