add const to encodePixels pixel parameter
authorreed <reed@google.com>
Fri, 19 Dec 2014 20:26:07 +0000 (12:26 -0800)
committerCommit bot <commit-bot@chromium.org>
Fri, 19 Dec 2014 20:26:07 +0000 (12:26 -0800)
BUG=skia:

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

include/core/SkImageEncoder.h
include/core/SkPixelSerializer.h
src/core/SkPicture.cpp
src/images/SkImageEncoder.cpp
tests/PictureTest.cpp
tools/PictureRenderer.cpp

index 4d4d2a83c0f18a0bd31a8d42bd64d947703a8126..6ee173cb0211ab2644854aacd71ce06a128a61e7 100644 (file)
@@ -1,14 +1,14 @@
-
 /*
  * Copyright 2011 Google Inc.
  *
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
+
 #ifndef SkImageEncoder_DEFINED
 #define SkImageEncoder_DEFINED
 
-#include "SkTypes.h"
+#include "SkImageInfo.h"
 #include "SkTRegistry.h"
 
 class SkBitmap;
@@ -59,7 +59,10 @@ public:
      */
     bool encodeStream(SkWStream* stream, const SkBitmap& bm, int quality);
 
+    static SkData* EncodeData(const SkImageInfo&, const void* pixels, size_t rowBytes,
+                              Type, int quality);
     static SkData* EncodeData(const SkBitmap&, Type, int quality);
+
     static bool EncodeFile(const char file[], const SkBitmap&, Type,
                            int quality);
     static bool EncodeStream(SkWStream*, const SkBitmap&, Type,
index 8fc445c753adcc8538ad8717b23329f5195f3a4c..d089209909816b720fb710206b0a6e8005a38f57 100644 (file)
@@ -32,7 +32,7 @@ public:
      *  Call to get the client's version of encoding these pixels. If it
      *  returns NULL, serialize the raw pixels.
      */
-    SkData* encodePixels(const SkImageInfo& info, void* pixels, size_t rowBytes) {
+    SkData* encodePixels(const SkImageInfo& info, const void* pixels, size_t rowBytes) {
         return this->onEncodePixels(info, pixels, rowBytes);
     }
 
@@ -47,6 +47,6 @@ protected:
      *  If you want to encode these pixels, return the encoded data as an SkData
      *  Return null if you want to serialize the raw pixels.
      */
-    virtual SkData* onEncodePixels(const SkImageInfo&, void* pixels, size_t rowBytes) = 0;
+    virtual SkData* onEncodePixels(const SkImageInfo&, const void* pixels, size_t rowBytes) = 0;
 };
 #endif // SkPixelSerializer_DEFINED
index 3296264be8ab76ac666f0adf91f106bc5536dc7b..921fbdf532a3e9340e12c30f3404dd374e0b58cb 100644 (file)
@@ -465,9 +465,9 @@ public:
         SkASSERT(fEncoder);
     }
 
-    virtual bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; }
+    bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; }
 
-    virtual SkData* onEncodePixels(const SkImageInfo& info, void* pixels,
+    SkData* onEncodePixels(const SkImageInfo& info, const void* pixels,
                                    size_t rowBytes) SK_OVERRIDE {
         // Required by signature of EncodeBitmap.
         size_t unused;
index 31fdcf96042eaf6c701e000e14307be0f5c92391..a6f109a207102de44368fa74a3271f2072c6c446 100644 (file)
@@ -50,3 +50,13 @@ SkData* SkImageEncoder::EncodeData(const SkBitmap& bm, Type t, int quality) {
     SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t));
     return enc.get() ? enc.get()->encodeData(bm, quality) : NULL;
 }
+
+SkData* SkImageEncoder::EncodeData(const SkImageInfo& info, const void* pixels, size_t rowBytes,
+                                   Type t, int quality) {
+    SkBitmap bm;
+    if (!bm.installPixels(info, const_cast<void*>(pixels), rowBytes)) {
+        return NULL;
+    }
+    SkAutoTDelete<SkImageEncoder> enc(SkImageEncoder::Create(t));
+    return enc.get() ? enc.get()->encodeData(bm, quality) : NULL;
+}
index 2881e5f5a825b0e732664a23a30d6b93e4f58575..b98cc4680e1798e68605a6ef6fe62e5460fc1d45 100644 (file)
@@ -1448,14 +1448,10 @@ static void test_bad_bitmap() {
 // FIXME: Share with PictureRenderer.cpp?
 class PngPixelSerializer : public SkPixelSerializer {
 public:
-    virtual bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; }
-    virtual SkData* onEncodePixels(const SkImageInfo& info, void* pixels,
-                                   size_t rowBytes) SK_OVERRIDE {
-        SkBitmap bm;
-        if (!bm.installPixels(info, pixels, rowBytes)) {
-            return NULL;
-        }
-        return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100);
+    bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; }
+    SkData* onEncodePixels(const SkImageInfo& info, const void* pixels,
+                           size_t rowBytes) SK_OVERRIDE {
+        return SkImageEncoder::EncodeData(info, pixels, rowBytes, SkImageEncoder::kPNG_Type, 100);
     }
 };
 
index 123cc2c5cccee9bc08a2d3486abbdd14f573a13b..5af0538a0dd53f71a05bc8a5860fba8a9e4b64a8 100644 (file)
@@ -366,14 +366,10 @@ SkCanvas* RecordPictureRenderer::setupCanvas(int width, int height) {
 
 class PngPixelSerializer : public SkPixelSerializer {
 public:
-    virtual bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; }
-    virtual SkData* onEncodePixels(const SkImageInfo& info, void* pixels,
-                                   size_t rowBytes) SK_OVERRIDE {
-        SkBitmap bm;
-        if (!bm.installPixels(info, pixels, rowBytes)) {
-            return NULL;
-        }
-        return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100);
+    bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; }
+    SkData* onEncodePixels(const SkImageInfo& info, const void* pixels,
+                           size_t rowBytes) SK_OVERRIDE {
+        return SkImageEncoder::EncodeData(info, pixels, rowBytes, SkImageEncoder::kPNG_Type, 100);
     }
 };