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

Convert canvas thumbnails to PNG #6299

Merged
merged 1 commit into from
Sep 10, 2015

Conversation

zinking
Copy link

@zinking zinking commented Aug 1, 2015

fixes #6035 , converting canvas thumb nails to png images


this.canvas = canvas;
this.div.setAttribute('data-loaded', true);
this.ring.appendChild(canvas);
//this.ring.appendChild(canvas);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the commented-out code here and above.

@timvandermeij
Copy link
Contributor

@zinking Once you have addressed the review comment, please squash the commits into one commit. See https://github.com/mozilla/pdf.js/wiki/Squashing-Commits on how to do that easily.

@timvandermeij timvandermeij changed the title 6035 png thumb nail Convert canvas thumbnails to PNG Aug 1, 2015
@Snuffleupagus
Copy link
Collaborator

It appears that the following from #6035 (comment) isn't implemented by the PR yet:

This should be done when the viewer is idle, i.e., not when the user is scrolling.

Edit: I'm wondering if a better solution for this PR wouldn't be to add a method to PDFThumbnailView that handles the conversion from <canvas> to png, and then calling that (iterating over all the thumbnails) from PDFThumbnailViewer_cleanup?

@zinking zinking force-pushed the 6035_png_thumb_nail branch from 9e4f3f7 to d1b15d9 Compare August 2, 2015 01:04
zinking pushed a commit to zinking/pdf.js that referenced this pull request Aug 2, 2015
@yurydelendik
Copy link
Contributor

The solution looks fine to me. @Snuffleupagus I think we can leave without reencoding-on-cleanup part -- unless there is a clear indication the encoding of the png takes unreasonable amount of CPU. It will use some CPU but I'm thinking in overall not using lots of canvases might be a better choice. It will be better if we will have some benchmark with this PR.

Also, using canvas'es toBlob() instead of toDataURL in some way might help with memory usage (similar to PDFJS.createObjectURL but it shall be async).

@timvandermeij
Copy link
Contributor

Looks good to me too with the nit addressed and re-squashed after that. toBlob might be better indeed, but having a benchmark to confirm that would be nice. Does not have to be too exact, just measuring the process memory usage a couple of times and taking the average before and after the patch should be enough.

@timvandermeij
Copy link
Contributor

@zinking Do you have time to finish up this PR by addressing the comments above?

@zinking
Copy link
Author

zinking commented Sep 2, 2015

@timvandermeij do you mean manually testing the memory usage ? I can do the rough testing using a few documents at hand, and provide some statistics, but this comment probably should be framed better so that my manual test is useful

@timvandermeij
Copy link
Contributor

Yes, all that needs to be done is address the nit above and manually test the memory usage before and after your patch.

@zinking
Copy link
Author

zinking commented Sep 3, 2015

browser pdf Page before(private) After (private) comment
chrome compressed.tracemonkey-pldi-09.pdf 14 406,260k 158,820k
chrome abel.pdf 285 638,996k 394,564k this has more pics
chrome AkkaScala.pdf 387 768,476k 434,732k

The test is conducted on OSX 10.9.5 , Chrome 44.0.2403.157 (64 bit)
memory stats is generated from : chrome://memory-redirect/

looks saving memory as expected.

@timvandermeij
Copy link
Contributor

@zinking Great, thank you for confirming that! Could you squash the commits into one commit? Then this should be good to merge.

@zinking zinking force-pushed the 6035_png_thumb_nail branch from 8da4a70 to 161def7 Compare September 4, 2015 01:59
@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/560a640ae4811a3/output.txt

timvandermeij added a commit that referenced this pull request Sep 10, 2015
@timvandermeij timvandermeij merged commit dffb2ef into mozilla:master Sep 10, 2015
@timvandermeij
Copy link
Contributor

Thank you for the patch!

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.

Reduce memory footprint of thumbnails
5 participants