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

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

Issue 411523005: Revert of Clean up. Experimental user avatars removed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « components/user_manager/user_image/user_image.h ('k') | media/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "third_party/skia/include/core/SkBitmap.h" 8 #include "third_party/skia/include/core/SkBitmap.h"
9 #include "ui/gfx/codec/jpeg_codec.h" 9 #include "ui/gfx/codec/jpeg_codec.h"
10 10
11 namespace user_manager { 11 namespace user_manager {
12 12
13 namespace { 13 namespace {
14 14
15 // Default quality for encoding user images. 15 // Default quality for encoding user images.
16 const int kDefaultEncodingQuality = 90; 16 const int kDefaultEncodingQuality = 90;
17 17
18 bool IsAnimatedImage(const UserImage::RawImage& data) {
19 const char kGIFStamp[] = "GIF";
20 const size_t kGIFStampLength = sizeof(kGIFStamp) - 1;
21
22 if (data.size() >= kGIFStampLength &&
23 memcmp(&data[0], kGIFStamp, kGIFStampLength) == 0) {
24 return true;
25 }
26 return false;
27 }
28
18 bool EncodeImageSkia(const gfx::ImageSkia& image, 29 bool EncodeImageSkia(const gfx::ImageSkia& image,
19 std::vector<unsigned char>* output) { 30 std::vector<unsigned char>* output) {
20 TRACE_EVENT2("oobe", "EncodeImageSkia", 31 TRACE_EVENT2("oobe", "EncodeImageSkia",
21 "width", image.width(), "height", image.height()); 32 "width", image.width(), "height", image.height());
22 if (image.isNull()) 33 if (image.isNull())
23 return false; 34 return false;
24 const SkBitmap& bitmap = *image.bitmap(); 35 const SkBitmap& bitmap = *image.bitmap();
25 SkAutoLockPixels lock_image(bitmap); 36 SkAutoLockPixels lock_image(bitmap);
26 return gfx::JPEGCodec::Encode( 37 return gfx::JPEGCodec::Encode(
27 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), 38 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)),
(...skipping 12 matching lines...) Expand all
40 if (EncodeImageSkia(image, &raw_image)) { 51 if (EncodeImageSkia(image, &raw_image)) {
41 UserImage result(image, raw_image); 52 UserImage result(image, raw_image);
42 result.MarkAsSafe(); 53 result.MarkAsSafe();
43 return result; 54 return result;
44 } 55 }
45 return UserImage(image); 56 return UserImage(image);
46 } 57 }
47 58
48 UserImage::UserImage() 59 UserImage::UserImage()
49 : has_raw_image_(false), 60 : has_raw_image_(false),
61 has_animated_image_(false),
50 is_safe_format_(false) { 62 is_safe_format_(false) {
51 } 63 }
52 64
53 UserImage::UserImage(const gfx::ImageSkia& image) 65 UserImage::UserImage(const gfx::ImageSkia& image)
54 : image_(image), 66 : image_(image),
55 has_raw_image_(false), 67 has_raw_image_(false),
68 has_animated_image_(false),
56 is_safe_format_(false) { 69 is_safe_format_(false) {
57 } 70 }
58 71
59 UserImage::UserImage(const gfx::ImageSkia& image, 72 UserImage::UserImage(const gfx::ImageSkia& image,
60 const RawImage& raw_image) 73 const RawImage& raw_image)
61 : image_(image), 74 : image_(image),
62 has_raw_image_(false), 75 has_raw_image_(false),
76 has_animated_image_(false),
63 is_safe_format_(false) { 77 is_safe_format_(false) {
64 has_raw_image_ = true; 78 if (IsAnimatedImage(raw_image)) {
65 raw_image_ = raw_image; 79 has_animated_image_ = true;
80 animated_image_ = raw_image;
81 if (EncodeImageSkia(image_, &raw_image_)) {
82 has_raw_image_ = true;
83 MarkAsSafe();
84 }
85 } else {
86 has_raw_image_ = true;
87 raw_image_ = raw_image;
88 }
66 } 89 }
67 90
68 UserImage::~UserImage() {} 91 UserImage::~UserImage() {}
69 92
70 void UserImage::DiscardRawImage() { 93 void UserImage::DiscardRawImage() {
71 RawImage().swap(raw_image_); // Clear |raw_image_|. 94 RawImage().swap(raw_image_); // Clear |raw_image_|.
72 } 95 }
73 96
74 void UserImage::MarkAsSafe() { 97 void UserImage::MarkAsSafe() {
75 is_safe_format_ = true; 98 is_safe_format_ = true;
76 } 99 }
77 100
78 } // namespace user_manager 101 } // namespace user_manager
OLDNEW
« no previous file with comments | « components/user_manager/user_image/user_image.h ('k') | media/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698