| OLD | NEW |
| 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 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "content/public/child/image_decoder_utils.h" | 12 #include "content/public/child/image_decoder_utils.h" |
| 13 #include "ipc/ipc_channel.h" | 13 #include "ipc/ipc_channel.h" |
| 14 #include "skia/ext/image_operations.h" | 14 #include "skia/ext/image_operations.h" |
| 15 #include "skia/public/type_converters.h" | |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
| 18 | 17 |
| 19 #if defined(OS_CHROMEOS) | 18 #if defined(OS_CHROMEOS) |
| 20 #include "ui/gfx/chromeos/codec/jpeg_codec_robust_slow.h" | 19 #include "ui/gfx/chromeos/codec/jpeg_codec_robust_slow.h" |
| 21 #include "ui/gfx/codec/png_codec.h" | 20 #include "ui/gfx/codec/png_codec.h" |
| 22 #endif | 21 #endif |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 int64_t kMaxMessageSize = IPC::Channel::kMaximumMessageSize; | 24 int64_t kMaxMessageSize = IPC::Channel::kMaximumMessageSize; |
| 26 int64_t kPadding = 64; | 25 int64_t kPadding = 64; |
| 27 } | 26 } |
| 28 | 27 |
| 29 ImageDecoderImpl::ImageDecoderImpl(int64_t max_message_size) | 28 ImageDecoderImpl::ImageDecoderImpl(int64_t max_message_size) |
| 30 : max_message_size_(max_message_size), binding_(this) { | 29 : max_message_size_(max_message_size), binding_(this) { |
| 31 } | 30 } |
| 32 | 31 |
| 33 ImageDecoderImpl::ImageDecoderImpl( | 32 ImageDecoderImpl::ImageDecoderImpl( |
| 34 mojo::InterfaceRequest<mojom::ImageDecoder> request) | 33 mojo::InterfaceRequest<mojom::ImageDecoder> request) |
| 35 : max_message_size_(kMaxMessageSize), binding_(this, std::move(request)) { | 34 : max_message_size_(kMaxMessageSize), binding_(this, std::move(request)) { |
| 36 } | 35 } |
| 37 | 36 |
| 38 ImageDecoderImpl::~ImageDecoderImpl() { | 37 ImageDecoderImpl::~ImageDecoderImpl() { |
| 39 } | 38 } |
| 40 | 39 |
| 41 void ImageDecoderImpl::DecodeImage( | 40 void ImageDecoderImpl::DecodeImage( |
| 42 mojo::Array<uint8_t> encoded_data, | 41 mojo::Array<uint8_t> encoded_data, |
| 43 mojom::ImageCodec codec, | 42 mojom::ImageCodec codec, |
| 44 bool shrink_to_fit, | 43 bool shrink_to_fit, |
| 45 const mojo::Callback<void(skia::mojom::BitmapPtr)>& callback) { | 44 const mojo::Callback<void(const SkBitmap&)>& callback) { |
| 46 if (encoded_data.size() == 0) { | 45 if (encoded_data.size() == 0) { |
| 47 callback.Run(nullptr); | 46 callback.Run(SkBitmap()); |
| 48 return; | 47 return; |
| 49 } | 48 } |
| 50 | 49 |
| 51 SkBitmap decoded_image; | 50 SkBitmap decoded_image; |
| 52 #if defined(OS_CHROMEOS) | 51 #if defined(OS_CHROMEOS) |
| 53 if (codec == mojom::ImageCodec::ROBUST_JPEG) { | 52 if (codec == mojom::ImageCodec::ROBUST_JPEG) { |
| 54 // Our robust jpeg decoding is using IJG libjpeg. | 53 // Our robust jpeg decoding is using IJG libjpeg. |
| 55 if (encoded_data.size()) { | 54 if (encoded_data.size()) { |
| 56 std::unique_ptr<SkBitmap> decoded_jpeg(gfx::JPEGCodecRobustSlow::Decode( | 55 std::unique_ptr<SkBitmap> decoded_jpeg(gfx::JPEGCodecRobustSlow::Decode( |
| 57 encoded_data.storage().data(), encoded_data.size())); | 56 encoded_data.storage().data(), encoded_data.size())); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 // TODO (Issue 416916): Instead of shrinking, return via shared memory | 91 // TODO (Issue 416916): Instead of shrinking, return via shared memory |
| 93 decoded_image = skia::ImageOperations::Resize( | 92 decoded_image = skia::ImageOperations::Resize( |
| 94 decoded_image, skia::ImageOperations::RESIZE_LANCZOS3, | 93 decoded_image, skia::ImageOperations::RESIZE_LANCZOS3, |
| 95 decoded_image.width() >> halves, decoded_image.height() >> halves); | 94 decoded_image.width() >> halves, decoded_image.height() >> halves); |
| 96 } else { | 95 } else { |
| 97 decoded_image.reset(); | 96 decoded_image.reset(); |
| 98 } | 97 } |
| 99 } | 98 } |
| 100 } | 99 } |
| 101 | 100 |
| 102 if (decoded_image.isNull()) | 101 callback.Run(decoded_image); |
| 103 callback.Run(nullptr); | |
| 104 else | |
| 105 callback.Run(skia::mojom::Bitmap::From(decoded_image)); | |
| 106 } | 102 } |
| OLD | NEW |