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
11 #include "Magick++/Include.h"
12 #include <string> // This is here to compile with Visual C++
13 #include "Magick++/Thread.h"
14 #include "Magick++/Exception.h"
15 #include "Magick++/Pixels.h"
23 // Construct pixel view using specified image.
24 Magick::Pixels::Pixels( Magick::Image &image_ )
26 _view(AcquireCacheView(_image.image())),
32 GetExceptionInfo( &_exception );
35 _image.throwImageException();
39 Magick::Pixels::~Pixels( void )
42 _view = DestroyCacheView( _view );
44 (void) DestroyExceptionInfo( &_exception );
47 // Transfer pixels from the image to the pixel view as defined by
48 // the specified region. Modified pixels may be subsequently
49 // transferred back to the image via sync.
50 Magick::PixelPacket* Magick::Pixels::get ( const ssize_t x_,
52 const size_t columns_,
60 PixelPacket* pixels = GetCacheViewAuthenticPixels( _view, x_, y_, columns_, rows_, &_exception);
63 throwException( _exception );
68 // Transfer read-only pixels from the image to the pixel view as
69 // defined by the specified region.
70 const Magick::PixelPacket* Magick::Pixels::getConst ( const ssize_t x_, const ssize_t y_,
71 const size_t columns_,
79 const PixelPacket* pixels =
80 GetCacheViewVirtualPixels(_view, x_, y_, columns_, rows_, &_exception );
83 throwException( _exception );
88 // Transfers the image view pixels to the image.
89 void Magick::Pixels::sync ( void )
91 if( !SyncCacheViewAuthenticPixels( _view, &_exception ) )
92 throwException( _exception );
95 // Allocate a pixel view region to store image pixels as defined
96 // by the region rectangle. This area is subsequently transferred
97 // from the pixel view to the image via 'sync'.
98 Magick::PixelPacket* Magick::Pixels::set ( const ssize_t x_,
100 const size_t columns_,
108 PixelPacket* pixels = QueueCacheViewAuthenticPixels( _view, x_, y_,
109 columns_, rows_, &_exception );
111 throwException( _exception );
116 // Return pixel colormap index array
117 Magick::IndexPacket* Magick::Pixels::indexes ( void )
119 IndexPacket* pixel_indexes = GetCacheViewAuthenticIndexQueue( _view );
121 if ( !pixel_indexes )
122 _image.throwImageException();
124 return pixel_indexes;