| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/login/simple_jpeg_encoder.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/location.h" |
| 9 #include "base/threading/worker_pool.h" |
| 10 #include "chrome/browser/chromeos/login/user_manager.h" |
| 11 #include "chrome/common/url_constants.h" |
| 12 #include "ui/gfx/codec/jpeg_codec.h" |
| 13 #include "ui/gfx/size.h" |
| 14 #include "ui/gfx/skia_util.h" |
| 15 |
| 16 namespace chromeos { |
| 17 |
| 18 namespace { |
| 19 const int kCustomWallpaperQuality = 90; |
| 20 } |
| 21 |
| 22 SimpleJpegEncoder::SimpleJpegEncoder( |
| 23 scoped_refptr<base::RefCountedBytes> data, |
| 24 SkBitmap image) |
| 25 : data_(data), |
| 26 image_(image) { |
| 27 } |
| 28 |
| 29 void SimpleJpegEncoder::Run(EncoderCallback callback) { |
| 30 base::WorkerPool::PostTaskAndReply( |
| 31 FROM_HERE, |
| 32 base::Bind(&SimpleJpegEncoder::EncodeWallpaper, this), |
| 33 base::Bind(callback, data_), |
| 34 true /* task_is_slow */); |
| 35 } |
| 36 |
| 37 void SimpleJpegEncoder::EncodeWallpaper() { |
| 38 if (cancel_flag_.IsSet()) |
| 39 return; |
| 40 SkAutoLockPixels lock_input(image_); |
| 41 gfx::JPEGCodec::Encode( |
| 42 reinterpret_cast<unsigned char*>(image_.getAddr32(0, 0)), |
| 43 gfx::JPEGCodec::FORMAT_SkBitmap, |
| 44 image_.width(), |
| 45 image_.height(), |
| 46 image_.width() * image_.bytesPerPixel(), |
| 47 kCustomWallpaperQuality, &data_->data()); |
| 48 } |
| 49 |
| 50 void SimpleJpegEncoder::Cancel() { |
| 51 cancel_flag_.Set(); |
| 52 } |
| 53 |
| 54 SimpleJpegEncoder::~SimpleJpegEncoder() { |
| 55 } |
| 56 |
| 57 } // namespace chromeos |
| OLD | NEW |