add optional pref-config table to codecs



git-svn-id: http://skia.googlecode.com/svn/trunk@519 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp
index 6df56b4..3548fc8 100644
--- a/src/images/SkImageDecoder_libpng.cpp
+++ b/src/images/SkImageDecoder_libpng.cpp
@@ -37,8 +37,7 @@
     }
     
 protected:
-    virtual bool onDecode(SkStream* stream, SkBitmap* bm,
-                          SkBitmap::Config pref, Mode);
+    virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode);
 };
 
 #ifndef png_jmpbuf
@@ -110,9 +109,9 @@
     return reallyHasAlpha;
 }
 
-static bool canUpscalePaletteToConfig(SkBitmap::Config prefConfig,
+static bool canUpscalePaletteToConfig(SkBitmap::Config dstConfig,
                                       bool srcHasAlpha) {
-    switch (prefConfig) {
+    switch (dstConfig) {
         case SkBitmap::kARGB_8888_Config:
         case SkBitmap::kARGB_4444_Config:
             return true;
@@ -137,7 +136,7 @@
 }
 
 bool SkPNGImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* decodedBitmap,
-                                 SkBitmap::Config prefConfig, Mode mode) {
+                                 Mode mode) {
 //    SkAutoTrace    apr("SkPNGImageDecoder::onDecode");
 
     /* Create and initialize the png_struct with the desired error handler
@@ -233,11 +232,11 @@
     }
     
     if (color_type == PNG_COLOR_TYPE_PALETTE) {
-        config = SkBitmap::kIndex8_Config;
-        // now see if we can upscale to their requested config
         bool paletteHasAlpha = hasTransparencyInPalette(png_ptr, info_ptr);
-        if (canUpscalePaletteToConfig(prefConfig, paletteHasAlpha)) {
-            config = prefConfig;
+        config = this->getPrefConfig(kIndex_SrcDepth, paletteHasAlpha);
+        // now see if we can upscale to their requested config
+        if (!canUpscalePaletteToConfig(config, paletteHasAlpha)) {
+            config = SkBitmap::kIndex8_Config;
         }
     } else {
         png_color_16p   transpColor = NULL;
@@ -278,14 +277,16 @@
                 PNG_COLOR_TYPE_RGB_ALPHA == color_type ||
                 PNG_COLOR_TYPE_GRAY_ALPHA == color_type) {
             hasAlpha = true;
-            config = SkBitmap::kARGB_8888_Config;
-        } else {    // we get to choose the config
-            config = prefConfig;
-            if (config == SkBitmap::kNo_Config) {
-                config = SkImageDecoder::GetDeviceConfig();
+        }
+        config = this->getPrefConfig(k32Bit_SrcDepth, hasAlpha);
+        // now match the request against our capabilities
+        if (hasAlpha) {
+            if (config != SkBitmap::kARGB_4444_Config) {
+                config = SkBitmap::kARGB_8888_Config;
             }
+        } else {
             if (config != SkBitmap::kRGB_565_Config &&
-                    config != SkBitmap::kARGB_4444_Config) {
+                config != SkBitmap::kARGB_4444_Config) {
                 config = SkBitmap::kARGB_8888_Config;
             }
         }
@@ -311,9 +312,6 @@
     const int sampleSize = this->getSampleSize();
     SkScaledBitmapSampler sampler(origWidth, origHeight, sampleSize);
 
-    // we must always return the same config, independent of mode, so if we were
-    // going to respect prefConfig, it must have happened by now
-
     decodedBitmap->setConfig(config, sampler.scaledWidth(),
                              sampler.scaledHeight(), 0);
     if (SkImageDecoder::kDecodeBounds_Mode == mode) {