OLD | NEW |
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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/md5.h" | 10 #include "base/md5.h" |
| 11 #include "base/safe_numerics.h" |
11 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
12 #include "printing/metafile.h" | 13 #include "printing/metafile.h" |
13 #include "printing/metafile_impl.h" | 14 #include "printing/metafile_impl.h" |
14 #include "third_party/skia/include/core/SkColor.h" | 15 #include "third_party/skia/include/core/SkColor.h" |
15 #include "ui/gfx/codec/png_codec.h" | 16 #include "ui/gfx/codec/png_codec.h" |
16 | 17 |
17 namespace printing { | 18 namespace printing { |
18 | 19 |
19 Image::Image(const FilePath& path) | 20 Image::Image(const FilePath& path) |
20 : row_length_(0), | 21 : row_length_(0), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 gfx::PNGCodec::FORMAT_BGRA, | 65 gfx::PNGCodec::FORMAT_BGRA, |
65 size_, | 66 size_, |
66 row_length_, | 67 row_length_, |
67 true, | 68 true, |
68 std::vector<gfx::PNGCodec::Comment>(), | 69 std::vector<gfx::PNGCodec::Comment>(), |
69 &compressed); | 70 &compressed); |
70 DCHECK(success && compressed.size()); | 71 DCHECK(success && compressed.size()); |
71 if (success) { | 72 if (success) { |
72 int write_bytes = file_util::WriteFile( | 73 int write_bytes = file_util::WriteFile( |
73 filepath, | 74 filepath, |
74 reinterpret_cast<char*>(&*compressed.begin()), compressed.size()); | 75 reinterpret_cast<char*>(&*compressed.begin()), |
| 76 base::checked_numeric_cast<int>(compressed.size())); |
75 success = (write_bytes == static_cast<int>(compressed.size())); | 77 success = (write_bytes == static_cast<int>(compressed.size())); |
76 DCHECK(success); | 78 DCHECK(success); |
77 } | 79 } |
78 return success; | 80 return success; |
79 } | 81 } |
80 | 82 |
81 double Image::PercentageDifferent(const Image& rhs) const { | 83 double Image::PercentageDifferent(const Image& rhs) const { |
82 if (size_.width() == 0 || size_.height() == 0 || | 84 if (size_.width() == 0 || size_.height() == 0 || |
83 rhs.size_.width() == 0 || rhs.size_.height() == 0) | 85 rhs.size_.width() == 0 || rhs.size_.height() == 0) |
84 return 100.; | 86 return 100.; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 reinterpret_cast<const unsigned char*>(compressed.c_str()), | 144 reinterpret_cast<const unsigned char*>(compressed.c_str()), |
143 compressed.size(), gfx::PNGCodec::FORMAT_BGRA, &data_, &w, &h); | 145 compressed.size(), gfx::PNGCodec::FORMAT_BGRA, &data_, &w, &h); |
144 size_.SetSize(w, h); | 146 size_.SetSize(w, h); |
145 row_length_ = size_.width() * sizeof(uint32); | 147 row_length_ = size_.width() * sizeof(uint32); |
146 return success; | 148 return success; |
147 } | 149 } |
148 | 150 |
149 bool Image::LoadMetafile(const std::string& data) { | 151 bool Image::LoadMetafile(const std::string& data) { |
150 DCHECK(!data.empty()); | 152 DCHECK(!data.empty()); |
151 NativeMetafile metafile; | 153 NativeMetafile metafile; |
152 if (!metafile.InitFromData(data.data(), data.size())) | 154 if (!metafile.InitFromData(data.data(), |
| 155 base::checked_numeric_cast<uint32>(data.size()))) |
153 return false; | 156 return false; |
154 return LoadMetafile(metafile); | 157 return LoadMetafile(metafile); |
155 } | 158 } |
156 | 159 |
157 } // namespace printing | 160 } // namespace printing |
OLD | NEW |