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 #ifndef PRINTING_IMAGE_H_ | 5 #ifndef PRINTING_IMAGE_H_ |
6 #define PRINTING_IMAGE_H_ | 6 #define PRINTING_IMAGE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // Return a checksum of the image (MD5 over the internal data structure). | 46 // Return a checksum of the image (MD5 over the internal data structure). |
47 std::string checksum() const; | 47 std::string checksum() const; |
48 | 48 |
49 // Save image as PNG. | 49 // Save image as PNG. |
50 bool SaveToPng(const base::FilePath& filepath) const; | 50 bool SaveToPng(const base::FilePath& filepath) const; |
51 | 51 |
52 // Returns % of pixels different | 52 // Returns % of pixels different |
53 double PercentageDifferent(const Image& rhs) const; | 53 double PercentageDifferent(const Image& rhs) const; |
54 | 54 |
55 // Returns the 0x0RGB or 0xARGB value of the pixel at the given location. | 55 // Returns the 0x0RGB or 0xARGB value of the pixel at the given location. |
56 uint32 Color(uint32 color) const { | 56 uint32_t Color(uint32_t color) const { |
57 if (ignore_alpha_) | 57 if (ignore_alpha_) |
58 return color & 0xFFFFFF; // Strip out A. | 58 return color & 0xFFFFFF; // Strip out A. |
59 else | 59 else |
60 return color; | 60 return color; |
61 } | 61 } |
62 | 62 |
63 uint32 pixel_at(int x, int y) const { | 63 uint32_t pixel_at(int x, int y) const { |
64 DCHECK(x >= 0 && x < size_.width()); | 64 DCHECK(x >= 0 && x < size_.width()); |
65 DCHECK(y >= 0 && y < size_.height()); | 65 DCHECK(y >= 0 && y < size_.height()); |
66 const uint32* data = reinterpret_cast<const uint32*>(&*data_.begin()); | 66 const uint32_t* data = reinterpret_cast<const uint32_t*>(&*data_.begin()); |
67 const uint32* data_row = data + y * row_length_ / sizeof(uint32); | 67 const uint32_t* data_row = data + y * row_length_ / sizeof(uint32_t); |
68 return Color(data_row[x]); | 68 return Color(data_row[x]); |
69 } | 69 } |
70 | 70 |
71 private: | 71 private: |
72 // Construct from metafile. This is kept internal since it's ambiguous what | 72 // Construct from metafile. This is kept internal since it's ambiguous what |
73 // kind of data is used (png, bmp, metafile etc). | 73 // kind of data is used (png, bmp, metafile etc). |
74 Image(const void* data, size_t size); | 74 Image(const void* data, size_t size); |
75 | 75 |
76 bool LoadPng(const std::string& compressed); | 76 bool LoadPng(const std::string& compressed); |
77 | 77 |
78 bool LoadMetafile(const std::string& data); | 78 bool LoadMetafile(const std::string& data); |
79 | 79 |
80 bool LoadMetafile(const Metafile& metafile); | 80 bool LoadMetafile(const Metafile& metafile); |
81 | 81 |
82 // Pixel dimensions of the image. | 82 // Pixel dimensions of the image. |
83 gfx::Size size_; | 83 gfx::Size size_; |
84 | 84 |
85 // Length of a line in bytes. | 85 // Length of a line in bytes. |
86 int row_length_; | 86 int row_length_; |
87 | 87 |
88 // Actual bitmap data in arrays of RGBAs (so when loaded as uint32, it's | 88 // Actual bitmap data in arrays of RGBAs (so when loaded as uint32_t, it's |
89 // 0xABGR). | 89 // 0xABGR). |
90 std::vector<unsigned char> data_; | 90 std::vector<unsigned char> data_; |
91 | 91 |
92 // Flag to signal if the comparison functions should ignore the alpha channel. | 92 // Flag to signal if the comparison functions should ignore the alpha channel. |
93 const bool ignore_alpha_; // Currently always true. | 93 const bool ignore_alpha_; // Currently always true. |
94 | 94 |
95 // Prevent operator= (this function has no implementation) | 95 // Prevent operator= (this function has no implementation) |
96 Image& operator=(const Image& image); | 96 Image& operator=(const Image& image); |
97 }; | 97 }; |
98 | 98 |
99 } // namespace printing | 99 } // namespace printing |
100 | 100 |
101 #endif // PRINTING_IMAGE_H_ | 101 #endif // PRINTING_IMAGE_H_ |
OLD | NEW |