From 802aa14a9988f4788f6b280340e514d1c70e8611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Rodr=C3=ADguez?= Date: Thu, 4 Jun 2020 08:43:46 +0200 Subject: [PATCH] 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 --- src/core/jpg.js | 13 ++++++++++++- test/pdfs/.gitignore | 1 + test/pdfs/issue11931.pdf | Bin 0 -> 6671 bytes test/test_manifest.json | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/pdfs/issue11931.pdf diff --git a/src/core/jpg.js b/src/core/jpg.js index 619cf5c3589a8..d9c49fa70535e 100644 --- a/src/core/jpg.js +++ b/src/core/jpg.js @@ -991,8 +991,10 @@ var JpegImage = (function JpegImageClosure() { var components = [], component; for (i = 0; i < selectorsCount; i++) { - var componentIndex = frame.componentIds[data[offset++]]; + const 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]; @@ -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, @@ -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 === /* "R" = */ 0x52 && + this.components[1].index === /* "G" = */ 0x47 && + this.components[2].index === /* "B" = */ 0x42 + ) { + // If the three components are indexed as RGB in ASCII + // then the colours should *not* be transformed. + return false; } return true; } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 680b5a66ad29f..4d463ddc99b30 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -147,6 +147,7 @@ !issue1055r.pdf !issue11713.pdf !issue1293r.pdf +!issue11931.pdf !issue1655r.pdf !issue6541.pdf !issue2948.pdf diff --git a/test/pdfs/issue11931.pdf b/test/pdfs/issue11931.pdf new file mode 100644 index 0000000000000000000000000000000000000000..787bb7bf0e0a73006e8c8c6e3e5dd55fcfa97d52 GIT binary patch literal 6671 zcmeHMX;f3!7QW07smLr^Ap(k(%8(EcMWO@v^tM9$_ez0?Ymkwi?L5pdK84V2Tzv?PX~r!^mSE(y=rK+5bcog<;0&FSoj6tWv321AP6M~Wgq zIj(=7a0DsFb00nk0>z%NpBO~&z}n4CIT47VVHCI(!fbBrLky;b!Oaot=f{r32nrzv zZt56;rx5H3L8RdMwYCwWLLp0pl^H^kIGGYdz(>NU=f+s(QUCxnTo7FkRl;3>{w~M@ z0t*N%Ah3YI0s;#NEFiFezybpQZ3JxP%hMg>B`klQn9lQk3E%#o5^HnIPkA*0H9ve$ ztL-s6{)kksM}11F#ZSaf0SqAZZ-}(CloWJHNxzqm|D?r@fF1xy$<2j%e+Q(bWn|^# z6%>_Viy(u_C4jV)jEuCbjGUaTEM$EUng?W6<NIozS2pT8J>`RXQ`6wD@BTC3d=IE90!yR-84pzes|whu z0%A6xEaL%S0XqOd10s>J04y2jX0EyP=hwB3H^U!|7N%eAdzRwhAX|=9Kk6p$Y$LTT zZfDo|UUyZOyEU-POr?+zBgG5KIaKL0Z%T_cmR-_69T%gisiF4MPuo>D>lpInXbAf4 z65*GVf^~`NU{P_>Lv*Q6gGvUP=N`buIn>m3#I8^oyh-mJP!OUS#A#K(a7*8Urkxep z9_ylvi*$Cs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5T<1_+dhHSM|>*gA@A6$4P9o)=7vjR7AwgBuqp z3&p^&FutU%L{aD_20TT%PeNaafe|q<`D;l*tpOi1S#&K~_i{UzSFO)8TCuk^s_5tbN0pG?q89|B4I^6zc+!Cib(gY7afn>W&YV0Rui z(?*9oX42!^7JF7{Yjx(E<}n@n`v}a}>Z^Mh!>QI|{nnQ=T1vrV=u|PV+(w3LnnKqS z8gNR|2Nu_cUcG;XdYP4P(lHjxP}p_rL{WP2XjJ=&ZMlXB79ujQpBj|kH(`;b@BO(;YfDXwwGXF3t7JcqXM}GMA(#)K>Rr zlw_MEE$#DvmYUUMyR4_OPIuU=)Gku!elffow_m#vaqTiubW|k6?>SPxhHB7&Ra?46mHDK!@j&R)uLcG+`W~!jTpY=Boly1|$KB~HX1vIF%*nwAyu=Nn zS5P-{(~_anWxyHEpwM)vDlPTP+Y|AFty*Bx)H*DNZ<=c3Q1J9MTes%Qz~&~C2?1ln z>;ACw+jUlJ{_Pa@M8;Njw>xOK|G`BQ_e!Yj=Tu)(vj3dwOG^85jNA<$BPo&3bp&SX z@g4*+DK;huY7y*5zXfUo!r5 z`S*5x$L4?0Q=o)|%h`OwDkAd#Rx%Pg?7 fH^`HCfBTeZpo=Lq{3;<&|V literal 0 HcmV?d00001 diff --git a/test/test_manifest.json b/test/test_manifest.json index cb3b99ea7e362..b0b29be848983 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -4367,6 +4367,12 @@ "type": "eq", "forms": true }, + { "id": "issue11931", + "file": "pdfs/issue11931.pdf", + "md5": "9ea233037992e1f10280420a49e72845", + "rounds": 1, + "type": "eq" + }, { "id": "annotation-button-widget-annotations", "file": "pdfs/annotation-button-widget.pdf", "md5": "5cf23adfff84256d9cfe261bea96dade",