| 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" |
| 11 #include "ui/gfx/codec/png_codec.h" | 11 #include "ui/gfx/codec/png_codec.h" |
| 12 #include "ui/gfx/geometry/size.h" | 12 #include "ui/gfx/geometry/size.h" |
| 13 | 13 |
| 14 namespace user_manager { | 14 namespace user_manager { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // Default quality for encoding user images. | 18 // Default quality for encoding user images. |
| 19 const int kDefaultEncodingQuality = 90; | 19 const int kDefaultEncodingQuality = 90; |
| 20 | 20 |
| 21 } // namespace | 21 } // namespace |
| 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)); | |
| 31 if (image_format == FORMAT_JPEG) { | 30 if (image_format == FORMAT_JPEG) { |
| 32 if (gfx::JPEGCodec::Encode( | 31 if (gfx::JPEGCodec::Encode(bitmap, kDefaultEncodingQuality, &output)) { |
| 33 bitmap_data, | |
| 34 gfx::JPEGCodec::FORMAT_SkBitmap, | |
| 35 bitmap.width(), | |
| 36 bitmap.height(), | |
| 37 bitmap.width() * bitmap.bytesPerPixel(), | |
| 38 kDefaultEncodingQuality, &output)) { | |
| 39 return base::RefCountedBytes::TakeVector(&output); | 32 return base::RefCountedBytes::TakeVector(&output); |
| 40 } | 33 } |
| 41 } else if (image_format == FORMAT_PNG) { | 34 } else if (image_format == FORMAT_PNG) { |
| 35 auto* bitmap_data = |
| 36 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)); |
| 42 if (gfx::PNGCodec::Encode( | 37 if (gfx::PNGCodec::Encode( |
| 43 bitmap_data, | 38 bitmap_data, |
| 44 gfx::PNGCodec::FORMAT_SkBitmap, | 39 gfx::PNGCodec::FORMAT_SkBitmap, |
| 45 gfx::Size(bitmap.width(), bitmap.height()), | 40 gfx::Size(bitmap.width(), bitmap.height()), |
| 46 bitmap.width() * bitmap.bytesPerPixel(), | 41 bitmap.width() * bitmap.bytesPerPixel(), |
| 47 false, // discard_transparency | 42 false, // discard_transparency |
| 48 std::vector<gfx::PNGCodec::Comment>(), &output)) { | 43 std::vector<gfx::PNGCodec::Comment>(), &output)) { |
| 49 return base::RefCountedBytes::TakeVector(&output); | 44 return base::RefCountedBytes::TakeVector(&output); |
| 50 } | 45 } |
| 51 } else { | 46 } else { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 image_format_(image_format) { | 87 image_format_(image_format) { |
| 93 } | 88 } |
| 94 | 89 |
| 95 UserImage::~UserImage() {} | 90 UserImage::~UserImage() {} |
| 96 | 91 |
| 97 void UserImage::MarkAsSafe() { | 92 void UserImage::MarkAsSafe() { |
| 98 is_safe_format_ = true; | 93 is_safe_format_ = true; |
| 99 } | 94 } |
| 100 | 95 |
| 101 } // namespace user_manager | 96 } // namespace user_manager |
| OLD | NEW |