cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % PPPP IIIII X X EEEEE L % |
| 7 | % P P I X X E L % |
| 8 | % PPPP I X EEE L % |
| 9 | % P I X X E L % |
| 10 | % P IIIII X X EEEEE LLLLL % |
| 11 | % % |
| 12 | % MagickCore Methods to Import/Export Pixels % |
| 13 | % % |
| 14 | % Software Design % |
| 15 | % John Cristy % |
| 16 | % October 1998 % |
| 17 | % % |
| 18 | % % |
cristy | 45ef08f | 2012-12-07 13:13:34 +0000 | [diff] [blame] | 19 | % Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 20 | % dedicated to making software imaging solutions freely available. % |
| 21 | % % |
| 22 | % You may not use this file except in compliance with the License. You may % |
| 23 | % obtain a copy of the License at % |
| 24 | % % |
| 25 | % http://www.imagemagick.org/script/license.php % |
| 26 | % % |
| 27 | % Unless required by applicable law or agreed to in writing, software % |
| 28 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 29 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 30 | % See the License for the specific language governing permissions and % |
| 31 | % limitations under the License. % |
| 32 | % % |
| 33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 34 | % |
| 35 | % |
| 36 | */ |
| 37 | |
| 38 | /* |
| 39 | Include declarations. |
| 40 | */ |
| 41 | #include "MagickCore/studio.h" |
| 42 | #include "MagickCore/property.h" |
| 43 | #include "MagickCore/blob.h" |
| 44 | #include "MagickCore/blob-private.h" |
cristy | 322d07d | 2012-03-18 21:17:23 +0000 | [diff] [blame] | 45 | #include "MagickCore/cache-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 46 | #include "MagickCore/color-private.h" |
| 47 | #include "MagickCore/draw.h" |
| 48 | #include "MagickCore/exception.h" |
| 49 | #include "MagickCore/exception-private.h" |
| 50 | #include "MagickCore/cache.h" |
| 51 | #include "MagickCore/constitute.h" |
| 52 | #include "MagickCore/delegate.h" |
| 53 | #include "MagickCore/geometry.h" |
| 54 | #include "MagickCore/image-private.h" |
| 55 | #include "MagickCore/list.h" |
| 56 | #include "MagickCore/magick.h" |
| 57 | #include "MagickCore/memory_.h" |
| 58 | #include "MagickCore/monitor.h" |
| 59 | #include "MagickCore/option.h" |
| 60 | #include "MagickCore/pixel.h" |
| 61 | #include "MagickCore/pixel-accessor.h" |
cristy | 380a11c | 2012-06-02 15:15:22 +0000 | [diff] [blame] | 62 | #include "MagickCore/pixel-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 63 | #include "MagickCore/quantum.h" |
| 64 | #include "MagickCore/quantum-private.h" |
| 65 | #include "MagickCore/resource_.h" |
| 66 | #include "MagickCore/semaphore.h" |
| 67 | #include "MagickCore/statistic.h" |
| 68 | #include "MagickCore/stream.h" |
| 69 | #include "MagickCore/string_.h" |
| 70 | #include "MagickCore/transform.h" |
| 71 | #include "MagickCore/utility.h" |
| 72 | |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 73 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 74 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 75 | % % |
| 76 | % % |
| 77 | % % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 78 | + A c q u i r e P i x e l C h a n n e l M a p % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 79 | % % |
| 80 | % % |
| 81 | % % |
| 82 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 83 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 84 | % AcquirePixelChannelMap() acquires a pixel component map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 85 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 86 | % The format of the AcquirePixelChannelMap() method is: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 87 | % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 88 | % PixelChannelMap *AcquirePixelChannelMap(void) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 89 | % |
| 90 | */ |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 91 | MagickExport PixelChannelMap *AcquirePixelChannelMap(void) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 92 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 93 | PixelChannelMap |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 94 | *channel_map; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 95 | |
| 96 | register ssize_t |
| 97 | i; |
| 98 | |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 99 | channel_map=(PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels, |
| 100 | sizeof(*channel_map)); |
| 101 | if (channel_map == (PixelChannelMap *) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 102 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 103 | (void) ResetMagickMemory(channel_map,0,MaxPixelChannels*sizeof(*channel_map)); |
| 104 | for (i=0; i < MaxPixelChannels; i++) |
| 105 | channel_map[i].channel=(PixelChannel) i; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 106 | return(channel_map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /* |
| 110 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 111 | % % |
| 112 | % % |
| 113 | % % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 114 | + C l o n e P i x e l C h a n n e l M a p % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 115 | % % |
| 116 | % % |
| 117 | % % |
| 118 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 119 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 120 | % ClonePixelChannelMap() clones a pixel component map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 121 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 122 | % The format of the ClonePixelChannelMap() method is: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 123 | % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 124 | % PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 125 | % |
| 126 | % A description of each parameter follows: |
| 127 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 128 | % o channel_map: the pixel component map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 129 | % |
| 130 | */ |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 131 | MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 132 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 133 | PixelChannelMap |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 134 | *clone_map; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 135 | |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 136 | assert(channel_map != (PixelChannelMap *) NULL); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 137 | clone_map=AcquirePixelChannelMap(); |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 138 | if (clone_map == (PixelChannelMap *) NULL) |
| 139 | return((PixelChannelMap *) NULL); |
| 140 | (void) CopyMagickMemory(clone_map,channel_map,MaxPixelChannels* |
| 141 | sizeof(*channel_map)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 142 | return(clone_map); |
| 143 | } |
| 144 | |
| 145 | /* |
| 146 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 147 | % % |
| 148 | % % |
| 149 | % % |
| 150 | + C l o n e P i x e l I n f o % |
| 151 | % % |
| 152 | % % |
| 153 | % % |
| 154 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 155 | % |
| 156 | % ClonePixelInfo() makes a duplicate of the given pixel info structure, or if |
| 157 | % pixel info is NULL, a new one. |
| 158 | % |
| 159 | % The format of the ClonePixelInfo method is: |
| 160 | % |
| 161 | % PixelInfo *ClonePixelInfo(const PixelInfo *pixel_info) |
| 162 | % |
| 163 | % A description of each parameter follows: |
| 164 | % |
| 165 | % o pixel_info: the pixel info. |
| 166 | % |
| 167 | */ |
| 168 | MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel) |
| 169 | { |
| 170 | PixelInfo |
| 171 | *pixel_info; |
| 172 | |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 173 | pixel_info=(PixelInfo *) AcquireQuantumMemory(1,sizeof(*pixel_info)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 174 | if (pixel_info == (PixelInfo *) NULL) |
| 175 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 176 | *pixel_info=(*pixel); |
| 177 | return(pixel_info); |
| 178 | } |
| 179 | |
| 180 | /* |
| 181 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 182 | % % |
| 183 | % % |
| 184 | % % |
cristy | c8aff84 | 2012-12-24 16:59:46 +0000 | [diff] [blame] | 185 | % D e c o d e P i x e l G a m m a % |
| 186 | % % |
| 187 | % % |
| 188 | % % |
| 189 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 190 | % |
| 191 | % DecodePixelGamma() applies the expansive power-law nonlinearity to the pixel. |
| 192 | % |
cristy | 3506059 | 2013-04-17 14:10:20 +0000 | [diff] [blame] | 193 | % The format of the DecodePixelGamma method is: |
cristy | c8aff84 | 2012-12-24 16:59:46 +0000 | [diff] [blame] | 194 | % |
| 195 | % double DecodePixelGamma(const MagickRealType pixel) |
| 196 | % |
| 197 | % A description of each parameter follows: |
| 198 | % |
| 199 | % o pixel: the pixel. |
| 200 | % |
| 201 | */ |
cristy | c29824a | 2013-04-17 21:52:56 +0000 | [diff] [blame] | 202 | |
| 203 | static inline double DecodeGamma(const double x) |
| 204 | { |
| 205 | div_t |
| 206 | quotient; |
| 207 | |
| 208 | double |
| 209 | p, |
| 210 | term[9]; |
| 211 | |
| 212 | int |
| 213 | exponent; |
| 214 | |
| 215 | static const double coefficient[] = /* terms for x^(7/5), x=1.5 */ |
| 216 | { |
| 217 | 1.7917488588043277509, |
| 218 | 0.82045614371976854984, |
| 219 | 0.027694100686325412819, |
| 220 | -0.00094244335181762134018, |
| 221 | 0.000064355540911469709545, |
| 222 | -5.7224404636060757485e-06, |
| 223 | 5.8767669437311184313e-07, |
| 224 | -6.6139920053589721168e-08, |
| 225 | 7.9323242696227458163e-09 |
| 226 | }; |
| 227 | |
| 228 | static const double powers_of_two[] = /* (2^x)^(7/5) */ |
| 229 | { |
| 230 | 1.0, |
| 231 | 2.6390158215457883983, |
| 232 | 6.9644045063689921093, |
| 233 | 1.8379173679952558018e+01, |
| 234 | 4.8502930128332728543e+01 |
| 235 | }; |
| 236 | |
| 237 | /* |
| 238 | Compute x^2.4 == x*x^(7/5) == pow(x,2.4). |
| 239 | */ |
| 240 | term[0]=1.0; |
| 241 | term[1]=4.0*frexp(x,&exponent)-3.0; |
| 242 | term[2]=2.0*term[1]*term[1]-term[0]; |
| 243 | term[3]=2.0*term[1]*term[2]-term[1]; |
| 244 | term[4]=2.0*term[1]*term[3]-term[2]; |
| 245 | term[5]=2.0*term[1]*term[4]-term[3]; |
| 246 | term[6]=2.0*term[1]*term[5]-term[4]; |
| 247 | term[7]=2.0*term[1]*term[6]-term[5]; |
| 248 | term[8]=2.0*term[1]*term[7]-term[6]; |
| 249 | p=coefficient[0]*term[0]+coefficient[1]*term[1]+coefficient[2]*term[2]+ |
| 250 | coefficient[3]*term[3]+coefficient[4]*term[4]+coefficient[5]*term[5]+ |
| 251 | coefficient[6]*term[6]+coefficient[7]*term[7]+coefficient[8]*term[8]; |
| 252 | quotient=div(exponent-1,5); |
| 253 | if (quotient.rem < 0) |
| 254 | { |
| 255 | quotient.quot-=1; |
| 256 | quotient.rem+=5; |
| 257 | } |
| 258 | return(x*ldexp(powers_of_two[quotient.rem]*p,7*quotient.quot)); |
| 259 | } |
| 260 | |
cristy | c8aff84 | 2012-12-24 16:59:46 +0000 | [diff] [blame] | 261 | MagickExport MagickRealType DecodePixelGamma(const MagickRealType pixel) |
| 262 | { |
| 263 | if (pixel <= (0.0404482362771076*QuantumRange)) |
| 264 | return(pixel/12.92f); |
cristy | c29824a | 2013-04-17 21:52:56 +0000 | [diff] [blame] | 265 | return((MagickRealType) (QuantumRange*DecodeGamma((double) (QuantumScale* |
| 266 | pixel+0.055)/1.055))); |
cristy | c8aff84 | 2012-12-24 16:59:46 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /* |
| 270 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 271 | % % |
| 272 | % % |
| 273 | % % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 274 | + D e s t r o y P i x e l C h a n n e l M a p % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 275 | % % |
| 276 | % % |
| 277 | % % |
| 278 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 279 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 280 | % DestroyPixelChannelMap() deallocates memory associated with the pixel |
| 281 | % channel map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 282 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 283 | % The format of the DestroyPixelChannelMap() method is: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 284 | % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 285 | % PixelChannelMap *DestroyPixelChannelMap(PixelChannelMap *channel_map) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 286 | % |
| 287 | % A description of each parameter follows: |
| 288 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 289 | % o channel_map: the pixel component map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 290 | % |
| 291 | */ |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 292 | MagickExport PixelChannelMap *DestroyPixelChannelMap( |
| 293 | PixelChannelMap *channel_map) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 294 | { |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 295 | assert(channel_map != (PixelChannelMap *) NULL); |
| 296 | channel_map=(PixelChannelMap *) RelinquishMagickMemory(channel_map); |
| 297 | return((PixelChannelMap *) RelinquishMagickMemory(channel_map)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /* |
| 301 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 302 | % % |
| 303 | % % |
| 304 | % % |
cristy | c8aff84 | 2012-12-24 16:59:46 +0000 | [diff] [blame] | 305 | + E n c o d e P i x e l G a m m a % |
| 306 | % % |
| 307 | % % |
| 308 | % % |
| 309 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 310 | % |
| 311 | % EncodePixelGamma() cancels any nonlinearity in the pixel. |
| 312 | % |
cristy | 3506059 | 2013-04-17 14:10:20 +0000 | [diff] [blame] | 313 | % The format of the EncodePixelGamma method is: |
cristy | c8aff84 | 2012-12-24 16:59:46 +0000 | [diff] [blame] | 314 | % |
| 315 | % MagickRealType EncodePixelGamma(const double MagickRealType) |
| 316 | % |
| 317 | % A description of each parameter follows: |
| 318 | % |
| 319 | % o pixel: the pixel. |
| 320 | % |
| 321 | */ |
cristy | c29824a | 2013-04-17 21:52:56 +0000 | [diff] [blame] | 322 | |
| 323 | static inline double EncodeGamma(const double x) |
| 324 | { |
| 325 | div_t |
| 326 | quotient; |
| 327 | |
| 328 | double |
| 329 | p, |
| 330 | term[9]; |
| 331 | |
| 332 | int |
| 333 | exponent; |
| 334 | |
| 335 | static const double coefficient[] = /* Chebychevi poly: x^(5/12), x=1.5 */ |
| 336 | { |
| 337 | 1.1758200232996901923, |
| 338 | 0.16665763094889061230, |
| 339 | -0.0083154894939042125035, |
| 340 | 0.00075187976780420279038, |
| 341 | -0.000083240178519391795367, |
| 342 | 0.000010229209410070008679, |
| 343 | -1.3400466409860246e-06, |
| 344 | 1.8333422241635376682e-07, |
| 345 | -2.5878596761348859722e-08 |
| 346 | }; |
| 347 | |
| 348 | static const double powers_of_two[] = /* (2^N)^(5/12) */ |
| 349 | { |
| 350 | 1.0, |
| 351 | 1.3348398541700343678, |
| 352 | 1.7817974362806785482, |
| 353 | 2.3784142300054420538, |
| 354 | 3.1748021039363991669, |
| 355 | 4.2378523774371812394, |
| 356 | 5.6568542494923805819, |
| 357 | 7.5509945014535482244, |
| 358 | 1.0079368399158985525e1, |
| 359 | 1.3454342644059433809e1, |
| 360 | 1.7959392772949968275e1, |
| 361 | 2.3972913230026907883e1 |
| 362 | }; |
| 363 | |
| 364 | /* |
| 365 | Compute x^(1/2.4) == x^(5/12) == pow(x,1.0/2.4). |
| 366 | */ |
| 367 | term[0]=1.0; |
| 368 | term[1]=4.0*frexp(x,&exponent)-3.0; |
| 369 | term[2]=2.0*term[1]*term[1]-term[0]; |
| 370 | term[3]=2.0*term[1]*term[2]-term[1]; |
| 371 | term[4]=2.0*term[1]*term[3]-term[2]; |
| 372 | term[5]=2.0*term[1]*term[4]-term[3]; |
| 373 | term[6]=2.0*term[1]*term[5]-term[4]; |
| 374 | term[7]=2.0*term[1]*term[6]-term[5]; |
| 375 | term[8]=2.0*term[1]*term[7]-term[6]; |
| 376 | p=coefficient[0]*term[0]+coefficient[1]*term[1]+coefficient[2]*term[2]+ |
| 377 | coefficient[3]*term[3]+coefficient[4]*term[4]+coefficient[5]*term[5]+ |
| 378 | coefficient[6]*term[6]+coefficient[7]*term[7]+coefficient[8]*term[8]; |
| 379 | quotient=div(exponent-1,12); |
| 380 | if (quotient.rem < 0) |
| 381 | { |
| 382 | quotient.quot-=1; |
| 383 | quotient.rem+=12; |
| 384 | } |
| 385 | return(ldexp(powers_of_two[quotient.rem]*p,5*quotient.quot)); |
| 386 | } |
| 387 | |
cristy | c8aff84 | 2012-12-24 16:59:46 +0000 | [diff] [blame] | 388 | MagickExport MagickRealType EncodePixelGamma(const MagickRealType pixel) |
| 389 | { |
| 390 | if (pixel <= (0.0031306684425005883*QuantumRange)) |
| 391 | return(12.92f*pixel); |
cristy | c29824a | 2013-04-17 21:52:56 +0000 | [diff] [blame] | 392 | return((MagickRealType) QuantumRange*(1.055*EncodeGamma((double) QuantumScale* |
cristy | 2a13aa6 | 2013-04-18 19:15:28 +0000 | [diff] [blame] | 393 | pixel)-0.055)); |
cristy | c8aff84 | 2012-12-24 16:59:46 +0000 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | /* |
| 397 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 398 | % % |
| 399 | % % |
| 400 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 401 | % E x p o r t I m a g e P i x e l s % |
| 402 | % % |
| 403 | % % |
| 404 | % % |
| 405 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 406 | % |
| 407 | % ExportImagePixels() extracts pixel data from an image and returns it to you. |
| 408 | % The method returns MagickTrue on success otherwise MagickFalse if an error is |
cristy | b5a45a3 | 2012-01-10 13:31:13 +0000 | [diff] [blame] | 409 | % encountered. The data is returned as char, short int, Quantum, unsigned int, |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 410 | % unsigned long long, float, or double in the order specified by map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 411 | % |
| 412 | % Suppose you want to extract the first scanline of a 640x480 image as |
| 413 | % character data in red-green-blue order: |
| 414 | % |
| 415 | % ExportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels,exception); |
| 416 | % |
| 417 | % The format of the ExportImagePixels method is: |
| 418 | % |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 419 | % MagickBooleanType ExportImagePixels(const Image *image,const ssize_t x, |
| 420 | % const ssize_t y,const size_t width,const size_t height, |
| 421 | % const char *map,const StorageType type,void *pixels, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 422 | % ExceptionInfo *exception) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 423 | % |
| 424 | % A description of each parameter follows: |
| 425 | % |
| 426 | % o image: the image. |
| 427 | % |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 428 | % o x,y,width,height: These values define the perimeter |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 429 | % of a region of pixels you want to extract. |
| 430 | % |
| 431 | % o map: This string reflects the expected ordering of the pixel array. |
| 432 | % It can be any combination or order of R = red, G = green, B = blue, |
| 433 | % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan, |
| 434 | % Y = yellow, M = magenta, K = black, I = intensity (for grayscale), |
| 435 | % P = pad. |
| 436 | % |
| 437 | % o type: Define the data type of the pixels. Float and double types are |
| 438 | % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 439 | % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *), |
cristy | ff6834e | 2012-01-10 03:00:25 +0000 | [diff] [blame] | 440 | % LongPixel (unsigned int *), LongLongPixel (unsigned long long *), |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 441 | % QuantumPixel (Quantum *), or ShortPixel (unsigned short *). |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 442 | % |
| 443 | % o pixels: This array of values contain the pixel components as defined by |
| 444 | % map and type. You must preallocate this array where the expected |
| 445 | % length varies depending on the values of width, height, map, and type. |
| 446 | % |
| 447 | % o exception: return any errors or warnings in this structure. |
| 448 | % |
| 449 | */ |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 450 | |
cristy | 2dc655d | 2012-07-05 13:16:28 +0000 | [diff] [blame] | 451 | static void ExportCharPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 452 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 453 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 454 | { |
| 455 | register const Quantum |
| 456 | *restrict p; |
| 457 | |
| 458 | register ssize_t |
| 459 | x; |
| 460 | |
| 461 | register unsigned char |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 462 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 463 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 464 | size_t |
| 465 | length; |
| 466 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 467 | ssize_t |
| 468 | y; |
| 469 | |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 470 | q=(unsigned char *) pixels; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 471 | if (LocaleCompare(map,"BGR") == 0) |
| 472 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 473 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 474 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 475 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 476 | if (p == (const Quantum *) NULL) |
| 477 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 478 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 479 | { |
| 480 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 481 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 482 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 483 | p+=GetPixelChannels(image); |
| 484 | } |
| 485 | } |
| 486 | return; |
| 487 | } |
| 488 | if (LocaleCompare(map,"BGRA") == 0) |
| 489 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 490 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 491 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 492 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 493 | if (p == (const Quantum *) NULL) |
| 494 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 495 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 496 | { |
| 497 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 498 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 499 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 500 | *q++=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
| 501 | p+=GetPixelChannels(image); |
| 502 | } |
| 503 | } |
| 504 | return; |
| 505 | } |
| 506 | if (LocaleCompare(map,"BGRP") == 0) |
| 507 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 508 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 509 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 510 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 511 | if (p == (const Quantum *) NULL) |
| 512 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 513 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 514 | { |
| 515 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 516 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 517 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 518 | *q++=ScaleQuantumToChar((Quantum) 0); |
| 519 | p+=GetPixelChannels(image); |
| 520 | } |
| 521 | } |
| 522 | return; |
| 523 | } |
| 524 | if (LocaleCompare(map,"I") == 0) |
| 525 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 526 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 527 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 528 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 529 | if (p == (const Quantum *) NULL) |
| 530 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 531 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 532 | { |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 533 | *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p))); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 534 | p+=GetPixelChannels(image); |
| 535 | } |
| 536 | } |
| 537 | return; |
| 538 | } |
| 539 | if (LocaleCompare(map,"RGB") == 0) |
| 540 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 541 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 542 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 543 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 544 | if (p == (const Quantum *) NULL) |
| 545 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 546 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 547 | { |
| 548 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 549 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 550 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 551 | p+=GetPixelChannels(image); |
| 552 | } |
| 553 | } |
| 554 | return; |
| 555 | } |
| 556 | if (LocaleCompare(map,"RGBA") == 0) |
| 557 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 558 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 559 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 560 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 561 | if (p == (const Quantum *) NULL) |
| 562 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 563 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 564 | { |
| 565 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 566 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 567 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 568 | *q++=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
| 569 | p+=GetPixelChannels(image); |
| 570 | } |
| 571 | } |
| 572 | return; |
| 573 | } |
| 574 | if (LocaleCompare(map,"RGBP") == 0) |
| 575 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 576 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 577 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 578 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 579 | if (p == (const Quantum *) NULL) |
| 580 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 581 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 582 | { |
| 583 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 584 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 585 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 586 | *q++=ScaleQuantumToChar((Quantum) 0); |
| 587 | p+=GetPixelChannels(image); |
| 588 | } |
| 589 | } |
| 590 | return; |
| 591 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 592 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 593 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 594 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 595 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 596 | if (p == (const Quantum *) NULL) |
| 597 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 598 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 599 | { |
| 600 | register ssize_t |
| 601 | i; |
| 602 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 603 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 604 | { |
| 605 | *q=0; |
| 606 | switch (quantum_map[i]) |
| 607 | { |
| 608 | case RedQuantum: |
| 609 | case CyanQuantum: |
| 610 | { |
| 611 | *q=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 612 | break; |
| 613 | } |
| 614 | case GreenQuantum: |
| 615 | case MagentaQuantum: |
| 616 | { |
| 617 | *q=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 618 | break; |
| 619 | } |
| 620 | case BlueQuantum: |
| 621 | case YellowQuantum: |
| 622 | { |
| 623 | *q=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 624 | break; |
| 625 | } |
| 626 | case AlphaQuantum: |
| 627 | { |
| 628 | *q=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
| 629 | break; |
| 630 | } |
| 631 | case OpacityQuantum: |
| 632 | { |
| 633 | *q=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
| 634 | break; |
| 635 | } |
| 636 | case BlackQuantum: |
| 637 | { |
| 638 | if (image->colorspace == CMYKColorspace) |
| 639 | *q=ScaleQuantumToChar(GetPixelBlack(image,p)); |
| 640 | break; |
| 641 | } |
| 642 | case IndexQuantum: |
| 643 | { |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 644 | *q=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p))); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 645 | break; |
| 646 | } |
| 647 | default: |
| 648 | break; |
| 649 | } |
| 650 | q++; |
| 651 | } |
| 652 | p+=GetPixelChannels(image); |
| 653 | } |
| 654 | } |
| 655 | } |
| 656 | |
cristy | 2dc655d | 2012-07-05 13:16:28 +0000 | [diff] [blame] | 657 | static void ExportDoublePixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 658 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 659 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 660 | { |
| 661 | register const Quantum |
| 662 | *restrict p; |
| 663 | |
| 664 | register double |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 665 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 666 | |
| 667 | register ssize_t |
| 668 | x; |
| 669 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 670 | size_t |
| 671 | length; |
| 672 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 673 | ssize_t |
| 674 | y; |
| 675 | |
| 676 | q=(double *) pixels; |
| 677 | if (LocaleCompare(map,"BGR") == 0) |
| 678 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 679 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 680 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 681 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 682 | if (p == (const Quantum *) NULL) |
| 683 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 684 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 685 | { |
| 686 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 687 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 688 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 689 | p+=GetPixelChannels(image); |
| 690 | } |
| 691 | } |
| 692 | return; |
| 693 | } |
| 694 | if (LocaleCompare(map,"BGRA") == 0) |
| 695 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 696 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 697 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 698 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 699 | if (p == (const Quantum *) NULL) |
| 700 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 701 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 702 | { |
| 703 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 704 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 705 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 706 | *q++=(double) (QuantumScale*GetPixelAlpha(image,p)); |
| 707 | p+=GetPixelChannels(image); |
| 708 | } |
| 709 | } |
| 710 | return; |
| 711 | } |
| 712 | if (LocaleCompare(map,"BGRP") == 0) |
| 713 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 714 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 715 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 716 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 717 | if (p == (const Quantum *) NULL) |
| 718 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 719 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 720 | { |
| 721 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 722 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 723 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 724 | *q++=0.0; |
| 725 | p+=GetPixelChannels(image); |
| 726 | } |
| 727 | } |
| 728 | return; |
| 729 | } |
| 730 | if (LocaleCompare(map,"I") == 0) |
| 731 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 732 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 733 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 734 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 735 | if (p == (const Quantum *) NULL) |
| 736 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 737 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 738 | { |
| 739 | *q++=(double) (QuantumScale*GetPixelIntensity(image,p)); |
| 740 | p+=GetPixelChannels(image); |
| 741 | } |
| 742 | } |
| 743 | return; |
| 744 | } |
| 745 | if (LocaleCompare(map,"RGB") == 0) |
| 746 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 747 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 748 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 749 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 750 | if (p == (const Quantum *) NULL) |
| 751 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 752 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 753 | { |
| 754 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 755 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 756 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 757 | p+=GetPixelChannels(image); |
| 758 | } |
| 759 | } |
| 760 | return; |
| 761 | } |
| 762 | if (LocaleCompare(map,"RGBA") == 0) |
| 763 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 764 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 765 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 766 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 767 | if (p == (const Quantum *) NULL) |
| 768 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 769 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 770 | { |
| 771 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 772 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 773 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 774 | *q++=(double) (QuantumScale*GetPixelAlpha(image,p)); |
| 775 | p+=GetPixelChannels(image); |
| 776 | } |
| 777 | } |
| 778 | return; |
| 779 | } |
| 780 | if (LocaleCompare(map,"RGBP") == 0) |
| 781 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 782 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 783 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 784 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 785 | if (p == (const Quantum *) NULL) |
| 786 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 787 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 788 | { |
| 789 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 790 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 791 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 792 | *q++=0.0; |
| 793 | p+=GetPixelChannels(image); |
| 794 | } |
| 795 | } |
| 796 | return; |
| 797 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 798 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 799 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 800 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 801 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 802 | if (p == (const Quantum *) NULL) |
| 803 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 804 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 805 | { |
| 806 | register ssize_t |
| 807 | i; |
| 808 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 809 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 810 | { |
| 811 | *q=0; |
| 812 | switch (quantum_map[i]) |
| 813 | { |
| 814 | case RedQuantum: |
| 815 | case CyanQuantum: |
| 816 | { |
| 817 | *q=(double) (QuantumScale*GetPixelRed(image,p)); |
| 818 | break; |
| 819 | } |
| 820 | case GreenQuantum: |
| 821 | case MagentaQuantum: |
| 822 | { |
| 823 | *q=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 824 | break; |
| 825 | } |
| 826 | case BlueQuantum: |
| 827 | case YellowQuantum: |
| 828 | { |
| 829 | *q=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 830 | break; |
| 831 | } |
| 832 | case AlphaQuantum: |
| 833 | { |
| 834 | *q=(double) (QuantumScale*GetPixelAlpha(image,p)); |
| 835 | break; |
| 836 | } |
| 837 | case OpacityQuantum: |
| 838 | { |
| 839 | *q=(double) (QuantumScale*GetPixelAlpha(image,p)); |
| 840 | break; |
| 841 | } |
| 842 | case BlackQuantum: |
| 843 | { |
| 844 | if (image->colorspace == CMYKColorspace) |
| 845 | *q=(double) (QuantumScale* |
| 846 | GetPixelBlack(image,p)); |
| 847 | break; |
| 848 | } |
| 849 | case IndexQuantum: |
| 850 | { |
| 851 | *q=(double) (QuantumScale*GetPixelIntensity(image,p)); |
| 852 | break; |
| 853 | } |
| 854 | default: |
| 855 | *q=0; |
| 856 | } |
| 857 | q++; |
| 858 | } |
| 859 | p+=GetPixelChannels(image); |
| 860 | } |
| 861 | } |
| 862 | } |
| 863 | |
cristy | 2dc655d | 2012-07-05 13:16:28 +0000 | [diff] [blame] | 864 | static void ExportFloatPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 865 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 866 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 867 | { |
| 868 | register const Quantum |
| 869 | *restrict p; |
| 870 | |
| 871 | register float |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 872 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 873 | |
| 874 | register ssize_t |
| 875 | x; |
| 876 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 877 | size_t |
| 878 | length; |
| 879 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 880 | ssize_t |
| 881 | y; |
| 882 | |
| 883 | q=(float *) pixels; |
| 884 | if (LocaleCompare(map,"BGR") == 0) |
| 885 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 886 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 887 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 888 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 889 | if (p == (const Quantum *) NULL) |
| 890 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 891 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 892 | { |
| 893 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 894 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 895 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 896 | p+=GetPixelChannels(image); |
| 897 | } |
| 898 | } |
| 899 | return; |
| 900 | } |
| 901 | if (LocaleCompare(map,"BGRA") == 0) |
| 902 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 903 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 904 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 905 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 906 | if (p == (const Quantum *) NULL) |
| 907 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 908 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 909 | { |
| 910 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 911 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 912 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 913 | *q++=(float) (QuantumScale*GetPixelAlpha(image,p)); |
| 914 | p+=GetPixelChannels(image); |
| 915 | } |
| 916 | } |
| 917 | return; |
| 918 | } |
| 919 | if (LocaleCompare(map,"BGRP") == 0) |
| 920 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 921 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 922 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 923 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 924 | if (p == (const Quantum *) NULL) |
| 925 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 926 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 927 | { |
| 928 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 929 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 930 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 931 | *q++=0.0; |
| 932 | p+=GetPixelChannels(image); |
| 933 | } |
| 934 | } |
| 935 | return; |
| 936 | } |
| 937 | if (LocaleCompare(map,"I") == 0) |
| 938 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 939 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 940 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 941 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 942 | if (p == (const Quantum *) NULL) |
| 943 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 944 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 945 | { |
| 946 | *q++=(float) (QuantumScale*GetPixelIntensity(image,p)); |
| 947 | p+=GetPixelChannels(image); |
| 948 | } |
| 949 | } |
| 950 | return; |
| 951 | } |
| 952 | if (LocaleCompare(map,"RGB") == 0) |
| 953 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 954 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 955 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 956 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 957 | if (p == (const Quantum *) NULL) |
| 958 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 959 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 960 | { |
| 961 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 962 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 963 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 964 | p+=GetPixelChannels(image); |
| 965 | } |
| 966 | } |
| 967 | return; |
| 968 | } |
| 969 | if (LocaleCompare(map,"RGBA") == 0) |
| 970 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 971 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 972 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 973 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 974 | if (p == (const Quantum *) NULL) |
| 975 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 976 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 977 | { |
| 978 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 979 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 980 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 981 | *q++=(float) (QuantumScale*GetPixelAlpha(image,p)); |
| 982 | p+=GetPixelChannels(image); |
| 983 | } |
| 984 | } |
| 985 | return; |
| 986 | } |
| 987 | if (LocaleCompare(map,"RGBP") == 0) |
| 988 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 989 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 990 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 991 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 992 | if (p == (const Quantum *) NULL) |
| 993 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 994 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 995 | { |
| 996 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 997 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 998 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 999 | *q++=0.0; |
| 1000 | p+=GetPixelChannels(image); |
| 1001 | } |
| 1002 | } |
| 1003 | return; |
| 1004 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1005 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1006 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1007 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1008 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1009 | if (p == (const Quantum *) NULL) |
| 1010 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1011 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1012 | { |
| 1013 | register ssize_t |
| 1014 | i; |
| 1015 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1016 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1017 | { |
| 1018 | *q=0; |
| 1019 | switch (quantum_map[i]) |
| 1020 | { |
| 1021 | case RedQuantum: |
| 1022 | case CyanQuantum: |
| 1023 | { |
| 1024 | *q=(float) (QuantumScale*GetPixelRed(image,p)); |
| 1025 | break; |
| 1026 | } |
| 1027 | case GreenQuantum: |
| 1028 | case MagentaQuantum: |
| 1029 | { |
| 1030 | *q=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 1031 | break; |
| 1032 | } |
| 1033 | case BlueQuantum: |
| 1034 | case YellowQuantum: |
| 1035 | { |
| 1036 | *q=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 1037 | break; |
| 1038 | } |
| 1039 | case AlphaQuantum: |
| 1040 | { |
| 1041 | *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p)))); |
| 1042 | break; |
| 1043 | } |
| 1044 | case OpacityQuantum: |
| 1045 | { |
| 1046 | *q=(float) (QuantumScale*GetPixelAlpha(image,p)); |
| 1047 | break; |
| 1048 | } |
| 1049 | case BlackQuantum: |
| 1050 | { |
| 1051 | if (image->colorspace == CMYKColorspace) |
| 1052 | *q=(float) (QuantumScale* GetPixelBlack(image,p)); |
| 1053 | break; |
| 1054 | } |
| 1055 | case IndexQuantum: |
| 1056 | { |
| 1057 | *q=(float) (QuantumScale*GetPixelIntensity(image,p)); |
| 1058 | break; |
| 1059 | } |
| 1060 | default: |
| 1061 | *q=0; |
| 1062 | } |
| 1063 | q++; |
| 1064 | } |
| 1065 | p+=GetPixelChannels(image); |
| 1066 | } |
| 1067 | } |
| 1068 | } |
| 1069 | |
cristy | 2dc655d | 2012-07-05 13:16:28 +0000 | [diff] [blame] | 1070 | static void ExportLongPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 1071 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 1072 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1073 | { |
| 1074 | register const Quantum |
| 1075 | *restrict p; |
| 1076 | |
| 1077 | register ssize_t |
| 1078 | x; |
| 1079 | |
| 1080 | register unsigned int |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 1081 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1082 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1083 | size_t |
| 1084 | length; |
| 1085 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1086 | ssize_t |
| 1087 | y; |
| 1088 | |
| 1089 | q=(unsigned int *) pixels; |
| 1090 | if (LocaleCompare(map,"BGR") == 0) |
| 1091 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1092 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1093 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1094 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1095 | if (p == (const Quantum *) NULL) |
| 1096 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1097 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1098 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1099 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1100 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1101 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1102 | p+=GetPixelChannels(image); |
| 1103 | } |
| 1104 | } |
| 1105 | return; |
| 1106 | } |
| 1107 | if (LocaleCompare(map,"BGRA") == 0) |
| 1108 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1109 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1110 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1111 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1112 | if (p == (const Quantum *) NULL) |
| 1113 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1114 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1115 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1116 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1117 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1118 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1119 | *q++=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1120 | p+=GetPixelChannels(image); |
| 1121 | } |
| 1122 | } |
| 1123 | return; |
| 1124 | } |
| 1125 | if (LocaleCompare(map,"BGRP") == 0) |
| 1126 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1127 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1128 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1129 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1130 | if (p == (const Quantum *) NULL) |
| 1131 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1132 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1133 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1134 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1135 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1136 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1137 | *q++=0; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1138 | p+=GetPixelChannels(image); |
| 1139 | } |
| 1140 | } |
| 1141 | return; |
| 1142 | } |
| 1143 | if (LocaleCompare(map,"I") == 0) |
| 1144 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1145 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1146 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1147 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1148 | if (p == (const Quantum *) NULL) |
| 1149 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1150 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1151 | { |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 1152 | *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p))); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1153 | p+=GetPixelChannels(image); |
| 1154 | } |
| 1155 | } |
| 1156 | return; |
| 1157 | } |
| 1158 | if (LocaleCompare(map,"RGB") == 0) |
| 1159 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1160 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1161 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1162 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1163 | if (p == (const Quantum *) NULL) |
| 1164 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1165 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1166 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1167 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1168 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1169 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1170 | p+=GetPixelChannels(image); |
| 1171 | } |
| 1172 | } |
| 1173 | return; |
| 1174 | } |
| 1175 | if (LocaleCompare(map,"RGBA") == 0) |
| 1176 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1177 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1178 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1179 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1180 | if (p == (const Quantum *) NULL) |
| 1181 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1182 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1183 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1184 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1185 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1186 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1187 | *q++=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1188 | p+=GetPixelChannels(image); |
| 1189 | } |
| 1190 | } |
| 1191 | return; |
| 1192 | } |
| 1193 | if (LocaleCompare(map,"RGBP") == 0) |
| 1194 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1195 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1196 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1197 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1198 | if (p == (const Quantum *) NULL) |
| 1199 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1200 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1201 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1202 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1203 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1204 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1205 | *q++=0; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1206 | p+=GetPixelChannels(image); |
| 1207 | } |
| 1208 | } |
| 1209 | return; |
| 1210 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1211 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1212 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1213 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1214 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1215 | if (p == (const Quantum *) NULL) |
| 1216 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1217 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1218 | { |
| 1219 | register ssize_t |
| 1220 | i; |
| 1221 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1222 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1223 | { |
| 1224 | *q=0; |
| 1225 | switch (quantum_map[i]) |
| 1226 | { |
| 1227 | case RedQuantum: |
| 1228 | case CyanQuantum: |
| 1229 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1230 | *q=ScaleQuantumToLong(GetPixelRed(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1231 | break; |
| 1232 | } |
| 1233 | case GreenQuantum: |
| 1234 | case MagentaQuantum: |
| 1235 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1236 | *q=ScaleQuantumToLong(GetPixelGreen(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1237 | break; |
| 1238 | } |
| 1239 | case BlueQuantum: |
| 1240 | case YellowQuantum: |
| 1241 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1242 | *q=ScaleQuantumToLong(GetPixelBlue(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1243 | break; |
| 1244 | } |
| 1245 | case AlphaQuantum: |
| 1246 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1247 | *q=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1248 | break; |
| 1249 | } |
| 1250 | case OpacityQuantum: |
| 1251 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1252 | *q=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1253 | break; |
| 1254 | } |
| 1255 | case BlackQuantum: |
| 1256 | { |
| 1257 | if (image->colorspace == CMYKColorspace) |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1258 | *q=ScaleQuantumToLong(GetPixelBlack(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1259 | break; |
| 1260 | } |
| 1261 | case IndexQuantum: |
| 1262 | { |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 1263 | *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p))); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1264 | break; |
| 1265 | } |
| 1266 | default: |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1267 | break; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1268 | } |
| 1269 | q++; |
| 1270 | } |
| 1271 | p+=GetPixelChannels(image); |
| 1272 | } |
| 1273 | } |
| 1274 | } |
| 1275 | |
cristy | 2dc655d | 2012-07-05 13:16:28 +0000 | [diff] [blame] | 1276 | static void ExportLongLongPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 1277 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 1278 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1279 | { |
| 1280 | register const Quantum |
| 1281 | *restrict p; |
| 1282 | |
| 1283 | register ssize_t |
| 1284 | x; |
| 1285 | |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1286 | register MagickSizeType |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 1287 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1288 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1289 | size_t |
| 1290 | length; |
| 1291 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1292 | ssize_t |
| 1293 | y; |
| 1294 | |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1295 | q=(MagickSizeType *) pixels; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1296 | if (LocaleCompare(map,"BGR") == 0) |
| 1297 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1298 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1299 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1300 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1301 | if (p == (const Quantum *) NULL) |
| 1302 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1303 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1304 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1305 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
| 1306 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
| 1307 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1308 | p+=GetPixelChannels(image); |
| 1309 | } |
| 1310 | } |
| 1311 | return; |
| 1312 | } |
| 1313 | if (LocaleCompare(map,"BGRA") == 0) |
| 1314 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1315 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1316 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1317 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1318 | if (p == (const Quantum *) NULL) |
| 1319 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1320 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1321 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1322 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
| 1323 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
| 1324 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
| 1325 | *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1326 | p+=GetPixelChannels(image); |
| 1327 | } |
| 1328 | } |
| 1329 | return; |
| 1330 | } |
| 1331 | if (LocaleCompare(map,"BGRP") == 0) |
| 1332 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1333 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1334 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1335 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1336 | if (p == (const Quantum *) NULL) |
| 1337 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1338 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1339 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1340 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
| 1341 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
| 1342 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1343 | *q++=0; |
| 1344 | p+=GetPixelChannels(image); |
| 1345 | } |
| 1346 | } |
| 1347 | return; |
| 1348 | } |
| 1349 | if (LocaleCompare(map,"I") == 0) |
| 1350 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1351 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1352 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1353 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1354 | if (p == (const Quantum *) NULL) |
| 1355 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1356 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1357 | { |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 1358 | *q++=ScaleQuantumToLongLong(ClampToQuantum(GetPixelIntensity(image,p))); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1359 | p+=GetPixelChannels(image); |
| 1360 | } |
| 1361 | } |
| 1362 | return; |
| 1363 | } |
| 1364 | if (LocaleCompare(map,"RGB") == 0) |
| 1365 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1366 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1367 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1368 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1369 | if (p == (const Quantum *) NULL) |
| 1370 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1371 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1372 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1373 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
| 1374 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
| 1375 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1376 | p+=GetPixelChannels(image); |
| 1377 | } |
| 1378 | } |
| 1379 | return; |
| 1380 | } |
| 1381 | if (LocaleCompare(map,"RGBA") == 0) |
| 1382 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1383 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1384 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1385 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1386 | if (p == (const Quantum *) NULL) |
| 1387 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1388 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1389 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1390 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
| 1391 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
| 1392 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
| 1393 | *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1394 | p+=GetPixelChannels(image); |
| 1395 | } |
| 1396 | } |
| 1397 | return; |
| 1398 | } |
| 1399 | if (LocaleCompare(map,"RGBP") == 0) |
| 1400 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1401 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1402 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1403 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1404 | if (p == (const Quantum *) NULL) |
| 1405 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1406 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1407 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1408 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
| 1409 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
| 1410 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1411 | *q++=0; |
| 1412 | p+=GetPixelChannels(image); |
| 1413 | } |
| 1414 | } |
| 1415 | return; |
| 1416 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1417 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1418 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1419 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1420 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1421 | if (p == (const Quantum *) NULL) |
| 1422 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1423 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1424 | { |
| 1425 | register ssize_t |
| 1426 | i; |
| 1427 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1428 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1429 | { |
| 1430 | *q=0; |
| 1431 | switch (quantum_map[i]) |
| 1432 | { |
| 1433 | case RedQuantum: |
| 1434 | case CyanQuantum: |
| 1435 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1436 | *q=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1437 | break; |
| 1438 | } |
| 1439 | case GreenQuantum: |
| 1440 | case MagentaQuantum: |
| 1441 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1442 | *q=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1443 | break; |
| 1444 | } |
| 1445 | case BlueQuantum: |
| 1446 | case YellowQuantum: |
| 1447 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1448 | *q=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1449 | break; |
| 1450 | } |
| 1451 | case AlphaQuantum: |
| 1452 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1453 | *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1454 | break; |
| 1455 | } |
| 1456 | case OpacityQuantum: |
| 1457 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1458 | *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1459 | break; |
| 1460 | } |
| 1461 | case BlackQuantum: |
| 1462 | { |
| 1463 | if (image->colorspace == CMYKColorspace) |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1464 | *q=ScaleQuantumToLongLong(GetPixelBlack(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1465 | break; |
| 1466 | } |
| 1467 | case IndexQuantum: |
| 1468 | { |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 1469 | *q=ScaleQuantumToLongLong(ClampToQuantum(GetPixelIntensity(image,p))); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1470 | break; |
| 1471 | } |
| 1472 | default: |
| 1473 | break; |
| 1474 | } |
| 1475 | q++; |
| 1476 | } |
| 1477 | p+=GetPixelChannels(image); |
| 1478 | } |
| 1479 | } |
| 1480 | } |
| 1481 | |
cristy | 2dc655d | 2012-07-05 13:16:28 +0000 | [diff] [blame] | 1482 | static void ExportQuantumPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 1483 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 1484 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1485 | { |
| 1486 | register const Quantum |
| 1487 | *restrict p; |
| 1488 | |
| 1489 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 1490 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1491 | |
| 1492 | register ssize_t |
| 1493 | x; |
| 1494 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1495 | size_t |
| 1496 | length; |
| 1497 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1498 | ssize_t |
| 1499 | y; |
| 1500 | |
| 1501 | q=(Quantum *) pixels; |
| 1502 | if (LocaleCompare(map,"BGR") == 0) |
| 1503 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1504 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1505 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1506 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1507 | if (p == (const Quantum *) NULL) |
| 1508 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1509 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1510 | { |
| 1511 | *q++=GetPixelBlue(image,p); |
| 1512 | *q++=GetPixelGreen(image,p); |
| 1513 | *q++=GetPixelRed(image,p); |
| 1514 | p+=GetPixelChannels(image); |
| 1515 | } |
| 1516 | } |
| 1517 | return; |
| 1518 | } |
| 1519 | if (LocaleCompare(map,"BGRA") == 0) |
| 1520 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1521 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1522 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1523 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1524 | if (p == (const Quantum *) NULL) |
| 1525 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1526 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1527 | { |
| 1528 | *q++=GetPixelBlue(image,p); |
| 1529 | *q++=GetPixelGreen(image,p); |
| 1530 | *q++=GetPixelRed(image,p); |
| 1531 | *q++=(Quantum) (GetPixelAlpha(image,p)); |
| 1532 | p+=GetPixelChannels(image); |
| 1533 | } |
| 1534 | } |
| 1535 | return; |
| 1536 | } |
| 1537 | if (LocaleCompare(map,"BGRP") == 0) |
| 1538 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1539 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1540 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1541 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1542 | if (p == (const Quantum *) NULL) |
| 1543 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1544 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1545 | { |
| 1546 | *q++=GetPixelBlue(image,p); |
| 1547 | *q++=GetPixelGreen(image,p); |
| 1548 | *q++=GetPixelRed(image,p); |
| 1549 | *q++=(Quantum) 0; |
| 1550 | p+=GetPixelChannels(image); |
| 1551 | } |
| 1552 | } |
| 1553 | return; |
| 1554 | } |
| 1555 | if (LocaleCompare(map,"I") == 0) |
| 1556 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1557 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1558 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1559 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1560 | if (p == (const Quantum *) NULL) |
| 1561 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1562 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1563 | { |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 1564 | *q++=ClampToQuantum(GetPixelIntensity(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1565 | p+=GetPixelChannels(image); |
| 1566 | } |
| 1567 | } |
| 1568 | return; |
| 1569 | } |
| 1570 | if (LocaleCompare(map,"RGB") == 0) |
| 1571 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1572 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1573 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1574 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1575 | if (p == (const Quantum *) NULL) |
| 1576 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1577 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1578 | { |
| 1579 | *q++=GetPixelRed(image,p); |
| 1580 | *q++=GetPixelGreen(image,p); |
| 1581 | *q++=GetPixelBlue(image,p); |
| 1582 | p+=GetPixelChannels(image); |
| 1583 | } |
| 1584 | } |
| 1585 | return; |
| 1586 | } |
| 1587 | if (LocaleCompare(map,"RGBA") == 0) |
| 1588 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1589 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1590 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1591 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1592 | if (p == (const Quantum *) NULL) |
| 1593 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1594 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1595 | { |
| 1596 | *q++=GetPixelRed(image,p); |
| 1597 | *q++=GetPixelGreen(image,p); |
| 1598 | *q++=GetPixelBlue(image,p); |
| 1599 | *q++=(Quantum) (GetPixelAlpha(image,p)); |
| 1600 | p+=GetPixelChannels(image); |
| 1601 | } |
| 1602 | } |
| 1603 | return; |
| 1604 | } |
| 1605 | if (LocaleCompare(map,"RGBP") == 0) |
| 1606 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1607 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1608 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1609 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1610 | if (p == (const Quantum *) NULL) |
| 1611 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1612 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1613 | { |
| 1614 | *q++=GetPixelRed(image,p); |
| 1615 | *q++=GetPixelGreen(image,p); |
| 1616 | *q++=GetPixelBlue(image,p); |
| 1617 | *q++=(Quantum) 0; |
| 1618 | p+=GetPixelChannels(image); |
| 1619 | } |
| 1620 | } |
| 1621 | return; |
| 1622 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1623 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1624 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1625 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1626 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1627 | if (p == (const Quantum *) NULL) |
| 1628 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1629 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1630 | { |
| 1631 | register ssize_t |
| 1632 | i; |
| 1633 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1634 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1635 | { |
| 1636 | *q=(Quantum) 0; |
| 1637 | switch (quantum_map[i]) |
| 1638 | { |
| 1639 | case RedQuantum: |
| 1640 | case CyanQuantum: |
| 1641 | { |
| 1642 | *q=GetPixelRed(image,p); |
| 1643 | break; |
| 1644 | } |
| 1645 | case GreenQuantum: |
| 1646 | case MagentaQuantum: |
| 1647 | { |
| 1648 | *q=GetPixelGreen(image,p); |
| 1649 | break; |
| 1650 | } |
| 1651 | case BlueQuantum: |
| 1652 | case YellowQuantum: |
| 1653 | { |
| 1654 | *q=GetPixelBlue(image,p); |
| 1655 | break; |
| 1656 | } |
| 1657 | case AlphaQuantum: |
| 1658 | { |
| 1659 | *q=GetPixelAlpha(image,p); |
| 1660 | break; |
| 1661 | } |
| 1662 | case OpacityQuantum: |
| 1663 | { |
| 1664 | *q=GetPixelAlpha(image,p); |
| 1665 | break; |
| 1666 | } |
| 1667 | case BlackQuantum: |
| 1668 | { |
| 1669 | if (image->colorspace == CMYKColorspace) |
| 1670 | *q=GetPixelBlack(image,p); |
| 1671 | break; |
| 1672 | } |
| 1673 | case IndexQuantum: |
| 1674 | { |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 1675 | *q=ClampToQuantum(GetPixelIntensity(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1676 | break; |
| 1677 | } |
| 1678 | default: |
| 1679 | { |
| 1680 | *q=(Quantum) 0; |
| 1681 | break; |
| 1682 | } |
| 1683 | } |
| 1684 | q++; |
| 1685 | } |
| 1686 | p+=GetPixelChannels(image); |
| 1687 | } |
| 1688 | } |
| 1689 | } |
| 1690 | |
cristy | 2dc655d | 2012-07-05 13:16:28 +0000 | [diff] [blame] | 1691 | static void ExportShortPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 1692 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 1693 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1694 | { |
| 1695 | register const Quantum |
| 1696 | *restrict p; |
| 1697 | |
| 1698 | register ssize_t |
| 1699 | x; |
| 1700 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1701 | register unsigned short |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 1702 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1703 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1704 | size_t |
| 1705 | length; |
| 1706 | |
| 1707 | ssize_t |
| 1708 | y; |
| 1709 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1710 | q=(unsigned short *) pixels; |
| 1711 | if (LocaleCompare(map,"BGR") == 0) |
| 1712 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1713 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1714 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1715 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1716 | if (p == (const Quantum *) NULL) |
| 1717 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1718 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1719 | { |
| 1720 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1721 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1722 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1723 | p+=GetPixelChannels(image); |
| 1724 | } |
| 1725 | } |
| 1726 | return; |
| 1727 | } |
| 1728 | if (LocaleCompare(map,"BGRA") == 0) |
| 1729 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1730 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1731 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1732 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1733 | if (p == (const Quantum *) NULL) |
| 1734 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1735 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1736 | { |
| 1737 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1738 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1739 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1740 | *q++=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
| 1741 | p+=GetPixelChannels(image); |
| 1742 | } |
| 1743 | } |
| 1744 | return; |
| 1745 | } |
| 1746 | if (LocaleCompare(map,"BGRP") == 0) |
| 1747 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1748 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1749 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1750 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1751 | if (p == (const Quantum *) NULL) |
| 1752 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1753 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1754 | { |
| 1755 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1756 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1757 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1758 | *q++=0; |
| 1759 | p+=GetPixelChannels(image); |
| 1760 | } |
| 1761 | } |
| 1762 | return; |
| 1763 | } |
| 1764 | if (LocaleCompare(map,"I") == 0) |
| 1765 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1766 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1767 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1768 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1769 | if (p == (const Quantum *) NULL) |
| 1770 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1771 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1772 | { |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 1773 | *q++=ScaleQuantumToShort(ClampToQuantum(GetPixelIntensity(image,p))); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1774 | p+=GetPixelChannels(image); |
| 1775 | } |
| 1776 | } |
| 1777 | return; |
| 1778 | } |
| 1779 | if (LocaleCompare(map,"RGB") == 0) |
| 1780 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1781 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1782 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1783 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1784 | if (p == (const Quantum *) NULL) |
| 1785 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1786 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1787 | { |
| 1788 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1789 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1790 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1791 | p+=GetPixelChannels(image); |
| 1792 | } |
| 1793 | } |
| 1794 | return; |
| 1795 | } |
| 1796 | if (LocaleCompare(map,"RGBA") == 0) |
| 1797 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1798 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1799 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1800 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1801 | if (p == (const Quantum *) NULL) |
| 1802 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1803 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1804 | { |
| 1805 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1806 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1807 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1808 | *q++=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
| 1809 | p+=GetPixelChannels(image); |
| 1810 | } |
| 1811 | } |
| 1812 | return; |
| 1813 | } |
| 1814 | if (LocaleCompare(map,"RGBP") == 0) |
| 1815 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1816 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1817 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1818 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1819 | if (p == (const Quantum *) NULL) |
| 1820 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1821 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1822 | { |
| 1823 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1824 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1825 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1826 | *q++=0; |
| 1827 | p+=GetPixelChannels(image); |
| 1828 | } |
| 1829 | } |
| 1830 | return; |
| 1831 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1832 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1833 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1834 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1835 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1836 | if (p == (const Quantum *) NULL) |
| 1837 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1838 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1839 | { |
| 1840 | register ssize_t |
| 1841 | i; |
| 1842 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1843 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1844 | { |
| 1845 | *q=0; |
| 1846 | switch (quantum_map[i]) |
| 1847 | { |
| 1848 | case RedQuantum: |
| 1849 | case CyanQuantum: |
| 1850 | { |
| 1851 | *q=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1852 | break; |
| 1853 | } |
| 1854 | case GreenQuantum: |
| 1855 | case MagentaQuantum: |
| 1856 | { |
| 1857 | *q=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1858 | break; |
| 1859 | } |
| 1860 | case BlueQuantum: |
| 1861 | case YellowQuantum: |
| 1862 | { |
| 1863 | *q=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1864 | break; |
| 1865 | } |
| 1866 | case AlphaQuantum: |
| 1867 | { |
| 1868 | *q=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
| 1869 | break; |
| 1870 | } |
| 1871 | case OpacityQuantum: |
| 1872 | { |
| 1873 | *q=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
| 1874 | break; |
| 1875 | } |
| 1876 | case BlackQuantum: |
| 1877 | { |
| 1878 | if (image->colorspace == CMYKColorspace) |
| 1879 | *q=ScaleQuantumToShort(GetPixelBlack(image,p)); |
| 1880 | break; |
| 1881 | } |
| 1882 | case IndexQuantum: |
| 1883 | { |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 1884 | *q=ScaleQuantumToShort(ClampToQuantum(GetPixelIntensity(image,p))); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1885 | break; |
| 1886 | } |
| 1887 | default: |
| 1888 | break; |
| 1889 | } |
| 1890 | q++; |
| 1891 | } |
| 1892 | p+=GetPixelChannels(image); |
| 1893 | } |
| 1894 | } |
| 1895 | } |
| 1896 | |
cristy | 2dc655d | 2012-07-05 13:16:28 +0000 | [diff] [blame] | 1897 | MagickExport MagickBooleanType ExportImagePixels(Image *image, |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1898 | const ssize_t x,const ssize_t y,const size_t width,const size_t height, |
| 1899 | const char *map,const StorageType type,void *pixels,ExceptionInfo *exception) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1900 | { |
| 1901 | QuantumType |
| 1902 | *quantum_map; |
| 1903 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1904 | RectangleInfo |
| 1905 | roi; |
| 1906 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1907 | register ssize_t |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1908 | i; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1909 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1910 | size_t |
| 1911 | length; |
| 1912 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1913 | assert(image != (Image *) NULL); |
| 1914 | assert(image->signature == MagickSignature); |
| 1915 | if (image->debug != MagickFalse) |
| 1916 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1917 | length=strlen(map); |
| 1918 | quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1919 | if (quantum_map == (QuantumType *) NULL) |
| 1920 | { |
| 1921 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1922 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1923 | return(MagickFalse); |
| 1924 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1925 | for (i=0; i < (ssize_t) length; i++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1926 | { |
| 1927 | switch (map[i]) |
| 1928 | { |
| 1929 | case 'A': |
| 1930 | case 'a': |
| 1931 | { |
| 1932 | quantum_map[i]=AlphaQuantum; |
| 1933 | break; |
| 1934 | } |
| 1935 | case 'B': |
| 1936 | case 'b': |
| 1937 | { |
| 1938 | quantum_map[i]=BlueQuantum; |
| 1939 | break; |
| 1940 | } |
| 1941 | case 'C': |
| 1942 | case 'c': |
| 1943 | { |
| 1944 | quantum_map[i]=CyanQuantum; |
| 1945 | if (image->colorspace == CMYKColorspace) |
| 1946 | break; |
| 1947 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1948 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1949 | "ColorSeparatedImageRequired","`%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1950 | return(MagickFalse); |
| 1951 | } |
| 1952 | case 'g': |
| 1953 | case 'G': |
| 1954 | { |
| 1955 | quantum_map[i]=GreenQuantum; |
| 1956 | break; |
| 1957 | } |
| 1958 | case 'I': |
| 1959 | case 'i': |
| 1960 | { |
| 1961 | quantum_map[i]=IndexQuantum; |
| 1962 | break; |
| 1963 | } |
| 1964 | case 'K': |
| 1965 | case 'k': |
| 1966 | { |
| 1967 | quantum_map[i]=BlackQuantum; |
| 1968 | if (image->colorspace == CMYKColorspace) |
| 1969 | break; |
| 1970 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1971 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1972 | "ColorSeparatedImageRequired","`%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1973 | return(MagickFalse); |
| 1974 | } |
| 1975 | case 'M': |
| 1976 | case 'm': |
| 1977 | { |
| 1978 | quantum_map[i]=MagentaQuantum; |
| 1979 | if (image->colorspace == CMYKColorspace) |
| 1980 | break; |
| 1981 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1982 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1983 | "ColorSeparatedImageRequired","`%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1984 | return(MagickFalse); |
| 1985 | } |
| 1986 | case 'o': |
| 1987 | case 'O': |
| 1988 | { |
| 1989 | quantum_map[i]=OpacityQuantum; |
| 1990 | break; |
| 1991 | } |
| 1992 | case 'P': |
| 1993 | case 'p': |
| 1994 | { |
| 1995 | quantum_map[i]=UndefinedQuantum; |
| 1996 | break; |
| 1997 | } |
| 1998 | case 'R': |
| 1999 | case 'r': |
| 2000 | { |
| 2001 | quantum_map[i]=RedQuantum; |
| 2002 | break; |
| 2003 | } |
| 2004 | case 'Y': |
| 2005 | case 'y': |
| 2006 | { |
| 2007 | quantum_map[i]=YellowQuantum; |
| 2008 | if (image->colorspace == CMYKColorspace) |
| 2009 | break; |
| 2010 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 2011 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2012 | "ColorSeparatedImageRequired","`%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2013 | return(MagickFalse); |
| 2014 | } |
| 2015 | default: |
| 2016 | { |
| 2017 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 2018 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2019 | "UnrecognizedPixelMap","`%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2020 | return(MagickFalse); |
| 2021 | } |
| 2022 | } |
| 2023 | } |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2024 | roi.width=width; |
| 2025 | roi.height=height; |
| 2026 | roi.x=x; |
| 2027 | roi.y=y; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2028 | switch (type) |
| 2029 | { |
| 2030 | case CharPixel: |
| 2031 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2032 | ExportCharPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2033 | break; |
| 2034 | } |
| 2035 | case DoublePixel: |
| 2036 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2037 | ExportDoublePixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2038 | break; |
| 2039 | } |
| 2040 | case FloatPixel: |
| 2041 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2042 | ExportFloatPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2043 | break; |
| 2044 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2045 | case LongPixel: |
| 2046 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2047 | ExportLongPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2048 | break; |
| 2049 | } |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 2050 | case LongLongPixel: |
| 2051 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2052 | ExportLongLongPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 2053 | break; |
| 2054 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2055 | case QuantumPixel: |
| 2056 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2057 | ExportQuantumPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2058 | break; |
| 2059 | } |
| 2060 | case ShortPixel: |
| 2061 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2062 | ExportShortPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2063 | break; |
| 2064 | } |
| 2065 | default: |
| 2066 | { |
| 2067 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 2068 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2069 | "UnrecognizedPixelMap","`%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2070 | break; |
| 2071 | } |
| 2072 | } |
| 2073 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 2074 | return(MagickTrue); |
| 2075 | } |
| 2076 | |
| 2077 | /* |
| 2078 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2079 | % % |
| 2080 | % % |
| 2081 | % % |
cristy | aa8634f | 2011-10-01 13:25:12 +0000 | [diff] [blame] | 2082 | % G e t P i x e l I n f o % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2083 | % % |
| 2084 | % % |
| 2085 | % % |
| 2086 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2087 | % |
| 2088 | % GetPixelInfo() initializes the PixelInfo structure. |
| 2089 | % |
| 2090 | % The format of the GetPixelInfo method is: |
| 2091 | % |
| 2092 | % GetPixelInfo(const Image *image,PixelInfo *pixel) |
| 2093 | % |
| 2094 | % A description of each parameter follows: |
| 2095 | % |
anthony | a322a83 | 2013-04-27 06:28:03 +0000 | [diff] [blame] | 2096 | % o image: the image. (optional - may be NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2097 | % |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 2098 | % o pixel: Specifies a pointer to a PixelInfo structure. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2099 | % |
| 2100 | */ |
cristy | aa8634f | 2011-10-01 13:25:12 +0000 | [diff] [blame] | 2101 | MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2102 | { |
| 2103 | pixel->storage_class=DirectClass; |
cristy | 7020ae6 | 2012-04-18 12:58:34 +0000 | [diff] [blame] | 2104 | pixel->colorspace=sRGBColorspace; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 2105 | pixel->alpha_trait=UndefinedPixelTrait; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2106 | pixel->fuzz=0.0; |
| 2107 | pixel->depth=MAGICKCORE_QUANTUM_DEPTH; |
| 2108 | pixel->red=0.0; |
| 2109 | pixel->green=0.0; |
| 2110 | pixel->blue=0.0; |
| 2111 | pixel->black=0.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2112 | pixel->alpha=(double) OpaqueAlpha; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2113 | pixel->index=0.0; |
| 2114 | if (image == (const Image *) NULL) |
| 2115 | return; |
| 2116 | pixel->storage_class=image->storage_class; |
| 2117 | pixel->colorspace=image->colorspace; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 2118 | pixel->alpha_trait=image->alpha_trait; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2119 | pixel->depth=image->depth; |
| 2120 | pixel->fuzz=image->fuzz; |
| 2121 | } |
| 2122 | |
| 2123 | /* |
| 2124 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2125 | % % |
| 2126 | % % |
| 2127 | % % |
cristy | 9731df7 | 2013-03-12 16:31:13 +0000 | [diff] [blame] | 2128 | % G e t P i x e l I n t e n s i t y % |
| 2129 | % % |
| 2130 | % % |
| 2131 | % % |
| 2132 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2133 | % |
cristy | 0c5c889 | 2013-03-12 16:33:48 +0000 | [diff] [blame] | 2134 | % GetPixelIntensity() returns a single sample intensity value from the red, |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 2135 | % green, and blue components of a pixel based on the selected method: |
| 2136 | % |
cristy | 2cf5d37 | 2013-03-13 12:03:11 +0000 | [diff] [blame] | 2137 | % Rec601Luma 0.298839R' + 0.586811G' + 0.114350B' |
| 2138 | % Rec601Luminance 0.298839R + 0.586811G + 0.114350B |
| 2139 | % Rec709Luma 0.21260R' + 0.71520G' + 0.07220B' |
| 2140 | % Rec709Luminance 0.21260R + 0.71520G + 0.07220B |
| 2141 | % Brightness max(R, G, B) |
| 2142 | % Lightness (min(R, G, B) + max(R, G, B)) / 2.0 |
| 2143 | % RMS (R'^2 + G'^2 + B'^2) / 3.0 |
| 2144 | % Average (R' + G' + B') / 3.0 |
cristy | 9731df7 | 2013-03-12 16:31:13 +0000 | [diff] [blame] | 2145 | % |
| 2146 | % The format of the GetPixelIntensity method is: |
| 2147 | % |
cristy | 2cf5d37 | 2013-03-13 12:03:11 +0000 | [diff] [blame] | 2148 | % MagickRealType GetPixelIntensity(const Image *image, |
| 2149 | % const Quantum *pixel) |
cristy | 9731df7 | 2013-03-12 16:31:13 +0000 | [diff] [blame] | 2150 | % |
| 2151 | % A description of each parameter follows: |
| 2152 | % |
| 2153 | % o image: the image. |
| 2154 | % |
| 2155 | % o pixel: Specifies a pointer to a Quantum structure. |
| 2156 | % |
| 2157 | */ |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 2158 | |
| 2159 | static inline MagickRealType MagickMax(const MagickRealType x, |
| 2160 | const MagickRealType y) |
| 2161 | { |
| 2162 | if (x > y) |
| 2163 | return(x); |
| 2164 | return(y); |
| 2165 | } |
| 2166 | |
| 2167 | static inline MagickRealType MagickMin(const MagickRealType x, |
| 2168 | const MagickRealType y) |
| 2169 | { |
| 2170 | if (x < y) |
| 2171 | return(x); |
| 2172 | return(y); |
| 2173 | } |
| 2174 | |
cristy | 9731df7 | 2013-03-12 16:31:13 +0000 | [diff] [blame] | 2175 | MagickExport MagickRealType GetPixelIntensity(const Image *restrict image, |
| 2176 | const Quantum *restrict pixel) |
| 2177 | { |
| 2178 | MagickRealType |
| 2179 | blue, |
| 2180 | green, |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 2181 | red, |
| 2182 | intensity; |
cristy | 9731df7 | 2013-03-12 16:31:13 +0000 | [diff] [blame] | 2183 | |
| 2184 | if (image->colorspace == GRAYColorspace) |
cristy | 592d6bb | 2013-04-07 15:20:37 +0000 | [diff] [blame] | 2185 | return((MagickRealType) GetPixelGray(image,pixel)); |
| 2186 | red=(MagickRealType) GetPixelRed(image,pixel); |
| 2187 | green=(MagickRealType) GetPixelGreen(image,pixel); |
| 2188 | blue=(MagickRealType) GetPixelBlue(image,pixel); |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 2189 | switch (image->intensity) |
| 2190 | { |
cristy | bf02d73 | 2013-03-13 16:28:58 +0000 | [diff] [blame] | 2191 | case AveragePixelIntensityMethod: |
| 2192 | { |
| 2193 | intensity=(red+green+blue)/3.0; |
| 2194 | break; |
| 2195 | } |
| 2196 | case BrightnessPixelIntensityMethod: |
| 2197 | { |
| 2198 | intensity=MagickMax(MagickMax(red,green),blue); |
| 2199 | break; |
| 2200 | } |
| 2201 | case LightnessPixelIntensityMethod: |
| 2202 | { |
| 2203 | intensity=MagickMin(MagickMin(red,green),blue); |
| 2204 | break; |
| 2205 | } |
cristy | 462c1ca | 2013-04-15 10:29:18 +0000 | [diff] [blame] | 2206 | case MSPixelIntensityMethod: |
| 2207 | { |
| 2208 | intensity=(MagickRealType) (((double) red*red+green*green+blue*blue)/ |
| 2209 | (3.0*QuantumRange)); |
| 2210 | break; |
| 2211 | } |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 2212 | case Rec601LumaPixelIntensityMethod: |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 2213 | { |
cristy | 9e2436a | 2013-05-02 20:35:59 +0000 | [diff] [blame] | 2214 | intensity=0.298839*red+0.586811*green+0.114350*blue; |
cristy | 2cf5d37 | 2013-03-13 12:03:11 +0000 | [diff] [blame] | 2215 | break; |
| 2216 | } |
| 2217 | case Rec601LuminancePixelIntensityMethod: |
| 2218 | { |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 2219 | if (image->colorspace == sRGBColorspace) |
| 2220 | { |
| 2221 | red=DecodePixelGamma(red); |
| 2222 | green=DecodePixelGamma(green); |
| 2223 | blue=DecodePixelGamma(blue); |
| 2224 | } |
cristy | 9e2436a | 2013-05-02 20:35:59 +0000 | [diff] [blame] | 2225 | intensity=0.298839*red+0.586811*green+0.114350*blue; |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 2226 | break; |
| 2227 | } |
| 2228 | case Rec709LumaPixelIntensityMethod: |
cristy | c94210c | 2013-05-06 14:09:53 +0000 | [diff] [blame] | 2229 | default: |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 2230 | { |
cristy | 2cf5d37 | 2013-03-13 12:03:11 +0000 | [diff] [blame] | 2231 | intensity=0.21260f*red+0.71520f*green+0.07220f*blue; |
| 2232 | break; |
| 2233 | } |
| 2234 | case Rec709LuminancePixelIntensityMethod: |
| 2235 | { |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 2236 | if (image->colorspace == sRGBColorspace) |
| 2237 | { |
| 2238 | red=DecodePixelGamma(red); |
| 2239 | green=DecodePixelGamma(green); |
| 2240 | blue=DecodePixelGamma(blue); |
| 2241 | } |
| 2242 | intensity=0.21260f*red+0.71520f*green+0.07220f*blue; |
| 2243 | break; |
| 2244 | } |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 2245 | case RMSPixelIntensityMethod: |
| 2246 | { |
cristy | 462c1ca | 2013-04-15 10:29:18 +0000 | [diff] [blame] | 2247 | intensity=(MagickRealType) (sqrt((double) red*red+green*green+blue*blue)/ |
| 2248 | sqrt(3.0)); |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 2249 | break; |
| 2250 | } |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 2251 | } |
| 2252 | return(intensity); |
cristy | 9731df7 | 2013-03-12 16:31:13 +0000 | [diff] [blame] | 2253 | } |
cristy | 9731df7 | 2013-03-12 16:31:13 +0000 | [diff] [blame] | 2254 | |
| 2255 | /* |
| 2256 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2257 | % % |
| 2258 | % % |
| 2259 | % % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2260 | % I m p o r t I m a g e P i x e l s % |
| 2261 | % % |
| 2262 | % % |
| 2263 | % % |
| 2264 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2265 | % |
| 2266 | % ImportImagePixels() accepts pixel data and stores in the image at the |
| 2267 | % location you specify. The method returns MagickTrue on success otherwise |
| 2268 | % MagickFalse if an error is encountered. The pixel data can be either char, |
cristy | b5a45a3 | 2012-01-10 13:31:13 +0000 | [diff] [blame] | 2269 | % Quantum, short int, unsigned int, unsigned long long, float, or double in |
| 2270 | % the order specified by map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2271 | % |
| 2272 | % Suppose your want to upload the first scanline of a 640x480 image from |
| 2273 | % character data in red-green-blue order: |
| 2274 | % |
| 2275 | % ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels); |
| 2276 | % |
| 2277 | % The format of the ImportImagePixels method is: |
| 2278 | % |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2279 | % MagickBooleanType ImportImagePixels(Image *image,const ssize_t x, |
| 2280 | % const ssize_t y,const size_t width,const size_t height, |
| 2281 | % const char *map,const StorageType type,const void *pixels, |
| 2282 | % ExceptionInfo *exception) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2283 | % |
| 2284 | % A description of each parameter follows: |
| 2285 | % |
| 2286 | % o image: the image. |
| 2287 | % |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2288 | % o x,y,width,height: These values define the perimeter |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2289 | % of a region of pixels you want to define. |
| 2290 | % |
| 2291 | % o map: This string reflects the expected ordering of the pixel array. |
| 2292 | % It can be any combination or order of R = red, G = green, B = blue, |
| 2293 | % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan, |
| 2294 | % Y = yellow, M = magenta, K = black, I = intensity (for grayscale), |
| 2295 | % P = pad. |
| 2296 | % |
| 2297 | % o type: Define the data type of the pixels. Float and double types are |
| 2298 | % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 2299 | % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *), |
cristy | ff6834e | 2012-01-10 03:00:25 +0000 | [diff] [blame] | 2300 | % LongPixel (unsigned int *), LongLongPixel (unsigned long long *), |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 2301 | % QuantumPixel (Quantum *), or ShortPixel (unsigned short *). |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2302 | % |
| 2303 | % o pixels: This array of values contain the pixel components as defined by |
| 2304 | % map and type. You must preallocate this array where the expected |
| 2305 | % length varies depending on the values of width, height, map, and type. |
| 2306 | % |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 2307 | % o exception: return any errors or warnings in this structure. |
| 2308 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2309 | */ |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2310 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2311 | static void ImportCharPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 2312 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 2313 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2314 | { |
| 2315 | register const unsigned char |
| 2316 | *restrict p; |
| 2317 | |
| 2318 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 2319 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2320 | |
| 2321 | register ssize_t |
| 2322 | x; |
| 2323 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2324 | size_t |
| 2325 | length; |
| 2326 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2327 | ssize_t |
| 2328 | y; |
| 2329 | |
| 2330 | p=(const unsigned char *) pixels; |
| 2331 | if (LocaleCompare(map,"BGR") == 0) |
| 2332 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2333 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2334 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2335 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2336 | if (q == (Quantum *) NULL) |
| 2337 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2338 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2339 | { |
| 2340 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2341 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2342 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2343 | q+=GetPixelChannels(image); |
| 2344 | } |
| 2345 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2346 | break; |
| 2347 | } |
| 2348 | return; |
| 2349 | } |
| 2350 | if (LocaleCompare(map,"BGRA") == 0) |
| 2351 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2352 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2353 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2354 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2355 | if (q == (Quantum *) NULL) |
| 2356 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2357 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2358 | { |
| 2359 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2360 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2361 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2362 | SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); |
| 2363 | q+=GetPixelChannels(image); |
| 2364 | } |
| 2365 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2366 | break; |
| 2367 | } |
| 2368 | return; |
| 2369 | } |
| 2370 | if (LocaleCompare(map,"BGRO") == 0) |
| 2371 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2372 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2373 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2374 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2375 | if (q == (Quantum *) NULL) |
| 2376 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2377 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2378 | { |
| 2379 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2380 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2381 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2382 | SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); |
| 2383 | q+=GetPixelChannels(image); |
| 2384 | } |
| 2385 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2386 | break; |
| 2387 | } |
| 2388 | return; |
| 2389 | } |
| 2390 | if (LocaleCompare(map,"BGRP") == 0) |
| 2391 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2392 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2393 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2394 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2395 | if (q == (Quantum *) NULL) |
| 2396 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2397 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2398 | { |
| 2399 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2400 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2401 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2402 | p++; |
| 2403 | q+=GetPixelChannels(image); |
| 2404 | } |
| 2405 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2406 | break; |
| 2407 | } |
| 2408 | return; |
| 2409 | } |
| 2410 | if (LocaleCompare(map,"I") == 0) |
| 2411 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2412 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2413 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2414 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2415 | if (q == (Quantum *) NULL) |
| 2416 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2417 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2418 | { |
| 2419 | SetPixelGray(image,ScaleCharToQuantum(*p++),q); |
| 2420 | q+=GetPixelChannels(image); |
| 2421 | } |
| 2422 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2423 | break; |
| 2424 | } |
| 2425 | return; |
| 2426 | } |
| 2427 | if (LocaleCompare(map,"RGB") == 0) |
| 2428 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2429 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2430 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2431 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2432 | if (q == (Quantum *) NULL) |
| 2433 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2434 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2435 | { |
| 2436 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2437 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2438 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2439 | q+=GetPixelChannels(image); |
| 2440 | } |
| 2441 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2442 | break; |
| 2443 | } |
| 2444 | return; |
| 2445 | } |
| 2446 | if (LocaleCompare(map,"RGBA") == 0) |
| 2447 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2448 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2449 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2450 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2451 | if (q == (Quantum *) NULL) |
| 2452 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2453 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2454 | { |
| 2455 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2456 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2457 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2458 | SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); |
| 2459 | q+=GetPixelChannels(image); |
| 2460 | } |
| 2461 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2462 | break; |
| 2463 | } |
| 2464 | return; |
| 2465 | } |
| 2466 | if (LocaleCompare(map,"RGBO") == 0) |
| 2467 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2468 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2469 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2470 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2471 | if (q == (Quantum *) NULL) |
| 2472 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2473 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2474 | { |
| 2475 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2476 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2477 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2478 | SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); |
| 2479 | q+=GetPixelChannels(image); |
| 2480 | } |
| 2481 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2482 | break; |
| 2483 | } |
| 2484 | return; |
| 2485 | } |
| 2486 | if (LocaleCompare(map,"RGBP") == 0) |
| 2487 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2488 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2489 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2490 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2491 | if (q == (Quantum *) NULL) |
| 2492 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2493 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2494 | { |
| 2495 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2496 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2497 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2498 | p++; |
| 2499 | q+=GetPixelChannels(image); |
| 2500 | } |
| 2501 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2502 | break; |
| 2503 | } |
| 2504 | return; |
| 2505 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2506 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2507 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2508 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2509 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2510 | if (q == (Quantum *) NULL) |
| 2511 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2512 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2513 | { |
| 2514 | register ssize_t |
| 2515 | i; |
| 2516 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2517 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2518 | { |
| 2519 | switch (quantum_map[i]) |
| 2520 | { |
| 2521 | case RedQuantum: |
| 2522 | case CyanQuantum: |
| 2523 | { |
| 2524 | SetPixelRed(image,ScaleCharToQuantum(*p),q); |
| 2525 | break; |
| 2526 | } |
| 2527 | case GreenQuantum: |
| 2528 | case MagentaQuantum: |
| 2529 | { |
| 2530 | SetPixelGreen(image,ScaleCharToQuantum(*p),q); |
| 2531 | break; |
| 2532 | } |
| 2533 | case BlueQuantum: |
| 2534 | case YellowQuantum: |
| 2535 | { |
| 2536 | SetPixelBlue(image,ScaleCharToQuantum(*p),q); |
| 2537 | break; |
| 2538 | } |
| 2539 | case AlphaQuantum: |
| 2540 | { |
| 2541 | SetPixelAlpha(image,ScaleCharToQuantum(*p),q); |
| 2542 | break; |
| 2543 | } |
| 2544 | case OpacityQuantum: |
| 2545 | { |
| 2546 | SetPixelAlpha(image,ScaleCharToQuantum(*p),q); |
| 2547 | break; |
| 2548 | } |
| 2549 | case BlackQuantum: |
| 2550 | { |
| 2551 | SetPixelBlack(image,ScaleCharToQuantum(*p),q); |
| 2552 | break; |
| 2553 | } |
| 2554 | case IndexQuantum: |
| 2555 | { |
| 2556 | SetPixelGray(image,ScaleCharToQuantum(*p),q); |
| 2557 | break; |
| 2558 | } |
| 2559 | default: |
| 2560 | break; |
| 2561 | } |
| 2562 | p++; |
| 2563 | } |
| 2564 | q+=GetPixelChannels(image); |
| 2565 | } |
| 2566 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2567 | break; |
| 2568 | } |
| 2569 | } |
| 2570 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2571 | static void ImportDoublePixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 2572 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 2573 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2574 | { |
| 2575 | register const double |
| 2576 | *restrict p; |
| 2577 | |
| 2578 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 2579 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2580 | |
| 2581 | register ssize_t |
| 2582 | x; |
| 2583 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2584 | size_t |
| 2585 | length; |
| 2586 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2587 | ssize_t |
| 2588 | y; |
| 2589 | |
| 2590 | p=(const double *) pixels; |
| 2591 | if (LocaleCompare(map,"BGR") == 0) |
| 2592 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2593 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2594 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2595 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2596 | if (q == (Quantum *) NULL) |
| 2597 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2598 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2599 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2600 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2601 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2602 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2603 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2604 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2605 | p++; |
| 2606 | q+=GetPixelChannels(image); |
| 2607 | } |
| 2608 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2609 | break; |
| 2610 | } |
| 2611 | return; |
| 2612 | } |
| 2613 | if (LocaleCompare(map,"BGRA") == 0) |
| 2614 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2615 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2616 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2617 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2618 | if (q == (Quantum *) NULL) |
| 2619 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2620 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2621 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2622 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2623 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2624 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2625 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2626 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2627 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2628 | SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2629 | p++; |
| 2630 | q+=GetPixelChannels(image); |
| 2631 | } |
| 2632 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2633 | break; |
| 2634 | } |
| 2635 | return; |
| 2636 | } |
| 2637 | if (LocaleCompare(map,"BGRP") == 0) |
| 2638 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2639 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2640 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2641 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2642 | if (q == (Quantum *) NULL) |
| 2643 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2644 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2645 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2646 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2647 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2648 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2649 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2650 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2651 | p++; |
| 2652 | p++; |
| 2653 | q+=GetPixelChannels(image); |
| 2654 | } |
| 2655 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2656 | break; |
| 2657 | } |
| 2658 | return; |
| 2659 | } |
| 2660 | if (LocaleCompare(map,"I") == 0) |
| 2661 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2662 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2663 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2664 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2665 | if (q == (Quantum *) NULL) |
| 2666 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2667 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2668 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2669 | SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2670 | p++; |
| 2671 | q+=GetPixelChannels(image); |
| 2672 | } |
| 2673 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2674 | break; |
| 2675 | } |
| 2676 | return; |
| 2677 | } |
| 2678 | if (LocaleCompare(map,"RGB") == 0) |
| 2679 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2680 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2681 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2682 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2683 | if (q == (Quantum *) NULL) |
| 2684 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2685 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2686 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2687 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2688 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2689 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2690 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2691 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2692 | p++; |
| 2693 | q+=GetPixelChannels(image); |
| 2694 | } |
| 2695 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2696 | break; |
| 2697 | } |
| 2698 | return; |
| 2699 | } |
| 2700 | if (LocaleCompare(map,"RGBA") == 0) |
| 2701 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2702 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2703 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2704 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2705 | if (q == (Quantum *) NULL) |
| 2706 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2707 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2708 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2709 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2710 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2711 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2712 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2713 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2714 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2715 | SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2716 | p++; |
| 2717 | q+=GetPixelChannels(image); |
| 2718 | } |
| 2719 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2720 | break; |
| 2721 | } |
| 2722 | return; |
| 2723 | } |
| 2724 | if (LocaleCompare(map,"RGBP") == 0) |
| 2725 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2726 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2727 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2728 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2729 | if (q == (Quantum *) NULL) |
| 2730 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2731 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2732 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2733 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2734 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2735 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2736 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2737 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2738 | p++; |
| 2739 | q+=GetPixelChannels(image); |
| 2740 | } |
| 2741 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2742 | break; |
| 2743 | } |
| 2744 | return; |
| 2745 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2746 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2747 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2748 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2749 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2750 | if (q == (Quantum *) NULL) |
| 2751 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2752 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2753 | { |
| 2754 | register ssize_t |
| 2755 | i; |
| 2756 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2757 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2758 | { |
| 2759 | switch (quantum_map[i]) |
| 2760 | { |
| 2761 | case RedQuantum: |
| 2762 | case CyanQuantum: |
| 2763 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2764 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2765 | break; |
| 2766 | } |
| 2767 | case GreenQuantum: |
| 2768 | case MagentaQuantum: |
| 2769 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2770 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2771 | break; |
| 2772 | } |
| 2773 | case BlueQuantum: |
| 2774 | case YellowQuantum: |
| 2775 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2776 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2777 | break; |
| 2778 | } |
| 2779 | case AlphaQuantum: |
| 2780 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2781 | SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2782 | break; |
| 2783 | } |
| 2784 | case OpacityQuantum: |
| 2785 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2786 | SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2787 | break; |
| 2788 | } |
| 2789 | case BlackQuantum: |
| 2790 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2791 | SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2792 | break; |
| 2793 | } |
| 2794 | case IndexQuantum: |
| 2795 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2796 | SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2797 | break; |
| 2798 | } |
| 2799 | default: |
| 2800 | break; |
| 2801 | } |
| 2802 | p++; |
| 2803 | } |
| 2804 | q+=GetPixelChannels(image); |
| 2805 | } |
| 2806 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2807 | break; |
| 2808 | } |
| 2809 | } |
| 2810 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2811 | static void ImportFloatPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 2812 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 2813 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2814 | { |
| 2815 | register const float |
| 2816 | *restrict p; |
| 2817 | |
| 2818 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 2819 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2820 | |
| 2821 | register ssize_t |
| 2822 | x; |
| 2823 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2824 | size_t |
| 2825 | length; |
| 2826 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2827 | ssize_t |
| 2828 | y; |
| 2829 | |
| 2830 | p=(const float *) pixels; |
| 2831 | if (LocaleCompare(map,"BGR") == 0) |
| 2832 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2833 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2834 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2835 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2836 | if (q == (Quantum *) NULL) |
| 2837 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2838 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2839 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2840 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2841 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2842 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2843 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2844 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2845 | p++; |
| 2846 | q+=GetPixelChannels(image); |
| 2847 | } |
| 2848 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2849 | break; |
| 2850 | } |
| 2851 | return; |
| 2852 | } |
| 2853 | if (LocaleCompare(map,"BGRA") == 0) |
| 2854 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2855 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2856 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2857 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2858 | if (q == (Quantum *) NULL) |
| 2859 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2860 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2861 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2862 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2863 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2864 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2865 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2866 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2867 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2868 | SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2869 | p++; |
| 2870 | q+=GetPixelChannels(image); |
| 2871 | } |
| 2872 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2873 | break; |
| 2874 | } |
| 2875 | return; |
| 2876 | } |
| 2877 | if (LocaleCompare(map,"BGRP") == 0) |
| 2878 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2879 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2880 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2881 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2882 | if (q == (Quantum *) NULL) |
| 2883 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2884 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2885 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2886 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2887 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2888 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2889 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2890 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2891 | p++; |
| 2892 | p++; |
| 2893 | q+=GetPixelChannels(image); |
| 2894 | } |
| 2895 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2896 | break; |
| 2897 | } |
| 2898 | return; |
| 2899 | } |
| 2900 | if (LocaleCompare(map,"I") == 0) |
| 2901 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2902 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2903 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2904 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2905 | if (q == (Quantum *) NULL) |
| 2906 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2907 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2908 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2909 | SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2910 | p++; |
| 2911 | q+=GetPixelChannels(image); |
| 2912 | } |
| 2913 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2914 | break; |
| 2915 | } |
| 2916 | return; |
| 2917 | } |
| 2918 | if (LocaleCompare(map,"RGB") == 0) |
| 2919 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2920 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2921 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2922 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2923 | if (q == (Quantum *) NULL) |
| 2924 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2925 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2926 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2927 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2928 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2929 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2930 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2931 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2932 | p++; |
| 2933 | q+=GetPixelChannels(image); |
| 2934 | } |
| 2935 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2936 | break; |
| 2937 | } |
| 2938 | return; |
| 2939 | } |
| 2940 | if (LocaleCompare(map,"RGBA") == 0) |
| 2941 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2942 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2943 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2944 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2945 | if (q == (Quantum *) NULL) |
| 2946 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2947 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2948 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2949 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2950 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2951 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2952 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2953 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2954 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2955 | SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2956 | p++; |
| 2957 | q+=GetPixelChannels(image); |
| 2958 | } |
| 2959 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2960 | break; |
| 2961 | } |
| 2962 | return; |
| 2963 | } |
| 2964 | if (LocaleCompare(map,"RGBP") == 0) |
| 2965 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2966 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2967 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2968 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2969 | if (q == (Quantum *) NULL) |
| 2970 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2971 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2972 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2973 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2974 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2975 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2976 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2977 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2978 | p++; |
| 2979 | q+=GetPixelChannels(image); |
| 2980 | } |
| 2981 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2982 | break; |
| 2983 | } |
| 2984 | return; |
| 2985 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2986 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2987 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2988 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2989 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2990 | if (q == (Quantum *) NULL) |
| 2991 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2992 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2993 | { |
| 2994 | register ssize_t |
| 2995 | i; |
| 2996 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2997 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2998 | { |
| 2999 | switch (quantum_map[i]) |
| 3000 | { |
| 3001 | case RedQuantum: |
| 3002 | case CyanQuantum: |
| 3003 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 3004 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3005 | break; |
| 3006 | } |
| 3007 | case GreenQuantum: |
| 3008 | case MagentaQuantum: |
| 3009 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 3010 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3011 | break; |
| 3012 | } |
| 3013 | case BlueQuantum: |
| 3014 | case YellowQuantum: |
| 3015 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 3016 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3017 | break; |
| 3018 | } |
| 3019 | case AlphaQuantum: |
| 3020 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 3021 | SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3022 | break; |
| 3023 | } |
| 3024 | case OpacityQuantum: |
| 3025 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 3026 | SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3027 | break; |
| 3028 | } |
| 3029 | case BlackQuantum: |
| 3030 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 3031 | SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3032 | break; |
| 3033 | } |
| 3034 | case IndexQuantum: |
| 3035 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 3036 | SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3037 | break; |
| 3038 | } |
| 3039 | default: |
| 3040 | break; |
| 3041 | } |
| 3042 | p++; |
| 3043 | } |
| 3044 | q+=GetPixelChannels(image); |
| 3045 | } |
| 3046 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3047 | break; |
| 3048 | } |
| 3049 | } |
| 3050 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3051 | static void ImportLongPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 3052 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 3053 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3054 | { |
| 3055 | register const unsigned int |
| 3056 | *restrict p; |
| 3057 | |
| 3058 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 3059 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3060 | |
| 3061 | register ssize_t |
| 3062 | x; |
| 3063 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3064 | size_t |
| 3065 | length; |
| 3066 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3067 | ssize_t |
| 3068 | y; |
| 3069 | |
| 3070 | p=(const unsigned int *) pixels; |
| 3071 | if (LocaleCompare(map,"BGR") == 0) |
| 3072 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3073 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3074 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3075 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3076 | if (q == (Quantum *) NULL) |
| 3077 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3078 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3079 | { |
| 3080 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 3081 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 3082 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 3083 | q+=GetPixelChannels(image); |
| 3084 | } |
| 3085 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3086 | break; |
| 3087 | } |
| 3088 | return; |
| 3089 | } |
| 3090 | if (LocaleCompare(map,"BGRA") == 0) |
| 3091 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3092 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3093 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3094 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3095 | if (q == (Quantum *) NULL) |
| 3096 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3097 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3098 | { |
| 3099 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 3100 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 3101 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 3102 | SetPixelAlpha(image,ScaleLongToQuantum(*p++),q); |
| 3103 | q+=GetPixelChannels(image); |
| 3104 | } |
| 3105 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3106 | break; |
| 3107 | } |
| 3108 | return; |
| 3109 | } |
| 3110 | if (LocaleCompare(map,"BGRP") == 0) |
| 3111 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3112 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3113 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3114 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3115 | if (q == (Quantum *) NULL) |
| 3116 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3117 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3118 | { |
| 3119 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 3120 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 3121 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 3122 | p++; |
| 3123 | q+=GetPixelChannels(image); |
| 3124 | } |
| 3125 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3126 | break; |
| 3127 | } |
| 3128 | return; |
| 3129 | } |
| 3130 | if (LocaleCompare(map,"I") == 0) |
| 3131 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3132 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3133 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3134 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3135 | if (q == (Quantum *) NULL) |
| 3136 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3137 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3138 | { |
| 3139 | SetPixelGray(image,ScaleLongToQuantum(*p++),q); |
| 3140 | q+=GetPixelChannels(image); |
| 3141 | } |
| 3142 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3143 | break; |
| 3144 | } |
| 3145 | return; |
| 3146 | } |
| 3147 | if (LocaleCompare(map,"RGB") == 0) |
| 3148 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3149 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3150 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3151 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3152 | if (q == (Quantum *) NULL) |
| 3153 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3154 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3155 | { |
| 3156 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 3157 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 3158 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 3159 | q+=GetPixelChannels(image); |
| 3160 | } |
| 3161 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3162 | break; |
| 3163 | } |
| 3164 | return; |
| 3165 | } |
| 3166 | if (LocaleCompare(map,"RGBA") == 0) |
| 3167 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3168 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3169 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3170 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3171 | if (q == (Quantum *) NULL) |
| 3172 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3173 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3174 | { |
| 3175 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 3176 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 3177 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 3178 | SetPixelAlpha(image,ScaleLongToQuantum(*p++),q); |
| 3179 | q+=GetPixelChannels(image); |
| 3180 | } |
| 3181 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3182 | break; |
| 3183 | } |
| 3184 | return; |
| 3185 | } |
| 3186 | if (LocaleCompare(map,"RGBP") == 0) |
| 3187 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3188 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3189 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3190 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3191 | if (q == (Quantum *) NULL) |
| 3192 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3193 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3194 | { |
| 3195 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 3196 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 3197 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 3198 | p++; |
| 3199 | q+=GetPixelChannels(image); |
| 3200 | } |
| 3201 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3202 | break; |
| 3203 | } |
| 3204 | return; |
| 3205 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3206 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3207 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3208 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3209 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3210 | if (q == (Quantum *) NULL) |
| 3211 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3212 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3213 | { |
| 3214 | register ssize_t |
| 3215 | i; |
| 3216 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3217 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3218 | { |
| 3219 | switch (quantum_map[i]) |
| 3220 | { |
| 3221 | case RedQuantum: |
| 3222 | case CyanQuantum: |
| 3223 | { |
| 3224 | SetPixelRed(image,ScaleLongToQuantum(*p),q); |
| 3225 | break; |
| 3226 | } |
| 3227 | case GreenQuantum: |
| 3228 | case MagentaQuantum: |
| 3229 | { |
| 3230 | SetPixelGreen(image,ScaleLongToQuantum(*p),q); |
| 3231 | break; |
| 3232 | } |
| 3233 | case BlueQuantum: |
| 3234 | case YellowQuantum: |
| 3235 | { |
| 3236 | SetPixelBlue(image,ScaleLongToQuantum(*p),q); |
| 3237 | break; |
| 3238 | } |
| 3239 | case AlphaQuantum: |
| 3240 | { |
| 3241 | SetPixelAlpha(image,ScaleLongToQuantum(*p),q); |
| 3242 | break; |
| 3243 | } |
| 3244 | case OpacityQuantum: |
| 3245 | { |
| 3246 | SetPixelAlpha(image,ScaleLongToQuantum(*p),q); |
| 3247 | break; |
| 3248 | } |
| 3249 | case BlackQuantum: |
| 3250 | { |
| 3251 | SetPixelBlack(image,ScaleLongToQuantum(*p),q); |
| 3252 | break; |
| 3253 | } |
| 3254 | case IndexQuantum: |
| 3255 | { |
| 3256 | SetPixelGray(image,ScaleLongToQuantum(*p),q); |
| 3257 | break; |
| 3258 | } |
| 3259 | default: |
| 3260 | break; |
| 3261 | } |
| 3262 | p++; |
| 3263 | } |
| 3264 | q+=GetPixelChannels(image); |
| 3265 | } |
| 3266 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3267 | break; |
| 3268 | } |
| 3269 | } |
| 3270 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3271 | static void ImportLongLongPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 3272 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 3273 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3274 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3275 | register const MagickSizeType |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3276 | *restrict p; |
| 3277 | |
| 3278 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 3279 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3280 | |
| 3281 | register ssize_t |
| 3282 | x; |
| 3283 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3284 | size_t |
| 3285 | length; |
| 3286 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3287 | ssize_t |
| 3288 | y; |
| 3289 | |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3290 | p=(const MagickSizeType *) pixels; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3291 | if (LocaleCompare(map,"BGR") == 0) |
| 3292 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3293 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3294 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3295 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3296 | if (q == (Quantum *) NULL) |
| 3297 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3298 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3299 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3300 | SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q); |
| 3301 | SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q); |
| 3302 | SetPixelRed(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3303 | q+=GetPixelChannels(image); |
| 3304 | } |
| 3305 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3306 | break; |
| 3307 | } |
| 3308 | return; |
| 3309 | } |
| 3310 | if (LocaleCompare(map,"BGRA") == 0) |
| 3311 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3312 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3313 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3314 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3315 | if (q == (Quantum *) NULL) |
| 3316 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3317 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3318 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3319 | SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q); |
| 3320 | SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q); |
| 3321 | SetPixelRed(image,ScaleLongLongToQuantum(*p++),q); |
| 3322 | SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3323 | q+=GetPixelChannels(image); |
| 3324 | } |
| 3325 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3326 | break; |
| 3327 | } |
| 3328 | return; |
| 3329 | } |
| 3330 | if (LocaleCompare(map,"BGRP") == 0) |
| 3331 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3332 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3333 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3334 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3335 | if (q == (Quantum *) NULL) |
| 3336 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3337 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3338 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3339 | SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q); |
| 3340 | SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q); |
| 3341 | SetPixelRed(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3342 | p++; |
| 3343 | q+=GetPixelChannels(image); |
| 3344 | } |
| 3345 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3346 | break; |
| 3347 | } |
| 3348 | return; |
| 3349 | } |
| 3350 | if (LocaleCompare(map,"I") == 0) |
| 3351 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3352 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3353 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3354 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3355 | if (q == (Quantum *) NULL) |
| 3356 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3357 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3358 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3359 | SetPixelGray(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3360 | q+=GetPixelChannels(image); |
| 3361 | } |
| 3362 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3363 | break; |
| 3364 | } |
| 3365 | return; |
| 3366 | } |
| 3367 | if (LocaleCompare(map,"RGB") == 0) |
| 3368 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3369 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3370 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3371 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3372 | if (q == (Quantum *) NULL) |
| 3373 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3374 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3375 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3376 | SetPixelRed(image,ScaleLongLongToQuantum(*p++),q); |
| 3377 | SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q); |
| 3378 | SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3379 | q+=GetPixelChannels(image); |
| 3380 | } |
| 3381 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3382 | break; |
| 3383 | } |
| 3384 | return; |
| 3385 | } |
| 3386 | if (LocaleCompare(map,"RGBA") == 0) |
| 3387 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3388 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3389 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3390 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3391 | if (q == (Quantum *) NULL) |
| 3392 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3393 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3394 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3395 | SetPixelRed(image,ScaleLongLongToQuantum(*p++),q); |
| 3396 | SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q); |
| 3397 | SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q); |
| 3398 | SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3399 | q+=GetPixelChannels(image); |
| 3400 | } |
| 3401 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3402 | break; |
| 3403 | } |
| 3404 | return; |
| 3405 | } |
| 3406 | if (LocaleCompare(map,"RGBP") == 0) |
| 3407 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3408 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3409 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3410 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3411 | if (q == (Quantum *) NULL) |
| 3412 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3413 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3414 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3415 | SetPixelRed(image,ScaleLongLongToQuantum(*p++),q); |
| 3416 | SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q); |
| 3417 | SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3418 | p++; |
| 3419 | q+=GetPixelChannels(image); |
| 3420 | } |
| 3421 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3422 | break; |
| 3423 | } |
| 3424 | return; |
| 3425 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3426 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3427 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3428 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3429 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3430 | if (q == (Quantum *) NULL) |
| 3431 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3432 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3433 | { |
| 3434 | register ssize_t |
| 3435 | i; |
| 3436 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3437 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3438 | { |
| 3439 | switch (quantum_map[i]) |
| 3440 | { |
| 3441 | case RedQuantum: |
| 3442 | case CyanQuantum: |
| 3443 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3444 | SetPixelRed(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3445 | break; |
| 3446 | } |
| 3447 | case GreenQuantum: |
| 3448 | case MagentaQuantum: |
| 3449 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3450 | SetPixelGreen(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3451 | break; |
| 3452 | } |
| 3453 | case BlueQuantum: |
| 3454 | case YellowQuantum: |
| 3455 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3456 | SetPixelBlue(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3457 | break; |
| 3458 | } |
| 3459 | case AlphaQuantum: |
| 3460 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3461 | SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3462 | break; |
| 3463 | } |
| 3464 | case OpacityQuantum: |
| 3465 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3466 | SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3467 | break; |
| 3468 | } |
| 3469 | case BlackQuantum: |
| 3470 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3471 | SetPixelBlack(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3472 | break; |
| 3473 | } |
| 3474 | case IndexQuantum: |
| 3475 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3476 | SetPixelGray(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3477 | break; |
| 3478 | } |
| 3479 | default: |
| 3480 | break; |
| 3481 | } |
| 3482 | p++; |
| 3483 | } |
| 3484 | q+=GetPixelChannels(image); |
| 3485 | } |
| 3486 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3487 | break; |
| 3488 | } |
| 3489 | } |
| 3490 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3491 | static void ImportQuantumPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 3492 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 3493 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3494 | { |
| 3495 | register const Quantum |
| 3496 | *restrict p; |
| 3497 | |
| 3498 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 3499 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3500 | |
| 3501 | register ssize_t |
| 3502 | x; |
| 3503 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3504 | size_t |
| 3505 | length; |
| 3506 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3507 | ssize_t |
| 3508 | y; |
| 3509 | |
| 3510 | p=(const Quantum *) pixels; |
| 3511 | if (LocaleCompare(map,"BGR") == 0) |
| 3512 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3513 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3514 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3515 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3516 | if (q == (Quantum *) NULL) |
| 3517 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3518 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3519 | { |
| 3520 | SetPixelBlue(image,*p++,q); |
| 3521 | SetPixelGreen(image,*p++,q); |
| 3522 | SetPixelRed(image,*p++,q); |
| 3523 | q+=GetPixelChannels(image); |
| 3524 | } |
| 3525 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3526 | break; |
| 3527 | } |
| 3528 | return; |
| 3529 | } |
| 3530 | if (LocaleCompare(map,"BGRA") == 0) |
| 3531 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3532 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3533 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3534 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3535 | if (q == (Quantum *) NULL) |
| 3536 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3537 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3538 | { |
| 3539 | SetPixelBlue(image,*p++,q); |
| 3540 | SetPixelGreen(image,*p++,q); |
| 3541 | SetPixelRed(image,*p++,q); |
| 3542 | SetPixelAlpha(image,*p++,q); |
| 3543 | q+=GetPixelChannels(image); |
| 3544 | } |
| 3545 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3546 | break; |
| 3547 | } |
| 3548 | return; |
| 3549 | } |
| 3550 | if (LocaleCompare(map,"BGRP") == 0) |
| 3551 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3552 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3553 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3554 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3555 | if (q == (Quantum *) NULL) |
| 3556 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3557 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3558 | { |
| 3559 | SetPixelBlue(image,*p++,q); |
| 3560 | SetPixelGreen(image,*p++,q); |
| 3561 | SetPixelRed(image,*p++,q); |
| 3562 | p++; |
| 3563 | q+=GetPixelChannels(image); |
| 3564 | } |
| 3565 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3566 | break; |
| 3567 | } |
| 3568 | return; |
| 3569 | } |
| 3570 | if (LocaleCompare(map,"I") == 0) |
| 3571 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3572 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3573 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3574 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3575 | if (q == (Quantum *) NULL) |
| 3576 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3577 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3578 | { |
| 3579 | SetPixelGray(image,*p++,q); |
| 3580 | q+=GetPixelChannels(image); |
| 3581 | } |
| 3582 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3583 | break; |
| 3584 | } |
| 3585 | return; |
| 3586 | } |
| 3587 | if (LocaleCompare(map,"RGB") == 0) |
| 3588 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3589 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3590 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3591 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3592 | if (q == (Quantum *) NULL) |
| 3593 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3594 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3595 | { |
| 3596 | SetPixelRed(image,*p++,q); |
| 3597 | SetPixelGreen(image,*p++,q); |
| 3598 | SetPixelBlue(image,*p++,q); |
| 3599 | q+=GetPixelChannels(image); |
| 3600 | } |
| 3601 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3602 | break; |
| 3603 | } |
| 3604 | return; |
| 3605 | } |
| 3606 | if (LocaleCompare(map,"RGBA") == 0) |
| 3607 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3608 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3609 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3610 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3611 | if (q == (Quantum *) NULL) |
| 3612 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3613 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3614 | { |
| 3615 | SetPixelRed(image,*p++,q); |
| 3616 | SetPixelGreen(image,*p++,q); |
| 3617 | SetPixelBlue(image,*p++,q); |
| 3618 | SetPixelAlpha(image,*p++,q); |
| 3619 | q+=GetPixelChannels(image); |
| 3620 | } |
| 3621 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3622 | break; |
| 3623 | } |
| 3624 | return; |
| 3625 | } |
| 3626 | if (LocaleCompare(map,"RGBP") == 0) |
| 3627 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3628 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3629 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3630 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3631 | if (q == (Quantum *) NULL) |
| 3632 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3633 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3634 | { |
| 3635 | SetPixelRed(image,*p++,q); |
| 3636 | SetPixelGreen(image,*p++,q); |
| 3637 | SetPixelBlue(image,*p++,q); |
| 3638 | p++; |
| 3639 | q+=GetPixelChannels(image); |
| 3640 | } |
| 3641 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3642 | break; |
| 3643 | } |
| 3644 | return; |
| 3645 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3646 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3647 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3648 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3649 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3650 | if (q == (Quantum *) NULL) |
| 3651 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3652 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3653 | { |
| 3654 | register ssize_t |
| 3655 | i; |
| 3656 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3657 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3658 | { |
| 3659 | switch (quantum_map[i]) |
| 3660 | { |
| 3661 | case RedQuantum: |
| 3662 | case CyanQuantum: |
| 3663 | { |
| 3664 | SetPixelRed(image,*p,q); |
| 3665 | break; |
| 3666 | } |
| 3667 | case GreenQuantum: |
| 3668 | case MagentaQuantum: |
| 3669 | { |
| 3670 | SetPixelGreen(image,*p,q); |
| 3671 | break; |
| 3672 | } |
| 3673 | case BlueQuantum: |
| 3674 | case YellowQuantum: |
| 3675 | { |
| 3676 | SetPixelBlue(image,*p,q); |
| 3677 | break; |
| 3678 | } |
| 3679 | case AlphaQuantum: |
| 3680 | { |
| 3681 | SetPixelAlpha(image,*p,q); |
| 3682 | break; |
| 3683 | } |
| 3684 | case OpacityQuantum: |
| 3685 | { |
| 3686 | SetPixelAlpha(image,*p,q); |
| 3687 | break; |
| 3688 | } |
| 3689 | case BlackQuantum: |
| 3690 | { |
| 3691 | SetPixelBlack(image,*p,q); |
| 3692 | break; |
| 3693 | } |
| 3694 | case IndexQuantum: |
| 3695 | { |
| 3696 | SetPixelGray(image,*p,q); |
| 3697 | break; |
| 3698 | } |
| 3699 | default: |
| 3700 | break; |
| 3701 | } |
| 3702 | p++; |
| 3703 | } |
| 3704 | q+=GetPixelChannels(image); |
| 3705 | } |
| 3706 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3707 | break; |
| 3708 | } |
| 3709 | } |
| 3710 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3711 | static void ImportShortPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 3712 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 3713 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3714 | { |
| 3715 | register const unsigned short |
| 3716 | *restrict p; |
| 3717 | |
| 3718 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 3719 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3720 | |
| 3721 | register ssize_t |
| 3722 | x; |
| 3723 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3724 | size_t |
| 3725 | length; |
| 3726 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3727 | ssize_t |
| 3728 | y; |
| 3729 | |
| 3730 | p=(const unsigned short *) pixels; |
| 3731 | if (LocaleCompare(map,"BGR") == 0) |
| 3732 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3733 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3734 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3735 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3736 | if (q == (Quantum *) NULL) |
| 3737 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3738 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3739 | { |
| 3740 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3741 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3742 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3743 | q+=GetPixelChannels(image); |
| 3744 | } |
| 3745 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3746 | break; |
| 3747 | } |
| 3748 | return; |
| 3749 | } |
| 3750 | if (LocaleCompare(map,"BGRA") == 0) |
| 3751 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3752 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3753 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3754 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3755 | if (q == (Quantum *) NULL) |
| 3756 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3757 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3758 | { |
| 3759 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3760 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3761 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3762 | SetPixelAlpha(image,ScaleShortToQuantum(*p++),q); |
| 3763 | q+=GetPixelChannels(image); |
| 3764 | } |
| 3765 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3766 | break; |
| 3767 | } |
| 3768 | return; |
| 3769 | } |
| 3770 | if (LocaleCompare(map,"BGRP") == 0) |
| 3771 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3772 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3773 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3774 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3775 | if (q == (Quantum *) NULL) |
| 3776 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3777 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3778 | { |
| 3779 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3780 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3781 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3782 | p++; |
| 3783 | q+=GetPixelChannels(image); |
| 3784 | } |
| 3785 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3786 | break; |
| 3787 | } |
| 3788 | return; |
| 3789 | } |
| 3790 | if (LocaleCompare(map,"I") == 0) |
| 3791 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3792 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3793 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3794 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3795 | if (q == (Quantum *) NULL) |
| 3796 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3797 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3798 | { |
| 3799 | SetPixelGray(image,ScaleShortToQuantum(*p++),q); |
| 3800 | q+=GetPixelChannels(image); |
| 3801 | } |
| 3802 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3803 | break; |
| 3804 | } |
| 3805 | return; |
| 3806 | } |
| 3807 | if (LocaleCompare(map,"RGB") == 0) |
| 3808 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3809 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3810 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3811 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3812 | if (q == (Quantum *) NULL) |
| 3813 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3814 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3815 | { |
| 3816 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3817 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3818 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3819 | q+=GetPixelChannels(image); |
| 3820 | } |
| 3821 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3822 | break; |
| 3823 | } |
| 3824 | return; |
| 3825 | } |
| 3826 | if (LocaleCompare(map,"RGBA") == 0) |
| 3827 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3828 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3829 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3830 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3831 | if (q == (Quantum *) NULL) |
| 3832 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3833 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3834 | { |
| 3835 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3836 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3837 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3838 | SetPixelAlpha(image,ScaleShortToQuantum(*p++),q); |
| 3839 | q+=GetPixelChannels(image); |
| 3840 | } |
| 3841 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3842 | break; |
| 3843 | } |
| 3844 | return; |
| 3845 | } |
| 3846 | if (LocaleCompare(map,"RGBP") == 0) |
| 3847 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3848 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3849 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3850 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3851 | if (q == (Quantum *) NULL) |
| 3852 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3853 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3854 | { |
| 3855 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3856 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3857 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3858 | p++; |
| 3859 | q+=GetPixelChannels(image); |
| 3860 | } |
| 3861 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3862 | break; |
| 3863 | } |
| 3864 | return; |
| 3865 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3866 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3867 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3868 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3869 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3870 | if (q == (Quantum *) NULL) |
| 3871 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3872 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3873 | { |
| 3874 | register ssize_t |
| 3875 | i; |
| 3876 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3877 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3878 | { |
| 3879 | switch (quantum_map[i]) |
| 3880 | { |
| 3881 | case RedQuantum: |
| 3882 | case CyanQuantum: |
| 3883 | { |
| 3884 | SetPixelRed(image,ScaleShortToQuantum(*p),q); |
| 3885 | break; |
| 3886 | } |
| 3887 | case GreenQuantum: |
| 3888 | case MagentaQuantum: |
| 3889 | { |
| 3890 | SetPixelGreen(image,ScaleShortToQuantum(*p),q); |
| 3891 | break; |
| 3892 | } |
| 3893 | case BlueQuantum: |
| 3894 | case YellowQuantum: |
| 3895 | { |
| 3896 | SetPixelBlue(image,ScaleShortToQuantum(*p),q); |
| 3897 | break; |
| 3898 | } |
| 3899 | case AlphaQuantum: |
| 3900 | { |
| 3901 | SetPixelAlpha(image,ScaleShortToQuantum(*p),q); |
| 3902 | break; |
| 3903 | } |
| 3904 | case OpacityQuantum: |
| 3905 | { |
| 3906 | SetPixelAlpha(image,ScaleShortToQuantum(*p),q); |
| 3907 | break; |
| 3908 | } |
| 3909 | case BlackQuantum: |
| 3910 | { |
| 3911 | SetPixelBlack(image,ScaleShortToQuantum(*p),q); |
| 3912 | break; |
| 3913 | } |
| 3914 | case IndexQuantum: |
| 3915 | { |
| 3916 | SetPixelGray(image,ScaleShortToQuantum(*p),q); |
| 3917 | break; |
| 3918 | } |
| 3919 | default: |
| 3920 | break; |
| 3921 | } |
| 3922 | p++; |
| 3923 | } |
| 3924 | q+=GetPixelChannels(image); |
| 3925 | } |
| 3926 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3927 | break; |
| 3928 | } |
| 3929 | } |
| 3930 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3931 | MagickExport MagickBooleanType ImportImagePixels(Image *image,const ssize_t x, |
| 3932 | const ssize_t y,const size_t width,const size_t height,const char *map, |
| 3933 | const StorageType type,const void *pixels,ExceptionInfo *exception) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3934 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3935 | QuantumType |
| 3936 | *quantum_map; |
| 3937 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3938 | RectangleInfo |
| 3939 | roi; |
| 3940 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3941 | register ssize_t |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3942 | i; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3943 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3944 | size_t |
| 3945 | length; |
| 3946 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3947 | /* |
| 3948 | Allocate image structure. |
| 3949 | */ |
| 3950 | assert(image != (Image *) NULL); |
| 3951 | assert(image->signature == MagickSignature); |
| 3952 | if (image->debug != MagickFalse) |
| 3953 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3954 | length=strlen(map); |
| 3955 | quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3956 | if (quantum_map == (QuantumType *) NULL) |
| 3957 | ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", |
| 3958 | image->filename); |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3959 | for (i=0; i < (ssize_t) length; i++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3960 | { |
| 3961 | switch (map[i]) |
| 3962 | { |
| 3963 | case 'a': |
| 3964 | case 'A': |
| 3965 | { |
| 3966 | quantum_map[i]=AlphaQuantum; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 3967 | image->alpha_trait=BlendPixelTrait; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3968 | break; |
| 3969 | } |
| 3970 | case 'B': |
| 3971 | case 'b': |
| 3972 | { |
| 3973 | quantum_map[i]=BlueQuantum; |
| 3974 | break; |
| 3975 | } |
| 3976 | case 'C': |
| 3977 | case 'c': |
| 3978 | { |
| 3979 | quantum_map[i]=CyanQuantum; |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 3980 | (void) SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3981 | break; |
| 3982 | } |
| 3983 | case 'g': |
| 3984 | case 'G': |
| 3985 | { |
| 3986 | quantum_map[i]=GreenQuantum; |
| 3987 | break; |
| 3988 | } |
| 3989 | case 'K': |
| 3990 | case 'k': |
| 3991 | { |
| 3992 | quantum_map[i]=BlackQuantum; |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 3993 | (void) SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3994 | break; |
| 3995 | } |
| 3996 | case 'I': |
| 3997 | case 'i': |
| 3998 | { |
| 3999 | quantum_map[i]=IndexQuantum; |
cristy | b7b3da6 | 2012-07-05 15:43:37 +0000 | [diff] [blame] | 4000 | (void) SetImageColorspace(image,GRAYColorspace,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4001 | break; |
| 4002 | } |
| 4003 | case 'm': |
| 4004 | case 'M': |
| 4005 | { |
| 4006 | quantum_map[i]=MagentaQuantum; |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 4007 | (void) SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4008 | break; |
| 4009 | } |
| 4010 | case 'O': |
| 4011 | case 'o': |
| 4012 | { |
| 4013 | quantum_map[i]=OpacityQuantum; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 4014 | image->alpha_trait=BlendPixelTrait; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4015 | break; |
| 4016 | } |
| 4017 | case 'P': |
| 4018 | case 'p': |
| 4019 | { |
| 4020 | quantum_map[i]=UndefinedQuantum; |
| 4021 | break; |
| 4022 | } |
| 4023 | case 'R': |
| 4024 | case 'r': |
| 4025 | { |
| 4026 | quantum_map[i]=RedQuantum; |
| 4027 | break; |
| 4028 | } |
| 4029 | case 'Y': |
| 4030 | case 'y': |
| 4031 | { |
| 4032 | quantum_map[i]=YellowQuantum; |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 4033 | (void) SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4034 | break; |
| 4035 | } |
| 4036 | default: |
| 4037 | { |
| 4038 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 4039 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 4040 | "UnrecognizedPixelMap","`%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4041 | return(MagickFalse); |
| 4042 | } |
| 4043 | } |
| 4044 | } |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 4045 | if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4046 | return(MagickFalse); |
| 4047 | /* |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 4048 | Transfer the pixels from the pixel data to the image. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4049 | */ |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 4050 | roi.width=width; |
| 4051 | roi.height=height; |
| 4052 | roi.x=x; |
| 4053 | roi.y=y; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4054 | switch (type) |
| 4055 | { |
| 4056 | case CharPixel: |
| 4057 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 4058 | ImportCharPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4059 | break; |
| 4060 | } |
| 4061 | case DoublePixel: |
| 4062 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 4063 | ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4064 | break; |
| 4065 | } |
| 4066 | case FloatPixel: |
| 4067 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 4068 | ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4069 | break; |
| 4070 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4071 | case LongPixel: |
| 4072 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 4073 | ImportLongPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4074 | break; |
| 4075 | } |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 4076 | case LongLongPixel: |
| 4077 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 4078 | ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 4079 | break; |
| 4080 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4081 | case QuantumPixel: |
| 4082 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 4083 | ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4084 | break; |
| 4085 | } |
| 4086 | case ShortPixel: |
| 4087 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 4088 | ImportShortPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4089 | break; |
| 4090 | } |
| 4091 | default: |
| 4092 | { |
| 4093 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 4094 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 4095 | "UnrecognizedPixelMap","`%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4096 | break; |
| 4097 | } |
| 4098 | } |
| 4099 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 4100 | return(MagickTrue); |
| 4101 | } |
| 4102 | |
| 4103 | /* |
| 4104 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4105 | % % |
| 4106 | % % |
| 4107 | % % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 4108 | + I n i t i a l i z e P i x e l C h a n n e l M a p % |
| 4109 | % % |
| 4110 | % % |
| 4111 | % % |
| 4112 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4113 | % |
| 4114 | % InitializePixelChannelMap() defines the standard pixel component map. |
| 4115 | % |
| 4116 | % The format of the InitializePixelChannelMap() method is: |
| 4117 | % |
| 4118 | % void InitializePixelChannelMap(Image *image) |
| 4119 | % |
| 4120 | % A description of each parameter follows: |
| 4121 | % |
| 4122 | % o image: the image. |
| 4123 | % |
| 4124 | */ |
cristy | 021216a | 2013-05-20 16:25:51 +0000 | [diff] [blame] | 4125 | |
| 4126 | static void LogPixelChannels(const Image *image) |
| 4127 | { |
| 4128 | register ssize_t |
| 4129 | i; |
| 4130 | |
| 4131 | (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%.20g]", |
| 4132 | image->filename,(double) image->number_channels); |
| 4133 | for (i=0; i < (ssize_t) image->number_channels; i++) |
| 4134 | { |
| 4135 | char |
| 4136 | traits[MaxTextExtent]; |
| 4137 | |
| 4138 | const char |
| 4139 | *name; |
| 4140 | |
| 4141 | PixelChannel |
| 4142 | channel; |
| 4143 | |
| 4144 | switch (GetPixelChannelChannel(image,i)) |
| 4145 | { |
| 4146 | case RedPixelChannel: |
| 4147 | { |
| 4148 | name="red"; |
| 4149 | if (image->colorspace == CMYKColorspace) |
| 4150 | name="cyan"; |
| 4151 | if (image->colorspace == GRAYColorspace) |
| 4152 | name="gray"; |
| 4153 | break; |
| 4154 | } |
| 4155 | case GreenPixelChannel: |
| 4156 | { |
| 4157 | name="green"; |
| 4158 | if (image->colorspace == CMYKColorspace) |
| 4159 | name="magenta"; |
| 4160 | break; |
| 4161 | } |
| 4162 | case BluePixelChannel: |
| 4163 | { |
| 4164 | name="blue"; |
| 4165 | if (image->colorspace == CMYKColorspace) |
| 4166 | name="yellow"; |
| 4167 | break; |
| 4168 | } |
| 4169 | case BlackPixelChannel: |
| 4170 | { |
| 4171 | name="black"; |
| 4172 | if (image->storage_class == PseudoClass) |
| 4173 | name="index"; |
| 4174 | break; |
| 4175 | } |
| 4176 | case IndexPixelChannel: |
| 4177 | { |
| 4178 | name="index"; |
| 4179 | break; |
| 4180 | } |
| 4181 | case AlphaPixelChannel: |
| 4182 | { |
| 4183 | name="alpha"; |
| 4184 | break; |
| 4185 | } |
| 4186 | case ReadMaskPixelChannel: |
| 4187 | { |
cristy | 0481714 | 2013-05-20 17:14:03 +0000 | [diff] [blame^] | 4188 | name="read-mask"; |
cristy | 021216a | 2013-05-20 16:25:51 +0000 | [diff] [blame] | 4189 | break; |
| 4190 | } |
| 4191 | case WriteMaskPixelChannel: |
| 4192 | { |
cristy | 0481714 | 2013-05-20 17:14:03 +0000 | [diff] [blame^] | 4193 | name="write-mask"; |
cristy | 021216a | 2013-05-20 16:25:51 +0000 | [diff] [blame] | 4194 | break; |
| 4195 | } |
| 4196 | case MetaPixelChannel: |
| 4197 | { |
| 4198 | name="meta"; |
| 4199 | break; |
| 4200 | } |
| 4201 | default: |
| 4202 | name="undefined"; |
| 4203 | } |
| 4204 | channel=GetPixelChannelChannel(image,i); |
| 4205 | *traits='\0'; |
| 4206 | if ((GetPixelChannelTraits(image,channel) & UpdatePixelTrait) != 0) |
| 4207 | (void) ConcatenateMagickString(traits,"update,",MaxTextExtent); |
| 4208 | if ((GetPixelChannelTraits(image,channel) & BlendPixelTrait) != 0) |
| 4209 | (void) ConcatenateMagickString(traits,"blend,",MaxTextExtent); |
| 4210 | if ((GetPixelChannelTraits(image,channel) & CopyPixelTrait) != 0) |
| 4211 | (void) ConcatenateMagickString(traits,"copy,",MaxTextExtent); |
| 4212 | if (*traits == '\0') |
| 4213 | (void) ConcatenateMagickString(traits,"undefined,",MaxTextExtent); |
| 4214 | traits[strlen(traits)-1]='\0'; |
| 4215 | (void) LogMagickEvent(PixelEvent,GetMagickModule()," %.20g: %s (%s)", |
| 4216 | (double) i,name,traits); |
| 4217 | } |
| 4218 | } |
| 4219 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 4220 | MagickExport void InitializePixelChannelMap(Image *image) |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 4221 | { |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 4222 | PixelTrait |
| 4223 | trait; |
| 4224 | |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 4225 | register ssize_t |
| 4226 | i; |
| 4227 | |
cristy | d26338f | 2011-12-14 02:39:30 +0000 | [diff] [blame] | 4228 | ssize_t |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 4229 | n; |
| 4230 | |
| 4231 | assert(image != (Image *) NULL); |
| 4232 | assert(image->signature == MagickSignature); |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 4233 | (void) ResetMagickMemory(image->channel_map,0,MaxPixelChannels* |
| 4234 | sizeof(*image->channel_map)); |
| 4235 | trait=UpdatePixelTrait; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 4236 | if (image->alpha_trait == BlendPixelTrait) |
cristy | 61f18ad | 2011-12-08 21:12:37 +0000 | [diff] [blame] | 4237 | trait=(PixelTrait) (trait | BlendPixelTrait); |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 4238 | n=0; |
cristy | c06c580 | 2011-12-31 23:36:16 +0000 | [diff] [blame] | 4239 | if (image->colorspace == GRAYColorspace) |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 4240 | { |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4241 | SetPixelChannelAttributes(image,BluePixelChannel,trait,n); |
| 4242 | SetPixelChannelAttributes(image,GreenPixelChannel,trait,n); |
| 4243 | SetPixelChannelAttributes(image,RedPixelChannel,trait,n++); |
cristy | 3c31628 | 2011-12-15 15:43:24 +0000 | [diff] [blame] | 4244 | } |
| 4245 | else |
| 4246 | { |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4247 | SetPixelChannelAttributes(image,RedPixelChannel,trait,n++); |
| 4248 | SetPixelChannelAttributes(image,GreenPixelChannel,trait,n++); |
| 4249 | SetPixelChannelAttributes(image,BluePixelChannel,trait,n++); |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 4250 | } |
| 4251 | if (image->colorspace == CMYKColorspace) |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4252 | SetPixelChannelAttributes(image,BlackPixelChannel,trait,n++); |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 4253 | if (image->alpha_trait != UndefinedPixelTrait) |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4254 | SetPixelChannelAttributes(image,AlphaPixelChannel,CopyPixelTrait,n++); |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 4255 | if (image->storage_class == PseudoClass) |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4256 | SetPixelChannelAttributes(image,IndexPixelChannel,CopyPixelTrait,n++); |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 4257 | if (image->read_mask != MagickFalse) |
| 4258 | SetPixelChannelAttributes(image,ReadMaskPixelChannel,CopyPixelTrait,n++); |
| 4259 | if (image->write_mask != MagickFalse) |
| 4260 | SetPixelChannelAttributes(image,WriteMaskPixelChannel,CopyPixelTrait,n++); |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 4261 | assert((n+image->number_meta_channels) < MaxPixelChannels); |
| 4262 | for (i=0; i < (ssize_t) image->number_meta_channels; i++) |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4263 | SetPixelChannelAttributes(image,(PixelChannel) (MetaPixelChannel+i), |
| 4264 | CopyPixelTrait,n++); |
cristy | d26338f | 2011-12-14 02:39:30 +0000 | [diff] [blame] | 4265 | image->number_channels=(size_t) n; |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 4266 | if (image->debug != MagickFalse) |
| 4267 | LogPixelChannels(image); |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4268 | (void) SetImageChannelMask(image,image->channel_mask); |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 4269 | } |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 4270 | |
| 4271 | /* |
| 4272 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4273 | % % |
| 4274 | % % |
| 4275 | % % |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4276 | % I n t e r p o l a t e P i x e l C h a n n e l % |
| 4277 | % % |
| 4278 | % % |
| 4279 | % % |
| 4280 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4281 | % |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4282 | % InterpolatePixelChannel() applies a pixel interpolation method between a |
| 4283 | % floating point coordinate and the pixels surrounding that coordinate. No |
| 4284 | % pixel area resampling, or scaling of the result is performed. |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4285 | % |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4286 | % Interpolation is restricted to just the specified channel. |
| 4287 | % |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4288 | % The format of the InterpolatePixelChannel method is: |
| 4289 | % |
| 4290 | % MagickBooleanType InterpolatePixelChannel(const Image *image, |
cristy | 444eda6 | 2011-08-10 02:07:46 +0000 | [diff] [blame] | 4291 | % const CacheView *image_view,const PixelChannel channel, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4292 | % const PixelInterpolateMethod method,const double x,const double y, |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4293 | % double *pixel,ExceptionInfo *exception) |
| 4294 | % |
| 4295 | % A description of each parameter follows: |
| 4296 | % |
| 4297 | % o image: the image. |
| 4298 | % |
| 4299 | % o image_view: the image view. |
| 4300 | % |
| 4301 | % o channel: the pixel channel to interpolate. |
| 4302 | % |
| 4303 | % o method: the pixel color interpolation method. |
| 4304 | % |
| 4305 | % o x,y: A double representing the current (x,y) position of the pixel. |
| 4306 | % |
| 4307 | % o pixel: return the interpolated pixel here. |
| 4308 | % |
| 4309 | % o exception: return any errors or warnings in this structure. |
| 4310 | % |
| 4311 | */ |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4312 | |
cristy | b0a657e | 2012-08-29 00:45:37 +0000 | [diff] [blame] | 4313 | static inline void CatromWeights(const double x,double (*weights)[4]) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4314 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4315 | double |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4316 | alpha, |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4317 | beta, |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4318 | gamma; |
| 4319 | |
cristy | 5a5e4d9 | 2012-08-29 00:06:25 +0000 | [diff] [blame] | 4320 | /* |
| 4321 | Nicolas Robidoux' 10 flops (4* + 5- + 1+) refactoring of the computation |
| 4322 | of the standard four 1D Catmull-Rom weights. The sampling location is |
| 4323 | assumed between the second and third input pixel locations, and x is the |
| 4324 | position relative to the second input pixel location. Formulas originally |
| 4325 | derived for the VIPS (Virtual Image Processing System) library. |
| 4326 | */ |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4327 | alpha=(double) 1.0-x; |
| 4328 | beta=(double) (-0.5)*x*alpha; |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4329 | (*weights)[0]=alpha*beta; |
| 4330 | (*weights)[3]=x*beta; |
| 4331 | /* |
cristy | 5a5e4d9 | 2012-08-29 00:06:25 +0000 | [diff] [blame] | 4332 | The following computation of the inner weights from the outer ones work |
| 4333 | for all Keys cubics. |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4334 | */ |
| 4335 | gamma=(*weights)[3]-(*weights)[0]; |
| 4336 | (*weights)[1]=alpha-(*weights)[0]+gamma; |
| 4337 | (*weights)[2]=x-(*weights)[3]-gamma; |
| 4338 | } |
| 4339 | |
cristy | b0a657e | 2012-08-29 00:45:37 +0000 | [diff] [blame] | 4340 | static inline void SplineWeights(const double x,double (*weights)[4]) |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4341 | { |
cristy | 5a5e4d9 | 2012-08-29 00:06:25 +0000 | [diff] [blame] | 4342 | double |
| 4343 | alpha, |
| 4344 | beta; |
| 4345 | |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4346 | /* |
| 4347 | Nicolas Robidoux' 12 flops (6* + 5- + 1+) refactoring of the |
| 4348 | computation of the standard four 1D cubic B-spline smoothing |
| 4349 | weights. The sampling location is assumed between the second and |
| 4350 | third input pixel locations, and x is the position relative to the |
| 4351 | second input pixel location. |
| 4352 | */ |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4353 | alpha=(double) 1.0-x; |
| 4354 | (*weights)[3]=(double) (1.0/6.0)*x*x*x; |
| 4355 | (*weights)[0]=(double) (1.0/6.0)*alpha*alpha*alpha; |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4356 | beta=(*weights)[3]-(*weights)[0]; |
| 4357 | (*weights)[1]=alpha-(*weights)[0]+beta; |
| 4358 | (*weights)[2]=x-(*weights)[3]-beta; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4359 | } |
| 4360 | |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4361 | static inline double MeshInterpolate(const PointInfo *delta,const double p, |
| 4362 | const double x,const double y) |
| 4363 | { |
| 4364 | return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p); |
| 4365 | } |
| 4366 | |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4367 | /* |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4368 | static inline ssize_t NearestNeighbor(const double x) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4369 | { |
| 4370 | if (x >= 0.0) |
| 4371 | return((ssize_t) (x+0.5)); |
| 4372 | return((ssize_t) (x-0.5)); |
| 4373 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4374 | */ |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4375 | |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4376 | MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image, |
| 4377 | const CacheView *image_view,const PixelChannel channel, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4378 | const PixelInterpolateMethod method,const double x,const double y, |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4379 | double *pixel,ExceptionInfo *exception) |
| 4380 | { |
| 4381 | MagickBooleanType |
| 4382 | status; |
| 4383 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4384 | double |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4385 | alpha[16], |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4386 | gamma, |
| 4387 | pixels[16]; |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4388 | |
| 4389 | PixelTrait |
| 4390 | traits; |
| 4391 | |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4392 | register const Quantum |
| 4393 | *p; |
| 4394 | |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4395 | register ssize_t |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4396 | i; |
| 4397 | |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4398 | ssize_t |
| 4399 | x_offset, |
| 4400 | y_offset; |
| 4401 | |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4402 | PixelInterpolateMethod |
| 4403 | interpolate; |
| 4404 | |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4405 | assert(image != (Image *) NULL); |
| 4406 | assert(image != (Image *) NULL); |
| 4407 | assert(image->signature == MagickSignature); |
| 4408 | assert(image_view != (CacheView *) NULL); |
| 4409 | status=MagickTrue; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4410 | *pixel=0.0; |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4411 | traits=GetPixelChannelTraits(image,channel); |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4412 | x_offset=(ssize_t) floor(x); |
| 4413 | y_offset=(ssize_t) floor(y); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4414 | interpolate = method; |
| 4415 | if ( interpolate == UndefinedInterpolatePixel ) |
| 4416 | interpolate = image->interpolate; |
| 4417 | switch (interpolate) |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4418 | { |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4419 | case AverageInterpolatePixel: /* nearest 4 neighbours */ |
| 4420 | case Average9InterpolatePixel: /* nearest 9 neighbours */ |
| 4421 | case Average16InterpolatePixel: /* nearest 16 neighbours */ |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4422 | { |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4423 | ssize_t |
| 4424 | count; |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4425 | |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4426 | count=2; /* size of the area to average - default nearest 4 */ |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4427 | if (interpolate == Average9InterpolatePixel) |
| 4428 | { |
| 4429 | count=3; |
| 4430 | x_offset=(ssize_t) (floor(x+0.5)-1); |
| 4431 | y_offset=(ssize_t) (floor(y+0.5)-1); |
| 4432 | } |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4433 | else |
| 4434 | if (interpolate == Average16InterpolatePixel) |
| 4435 | { |
| 4436 | count=4; |
| 4437 | x_offset--; |
| 4438 | y_offset--; |
| 4439 | } |
cristy | 021216a | 2013-05-20 16:25:51 +0000 | [diff] [blame] | 4440 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(size_t) count, |
| 4441 | (size_t) count,exception); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4442 | if (p == (const Quantum *) NULL) |
| 4443 | { |
| 4444 | status=MagickFalse; |
| 4445 | break; |
| 4446 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4447 | count*=count; /* Number of pixels to Average */ |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 4448 | if ((traits & BlendPixelTrait) == 0) |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4449 | for (i=0; i < (ssize_t) count; i++) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4450 | { |
| 4451 | alpha[i]=1.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4452 | pixels[i]=(double) p[i*GetPixelChannels(image)+channel]; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4453 | } |
| 4454 | else |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4455 | for (i=0; i < (ssize_t) count; i++) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4456 | { |
| 4457 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4458 | GetPixelChannels(image)); |
| 4459 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4460 | } |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4461 | for (i=0; i < (ssize_t) count; i++) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4462 | { |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4463 | gamma=PerceptibleReciprocal(alpha[i])/count; |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4464 | *pixel+=gamma*pixels[i]; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4465 | } |
| 4466 | break; |
| 4467 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4468 | case BilinearInterpolatePixel: |
| 4469 | default: |
| 4470 | { |
| 4471 | PointInfo |
| 4472 | delta, |
| 4473 | epsilon; |
| 4474 | |
| 4475 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
| 4476 | if (p == (const Quantum *) NULL) |
| 4477 | { |
| 4478 | status=MagickFalse; |
| 4479 | break; |
| 4480 | } |
| 4481 | if ((traits & BlendPixelTrait) == 0) |
| 4482 | for (i=0; i < 4; i++) |
| 4483 | { |
| 4484 | alpha[i]=1.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4485 | pixels[i]=(double) p[i*GetPixelChannels(image)+channel]; |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4486 | } |
| 4487 | else |
| 4488 | for (i=0; i < 4; i++) |
| 4489 | { |
| 4490 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4491 | GetPixelChannels(image)); |
| 4492 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4493 | } |
| 4494 | delta.x=x-x_offset; |
| 4495 | delta.y=y-y_offset; |
| 4496 | epsilon.x=1.0-delta.x; |
| 4497 | epsilon.y=1.0-delta.y; |
| 4498 | gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y* |
| 4499 | (epsilon.x*alpha[2]+delta.x*alpha[3]))); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4500 | gamma=PerceptibleReciprocal(gamma); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4501 | *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y* |
| 4502 | (epsilon.x*pixels[2]+delta.x*pixels[3])); |
| 4503 | break; |
| 4504 | } |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 4505 | case BlendInterpolatePixel: |
| 4506 | { |
| 4507 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
| 4508 | if (p == (const Quantum *) NULL) |
| 4509 | { |
| 4510 | status=MagickFalse; |
| 4511 | break; |
| 4512 | } |
| 4513 | if ((traits & BlendPixelTrait) == 0) |
| 4514 | for (i=0; i < 4; i++) |
| 4515 | { |
| 4516 | alpha[i]=1.0; |
| 4517 | pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel]; |
| 4518 | } |
| 4519 | else |
| 4520 | for (i=0; i < 4; i++) |
| 4521 | { |
| 4522 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4523 | GetPixelChannels(image)); |
| 4524 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4525 | } |
| 4526 | gamma=1.0; /* number of pixels blended together (its variable) */ |
| 4527 | for (i=0; i <= 1L; i++) { |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4528 | if ((y-y_offset) >= 0.75) |
| 4529 | { |
| 4530 | alpha[i]=alpha[i+2]; /* take right pixels */ |
| 4531 | pixels[i]=pixels[i+2]; |
| 4532 | } |
| 4533 | else |
| 4534 | if ((y-y_offset) > 0.25) |
| 4535 | { |
| 4536 | gamma=2.0; /* blend both pixels in row */ |
| 4537 | alpha[i]+=alpha[i+2]; /* add up alpha weights */ |
| 4538 | pixels[i]+=pixels[i+2]; |
| 4539 | } |
| 4540 | } |
| 4541 | if ((x-x_offset) >= 0.75) |
| 4542 | { |
| 4543 | alpha[0]=alpha[1]; /* take bottom row blend */ |
| 4544 | pixels[0]=pixels[1]; |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 4545 | } |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4546 | else |
| 4547 | if ((x-x_offset) > 0.25) |
| 4548 | { |
| 4549 | gamma*=2.0; /* blend both rows */ |
| 4550 | alpha[0]+=alpha[1]; /* add up alpha weights */ |
| 4551 | pixels[0]+=pixels[1]; |
| 4552 | } |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 4553 | if (channel != AlphaPixelChannel) |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4554 | gamma=PerceptibleReciprocal(alpha[0]); /* (color) 1/alpha_weights */ |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 4555 | else |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4556 | gamma=PerceptibleReciprocal(gamma); /* (alpha) 1/number_of_pixels */ |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 4557 | *pixel=gamma*pixels[0]; |
| 4558 | break; |
| 4559 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4560 | case CatromInterpolatePixel: |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4561 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4562 | double |
cristy | 380a11c | 2012-06-02 15:15:22 +0000 | [diff] [blame] | 4563 | cx[4], |
nicolas | 6676f5a | 2012-06-12 16:01:15 +0000 | [diff] [blame] | 4564 | cy[4]; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4565 | |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4566 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 4567 | exception); |
| 4568 | if (p == (const Quantum *) NULL) |
| 4569 | { |
| 4570 | status=MagickFalse; |
| 4571 | break; |
| 4572 | } |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 4573 | if ((traits & BlendPixelTrait) == 0) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4574 | for (i=0; i < 16; i++) |
| 4575 | { |
| 4576 | alpha[i]=1.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4577 | pixels[i]=(double) p[i*GetPixelChannels(image)+channel]; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4578 | } |
| 4579 | else |
| 4580 | for (i=0; i < 16; i++) |
| 4581 | { |
| 4582 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4583 | GetPixelChannels(image)); |
| 4584 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4585 | } |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4586 | CatromWeights((double) (x-x_offset),&cx); |
| 4587 | CatromWeights((double) (y-y_offset),&cy); |
| 4588 | gamma=(channel == AlphaPixelChannel ? (double) 1.0 : |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4589 | PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]* |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4590 | alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]* |
| 4591 | alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]* |
| 4592 | alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+ |
| 4593 | cx[2]*alpha[14]+cx[3]*alpha[15]))); |
cristy | 380a11c | 2012-06-02 15:15:22 +0000 | [diff] [blame] | 4594 | *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+ |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4595 | cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]* |
| 4596 | pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+ |
| 4597 | cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]* |
| 4598 | pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15])); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4599 | break; |
| 4600 | } |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4601 | case IntegerInterpolatePixel: |
| 4602 | { |
| 4603 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception); |
| 4604 | if (p == (const Quantum *) NULL) |
| 4605 | { |
| 4606 | status=MagickFalse; |
| 4607 | break; |
| 4608 | } |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 4609 | *pixel=(double) GetPixelChannel(image,channel,p); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4610 | break; |
| 4611 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4612 | case NearestInterpolatePixel: |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4613 | { |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4614 | x_offset=(ssize_t) floor(x+0.5); |
| 4615 | y_offset=(ssize_t) floor(y+0.5); |
| 4616 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4617 | if (p == (const Quantum *) NULL) |
| 4618 | { |
| 4619 | status=MagickFalse; |
| 4620 | break; |
| 4621 | } |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 4622 | *pixel=(double) GetPixelChannel(image,channel,p); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4623 | break; |
| 4624 | } |
| 4625 | case MeshInterpolatePixel: |
| 4626 | { |
| 4627 | PointInfo |
| 4628 | delta, |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4629 | luminance; |
| 4630 | |
| 4631 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
| 4632 | if (p == (const Quantum *) NULL) |
| 4633 | { |
| 4634 | status=MagickFalse; |
| 4635 | break; |
| 4636 | } |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 4637 | if ((traits & BlendPixelTrait) == 0) |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4638 | for (i=0; i < 4; i++) |
| 4639 | { |
| 4640 | alpha[i]=1.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4641 | pixels[i]=(double) p[i*GetPixelChannels(image)+channel]; |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4642 | } |
| 4643 | else |
| 4644 | for (i=0; i < 4; i++) |
| 4645 | { |
| 4646 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4647 | GetPixelChannels(image)); |
| 4648 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4649 | } |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4650 | delta.x=x-x_offset; |
| 4651 | delta.y=y-y_offset; |
| 4652 | luminance.x=GetPixelLuminance(image,p)-(double) |
| 4653 | GetPixelLuminance(image,p+3*GetPixelChannels(image)); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 4654 | luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4655 | GetPixelLuminance(image,p+2*GetPixelChannels(image)); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4656 | if (fabs(luminance.x) < fabs(luminance.y)) |
| 4657 | { |
| 4658 | /* |
| 4659 | Diagonal 0-3 NW-SE. |
| 4660 | */ |
| 4661 | if (delta.x <= delta.y) |
| 4662 | { |
| 4663 | /* |
| 4664 | Bottom-left triangle (pixel: 2, diagonal: 0-3). |
| 4665 | */ |
| 4666 | delta.y=1.0-delta.y; |
| 4667 | gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4668 | gamma=PerceptibleReciprocal(gamma); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4669 | *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3], |
| 4670 | pixels[0]); |
| 4671 | } |
| 4672 | else |
| 4673 | { |
| 4674 | /* |
| 4675 | Top-right triangle (pixel: 1, diagonal: 0-3). |
| 4676 | */ |
| 4677 | delta.x=1.0-delta.x; |
| 4678 | gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4679 | gamma=PerceptibleReciprocal(gamma); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4680 | *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0], |
| 4681 | pixels[3]); |
| 4682 | } |
| 4683 | } |
| 4684 | else |
| 4685 | { |
| 4686 | /* |
| 4687 | Diagonal 1-2 NE-SW. |
| 4688 | */ |
| 4689 | if (delta.x <= (1.0-delta.y)) |
| 4690 | { |
| 4691 | /* |
| 4692 | Top-left triangle (pixel: 0, diagonal: 1-2). |
| 4693 | */ |
| 4694 | gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4695 | gamma=PerceptibleReciprocal(gamma); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4696 | *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1], |
| 4697 | pixels[2]); |
| 4698 | } |
| 4699 | else |
| 4700 | { |
| 4701 | /* |
| 4702 | Bottom-right triangle (pixel: 3, diagonal: 1-2). |
| 4703 | */ |
| 4704 | delta.x=1.0-delta.x; |
| 4705 | delta.y=1.0-delta.y; |
| 4706 | gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4707 | gamma=PerceptibleReciprocal(gamma); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4708 | *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2], |
| 4709 | pixels[1]); |
| 4710 | } |
| 4711 | } |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4712 | break; |
| 4713 | } |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4714 | case SplineInterpolatePixel: |
| 4715 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4716 | double |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4717 | cx[4], |
nicolas | 6676f5a | 2012-06-12 16:01:15 +0000 | [diff] [blame] | 4718 | cy[4]; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4719 | |
| 4720 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 4721 | exception); |
| 4722 | if (p == (const Quantum *) NULL) |
| 4723 | { |
| 4724 | status=MagickFalse; |
| 4725 | break; |
| 4726 | } |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 4727 | if ((traits & BlendPixelTrait) == 0) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4728 | for (i=0; i < 16; i++) |
| 4729 | { |
| 4730 | alpha[i]=1.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4731 | pixels[i]=(double) p[i*GetPixelChannels(image)+channel]; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4732 | } |
| 4733 | else |
| 4734 | for (i=0; i < 16; i++) |
| 4735 | { |
| 4736 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4737 | GetPixelChannels(image)); |
| 4738 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4739 | } |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4740 | SplineWeights((double) (x-x_offset),&cx); |
| 4741 | SplineWeights((double) (y-y_offset),&cy); |
| 4742 | gamma=(channel == AlphaPixelChannel ? (double) 1.0 : |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4743 | PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]* |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4744 | alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]* |
| 4745 | alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]* |
| 4746 | alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+ |
| 4747 | cx[2]*alpha[14]+cx[3]*alpha[15]))); |
| 4748 | *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+ |
| 4749 | cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]* |
| 4750 | pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+ |
| 4751 | cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]* |
| 4752 | pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15])); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4753 | break; |
| 4754 | } |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4755 | } |
| 4756 | return(status); |
| 4757 | } |
| 4758 | |
| 4759 | /* |
| 4760 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4761 | % % |
| 4762 | % % |
| 4763 | % % |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4764 | % I n t e r p o l a t e P i x e l C h a n n e l s % |
| 4765 | % % |
| 4766 | % % |
| 4767 | % % |
| 4768 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4769 | % |
| 4770 | % InterpolatePixelChannels() applies a pixel interpolation method between a |
| 4771 | % floating point coordinate and the pixels surrounding that coordinate. No |
| 4772 | % pixel area resampling, or scaling of the result is performed. |
| 4773 | % |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4774 | % Interpolation is restricted to just the current channel setting of the |
| 4775 | % destination image into which the color is to be stored |
| 4776 | % |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4777 | % The format of the InterpolatePixelChannels method is: |
| 4778 | % |
| 4779 | % MagickBooleanType InterpolatePixelChannels(const Image *source, |
| 4780 | % const CacheView *source_view,const Image *destination, |
| 4781 | % const PixelInterpolateMethod method,const double x,const double y, |
| 4782 | % Quantum *pixel,ExceptionInfo *exception) |
| 4783 | % |
| 4784 | % A description of each parameter follows: |
| 4785 | % |
| 4786 | % o source: the source. |
| 4787 | % |
| 4788 | % o source_view: the source view. |
| 4789 | % |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4790 | % o destination: the destination image, for the interpolated color |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4791 | % |
| 4792 | % o method: the pixel color interpolation method. |
| 4793 | % |
| 4794 | % o x,y: A double representing the current (x,y) position of the pixel. |
| 4795 | % |
| 4796 | % o pixel: return the interpolated pixel here. |
| 4797 | % |
| 4798 | % o exception: return any errors or warnings in this structure. |
| 4799 | % |
| 4800 | */ |
| 4801 | MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source, |
| 4802 | const CacheView *source_view,const Image *destination, |
| 4803 | const PixelInterpolateMethod method,const double x,const double y, |
| 4804 | Quantum *pixel,ExceptionInfo *exception) |
| 4805 | { |
| 4806 | MagickBooleanType |
| 4807 | status; |
| 4808 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4809 | double |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4810 | alpha[16], |
| 4811 | gamma, |
| 4812 | pixels[16]; |
| 4813 | |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4814 | register const Quantum |
| 4815 | *p; |
| 4816 | |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4817 | register ssize_t |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4818 | i; |
| 4819 | |
| 4820 | ssize_t |
| 4821 | x_offset, |
| 4822 | y_offset; |
| 4823 | |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4824 | PixelInterpolateMethod |
| 4825 | interpolate; |
| 4826 | |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4827 | assert(source != (Image *) NULL); |
| 4828 | assert(source != (Image *) NULL); |
| 4829 | assert(source->signature == MagickSignature); |
| 4830 | assert(source_view != (CacheView *) NULL); |
| 4831 | status=MagickTrue; |
| 4832 | x_offset=(ssize_t) floor(x); |
| 4833 | y_offset=(ssize_t) floor(y); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4834 | interpolate = method; |
| 4835 | if ( interpolate == UndefinedInterpolatePixel ) |
| 4836 | interpolate = source->interpolate; |
| 4837 | switch (interpolate) |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4838 | { |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4839 | case AverageInterpolatePixel: /* nearest 4 neighbours */ |
| 4840 | case Average9InterpolatePixel: /* nearest 9 neighbours */ |
| 4841 | case Average16InterpolatePixel: /* nearest 16 neighbours */ |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4842 | { |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4843 | ssize_t |
| 4844 | count; |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4845 | |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4846 | count=2; /* size of the area to average - default nearest 4 */ |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4847 | if (interpolate == Average9InterpolatePixel) |
| 4848 | { |
| 4849 | count=3; |
| 4850 | x_offset=(ssize_t) (floor(x+0.5)-1); |
| 4851 | y_offset=(ssize_t) (floor(y+0.5)-1); |
| 4852 | } |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4853 | else |
| 4854 | if (interpolate == Average16InterpolatePixel) |
| 4855 | { |
| 4856 | count=4; |
| 4857 | x_offset--; |
| 4858 | y_offset--; |
| 4859 | } |
cristy | 1b72b81 | 2013-04-19 00:57:44 +0000 | [diff] [blame] | 4860 | p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,(size_t) count, |
| 4861 | (size_t) count,exception); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4862 | if (p == (const Quantum *) NULL) |
| 4863 | { |
| 4864 | status=MagickFalse; |
| 4865 | break; |
| 4866 | } |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4867 | count*=count; /* Number of pixels to Average */ |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4868 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4869 | { |
| 4870 | double |
| 4871 | sum; |
| 4872 | |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4873 | register ssize_t |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4874 | j; |
| 4875 | |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 4876 | PixelChannel channel=GetPixelChannelChannel(source,i); |
| 4877 | PixelTrait traits=GetPixelChannelTraits(source,channel); |
| 4878 | PixelTrait destination_traits=GetPixelChannelTraits(destination, |
| 4879 | channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4880 | if ((traits == UndefinedPixelTrait) || |
| 4881 | (destination_traits == UndefinedPixelTrait)) |
| 4882 | continue; |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4883 | for (j=0; j < (ssize_t) count; j++) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4884 | pixels[j]=(double) p[j*GetPixelChannels(source)+i]; |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4885 | sum=0.0; |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4886 | if ((traits & BlendPixelTrait) == 0) |
| 4887 | { |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4888 | for (j=0; j < (ssize_t) count; j++) |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4889 | sum+=pixels[j]; |
| 4890 | sum/=count; |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4891 | SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4892 | continue; |
| 4893 | } |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4894 | for (j=0; j < (ssize_t) count; j++) |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4895 | { |
| 4896 | alpha[j]=QuantumScale*GetPixelAlpha(source,p+j* |
| 4897 | GetPixelChannels(source)); |
| 4898 | pixels[j]*=alpha[j]; |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4899 | gamma=PerceptibleReciprocal(alpha[j]); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4900 | sum+=gamma*pixels[j]; |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4901 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4902 | sum/=count; |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4903 | SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4904 | } |
| 4905 | break; |
| 4906 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4907 | case BilinearInterpolatePixel: |
| 4908 | default: |
| 4909 | { |
| 4910 | p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception); |
| 4911 | if (p == (const Quantum *) NULL) |
| 4912 | { |
| 4913 | status=MagickFalse; |
| 4914 | break; |
| 4915 | } |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4916 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4917 | { |
| 4918 | PointInfo |
| 4919 | delta, |
| 4920 | epsilon; |
| 4921 | |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 4922 | PixelChannel channel=GetPixelChannelChannel(source,i); |
| 4923 | PixelTrait traits=GetPixelChannelTraits(source,channel); |
| 4924 | PixelTrait destination_traits=GetPixelChannelTraits(destination, |
| 4925 | channel); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4926 | if ((traits == UndefinedPixelTrait) || |
| 4927 | (destination_traits == UndefinedPixelTrait)) |
| 4928 | continue; |
| 4929 | delta.x=x-x_offset; |
| 4930 | delta.y=y-y_offset; |
| 4931 | epsilon.x=1.0-delta.x; |
| 4932 | epsilon.y=1.0-delta.y; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4933 | pixels[0]=(double) p[i]; |
| 4934 | pixels[1]=(double) p[GetPixelChannels(source)+i]; |
| 4935 | pixels[2]=(double) p[2*GetPixelChannels(source)+i]; |
| 4936 | pixels[3]=(double) p[3*GetPixelChannels(source)+i]; |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4937 | if ((traits & BlendPixelTrait) == 0) |
| 4938 | { |
| 4939 | gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x))); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4940 | gamma=PerceptibleReciprocal(gamma); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4941 | SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y* |
| 4942 | (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x* |
| 4943 | pixels[2]+delta.x*pixels[3]))),pixel); |
| 4944 | continue; |
| 4945 | } |
| 4946 | alpha[0]=QuantumScale*GetPixelAlpha(source,p); |
| 4947 | alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source)); |
| 4948 | alpha[2]=QuantumScale*GetPixelAlpha(source,p+2* |
| 4949 | GetPixelChannels(source)); |
| 4950 | alpha[3]=QuantumScale*GetPixelAlpha(source,p+3* |
| 4951 | GetPixelChannels(source)); |
| 4952 | pixels[0]*=alpha[0]; |
| 4953 | pixels[1]*=alpha[1]; |
| 4954 | pixels[2]*=alpha[2]; |
| 4955 | pixels[3]*=alpha[3]; |
| 4956 | gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y* |
| 4957 | (epsilon.x*alpha[2]+delta.x*alpha[3]))); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4958 | gamma=PerceptibleReciprocal(gamma); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4959 | SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y* |
| 4960 | (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+ |
| 4961 | delta.x*pixels[3]))),pixel); |
| 4962 | } |
| 4963 | break; |
| 4964 | } |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 4965 | case BlendInterpolatePixel: |
| 4966 | { |
| 4967 | p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception); |
| 4968 | if (p == (const Quantum *) NULL) |
| 4969 | { |
| 4970 | status=MagickFalse; |
| 4971 | break; |
| 4972 | } |
| 4973 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
| 4974 | { |
| 4975 | register ssize_t |
| 4976 | j; |
| 4977 | |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 4978 | PixelChannel channel=GetPixelChannelChannel(source,i); |
| 4979 | PixelTrait traits=GetPixelChannelTraits(source,channel); |
| 4980 | PixelTrait destination_traits=GetPixelChannelTraits(destination, |
| 4981 | channel); |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 4982 | if ((traits == UndefinedPixelTrait) || |
| 4983 | (destination_traits == UndefinedPixelTrait)) |
| 4984 | continue; |
| 4985 | if ((traits & BlendPixelTrait) == 0) |
| 4986 | for (j=0; j < 4; j++) |
| 4987 | { |
| 4988 | alpha[j]=1.0; |
| 4989 | pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+channel]; |
| 4990 | } |
| 4991 | else |
| 4992 | for (j=0; j < 4; j++) |
| 4993 | { |
| 4994 | alpha[j]=QuantumScale*GetPixelAlpha(source,p+j* |
| 4995 | GetPixelChannels(source)); |
| 4996 | pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+channel]; |
| 4997 | } |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4998 | gamma=1.0; /* number of pixels blended together (its variable) */ |
| 4999 | for (j=0; j <= 1L; j++) |
| 5000 | { |
| 5001 | if ((y-y_offset) >= 0.75) |
| 5002 | { |
| 5003 | alpha[j]=alpha[j+2]; /* take right pixels */ |
| 5004 | pixels[j]=pixels[j+2]; |
| 5005 | } |
| 5006 | else |
| 5007 | if ((y-y_offset) > 0.25) |
| 5008 | { |
| 5009 | gamma=2.0; /* blend both pixels in row */ |
| 5010 | alpha[j]+=alpha[j+2]; /* add up alpha weights */ |
| 5011 | pixels[j]+=pixels[j+2]; |
| 5012 | } |
| 5013 | } |
| 5014 | if ((x-x_offset) >= 0.75) |
| 5015 | { |
| 5016 | alpha[0]=alpha[1]; /* take bottom row blend */ |
| 5017 | pixels[0]=pixels[1]; |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 5018 | } |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5019 | else |
| 5020 | if ((x-x_offset) > 0.25) |
| 5021 | { |
| 5022 | gamma*=2.0; /* blend both rows */ |
| 5023 | alpha[0]+=alpha[1]; /* add up alpha weights */ |
| 5024 | pixels[0]+=pixels[1]; |
| 5025 | } |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 5026 | if ((traits & BlendPixelTrait) == 0) |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5027 | gamma=PerceptibleReciprocal(alpha[0]); /* (color) 1/alpha_weights */ |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 5028 | else |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5029 | gamma=PerceptibleReciprocal(gamma); /* (alpha) 1/number_of_pixels */ |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 5030 | SetPixelChannel(destination,channel,ClampToQuantum(gamma*pixels[0]), |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5031 | pixel); |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 5032 | } |
| 5033 | break; |
| 5034 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5035 | case CatromInterpolatePixel: |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5036 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5037 | double |
cristy | 380a11c | 2012-06-02 15:15:22 +0000 | [diff] [blame] | 5038 | cx[4], |
| 5039 | cy[4]; |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5040 | |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5041 | p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4, |
| 5042 | exception); |
| 5043 | if (p == (const Quantum *) NULL) |
| 5044 | { |
| 5045 | status=MagickFalse; |
| 5046 | break; |
| 5047 | } |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 5048 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5049 | { |
| 5050 | register ssize_t |
| 5051 | j; |
| 5052 | |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 5053 | PixelChannel channel=GetPixelChannelChannel(source,i); |
| 5054 | PixelTrait traits=GetPixelChannelTraits(source,channel); |
| 5055 | PixelTrait destination_traits=GetPixelChannelTraits(destination, |
| 5056 | channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5057 | if ((traits == UndefinedPixelTrait) || |
| 5058 | (destination_traits == UndefinedPixelTrait)) |
| 5059 | continue; |
| 5060 | if ((traits & BlendPixelTrait) == 0) |
| 5061 | for (j=0; j < 16; j++) |
| 5062 | { |
| 5063 | alpha[j]=1.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5064 | pixels[j]=(double) p[j*GetPixelChannels(source)+i]; |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5065 | } |
| 5066 | else |
| 5067 | for (j=0; j < 16; j++) |
| 5068 | { |
| 5069 | alpha[j]=QuantumScale*GetPixelAlpha(source,p+j* |
| 5070 | GetPixelChannels(source)); |
| 5071 | pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i]; |
| 5072 | } |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5073 | CatromWeights((double) (x-x_offset),&cx); |
| 5074 | CatromWeights((double) (y-y_offset),&cy); |
| 5075 | gamma=((traits & BlendPixelTrait) ? (double) (1.0) : |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5076 | PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]* |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 5077 | alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]* |
| 5078 | alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]* |
| 5079 | alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+ |
| 5080 | cx[2]*alpha[14]+cx[3]*alpha[15]))); |
cristy | 380a11c | 2012-06-02 15:15:22 +0000 | [diff] [blame] | 5081 | SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]* |
| 5082 | pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]* |
| 5083 | (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+ |
| 5084 | cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]* |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 5085 | pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]* |
| 5086 | pixels[14]+cx[3]*pixels[15]))),pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5087 | } |
| 5088 | break; |
| 5089 | } |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5090 | case IntegerInterpolatePixel: |
| 5091 | { |
| 5092 | p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception); |
| 5093 | if (p == (const Quantum *) NULL) |
| 5094 | { |
| 5095 | status=MagickFalse; |
| 5096 | break; |
| 5097 | } |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 5098 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5099 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 5100 | PixelChannel channel=GetPixelChannelChannel(source,i); |
| 5101 | PixelTrait traits=GetPixelChannelTraits(source,channel); |
| 5102 | PixelTrait destination_traits=GetPixelChannelTraits(destination, |
| 5103 | channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5104 | if ((traits == UndefinedPixelTrait) || |
| 5105 | (destination_traits == UndefinedPixelTrait)) |
| 5106 | continue; |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 5107 | SetPixelChannel(destination,channel,p[i],pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5108 | } |
| 5109 | break; |
| 5110 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5111 | case NearestInterpolatePixel: |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5112 | { |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5113 | x_offset=(ssize_t) floor(x+0.5); |
| 5114 | y_offset=(ssize_t) floor(y+0.5); |
| 5115 | p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5116 | if (p == (const Quantum *) NULL) |
| 5117 | { |
| 5118 | status=MagickFalse; |
| 5119 | break; |
| 5120 | } |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 5121 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5122 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 5123 | PixelChannel channel=GetPixelChannelChannel(source,i); |
| 5124 | PixelTrait traits=GetPixelChannelTraits(source,channel); |
| 5125 | PixelTrait destination_traits=GetPixelChannelTraits(destination, |
| 5126 | channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5127 | if ((traits == UndefinedPixelTrait) || |
| 5128 | (destination_traits == UndefinedPixelTrait)) |
| 5129 | continue; |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 5130 | SetPixelChannel(destination,channel,p[i],pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5131 | } |
| 5132 | break; |
| 5133 | } |
| 5134 | case MeshInterpolatePixel: |
| 5135 | { |
| 5136 | p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception); |
| 5137 | if (p == (const Quantum *) NULL) |
| 5138 | { |
| 5139 | status=MagickFalse; |
| 5140 | break; |
| 5141 | } |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 5142 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5143 | { |
| 5144 | PointInfo |
| 5145 | delta, |
| 5146 | luminance; |
| 5147 | |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 5148 | PixelChannel channel=GetPixelChannelChannel(source,i); |
| 5149 | PixelTrait traits=GetPixelChannelTraits(source,channel); |
| 5150 | PixelTrait destination_traits=GetPixelChannelTraits(destination, |
| 5151 | channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5152 | if ((traits == UndefinedPixelTrait) || |
| 5153 | (destination_traits == UndefinedPixelTrait)) |
| 5154 | continue; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5155 | pixels[0]=(double) p[i]; |
| 5156 | pixels[1]=(double) p[GetPixelChannels(source)+i]; |
| 5157 | pixels[2]=(double) p[2*GetPixelChannels(source)+i]; |
| 5158 | pixels[3]=(double) p[3*GetPixelChannels(source)+i]; |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 5159 | if ((traits & BlendPixelTrait) == 0) |
| 5160 | { |
| 5161 | alpha[0]=1.0; |
| 5162 | alpha[1]=1.0; |
| 5163 | alpha[2]=1.0; |
| 5164 | alpha[3]=1.0; |
| 5165 | } |
| 5166 | else |
| 5167 | { |
| 5168 | alpha[0]=QuantumScale*GetPixelAlpha(source,p); |
| 5169 | alpha[1]=QuantumScale*GetPixelAlpha(source,p+ |
| 5170 | GetPixelChannels(source)); |
| 5171 | alpha[2]=QuantumScale*GetPixelAlpha(source,p+2* |
| 5172 | GetPixelChannels(source)); |
| 5173 | alpha[3]=QuantumScale*GetPixelAlpha(source,p+3* |
| 5174 | GetPixelChannels(source)); |
| 5175 | } |
| 5176 | delta.x=x-x_offset; |
| 5177 | delta.y=y-y_offset; |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5178 | luminance.x=fabs((double) (GetPixelLuminance(source,p)- |
| 5179 | GetPixelLuminance(source,p+3*GetPixelChannels(source)))); |
| 5180 | luminance.y=fabs((double) (GetPixelLuminance(source,p+ |
| 5181 | GetPixelChannels(source))-GetPixelLuminance(source,p+2* |
| 5182 | GetPixelChannels(source)))); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5183 | if (luminance.x < luminance.y) |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 5184 | { |
| 5185 | /* |
| 5186 | Diagonal 0-3 NW-SE. |
| 5187 | */ |
| 5188 | if (delta.x <= delta.y) |
| 5189 | { |
| 5190 | /* |
| 5191 | Bottom-left triangle (pixel: 2, diagonal: 0-3). |
| 5192 | */ |
| 5193 | delta.y=1.0-delta.y; |
| 5194 | gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5195 | gamma=PerceptibleReciprocal(gamma); |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 5196 | SetPixelChannel(destination,channel,ClampToQuantum(gamma* |
| 5197 | MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel); |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 5198 | } |
| 5199 | else |
| 5200 | { |
| 5201 | /* |
| 5202 | Top-right triangle (pixel: 1, diagonal: 0-3). |
| 5203 | */ |
| 5204 | delta.x=1.0-delta.x; |
| 5205 | gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5206 | gamma=PerceptibleReciprocal(gamma); |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 5207 | SetPixelChannel(destination,channel,ClampToQuantum(gamma* |
| 5208 | MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel); |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 5209 | } |
| 5210 | } |
| 5211 | else |
| 5212 | { |
| 5213 | /* |
| 5214 | Diagonal 1-2 NE-SW. |
| 5215 | */ |
| 5216 | if (delta.x <= (1.0-delta.y)) |
| 5217 | { |
| 5218 | /* |
| 5219 | Top-left triangle (pixel: 0, diagonal: 1-2). |
| 5220 | */ |
| 5221 | gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5222 | gamma=PerceptibleReciprocal(gamma); |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 5223 | SetPixelChannel(destination,channel,ClampToQuantum(gamma* |
| 5224 | MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel); |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 5225 | } |
| 5226 | else |
| 5227 | { |
| 5228 | /* |
| 5229 | Bottom-right triangle (pixel: 3, diagonal: 1-2). |
| 5230 | */ |
| 5231 | delta.x=1.0-delta.x; |
| 5232 | delta.y=1.0-delta.y; |
| 5233 | gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5234 | gamma=PerceptibleReciprocal(gamma); |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 5235 | SetPixelChannel(destination,channel,ClampToQuantum(gamma* |
| 5236 | MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel); |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 5237 | } |
| 5238 | } |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5239 | } |
| 5240 | break; |
| 5241 | } |
| 5242 | case SplineInterpolatePixel: |
| 5243 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5244 | double |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 5245 | cx[4], |
| 5246 | cy[4]; |
| 5247 | |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5248 | p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4, |
| 5249 | exception); |
| 5250 | if (p == (const Quantum *) NULL) |
| 5251 | { |
| 5252 | status=MagickFalse; |
| 5253 | break; |
| 5254 | } |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 5255 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5256 | { |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5257 | register ssize_t |
| 5258 | j; |
| 5259 | |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 5260 | PixelChannel channel=GetPixelChannelChannel(source,i); |
| 5261 | PixelTrait traits=GetPixelChannelTraits(source,channel); |
| 5262 | PixelTrait destination_traits=GetPixelChannelTraits(destination, |
| 5263 | channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5264 | if ((traits == UndefinedPixelTrait) || |
| 5265 | (destination_traits == UndefinedPixelTrait)) |
| 5266 | continue; |
| 5267 | if ((traits & BlendPixelTrait) == 0) |
| 5268 | for (j=0; j < 16; j++) |
| 5269 | { |
| 5270 | alpha[j]=1.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5271 | pixels[j]=(double) p[j*GetPixelChannels(source)+i]; |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5272 | } |
| 5273 | else |
| 5274 | for (j=0; j < 16; j++) |
| 5275 | { |
| 5276 | alpha[j]=QuantumScale*GetPixelAlpha(source,p+j* |
| 5277 | GetPixelChannels(source)); |
| 5278 | pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i]; |
| 5279 | } |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5280 | SplineWeights((double) (x-x_offset),&cx); |
| 5281 | SplineWeights((double) (y-y_offset),&cy); |
| 5282 | gamma=((traits & BlendPixelTrait) ? (double) (1.0) : |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5283 | PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]* |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 5284 | alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]* |
| 5285 | alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]* |
| 5286 | alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+ |
| 5287 | cx[2]*alpha[14]+cx[3]*alpha[15]))); |
| 5288 | SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]* |
| 5289 | pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]* |
| 5290 | (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+ |
| 5291 | cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]* |
| 5292 | pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]* |
| 5293 | pixels[14]+cx[3]*pixels[15]))),pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5294 | } |
| 5295 | break; |
| 5296 | } |
| 5297 | } |
| 5298 | return(status); |
| 5299 | } |
| 5300 | |
| 5301 | /* |
| 5302 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5303 | % % |
| 5304 | % % |
| 5305 | % % |
cristy | 9075cdb | 2011-07-30 01:06:23 +0000 | [diff] [blame] | 5306 | % I n t e r p o l a t e P i x e l I n f o % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5307 | % % |
| 5308 | % % |
| 5309 | % % |
| 5310 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5311 | % |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 5312 | % InterpolatePixelInfo() applies a pixel interpolation method between a |
| 5313 | % floating point coordinate and the pixels surrounding that coordinate. No |
| 5314 | % pixel area resampling, or scaling of the result is performed. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5315 | % |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5316 | % Interpolation is restricted to just RGBKA channels. |
| 5317 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5318 | % The format of the InterpolatePixelInfo method is: |
| 5319 | % |
| 5320 | % MagickBooleanType InterpolatePixelInfo(const Image *image, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5321 | % const CacheView *image_view,const PixelInterpolateMethod method, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5322 | % const double x,const double y,PixelInfo *pixel, |
| 5323 | % ExceptionInfo *exception) |
| 5324 | % |
| 5325 | % A description of each parameter follows: |
| 5326 | % |
| 5327 | % o image: the image. |
| 5328 | % |
| 5329 | % o image_view: the image view. |
| 5330 | % |
| 5331 | % o method: the pixel color interpolation method. |
| 5332 | % |
| 5333 | % o x,y: A double representing the current (x,y) position of the pixel. |
| 5334 | % |
| 5335 | % o pixel: return the interpolated pixel here. |
| 5336 | % |
| 5337 | % o exception: return any errors or warnings in this structure. |
| 5338 | % |
| 5339 | */ |
| 5340 | |
| 5341 | static inline void AlphaBlendPixelInfo(const Image *image, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5342 | const Quantum *pixel,PixelInfo *pixel_info,double *alpha) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5343 | { |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5344 | if (image->alpha_trait != BlendPixelTrait) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5345 | { |
| 5346 | *alpha=1.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5347 | pixel_info->red=(double) GetPixelRed(image,pixel); |
| 5348 | pixel_info->green=(double) GetPixelGreen(image,pixel); |
| 5349 | pixel_info->blue=(double) GetPixelBlue(image,pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5350 | pixel_info->black=0.0; |
| 5351 | if (image->colorspace == CMYKColorspace) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5352 | pixel_info->black=(double) GetPixelBlack(image,pixel); |
| 5353 | pixel_info->alpha=(double) GetPixelAlpha(image,pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5354 | return; |
| 5355 | } |
| 5356 | *alpha=QuantumScale*GetPixelAlpha(image,pixel); |
| 5357 | pixel_info->red=(*alpha*GetPixelRed(image,pixel)); |
| 5358 | pixel_info->green=(*alpha*GetPixelGreen(image,pixel)); |
| 5359 | pixel_info->blue=(*alpha*GetPixelBlue(image,pixel)); |
| 5360 | pixel_info->black=0.0; |
| 5361 | if (image->colorspace == CMYKColorspace) |
| 5362 | pixel_info->black=(*alpha*GetPixelBlack(image,pixel)); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5363 | pixel_info->alpha=(double) GetPixelAlpha(image,pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5364 | } |
| 5365 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5366 | MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5367 | const CacheView *image_view,const PixelInterpolateMethod method, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5368 | const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception) |
| 5369 | { |
| 5370 | MagickBooleanType |
| 5371 | status; |
| 5372 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5373 | double |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5374 | alpha[16], |
| 5375 | gamma; |
| 5376 | |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5377 | PixelInfo |
| 5378 | pixels[16]; |
| 5379 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5380 | register const Quantum |
| 5381 | *p; |
| 5382 | |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 5383 | register ssize_t |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5384 | i; |
| 5385 | |
| 5386 | ssize_t |
| 5387 | x_offset, |
| 5388 | y_offset; |
| 5389 | |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5390 | PixelInterpolateMethod |
| 5391 | interpolate; |
| 5392 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5393 | assert(image != (Image *) NULL); |
| 5394 | assert(image->signature == MagickSignature); |
| 5395 | assert(image_view != (CacheView *) NULL); |
| 5396 | status=MagickTrue; |
| 5397 | x_offset=(ssize_t) floor(x); |
| 5398 | y_offset=(ssize_t) floor(y); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5399 | interpolate = method; |
| 5400 | if ( interpolate == UndefinedInterpolatePixel ) |
| 5401 | interpolate = image->interpolate; |
| 5402 | switch (interpolate) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5403 | { |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5404 | case AverageInterpolatePixel: /* nearest 4 neighbours */ |
| 5405 | case Average9InterpolatePixel: /* nearest 9 neighbours */ |
| 5406 | case Average16InterpolatePixel: /* nearest 16 neighbours */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5407 | { |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5408 | ssize_t |
| 5409 | count; |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5410 | |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5411 | count=2; /* size of the area to average - default nearest 4 */ |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5412 | if (interpolate == Average9InterpolatePixel) |
| 5413 | { |
| 5414 | count=3; |
| 5415 | x_offset=(ssize_t) (floor(x+0.5)-1); |
| 5416 | y_offset=(ssize_t) (floor(y+0.5)-1); |
| 5417 | } |
| 5418 | else if (interpolate == Average16InterpolatePixel) |
| 5419 | { |
| 5420 | count=4; |
| 5421 | x_offset--; |
| 5422 | y_offset--; |
| 5423 | } |
cristy | 021216a | 2013-05-20 16:25:51 +0000 | [diff] [blame] | 5424 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,(size_t) count, |
| 5425 | (size_t) count,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5426 | if (p == (const Quantum *) NULL) |
| 5427 | { |
| 5428 | status=MagickFalse; |
| 5429 | break; |
| 5430 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5431 | pixel->red=0.0; |
| 5432 | pixel->green=0.0; |
| 5433 | pixel->blue=0.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5434 | pixel->black=0.0; |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5435 | pixel->alpha=0.0; |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5436 | count*=count; /* number of pixels - square of size */ |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 5437 | for (i=0; i < (ssize_t) count; i++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5438 | { |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5439 | AlphaBlendPixelInfo(image,p,pixels,alpha); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5440 | gamma=PerceptibleReciprocal(alpha[0]); |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5441 | pixel->red+=gamma*pixels[0].red; |
| 5442 | pixel->green+=gamma*pixels[0].green; |
| 5443 | pixel->blue+=gamma*pixels[0].blue; |
| 5444 | pixel->black+=gamma*pixels[0].black; |
| 5445 | pixel->alpha+=pixels[0].alpha; |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5446 | p += GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5447 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5448 | gamma=1.0/count; /* average weighting of each pixel in area */ |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5449 | pixel->red*=gamma; |
| 5450 | pixel->green*=gamma; |
| 5451 | pixel->blue*=gamma; |
| 5452 | pixel->black*=gamma; |
| 5453 | pixel->alpha*=gamma; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5454 | break; |
| 5455 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5456 | case BackgroundInterpolatePixel: |
| 5457 | { |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5458 | *pixel=image->background_color; /* Copy PixelInfo Structure */ |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5459 | break; |
| 5460 | } |
| 5461 | case BilinearInterpolatePixel: |
| 5462 | default: |
| 5463 | { |
| 5464 | PointInfo |
| 5465 | delta, |
| 5466 | epsilon; |
| 5467 | |
| 5468 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
| 5469 | if (p == (const Quantum *) NULL) |
| 5470 | { |
| 5471 | status=MagickFalse; |
| 5472 | break; |
| 5473 | } |
| 5474 | for (i=0; i < 4L; i++) |
| 5475 | AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i); |
| 5476 | delta.x=x-x_offset; |
| 5477 | delta.y=y-y_offset; |
| 5478 | epsilon.x=1.0-delta.x; |
| 5479 | epsilon.y=1.0-delta.y; |
| 5480 | gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y* |
| 5481 | (epsilon.x*alpha[2]+delta.x*alpha[3]))); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5482 | gamma=PerceptibleReciprocal(gamma); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5483 | pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x* |
| 5484 | pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red)); |
| 5485 | pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x* |
| 5486 | pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x* |
| 5487 | pixels[3].green)); |
| 5488 | pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x* |
| 5489 | pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x* |
| 5490 | pixels[3].blue)); |
| 5491 | if (image->colorspace == CMYKColorspace) |
| 5492 | pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x* |
| 5493 | pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x* |
| 5494 | pixels[3].black)); |
| 5495 | gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x))); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5496 | gamma=PerceptibleReciprocal(gamma); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5497 | pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x* |
| 5498 | pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x* |
| 5499 | pixels[3].alpha)); |
| 5500 | break; |
| 5501 | } |
| 5502 | case BlendInterpolatePixel: |
| 5503 | { |
| 5504 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
| 5505 | if (p == (const Quantum *) NULL) |
| 5506 | { |
| 5507 | status=MagickFalse; |
| 5508 | break; |
| 5509 | } |
| 5510 | for (i=0; i < 4L; i++) |
| 5511 | AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i); |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5512 | gamma=1.0; /* number of pixels blended together (its variable) */ |
| 5513 | for (i=0; i <= 1L; i++) |
| 5514 | { |
| 5515 | if ((y-y_offset) >= 0.75) |
| 5516 | { |
| 5517 | alpha[i]=alpha[i+2]; /* take right pixels */ |
| 5518 | pixels[i]=pixels[i+2]; |
| 5519 | } |
| 5520 | else |
| 5521 | if ((y-y_offset) > 0.25) |
| 5522 | { |
| 5523 | gamma=2.0; /* blend both pixels in row */ |
| 5524 | alpha[i]+=alpha[i+2]; /* add up alpha weights */ |
| 5525 | pixels[i].red+=pixels[i+2].red; |
| 5526 | pixels[i].green+=pixels[i+2].green; |
| 5527 | pixels[i].blue+=pixels[i+2].blue; |
| 5528 | pixels[i].black+=pixels[i+2].black; |
| 5529 | pixels[i].alpha+=pixels[i+2].alpha; |
| 5530 | } |
| 5531 | } |
| 5532 | if ((x-x_offset) >= 0.75) |
| 5533 | { |
| 5534 | alpha[0]=alpha[1]; |
| 5535 | pixels[0]=pixels[1]; |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5536 | } |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5537 | else |
| 5538 | if ((x-x_offset) > 0.25) |
| 5539 | { |
| 5540 | gamma*=2.0; /* blend both rows */ |
| 5541 | alpha[0]+= alpha[1]; /* add up alpha weights */ |
| 5542 | pixels[0].red+=pixels[1].red; |
| 5543 | pixels[0].green+=pixels[1].green; |
| 5544 | pixels[0].blue+=pixels[1].blue; |
| 5545 | pixels[0].black+=pixels[1].black; |
| 5546 | pixels[0].alpha+=pixels[1].alpha; |
| 5547 | } |
| 5548 | gamma=1.0/gamma; |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5549 | alpha[0]=PerceptibleReciprocal(alpha[0]); |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5550 | pixel->red=alpha[0]*pixels[0].red; |
| 5551 | pixel->green=alpha[0]*pixels[0].green; /* divide by sum of alpha */ |
| 5552 | pixel->blue=alpha[0]*pixels[0].blue; |
| 5553 | pixel->black=alpha[0]*pixels[0].black; |
| 5554 | pixel->alpha=gamma*pixels[0].alpha; /* divide by number of pixels */ |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5555 | break; |
| 5556 | } |
| 5557 | case CatromInterpolatePixel: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5558 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5559 | double |
cristy | 380a11c | 2012-06-02 15:15:22 +0000 | [diff] [blame] | 5560 | cx[4], |
| 5561 | cy[4]; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5562 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5563 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 5564 | exception); |
| 5565 | if (p == (const Quantum *) NULL) |
| 5566 | { |
| 5567 | status=MagickFalse; |
| 5568 | break; |
| 5569 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5570 | for (i=0; i < 16L; i++) |
| 5571 | AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5572 | CatromWeights((double) (x-x_offset),&cx); |
| 5573 | CatromWeights((double) (y-y_offset),&cy); |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5574 | pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]* |
| 5575 | pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]* |
| 5576 | pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]* |
| 5577 | pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]* |
| 5578 | pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]* |
| 5579 | pixels[14].red+cx[3]*pixels[15].red)); |
| 5580 | pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]* |
| 5581 | pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+ |
| 5582 | cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+ |
| 5583 | cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]* |
| 5584 | pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]* |
| 5585 | pixels[12].green+cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]* |
| 5586 | pixels[15].green)); |
| 5587 | pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]* |
| 5588 | pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]* |
| 5589 | pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]* |
| 5590 | pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]* |
| 5591 | pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+ |
| 5592 | cx[2]*pixels[14].blue+cx[3]*pixels[15].blue)); |
cristy | 380a11c | 2012-06-02 15:15:22 +0000 | [diff] [blame] | 5593 | if (image->colorspace == CMYKColorspace) |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5594 | pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]* |
| 5595 | pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+ |
| 5596 | cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+ |
| 5597 | cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]* |
| 5598 | pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]* |
| 5599 | pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]* |
| 5600 | pixels[15].black)); |
| 5601 | pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]* |
| 5602 | pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+ |
| 5603 | cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+ |
| 5604 | cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]* |
| 5605 | pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+ |
| 5606 | cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5607 | break; |
| 5608 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5609 | case IntegerInterpolatePixel: |
| 5610 | { |
| 5611 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception); |
| 5612 | if (p == (const Quantum *) NULL) |
| 5613 | { |
| 5614 | status=MagickFalse; |
| 5615 | break; |
| 5616 | } |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 5617 | GetPixelInfoPixel(image,p,pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5618 | break; |
| 5619 | } |
| 5620 | case MeshInterpolatePixel: |
| 5621 | { |
| 5622 | PointInfo |
| 5623 | delta, |
| 5624 | luminance; |
| 5625 | |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5626 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5627 | if (p == (const Quantum *) NULL) |
| 5628 | { |
| 5629 | status=MagickFalse; |
| 5630 | break; |
| 5631 | } |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5632 | delta.x=x-x_offset; |
| 5633 | delta.y=y-y_offset; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 5634 | luminance.x=GetPixelLuminance(image,p)-(double) |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5635 | GetPixelLuminance(image,p+3*GetPixelChannels(image)); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5636 | luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double) |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5637 | GetPixelLuminance(image,p+2*GetPixelChannels(image)); |
cristy | 5ce8df8 | 2011-07-07 14:52:23 +0000 | [diff] [blame] | 5638 | AlphaBlendPixelInfo(image,p,pixels+0,alpha+0); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5639 | AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5640 | AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2); |
| 5641 | AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5642 | if (fabs(luminance.x) < fabs(luminance.y)) |
| 5643 | { |
| 5644 | /* |
| 5645 | Diagonal 0-3 NW-SE. |
| 5646 | */ |
| 5647 | if (delta.x <= delta.y) |
| 5648 | { |
| 5649 | /* |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5650 | Bottom-left triangle (pixel: 2, diagonal: 0-3). |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5651 | */ |
| 5652 | delta.y=1.0-delta.y; |
| 5653 | gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5654 | gamma=PerceptibleReciprocal(gamma); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5655 | pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red, |
| 5656 | pixels[3].red,pixels[0].red); |
| 5657 | pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green, |
| 5658 | pixels[3].green,pixels[0].green); |
| 5659 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue, |
| 5660 | pixels[3].blue,pixels[0].blue); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5661 | if (image->colorspace == CMYKColorspace) |
| 5662 | pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black, |
| 5663 | pixels[3].black,pixels[0].black); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5664 | gamma=MeshInterpolate(&delta,1.0,1.0,1.0); |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5665 | pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha, |
| 5666 | pixels[3].alpha,pixels[0].alpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5667 | } |
| 5668 | else |
| 5669 | { |
| 5670 | /* |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5671 | Top-right triangle (pixel:1 , diagonal: 0-3). |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5672 | */ |
| 5673 | delta.x=1.0-delta.x; |
| 5674 | gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5675 | gamma=PerceptibleReciprocal(gamma); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5676 | pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red, |
| 5677 | pixels[0].red,pixels[3].red); |
| 5678 | pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green, |
| 5679 | pixels[0].green,pixels[3].green); |
| 5680 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue, |
| 5681 | pixels[0].blue,pixels[3].blue); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5682 | if (image->colorspace == CMYKColorspace) |
| 5683 | pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black, |
| 5684 | pixels[0].black,pixels[3].black); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5685 | gamma=MeshInterpolate(&delta,1.0,1.0,1.0); |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5686 | pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha, |
| 5687 | pixels[0].alpha,pixels[3].alpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5688 | } |
| 5689 | } |
| 5690 | else |
| 5691 | { |
| 5692 | /* |
| 5693 | Diagonal 1-2 NE-SW. |
| 5694 | */ |
| 5695 | if (delta.x <= (1.0-delta.y)) |
| 5696 | { |
| 5697 | /* |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5698 | Top-left triangle (pixel: 0, diagonal: 1-2). |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5699 | */ |
| 5700 | gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5701 | gamma=PerceptibleReciprocal(gamma); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5702 | pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red, |
| 5703 | pixels[1].red,pixels[2].red); |
| 5704 | pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green, |
| 5705 | pixels[1].green,pixels[2].green); |
| 5706 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue, |
| 5707 | pixels[1].blue,pixels[2].blue); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5708 | if (image->colorspace == CMYKColorspace) |
| 5709 | pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black, |
| 5710 | pixels[1].black,pixels[2].black); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5711 | gamma=MeshInterpolate(&delta,1.0,1.0,1.0); |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5712 | pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha, |
| 5713 | pixels[1].alpha,pixels[2].alpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5714 | } |
| 5715 | else |
| 5716 | { |
| 5717 | /* |
| 5718 | Bottom-right triangle (pixel: 3, diagonal: 1-2). |
| 5719 | */ |
| 5720 | delta.x=1.0-delta.x; |
| 5721 | delta.y=1.0-delta.y; |
| 5722 | gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5723 | gamma=PerceptibleReciprocal(gamma); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5724 | pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red, |
| 5725 | pixels[2].red,pixels[1].red); |
| 5726 | pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green, |
| 5727 | pixels[2].green,pixels[1].green); |
| 5728 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue, |
| 5729 | pixels[2].blue,pixels[1].blue); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5730 | if (image->colorspace == CMYKColorspace) |
| 5731 | pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black, |
| 5732 | pixels[2].black,pixels[1].black); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5733 | gamma=MeshInterpolate(&delta,1.0,1.0,1.0); |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5734 | pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha, |
| 5735 | pixels[2].alpha,pixels[1].alpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5736 | } |
| 5737 | } |
| 5738 | break; |
| 5739 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5740 | case NearestInterpolatePixel: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5741 | { |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5742 | x_offset=(ssize_t) floor(x+0.5); |
| 5743 | y_offset=(ssize_t) floor(y+0.5); |
| 5744 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5745 | if (p == (const Quantum *) NULL) |
| 5746 | { |
| 5747 | status=MagickFalse; |
| 5748 | break; |
| 5749 | } |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 5750 | GetPixelInfoPixel(image,p,pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5751 | break; |
| 5752 | } |
| 5753 | case SplineInterpolatePixel: |
| 5754 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5755 | double |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 5756 | cx[4], |
| 5757 | cy[4]; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5758 | |
| 5759 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 5760 | exception); |
| 5761 | if (p == (const Quantum *) NULL) |
| 5762 | { |
| 5763 | status=MagickFalse; |
| 5764 | break; |
| 5765 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5766 | for (i=0; i < 16L; i++) |
| 5767 | AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5768 | SplineWeights((double) (x-x_offset),&cx); |
| 5769 | SplineWeights((double) (y-y_offset),&cy); |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5770 | pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]* |
| 5771 | pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]* |
| 5772 | pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]* |
| 5773 | pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]* |
| 5774 | pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]* |
| 5775 | pixels[14].red+cx[3]*pixels[15].red)); |
| 5776 | pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]* |
| 5777 | pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+ |
| 5778 | cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+ |
| 5779 | cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]* |
| 5780 | pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*pixels[12].green+ |
| 5781 | cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*pixels[15].green)); |
| 5782 | pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]* |
| 5783 | pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]* |
| 5784 | pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]* |
| 5785 | pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]* |
| 5786 | pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+ |
| 5787 | cx[2]*pixels[14].blue+cx[3]*pixels[15].blue)); |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 5788 | if (image->colorspace == CMYKColorspace) |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5789 | pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]* |
| 5790 | pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+ |
| 5791 | cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+ |
| 5792 | cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]* |
| 5793 | pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]* |
| 5794 | pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]* |
| 5795 | pixels[15].black)); |
| 5796 | pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]* |
| 5797 | pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+ |
| 5798 | cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+ |
| 5799 | cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]* |
| 5800 | pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+ |
| 5801 | cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5802 | break; |
| 5803 | } |
| 5804 | } |
| 5805 | return(status); |
| 5806 | } |
| 5807 | |
| 5808 | /* |
| 5809 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5810 | % % |
| 5811 | % % |
| 5812 | % % |
| 5813 | + I s F u z z y E q u i v a l e n c e P i x e l % |
| 5814 | % % |
| 5815 | % % |
| 5816 | % % |
| 5817 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5818 | % |
| 5819 | % IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two |
| 5820 | % pixels is less than the specified distance in a linear three (or four)u |
| 5821 | % dimensional color space. |
| 5822 | % |
| 5823 | % The format of the IsFuzzyEquivalencePixel method is: |
| 5824 | % |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5825 | % void IsFuzzyEquivalencePixel(const Image *source,const Quantum *p, |
| 5826 | % const Image *destination,const Quantum *q) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5827 | % |
| 5828 | % A description of each parameter follows: |
| 5829 | % |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5830 | % o source: the source image. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5831 | % |
| 5832 | % o p: Pixel p. |
| 5833 | % |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5834 | % o destination: the destination image. |
| 5835 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5836 | % o q: Pixel q. |
| 5837 | % |
| 5838 | */ |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5839 | MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *source, |
| 5840 | const Quantum *p,const Image *destination,const Quantum *q) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5841 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5842 | double |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5843 | fuzz, |
| 5844 | pixel; |
| 5845 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5846 | register double |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5847 | distance, |
| 5848 | scale; |
| 5849 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5850 | fuzz=MagickMax(source->fuzz,(double) MagickSQ1_2)*MagickMax( |
| 5851 | destination->fuzz,(double) MagickSQ1_2); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5852 | scale=1.0; |
| 5853 | distance=0.0; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5854 | if (source->alpha_trait == BlendPixelTrait) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5855 | { |
| 5856 | /* |
| 5857 | Transparencies are involved - set alpha distance |
| 5858 | */ |
cristy | 70e9f68 | 2013-03-12 22:31:22 +0000 | [diff] [blame] | 5859 | pixel=GetPixelAlpha(source,p)-(double) GetPixelAlpha(destination,q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5860 | distance=pixel*pixel; |
| 5861 | if (distance > fuzz) |
| 5862 | return(MagickFalse); |
| 5863 | /* |
| 5864 | Generate a alpha scaling factor to generate a 4D cone on colorspace |
| 5865 | Note that if one color is transparent, distance has no color component. |
| 5866 | */ |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5867 | scale=QuantumScale*GetPixelAlpha(source,p); |
| 5868 | scale*=QuantumScale*GetPixelAlpha(destination,q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5869 | if (scale <= MagickEpsilon) |
| 5870 | return(MagickTrue); |
| 5871 | } |
| 5872 | /* |
| 5873 | RGB or CMY color cube |
| 5874 | */ |
| 5875 | distance*=3.0; /* rescale appropriately */ |
| 5876 | fuzz*=3.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5877 | pixel=GetPixelRed(source,p)-(double) GetPixelRed(destination,q); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5878 | if ((source->colorspace == HSLColorspace) || |
| 5879 | (source->colorspace == HSBColorspace) || |
| 5880 | (source->colorspace == HWBColorspace)) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5881 | { |
| 5882 | /* |
| 5883 | Compute an arc distance for hue. It should be a vector angle of |
| 5884 | 'S'/'W' length with 'L'/'B' forming appropriate cones. |
| 5885 | */ |
| 5886 | if (fabs((double) pixel) > (QuantumRange/2)) |
| 5887 | pixel-=QuantumRange; |
| 5888 | pixel*=2; |
| 5889 | } |
| 5890 | distance+=scale*pixel*pixel; |
| 5891 | if (distance > fuzz) |
| 5892 | return(MagickFalse); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5893 | pixel=GetPixelGreen(source,p)-(double) GetPixelGreen(destination,q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5894 | distance+=scale*pixel*pixel; |
| 5895 | if (distance > fuzz) |
| 5896 | return(MagickFalse); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5897 | pixel=GetPixelBlue(source,p)-(double) GetPixelBlue(destination,q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5898 | distance+=scale*pixel*pixel; |
| 5899 | if (distance > fuzz) |
| 5900 | return(MagickFalse); |
| 5901 | return(MagickTrue); |
| 5902 | } |
| 5903 | |
| 5904 | /* |
| 5905 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5906 | % % |
| 5907 | % % |
| 5908 | % % |
| 5909 | + I s F u z z y E q u i v a l e n c e P i x e l I n f o % |
| 5910 | % % |
| 5911 | % % |
| 5912 | % % |
| 5913 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5914 | % |
| 5915 | % IsFuzzyEquivalencePixelInfo() returns true if the distance between two |
| 5916 | % colors is less than the specified distance in a linear three (or four) |
| 5917 | % dimensional color space. |
| 5918 | % |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5919 | % This implements the equivalent of: |
| 5920 | % fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5921 | % |
| 5922 | % Which produces a multi-dimensional cone for that colorspace along the |
| 5923 | % transparency vector. |
| 5924 | % |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5925 | % For example for an RGB: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5926 | % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3 |
| 5927 | % |
| 5928 | % See http://www.imagemagick.org/Usage/bugs/fuzz_distance/ |
| 5929 | % |
| 5930 | % Hue colorspace distances need more work. Hue is not a distance, it is an |
| 5931 | % angle! |
| 5932 | % |
| 5933 | % A check that q is in the same color space as p should be made and the |
| 5934 | % appropriate mapping made. -- Anthony Thyssen 8 December 2010 |
| 5935 | % |
| 5936 | % The format of the IsFuzzyEquivalencePixelInfo method is: |
| 5937 | % |
| 5938 | % MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p, |
| 5939 | % const PixelInfo *q) |
| 5940 | % |
| 5941 | % A description of each parameter follows: |
| 5942 | % |
| 5943 | % o p: Pixel p. |
| 5944 | % |
| 5945 | % o q: Pixel q. |
| 5946 | % |
| 5947 | */ |
| 5948 | MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p, |
| 5949 | const PixelInfo *q) |
| 5950 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5951 | double |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5952 | fuzz, |
| 5953 | pixel; |
| 5954 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5955 | register double |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5956 | scale, |
| 5957 | distance; |
| 5958 | |
| 5959 | if ((p->fuzz == 0.0) && (q->fuzz == 0.0)) |
| 5960 | return(IsPixelInfoEquivalent(p,q)); |
| 5961 | if (p->fuzz == 0.0) |
cristy | 24dc972 | 2013-05-20 16:02:22 +0000 | [diff] [blame] | 5962 | fuzz=MagickMax(q->fuzz,(double) MagickSQ1_2)*MagickMax(q->fuzz,MagickSQ1_2); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5963 | else if (q->fuzz == 0.0) |
cristy | 24dc972 | 2013-05-20 16:02:22 +0000 | [diff] [blame] | 5964 | fuzz=MagickMax(p->fuzz,(double) MagickSQ1_2)*MagickMax(p->fuzz,MagickSQ1_2); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5965 | else |
cristy | 24dc972 | 2013-05-20 16:02:22 +0000 | [diff] [blame] | 5966 | fuzz=MagickMax(p->fuzz,(double) MagickSQ1_2)*MagickMax(q->fuzz,MagickSQ1_2); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5967 | scale=1.0; |
| 5968 | distance=0.0; |
cristy | 24dc972 | 2013-05-20 16:02:22 +0000 | [diff] [blame] | 5969 | if ((p->alpha_trait == BlendPixelTrait) || |
| 5970 | (q->alpha_trait == BlendPixelTrait)) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5971 | { |
| 5972 | /* |
| 5973 | Transparencies are involved - set alpha distance. |
| 5974 | */ |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5975 | pixel=(p->alpha_trait == BlendPixelTrait ? p->alpha : OpaqueAlpha)- |
| 5976 | (q->alpha_trait == BlendPixelTrait ? q->alpha : OpaqueAlpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5977 | distance=pixel*pixel; |
| 5978 | if (distance > fuzz) |
| 5979 | return(MagickFalse); |
| 5980 | /* |
| 5981 | Generate a alpha scaling factor to generate a 4D cone on colorspace. |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5982 | If one color is transparent, distance has no color component. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5983 | */ |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5984 | if (p->alpha_trait == BlendPixelTrait) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5985 | scale=(QuantumScale*p->alpha); |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5986 | if (q->alpha_trait == BlendPixelTrait) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5987 | scale*=(QuantumScale*q->alpha); |
| 5988 | if (scale <= MagickEpsilon ) |
| 5989 | return(MagickTrue); |
| 5990 | } |
| 5991 | /* |
| 5992 | CMYK create a CMY cube with a multi-dimensional cone toward black. |
| 5993 | */ |
| 5994 | if (p->colorspace == CMYKColorspace) |
| 5995 | { |
| 5996 | pixel=p->black-q->black; |
| 5997 | distance+=pixel*pixel*scale; |
| 5998 | if (distance > fuzz) |
| 5999 | return(MagickFalse); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 6000 | scale*=(double) (QuantumScale*(QuantumRange-p->black)); |
| 6001 | scale*=(double) (QuantumScale*(QuantumRange-q->black)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 6002 | } |
| 6003 | /* |
| 6004 | RGB or CMY color cube. |
| 6005 | */ |
| 6006 | distance*=3.0; /* rescale appropriately */ |
| 6007 | fuzz*=3.0; |
| 6008 | pixel=p->red-q->red; |
| 6009 | if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) || |
| 6010 | (p->colorspace == HWBColorspace)) |
| 6011 | { |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 6012 | /* |
| 6013 | This calculates a arc distance for hue-- it should be a vector angle |
| 6014 | of 'S'/'W' length with 'L'/'B' forming appropriate cones. In other |
| 6015 | words this is a hack - Anthony. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 6016 | */ |
| 6017 | if (fabs((double) pixel) > (QuantumRange/2)) |
| 6018 | pixel-=QuantumRange; |
| 6019 | pixel*=2; |
| 6020 | } |
| 6021 | distance+=pixel*pixel*scale; |
| 6022 | if (distance > fuzz) |
| 6023 | return(MagickFalse); |
| 6024 | pixel=p->green-q->green; |
| 6025 | distance+=pixel*pixel*scale; |
| 6026 | if (distance > fuzz) |
| 6027 | return(MagickFalse); |
| 6028 | pixel=p->blue-q->blue; |
| 6029 | distance+=pixel*pixel*scale; |
| 6030 | if (distance > fuzz) |
| 6031 | return(MagickFalse); |
| 6032 | return(MagickTrue); |
| 6033 | } |
| 6034 | |
| 6035 | /* |
| 6036 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 6037 | % % |
| 6038 | % % |
| 6039 | % % |
cristy | 7ae1654 | 2013-05-15 22:41:24 +0000 | [diff] [blame] | 6040 | % S e t P i x e l C h a n n e l M a s k % |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 6041 | % % |
| 6042 | % % |
| 6043 | % % |
| 6044 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 6045 | % |
cristy | 7ae1654 | 2013-05-15 22:41:24 +0000 | [diff] [blame] | 6046 | % SetPixelChannelMask() sets the pixel channel map from the specified channel |
| 6047 | % mask. |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 6048 | % |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 6049 | % The format of the SetPixelChannelMask method is: |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 6050 | % |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 6051 | % void SetPixelChannelMask(Image *image,const ChannelType channel_mask) |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 6052 | % |
| 6053 | % A description of each parameter follows: |
| 6054 | % |
| 6055 | % o image: the image. |
| 6056 | % |
cristy | dfdb19e | 2012-03-21 22:22:24 +0000 | [diff] [blame] | 6057 | % o channel_mask: the channel mask. |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 6058 | % |
| 6059 | */ |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 6060 | MagickExport void SetPixelChannelMask(Image *image, |
cristy | 07a6785 | 2011-08-26 13:25:03 +0000 | [diff] [blame] | 6061 | const ChannelType channel_mask) |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 6062 | { |
cristy | 6a917d6 | 2011-08-24 17:31:30 +0000 | [diff] [blame] | 6063 | #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01) |
cristy | dafd287 | 2011-07-24 22:06:13 +0000 | [diff] [blame] | 6064 | |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 6065 | register ssize_t |
| 6066 | i; |
| 6067 | |
cristy | 177e41c | 2012-04-15 15:08:25 +0000 | [diff] [blame] | 6068 | if (image->debug != MagickFalse) |
| 6069 | (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%08x]", \ |
| 6070 | image->filename,channel_mask); \ |
cristy | 3c30981 | 2011-11-08 02:40:43 +0000 | [diff] [blame] | 6071 | image->channel_mask=channel_mask; |
cristy | dafd287 | 2011-07-24 22:06:13 +0000 | [diff] [blame] | 6072 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 6073 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 6074 | PixelChannel channel=GetPixelChannelChannel(image,i); |
cristy | 297e3a4 | 2012-08-26 21:27:29 +0000 | [diff] [blame] | 6075 | SetPixelChannelTraits(image,channel, |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 6076 | GetChannelBit(channel_mask,channel) == 0 ? CopyPixelTrait : |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 6077 | image->alpha_trait != BlendPixelTrait || (channel == AlphaPixelChannel) ? |
| 6078 | UpdatePixelTrait : (PixelTrait) (UpdatePixelTrait | image->alpha_trait)); |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 6079 | } |
cristy | 1685e72 | 2011-09-06 00:04:19 +0000 | [diff] [blame] | 6080 | if (image->storage_class == PseudoClass) |
cristy | 297e3a4 | 2012-08-26 21:27:29 +0000 | [diff] [blame] | 6081 | SetPixelChannelTraits(image,IndexPixelChannel,CopyPixelTrait); |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 6082 | if (image->read_mask != MagickFalse) |
| 6083 | SetPixelChannelTraits(image,ReadMaskPixelChannel,CopyPixelTrait); |
| 6084 | if (image->write_mask != MagickFalse) |
| 6085 | SetPixelChannelTraits(image,WriteMaskPixelChannel,CopyPixelTrait); |
cristy | 6dcb9b8 | 2011-10-23 23:21:25 +0000 | [diff] [blame] | 6086 | if (image->debug != MagickFalse) |
| 6087 | LogPixelChannels(image); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 6088 | } |
| 6089 | |
| 6090 | /* |
| 6091 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 6092 | % % |
| 6093 | % % |
| 6094 | % % |
cristy | 322d07d | 2012-03-18 21:17:23 +0000 | [diff] [blame] | 6095 | % S e t P i x e l M e t a C h a n n e l s % |
| 6096 | % % |
| 6097 | % % |
| 6098 | % % |
| 6099 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 6100 | % |
| 6101 | % SetPixelMetaChannels() sets the image meta channels. |
| 6102 | % |
| 6103 | % The format of the SetPixelMetaChannels method is: |
| 6104 | % |
| 6105 | % MagickBooleanType SetPixelMetaChannels(Image *image, |
| 6106 | % const size_t number_meta_channels,ExceptionInfo *exception) |
| 6107 | % |
| 6108 | % A description of each parameter follows: |
| 6109 | % |
| 6110 | % o image: the image. |
| 6111 | % |
| 6112 | % o number_meta_channels: the number of meta channels. |
| 6113 | % |
| 6114 | % o exception: return any errors or warnings in this structure. |
| 6115 | % |
| 6116 | */ |
| 6117 | MagickExport MagickBooleanType SetPixelMetaChannels(Image *image, |
| 6118 | const size_t number_meta_channels,ExceptionInfo *exception) |
| 6119 | { |
| 6120 | image->number_meta_channels=number_meta_channels; |
| 6121 | return(SyncImagePixelCache(image,exception)); |
| 6122 | } |