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