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

Side by Side Diff: chrome/browser/chromeos/login/users/avatar/user_image_manager_test_util.cc

Issue 2537713002: Add support for transparent/translucent pixels in the user image (Closed)
Patch Set: rebased Created 4 years 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 "chrome/browser/chromeos/login/users/avatar/user_image_manager_test_uti l.h" 5 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_test_uti l.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "third_party/skia/include/core/SkBitmap.h" 15 #include "third_party/skia/include/core/SkBitmap.h"
16 #include "ui/gfx/image/image_skia.h" 16 #include "ui/gfx/image/image_skia.h"
17 #include "ui/gfx/image/image_skia_rep.h" 17 #include "ui/gfx/image/image_skia_rep.h"
18 18
19 namespace chromeos { 19 namespace chromeos {
20 namespace test { 20 namespace test {
21 21
22 const char kUserAvatarImage1RelativePath[] = "chromeos/avatar1.jpg"; 22 const char kUserAvatarImage1RelativePath[] = "chromeos/avatar1.jpg";
23 const char kUserAvatarImage2RelativePath[] = "chromeos/avatar2.jpg"; 23 const char kUserAvatarImage2RelativePath[] = "chromeos/avatar2.jpg";
24 const char kUserAvatarImage3RelativePath[] = "chromeos/avatar3.png";
24 25
25 bool AreImagesEqual(const gfx::ImageSkia& first, const gfx::ImageSkia& second) { 26 bool AreImagesEqual(const gfx::ImageSkia& first, const gfx::ImageSkia& second) {
26 if (first.width() != second.width() || first.height() != second.height()) 27 if (first.width() != second.width() || first.height() != second.height())
27 return false; 28 return false;
28 const SkBitmap* first_bitmap = first.bitmap(); 29 const SkBitmap* first_bitmap = first.bitmap();
29 const SkBitmap* second_bitmap = second.bitmap(); 30 const SkBitmap* second_bitmap = second.bitmap();
30 if (!first_bitmap && !second_bitmap) 31 if (!first_bitmap && !second_bitmap)
31 return true; 32 return true;
32 if (!first_bitmap || !second_bitmap) 33 if (!first_bitmap || !second_bitmap)
33 return false; 34 return false;
(...skipping 15 matching lines...) Expand all
49 50
50 ImageLoader::ImageLoader(const base::FilePath& path) : path_(path) { 51 ImageLoader::ImageLoader(const base::FilePath& path) : path_(path) {
51 } 52 }
52 53
53 ImageLoader::~ImageLoader() { 54 ImageLoader::~ImageLoader() {
54 } 55 }
55 56
56 std::unique_ptr<gfx::ImageSkia> ImageLoader::Load() { 57 std::unique_ptr<gfx::ImageSkia> ImageLoader::Load() {
57 std::string image_data; 58 std::string image_data;
58 ReadFileToString(path_, &image_data); 59 ReadFileToString(path_, &image_data);
59 ImageDecoder::StartWithOptions(this, image_data, 60 const ImageDecoder::ImageCodec codec =
60 ImageDecoder::ROBUST_JPEG_CODEC, false); 61 (path_.Extension() == FILE_PATH_LITERAL(".jpg")
62 ? ImageDecoder::ROBUST_JPEG_CODEC
63 : ImageDecoder::ROBUST_PNG_CODEC);
64 ImageDecoder::StartWithOptions(this, image_data, codec, false);
61 run_loop_.Run(); 65 run_loop_.Run();
62 return std::move(decoded_image_); 66 return std::move(decoded_image_);
63 } 67 }
64 68
65 void ImageLoader::OnImageDecoded(const SkBitmap& decoded_image) { 69 void ImageLoader::OnImageDecoded(const SkBitmap& decoded_image) {
66 decoded_image_.reset( 70 decoded_image_.reset(
67 new gfx::ImageSkia(gfx::ImageSkiaRep(decoded_image, 1.0f))); 71 new gfx::ImageSkia(gfx::ImageSkiaRep(decoded_image, 1.0f)));
68 run_loop_.Quit(); 72 run_loop_.Quit();
69 } 73 }
70 74
71 void ImageLoader::OnDecodeImageFailed() { 75 void ImageLoader::OnDecodeImageFailed() {
72 run_loop_.Quit(); 76 run_loop_.Quit();
73 } 77 }
74 78
75 } // namespace test 79 } // namespace test
76 } // namespace chromeos 80 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698