2015-09-08 22:35:32 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkBitmapRegionCanvas.h"
|
|
|
|
#include "SkBitmapRegionDecoderInterface.h"
|
|
|
|
#include "SkBitmapRegionSampler.h"
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
#include "SkCodec.h"
|
2015-10-12 17:24:38 +00:00
|
|
|
#include "SkCodecPriv.h"
|
2015-09-08 22:35:32 +00:00
|
|
|
#include "SkImageDecoder.h"
|
|
|
|
|
|
|
|
SkBitmapRegionDecoderInterface* SkBitmapRegionDecoderInterface::CreateBitmapRegionDecoder(
|
|
|
|
SkStreamRewindable* stream, Strategy strategy) {
|
2015-10-09 19:15:57 +00:00
|
|
|
SkAutoTDelete<SkStreamRewindable> streamDeleter(stream);
|
2015-09-08 22:35:32 +00:00
|
|
|
switch (strategy) {
|
|
|
|
case kOriginal_Strategy: {
|
|
|
|
SkImageDecoder* decoder = SkImageDecoder::Factory(stream);
|
|
|
|
int width, height;
|
|
|
|
if (nullptr == decoder) {
|
2015-10-12 17:24:38 +00:00
|
|
|
SkCodecPrintf("Error: Could not create image decoder.\n");
|
2015-09-08 22:35:32 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2015-10-09 19:15:57 +00:00
|
|
|
if (!decoder->buildTileIndex(streamDeleter.detach(), &width, &height)) {
|
2015-10-12 17:24:38 +00:00
|
|
|
SkCodecPrintf("Error: Could not build tile index.\n");
|
2015-09-08 22:35:32 +00:00
|
|
|
delete decoder;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return new SkBitmapRegionSampler(decoder, width, height);
|
|
|
|
}
|
|
|
|
case kCanvas_Strategy: {
|
2015-10-09 19:15:57 +00:00
|
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(streamDeleter.detach()));
|
2015-10-09 18:07:34 +00:00
|
|
|
if (nullptr == codec) {
|
2015-10-12 17:24:38 +00:00
|
|
|
SkCodecPrintf("Error: Failed to create decoder.\n");
|
2015-09-08 22:35:32 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2015-10-09 18:07:34 +00:00
|
|
|
switch (codec->getScanlineOrder()) {
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
case SkCodec::kTopDown_SkScanlineOrder:
|
|
|
|
case SkCodec::kNone_SkScanlineOrder:
|
2015-09-08 22:35:32 +00:00
|
|
|
break;
|
|
|
|
default:
|
2015-10-12 17:24:38 +00:00
|
|
|
SkCodecPrintf("Error: Scanline ordering not supported.\n");
|
2015-09-08 22:35:32 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2015-10-09 18:07:34 +00:00
|
|
|
return new SkBitmapRegionCanvas(codec.detach());
|
2015-09-08 22:35:32 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|