SkCodec no longer inherits from SkImageGenerator.
authorscroggo <scroggo@chromium.org>
Thu, 9 Jul 2015 15:16:03 +0000 (08:16 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 9 Jul 2015 15:16:03 +0000 (08:16 -0700)
SkImageGenerator makes some assumptions that are not necessarily valid
for SkCodec. For example, SkCodec does not assume that it can always be
rewound.

We also have an ongoing question of what an SkCodec should report as
its default settings (i.e. the return from getInfo). It makes sense for
an SkCodec to report that its pixels are unpremultiplied, if that is
the case for the underlying data, but if a client of SkImageGenerator
uses the default settings (as many do), they will receive
unpremultiplied pixels which cannot (currently) be drawn with Skia. We
may ultimately decide to revisit SkCodec reporting an SkImageInfo, but
I have left it unchanged for now.

Import features of SkImageGenerator used by SkCodec into SkCodec.

I have left SkImageGenerator unchanged for now, but it no longer needs
Result or Options. This will require changes to Chromium.

Manually handle the lifetime of fScanlineDecoder, so SkScanlineDecoder.h
can include SkCodec.h (where Result is), and SkCodec.h does not need
to include it (to delete fScanlineDecoder).

In many places, make the following simple changes:
- Now include SkScanlineDecoder.h, which is no longer included by
  SkCodec.h
- Use the enums in SkCodec, rather than SkImageGenerator
- Stop including SkImageGenerator.h where no longer needed

Review URL: https://codereview.chromium.org/1220733013

17 files changed:
bench/CodecBench.cpp
bench/nanobench.cpp
bench/subset/SubsetSingleBench.cpp
bench/subset/SubsetTranslateBench.cpp
bench/subset/SubsetZoomBench.cpp
dm/DMSrcSink.cpp
include/codec/SkCodec.h
include/codec/SkScanlineDecoder.h
src/codec/SkCodec.cpp
src/codec/SkCodec_libbmp.cpp
src/codec/SkCodec_libpng.cpp
src/codec/SkCodec_wbmp.cpp
src/codec/SkJpegCodec.cpp
src/codec/SkSwizzler.cpp
src/codec/SkSwizzler.h
src/codec/SkWebpCodec.cpp
tests/CodexTest.cpp

index debda71..903b733 100644 (file)
@@ -8,7 +8,6 @@
 #include "CodecBench.h"
 #include "SkBitmap.h"
 #include "SkCodec.h"
-#include "SkImageGenerator.h"
 #include "SkOSFile.h"
 
 CodecBench::CodecBench(SkString baseName, SkData* encoded, SkColorType colorType)
@@ -70,11 +69,11 @@ void CodecBench::onDraw(const int n, SkCanvas* canvas) {
         colorCount = 256;
         codec.reset(SkCodec::NewFromData(fData));
 #ifdef SK_DEBUG
-        const SkImageGenerator::Result result =
+        const SkCodec::Result result =
 #endif
         codec->getPixels(fInfo, fPixelStorage.get(), fInfo.minRowBytes(),
                          NULL, colorTable, &colorCount);
-        SkASSERT(result == SkImageGenerator::kSuccess
-                 || result == SkImageGenerator::kIncompleteInput);
+        SkASSERT(result == SkCodec::kSuccess
+                 || result == SkCodec::kIncompleteInput);
     }
 }
index 519d320..a2f349b 100644 (file)
@@ -780,15 +780,15 @@ public:
                 int colorCount = 256;
                 SkPMColor colors[256];
 
