Chromium Code Reviews| Index: chrome/browser/chromeos/login/simple_png_encoder.cc |
| diff --git a/chrome/browser/chromeos/login/simple_png_encoder.cc b/chrome/browser/chromeos/login/simple_png_encoder.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..214860764725bf121d76e0927c012de8f058ad1d |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/login/simple_png_encoder.cc |
| @@ -0,0 +1,58 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/login/simple_png_encoder.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/location.h" |
| +#include "base/threading/worker_pool.h" |
| +#include "chrome/browser/chromeos/login/user_manager.h" |
| +#include "chrome/common/url_constants.h" |
| +#include "ui/gfx/codec/png_codec.h" |
| +#include "ui/gfx/size.h" |
| +#include "ui/gfx/skia_util.h" |
| + |
| +#include <zlib.h> |
|
Ivan Korotkov
2012/08/28 16:16:13
This shouldn't make a big difference since you onl
bshe
2012/08/29 14:30:07
Done. Looks like I need to add third_party/zlib/zl
|
| + |
| +namespace chromeos { |
| + |
| +SimplePngEncoder::SimplePngEncoder( |
| + scoped_refptr<base::RefCountedBytes> data, |
| + SkBitmap image) |
| + : data_(data), |
| + image_(image) { |
| +} |
| + |
| +void SimplePngEncoder::Run(EncoderCallback callback) { |
| + base::WorkerPool::PostTaskAndReply( |
| + FROM_HERE, |
| + base::Bind(&SimplePngEncoder::EncodeWallpaper, this), |
| + base::Bind(callback, data_), |
| + true /* task_is_slow */); |
| +} |
| + |
| +void SimplePngEncoder::EncodeWallpaper() { |
| + if (cancel_flag_.IsSet()) |
| + return; |
| + SkAutoLockPixels lock_input(image_); |
| + // Avoid compression to make things faster. |
| + gfx::PNGCodec::EncodeWithCompressionLevel( |
| + reinterpret_cast<unsigned char*>(image_.getAddr32(0, 0)), |
| + gfx::PNGCodec::FORMAT_SkBitmap, |
| + gfx::Size(image_.width(), image_.height()), |
| + image_.width() * image_.bytesPerPixel(), |
| + false, |
| + std::vector<gfx::PNGCodec::Comment>(), |
| + Z_NO_COMPRESSION, |
| + &data_->data()); |
| +} |
| + |
| +void SimplePngEncoder::Cancel() { |
| + cancel_flag_.Set(); |
| +} |
| + |
| +SimplePngEncoder::~SimplePngEncoder() { |
| +} |
| + |
| +} // namespace chromeos |