1 // This may look like C code, but it is really -*- C++ -*-
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
5 // Pixels Implementation
8 #define MAGICKCORE_IMPLEMENTATION 1
9 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
12 #include "Magick++/Include.h"
13 #include <string> // This is here to compile with Visual C++
14 #include "Magick++/Thread.h"
15 #include "Magick++/Exception.h"
16 #include "Magick++/Pixels.h"
24 // Construct pixel view using specified image.
25 Magick::Pixels::Pixels( Magick::Image &image_ )
27 _view(AcquireVirtualCacheView(_image.image(),&_exception)),
33 GetExceptionInfo( &_exception );
36 _image.throwImageException();
40 Magick::Pixels::~Pixels( void )
43 _view = DestroyCacheView( _view );
45 (void) DestroyExceptionInfo( &_exception );
48 // Transfer pixels from the image to the pixel view as defined by
49 // the specified region. Modified pixels may be subsequently
50 // transferred back to the image via sync.
51 Magick::Quantum* Magick::Pixels::get ( const ssize_t x_,
53 const size_t columns_,
61 Quantum* pixels = GetCacheViewAuthenticPixels( _view, x_, y_, columns_, rows_, &_exception);
64 throwException( _exception );
69 // Transfer read-only pixels from the image to the pixel view as
70 // defined by the specified region.
71 const Magick::Quantum* Magick::Pixels::getConst ( const ssize_t x_, const ssize_t y_,
72 const size_t columns_,
80 const Quantum* pixels =
81 GetCacheViewVirtualPixels(_view, x_, y_, columns_, rows_, &_exception );
84 throwException( _exception );
89 // Transfers the image view pixels to the image.
90 void Magick::Pixels::sync ( void )
92 if( !SyncCacheViewAuthenticPixels( _view, &_exception ) )
93 throwException( _exception );
96 // Allocate a pixel view region to store image pixels as defined
97 // by the region rectangle. This area is subsequently transferred
98 // from the pixel view to the image via 'sync'.
99 Magick::Quantum* Magick::Pixels::set ( const ssize_t x_,
101 const size_t columns_,
109 Quantum* pixels = QueueCacheViewAuthenticPixels( _view, x_, y_,
110 columns_, rows_, &_exception );
112 throwException( _exception );
117 // Return pixel colormap index array
119 Magick::void* Magick::Pixels::metacontent ( void )
121 void* pixel_metacontent = GetCacheViewAuthenticMetacontent( _view );
123 if ( !pixel_metacontent )
124 _image.throwImageException();
126 return pixel_metacontent;