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

Side by Side Diff: chrome/browser/chromeos/login/user_image.cc

Issue 10831064: [cros] Remove redundant PNG enconding in UserImage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/login/user_image.h" 5 #include "chrome/browser/chromeos/login/user_image.h"
6 6
7 #include "ui/gfx/codec/png_codec.h" 7 #include "ui/gfx/codec/png_codec.h"
8 8
9 namespace chromeos { 9 namespace chromeos {
10 10
11 namespace { 11 namespace {
12 12
13 bool IsAnimatedImage(const UserImage::RawImage& data) { 13 bool IsAnimatedImage(const UserImage::RawImage& data) {
14 const char kGIFStamp[] = "GIF"; 14 const char kGIFStamp[] = "GIF";
15 const size_t kGIFStampLength = sizeof(kGIFStamp) - 1; 15 const size_t kGIFStampLength = sizeof(kGIFStamp) - 1;
16 16
17 if (data.size() >= kGIFStampLength && 17 if (data.size() >= kGIFStampLength &&
18 memcmp(&data[0], kGIFStamp, kGIFStampLength) == 0) { 18 memcmp(&data[0], kGIFStamp, kGIFStampLength) == 0) {
19 return true; 19 return true;
20 } 20 }
21 return false; 21 return false;
22 } 22 }
23 23
24 } // namespace 24 } // namespace
25 25
26 UserImage::UserImage()
27 : has_raw_image_(false),
28 has_animated_image_(false) {
29 }
30
26 UserImage::UserImage(const gfx::ImageSkia& image) 31 UserImage::UserImage(const gfx::ImageSkia& image)
27 : image_(image), 32 : image_(image),
28 has_raw_image_(false), 33 has_raw_image_(false),
29 has_animated_image_(false) { 34 has_animated_image_(false) {
30 if (gfx::PNGCodec::EncodeBGRASkBitmap(image_, false, &raw_image_))
31 has_raw_image_ = true;
32 } 35 }
33 36
34 UserImage::UserImage(const gfx::ImageSkia& image, 37 UserImage::UserImage(const gfx::ImageSkia& image,
35 const RawImage& raw_image) 38 const RawImage& raw_image)
36 : image_(image), 39 : image_(image),
37 has_raw_image_(false), 40 has_raw_image_(false),
38 has_animated_image_(false) { 41 has_animated_image_(false) {
39 if (IsAnimatedImage(raw_image)) { 42 if (IsAnimatedImage(raw_image)) {
40 has_animated_image_ = true; 43 has_animated_image_ = true;
41 animated_image_ = raw_image; 44 animated_image_ = raw_image;
45 if (gfx::PNGCodec::EncodeBGRASkBitmap(image_, false, &raw_image_))
46 has_raw_image_ = true;
47 } else {
48 has_raw_image_ = true;
49 raw_image_ = raw_image;
42 } 50 }
43 if (gfx::PNGCodec::EncodeBGRASkBitmap(image_, false, &raw_image_))
44 has_raw_image_ = true;
45 } 51 }
46 52
47 UserImage::~UserImage() {} 53 UserImage::~UserImage() {}
48 54
49 void UserImage::SetImage(const gfx::ImageSkia& image) {
50 image_ = image;
51 if (gfx::PNGCodec::EncodeBGRASkBitmap(image_, false, &raw_image_)) {
52 has_raw_image_ = true;
53 } else {
54 has_raw_image_ = false;
55 RawImage().swap(raw_image_); // Clear |raw_image_|.
56 }
57
58 has_animated_image_ = false;
59 if (!animated_image_.empty())
60 RawImage().swap(animated_image_); // Clear |animated_image_|.
61 }
62
63 } // namespace chromeos 55 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698