-                const SkImageGenerator::Result result = codec->getPixels(
+                const SkCodec::Result result = codec->getPixels(
                         info, storage.get(), rowBytes, NULL, colors,
                         &colorCount);
                 switch (result) {
-                    case SkImageGenerator::kSuccess:
-                    case SkImageGenerator::kIncompleteInput:
+                    case SkCodec::kSuccess:
+                    case SkCodec::kIncompleteInput:
                         return new CodecBench(SkOSPath::Basename(path.c_str()),
                                 encoded, colorType);
-                    case SkImageGenerator::kInvalidConversion:
+                    case SkCodec::kInvalidConversion:
                         // This is okay. Not all conversions are valid.
                         break;
                     default:
index 6c1da5c..9fd31e8 100644 (file)
@@ -11,6 +11,7 @@
 #include "SkCodec.h"
 #include "SkImageDecoder.h"
 #include "SkOSFile.h"
+#include "SkScanlineDecoder.h"
 #include "SkStream.h"
 
 /*
index 0769015..2745a9c 100644 (file)
@@ -11,6 +11,7 @@
 #include "SkCodec.h"
 #include "SkImageDecoder.h"
 #include "SkOSFile.h"
+#include "SkScanlineDecoder.h"
 #include "SkStream.h"
 
 /*
index 39f234a..12dd885 100644 (file)
@@ -11,6 +11,7 @@
 #include "SkCodec.h"
 #include "SkImageDecoder.h"
 #include "SkOSFile.h"
+#include "SkScanlineDecoder.h"
 #include "SkStream.h"
 
 /*
index f83ba3b..f7daad7 100644 (file)
@@ -143,12 +143,12 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
         case kNormal_Mode: {
             switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowBytes(), NULL,
                     colorPtr, colorCountPtr)) {
-                case SkImageGenerator::kSuccess:
+                case SkCodec::kSuccess:
                     // We consider incomplete to be valid, since we should still decode what is
                     // available.
-                case SkImageGenerator::kIncompleteInput:
+                case SkCodec::kIncompleteInput:
                     break;
-                case SkImageGenerator::kInvalidConversion:
+                case SkCodec::kInvalidConversion:
                     return Error::Nonfatal("Incompatible colortype conversion");
                 default:
                     // Everything else is considered a failure.
@@ -163,11 +163,11 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
             if (NULL == scanlineDecoder) {
                 return Error::Nonfatal("Cannot use scanline decoder for all images");
             }
-            const SkImageGenerator::Result result = scanlineDecoder->getScanlines(
+            const SkCodec::Result result = scanlineDecoder->getScanlines(
                     bitmap.getAddr(0, 0), decodeInfo.height(), bitmap.rowBytes());
             switch (result) {
-                case SkImageGenerator::kSuccess:
-                case SkImageGenerator::kIncompleteInput:
+                case SkCodec::kSuccess:
+                case SkCodec::kIncompleteInput:
                     break;
                 default:
                     return SkStringPrintf("%s failed with error message %d",
@@ -231,11 +231,11 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
                         }
                     }
                     //skip to first line of subset
-                    const SkImageGenerator::Result skipResult =
+                    const SkCodec::Result skipResult =
                             subsetScanlineDecoder->skipScanlines(y);
                     switch (skipResult) {
-                        case SkImageGenerator::kSuccess:
-                        case SkImageGenerator::kIncompleteInput:
+                        case SkCodec::kSuccess:
+                        case SkCodec::kIncompleteInput:
                             break;
                         default:
                             return SkStringPrintf("%s failed after attempting to skip %d scanlines"
@@ -247,11 +247,11 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
                     bounds.setXYWH(0, 0, currentSubsetWidth, currentSubsetHeight);
                     SkAssertResult(largestSubsetBm.extractSubset(&subsetBm, bounds));
                     SkAutoLockPixels autlockSubsetBm(subsetBm, true);
-                    const SkImageGenerator::Result subsetResult =
+                    const SkCodec::Result subsetResult =
                         subsetScanlineDecoder->getScanlines(buffer, currentSubsetHeight, rowBytes);
                     switch (subsetResult) {
-                        case SkImageGenerator::kSuccess:
-                        case SkImageGenerator::kIncompleteInput:
+                        case SkCodec::kSuccess:
+                        case SkCodec::kIncompleteInput:
                             break;
                         default:
                             return SkStringPrintf("%s failed with error message %d",
@@ -295,10 +295,10 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
             for (int i = 0; i < numStripes; i += 2) {
                 // Skip a stripe
                 const int linesToSkip = SkTMin(stripeHeight, height - i * stripeHeight);
-                SkImageGenerator::Result result = decoder->skipScanlines(linesToSkip);
+                SkCodec::Result result = decoder->skipScanlines(linesToSkip);
                 switch (result) {
-                    case SkImageGenerator::kSuccess:
-                    case SkImageGenerator::kIncompleteInput:
+                    case SkCodec::kSuccess:
+                    case SkCodec::kIncompleteInput:
                         break;
                     default:
                         return SkStringPrintf("Cannot skip scanlines for %s.", fPath.c_str());
@@ -311,8 +311,8 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
                     result = decoder->getScanlines(bitmap.getAddr(0, startY),
                             linesToRead, bitmap.rowBytes());
                     switch (result) {
-                        case SkImageGenerator::kSuccess:
-                        case SkImageGenerator::kIncompleteInput:
+                        case SkCodec::kSuccess:
+                        case SkCodec::kIncompleteInput:
                             break;
                         default:
                             return SkStringPrintf("Cannot get scanlines for %s.", fPath.c_str());
@@ -329,11 +329,11 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
                 // Read a stripe
                 const int startY = i * stripeHeight;
                 const int linesToRead = SkTMin(stripeHeight, height - startY);
-                SkImageGenerator::Result result = decoder->getScanlines(bitmap.getAddr(0, startY),
+                SkCodec::Result result = decoder->getScanlines(bitmap.getAddr(0, startY),
                         linesToRead, bitmap.rowBytes());
                 switch (result) {
-                    case SkImageGenerator::kSuccess:
-                    case SkImageGenerator::kIncompleteInput:
+                    case SkCodec::kSuccess:
+                    case SkCodec::kIncompleteInput:
                         break;
                     default:
                         return SkStringPrintf("Cannot get scanlines for %s.", fPath.c_str());
@@ -344,8 +344,8 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
                 if (linesToSkip > 0) {
                     result = decoder->skipScanlines(linesToSkip);
                     switch (result) {
-                        case SkImageGenerator::kSuccess:
-                        case SkImageGenerator::kIncompleteInput:
+                        case SkCodec::kSuccess:
+                        case SkCodec::kIncompleteInput:
                             break;
                         default:
                             return SkStringPrintf("Cannot skip scanlines for %s.", fPath.c_str());
index e462be2..54bd6ff 100644 (file)
@@ -8,21 +8,21 @@
 #ifndef SkCodec_DEFINED
 #define SkCodec_DEFINED
 
+#include "SkColor.h"
 #include "SkEncodedFormat.h"
-#include "SkImageGenerator.h"
 #include "SkImageInfo.h"
-#include "SkScanlineDecoder.h"
 #include "SkSize.h"
 #include "SkStream.h"
 #include "SkTemplates.h"
 #include "SkTypes.h"
 
 class SkData;
+class SkScanlineDecoder;
 
 /**
  *  Abstraction layer directly on top of an image codec.
  */
-class SkCodec : public SkImageGenerator {
+class SkCodec : SkNoncopyable {
 public:
     /**
      *  If this stream represents an encoded image that we know how to decode,
@@ -41,12 +41,17 @@ public:
      */
     static SkCodec* NewFromData(SkData*);
 
+    virtual ~SkCodec();
+
+    /**
+     *  Return the ImageInfo associated with this codec.
+     */
+    const SkImageInfo& getInfo() const { return fInfo; }
+
     /**
      *  Return a size that approximately supports the desired scale factor.
      *  The codec may not be able to scale efficiently to the exact scale
      *  factor requested, so return a size that approximates that scale.
-     *
-     *  FIXME: Move to SkImageGenerator?
      */
     SkISize getScaledDimensions(float desiredScale) const {
         return this->onGetScaledDimensions(desiredScale);
@@ -58,6 +63,115 @@ public:
     SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat(); }
 
     /**
+     *  Used to describe the result of a call to getPixels().
+     *
+     *  Result is the union of possible results from subclasses.
+     */
+    enum Result {
+        /**
+         *  General return value for success.
+         */
+        kSuccess,
+        /**
+         *  The input is incomplete. A partial image was generated.
+         */
+        kIncompleteInput,
+        /**
+         *  The generator cannot convert to match the request, ignoring
+         *  dimensions.
+         */
+        kInvalidConversion,
+        /**
+         *  The generator cannot scale to requested size.
+         */
+        kInvalidScale,
+        /**
+         *  Parameters (besides info) are invalid. e.g. NULL pixels, rowBytes
+         *  too small, etc.
+         */
+        kInvalidParameters,
+        /**
+         *  The input did not contain a valid image.
+         */
+        kInvalidInput,
+        /**
+         *  Fulfilling this request requires rewinding the input, which is not
+         *  supported for this input.
+         */
+        kCouldNotRewind,
+        /**
+         *  This method is not implemented by this generator.
+         */
+        kUnimplemented,
+    };
+
+    /**
+     *  Whether or not the memory passed to getPixels is zero initialized.
+     */
+    enum ZeroInitialized {
+        /**
+         *  The memory passed to getPixels is zero initialized. The SkCodec
+         *  may take advantage of this by skipping writing zeroes.
+         */
+        kYes_ZeroInitialized,
+        /**
+         *  The memory passed to getPixels has not been initialized to zero,
+         *  so the SkCodec must write all zeroes to memory.
+         *
+         *  This is the default. It will be used if no Options struct is used.
+         */
+        kNo_ZeroInitialized,
+    };
+
+    /**
+     *  Additional options to pass to getPixels.
+     */
+    struct Options {
+        Options()
+            : fZeroInitialized(kNo_ZeroInitialized) {}
+
+        ZeroInitialized fZeroInitialized;
+    };
+
+    /**
+     *  Decode into the given pixels, a block of memory of size at
+     *  least (info.fHeight - 1) * rowBytes + (info.fWidth *
+     *  bytesPerPixel)
+     *
+     *  Repeated calls to this function should give the same results,
+     *  allowing the PixelRef to be immutable.
+     *
+     *  @param info A description of the format (config, size)
+     *         expected by the caller.  This can simply be identical
+     *         to the info returned by getInfo().
+     *
+     *         This contract also allows the caller to specify
+     *         different output-configs, which the implementation can
+     *         decide to support or not.
+     *
+     *         A size that does not match getInfo() implies a request
+     *         to scale. If the generator cannot perform this scale,
+     *         it will return kInvalidScale.
+     *
+     *  If info is kIndex8_SkColorType, then the caller must provide storage for up to 256
+     *  SkPMColor values in ctable. On success the generator must copy N colors into that storage,
+     *  (where N is the logical number of table entries) and set ctableCount to N.
+     *
+     *  If info is not kIndex8_SkColorType, then the last two parameters may be NULL. If ctableCount
+     *  is not null, it will be set to 0.
+     *
+     *  @return Result kSuccess, or another value explaining the type of failure.
+     */
+    Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options*,
+                     SkPMColor ctable[], int* ctableCount);
+
+    /**
+     *  Simplified version of getPixels() that asserts that info is NOT kIndex8_SkColorType and
+     *  uses the default Options.
+     */
+    Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes);
+
+    /**
      *  Return an object which can be used to decode individual scanlines.
      *
      *  This object is owned by the SkCodec, which will handle its lifetime. The
@@ -118,6 +232,10 @@ protected:
 
     virtual SkEncodedFormat onGetEncodedFormat() const = 0;
 
+    virtual Result onGetPixels(const SkImageInfo& info,
+                               void* pixels, size_t rowBytes, const Options&,
+                               SkPMColor ctable[], int* ctableCount) = 0;
+
     /**
      *  Override if your codec supports scanline decoding.
      *
@@ -182,7 +300,7 @@ protected:
      * created a new scanline decoder.
      */
     SkScanlineDecoder* scanlineDecoder() {
-        return fScanlineDecoder.get();
+        return fScanlineDecoder;
     }
 
     /**
@@ -191,14 +309,15 @@ protected:
      * in the destructor of the subclass.
      */
     SkScanlineDecoder* detachScanlineDecoder() {
-        return fScanlineDecoder.detach();
+        SkScanlineDecoder* scanlineDecoder = fScanlineDecoder;
+        fScanlineDecoder = NULL;
+        return scanlineDecoder;
     }
 
 private:
-    SkAutoTDelete<SkStream>             fStream;
-    bool                                fNeedsRewind;
-    SkAutoTDelete<SkScanlineDecoder>    fScanlineDecoder;
-
-    typedef SkImageGenerator INHERITED;
+    const SkImageInfo       fInfo;
+    SkAutoTDelete<SkStream> fStream;
+    bool                    fNeedsRewind;
+    SkScanlineDecoder*      fScanlineDecoder;
 };
 #endif // SkCodec_DEFINED
index eac31ef..942c1b9 100644 (file)
@@ -9,8 +9,8 @@
 #define SkScanlineDecoder_DEFINED
 
 #include "SkTypes.h"
+#include "SkCodec.h"
 #include "SkTemplates.h"
-#include "SkImageGenerator.h"
 #include "SkImageInfo.h"
 
 class SkScanlineDecoder : public SkNoncopyable {
@@ -40,12 +40,12 @@ public:
      *  @param rowBytes Number of bytes per row. Must be large enough to hold
      *      a scanline based on the SkImageInfo used to create this object.
      */
-    SkImageGenerator::Result getScanlines(void* dst, int countLines, size_t rowBytes) {
+    SkCodec::Result getScanlines(void* dst, int countLines, size_t rowBytes) {
         if ((rowBytes < fDstInfo.minRowBytes() && countLines > 1 ) || countLines <= 0
                 || fCurrScanline + countLines > fDstInfo.height()) {
-            return SkImageGenerator::kInvalidParameters;
+            return SkCodec::kInvalidParameters;
         }
-        const SkImageGenerator::Result result = this->onGetScanlines(dst, countLines, rowBytes);
+        const SkCodec::Result result = this->onGetScanlines(dst, countLines, rowBytes);
         fCurrScanline += countLines;
         return result;
     }
@@ -58,14 +58,14 @@ public:
      *  will make reallyHasAlpha return true, when it could have returned
      *  false.
      */
-    SkImageGenerator::Result skipScanlines(int countLines) {
+    SkCodec::Result skipScanlines(int countLines) {
         if (fCurrScanline + countLines > fDstInfo.height()) {
             // Arguably, we could just skip the scanlines which are remaining,
             // and return kSuccess. We choose to return invalid so the client
             // can catch their bug.
-            return SkImageGenerator::kInvalidParameters;
+            return SkCodec::kInvalidParameters;
         }
-        const SkImageGenerator::Result result = this->onSkipScanlines(countLines);
+        const SkCodec::Result result = this->onSkipScanlines(countLines);
         fCurrScanline += countLines;
         return result;
     }
@@ -96,7 +96,7 @@ private:
     int                 fCurrScanline;
 
     // Naive default version just calls onGetScanlines on temp memory.
-    virtual SkImageGenerator::Result onSkipScanlines(int countLines) {
+    virtual SkCodec::Result onSkipScanlines(int countLines) {
         SkAutoMalloc storage(fDstInfo.minRowBytes());
         // Note that we pass 0 to rowBytes so we continue to use the same memory.
         // Also note that while getScanlines checks that rowBytes is big enough,
@@ -106,7 +106,7 @@ private:
         return this->onGetScanlines(storage.get(), countLines, 0);
     }
 
-    virtual SkImageGenerator::Result onGetScanlines(void* dst, int countLines,
+    virtual SkCodec::Result onGetScanlines(void* dst, int countLines,
                                                     size_t rowBytes) = 0;
 
 };
index c24bb54..760975e 100644 (file)
@@ -16,6 +16,7 @@
 #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
 #include "SkJpegCodec.h"
 #endif
+#include "SkScanlineDecoder.h"
 #include "SkStream.h"
 #include "SkWebpCodec.h"
 
@@ -76,11 +77,16 @@ SkCodec* SkCodec::NewFromData(SkData* data) {
 }
 
 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream)
-    : INHERITED(info)
+    : fInfo(info)
     , fStream(stream)
     , fNeedsRewind(false)
+    , fScanlineDecoder(NULL)
 {}
 
+SkCodec::~SkCodec() {
+    SkDELETE(fScanlineDecoder);
+}
+
 SkCodec::RewindState SkCodec::rewindIfNeeded() {
     // Store the value of fNeedsRewind so we can update it. Next read will
     // require a rewind.
@@ -93,6 +99,51 @@ SkCodec::RewindState SkCodec::rewindIfNeeded() {
                              : kCouldNotRewind_RewindState;
 }
 
+SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
+                                   const Options* options, SkPMColor ctable[], int* ctableCount) {
+    if (kUnknown_SkColorType == info.colorType()) {
+        return kInvalidConversion;
+    }
+    if (NULL == pixels) {
+        return kInvalidParameters;
+    }
+    if (rowBytes < info.minRowBytes()) {
+        return kInvalidParameters;
+    }
+
+    if (kIndex_8_SkColorType == info.colorType()) {
+        if (NULL == ctable || NULL == ctableCount) {
+            return kInvalidParameters;
+        }
+    } else {
+        if (ctableCount) {
+            *ctableCount = 0;
+        }
+        ctableCount = NULL;
+        ctable = NULL;
+    }
+
+    // Default options.
+    Options optsStorage;
+    if (NULL == options) {
+        options = &optsStorage;
+    }
+    const Result result = this->onGetPixels(info, pixels, rowBytes, *options, ctable, ctableCount);
+
+    if ((kIncompleteInput == result || kSuccess == result) && ctableCount) {
+        SkASSERT(*ctableCount >= 0 && *ctableCount <= 256);
+    }
+    return result;
+}
+
+SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) {
+    SkASSERT(kIndex_8_SkColorType != info.colorType());
+    if (kIndex_8_SkColorType == info.colorType()) {
+        return kInvalidConversion;
+    }
+    return this->getPixels(info, pixels, rowBytes, NULL, NULL, NULL);
+}
+
 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo, const Options* options,
         SkPMColor ctable[], int* ctableCount) {
 
@@ -102,8 +153,9 @@ SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo, const
         options = &optsStorage;
     }
 
-    fScanlineDecoder.reset(this->onGetScanlineDecoder(dstInfo, *options, ctable, ctableCount));
-    return fScanlineDecoder.get();
+    SkDELETE(fScanlineDecoder);
+    fScanlineDecoder = this->onGetScanlineDecoder(dstInfo, *options, ctable, ctableCount);
+    return fScanlineDecoder;
 }
 
 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo) {
index fdb0bd6..3ac4b0b 100644 (file)
@@ -1130,8 +1130,7 @@ SkCodec::Result SkBmpCodec::decode(const SkImageInfo& dstInfo,
 
     // Create swizzler
     SkAutoTDelete<SkSwizzler> swizzler(SkSwizzler::CreateSwizzler(config,
-            colorPtr, dstInfo, dst, dstRowBytes,
-            SkImageGenerator::kNo_ZeroInitialized));
+            colorPtr, dstInfo, dst, dstRowBytes, kNo_ZeroInitialized));
 
     // Allocate space for a row buffer and a source for the swizzler
     SkAutoTDeleteArray<uint8_t> srcBuffer(SkNEW_ARRAY(uint8_t, rowBytes));
