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
3 // found in the LICENSE file.
5 #ifndef PRINTING_IMAGE_H_
6 #define PRINTING_IMAGE_H_
14 #include "base/logging.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 {
42 // Return a checksum of the image (MD5 over the internal data structure).
43 std::string checksum() const;
46 bool SaveToPng(const base::FilePath& filepath) const;
48 // Returns % of pixels different
49 double PercentageDifferent(const Image& rhs) const;
51 // Returns the 0x0RGB or 0xARGB value of the pixel at the given location.
52 uint32_t Color(uint32_t color) const {
54 return color & 0xFFFFFF; // Strip out A.
59 uint32_t pixel_at(int x, int y) const {
60 DCHECK(x >= 0 && x < size_.width());
61 DCHECK(y >= 0 && y < size_.height());
62 const uint32_t* data = reinterpret_cast<const uint32_t*>(&*data_.begin());
63 const uint32_t* data_row = data + y * row_length_ / sizeof(uint32_t);
64 return Color(data_row[x]);
68 // Construct from metafile. This is kept internal since it's ambiguous what
69 // kind of data is used (png, bmp, metafile etc).
70 Image(const void* data, size_t size);
72 bool LoadPng(const std::string& compressed);
74 // Loads the first page from |metafile|.
75 bool LoadMetafile(const Metafile& metafile);
77 // Pixel dimensions of the image.
80 // Length of a line in bytes.
83 // Actual bitmap data in arrays of RGBAs (so when loaded as uint32_t, it's
85 std::vector<unsigned char> data_;
87 // Flag to signal if the comparison functions should ignore the alpha channel.
88 const bool ignore_alpha_; // Currently always true.
90 // Prevent operator= (this function has no implementation)
91 Image& operator=(const Image& image);
94 } // namespace printing
96 #endif // PRINTING_IMAGE_H_