• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002
4 // Copyright Dirk Lemstra 2014
5 //
6 // Representation of a pixel view.
7 //
8 
9 #if !defined(Magick_Pixels_header)
10 #define Magick_Pixels_header
11 
12 #include "Magick++/Include.h"
13 #include "Magick++/Color.h"
14 #include "Magick++/Image.h"
15 
16 namespace Magick
17 {
18   class MagickPPExport Pixels
19   {
20   public:
21 
22     // Construct pixel view using specified image.
23     Pixels(Magick::Image &image_);
24 
25     // Destroy pixel view
26     ~Pixels(void);
27 
28     // Transfer pixels from the image to the pixel view as defined by
29     // the specified region. Modified pixels may be subsequently
30     // transferred back to the image via sync.
31     Quantum *get(const ::ssize_t x_,const ::ssize_t y_,
32       const size_t columns_,const size_t rows_);
33 
34     // Transfer read-only pixels from the image to the pixel view as
35     // defined by the specified region.
36     const Quantum *getConst(const ::ssize_t x_,const ::ssize_t y_,
37       const size_t columns_,const size_t rows_);
38 
39     // Return pixel metacontent
40     void *metacontent(void);
41 
42     // Returns the offset for the specified channel.
43     ssize_t offset(PixelChannel channel) const;
44 
45     // Allocate a pixel view region to store image pixels as defined
46     // by the region rectangle.  This area is subsequently transferred
47     // from the pixel view to the image via sync.
48     Quantum *set(const ::ssize_t x_,const ::ssize_t y_,const size_t columns_,
49       const size_t rows_ );
50 
51     // Transfers the image view pixels to the image.
52     void sync(void);
53 
54     // Left ordinate of view
55     ::ssize_t x(void) const;
56 
57     // Top ordinate of view
58     ::ssize_t y(void) const;
59 
60     // Width of view
61     size_t columns(void) const;
62 
63     // Height of view
64     size_t rows(void) const;
65 
66   private:
67 
68     // Copying and assigning Pixels is not supported.
69     Pixels(const Pixels& pixels_);
70     const Pixels& operator=(const Pixels& pixels_);
71 
72     Magick::Image             _image;     // Image reference
73     MagickCore::CacheView     *_view;     // Image view handle
74     ::ssize_t                 _x;         // Left ordinate of view
75     ::ssize_t                 _y;         // Top ordinate of view
76     size_t                    _columns;   // Width of view
77     size_t                    _rows;      // Height of view
78 
79   }; // class Pixels
80 
81   class MagickPPExport PixelData
82   {
83   public:
84 
85     // Construct pixel data using specified image
86     PixelData(Magick::Image &image_,std::string map_,const StorageType type_);
87 
88     // Construct pixel data using specified image
89     PixelData(Magick::Image &image_,const ::ssize_t x_,const ::ssize_t y_,
90       const size_t width_,const size_t height_,std::string map_,
91       const StorageType type_);
92 
93     // Destroy pixel data
94     ~PixelData(void);
95 
96     // Pixel data buffer
97     const void *data(void) const;
98 
99     // Length of the buffer
100     ::ssize_t length(void) const;
101 
102     // Size of the buffer in bytes
103     ::ssize_t size(void) const;
104 
105   private:
106 
107     // Copying and assigning PixelData is not supported
108     PixelData(const PixelData& pixels_);
109     const PixelData& operator=(const PixelData& pixels_);
110 
111     void init(Magick::Image &image_,const ::ssize_t x_,const ::ssize_t y_,
112       const size_t width_,const size_t height_,std::string map_,
113       const StorageType type_);
114 
115     void relinquish(void) throw();
116 
117     void      *_data;  // The pixel data
118     ::ssize_t _length; // Length of the data
119     ::ssize_t _size;   // Size of the data
120   }; // class PixelData
121 
122 } // Magick namespace
123 
124 //
125 // Inline methods
126 //
127 
128 // Left ordinate of view
x(void)129 inline ::ssize_t Magick::Pixels::x(void) const
130 {
131   return _x;
132 }
133 
134 // Top ordinate of view
y(void)135 inline ::ssize_t Magick::Pixels::y(void) const
136 {
137   return _y;
138 }
139 
140 // Width of view
columns(void)141 inline size_t Magick::Pixels::columns(void) const
142 {
143   return _columns;
144 }
145 
146 // Height of view
rows(void)147 inline size_t Magick::Pixels::rows(void) const
148 {
149   return _rows;
150 }
151 
152 #endif // Magick_Pixels_header
153