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

implement CalRGB color space #5165

Merged
merged 1 commit into from
Aug 15, 2014
Merged

implement CalRGB color space #5165

merged 1 commit into from
Aug 15, 2014

Conversation

kkujala
Copy link
Contributor

@kkujala kkujala commented Aug 10, 2014

Both whitespace and blackspace support are implemented.

@yurydelendik
Copy link
Contributor

Could you also provide test PDF document(s) ?

@kkujala
Copy link
Contributor Author

kkujala commented Aug 10, 2014

Of course :) It was already included but I forgot to add the test.manifest changes. I've update the patch with that now.

And if one compares pdf.js and acrobat then for the most part they are almost the same. Only on few pages acrobat goes to disco.

@kkujala
Copy link
Contributor Author

kkujala commented Aug 10, 2014

I'll update the patch a bit more, so don't merge just yet.
EDIT: ready for review now, I modified the test pdf to include info section.

@kkujala
Copy link
Contributor Author

kkujala commented Aug 10, 2014

Addressed the review nits from @timvandermeij. Thanks for the review!

@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/8a76ae3d32067fe/output.txt

@timvandermeij
Copy link
Contributor

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/aa1c1de090e4bd9/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/13ac6169e22edee/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://107.22.172.223:8877/13ac6169e22edee/output.txt

Total script time: 19.77 mins

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

Image differences available at: http://107.22.172.223:8877/13ac6169e22edee/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

From: Bot.io (Linux)


Failed

Full output at http://107.21.233.14:8877/aa1c1de090e4bd9/output.txt

Total script time: 22.55 mins

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

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

{ "id": "calrgb",
"file": "pdfs/calrgb.pdf",
"md5": "29e6f9dc529523cbed41401eb1b4165e",
"rounds": 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's specify lastPage=8 -- 36 pages is too many

@yurydelendik
Copy link
Contributor

Looks good. However it will be nice to see less objects created in the function, i.e. move const matrix definitions outsize, and accept destination matrix as parameter vs returning new one: function fn(a, b, result) { result[0] = a[0] + b[0]; ... } vs function fn(a, b) { return [a[0] * b[0]]; }. You can create temporary matrices in a closure and assign them to the meaningfully-named variables in the functions before call (that will also allow to re-use the same temp for different calls if needed)

@CodingFabian
Copy link
Contributor

whats causing the failure for 1597? all other pdf viewers render the white as ffffff not as fefeff. Even pdfjs before the patch did. is that rounding issue? is there an alpha layer above it?

@kkujala
Copy link
Contributor Author

kkujala commented Aug 11, 2014

@yurydelendik, I created those temp matrices as you suggested. On the positive side I was able to nuke three functions and on the negative side few places became a little less readable but only a little. Overall I think it is better.

Btw, do you want me to hoist the const matrices outside of the CalRGBCS class? There would be then even less object creation but they would be global then and I don't know if it makes any difference performance wise.

What would be the best way to test the gains from this temp matrices optimization? Speed and memory wise?

@CodingFabian, I'll check what's going on there.

And I'll squash the commits if Yury thinks my changes are ok.

@yurydelendik
Copy link
Contributor

negative side few places became a little less readable but only a little. Overall I think it is better.
It is good. Let me add some improvements. It does not matter how you will name the temporary matrices, e.g. tempMatrix1, tempMatrix2, etc. will work -- it will be useful to reuse those, e.g.

 normalizeWhitePointToFlat([cs.XW, cs.YW, cs.ZW], [X, Y, Z],
 tempXYZ_FlatMatrix);
 var XYZ_Flat = tempXYZ_FlatMatrix;

 compensateBlackPoint([cs.XB, cs.YB, cs.ZB], XYZ_Flat, tempXYZ_BlackMatrix);
 var XYZ_Black = tempXYZ_BlackMatrix;

 normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black,
 tempXYZ_D65Matrix);
 var XYZ_D65 = tempXYZ_D65Matrix;

will look as:

 var  XYZ_Flat = tempMatrix1;
 normalizeWhitePointToFlat([cs.XW, cs.YW, cs.ZW], [X, Y, Z], XYZ_Flat);

 var XYZ_Black = tempMatrix2;
 compensateBlackPoint([cs.XB, cs.YB, cs.ZB], XYZ_Flat, XYZ_Black);

 var XYZ_D65 = tempMatrix1;
 normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);

