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

Side by Side Diff: printing/image.h

Issue 149644: Print only the focused frame. This makes more sense than trying to print all... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/gfx/size.h" 12 #include "base/gfx/size.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "printing/native_metafile.h"
14 15
15 namespace printing { 16 namespace printing {
16 17
17 // Lightweight raw-bitmap management. The image, once initialized, is immuable. 18 // Lightweight raw-bitmap management. The image, once initialized, is immutable.
18 // The main purpose is testing image contents. 19 // The main purpose is testing image contents.
19 class Image { 20 class Image {
20 public: 21 public:
21 // Creates the image from the given filename on disk. Uses extension to 22 // Creates the image from the given filename on disk. Uses extension to
22 // defer file type. PNG and EMF (on Windows) currently supported. 23 // defer file type. PNG and EMF (on Windows) currently supported.
23 // If image loading fails size().IsEmpty() will be true. 24 // If image loading fails size().IsEmpty() will be true.
24 explicit Image(const std::wstring& filename); 25 explicit Image(const std::wstring& filename);
25 26
27 // Creates the image from the metafile. Deduces bounds based on bounds in
28 // metafile. If loading fails size().IsEmpty() will be true.
29 explicit Image(const NativeMetafile& metafile);
30
31 // Copy constructor.
32 explicit Image(const Image& image);
33
26 const gfx::Size& size() const { 34 const gfx::Size& size() const {
27 return size_; 35 return size_;
28 } 36 }
29 37
38 // Return a checksum of the image (MD5 over the internal data structure).
39 std::string checksum() const;
40
30 // Save image as PNG. 41 // Save image as PNG.
31 bool SaveToPng(const std::wstring& filename); 42 bool SaveToPng(const std::wstring& filename) const;
32 43
33 // Returns % of pixels different 44 // Returns % of pixels different
34 double PercentageDifferent(const Image& rhs) const; 45 double PercentageDifferent(const Image& rhs) const;
35 46
36 // Returns the 0x0RGB or 0xARGB value of the pixel at the given location. 47 // Returns the 0x0RGB or 0xARGB value of the pixel at the given location.
37 uint32 Color(uint32 color) const { 48 uint32 Color(uint32 color) const {
38 if (ignore_alpha_) 49 if (ignore_alpha_)
39 return color & 0xFFFFFF; // Strip out A. 50 return color & 0xFFFFFF; // Strip out A.
40 else 51 else
41 return color; 52 return color;
42 } 53 }
43 54
44 uint32 pixel_at(int x, int y) const { 55 uint32 pixel_at(int x, int y) const {
45 DCHECK(x >= 0 && x < size_.width()); 56 DCHECK(x >= 0 && x < size_.width());
46 DCHECK(y >= 0 && y < size_.height()); 57 DCHECK(y >= 0 && y < size_.height());
47 const uint32* data = reinterpret_cast<const uint32*>(&*data_.begin()); 58 const uint32* data = reinterpret_cast<const uint32*>(&*data_.begin());
48 const uint32* data_row = data + y * row_length_ / sizeof(uint32); 59 const uint32* data_row = data + y * row_length_ / sizeof(uint32);
49 return Color(data_row[x]); 60 return Color(data_row[x]);
50 } 61 }
51 62
52 private: 63 private:
64 // Construct from metafile. This is kept internal since it's ambiguous what
65 // kind of data is used (png, bmp, metafile etc).
66 Image(const void* data, size_t size);
67
53 bool LoadPng(const std::string& compressed); 68 bool LoadPng(const std::string& compressed);
54 69
55 bool LoadMetafile(const std::string& data); 70 bool LoadMetafile(const std::string& data);
56 71
72 bool LoadMetafile(const NativeMetafile& metafile);
73
57 // Pixel dimensions of the image. 74 // Pixel dimensions of the image.
58 gfx::Size size_; 75 gfx::Size size_;
59 76
60 // Length of a line in bytes. 77 // Length of a line in bytes.
61 int row_length_; 78 int row_length_;
62 79
63 // Actual bitmap data in arrays of RGBAs (so when loaded as uint32, it's 80 // Actual bitmap data in arrays of RGBAs (so when loaded as uint32, it's
64 // 0xABGR). 81 // 0xABGR).
65 std::vector<unsigned char> data_; 82 std::vector<unsigned char> data_;
66 83
67 // Flag to signal if the comparison functions should ignore the alpha channel. 84 // Flag to signal if the comparison functions should ignore the alpha channel.
68 const bool ignore_alpha_; // Currently always true. 85 const bool ignore_alpha_; // Currently always true.
69 86
70 DISALLOW_EVIL_CONSTRUCTORS(Image); 87 // Prevent operator= (this function has no implementation)
88 Image& operator=(const Image& image);
71 }; 89 };
72 90
73 } // namespace printing 91 } // namespace printing
74 92
75 #endif // PRINTING_IMAGE_H_ 93 #endif // PRINTING_IMAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698