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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « ui/gfx/codec/skia_image_encoder_adapter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/gfx/codec/skia_image_encoder_adapter.h"
6
7 #include "third_party/skia/include/core/SkBitmap.h"
8 #include "third_party/skia/include/core/SkStream.h"
9 #include "ui/gfx/codec/jpeg_codec.h"
10 #include "ui/gfx/codec/png_codec.h"
11 #include "ui/gfx/geometry/size.h"
12
13 bool gfx::EncodeSkiaImage(SkWStream* dst,
14 const SkPixmap& pixmap,
15 SkEncodedImageFormat format,
16 int quality) {
17 if (kN32_SkColorType != pixmap.colorType() ||
18 (kPremul_SkAlphaType != pixmap.alphaType() &&
19 kOpaque_SkAlphaType != pixmap.alphaType())) {
20 return false;
21 }
22 std::vector<unsigned char> buffer;
23 switch (format) {
24 case SkEncodedImageFormat::kPNG:
25 return gfx::PNGCodec::Encode(
26 reinterpret_cast<const unsigned char*>(pixmap.addr()),
27 gfx::PNGCodec::FORMAT_SkBitmap,
28 gfx::Size(pixmap.width(), pixmap.height()),
29 static_cast<int>(pixmap.rowBytes()), false,
30 std::vector<gfx::PNGCodec::Comment>(), &buffer) &&
31 dst->write(buffer.data(), buffer.size());
32 case SkEncodedImageFormat::kJPEG:
33 return gfx::JPEGCodec::Encode(
34 reinterpret_cast<const unsigned char*>(pixmap.addr()),
35 gfx::JPEGCodec::FORMAT_SkBitmap, pixmap.width(),
36 pixmap.height(), static_cast<int>(pixmap.rowBytes()), quality,
37 &buffer) &&
38 dst->write(buffer.data(), buffer.size());
39 default:
40 return false;
41 }
42 }
OLDNEW
« 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