This repository has been archived by the owner on May 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracting TIFF splitting logic from IIIF Print
As I'm thinking through the logic, I'm realizing that we have a splitter and a strategy; the splitter leverages the strategy. As implemented the splitter is the strategy is the splitter. Related to: - scientist-softserv/iiif_print#194 - samvera/bulkrax#760 - scientist-softserv/utk-hyku#343 - https://github.com/scientist-softserv/adventist-dl/issues/330
- Loading branch information
Showing
10 changed files
with
128 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
|
||
module SpaceStone | ||
module PdfSplitter | ||
module Strategies | ||
# The purpose of this class is to split the PDF into constituent tiff files. | ||
class Tiff < Strategies::Base | ||
self.image_extension = 'tiff' | ||
self.compression = 'lzw' | ||
|
||
## | ||
# @api private | ||
# | ||
# @param gsdevice [Object] | ||
def gsdevice | ||
return @gsdevice if defined?(@gsdevice) | ||
|
||
color = pdf_pages_summary.color_description | ||
channels = pdf_pages_summary.channels | ||
bpc = pdf_pages_summary.bits_per_channel | ||
|
||
if color == 'gray' | ||
# CCITT Group 4 Black and White, if applicable: | ||
if bpc == 1 | ||
self.compression = 'g4' | ||
return @gsdevice = 'tiffg4' | ||
elsif bpc > 1 | ||
# 8 Bit Grayscale, if applicable: | ||
return @gsdevice = 'tiffgray' | ||
end | ||
end | ||
|
||
# otherwise color: | ||
@gsdevice = colordevice(channels, bpc) | ||
end | ||
|
||
def colordevice(channels, bpc) | ||
bits = bpc * channels | ||
# will be either 8bpc/16bpd color TIFF, | ||
# with any CMYK source transformed to 8bpc RBG | ||
bits = 24 unless [24, 48].include? bits | ||
"tiff#{bits}nc" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
require 'spec_helper' | ||
|
||
RSpec.describe SpaceStone::PdfSplitter::Strategies::Tiff do | ||
let(:path) { __FILE__ } | ||
let(:pdf_pages_summary) { double(SpaceStone::PdfSplitter::PdfPagesSummary) } | ||
|
||
let(:splitter) { described_class.new(path, pdf_pages_summary: pdf_pages_summary) } | ||
|
||
describe '.compression' do | ||
subject { described_class.compression } | ||
it { is_expected.to eq('lzw') } | ||
end | ||
|
||
describe '.compression?' do | ||
subject { described_class.compression? } | ||
it { is_expected.to be_truthy } | ||
end | ||
|
||
describe '.image_extension' do | ||
subject { described_class.image_extension } | ||
it { is_expected.to eq('tiff') } | ||
end | ||
|
||
describe '#gsdevice' do | ||
DEFAULT_SUMMARY_ATTRIBUTES = { | ||
page_count: 10, | ||
color_description: 'rgb', | ||
bits_per_channel: 0, | ||
channels: 0 | ||
}.freeze | ||
|
||
[ | ||
[{ color_description: 'gray', bits_per_channel: 2 }, 'tiffgray'], | ||
[{ color_description: 'gray', bits_per_channel: 1 }, 'tiffg4'], | ||
[{ color_description: 'rgb', bits_per_channel: 1 }, 'tiff24nc'], | ||
[{ color_description: 'rgb', channels: 8, bits_per_channel: 6 }, 'tiff48nc'], | ||
[{ color_description: 'rgb', channels: 8, bits_per_channel: 5 }, 'tiff24nc'], | ||
[{ color_description: 'rgb', channels: 8, bits_per_channel: 3 }, 'tiff24nc'] | ||
].each do |attributes, expected_value| | ||
context 'with #{attributes.inspect}' do | ||
it "is expected to be #{expected_value.inspect}" do | ||
summary = SpaceStone::PdfSplitter::PdfPagesSummary.new(**DEFAULT_SUMMARY_ATTRIBUTES.merge(attributes)) | ||
expect(described_class.new(__FILE__, pdf_pages_summary: summary).gsdevice).to eq(expected_value) | ||
end | ||
end | ||
end | ||
end | ||
end |