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 | 1454be7 | 2011-12-19 01:52:48 +0000 | [diff] [blame] | 19 | % Copyright 1999-2012 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" |
| 45 | #include "MagickCore/color-private.h" |
| 46 | #include "MagickCore/draw.h" |
| 47 | #include "MagickCore/exception.h" |
| 48 | #include "MagickCore/exception-private.h" |
| 49 | #include "MagickCore/cache.h" |
| 50 | #include "MagickCore/constitute.h" |
| 51 | #include "MagickCore/delegate.h" |
| 52 | #include "MagickCore/geometry.h" |
| 53 | #include "MagickCore/image-private.h" |
| 54 | #include "MagickCore/list.h" |
| 55 | #include "MagickCore/magick.h" |
| 56 | #include "MagickCore/memory_.h" |
| 57 | #include "MagickCore/monitor.h" |
| 58 | #include "MagickCore/option.h" |
| 59 | #include "MagickCore/pixel.h" |
| 60 | #include "MagickCore/pixel-accessor.h" |
| 61 | #include "MagickCore/quantum.h" |
| 62 | #include "MagickCore/quantum-private.h" |
| 63 | #include "MagickCore/resource_.h" |
| 64 | #include "MagickCore/semaphore.h" |
| 65 | #include "MagickCore/statistic.h" |
| 66 | #include "MagickCore/stream.h" |
| 67 | #include "MagickCore/string_.h" |
| 68 | #include "MagickCore/transform.h" |
| 69 | #include "MagickCore/utility.h" |
| 70 | |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 71 | #define LogPixelChannels(image) \ |
| 72 | { \ |
| 73 | register ssize_t \ |
| 74 | i; \ |
| 75 | \ |
| 76 | (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%.20g]", \ |
| 77 | image->filename,(double) image->number_channels); \ |
| 78 | for (i=0; i < (ssize_t) image->number_channels; i++) \ |
| 79 | { \ |
| 80 | char \ |
| 81 | traits[MaxTextExtent]; \ |
| 82 | \ |
| 83 | const char \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 84 | *name; \ |
| 85 | \ |
| 86 | PixelChannel \ |
| 87 | channel; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 88 | \ |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 89 | switch (GetPixelChannelMapChannel(image,i)) \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 90 | { \ |
| 91 | case RedPixelChannel: \ |
| 92 | { \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 93 | name="red"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 94 | if (image->colorspace == CMYKColorspace) \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 95 | name="cyan"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 96 | if (image->colorspace == GRAYColorspace) \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 97 | name="gray"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 98 | break; \ |
| 99 | } \ |
| 100 | case GreenPixelChannel: \ |
| 101 | { \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 102 | name="green"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 103 | if (image->colorspace == CMYKColorspace) \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 104 | name="magenta"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 105 | break; \ |
| 106 | } \ |
| 107 | case BluePixelChannel: \ |
| 108 | { \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 109 | name="blue"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 110 | if (image->colorspace == CMYKColorspace) \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 111 | name="yellow"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 112 | break; \ |
| 113 | } \ |
| 114 | case BlackPixelChannel: \ |
| 115 | { \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 116 | name="black"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 117 | if (image->storage_class == PseudoClass) \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 118 | name="index"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 119 | break; \ |
| 120 | } \ |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 121 | case IndexPixelChannel: \ |
| 122 | { \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 123 | name="index"; \ |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 124 | break; \ |
| 125 | } \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 126 | case AlphaPixelChannel: \ |
| 127 | { \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 128 | name="alpha"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 129 | break; \ |
| 130 | } \ |
| 131 | case MaskPixelChannel: \ |
| 132 | { \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 133 | name="mask"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 134 | break; \ |
| 135 | } \ |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 136 | case MetaPixelChannel: \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 137 | { \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 138 | name="meta"; \ |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 139 | break; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 140 | } \ |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 141 | default: \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 142 | name="undefined"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 143 | } \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 144 | channel=GetPixelChannelMapChannel(image,i); \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 145 | *traits='\0'; \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 146 | if ((GetPixelChannelMapTraits(image,channel) & UpdatePixelTrait) != 0) \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 147 | (void) ConcatenateMagickString(traits,"update,",MaxTextExtent); \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 148 | if ((GetPixelChannelMapTraits(image,channel) & BlendPixelTrait) != 0) \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 149 | (void) ConcatenateMagickString(traits,"blend,",MaxTextExtent); \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 150 | if ((GetPixelChannelMapTraits(image,channel) & CopyPixelTrait) != 0) \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 151 | (void) ConcatenateMagickString(traits,"copy,",MaxTextExtent); \ |
| 152 | if (*traits == '\0') \ |
| 153 | (void) ConcatenateMagickString(traits,"undefined,",MaxTextExtent); \ |
| 154 | traits[strlen(traits)-1]='\0'; \ |
| 155 | (void) LogMagickEvent(PixelEvent,GetMagickModule()," %.20g: %s (%s)", \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 156 | (double) i,name,traits); \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 157 | } \ |
| 158 | } |
| 159 | |
| 160 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 161 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 162 | % % |
| 163 | % % |
| 164 | % % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 165 | + 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] | 166 | % % |
| 167 | % % |
| 168 | % % |
| 169 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 170 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 171 | % AcquirePixelChannelMap() acquires a pixel component map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 172 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 173 | % The format of the AcquirePixelChannelMap() method is: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 174 | % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 175 | % PixelChannelMap *AcquirePixelChannelMap(void) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 176 | % |
| 177 | */ |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 178 | MagickExport PixelChannelMap *AcquirePixelChannelMap(void) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 179 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 180 | PixelChannelMap |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 181 | *channel_map; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 182 | |
| 183 | register ssize_t |
| 184 | i; |
| 185 | |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 186 | channel_map=(PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels, |
| 187 | sizeof(*channel_map)); |
| 188 | if (channel_map == (PixelChannelMap *) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 189 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 190 | (void) ResetMagickMemory(channel_map,0,MaxPixelChannels*sizeof(*channel_map)); |
| 191 | for (i=0; i < MaxPixelChannels; i++) |
| 192 | channel_map[i].channel=(PixelChannel) i; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 193 | return(channel_map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /* |
| 197 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 198 | % % |
| 199 | % % |
| 200 | % % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 201 | + 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] | 202 | % % |
| 203 | % % |
| 204 | % % |
| 205 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 206 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 207 | % ClonePixelChannelMap() clones a pixel component map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 208 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 209 | % The format of the ClonePixelChannelMap() method is: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 210 | % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 211 | % PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 212 | % |
| 213 | % A description of each parameter follows: |
| 214 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 215 | % o channel_map: the pixel component map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 216 | % |
| 217 | */ |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 218 | MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 219 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 220 | PixelChannelMap |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 221 | *clone_map; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 222 | |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 223 | assert(channel_map != (PixelChannelMap *) NULL); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 224 | clone_map=AcquirePixelChannelMap(); |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 225 | if (clone_map == (PixelChannelMap *) NULL) |
| 226 | return((PixelChannelMap *) NULL); |
| 227 | (void) CopyMagickMemory(clone_map,channel_map,MaxPixelChannels* |
| 228 | sizeof(*channel_map)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 229 | return(clone_map); |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 234 | % % |
| 235 | % % |
| 236 | % % |
| 237 | + C l o n e P i x e l I n f o % |
| 238 | % % |
| 239 | % % |
| 240 | % % |
| 241 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 242 | % |
| 243 | % ClonePixelInfo() makes a duplicate of the given pixel info structure, or if |
| 244 | % pixel info is NULL, a new one. |
| 245 | % |
| 246 | % The format of the ClonePixelInfo method is: |
| 247 | % |
| 248 | % PixelInfo *ClonePixelInfo(const PixelInfo *pixel_info) |
| 249 | % |
| 250 | % A description of each parameter follows: |
| 251 | % |
| 252 | % o pixel_info: the pixel info. |
| 253 | % |
| 254 | */ |
| 255 | MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel) |
| 256 | { |
| 257 | PixelInfo |
| 258 | *pixel_info; |
| 259 | |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 260 | pixel_info=(PixelInfo *) AcquireQuantumMemory(1,sizeof(*pixel_info)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 261 | if (pixel_info == (PixelInfo *) NULL) |
| 262 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 263 | *pixel_info=(*pixel); |
| 264 | return(pixel_info); |
| 265 | } |
| 266 | |
| 267 | /* |
| 268 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 269 | % % |
| 270 | % % |
| 271 | % % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 272 | + 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] | 273 | % % |
| 274 | % % |
| 275 | % % |
| 276 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 277 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 278 | % DestroyPixelChannelMap() deallocates memory associated with the pixel |
| 279 | % channel map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 280 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 281 | % The format of the DestroyPixelChannelMap() method is: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 282 | % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 283 | % PixelChannelMap *DestroyPixelChannelMap(PixelChannelMap *channel_map) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 284 | % |
| 285 | % A description of each parameter follows: |
| 286 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 287 | % o channel_map: the pixel component map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 288 | % |
| 289 | */ |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 290 | MagickExport PixelChannelMap *DestroyPixelChannelMap( |
| 291 | PixelChannelMap *channel_map) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 292 | { |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 293 | assert(channel_map != (PixelChannelMap *) NULL); |
| 294 | channel_map=(PixelChannelMap *) RelinquishMagickMemory(channel_map); |
| 295 | return((PixelChannelMap *) RelinquishMagickMemory(channel_map)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | /* |
| 299 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 300 | % % |
| 301 | % % |
| 302 | % % |
| 303 | % E x p o r t I m a g e P i x e l s % |
| 304 | % % |
| 305 | % % |
| 306 | % % |
| 307 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 308 | % |
| 309 | % ExportImagePixels() extracts pixel data from an image and returns it to you. |
| 310 | % The method returns MagickTrue on success otherwise MagickFalse if an error is |
cristy | b5a45a3 | 2012-01-10 13:31:13 +0000 | [diff] [blame] | 311 | % encountered. The data is returned as char, short int, Quantum, unsigned int, |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 312 | % unsigned long long, float, or double in the order specified by map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 313 | % |
| 314 | % Suppose you want to extract the first scanline of a 640x480 image as |
| 315 | % character data in red-green-blue order: |
| 316 | % |
| 317 | % ExportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels,exception); |
| 318 | % |
| 319 | % The format of the ExportImagePixels method is: |
| 320 | % |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 321 | % MagickBooleanType ExportImagePixels(const Image *image,const ssize_t x, |
| 322 | % const ssize_t y,const size_t width,const size_t height, |
| 323 | % const char *map,const StorageType type,void *pixels, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 324 | % ExceptionInfo *exception) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 325 | % |
| 326 | % A description of each parameter follows: |
| 327 | % |
| 328 | % o image: the image. |
| 329 | % |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 330 | % o x,y,width,height: These values define the perimeter |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 331 | % of a region of pixels you want to extract. |
| 332 | % |
| 333 | % o map: This string reflects the expected ordering of the pixel array. |
| 334 | % It can be any combination or order of R = red, G = green, B = blue, |
| 335 | % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan, |
| 336 | % Y = yellow, M = magenta, K = black, I = intensity (for grayscale), |
| 337 | % P = pad. |
| 338 | % |
| 339 | % o type: Define the data type of the pixels. Float and double types are |
| 340 | % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 341 | % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *), |
cristy | ff6834e | 2012-01-10 03:00:25 +0000 | [diff] [blame] | 342 | % LongPixel (unsigned int *), LongLongPixel (unsigned long long *), |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 343 | % QuantumPixel (Quantum *), or ShortPixel (unsigned short *). |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 344 | % |
| 345 | % o pixels: This array of values contain the pixel components as defined by |
| 346 | % map and type. You must preallocate this array where the expected |
| 347 | % length varies depending on the values of width, height, map, and type. |
| 348 | % |
| 349 | % o exception: return any errors or warnings in this structure. |
| 350 | % |
| 351 | */ |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 352 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 353 | static void ExportCharPixel(const Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 354 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 355 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 356 | { |
| 357 | register const Quantum |
| 358 | *restrict p; |
| 359 | |
| 360 | register ssize_t |
| 361 | x; |
| 362 | |
| 363 | register unsigned char |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 364 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 365 | |
| 366 | ssize_t |
| 367 | y; |
| 368 | |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 369 | q=(unsigned char *) pixels; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 370 | if (LocaleCompare(map,"BGR") == 0) |
| 371 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 372 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 373 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 374 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 375 | if (p == (const Quantum *) NULL) |
| 376 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 377 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 378 | { |
| 379 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 380 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 381 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 382 | p+=GetPixelChannels(image); |
| 383 | } |
| 384 | } |
| 385 | return; |
| 386 | } |
| 387 | if (LocaleCompare(map,"BGRA") == 0) |
| 388 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 389 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 390 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 391 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 392 | if (p == (const Quantum *) NULL) |
| 393 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 394 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 395 | { |
| 396 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 397 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 398 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 399 | *q++=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
| 400 | p+=GetPixelChannels(image); |
| 401 | } |
| 402 | } |
| 403 | return; |
| 404 | } |
| 405 | if (LocaleCompare(map,"BGRP") == 0) |
| 406 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 407 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 408 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 409 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 410 | if (p == (const Quantum *) NULL) |
| 411 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 412 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 413 | { |
| 414 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 415 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 416 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 417 | *q++=ScaleQuantumToChar((Quantum) 0); |
| 418 | p+=GetPixelChannels(image); |
| 419 | } |
| 420 | } |
| 421 | return; |
| 422 | } |
| 423 | if (LocaleCompare(map,"I") == 0) |
| 424 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 425 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 426 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 427 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 428 | if (p == (const Quantum *) NULL) |
| 429 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 430 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 431 | { |
| 432 | *q++=ScaleQuantumToChar(GetPixelIntensity(image,p)); |
| 433 | p+=GetPixelChannels(image); |
| 434 | } |
| 435 | } |
| 436 | return; |
| 437 | } |
| 438 | if (LocaleCompare(map,"RGB") == 0) |
| 439 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 440 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 441 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 442 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 443 | if (p == (const Quantum *) NULL) |
| 444 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 445 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 446 | { |
| 447 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 448 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 449 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 450 | p+=GetPixelChannels(image); |
| 451 | } |
| 452 | } |
| 453 | return; |
| 454 | } |
| 455 | if (LocaleCompare(map,"RGBA") == 0) |
| 456 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 457 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 458 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 459 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 460 | if (p == (const Quantum *) NULL) |
| 461 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 462 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 463 | { |
| 464 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 465 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 466 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 467 | *q++=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
| 468 | p+=GetPixelChannels(image); |
| 469 | } |
| 470 | } |
| 471 | return; |
| 472 | } |
| 473 | if (LocaleCompare(map,"RGBP") == 0) |
| 474 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 475 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 476 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 477 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 478 | if (p == (const Quantum *) NULL) |
| 479 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 480 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 481 | { |
| 482 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 483 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 484 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 485 | *q++=ScaleQuantumToChar((Quantum) 0); |
| 486 | p+=GetPixelChannels(image); |
| 487 | } |
| 488 | } |
| 489 | return; |
| 490 | } |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 491 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 492 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 493 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 494 | if (p == (const Quantum *) NULL) |
| 495 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 496 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 497 | { |
| 498 | register ssize_t |
| 499 | i; |
| 500 | |
| 501 | for (i=0; i < (ssize_t) strlen(map); i++) |
| 502 | { |
| 503 | *q=0; |
| 504 | switch (quantum_map[i]) |
| 505 | { |
| 506 | case RedQuantum: |
| 507 | case CyanQuantum: |
| 508 | { |
| 509 | *q=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 510 | break; |
| 511 | } |
| 512 | case GreenQuantum: |
| 513 | case MagentaQuantum: |
| 514 | { |
| 515 | *q=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 516 | break; |
| 517 | } |
| 518 | case BlueQuantum: |
| 519 | case YellowQuantum: |
| 520 | { |
| 521 | *q=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 522 | break; |
| 523 | } |
| 524 | case AlphaQuantum: |
| 525 | { |
| 526 | *q=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
| 527 | break; |
| 528 | } |
| 529 | case OpacityQuantum: |
| 530 | { |
| 531 | *q=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
| 532 | break; |
| 533 | } |
| 534 | case BlackQuantum: |
| 535 | { |
| 536 | if (image->colorspace == CMYKColorspace) |
| 537 | *q=ScaleQuantumToChar(GetPixelBlack(image,p)); |
| 538 | break; |
| 539 | } |
| 540 | case IndexQuantum: |
| 541 | { |
| 542 | *q=ScaleQuantumToChar(GetPixelIntensity(image,p)); |
| 543 | break; |
| 544 | } |
| 545 | default: |
| 546 | break; |
| 547 | } |
| 548 | q++; |
| 549 | } |
| 550 | p+=GetPixelChannels(image); |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 555 | static void ExportDoublePixel(const Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 556 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 557 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 558 | { |
| 559 | register const Quantum |
| 560 | *restrict p; |
| 561 | |
| 562 | register double |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 563 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 564 | |
| 565 | register ssize_t |
| 566 | x; |
| 567 | |
| 568 | ssize_t |
| 569 | y; |
| 570 | |
| 571 | q=(double *) pixels; |
| 572 | if (LocaleCompare(map,"BGR") == 0) |
| 573 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 574 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 575 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 576 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 577 | if (p == (const Quantum *) NULL) |
| 578 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 579 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 580 | { |
| 581 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 582 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 583 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 584 | p+=GetPixelChannels(image); |
| 585 | } |
| 586 | } |
| 587 | return; |
| 588 | } |
| 589 | if (LocaleCompare(map,"BGRA") == 0) |
| 590 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 591 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 592 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 593 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 594 | if (p == (const Quantum *) NULL) |
| 595 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 596 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 597 | { |
| 598 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 599 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 600 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 601 | *q++=(double) (QuantumScale*GetPixelAlpha(image,p)); |
| 602 | p+=GetPixelChannels(image); |
| 603 | } |
| 604 | } |
| 605 | return; |
| 606 | } |
| 607 | if (LocaleCompare(map,"BGRP") == 0) |
| 608 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 609 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 610 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 611 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 612 | if (p == (const Quantum *) NULL) |
| 613 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 614 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 615 | { |
| 616 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 617 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 618 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 619 | *q++=0.0; |
| 620 | p+=GetPixelChannels(image); |
| 621 | } |
| 622 | } |
| 623 | return; |
| 624 | } |
| 625 | if (LocaleCompare(map,"I") == 0) |
| 626 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 627 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 628 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 629 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 630 | if (p == (const Quantum *) NULL) |
| 631 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 632 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 633 | { |
| 634 | *q++=(double) (QuantumScale*GetPixelIntensity(image,p)); |
| 635 | p+=GetPixelChannels(image); |
| 636 | } |
| 637 | } |
| 638 | return; |
| 639 | } |
| 640 | if (LocaleCompare(map,"RGB") == 0) |
| 641 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 642 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 643 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 644 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 645 | if (p == (const Quantum *) NULL) |
| 646 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 647 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 648 | { |
| 649 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 650 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 651 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 652 | p+=GetPixelChannels(image); |
| 653 | } |
| 654 | } |
| 655 | return; |
| 656 | } |
| 657 | if (LocaleCompare(map,"RGBA") == 0) |
| 658 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 659 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 660 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 661 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 662 | if (p == (const Quantum *) NULL) |
| 663 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 664 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 665 | { |
| 666 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 667 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 668 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 669 | *q++=(double) (QuantumScale*GetPixelAlpha(image,p)); |
| 670 | p+=GetPixelChannels(image); |
| 671 | } |
| 672 | } |
| 673 | return; |
| 674 | } |
| 675 | if (LocaleCompare(map,"RGBP") == 0) |
| 676 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 677 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 678 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 679 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 680 | if (p == (const Quantum *) NULL) |
| 681 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 682 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 683 | { |
| 684 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 685 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 686 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 687 | *q++=0.0; |
| 688 | p+=GetPixelChannels(image); |
| 689 | } |
| 690 | } |
| 691 | return; |
| 692 | } |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 693 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 694 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 695 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 696 | if (p == (const Quantum *) NULL) |
| 697 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 698 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 699 | { |
| 700 | register ssize_t |
| 701 | i; |
| 702 | |
| 703 | for (i=0; i < (ssize_t) strlen(map); i++) |
| 704 | { |
| 705 | *q=0; |
| 706 | switch (quantum_map[i]) |
| 707 | { |
| 708 | case RedQuantum: |
| 709 | case CyanQuantum: |
| 710 | { |
| 711 | *q=(double) (QuantumScale*GetPixelRed(image,p)); |
| 712 | break; |
| 713 | } |
| 714 | case GreenQuantum: |
| 715 | case MagentaQuantum: |
| 716 | { |
| 717 | *q=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 718 | break; |
| 719 | } |
| 720 | case BlueQuantum: |
| 721 | case YellowQuantum: |
| 722 | { |
| 723 | *q=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 724 | break; |
| 725 | } |
| 726 | case AlphaQuantum: |
| 727 | { |
| 728 | *q=(double) (QuantumScale*GetPixelAlpha(image,p)); |
| 729 | break; |
| 730 | } |
| 731 | case OpacityQuantum: |
| 732 | { |
| 733 | *q=(double) (QuantumScale*GetPixelAlpha(image,p)); |
| 734 | break; |
| 735 | } |
| 736 | case BlackQuantum: |
| 737 | { |
| 738 | if (image->colorspace == CMYKColorspace) |
| 739 | *q=(double) (QuantumScale* |
| 740 | GetPixelBlack(image,p)); |
| 741 | break; |
| 742 | } |
| 743 | case IndexQuantum: |
| 744 | { |
| 745 | *q=(double) (QuantumScale*GetPixelIntensity(image,p)); |
| 746 | break; |
| 747 | } |
| 748 | default: |
| 749 | *q=0; |
| 750 | } |
| 751 | q++; |
| 752 | } |
| 753 | p+=GetPixelChannels(image); |
| 754 | } |
| 755 | } |
| 756 | } |
| 757 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 758 | static void ExportFloatPixel(const Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 759 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 760 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 761 | { |
| 762 | register const Quantum |
| 763 | *restrict p; |
| 764 | |
| 765 | register float |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 766 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 767 | |
| 768 | register ssize_t |
| 769 | x; |
| 770 | |
| 771 | ssize_t |
| 772 | y; |
| 773 | |
| 774 | q=(float *) pixels; |
| 775 | if (LocaleCompare(map,"BGR") == 0) |
| 776 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 777 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 778 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 779 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 780 | if (p == (const Quantum *) NULL) |
| 781 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 782 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 783 | { |
| 784 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 785 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 786 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 787 | p+=GetPixelChannels(image); |
| 788 | } |
| 789 | } |
| 790 | return; |
| 791 | } |
| 792 | if (LocaleCompare(map,"BGRA") == 0) |
| 793 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 794 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 795 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 796 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 797 | if (p == (const Quantum *) NULL) |
| 798 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 799 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 800 | { |
| 801 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 802 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 803 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 804 | *q++=(float) (QuantumScale*GetPixelAlpha(image,p)); |
| 805 | p+=GetPixelChannels(image); |
| 806 | } |
| 807 | } |
| 808 | return; |
| 809 | } |
| 810 | if (LocaleCompare(map,"BGRP") == 0) |
| 811 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 812 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 813 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 814 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 815 | if (p == (const Quantum *) NULL) |
| 816 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 817 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 818 | { |
| 819 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 820 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 821 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 822 | *q++=0.0; |
| 823 | p+=GetPixelChannels(image); |
| 824 | } |
| 825 | } |
| 826 | return; |
| 827 | } |
| 828 | if (LocaleCompare(map,"I") == 0) |
| 829 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 830 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 831 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 832 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 833 | if (p == (const Quantum *) NULL) |
| 834 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 835 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 836 | { |
| 837 | *q++=(float) (QuantumScale*GetPixelIntensity(image,p)); |
| 838 | p+=GetPixelChannels(image); |
| 839 | } |
| 840 | } |
| 841 | return; |
| 842 | } |
| 843 | if (LocaleCompare(map,"RGB") == 0) |
| 844 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 845 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 846 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 847 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 848 | if (p == (const Quantum *) NULL) |
| 849 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 850 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 851 | { |
| 852 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 853 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 854 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 855 | p+=GetPixelChannels(image); |
| 856 | } |
| 857 | } |
| 858 | return; |
| 859 | } |
| 860 | if (LocaleCompare(map,"RGBA") == 0) |
| 861 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 862 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 863 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 864 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 865 | if (p == (const Quantum *) NULL) |
| 866 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 867 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 868 | { |
| 869 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 870 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 871 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 872 | *q++=(float) (QuantumScale*GetPixelAlpha(image,p)); |
| 873 | p+=GetPixelChannels(image); |
| 874 | } |
| 875 | } |
| 876 | return; |
| 877 | } |
| 878 | if (LocaleCompare(map,"RGBP") == 0) |
| 879 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 880 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 881 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 882 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 883 | if (p == (const Quantum *) NULL) |
| 884 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 885 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 886 | { |
| 887 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 888 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 889 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 890 | *q++=0.0; |
| 891 | p+=GetPixelChannels(image); |
| 892 | } |
| 893 | } |
| 894 | return; |
| 895 | } |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 896 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 897 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 898 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 899 | if (p == (const Quantum *) NULL) |
| 900 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 901 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 902 | { |
| 903 | register ssize_t |
| 904 | i; |
| 905 | |
| 906 | for (i=0; i < (ssize_t) strlen(map); i++) |
| 907 | { |
| 908 | *q=0; |
| 909 | switch (quantum_map[i]) |
| 910 | { |
| 911 | case RedQuantum: |
| 912 | case CyanQuantum: |
| 913 | { |
| 914 | *q=(float) (QuantumScale*GetPixelRed(image,p)); |
| 915 | break; |
| 916 | } |
| 917 | case GreenQuantum: |
| 918 | case MagentaQuantum: |
| 919 | { |
| 920 | *q=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 921 | break; |
| 922 | } |
| 923 | case BlueQuantum: |
| 924 | case YellowQuantum: |
| 925 | { |
| 926 | *q=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 927 | break; |
| 928 | } |
| 929 | case AlphaQuantum: |
| 930 | { |
| 931 | *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p)))); |
| 932 | break; |
| 933 | } |
| 934 | case OpacityQuantum: |
| 935 | { |
| 936 | *q=(float) (QuantumScale*GetPixelAlpha(image,p)); |
| 937 | break; |
| 938 | } |
| 939 | case BlackQuantum: |
| 940 | { |
| 941 | if (image->colorspace == CMYKColorspace) |
| 942 | *q=(float) (QuantumScale* GetPixelBlack(image,p)); |
| 943 | break; |
| 944 | } |
| 945 | case IndexQuantum: |
| 946 | { |
| 947 | *q=(float) (QuantumScale*GetPixelIntensity(image,p)); |
| 948 | break; |
| 949 | } |
| 950 | default: |
| 951 | *q=0; |
| 952 | } |
| 953 | q++; |
| 954 | } |
| 955 | p+=GetPixelChannels(image); |
| 956 | } |
| 957 | } |
| 958 | } |
| 959 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 960 | static void ExportLongPixel(const Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 961 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 962 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 963 | { |
| 964 | register const Quantum |
| 965 | *restrict p; |
| 966 | |
| 967 | register ssize_t |
| 968 | x; |
| 969 | |
| 970 | register unsigned int |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 971 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 972 | |
| 973 | ssize_t |
| 974 | y; |
| 975 | |
| 976 | q=(unsigned int *) pixels; |
| 977 | if (LocaleCompare(map,"BGR") == 0) |
| 978 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 979 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 980 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 981 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 982 | if (p == (const Quantum *) NULL) |
| 983 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 984 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 985 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 986 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 987 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 988 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 989 | p+=GetPixelChannels(image); |
| 990 | } |
| 991 | } |
| 992 | return; |
| 993 | } |
| 994 | if (LocaleCompare(map,"BGRA") == 0) |
| 995 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 996 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 997 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 998 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 999 | if (p == (const Quantum *) NULL) |
| 1000 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1001 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1002 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1003 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1004 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1005 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1006 | *q++=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1007 | p+=GetPixelChannels(image); |
| 1008 | } |
| 1009 | } |
| 1010 | return; |
| 1011 | } |
| 1012 | if (LocaleCompare(map,"BGRP") == 0) |
| 1013 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1014 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1015 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1016 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1017 | if (p == (const Quantum *) NULL) |
| 1018 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1019 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1020 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1021 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1022 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1023 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1024 | *q++=0; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1025 | p+=GetPixelChannels(image); |
| 1026 | } |
| 1027 | } |
| 1028 | return; |
| 1029 | } |
| 1030 | if (LocaleCompare(map,"I") == 0) |
| 1031 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1032 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1033 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1034 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1035 | if (p == (const Quantum *) NULL) |
| 1036 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1037 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1038 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1039 | *q++=ScaleQuantumToLong(GetPixelIntensity(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1040 | p+=GetPixelChannels(image); |
| 1041 | } |
| 1042 | } |
| 1043 | return; |
| 1044 | } |
| 1045 | if (LocaleCompare(map,"RGB") == 0) |
| 1046 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1047 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1048 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1049 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1050 | if (p == (const Quantum *) NULL) |
| 1051 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1052 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1053 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1054 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1055 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1056 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1057 | p+=GetPixelChannels(image); |
| 1058 | } |
| 1059 | } |
| 1060 | return; |
| 1061 | } |
| 1062 | if (LocaleCompare(map,"RGBA") == 0) |
| 1063 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1064 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1065 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1066 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1067 | if (p == (const Quantum *) NULL) |
| 1068 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1069 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1070 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1071 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1072 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1073 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1074 | *q++=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1075 | p+=GetPixelChannels(image); |
| 1076 | } |
| 1077 | } |
| 1078 | return; |
| 1079 | } |
| 1080 | if (LocaleCompare(map,"RGBP") == 0) |
| 1081 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1082 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1083 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1084 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1085 | if (p == (const Quantum *) NULL) |
| 1086 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1087 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1088 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1089 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1090 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1091 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1092 | *q++=0; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1093 | p+=GetPixelChannels(image); |
| 1094 | } |
| 1095 | } |
| 1096 | return; |
| 1097 | } |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1098 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1099 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1100 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1101 | if (p == (const Quantum *) NULL) |
| 1102 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1103 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1104 | { |
| 1105 | register ssize_t |
| 1106 | i; |
| 1107 | |
| 1108 | for (i=0; i < (ssize_t) strlen(map); i++) |
| 1109 | { |
| 1110 | *q=0; |
| 1111 | switch (quantum_map[i]) |
| 1112 | { |
| 1113 | case RedQuantum: |
| 1114 | case CyanQuantum: |
| 1115 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1116 | *q=ScaleQuantumToLong(GetPixelRed(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1117 | break; |
| 1118 | } |
| 1119 | case GreenQuantum: |
| 1120 | case MagentaQuantum: |
| 1121 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1122 | *q=ScaleQuantumToLong(GetPixelGreen(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1123 | break; |
| 1124 | } |
| 1125 | case BlueQuantum: |
| 1126 | case YellowQuantum: |
| 1127 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1128 | *q=ScaleQuantumToLong(GetPixelBlue(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1129 | break; |
| 1130 | } |
| 1131 | case AlphaQuantum: |
| 1132 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1133 | *q=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1134 | break; |
| 1135 | } |
| 1136 | case OpacityQuantum: |
| 1137 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1138 | *q=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1139 | break; |
| 1140 | } |
| 1141 | case BlackQuantum: |
| 1142 | { |
| 1143 | if (image->colorspace == CMYKColorspace) |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1144 | *q=ScaleQuantumToLong(GetPixelBlack(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1145 | break; |
| 1146 | } |
| 1147 | case IndexQuantum: |
| 1148 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1149 | *q=ScaleQuantumToLong(GetPixelIntensity(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1150 | break; |
| 1151 | } |
| 1152 | default: |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1153 | break; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1154 | } |
| 1155 | q++; |
| 1156 | } |
| 1157 | p+=GetPixelChannels(image); |
| 1158 | } |
| 1159 | } |
| 1160 | } |
| 1161 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1162 | static void ExportLongLongPixel(const Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 1163 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 1164 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1165 | { |
| 1166 | register const Quantum |
| 1167 | *restrict p; |
| 1168 | |
| 1169 | register ssize_t |
| 1170 | x; |
| 1171 | |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1172 | register MagickSizeType |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 1173 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1174 | |
| 1175 | ssize_t |
| 1176 | y; |
| 1177 | |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1178 | q=(MagickSizeType *) pixels; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1179 | if (LocaleCompare(map,"BGR") == 0) |
| 1180 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1181 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1182 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1183 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1184 | if (p == (const Quantum *) NULL) |
| 1185 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1186 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1187 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1188 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
| 1189 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
| 1190 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1191 | p+=GetPixelChannels(image); |
| 1192 | } |
| 1193 | } |
| 1194 | return; |
| 1195 | } |
| 1196 | if (LocaleCompare(map,"BGRA") == 0) |
| 1197 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1198 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1199 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1200 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1201 | if (p == (const Quantum *) NULL) |
| 1202 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1203 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1204 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1205 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
| 1206 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
| 1207 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
| 1208 | *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1209 | p+=GetPixelChannels(image); |
| 1210 | } |
| 1211 | } |
| 1212 | return; |
| 1213 | } |
| 1214 | if (LocaleCompare(map,"BGRP") == 0) |
| 1215 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1216 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1217 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1218 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1219 | if (p == (const Quantum *) NULL) |
| 1220 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1221 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1222 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1223 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
| 1224 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
| 1225 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1226 | *q++=0; |
| 1227 | p+=GetPixelChannels(image); |
| 1228 | } |
| 1229 | } |
| 1230 | return; |
| 1231 | } |
| 1232 | if (LocaleCompare(map,"I") == 0) |
| 1233 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1234 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1235 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1236 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1237 | if (p == (const Quantum *) NULL) |
| 1238 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1239 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1240 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1241 | *q++=ScaleQuantumToLongLong(GetPixelIntensity(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1242 | p+=GetPixelChannels(image); |
| 1243 | } |
| 1244 | } |
| 1245 | return; |
| 1246 | } |
| 1247 | if (LocaleCompare(map,"RGB") == 0) |
| 1248 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1249 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1250 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1251 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1252 | if (p == (const Quantum *) NULL) |
| 1253 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1254 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1255 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1256 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
| 1257 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
| 1258 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1259 | p+=GetPixelChannels(image); |
| 1260 | } |
| 1261 | } |
| 1262 | return; |
| 1263 | } |
| 1264 | if (LocaleCompare(map,"RGBA") == 0) |
| 1265 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1266 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1267 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1268 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1269 | if (p == (const Quantum *) NULL) |
| 1270 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1271 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1272 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1273 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
| 1274 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
| 1275 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
| 1276 | *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1277 | p+=GetPixelChannels(image); |
| 1278 | } |
| 1279 | } |
| 1280 | return; |
| 1281 | } |
| 1282 | if (LocaleCompare(map,"RGBP") == 0) |
| 1283 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1284 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1285 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1286 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1287 | if (p == (const Quantum *) NULL) |
| 1288 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1289 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1290 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1291 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
| 1292 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
| 1293 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1294 | *q++=0; |
| 1295 | p+=GetPixelChannels(image); |
| 1296 | } |
| 1297 | } |
| 1298 | return; |
| 1299 | } |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1300 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1301 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1302 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1303 | if (p == (const Quantum *) NULL) |
| 1304 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1305 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1306 | { |
| 1307 | register ssize_t |
| 1308 | i; |
| 1309 | |
| 1310 | for (i=0; i < (ssize_t) strlen(map); i++) |
| 1311 | { |
| 1312 | *q=0; |
| 1313 | switch (quantum_map[i]) |
| 1314 | { |
| 1315 | case RedQuantum: |
| 1316 | case CyanQuantum: |
| 1317 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1318 | *q=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1319 | break; |
| 1320 | } |
| 1321 | case GreenQuantum: |
| 1322 | case MagentaQuantum: |
| 1323 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1324 | *q=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1325 | break; |
| 1326 | } |
| 1327 | case BlueQuantum: |
| 1328 | case YellowQuantum: |
| 1329 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1330 | *q=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1331 | break; |
| 1332 | } |
| 1333 | case AlphaQuantum: |
| 1334 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1335 | *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1336 | break; |
| 1337 | } |
| 1338 | case OpacityQuantum: |
| 1339 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1340 | *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1341 | break; |
| 1342 | } |
| 1343 | case BlackQuantum: |
| 1344 | { |
| 1345 | if (image->colorspace == CMYKColorspace) |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1346 | *q=ScaleQuantumToLongLong(GetPixelBlack(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1347 | break; |
| 1348 | } |
| 1349 | case IndexQuantum: |
| 1350 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1351 | *q=ScaleQuantumToLongLong(GetPixelIntensity(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1352 | break; |
| 1353 | } |
| 1354 | default: |
| 1355 | break; |
| 1356 | } |
| 1357 | q++; |
| 1358 | } |
| 1359 | p+=GetPixelChannels(image); |
| 1360 | } |
| 1361 | } |
| 1362 | } |
| 1363 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1364 | static void ExportQuantumPixel(const Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 1365 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 1366 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1367 | { |
| 1368 | register const Quantum |
| 1369 | *restrict p; |
| 1370 | |
| 1371 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 1372 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1373 | |
| 1374 | register ssize_t |
| 1375 | x; |
| 1376 | |
| 1377 | ssize_t |
| 1378 | y; |
| 1379 | |
| 1380 | q=(Quantum *) pixels; |
| 1381 | if (LocaleCompare(map,"BGR") == 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 | { |
| 1390 | *q++=GetPixelBlue(image,p); |
| 1391 | *q++=GetPixelGreen(image,p); |
| 1392 | *q++=GetPixelRed(image,p); |
| 1393 | p+=GetPixelChannels(image); |
| 1394 | } |
| 1395 | } |
| 1396 | return; |
| 1397 | } |
| 1398 | if (LocaleCompare(map,"BGRA") == 0) |
| 1399 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1400 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1401 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1402 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1403 | if (p == (const Quantum *) NULL) |
| 1404 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1405 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1406 | { |
| 1407 | *q++=GetPixelBlue(image,p); |
| 1408 | *q++=GetPixelGreen(image,p); |
| 1409 | *q++=GetPixelRed(image,p); |
| 1410 | *q++=(Quantum) (GetPixelAlpha(image,p)); |
| 1411 | p+=GetPixelChannels(image); |
| 1412 | } |
| 1413 | } |
| 1414 | return; |
| 1415 | } |
| 1416 | if (LocaleCompare(map,"BGRP") == 0) |
| 1417 | { |
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 | *q++=GetPixelBlue(image,p); |
| 1426 | *q++=GetPixelGreen(image,p); |
| 1427 | *q++=GetPixelRed(image,p); |
| 1428 | *q++=(Quantum) 0; |
| 1429 | p+=GetPixelChannels(image); |
| 1430 | } |
| 1431 | } |
| 1432 | return; |
| 1433 | } |
| 1434 | if (LocaleCompare(map,"I") == 0) |
| 1435 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1436 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1437 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1438 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1439 | if (p == (const Quantum *) NULL) |
| 1440 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1441 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1442 | { |
| 1443 | *q++=GetPixelIntensity(image,p); |
| 1444 | p+=GetPixelChannels(image); |
| 1445 | } |
| 1446 | } |
| 1447 | return; |
| 1448 | } |
| 1449 | if (LocaleCompare(map,"RGB") == 0) |
| 1450 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1451 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1452 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1453 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1454 | if (p == (const Quantum *) NULL) |
| 1455 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1456 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1457 | { |
| 1458 | *q++=GetPixelRed(image,p); |
| 1459 | *q++=GetPixelGreen(image,p); |
| 1460 | *q++=GetPixelBlue(image,p); |
| 1461 | p+=GetPixelChannels(image); |
| 1462 | } |
| 1463 | } |
| 1464 | return; |
| 1465 | } |
| 1466 | if (LocaleCompare(map,"RGBA") == 0) |
| 1467 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1468 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1469 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1470 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1471 | if (p == (const Quantum *) NULL) |
| 1472 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1473 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1474 | { |
| 1475 | *q++=GetPixelRed(image,p); |
| 1476 | *q++=GetPixelGreen(image,p); |
| 1477 | *q++=GetPixelBlue(image,p); |
| 1478 | *q++=(Quantum) (GetPixelAlpha(image,p)); |
| 1479 | p+=GetPixelChannels(image); |
| 1480 | } |
| 1481 | } |
| 1482 | return; |
| 1483 | } |
| 1484 | if (LocaleCompare(map,"RGBP") == 0) |
| 1485 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1486 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1487 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1488 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1489 | if (p == (const Quantum *) NULL) |
| 1490 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1491 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1492 | { |
| 1493 | *q++=GetPixelRed(image,p); |
| 1494 | *q++=GetPixelGreen(image,p); |
| 1495 | *q++=GetPixelBlue(image,p); |
| 1496 | *q++=(Quantum) 0; |
| 1497 | p+=GetPixelChannels(image); |
| 1498 | } |
| 1499 | } |
| 1500 | return; |
| 1501 | } |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1502 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1503 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1504 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1505 | if (p == (const Quantum *) NULL) |
| 1506 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1507 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1508 | { |
| 1509 | register ssize_t |
| 1510 | i; |
| 1511 | |
| 1512 | for (i=0; i < (ssize_t) strlen(map); i++) |
| 1513 | { |
| 1514 | *q=(Quantum) 0; |
| 1515 | switch (quantum_map[i]) |
| 1516 | { |
| 1517 | case RedQuantum: |
| 1518 | case CyanQuantum: |
| 1519 | { |
| 1520 | *q=GetPixelRed(image,p); |
| 1521 | break; |
| 1522 | } |
| 1523 | case GreenQuantum: |
| 1524 | case MagentaQuantum: |
| 1525 | { |
| 1526 | *q=GetPixelGreen(image,p); |
| 1527 | break; |
| 1528 | } |
| 1529 | case BlueQuantum: |
| 1530 | case YellowQuantum: |
| 1531 | { |
| 1532 | *q=GetPixelBlue(image,p); |
| 1533 | break; |
| 1534 | } |
| 1535 | case AlphaQuantum: |
| 1536 | { |
| 1537 | *q=GetPixelAlpha(image,p); |
| 1538 | break; |
| 1539 | } |
| 1540 | case OpacityQuantum: |
| 1541 | { |
| 1542 | *q=GetPixelAlpha(image,p); |
| 1543 | break; |
| 1544 | } |
| 1545 | case BlackQuantum: |
| 1546 | { |
| 1547 | if (image->colorspace == CMYKColorspace) |
| 1548 | *q=GetPixelBlack(image,p); |
| 1549 | break; |
| 1550 | } |
| 1551 | case IndexQuantum: |
| 1552 | { |
| 1553 | *q=(GetPixelIntensity(image,p)); |
| 1554 | break; |
| 1555 | } |
| 1556 | default: |
| 1557 | { |
| 1558 | *q=(Quantum) 0; |
| 1559 | break; |
| 1560 | } |
| 1561 | } |
| 1562 | q++; |
| 1563 | } |
| 1564 | p+=GetPixelChannels(image); |
| 1565 | } |
| 1566 | } |
| 1567 | } |
| 1568 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1569 | static void ExportShortPixel(const Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 1570 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 1571 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1572 | { |
| 1573 | register const Quantum |
| 1574 | *restrict p; |
| 1575 | |
| 1576 | register ssize_t |
| 1577 | x; |
| 1578 | |
| 1579 | ssize_t |
| 1580 | y; |
| 1581 | |
| 1582 | register unsigned short |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 1583 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1584 | |
| 1585 | q=(unsigned short *) pixels; |
| 1586 | if (LocaleCompare(map,"BGR") == 0) |
| 1587 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1588 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1589 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1590 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1591 | if (p == (const Quantum *) NULL) |
| 1592 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1593 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1594 | { |
| 1595 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1596 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1597 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1598 | p+=GetPixelChannels(image); |
| 1599 | } |
| 1600 | } |
| 1601 | return; |
| 1602 | } |
| 1603 | if (LocaleCompare(map,"BGRA") == 0) |
| 1604 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1605 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1606 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1607 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1608 | if (p == (const Quantum *) NULL) |
| 1609 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1610 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1611 | { |
| 1612 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1613 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1614 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1615 | *q++=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
| 1616 | p+=GetPixelChannels(image); |
| 1617 | } |
| 1618 | } |
| 1619 | return; |
| 1620 | } |
| 1621 | if (LocaleCompare(map,"BGRP") == 0) |
| 1622 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1623 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1624 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1625 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1626 | if (p == (const Quantum *) NULL) |
| 1627 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1628 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1629 | { |
| 1630 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1631 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1632 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1633 | *q++=0; |
| 1634 | p+=GetPixelChannels(image); |
| 1635 | } |
| 1636 | } |
| 1637 | return; |
| 1638 | } |
| 1639 | if (LocaleCompare(map,"I") == 0) |
| 1640 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1641 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1642 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1643 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1644 | if (p == (const Quantum *) NULL) |
| 1645 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1646 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1647 | { |
| 1648 | *q++=ScaleQuantumToShort(GetPixelIntensity(image,p)); |
| 1649 | p+=GetPixelChannels(image); |
| 1650 | } |
| 1651 | } |
| 1652 | return; |
| 1653 | } |
| 1654 | if (LocaleCompare(map,"RGB") == 0) |
| 1655 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1656 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1657 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1658 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1659 | if (p == (const Quantum *) NULL) |
| 1660 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1661 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1662 | { |
| 1663 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1664 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1665 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1666 | p+=GetPixelChannels(image); |
| 1667 | } |
| 1668 | } |
| 1669 | return; |
| 1670 | } |
| 1671 | if (LocaleCompare(map,"RGBA") == 0) |
| 1672 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1673 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1674 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1675 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1676 | if (p == (const Quantum *) NULL) |
| 1677 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1678 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1679 | { |
| 1680 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1681 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1682 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1683 | *q++=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
| 1684 | p+=GetPixelChannels(image); |
| 1685 | } |
| 1686 | } |
| 1687 | return; |
| 1688 | } |
| 1689 | if (LocaleCompare(map,"RGBP") == 0) |
| 1690 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1691 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1692 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1693 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1694 | if (p == (const Quantum *) NULL) |
| 1695 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1696 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1697 | { |
| 1698 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1699 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1700 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1701 | *q++=0; |
| 1702 | p+=GetPixelChannels(image); |
| 1703 | } |
| 1704 | } |
| 1705 | return; |
| 1706 | } |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1707 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1708 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1709 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1710 | if (p == (const Quantum *) NULL) |
| 1711 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1712 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1713 | { |
| 1714 | register ssize_t |
| 1715 | i; |
| 1716 | |
| 1717 | for (i=0; i < (ssize_t) strlen(map); i++) |
| 1718 | { |
| 1719 | *q=0; |
| 1720 | switch (quantum_map[i]) |
| 1721 | { |
| 1722 | case RedQuantum: |
| 1723 | case CyanQuantum: |
| 1724 | { |
| 1725 | *q=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1726 | break; |
| 1727 | } |
| 1728 | case GreenQuantum: |
| 1729 | case MagentaQuantum: |
| 1730 | { |
| 1731 | *q=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1732 | break; |
| 1733 | } |
| 1734 | case BlueQuantum: |
| 1735 | case YellowQuantum: |
| 1736 | { |
| 1737 | *q=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1738 | break; |
| 1739 | } |
| 1740 | case AlphaQuantum: |
| 1741 | { |
| 1742 | *q=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
| 1743 | break; |
| 1744 | } |
| 1745 | case OpacityQuantum: |
| 1746 | { |
| 1747 | *q=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
| 1748 | break; |
| 1749 | } |
| 1750 | case BlackQuantum: |
| 1751 | { |
| 1752 | if (image->colorspace == CMYKColorspace) |
| 1753 | *q=ScaleQuantumToShort(GetPixelBlack(image,p)); |
| 1754 | break; |
| 1755 | } |
| 1756 | case IndexQuantum: |
| 1757 | { |
| 1758 | *q=ScaleQuantumToShort(GetPixelIntensity(image,p)); |
| 1759 | break; |
| 1760 | } |
| 1761 | default: |
| 1762 | break; |
| 1763 | } |
| 1764 | q++; |
| 1765 | } |
| 1766 | p+=GetPixelChannels(image); |
| 1767 | } |
| 1768 | } |
| 1769 | } |
| 1770 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1771 | MagickExport MagickBooleanType ExportImagePixels(const Image *image, |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1772 | const ssize_t x,const ssize_t y,const size_t width,const size_t height, |
| 1773 | const char *map,const StorageType type,void *pixels,ExceptionInfo *exception) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1774 | { |
| 1775 | QuantumType |
| 1776 | *quantum_map; |
| 1777 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1778 | RectangleInfo |
| 1779 | roi; |
| 1780 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1781 | register ssize_t |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1782 | i; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1783 | |
| 1784 | assert(image != (Image *) NULL); |
| 1785 | assert(image->signature == MagickSignature); |
| 1786 | if (image->debug != MagickFalse) |
| 1787 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1788 | quantum_map=(QuantumType *) AcquireQuantumMemory(strlen(map), |
| 1789 | sizeof(*quantum_map)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1790 | if (quantum_map == (QuantumType *) NULL) |
| 1791 | { |
| 1792 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 1793 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
| 1794 | return(MagickFalse); |
| 1795 | } |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1796 | for (i=0; i < (ssize_t) strlen(map); i++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1797 | { |
| 1798 | switch (map[i]) |
| 1799 | { |
| 1800 | case 'A': |
| 1801 | case 'a': |
| 1802 | { |
| 1803 | quantum_map[i]=AlphaQuantum; |
| 1804 | break; |
| 1805 | } |
| 1806 | case 'B': |
| 1807 | case 'b': |
| 1808 | { |
| 1809 | quantum_map[i]=BlueQuantum; |
| 1810 | break; |
| 1811 | } |
| 1812 | case 'C': |
| 1813 | case 'c': |
| 1814 | { |
| 1815 | quantum_map[i]=CyanQuantum; |
| 1816 | if (image->colorspace == CMYKColorspace) |
| 1817 | break; |
| 1818 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1819 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
| 1820 | "ColorSeparatedImageRequired","`%s'",map); |
| 1821 | return(MagickFalse); |
| 1822 | } |
| 1823 | case 'g': |
| 1824 | case 'G': |
| 1825 | { |
| 1826 | quantum_map[i]=GreenQuantum; |
| 1827 | break; |
| 1828 | } |
| 1829 | case 'I': |
| 1830 | case 'i': |
| 1831 | { |
| 1832 | quantum_map[i]=IndexQuantum; |
| 1833 | break; |
| 1834 | } |
| 1835 | case 'K': |
| 1836 | case 'k': |
| 1837 | { |
| 1838 | quantum_map[i]=BlackQuantum; |
| 1839 | if (image->colorspace == CMYKColorspace) |
| 1840 | break; |
| 1841 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1842 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
| 1843 | "ColorSeparatedImageRequired","`%s'",map); |
| 1844 | return(MagickFalse); |
| 1845 | } |
| 1846 | case 'M': |
| 1847 | case 'm': |
| 1848 | { |
| 1849 | quantum_map[i]=MagentaQuantum; |
| 1850 | if (image->colorspace == CMYKColorspace) |
| 1851 | break; |
| 1852 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1853 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
| 1854 | "ColorSeparatedImageRequired","`%s'",map); |
| 1855 | return(MagickFalse); |
| 1856 | } |
| 1857 | case 'o': |
| 1858 | case 'O': |
| 1859 | { |
| 1860 | quantum_map[i]=OpacityQuantum; |
| 1861 | break; |
| 1862 | } |
| 1863 | case 'P': |
| 1864 | case 'p': |
| 1865 | { |
| 1866 | quantum_map[i]=UndefinedQuantum; |
| 1867 | break; |
| 1868 | } |
| 1869 | case 'R': |
| 1870 | case 'r': |
| 1871 | { |
| 1872 | quantum_map[i]=RedQuantum; |
| 1873 | break; |
| 1874 | } |
| 1875 | case 'Y': |
| 1876 | case 'y': |
| 1877 | { |
| 1878 | quantum_map[i]=YellowQuantum; |
| 1879 | if (image->colorspace == CMYKColorspace) |
| 1880 | break; |
| 1881 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1882 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
| 1883 | "ColorSeparatedImageRequired","`%s'",map); |
| 1884 | return(MagickFalse); |
| 1885 | } |
| 1886 | default: |
| 1887 | { |
| 1888 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1889 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
| 1890 | "UnrecognizedPixelMap","`%s'",map); |
| 1891 | return(MagickFalse); |
| 1892 | } |
| 1893 | } |
| 1894 | } |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1895 | roi.width=width; |
| 1896 | roi.height=height; |
| 1897 | roi.x=x; |
| 1898 | roi.y=y; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1899 | switch (type) |
| 1900 | { |
| 1901 | case CharPixel: |
| 1902 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1903 | ExportCharPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1904 | break; |
| 1905 | } |
| 1906 | case DoublePixel: |
| 1907 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1908 | ExportDoublePixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1909 | break; |
| 1910 | } |
| 1911 | case FloatPixel: |
| 1912 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1913 | ExportFloatPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1914 | break; |
| 1915 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1916 | case LongPixel: |
| 1917 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1918 | ExportLongPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1919 | break; |
| 1920 | } |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1921 | case LongLongPixel: |
| 1922 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1923 | ExportLongLongPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1924 | break; |
| 1925 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1926 | case QuantumPixel: |
| 1927 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1928 | ExportQuantumPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1929 | break; |
| 1930 | } |
| 1931 | case ShortPixel: |
| 1932 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1933 | ExportShortPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1934 | break; |
| 1935 | } |
| 1936 | default: |
| 1937 | { |
| 1938 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1939 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
| 1940 | "UnrecognizedPixelMap","`%s'",map); |
| 1941 | break; |
| 1942 | } |
| 1943 | } |
| 1944 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1945 | return(MagickTrue); |
| 1946 | } |
| 1947 | |
| 1948 | /* |
| 1949 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1950 | % % |
| 1951 | % % |
| 1952 | % % |
cristy | aa8634f | 2011-10-01 13:25:12 +0000 | [diff] [blame] | 1953 | % G e t P i x e l I n f o % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1954 | % % |
| 1955 | % % |
| 1956 | % % |
| 1957 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1958 | % |
| 1959 | % GetPixelInfo() initializes the PixelInfo structure. |
| 1960 | % |
| 1961 | % The format of the GetPixelInfo method is: |
| 1962 | % |
| 1963 | % GetPixelInfo(const Image *image,PixelInfo *pixel) |
| 1964 | % |
| 1965 | % A description of each parameter follows: |
| 1966 | % |
| 1967 | % o image: the image. |
| 1968 | % |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 1969 | % o pixel: Specifies a pointer to a PixelInfo structure. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1970 | % |
| 1971 | */ |
cristy | aa8634f | 2011-10-01 13:25:12 +0000 | [diff] [blame] | 1972 | MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1973 | { |
| 1974 | pixel->storage_class=DirectClass; |
| 1975 | pixel->colorspace=RGBColorspace; |
| 1976 | pixel->matte=MagickFalse; |
| 1977 | pixel->fuzz=0.0; |
| 1978 | pixel->depth=MAGICKCORE_QUANTUM_DEPTH; |
| 1979 | pixel->red=0.0; |
| 1980 | pixel->green=0.0; |
| 1981 | pixel->blue=0.0; |
| 1982 | pixel->black=0.0; |
| 1983 | pixel->alpha=(MagickRealType) OpaqueAlpha; |
| 1984 | pixel->index=0.0; |
| 1985 | if (image == (const Image *) NULL) |
| 1986 | return; |
| 1987 | pixel->storage_class=image->storage_class; |
| 1988 | pixel->colorspace=image->colorspace; |
| 1989 | pixel->matte=image->matte; |
| 1990 | pixel->depth=image->depth; |
| 1991 | pixel->fuzz=image->fuzz; |
| 1992 | } |
| 1993 | |
| 1994 | /* |
| 1995 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1996 | % % |
| 1997 | % % |
| 1998 | % % |
| 1999 | % I m p o r t I m a g e P i x e l s % |
| 2000 | % % |
| 2001 | % % |
| 2002 | % % |
| 2003 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2004 | % |
| 2005 | % ImportImagePixels() accepts pixel data and stores in the image at the |
| 2006 | % location you specify. The method returns MagickTrue on success otherwise |
| 2007 | % MagickFalse if an error is encountered. The pixel data can be either char, |
cristy | b5a45a3 | 2012-01-10 13:31:13 +0000 | [diff] [blame] | 2008 | % Quantum, short int, unsigned int, unsigned long long, float, or double in |
| 2009 | % the order specified by map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2010 | % |
| 2011 | % Suppose your want to upload the first scanline of a 640x480 image from |
| 2012 | % character data in red-green-blue order: |
| 2013 | % |
| 2014 | % ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels); |
| 2015 | % |
| 2016 | % The format of the ImportImagePixels method is: |
| 2017 | % |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2018 | % MagickBooleanType ImportImagePixels(Image *image,const ssize_t x, |
| 2019 | % const ssize_t y,const size_t width,const size_t height, |
| 2020 | % const char *map,const StorageType type,const void *pixels, |
| 2021 | % ExceptionInfo *exception) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2022 | % |
| 2023 | % A description of each parameter follows: |
| 2024 | % |
| 2025 | % o image: the image. |
| 2026 | % |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2027 | % o x,y,width,height: These values define the perimeter |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2028 | % of a region of pixels you want to define. |
| 2029 | % |
| 2030 | % o map: This string reflects the expected ordering of the pixel array. |
| 2031 | % It can be any combination or order of R = red, G = green, B = blue, |
| 2032 | % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan, |
| 2033 | % Y = yellow, M = magenta, K = black, I = intensity (for grayscale), |
| 2034 | % P = pad. |
| 2035 | % |
| 2036 | % o type: Define the data type of the pixels. Float and double types are |
| 2037 | % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 2038 | % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *), |
cristy | ff6834e | 2012-01-10 03:00:25 +0000 | [diff] [blame] | 2039 | % LongPixel (unsigned int *), LongLongPixel (unsigned long long *), |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 2040 | % QuantumPixel (Quantum *), or ShortPixel (unsigned short *). |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2041 | % |
| 2042 | % o pixels: This array of values contain the pixel components as defined by |
| 2043 | % map and type. You must preallocate this array where the expected |
| 2044 | % length varies depending on the values of width, height, map, and type. |
| 2045 | % |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 2046 | % o exception: return any errors or warnings in this structure. |
| 2047 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2048 | */ |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2049 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2050 | static void ImportCharPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 2051 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 2052 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2053 | { |
| 2054 | register const unsigned char |
| 2055 | *restrict p; |
| 2056 | |
| 2057 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 2058 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2059 | |
| 2060 | register ssize_t |
| 2061 | x; |
| 2062 | |
| 2063 | ssize_t |
| 2064 | y; |
| 2065 | |
| 2066 | p=(const unsigned char *) pixels; |
| 2067 | if (LocaleCompare(map,"BGR") == 0) |
| 2068 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2069 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2070 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2071 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2072 | if (q == (Quantum *) NULL) |
| 2073 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2074 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2075 | { |
| 2076 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2077 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2078 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2079 | q+=GetPixelChannels(image); |
| 2080 | } |
| 2081 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2082 | break; |
| 2083 | } |
| 2084 | return; |
| 2085 | } |
| 2086 | if (LocaleCompare(map,"BGRA") == 0) |
| 2087 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2088 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2089 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2090 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2091 | if (q == (Quantum *) NULL) |
| 2092 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2093 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2094 | { |
| 2095 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2096 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2097 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2098 | SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); |
| 2099 | q+=GetPixelChannels(image); |
| 2100 | } |
| 2101 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2102 | break; |
| 2103 | } |
| 2104 | return; |
| 2105 | } |
| 2106 | if (LocaleCompare(map,"BGRO") == 0) |
| 2107 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2108 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2109 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2110 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2111 | if (q == (Quantum *) NULL) |
| 2112 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2113 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2114 | { |
| 2115 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2116 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2117 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2118 | SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); |
| 2119 | q+=GetPixelChannels(image); |
| 2120 | } |
| 2121 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2122 | break; |
| 2123 | } |
| 2124 | return; |
| 2125 | } |
| 2126 | if (LocaleCompare(map,"BGRP") == 0) |
| 2127 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2128 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2129 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2130 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2131 | if (q == (Quantum *) NULL) |
| 2132 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2133 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2134 | { |
| 2135 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2136 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2137 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2138 | p++; |
| 2139 | q+=GetPixelChannels(image); |
| 2140 | } |
| 2141 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2142 | break; |
| 2143 | } |
| 2144 | return; |
| 2145 | } |
| 2146 | if (LocaleCompare(map,"I") == 0) |
| 2147 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2148 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2149 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2150 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2151 | if (q == (Quantum *) NULL) |
| 2152 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2153 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2154 | { |
| 2155 | SetPixelGray(image,ScaleCharToQuantum(*p++),q); |
| 2156 | q+=GetPixelChannels(image); |
| 2157 | } |
| 2158 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2159 | break; |
| 2160 | } |
| 2161 | return; |
| 2162 | } |
| 2163 | if (LocaleCompare(map,"RGB") == 0) |
| 2164 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2165 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2166 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2167 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2168 | if (q == (Quantum *) NULL) |
| 2169 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2170 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2171 | { |
| 2172 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2173 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2174 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2175 | q+=GetPixelChannels(image); |
| 2176 | } |
| 2177 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2178 | break; |
| 2179 | } |
| 2180 | return; |
| 2181 | } |
| 2182 | if (LocaleCompare(map,"RGBA") == 0) |
| 2183 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2184 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2185 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2186 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2187 | if (q == (Quantum *) NULL) |
| 2188 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2189 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2190 | { |
| 2191 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2192 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2193 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2194 | SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); |
| 2195 | q+=GetPixelChannels(image); |
| 2196 | } |
| 2197 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2198 | break; |
| 2199 | } |
| 2200 | return; |
| 2201 | } |
| 2202 | if (LocaleCompare(map,"RGBO") == 0) |
| 2203 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2204 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2205 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2206 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2207 | if (q == (Quantum *) NULL) |
| 2208 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2209 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2210 | { |
| 2211 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2212 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2213 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2214 | SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); |
| 2215 | q+=GetPixelChannels(image); |
| 2216 | } |
| 2217 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2218 | break; |
| 2219 | } |
| 2220 | return; |
| 2221 | } |
| 2222 | if (LocaleCompare(map,"RGBP") == 0) |
| 2223 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2224 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2225 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2226 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2227 | if (q == (Quantum *) NULL) |
| 2228 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2229 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2230 | { |
| 2231 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2232 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2233 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2234 | p++; |
| 2235 | q+=GetPixelChannels(image); |
| 2236 | } |
| 2237 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2238 | break; |
| 2239 | } |
| 2240 | return; |
| 2241 | } |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2242 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2243 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2244 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2245 | if (q == (Quantum *) NULL) |
| 2246 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2247 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2248 | { |
| 2249 | register ssize_t |
| 2250 | i; |
| 2251 | |
| 2252 | for (i=0; i < (ssize_t) strlen(map); i++) |
| 2253 | { |
| 2254 | switch (quantum_map[i]) |
| 2255 | { |
| 2256 | case RedQuantum: |
| 2257 | case CyanQuantum: |
| 2258 | { |
| 2259 | SetPixelRed(image,ScaleCharToQuantum(*p),q); |
| 2260 | break; |
| 2261 | } |
| 2262 | case GreenQuantum: |
| 2263 | case MagentaQuantum: |
| 2264 | { |
| 2265 | SetPixelGreen(image,ScaleCharToQuantum(*p),q); |
| 2266 | break; |
| 2267 | } |
| 2268 | case BlueQuantum: |
| 2269 | case YellowQuantum: |
| 2270 | { |
| 2271 | SetPixelBlue(image,ScaleCharToQuantum(*p),q); |
| 2272 | break; |
| 2273 | } |
| 2274 | case AlphaQuantum: |
| 2275 | { |
| 2276 | SetPixelAlpha(image,ScaleCharToQuantum(*p),q); |
| 2277 | break; |
| 2278 | } |
| 2279 | case OpacityQuantum: |
| 2280 | { |
| 2281 | SetPixelAlpha(image,ScaleCharToQuantum(*p),q); |
| 2282 | break; |
| 2283 | } |
| 2284 | case BlackQuantum: |
| 2285 | { |
| 2286 | SetPixelBlack(image,ScaleCharToQuantum(*p),q); |
| 2287 | break; |
| 2288 | } |
| 2289 | case IndexQuantum: |
| 2290 | { |
| 2291 | SetPixelGray(image,ScaleCharToQuantum(*p),q); |
| 2292 | break; |
| 2293 | } |
| 2294 | default: |
| 2295 | break; |
| 2296 | } |
| 2297 | p++; |
| 2298 | } |
| 2299 | q+=GetPixelChannels(image); |
| 2300 | } |
| 2301 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2302 | break; |
| 2303 | } |
| 2304 | } |
| 2305 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2306 | static void ImportDoublePixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 2307 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 2308 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2309 | { |
| 2310 | register const double |
| 2311 | *restrict p; |
| 2312 | |
| 2313 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 2314 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2315 | |
| 2316 | register ssize_t |
| 2317 | x; |
| 2318 | |
| 2319 | ssize_t |
| 2320 | y; |
| 2321 | |
| 2322 | p=(const double *) pixels; |
| 2323 | if (LocaleCompare(map,"BGR") == 0) |
| 2324 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2325 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2326 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2327 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2328 | if (q == (Quantum *) NULL) |
| 2329 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2330 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2331 | { |
| 2332 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2333 | (*p)),q); |
| 2334 | p++; |
| 2335 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2336 | (*p)),q); |
| 2337 | p++; |
| 2338 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2339 | (*p)),q); |
| 2340 | p++; |
| 2341 | q+=GetPixelChannels(image); |
| 2342 | } |
| 2343 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2344 | break; |
| 2345 | } |
| 2346 | return; |
| 2347 | } |
| 2348 | if (LocaleCompare(map,"BGRA") == 0) |
| 2349 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2350 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2351 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2352 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2353 | if (q == (Quantum *) NULL) |
| 2354 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2355 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2356 | { |
| 2357 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2358 | (*p)),q); |
| 2359 | p++; |
| 2360 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2361 | (*p)),q); |
| 2362 | p++; |
| 2363 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2364 | (*p)),q); |
| 2365 | p++; |
| 2366 | SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2367 | (*p)),q); |
| 2368 | p++; |
| 2369 | q+=GetPixelChannels(image); |
| 2370 | } |
| 2371 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2372 | break; |
| 2373 | } |
| 2374 | return; |
| 2375 | } |
| 2376 | if (LocaleCompare(map,"BGRP") == 0) |
| 2377 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2378 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2379 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2380 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2381 | if (q == (Quantum *) NULL) |
| 2382 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2383 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2384 | { |
| 2385 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2386 | (*p)),q); |
| 2387 | p++; |
| 2388 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2389 | (*p)),q); |
| 2390 | p++; |
| 2391 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2392 | (*p)),q); |
| 2393 | p++; |
| 2394 | p++; |
| 2395 | q+=GetPixelChannels(image); |
| 2396 | } |
| 2397 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2398 | break; |
| 2399 | } |
| 2400 | return; |
| 2401 | } |
| 2402 | if (LocaleCompare(map,"I") == 0) |
| 2403 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2404 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2405 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2406 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2407 | if (q == (Quantum *) NULL) |
| 2408 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2409 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2410 | { |
| 2411 | SetPixelGray(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2412 | (*p)),q); |
| 2413 | p++; |
| 2414 | q+=GetPixelChannels(image); |
| 2415 | } |
| 2416 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2417 | break; |
| 2418 | } |
| 2419 | return; |
| 2420 | } |
| 2421 | if (LocaleCompare(map,"RGB") == 0) |
| 2422 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2423 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2424 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2425 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2426 | if (q == (Quantum *) NULL) |
| 2427 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2428 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2429 | { |
| 2430 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2431 | (*p)),q); |
| 2432 | p++; |
| 2433 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2434 | (*p)),q); |
| 2435 | p++; |
| 2436 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2437 | (*p)),q); |
| 2438 | p++; |
| 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,ClampToQuantum((MagickRealType) QuantumRange* |
| 2456 | (*p)),q); |
| 2457 | p++; |
| 2458 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2459 | (*p)),q); |
| 2460 | p++; |
| 2461 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2462 | (*p)),q); |
| 2463 | p++; |
| 2464 | SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2465 | (*p)),q); |
| 2466 | p++; |
| 2467 | q+=GetPixelChannels(image); |
| 2468 | } |
| 2469 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2470 | break; |
| 2471 | } |
| 2472 | return; |
| 2473 | } |
| 2474 | if (LocaleCompare(map,"RGBP") == 0) |
| 2475 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2476 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2477 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2478 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2479 | if (q == (Quantum *) NULL) |
| 2480 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2481 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2482 | { |
| 2483 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2484 | (*p)),q); |
| 2485 | p++; |
| 2486 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2487 | (*p)),q); |
| 2488 | p++; |
| 2489 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2490 | (*p)),q); |
| 2491 | p++; |
| 2492 | q+=GetPixelChannels(image); |
| 2493 | } |
| 2494 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2495 | break; |
| 2496 | } |
| 2497 | return; |
| 2498 | } |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2499 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2500 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2501 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2502 | if (q == (Quantum *) NULL) |
| 2503 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2504 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2505 | { |
| 2506 | register ssize_t |
| 2507 | i; |
| 2508 | |
| 2509 | for (i=0; i < (ssize_t) strlen(map); i++) |
| 2510 | { |
| 2511 | switch (quantum_map[i]) |
| 2512 | { |
| 2513 | case RedQuantum: |
| 2514 | case CyanQuantum: |
| 2515 | { |
| 2516 | SetPixelRed(image,ClampToQuantum((MagickRealType) |
| 2517 | QuantumRange*(*p)),q); |
| 2518 | break; |
| 2519 | } |
| 2520 | case GreenQuantum: |
| 2521 | case MagentaQuantum: |
| 2522 | { |
| 2523 | SetPixelGreen(image,ClampToQuantum((MagickRealType) |
| 2524 | QuantumRange*(*p)),q); |
| 2525 | break; |
| 2526 | } |
| 2527 | case BlueQuantum: |
| 2528 | case YellowQuantum: |
| 2529 | { |
| 2530 | SetPixelBlue(image,ClampToQuantum((MagickRealType) |
| 2531 | QuantumRange*(*p)),q); |
| 2532 | break; |
| 2533 | } |
| 2534 | case AlphaQuantum: |
| 2535 | { |
| 2536 | SetPixelAlpha(image,ClampToQuantum((MagickRealType) |
| 2537 | QuantumRange*(*p)),q); |
| 2538 | break; |
| 2539 | } |
| 2540 | case OpacityQuantum: |
| 2541 | { |
| 2542 | SetPixelAlpha(image,ClampToQuantum((MagickRealType) |
| 2543 | QuantumRange*(*p)),q); |
| 2544 | break; |
| 2545 | } |
| 2546 | case BlackQuantum: |
| 2547 | { |
| 2548 | SetPixelBlack(image,ClampToQuantum((MagickRealType) |
| 2549 | QuantumRange*(*p)),q); |
| 2550 | break; |
| 2551 | } |
| 2552 | case IndexQuantum: |
| 2553 | { |
| 2554 | SetPixelGray(image,ClampToQuantum((MagickRealType) |
| 2555 | QuantumRange*(*p)),q); |
| 2556 | break; |
| 2557 | } |
| 2558 | default: |
| 2559 | break; |
| 2560 | } |
| 2561 | p++; |
| 2562 | } |
| 2563 | q+=GetPixelChannels(image); |
| 2564 | } |
| 2565 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2566 | break; |
| 2567 | } |
| 2568 | } |
| 2569 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2570 | static void ImportFloatPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 2571 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 2572 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2573 | { |
| 2574 | register const float |
| 2575 | *restrict p; |
| 2576 | |
| 2577 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 2578 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2579 | |
| 2580 | register ssize_t |
| 2581 | x; |
| 2582 | |
| 2583 | ssize_t |
| 2584 | y; |
| 2585 | |
| 2586 | p=(const float *) pixels; |
| 2587 | if (LocaleCompare(map,"BGR") == 0) |
| 2588 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2589 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2590 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2591 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2592 | if (q == (Quantum *) NULL) |
| 2593 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2594 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2595 | { |
| 2596 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2597 | (*p)),q); |
| 2598 | p++; |
| 2599 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2600 | (*p)),q); |
| 2601 | p++; |
| 2602 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2603 | (*p)),q); |
| 2604 | p++; |
| 2605 | q+=GetPixelChannels(image); |
| 2606 | } |
| 2607 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2608 | break; |
| 2609 | } |
| 2610 | return; |
| 2611 | } |
| 2612 | if (LocaleCompare(map,"BGRA") == 0) |
| 2613 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2614 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2615 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2616 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2617 | if (q == (Quantum *) NULL) |
| 2618 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2619 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2620 | { |
| 2621 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2622 | (*p)),q); |
| 2623 | p++; |
| 2624 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2625 | (*p)),q); |
| 2626 | p++; |
| 2627 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2628 | (*p)),q); |
| 2629 | p++; |
| 2630 | SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2631 | (*p)),q); |
| 2632 | p++; |
| 2633 | q+=GetPixelChannels(image); |
| 2634 | } |
| 2635 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2636 | break; |
| 2637 | } |
| 2638 | return; |
| 2639 | } |
| 2640 | if (LocaleCompare(map,"BGRP") == 0) |
| 2641 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2642 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2643 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2644 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2645 | if (q == (Quantum *) NULL) |
| 2646 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2647 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2648 | { |
| 2649 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2650 | (*p)),q); |
| 2651 | p++; |
| 2652 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2653 | (*p)),q); |
| 2654 | p++; |
| 2655 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2656 | (*p)),q); |
| 2657 | p++; |
| 2658 | p++; |
| 2659 | q+=GetPixelChannels(image); |
| 2660 | } |
| 2661 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2662 | break; |
| 2663 | } |
| 2664 | return; |
| 2665 | } |
| 2666 | if (LocaleCompare(map,"I") == 0) |
| 2667 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2668 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2669 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2670 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2671 | if (q == (Quantum *) NULL) |
| 2672 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2673 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2674 | { |
| 2675 | SetPixelGray(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2676 | (*p)),q); |
| 2677 | p++; |
| 2678 | q+=GetPixelChannels(image); |
| 2679 | } |
| 2680 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2681 | break; |
| 2682 | } |
| 2683 | return; |
| 2684 | } |
| 2685 | if (LocaleCompare(map,"RGB") == 0) |
| 2686 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2687 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2688 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2689 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2690 | if (q == (Quantum *) NULL) |
| 2691 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2692 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2693 | { |
| 2694 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2695 | (*p)),q); |
| 2696 | p++; |
| 2697 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2698 | (*p)),q); |
| 2699 | p++; |
| 2700 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2701 | (*p)),q); |
| 2702 | p++; |
| 2703 | q+=GetPixelChannels(image); |
| 2704 | } |
| 2705 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2706 | break; |
| 2707 | } |
| 2708 | return; |
| 2709 | } |
| 2710 | if (LocaleCompare(map,"RGBA") == 0) |
| 2711 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2712 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2713 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2714 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2715 | if (q == (Quantum *) NULL) |
| 2716 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2717 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2718 | { |
| 2719 | SetPixelRed(image,ClampToQuantum((MagickRealType) |
| 2720 | QuantumRange*(*p)),q); |
| 2721 | p++; |
| 2722 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2723 | (*p)),q); |
| 2724 | p++; |
| 2725 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2726 | (*p)),q); |
| 2727 | p++; |
| 2728 | SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2729 | (*p)),q); |
| 2730 | p++; |
| 2731 | q+=GetPixelChannels(image); |
| 2732 | } |
| 2733 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2734 | break; |
| 2735 | } |
| 2736 | return; |
| 2737 | } |
| 2738 | if (LocaleCompare(map,"RGBP") == 0) |
| 2739 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2740 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2741 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2742 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2743 | if (q == (Quantum *) NULL) |
| 2744 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2745 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2746 | { |
| 2747 | SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2748 | (*p)),q); |
| 2749 | p++; |
| 2750 | SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2751 | (*p)),q); |
| 2752 | p++; |
| 2753 | SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange* |
| 2754 | (*p)),q); |
| 2755 | p++; |
| 2756 | q+=GetPixelChannels(image); |
| 2757 | } |
| 2758 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2759 | break; |
| 2760 | } |
| 2761 | return; |
| 2762 | } |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2763 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2764 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2765 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2766 | if (q == (Quantum *) NULL) |
| 2767 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2768 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2769 | { |
| 2770 | register ssize_t |
| 2771 | i; |
| 2772 | |
| 2773 | for (i=0; i < (ssize_t) strlen(map); i++) |
| 2774 | { |
| 2775 | switch (quantum_map[i]) |
| 2776 | { |
| 2777 | case RedQuantum: |
| 2778 | case CyanQuantum: |
| 2779 | { |
| 2780 | SetPixelRed(image,ClampToQuantum((MagickRealType) |
| 2781 | QuantumRange*(*p)),q); |
| 2782 | break; |
| 2783 | } |
| 2784 | case GreenQuantum: |
| 2785 | case MagentaQuantum: |
| 2786 | { |
| 2787 | SetPixelGreen(image,ClampToQuantum((MagickRealType) |
| 2788 | QuantumRange*(*p)),q); |
| 2789 | break; |
| 2790 | } |
| 2791 | case BlueQuantum: |
| 2792 | case YellowQuantum: |
| 2793 | { |
| 2794 | SetPixelBlue(image,ClampToQuantum((MagickRealType) |
| 2795 | QuantumRange*(*p)),q); |
| 2796 | break; |
| 2797 | } |
| 2798 | case AlphaQuantum: |
| 2799 | { |
| 2800 | SetPixelAlpha(image,ClampToQuantum((MagickRealType) |
| 2801 | QuantumRange*(*p)),q); |
| 2802 | break; |
| 2803 | } |
| 2804 | case OpacityQuantum: |
| 2805 | { |
| 2806 | SetPixelAlpha(image,ClampToQuantum((MagickRealType) |
| 2807 | QuantumRange*(*p)),q); |
| 2808 | break; |
| 2809 | } |
| 2810 | case BlackQuantum: |
| 2811 | { |
| 2812 | SetPixelBlack(image,ClampToQuantum((MagickRealType) |
| 2813 | QuantumRange*(*p)),q); |
| 2814 | break; |
| 2815 | } |
| 2816 | case IndexQuantum: |
| 2817 | { |
| 2818 | SetPixelGray(image,ClampToQuantum((MagickRealType) |
| 2819 | QuantumRange*(*p)),q); |
| 2820 | break; |
| 2821 | } |
| 2822 | default: |
| 2823 | break; |
| 2824 | } |
| 2825 | p++; |
| 2826 | } |
| 2827 | q+=GetPixelChannels(image); |
| 2828 | } |
| 2829 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2830 | break; |
| 2831 | } |
| 2832 | } |
| 2833 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2834 | static void ImportLongPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 2835 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 2836 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2837 | { |
| 2838 | register const unsigned int |
| 2839 | *restrict p; |
| 2840 | |
| 2841 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 2842 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2843 | |
| 2844 | register ssize_t |
| 2845 | x; |
| 2846 | |
| 2847 | ssize_t |
| 2848 | y; |
| 2849 | |
| 2850 | p=(const unsigned int *) pixels; |
| 2851 | if (LocaleCompare(map,"BGR") == 0) |
| 2852 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2853 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2854 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2855 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2856 | if (q == (Quantum *) NULL) |
| 2857 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2858 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2859 | { |
| 2860 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 2861 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 2862 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 2863 | q+=GetPixelChannels(image); |
| 2864 | } |
| 2865 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2866 | break; |
| 2867 | } |
| 2868 | return; |
| 2869 | } |
| 2870 | if (LocaleCompare(map,"BGRA") == 0) |
| 2871 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2872 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2873 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2874 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2875 | if (q == (Quantum *) NULL) |
| 2876 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2877 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2878 | { |
| 2879 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 2880 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 2881 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 2882 | SetPixelAlpha(image,ScaleLongToQuantum(*p++),q); |
| 2883 | q+=GetPixelChannels(image); |
| 2884 | } |
| 2885 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2886 | break; |
| 2887 | } |
| 2888 | return; |
| 2889 | } |
| 2890 | if (LocaleCompare(map,"BGRP") == 0) |
| 2891 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2892 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2893 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2894 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2895 | if (q == (Quantum *) NULL) |
| 2896 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2897 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2898 | { |
| 2899 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 2900 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 2901 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 2902 | p++; |
| 2903 | q+=GetPixelChannels(image); |
| 2904 | } |
| 2905 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2906 | break; |
| 2907 | } |
| 2908 | return; |
| 2909 | } |
| 2910 | if (LocaleCompare(map,"I") == 0) |
| 2911 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2912 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2913 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2914 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2915 | if (q == (Quantum *) NULL) |
| 2916 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2917 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2918 | { |
| 2919 | SetPixelGray(image,ScaleLongToQuantum(*p++),q); |
| 2920 | q+=GetPixelChannels(image); |
| 2921 | } |
| 2922 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2923 | break; |
| 2924 | } |
| 2925 | return; |
| 2926 | } |
| 2927 | if (LocaleCompare(map,"RGB") == 0) |
| 2928 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2929 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2930 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2931 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2932 | if (q == (Quantum *) NULL) |
| 2933 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2934 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2935 | { |
| 2936 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 2937 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 2938 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 2939 | q+=GetPixelChannels(image); |
| 2940 | } |
| 2941 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2942 | break; |
| 2943 | } |
| 2944 | return; |
| 2945 | } |
| 2946 | if (LocaleCompare(map,"RGBA") == 0) |
| 2947 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2948 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2949 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2950 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2951 | if (q == (Quantum *) NULL) |
| 2952 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2953 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2954 | { |
| 2955 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 2956 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 2957 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 2958 | SetPixelAlpha(image,ScaleLongToQuantum(*p++),q); |
| 2959 | q+=GetPixelChannels(image); |
| 2960 | } |
| 2961 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2962 | break; |
| 2963 | } |
| 2964 | return; |
| 2965 | } |
| 2966 | if (LocaleCompare(map,"RGBP") == 0) |
| 2967 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2968 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2969 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2970 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2971 | if (q == (Quantum *) NULL) |
| 2972 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2973 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2974 | { |
| 2975 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 2976 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 2977 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 2978 | p++; |
| 2979 | q+=GetPixelChannels(image); |
| 2980 | } |
| 2981 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2982 | break; |
| 2983 | } |
| 2984 | return; |
| 2985 | } |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2986 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2987 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2988 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2989 | if (q == (Quantum *) NULL) |
| 2990 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2991 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2992 | { |
| 2993 | register ssize_t |
| 2994 | i; |
| 2995 | |
| 2996 | for (i=0; i < (ssize_t) strlen(map); i++) |
| 2997 | { |
| 2998 | switch (quantum_map[i]) |
| 2999 | { |
| 3000 | case RedQuantum: |
| 3001 | case CyanQuantum: |
| 3002 | { |
| 3003 | SetPixelRed(image,ScaleLongToQuantum(*p),q); |
| 3004 | break; |
| 3005 | } |
| 3006 | case GreenQuantum: |
| 3007 | case MagentaQuantum: |
| 3008 | { |
| 3009 | SetPixelGreen(image,ScaleLongToQuantum(*p),q); |
| 3010 | break; |
| 3011 | } |
| 3012 | case BlueQuantum: |
| 3013 | case YellowQuantum: |
| 3014 | { |
| 3015 | SetPixelBlue(image,ScaleLongToQuantum(*p),q); |
| 3016 | break; |
| 3017 | } |
| 3018 | case AlphaQuantum: |
| 3019 | { |
| 3020 | SetPixelAlpha(image,ScaleLongToQuantum(*p),q); |
| 3021 | break; |
| 3022 | } |
| 3023 | case OpacityQuantum: |
| 3024 | { |
| 3025 | SetPixelAlpha(image,ScaleLongToQuantum(*p),q); |
| 3026 | break; |
| 3027 | } |
| 3028 | case BlackQuantum: |
| 3029 | { |
| 3030 | SetPixelBlack(image,ScaleLongToQuantum(*p),q); |
| 3031 | break; |
| 3032 | } |
| 3033 | case IndexQuantum: |
| 3034 | { |
| 3035 | SetPixelGray(image,ScaleLongToQuantum(*p),q); |
| 3036 | break; |
| 3037 | } |
| 3038 | default: |
| 3039 | break; |
| 3040 | } |
| 3041 | p++; |
| 3042 | } |
| 3043 | q+=GetPixelChannels(image); |
| 3044 | } |
| 3045 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3046 | break; |
| 3047 | } |
| 3048 | } |
| 3049 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3050 | static void ImportLongLongPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 3051 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 3052 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3053 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3054 | register const MagickSizeType |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3055 | *restrict p; |
| 3056 | |
| 3057 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 3058 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3059 | |
| 3060 | register ssize_t |
| 3061 | x; |
| 3062 | |
| 3063 | ssize_t |
| 3064 | y; |
| 3065 | |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3066 | p=(const MagickSizeType *) pixels; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3067 | if (LocaleCompare(map,"BGR") == 0) |
| 3068 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3069 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3070 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3071 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3072 | if (q == (Quantum *) NULL) |
| 3073 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3074 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3075 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3076 | SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q); |
| 3077 | SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q); |
| 3078 | SetPixelRed(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3079 | q+=GetPixelChannels(image); |
| 3080 | } |
| 3081 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3082 | break; |
| 3083 | } |
| 3084 | return; |
| 3085 | } |
| 3086 | if (LocaleCompare(map,"BGRA") == 0) |
| 3087 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3088 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3089 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3090 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3091 | if (q == (Quantum *) NULL) |
| 3092 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3093 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3094 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3095 | SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q); |
| 3096 | SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q); |
| 3097 | SetPixelRed(image,ScaleLongLongToQuantum(*p++),q); |
| 3098 | SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3099 | q+=GetPixelChannels(image); |
| 3100 | } |
| 3101 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3102 | break; |
| 3103 | } |
| 3104 | return; |
| 3105 | } |
| 3106 | if (LocaleCompare(map,"BGRP") == 0) |
| 3107 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3108 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3109 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3110 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3111 | if (q == (Quantum *) NULL) |
| 3112 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3113 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3114 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3115 | SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q); |
| 3116 | SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q); |
| 3117 | SetPixelRed(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3118 | p++; |
| 3119 | q+=GetPixelChannels(image); |
| 3120 | } |
| 3121 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3122 | break; |
| 3123 | } |
| 3124 | return; |
| 3125 | } |
| 3126 | if (LocaleCompare(map,"I") == 0) |
| 3127 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3128 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3129 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3130 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3131 | if (q == (Quantum *) NULL) |
| 3132 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3133 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3134 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3135 | SetPixelGray(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3136 | q+=GetPixelChannels(image); |
| 3137 | } |
| 3138 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3139 | break; |
| 3140 | } |
| 3141 | return; |
| 3142 | } |
| 3143 | if (LocaleCompare(map,"RGB") == 0) |
| 3144 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3145 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3146 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3147 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3148 | if (q == (Quantum *) NULL) |
| 3149 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3150 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3151 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3152 | SetPixelRed(image,ScaleLongLongToQuantum(*p++),q); |
| 3153 | SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q); |
| 3154 | SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3155 | q+=GetPixelChannels(image); |
| 3156 | } |
| 3157 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3158 | break; |
| 3159 | } |
| 3160 | return; |
| 3161 | } |
| 3162 | if (LocaleCompare(map,"RGBA") == 0) |
| 3163 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3164 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3165 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3166 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3167 | if (q == (Quantum *) NULL) |
| 3168 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3169 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3170 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3171 | SetPixelRed(image,ScaleLongLongToQuantum(*p++),q); |
| 3172 | SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q); |
| 3173 | SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q); |
| 3174 | SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3175 | q+=GetPixelChannels(image); |
| 3176 | } |
| 3177 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3178 | break; |
| 3179 | } |
| 3180 | return; |
| 3181 | } |
| 3182 | if (LocaleCompare(map,"RGBP") == 0) |
| 3183 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3184 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3185 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3186 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3187 | if (q == (Quantum *) NULL) |
| 3188 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3189 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3190 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3191 | SetPixelRed(image,ScaleLongLongToQuantum(*p++),q); |
| 3192 | SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q); |
| 3193 | SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3194 | p++; |
| 3195 | q+=GetPixelChannels(image); |
| 3196 | } |
| 3197 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3198 | break; |
| 3199 | } |
| 3200 | return; |
| 3201 | } |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3202 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3203 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3204 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3205 | if (q == (Quantum *) NULL) |
| 3206 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3207 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3208 | { |
| 3209 | register ssize_t |
| 3210 | i; |
| 3211 | |
| 3212 | for (i=0; i < (ssize_t) strlen(map); i++) |
| 3213 | { |
| 3214 | switch (quantum_map[i]) |
| 3215 | { |
| 3216 | case RedQuantum: |
| 3217 | case CyanQuantum: |
| 3218 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3219 | SetPixelRed(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3220 | break; |
| 3221 | } |
| 3222 | case GreenQuantum: |
| 3223 | case MagentaQuantum: |
| 3224 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3225 | SetPixelGreen(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3226 | break; |
| 3227 | } |
| 3228 | case BlueQuantum: |
| 3229 | case YellowQuantum: |
| 3230 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3231 | SetPixelBlue(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3232 | break; |
| 3233 | } |
| 3234 | case AlphaQuantum: |
| 3235 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3236 | SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3237 | break; |
| 3238 | } |
| 3239 | case OpacityQuantum: |
| 3240 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3241 | SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3242 | break; |
| 3243 | } |
| 3244 | case BlackQuantum: |
| 3245 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3246 | SetPixelBlack(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3247 | break; |
| 3248 | } |
| 3249 | case IndexQuantum: |
| 3250 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3251 | SetPixelGray(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3252 | break; |
| 3253 | } |
| 3254 | default: |
| 3255 | break; |
| 3256 | } |
| 3257 | p++; |
| 3258 | } |
| 3259 | q+=GetPixelChannels(image); |
| 3260 | } |
| 3261 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3262 | break; |
| 3263 | } |
| 3264 | } |
| 3265 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3266 | static void ImportQuantumPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 3267 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 3268 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3269 | { |
| 3270 | register const Quantum |
| 3271 | *restrict p; |
| 3272 | |
| 3273 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 3274 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3275 | |
| 3276 | register ssize_t |
| 3277 | x; |
| 3278 | |
| 3279 | ssize_t |
| 3280 | y; |
| 3281 | |
| 3282 | p=(const Quantum *) pixels; |
| 3283 | if (LocaleCompare(map,"BGR") == 0) |
| 3284 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3285 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3286 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3287 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3288 | if (q == (Quantum *) NULL) |
| 3289 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3290 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3291 | { |
| 3292 | SetPixelBlue(image,*p++,q); |
| 3293 | SetPixelGreen(image,*p++,q); |
| 3294 | SetPixelRed(image,*p++,q); |
| 3295 | q+=GetPixelChannels(image); |
| 3296 | } |
| 3297 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3298 | break; |
| 3299 | } |
| 3300 | return; |
| 3301 | } |
| 3302 | if (LocaleCompare(map,"BGRA") == 0) |
| 3303 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3304 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3305 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3306 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3307 | if (q == (Quantum *) NULL) |
| 3308 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3309 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3310 | { |
| 3311 | SetPixelBlue(image,*p++,q); |
| 3312 | SetPixelGreen(image,*p++,q); |
| 3313 | SetPixelRed(image,*p++,q); |
| 3314 | SetPixelAlpha(image,*p++,q); |
| 3315 | q+=GetPixelChannels(image); |
| 3316 | } |
| 3317 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3318 | break; |
| 3319 | } |
| 3320 | return; |
| 3321 | } |
| 3322 | if (LocaleCompare(map,"BGRP") == 0) |
| 3323 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3324 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3325 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3326 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3327 | if (q == (Quantum *) NULL) |
| 3328 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3329 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3330 | { |
| 3331 | SetPixelBlue(image,*p++,q); |
| 3332 | SetPixelGreen(image,*p++,q); |
| 3333 | SetPixelRed(image,*p++,q); |
| 3334 | p++; |
| 3335 | q+=GetPixelChannels(image); |
| 3336 | } |
| 3337 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3338 | break; |
| 3339 | } |
| 3340 | return; |
| 3341 | } |
| 3342 | if (LocaleCompare(map,"I") == 0) |
| 3343 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3344 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3345 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3346 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3347 | if (q == (Quantum *) NULL) |
| 3348 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3349 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3350 | { |
| 3351 | SetPixelGray(image,*p++,q); |
| 3352 | q+=GetPixelChannels(image); |
| 3353 | } |
| 3354 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3355 | break; |
| 3356 | } |
| 3357 | return; |
| 3358 | } |
| 3359 | if (LocaleCompare(map,"RGB") == 0) |
| 3360 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3361 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3362 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3363 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3364 | if (q == (Quantum *) NULL) |
| 3365 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3366 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3367 | { |
| 3368 | SetPixelRed(image,*p++,q); |
| 3369 | SetPixelGreen(image,*p++,q); |
| 3370 | SetPixelBlue(image,*p++,q); |
| 3371 | q+=GetPixelChannels(image); |
| 3372 | } |
| 3373 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3374 | break; |
| 3375 | } |
| 3376 | return; |
| 3377 | } |
| 3378 | if (LocaleCompare(map,"RGBA") == 0) |
| 3379 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3380 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3381 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3382 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3383 | if (q == (Quantum *) NULL) |
| 3384 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3385 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3386 | { |
| 3387 | SetPixelRed(image,*p++,q); |
| 3388 | SetPixelGreen(image,*p++,q); |
| 3389 | SetPixelBlue(image,*p++,q); |
| 3390 | SetPixelAlpha(image,*p++,q); |
| 3391 | q+=GetPixelChannels(image); |
| 3392 | } |
| 3393 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3394 | break; |
| 3395 | } |
| 3396 | return; |
| 3397 | } |
| 3398 | if (LocaleCompare(map,"RGBP") == 0) |
| 3399 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3400 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3401 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3402 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3403 | if (q == (Quantum *) NULL) |
| 3404 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3405 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3406 | { |
| 3407 | SetPixelRed(image,*p++,q); |
| 3408 | SetPixelGreen(image,*p++,q); |
| 3409 | SetPixelBlue(image,*p++,q); |
| 3410 | p++; |
| 3411 | q+=GetPixelChannels(image); |
| 3412 | } |
| 3413 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3414 | break; |
| 3415 | } |
| 3416 | return; |
| 3417 | } |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3418 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3419 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3420 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3421 | if (q == (Quantum *) NULL) |
| 3422 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3423 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3424 | { |
| 3425 | register ssize_t |
| 3426 | i; |
| 3427 | |
| 3428 | for (i=0; i < (ssize_t) strlen(map); i++) |
| 3429 | { |
| 3430 | switch (quantum_map[i]) |
| 3431 | { |
| 3432 | case RedQuantum: |
| 3433 | case CyanQuantum: |
| 3434 | { |
| 3435 | SetPixelRed(image,*p,q); |
| 3436 | break; |
| 3437 | } |
| 3438 | case GreenQuantum: |
| 3439 | case MagentaQuantum: |
| 3440 | { |
| 3441 | SetPixelGreen(image,*p,q); |
| 3442 | break; |
| 3443 | } |
| 3444 | case BlueQuantum: |
| 3445 | case YellowQuantum: |
| 3446 | { |
| 3447 | SetPixelBlue(image,*p,q); |
| 3448 | break; |
| 3449 | } |
| 3450 | case AlphaQuantum: |
| 3451 | { |
| 3452 | SetPixelAlpha(image,*p,q); |
| 3453 | break; |
| 3454 | } |
| 3455 | case OpacityQuantum: |
| 3456 | { |
| 3457 | SetPixelAlpha(image,*p,q); |
| 3458 | break; |
| 3459 | } |
| 3460 | case BlackQuantum: |
| 3461 | { |
| 3462 | SetPixelBlack(image,*p,q); |
| 3463 | break; |
| 3464 | } |
| 3465 | case IndexQuantum: |
| 3466 | { |
| 3467 | SetPixelGray(image,*p,q); |
| 3468 | break; |
| 3469 | } |
| 3470 | default: |
| 3471 | break; |
| 3472 | } |
| 3473 | p++; |
| 3474 | } |
| 3475 | q+=GetPixelChannels(image); |
| 3476 | } |
| 3477 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3478 | break; |
| 3479 | } |
| 3480 | } |
| 3481 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3482 | static void ImportShortPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 3483 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 3484 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3485 | { |
| 3486 | register const unsigned short |
| 3487 | *restrict p; |
| 3488 | |
| 3489 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 3490 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3491 | |
| 3492 | register ssize_t |
| 3493 | x; |
| 3494 | |
| 3495 | ssize_t |
| 3496 | y; |
| 3497 | |
| 3498 | p=(const unsigned short *) pixels; |
| 3499 | if (LocaleCompare(map,"BGR") == 0) |
| 3500 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3501 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3502 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3503 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3504 | if (q == (Quantum *) NULL) |
| 3505 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3506 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3507 | { |
| 3508 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3509 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3510 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3511 | q+=GetPixelChannels(image); |
| 3512 | } |
| 3513 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3514 | break; |
| 3515 | } |
| 3516 | return; |
| 3517 | } |
| 3518 | if (LocaleCompare(map,"BGRA") == 0) |
| 3519 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3520 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3521 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3522 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3523 | if (q == (Quantum *) NULL) |
| 3524 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3525 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3526 | { |
| 3527 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3528 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3529 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3530 | SetPixelAlpha(image,ScaleShortToQuantum(*p++),q); |
| 3531 | q+=GetPixelChannels(image); |
| 3532 | } |
| 3533 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3534 | break; |
| 3535 | } |
| 3536 | return; |
| 3537 | } |
| 3538 | if (LocaleCompare(map,"BGRP") == 0) |
| 3539 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3540 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3541 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3542 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3543 | if (q == (Quantum *) NULL) |
| 3544 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3545 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3546 | { |
| 3547 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3548 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3549 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3550 | p++; |
| 3551 | q+=GetPixelChannels(image); |
| 3552 | } |
| 3553 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3554 | break; |
| 3555 | } |
| 3556 | return; |
| 3557 | } |
| 3558 | if (LocaleCompare(map,"I") == 0) |
| 3559 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3560 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3561 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3562 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3563 | if (q == (Quantum *) NULL) |
| 3564 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3565 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3566 | { |
| 3567 | SetPixelGray(image,ScaleShortToQuantum(*p++),q); |
| 3568 | q+=GetPixelChannels(image); |
| 3569 | } |
| 3570 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3571 | break; |
| 3572 | } |
| 3573 | return; |
| 3574 | } |
| 3575 | if (LocaleCompare(map,"RGB") == 0) |
| 3576 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3577 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3578 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3579 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3580 | if (q == (Quantum *) NULL) |
| 3581 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3582 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3583 | { |
| 3584 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3585 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3586 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3587 | q+=GetPixelChannels(image); |
| 3588 | } |
| 3589 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3590 | break; |
| 3591 | } |
| 3592 | return; |
| 3593 | } |
| 3594 | if (LocaleCompare(map,"RGBA") == 0) |
| 3595 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3596 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3597 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3598 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3599 | if (q == (Quantum *) NULL) |
| 3600 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3601 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3602 | { |
| 3603 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3604 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3605 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3606 | SetPixelAlpha(image,ScaleShortToQuantum(*p++),q); |
| 3607 | q+=GetPixelChannels(image); |
| 3608 | } |
| 3609 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3610 | break; |
| 3611 | } |
| 3612 | return; |
| 3613 | } |
| 3614 | if (LocaleCompare(map,"RGBP") == 0) |
| 3615 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3616 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3617 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3618 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3619 | if (q == (Quantum *) NULL) |
| 3620 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3621 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3622 | { |
| 3623 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3624 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3625 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3626 | p++; |
| 3627 | q+=GetPixelChannels(image); |
| 3628 | } |
| 3629 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3630 | break; |
| 3631 | } |
| 3632 | return; |
| 3633 | } |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3634 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3635 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3636 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3637 | if (q == (Quantum *) NULL) |
| 3638 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3639 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3640 | { |
| 3641 | register ssize_t |
| 3642 | i; |
| 3643 | |
| 3644 | for (i=0; i < (ssize_t) strlen(map); i++) |
| 3645 | { |
| 3646 | switch (quantum_map[i]) |
| 3647 | { |
| 3648 | case RedQuantum: |
| 3649 | case CyanQuantum: |
| 3650 | { |
| 3651 | SetPixelRed(image,ScaleShortToQuantum(*p),q); |
| 3652 | break; |
| 3653 | } |
| 3654 | case GreenQuantum: |
| 3655 | case MagentaQuantum: |
| 3656 | { |
| 3657 | SetPixelGreen(image,ScaleShortToQuantum(*p),q); |
| 3658 | break; |
| 3659 | } |
| 3660 | case BlueQuantum: |
| 3661 | case YellowQuantum: |
| 3662 | { |
| 3663 | SetPixelBlue(image,ScaleShortToQuantum(*p),q); |
| 3664 | break; |
| 3665 | } |
| 3666 | case AlphaQuantum: |
| 3667 | { |
| 3668 | SetPixelAlpha(image,ScaleShortToQuantum(*p),q); |
| 3669 | break; |
| 3670 | } |
| 3671 | case OpacityQuantum: |
| 3672 | { |
| 3673 | SetPixelAlpha(image,ScaleShortToQuantum(*p),q); |
| 3674 | break; |
| 3675 | } |
| 3676 | case BlackQuantum: |
| 3677 | { |
| 3678 | SetPixelBlack(image,ScaleShortToQuantum(*p),q); |
| 3679 | break; |
| 3680 | } |
| 3681 | case IndexQuantum: |
| 3682 | { |
| 3683 | SetPixelGray(image,ScaleShortToQuantum(*p),q); |
| 3684 | break; |
| 3685 | } |
| 3686 | default: |
| 3687 | break; |
| 3688 | } |
| 3689 | p++; |
| 3690 | } |
| 3691 | q+=GetPixelChannels(image); |
| 3692 | } |
| 3693 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3694 | break; |
| 3695 | } |
| 3696 | } |
| 3697 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3698 | MagickExport MagickBooleanType ImportImagePixels(Image *image,const ssize_t x, |
| 3699 | const ssize_t y,const size_t width,const size_t height,const char *map, |
| 3700 | const StorageType type,const void *pixels,ExceptionInfo *exception) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3701 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3702 | QuantumType |
| 3703 | *quantum_map; |
| 3704 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3705 | RectangleInfo |
| 3706 | roi; |
| 3707 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3708 | register ssize_t |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3709 | i; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3710 | |
| 3711 | /* |
| 3712 | Allocate image structure. |
| 3713 | */ |
| 3714 | assert(image != (Image *) NULL); |
| 3715 | assert(image->signature == MagickSignature); |
| 3716 | if (image->debug != MagickFalse) |
| 3717 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3718 | quantum_map=(QuantumType *) AcquireQuantumMemory(strlen(map), |
| 3719 | sizeof(*quantum_map)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3720 | if (quantum_map == (QuantumType *) NULL) |
| 3721 | ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", |
| 3722 | image->filename); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3723 | for (i=0; i < (ssize_t) strlen(map); i++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3724 | { |
| 3725 | switch (map[i]) |
| 3726 | { |
| 3727 | case 'a': |
| 3728 | case 'A': |
| 3729 | { |
| 3730 | quantum_map[i]=AlphaQuantum; |
| 3731 | image->matte=MagickTrue; |
| 3732 | break; |
| 3733 | } |
| 3734 | case 'B': |
| 3735 | case 'b': |
| 3736 | { |
| 3737 | quantum_map[i]=BlueQuantum; |
| 3738 | break; |
| 3739 | } |
| 3740 | case 'C': |
| 3741 | case 'c': |
| 3742 | { |
| 3743 | quantum_map[i]=CyanQuantum; |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 3744 | (void) SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3745 | break; |
| 3746 | } |
| 3747 | case 'g': |
| 3748 | case 'G': |
| 3749 | { |
| 3750 | quantum_map[i]=GreenQuantum; |
| 3751 | break; |
| 3752 | } |
| 3753 | case 'K': |
| 3754 | case 'k': |
| 3755 | { |
| 3756 | quantum_map[i]=BlackQuantum; |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 3757 | (void) SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3758 | break; |
| 3759 | } |
| 3760 | case 'I': |
| 3761 | case 'i': |
| 3762 | { |
| 3763 | quantum_map[i]=IndexQuantum; |
| 3764 | break; |
| 3765 | } |
| 3766 | case 'm': |
| 3767 | case 'M': |
| 3768 | { |
| 3769 | quantum_map[i]=MagentaQuantum; |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 3770 | (void) SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3771 | break; |
| 3772 | } |
| 3773 | case 'O': |
| 3774 | case 'o': |
| 3775 | { |
| 3776 | quantum_map[i]=OpacityQuantum; |
| 3777 | image->matte=MagickTrue; |
| 3778 | break; |
| 3779 | } |
| 3780 | case 'P': |
| 3781 | case 'p': |
| 3782 | { |
| 3783 | quantum_map[i]=UndefinedQuantum; |
| 3784 | break; |
| 3785 | } |
| 3786 | case 'R': |
| 3787 | case 'r': |
| 3788 | { |
| 3789 | quantum_map[i]=RedQuantum; |
| 3790 | break; |
| 3791 | } |
| 3792 | case 'Y': |
| 3793 | case 'y': |
| 3794 | { |
| 3795 | quantum_map[i]=YellowQuantum; |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 3796 | (void) SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3797 | break; |
| 3798 | } |
| 3799 | default: |
| 3800 | { |
| 3801 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 3802 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
| 3803 | "UnrecognizedPixelMap","`%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3804 | return(MagickFalse); |
| 3805 | } |
| 3806 | } |
| 3807 | } |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 3808 | if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3809 | return(MagickFalse); |
| 3810 | /* |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3811 | Transfer the pixels from the pixel data to the image. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3812 | */ |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3813 | roi.width=width; |
| 3814 | roi.height=height; |
| 3815 | roi.x=x; |
| 3816 | roi.y=y; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3817 | switch (type) |
| 3818 | { |
| 3819 | case CharPixel: |
| 3820 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3821 | ImportCharPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3822 | break; |
| 3823 | } |
| 3824 | case DoublePixel: |
| 3825 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3826 | ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3827 | break; |
| 3828 | } |
| 3829 | case FloatPixel: |
| 3830 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3831 | ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3832 | break; |
| 3833 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3834 | case LongPixel: |
| 3835 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3836 | ImportLongPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3837 | break; |
| 3838 | } |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 3839 | case LongLongPixel: |
| 3840 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3841 | ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 3842 | break; |
| 3843 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3844 | case QuantumPixel: |
| 3845 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3846 | ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3847 | break; |
| 3848 | } |
| 3849 | case ShortPixel: |
| 3850 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3851 | ImportShortPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3852 | break; |
| 3853 | } |
| 3854 | default: |
| 3855 | { |
| 3856 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 3857 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
| 3858 | "UnrecognizedPixelMap","`%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3859 | break; |
| 3860 | } |
| 3861 | } |
| 3862 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 3863 | return(MagickTrue); |
| 3864 | } |
| 3865 | |
| 3866 | /* |
| 3867 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3868 | % % |
| 3869 | % % |
| 3870 | % % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 3871 | + 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 % |
| 3872 | % % |
| 3873 | % % |
| 3874 | % % |
| 3875 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3876 | % |
| 3877 | % InitializePixelChannelMap() defines the standard pixel component map. |
| 3878 | % |
| 3879 | % The format of the InitializePixelChannelMap() method is: |
| 3880 | % |
| 3881 | % void InitializePixelChannelMap(Image *image) |
| 3882 | % |
| 3883 | % A description of each parameter follows: |
| 3884 | % |
| 3885 | % o image: the image. |
| 3886 | % |
| 3887 | */ |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3888 | MagickExport void InitializePixelChannelMap(Image *image) |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 3889 | { |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3890 | PixelTrait |
| 3891 | trait; |
| 3892 | |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 3893 | register ssize_t |
| 3894 | i; |
| 3895 | |
cristy | d26338f | 2011-12-14 02:39:30 +0000 | [diff] [blame] | 3896 | ssize_t |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 3897 | n; |
| 3898 | |
| 3899 | assert(image != (Image *) NULL); |
| 3900 | assert(image->signature == MagickSignature); |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3901 | (void) ResetMagickMemory(image->channel_map,0,MaxPixelChannels* |
| 3902 | sizeof(*image->channel_map)); |
| 3903 | trait=UpdatePixelTrait; |
| 3904 | if (image->matte != MagickFalse) |
cristy | 61f18ad | 2011-12-08 21:12:37 +0000 | [diff] [blame] | 3905 | trait=(PixelTrait) (trait | BlendPixelTrait); |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 3906 | n=0; |
cristy | c06c580 | 2011-12-31 23:36:16 +0000 | [diff] [blame] | 3907 | if (image->colorspace == GRAYColorspace) |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 3908 | { |
cristy | 3c31628 | 2011-12-15 15:43:24 +0000 | [diff] [blame] | 3909 | SetPixelChannelMap(image,BluePixelChannel,trait,n); |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3910 | SetPixelChannelMap(image,GreenPixelChannel,trait,n); |
cristy | 3c31628 | 2011-12-15 15:43:24 +0000 | [diff] [blame] | 3911 | SetPixelChannelMap(image,RedPixelChannel,trait,n++); |
| 3912 | } |
| 3913 | else |
| 3914 | { |
| 3915 | SetPixelChannelMap(image,RedPixelChannel,trait,n++); |
| 3916 | SetPixelChannelMap(image,GreenPixelChannel,trait,n++); |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3917 | SetPixelChannelMap(image,BluePixelChannel,trait,n++); |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 3918 | } |
| 3919 | if (image->colorspace == CMYKColorspace) |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3920 | SetPixelChannelMap(image,BlackPixelChannel,trait,n++); |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 3921 | if (image->matte != MagickFalse) |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3922 | SetPixelChannelMap(image,AlphaPixelChannel,CopyPixelTrait,n++); |
| 3923 | if (image->storage_class == PseudoClass) |
| 3924 | SetPixelChannelMap(image,IndexPixelChannel,CopyPixelTrait,n++); |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame^] | 3925 | if (image->masky != MagickFalse) |
| 3926 | SetPixelChannelMap(image,MaskPixelChannel,CopyPixelTrait,n++); |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3927 | assert((n+image->number_meta_channels) < MaxPixelChannels); |
| 3928 | for (i=0; i < (ssize_t) image->number_meta_channels; i++) |
cristy | 61f18ad | 2011-12-08 21:12:37 +0000 | [diff] [blame] | 3929 | SetPixelChannelMap(image,(PixelChannel) (MetaPixelChannel+i),CopyPixelTrait, |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3930 | n++); |
cristy | d26338f | 2011-12-14 02:39:30 +0000 | [diff] [blame] | 3931 | image->number_channels=(size_t) n; |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 3932 | if (image->debug != MagickFalse) |
| 3933 | LogPixelChannels(image); |
| 3934 | (void) SetPixelChannelMask(image,image->channel_mask); |
| 3935 | } |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 3936 | |
| 3937 | /* |
| 3938 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3939 | % % |
| 3940 | % % |
| 3941 | % % |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 3942 | % I n t e r p o l a t e P i x e l C h a n n e l % |
| 3943 | % % |
| 3944 | % % |
| 3945 | % % |
| 3946 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3947 | % |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 3948 | % InterpolatePixelChannel() applies a pixel interpolation method between a |
| 3949 | % floating point coordinate and the pixels surrounding that coordinate. No |
| 3950 | % pixel area resampling, or scaling of the result is performed. |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 3951 | % |
| 3952 | % The format of the InterpolatePixelChannel method is: |
| 3953 | % |
| 3954 | % MagickBooleanType InterpolatePixelChannel(const Image *image, |
cristy | 444eda6 | 2011-08-10 02:07:46 +0000 | [diff] [blame] | 3955 | % const CacheView *image_view,const PixelChannel channel, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 3956 | % const PixelInterpolateMethod method,const double x,const double y, |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 3957 | % double *pixel,ExceptionInfo *exception) |
| 3958 | % |
| 3959 | % A description of each parameter follows: |
| 3960 | % |
| 3961 | % o image: the image. |
| 3962 | % |
| 3963 | % o image_view: the image view. |
| 3964 | % |
| 3965 | % o channel: the pixel channel to interpolate. |
| 3966 | % |
| 3967 | % o method: the pixel color interpolation method. |
| 3968 | % |
| 3969 | % o x,y: A double representing the current (x,y) position of the pixel. |
| 3970 | % |
| 3971 | % o pixel: return the interpolated pixel here. |
| 3972 | % |
| 3973 | % o exception: return any errors or warnings in this structure. |
| 3974 | % |
| 3975 | */ |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 3976 | |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 3977 | static inline double MagickMax(const MagickRealType x,const MagickRealType y) |
| 3978 | { |
| 3979 | if (x > y) |
| 3980 | return(x); |
| 3981 | return(y); |
| 3982 | } |
| 3983 | |
| 3984 | static inline MagickRealType CubicWeightingFunction(const MagickRealType x) |
| 3985 | { |
| 3986 | MagickRealType |
| 3987 | alpha, |
| 3988 | gamma; |
| 3989 | |
| 3990 | alpha=MagickMax(x+2.0,0.0); |
| 3991 | gamma=1.0*alpha*alpha*alpha; |
| 3992 | alpha=MagickMax(x+1.0,0.0); |
| 3993 | gamma-=4.0*alpha*alpha*alpha; |
| 3994 | alpha=MagickMax(x+0.0,0.0); |
| 3995 | gamma+=6.0*alpha*alpha*alpha; |
| 3996 | alpha=MagickMax(x-1.0,0.0); |
| 3997 | gamma-=4.0*alpha*alpha*alpha; |
| 3998 | return(gamma/6.0); |
| 3999 | } |
| 4000 | |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4001 | static inline double MeshInterpolate(const PointInfo *delta,const double p, |
| 4002 | const double x,const double y) |
| 4003 | { |
| 4004 | return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p); |
| 4005 | } |
| 4006 | |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4007 | static inline ssize_t NearestNeighbor(const MagickRealType x) |
| 4008 | { |
| 4009 | if (x >= 0.0) |
| 4010 | return((ssize_t) (x+0.5)); |
| 4011 | return((ssize_t) (x-0.5)); |
| 4012 | } |
| 4013 | |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4014 | MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image, |
| 4015 | const CacheView *image_view,const PixelChannel channel, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4016 | const PixelInterpolateMethod method,const double x,const double y, |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4017 | double *pixel,ExceptionInfo *exception) |
| 4018 | { |
| 4019 | MagickBooleanType |
| 4020 | status; |
| 4021 | |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4022 | MagickRealType |
| 4023 | alpha[16], |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4024 | gamma, |
| 4025 | pixels[16]; |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4026 | |
| 4027 | PixelTrait |
| 4028 | traits; |
| 4029 | |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4030 | register const Quantum |
| 4031 | *p; |
| 4032 | |
| 4033 | register ssize_t |
| 4034 | i; |
| 4035 | |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4036 | ssize_t |
| 4037 | x_offset, |
| 4038 | y_offset; |
| 4039 | |
| 4040 | assert(image != (Image *) NULL); |
| 4041 | assert(image != (Image *) NULL); |
| 4042 | assert(image->signature == MagickSignature); |
| 4043 | assert(image_view != (CacheView *) NULL); |
| 4044 | status=MagickTrue; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4045 | *pixel=0.0; |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4046 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4047 | x_offset=(ssize_t) floor(x); |
| 4048 | y_offset=(ssize_t) floor(y); |
| 4049 | switch (method == UndefinedInterpolatePixel ? image->interpolate : method) |
| 4050 | { |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4051 | case AverageInterpolatePixel: |
| 4052 | { |
| 4053 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 4054 | exception); |
| 4055 | if (p == (const Quantum *) NULL) |
| 4056 | { |
| 4057 | status=MagickFalse; |
| 4058 | break; |
| 4059 | } |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 4060 | if ((traits & BlendPixelTrait) == 0) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4061 | for (i=0; i < 16; i++) |
| 4062 | { |
| 4063 | alpha[i]=1.0; |
| 4064 | pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel]; |
| 4065 | } |
| 4066 | else |
| 4067 | for (i=0; i < 16; i++) |
| 4068 | { |
| 4069 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4070 | GetPixelChannels(image)); |
| 4071 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4072 | } |
| 4073 | for (i=0; i < 16; i++) |
| 4074 | { |
| 4075 | gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]); |
| 4076 | *pixel+=gamma*0.0625*pixels[i]; |
| 4077 | } |
| 4078 | break; |
| 4079 | } |
| 4080 | case BicubicInterpolatePixel: |
| 4081 | { |
| 4082 | MagickRealType |
| 4083 | u[4], |
| 4084 | v[4]; |
| 4085 | |
| 4086 | PointInfo |
| 4087 | delta; |
| 4088 | |
| 4089 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 4090 | exception); |
| 4091 | if (p == (const Quantum *) NULL) |
| 4092 | { |
| 4093 | status=MagickFalse; |
| 4094 | break; |
| 4095 | } |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 4096 | if ((traits & BlendPixelTrait) == 0) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4097 | for (i=0; i < 16; i++) |
| 4098 | { |
| 4099 | alpha[i]=1.0; |
| 4100 | pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel]; |
| 4101 | } |
| 4102 | else |
| 4103 | for (i=0; i < 16; i++) |
| 4104 | { |
| 4105 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4106 | GetPixelChannels(image)); |
| 4107 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4108 | } |
| 4109 | delta.x=x-x_offset; |
| 4110 | delta.y=y-y_offset; |
| 4111 | for (i=0; i < 4; i++) |
| 4112 | { |
| 4113 | u[0]=(pixels[4*i+3]-pixels[4*i+2])-(pixels[4*i+0]-pixels[4*i+1]); |
| 4114 | u[1]=(pixels[4*i+0]-pixels[4*i+1])-u[0]; |
| 4115 | u[2]=pixels[4*i+2]-pixels[4*i+0]; |
| 4116 | u[3]=pixels[4*i+1]; |
| 4117 | v[i]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x* |
| 4118 | u[2])+u[3]; |
| 4119 | } |
| 4120 | u[0]=(v[3]-v[2])-(v[0]-v[1]); |
| 4121 | u[1]=(v[0]-v[1])-u[0]; |
| 4122 | u[2]=v[2]-v[0]; |
| 4123 | u[3]=v[1]; |
| 4124 | *pixel=(delta.y*delta.y*delta.y*u[0])+(delta.y*delta.y*u[1])+(delta.y* |
| 4125 | u[2])+u[3]; |
| 4126 | break; |
| 4127 | } |
| 4128 | case BilinearInterpolatePixel: |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4129 | default: |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4130 | { |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4131 | PointInfo |
| 4132 | delta, |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4133 | epsilon; |
| 4134 | |
| 4135 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
| 4136 | if (p == (const Quantum *) NULL) |
| 4137 | { |
| 4138 | status=MagickFalse; |
| 4139 | break; |
| 4140 | } |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 4141 | if ((traits & BlendPixelTrait) == 0) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4142 | for (i=0; i < 4; i++) |
| 4143 | { |
| 4144 | alpha[i]=1.0; |
| 4145 | pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel]; |
| 4146 | } |
| 4147 | else |
| 4148 | for (i=0; i < 4; i++) |
| 4149 | { |
| 4150 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4151 | GetPixelChannels(image)); |
| 4152 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4153 | } |
| 4154 | delta.x=x-x_offset; |
| 4155 | delta.y=y-y_offset; |
| 4156 | epsilon.x=1.0-delta.x; |
| 4157 | epsilon.y=1.0-delta.y; |
| 4158 | gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y* |
| 4159 | (epsilon.x*alpha[2]+delta.x*alpha[3]))); |
| 4160 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 4161 | *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y* |
| 4162 | (epsilon.x*pixels[2]+delta.x*pixels[3])); |
| 4163 | break; |
| 4164 | } |
| 4165 | case FilterInterpolatePixel: |
| 4166 | { |
| 4167 | CacheView |
| 4168 | *filter_view; |
| 4169 | |
| 4170 | Image |
| 4171 | *excerpt_image, |
| 4172 | *filter_image; |
| 4173 | |
| 4174 | RectangleInfo |
| 4175 | geometry; |
| 4176 | |
| 4177 | geometry.width=4L; |
| 4178 | geometry.height=4L; |
| 4179 | geometry.x=x_offset-1; |
| 4180 | geometry.y=y_offset-1; |
| 4181 | excerpt_image=ExcerptImage(image,&geometry,exception); |
| 4182 | if (excerpt_image == (Image *) NULL) |
| 4183 | { |
| 4184 | status=MagickFalse; |
| 4185 | break; |
| 4186 | } |
| 4187 | filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur, |
| 4188 | exception); |
| 4189 | excerpt_image=DestroyImage(excerpt_image); |
| 4190 | if (filter_image == (Image *) NULL) |
| 4191 | break; |
| 4192 | filter_view=AcquireCacheView(filter_image); |
| 4193 | p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception); |
| 4194 | if (p == (const Quantum *) NULL) |
| 4195 | status=MagickFalse; |
| 4196 | else |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 4197 | *pixel=(double) GetPixelChannel(image,channel,p); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4198 | filter_view=DestroyCacheView(filter_view); |
| 4199 | filter_image=DestroyImage(filter_image); |
| 4200 | break; |
| 4201 | } |
| 4202 | case IntegerInterpolatePixel: |
| 4203 | { |
| 4204 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception); |
| 4205 | if (p == (const Quantum *) NULL) |
| 4206 | { |
| 4207 | status=MagickFalse; |
| 4208 | break; |
| 4209 | } |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 4210 | *pixel=(double) GetPixelChannel(image,channel,p); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4211 | break; |
| 4212 | } |
| 4213 | case NearestNeighborInterpolatePixel: |
| 4214 | { |
| 4215 | p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x), |
| 4216 | NearestNeighbor(y),1,1,exception); |
| 4217 | if (p == (const Quantum *) NULL) |
| 4218 | { |
| 4219 | status=MagickFalse; |
| 4220 | break; |
| 4221 | } |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 4222 | *pixel=(double) GetPixelChannel(image,channel,p); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4223 | break; |
| 4224 | } |
| 4225 | case MeshInterpolatePixel: |
| 4226 | { |
| 4227 | PointInfo |
| 4228 | delta, |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4229 | luminance; |
| 4230 | |
| 4231 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
| 4232 | if (p == (const Quantum *) NULL) |
| 4233 | { |
| 4234 | status=MagickFalse; |
| 4235 | break; |
| 4236 | } |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 4237 | if ((traits & BlendPixelTrait) == 0) |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4238 | for (i=0; i < 4; i++) |
| 4239 | { |
| 4240 | alpha[i]=1.0; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4241 | pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel]; |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4242 | } |
| 4243 | else |
| 4244 | for (i=0; i < 4; i++) |
| 4245 | { |
| 4246 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4247 | GetPixelChannels(image)); |
| 4248 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4249 | } |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4250 | delta.x=x-x_offset; |
| 4251 | delta.y=y-y_offset; |
| 4252 | luminance.x=GetPixelLuminance(image,p)-(double) |
| 4253 | GetPixelLuminance(image,p+3*GetPixelChannels(image)); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 4254 | luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4255 | GetPixelLuminance(image,p+2*GetPixelChannels(image)); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4256 | if (fabs(luminance.x) < fabs(luminance.y)) |
| 4257 | { |
| 4258 | /* |
| 4259 | Diagonal 0-3 NW-SE. |
| 4260 | */ |
| 4261 | if (delta.x <= delta.y) |
| 4262 | { |
| 4263 | /* |
| 4264 | Bottom-left triangle (pixel: 2, diagonal: 0-3). |
| 4265 | */ |
| 4266 | delta.y=1.0-delta.y; |
| 4267 | gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]); |
| 4268 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 4269 | *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3], |
| 4270 | pixels[0]); |
| 4271 | } |
| 4272 | else |
| 4273 | { |
| 4274 | /* |
| 4275 | Top-right triangle (pixel: 1, diagonal: 0-3). |
| 4276 | */ |
| 4277 | delta.x=1.0-delta.x; |
| 4278 | gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]); |
| 4279 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 4280 | *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0], |
| 4281 | pixels[3]); |
| 4282 | } |
| 4283 | } |
| 4284 | else |
| 4285 | { |
| 4286 | /* |
| 4287 | Diagonal 1-2 NE-SW. |
| 4288 | */ |
| 4289 | if (delta.x <= (1.0-delta.y)) |
| 4290 | { |
| 4291 | /* |
| 4292 | Top-left triangle (pixel: 0, diagonal: 1-2). |
| 4293 | */ |
| 4294 | gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]); |
| 4295 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 4296 | *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1], |
| 4297 | pixels[2]); |
| 4298 | } |
| 4299 | else |
| 4300 | { |
| 4301 | /* |
| 4302 | Bottom-right triangle (pixel: 3, diagonal: 1-2). |
| 4303 | */ |
| 4304 | delta.x=1.0-delta.x; |
| 4305 | delta.y=1.0-delta.y; |
| 4306 | gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]); |
| 4307 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 4308 | *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2], |
| 4309 | pixels[1]); |
| 4310 | } |
| 4311 | } |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4312 | break; |
| 4313 | } |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4314 | case SplineInterpolatePixel: |
| 4315 | { |
| 4316 | MagickRealType |
| 4317 | dx, |
| 4318 | dy; |
| 4319 | |
| 4320 | PointInfo |
| 4321 | delta; |
| 4322 | |
| 4323 | ssize_t |
| 4324 | j, |
| 4325 | n; |
| 4326 | |
| 4327 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 4328 | exception); |
| 4329 | if (p == (const Quantum *) NULL) |
| 4330 | { |
| 4331 | status=MagickFalse; |
| 4332 | break; |
| 4333 | } |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 4334 | if ((traits & BlendPixelTrait) == 0) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4335 | for (i=0; i < 16; i++) |
| 4336 | { |
| 4337 | alpha[i]=1.0; |
| 4338 | pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel]; |
| 4339 | } |
| 4340 | else |
| 4341 | for (i=0; i < 16; i++) |
| 4342 | { |
| 4343 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4344 | GetPixelChannels(image)); |
| 4345 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4346 | } |
| 4347 | delta.x=x-x_offset; |
| 4348 | delta.y=y-y_offset; |
| 4349 | n=0; |
| 4350 | for (i=(-1); i < 3L; i++) |
| 4351 | { |
| 4352 | dy=CubicWeightingFunction((MagickRealType) i-delta.y); |
| 4353 | for (j=(-1); j < 3L; j++) |
| 4354 | { |
| 4355 | dx=CubicWeightingFunction(delta.x-(MagickRealType) j); |
| 4356 | gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]); |
| 4357 | *pixel+=gamma*dx*dy*pixels[n]; |
| 4358 | n++; |
| 4359 | } |
| 4360 | } |
| 4361 | break; |
| 4362 | } |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4363 | } |
| 4364 | return(status); |
| 4365 | } |
| 4366 | |
| 4367 | /* |
| 4368 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4369 | % % |
| 4370 | % % |
| 4371 | % % |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4372 | % I n t e r p o l a t e P i x e l C h a n n e l s % |
| 4373 | % % |
| 4374 | % % |
| 4375 | % % |
| 4376 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4377 | % |
| 4378 | % InterpolatePixelChannels() applies a pixel interpolation method between a |
| 4379 | % floating point coordinate and the pixels surrounding that coordinate. No |
| 4380 | % pixel area resampling, or scaling of the result is performed. |
| 4381 | % |
| 4382 | % The format of the InterpolatePixelChannels method is: |
| 4383 | % |
| 4384 | % MagickBooleanType InterpolatePixelChannels(const Image *source, |
| 4385 | % const CacheView *source_view,const Image *destination, |
| 4386 | % const PixelInterpolateMethod method,const double x,const double y, |
| 4387 | % Quantum *pixel,ExceptionInfo *exception) |
| 4388 | % |
| 4389 | % A description of each parameter follows: |
| 4390 | % |
| 4391 | % o source: the source. |
| 4392 | % |
| 4393 | % o source_view: the source view. |
| 4394 | % |
| 4395 | % o destination: the destination image. |
| 4396 | % |
| 4397 | % o method: the pixel color interpolation method. |
| 4398 | % |
| 4399 | % o x,y: A double representing the current (x,y) position of the pixel. |
| 4400 | % |
| 4401 | % o pixel: return the interpolated pixel here. |
| 4402 | % |
| 4403 | % o exception: return any errors or warnings in this structure. |
| 4404 | % |
| 4405 | */ |
| 4406 | MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source, |
| 4407 | const CacheView *source_view,const Image *destination, |
| 4408 | const PixelInterpolateMethod method,const double x,const double y, |
| 4409 | Quantum *pixel,ExceptionInfo *exception) |
| 4410 | { |
| 4411 | MagickBooleanType |
| 4412 | status; |
| 4413 | |
| 4414 | MagickRealType |
| 4415 | alpha[16], |
| 4416 | gamma, |
| 4417 | pixels[16]; |
| 4418 | |
| 4419 | PixelChannel |
| 4420 | channel; |
| 4421 | |
| 4422 | PixelTrait |
| 4423 | destination_traits, |
| 4424 | traits; |
| 4425 | |
| 4426 | register const Quantum |
| 4427 | *p; |
| 4428 | |
| 4429 | register ssize_t |
| 4430 | i; |
| 4431 | |
| 4432 | ssize_t |
| 4433 | x_offset, |
| 4434 | y_offset; |
| 4435 | |
| 4436 | assert(source != (Image *) NULL); |
| 4437 | assert(source != (Image *) NULL); |
| 4438 | assert(source->signature == MagickSignature); |
| 4439 | assert(source_view != (CacheView *) NULL); |
| 4440 | status=MagickTrue; |
| 4441 | x_offset=(ssize_t) floor(x); |
| 4442 | y_offset=(ssize_t) floor(y); |
| 4443 | switch (method == UndefinedInterpolatePixel ? source->interpolate : method) |
| 4444 | { |
| 4445 | case AverageInterpolatePixel: |
| 4446 | { |
| 4447 | p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4, |
| 4448 | exception); |
| 4449 | if (p == (const Quantum *) NULL) |
| 4450 | { |
| 4451 | status=MagickFalse; |
| 4452 | break; |
| 4453 | } |
| 4454 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
| 4455 | { |
| 4456 | double |
| 4457 | sum; |
| 4458 | |
| 4459 | register ssize_t |
| 4460 | j; |
| 4461 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 4462 | channel=GetPixelChannelMapChannel(source,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 4463 | traits=GetPixelChannelMapTraits(source,channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4464 | destination_traits=GetPixelChannelMapTraits(destination,channel); |
| 4465 | if ((traits == UndefinedPixelTrait) || |
| 4466 | (destination_traits == UndefinedPixelTrait)) |
| 4467 | continue; |
| 4468 | for (j=0; j < 16; j++) |
| 4469 | pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i]; |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4470 | sum=0.0; |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4471 | if ((traits & BlendPixelTrait) == 0) |
| 4472 | { |
| 4473 | for (j=0; j < 16; j++) |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4474 | sum+=0.0625*pixels[j]; |
| 4475 | SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4476 | continue; |
| 4477 | } |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4478 | for (j=0; j < 16; j++) |
| 4479 | { |
| 4480 | alpha[j]=QuantumScale*GetPixelAlpha(source,p+j* |
| 4481 | GetPixelChannels(source)); |
| 4482 | pixels[j]*=alpha[j]; |
| 4483 | gamma=1.0/(fabs((double) alpha[j]) <= MagickEpsilon ? 1.0 : alpha[j]); |
| 4484 | sum+=gamma*0.0625*pixels[j]; |
| 4485 | } |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4486 | SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4487 | } |
| 4488 | break; |
| 4489 | } |
| 4490 | case BicubicInterpolatePixel: |
| 4491 | { |
| 4492 | MagickRealType |
| 4493 | u[4], |
| 4494 | v[4]; |
| 4495 | |
| 4496 | PointInfo |
| 4497 | delta; |
| 4498 | |
| 4499 | p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4, |
| 4500 | exception); |
| 4501 | if (p == (const Quantum *) NULL) |
| 4502 | { |
| 4503 | status=MagickFalse; |
| 4504 | break; |
| 4505 | } |
| 4506 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
| 4507 | { |
| 4508 | register ssize_t |
| 4509 | j; |
| 4510 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 4511 | channel=GetPixelChannelMapChannel(source,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 4512 | traits=GetPixelChannelMapTraits(source,channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4513 | destination_traits=GetPixelChannelMapTraits(destination,channel); |
| 4514 | if ((traits == UndefinedPixelTrait) || |
| 4515 | (destination_traits == UndefinedPixelTrait)) |
| 4516 | continue; |
| 4517 | if ((traits & BlendPixelTrait) == 0) |
| 4518 | for (j=0; j < 16; j++) |
| 4519 | { |
| 4520 | alpha[j]=1.0; |
| 4521 | pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i]; |
| 4522 | } |
| 4523 | else |
| 4524 | for (j=0; j < 16; j++) |
| 4525 | { |
| 4526 | alpha[j]=QuantumScale*GetPixelAlpha(source,p+j* |
| 4527 | GetPixelChannels(source)); |
| 4528 | pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i]; |
| 4529 | } |
| 4530 | delta.x=x-x_offset; |
| 4531 | delta.y=y-y_offset; |
| 4532 | for (j=0; j < 4; j++) |
| 4533 | { |
| 4534 | u[0]=(pixels[4*j+3]-pixels[4*j+2])-(pixels[4*j+0]-pixels[4*j+1]); |
| 4535 | u[1]=(pixels[4*j+0]-pixels[4*j+1])-u[0]; |
| 4536 | u[2]=pixels[4*j+2]-pixels[4*j+0]; |
| 4537 | u[3]=pixels[4*j+1]; |
| 4538 | v[j]=(delta.x*delta.x*delta.x*u[0])+(delta.x*delta.x*u[1])+(delta.x* |
| 4539 | u[2])+u[3]; |
| 4540 | } |
| 4541 | u[0]=(v[3]-v[2])-(v[0]-v[1]); |
| 4542 | u[1]=(v[0]-v[1])-u[0]; |
| 4543 | u[2]=v[2]-v[0]; |
| 4544 | u[3]=v[1]; |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4545 | SetPixelChannel(destination,channel,ClampToQuantum((delta.y*delta.y* |
| 4546 | delta.y*u[0])+(delta.y*delta.y*u[1])+(delta.y*u[2])+u[3]),pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4547 | } |
| 4548 | break; |
| 4549 | } |
| 4550 | case BilinearInterpolatePixel: |
| 4551 | default: |
| 4552 | { |
| 4553 | p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception); |
| 4554 | if (p == (const Quantum *) NULL) |
| 4555 | { |
| 4556 | status=MagickFalse; |
| 4557 | break; |
| 4558 | } |
| 4559 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
| 4560 | { |
| 4561 | PointInfo |
| 4562 | delta, |
| 4563 | epsilon; |
| 4564 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 4565 | channel=GetPixelChannelMapChannel(source,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 4566 | traits=GetPixelChannelMapTraits(source,channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4567 | destination_traits=GetPixelChannelMapTraits(destination,channel); |
| 4568 | if ((traits == UndefinedPixelTrait) || |
| 4569 | (destination_traits == UndefinedPixelTrait)) |
| 4570 | continue; |
| 4571 | delta.x=x-x_offset; |
| 4572 | delta.y=y-y_offset; |
| 4573 | epsilon.x=1.0-delta.x; |
| 4574 | epsilon.y=1.0-delta.y; |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 4575 | pixels[0]=(MagickRealType) p[i]; |
| 4576 | pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i]; |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4577 | pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i]; |
| 4578 | pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i]; |
| 4579 | if ((traits & BlendPixelTrait) == 0) |
| 4580 | { |
| 4581 | gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x))); |
| 4582 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4583 | SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y* |
| 4584 | (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x* |
| 4585 | pixels[2]+delta.x*pixels[3]))),pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4586 | continue; |
| 4587 | } |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 4588 | alpha[0]=QuantumScale*GetPixelAlpha(source,p); |
| 4589 | alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source)); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4590 | alpha[2]=QuantumScale*GetPixelAlpha(source,p+2* |
| 4591 | GetPixelChannels(source)); |
| 4592 | alpha[3]=QuantumScale*GetPixelAlpha(source,p+3* |
| 4593 | GetPixelChannels(source)); |
| 4594 | pixels[0]*=alpha[0]; |
| 4595 | pixels[1]*=alpha[1]; |
| 4596 | pixels[2]*=alpha[2]; |
| 4597 | pixels[3]*=alpha[3]; |
| 4598 | gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y* |
| 4599 | (epsilon.x*alpha[2]+delta.x*alpha[3]))); |
| 4600 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4601 | SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y* |
| 4602 | (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+ |
| 4603 | delta.x*pixels[3]))),pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4604 | } |
| 4605 | break; |
| 4606 | } |
| 4607 | case FilterInterpolatePixel: |
| 4608 | { |
| 4609 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
| 4610 | { |
| 4611 | CacheView |
| 4612 | *filter_view; |
| 4613 | |
| 4614 | Image |
| 4615 | *excerpt_source, |
| 4616 | *filter_source; |
| 4617 | |
| 4618 | RectangleInfo |
| 4619 | geometry; |
| 4620 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 4621 | channel=GetPixelChannelMapChannel(source,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 4622 | traits=GetPixelChannelMapTraits(source,channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4623 | destination_traits=GetPixelChannelMapTraits(destination,channel); |
| 4624 | if ((traits == UndefinedPixelTrait) || |
| 4625 | (destination_traits == UndefinedPixelTrait)) |
| 4626 | continue; |
| 4627 | geometry.width=4L; |
| 4628 | geometry.height=4L; |
| 4629 | geometry.x=x_offset-1; |
| 4630 | geometry.y=y_offset-1; |
| 4631 | excerpt_source=ExcerptImage(source,&geometry,exception); |
| 4632 | if (excerpt_source == (Image *) NULL) |
| 4633 | { |
| 4634 | status=MagickFalse; |
| 4635 | continue; |
| 4636 | } |
| 4637 | filter_source=ResizeImage(excerpt_source,1,1,source->filter, |
| 4638 | source->blur,exception); |
| 4639 | excerpt_source=DestroyImage(excerpt_source); |
| 4640 | if (filter_source == (Image *) NULL) |
| 4641 | continue; |
| 4642 | filter_view=AcquireCacheView(filter_source); |
| 4643 | p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception); |
| 4644 | if (p == (const Quantum *) NULL) |
| 4645 | status=MagickFalse; |
| 4646 | else |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 4647 | { |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4648 | SetPixelChannel(destination,channel,p[i],pixel); |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 4649 | } |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4650 | filter_view=DestroyCacheView(filter_view); |
| 4651 | filter_source=DestroyImage(filter_source); |
| 4652 | } |
| 4653 | break; |
| 4654 | } |
| 4655 | case IntegerInterpolatePixel: |
| 4656 | { |
| 4657 | p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception); |
| 4658 | if (p == (const Quantum *) NULL) |
| 4659 | { |
| 4660 | status=MagickFalse; |
| 4661 | break; |
| 4662 | } |
| 4663 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
| 4664 | { |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 4665 | channel=GetPixelChannelMapChannel(source,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 4666 | traits=GetPixelChannelMapTraits(source,channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4667 | destination_traits=GetPixelChannelMapTraits(destination,channel); |
| 4668 | if ((traits == UndefinedPixelTrait) || |
| 4669 | (destination_traits == UndefinedPixelTrait)) |
| 4670 | continue; |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4671 | SetPixelChannel(destination,channel,p[i],pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4672 | } |
| 4673 | break; |
| 4674 | } |
| 4675 | case NearestNeighborInterpolatePixel: |
| 4676 | { |
| 4677 | p=GetCacheViewVirtualPixels(source_view,NearestNeighbor(x), |
| 4678 | NearestNeighbor(y),1,1,exception); |
| 4679 | if (p == (const Quantum *) NULL) |
| 4680 | { |
| 4681 | status=MagickFalse; |
| 4682 | break; |
| 4683 | } |
| 4684 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
| 4685 | { |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 4686 | channel=GetPixelChannelMapChannel(source,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 4687 | traits=GetPixelChannelMapTraits(source,channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4688 | destination_traits=GetPixelChannelMapTraits(destination,channel); |
| 4689 | if ((traits == UndefinedPixelTrait) || |
| 4690 | (destination_traits == UndefinedPixelTrait)) |
| 4691 | continue; |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4692 | SetPixelChannel(destination,channel,p[i],pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4693 | } |
| 4694 | break; |
| 4695 | } |
| 4696 | case MeshInterpolatePixel: |
| 4697 | { |
| 4698 | p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception); |
| 4699 | if (p == (const Quantum *) NULL) |
| 4700 | { |
| 4701 | status=MagickFalse; |
| 4702 | break; |
| 4703 | } |
| 4704 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
| 4705 | { |
| 4706 | PointInfo |
| 4707 | delta, |
| 4708 | luminance; |
| 4709 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 4710 | channel=GetPixelChannelMapChannel(source,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 4711 | traits=GetPixelChannelMapTraits(source,channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4712 | destination_traits=GetPixelChannelMapTraits(destination,channel); |
| 4713 | if ((traits == UndefinedPixelTrait) || |
| 4714 | (destination_traits == UndefinedPixelTrait)) |
| 4715 | continue; |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 4716 | pixels[0]=(MagickRealType) p[i]; |
| 4717 | pixels[1]=(MagickRealType) p[GetPixelChannels(source)+i]; |
| 4718 | pixels[2]=(MagickRealType) p[2*GetPixelChannels(source)+i]; |
| 4719 | pixels[3]=(MagickRealType) p[3*GetPixelChannels(source)+i]; |
| 4720 | if ((traits & BlendPixelTrait) == 0) |
| 4721 | { |
| 4722 | alpha[0]=1.0; |
| 4723 | alpha[1]=1.0; |
| 4724 | alpha[2]=1.0; |
| 4725 | alpha[3]=1.0; |
| 4726 | } |
| 4727 | else |
| 4728 | { |
| 4729 | alpha[0]=QuantumScale*GetPixelAlpha(source,p); |
| 4730 | alpha[1]=QuantumScale*GetPixelAlpha(source,p+ |
| 4731 | GetPixelChannels(source)); |
| 4732 | alpha[2]=QuantumScale*GetPixelAlpha(source,p+2* |
| 4733 | GetPixelChannels(source)); |
| 4734 | alpha[3]=QuantumScale*GetPixelAlpha(source,p+3* |
| 4735 | GetPixelChannels(source)); |
| 4736 | } |
| 4737 | delta.x=x-x_offset; |
| 4738 | delta.y=y-y_offset; |
| 4739 | luminance.x=GetPixelLuminance(source,p)-(double) |
| 4740 | GetPixelLuminance(source,p+3*GetPixelChannels(source)); |
| 4741 | luminance.y=GetPixelLuminance(source,p+GetPixelChannels(source))- |
| 4742 | (double) GetPixelLuminance(source,p+2*GetPixelChannels(source)); |
| 4743 | if (fabs(luminance.x) < fabs(luminance.y)) |
| 4744 | { |
| 4745 | /* |
| 4746 | Diagonal 0-3 NW-SE. |
| 4747 | */ |
| 4748 | if (delta.x <= delta.y) |
| 4749 | { |
| 4750 | /* |
| 4751 | Bottom-left triangle (pixel: 2, diagonal: 0-3). |
| 4752 | */ |
| 4753 | delta.y=1.0-delta.y; |
| 4754 | gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]); |
| 4755 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4756 | SetPixelChannel(destination,channel,ClampToQuantum(gamma* |
| 4757 | MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel); |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 4758 | } |
| 4759 | else |
| 4760 | { |
| 4761 | /* |
| 4762 | Top-right triangle (pixel: 1, diagonal: 0-3). |
| 4763 | */ |
| 4764 | delta.x=1.0-delta.x; |
| 4765 | gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]); |
| 4766 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4767 | SetPixelChannel(destination,channel,ClampToQuantum(gamma* |
| 4768 | MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel); |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 4769 | } |
| 4770 | } |
| 4771 | else |
| 4772 | { |
| 4773 | /* |
| 4774 | Diagonal 1-2 NE-SW. |
| 4775 | */ |
| 4776 | if (delta.x <= (1.0-delta.y)) |
| 4777 | { |
| 4778 | /* |
| 4779 | Top-left triangle (pixel: 0, diagonal: 1-2). |
| 4780 | */ |
| 4781 | gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]); |
| 4782 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4783 | SetPixelChannel(destination,channel,ClampToQuantum(gamma* |
| 4784 | MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel); |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 4785 | } |
| 4786 | else |
| 4787 | { |
| 4788 | /* |
| 4789 | Bottom-right triangle (pixel: 3, diagonal: 1-2). |
| 4790 | */ |
| 4791 | delta.x=1.0-delta.x; |
| 4792 | delta.y=1.0-delta.y; |
| 4793 | gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]); |
| 4794 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4795 | SetPixelChannel(destination,channel,ClampToQuantum(gamma* |
| 4796 | MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel); |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 4797 | } |
| 4798 | } |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4799 | } |
| 4800 | break; |
| 4801 | } |
| 4802 | case SplineInterpolatePixel: |
| 4803 | { |
| 4804 | p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4, |
| 4805 | exception); |
| 4806 | if (p == (const Quantum *) NULL) |
| 4807 | { |
| 4808 | status=MagickFalse; |
| 4809 | break; |
| 4810 | } |
| 4811 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
| 4812 | { |
| 4813 | double |
| 4814 | sum; |
| 4815 | |
| 4816 | MagickRealType |
| 4817 | dx, |
| 4818 | dy; |
| 4819 | |
| 4820 | PointInfo |
| 4821 | delta; |
| 4822 | |
| 4823 | register ssize_t |
| 4824 | j; |
| 4825 | |
| 4826 | ssize_t |
| 4827 | k, |
| 4828 | n; |
| 4829 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 4830 | channel=GetPixelChannelMapChannel(source,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 4831 | traits=GetPixelChannelMapTraits(source,channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4832 | destination_traits=GetPixelChannelMapTraits(destination,channel); |
| 4833 | if ((traits == UndefinedPixelTrait) || |
| 4834 | (destination_traits == UndefinedPixelTrait)) |
| 4835 | continue; |
| 4836 | if ((traits & BlendPixelTrait) == 0) |
| 4837 | for (j=0; j < 16; j++) |
| 4838 | { |
| 4839 | alpha[j]=1.0; |
| 4840 | pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+i]; |
| 4841 | } |
| 4842 | else |
| 4843 | for (j=0; j < 16; j++) |
| 4844 | { |
| 4845 | alpha[j]=QuantumScale*GetPixelAlpha(source,p+j* |
| 4846 | GetPixelChannels(source)); |
| 4847 | pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i]; |
| 4848 | } |
| 4849 | delta.x=x-x_offset; |
| 4850 | delta.y=y-y_offset; |
| 4851 | sum=0.0; |
| 4852 | n=0; |
| 4853 | for (j=(-1); j < 3L; j++) |
| 4854 | { |
| 4855 | dy=CubicWeightingFunction((MagickRealType) j-delta.y); |
| 4856 | for (k=(-1); k < 3L; k++) |
| 4857 | { |
| 4858 | dx=CubicWeightingFunction(delta.x-(MagickRealType) k); |
| 4859 | gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : |
| 4860 | alpha[n]); |
| 4861 | sum+=gamma*dx*dy*pixels[n]; |
| 4862 | n++; |
| 4863 | } |
| 4864 | } |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4865 | SetPixelChannel(destination,channel,p[i],pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4866 | } |
| 4867 | break; |
| 4868 | } |
| 4869 | } |
| 4870 | return(status); |
| 4871 | } |
| 4872 | |
| 4873 | /* |
| 4874 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4875 | % % |
| 4876 | % % |
| 4877 | % % |
cristy | 9075cdb | 2011-07-30 01:06:23 +0000 | [diff] [blame] | 4878 | % 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] | 4879 | % % |
| 4880 | % % |
| 4881 | % % |
| 4882 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4883 | % |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4884 | % InterpolatePixelInfo() applies a pixel interpolation method between a |
| 4885 | % floating point coordinate and the pixels surrounding that coordinate. No |
| 4886 | % pixel area resampling, or scaling of the result is performed. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4887 | % |
| 4888 | % The format of the InterpolatePixelInfo method is: |
| 4889 | % |
| 4890 | % MagickBooleanType InterpolatePixelInfo(const Image *image, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4891 | % const CacheView *image_view,const PixelInterpolateMethod method, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4892 | % const double x,const double y,PixelInfo *pixel, |
| 4893 | % ExceptionInfo *exception) |
| 4894 | % |
| 4895 | % A description of each parameter follows: |
| 4896 | % |
| 4897 | % o image: the image. |
| 4898 | % |
| 4899 | % o image_view: the image view. |
| 4900 | % |
| 4901 | % o method: the pixel color interpolation method. |
| 4902 | % |
| 4903 | % o x,y: A double representing the current (x,y) position of the pixel. |
| 4904 | % |
| 4905 | % o pixel: return the interpolated pixel here. |
| 4906 | % |
| 4907 | % o exception: return any errors or warnings in this structure. |
| 4908 | % |
| 4909 | */ |
| 4910 | |
| 4911 | static inline void AlphaBlendPixelInfo(const Image *image, |
| 4912 | const Quantum *pixel,PixelInfo *pixel_info,MagickRealType *alpha) |
| 4913 | { |
| 4914 | if (image->matte == MagickFalse) |
| 4915 | { |
| 4916 | *alpha=1.0; |
| 4917 | pixel_info->red=(MagickRealType) GetPixelRed(image,pixel); |
| 4918 | pixel_info->green=(MagickRealType) GetPixelGreen(image,pixel); |
| 4919 | pixel_info->blue=(MagickRealType) GetPixelBlue(image,pixel); |
| 4920 | pixel_info->black=0.0; |
| 4921 | if (image->colorspace == CMYKColorspace) |
| 4922 | pixel_info->black=(MagickRealType) GetPixelBlack(image,pixel); |
| 4923 | pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel); |
| 4924 | return; |
| 4925 | } |
| 4926 | *alpha=QuantumScale*GetPixelAlpha(image,pixel); |
| 4927 | pixel_info->red=(*alpha*GetPixelRed(image,pixel)); |
| 4928 | pixel_info->green=(*alpha*GetPixelGreen(image,pixel)); |
| 4929 | pixel_info->blue=(*alpha*GetPixelBlue(image,pixel)); |
| 4930 | pixel_info->black=0.0; |
| 4931 | if (image->colorspace == CMYKColorspace) |
| 4932 | pixel_info->black=(*alpha*GetPixelBlack(image,pixel)); |
| 4933 | pixel_info->alpha=(MagickRealType) GetPixelAlpha(image,pixel); |
| 4934 | } |
| 4935 | |
| 4936 | static void BicubicInterpolate(const PixelInfo *pixels,const double dx, |
| 4937 | PixelInfo *pixel) |
| 4938 | { |
| 4939 | MagickRealType |
| 4940 | dx2, |
| 4941 | p, |
| 4942 | q, |
| 4943 | r, |
| 4944 | s; |
| 4945 | |
| 4946 | dx2=dx*dx; |
| 4947 | p=(pixels[3].red-pixels[2].red)-(pixels[0].red-pixels[1].red); |
| 4948 | q=(pixels[0].red-pixels[1].red)-p; |
| 4949 | r=pixels[2].red-pixels[0].red; |
| 4950 | s=pixels[1].red; |
| 4951 | pixel->red=(dx*dx2*p)+(dx2*q)+(dx*r)+s; |
| 4952 | p=(pixels[3].green-pixels[2].green)-(pixels[0].green-pixels[1].green); |
| 4953 | q=(pixels[0].green-pixels[1].green)-p; |
| 4954 | r=pixels[2].green-pixels[0].green; |
| 4955 | s=pixels[1].green; |
| 4956 | pixel->green=(dx*dx2*p)+(dx2*q)+(dx*r)+s; |
| 4957 | p=(pixels[3].blue-pixels[2].blue)-(pixels[0].blue-pixels[1].blue); |
| 4958 | q=(pixels[0].blue-pixels[1].blue)-p; |
| 4959 | r=pixels[2].blue-pixels[0].blue; |
| 4960 | s=pixels[1].blue; |
| 4961 | pixel->blue=(dx*dx2*p)+(dx2*q)+(dx*r)+s; |
| 4962 | p=(pixels[3].alpha-pixels[2].alpha)-(pixels[0].alpha-pixels[1].alpha); |
| 4963 | q=(pixels[0].alpha-pixels[1].alpha)-p; |
| 4964 | r=pixels[2].alpha-pixels[0].alpha; |
| 4965 | s=pixels[1].alpha; |
| 4966 | pixel->alpha=(dx*dx2*p)+(dx2*q)+(dx*r)+s; |
| 4967 | if (pixel->colorspace == CMYKColorspace) |
| 4968 | { |
| 4969 | p=(pixels[3].black-pixels[2].black)-(pixels[0].black-pixels[1].black); |
| 4970 | q=(pixels[0].black-pixels[1].black)-p; |
| 4971 | r=pixels[2].black-pixels[0].black; |
| 4972 | s=pixels[1].black; |
| 4973 | pixel->black=(dx*dx2*p)+(dx2*q)+(dx*r)+s; |
| 4974 | } |
| 4975 | } |
| 4976 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4977 | MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4978 | const CacheView *image_view,const PixelInterpolateMethod method, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4979 | const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception) |
| 4980 | { |
| 4981 | MagickBooleanType |
| 4982 | status; |
| 4983 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4984 | MagickRealType |
| 4985 | alpha[16], |
| 4986 | gamma; |
| 4987 | |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 4988 | PixelInfo |
| 4989 | pixels[16]; |
| 4990 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4991 | register const Quantum |
| 4992 | *p; |
| 4993 | |
| 4994 | register ssize_t |
| 4995 | i; |
| 4996 | |
| 4997 | ssize_t |
| 4998 | x_offset, |
| 4999 | y_offset; |
| 5000 | |
| 5001 | assert(image != (Image *) NULL); |
| 5002 | assert(image->signature == MagickSignature); |
| 5003 | assert(image_view != (CacheView *) NULL); |
| 5004 | status=MagickTrue; |
| 5005 | x_offset=(ssize_t) floor(x); |
| 5006 | y_offset=(ssize_t) floor(y); |
| 5007 | switch (method == UndefinedInterpolatePixel ? image->interpolate : method) |
| 5008 | { |
| 5009 | case AverageInterpolatePixel: |
| 5010 | { |
| 5011 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 5012 | exception); |
| 5013 | if (p == (const Quantum *) NULL) |
| 5014 | { |
| 5015 | status=MagickFalse; |
| 5016 | break; |
| 5017 | } |
cristy | 5ce8df8 | 2011-07-07 14:52:23 +0000 | [diff] [blame] | 5018 | AlphaBlendPixelInfo(image,p,pixels+0,alpha+0); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5019 | AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5020 | AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2); |
| 5021 | AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3); |
| 5022 | AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4); |
| 5023 | AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5); |
| 5024 | AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6); |
| 5025 | AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7); |
| 5026 | AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8); |
| 5027 | AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9); |
| 5028 | AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5029 | 10); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5030 | AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5031 | 11); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5032 | AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5033 | 12); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5034 | AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5035 | 13); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5036 | AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5037 | 14); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5038 | AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5039 | 15); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5040 | pixel->red=0.0; |
| 5041 | pixel->green=0.0; |
| 5042 | pixel->blue=0.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5043 | pixel->black=0.0; |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5044 | pixel->alpha=0.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5045 | for (i=0; i < 16L; i++) |
| 5046 | { |
| 5047 | gamma=1.0/(fabs((double) alpha[i]) <= MagickEpsilon ? 1.0 : alpha[i]); |
| 5048 | pixel->red+=gamma*0.0625*pixels[i].red; |
| 5049 | pixel->green+=gamma*0.0625*pixels[i].green; |
| 5050 | pixel->blue+=gamma*0.0625*pixels[i].blue; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5051 | if (image->colorspace == CMYKColorspace) |
| 5052 | pixel->black+=gamma*0.0625*pixels[i].black; |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5053 | pixel->alpha+=0.0625*pixels[i].alpha; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5054 | } |
| 5055 | break; |
| 5056 | } |
| 5057 | case BicubicInterpolatePixel: |
| 5058 | { |
| 5059 | PixelInfo |
| 5060 | u[4]; |
| 5061 | |
| 5062 | PointInfo |
| 5063 | delta; |
| 5064 | |
| 5065 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 5066 | exception); |
| 5067 | if (p == (const Quantum *) NULL) |
| 5068 | { |
| 5069 | status=MagickFalse; |
| 5070 | break; |
| 5071 | } |
cristy | 5ce8df8 | 2011-07-07 14:52:23 +0000 | [diff] [blame] | 5072 | AlphaBlendPixelInfo(image,p,pixels+0,alpha+0); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5073 | AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5074 | AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2); |
| 5075 | AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3); |
| 5076 | AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4); |
| 5077 | AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5); |
| 5078 | AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6); |
| 5079 | AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7); |
| 5080 | AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8); |
| 5081 | AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9); |
| 5082 | AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5083 | 10); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5084 | AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5085 | 11); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5086 | AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5087 | 12); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5088 | AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5089 | 13); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5090 | AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5091 | 14); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5092 | AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5093 | 15); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5094 | delta.x=x-x_offset; |
| 5095 | delta.y=y-y_offset; |
| 5096 | for (i=0; i < 4L; i++) |
| 5097 | BicubicInterpolate(pixels+4*i,delta.x,u+i); |
| 5098 | BicubicInterpolate(u,delta.y,pixel); |
| 5099 | break; |
| 5100 | } |
| 5101 | case BilinearInterpolatePixel: |
| 5102 | default: |
| 5103 | { |
| 5104 | PointInfo |
| 5105 | delta, |
| 5106 | epsilon; |
| 5107 | |
| 5108 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
| 5109 | if (p == (const Quantum *) NULL) |
| 5110 | { |
| 5111 | status=MagickFalse; |
| 5112 | break; |
| 5113 | } |
cristy | 5ce8df8 | 2011-07-07 14:52:23 +0000 | [diff] [blame] | 5114 | AlphaBlendPixelInfo(image,p,pixels+0,alpha+0); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5115 | AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5116 | AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2); |
| 5117 | AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5118 | delta.x=x-x_offset; |
| 5119 | delta.y=y-y_offset; |
| 5120 | epsilon.x=1.0-delta.x; |
| 5121 | epsilon.y=1.0-delta.y; |
| 5122 | gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y* |
| 5123 | (epsilon.x*alpha[2]+delta.x*alpha[3]))); |
| 5124 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 5125 | pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x* |
| 5126 | pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red)); |
| 5127 | pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x* |
| 5128 | pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x* |
| 5129 | pixels[3].green)); |
| 5130 | pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x* |
| 5131 | pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x* |
| 5132 | pixels[3].blue)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5133 | if (image->colorspace == CMYKColorspace) |
| 5134 | pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x* |
| 5135 | pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x* |
| 5136 | pixels[3].black)); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 5137 | gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x))); |
| 5138 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5139 | pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x* |
| 5140 | pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x* |
| 5141 | pixels[3].alpha)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5142 | break; |
| 5143 | } |
| 5144 | case FilterInterpolatePixel: |
| 5145 | { |
| 5146 | CacheView |
| 5147 | *filter_view; |
| 5148 | |
| 5149 | Image |
| 5150 | *excerpt_image, |
| 5151 | *filter_image; |
| 5152 | |
| 5153 | RectangleInfo |
| 5154 | geometry; |
| 5155 | |
| 5156 | geometry.width=4L; |
| 5157 | geometry.height=4L; |
| 5158 | geometry.x=x_offset-1; |
| 5159 | geometry.y=y_offset-1; |
| 5160 | excerpt_image=ExcerptImage(image,&geometry,exception); |
| 5161 | if (excerpt_image == (Image *) NULL) |
| 5162 | { |
| 5163 | status=MagickFalse; |
| 5164 | break; |
| 5165 | } |
| 5166 | filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur, |
| 5167 | exception); |
| 5168 | excerpt_image=DestroyImage(excerpt_image); |
| 5169 | if (filter_image == (Image *) NULL) |
| 5170 | break; |
| 5171 | filter_view=AcquireCacheView(filter_image); |
| 5172 | p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception); |
| 5173 | if (p != (const Quantum *) NULL) |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 5174 | GetPixelInfoPixel(image,p,pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5175 | filter_view=DestroyCacheView(filter_view); |
| 5176 | filter_image=DestroyImage(filter_image); |
| 5177 | break; |
| 5178 | } |
| 5179 | case IntegerInterpolatePixel: |
| 5180 | { |
| 5181 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception); |
| 5182 | if (p == (const Quantum *) NULL) |
| 5183 | { |
| 5184 | status=MagickFalse; |
| 5185 | break; |
| 5186 | } |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 5187 | GetPixelInfoPixel(image,p,pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5188 | break; |
| 5189 | } |
| 5190 | case MeshInterpolatePixel: |
| 5191 | { |
| 5192 | PointInfo |
| 5193 | delta, |
| 5194 | luminance; |
| 5195 | |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5196 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5197 | if (p == (const Quantum *) NULL) |
| 5198 | { |
| 5199 | status=MagickFalse; |
| 5200 | break; |
| 5201 | } |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5202 | delta.x=x-x_offset; |
| 5203 | delta.y=y-y_offset; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 5204 | luminance.x=GetPixelLuminance(image,p)-(double) |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5205 | GetPixelLuminance(image,p+3*GetPixelChannels(image)); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5206 | luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double) |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5207 | GetPixelLuminance(image,p+2*GetPixelChannels(image)); |
cristy | 5ce8df8 | 2011-07-07 14:52:23 +0000 | [diff] [blame] | 5208 | AlphaBlendPixelInfo(image,p,pixels+0,alpha+0); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5209 | AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5210 | AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2); |
| 5211 | AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5212 | if (fabs(luminance.x) < fabs(luminance.y)) |
| 5213 | { |
| 5214 | /* |
| 5215 | Diagonal 0-3 NW-SE. |
| 5216 | */ |
| 5217 | if (delta.x <= delta.y) |
| 5218 | { |
| 5219 | /* |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5220 | Bottom-left triangle (pixel: 2, diagonal: 0-3). |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5221 | */ |
| 5222 | delta.y=1.0-delta.y; |
| 5223 | gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]); |
| 5224 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 5225 | pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red, |
| 5226 | pixels[3].red,pixels[0].red); |
| 5227 | pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green, |
| 5228 | pixels[3].green,pixels[0].green); |
| 5229 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue, |
| 5230 | pixels[3].blue,pixels[0].blue); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5231 | if (image->colorspace == CMYKColorspace) |
| 5232 | pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black, |
| 5233 | pixels[3].black,pixels[0].black); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5234 | gamma=MeshInterpolate(&delta,1.0,1.0,1.0); |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5235 | pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha, |
| 5236 | pixels[3].alpha,pixels[0].alpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5237 | } |
| 5238 | else |
| 5239 | { |
| 5240 | /* |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5241 | Top-right triangle (pixel:1 , diagonal: 0-3). |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5242 | */ |
| 5243 | delta.x=1.0-delta.x; |
| 5244 | gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]); |
| 5245 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 5246 | pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red, |
| 5247 | pixels[0].red,pixels[3].red); |
| 5248 | pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green, |
| 5249 | pixels[0].green,pixels[3].green); |
| 5250 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue, |
| 5251 | pixels[0].blue,pixels[3].blue); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5252 | if (image->colorspace == CMYKColorspace) |
| 5253 | pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black, |
| 5254 | pixels[0].black,pixels[3].black); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5255 | gamma=MeshInterpolate(&delta,1.0,1.0,1.0); |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5256 | pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha, |
| 5257 | pixels[0].alpha,pixels[3].alpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5258 | } |
| 5259 | } |
| 5260 | else |
| 5261 | { |
| 5262 | /* |
| 5263 | Diagonal 1-2 NE-SW. |
| 5264 | */ |
| 5265 | if (delta.x <= (1.0-delta.y)) |
| 5266 | { |
| 5267 | /* |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5268 | Top-left triangle (pixel: 0, diagonal: 1-2). |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5269 | */ |
| 5270 | gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]); |
| 5271 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 5272 | pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red, |
| 5273 | pixels[1].red,pixels[2].red); |
| 5274 | pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green, |
| 5275 | pixels[1].green,pixels[2].green); |
| 5276 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue, |
| 5277 | pixels[1].blue,pixels[2].blue); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5278 | if (image->colorspace == CMYKColorspace) |
| 5279 | pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black, |
| 5280 | pixels[1].black,pixels[2].black); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5281 | gamma=MeshInterpolate(&delta,1.0,1.0,1.0); |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5282 | pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha, |
| 5283 | pixels[1].alpha,pixels[2].alpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5284 | } |
| 5285 | else |
| 5286 | { |
| 5287 | /* |
| 5288 | Bottom-right triangle (pixel: 3, diagonal: 1-2). |
| 5289 | */ |
| 5290 | delta.x=1.0-delta.x; |
| 5291 | delta.y=1.0-delta.y; |
| 5292 | gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]); |
| 5293 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 5294 | pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red, |
| 5295 | pixels[2].red,pixels[1].red); |
| 5296 | pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green, |
| 5297 | pixels[2].green,pixels[1].green); |
| 5298 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue, |
| 5299 | pixels[2].blue,pixels[1].blue); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5300 | if (image->colorspace == CMYKColorspace) |
| 5301 | pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black, |
| 5302 | pixels[2].black,pixels[1].black); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5303 | gamma=MeshInterpolate(&delta,1.0,1.0,1.0); |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5304 | pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha, |
| 5305 | pixels[2].alpha,pixels[1].alpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5306 | } |
| 5307 | } |
| 5308 | break; |
| 5309 | } |
| 5310 | case NearestNeighborInterpolatePixel: |
| 5311 | { |
| 5312 | p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x), |
| 5313 | NearestNeighbor(y),1,1,exception); |
| 5314 | if (p == (const Quantum *) NULL) |
| 5315 | { |
| 5316 | status=MagickFalse; |
| 5317 | break; |
| 5318 | } |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 5319 | GetPixelInfoPixel(image,p,pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5320 | break; |
| 5321 | } |
| 5322 | case SplineInterpolatePixel: |
| 5323 | { |
| 5324 | MagickRealType |
| 5325 | dx, |
| 5326 | dy; |
| 5327 | |
| 5328 | PointInfo |
| 5329 | delta; |
| 5330 | |
| 5331 | ssize_t |
| 5332 | j, |
| 5333 | n; |
| 5334 | |
| 5335 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 5336 | exception); |
| 5337 | if (p == (const Quantum *) NULL) |
| 5338 | { |
| 5339 | status=MagickFalse; |
| 5340 | break; |
| 5341 | } |
cristy | 5ce8df8 | 2011-07-07 14:52:23 +0000 | [diff] [blame] | 5342 | AlphaBlendPixelInfo(image,p,pixels+0,alpha+0); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5343 | AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5344 | AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2); |
| 5345 | AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3); |
| 5346 | AlphaBlendPixelInfo(image,p+4*GetPixelChannels(image),pixels+4,alpha+4); |
| 5347 | AlphaBlendPixelInfo(image,p+5*GetPixelChannels(image),pixels+5,alpha+5); |
| 5348 | AlphaBlendPixelInfo(image,p+6*GetPixelChannels(image),pixels+6,alpha+6); |
| 5349 | AlphaBlendPixelInfo(image,p+7*GetPixelChannels(image),pixels+7,alpha+7); |
| 5350 | AlphaBlendPixelInfo(image,p+8*GetPixelChannels(image),pixels+8,alpha+8); |
| 5351 | AlphaBlendPixelInfo(image,p+9*GetPixelChannels(image),pixels+9,alpha+9); |
| 5352 | AlphaBlendPixelInfo(image,p+10*GetPixelChannels(image),pixels+10,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5353 | 10); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5354 | AlphaBlendPixelInfo(image,p+11*GetPixelChannels(image),pixels+11,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5355 | 11); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5356 | AlphaBlendPixelInfo(image,p+12*GetPixelChannels(image),pixels+12,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5357 | 12); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5358 | AlphaBlendPixelInfo(image,p+13*GetPixelChannels(image),pixels+13,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5359 | 13); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5360 | AlphaBlendPixelInfo(image,p+14*GetPixelChannels(image),pixels+14,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5361 | 14); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5362 | AlphaBlendPixelInfo(image,p+15*GetPixelChannels(image),pixels+15,alpha+ |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5363 | 15); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5364 | pixel->red=0.0; |
| 5365 | pixel->green=0.0; |
| 5366 | pixel->blue=0.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5367 | pixel->black=0.0; |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5368 | pixel->alpha=0.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5369 | delta.x=x-x_offset; |
| 5370 | delta.y=y-y_offset; |
| 5371 | n=0; |
| 5372 | for (i=(-1); i < 3L; i++) |
| 5373 | { |
| 5374 | dy=CubicWeightingFunction((MagickRealType) i-delta.y); |
| 5375 | for (j=(-1); j < 3L; j++) |
| 5376 | { |
| 5377 | dx=CubicWeightingFunction(delta.x-(MagickRealType) j); |
| 5378 | gamma=1.0/(fabs((double) alpha[n]) <= MagickEpsilon ? 1.0 : alpha[n]); |
| 5379 | pixel->red+=gamma*dx*dy*pixels[n].red; |
| 5380 | pixel->green+=gamma*dx*dy*pixels[n].green; |
| 5381 | pixel->blue+=gamma*dx*dy*pixels[n].blue; |
| 5382 | if (image->colorspace == CMYKColorspace) |
| 5383 | pixel->black+=gamma*dx*dy*pixels[n].black; |
| 5384 | pixel->alpha+=dx*dy*pixels[n].alpha; |
| 5385 | n++; |
| 5386 | } |
| 5387 | } |
| 5388 | break; |
| 5389 | } |
| 5390 | } |
| 5391 | return(status); |
| 5392 | } |
| 5393 | |
| 5394 | /* |
| 5395 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5396 | % % |
| 5397 | % % |
| 5398 | % % |
| 5399 | + I s F u z z y E q u i v a l e n c e P i x e l % |
| 5400 | % % |
| 5401 | % % |
| 5402 | % % |
| 5403 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5404 | % |
| 5405 | % IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two |
| 5406 | % pixels is less than the specified distance in a linear three (or four)u |
| 5407 | % dimensional color space. |
| 5408 | % |
| 5409 | % The format of the IsFuzzyEquivalencePixel method is: |
| 5410 | % |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5411 | % void IsFuzzyEquivalencePixel(const Image *source,const Quantum *p, |
| 5412 | % const Image *destination,const Quantum *q) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5413 | % |
| 5414 | % A description of each parameter follows: |
| 5415 | % |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5416 | % o source: the source image. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5417 | % |
| 5418 | % o p: Pixel p. |
| 5419 | % |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5420 | % o destination: the destination image. |
| 5421 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5422 | % o q: Pixel q. |
| 5423 | % |
| 5424 | */ |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5425 | MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *source, |
| 5426 | const Quantum *p,const Image *destination,const Quantum *q) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5427 | { |
| 5428 | MagickRealType |
| 5429 | fuzz, |
| 5430 | pixel; |
| 5431 | |
| 5432 | register MagickRealType |
| 5433 | distance, |
| 5434 | scale; |
| 5435 | |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5436 | fuzz=MagickMax(source->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax( |
| 5437 | destination->fuzz,(MagickRealType) MagickSQ1_2); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5438 | scale=1.0; |
| 5439 | distance=0.0; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5440 | if (source->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5441 | { |
| 5442 | /* |
| 5443 | Transparencies are involved - set alpha distance |
| 5444 | */ |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 5445 | pixel=GetPixelAlpha(source,p)-(MagickRealType) |
| 5446 | GetPixelAlpha(destination,q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5447 | distance=pixel*pixel; |
| 5448 | if (distance > fuzz) |
| 5449 | return(MagickFalse); |
| 5450 | /* |
| 5451 | Generate a alpha scaling factor to generate a 4D cone on colorspace |
| 5452 | Note that if one color is transparent, distance has no color component. |
| 5453 | */ |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5454 | scale=QuantumScale*GetPixelAlpha(source,p); |
| 5455 | scale*=QuantumScale*GetPixelAlpha(destination,q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5456 | if (scale <= MagickEpsilon) |
| 5457 | return(MagickTrue); |
| 5458 | } |
| 5459 | /* |
| 5460 | RGB or CMY color cube |
| 5461 | */ |
| 5462 | distance*=3.0; /* rescale appropriately */ |
| 5463 | fuzz*=3.0; |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5464 | pixel=GetPixelRed(source,p)-(MagickRealType) GetPixelRed(destination,q); |
| 5465 | if ((source->colorspace == HSLColorspace) || |
| 5466 | (source->colorspace == HSBColorspace) || |
| 5467 | (source->colorspace == HWBColorspace)) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5468 | { |
| 5469 | /* |
| 5470 | Compute an arc distance for hue. It should be a vector angle of |
| 5471 | 'S'/'W' length with 'L'/'B' forming appropriate cones. |
| 5472 | */ |
| 5473 | if (fabs((double) pixel) > (QuantumRange/2)) |
| 5474 | pixel-=QuantumRange; |
| 5475 | pixel*=2; |
| 5476 | } |
| 5477 | distance+=scale*pixel*pixel; |
| 5478 | if (distance > fuzz) |
| 5479 | return(MagickFalse); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5480 | pixel=GetPixelGreen(source,p)-(MagickRealType) GetPixelGreen(destination,q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5481 | distance+=scale*pixel*pixel; |
| 5482 | if (distance > fuzz) |
| 5483 | return(MagickFalse); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5484 | pixel=GetPixelBlue(source,p)-(MagickRealType) GetPixelBlue(destination,q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5485 | distance+=scale*pixel*pixel; |
| 5486 | if (distance > fuzz) |
| 5487 | return(MagickFalse); |
| 5488 | return(MagickTrue); |
| 5489 | } |
| 5490 | |
| 5491 | /* |
| 5492 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5493 | % % |
| 5494 | % % |
| 5495 | % % |
| 5496 | + 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 % |
| 5497 | % % |
| 5498 | % % |
| 5499 | % % |
| 5500 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5501 | % |
| 5502 | % IsFuzzyEquivalencePixelInfo() returns true if the distance between two |
| 5503 | % colors is less than the specified distance in a linear three (or four) |
| 5504 | % dimensional color space. |
| 5505 | % |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5506 | % This implements the equivalent of: |
| 5507 | % fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5508 | % |
| 5509 | % Which produces a multi-dimensional cone for that colorspace along the |
| 5510 | % transparency vector. |
| 5511 | % |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5512 | % For example for an RGB: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5513 | % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3 |
| 5514 | % |
| 5515 | % See http://www.imagemagick.org/Usage/bugs/fuzz_distance/ |
| 5516 | % |
| 5517 | % Hue colorspace distances need more work. Hue is not a distance, it is an |
| 5518 | % angle! |
| 5519 | % |
| 5520 | % A check that q is in the same color space as p should be made and the |
| 5521 | % appropriate mapping made. -- Anthony Thyssen 8 December 2010 |
| 5522 | % |
| 5523 | % The format of the IsFuzzyEquivalencePixelInfo method is: |
| 5524 | % |
| 5525 | % MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p, |
| 5526 | % const PixelInfo *q) |
| 5527 | % |
| 5528 | % A description of each parameter follows: |
| 5529 | % |
| 5530 | % o p: Pixel p. |
| 5531 | % |
| 5532 | % o q: Pixel q. |
| 5533 | % |
| 5534 | */ |
| 5535 | MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p, |
| 5536 | const PixelInfo *q) |
| 5537 | { |
| 5538 | MagickRealType |
| 5539 | fuzz, |
| 5540 | pixel; |
| 5541 | |
| 5542 | register MagickRealType |
| 5543 | scale, |
| 5544 | distance; |
| 5545 | |
| 5546 | if ((p->fuzz == 0.0) && (q->fuzz == 0.0)) |
| 5547 | return(IsPixelInfoEquivalent(p,q)); |
| 5548 | if (p->fuzz == 0.0) |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5549 | fuzz=MagickMax(q->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz, |
| 5550 | (MagickRealType) MagickSQ1_2); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5551 | else if (q->fuzz == 0.0) |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5552 | fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(p->fuzz, |
| 5553 | (MagickRealType) MagickSQ1_2); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5554 | else |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5555 | fuzz=MagickMax(p->fuzz,(MagickRealType) MagickSQ1_2)*MagickMax(q->fuzz, |
| 5556 | (MagickRealType) MagickSQ1_2); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5557 | scale=1.0; |
| 5558 | distance=0.0; |
| 5559 | if ((p->matte != MagickFalse) || (q->matte != MagickFalse)) |
| 5560 | { |
| 5561 | /* |
| 5562 | Transparencies are involved - set alpha distance. |
| 5563 | */ |
| 5564 | pixel=(p->matte != MagickFalse ? p->alpha : OpaqueAlpha)- |
| 5565 | (q->matte != MagickFalse ? q->alpha : OpaqueAlpha); |
| 5566 | distance=pixel*pixel; |
| 5567 | if (distance > fuzz) |
| 5568 | return(MagickFalse); |
| 5569 | /* |
| 5570 | Generate a alpha scaling factor to generate a 4D cone on colorspace. |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5571 | If one color is transparent, distance has no color component. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5572 | */ |
| 5573 | if (p->matte != MagickFalse) |
| 5574 | scale=(QuantumScale*p->alpha); |
| 5575 | if (q->matte != MagickFalse) |
| 5576 | scale*=(QuantumScale*q->alpha); |
| 5577 | if (scale <= MagickEpsilon ) |
| 5578 | return(MagickTrue); |
| 5579 | } |
| 5580 | /* |
| 5581 | CMYK create a CMY cube with a multi-dimensional cone toward black. |
| 5582 | */ |
| 5583 | if (p->colorspace == CMYKColorspace) |
| 5584 | { |
| 5585 | pixel=p->black-q->black; |
| 5586 | distance+=pixel*pixel*scale; |
| 5587 | if (distance > fuzz) |
| 5588 | return(MagickFalse); |
| 5589 | scale*=(MagickRealType) (QuantumScale*(QuantumRange-p->black)); |
| 5590 | scale*=(MagickRealType) (QuantumScale*(QuantumRange-q->black)); |
| 5591 | } |
| 5592 | /* |
| 5593 | RGB or CMY color cube. |
| 5594 | */ |
| 5595 | distance*=3.0; /* rescale appropriately */ |
| 5596 | fuzz*=3.0; |
| 5597 | pixel=p->red-q->red; |
| 5598 | if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) || |
| 5599 | (p->colorspace == HWBColorspace)) |
| 5600 | { |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5601 | /* |
| 5602 | This calculates a arc distance for hue-- it should be a vector angle |
| 5603 | of 'S'/'W' length with 'L'/'B' forming appropriate cones. In other |
| 5604 | words this is a hack - Anthony. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5605 | */ |
| 5606 | if (fabs((double) pixel) > (QuantumRange/2)) |
| 5607 | pixel-=QuantumRange; |
| 5608 | pixel*=2; |
| 5609 | } |
| 5610 | distance+=pixel*pixel*scale; |
| 5611 | if (distance > fuzz) |
| 5612 | return(MagickFalse); |
| 5613 | pixel=p->green-q->green; |
| 5614 | distance+=pixel*pixel*scale; |
| 5615 | if (distance > fuzz) |
| 5616 | return(MagickFalse); |
| 5617 | pixel=p->blue-q->blue; |
| 5618 | distance+=pixel*pixel*scale; |
| 5619 | if (distance > fuzz) |
| 5620 | return(MagickFalse); |
| 5621 | return(MagickTrue); |
| 5622 | } |
| 5623 | |
| 5624 | /* |
| 5625 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5626 | % % |
| 5627 | % % |
| 5628 | % % |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 5629 | % S e t P i x e l C h a n n e l M a p M a s k % |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5630 | % % |
| 5631 | % % |
| 5632 | % % |
| 5633 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5634 | % |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 5635 | % SetPixelChannelMapMask() sets the pixel channel map from the specified |
| 5636 | % channel mask. |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5637 | % |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 5638 | % The format of the SetPixelChannelMapMask method is: |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5639 | % |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 5640 | % void SetPixelChannelMapMask(Image *image,const ChannelType channel_mask) |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5641 | % |
| 5642 | % A description of each parameter follows: |
| 5643 | % |
| 5644 | % o image: the image. |
| 5645 | % |
cristy | 4426146 | 2011-08-09 13:34:47 +0000 | [diff] [blame] | 5646 | % o mask: the channel mask. |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5647 | % |
| 5648 | */ |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 5649 | MagickExport void SetPixelChannelMapMask(Image *image, |
cristy | 07a6785 | 2011-08-26 13:25:03 +0000 | [diff] [blame] | 5650 | const ChannelType channel_mask) |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5651 | { |
cristy | 6a917d6 | 2011-08-24 17:31:30 +0000 | [diff] [blame] | 5652 | #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01) |
cristy | dafd287 | 2011-07-24 22:06:13 +0000 | [diff] [blame] | 5653 | |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5654 | register ssize_t |
| 5655 | i; |
| 5656 | |
cristy | 3c30981 | 2011-11-08 02:40:43 +0000 | [diff] [blame] | 5657 | image->channel_mask=channel_mask; |
cristy | dafd287 | 2011-07-24 22:06:13 +0000 | [diff] [blame] | 5658 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 5659 | { |
| 5660 | PixelChannel |
| 5661 | channel; |
| 5662 | |
| 5663 | channel=GetPixelChannelMapChannel(image,i); |
| 5664 | SetPixelChannelMapTraits(image,channel, |
| 5665 | GetChannelBit(channel_mask,channel) == 0 ? CopyPixelTrait : |
cristy | 0bbd87c | 2011-12-13 19:34:45 +0000 | [diff] [blame] | 5666 | image->matte == MagickFalse || (channel == AlphaPixelChannel) ? |
| 5667 | UpdatePixelTrait : (PixelTrait) (UpdatePixelTrait | BlendPixelTrait)); |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 5668 | } |
cristy | 1685e72 | 2011-09-06 00:04:19 +0000 | [diff] [blame] | 5669 | if (image->storage_class == PseudoClass) |
| 5670 | SetPixelChannelMapTraits(image,IndexPixelChannel,CopyPixelTrait); |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame^] | 5671 | if (image->masky != MagickFalse) |
| 5672 | SetPixelChannelMapTraits(image,MaskPixelChannel,CopyPixelTrait); |
cristy | 6dcb9b8 | 2011-10-23 23:21:25 +0000 | [diff] [blame] | 5673 | if (image->debug != MagickFalse) |
| 5674 | LogPixelChannels(image); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5675 | } |
| 5676 | |
| 5677 | /* |
| 5678 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5679 | % % |
| 5680 | % % |
| 5681 | % % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 5682 | % 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] | 5683 | % % |
| 5684 | % % |
| 5685 | % % |
| 5686 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5687 | % |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5688 | % SetPixelChannelMask() sets the pixel channel mask from the specified channel |
| 5689 | % mask. |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5690 | % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 5691 | % The format of the SetPixelChannelMask method is: |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5692 | % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 5693 | % ChannelType SetPixelChannelMask(Image *image, |
| 5694 | % const ChannelType channel_mask) |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5695 | % |
| 5696 | % A description of each parameter follows: |
| 5697 | % |
| 5698 | % o image: the image. |
| 5699 | % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 5700 | % o channel_mask: the channel mask. |
| 5701 | % |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5702 | */ |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 5703 | MagickExport ChannelType SetPixelChannelMask(Image *image, |
| 5704 | const ChannelType channel_mask) |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5705 | { |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 5706 | ChannelType |
| 5707 | mask; |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 5708 | |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 5709 | mask=image->channel_mask; |
| 5710 | image->channel_mask=channel_mask; |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 5711 | SetPixelChannelMapMask(image,channel_mask); |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 5712 | return(mask); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5713 | } |