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

Side by Side Diff: ui/gfx/codec/install_skia_codec.cc

Issue 2527833002: Implement SkEncodeImage() (Closed)
Patch Set: refactor install_skia_codec Created 4 years 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/install_skia_codec.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/install_skia_codec.h"
6
7 #include "base/synchronization/lock.h"
8 #include "skia/ext/skia_encode_image.h"
9 #include "third_party/skia/include/core/SkBitmap.h"
10 #include "third_party/skia/include/core/SkEncodedImageFormat.h"
11 #include "third_party/skia/include/core/SkStream.h"
12 #include "ui/gfx/codec/jpeg_codec.h"
13 #include "ui/gfx/codec/png_codec.h"
14 #include "ui/gfx/geometry/size.h"
15
16 static bool Encode(SkWStream* dst,
17 const SkPixmap& pixmap,
18 SkEncodedImageFormat format,
19 int quality) {
20 if (kN32_SkColorType != pixmap.colorType() ||
21 (kPremul_SkAlphaType != pixmap.alphaType() &&
22 kOpaque_SkAlphaType != pixmap.alphaType())) {
scroggo 2016/11/29 20:15:24 Why not support unpremul? It looks like PNGCodec::
hal.canary 2016/11/29 20:27:04 Fixing gfx::PNGCodec::Encode() to allow unpremulip
23 return false;
24 }
25 std::vector<unsigned char> buffer;
26 switch (format) {
27 case SkEncodedImageFormat::kPNG:
28 return gfx::PNGCodec::Encode(
29 reinterpret_cast<const unsigned char*>(pixmap.addr()),
30 gfx::PNGCodec::FORMAT_SkBitmap,
31 gfx::Size(pixmap.width(), pixmap.height()),
32 static_cast<int>(pixmap.rowBytes()), false,
33 std::vector<gfx::PNGCodec::Comment>(), &buffer) &&
34 dst->write(&buffer[0], buffer.size());
dcheng 2016/11/29 23:37:43 Is it guaranteed that |buffer.size()| > 0 here and
hal.canary 2016/11/30 18:24:06 Done.
dcheng 2016/12/01 06:22:38 Rather than the conditional, I think it's probably
35 case SkEncodedImageFormat::kJPEG:
36 return gfx::JPEGCodec::Encode(
37 reinterpret_cast<const unsigned char*>(pixmap.addr()),
38 gfx::JPEGCodec::FORMAT_SkBitmap, pixmap.width(),
39 pixmap.height(), static_cast<int>(pixmap.rowBytes()), quality,
40 &buffer) &&
41 dst->write(&buffer[0], buffer.size());
42 default:
43 return false;
44 }
45 }
46
47 void gfx::InstallCodecsIntoSkia() {
48 // FIXME: What is the chromium version of SkOnce?
dcheng 2016/11/29 23:37:43 There is no Chromium version: the base::Lock here
hal.canary 2016/11/30 18:24:06 d'oh! That's what I meant to do.
49 base::Lock lock;
50 base::AutoLock autoLock(lock);
51 static bool g_done = false;
52 if (!g_done) {
53 skia::SetImageEncoder(&Encode);
54 g_done = true;
55 }
56 }
OLDNEW
« no previous file with comments | « ui/gfx/codec/install_skia_codec.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698