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

Side by Side Diff: components/suggestions/image_encoder.cc

Issue 1879443002: JPEG decoding: replace ownership comments with std::unique_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build fixes Created 4 years, 8 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
« no previous file with comments | « components/suggestions/image_encoder.h ('k') | components/suggestions/image_encoder_ios.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/suggestions/image_encoder.h" 5 #include "components/suggestions/image_encoder.h"
6 6
7 #include "ui/gfx/codec/jpeg_codec.h" 7 #include "ui/gfx/codec/jpeg_codec.h"
8 #include "ui/gfx/image/image_skia.h" 8 #include "ui/gfx/image/image_skia.h"
9 9
10 namespace suggestions { 10 namespace suggestions {
11 11
12 SkBitmap* DecodeJPEGToSkBitmap(const void* encoded_data, size_t size) { 12 std::unique_ptr<SkBitmap> DecodeJPEGToSkBitmap(const void* encoded_data,
13 size_t size) {
13 return gfx::JPEGCodec::Decode(static_cast<const unsigned char*>(encoded_data), 14 return gfx::JPEGCodec::Decode(static_cast<const unsigned char*>(encoded_data),
14 size); 15 size);
15 } 16 }
16 17
17 bool EncodeSkBitmapToJPEG(const SkBitmap& bitmap, 18 bool EncodeSkBitmapToJPEG(const SkBitmap& bitmap,
18 std::vector<unsigned char>* dest) { 19 std::vector<unsigned char>* dest) {
19 SkAutoLockPixels bitmap_lock(bitmap); 20 SkAutoLockPixels bitmap_lock(bitmap);
20 if (!bitmap.readyToDraw() || bitmap.isNull()) { 21 if (!bitmap.readyToDraw() || bitmap.isNull()) {
21 return false; 22 return false;
22 } 23 }
23 return gfx::JPEGCodec::Encode( 24 return gfx::JPEGCodec::Encode(
24 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), 25 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)),
25 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(), 26 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), bitmap.height(),
26 bitmap.rowBytes(), 100, dest); 27 bitmap.rowBytes(), 100, dest);
27 } 28 }
28 29
29 } // namespace suggestions 30 } // namespace suggestions
OLDNEW
« no previous file with comments | « components/suggestions/image_encoder.h ('k') | components/suggestions/image_encoder_ios.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698