1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/login/user_image_manager_test_util.h"
9 #include "base/file_util.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/message_loop/message_loop_proxy.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "ui/gfx/image/image_skia.h"
14 #include "ui/gfx/image/image_skia_rep.h"
19 const char kUserAvatarImage1RelativePath
[] = "chromeos/avatar1.jpg";
20 const char kUserAvatarImage2RelativePath
[] = "chromeos/avatar2.jpg";
22 bool AreImagesEqual(const gfx::ImageSkia
& first
, const gfx::ImageSkia
& second
) {
23 if (first
.width() != second
.width() || first
.height() != second
.height())
25 const SkBitmap
* first_bitmap
= first
.bitmap();
26 const SkBitmap
* second_bitmap
= second
.bitmap();
27 if (!first_bitmap
&& !second_bitmap
)
29 if (!first_bitmap
|| !second_bitmap
)
32 const size_t size
= first_bitmap
->getSize();
33 if (second_bitmap
->getSize() != size
)
36 SkAutoLockPixels
first_pixel_lock(*first_bitmap
);
37 SkAutoLockPixels
second_pixel_lock(*second_bitmap
);
38 uint8_t* first_data
= reinterpret_cast<uint8_t*>(first_bitmap
->getPixels());
39 uint8_t* second_data
= reinterpret_cast<uint8_t*>(second_bitmap
->getPixels());
40 for (size_t i
= 0; i
< size
; ++i
) {
41 if (first_data
[i
] != second_data
[i
])
47 ImageLoader::ImageLoader(const base::FilePath
& path
) : path_(path
) {
50 ImageLoader::~ImageLoader() {
53 scoped_ptr
<gfx::ImageSkia
> ImageLoader::Load() {
54 std::string image_data
;
55 ReadFileToString(path_
, &image_data
);
56 scoped_refptr
<ImageDecoder
> image_decoder
= new ImageDecoder(
59 ImageDecoder::ROBUST_JPEG_CODEC
);
60 image_decoder
->Start(base::MessageLoopProxy::current());
62 return decoded_image_
.Pass();
65 void ImageLoader::OnImageDecoded(const ImageDecoder
* decoder
,
66 const SkBitmap
& decoded_image
) {
68 new gfx::ImageSkia(gfx::ImageSkiaRep(decoded_image
, 1.0f
)));
72 void ImageLoader::OnDecodeImageFailed(const ImageDecoder
* decoder
) {
77 } // namespace chromeos