1 // Copyright 2011 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef PRINTING_IMAGE_H_
6 #define PRINTING_IMAGE_H_
14 #include "base/check.h"
15 #include "ui/gfx/geometry/size.h"
25 // Lightweight raw-bitmap management. The image, once initialized, is immutable.
26 // The main purpose is testing image contents.
29 // Creates the image from the metafile. Deduces bounds based on bounds in
30 // metafile. If loading fails size().IsEmpty() will be true.
31 explicit Image(const Metafile& metafile);
34 explicit Image(const Image& image);
38 const gfx::Size& size() const { return size_; }
40 // Return a checksum of the image (MD5 over the internal data structure).
41 std::string checksum() const;
44 bool SaveToPng(const base::FilePath& filepath) const;
46 // Returns % of pixels different
47 double PercentageDifferent(const Image& rhs) const;
49 // Returns the 0x0RGB or 0xARGB value of the pixel at the given location.
50 uint32_t Color(uint32_t color) const {
52 return color & 0xFFFFFF; // Strip out A.
57 uint32_t pixel_at(int x, int y) const {
58 DCHECK(x >= 0 && x < size_.width());
59 DCHECK(y >= 0 && y < size_.height());
60 const uint32_t* data = reinterpret_cast<const uint32_t*>(&*data_.begin());
61 const uint32_t* data_row = data + y * row_length_ / sizeof(uint32_t);
62 return Color(data_row[x]);
66 // Construct from metafile. This is kept internal since it's ambiguous what
67 // kind of data is used (png, bmp, metafile etc).
68 Image(const void* data, size_t size);
70 bool LoadPng(const std::string& compressed);
72 // Loads the first page from `metafile`.
73 bool LoadMetafile(const Metafile& metafile);
75 // Pixel dimensions of the image.
78 // Length of a line in bytes.
81 // Actual bitmap data in arrays of RGBAs (so when loaded as uint32_t, it's
83 std::vector<unsigned char> data_;
85 // Flag to signal if the comparison functions should ignore the alpha channel.
86 const bool ignore_alpha_; // Currently always true.
88 // Prevent operator= (this function has no implementation)
89 Image& operator=(const Image& image);
92 } // namespace printing
94 #endif // PRINTING_IMAGE_H_