| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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> | |
| 8 | |
| 9 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 10 #include "base/logging.h" | |
| 11 #include "base/md5.h" | 8 #include "base/md5.h" |
| 12 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 13 #include "gfx/codec/png_codec.h" | 10 #include "gfx/codec/png_codec.h" |
| 14 #include "third_party/skia/include/core/SkColor.h" | 11 #include "third_party/skia/include/core/SkColor.h" |
| 15 | 12 |
| 16 namespace printing { | 13 namespace printing { |
| 17 | 14 |
| 18 Image::Image(const FilePath& path) | 15 Image::Image(const FilePath& path) |
| 19 : row_length_(0), | 16 : row_length_(0), |
| 20 ignore_alpha_(true) { | 17 ignore_alpha_(true) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 } | 124 } |
| 128 } | 125 } |
| 129 | 126 |
| 130 // Like the WebKit ImageDiff tool, we define percentage different in terms | 127 // Like the WebKit ImageDiff tool, we define percentage different in terms |
| 131 // of the size of the 'actual' bitmap. | 128 // of the size of the 'actual' bitmap. |
| 132 double total_pixels = static_cast<double>(size_.width()) * | 129 double total_pixels = static_cast<double>(size_.width()) * |
| 133 static_cast<double>(height); | 130 static_cast<double>(height); |
| 134 return static_cast<double>(pixels_different) / total_pixels * 100.; | 131 return static_cast<double>(pixels_different) / total_pixels * 100.; |
| 135 } | 132 } |
| 136 | 133 |
| 137 uint32 Image::pixel_at(int x, int y) const { | |
| 138 DCHECK(x >= 0 && x < size_.width()); | |
| 139 DCHECK(y >= 0 && y < size_.height()); | |
| 140 const uint32* data = reinterpret_cast<const uint32*>(&*data_.begin()); | |
| 141 const uint32* data_row = data + y * row_length_ / sizeof(uint32); | |
| 142 return Color(data_row[x]); | |
| 143 } | |
| 144 | |
| 145 bool Image::LoadPng(const std::string& compressed) { | 134 bool Image::LoadPng(const std::string& compressed) { |
| 146 int w; | 135 int w; |
| 147 int h; | 136 int h; |
| 148 bool success = gfx::PNGCodec::Decode( | 137 bool success = gfx::PNGCodec::Decode( |
| 149 reinterpret_cast<const unsigned char*>(compressed.c_str()), | 138 reinterpret_cast<const unsigned char*>(compressed.c_str()), |
| 150 compressed.size(), gfx::PNGCodec::FORMAT_BGRA, &data_, &w, &h); | 139 compressed.size(), gfx::PNGCodec::FORMAT_BGRA, &data_, &w, &h); |
| 151 size_.SetSize(w, h); | 140 size_.SetSize(w, h); |
| 152 row_length_ = size_.width() * sizeof(uint32); | 141 row_length_ = size_.width() * sizeof(uint32); |
| 153 return success; | 142 return success; |
| 154 } | 143 } |
| 155 | 144 |
| 156 bool Image::LoadMetafile(const std::string& data) { | 145 bool Image::LoadMetafile(const std::string& data) { |
| 157 DCHECK(!data.empty()); | 146 DCHECK(!data.empty()); |
| 158 NativeMetafile metafile; | 147 NativeMetafile metafile; |
| 159 metafile.Init(data.data(), data.size()); | 148 metafile.Init(data.data(), data.size()); |
| 160 return LoadMetafile(metafile); | 149 return LoadMetafile(metafile); |
| 161 } | 150 } |
| 162 | 151 |
| 163 } // namespace printing | 152 } // namespace printing |
| OLD | NEW |