index 18e973b..a14a67c 100644 (file)
@@ -610,10 +610,10 @@ public:
         fSrcRow = static_cast<uint8_t*>(fStorage.get());
     }
 
-    SkImageGenerator::Result onGetScanlines(void* dst, int count, size_t rowBytes) override {
+    SkCodec::Result onGetScanlines(void* dst, int count, size_t rowBytes) override {
         if (setjmp(png_jmpbuf(fCodec->fPng_ptr))) {
             SkCodecPrintf("setjmp long jump!\n");
-            return SkImageGenerator::kInvalidInput;
+            return SkCodec::kInvalidInput;
         }
 
         for (int i = 0; i < count; i++) {
@@ -622,15 +622,15 @@ public:
             fHasAlpha |= !SkSwizzler::IsOpaque(fCodec->fSwizzler->next(fSrcRow));
             dst = SkTAddOffset<void>(dst, rowBytes);
         }
-        return SkImageGenerator::kSuccess;
+        return SkCodec::kSuccess;
     }
 
-    SkImageGenerator::Result onSkipScanlines(int count) override {
+    SkCodec::Result onSkipScanlines(int count) override {
         // FIXME: Could we use the return value of setjmp to specify the type of
         // error?
         if (setjmp(png_jmpbuf(fCodec->fPng_ptr))) {
             SkCodecPrintf("setjmp long jump!\n");
-            return SkImageGenerator::kInvalidInput;
+            return SkCodec::kInvalidInput;
         }
         //there is a potential tradeoff of memory vs speed created by putting this in a loop. 
         //calling png_read_rows in a loop is insignificantly slower than calling it once with count 
@@ -638,7 +638,7 @@ public:
         for (int i = 0; i < count; i++) {
             png_read_rows(fCodec->fPng_ptr, &fSrcRow, png_bytepp_NULL, 1);
         }
-        return SkImageGenerator::kSuccess;
+        return SkCodec::kSuccess;
     }
 
     bool onReallyHasAlpha() const override { return fHasAlpha; }
@@ -668,19 +668,19 @@ public:
         fGarbageRowPtr = static_cast<uint8_t*>(fGarbageRow.get());
     }
 
-    SkImageGenerator::Result onGetScanlines(void* dst, int count, size_t dstRowBytes) override {
+    SkCodec::Result onGetScanlines(void* dst, int count, size_t dstRowBytes) override {
         //rewind stream if have previously called onGetScanlines, 
         //since we need entire progressive image to get scanlines
         if (fRewindNeeded) {
             if(false == fCodec->handleRewind()) {
-                return SkImageGenerator::kCouldNotRewind;
+                return SkCodec::kCouldNotRewind;
             }
         } else {
             fRewindNeeded = true;
         }
         if (setjmp(png_jmpbuf(fCodec->fPng_ptr))) {
             SkCodecPrintf("setjmp long jump!\n");
-            return SkImageGenerator::kInvalidInput;
+            return SkCodec::kInvalidInput;
         }
         const int number_passes = png_set_interlace_handling(fCodec->fPng_ptr);
         SkAutoMalloc storage(count * fSrcRowBytes);
@@ -711,13 +711,13 @@ public:
             srcRow += fSrcRowBytes;
         }
         fCurrentRow += count;
-        return SkImageGenerator::kSuccess;
+        return SkCodec::kSuccess;
     }
 
-    SkImageGenerator::Result onSkipScanlines(int count) override {
+    SkCodec::Result onSkipScanlines(int count) override {
         //when ongetScanlines is called it will skip to fCurrentRow
         fCurrentRow += count;
-        return SkImageGenerator::kSuccess;
+        return SkCodec::kSuccess;
     }
 
     bool onReallyHasAlpha() const override { return fHasAlpha; }
index 073165d..9709a68 100644 (file)
@@ -100,20 +100,20 @@ SkEncodedFormat SkWbmpCodec::onGetEncodedFormat() const {
     return kWBMP_SkEncodedFormat;
 }
 
-SkImageGenerator::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info,
-                                                  void* pixels,
-                                                  size_t rowBytes,
-                                                  const Options&,
-                                                  SkPMColor ctable[],
-                                                  int* ctableCount) {
+SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info,
+                                         void* pixels,
+                                         size_t rowBytes,
+                                         const Options&,
+                                         SkPMColor ctable[],
+                                         int* ctableCount) {
     SkCodec::RewindState rewindState = this->rewindIfNeeded();
     if (rewindState == kCouldNotRewind_RewindState) {
-        return SkImageGenerator::kCouldNotRewind;
+        return kCouldNotRewind;
     } else if (rewindState == kRewound_RewindState) {
         (void)read_header(this->stream(), NULL);
     }
     if (info.dimensions() != this->getInfo().dimensions()) {
-        return SkImageGenerator::kInvalidScale;
+        return kInvalidScale;
     }
     ExpandProc proc = NULL;
     switch (info.colorType()) {
@@ -133,7 +133,7 @@ SkImageGenerator::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info,
             proc = expand_bits_to_T<uint16_t, bit_to_rgb565>;
             break;
         default:
-            return SkImageGenerator::kInvalidConversion;
+            return kInvalidConversion;
     }
     SkISize size = info.dimensions();
     uint8_t* dst = static_cast<uint8_t*>(pixels);
@@ -141,12 +141,12 @@ SkImageGenerator::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info,
     SkAutoTMalloc<uint8_t> src(srcRowBytes);
     for (int y = 0; y < size.height(); ++y) {
         if (this->stream()->read(src.get(), srcRowBytes) != srcRowBytes) {
-            return SkImageGenerator::kIncompleteInput;
+            return kIncompleteInput;
         }
         proc(dst, src.get(), size.width());
         dst += rowBytes;
     }
-    return SkImageGenerator::kSuccess;
+    return kSuccess;
 }
 
 bool SkWbmpCodec::IsWbmp(SkStream* stream) {
index 5e24b17..858e305 100644 (file)
@@ -11,6 +11,7 @@
 #include "SkJpegUtility_codec.h"
 #include "SkCodecPriv.h"
 #include "SkColorPriv.h"
+#include "SkScanlineDecoder.h"
 #include "SkStream.h"
 #include "SkTemplates.h"
 #include "SkTypes.h"
@@ -407,10 +408,10 @@ public:
         , fCodec(codec)
     {}
 
-    SkImageGenerator::Result onGetScanlines(void* dst, int count, size_t rowBytes) override {
+    SkCodec::Result onGetScanlines(void* dst, int count, size_t rowBytes) override {
         // Set the jump location for libjpeg errors
         if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) {
-            return fCodec->fDecoderMgr->returnFailure("setjmp", SkImageGenerator::kInvalidInput);
+            return fCodec->fDecoderMgr->returnFailure("setjmp", SkCodec::kInvalidInput);
         }
 
         // Read rows one at a time
@@ -423,7 +424,7 @@ public:
                 SkSwizzler::Fill(
                         dstRow, this->dstInfo(), rowBytes, count - y, SK_ColorBLACK, NULL);
                 fCodec->fDecoderMgr->dinfo()->output_scanline = this->dstInfo().height();
-                return SkImageGenerator::kIncompleteInput;
+                return SkCodec::kIncompleteInput;
             }
 
             // Convert to RGBA if necessary
@@ -435,7 +436,7 @@ public:
             dstRow = SkTAddOffset<JSAMPLE>(dstRow, rowBytes);
         }
 
-        return SkImageGenerator::kSuccess;
+        return SkCodec::kSuccess;
     }
 
 #ifndef TURBO_HAS_SKIP
