blob: 4007670178909558622464fe38fd3be7da1aeea0 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001// 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
17namespace Magick
18{
19
20
21}
22
23// Construct pixel view using specified image.
24Magick::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
40Magick::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.
50Magick::PixelPacket* Magick::Pixels::get ( const int x_,
51 const int y_,
cristyeaedf062010-05-29 22:36:02 +000052 const size_t columns_,
53 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +000054{
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.
70const Magick::PixelPacket* Magick::Pixels::getConst ( const int x_, const int y_,
cristyeaedf062010-05-29 22:36:02 +000071 const size_t columns_,
72 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +000073{
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.
89void 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'.
98Magick::PixelPacket* Magick::Pixels::set ( const int x_,
99 const int y_,
cristyeaedf062010-05-29 22:36:02 +0000100 const size_t columns_,
101 const size_t rows_ )
cristy3ed852e2009-09-05 21:47:34 +0000102{
103 _x = x_;
104 _y = y_;
105 _columns = columns_;
106 _rows = rows_;
107
cristybb503372010-05-27 20:51:26 +0000108 PixelPacket* pixels = QueueCacheViewAuthenticPixels( _view, static_cast<ssize_t>(x_), static_cast<ssize_t>(y_),
cristy3ed852e2009-09-05 21:47:34 +0000109 columns_, rows_, &_exception );
110 if ( !pixels )
111 throwException( _exception );
112
113 return pixels;
114}
115
116// Return pixel colormap index array
117Magick::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}