Skip to content

Commit

Permalink
Do not transform jpeg RGB components
Browse files Browse the repository at this point in the history
  • Loading branch information
havocbcn committed Jun 4, 2020
1 parent 96ad60f commit 14d893d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/core/jpg.js
Original file line number Diff line number Diff line change
Expand Up @@ -991,8 +991,10 @@ var JpegImage = (function JpegImageClosure() {
var components = [],
component;
for (i = 0; i < selectorsCount; i++) {
var componentIndex = frame.componentIds[data[offset++]];
var index = data[offset++];
var componentIndex = frame.componentIds[index];
component = frame.components[componentIndex];
component.index = index;
var tableSpec = data[offset++];
component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
Expand Down Expand Up @@ -1088,6 +1090,7 @@ var JpegImage = (function JpegImageClosure() {
}

this.components.push({
index: component.index,
output: buildComponentData(frame, component),
scaleX: component.h / frame.maxH,
scaleY: component.v / frame.maxV,
Expand Down Expand Up @@ -1183,6 +1186,14 @@ var JpegImage = (function JpegImageClosure() {
// dictionary has a 'ColorTransform' entry, explicitly set to `0`,
// then the colours should *not* be transformed.
return false;
} else if (
this.components[0].index === 0x52 && // ASCII R. G and B
this.components[1].index === 0x47 &&
this.components[2].index === 0x42
) {
// If the three components are indexed as RGB in ASCII
// then the colours should *not* be transformed.
return false;
}
return true;
}
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
!issue1055r.pdf
!issue11713.pdf
!issue1293r.pdf
!jpeg_rgb.pdf
!issue1655r.pdf
!issue6541.pdf
!issue2948.pdf
Expand Down
Binary file added test/pdfs/jpeg_rgb.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4367,6 +4367,12 @@
"type": "eq",
"forms": true
},
{ "id": "jpeg_rgb",
"file": "pdfs/jpeg_rgb.pdf",
"md5": "9ea233037992e1f10280420a49e72845",
"rounds": 1,
"type": "eq"
},
{ "id": "annotation-button-widget-annotations",
"file": "pdfs/annotation-button-widget.pdf",
"md5": "5cf23adfff84256d9cfe261bea96dade",
Expand Down

0 comments on commit 14d893d

Please sign in to comment.