Magick++ 7.1.0

Pixels.cpp
Go to the documentation of this file.
1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
4 //
5 // Copyright @ 2013 ImageMagick Studio LLC, a non-profit organization
6 // dedicated to making software imaging solutions freely available.
7 //
8 // Pixels Implementation
9 //
10
11 #define MAGICKCORE_IMPLEMENTATION 1
12 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
13
14 #include <cstring>
15 #include "Magick++/Include.h"
16 #include <string> // This is here to compile with Visual C++
17 #include "Magick++/Thread.h"
18 #include "Magick++/Exception.h"
19 #include "Magick++/Pixels.h"
20
21 Magick::Pixels::Pixels(Magick::Image &image_)
22 : _image(image_),
23 _x(0),
24 _y(0),
25 _columns(0),
26 _rows(0)
27 {
28 GetPPException;
29 _view=AcquireVirtualCacheView(image_.image(),exceptionInfo),
30 ThrowPPException(image_.quiet());
31 }
32
33 Magick::Pixels::~Pixels(void)
34 {
35 if (_view)
36 _view=DestroyCacheView(_view);
37 }
38
39 Magick::Quantum* Magick::Pixels::get(const ssize_t x_,const ssize_t y_,
40 const size_t columns_,const size_t rows_)
41 {
42 _x=x_;
43 _y=y_;
44 _columns=columns_;
45 _rows=rows_;
46
47 GetPPException;
48 Quantum* pixels=GetCacheViewAuthenticPixels(_view,x_,y_,columns_,rows_,
49 exceptionInfo);
50 ThrowPPException(_image.quiet());
51
52 return pixels;
53 }
54
55 const Magick::Quantum* Magick::Pixels::getConst(const ssize_t x_,
56 const ssize_t y_,const size_t columns_,const size_t rows_)
57 {
58 _x=x_;
59 _y=y_;
60 _columns=columns_;
61 _rows=rows_;
62
63 GetPPException;
64 const Quantum* pixels=GetCacheViewVirtualPixels(_view,x_,y_,columns_,rows_,
65 exceptionInfo);
66 ThrowPPException(_image.quiet());
67
68 return pixels;
69 }
70
71 ssize_t Magick::Pixels::offset(PixelChannel channel) const
72 {
73 if (_image.constImage()->channel_map[channel].traits == UndefinedPixelTrait)
74 return -1;
75 return _image.constImage()->channel_map[channel].offset;
76 }
77
78 Magick::Quantum* Magick::Pixels::set(const ssize_t x_,const ssize_t y_,
79 const size_t columns_,const size_t rows_)
80 {
81 _x=x_;
82 _y=y_;
83 _columns=columns_;
84 _rows=rows_;
85
86 GetPPException;
87 Quantum* pixels=QueueCacheViewAuthenticPixels(_view,x_,y_,columns_,rows_,
88 exceptionInfo);
89 ThrowPPException(_image.quiet());
90
91 return pixels;
92 }
93
94 void Magick::Pixels::sync(void)
95 {
96 GetPPException;
97 (void) SyncCacheViewAuthenticPixels(_view,exceptionInfo);
98 ThrowPPException(_image.quiet());
99 }
100
101 // Return pixel meta content
102 void* Magick::Pixels::metacontent(void)
103 {
104 void* pixel_metacontent=GetCacheViewAuthenticMetacontent(_view);
105
106 return pixel_metacontent;
107 }
108
109 Magick::PixelData::PixelData(Magick::Image &image_,std::string map_,
110 const StorageType type_)
111 {
112 init(image_,0,0,image_.columns(),image_.rows(),map_,type_);
113 }
114
115 Magick::PixelData::PixelData(Magick::Image &image_,const ::ssize_t x_,
116 const ::ssize_t y_,const size_t width_,const size_t height_,std::string map_,
117 const StorageType type_)
118 {
119 init(image_,x_,y_,width_,height_,map_,type_);
120 }
121
122 Magick::PixelData::~PixelData(void)
123 {
124 relinquish();
125 }
126
127 const void *Magick::PixelData::data(void) const
128 {
129 return(_data);
130 }
131
132 ::ssize_t Magick::PixelData::length(void) const
133 {
134 return(_length);
135 }
136
137 ::ssize_t Magick::PixelData::size(void) const
138 {
139 return(_size);
140 }
141
142 void Magick::PixelData::init(Magick::Image &image_,const ::ssize_t x_,
143 const ::ssize_t y_,const size_t width_,const size_t height_,
144 std::string map_,const StorageType type_)
145 {
146 size_t
147 size;
148
149 _data=(void *) NULL;
150 _length=0;
151 _size=0;
152 if ((x_ < 0) || (width_ == 0) || (y_ < 0) || (height_ == 0) ||
153 (x_ > (ssize_t) image_.columns()) || ((width_ + x_) > image_.columns())
154 || (y_ > (ssize_t) image_.rows()) || ((height_ + y_) > image_.rows())
155 || (map_.length() == 0))
156 return;
157
158 switch(type_)
159 {
160 case CharPixel:
161 size=sizeof(unsigned char);
162 break;
163 case DoublePixel:
164 size=sizeof(double);
165 break;
166 case FloatPixel:
167 size=sizeof(float);
168 break;
169 case LongPixel:
170 size=sizeof(unsigned int);
171 break;
172 case LongLongPixel:
173 size=sizeof(MagickSizeType);
174 break;
175 case QuantumPixel:
176 size=sizeof(Quantum);
177 break;
178 case ShortPixel:
179 size=sizeof(unsigned short);
180 break;
181 default:
182 throwExceptionExplicit(MagickCore::OptionError,"Invalid type");
183 return;
184 }
185
186 _length=width_*height_*map_.length();
187 _size=_length*size;
188 _data=AcquireMagickMemory(_size);
189
190 GetPPException;
191 MagickCore::ExportImagePixels(image_.image(),x_,y_,width_,height_,
192 map_.c_str(),type_,_data,exceptionInfo);
193 if (exceptionInfo->severity != MagickCore::UndefinedException)
194 relinquish();
195 ThrowPPException(image_.quiet());
196 }
197
198 void Magick::PixelData::relinquish(void) throw()
199 {
200 if (_data != (void *)NULL)
201 _data=RelinquishMagickMemory(_data);
202 _length=0;
203 _size=0;
204 }
Magick::Pixels::get
Quantum * get(const ::ssize_t x_, const ::ssize_t y_, const size_t columns_, const size_t rows_)
Definition: Pixels.cpp:39
Magick::Pixels::getConst
const Quantum * getConst(const ::ssize_t x_, const ::ssize_t y_, const size_t columns_, const size_t rows_)
Definition: Pixels.cpp:55
Magick::Image::quiet
void quiet(const bool quiet_)
Definition: Image.cpp:1316
Magick::PixelData::~PixelData
~PixelData(void)
Definition: Pixels.cpp:122
Magick::Image::image
MagickCore::Image *& image(void)
Definition: Image.cpp:5024
Thread.h
Magick::PixelData::length
::ssize_t length(void) const
Definition: Pixels.cpp:132
Magick::PixelData::data
const void * data(void) const
Definition: Pixels.cpp:127
Magick::Pixels::sync
void sync(void)
Definition: Pixels.cpp:94
Magick::Pixels::Pixels
Pixels(Magick::Image &image_)
Definition: Pixels.cpp:21
Magick::PixelData::size
::ssize_t size(void) const
Definition: Pixels.cpp:137
Magick::Pixels::~Pixels
~Pixels(void)
Definition: Pixels.cpp:33
Magick::throwExceptionExplicit
MagickPPExport void throwExceptionExplicit(const MagickCore::ExceptionType severity_, const char *reason_, const char *description_=(char *) NULL)
Definition: Exception.cpp:808
ThrowPPException
#define ThrowPPException(quiet)
Definition: Include.h:1580
Magick::PixelData::PixelData
PixelData(Magick::Image &image_, std::string map_, const StorageType type_)
Definition: Pixels.cpp:109
Magick::Pixels::set
Quantum * set(const ::ssize_t x_, const ::ssize_t y_, const size_t columns_, const size_t rows_)
Definition: Pixels.cpp:78
Include.h
Magick::Pixels::offset
ssize_t offset(PixelChannel channel) const
Definition: Pixels.cpp:71
Magick::Image::rows
size_t rows(void) const
Definition: Image.cpp:1352
Magick::Image::columns
size_t columns(void) const
Definition: Image.cpp:590
Pixels.h
Magick::Pixels::metacontent
void * metacontent(void)
Definition: Pixels.cpp:102
GetPPException
#define GetPPException
Definition: Include.h:1561
Exception.h
Magick::Image
Definition: Image.h:55