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

Fixes drawImage for thumbs #4924

Merged
merged 1 commit into from
Jun 13, 2014
Merged

Conversation

yurydelendik
Copy link
Contributor

Fixes #4921

And don't think we need to worry fixing #2888 as well, thumbnails just to quickly locate the page and not read it.

@yurydelendik
Copy link
Contributor Author

/botio-windows preview

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

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

@timvandermeij
Copy link
Contributor

This looks a lot better, yes. I agree that making it even better might not be useful because indeed users do not need to read it. It would only affect performance to make it even better.

@yurydelendik
Copy link
Contributor Author

Fixes #2888

@@ -1260,6 +1260,8 @@ var PDFView = {
}
}
this.pdfDocument.cleanup();

ThumbnailView.tempImageCache = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

either this, or the last line in thumbnail_view.js looks like a duplicate for me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

first one initializes, second one cleans up

@CodingFabian
Copy link
Contributor

the quality looks now comparable between the two ways the thumb can be generated. I still believe i can see a difference, but maybe thats only because i have looked at them for a day.

I was looking into ways without writing our own resampling algorithm. But because thats what you have done here, let me at least post this SO question containing alternative resizing implementations.
http://stackoverflow.com/questions/2303690/resizing-an-image-in-an-html5-canvas

Maybe it should be refactored out, so it can be benchmarked and optimised separately.

@yurydelendik
Copy link
Contributor Author

@CodingFabian we have couple of resizing algorithms e.g. in image.js, but we shall not perform any of those for 1) memory consumption, 2) or, block the main thread by JS code execution

@Snuffleupagus
Copy link
Collaborator

This looks great!
However it doesn't seem to help when ThumbnailView.draw is called. Perhaps we could draw on a larger canvas in this case and then use the code in this PR to scale it down?

@yurydelendik
Copy link
Contributor Author

Perhaps we could draw on a larger canvas

Bad idea from memory consumption point of view and drawing on large canvas is slower than on smaller

@yurydelendik
Copy link
Contributor Author

I was looking into ways without writing our own resampling algorithm.

Also, getting the raw pixel data messes with hardware acceleration of the canvas (not counting on amount of memory you will be allocating) and makes the canvas operations even slower.

@yurydelendik
Copy link
Contributor Author

Comparison: first is before, second is after starting from page 1, third is after starting from page4

screen shot 2014-06-12 at 12 04 40 pm

Notice that page 2 thumb is generated using different methods.

var reducedHeight = img.height;

// drawImage does an awful job of rescaling the image, doing it gradually
var MAX_SCALE_FACTOR = 2.0;
Copy link
Contributor

Choose a reason for hiding this comment

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

you could use 4 as max scale factor.
the while loop will trigger when for example the needed scale is 2.1, which will downscale to 1.1 which then the final draw will make to 1.0.
by using a scale like 4, the last draw Image call will get some more downscaling to do, effectively cutting down one loop with little noticeable effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

2 is used for a reason to avoid loosing any pixel information, which is important for text or thin lines.

@CodingFabian
Copy link
Contributor

in my benchmarks, this is about 2-3 times better than the old code on chrome, which surprises me. but it seems that most scale down is now done in GPU memory. The thumbnail quality looks good for me. i would merge it like this.

yurydelendik added a commit that referenced this pull request Jun 13, 2014
@yurydelendik yurydelendik merged commit cab0430 into mozilla:master Jun 13, 2014
@yurydelendik yurydelendik deleted the fixthumb branch June 13, 2014 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Thumbnail quality bad when scaled from rendered canvas
5 participants