| 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 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 : max_message_size_(kMaxMessageSize), binding_(this, std::move(request)) { | 35 : max_message_size_(kMaxMessageSize), binding_(this, std::move(request)) { |
| 36 } | 36 } |
| 37 | 37 |
| 38 ImageDecoderImpl::~ImageDecoderImpl() { | 38 ImageDecoderImpl::~ImageDecoderImpl() { |
| 39 } | 39 } |
| 40 | 40 |
| 41 void ImageDecoderImpl::DecodeImage( | 41 void ImageDecoderImpl::DecodeImage( |
| 42 mojo::Array<uint8_t> encoded_data, | 42 mojo::Array<uint8_t> encoded_data, |
| 43 mojom::ImageCodec codec, | 43 mojom::ImageCodec codec, |
| 44 bool shrink_to_fit, | 44 bool shrink_to_fit, |
| 45 const mojo::Callback<void(skia::mojom::BitmapPtr)>& callback) { | 45 const mojo::Callback<void(blink::mojom::BitmapPtr)>& callback) { |
| 46 if (encoded_data.size() == 0) { | 46 if (encoded_data.size() == 0) { |
| 47 callback.Run(nullptr); | 47 callback.Run(nullptr); |
| 48 return; | 48 return; |
| 49 } | 49 } |
| 50 | 50 |
| 51 SkBitmap decoded_image; | 51 SkBitmap decoded_image; |
| 52 #if defined(OS_CHROMEOS) | 52 #if defined(OS_CHROMEOS) |
| 53 if (codec == mojom::ImageCodec::ROBUST_JPEG) { | 53 if (codec == mojom::ImageCodec::ROBUST_JPEG) { |
| 54 // Our robust jpeg decoding is using IJG libjpeg. | 54 // Our robust jpeg decoding is using IJG libjpeg. |
| 55 if (encoded_data.size()) { | 55 if (encoded_data.size()) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 #endif // defined(OS_CHROMEOS) | 71 #endif // defined(OS_CHROMEOS) |
| 72 if (codec == mojom::ImageCodec::DEFAULT) { | 72 if (codec == mojom::ImageCodec::DEFAULT) { |
| 73 decoded_image = content::DecodeImage(encoded_data.storage().data(), | 73 decoded_image = content::DecodeImage(encoded_data.storage().data(), |
| 74 gfx::Size(), encoded_data.size()); | 74 gfx::Size(), encoded_data.size()); |
| 75 } | 75 } |
| 76 | 76 |
| 77 if (!decoded_image.isNull()) { | 77 if (!decoded_image.isNull()) { |
| 78 skia::mojom::BitmapPtr dummy_image = skia::mojom::Bitmap::New(); | 78 blink::mojom::BitmapPtr dummy_image = blink::mojom::Bitmap::New(); |
| 79 int64_t struct_size = | 79 int64_t struct_size = |
| 80 skia::mojom::GetSerializedSize_(dummy_image, nullptr) + kPadding; | 80 blink::mojom::GetSerializedSize_(dummy_image, nullptr) + kPadding; |
| 81 int64_t image_size = decoded_image.computeSize64(); | 81 int64_t image_size = decoded_image.computeSize64(); |
| 82 int halves = 0; | 82 int halves = 0; |
| 83 while (struct_size + (image_size >> 2 * halves) > max_message_size_) | 83 while (struct_size + (image_size >> 2 * halves) > max_message_size_) |
| 84 halves++; | 84 halves++; |
| 85 if (halves) { | 85 if (halves) { |
| 86 if (shrink_to_fit) { | 86 if (shrink_to_fit) { |
| 87 // If decoded image is too large for IPC message, shrink it by halves. | 87 // If decoded image is too large for IPC message, shrink it by halves. |
| 88 // This prevents quality loss, and should never overshrink on displays | 88 // This prevents quality loss, and should never overshrink on displays |
| 89 // smaller than 3600x2400. | 89 // smaller than 3600x2400. |
| 90 // TODO (Issue 416916): Instead of shrinking, return via shared memory | 90 // TODO (Issue 416916): Instead of shrinking, return via shared memory |
| 91 decoded_image = skia::ImageOperations::Resize( | 91 decoded_image = skia::ImageOperations::Resize( |
| 92 decoded_image, skia::ImageOperations::RESIZE_LANCZOS3, | 92 decoded_image, skia::ImageOperations::RESIZE_LANCZOS3, |
| 93 decoded_image.width() >> halves, decoded_image.height() >> halves); | 93 decoded_image.width() >> halves, decoded_image.height() >> halves); |
| 94 } else { | 94 } else { |
| 95 decoded_image.reset(); | 95 decoded_image.reset(); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 if (decoded_image.isNull()) | 100 if (decoded_image.isNull()) |
| 101 callback.Run(nullptr); | 101 callback.Run(nullptr); |
| 102 else | 102 else |
| 103 callback.Run(skia::mojom::Bitmap::From(decoded_image)); | 103 callback.Run(blink::mojom::Bitmap::From(decoded_image)); |
| 104 } | 104 } |
| OLD | NEW |