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

Side by Side Diff: chrome/utility/image_decoder_impl.cc

Issue 2483013002: Mojo C++ bindings: Remove more use_new_wrapper_types=false. (Closed)
Patch Set: . Created 4 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
« no previous file with comments | « chrome/utility/image_decoder_impl.h ('k') | chrome/utility/image_decoder_impl_unittest.cc » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/utility/image_decoder_impl.h" 5 #include "chrome/utility/image_decoder_impl.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 16 matching lines...) Expand all
27 } 27 }
28 28
29 ImageDecoderImpl::ImageDecoderImpl() : ImageDecoderImpl(kMaxMessageSize) {} 29 ImageDecoderImpl::ImageDecoderImpl() : ImageDecoderImpl(kMaxMessageSize) {}
30 30
31 ImageDecoderImpl::ImageDecoderImpl(int64_t max_message_size) 31 ImageDecoderImpl::ImageDecoderImpl(int64_t max_message_size)
32 : max_message_size_(max_message_size) {} 32 : max_message_size_(max_message_size) {}
33 33
34 ImageDecoderImpl::~ImageDecoderImpl() { 34 ImageDecoderImpl::~ImageDecoderImpl() {
35 } 35 }
36 36
37 void ImageDecoderImpl::DecodeImage( 37 void ImageDecoderImpl::DecodeImage(const std::vector<uint8_t>& encoded_data,
38 mojo::Array<uint8_t> encoded_data, 38 mojom::ImageCodec codec,
39 mojom::ImageCodec codec, 39 bool shrink_to_fit,
40 bool shrink_to_fit, 40 const DecodeImageCallback& callback) {
41 const DecodeImageCallback& callback) { 41 if (encoded_data.empty()) {
42 if (encoded_data.size() == 0) {
43 callback.Run(SkBitmap()); 42 callback.Run(SkBitmap());
44 return; 43 return;
45 } 44 }
46 45
47 SkBitmap decoded_image; 46 SkBitmap decoded_image;
48 #if defined(OS_CHROMEOS) 47 #if defined(OS_CHROMEOS)
49 if (codec == mojom::ImageCodec::ROBUST_JPEG) { 48 if (codec == mojom::ImageCodec::ROBUST_JPEG) {
50 // Our robust jpeg decoding is using IJG libjpeg. 49 // Our robust jpeg decoding is using IJG libjpeg.
51 if (encoded_data.size()) { 50 std::unique_ptr<SkBitmap> decoded_jpeg(gfx::JPEGCodecRobustSlow::Decode(
52 std::unique_ptr<SkBitmap> decoded_jpeg(gfx::JPEGCodecRobustSlow::Decode( 51 encoded_data.data(), encoded_data.size()));
53 encoded_data.storage().data(), encoded_data.size())); 52 if (decoded_jpeg.get() && !decoded_jpeg->empty())
54 if (decoded_jpeg.get() && !decoded_jpeg->empty()) 53 decoded_image = *decoded_jpeg;
55 decoded_image = *decoded_jpeg;
56 }
57 } else if (codec == mojom::ImageCodec::ROBUST_PNG) { 54 } else if (codec == mojom::ImageCodec::ROBUST_PNG) {
58 // Our robust PNG decoding is using libpng. 55 // Our robust PNG decoding is using libpng.
59 if (encoded_data.size()) { 56 SkBitmap decoded_png;
60 SkBitmap decoded_png; 57 if (gfx::PNGCodec::Decode(encoded_data.data(), encoded_data.size(),
61 if (gfx::PNGCodec::Decode(encoded_data.storage().data(), 58 &decoded_png)) {
62 encoded_data.size(), &decoded_png)) { 59 decoded_image = decoded_png;
63 decoded_image = decoded_png;
64 }
65 } 60 }
66 } 61 }
67 #endif // defined(OS_CHROMEOS) 62 #endif // defined(OS_CHROMEOS)
68 if (codec == mojom::ImageCodec::DEFAULT) { 63 if (codec == mojom::ImageCodec::DEFAULT) {
69 decoded_image = content::DecodeImage(encoded_data.storage().data(), 64 decoded_image = content::DecodeImage(encoded_data.data(), gfx::Size(),
70 gfx::Size(), encoded_data.size()); 65 encoded_data.size());
71 } 66 }
72 67
73 if (!decoded_image.isNull()) { 68 if (!decoded_image.isNull()) {
74 // When serialized, the space taken up by a skia::mojom::Bitmap excluding 69 // When serialized, the space taken up by a skia::mojom::Bitmap excluding
75 // the pixel data payload should be: 70 // the pixel data payload should be:
76 // sizeof(skia::mojom::Bitmap::Data_) + pixel data array header (8 bytes) 71 // sizeof(skia::mojom::Bitmap::Data_) + pixel data array header (8 bytes)
77 // Use a bigger number in case we need padding at the end. 72 // Use a bigger number in case we need padding at the end.
78 int64_t struct_size = sizeof(skia::mojom::Bitmap::Data_) + kPadding; 73 int64_t struct_size = sizeof(skia::mojom::Bitmap::Data_) + kPadding;
79 int64_t image_size = decoded_image.computeSize64(); 74 int64_t image_size = decoded_image.computeSize64();
80 int halves = 0; 75 int halves = 0;
81 while (struct_size + (image_size >> 2 * halves) > max_message_size_) 76 while (struct_size + (image_size >> 2 * halves) > max_message_size_)
82 halves++; 77 halves++;
83 if (halves) { 78 if (halves) {
84 if (shrink_to_fit) { 79 if (shrink_to_fit) {
85 // If decoded image is too large for IPC message, shrink it by halves. 80 // If decoded image is too large for IPC message, shrink it by halves.
86 // This prevents quality loss, and should never overshrink on displays 81 // This prevents quality loss, and should never overshrink on displays
87 // smaller than 3600x2400. 82 // smaller than 3600x2400.
88 // TODO (Issue 416916): Instead of shrinking, return via shared memory 83 // TODO (Issue 416916): Instead of shrinking, return via shared memory
89 decoded_image = skia::ImageOperations::Resize( 84 decoded_image = skia::ImageOperations::Resize(
90 decoded_image, skia::ImageOperations::RESIZE_LANCZOS3, 85 decoded_image, skia::ImageOperations::RESIZE_LANCZOS3,
91 decoded_image.width() >> halves, decoded_image.height() >> halves); 86 decoded_image.width() >> halves, decoded_image.height() >> halves);
92 } else { 87 } else {
93 decoded_image.reset(); 88 decoded_image.reset();
94 } 89 }
95 } 90 }
96 } 91 }
97 92
98 callback.Run(decoded_image); 93 callback.Run(decoded_image);
99 } 94 }
OLDNEW
« no previous file with comments | « chrome/utility/image_decoder_impl.h ('k') | chrome/utility/image_decoder_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698