Skip to content

Commit 802aa14

Browse files
committed
Jpeg encoded with RGB -instead of YCbCr- write the components index as "RGB" in ASCII to say it so
On ISO/IEC 10918-6:2013 (E), section 6.1: (http://www.itu.int/rec/T-REC-T.872-201206-I/en) "Images encoded with three components are assumed to be RGB data encoded as YCbCr unless the image contains an APP14 marker segment as specified in 6.5.3, in which case the colour encoding is considered either RGB or YCbCr according to the application data of the APP14 marker segment" But common jpeg libraries consider RGB too if components index are ASCII R (0x52), G (0x47) and B (0x42): https://stackoverflow.com/questions/50798014/determining-color-space-for-jpeg/50861048 Issue #11931
1 parent 96ad60f commit 802aa14

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

src/core/jpg.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -991,8 +991,10 @@ var JpegImage = (function JpegImageClosure() {
991991
var components = [],
992992
component;
993993
for (i = 0; i < selectorsCount; i++) {
994-
var componentIndex = frame.componentIds[data[offset++]];
994+
const index = data[offset++];
995+
var componentIndex = frame.componentIds[index];
995996
component = frame.components[componentIndex];
997+
component.index = index;
996998
var tableSpec = data[offset++];
997999
component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
9981000
component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
@@ -1088,6 +1090,7 @@ var JpegImage = (function JpegImageClosure() {
10881090
}
10891091

10901092
this.components.push({
1093+
index: component.index,
10911094
output: buildComponentData(frame, component),
10921095
scaleX: component.h / frame.maxH,
10931096
scaleY: component.v / frame.maxV,
@@ -1183,6 +1186,14 @@ var JpegImage = (function JpegImageClosure() {
11831186
// dictionary has a 'ColorTransform' entry, explicitly set to `0`,
11841187
// then the colours should *not* be transformed.
11851188
return false;
1189+
} else if (
1190+
this.components[0].index === /* "R" = */ 0x52 &&
1191+
this.components[1].index === /* "G" = */ 0x47 &&
1192+
this.components[2].index === /* "B" = */ 0x42
1193+
) {
1194+
// If the three components are indexed as RGB in ASCII
1195+
// then the colours should *not* be transformed.
1196+
return false;
11861197
}
11871198
return true;
11881199
}

test/pdfs/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
!issue1055r.pdf
148148
!issue11713.pdf
149149
!issue1293r.pdf
150+
!issue11931.pdf
150151
!issue1655r.pdf
151152
!issue6541.pdf
152153
!issue2948.pdf

test/pdfs/issue11931.pdf

6.51 KB
Binary file not shown.

test/test_manifest.json

+6
Original file line numberDiff line numberDiff line change
@@ -4367,6 +4367,12 @@
43674367
"type": "eq",
43684368
"forms": true
43694369
},
4370+
{ "id": "issue11931",
4371+
"file": "pdfs/issue11931.pdf",
4372+
"md5": "9ea233037992e1f10280420a49e72845",
4373+
"rounds": 1,
4374+
"type": "eq"
4375+
},
43704376
{ "id": "annotation-button-widget-annotations",
43714377
"file": "pdfs/annotation-button-widget.pdf",
43724378
"md5": "5cf23adfff84256d9cfe261bea96dade",

0 commit comments

Comments
 (0)