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

Side by Side Diff: ui/gfx/image/image_util.cc

Issue 8631002: [ntp4] Use highest quality jpeg compression for thumbnail images. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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
« ui/gfx/image/image_util.h ('K') | « ui/gfx/image/image_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ui/gfx/image/image_util.h" 5 #include "ui/gfx/image/image_util.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "third_party/skia/include/core/SkBitmap.h" 8 #include "third_party/skia/include/core/SkBitmap.h"
9 #include "ui/gfx/codec/jpeg_codec.h" 9 #include "ui/gfx/codec/jpeg_codec.h"
10 #include "ui/gfx/codec/png_codec.h" 10 #include "ui/gfx/codec/png_codec.h"
11 #include "ui/gfx/image/image.h" 11 #include "ui/gfx/image/image.h"
12 12
13 namespace gfx { 13 namespace gfx {
14 14
15 Image* ImageFromPNGEncodedData(const unsigned char* input, size_t input_size) { 15 Image* ImageFromPNGEncodedData(const unsigned char* input, size_t input_size) {
16 scoped_ptr<SkBitmap> favicon_bitmap(new SkBitmap()); 16 scoped_ptr<SkBitmap> favicon_bitmap(new SkBitmap());
17 if (gfx::PNGCodec::Decode(input, input_size, favicon_bitmap.get())) 17 if (gfx::PNGCodec::Decode(input, input_size, favicon_bitmap.get()))
18 return new Image(favicon_bitmap.release()); 18 return new Image(favicon_bitmap.release());
19 19
20 return NULL; 20 return NULL;
21 } 21 }
22 22
23 bool PNGEncodedDataFromImage(const Image& image, 23 bool PNGEncodedDataFromImage(const Image& image,
24 std::vector<unsigned char>* dst) { 24 std::vector<unsigned char>* dst) {
25 const SkBitmap& bitmap = image; 25 const SkBitmap& bitmap = image;
26 return gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, dst); 26 return gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, dst);
27 } 27 }
28 28
29 bool JPEGEncodedDataFromImage(const Image& image, 29 bool JPEGEncodedDataFromImage(const Image& image, int quality,
30 std::vector<unsigned char>* dst) { 30 std::vector<unsigned char>* dst) {
31 const SkBitmap& bitmap = image; 31 const SkBitmap& bitmap = image;
32 SkAutoLockPixels bitmap_lock(bitmap); 32 SkAutoLockPixels bitmap_lock(bitmap);
33 33
34 if (!bitmap.readyToDraw()) 34 if (!bitmap.readyToDraw())
35 return false; 35 return false;
36 36
37 // Use 90 quality (out of 100) which is pretty high, because
38 // we're very sensitive to artifacts for these small sized,
39 // highly detailed images.
40 return gfx::JPEGCodec::Encode( 37 return gfx::JPEGCodec::Encode(
41 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), 38 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)),
42 gfx::JPEGCodec::FORMAT_BGRA, bitmap.width(), 39 gfx::JPEGCodec::FORMAT_BGRA, bitmap.width(),
43 bitmap.height(), 40 bitmap.height(),
44 static_cast<int>(bitmap.rowBytes()), 90, 41 static_cast<int>(bitmap.rowBytes()), quality,
45 dst); 42 dst);
46 } 43 }
47 44
48 } 45 }
OLDNEW
« ui/gfx/image/image_util.h ('K') | « ui/gfx/image/image_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698