| 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/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/md5.h" | 10 #include "base/md5.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 row_length_(image.row_length_), | 48 row_length_(image.row_length_), |
| 49 data_(image.data_), | 49 data_(image.data_), |
| 50 ignore_alpha_(image.ignore_alpha_) { | 50 ignore_alpha_(image.ignore_alpha_) { |
| 51 } | 51 } |
| 52 | 52 |
| 53 Image::~Image() {} | 53 Image::~Image() {} |
| 54 | 54 |
| 55 std::string Image::checksum() const { | 55 std::string Image::checksum() const { |
| 56 base::MD5Digest digest; | 56 base::MD5Digest digest; |
| 57 base::MD5Sum(&data_[0], data_.size(), &digest); | 57 base::MD5Sum(&data_[0], data_.size(), &digest); |
| 58 return base::HexEncode(&digest, sizeof(digest)); | 58 return base::MD5DigestToBase16(digest); |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool Image::SaveToPng(const base::FilePath& filepath) const { | 61 bool Image::SaveToPng(const base::FilePath& filepath) const { |
| 62 DCHECK(!data_.empty()); | 62 DCHECK(!data_.empty()); |
| 63 std::vector<unsigned char> compressed; | 63 std::vector<unsigned char> compressed; |
| 64 bool success = gfx::PNGCodec::Encode(&*data_.begin(), | 64 bool success = gfx::PNGCodec::Encode(&*data_.begin(), |
| 65 gfx::PNGCodec::FORMAT_BGRA, | 65 gfx::PNGCodec::FORMAT_BGRA, |
| 66 size_, | 66 size_, |
| 67 row_length_, | 67 row_length_, |
| 68 true, | 68 true, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 bool Image::LoadMetafile(const std::string& data) { | 151 bool Image::LoadMetafile(const std::string& data) { |
| 152 DCHECK(!data.empty()); | 152 DCHECK(!data.empty()); |
| 153 PdfMetafileSkia metafile; | 153 PdfMetafileSkia metafile; |
| 154 if (!metafile.InitFromData(data.data(), | 154 if (!metafile.InitFromData(data.data(), |
| 155 base::checked_cast<uint32>(data.size()))) | 155 base::checked_cast<uint32>(data.size()))) |
| 156 return false; | 156 return false; |
| 157 return LoadMetafile(metafile); | 157 return LoadMetafile(metafile); |
| 158 } | 158 } |
| 159 | 159 |
| 160 } // namespace printing | 160 } // namespace printing |
| OLD | NEW |