cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame^] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | |
| 5 | <meta http-equiv="CONTENT-TYPE" content="text/html; charset=ibm437"> |
| 6 | <title>Magick::Pixels Class</title> |
| 7 | |
| 8 | <meta name="GENERATOR" content="OpenOffice.org 1.0 (Win32)"> |
| 9 | |
| 10 | <meta name="AUTHOR" content="Bob Friesenhahn"> |
| 11 | |
| 12 | <meta name="CREATED" content="20020805;15302080"> |
| 13 | |
| 14 | <meta name="CHANGEDBY" content="Bob Friesenhahn"> |
| 15 | |
| 16 | <meta name="CHANGED" content="20020805;15341200"> |
| 17 | |
| 18 | <meta name="DESCRIPTION" content="Class to access raw image pixels."> |
| 19 | |
| 20 | <meta name="KEYWORDS" content="ImageMagick,Pixel,Magick++"> |
| 21 | |
| 22 | <style> |
| 23 | <!-- |
| 24 | TD P { color: #000000 } |
| 25 | H1 { color: #000000 } |
| 26 | P { color: #000000 } |
| 27 | A:link { color: #0000ff } |
| 28 | A:visited { color: #ff0000 } |
| 29 | --> |
| 30 | </style> |
| 31 | </head> |
| 32 | <body lang="en-US" text="#000000" link="#0000ff" vlink="#ff0000" |
| 33 | bgcolor="#ffffff"> |
| 34 | <h1 align="center">Magick::Pixels</h1> |
| 35 | <p>The <i>Pixels</i> class provides efficient access to raw image |
| 36 | pixels. Image pixels (of type <a href="PixelPacket.html"><i>PixelPacket</i></a>) |
| 37 | may be accessed directly via the <i>Image Pixel Cache</i>. The image |
| 38 | pixel cache is a rectangular window (a view) into the actual image |
| 39 | pixels (which may be in memory, memory-mapped from a disk file, or |
| 40 | entirely on disk). Obtain existing image pixels via <i>get()</i>. |
| 41 | Create a new pixel region using <i>set().</i> </p> |
| 42 | <p>Depending on the capabilities of the operating system, and the |
| 43 | relationship of the window to the image, the pixel cache may be a copy |
| 44 | of the pixels in the selected window, or it may be the actual image |
| 45 | pixels. In any case calling <i>sync()</i> insures that the base image |
| 46 | is updated with the contents of the modified pixel cache. The method <i>decode()</i>supports |
| 47 | copying foreign pixel data formats into the pixel cache according to |
| 48 | the <i>QuantumTypes</i>. The method <i>encode()</i> supports copying |
| 49 | the pixels in the cache to a foreign pixel representation according to |
| 50 | the format specified by <i>QuantumTypes</i>. </p> |
| 51 | <p>Setting a view using the Pixels class does not cause the number of |
| 52 | references to the underlying image to be reduced to one. Therefore, in |
| 53 | order to ensure that only the current generation of the image is |
| 54 | modified, the Image's <a href="Image.html#modifyImage">modifyImage()</a> |
| 55 | method should be invoked to reduce the reference count on the underlying |
| 56 | image to one. If this is not done, then it is possible for a previous |
| 57 | generation of the image to be modified due to the use of reference |
| 58 | counting when copying or constructing an Image. </p> |
| 59 | <p>The <i>PixelPacket</i>* returned by the <i>set</i> and <i>get</i> |
| 60 | methods, and the <i>IndexPacket</i>* returned by the <i>indexes</i> |
| 61 | method point to pixel data managed by the <i>Pixels</i> class. The <i>Pixels</i> |
| 62 | class is responsible for releasing resources associated with the pixel |
| 63 | view. This means that the pointer should never be passed to delete() or |
| 64 | free(). </p> |
| 65 | <p style="margin-bottom: 0cm;">The pixel view is a small image in which |
| 66 | the pixels may be accessed, addressed, and updated, as shown in the |
| 67 | following example, which produces an image similar to the one on the |
| 68 | right (minus lines and text): <br> |
| 69 | <br> |
| 70 | </p> |
| 71 | <table width="100%" border="0" cellpadding="2" cellspacing="2"> |
| 72 | <tbody> |
| 73 | <tr> |
| 74 | <td> |
| 75 | <p><font size="2"><font face="Courier New, Courier"><font |
| 76 | color="#000099"> </font><font color="#ff0000">// Create base image</font></font></font> |
| 77 | <br> |
| 78 | <font size="2"><font face="Courier New, Courier"><font |
| 79 | color="#000099"> Image image(Geometry(254,218), "white");</font></font></font> |
| 80 | </p> |
| 81 | |
| 82 | <p><font size="2"></font></p> |
| 83 | <p> <font face="Courier New,Courier"><font color="#ff0000"><font |
| 84 | size="-1"> // Set the image type to TrueColor DirectClass |
| 85 | representation.</font></font></font><br> |
| 86 | <font size="-1"><span |
| 87 | style="color: rgb(0, 0, 153); font-family: courier new,courier,monospace;"> |
| 88 | image.type(TrueColorType</span></font><font size="-1"><span |
| 89 | style="color: rgb(0, 0, 153); font-family: courier new,courier,monospace;">);</span></font><br> |
| 90 | </p> |
| 91 | |
| 92 | <p><font size="2"><font face="Courier New, Courier"> <font |
| 93 | color="#ff0000">// Ensure that there is only one reference to |
| 94 | underlying image</font></font></font> <br> |
| 95 | <font size="2"><font face="Courier New, Courier"><font |
| 96 | color="#ff0000"> // If this is not done, then image pixels will |
| 97 | not be modified.</font></font></font><br> |
| 98 | <font size="2"><font face="Courier New, Courier"> <font |
| 99 | color="#000099">image.modifyImage();<br> |
| 100 | </font></font></font></p> |
| 101 | <p><font size="2"><font face="Courier New, Courier"><font |
| 102 | color="#000099"> </font><font color="#ff0000"> // Allocate pixel |
| 103 | view</font></font></font> <br> |
| 104 | <font size="2"><font face="Courier New, Courier"><font |
| 105 | color="#000099"> Pixels view(image);</font></font></font> </p> |
| 106 | |
| 107 | <p><font size="2"><font face="Courier New, Courier"><font |
| 108 | color="#000099"> </font><font color="#ff0000"> // Set all pixels |
| 109 | in region anchored at 38x36, with size 160x230 to green.</font></font></font> <br> |
| 110 | <font size="2"><font face="Courier New, Courier"><font |
| 111 | color="#000099"> unsigned int columns = 196; unsigned int rows = |
| 112 | 162;</font></font></font> <br> |
| 113 | <font size="2"><font face="Courier New, Courier"><font |
| 114 | color="#000099"> Color green("green");</font></font></font> <br> |
| 115 | <font size="2"><font face="Courier New, Courier"><font |
| 116 | color="#000099"> PixelPacket *pixels = |
| 117 | view.get(38,36,columns,rows);</font></font></font> <br> |
| 118 | <font size="2"><font face="Courier New, Courier"><font |
| 119 | color="#000099"> for ( int row = 0; row < rows ; ++row )</font></font></font> |
| 120 | <br> |
| 121 | <font size="2"><font face="Courier New, Courier"><font |
| 122 | color="#000099"> for ( int column = 0; column < columns ; |
| 123 | ++column )</font></font></font> <br> |
| 124 | <font size="2"><font face="Courier New, Courier"><font |
| 125 | color="#000099"> *pixels++=green;</font></font></font> </p> |
| 126 | <p><font size="2"><font face="Courier New, Courier"><font |
| 127 | color="#000099"> </font><font color="#ff0000"> // Save changes to |
| 128 | image.<br> |
| 129 | </font></font></font><font size="2"></font><font size="2"><font |
| 130 | face="Courier New, Courier"><font color="#000099"> view.sync();</font></font></font> |
| 131 | </p> |
| 132 | |
| 133 | <p><font size="2"><font face="Courier New, Courier"><font |
| 134 | color="#000099"> </font><font color="#ff0000"> // Set all pixels |
| 135 | in region anchored at 86x72, with size 108x67 to yellow.</font></font></font> <br> |
| 136 | <font size="2"><font face="Courier New, Courier"><font |
| 137 | color="#000099"> columns = 108; rows = 67;</font></font></font> <br> |
| 138 | <font size="2"><font face="Courier New, Courier"><font |
| 139 | color="#000099"> Color yellow("yellow");</font></font></font> <br> |
| 140 | <font size="2"><font face="Courier New, Courier"><font |
| 141 | color="#000099"> pixels = view.get(86,72,columns,rows);</font></font></font> <br> |
| 142 | <font size="2"><font face="Courier New, Courier"><font |
| 143 | color="#000099"> for ( int row = 0; row < rows ; ++row )</font></font></font> |
| 144 | <br> |
| 145 | <font size="2"><font face="Courier New, Courier"><font |
| 146 | color="#000099"> for ( int column = 0; column < columns ; |
| 147 | ++column )</font></font></font> <br> |
| 148 | <font size="2"><font face="Courier New, Courier"><font |
| 149 | color="#000099"> *pixels++=yellow;</font></font></font> <br> |
| 150 | <font size="2"><font face="Courier New, Courier"><font |
| 151 | color="#000099"> view.sync();</font></font></font> </p> |
| 152 | |
| 153 | <p><font size="2"><font face="Courier New, Courier"><font |
| 154 | color="#000099"> </font><font color="#ff0000"> // Set pixel at |
| 155 | position 108,94 to red</font></font></font> <br> |
| 156 | <font size="2"><font face="Courier New, Courier"><font |
| 157 | color="#000099"> *(view.get(108,94,1,1)) = Color("red");</font></font></font> </p> |
| 158 | <p><font size="2"><font face="Courier New, Courier"><font |
| 159 | color="#000099"> </font><font color="#ff0000"> // Save changes to |
| 160 | image.<br> |
| 161 | </font></font></font><font size="2"><font |
| 162 | face="Courier New, Courier"><font color="#000099"> view.sync();<br> |
| 163 | <br> |
| 164 | </font></font></font></p> |
| 165 | </td> |
| 166 | <td> |
| 167 | <p><img src="Cache.png" name="Graphic1" align="bottom" width="254" |
| 168 | height="218" border="0"></p> |
| 169 | </td> |
| 170 | </tr> |
| 171 | </tbody> |
| 172 | </table> |
| 173 | <p style="margin-bottom: 0cm;"><i>Pixels</i> supports the following |
| 174 | methods: <br> |
| 175 | <br> |
| 176 | </p> |
| 177 | <p align="center" style="margin-bottom: 0cm;"><b>Pixel Cache Methods</b></p> |
| 178 | <table width="100%" border="1" cellpadding="2" cellspacing="2"> |
| 179 | <tbody> |
| 180 | <tr> |
| 181 | <td> |
| 182 | <p align="center"><b>Method</b></p> |
| 183 | </td> |
| 184 | <td> |
| 185 | <p align="center"><b>Returns</b></p> |
| 186 | </td> |
| 187 | <td> |
| 188 | <p align="center"><b>Signature</b></p> |
| 189 | </td> |
| 190 | <td> |
| 191 | <p align="center"><b>Description</b></p> |
| 192 | </td> |
| 193 | </tr> |
| 194 | <tr> |
| 195 | <td> |
| 196 | <p align="center"><a name="get"></a><font size="2">get</font></p> |
| 197 | </td> |
| 198 | <td> |
| 199 | <p><font size="2"><a href="PixelPacket.html">PixelPacket</a>*</font></p> |
| 200 | </td> |
| 201 | <td> |
| 202 | <p><font size="2">const int x_, const int y_, const unsigned |
| 203 | const int columns_, const unsigned int rows_</font></p> |
| 204 | </td> |
| 205 | <td> |
| 206 | <p><font size="2">Transfers read-write pixels from the image to |
| 207 | the pixel cache as defined by the specified rectangular region. |
| 208 | Modified pixels may be subsequently transferred back to the image |
| 209 | via <i>sync</i>. The value returned is intended for pixel access |
| 210 | only. It should never be deallocated.</font></p> |
| 211 | </td> |
| 212 | </tr> |
| 213 | <tr> |
| 214 | <td> |
| 215 | <p align="center"><a name="getConst"></a><font size="2">getConst</font></p> |
| 216 | </td> |
| 217 | <td> |
| 218 | <p><font size="2">const <a href="PixelPacket.html">PixelPacket</a>*</font></p> |
| 219 | </td> |
| 220 | <td> |
| 221 | <p><font size="2">const int x_, const int y_, const unsigned int |
| 222 | columns_, const unsigned int rows_</font></p> |
| 223 | </td> |
| 224 | <td> |
| 225 | <p><font size="2">Transfers read-only pixels from the image to |
| 226 | the pixel cache as defined by the specified rectangular region.</font></p> |
| 227 | </td> |
| 228 | </tr> |
| 229 | <tr> |
| 230 | <td> |
| 231 | <p align="center"><a name="set"></a><font size="2">set</font></p> |
| 232 | </td> |
| 233 | <td> |
| 234 | <p><font size="2"><a href="PixelPacket.html">PixelPacket</a>*</font></p> |
| 235 | </td> |
| 236 | <td> |
| 237 | <p><font size="2">const int x_, const int y_, const unsigned int |
| 238 | columns_, const unsigned int rows_</font></p> |
| 239 | </td> |
| 240 | <td> |
| 241 | <p><font size="2">Allocates a pixel cache region to store image |
| 242 | pixels as defined by the region rectangle. This area is |
| 243 | subsequently transferred from the pixel cache to the image via <i>sync</i>. |
| 244 | The value returned is intended for pixel access only. It should |
| 245 | never be deallocated.</font></p> |
| 246 | </td> |
| 247 | </tr> |
| 248 | <tr> |
| 249 | <td> |
| 250 | <p align="center"><a name="sync"></a><font size="2">sync</font></p> |
| 251 | </td> |
| 252 | <td> |
| 253 | <p><font size="2">void</font></p> |
| 254 | </td> |
| 255 | <td> |
| 256 | <p><font size="2">void</font></p> |
| 257 | </td> |
| 258 | <td> |
| 259 | <p><font size="2">Transfers the image cache pixels to the image.</font></p> |
| 260 | </td> |
| 261 | </tr> |
| 262 | <tr> |
| 263 | <td> |
| 264 | <p align="center"><a name="indexes"></a><font size="2">indexes</font></p> |
| 265 | </td> |
| 266 | <td> |
| 267 | <p><font size="2">IndexPacket*</font></p> |
| 268 | </td> |
| 269 | <td> |
| 270 | <p><font size="2">void</font></p> |
| 271 | </td> |
| 272 | <td> |
| 273 | <p><font size="2">Returns the PsuedoColor pixel indexes |
| 274 | corresponding to the pixel region defined by the last <a href="#get">get</a> |
| 275 | , <a href="#getConst">getConst</a>, or <a href="#set">set</a> |
| 276 | call. Only valid for PseudoColor and CMYKA images. The pixel |
| 277 | indexes (an array of type <i>IndexPacket</i>, which is typedef <i>Quantum</i>, |
| 278 | which is itself typedef <i>unsigned char</i>, or <i>unsigned short</i>, |
| 279 | depending on the value of the <i>QuantumDepth </i>define) provide |
| 280 | the <span lang="en-US">colormap</span> index (see <a |
| 281 | href="Image.html#colorMap">colorMap</a>) for each pixel in the |
| 282 | image. For CMYKA images, the indexes represent the black |
| 283 | channel. The value returned is intended for pixel access only. It |
| 284 | should never be deallocated.</font></p> |
| 285 | </td> |
| 286 | </tr> |
| 287 | <tr> |
| 288 | <td> |
| 289 | <p align="center"><a name="x"></a><font size="2">x</font></p> |
| 290 | </td> |
| 291 | <td> |
| 292 | <p><font size="2">int</font></p> |
| 293 | </td> |
| 294 | <td> |
| 295 | <p><font size="2">void</font></p> |
| 296 | </td> |
| 297 | <td> |
| 298 | <p><font size="2">Left ordinate of view</font></p> |
| 299 | </td> |
| 300 | </tr> |
| 301 | <tr> |
| 302 | <td> |
| 303 | <p align="center"><a name="y"></a><font size="2">y</font></p> |
| 304 | </td> |
| 305 | <td> |
| 306 | <p><font size="2">int</font></p> |
| 307 | </td> |
| 308 | <td> |
| 309 | <p><font size="2">void</font></p> |
| 310 | </td> |
| 311 | <td> |
| 312 | <p><font size="2">Top ordinate of view</font></p> |
| 313 | </td> |
| 314 | </tr> |
| 315 | <tr> |
| 316 | <td> |
| 317 | <p align="center"><a name="columns"></a><font size="2">columns</font></p> |
| 318 | </td> |
| 319 | <td> |
| 320 | <p><font size="2">unsigned int</font></p> |
| 321 | </td> |
| 322 | <td> |
| 323 | <p><font size="2">void</font></p> |
| 324 | </td> |
| 325 | <td> |
| 326 | <p><font size="2">Width of view</font></p> |
| 327 | </td> |
| 328 | </tr> |
| 329 | <tr> |
| 330 | <td> |
| 331 | <p align="center"><a name="rows"></a><font size="2">rows</font></p> |
| 332 | </td> |
| 333 | <td> |
| 334 | <p><font size="2">unsigned int</font></p> |
| 335 | </td> |
| 336 | <td> |
| 337 | <p><font size="2">void</font></p> |
| 338 | </td> |
| 339 | <td> |
| 340 | <p><font size="2">Height of view</font></p> |
| 341 | </td> |
| 342 | </tr> |
| 343 | </tbody> |
| 344 | </table> |
| 345 | <p><br> |
| 346 | <br> |
| 347 | </p> |
| 348 | </body> |
| 349 | </html> |