Updates to skimage tool to use it for testing.

skimage_main.cpp:
More changes in the interest of testing our decoders.

force_all_opaque before writing PNG files.

Test reencoding the image to its original type (if possible), and
then test redecoding it (to make sure the encoding was successful).
Add an option to turn off this behavior.

Merge decodeFileAndWrite with decodeFile.

SkImageDecoder:
Add kUnknown_Type to SkImageEncoder::Types.

Add a static function to get the Format of an SkStream.

In getFormatName(), remove an incorrect assert.

When calling the flavor of DecodeStream that returns the Format,
check the stream if the decoder returns kUnknown_Format.

BUG=https://code.google.com/p/skia/issues/detail?id=1241

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

git-svn-id: http://skia.googlecode.com/svn/trunk@8862 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/images/SkImageDecoder.cpp b/src/images/SkImageDecoder.cpp
index c16efcf..16cba64 100644
--- a/src/images/SkImageDecoder.cpp
+++ b/src/images/SkImageDecoder.cpp
@@ -18,17 +18,6 @@
 SK_DEFINE_INST_COUNT(SkImageDecoder::Chooser)
 SK_DEFINE_INST_COUNT(SkImageDecoderFactory)
 
-const char *SkImageDecoder::sFormatName[] = {
-    "Unknown Format",
-    "BMP",
-    "GIF",
-    "ICO",
-    "JPEG",
-    "PNG",
-    "WBMP",
-    "WEBP",
-};
-
 static SkBitmap::Config gDeviceConfig = SkBitmap::kNo_Config;
 
 SkBitmap::Config SkImageDecoder::GetDeviceConfig()
@@ -60,8 +49,27 @@
 }
 
 const char* SkImageDecoder::getFormatName() const {
-    SkASSERT(SK_ARRAY_COUNT(sFormatName) == kLastKnownFormat);
-    return sFormatName[this->getFormat()];
+    switch (this->getFormat()) {
+        case kUnknown_Format:
+            return "Unknown Format";
+        case kBMP_Format:
+            return "BMP";
+        case kGIF_Format:
+            return "GIF";
+        case kICO_Format:
+            return "ICO";
+        case kJPEG_Format:
+            return "JPEG";
+        case kPNG_Format:
+            return "PNG";
+        case kWBMP_Format:
+            return "WBMP";
+        case kWEBP_Format:
+            return "WEBP";
+        default:
+            SkASSERT(!"Invalid format type!");
+    }
+    return "Unknown Format";
 }
 
 SkImageDecoder::Peeker* SkImageDecoder::setPeeker(Peeker* peeker) {
@@ -321,6 +329,11 @@
         success = codec->decode(stream, bm, pref, mode);
         if (success && format) {
             *format = codec->getFormat();
+            if (kUnknown_Format == *format) {
+                if (stream->rewind()) {
+                    *format = GetStreamFormat(stream);
+                }
+            }
         }
         delete codec;
     }