Support more swizzles to 565 in SkCodec

Add more swizzling functions for swizzling to 565. Much of this
code was revived from crrev.com/1055743003 (for BMP). Also added
swizzling functions for WBMP.

Consolidate the static function conversion_possible.

In SkCodec::getPixels, check that the alphatype corresponds to the
colorType. This prevents requesting 565 + non-opaque.

In SkIcoCodec, report that the image is unpremul (instead of
whatever the largest embedded codec thinks), but modify the
requested info to have the alpha type expected/required by the
embedded codec.

Add tests for decoding to 565.

BUG=skia:3257
BUG=skia:3683

Review URL: https://codereview.chromium.org/1277213002
diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp
index 624ff74..1f69b4f 100644
--- a/src/codec/SkWebpCodec.cpp
+++ b/src/codec/SkWebpCodec.cpp
@@ -5,6 +5,7 @@
  * found in the LICENSE file.
  */
 
+#include "SkCodecPriv.h"
 #include "SkWebpCodec.h"
 #include "SkTemplates.h"
 
@@ -81,29 +82,27 @@
     return NULL;
 }
 
-static bool conversion_possible(const SkImageInfo& dst, const SkImageInfo& src) {
+// This version is slightly different from SkCodecPriv's version of conversion_possible. It
+// supports both byte orders for 8888.
+static bool webp_conversion_possible(const SkImageInfo& dst, const SkImageInfo& src) {
     if (dst.profileType() != src.profileType()) {
         return false;
     }
+
+    if (!valid_alpha(dst.alphaType(), src.alphaType())) {
+        return false;
+    }
+
     switch (dst.colorType()) {
         // Both byte orders are supported.
         case kBGRA_8888_SkColorType:
         case kRGBA_8888_SkColorType:
-            break;
+            return true;
         case kRGB_565_SkColorType:
-            if (src.alphaType() == kOpaque_SkAlphaType
-                && dst.alphaType() == kOpaque_SkAlphaType)
-            {
-                return true;
-            }
+            return src.alphaType() == kOpaque_SkAlphaType;
         default:
             return false;
     }
-    if (dst.alphaType() == src.alphaType()) {
-        return true;
-    }
-    return kPremul_SkAlphaType == dst.alphaType() &&
-            kUnpremul_SkAlphaType == src.alphaType();
 }
 
 SkISize SkWebpCodec::onGetScaledDimensions(float desiredScale) const {
@@ -157,7 +156,7 @@
         return kCouldNotRewind;
     }
 
-    if (!conversion_possible(dstInfo, this->getInfo())) {
+    if (!webp_conversion_possible(dstInfo, this->getInfo())) {
         return kInvalidConversion;
     }