Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Issue 1395183003: Add scaled subset API to SkCodec (Closed)

Created:
5 years, 2 months ago by msarett
Modified:
5 years, 1 month ago
Reviewers:
scroggo, reed1
CC:
reviews_skia.org
Base URL:
https://skia.googlesource.com/skia.git@split0
Target Ref:
refs/heads/master
Project:
skia
Visibility:
Public.

Description

Add scaled subset API to SkCodec The new API is implemented by SkScaledCodec and SkWebpCodec. BUG=skia:3257

Patch Set 1 : #

Total comments: 15
Unified diffs Side-by-side diffs Delta from patch set Stats (+566 lines, -184 lines) Patch
M dm/DMSrcSink.cpp View 5 chunks +13 lines, -18 lines 0 comments Download
M include/codec/SkCodec.h View 6 chunks +96 lines, -25 lines 7 comments Download
M include/codec/SkScaledCodec.h View 2 chunks +39 lines, -0 lines 0 comments Download
M src/codec/SkBmpRLECodec.cpp View 2 chunks +2 lines, -2 lines 0 comments Download
M src/codec/SkCodec.cpp View 3 chunks +90 lines, -23 lines 1 comment Download
M src/codec/SkCodecPriv.h View 2 chunks +17 lines, -6 lines 1 comment Download
M src/codec/SkScaledCodec.cpp View 10 chunks +277 lines, -81 lines 2 comments Download
M src/codec/SkSwizzler.cpp View 1 chunk +0 lines, -3 lines 2 comments Download
M src/codec/SkWebpCodec.h View 1 chunk +5 lines, -1 line 0 comments Download
M src/codec/SkWebpCodec.cpp View 3 chunks +26 lines, -24 lines 2 comments Download
M tests/CodexTest.cpp View 1 chunk +1 line, -1 line 0 comments Download

Depends on Patchset:

Dependent Patchsets:

Messages

Total messages: 14 (10 generated)
msarett
I decided to split this up one more time. These are the changes to the ...
5 years, 2 months ago (2015-10-12 18:33:29 UTC) #11
reed1
https://codereview.chromium.org/1395183003/diff/180001/include/codec/SkCodec.h File include/codec/SkCodec.h (right): https://codereview.chromium.org/1395183003/diff/180001/include/codec/SkCodec.h#newcode228 include/codec/SkCodec.h:228: bool getScaledSubsetDimensions(float desiredScale, const Options& options) const; wow, pretty ...
5 years, 2 months ago (2015-10-12 20:21:00 UTC) #12
msarett
Yeah you're right. I'll work on splitting this into multiple functions. In the meantime, how ...
5 years, 2 months ago (2015-10-12 20:30:27 UTC) #13
scroggo
5 years, 2 months ago (2015-10-12 20:47:07 UTC) #14
https://codereview.chromium.org/1395183003/diff/180001/include/codec/SkCodec.h
File include/codec/SkCodec.h (right):

https://codereview.chromium.org/1395183003/diff/180001/include/codec/SkCodec....
include/codec/SkCodec.h:172: *      (3) If fSubset is NULL and the dstInfo
dimensions match the
Maybe it is worth noting that (2) and (3) are the same as if there was no
Options object?

https://codereview.chromium.org/1395183003/diff/180001/include/codec/SkCodec....
include/codec/SkCodec.h:176: *  If both are non-NULL we are performing a scaled
subset decode:
Which "both"? fScaledDimensions and fScaledSubset?

