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

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

Issue 2527833002: Implement SkEncodeImage() (Closed)
Patch Set: 2016-11-28 (Monday) 17:33:22 EST 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
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
15 static bool Encode(SkWStream* dst,
16 const SkPixmap& pixmap,
17 SkEncodedImageFormat format,
18 int quality) {
19 SkBitmap bitmap;
scroggo 2016/11/29 14:52:54 This is only used in the PNG case - why not move i
hal.canary 2016/11/29 18:24:27 Done.
20 std::vector<unsigned char> buffer;
21 switch (format) {
22 case SkEncodedImageFormat::kPNG:
23 return bitmap.installPixels(pixmap) &&
24 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &buffer) &&
25 dst->write(&buffer[0], buffer.size());
26 case SkEncodedImageFormat::kJPEG:
27 return gfx::JPEGCodec::Encode((const unsigned char*)pixmap.addr(),
scroggo 2016/11/29 14:52:54 reinterpret_cast?
hal.canary 2016/11/29 18:24:27 Done.
28 gfx::JPEGCodec::FORMAT_SkBitmap,
29 pixmap.width(), pixmap.height(),
30 (int)pixmap.rowBytes(), quality, &buffer) &&
scroggo 2016/11/29 14:52:54 static_cast?
hal.canary 2016/11/29 18:24:27 Done.
31 dst->write(&buffer[0], buffer.size());
32 default:
33 return false;
34 }
35 }
36
37 void gfx::InstallCodecsIntoSkia() {
38 // FIXME: What is the chromium version of SkOnce?
39 base::Lock lock;
40 base::AutoLock autoLock(lock);
41 static bool g_done = false;
42 if (!g_done) {
43 skia::SetEmageEncoder(&Encode);
44 g_done = true;
45 }
46 }
OLDNEW
« skia/ext/skia_encode_image.h ('K') | « 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