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

Side by Side Diff: services/image_decoder/image_decoder_impl.cc

Issue 1028543002: Turn the utility process image decoder into a Mojo service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move things around. Created 5 years, 9 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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 #include "services/image_decoder/image_decoder_impl.h"
5
6 #include <string.h>
7
8 #include "content/public/child/image_decoder_utils.h"
9 #include "ipc/ipc_channel.h"
10 #include "skia/ext/image_operations.h"
11 #include "skia/public/type_converters.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "ui/gfx/codec/jpeg_codec.h"
14 #include "ui/gfx/geometry/size.h"
15
16
17 namespace services {
18 namespace image_decoder {
19
20 namespace {
21 // TODO(amistry): Replace with more correct value.
22 int64_t kMaxMessageSize = IPC::Channel::kMaximumMessageSize;
23 }
24
25 ImageDecoderImpl::ImageDecoderImpl(mojo::InterfaceRequest<ImageDecoder> request)
26 : binding_(this, request.Pass()) {
27 }
28
29 ImageDecoderImpl::~ImageDecoderImpl() {
30 }
31
32 void ImageDecoderImpl::DecodeImage(
33 mojo::Array<uint8_t> encoded_data,
34 ImageCodec codec,
35 bool shrink_to_fit,
36 const mojo::Callback<void(bool, skia::ImagePtr)>& callback) {
37 LOG(INFO) << "ImageDecoderImpl::DecodeImage: " << encoded_data.size()
38 << ", " << codec << ", " << shrink_to_fit;
39
40 SkBitmap decoded_image;
41 if (codec == IMAGE_CODEC_ROBUST_JPEG) {
42 // Our robust jpeg decoding is using IJG libjpeg.
43 if (gfx::JPEGCodec::JpegLibraryVariant() == gfx::JPEGCodec::IJG_LIBJPEG &&
44 encoded_data.size()) {
45 scoped_ptr<SkBitmap> decoded_jpeg(gfx::JPEGCodec::Decode(
46 &encoded_data[0], encoded_data.size()));
47 if (decoded_jpeg.get() && !decoded_jpeg->empty()) {
48 decoded_image = *decoded_jpeg;
49 } else {
50 LOG(ERROR) << "Rebust JPEG decode failed";
51 }
52 } else {
53 LOG(ERROR) << "Unable to do robust JPEG decode";
54 }
55 } else {
56 decoded_image = content::DecodeImage(&encoded_data[0],
57 gfx::Size(),
58 encoded_data.size());
59 }
60
61 if (!decoded_image.isNull()) {
62 skia::ImagePtr dummy_image = skia::Image::New();
63 int64_t struct_size = GetSerializedSize_(dummy_image);
64 int64_t image_size = decoded_image.computeSize64();
65 int halves = 0;
66 while (struct_size + (image_size >> 2*halves) > kMaxMessageSize)
67 halves++;
68 if (halves) {
69 if (shrink_to_fit) {
70 // If decoded image is too large for IPC message, shrink it by halves.
71 // This prevents quality loss, and should never overshrink on displays
72 // smaller than 3600x2400.
73 // TODO (Issue 416916): Instead of shrinking, return via shared memory
74 decoded_image = skia::ImageOperations::Resize(
75 decoded_image, skia::ImageOperations::RESIZE_LANCZOS3,
76 decoded_image.width() >> halves, decoded_image.height() >> halves);
77 } else {
78 LOG(ERROR) << "Image too big and not shrinking";
79 decoded_image.reset();
80 }
81 }
82 }
83
84 if (decoded_image.isNull()) {
85 LOG(ERROR) << "No decoded image";
86 callback.Run(false, nullptr);
87 return;
88 }
89
90 callback.Run(true, skia::Image::From(decoded_image));
91 LOG(INFO) << "............Done decoding image";
92 }
93
94 } // namespace image_decoder
95 } // namespace services
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698