Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not transform jpeg RGB components #11967

Merged
merged 1 commit into from Jun 4, 2020
Merged

Conversation

havocbcn
Copy link
Contributor

@havocbcn havocbcn commented Jun 4, 2020

Hello,

Fix issue #11931

The image is encoded using RGB, not YCbCr

here : https://stackoverflow.com/questions/50798014/determining-color-space-for-jpeg/50861048

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

The head.jpg doesn't have a app14, so image seems to be using YCbCr not RGB

But, the second best answer points to look up the implementation of a Java jpeg library, seems that if components are called R, G and B, the space color is RGB, and this is the case, the components are called in this way.

This pull request maintain the index in the components struct to allow _isColorConversionNeeded to do not convert if the components are called R, G and B.

The Pdf is now showed correctly

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also update the commit message to include all of the relevant information found in #11967 (comment), such that that information is available on e.g. the Git command-line as well.

Please remember to squash the commits once you've made changes, see https://github.com/mozilla/pdf.js/wiki/Squashing-Commits

@@ -147,6 +147,7 @@
!issue1055r.pdf
!issue11713.pdf
!issue1293r.pdf
!jpeg_rgb.pdf
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the name of the file to issue11931.pdf instead, which is the usual format used in the PDF.js code-base since it makes finding/associating the test-case with the original issue easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 4370 to 4371
{ "id": "jpeg_rgb",
"file": "pdfs/jpeg_rgb.pdf",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As outline above, please change to

{  "id": "issue11931",
   "file": "pdfs/issue11931.pdf",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/core/jpg.js Outdated
Comment on lines 1190 to 1192
this.components[0].index === 0x52 && // ASCII R. G and B
this.components[1].index === 0x47 &&
this.components[2].index === 0x42
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It's probably not a bad idea to change the comment to something like the following example instead (which is a somewhat common format in these types of situations throughout the code-base):

this.components[0].index === /* "R" = */ 0x52 &&
this.components[1].index === /* "G" = */ 0x47 &&
this.components[2].index === /* "B" = */ 0x42

That way you'd ensure that the comment doesn't move and thus become more difficult to connect to the relevant code, which can sometimes be a problem if/when automatic reformatting happens (as triggered by updating the Prettier dependency).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/core/jpg.js Outdated
@@ -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++];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Please use let or const, as appropriate, when adding new code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@havocbcn
Copy link
Contributor Author

havocbcn commented Jun 4, 2020

Updated commit message, test name, comments and the var to a const.

Thanks

…s "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 mozilla#11931
@Snuffleupagus
Copy link
Collaborator

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Jun 4, 2020

From: Bot.io (Linux m4)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/f7a373e0edb796c/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jun 4, 2020

From: Bot.io (Windows)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.215.176.217:8877/aedd1150192f05e/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jun 4, 2020

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/f7a373e0edb796c/output.txt

Total script time: 25.79 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: FAILED

Image differences available at: http://54.67.70.0:8877/f7a373e0edb796c/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

pdfjsbot commented Jun 4, 2020

From: Bot.io (Windows)


Failed

Full output at http://54.215.176.217:8877/aedd1150192f05e/output.txt

Total script time: 27.75 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: FAILED

Image differences available at: http://54.215.176.217:8877/aedd1150192f05e/reftest-analyzer.html#web=eq.log

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you!

@Snuffleupagus
Copy link
Collaborator

/botio makeref

@pdfjsbot
Copy link

pdfjsbot commented Jun 4, 2020

From: Bot.io (Linux m4)


Received

Command cmd_makeref from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/9d830ab145da83f/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jun 4, 2020

From: Bot.io (Windows)


Received

Command cmd_makeref from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.215.176.217:8877/4808cf3841e3203/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jun 4, 2020

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/9d830ab145da83f/output.txt

Total script time: 23.98 mins

  • Lint: Passed
  • Make references: Passed
  • Check references: Passed

@pdfjsbot
Copy link

pdfjsbot commented Jun 4, 2020

From: Bot.io (Windows)


Failed

Full output at http://54.215.176.217:8877/4808cf3841e3203/output.txt

Total script time: 25.41 mins

  • Lint: Passed
  • Make references: FAILED

@Snuffleupagus
Copy link
Collaborator

/botio-windows makeref

@pdfjsbot
Copy link

pdfjsbot commented Jun 4, 2020

From: Bot.io (Windows)


Received

Command cmd_makeref from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.215.176.217:8877/c51062b9c20ec75/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jun 4, 2020

From: Bot.io (Windows)


Success

Full output at http://54.215.176.217:8877/c51062b9c20ec75/output.txt

Total script time: 25.93 mins

  • Lint: Passed
  • Make references: Passed
  • Check references: Passed

@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

pdfjsbot commented Jun 4, 2020

From: Bot.io (Linux m4)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/04fd3d47e0d5c99/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jun 4, 2020

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/04fd3d47e0d5c99/output.txt

Total script time: 3.31 mins

Published

@timvandermeij timvandermeij merged commit ad261a2 into mozilla:master Jun 4, 2020
@timvandermeij
Copy link
Contributor

Thank you for your contribution!

@havocbcn havocbcn deleted the jpg-rgb branch June 5, 2020 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants