OLD | NEW |
1 // Copyright (c) 2009 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 #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 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/logging.h" | |
13 #include "gfx/size.h" | 12 #include "gfx/size.h" |
14 #include "printing/native_metafile.h" | 13 #include "printing/native_metafile.h" |
15 | 14 |
16 class FilePath; | 15 class FilePath; |
17 | 16 |
18 namespace printing { | 17 namespace printing { |
19 | 18 |
20 // Lightweight raw-bitmap management. The image, once initialized, is immutable. | 19 // Lightweight raw-bitmap management. The image, once initialized, is immutable. |
21 // The main purpose is testing image contents. | 20 // The main purpose is testing image contents. |
22 class Image { | 21 class Image { |
(...skipping 26 matching lines...) Expand all Loading... |
49 double PercentageDifferent(const Image& rhs) const; | 48 double PercentageDifferent(const Image& rhs) const; |
50 | 49 |
51 // Returns the 0x0RGB or 0xARGB value of the pixel at the given location. | 50 // Returns the 0x0RGB or 0xARGB value of the pixel at the given location. |
52 uint32 Color(uint32 color) const { | 51 uint32 Color(uint32 color) const { |
53 if (ignore_alpha_) | 52 if (ignore_alpha_) |
54 return color & 0xFFFFFF; // Strip out A. | 53 return color & 0xFFFFFF; // Strip out A. |
55 else | 54 else |
56 return color; | 55 return color; |
57 } | 56 } |
58 | 57 |
59 uint32 pixel_at(int x, int y) const { | 58 uint32 pixel_at(int x, int y) const; |
60 DCHECK(x >= 0 && x < size_.width()); | |
61 DCHECK(y >= 0 && y < size_.height()); | |
62 const uint32* data = reinterpret_cast<const uint32*>(&*data_.begin()); | |
63 const uint32* data_row = data + y * row_length_ / sizeof(uint32); | |
64 return Color(data_row[x]); | |
65 } | |
66 | 59 |
67 private: | 60 private: |
68 // Construct from metafile. This is kept internal since it's ambiguous what | 61 // Construct from metafile. This is kept internal since it's ambiguous what |
69 // kind of data is used (png, bmp, metafile etc). | 62 // kind of data is used (png, bmp, metafile etc). |
70 Image(const void* data, size_t size); | 63 Image(const void* data, size_t size); |
71 | 64 |
72 bool LoadPng(const std::string& compressed); | 65 bool LoadPng(const std::string& compressed); |
73 | 66 |
74 bool LoadMetafile(const std::string& data); | 67 bool LoadMetafile(const std::string& data); |
75 | 68 |
(...skipping 12 matching lines...) Expand all Loading... |
88 // Flag to signal if the comparison functions should ignore the alpha channel. | 81 // Flag to signal if the comparison functions should ignore the alpha channel. |
89 const bool ignore_alpha_; // Currently always true. | 82 const bool ignore_alpha_; // Currently always true. |
90 | 83 |
91 // Prevent operator= (this function has no implementation) | 84 // Prevent operator= (this function has no implementation) |
92 Image& operator=(const Image& image); | 85 Image& operator=(const Image& image); |
93 }; | 86 }; |
94 | 87 |
95 } // namespace printing | 88 } // namespace printing |
96 | 89 |
97 #endif // PRINTING_IMAGE_H_ | 90 #endif // PRINTING_IMAGE_H_ |
OLD | NEW |