diff options
author | scroggo <scroggo@google.com> | 2015-09-30 08:57:13 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-30 08:57:14 -0700 |
commit | 46c574725676b26ada63ac15e42cda309dcd5090 (patch) | |
tree | d9ee41e9f1c607ff139eca622bb03809eb9a83d3 /src/codec/SkBmpCodec.h | |
parent | e2bcec38486f2e1a897973c953e5610eaef4221e (diff) |
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
Diffstat (limited to 'src/codec/SkBmpCodec.h')
-rw-r--r-- | src/codec/SkBmpCodec.h | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/codec/SkBmpCodec.h b/src/codec/SkBmpCodec.h index 4b2cd2a268..ea6f789407 100644 --- a/src/codec/SkBmpCodec.h +++ b/src/codec/SkBmpCodec.h @@ -11,7 +11,6 @@ #include "SkColorTable.h" #include "SkImageInfo.h" #include "SkMaskSwizzler.h" -#include "SkScanlineDecoder.h" #include "SkStream.h" #include "SkSwizzler.h" #include "SkTypes.h" @@ -41,17 +40,10 @@ public: */ static SkCodec* NewFromIco(SkStream*); - /* - * Assumes IsBmp was called and returned true - * Creates a bmp scanline decoder - * Takes ownership of the stream - */ - static SkScanlineDecoder* NewSDFromStream(SkStream* stream); - protected: SkBmpCodec(const SkImageInfo& info, SkStream* stream, uint16_t bitsPerPixel, - SkScanlineDecoder::SkScanlineOrder rowOrder); + SkCodec::SkScanlineOrder rowOrder); SkEncodedFormat onGetEncodedFormat() const override { return kBMP_SkEncodedFormat; } @@ -87,7 +79,7 @@ protected: * when we want to decode the full or one when we are * sampling. */ - int32_t getDstRow(int32_t y, int32_t height); + int32_t getDstRow(int32_t y, int32_t height) const; /* * Get the destination row to start filling from @@ -107,7 +99,7 @@ protected: * Accessors used by subclasses */ uint16_t bitsPerPixel() const { return fBitsPerPixel; } - SkScanlineDecoder::SkScanlineOrder rowOrder() const { return fRowOrder; } + SkScanlineOrder onGetScanlineOrder() const override { return fRowOrder; } /* * To be overriden by bmp subclasses, which provide unique implementations. @@ -153,10 +145,17 @@ private: virtual Result decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, const Options& opts) = 0; - const uint16_t fBitsPerPixel; - const SkScanlineDecoder::SkScanlineOrder fRowOrder; + Result onStartScanlineDecode(const SkImageInfo& dstInfo, const SkCodec::Options&, + SkPMColor inputColorPtr[], int* inputColorCount) override; + + Result onGetScanlines(void* dst, int count, size_t rowBytes) override; + + int onNextScanline() const override; + + // TODO(msarett): Override default skipping with something more clever. - friend class SkBmpScanlineDecoder; + const uint16_t fBitsPerPixel; + const SkScanlineOrder fRowOrder; typedef SkCodec INHERITED; }; |