cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | // This may look like C code, but it is really -*- C++ -*- |
| 2 | // |
| 3 | // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003 |
| 4 | // |
| 5 | // Pixels Implementation |
| 6 | // |
| 7 | |
| 8 | #define MAGICKCORE_IMPLEMENTATION 1 |
| 9 | #define MAGICK_PLUSPLUS_IMPLEMENTATION 1 |
| 10 | |
| 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" |
| 16 | |
| 17 | namespace Magick |
| 18 | { |
| 19 | |
| 20 | |
| 21 | } |
| 22 | |
| 23 | // Construct pixel view using specified image. |
| 24 | Magick::Pixels::Pixels( Magick::Image &image_ ) |
| 25 | : _image(image_), |
| 26 | _view(AcquireCacheView(_image.image())), |
| 27 | _x(0), |
| 28 | _y(0), |
| 29 | _columns(0), |
| 30 | _rows(0) |
| 31 | { |
| 32 | GetExceptionInfo( &_exception ); |
| 33 | |
| 34 | if (!_view) |
| 35 | _image.throwImageException(); |
| 36 | (void) DestroyExceptionInfo( &_exception ); |
| 37 | } |
| 38 | |
| 39 | // Destroy pixel view |
| 40 | Magick::Pixels::~Pixels( void ) |
| 41 | { |
| 42 | if ( _view ) |
| 43 | _view = DestroyCacheView( _view ); |
| 44 | |
| 45 | } |
| 46 | |
| 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 int x_, |
| 51 | const int y_, |
| 52 | const unsigned int columns_, |
| 53 | const unsigned int rows_ ) |
| 54 | { |
| 55 | _x = x_; |
| 56 | _y = y_; |
| 57 | _columns = columns_; |
| 58 | _rows = rows_; |
| 59 | |
| 60 | PixelPacket* pixels = GetCacheViewAuthenticPixels( _view, x_, y_, columns_, rows_, &_exception); |
| 61 | |
| 62 | if ( !pixels ) |
| 63 | throwException( *GetCacheViewException(_view) ); |
| 64 | |
| 65 | return pixels; |
| 66 | } |
| 67 | |
| 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 int x_, const int y_, |
| 71 | const unsigned int columns_, |
| 72 | const unsigned int rows_ ) |
| 73 | { |
| 74 | _x = x_; |
| 75 | _y = y_; |
| 76 | _columns = columns_; |
| 77 | _rows = rows_; |
| 78 | |
| 79 | const PixelPacket* pixels = |
| 80 | GetCacheViewVirtualPixels(_view, x_, y_, columns_, rows_, &_exception ); |
| 81 | |
| 82 | if ( !pixels ) |
| 83 | throwException( _exception ); |
| 84 | |
| 85 | return pixels; |
| 86 | } |
| 87 | |
| 88 | // Transfers the image view pixels to the image. |
| 89 | void Magick::Pixels::sync ( void ) |
| 90 | { |
| 91 | if( !SyncCacheViewAuthenticPixels( _view, &_exception ) ) |
| 92 | throwException( _exception ); |
| 93 | } |
| 94 | |
| 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 int x_, |
| 99 | const int y_, |
| 100 | const unsigned int columns_, |
| 101 | const unsigned int rows_ ) |
| 102 | { |
| 103 | _x = x_; |
| 104 | _y = y_; |
| 105 | _columns = columns_; |
| 106 | _rows = rows_; |
| 107 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 108 | PixelPacket* pixels = QueueCacheViewAuthenticPixels( _view, static_cast<ssize_t>(x_), static_cast<ssize_t>(y_), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 109 | columns_, rows_, &_exception ); |
| 110 | if ( !pixels ) |
| 111 | throwException( _exception ); |
| 112 | |
| 113 | return pixels; |
| 114 | } |
| 115 | |
| 116 | // Return pixel colormap index array |
| 117 | Magick::IndexPacket* Magick::Pixels::indexes ( void ) |
| 118 | { |
| 119 | IndexPacket* pixel_indexes = GetCacheViewAuthenticIndexQueue( _view ); |
| 120 | |
| 121 | if ( !pixel_indexes ) |
| 122 | _image.throwImageException(); |
| 123 | |
| 124 | return pixel_indexes; |
| 125 | } |