or even:

 var  XYZ_Flat = tempMatrix1, XYZ = tempMatrix2;
 XYZ[0] = X; XYZ[1] = Y; XYZ[2] = Z;
 normalizeWhitePointToFlat(cs.XYZ_White, XYZ, XYZ_Flat);

What would be the best way to test the gains from this temp matrices optimization? Speed and memory wise?

I'm afraid we cannot effectively measure speed/memory on any of the PDF. However, you can modify getRgb to run convertToRgb hundreds thousand times and clock the execution time.

Using Float32Array/Float32Array instead of JS Array might speed up the execution as well.

var LMS_Flat = tempLMS_FlatMatrix;

matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat,
tempBradfordInverseMatrix);
Copy link
Contributor

Choose a reason for hiding this comment

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

result instead of tempBradfordInverseMatrix can be used here

@kkujala
Copy link
Contributor Author

kkujala commented Aug 11, 2014

Yes, it looks better like that. I'll make the changes. Did you have an opinion about the location of the const matrices? I.e is it better to have them inside the class?

@yurydelendik
Copy link
Contributor

Did you have an opinion about the location of the const matrices? I.e is it better to have them inside the class?

Yes, inside of class closure is fine (as you have them now)

@kkujala
Copy link
Contributor Author

kkujala commented Aug 12, 2014

I've made the temp matrix changes. I'll still check that one regression failure and I'll also modify the test pdf so that 8 pages long.

@yurydelendik
Copy link
Contributor

Really nice.

Not sure, but making the arrays typed might give you some perf improvements, e.g. var BRADFORD_SCALE_MATRIX = [0.8951, ..]; => var BRADFORD_SCALE_MATRIX = new Float32Array([0.8951, ...]); and var temp = [0,0,0]; => var temp = new Float32Array(3);;

@kkujala
Copy link
Contributor Author

kkujala commented Aug 14, 2014

@yurydelendik, I changed all the matrices to typed arrays and I updated the test pdf to be more compact. It currently has 17 pages and when I ran the browsertest it took 10 seconds. I can add the last page = 8 to the test manifest if you think it is still needed.

@CodingFabian, It was as you suspected a rounding error. The value for red was 254,999.., which was then truncated to 254. I modified the code to use Math.round and now it is 255.

@yurydelendik
Copy link
Contributor

I can add the last page = 8 to the test manifest if you think it is still needed.

Our reftest hardness stores images of every page, we are trying to not burden it with unneeded memory usage.

Both whitespace and blackspace support are implemented.
@kkujala
Copy link
Contributor Author

kkujala commented Aug 14, 2014

Sure, I preemptively moved all the interesting pages to the front and more esoteric pages to the end, so it's cool with me. Patch updated.

@yurydelendik
Copy link
Contributor

Awesome. This looks good.

/botio test

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/7f30cc69e0ffcd8/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/62302241cef33d8/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://107.22.172.223:8877/7f30cc69e0ffcd8/output.txt

Total script time: 19.73 mins

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

Image differences available at: http://107.22.172.223:8877/7f30cc69e0ffcd8/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

From: Bot.io (Linux)


Failed

Full output at http://107.21.233.14:8877/62302241cef33d8/output.txt

Total script time: 22.59 mins

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

Image differences available at: http://107.21.233.14:8877/62302241cef33d8/reftest-analyzer.html#web=eq.log

@yurydelendik
Copy link
Contributor

/botio makeref

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/59644205210b29a/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/c5b4be44d593c86/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/59644205210b29a/output.txt

Total script time: 21.31 mins

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

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/c5b4be44d593c86/output.txt

Total script time: 22.48 mins

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

yurydelendik added a commit that referenced this pull request Aug 15, 2014
implement CalRGB color space
@yurydelendik yurydelendik merged commit fa8d385 into mozilla:master Aug 15, 2014
@yurydelendik
Copy link
Contributor

Thank you

@kkujala
Copy link
Contributor Author

kkujala commented Aug 15, 2014

Super, 1 year's worth of effort comes into fruition :) CalGray blackpoint should be farely easy now. Crossreferencing #252.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants