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 | |
cristy | 05065f4 | 2011-09-08 01:11:30 +0000 | [diff] [blame] | 11 | #include <cstring> |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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" |
| 17 | |
| 18 | namespace Magick |
| 19 | { |
| 20 | |
| 21 | |
| 22 | } |
| 23 | |
| 24 | // Construct pixel view using specified image. |
| 25 | Magick::Pixels::Pixels( Magick::Image &image_ ) |
| 26 | : _image(image_), |
| 27 | _view(AcquireCacheView(_image.image())), |
| 28 | _x(0), |
| 29 | _y(0), |
| 30 | _columns(0), |
| 31 | _rows(0) |
| 32 | { |
| 33 | GetExceptionInfo( &_exception ); |
| 34 | |
| 35 | if (!_view) |
| 36 | _image.throwImageException(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | // Destroy pixel view |
| 40 | Magick::Pixels::~Pixels( void ) |
| 41 | { |
| 42 | if ( _view ) |
| 43 | _view = DestroyCacheView( _view ); |
| 44 | |
cristy | 2040ecb | 2010-10-19 01:02:48 +0000 | [diff] [blame] | 45 | (void) DestroyExceptionInfo( &_exception ); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 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. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 51 | Magick::Quantum* Magick::Pixels::get ( const ssize_t x_, |
cristy | d99b096 | 2010-05-29 23:14:26 +0000 | [diff] [blame] | 52 | const ssize_t y_, |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 53 | const size_t columns_, |
| 54 | const size_t rows_ ) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 55 | { |
| 56 | _x = x_; |
| 57 | _y = y_; |
| 58 | _columns = columns_; |
| 59 | _rows = rows_; |
| 60 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 61 | Quantum* pixels = GetCacheViewAuthenticPixels( _view, x_, y_, columns_, rows_, &_exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 62 | |
| 63 | if ( !pixels ) |
cristy | 1f1d637 | 2010-10-19 01:08:11 +0000 | [diff] [blame] | 64 | throwException( _exception ); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 65 | |
| 66 | return pixels; |
| 67 | } |
| 68 | |
| 69 | // Transfer read-only pixels from the image to the pixel view as |
| 70 | // defined by the specified region. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 71 | const Magick::Quantum* Magick::Pixels::getConst ( const ssize_t x_, const ssize_t y_, |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 72 | const size_t columns_, |
| 73 | const size_t rows_ ) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 74 | { |
| 75 | _x = x_; |
| 76 | _y = y_; |
| 77 | _columns = columns_; |
| 78 | _rows = rows_; |
| 79 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 80 | const Quantum* pixels = |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 81 | GetCacheViewVirtualPixels(_view, x_, y_, columns_, rows_, &_exception ); |
| 82 | |
| 83 | if ( !pixels ) |
| 84 | throwException( _exception ); |
| 85 | |
| 86 | return pixels; |
| 87 | } |
| 88 | |
| 89 | // Transfers the image view pixels to the image. |
| 90 | void Magick::Pixels::sync ( void ) |
| 91 | { |
| 92 | if( !SyncCacheViewAuthenticPixels( _view, &_exception ) ) |
| 93 | throwException( _exception ); |
| 94 | } |
| 95 | |
| 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'. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 99 | Magick::Quantum* Magick::Pixels::set ( const ssize_t x_, |
cristy | d99b096 | 2010-05-29 23:14:26 +0000 | [diff] [blame] | 100 | const ssize_t y_, |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 101 | const size_t columns_, |
| 102 | const size_t rows_ ) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 103 | { |
| 104 | _x = x_; |
| 105 | _y = y_; |
| 106 | _columns = columns_; |
| 107 | _rows = rows_; |
| 108 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 109 | Quantum* pixels = QueueCacheViewAuthenticPixels( _view, x_, y_, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 110 | columns_, rows_, &_exception ); |
| 111 | if ( !pixels ) |
| 112 | throwException( _exception ); |
| 113 | |
| 114 | return pixels; |
| 115 | } |
| 116 | |
| 117 | // Return pixel colormap index array |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 118 | /* |
| 119 | Magick::void* Magick::Pixels::metacontent ( void ) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 120 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 121 | void* pixel_metacontent = GetCacheViewAuthenticMetacontent( _view ); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 122 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 123 | if ( !pixel_metacontent ) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 124 | _image.throwImageException(); |
| 125 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 126 | return pixel_metacontent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 127 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 128 | */ |