Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: printing/image.h

Issue 2835193007: Revert of clean up printing::Image and printing::Metafile (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « printing/emf_win.h ('k') | printing/image.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "printing/printing_export.h" 15 #include "printing/printing_export.h"
16 #include "ui/gfx/geometry/size.h" 16 #include "ui/gfx/geometry/size.h"
17 17
18 namespace base { 18 namespace base {
19 class FilePath; 19 class FilePath;
20 } 20 }
21 21
22 namespace printing { 22 namespace printing {
23 23
24 class Metafile;
25
24 // Lightweight raw-bitmap management. The image, once initialized, is immutable. 26 // Lightweight raw-bitmap management. The image, once initialized, is immutable.
25 // The main purpose is testing image contents. 27 // The main purpose is testing image contents.
26 class PRINTING_EXPORT Image { 28 class PRINTING_EXPORT Image {
27 public: 29 public:
28 // Creates the image from the metafile. Deduces bounds based on bounds in 30 // Creates the image from the metafile. Deduces bounds based on bounds in
29 // metafile. If loading fails size().IsEmpty() will be true. 31 // metafile. If loading fails size().IsEmpty() will be true.
30 Image(const void* metafile_src_buffer, size_t metafile_src_buffer_size); 32 explicit Image(const Metafile& metafile);
31 33
32 Image(const Image& image); 34 // Copy constructor.
33 Image(Image&& image); 35 explicit Image(const Image& image);
34 36
35 ~Image(); 37 ~Image();
36 38
37 const gfx::Size& size() const { 39 const gfx::Size& size() const {
38 return size_; 40 return size_;
39 } 41 }
40 42
41 // Return a checksum of the image (MD5 over the internal data structure). 43 // Return a checksum of the image (MD5 over the internal data structure).
42 std::string checksum() const; 44 std::string checksum() const;
43 45
44 // Save image as PNG. 46 // Save image as PNG.
45 bool SaveToPng(const base::FilePath& filepath) const; 47 bool SaveToPng(const base::FilePath& filepath) const;
46 48
49 // Returns % of pixels different
50 double PercentageDifferent(const Image& rhs) const;
51
52 // Returns the 0x0RGB or 0xARGB value of the pixel at the given location.
53 uint32_t Color(uint32_t color) const {
54 if (ignore_alpha_)
55 return color & 0xFFFFFF; // Strip out A.
56 else
57 return color;
58 }
59
60 uint32_t pixel_at(int x, int y) const {
61 DCHECK(x >= 0 && x < size_.width());
62 DCHECK(y >= 0 && y < size_.height());
63 const uint32_t* data = reinterpret_cast<const uint32_t*>(&*data_.begin());
64 const uint32_t* data_row = data + y * row_length_ / sizeof(uint32_t);
65 return Color(data_row[x]);
66 }
67
47 private: 68 private:
48 bool LoadMetafile(const void* metafile_src_buffer, 69 // Construct from metafile. This is kept internal since it's ambiguous what
49 size_t metafile_src_buffer_size); 70 // kind of data is used (png, bmp, metafile etc).
71 Image(const void* data, size_t size);
72
73 bool LoadPng(const std::string& compressed);
74
75 bool LoadMetafile(const Metafile& metafile);
50 76
51 // Pixel dimensions of the image. 77 // Pixel dimensions of the image.
52 gfx::Size size_; 78 gfx::Size size_;
53 79
54 // Length of a line in bytes. 80 // Length of a line in bytes.
55 int row_length_; 81 int row_length_;
56 82
57 // Actual bitmap data in arrays of RGBAs (so when loaded as uint32_t, it's 83 // Actual bitmap data in arrays of RGBAs (so when loaded as uint32_t, it's
58 // 0xABGR). 84 // 0xABGR).
59 std::vector<unsigned char> data_; 85 std::vector<unsigned char> data_;
60 86
61 // Flag to signal if the comparison functions should ignore the alpha channel. 87 // Flag to signal if the comparison functions should ignore the alpha channel.
62 const bool ignore_alpha_; // Currently always true. 88 const bool ignore_alpha_; // Currently always true.
63 89
64 // Prevent operator= (this function has no implementation) 90 // Prevent operator= (this function has no implementation)
65 Image& operator=(const Image& image); 91 Image& operator=(const Image& image);
66 }; 92 };
67 93
68 } // namespace printing 94 } // namespace printing
69 95
70 #endif // PRINTING_IMAGE_H_ 96 #endif // PRINTING_IMAGE_H_
OLDNEW
« no previous file with comments | « printing/emf_win.h ('k') | printing/image.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698