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

Side by Side Diff: printing/image.cc

Issue 2066843002: printing::Image: remove unused constructor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 | « printing/image.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "printing/image.h" 5 #include "printing/image.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/md5.h" 12 #include "base/md5.h"
13 #include "base/numerics/safe_conversions.h" 13 #include "base/numerics/safe_conversions.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "printing/metafile.h" 15 #include "printing/metafile.h"
16 #include "printing/pdf_metafile_skia.h"
17 #include "third_party/skia/include/core/SkColor.h" 16 #include "third_party/skia/include/core/SkColor.h"
18 #include "ui/gfx/codec/png_codec.h" 17 #include "ui/gfx/codec/png_codec.h"
19 18
20 namespace printing { 19 namespace printing {
21 20
22 Image::Image(const base::FilePath& path)
23 : row_length_(0),
24 ignore_alpha_(true) {
25 std::string data;
26 base::ReadFileToString(path, &data);
27 bool success = false;
28 if (path.MatchesExtension(FILE_PATH_LITERAL(".png"))) {
29 success = LoadPng(data);
30 } else if (path.MatchesExtension(FILE_PATH_LITERAL(".emf"))) {
31 success = LoadMetafile(data);
32 } else {
33 DCHECK(false);
34 }
35 if (!success) {
36 size_.SetSize(0, 0);
37 row_length_ = 0;
38 data_.clear();
39 }
40 }
41
42 Image::Image(const Metafile& metafile) 21 Image::Image(const Metafile& metafile)
43 : row_length_(0), 22 : row_length_(0),
44 ignore_alpha_(true) { 23 ignore_alpha_(true) {
45 LoadMetafile(metafile); 24 LoadMetafile(metafile);
46 } 25 }
47 26
48 Image::Image(const Image& image) 27 Image::Image(const Image& image)
49 : size_(image.size_), 28 : size_(image.size_),
50 row_length_(image.row_length_), 29 row_length_(image.row_length_),
51 data_(image.data_), 30 data_(image.data_),
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 int w; 122 int w;
144 int h; 123 int h;
145 bool success = gfx::PNGCodec::Decode( 124 bool success = gfx::PNGCodec::Decode(
146 reinterpret_cast<const unsigned char*>(compressed.c_str()), 125 reinterpret_cast<const unsigned char*>(compressed.c_str()),
147 compressed.size(), gfx::PNGCodec::FORMAT_BGRA, &data_, &w, &h); 126 compressed.size(), gfx::PNGCodec::FORMAT_BGRA, &data_, &w, &h);
148 size_.SetSize(w, h); 127 size_.SetSize(w, h);
149 row_length_ = size_.width() * sizeof(uint32_t); 128 row_length_ = size_.width() * sizeof(uint32_t);
150 return success; 129 return success;
151 } 130 }
152 131
153 bool Image::LoadMetafile(const std::string& data) {
154 DCHECK(!data.empty());
155 PdfMetafileSkia metafile;
156 if (!metafile.InitFromData(data.data(),
157 base::checked_cast<uint32_t>(data.size())))
158 return false;
159 return LoadMetafile(metafile);
160 }
161
162 } // namespace printing 132 } // namespace printing
OLDNEW
« no previous file with comments | « printing/image.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698