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

Side by Side Diff: components/user_manager/user_image/user_image.cc

Issue 2895953003: Use SkJpegEncoder in gfx jpeg_codec (Closed)
Patch Set: Update comment Created 3 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/user_manager/user_image/user_image.h" 5 #include "components/user_manager/user_image/user_image.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/trace_event/trace_event.h" 8 #include "base/trace_event/trace_event.h"
9 #include "third_party/skia/include/core/SkBitmap.h" 9 #include "third_party/skia/include/core/SkBitmap.h"
10 #include "ui/gfx/codec/jpeg_codec.h" 10 #include "ui/gfx/codec/jpeg_codec.h"
(...skipping 11 matching lines...) Expand all
22 22
23 // static 23 // static
24 scoped_refptr<base::RefCountedBytes> UserImage::Encode( 24 scoped_refptr<base::RefCountedBytes> UserImage::Encode(
25 const SkBitmap& bitmap, 25 const SkBitmap& bitmap,
26 ImageFormat image_format) { 26 ImageFormat image_format) {
27 TRACE_EVENT2("oobe", "UserImage::Encode", 27 TRACE_EVENT2("oobe", "UserImage::Encode",
28 "width", bitmap.width(), "height", bitmap.height()); 28 "width", bitmap.width(), "height", bitmap.height());
29 std::vector<unsigned char> output; 29 std::vector<unsigned char> output;
30 auto* bitmap_data = reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)); 30 auto* bitmap_data = reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0));
31 if (image_format == FORMAT_JPEG) { 31 if (image_format == FORMAT_JPEG) {
32 if (gfx::JPEGCodec::Encode( 32 SkPixmap pixmap;
33 bitmap_data, 33 bool success = bitmap.peekPixels(&pixmap);
34 gfx::JPEGCodec::FORMAT_SkBitmap, 34 DCHECK(success);
35 bitmap.width(), 35
36 bitmap.height(), 36 if (gfx::JPEGCodec::Encode(pixmap, kDefaultEncodingQuality, &output)) {
37 bitmap.width() * bitmap.bytesPerPixel(),
38 kDefaultEncodingQuality, &output)) {
39 return base::RefCountedBytes::TakeVector(&output); 37 return base::RefCountedBytes::TakeVector(&output);
40 } 38 }
41 } else if (image_format == FORMAT_PNG) { 39 } else if (image_format == FORMAT_PNG) {
42 if (gfx::PNGCodec::Encode( 40 if (gfx::PNGCodec::Encode(
43 bitmap_data, 41 bitmap_data,
44 gfx::PNGCodec::FORMAT_SkBitmap, 42 gfx::PNGCodec::FORMAT_SkBitmap,
45 gfx::Size(bitmap.width(), bitmap.height()), 43 gfx::Size(bitmap.width(), bitmap.height()),
46 bitmap.width() * bitmap.bytesPerPixel(), 44 bitmap.width() * bitmap.bytesPerPixel(),
47 false, // discard_transparency 45 false, // discard_transparency
48 std::vector<gfx::PNGCodec::Comment>(), &output)) { 46 std::vector<gfx::PNGCodec::Comment>(), &output)) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 image_format_(image_format) { 90 image_format_(image_format) {
93 } 91 }
94 92
95 UserImage::~UserImage() {} 93 UserImage::~UserImage() {}
96 94
97 void UserImage::MarkAsSafe() { 95 void UserImage::MarkAsSafe() {
98 is_safe_format_ = true; 96 is_safe_format_ = true;
99 } 97 }
100 98
101 } // namespace user_manager 99 } // namespace user_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698