Closed
Bug 1045929
Opened 10 years ago
Closed 10 years ago
Add downscale-during-decode support for the JPEG decoder
Categories
(Core :: Graphics: ImageLib, defect)
Core
Graphics: ImageLib
Tracking
()
RESOLVED
FIXED
mozilla38
People
(Reporter: seth, Assigned: seth)
References
(Blocks 1 open bug)
Details
Attachments
(2 files, 4 obsolete files)
(deleted),
patch
|
Details | Diff | Splinter Review | |
(deleted),
patch
|
Details | Diff | Splinter Review |
The JPEG decoder should support downscaling during decode. We need to support arbitrary sizes (within reason) and use the minimum amount of memory feasible.
We already have some support for downscaling JPEGs during decode using the -moz-sample-size media fragment, but it's not flexible enough for our needs in practice, and it's something that I don't think we want to standardize. -moz-sample-size only supports a fixed set of ratios, and we need arbitrary sizes to work.
Comment 1•10 years ago
|
||
Comment 2•10 years ago
|
||
Assignee | ||
Updated•10 years ago
|
Attachment #8481953 -
Attachment is obsolete: true
Assignee | ||
Comment 3•10 years ago
|
||
I'll take this over to get this pushed over the finish line.
Assignee: asobolev → seth
Assignee | ||
Updated•10 years ago
|
Attachment #8484672 -
Attachment is obsolete: true
Assignee | ||
Comment 4•10 years ago
|
||
This patch adds a new class to ImageLib, Downscaler, which does streaming
high-quality downscaling using Skia's downscaling code.
The API should be pretty clear. Essentially, decoders do not write their output
directly into their output buffer, but instead into a buffer owned by
Downscaler, which then uses Skia to do the downscaling and then writes the
resulting scaled image to the decoder's output buffer.
Attachment #8546991 -
Flags: review?(tnikkel)
Assignee | ||
Comment 5•10 years ago
|
||
Here's the patch where we flip it on for JPEG images. There's not that much
here, actually.
- We update ImageFactory::ShouldDownscaleDuringDecode to return true for all
JPEG content types.
- We add an override for SetTargetSize in nsJPEGDecoder that creates a
Downscaler.
- We use the target size when allocating a frame in nsJPEGDecoder if a
Downscaler is present.
- The code that actually writes to the output buffer is updated to use the
Downscaler API if a Downscaler is present.
That's it!
Attachment #8546993 -
Flags: review?(tnikkel)
Comment 6•10 years ago
|
||
Comment on attachment 8546991 [details] [diff] [review]
(Part 1) - Add a streaming downscaler to ImageLib
>+Downscaler::DownscaleInputLine()
>+ // Shift the buffer. We're just moving pointers here, so this is cheap.
>+ mLinesInBuffer -= diff;
>+ mLinesInBuffer = max(mLinesInBuffer, 0);
>+ for (int32_t i = 0; i < mLinesInBuffer; ++i) {
>+ swap(mWindow[i], mWindow[filterLength - mLinesInBuffer + i]);
>+ }
Isn't |filterLength - mLinesInBuffer| equal to diff here?
Attachment #8546991 -
Flags: review?(tnikkel) → review+
Updated•10 years ago
|
Attachment #8546993 -
Flags: review?(tnikkel) → review+
Assignee | ||
Comment 7•10 years ago
|
||
(In reply to Timothy Nikkel (:tn) from comment #6)
> Isn't |filterLength - mLinesInBuffer| equal to diff here?
That seems right but I was scared to make this simplification before pushing.
Pushed:
remote: https://hg.mozilla.org/integration/mozilla-inbound/rev/9e4626f6062b
remote: https://hg.mozilla.org/integration/mozilla-inbound/rev/66a9a3b1aadb
Based on this try job, which looks pretty green right now:
https://tbpl.mozilla.org/?tree=Try&rev=f3f4d04d1fbe
Comment 8•10 years ago
|
||
sorry had to back this out in:
https://treeherder.mozilla.org/#/jobs?repo=mozilla-inbound&revision=5c20be43873b
because it seems backing out alone Bug 1120050 caused a bustage there and so this changeset had to go out as well. Sorry
Comment 9•10 years ago
|
||
Comment 10•10 years ago
|
||
Does this patch give us any way to tell gecko to immediately discard all memory used for a decoded image? If img contains an 8mp offscreen image, and I've just copied it into a canvas element for editing, can I do img.width = 0 or something like that to free the memory associated with it? I think currently I set img.src to '', but I am not sure that that will always discard the image immediately. Just looking for optimization opportunities here.
Updated•10 years ago
|
Flags: needinfo?(seth)
Comment 11•10 years ago
|
||
And another question: is there any intention to uplift this to the newly-cut Gecko branch for FirefoxOS v2.2? If so, that will dramatically change the urgency behind bug 1121648.
Assignee | ||
Comment 12•10 years ago
|
||
(In reply to David Flanagan [:djf] from comment #10)
> Does this patch give us any way to tell gecko to immediately discard all
> memory used for a decoded image? If img contains an 8mp offscreen image, and
> I've just copied it into a canvas element for editing, can I do img.width =
> 0 or something like that to free the memory associated with it? I think
> currently I set img.src to '', but I am not sure that that will always
> discard the image immediately. Just looking for optimization opportunities
> here.
This patch doesn't address that, but I do think we can look at being more aggressive about dropping decoded versions of images once the only reference to them is the image cache. (i.e., we can ensure that the |img.src = '';| approach works)
As I mentioned on IRC, I'll file a bug about this later today.
Flags: needinfo?(seth)
Assignee | ||
Comment 13•10 years ago
|
||
(In reply to David Flanagan [:djf] from comment #11)
> And another question: is there any intention to uplift this to the newly-cut
> Gecko branch for FirefoxOS v2.2? If so, that will dramatically change the
> urgency behind bug 1121648.
The plan is to uplift to B2G 2.2, yeah.
Assignee | ||
Comment 14•10 years ago
|
||
This needed a rebase.
Assignee | ||
Updated•10 years ago
|
Attachment #8546991 -
Attachment is obsolete: true
Assignee | ||
Comment 15•10 years ago
|
||
This needed a rebase.
Assignee | ||
Updated•10 years ago
|
Attachment #8546993 -
Attachment is obsolete: true
Assignee | ||
Comment 16•10 years ago
|
||
We need a new try job:
https://tbpl.mozilla.org/?tree=Try&rev=1f74115e24ec
Assignee | ||
Comment 17•10 years ago
|
||
Try job looks OK. This should be ready to push.
Assignee | ||
Comment 18•10 years ago
|
||
Comment 19•10 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/c3ae3c5f147a
https://hg.mozilla.org/mozilla-central/rev/dba129633849
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla38
FWIW, this broke --disable-skia, since MOZ_RELEASE_ASSERT expects a condition to check, not just a string.
Assignee | ||
Comment 21•10 years ago
|
||
(In reply to Kyle Huey [:khuey] (khuey@mozilla.com) (Away 1/22-2/8) from comment #20)
> FWIW, this broke --disable-skia, since MOZ_RELEASE_ASSERT expects a
> condition to check, not just a string.
Doh, thanks for pointing that out. I'll file a followup to fix it.
You need to log in
before you can comment on or make changes to this bug.
Description
•