Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(740)

Unified Diff: ui/gfx/codec/skia_image_encoder_adapter.cc

Issue 2527833002: Implement SkEncodeImage() (Closed)
Patch Set: rebase again Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/codec/skia_image_encoder_adapter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/codec/skia_image_encoder_adapter.cc
diff --git a/ui/gfx/codec/skia_image_encoder_adapter.cc b/ui/gfx/codec/skia_image_encoder_adapter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6dbb457a598b5b20a5d1a723d2b178aa80cedaeb
--- /dev/null
+++ b/ui/gfx/codec/skia_image_encoder_adapter.cc
@@ -0,0 +1,42 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/codec/skia_image_encoder_adapter.h"
+
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "third_party/skia/include/core/SkStream.h"
+#include "ui/gfx/codec/jpeg_codec.h"
+#include "ui/gfx/codec/png_codec.h"
+#include "ui/gfx/geometry/size.h"
+
+bool gfx::EncodeSkiaImage(SkWStream* dst,
+ const SkPixmap& pixmap,
+ SkEncodedImageFormat format,
+ int quality) {
+ if (kN32_SkColorType != pixmap.colorType() ||
+ (kPremul_SkAlphaType != pixmap.alphaType() &&
+ kOpaque_SkAlphaType != pixmap.alphaType())) {
+ return false;
+ }
+ std::vector<unsigned char> buffer;
+ switch (format) {
+ case SkEncodedImageFormat::kPNG:
+ return gfx::PNGCodec::Encode(
+ reinterpret_cast<const unsigned char*>(pixmap.addr()),
+ gfx::PNGCodec::FORMAT_SkBitmap,
+ gfx::Size(pixmap.width(), pixmap.height()),
+ static_cast<int>(pixmap.rowBytes()), false,
+ std::vector<gfx::PNGCodec::Comment>(), &buffer) &&
+ dst->write(buffer.data(), buffer.size());
+ case SkEncodedImageFormat::kJPEG:
+ return gfx::JPEGCodec::Encode(
+ reinterpret_cast<const unsigned char*>(pixmap.addr()),
+ gfx::JPEGCodec::FORMAT_SkBitmap, pixmap.width(),
+ pixmap.height(), static_cast<int>(pixmap.rowBytes()), quality,
+ &buffer) &&
+ dst->write(buffer.data(), buffer.size());
+ default:
+ return false;
+ }
+}
« no previous file with comments | « ui/gfx/codec/skia_image_encoder_adapter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698