]> granicus.if.org Git - imagemagick/blob - Magick++/lib/Pixels.cpp
Updated CompositeOperator values.
[imagemagick] / Magick++ / lib / Pixels.cpp
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 <cstring>
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(AcquireVirtualCacheView(_image.image(),&_exception)),
28     _x(0),
29     _y(0),
30     _columns(0),
31     _rows(0)
32 {
33   GetExceptionInfo( &_exception );
34
35   if (!_view)
36     _image.throwImageException();
37 }
38
39 // Destroy pixel view
40 Magick::Pixels::~Pixels( void )
41 {
42   if ( _view )
43     _view = DestroyCacheView( _view );
44   
45   (void) DestroyExceptionInfo( &_exception );
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.
51 Magick::Quantum* Magick::Pixels::get ( const ssize_t x_,
52                                            const ssize_t y_,
53                                            const size_t columns_,
54                                            const size_t rows_ )
55 {
56   _x = x_;
57   _y = y_;
58   _columns = columns_;
59   _rows = rows_;
60
61   Quantum* pixels = GetCacheViewAuthenticPixels( _view, x_, y_, columns_, rows_,  &_exception);
62
63   if ( !pixels )
64     throwException( _exception );
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.
71 const Magick::Quantum* Magick::Pixels::getConst ( const ssize_t x_, const ssize_t y_,
72                                                       const size_t columns_,
73                                                       const size_t rows_ )
74 {
75   _x = x_;
76   _y = y_;
77   _columns = columns_;
78   _rows = rows_;
79
80   const Quantum* pixels =
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'.
99 Magick::Quantum* Magick::Pixels::set ( const ssize_t x_,
100                                            const ssize_t y_,
101                                            const size_t columns_,
102                                            const size_t rows_ )
103 {
104   _x = x_;
105   _y = y_;
106   _columns = columns_;
107   _rows = rows_;
108
109   Quantum* pixels = QueueCacheViewAuthenticPixels( _view, x_, y_,
110                                       columns_, rows_,  &_exception );
111   if ( !pixels )
112     throwException( _exception );
113   
114   return pixels;
115 }
116
117 // Return pixel colormap index array
118 /*
119 Magick::void* Magick::Pixels::metacontent ( void )
120 {
121   void* pixel_metacontent = GetCacheViewAuthenticMetacontent( _view );
122
123   if ( !pixel_metacontent )
124     _image.throwImageException();
125
126   return pixel_metacontent;
127 }
128 */