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

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

Issue 10883062: Resize and save custom wallpaper to large and small size (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reviews Created 8 years, 3 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
(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_png_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/png_codec.h"
13 #include "ui/gfx/size.h"
14 #include "ui/gfx/skia_util.h"
15
16 #if defined(USE_SYSTEM_ZLIB)
17 #include <zlib.h>
18 #else
19 #include "third_party/zlib/zlib.h"
20 #endif
21
22 namespace chromeos {
23
24 SimplePngEncoder::SimplePngEncoder(
25 scoped_refptr<base::RefCountedBytes> data,
26 SkBitmap image)
27 : data_(data),
28 image_(image) {
29 }
30
31 void SimplePngEncoder::Run(EncoderCallback callback) {
32 base::WorkerPool::PostTaskAndReply(
33 FROM_HERE,
34 base::Bind(&SimplePngEncoder::EncodeWallpaper, this),
35 base::Bind(callback, data_),
36 true /* task_is_slow */);
37 }
38
39 void SimplePngEncoder::EncodeWallpaper() {
40 if (cancel_flag_.IsSet())
41 return;
42 SkAutoLockPixels lock_input(image_);
43 // Avoid compression to make things faster.
44 gfx::PNGCodec::EncodeWithCompressionLevel(
45 reinterpret_cast<unsigned char*>(image_.getAddr32(0, 0)),
46 gfx::PNGCodec::FORMAT_SkBitmap,
47 gfx::Size(image_.width(), image_.height()),
48 image_.width() * image_.bytesPerPixel(),
49 false,
50 std::vector<gfx::PNGCodec::Comment>(),
51 Z_NO_COMPRESSION,
52 &data_->data());
53 }
54
55 void SimplePngEncoder::Cancel() {
56 cancel_flag_.Set();
57 }
58
59 SimplePngEncoder::~SimplePngEncoder() {
60 }
61
62 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698