Remove uses SkImageDecoder in imgblur and imgslice
authormsarett <msarett@google.com>
Wed, 9 Mar 2016 18:09:02 +0000 (10:09 -0800)
committerCommit bot <commit-bot@chromium.org>
Wed, 9 Mar 2016 18:09:02 +0000 (10:09 -0800)
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1777753002

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

tools/imgblur.cpp
tools/imgslice.cpp

index 5ee8b123707d8a652c6a901789da1a956bc19354..4f106dc712c09c0efa7835ded58d45f9bf84c9b7 100644 (file)
@@ -5,14 +5,19 @@
  * found in the LICENSE file.
  */
 
+#include "SkBitmap.h"
 #include "SkCommandLineFlags.h"
 #include "SkCommonFlags.h"
-#include "SkImageDecoder.h"
+#include "SkData.h"
+#include "SkForceLinking.h"
+#include "SkImage.h"
 #include "SkStream.h"
 #include "SkTypes.h"
 
 #include "sk_tool_utils.h"
 
+__SK_FORCE_IMAGE_DECODER_LINKING;
+
 DEFINE_string(in, "input.png", "Input image");
 DEFINE_string(out, "blurred.png", "Output image");
 DEFINE_double(sigma, 1, "Sigma to be used for blur (> 0.0f)");
@@ -35,32 +40,27 @@ int tool_main(int argc, char** argv) {
         return kError;       
     }
 
-    SkFILEStream inputStream(FLAGS_in[0]);
-    if (!inputStream.isValid()) {
+    SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_in[0]));
+    if (nullptr == data) {
         if (!FLAGS_quiet) {
             SkDebugf("Couldn't open file: %s\n", FLAGS_in[0]);
         }
         return kError;
     }
 
-    SkAutoTDelete<SkImageDecoder> codec(SkImageDecoder::Factory(&inputStream));
-    if (!codec) {
+    SkAutoTDelete<SkImage> image(SkImage::NewFromEncoded(data));
+    if (!image) {
         if (!FLAGS_quiet) {
-            SkDebugf("Couldn't create codec for: %s.\n", FLAGS_in[0]);
+            SkDebugf("Couldn't create image for: %s.\n", FLAGS_in[0]);
         }
         return kError;
     }
 
     SkBitmap src;
-
-    inputStream.rewind();
-    SkImageDecoder::Result res = codec->decode(&inputStream, &src,
-                                               kN32_SkColorType,
-                                               SkImageDecoder::kDecodePixels_Mode);
-    if (SkImageDecoder::kSuccess != res) {
+    if (!image->asLegacyBitmap(&src, SkImage::kRW_LegacyBitmapMode)) {
         if (!FLAGS_quiet) {
-            SkDebugf("Couldn't decode image: %s.\n", FLAGS_in[0]);
-        }    
+            SkDebugf("Couldn't create bitmap for: %s.\n", FLAGS_in[0]);
+        }
         return kError;
     }
 
index e9e3832cd4155f9b8fd6dc9d6d5e4c9108626d12..8128f77dd43d1e8072c19fa64c4d2d3002f2eae5 100644 (file)
@@ -5,8 +5,10 @@
  * found in the LICENSE file.
  */
 
+#include "SkBitmap.h"
 #include "SkCommandLineFlags.h"
-#include "SkImageDecoder.h"
+#include "SkData.h"
+#include "SkImage.h"
 #include "SkStream.h"
 
 DEFINE_bool(header, false, "Print an extra row of the min-max values");
@@ -57,26 +59,29 @@ int tool_main(int argc, char** argv) {
         return kError;       
     }
 
-    SkFILEStream inputStream(FLAGS_image[0]);
-    if (!inputStream.isValid()) {
+    SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_image[0]));
+    if (nullptr == data) {
         if (!FLAGS_quiet) {
             SkDebugf("Couldn't open file: %s\n", FLAGS_image[0]);
         }
         return kError;
     }
 
-    SkAutoTDelete<SkImageDecoder> codec(SkImageDecoder::Factory(&inputStream));
-    if (!codec) {
+    SkAutoTDelete<SkImage> image(SkImage::NewFromEncoded(data));
+    if (!image) {
         if (!FLAGS_quiet) {
-            SkDebugf("Couldn't create codec for: %s.\n", FLAGS_image[0]);
+            SkDebugf("Couldn't create image for: %s.\n", FLAGS_image[0]);
         }
         return kError;
     }
 
     SkBitmap bitmap;
-
-    inputStream.rewind();
-    codec->decode(&inputStream, &bitmap, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
+    if (!image->asLegacyBitmap(&bitmap, SkImage::kRW_LegacyBitmapMode)) {
+        if (!FLAGS_quiet) {
+            SkDebugf("Couldn't create bitmap for: %s.\n", FLAGS_image[0]);
+        }
+        return kError;
+    }
 
     int top, bottom, left, right;