summaryrefslogtreecommitdiff
path: root/www/Magick++/Pixels.html
blob: 7a72bcca2418eefa706438898a84e62dbff9fe62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta content="en" name="language">
	<title>Magick::Pixels</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link media="screen" href="../docutils-articles.css" type="text/css" rel="stylesheet">

</head>

<body>

<div class="banner">
<img src="../images/gm-107x76.png" alt="GraphicMagick logo" width="107" height="76" />
<span class="title">GraphicsMagick</span>
<form action="http://www.google.com/search">
  <input type="hidden" name="domains" value="www.graphicsmagick.org" />
  <input type="hidden" name="sitesearch" value="www.graphicsmagick.org" />
<span class="nowrap"><input type="text" name="q" size="25" maxlength="255" />&nbsp;<input type="submit" name="sa" value="Search" /></span>
</form>
</div>


<div class="navmenu">
<ul>
  <li><a href="../index.html">Home</a></li>
  <li><a href="../project.html">Project</a></li>
  <li><a href="../download.html">Download</a></li>
  <li><a href="../README.html">Install</a></li>
  <li><a href="../Hg.html">Source</a></li>
  <li><a href="../NEWS.html">News</a> </li>
  <li><a href="../utilities.html">Utilities</a></li>
  <li><a href="../programming.html">Programming</a></li>
  <li><a href="../reference.html">Reference</a></li>
</ul>
</div>

<div class="document" id="magick-pixels">
<h1 class="title">Magick::Pixels</h1>
<!-- -*- mode: rst -*- -->
<!-- This text is in reStucturedText format, so it may look a bit odd. -->
<!-- See http://docutils.sourceforge.net/rst.html for details. -->
<p>The Pixels class provides efficient access to raw image pixels. Image
pixels (of type <a class="reference external" href="PixelPacket.html">PixelPacket</a>) may be accessed
directly via the Image Pixel Cache. The image pixel cache is a
rectangular window (a view) into the actual image pixels (which may be
in memory, memory-mapped from a disk file, or entirely on
disk). Obtain existing image pixels via get(). Create a new pixel
region using set().</p>
<p>Depending on the capabilities of the operating system, and the
relationship of the window to the image, the pixel cache may be a copy
of the pixels in the selected window, or it may be the actual image
pixels. In any case calling sync() insures that the base image is
updated with the contents of the modified pixel cache. The method
decode()supports copying foreign pixel data formats into the pixel
cache according to the QuantumTypes. The method encode() supports
copying the pixels in the cache to a foreign pixel representation
according to the format specified by QuantumTypes.</p>
<p>Setting a view using the Pixels class does not cause the number of
references to the underlying image to be reduced to one. Therefore, in
order to ensure that only the current generation of the image is
modified, the Image's modifyImage() method should be invoked to reduce
the reference count on the underlying image to one. If this is not
done, then it is possible for a previous generation of the image to be
modified due to the use of reference counting when copying or
constructing an Image.</p>
<p>The PixelPacket* returned by the set and get methods, and the
IndexPacket* returned by the indexes method point to pixel data
managed by the Pixels class. The Pixels class is responsible for
releasing resources associated with the pixel view. This means that
the pointer should never be passed to delete() or free().</p>
<img alt="Figure showing pixel cache access" class="align-center" src="Cache.png" style="width: 254.0px; height: 218.0px;" />
<!-- Probably want bottom alignment for above (but not accepted by -->
<!-- currently installed rst2html.py parser) -->
<p>The pixel view is a small image in which the pixels may be accessed,
addressed, and updated, as shown in the following example, which
produces an image similar to the one on the right (minus lines and
text):</p>
<pre class="literal-block">// Create base image
Image image(Geometry(254,218), &quot;white&quot;);

// Set the image type to TrueColor DirectClass representation.
image.type(TrueColorType);

// Ensure that there is only one reference to underlying image
// If this is not done, then image pixels will not be modified.
image.modifyImage();

// Allocate pixel view
Pixels view(image);

// Set all pixels in region anchored at 38x36, with size 160x230 to green.
unsigned int columns = 196; unsigned int rows = 162;
Color green(&quot;green&quot;);
PixelPacket *pixels = view.get(38,36,columns,rows);
for ( int row = 0; row &lt; rows ; ++row )
for ( int column = 0; column &lt; columns ; ++column )
*pixels++=green;

// Save changes to image.
view.sync();

// Set all pixels in region anchored at 86x72, with size 108x67 to yellow.
columns = 108; rows = 67;
Color yellow(&quot;yellow&quot;);
pixels = view.get(86,72,columns,rows);
for ( int row = 0; row &lt; rows ; ++row )
for ( int column = 0; column &lt; columns ; ++column )
*pixels++=yellow;
view.sync();

// Set pixel at position 108,94 to red
*(view.get(108,94,1,1)) = Color(&quot;red&quot;);

// Save changes to image.
view.sync();</pre>
<p>The following is the definition of the Magick::Pixels class:</p>
<pre class="literal-block">class Pixels
{
public:

  // Construct pixel view using specified image.
  Pixels( Magick::Image &amp;image_ );

  // Destroy pixel view
  ~Pixels( void );

  // Transfer pixels from the image to the pixel view as defined by
  // the specified region. Modified pixels may be subsequently
  // transferred back to the image via sync.
  PixelPacket* get ( const int x_, const int y_,
                     const unsigned int columns_,const  unsigned int rows_ );

  // Transfer read-only pixels from the image to the pixel view as
  // defined by the specified region.
  const PixelPacket* getConst ( const int x_, const int y_,
                                const unsigned int columns_,
                                const unsigned int rows_ );

  // Transfers the image view pixels to the image.
  void sync ( void );

  // Allocate a pixel view region to store image pixels as defined
  // by the region rectangle.  This area is subsequently transferred
  // from the pixel view to the image via sync.
  PixelPacket* set ( const int x_, const int y_,
                     const unsigned int columns_, const unsigned int rows_ );

  // Return pixel colormap index array
  IndexPacket* indexes ( void );

  // Left ordinate of view
  int x ( void ) const;

  // Top ordinate of view
  int y ( void ) const;

  // Width of view
  unsigned int columns ( void ) const;

  // Height of view
  unsigned int rows ( void ) const;

};</pre>
<p>Copyright © Bob Friesenhahn 1999 - 2022</p>
</div>


<hr class="docutils">
<div class="document">
    <p><a href="../Copyright.html">Copyright</a> © GraphicsMagick Group 2002 - 2023<!--SPONSOR_LOGO--></p>
</div>

</div>
</body>
</html>