@@ -447,15 +448,15 @@ public:
     }
 #endif
 
-    SkImageGenerator::Result onSkipScanlines(int count) override {
+    SkCodec::Result onSkipScanlines(int count) override {
         // Set the jump location for libjpeg errors
         if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) {
-            return fCodec->fDecoderMgr->returnFailure("setjmp", SkImageGenerator::kInvalidInput);
+            return fCodec->fDecoderMgr->returnFailure("setjmp", SkCodec::kInvalidInput);
         }
 
         turbo_jpeg_skip_scanlines(fCodec->fDecoderMgr->dinfo(), count);
 
-        return SkImageGenerator::kSuccess;
+        return SkCodec::kSuccess;
     }
 
 private:
index 294229c..71cb82a 100644 (file)
@@ -275,7 +275,7 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
                                        const SkPMColor* ctable,
                                        const SkImageInfo& info, void* dst,
                                        size_t dstRowBytes,
-                                       SkImageGenerator::ZeroInitialized zeroInit) {
+                                       SkCodec::ZeroInitialized zeroInit) {
     if (info.colorType() == kUnknown_SkColorType || kUnknown == sc) {
         return NULL;
     }
@@ -306,7 +306,7 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
             switch (info.colorType()) {
                 case kN32_SkColorType:
                     // We assume the color premultiplied ctable (or not) as desired.
-                    if (SkImageGenerator::kYes_ZeroInitialized == zeroInit) {
+                    if (SkCodec::kYes_ZeroInitialized == zeroInit) {
                         proc = &swizzle_index_to_n32_skipZ;
                         break;
                     } else {
@@ -377,7 +377,7 @@ SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
                         // Respect zeroInit?
                         proc = &swizzle_rgba_to_n32_unpremul;
                     } else {
-                        if (SkImageGenerator::kYes_ZeroInitialized == zeroInit) {
+                        if (SkCodec::kYes_ZeroInitialized == zeroInit) {
                             proc = &swizzle_rgba_to_n32_premul_skipZ;
                         } else {
                             proc = &swizzle_rgba_to_n32_premul;
index e3a38cb..b00ee14 100644 (file)
@@ -127,7 +127,7 @@ public:
     static SkSwizzler* CreateSwizzler(SrcConfig, const SkPMColor* ctable,
                                       const SkImageInfo&, void* dst,
                                       size_t dstRowBytes,
-                                      SkImageGenerator::ZeroInitialized);
+                                      SkCodec::ZeroInitialized);
 
     /**
      * Fill the remainder of the destination with a single color
index 5ffdd34..32a8b78 100644 (file)
@@ -6,7 +6,6 @@
  */
 
 #include "SkWebpCodec.h"
-#include "SkImageGenerator.h"
 #include "SkTemplates.h"
 
 // A WebP decoder on top of (subset of) libwebp
@@ -63,7 +62,7 @@ static bool webp_parse_header(SkStream* stream, SkImageInfo* info) {
 
     if (info) {
         // FIXME: Is N32 the right type?
-        // Is unpremul the right type? Clients of SkImageGenerator may assume it's the
+        // Is unpremul the right type? Clients of SkCodec may assume it's the
         // best type, when Skia currently cannot draw unpremul (and raster is faster
         // with premul).
         *info = SkImageInfo::Make(features.width, features.height, kN32_SkColorType,
@@ -126,9 +125,8 @@ static WEBP_CSP_MODE webp_decode_mode(SkColorType ct, bool premultiply) {
 // is arbitrary.
 static const size_t BUFFER_SIZE = 4096;
 
-SkImageGenerator::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
-                                                  size_t rowBytes, const Options&, SkPMColor*,
-                                                  int*) {
+SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
+                                         const Options&, SkPMColor*, int*) {
     switch (this->rewindIfNeeded()) {
         case kCouldNotRewind_RewindState:
             return kCouldNotRewind;
index 0edd3cf..32968fd 100644 (file)
@@ -9,6 +9,7 @@
 #include "SkBitmap.h"
 #include "SkCodec.h"
 #include "SkMD5.h"
+#include "SkScanlineDecoder.h"
 #include "Test.h"
 
 static SkStreamAsset* resource(const char path[]) {
@@ -51,9 +52,9 @@ static void check(skiatest::Reporter* r,
     SkBitmap bm;
     bm.allocPixels(info);
     SkAutoLockPixels autoLockPixels(bm);
-    SkImageGenerator::Result result =
+    SkCodec::Result result =
         codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL);
-    REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess);
+    REPORTER_ASSERT(r, result == SkCodec::kSuccess);
 
     SkMD5::Digest digest1, digest2;
     md5(bm, &digest1);
@@ -63,7 +64,7 @@ static void check(skiatest::Reporter* r,
     result =
         codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL);
 
-    REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess);
+    REPORTER_ASSERT(r, result == SkCodec::kSuccess);
     // verify that re-decoding gives the same result.
     md5(bm, &digest2);
     REPORTER_ASSERT(r, digest1 == digest2);
@@ -75,10 +76,10 @@ static void check(skiatest::Reporter* r,
 
         // Regular decodes should be disabled after creating a scanline decoder
         result = codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL);
-        REPORTER_ASSERT(r, SkImageGenerator::kInvalidParameters == result);
+        REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result);
         for (int y = 0; y < info.height(); y++) {
             result = scanlineDecoder->getScanlines(bm.getAddr(0, y), 1, 0);
-            REPORTER_ASSERT(r, result == SkImageGenerator::kSuccess);
+            REPORTER_ASSERT(r, result == SkCodec::kSuccess);
         }
         // verify that scanline decoding gives the same result.
         SkMD5::Digest digest3;
@@ -189,9 +190,9 @@ static void test_dimensions(skiatest::Reporter* r, const char path[]) {
         size_t totalBytes = scaledInfo.getSafeSize(rowBytes);
         SkAutoTMalloc<SkPMColor> pixels(totalBytes);
 
-        SkImageGenerator::Result result =
+        SkCodec::Result result =
                 codec->getPixels(scaledInfo, pixels.get(), rowBytes, NULL, NULL, NULL);
-        REPORTER_ASSERT(r, SkImageGenerator::kSuccess == result);
+        REPORTER_ASSERT(r, SkCodec::kSuccess == result);
     }
 }