Skip to content

Commit c4d7a42

Browse files
committed
Handle grayscale JP2s with RGB color profiles
This installs the patch from uclouvain/openjpeg#1207 to handle the case where an image has a color profile which is not compatible with the actual channel definitions.
1 parent 0e9a1c8 commit c4d7a42

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

Dockerfile

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,48 @@
1+
FROM debian:buster AS builder
2+
3+
ENV DEBIAN_FRONTEND="noninteractive"
4+
5+
# Enable deb-src repos so we can retrieve the packages used to build libopenjp2:
6+
RUN sed -i -e '/^deb/p; s/^deb /deb-src /' /etc/apt/sources.list
7+
8+
RUN apt-get update -qqy && apt-get dist-upgrade -qqy && apt-get install -qqy quilt devscripts && apt-get build-dep -qy libopenjp2-tools
9+
10+
RUN adduser --system --group builder
11+
RUN install -d -o builder -g builder /build
12+
13+
USER builder
14+
15+
WORKDIR /build
16+
17+
RUN apt-get source openjpeg2
18+
19+
WORKDIR /build/openjpeg2-2.3.0
20+
ENV QUILT_PATCHES=debian/patches
21+
22+
# Add the patch from https://github.com/uclouvain/openjpeg/issues/1207
23+
COPY handle_colorspace_conflicts.patch /build/
24+
25+
# Apply the patch to the local source directory
26+
RUN quilt import /build/handle_colorspace_conflicts.patch
27+
RUN quilt push -a -v
28+
29+
# Build all of the openjpeg2 packages
30+
RUN debuild -uc -us
31+
132
FROM debian:buster
233

334
EXPOSE 8182
435

536
VOLUME /imageroot
637

7-
# Update packages and install tools
838
RUN apt-get update -qy && apt-get dist-upgrade -qy && \
9-
apt-get install -qy --no-install-recommends curl imagemagick libopenjp2-tools ffmpeg gettext unzip default-jre-headless && \
39+
apt-get install -qy --no-install-recommends curl imagemagick ffmpeg gettext unzip default-jre-headless && \
1040
apt-get -qqy autoremove && apt-get -qqy autoclean
1141

42+
# Install the patched openjpeg2 tools
43+
COPY --from=builder /build/*.deb /tmp/
44+
RUN dpkg -i /tmp/libopenjp2-*.deb /tmp/libopenjp2-tools-*.deb
45+
1246
# Run non privileged
1347
RUN adduser --system cantaloupe
1448

handle_colorspace_conflicts.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--- a/src/bin/common/color.c 2019-08-08 00:45:01.903651387 +0200
2+
+++ b/src/bin/common/color.c 2019-08-08 00:39:24.442674016 +0200
3+
@@ -488,6 +488,10 @@
4+
if (out_space == cmsSigRgbData) { /* enumCS 16 */
5+
unsigned int i, nr_comp = image->numcomps;
6+
7+
+ if (nr_comp < 3) { /* GRAY or GRAYA, not RGB or RGBA */
8+
+ cmsCloseProfile(in_prof);
9+
+ return;
10+
+ }
11+
if (nr_comp > 4) {
12+
nr_comp = 4;
13+
}

0 commit comments

Comments
 (0)