Skip to content

Commit 4cc87a7

Browse files
authored
Merge pull request #143 from mlibrary/kakadu-to-grok
AIM-45 replace kakadu with grok using HT's settings
2 parents 4f47f54 + 7ec17ae commit 4cc87a7

File tree

5 files changed

+21
-32
lines changed

5 files changed

+21
-32
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
name: Run CI
22

3-
on:
4-
push:
5-
branches:
6-
- $default-branch
7-
8-
pull_request:
3+
on: push
94

105
jobs:
116
# Run tests
@@ -34,5 +29,8 @@ jobs:
3429
- name: Run standard
3530
run: docker compose run --rm test bundle exec standardrb
3631

37-
- name: Run tests
32+
- name: Run minitest tests
3833
run: docker compose run --rm test
34+
35+
- name: Run rspec tests
36+
run: docker compose run --rm test bundle exec rspec

Dockerfile

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@ ARG FEED_VERSION=feed_v1.14.1
88
RUN gem install bundler
99

1010
WORKDIR /tmp
11-
RUN wget https://kakadusoftware.com/wp-content/uploads/$KAKADU_FILE
12-
RUN unzip -j -d kakadu $KAKADU_FILE
13-
RUN mv /tmp/kakadu/*.so /usr/local/lib
14-
RUN mv /tmp/kakadu/kdu* /usr/local/bin
15-
RUN echo "/usr/local/lib" > /etc/ld.so.conf.d/kakadu.conf
16-
RUN ldconfig
11+
12+
RUN curl https://apt.lib.umich.edu/mlibrary-archive-keyring.gpg -o /etc/apt/keyrings/mlibrary-archive-keyring.gpg
13+
RUN echo "deb [signed-by=/etc/apt/keyrings/mlibrary-archive-keyring.gpg] https://apt.lib.umich.edu bookworm main" > /etc/apt/sources.list.d/mlibrary.list
1714

1815
RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \
1916
libtiff-tools\
2017
exiftool \
21-
netpbm
18+
netpbm\
19+
grokj2k
20+
2221

2322
ENV APP_PATH=/usr/src/app
2423
RUN mkdir -p $APP_PATH

lib/compressor.rb

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
require "tiff"
22

3-
module Kakadu
3+
module Grok
44
JP2_LEVEL_MIN = 5
5-
JP2_LAYERS = 8
6-
JP2_ORDER = "RLCP"
7-
JP2_USE_SOP = "yes"
8-
JP2_USE_EPH = "yes"
9-
JP2_MODES = '"RESET|RESTART|CAUSAL|ERTERM|SEGMARK"'
10-
JP2_SLOPE = 42_988
5+
6+
# Settings for grk_compress recommended from Roger Espinosa. "-slope"
7+
# is a VBR compression mode; the value of 42988 corresponds to pre-6.4
8+
# slope of 51180, the current (as of 5/6/2011) recommended setting for
9+
# Google digifeeds.
1110
def self.compress(source, destination, tiffinfo)
1211
clevels = jp2_clevels(tiffinfo)
13-
cmd = "kdu_compress -quiet -i #{source} -o #{destination}" \
14-
" 'Clevels=#{clevels}'" \
15-
" 'Clayers=#{JP2_LAYERS}'" \
16-
" 'Corder=#{JP2_ORDER}'" \
17-
" 'Cuse_sop=#{JP2_USE_SOP}'" \
18-
" 'Cuse_eph=#{JP2_USE_EPH}'" \
19-
" Cmodes=#{JP2_MODES}" \
20-
" -no_weights -slope '#{JP2_SLOPE}'"
12+
cmd = "grk_compress -i \"#{source}\" -o \"#{destination}\" -p RLCP -n #{clevels} -S -E -M 62 -I -q 32"
2113
status = Command.new(cmd).run
2214
LogEntry.info(command: cmd, time: status[:time])
2315
end
@@ -213,7 +205,7 @@ def compression_type
213205
"JP2"
214206
end
215207

216-
def run(compression_tool = Kakadu)
208+
def run(compression_tool = Grok)
217209
# We don't want any XMP metadata to be copied over on its own. If
218210
# it's been a while since we last ran exiftool, this might take a sec.
219211
log_it ExifTool.remove_tiff_metadata(source: image_file.path, destination: sparse_path)

lib/stage/dlxs_compressor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def pgm_to_bitonal(dir)
126126

127127
# Expand existing jp2 into tif in temp directory
128128
def expand_jp2(src, dest)
129-
cmd = "kdu_expand -quiet -i '#{src}' -o '#{dest}'"
129+
cmd = "grk_decompress -i '#{src}' -o '#{dest}'"
130130
status = Command.new(cmd).run
131131
log cmd, status[:time]
132132
end

spec/compressor_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def tiffinfo(path)
6363

6464
it "runs the compression tool" do
6565
compressor.run
66-
expect(log.entries).to include(match("kdu_compress"))
66+
expect(log.entries).to include(match("grk_compress"))
6767
end
6868

6969
it "copies original metadata to the jpeg2000" do

0 commit comments

Comments
 (0)