OLD | NEW |
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 Loading... |
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 if (gfx::JPEGCodec::Encode(bitmap_data, kN32_SkColorType, bitmap.width(), |
33 bitmap_data, | 33 bitmap.height(), |
34 gfx::JPEGCodec::FORMAT_SkBitmap, | 34 bitmap.width() * bitmap.bytesPerPixel(), |
35 bitmap.width(), | 35 kDefaultEncodingQuality, &output)) { |
36 bitmap.height(), | |
37 bitmap.width() * bitmap.bytesPerPixel(), | |
38 kDefaultEncodingQuality, &output)) { | |
39 return base::RefCountedBytes::TakeVector(&output); | 36 return base::RefCountedBytes::TakeVector(&output); |
40 } | 37 } |
41 } else if (image_format == FORMAT_PNG) { | 38 } else if (image_format == FORMAT_PNG) { |
42 if (gfx::PNGCodec::Encode( | 39 if (gfx::PNGCodec::Encode( |
43 bitmap_data, | 40 bitmap_data, |
44 gfx::PNGCodec::FORMAT_SkBitmap, | 41 gfx::PNGCodec::FORMAT_SkBitmap, |
45 gfx::Size(bitmap.width(), bitmap.height()), | 42 gfx::Size(bitmap.width(), bitmap.height()), |
46 bitmap.width() * bitmap.bytesPerPixel(), | 43 bitmap.width() * bitmap.bytesPerPixel(), |
47 false, // discard_transparency | 44 false, // discard_transparency |
48 std::vector<gfx::PNGCodec::Comment>(), &output)) { | 45 std::vector<gfx::PNGCodec::Comment>(), &output)) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 image_format_(image_format) { | 89 image_format_(image_format) { |
93 } | 90 } |
94 | 91 |
95 UserImage::~UserImage() {} | 92 UserImage::~UserImage() {} |
96 | 93 |
97 void UserImage::MarkAsSafe() { | 94 void UserImage::MarkAsSafe() { |
98 is_safe_format_ = true; | 95 is_safe_format_ = true; |
99 } | 96 } |
100 | 97 |
101 } // namespace user_manager | 98 } // namespace user_manager |
OLD | NEW |