]> granicus.if.org Git - imagemagick/blob - Magick++/lib/Pixels.cpp
(no commit message)
[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 "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 }
37
38 // Destroy pixel view
39 Magick::Pixels::~Pixels( void )
40 {
41   if ( _view )
42     _view = DestroyCacheView( _view );
43   
44   (void) DestroyExceptionInfo( &_exception );
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 ssize_t x_,
51                                            const ssize_t y_,
52                                            const size_t columns_,
53                                            const size_t 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( _exception );
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 ssize_t x_, const ssize_t y_,
71                                                       const size_t columns_,
72                                                       const size_t 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 ssize_t x_,
99                                            const ssize_t y_,
100                                            const size_t columns_,
101                                            const size_t rows_ )
102 {
103   _x = x_;
104   _y = y_;
105   _columns = columns_;
106   _rows = rows_;
107
108   PixelPacket* pixels = QueueCacheViewAuthenticPixels( _view, x_, y_,
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 }