Fix colorType/alphaType checks in SkCodec

Make getPixels() and startScanlineDecode() behave
consistently.

Require that kGray8 decodes are opaque.

Assert that creating the swizzler succeeds.

BUG=skia:4203
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1695473002

Committed: https://skia.googlesource.com/skia/+/c7578b6cdd03b61f076ffc7956efd952d6c301c0

Review URL: https://codereview.chromium.org/1695473002
diff --git a/src/codec/SkWbmpCodec.cpp b/src/codec/SkWbmpCodec.cpp
index af1ab46..706d5dd 100644
--- a/src/codec/SkWbmpCodec.cpp
+++ b/src/codec/SkWbmpCodec.cpp
@@ -30,6 +30,19 @@
     }
 }
 
+static inline bool valid_color_type(SkColorType colorType, SkAlphaType alphaType) {
+    switch (colorType) {
+        case kN32_SkColorType:
+        case kIndex_8_SkColorType:
+            return true;
+        case kGray_8_SkColorType:
+        case kRGB_565_SkColorType:
+            return kOpaque_SkAlphaType == alphaType;
+        default:
+            return false;
+    }
+}
+
 static bool read_byte(SkStream* stream, uint8_t* data)
 {
     return stream->read(data, 1) == 1;
@@ -84,16 +97,6 @@
 
 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, const SkPMColor* ctable,
         const Options& opts) {
-    // Create the swizzler based on the desired color type
-    switch (info.colorType()) {
-        case kIndex_8_SkColorType:
-        case kN32_SkColorType:
-        case kRGB_565_SkColorType:
-        case kGray_8_SkColorType:
-            break;
-        default:
-            return nullptr;
-    }
     return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, opts);
 }
 
@@ -124,7 +127,8 @@
         return kUnimplemented;
     }
 
-    if (!valid_alpha(info.alphaType(), this->getInfo().alphaType())) {
+    if (!valid_color_type(info.colorType(), info.alphaType()) ||
+            !valid_alpha(info.alphaType(), this->getInfo().alphaType())) {
         return kInvalidConversion;
     }
 
@@ -133,9 +137,7 @@
 
     // Initialize the swizzler
     SkAutoTDelete<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, options));
-    if (nullptr == swizzler.get()) {
-        return kInvalidConversion;
-    }
+    SkASSERT(swizzler);
 
     // Perform the decode
     SkISize size = info.dimensions();
@@ -193,7 +195,8 @@
         return kUnimplemented;
     }
 
-    if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) {
+    if (!valid_color_type(dstInfo.colorType(), dstInfo.alphaType()) ||
+            !valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) {
         return kInvalidConversion;
     }
 
@@ -207,9 +210,7 @@
 
     // Initialize the swizzler
     fSwizzler.reset(this->initializeSwizzler(dstInfo, get_color_ptr(fColorTable.get()), options));
-    if (nullptr == fSwizzler.get()) {
-        return kInvalidConversion;
-    }
+    SkASSERT(fSwizzler);
 
     fSrcBuffer.reset(fSrcRowBytes);