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_
13 #include "base/check.h"
14 #include "ui/gfx/geometry/size.h"
18 // Lightweight raw-bitmap management. The image, once initialized, is immutable.
19 // The only purpose is testing image contents.
22 // Creates an image from raw ARGB pixel data, 32 bits per pixel.
23 Image(gfx::Size size, int line_stride, std::vector<unsigned char> buffer);
25 Image(const Image& image);
26 Image& operator=(const Image& image) = delete;
30 bool operator==(const Image& other) const;
32 const gfx::Size& size() const { return size_; }
34 // Returns the 0x0RGB value of the pixel at the given location.
35 uint32_t Color(uint32_t color) const {
36 return color & 0xFFFFFF; // Strip out alpha channel.
39 uint32_t pixel_at(int x, int y) const {
40 DCHECK(x >= 0 && x < size_.width());
41 DCHECK(y >= 0 && y < size_.height());
42 const uint32_t* data = reinterpret_cast<const uint32_t*>(&*data_.begin());
43 const uint32_t* data_row = data + y * row_length_ / sizeof(uint32_t);
44 return Color(data_row[x]);
48 // Pixel dimensions of the image.
49 const gfx::Size size_;
51 // Length of a line in bytes.
52 const int row_length_;
54 // Actual bitmap data in arrays of RGBAs (so when loaded as uint32_t, it's
56 const std::vector<unsigned char> data_;
59 } // namespace printing
61 #endif // PRINTING_IMAGE_H_