https://codereview.chromium.org/1395183003/diff/180001/include/codec/SkCodec....
include/codec/SkCodec.h:208: *                      options->fSubset (in/out)
specifies the
If we wanted to, we could make options an optional parameter (haha) and combine
this with getScaledDimensions. I'm not sure whether that's better. (My suspicion
is that since most codecs do not support subsets at all, it makes sense to keep
them separate, so asking for a scale does not worry about subsetting, but I do
think it's at least worth considering.)

Sort of on the other extreme, it seems like SkCodec needs to do a lot of work to
handle subsets, which are only supported by two subclasses. I wonder if we
should refactor things so that SkCodec doesn't need to know anything about
subsets. The sticky point here is webp, which supports subsets natively instead
of supporting scanline decoding. I think we have the following options:
- This approach, where SkCodec has to deal with subsets
- Sort of a hybrid approach, where SkCodec knows minimally about subsets (in
order to support webp). All of this new functionality goes directly on
SkScaledCodec (which I think will need to pass through to SkWebpCodec). Maybe
SkScaledCodec's API looks very different, as it will be focused on handling
subsets.
- All subset handling is done inside SkScaledCodec. Webp will potentially be
very slow, since we do not have a scanline decoder. (We could write a dumb one
though, which decodes 16 scanlines (the blocks that webp are stored in) and
stores them, and then returns one line at a time).
- Maybe SkScaledCodec has its own interface, for which webp has its own
implementation.

There are probably more options I haven't thought of, and it will probably make
sense to discuss in person.

https://codereview.chromium.org/1395183003/diff/180001/include/codec/SkCodec....
include/codec/SkCodec.h:217: *                      the fSubset in terms of
fScaledDimensions.
"in terms of fScaledDimensions" is not intuitive to me.

Do you mean it specifies fSubset after scaling the entire image to
fScaledDimensions? I think something like this may be more clear.

https://codereview.chromium.org/1395183003/diff/180001/include/codec/SkCodec....
include/codec/SkCodec.h:224: *  @return true if fScaledDimensions and
fScaledSubset have been
You've removed getValidSubset, so I assume the intent is to use this function
with desiredScale == 1.0f, but the comments do not describe that use case.

It seems like there should be an option to pass 1.0f and just a subset, and the
caller need never worry about fScaledDimensions or fScaledSubset, since they are
doing neither.

On that note, you do not mention who owns fScaledDimensions or fScaledSubset.
I'm assuming that the client does the following:

Options options;
options.fSubset = &some_rect;
options.fScaledDimensions = &uninitialized_dim;
options.fScaledSubset = &uninitialized_rect;

if (codec->getScaledSubsetDimensions(scale, options)) {
  ...
}

So they handle the pointers.

https://codereview.chromium.org/1395183003/diff/180001/include/codec/SkCodec....
include/codec/SkCodec.h:228: bool getScaledSubsetDimensions(float desiredScale,
const Options& options) const;
The options object does not appear to be const.

https://codereview.chromium.org/1395183003/diff/180001/src/codec/SkCodec.cpp
File src/codec/SkCodec.cpp (right):

https://codereview.chromium.org/1395183003/diff/180001/src/codec/SkCodec.cpp#...
src/codec/SkCodec.cpp:141: if (!is_valid_subset(subset,
this->getInfo().dimensions())) {
nit: fInfo.dimensions()

No need to call the accessor function, since this class can access it directly
(unless there was a side effect, and I believe there is not).

https://codereview.chromium.org/1395183003/diff/180001/src/codec/SkCodecPriv.h
File src/codec/SkCodecPriv.h (right):

https://codereview.chromium.org/1395183003/diff/180001/src/codec/SkCodecPriv....
src/codec/SkCodecPriv.h:73: * to name variables using y-coordinate naming
conventions.
Was y picked arbitrarily over x? I understand it makes sense to be less
abstract, but I don't see why y is more clear.

https://codereview.chromium.org/1395183003/diff/180001/src/codec/SkScaledCode...
File src/codec/SkScaledCodec.cpp (right):

https://codereview.chromium.org/1395183003/diff/180001/src/codec/SkScaledCode...
src/codec/SkScaledCodec.cpp:54: static bool is_in_subset(int coord, int offset,
int length) {
nit: It seems like this is a more generic function. To me it looks like:

  static bool is_in_range(int x, int minInclusive, int maxExclusive)

which is clearer to me. Thoughts?

https://codereview.chromium.org/1395183003/diff/180001/src/codec/SkScaledCode...
src/codec/SkScaledCodec.cpp:55: if (coord < offset || coord >= offset + length)
{
nit: This can just be:

  return coord >= offset && coord < offset + length;

(unless you find what you have more clear?)

https://codereview.chromium.org/1395183003/diff/180001/src/codec/SkSwizzler.cpp
File src/codec/SkSwizzler.cpp (left):

https://codereview.chromium.org/1395183003/diff/180001/src/codec/SkSwizzler.c...
src/codec/SkSwizzler.cpp:713: 
On 2015/10/12 18:33:29, msarett wrote:
> I missed this in an earlier CL, but this check is no longer valid.
> 
> We may want a ten pixel subset that starts twenty pixels from the left edge of
> the image.
> 
> This is completely valid, but in this case fX0 = 20 and fSrcWidth = 10.

Wait, does this belong in crrev.com/1390213002? I would prefer it go in with
that one (or by itself) than here.

https://codereview.chromium.org/1395183003/diff/180001/src/codec/SkWebpCodec.cpp
File src/codec/SkWebpCodec.cpp (right):

https://codereview.chromium.org/1395183003/diff/180001/src/codec/SkWebpCodec....
src/codec/SkWebpCodec.cpp:124: return !((subset.left() & 1) || (subset.top() &
1));
Could you add a comment explaining this? (Left and top must be even.)

I suppose we don't need to worry about containment, because that was checked in
in subsetSupported?

Powered by Google App Engine
This is Rietveld 408576698