Create a factory to decode an SkBitmap from an SkData.

Add a test and a GM for the factory, and a PNG file for it to decode.
The PNG file is copyright-free, obtained from
http://openclipart.org/detail/29213/paper-plane-by-ddoo

In cmykjpeg, do not attempt to decode in the constructor, since it
currently crashes on Mac (if you provide the correct resource path).
Even when we fix this crash there is no need to do it in the
constructor, since we create all of the gms in order to
get their names (to determine whether to run them).

Review URL: https://codereview.appspot.com/6847122

git-svn-id: http://skia.googlecode.com/svn/trunk@6618 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/images/SkBitmapFactory.cpp b/src/images/SkBitmapFactory.cpp
new file mode 100644
index 0000000..4e5d90b
--- /dev/null
+++ b/src/images/SkBitmapFactory.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkBitmapFactory.h"
+
+#include "SkBitmap.h"
+#include "SkData.h"
+#include "SkImageDecoder.h"
+#include "SkStream.h"
+#include "SkTemplates.h"
+
+bool SkBitmapFactory::DecodeBitmap(SkBitmap* dst, const SkData* data, Constraints constraint) {
+    if (NULL == data || data->size() == 0 || dst == NULL) {
+        return false;
+    }
+
+    SkMemoryStream stream(data->data(), data->size());
+    SkAutoTDelete<SkImageDecoder> decoder (SkImageDecoder::Factory(&stream));
+    if (decoder.get() == NULL) {
+        return false;
+    }
+
+    SkBitmap tmp;
+    SkImageDecoder::Mode mode;
+    if (kDecodeBoundsOnly_Constraint == constraint) {
+        mode = SkImageDecoder::kDecodeBounds_Mode;
+    } else {
+        mode = SkImageDecoder::kDecodePixels_Mode;
+    }
+
+    if (decoder->decode(&stream, &tmp, mode)) {
+        tmp.swap(*dst);
+        return true;
+    } else {
+        return false;
+    }
+}