cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % PPPP IIIII X X EEEEE L % |
| 7 | % P P I X X E L % |
| 8 | % PPPP I X EEE L % |
| 9 | % P I X X E L % |
| 10 | % P IIIII X X EEEEE LLLLL % |
| 11 | % % |
| 12 | % MagickCore Methods to Import/Export Pixels % |
| 13 | % % |
| 14 | % Software Design % |
| 15 | % John Cristy % |
| 16 | % October 1998 % |
| 17 | % % |
| 18 | % % |
cristy | 45ef08f | 2012-12-07 13:13:34 +0000 | [diff] [blame] | 19 | % Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 20 | % dedicated to making software imaging solutions freely available. % |
| 21 | % % |
| 22 | % You may not use this file except in compliance with the License. You may % |
| 23 | % obtain a copy of the License at % |
| 24 | % % |
| 25 | % http://www.imagemagick.org/script/license.php % |
| 26 | % % |
| 27 | % Unless required by applicable law or agreed to in writing, software % |
| 28 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 29 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 30 | % See the License for the specific language governing permissions and % |
| 31 | % limitations under the License. % |
| 32 | % % |
| 33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 34 | % |
| 35 | % |
| 36 | */ |
| 37 | |
| 38 | /* |
| 39 | Include declarations. |
| 40 | */ |
| 41 | #include "MagickCore/studio.h" |
| 42 | #include "MagickCore/property.h" |
| 43 | #include "MagickCore/blob.h" |
| 44 | #include "MagickCore/blob-private.h" |
cristy | 322d07d | 2012-03-18 21:17:23 +0000 | [diff] [blame] | 45 | #include "MagickCore/cache-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 46 | #include "MagickCore/color-private.h" |
| 47 | #include "MagickCore/draw.h" |
| 48 | #include "MagickCore/exception.h" |
| 49 | #include "MagickCore/exception-private.h" |
| 50 | #include "MagickCore/cache.h" |
| 51 | #include "MagickCore/constitute.h" |
| 52 | #include "MagickCore/delegate.h" |
| 53 | #include "MagickCore/geometry.h" |
| 54 | #include "MagickCore/image-private.h" |
| 55 | #include "MagickCore/list.h" |
| 56 | #include "MagickCore/magick.h" |
| 57 | #include "MagickCore/memory_.h" |
| 58 | #include "MagickCore/monitor.h" |
| 59 | #include "MagickCore/option.h" |
| 60 | #include "MagickCore/pixel.h" |
| 61 | #include "MagickCore/pixel-accessor.h" |
cristy | 380a11c | 2012-06-02 15:15:22 +0000 | [diff] [blame] | 62 | #include "MagickCore/pixel-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 63 | #include "MagickCore/quantum.h" |
| 64 | #include "MagickCore/quantum-private.h" |
| 65 | #include "MagickCore/resource_.h" |
| 66 | #include "MagickCore/semaphore.h" |
| 67 | #include "MagickCore/statistic.h" |
| 68 | #include "MagickCore/stream.h" |
| 69 | #include "MagickCore/string_.h" |
| 70 | #include "MagickCore/transform.h" |
| 71 | #include "MagickCore/utility.h" |
| 72 | |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 73 | #define LogPixelChannels(image) \ |
| 74 | { \ |
| 75 | register ssize_t \ |
| 76 | i; \ |
| 77 | \ |
| 78 | (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%.20g]", \ |
| 79 | image->filename,(double) image->number_channels); \ |
| 80 | for (i=0; i < (ssize_t) image->number_channels; i++) \ |
| 81 | { \ |
| 82 | char \ |
| 83 | traits[MaxTextExtent]; \ |
| 84 | \ |
| 85 | const char \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 86 | *name; \ |
| 87 | \ |
| 88 | PixelChannel \ |
| 89 | channel; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 90 | \ |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 91 | switch (GetPixelChannelChannel(image,i)) \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 92 | { \ |
| 93 | case RedPixelChannel: \ |
| 94 | { \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 95 | name="red"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 96 | if (image->colorspace == CMYKColorspace) \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 97 | name="cyan"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 98 | if (image->colorspace == GRAYColorspace) \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 99 | name="gray"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 100 | break; \ |
| 101 | } \ |
| 102 | case GreenPixelChannel: \ |
| 103 | { \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 104 | name="green"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 105 | if (image->colorspace == CMYKColorspace) \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 106 | name="magenta"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 107 | break; \ |
| 108 | } \ |
| 109 | case BluePixelChannel: \ |
| 110 | { \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 111 | name="blue"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 112 | if (image->colorspace == CMYKColorspace) \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 113 | name="yellow"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 114 | break; \ |
| 115 | } \ |
| 116 | case BlackPixelChannel: \ |
| 117 | { \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 118 | name="black"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 119 | if (image->storage_class == PseudoClass) \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 120 | name="index"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 121 | break; \ |
| 122 | } \ |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 123 | case IndexPixelChannel: \ |
| 124 | { \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 125 | name="index"; \ |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 126 | break; \ |
| 127 | } \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 128 | case AlphaPixelChannel: \ |
| 129 | { \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 130 | name="alpha"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 131 | break; \ |
| 132 | } \ |
| 133 | case MaskPixelChannel: \ |
| 134 | { \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 135 | name="mask"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 136 | break; \ |
| 137 | } \ |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 138 | case MetaPixelChannel: \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 139 | { \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 140 | name="meta"; \ |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 141 | break; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 142 | } \ |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 143 | default: \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 144 | name="undefined"; \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 145 | } \ |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 146 | channel=GetPixelChannelChannel(image,i); \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 147 | *traits='\0'; \ |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 148 | if ((GetPixelChannelTraits(image,channel) & UpdatePixelTrait) != 0) \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 149 | (void) ConcatenateMagickString(traits,"update,",MaxTextExtent); \ |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 150 | if ((GetPixelChannelTraits(image,channel) & BlendPixelTrait) != 0) \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 151 | (void) ConcatenateMagickString(traits,"blend,",MaxTextExtent); \ |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 152 | if ((GetPixelChannelTraits(image,channel) & CopyPixelTrait) != 0) \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 153 | (void) ConcatenateMagickString(traits,"copy,",MaxTextExtent); \ |
| 154 | if (*traits == '\0') \ |
| 155 | (void) ConcatenateMagickString(traits,"undefined,",MaxTextExtent); \ |
| 156 | traits[strlen(traits)-1]='\0'; \ |
| 157 | (void) LogMagickEvent(PixelEvent,GetMagickModule()," %.20g: %s (%s)", \ |
cristy | 4679572 | 2011-12-10 23:56:57 +0000 | [diff] [blame] | 158 | (double) i,name,traits); \ |
cristy | 146a62b | 2011-10-23 23:40:46 +0000 | [diff] [blame] | 159 | } \ |
| 160 | } |
| 161 | |
| 162 | /* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 163 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 164 | % % |
| 165 | % % |
| 166 | % % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 167 | + 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] | 168 | % % |
| 169 | % % |
| 170 | % % |
| 171 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 172 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 173 | % AcquirePixelChannelMap() acquires a pixel component map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 174 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 175 | % The format of the AcquirePixelChannelMap() method is: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 176 | % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 177 | % PixelChannelMap *AcquirePixelChannelMap(void) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 178 | % |
| 179 | */ |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 180 | MagickExport PixelChannelMap *AcquirePixelChannelMap(void) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 181 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 182 | PixelChannelMap |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 183 | *channel_map; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 184 | |
| 185 | register ssize_t |
| 186 | i; |
| 187 | |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 188 | channel_map=(PixelChannelMap *) AcquireQuantumMemory(MaxPixelChannels, |
| 189 | sizeof(*channel_map)); |
| 190 | if (channel_map == (PixelChannelMap *) NULL) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 191 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 192 | (void) ResetMagickMemory(channel_map,0,MaxPixelChannels*sizeof(*channel_map)); |
| 193 | for (i=0; i < MaxPixelChannels; i++) |
| 194 | channel_map[i].channel=(PixelChannel) i; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 195 | return(channel_map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | /* |
| 199 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 200 | % % |
| 201 | % % |
| 202 | % % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 203 | + 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] | 204 | % % |
| 205 | % % |
| 206 | % % |
| 207 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 208 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 209 | % ClonePixelChannelMap() clones a pixel component map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 210 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 211 | % The format of the ClonePixelChannelMap() method is: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 212 | % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 213 | % PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 214 | % |
| 215 | % A description of each parameter follows: |
| 216 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 217 | % o channel_map: the pixel component map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 218 | % |
| 219 | */ |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 220 | MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 221 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 222 | PixelChannelMap |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 223 | *clone_map; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 224 | |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 225 | assert(channel_map != (PixelChannelMap *) NULL); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 226 | clone_map=AcquirePixelChannelMap(); |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 227 | if (clone_map == (PixelChannelMap *) NULL) |
| 228 | return((PixelChannelMap *) NULL); |
| 229 | (void) CopyMagickMemory(clone_map,channel_map,MaxPixelChannels* |
| 230 | sizeof(*channel_map)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 231 | return(clone_map); |
| 232 | } |
| 233 | |
| 234 | /* |
| 235 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 236 | % % |
| 237 | % % |
| 238 | % % |
| 239 | + C l o n e P i x e l I n f o % |
| 240 | % % |
| 241 | % % |
| 242 | % % |
| 243 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 244 | % |
| 245 | % ClonePixelInfo() makes a duplicate of the given pixel info structure, or if |
| 246 | % pixel info is NULL, a new one. |
| 247 | % |
| 248 | % The format of the ClonePixelInfo method is: |
| 249 | % |
| 250 | % PixelInfo *ClonePixelInfo(const PixelInfo *pixel_info) |
| 251 | % |
| 252 | % A description of each parameter follows: |
| 253 | % |
| 254 | % o pixel_info: the pixel info. |
| 255 | % |
| 256 | */ |
| 257 | MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel) |
| 258 | { |
| 259 | PixelInfo |
| 260 | *pixel_info; |
| 261 | |
cristy | a64b85d | 2011-09-14 01:02:31 +0000 | [diff] [blame] | 262 | pixel_info=(PixelInfo *) AcquireQuantumMemory(1,sizeof(*pixel_info)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 263 | if (pixel_info == (PixelInfo *) NULL) |
| 264 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 265 | *pixel_info=(*pixel); |
| 266 | return(pixel_info); |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 271 | % % |
| 272 | % % |
| 273 | % % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 274 | + D e s t r o y P i x e l C h a n n e l M a p % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 275 | % % |
| 276 | % % |
| 277 | % % |
| 278 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 279 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 280 | % DestroyPixelChannelMap() deallocates memory associated with the pixel |
| 281 | % channel map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 282 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 283 | % The format of the DestroyPixelChannelMap() method is: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 284 | % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 285 | % PixelChannelMap *DestroyPixelChannelMap(PixelChannelMap *channel_map) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 286 | % |
| 287 | % A description of each parameter follows: |
| 288 | % |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 289 | % o channel_map: the pixel component map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 290 | % |
| 291 | */ |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 292 | MagickExport PixelChannelMap *DestroyPixelChannelMap( |
| 293 | PixelChannelMap *channel_map) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 294 | { |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 295 | assert(channel_map != (PixelChannelMap *) NULL); |
| 296 | channel_map=(PixelChannelMap *) RelinquishMagickMemory(channel_map); |
| 297 | return((PixelChannelMap *) RelinquishMagickMemory(channel_map)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /* |
| 301 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 302 | % % |
| 303 | % % |
| 304 | % % |
| 305 | % E x p o r t I m a g e P i x e l s % |
| 306 | % % |
| 307 | % % |
| 308 | % % |
| 309 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 310 | % |
| 311 | % ExportImagePixels() extracts pixel data from an image and returns it to you. |
| 312 | % The method returns MagickTrue on success otherwise MagickFalse if an error is |
cristy | b5a45a3 | 2012-01-10 13:31:13 +0000 | [diff] [blame] | 313 | % encountered. The data is returned as char, short int, Quantum, unsigned int, |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 314 | % unsigned long long, float, or double in the order specified by map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 315 | % |
| 316 | % Suppose you want to extract the first scanline of a 640x480 image as |
| 317 | % character data in red-green-blue order: |
| 318 | % |
| 319 | % ExportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels,exception); |
| 320 | % |
| 321 | % The format of the ExportImagePixels method is: |
| 322 | % |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 323 | % MagickBooleanType ExportImagePixels(const Image *image,const ssize_t x, |
| 324 | % const ssize_t y,const size_t width,const size_t height, |
| 325 | % const char *map,const StorageType type,void *pixels, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 326 | % ExceptionInfo *exception) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 327 | % |
| 328 | % A description of each parameter follows: |
| 329 | % |
| 330 | % o image: the image. |
| 331 | % |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 332 | % o x,y,width,height: These values define the perimeter |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 333 | % of a region of pixels you want to extract. |
| 334 | % |
| 335 | % o map: This string reflects the expected ordering of the pixel array. |
| 336 | % It can be any combination or order of R = red, G = green, B = blue, |
| 337 | % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan, |
| 338 | % Y = yellow, M = magenta, K = black, I = intensity (for grayscale), |
| 339 | % P = pad. |
| 340 | % |
| 341 | % o type: Define the data type of the pixels. Float and double types are |
| 342 | % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 343 | % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *), |
cristy | ff6834e | 2012-01-10 03:00:25 +0000 | [diff] [blame] | 344 | % LongPixel (unsigned int *), LongLongPixel (unsigned long long *), |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 345 | % QuantumPixel (Quantum *), or ShortPixel (unsigned short *). |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 346 | % |
| 347 | % o pixels: This array of values contain the pixel components as defined by |
| 348 | % map and type. You must preallocate this array where the expected |
| 349 | % length varies depending on the values of width, height, map, and type. |
| 350 | % |
| 351 | % o exception: return any errors or warnings in this structure. |
| 352 | % |
| 353 | */ |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 354 | |
cristy | 2dc655d | 2012-07-05 13:16:28 +0000 | [diff] [blame] | 355 | static void ExportCharPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 356 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 357 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 358 | { |
| 359 | register const Quantum |
| 360 | *restrict p; |
| 361 | |
| 362 | register ssize_t |
| 363 | x; |
| 364 | |
| 365 | register unsigned char |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 366 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 367 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 368 | size_t |
| 369 | length; |
| 370 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 371 | ssize_t |
| 372 | y; |
| 373 | |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 374 | q=(unsigned char *) pixels; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 375 | if (LocaleCompare(map,"BGR") == 0) |
| 376 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 377 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 378 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 379 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 380 | if (p == (const Quantum *) NULL) |
| 381 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 382 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 383 | { |
| 384 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 385 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 386 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 387 | p+=GetPixelChannels(image); |
| 388 | } |
| 389 | } |
| 390 | return; |
| 391 | } |
| 392 | if (LocaleCompare(map,"BGRA") == 0) |
| 393 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 394 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 395 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 396 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 397 | if (p == (const Quantum *) NULL) |
| 398 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 399 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 400 | { |
| 401 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 402 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 403 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 404 | *q++=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
| 405 | p+=GetPixelChannels(image); |
| 406 | } |
| 407 | } |
| 408 | return; |
| 409 | } |
| 410 | if (LocaleCompare(map,"BGRP") == 0) |
| 411 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 412 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 413 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 414 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 415 | if (p == (const Quantum *) NULL) |
| 416 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 417 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 418 | { |
| 419 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 420 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 421 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 422 | *q++=ScaleQuantumToChar((Quantum) 0); |
| 423 | p+=GetPixelChannels(image); |
| 424 | } |
| 425 | } |
| 426 | return; |
| 427 | } |
| 428 | if (LocaleCompare(map,"I") == 0) |
| 429 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 430 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 431 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 432 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 433 | if (p == (const Quantum *) NULL) |
| 434 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 435 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 436 | { |
| 437 | *q++=ScaleQuantumToChar(GetPixelIntensity(image,p)); |
| 438 | p+=GetPixelChannels(image); |
| 439 | } |
| 440 | } |
| 441 | return; |
| 442 | } |
| 443 | if (LocaleCompare(map,"RGB") == 0) |
| 444 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 445 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 446 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 447 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 448 | if (p == (const Quantum *) NULL) |
| 449 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 450 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 451 | { |
| 452 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 453 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 454 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 455 | p+=GetPixelChannels(image); |
| 456 | } |
| 457 | } |
| 458 | return; |
| 459 | } |
| 460 | if (LocaleCompare(map,"RGBA") == 0) |
| 461 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 462 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 463 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 464 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 465 | if (p == (const Quantum *) NULL) |
| 466 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 467 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 468 | { |
| 469 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 470 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 471 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 472 | *q++=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
| 473 | p+=GetPixelChannels(image); |
| 474 | } |
| 475 | } |
| 476 | return; |
| 477 | } |
| 478 | if (LocaleCompare(map,"RGBP") == 0) |
| 479 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 480 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 481 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 482 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 483 | if (p == (const Quantum *) NULL) |
| 484 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 485 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 486 | { |
| 487 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 488 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 489 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 490 | *q++=ScaleQuantumToChar((Quantum) 0); |
| 491 | p+=GetPixelChannels(image); |
| 492 | } |
| 493 | } |
| 494 | return; |
| 495 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 496 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 497 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 498 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 499 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 500 | if (p == (const Quantum *) NULL) |
| 501 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 502 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 503 | { |
| 504 | register ssize_t |
| 505 | i; |
| 506 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 507 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 508 | { |
| 509 | *q=0; |
| 510 | switch (quantum_map[i]) |
| 511 | { |
| 512 | case RedQuantum: |
| 513 | case CyanQuantum: |
| 514 | { |
| 515 | *q=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 516 | break; |
| 517 | } |
| 518 | case GreenQuantum: |
| 519 | case MagentaQuantum: |
| 520 | { |
| 521 | *q=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 522 | break; |
| 523 | } |
| 524 | case BlueQuantum: |
| 525 | case YellowQuantum: |
| 526 | { |
| 527 | *q=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 528 | break; |
| 529 | } |
| 530 | case AlphaQuantum: |
| 531 | { |
| 532 | *q=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
| 533 | break; |
| 534 | } |
| 535 | case OpacityQuantum: |
| 536 | { |
| 537 | *q=ScaleQuantumToChar(GetPixelAlpha(image,p)); |
| 538 | break; |
| 539 | } |
| 540 | case BlackQuantum: |
| 541 | { |
| 542 | if (image->colorspace == CMYKColorspace) |
| 543 | *q=ScaleQuantumToChar(GetPixelBlack(image,p)); |
| 544 | break; |
| 545 | } |
| 546 | case IndexQuantum: |
| 547 | { |
| 548 | *q=ScaleQuantumToChar(GetPixelIntensity(image,p)); |
| 549 | break; |
| 550 | } |
| 551 | default: |
| 552 | break; |
| 553 | } |
| 554 | q++; |
| 555 | } |
| 556 | p+=GetPixelChannels(image); |
| 557 | } |
| 558 | } |
| 559 | } |
| 560 | |
cristy | 2dc655d | 2012-07-05 13:16:28 +0000 | [diff] [blame] | 561 | static void ExportDoublePixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 562 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 563 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 564 | { |
| 565 | register const Quantum |
| 566 | *restrict p; |
| 567 | |
| 568 | register double |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 569 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 570 | |
| 571 | register ssize_t |
| 572 | x; |
| 573 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 574 | size_t |
| 575 | length; |
| 576 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 577 | ssize_t |
| 578 | y; |
| 579 | |
| 580 | q=(double *) pixels; |
| 581 | if (LocaleCompare(map,"BGR") == 0) |
| 582 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 583 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 584 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 585 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 586 | if (p == (const Quantum *) NULL) |
| 587 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 588 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 589 | { |
| 590 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 591 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 592 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 593 | p+=GetPixelChannels(image); |
| 594 | } |
| 595 | } |
| 596 | return; |
| 597 | } |
| 598 | if (LocaleCompare(map,"BGRA") == 0) |
| 599 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 600 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 601 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 602 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 603 | if (p == (const Quantum *) NULL) |
| 604 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 605 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 606 | { |
| 607 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 608 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 609 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 610 | *q++=(double) (QuantumScale*GetPixelAlpha(image,p)); |
| 611 | p+=GetPixelChannels(image); |
| 612 | } |
| 613 | } |
| 614 | return; |
| 615 | } |
| 616 | if (LocaleCompare(map,"BGRP") == 0) |
| 617 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 618 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 619 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 620 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 621 | if (p == (const Quantum *) NULL) |
| 622 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 623 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 624 | { |
| 625 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 626 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 627 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 628 | *q++=0.0; |
| 629 | p+=GetPixelChannels(image); |
| 630 | } |
| 631 | } |
| 632 | return; |
| 633 | } |
| 634 | if (LocaleCompare(map,"I") == 0) |
| 635 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 636 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 637 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 638 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 639 | if (p == (const Quantum *) NULL) |
| 640 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 641 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 642 | { |
| 643 | *q++=(double) (QuantumScale*GetPixelIntensity(image,p)); |
| 644 | p+=GetPixelChannels(image); |
| 645 | } |
| 646 | } |
| 647 | return; |
| 648 | } |
| 649 | if (LocaleCompare(map,"RGB") == 0) |
| 650 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 651 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 652 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 653 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 654 | if (p == (const Quantum *) NULL) |
| 655 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 656 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 657 | { |
| 658 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 659 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 660 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 661 | p+=GetPixelChannels(image); |
| 662 | } |
| 663 | } |
| 664 | return; |
| 665 | } |
| 666 | if (LocaleCompare(map,"RGBA") == 0) |
| 667 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 668 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 669 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 670 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 671 | if (p == (const Quantum *) NULL) |
| 672 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 673 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 674 | { |
| 675 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 676 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 677 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 678 | *q++=(double) (QuantumScale*GetPixelAlpha(image,p)); |
| 679 | p+=GetPixelChannels(image); |
| 680 | } |
| 681 | } |
| 682 | return; |
| 683 | } |
| 684 | if (LocaleCompare(map,"RGBP") == 0) |
| 685 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 686 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 687 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 688 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 689 | if (p == (const Quantum *) NULL) |
| 690 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 691 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 692 | { |
| 693 | *q++=(double) (QuantumScale*GetPixelRed(image,p)); |
| 694 | *q++=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 695 | *q++=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 696 | *q++=0.0; |
| 697 | p+=GetPixelChannels(image); |
| 698 | } |
| 699 | } |
| 700 | return; |
| 701 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 702 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 703 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 704 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 705 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 706 | if (p == (const Quantum *) NULL) |
| 707 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 708 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 709 | { |
| 710 | register ssize_t |
| 711 | i; |
| 712 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 713 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 714 | { |
| 715 | *q=0; |
| 716 | switch (quantum_map[i]) |
| 717 | { |
| 718 | case RedQuantum: |
| 719 | case CyanQuantum: |
| 720 | { |
| 721 | *q=(double) (QuantumScale*GetPixelRed(image,p)); |
| 722 | break; |
| 723 | } |
| 724 | case GreenQuantum: |
| 725 | case MagentaQuantum: |
| 726 | { |
| 727 | *q=(double) (QuantumScale*GetPixelGreen(image,p)); |
| 728 | break; |
| 729 | } |
| 730 | case BlueQuantum: |
| 731 | case YellowQuantum: |
| 732 | { |
| 733 | *q=(double) (QuantumScale*GetPixelBlue(image,p)); |
| 734 | break; |
| 735 | } |
| 736 | case AlphaQuantum: |
| 737 | { |
| 738 | *q=(double) (QuantumScale*GetPixelAlpha(image,p)); |
| 739 | break; |
| 740 | } |
| 741 | case OpacityQuantum: |
| 742 | { |
| 743 | *q=(double) (QuantumScale*GetPixelAlpha(image,p)); |
| 744 | break; |
| 745 | } |
| 746 | case BlackQuantum: |
| 747 | { |
| 748 | if (image->colorspace == CMYKColorspace) |
| 749 | *q=(double) (QuantumScale* |
| 750 | GetPixelBlack(image,p)); |
| 751 | break; |
| 752 | } |
| 753 | case IndexQuantum: |
| 754 | { |
| 755 | *q=(double) (QuantumScale*GetPixelIntensity(image,p)); |
| 756 | break; |
| 757 | } |
| 758 | default: |
| 759 | *q=0; |
| 760 | } |
| 761 | q++; |
| 762 | } |
| 763 | p+=GetPixelChannels(image); |
| 764 | } |
| 765 | } |
| 766 | } |
| 767 | |
cristy | 2dc655d | 2012-07-05 13:16:28 +0000 | [diff] [blame] | 768 | static void ExportFloatPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 769 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 770 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 771 | { |
| 772 | register const Quantum |
| 773 | *restrict p; |
| 774 | |
| 775 | register float |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 776 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 777 | |
| 778 | register ssize_t |
| 779 | x; |
| 780 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 781 | size_t |
| 782 | length; |
| 783 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 784 | ssize_t |
| 785 | y; |
| 786 | |
| 787 | q=(float *) pixels; |
| 788 | if (LocaleCompare(map,"BGR") == 0) |
| 789 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 790 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 791 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 792 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 793 | if (p == (const Quantum *) NULL) |
| 794 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 795 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 796 | { |
| 797 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 798 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 799 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 800 | p+=GetPixelChannels(image); |
| 801 | } |
| 802 | } |
| 803 | return; |
| 804 | } |
| 805 | if (LocaleCompare(map,"BGRA") == 0) |
| 806 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 807 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 808 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 809 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 810 | if (p == (const Quantum *) NULL) |
| 811 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 812 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 813 | { |
| 814 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 815 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 816 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 817 | *q++=(float) (QuantumScale*GetPixelAlpha(image,p)); |
| 818 | p+=GetPixelChannels(image); |
| 819 | } |
| 820 | } |
| 821 | return; |
| 822 | } |
| 823 | if (LocaleCompare(map,"BGRP") == 0) |
| 824 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 825 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 826 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 827 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 828 | if (p == (const Quantum *) NULL) |
| 829 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 830 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 831 | { |
| 832 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 833 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 834 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 835 | *q++=0.0; |
| 836 | p+=GetPixelChannels(image); |
| 837 | } |
| 838 | } |
| 839 | return; |
| 840 | } |
| 841 | if (LocaleCompare(map,"I") == 0) |
| 842 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 843 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 844 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 845 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 846 | if (p == (const Quantum *) NULL) |
| 847 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 848 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 849 | { |
| 850 | *q++=(float) (QuantumScale*GetPixelIntensity(image,p)); |
| 851 | p+=GetPixelChannels(image); |
| 852 | } |
| 853 | } |
| 854 | return; |
| 855 | } |
| 856 | if (LocaleCompare(map,"RGB") == 0) |
| 857 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 858 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 859 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 860 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 861 | if (p == (const Quantum *) NULL) |
| 862 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 863 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 864 | { |
| 865 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 866 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 867 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 868 | p+=GetPixelChannels(image); |
| 869 | } |
| 870 | } |
| 871 | return; |
| 872 | } |
| 873 | if (LocaleCompare(map,"RGBA") == 0) |
| 874 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 875 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 876 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 877 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 878 | if (p == (const Quantum *) NULL) |
| 879 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 880 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 881 | { |
| 882 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 883 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 884 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 885 | *q++=(float) (QuantumScale*GetPixelAlpha(image,p)); |
| 886 | p+=GetPixelChannels(image); |
| 887 | } |
| 888 | } |
| 889 | return; |
| 890 | } |
| 891 | if (LocaleCompare(map,"RGBP") == 0) |
| 892 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 893 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 894 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 895 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 896 | if (p == (const Quantum *) NULL) |
| 897 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 898 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 899 | { |
| 900 | *q++=(float) (QuantumScale*GetPixelRed(image,p)); |
| 901 | *q++=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 902 | *q++=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 903 | *q++=0.0; |
| 904 | p+=GetPixelChannels(image); |
| 905 | } |
| 906 | } |
| 907 | return; |
| 908 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 909 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 910 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 911 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 912 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 913 | if (p == (const Quantum *) NULL) |
| 914 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 915 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 916 | { |
| 917 | register ssize_t |
| 918 | i; |
| 919 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 920 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 921 | { |
| 922 | *q=0; |
| 923 | switch (quantum_map[i]) |
| 924 | { |
| 925 | case RedQuantum: |
| 926 | case CyanQuantum: |
| 927 | { |
| 928 | *q=(float) (QuantumScale*GetPixelRed(image,p)); |
| 929 | break; |
| 930 | } |
| 931 | case GreenQuantum: |
| 932 | case MagentaQuantum: |
| 933 | { |
| 934 | *q=(float) (QuantumScale*GetPixelGreen(image,p)); |
| 935 | break; |
| 936 | } |
| 937 | case BlueQuantum: |
| 938 | case YellowQuantum: |
| 939 | { |
| 940 | *q=(float) (QuantumScale*GetPixelBlue(image,p)); |
| 941 | break; |
| 942 | } |
| 943 | case AlphaQuantum: |
| 944 | { |
| 945 | *q=(float) (QuantumScale*((Quantum) (GetPixelAlpha(image,p)))); |
| 946 | break; |
| 947 | } |
| 948 | case OpacityQuantum: |
| 949 | { |
| 950 | *q=(float) (QuantumScale*GetPixelAlpha(image,p)); |
| 951 | break; |
| 952 | } |
| 953 | case BlackQuantum: |
| 954 | { |
| 955 | if (image->colorspace == CMYKColorspace) |
| 956 | *q=(float) (QuantumScale* GetPixelBlack(image,p)); |
| 957 | break; |
| 958 | } |
| 959 | case IndexQuantum: |
| 960 | { |
| 961 | *q=(float) (QuantumScale*GetPixelIntensity(image,p)); |
| 962 | break; |
| 963 | } |
| 964 | default: |
| 965 | *q=0; |
| 966 | } |
| 967 | q++; |
| 968 | } |
| 969 | p+=GetPixelChannels(image); |
| 970 | } |
| 971 | } |
| 972 | } |
| 973 | |
cristy | 2dc655d | 2012-07-05 13:16:28 +0000 | [diff] [blame] | 974 | static void ExportLongPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 975 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 976 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 977 | { |
| 978 | register const Quantum |
| 979 | *restrict p; |
| 980 | |
| 981 | register ssize_t |
| 982 | x; |
| 983 | |
| 984 | register unsigned int |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 985 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 986 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 987 | size_t |
| 988 | length; |
| 989 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 990 | ssize_t |
| 991 | y; |
| 992 | |
| 993 | q=(unsigned int *) pixels; |
| 994 | if (LocaleCompare(map,"BGR") == 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)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1006 | p+=GetPixelChannels(image); |
| 1007 | } |
| 1008 | } |
| 1009 | return; |
| 1010 | } |
| 1011 | if (LocaleCompare(map,"BGRA") == 0) |
| 1012 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1013 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1014 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1015 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1016 | if (p == (const Quantum *) NULL) |
| 1017 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1018 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1019 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1020 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1021 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1022 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1023 | *q++=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1024 | p+=GetPixelChannels(image); |
| 1025 | } |
| 1026 | } |
| 1027 | return; |
| 1028 | } |
| 1029 | if (LocaleCompare(map,"BGRP") == 0) |
| 1030 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1031 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1032 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1033 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1034 | if (p == (const Quantum *) NULL) |
| 1035 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1036 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1037 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1038 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1039 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1040 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1041 | *q++=0; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1042 | p+=GetPixelChannels(image); |
| 1043 | } |
| 1044 | } |
| 1045 | return; |
| 1046 | } |
| 1047 | if (LocaleCompare(map,"I") == 0) |
| 1048 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1049 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1050 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1051 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1052 | if (p == (const Quantum *) NULL) |
| 1053 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1054 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1055 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1056 | *q++=ScaleQuantumToLong(GetPixelIntensity(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,"RGB") == 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)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1074 | p+=GetPixelChannels(image); |
| 1075 | } |
| 1076 | } |
| 1077 | return; |
| 1078 | } |
| 1079 | if (LocaleCompare(map,"RGBA") == 0) |
| 1080 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1081 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1082 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1083 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1084 | if (p == (const Quantum *) NULL) |
| 1085 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1086 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1087 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1088 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1089 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1090 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1091 | *q++=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1092 | p+=GetPixelChannels(image); |
| 1093 | } |
| 1094 | } |
| 1095 | return; |
| 1096 | } |
| 1097 | if (LocaleCompare(map,"RGBP") == 0) |
| 1098 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1099 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1100 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1101 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1102 | if (p == (const Quantum *) NULL) |
| 1103 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1104 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1105 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1106 | *q++=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 1107 | *q++=ScaleQuantumToLong(GetPixelGreen(image,p)); |
| 1108 | *q++=ScaleQuantumToLong(GetPixelBlue(image,p)); |
| 1109 | *q++=0; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1110 | p+=GetPixelChannels(image); |
| 1111 | } |
| 1112 | } |
| 1113 | return; |
| 1114 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1115 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1116 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1117 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1118 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1119 | if (p == (const Quantum *) NULL) |
| 1120 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1121 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1122 | { |
| 1123 | register ssize_t |
| 1124 | i; |
| 1125 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1126 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1127 | { |
| 1128 | *q=0; |
| 1129 | switch (quantum_map[i]) |
| 1130 | { |
| 1131 | case RedQuantum: |
| 1132 | case CyanQuantum: |
| 1133 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1134 | *q=ScaleQuantumToLong(GetPixelRed(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1135 | break; |
| 1136 | } |
| 1137 | case GreenQuantum: |
| 1138 | case MagentaQuantum: |
| 1139 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1140 | *q=ScaleQuantumToLong(GetPixelGreen(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1141 | break; |
| 1142 | } |
| 1143 | case BlueQuantum: |
| 1144 | case YellowQuantum: |
| 1145 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1146 | *q=ScaleQuantumToLong(GetPixelBlue(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1147 | break; |
| 1148 | } |
| 1149 | case AlphaQuantum: |
| 1150 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1151 | *q=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1152 | break; |
| 1153 | } |
| 1154 | case OpacityQuantum: |
| 1155 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1156 | *q=ScaleQuantumToLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1157 | break; |
| 1158 | } |
| 1159 | case BlackQuantum: |
| 1160 | { |
| 1161 | if (image->colorspace == CMYKColorspace) |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1162 | *q=ScaleQuantumToLong(GetPixelBlack(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1163 | break; |
| 1164 | } |
| 1165 | case IndexQuantum: |
| 1166 | { |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1167 | *q=ScaleQuantumToLong(GetPixelIntensity(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1168 | break; |
| 1169 | } |
| 1170 | default: |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1171 | break; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1172 | } |
| 1173 | q++; |
| 1174 | } |
| 1175 | p+=GetPixelChannels(image); |
| 1176 | } |
| 1177 | } |
| 1178 | } |
| 1179 | |
cristy | 2dc655d | 2012-07-05 13:16:28 +0000 | [diff] [blame] | 1180 | static void ExportLongLongPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 1181 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 1182 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1183 | { |
| 1184 | register const Quantum |
| 1185 | *restrict p; |
| 1186 | |
| 1187 | register ssize_t |
| 1188 | x; |
| 1189 | |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1190 | register MagickSizeType |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 1191 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1192 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1193 | size_t |
| 1194 | length; |
| 1195 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1196 | ssize_t |
| 1197 | y; |
| 1198 | |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1199 | q=(MagickSizeType *) pixels; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1200 | if (LocaleCompare(map,"BGR") == 0) |
| 1201 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1202 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1203 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1204 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1205 | if (p == (const Quantum *) NULL) |
| 1206 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1207 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1208 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1209 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
| 1210 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
| 1211 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1212 | p+=GetPixelChannels(image); |
| 1213 | } |
| 1214 | } |
| 1215 | return; |
| 1216 | } |
| 1217 | if (LocaleCompare(map,"BGRA") == 0) |
| 1218 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1219 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1220 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1221 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1222 | if (p == (const Quantum *) NULL) |
| 1223 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1224 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1225 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1226 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
| 1227 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
| 1228 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
| 1229 | *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1230 | p+=GetPixelChannels(image); |
| 1231 | } |
| 1232 | } |
| 1233 | return; |
| 1234 | } |
| 1235 | if (LocaleCompare(map,"BGRP") == 0) |
| 1236 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1237 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1238 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1239 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1240 | if (p == (const Quantum *) NULL) |
| 1241 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1242 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1243 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1244 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
| 1245 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
| 1246 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1247 | *q++=0; |
| 1248 | p+=GetPixelChannels(image); |
| 1249 | } |
| 1250 | } |
| 1251 | return; |
| 1252 | } |
| 1253 | if (LocaleCompare(map,"I") == 0) |
| 1254 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1255 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1256 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1257 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1258 | if (p == (const Quantum *) NULL) |
| 1259 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1260 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1261 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1262 | *q++=ScaleQuantumToLongLong(GetPixelIntensity(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1263 | p+=GetPixelChannels(image); |
| 1264 | } |
| 1265 | } |
| 1266 | return; |
| 1267 | } |
| 1268 | if (LocaleCompare(map,"RGB") == 0) |
| 1269 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1270 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1271 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1272 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1273 | if (p == (const Quantum *) NULL) |
| 1274 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1275 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1276 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1277 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
| 1278 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
| 1279 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1280 | p+=GetPixelChannels(image); |
| 1281 | } |
| 1282 | } |
| 1283 | return; |
| 1284 | } |
| 1285 | if (LocaleCompare(map,"RGBA") == 0) |
| 1286 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1287 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1288 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1289 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1290 | if (p == (const Quantum *) NULL) |
| 1291 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1292 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1293 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1294 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
| 1295 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
| 1296 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
| 1297 | *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1298 | p+=GetPixelChannels(image); |
| 1299 | } |
| 1300 | } |
| 1301 | return; |
| 1302 | } |
| 1303 | if (LocaleCompare(map,"RGBP") == 0) |
| 1304 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1305 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1306 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1307 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1308 | if (p == (const Quantum *) NULL) |
| 1309 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1310 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1311 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1312 | *q++=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
| 1313 | *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
| 1314 | *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1315 | *q++=0; |
| 1316 | p+=GetPixelChannels(image); |
| 1317 | } |
| 1318 | } |
| 1319 | return; |
| 1320 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1321 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1322 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1323 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1324 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1325 | if (p == (const Quantum *) NULL) |
| 1326 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1327 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1328 | { |
| 1329 | register ssize_t |
| 1330 | i; |
| 1331 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1332 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1333 | { |
| 1334 | *q=0; |
| 1335 | switch (quantum_map[i]) |
| 1336 | { |
| 1337 | case RedQuantum: |
| 1338 | case CyanQuantum: |
| 1339 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1340 | *q=ScaleQuantumToLongLong(GetPixelRed(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1341 | break; |
| 1342 | } |
| 1343 | case GreenQuantum: |
| 1344 | case MagentaQuantum: |
| 1345 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1346 | *q=ScaleQuantumToLongLong(GetPixelGreen(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1347 | break; |
| 1348 | } |
| 1349 | case BlueQuantum: |
| 1350 | case YellowQuantum: |
| 1351 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1352 | *q=ScaleQuantumToLongLong(GetPixelBlue(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1353 | break; |
| 1354 | } |
| 1355 | case AlphaQuantum: |
| 1356 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1357 | *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1358 | break; |
| 1359 | } |
| 1360 | case OpacityQuantum: |
| 1361 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1362 | *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1363 | break; |
| 1364 | } |
| 1365 | case BlackQuantum: |
| 1366 | { |
| 1367 | if (image->colorspace == CMYKColorspace) |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1368 | *q=ScaleQuantumToLongLong(GetPixelBlack(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1369 | break; |
| 1370 | } |
| 1371 | case IndexQuantum: |
| 1372 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 1373 | *q=ScaleQuantumToLongLong(GetPixelIntensity(image,p)); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1374 | break; |
| 1375 | } |
| 1376 | default: |
| 1377 | break; |
| 1378 | } |
| 1379 | q++; |
| 1380 | } |
| 1381 | p+=GetPixelChannels(image); |
| 1382 | } |
| 1383 | } |
| 1384 | } |
| 1385 | |
cristy | 2dc655d | 2012-07-05 13:16:28 +0000 | [diff] [blame] | 1386 | static void ExportQuantumPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 1387 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 1388 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1389 | { |
| 1390 | register const Quantum |
| 1391 | *restrict p; |
| 1392 | |
| 1393 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 1394 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1395 | |
| 1396 | register ssize_t |
| 1397 | x; |
| 1398 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1399 | size_t |
| 1400 | length; |
| 1401 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1402 | ssize_t |
| 1403 | y; |
| 1404 | |
| 1405 | q=(Quantum *) pixels; |
| 1406 | if (LocaleCompare(map,"BGR") == 0) |
| 1407 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1408 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1409 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1410 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1411 | if (p == (const Quantum *) NULL) |
| 1412 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1413 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1414 | { |
| 1415 | *q++=GetPixelBlue(image,p); |
| 1416 | *q++=GetPixelGreen(image,p); |
| 1417 | *q++=GetPixelRed(image,p); |
| 1418 | p+=GetPixelChannels(image); |
| 1419 | } |
| 1420 | } |
| 1421 | return; |
| 1422 | } |
| 1423 | if (LocaleCompare(map,"BGRA") == 0) |
| 1424 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1425 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1426 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1427 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1428 | if (p == (const Quantum *) NULL) |
| 1429 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1430 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1431 | { |
| 1432 | *q++=GetPixelBlue(image,p); |
| 1433 | *q++=GetPixelGreen(image,p); |
| 1434 | *q++=GetPixelRed(image,p); |
| 1435 | *q++=(Quantum) (GetPixelAlpha(image,p)); |
| 1436 | p+=GetPixelChannels(image); |
| 1437 | } |
| 1438 | } |
| 1439 | return; |
| 1440 | } |
| 1441 | if (LocaleCompare(map,"BGRP") == 0) |
| 1442 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1443 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1444 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1445 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1446 | if (p == (const Quantum *) NULL) |
| 1447 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1448 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1449 | { |
| 1450 | *q++=GetPixelBlue(image,p); |
| 1451 | *q++=GetPixelGreen(image,p); |
| 1452 | *q++=GetPixelRed(image,p); |
| 1453 | *q++=(Quantum) 0; |
| 1454 | p+=GetPixelChannels(image); |
| 1455 | } |
| 1456 | } |
| 1457 | return; |
| 1458 | } |
| 1459 | if (LocaleCompare(map,"I") == 0) |
| 1460 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1461 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1462 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1463 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1464 | if (p == (const Quantum *) NULL) |
| 1465 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1466 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1467 | { |
| 1468 | *q++=GetPixelIntensity(image,p); |
| 1469 | p+=GetPixelChannels(image); |
| 1470 | } |
| 1471 | } |
| 1472 | return; |
| 1473 | } |
| 1474 | if (LocaleCompare(map,"RGB") == 0) |
| 1475 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1476 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1477 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1478 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1479 | if (p == (const Quantum *) NULL) |
| 1480 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1481 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1482 | { |
| 1483 | *q++=GetPixelRed(image,p); |
| 1484 | *q++=GetPixelGreen(image,p); |
| 1485 | *q++=GetPixelBlue(image,p); |
| 1486 | p+=GetPixelChannels(image); |
| 1487 | } |
| 1488 | } |
| 1489 | return; |
| 1490 | } |
| 1491 | if (LocaleCompare(map,"RGBA") == 0) |
| 1492 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1493 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1494 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1495 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1496 | if (p == (const Quantum *) NULL) |
| 1497 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1498 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1499 | { |
| 1500 | *q++=GetPixelRed(image,p); |
| 1501 | *q++=GetPixelGreen(image,p); |
| 1502 | *q++=GetPixelBlue(image,p); |
| 1503 | *q++=(Quantum) (GetPixelAlpha(image,p)); |
| 1504 | p+=GetPixelChannels(image); |
| 1505 | } |
| 1506 | } |
| 1507 | return; |
| 1508 | } |
| 1509 | if (LocaleCompare(map,"RGBP") == 0) |
| 1510 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1511 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1512 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1513 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1514 | if (p == (const Quantum *) NULL) |
| 1515 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1516 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1517 | { |
| 1518 | *q++=GetPixelRed(image,p); |
| 1519 | *q++=GetPixelGreen(image,p); |
| 1520 | *q++=GetPixelBlue(image,p); |
| 1521 | *q++=(Quantum) 0; |
| 1522 | p+=GetPixelChannels(image); |
| 1523 | } |
| 1524 | } |
| 1525 | return; |
| 1526 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1527 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1528 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1529 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1530 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1531 | if (p == (const Quantum *) NULL) |
| 1532 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1533 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1534 | { |
| 1535 | register ssize_t |
| 1536 | i; |
| 1537 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1538 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1539 | { |
| 1540 | *q=(Quantum) 0; |
| 1541 | switch (quantum_map[i]) |
| 1542 | { |
| 1543 | case RedQuantum: |
| 1544 | case CyanQuantum: |
| 1545 | { |
| 1546 | *q=GetPixelRed(image,p); |
| 1547 | break; |
| 1548 | } |
| 1549 | case GreenQuantum: |
| 1550 | case MagentaQuantum: |
| 1551 | { |
| 1552 | *q=GetPixelGreen(image,p); |
| 1553 | break; |
| 1554 | } |
| 1555 | case BlueQuantum: |
| 1556 | case YellowQuantum: |
| 1557 | { |
| 1558 | *q=GetPixelBlue(image,p); |
| 1559 | break; |
| 1560 | } |
| 1561 | case AlphaQuantum: |
| 1562 | { |
| 1563 | *q=GetPixelAlpha(image,p); |
| 1564 | break; |
| 1565 | } |
| 1566 | case OpacityQuantum: |
| 1567 | { |
| 1568 | *q=GetPixelAlpha(image,p); |
| 1569 | break; |
| 1570 | } |
| 1571 | case BlackQuantum: |
| 1572 | { |
| 1573 | if (image->colorspace == CMYKColorspace) |
| 1574 | *q=GetPixelBlack(image,p); |
| 1575 | break; |
| 1576 | } |
| 1577 | case IndexQuantum: |
| 1578 | { |
| 1579 | *q=(GetPixelIntensity(image,p)); |
| 1580 | break; |
| 1581 | } |
| 1582 | default: |
| 1583 | { |
| 1584 | *q=(Quantum) 0; |
| 1585 | break; |
| 1586 | } |
| 1587 | } |
| 1588 | q++; |
| 1589 | } |
| 1590 | p+=GetPixelChannels(image); |
| 1591 | } |
| 1592 | } |
| 1593 | } |
| 1594 | |
cristy | 2dc655d | 2012-07-05 13:16:28 +0000 | [diff] [blame] | 1595 | static void ExportShortPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 1596 | const char *restrict map,const QuantumType *quantum_map,void *pixels, |
| 1597 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1598 | { |
| 1599 | register const Quantum |
| 1600 | *restrict p; |
| 1601 | |
| 1602 | register ssize_t |
| 1603 | x; |
| 1604 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1605 | register unsigned short |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 1606 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1607 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1608 | size_t |
| 1609 | length; |
| 1610 | |
| 1611 | ssize_t |
| 1612 | y; |
| 1613 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1614 | q=(unsigned short *) pixels; |
| 1615 | if (LocaleCompare(map,"BGR") == 0) |
| 1616 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1617 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1618 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1619 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1620 | if (p == (const Quantum *) NULL) |
| 1621 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1622 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1623 | { |
| 1624 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1625 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1626 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1627 | p+=GetPixelChannels(image); |
| 1628 | } |
| 1629 | } |
| 1630 | return; |
| 1631 | } |
| 1632 | if (LocaleCompare(map,"BGRA") == 0) |
| 1633 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1634 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1635 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1636 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1637 | if (p == (const Quantum *) NULL) |
| 1638 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1639 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1640 | { |
| 1641 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1642 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1643 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1644 | *q++=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
| 1645 | p+=GetPixelChannels(image); |
| 1646 | } |
| 1647 | } |
| 1648 | return; |
| 1649 | } |
| 1650 | if (LocaleCompare(map,"BGRP") == 0) |
| 1651 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1652 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1653 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1654 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1655 | if (p == (const Quantum *) NULL) |
| 1656 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1657 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1658 | { |
| 1659 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1660 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1661 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1662 | *q++=0; |
| 1663 | p+=GetPixelChannels(image); |
| 1664 | } |
| 1665 | } |
| 1666 | return; |
| 1667 | } |
| 1668 | if (LocaleCompare(map,"I") == 0) |
| 1669 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1670 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1671 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1672 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1673 | if (p == (const Quantum *) NULL) |
| 1674 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1675 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1676 | { |
| 1677 | *q++=ScaleQuantumToShort(GetPixelIntensity(image,p)); |
| 1678 | p+=GetPixelChannels(image); |
| 1679 | } |
| 1680 | } |
| 1681 | return; |
| 1682 | } |
| 1683 | if (LocaleCompare(map,"RGB") == 0) |
| 1684 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1685 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1686 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1687 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1688 | if (p == (const Quantum *) NULL) |
| 1689 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1690 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1691 | { |
| 1692 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1693 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1694 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1695 | p+=GetPixelChannels(image); |
| 1696 | } |
| 1697 | } |
| 1698 | return; |
| 1699 | } |
| 1700 | if (LocaleCompare(map,"RGBA") == 0) |
| 1701 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1702 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1703 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1704 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1705 | if (p == (const Quantum *) NULL) |
| 1706 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1707 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1708 | { |
| 1709 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1710 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1711 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1712 | *q++=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
| 1713 | p+=GetPixelChannels(image); |
| 1714 | } |
| 1715 | } |
| 1716 | return; |
| 1717 | } |
| 1718 | if (LocaleCompare(map,"RGBP") == 0) |
| 1719 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1720 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1721 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1722 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1723 | if (p == (const Quantum *) NULL) |
| 1724 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1725 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1726 | { |
| 1727 | *q++=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1728 | *q++=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1729 | *q++=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1730 | *q++=0; |
| 1731 | p+=GetPixelChannels(image); |
| 1732 | } |
| 1733 | } |
| 1734 | return; |
| 1735 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1736 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1737 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1738 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1739 | p=GetVirtualPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1740 | if (p == (const Quantum *) NULL) |
| 1741 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1742 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1743 | { |
| 1744 | register ssize_t |
| 1745 | i; |
| 1746 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1747 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1748 | { |
| 1749 | *q=0; |
| 1750 | switch (quantum_map[i]) |
| 1751 | { |
| 1752 | case RedQuantum: |
| 1753 | case CyanQuantum: |
| 1754 | { |
| 1755 | *q=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 1756 | break; |
| 1757 | } |
| 1758 | case GreenQuantum: |
| 1759 | case MagentaQuantum: |
| 1760 | { |
| 1761 | *q=ScaleQuantumToShort(GetPixelGreen(image,p)); |
| 1762 | break; |
| 1763 | } |
| 1764 | case BlueQuantum: |
| 1765 | case YellowQuantum: |
| 1766 | { |
| 1767 | *q=ScaleQuantumToShort(GetPixelBlue(image,p)); |
| 1768 | break; |
| 1769 | } |
| 1770 | case AlphaQuantum: |
| 1771 | { |
| 1772 | *q=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
| 1773 | break; |
| 1774 | } |
| 1775 | case OpacityQuantum: |
| 1776 | { |
| 1777 | *q=ScaleQuantumToShort(GetPixelAlpha(image,p)); |
| 1778 | break; |
| 1779 | } |
| 1780 | case BlackQuantum: |
| 1781 | { |
| 1782 | if (image->colorspace == CMYKColorspace) |
| 1783 | *q=ScaleQuantumToShort(GetPixelBlack(image,p)); |
| 1784 | break; |
| 1785 | } |
| 1786 | case IndexQuantum: |
| 1787 | { |
| 1788 | *q=ScaleQuantumToShort(GetPixelIntensity(image,p)); |
| 1789 | break; |
| 1790 | } |
| 1791 | default: |
| 1792 | break; |
| 1793 | } |
| 1794 | q++; |
| 1795 | } |
| 1796 | p+=GetPixelChannels(image); |
| 1797 | } |
| 1798 | } |
| 1799 | } |
| 1800 | |
cristy | 2dc655d | 2012-07-05 13:16:28 +0000 | [diff] [blame] | 1801 | MagickExport MagickBooleanType ExportImagePixels(Image *image, |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1802 | const ssize_t x,const ssize_t y,const size_t width,const size_t height, |
| 1803 | const char *map,const StorageType type,void *pixels,ExceptionInfo *exception) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1804 | { |
| 1805 | QuantumType |
| 1806 | *quantum_map; |
| 1807 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1808 | RectangleInfo |
| 1809 | roi; |
| 1810 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1811 | register ssize_t |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 1812 | i; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1813 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1814 | size_t |
| 1815 | length; |
| 1816 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1817 | assert(image != (Image *) NULL); |
| 1818 | assert(image->signature == MagickSignature); |
| 1819 | if (image->debug != MagickFalse) |
| 1820 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1821 | length=strlen(map); |
| 1822 | quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1823 | if (quantum_map == (QuantumType *) NULL) |
| 1824 | { |
| 1825 | (void) ThrowMagickException(exception,GetMagickModule(), |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1826 | ResourceLimitError,"MemoryAllocationFailed","'%s'",image->filename); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1827 | return(MagickFalse); |
| 1828 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 1829 | for (i=0; i < (ssize_t) length; i++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1830 | { |
| 1831 | switch (map[i]) |
| 1832 | { |
| 1833 | case 'A': |
| 1834 | case 'a': |
| 1835 | { |
| 1836 | quantum_map[i]=AlphaQuantum; |
| 1837 | break; |
| 1838 | } |
| 1839 | case 'B': |
| 1840 | case 'b': |
| 1841 | { |
| 1842 | quantum_map[i]=BlueQuantum; |
| 1843 | break; |
| 1844 | } |
| 1845 | case 'C': |
| 1846 | case 'c': |
| 1847 | { |
| 1848 | quantum_map[i]=CyanQuantum; |
| 1849 | if (image->colorspace == CMYKColorspace) |
| 1850 | break; |
| 1851 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1852 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1853 | "ColorSeparatedImageRequired","'%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1854 | return(MagickFalse); |
| 1855 | } |
| 1856 | case 'g': |
| 1857 | case 'G': |
| 1858 | { |
| 1859 | quantum_map[i]=GreenQuantum; |
| 1860 | break; |
| 1861 | } |
| 1862 | case 'I': |
| 1863 | case 'i': |
| 1864 | { |
| 1865 | quantum_map[i]=IndexQuantum; |
| 1866 | break; |
| 1867 | } |
| 1868 | case 'K': |
| 1869 | case 'k': |
| 1870 | { |
| 1871 | quantum_map[i]=BlackQuantum; |
| 1872 | if (image->colorspace == CMYKColorspace) |
| 1873 | break; |
| 1874 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1875 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1876 | "ColorSeparatedImageRequired","'%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1877 | return(MagickFalse); |
| 1878 | } |
| 1879 | case 'M': |
| 1880 | case 'm': |
| 1881 | { |
| 1882 | quantum_map[i]=MagentaQuantum; |
| 1883 | if (image->colorspace == CMYKColorspace) |
| 1884 | break; |
| 1885 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1886 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1887 | "ColorSeparatedImageRequired","'%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1888 | return(MagickFalse); |
| 1889 | } |
| 1890 | case 'o': |
| 1891 | case 'O': |
| 1892 | { |
| 1893 | quantum_map[i]=OpacityQuantum; |
| 1894 | break; |
| 1895 | } |
| 1896 | case 'P': |
| 1897 | case 'p': |
| 1898 | { |
| 1899 | quantum_map[i]=UndefinedQuantum; |
| 1900 | break; |
| 1901 | } |
| 1902 | case 'R': |
| 1903 | case 'r': |
| 1904 | { |
| 1905 | quantum_map[i]=RedQuantum; |
| 1906 | break; |
| 1907 | } |
| 1908 | case 'Y': |
| 1909 | case 'y': |
| 1910 | { |
| 1911 | quantum_map[i]=YellowQuantum; |
| 1912 | if (image->colorspace == CMYKColorspace) |
| 1913 | break; |
| 1914 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1915 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1916 | "ColorSeparatedImageRequired","'%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1917 | return(MagickFalse); |
| 1918 | } |
| 1919 | default: |
| 1920 | { |
| 1921 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1922 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1923 | "UnrecognizedPixelMap","'%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1924 | return(MagickFalse); |
| 1925 | } |
| 1926 | } |
| 1927 | } |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1928 | roi.width=width; |
| 1929 | roi.height=height; |
| 1930 | roi.x=x; |
| 1931 | roi.y=y; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1932 | switch (type) |
| 1933 | { |
| 1934 | case CharPixel: |
| 1935 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1936 | ExportCharPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1937 | break; |
| 1938 | } |
| 1939 | case DoublePixel: |
| 1940 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1941 | ExportDoublePixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1942 | break; |
| 1943 | } |
| 1944 | case FloatPixel: |
| 1945 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1946 | ExportFloatPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1947 | break; |
| 1948 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1949 | case LongPixel: |
| 1950 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1951 | ExportLongPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1952 | break; |
| 1953 | } |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1954 | case LongLongPixel: |
| 1955 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1956 | ExportLongLongPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 1957 | break; |
| 1958 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1959 | case QuantumPixel: |
| 1960 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1961 | ExportQuantumPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1962 | break; |
| 1963 | } |
| 1964 | case ShortPixel: |
| 1965 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 1966 | ExportShortPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1967 | break; |
| 1968 | } |
| 1969 | default: |
| 1970 | { |
| 1971 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1972 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1973 | "UnrecognizedPixelMap","'%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1974 | break; |
| 1975 | } |
| 1976 | } |
| 1977 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 1978 | return(MagickTrue); |
| 1979 | } |
| 1980 | |
| 1981 | /* |
| 1982 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1983 | % % |
| 1984 | % % |
| 1985 | % % |
cristy | aa8634f | 2011-10-01 13:25:12 +0000 | [diff] [blame] | 1986 | % G e t P i x e l I n f o % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1987 | % % |
| 1988 | % % |
| 1989 | % % |
| 1990 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1991 | % |
| 1992 | % GetPixelInfo() initializes the PixelInfo structure. |
| 1993 | % |
| 1994 | % The format of the GetPixelInfo method is: |
| 1995 | % |
| 1996 | % GetPixelInfo(const Image *image,PixelInfo *pixel) |
| 1997 | % |
| 1998 | % A description of each parameter follows: |
| 1999 | % |
| 2000 | % o image: the image. |
| 2001 | % |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 2002 | % o pixel: Specifies a pointer to a PixelInfo structure. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2003 | % |
| 2004 | */ |
cristy | aa8634f | 2011-10-01 13:25:12 +0000 | [diff] [blame] | 2005 | MagickExport void GetPixelInfo(const Image *image,PixelInfo *pixel) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2006 | { |
| 2007 | pixel->storage_class=DirectClass; |
cristy | 7020ae6 | 2012-04-18 12:58:34 +0000 | [diff] [blame] | 2008 | pixel->colorspace=sRGBColorspace; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 2009 | pixel->alpha_trait=UndefinedPixelTrait; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2010 | pixel->fuzz=0.0; |
| 2011 | pixel->depth=MAGICKCORE_QUANTUM_DEPTH; |
| 2012 | pixel->red=0.0; |
| 2013 | pixel->green=0.0; |
| 2014 | pixel->blue=0.0; |
| 2015 | pixel->black=0.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2016 | pixel->alpha=(double) OpaqueAlpha; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2017 | pixel->index=0.0; |
| 2018 | if (image == (const Image *) NULL) |
| 2019 | return; |
| 2020 | pixel->storage_class=image->storage_class; |
| 2021 | pixel->colorspace=image->colorspace; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 2022 | pixel->alpha_trait=image->alpha_trait; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2023 | pixel->depth=image->depth; |
| 2024 | pixel->fuzz=image->fuzz; |
| 2025 | } |
| 2026 | |
| 2027 | /* |
| 2028 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2029 | % % |
| 2030 | % % |
| 2031 | % % |
| 2032 | % I m p o r t I m a g e P i x e l s % |
| 2033 | % % |
| 2034 | % % |
| 2035 | % % |
| 2036 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2037 | % |
| 2038 | % ImportImagePixels() accepts pixel data and stores in the image at the |
| 2039 | % location you specify. The method returns MagickTrue on success otherwise |
| 2040 | % MagickFalse if an error is encountered. The pixel data can be either char, |
cristy | b5a45a3 | 2012-01-10 13:31:13 +0000 | [diff] [blame] | 2041 | % Quantum, short int, unsigned int, unsigned long long, float, or double in |
| 2042 | % the order specified by map. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2043 | % |
| 2044 | % Suppose your want to upload the first scanline of a 640x480 image from |
| 2045 | % character data in red-green-blue order: |
| 2046 | % |
| 2047 | % ImportImagePixels(image,0,0,640,1,"RGB",CharPixel,pixels); |
| 2048 | % |
| 2049 | % The format of the ImportImagePixels method is: |
| 2050 | % |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2051 | % MagickBooleanType ImportImagePixels(Image *image,const ssize_t x, |
| 2052 | % const ssize_t y,const size_t width,const size_t height, |
| 2053 | % const char *map,const StorageType type,const void *pixels, |
| 2054 | % ExceptionInfo *exception) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2055 | % |
| 2056 | % A description of each parameter follows: |
| 2057 | % |
| 2058 | % o image: the image. |
| 2059 | % |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2060 | % o x,y,width,height: These values define the perimeter |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2061 | % of a region of pixels you want to define. |
| 2062 | % |
| 2063 | % o map: This string reflects the expected ordering of the pixel array. |
| 2064 | % It can be any combination or order of R = red, G = green, B = blue, |
| 2065 | % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan, |
| 2066 | % Y = yellow, M = magenta, K = black, I = intensity (for grayscale), |
| 2067 | % P = pad. |
| 2068 | % |
| 2069 | % o type: Define the data type of the pixels. Float and double types are |
| 2070 | % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 2071 | % types: CharPixel (char *), DoublePixel (double *), FloatPixel (float *), |
cristy | ff6834e | 2012-01-10 03:00:25 +0000 | [diff] [blame] | 2072 | % LongPixel (unsigned int *), LongLongPixel (unsigned long long *), |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 2073 | % QuantumPixel (Quantum *), or ShortPixel (unsigned short *). |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2074 | % |
| 2075 | % o pixels: This array of values contain the pixel components as defined by |
| 2076 | % map and type. You must preallocate this array where the expected |
| 2077 | % length varies depending on the values of width, height, map, and type. |
| 2078 | % |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 2079 | % o exception: return any errors or warnings in this structure. |
| 2080 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2081 | */ |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2082 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2083 | static void ImportCharPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 2084 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 2085 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2086 | { |
| 2087 | register const unsigned char |
| 2088 | *restrict p; |
| 2089 | |
| 2090 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 2091 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2092 | |
| 2093 | register ssize_t |
| 2094 | x; |
| 2095 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2096 | size_t |
| 2097 | length; |
| 2098 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2099 | ssize_t |
| 2100 | y; |
| 2101 | |
| 2102 | p=(const unsigned char *) pixels; |
| 2103 | if (LocaleCompare(map,"BGR") == 0) |
| 2104 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2105 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2106 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2107 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2108 | if (q == (Quantum *) NULL) |
| 2109 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2110 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2111 | { |
| 2112 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2113 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2114 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2115 | q+=GetPixelChannels(image); |
| 2116 | } |
| 2117 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2118 | break; |
| 2119 | } |
| 2120 | return; |
| 2121 | } |
| 2122 | if (LocaleCompare(map,"BGRA") == 0) |
| 2123 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2124 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2125 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2126 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2127 | if (q == (Quantum *) NULL) |
| 2128 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2129 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2130 | { |
| 2131 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2132 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2133 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2134 | SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); |
| 2135 | q+=GetPixelChannels(image); |
| 2136 | } |
| 2137 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2138 | break; |
| 2139 | } |
| 2140 | return; |
| 2141 | } |
| 2142 | if (LocaleCompare(map,"BGRO") == 0) |
| 2143 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2144 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2145 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2146 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2147 | if (q == (Quantum *) NULL) |
| 2148 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2149 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2150 | { |
| 2151 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2152 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2153 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2154 | SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); |
| 2155 | q+=GetPixelChannels(image); |
| 2156 | } |
| 2157 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2158 | break; |
| 2159 | } |
| 2160 | return; |
| 2161 | } |
| 2162 | if (LocaleCompare(map,"BGRP") == 0) |
| 2163 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2164 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2165 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2166 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2167 | if (q == (Quantum *) NULL) |
| 2168 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2169 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2170 | { |
| 2171 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2172 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2173 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2174 | p++; |
| 2175 | q+=GetPixelChannels(image); |
| 2176 | } |
| 2177 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2178 | break; |
| 2179 | } |
| 2180 | return; |
| 2181 | } |
| 2182 | if (LocaleCompare(map,"I") == 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 | SetPixelGray(image,ScaleCharToQuantum(*p++),q); |
| 2192 | q+=GetPixelChannels(image); |
| 2193 | } |
| 2194 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2195 | break; |
| 2196 | } |
| 2197 | return; |
| 2198 | } |
| 2199 | if (LocaleCompare(map,"RGB") == 0) |
| 2200 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2201 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2202 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2203 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2204 | if (q == (Quantum *) NULL) |
| 2205 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2206 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2207 | { |
| 2208 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2209 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2210 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2211 | q+=GetPixelChannels(image); |
| 2212 | } |
| 2213 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2214 | break; |
| 2215 | } |
| 2216 | return; |
| 2217 | } |
| 2218 | if (LocaleCompare(map,"RGBA") == 0) |
| 2219 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2220 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2221 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2222 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2223 | if (q == (Quantum *) NULL) |
| 2224 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2225 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2226 | { |
| 2227 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2228 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2229 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2230 | SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); |
| 2231 | q+=GetPixelChannels(image); |
| 2232 | } |
| 2233 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2234 | break; |
| 2235 | } |
| 2236 | return; |
| 2237 | } |
| 2238 | if (LocaleCompare(map,"RGBO") == 0) |
| 2239 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2240 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2241 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2242 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2243 | if (q == (Quantum *) NULL) |
| 2244 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2245 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2246 | { |
| 2247 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2248 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2249 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2250 | SetPixelAlpha(image,ScaleCharToQuantum(*p++),q); |
| 2251 | q+=GetPixelChannels(image); |
| 2252 | } |
| 2253 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2254 | break; |
| 2255 | } |
| 2256 | return; |
| 2257 | } |
| 2258 | if (LocaleCompare(map,"RGBP") == 0) |
| 2259 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2260 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2261 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2262 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2263 | if (q == (Quantum *) NULL) |
| 2264 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2265 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2266 | { |
| 2267 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 2268 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 2269 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 2270 | p++; |
| 2271 | q+=GetPixelChannels(image); |
| 2272 | } |
| 2273 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2274 | break; |
| 2275 | } |
| 2276 | return; |
| 2277 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2278 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2279 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2280 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2281 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2282 | if (q == (Quantum *) NULL) |
| 2283 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2284 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2285 | { |
| 2286 | register ssize_t |
| 2287 | i; |
| 2288 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2289 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2290 | { |
| 2291 | switch (quantum_map[i]) |
| 2292 | { |
| 2293 | case RedQuantum: |
| 2294 | case CyanQuantum: |
| 2295 | { |
| 2296 | SetPixelRed(image,ScaleCharToQuantum(*p),q); |
| 2297 | break; |
| 2298 | } |
| 2299 | case GreenQuantum: |
| 2300 | case MagentaQuantum: |
| 2301 | { |
| 2302 | SetPixelGreen(image,ScaleCharToQuantum(*p),q); |
| 2303 | break; |
| 2304 | } |
| 2305 | case BlueQuantum: |
| 2306 | case YellowQuantum: |
| 2307 | { |
| 2308 | SetPixelBlue(image,ScaleCharToQuantum(*p),q); |
| 2309 | break; |
| 2310 | } |
| 2311 | case AlphaQuantum: |
| 2312 | { |
| 2313 | SetPixelAlpha(image,ScaleCharToQuantum(*p),q); |
| 2314 | break; |
| 2315 | } |
| 2316 | case OpacityQuantum: |
| 2317 | { |
| 2318 | SetPixelAlpha(image,ScaleCharToQuantum(*p),q); |
| 2319 | break; |
| 2320 | } |
| 2321 | case BlackQuantum: |
| 2322 | { |
| 2323 | SetPixelBlack(image,ScaleCharToQuantum(*p),q); |
| 2324 | break; |
| 2325 | } |
| 2326 | case IndexQuantum: |
| 2327 | { |
| 2328 | SetPixelGray(image,ScaleCharToQuantum(*p),q); |
| 2329 | break; |
| 2330 | } |
| 2331 | default: |
| 2332 | break; |
| 2333 | } |
| 2334 | p++; |
| 2335 | } |
| 2336 | q+=GetPixelChannels(image); |
| 2337 | } |
| 2338 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2339 | break; |
| 2340 | } |
| 2341 | } |
| 2342 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2343 | static void ImportDoublePixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 2344 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 2345 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2346 | { |
| 2347 | register const double |
| 2348 | *restrict p; |
| 2349 | |
| 2350 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 2351 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2352 | |
| 2353 | register ssize_t |
| 2354 | x; |
| 2355 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2356 | size_t |
| 2357 | length; |
| 2358 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2359 | ssize_t |
| 2360 | y; |
| 2361 | |
| 2362 | p=(const double *) pixels; |
| 2363 | if (LocaleCompare(map,"BGR") == 0) |
| 2364 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2365 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2366 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2367 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2368 | if (q == (Quantum *) NULL) |
| 2369 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2370 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2371 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2372 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2373 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2374 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2375 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2376 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2377 | p++; |
| 2378 | q+=GetPixelChannels(image); |
| 2379 | } |
| 2380 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2381 | break; |
| 2382 | } |
| 2383 | return; |
| 2384 | } |
| 2385 | if (LocaleCompare(map,"BGRA") == 0) |
| 2386 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2387 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2388 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2389 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2390 | if (q == (Quantum *) NULL) |
| 2391 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2392 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2393 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2394 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2395 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2396 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2397 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2398 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2399 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2400 | SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2401 | p++; |
| 2402 | q+=GetPixelChannels(image); |
| 2403 | } |
| 2404 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2405 | break; |
| 2406 | } |
| 2407 | return; |
| 2408 | } |
| 2409 | if (LocaleCompare(map,"BGRP") == 0) |
| 2410 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2411 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2412 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2413 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2414 | if (q == (Quantum *) NULL) |
| 2415 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2416 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2417 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2418 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2419 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2420 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2421 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2422 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2423 | p++; |
| 2424 | p++; |
| 2425 | q+=GetPixelChannels(image); |
| 2426 | } |
| 2427 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2428 | break; |
| 2429 | } |
| 2430 | return; |
| 2431 | } |
| 2432 | if (LocaleCompare(map,"I") == 0) |
| 2433 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2434 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2435 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2436 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2437 | if (q == (Quantum *) NULL) |
| 2438 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2439 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2440 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2441 | SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2442 | p++; |
| 2443 | q+=GetPixelChannels(image); |
| 2444 | } |
| 2445 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2446 | break; |
| 2447 | } |
| 2448 | return; |
| 2449 | } |
| 2450 | if (LocaleCompare(map,"RGB") == 0) |
| 2451 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2452 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2453 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2454 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2455 | if (q == (Quantum *) NULL) |
| 2456 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2457 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2458 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2459 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2460 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2461 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2462 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2463 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2464 | p++; |
| 2465 | q+=GetPixelChannels(image); |
| 2466 | } |
| 2467 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2468 | break; |
| 2469 | } |
| 2470 | return; |
| 2471 | } |
| 2472 | if (LocaleCompare(map,"RGBA") == 0) |
| 2473 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2474 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2475 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2476 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2477 | if (q == (Quantum *) NULL) |
| 2478 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2479 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2480 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2481 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2482 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2483 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2484 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2485 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2486 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2487 | SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2488 | p++; |
| 2489 | q+=GetPixelChannels(image); |
| 2490 | } |
| 2491 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2492 | break; |
| 2493 | } |
| 2494 | return; |
| 2495 | } |
| 2496 | if (LocaleCompare(map,"RGBP") == 0) |
| 2497 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2498 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2499 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2500 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2501 | if (q == (Quantum *) NULL) |
| 2502 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2503 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2504 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2505 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2506 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2507 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2508 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2509 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2510 | p++; |
| 2511 | q+=GetPixelChannels(image); |
| 2512 | } |
| 2513 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2514 | break; |
| 2515 | } |
| 2516 | return; |
| 2517 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2518 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2519 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2520 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2521 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2522 | if (q == (Quantum *) NULL) |
| 2523 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2524 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2525 | { |
| 2526 | register ssize_t |
| 2527 | i; |
| 2528 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2529 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2530 | { |
| 2531 | switch (quantum_map[i]) |
| 2532 | { |
| 2533 | case RedQuantum: |
| 2534 | case CyanQuantum: |
| 2535 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2536 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2537 | break; |
| 2538 | } |
| 2539 | case GreenQuantum: |
| 2540 | case MagentaQuantum: |
| 2541 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2542 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2543 | break; |
| 2544 | } |
| 2545 | case BlueQuantum: |
| 2546 | case YellowQuantum: |
| 2547 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2548 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2549 | break; |
| 2550 | } |
| 2551 | case AlphaQuantum: |
| 2552 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2553 | SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2554 | break; |
| 2555 | } |
| 2556 | case OpacityQuantum: |
| 2557 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2558 | SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2559 | break; |
| 2560 | } |
| 2561 | case BlackQuantum: |
| 2562 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2563 | SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2564 | break; |
| 2565 | } |
| 2566 | case IndexQuantum: |
| 2567 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2568 | SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2569 | break; |
| 2570 | } |
| 2571 | default: |
| 2572 | break; |
| 2573 | } |
| 2574 | p++; |
| 2575 | } |
| 2576 | q+=GetPixelChannels(image); |
| 2577 | } |
| 2578 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2579 | break; |
| 2580 | } |
| 2581 | } |
| 2582 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2583 | static void ImportFloatPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 2584 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 2585 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2586 | { |
| 2587 | register const float |
| 2588 | *restrict p; |
| 2589 | |
| 2590 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 2591 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2592 | |
| 2593 | register ssize_t |
| 2594 | x; |
| 2595 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2596 | size_t |
| 2597 | length; |
| 2598 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2599 | ssize_t |
| 2600 | y; |
| 2601 | |
| 2602 | p=(const float *) pixels; |
| 2603 | if (LocaleCompare(map,"BGR") == 0) |
| 2604 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2605 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2606 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2607 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2608 | if (q == (Quantum *) NULL) |
| 2609 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2610 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2611 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2612 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2613 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2614 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2615 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2616 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2617 | p++; |
| 2618 | q+=GetPixelChannels(image); |
| 2619 | } |
| 2620 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2621 | break; |
| 2622 | } |
| 2623 | return; |
| 2624 | } |
| 2625 | if (LocaleCompare(map,"BGRA") == 0) |
| 2626 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2627 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2628 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2629 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2630 | if (q == (Quantum *) NULL) |
| 2631 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2632 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2633 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2634 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2635 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2636 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2637 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2638 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2639 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2640 | SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2641 | p++; |
| 2642 | q+=GetPixelChannels(image); |
| 2643 | } |
| 2644 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2645 | break; |
| 2646 | } |
| 2647 | return; |
| 2648 | } |
| 2649 | if (LocaleCompare(map,"BGRP") == 0) |
| 2650 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2651 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2652 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2653 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2654 | if (q == (Quantum *) NULL) |
| 2655 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2656 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2657 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2658 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2659 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2660 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2661 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2662 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2663 | p++; |
| 2664 | p++; |
| 2665 | q+=GetPixelChannels(image); |
| 2666 | } |
| 2667 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2668 | break; |
| 2669 | } |
| 2670 | return; |
| 2671 | } |
| 2672 | if (LocaleCompare(map,"I") == 0) |
| 2673 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2674 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2675 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2676 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2677 | if (q == (Quantum *) NULL) |
| 2678 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2679 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2680 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2681 | SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2682 | p++; |
| 2683 | q+=GetPixelChannels(image); |
| 2684 | } |
| 2685 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2686 | break; |
| 2687 | } |
| 2688 | return; |
| 2689 | } |
| 2690 | if (LocaleCompare(map,"RGB") == 0) |
| 2691 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2692 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2693 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2694 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2695 | if (q == (Quantum *) NULL) |
| 2696 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2697 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2698 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2699 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2700 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2701 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2702 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2703 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2704 | p++; |
| 2705 | q+=GetPixelChannels(image); |
| 2706 | } |
| 2707 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2708 | break; |
| 2709 | } |
| 2710 | return; |
| 2711 | } |
| 2712 | if (LocaleCompare(map,"RGBA") == 0) |
| 2713 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2714 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2715 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2716 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2717 | if (q == (Quantum *) NULL) |
| 2718 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2719 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2720 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2721 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2722 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2723 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2724 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2725 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2726 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2727 | SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2728 | p++; |
| 2729 | q+=GetPixelChannels(image); |
| 2730 | } |
| 2731 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2732 | break; |
| 2733 | } |
| 2734 | return; |
| 2735 | } |
| 2736 | if (LocaleCompare(map,"RGBP") == 0) |
| 2737 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2738 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2739 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2740 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2741 | if (q == (Quantum *) NULL) |
| 2742 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2743 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2744 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2745 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2746 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2747 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2748 | p++; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2749 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2750 | p++; |
| 2751 | q+=GetPixelChannels(image); |
| 2752 | } |
| 2753 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2754 | break; |
| 2755 | } |
| 2756 | return; |
| 2757 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2758 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2759 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2760 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2761 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2762 | if (q == (Quantum *) NULL) |
| 2763 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2764 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2765 | { |
| 2766 | register ssize_t |
| 2767 | i; |
| 2768 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2769 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2770 | { |
| 2771 | switch (quantum_map[i]) |
| 2772 | { |
| 2773 | case RedQuantum: |
| 2774 | case CyanQuantum: |
| 2775 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2776 | SetPixelRed(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2777 | break; |
| 2778 | } |
| 2779 | case GreenQuantum: |
| 2780 | case MagentaQuantum: |
| 2781 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2782 | SetPixelGreen(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2783 | break; |
| 2784 | } |
| 2785 | case BlueQuantum: |
| 2786 | case YellowQuantum: |
| 2787 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2788 | SetPixelBlue(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2789 | break; |
| 2790 | } |
| 2791 | case AlphaQuantum: |
| 2792 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2793 | SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2794 | break; |
| 2795 | } |
| 2796 | case OpacityQuantum: |
| 2797 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2798 | SetPixelAlpha(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2799 | break; |
| 2800 | } |
| 2801 | case BlackQuantum: |
| 2802 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2803 | SetPixelBlack(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2804 | break; |
| 2805 | } |
| 2806 | case IndexQuantum: |
| 2807 | { |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2808 | SetPixelGray(image,ClampToQuantum(QuantumRange*(*p)),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2809 | break; |
| 2810 | } |
| 2811 | default: |
| 2812 | break; |
| 2813 | } |
| 2814 | p++; |
| 2815 | } |
| 2816 | q+=GetPixelChannels(image); |
| 2817 | } |
| 2818 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2819 | break; |
| 2820 | } |
| 2821 | } |
| 2822 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2823 | static void ImportLongPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 2824 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 2825 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2826 | { |
| 2827 | register const unsigned int |
| 2828 | *restrict p; |
| 2829 | |
| 2830 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 2831 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2832 | |
| 2833 | register ssize_t |
| 2834 | x; |
| 2835 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2836 | size_t |
| 2837 | length; |
| 2838 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2839 | ssize_t |
| 2840 | y; |
| 2841 | |
| 2842 | p=(const unsigned int *) pixels; |
| 2843 | if (LocaleCompare(map,"BGR") == 0) |
| 2844 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2845 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2846 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2847 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2848 | if (q == (Quantum *) NULL) |
| 2849 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2850 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2851 | { |
| 2852 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 2853 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 2854 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 2855 | q+=GetPixelChannels(image); |
| 2856 | } |
| 2857 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2858 | break; |
| 2859 | } |
| 2860 | return; |
| 2861 | } |
| 2862 | if (LocaleCompare(map,"BGRA") == 0) |
| 2863 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2864 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2865 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2866 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2867 | if (q == (Quantum *) NULL) |
| 2868 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2869 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2870 | { |
| 2871 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 2872 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 2873 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 2874 | SetPixelAlpha(image,ScaleLongToQuantum(*p++),q); |
| 2875 | q+=GetPixelChannels(image); |
| 2876 | } |
| 2877 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2878 | break; |
| 2879 | } |
| 2880 | return; |
| 2881 | } |
| 2882 | if (LocaleCompare(map,"BGRP") == 0) |
| 2883 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2884 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2885 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2886 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2887 | if (q == (Quantum *) NULL) |
| 2888 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2889 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2890 | { |
| 2891 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 2892 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 2893 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 2894 | p++; |
| 2895 | q+=GetPixelChannels(image); |
| 2896 | } |
| 2897 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2898 | break; |
| 2899 | } |
| 2900 | return; |
| 2901 | } |
| 2902 | if (LocaleCompare(map,"I") == 0) |
| 2903 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2904 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2905 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2906 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2907 | if (q == (Quantum *) NULL) |
| 2908 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2909 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2910 | { |
| 2911 | SetPixelGray(image,ScaleLongToQuantum(*p++),q); |
| 2912 | q+=GetPixelChannels(image); |
| 2913 | } |
| 2914 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2915 | break; |
| 2916 | } |
| 2917 | return; |
| 2918 | } |
| 2919 | if (LocaleCompare(map,"RGB") == 0) |
| 2920 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2921 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2922 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2923 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2924 | if (q == (Quantum *) NULL) |
| 2925 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2926 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2927 | { |
| 2928 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 2929 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 2930 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 2931 | q+=GetPixelChannels(image); |
| 2932 | } |
| 2933 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2934 | break; |
| 2935 | } |
| 2936 | return; |
| 2937 | } |
| 2938 | if (LocaleCompare(map,"RGBA") == 0) |
| 2939 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2940 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2941 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2942 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2943 | if (q == (Quantum *) NULL) |
| 2944 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2945 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2946 | { |
| 2947 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 2948 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 2949 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 2950 | SetPixelAlpha(image,ScaleLongToQuantum(*p++),q); |
| 2951 | q+=GetPixelChannels(image); |
| 2952 | } |
| 2953 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2954 | break; |
| 2955 | } |
| 2956 | return; |
| 2957 | } |
| 2958 | if (LocaleCompare(map,"RGBP") == 0) |
| 2959 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2960 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2961 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2962 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2963 | if (q == (Quantum *) NULL) |
| 2964 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2965 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2966 | { |
| 2967 | SetPixelRed(image,ScaleLongToQuantum(*p++),q); |
| 2968 | SetPixelGreen(image,ScaleLongToQuantum(*p++),q); |
| 2969 | SetPixelBlue(image,ScaleLongToQuantum(*p++),q); |
| 2970 | p++; |
| 2971 | q+=GetPixelChannels(image); |
| 2972 | } |
| 2973 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 2974 | break; |
| 2975 | } |
| 2976 | return; |
| 2977 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2978 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2979 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2980 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2981 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2982 | if (q == (Quantum *) NULL) |
| 2983 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 2984 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2985 | { |
| 2986 | register ssize_t |
| 2987 | i; |
| 2988 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 2989 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 2990 | { |
| 2991 | switch (quantum_map[i]) |
| 2992 | { |
| 2993 | case RedQuantum: |
| 2994 | case CyanQuantum: |
| 2995 | { |
| 2996 | SetPixelRed(image,ScaleLongToQuantum(*p),q); |
| 2997 | break; |
| 2998 | } |
| 2999 | case GreenQuantum: |
| 3000 | case MagentaQuantum: |
| 3001 | { |
| 3002 | SetPixelGreen(image,ScaleLongToQuantum(*p),q); |
| 3003 | break; |
| 3004 | } |
| 3005 | case BlueQuantum: |
| 3006 | case YellowQuantum: |
| 3007 | { |
| 3008 | SetPixelBlue(image,ScaleLongToQuantum(*p),q); |
| 3009 | break; |
| 3010 | } |
| 3011 | case AlphaQuantum: |
| 3012 | { |
| 3013 | SetPixelAlpha(image,ScaleLongToQuantum(*p),q); |
| 3014 | break; |
| 3015 | } |
| 3016 | case OpacityQuantum: |
| 3017 | { |
| 3018 | SetPixelAlpha(image,ScaleLongToQuantum(*p),q); |
| 3019 | break; |
| 3020 | } |
| 3021 | case BlackQuantum: |
| 3022 | { |
| 3023 | SetPixelBlack(image,ScaleLongToQuantum(*p),q); |
| 3024 | break; |
| 3025 | } |
| 3026 | case IndexQuantum: |
| 3027 | { |
| 3028 | SetPixelGray(image,ScaleLongToQuantum(*p),q); |
| 3029 | break; |
| 3030 | } |
| 3031 | default: |
| 3032 | break; |
| 3033 | } |
| 3034 | p++; |
| 3035 | } |
| 3036 | q+=GetPixelChannels(image); |
| 3037 | } |
| 3038 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3039 | break; |
| 3040 | } |
| 3041 | } |
| 3042 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3043 | static void ImportLongLongPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 3044 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 3045 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3046 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3047 | register const MagickSizeType |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3048 | *restrict p; |
| 3049 | |
| 3050 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 3051 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3052 | |
| 3053 | register ssize_t |
| 3054 | x; |
| 3055 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3056 | size_t |
| 3057 | length; |
| 3058 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3059 | ssize_t |
| 3060 | y; |
| 3061 | |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3062 | p=(const MagickSizeType *) pixels; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3063 | if (LocaleCompare(map,"BGR") == 0) |
| 3064 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3065 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3066 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3067 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3068 | if (q == (Quantum *) NULL) |
| 3069 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3070 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3071 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3072 | SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q); |
| 3073 | SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q); |
| 3074 | SetPixelRed(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3075 | q+=GetPixelChannels(image); |
| 3076 | } |
| 3077 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3078 | break; |
| 3079 | } |
| 3080 | return; |
| 3081 | } |
| 3082 | if (LocaleCompare(map,"BGRA") == 0) |
| 3083 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3084 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3085 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3086 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3087 | if (q == (Quantum *) NULL) |
| 3088 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3089 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3090 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3091 | SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q); |
| 3092 | SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q); |
| 3093 | SetPixelRed(image,ScaleLongLongToQuantum(*p++),q); |
| 3094 | SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3095 | q+=GetPixelChannels(image); |
| 3096 | } |
| 3097 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3098 | break; |
| 3099 | } |
| 3100 | return; |
| 3101 | } |
| 3102 | if (LocaleCompare(map,"BGRP") == 0) |
| 3103 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3104 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3105 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3106 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3107 | if (q == (Quantum *) NULL) |
| 3108 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3109 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3110 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3111 | SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q); |
| 3112 | SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q); |
| 3113 | SetPixelRed(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3114 | p++; |
| 3115 | q+=GetPixelChannels(image); |
| 3116 | } |
| 3117 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3118 | break; |
| 3119 | } |
| 3120 | return; |
| 3121 | } |
| 3122 | if (LocaleCompare(map,"I") == 0) |
| 3123 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3124 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3125 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3126 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3127 | if (q == (Quantum *) NULL) |
| 3128 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3129 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3130 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3131 | SetPixelGray(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3132 | q+=GetPixelChannels(image); |
| 3133 | } |
| 3134 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3135 | break; |
| 3136 | } |
| 3137 | return; |
| 3138 | } |
| 3139 | if (LocaleCompare(map,"RGB") == 0) |
| 3140 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3141 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3142 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3143 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3144 | if (q == (Quantum *) NULL) |
| 3145 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3146 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3147 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3148 | SetPixelRed(image,ScaleLongLongToQuantum(*p++),q); |
| 3149 | SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q); |
| 3150 | SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3151 | q+=GetPixelChannels(image); |
| 3152 | } |
| 3153 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3154 | break; |
| 3155 | } |
| 3156 | return; |
| 3157 | } |
| 3158 | if (LocaleCompare(map,"RGBA") == 0) |
| 3159 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3160 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3161 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3162 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3163 | if (q == (Quantum *) NULL) |
| 3164 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3165 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3166 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3167 | SetPixelRed(image,ScaleLongLongToQuantum(*p++),q); |
| 3168 | SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q); |
| 3169 | SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q); |
| 3170 | SetPixelAlpha(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3171 | q+=GetPixelChannels(image); |
| 3172 | } |
| 3173 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3174 | break; |
| 3175 | } |
| 3176 | return; |
| 3177 | } |
| 3178 | if (LocaleCompare(map,"RGBP") == 0) |
| 3179 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3180 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3181 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3182 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3183 | if (q == (Quantum *) NULL) |
| 3184 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3185 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3186 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3187 | SetPixelRed(image,ScaleLongLongToQuantum(*p++),q); |
| 3188 | SetPixelGreen(image,ScaleLongLongToQuantum(*p++),q); |
| 3189 | SetPixelBlue(image,ScaleLongLongToQuantum(*p++),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3190 | p++; |
| 3191 | q+=GetPixelChannels(image); |
| 3192 | } |
| 3193 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3194 | break; |
| 3195 | } |
| 3196 | return; |
| 3197 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3198 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3199 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3200 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3201 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3202 | if (q == (Quantum *) NULL) |
| 3203 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3204 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3205 | { |
| 3206 | register ssize_t |
| 3207 | i; |
| 3208 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3209 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3210 | { |
| 3211 | switch (quantum_map[i]) |
| 3212 | { |
| 3213 | case RedQuantum: |
| 3214 | case CyanQuantum: |
| 3215 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3216 | SetPixelRed(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3217 | break; |
| 3218 | } |
| 3219 | case GreenQuantum: |
| 3220 | case MagentaQuantum: |
| 3221 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3222 | SetPixelGreen(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3223 | break; |
| 3224 | } |
| 3225 | case BlueQuantum: |
| 3226 | case YellowQuantum: |
| 3227 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3228 | SetPixelBlue(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3229 | break; |
| 3230 | } |
| 3231 | case AlphaQuantum: |
| 3232 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3233 | SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3234 | break; |
| 3235 | } |
| 3236 | case OpacityQuantum: |
| 3237 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3238 | SetPixelAlpha(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3239 | break; |
| 3240 | } |
| 3241 | case BlackQuantum: |
| 3242 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3243 | SetPixelBlack(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3244 | break; |
| 3245 | } |
| 3246 | case IndexQuantum: |
| 3247 | { |
cristy | b13e12a | 2012-01-06 21:48:27 +0000 | [diff] [blame] | 3248 | SetPixelGray(image,ScaleLongLongToQuantum(*p),q); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3249 | break; |
| 3250 | } |
| 3251 | default: |
| 3252 | break; |
| 3253 | } |
| 3254 | p++; |
| 3255 | } |
| 3256 | q+=GetPixelChannels(image); |
| 3257 | } |
| 3258 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3259 | break; |
| 3260 | } |
| 3261 | } |
| 3262 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3263 | static void ImportQuantumPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 3264 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 3265 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3266 | { |
| 3267 | register const Quantum |
| 3268 | *restrict p; |
| 3269 | |
| 3270 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 3271 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3272 | |
| 3273 | register ssize_t |
| 3274 | x; |
| 3275 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3276 | size_t |
| 3277 | length; |
| 3278 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 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 | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3418 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3419 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3420 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3421 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3422 | if (q == (Quantum *) NULL) |
| 3423 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3424 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3425 | { |
| 3426 | register ssize_t |
| 3427 | i; |
| 3428 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3429 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3430 | { |
| 3431 | switch (quantum_map[i]) |
| 3432 | { |
| 3433 | case RedQuantum: |
| 3434 | case CyanQuantum: |
| 3435 | { |
| 3436 | SetPixelRed(image,*p,q); |
| 3437 | break; |
| 3438 | } |
| 3439 | case GreenQuantum: |
| 3440 | case MagentaQuantum: |
| 3441 | { |
| 3442 | SetPixelGreen(image,*p,q); |
| 3443 | break; |
| 3444 | } |
| 3445 | case BlueQuantum: |
| 3446 | case YellowQuantum: |
| 3447 | { |
| 3448 | SetPixelBlue(image,*p,q); |
| 3449 | break; |
| 3450 | } |
| 3451 | case AlphaQuantum: |
| 3452 | { |
| 3453 | SetPixelAlpha(image,*p,q); |
| 3454 | break; |
| 3455 | } |
| 3456 | case OpacityQuantum: |
| 3457 | { |
| 3458 | SetPixelAlpha(image,*p,q); |
| 3459 | break; |
| 3460 | } |
| 3461 | case BlackQuantum: |
| 3462 | { |
| 3463 | SetPixelBlack(image,*p,q); |
| 3464 | break; |
| 3465 | } |
| 3466 | case IndexQuantum: |
| 3467 | { |
| 3468 | SetPixelGray(image,*p,q); |
| 3469 | break; |
| 3470 | } |
| 3471 | default: |
| 3472 | break; |
| 3473 | } |
| 3474 | p++; |
| 3475 | } |
| 3476 | q+=GetPixelChannels(image); |
| 3477 | } |
| 3478 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3479 | break; |
| 3480 | } |
| 3481 | } |
| 3482 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3483 | static void ImportShortPixel(Image *image,const RectangleInfo *roi, |
cristy | 46f4be2 | 2012-01-07 00:26:39 +0000 | [diff] [blame] | 3484 | const char *restrict map,const QuantumType *quantum_map,const void *pixels, |
| 3485 | ExceptionInfo *exception) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3486 | { |
| 3487 | register const unsigned short |
| 3488 | *restrict p; |
| 3489 | |
| 3490 | register Quantum |
cristy | 3fe1145 | 2012-01-09 01:27:42 +0000 | [diff] [blame] | 3491 | *restrict q; |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3492 | |
| 3493 | register ssize_t |
| 3494 | x; |
| 3495 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3496 | size_t |
| 3497 | length; |
| 3498 | |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3499 | ssize_t |
| 3500 | y; |
| 3501 | |
| 3502 | p=(const unsigned short *) pixels; |
| 3503 | if (LocaleCompare(map,"BGR") == 0) |
| 3504 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3505 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3506 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3507 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3508 | if (q == (Quantum *) NULL) |
| 3509 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3510 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3511 | { |
| 3512 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3513 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3514 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3515 | q+=GetPixelChannels(image); |
| 3516 | } |
| 3517 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3518 | break; |
| 3519 | } |
| 3520 | return; |
| 3521 | } |
| 3522 | if (LocaleCompare(map,"BGRA") == 0) |
| 3523 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3524 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3525 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3526 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3527 | if (q == (Quantum *) NULL) |
| 3528 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3529 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3530 | { |
| 3531 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3532 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3533 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3534 | SetPixelAlpha(image,ScaleShortToQuantum(*p++),q); |
| 3535 | q+=GetPixelChannels(image); |
| 3536 | } |
| 3537 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3538 | break; |
| 3539 | } |
| 3540 | return; |
| 3541 | } |
| 3542 | if (LocaleCompare(map,"BGRP") == 0) |
| 3543 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3544 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3545 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3546 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3547 | if (q == (Quantum *) NULL) |
| 3548 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3549 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3550 | { |
| 3551 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3552 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3553 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3554 | p++; |
| 3555 | q+=GetPixelChannels(image); |
| 3556 | } |
| 3557 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3558 | break; |
| 3559 | } |
| 3560 | return; |
| 3561 | } |
| 3562 | if (LocaleCompare(map,"I") == 0) |
| 3563 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3564 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3565 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3566 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3567 | if (q == (Quantum *) NULL) |
| 3568 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3569 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3570 | { |
| 3571 | SetPixelGray(image,ScaleShortToQuantum(*p++),q); |
| 3572 | q+=GetPixelChannels(image); |
| 3573 | } |
| 3574 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3575 | break; |
| 3576 | } |
| 3577 | return; |
| 3578 | } |
| 3579 | if (LocaleCompare(map,"RGB") == 0) |
| 3580 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3581 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3582 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3583 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3584 | if (q == (Quantum *) NULL) |
| 3585 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3586 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3587 | { |
| 3588 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3589 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3590 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3591 | q+=GetPixelChannels(image); |
| 3592 | } |
| 3593 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3594 | break; |
| 3595 | } |
| 3596 | return; |
| 3597 | } |
| 3598 | if (LocaleCompare(map,"RGBA") == 0) |
| 3599 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3600 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3601 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3602 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3603 | if (q == (Quantum *) NULL) |
| 3604 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3605 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3606 | { |
| 3607 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3608 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3609 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3610 | SetPixelAlpha(image,ScaleShortToQuantum(*p++),q); |
| 3611 | q+=GetPixelChannels(image); |
| 3612 | } |
| 3613 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3614 | break; |
| 3615 | } |
| 3616 | return; |
| 3617 | } |
| 3618 | if (LocaleCompare(map,"RGBP") == 0) |
| 3619 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3620 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3621 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3622 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3623 | if (q == (Quantum *) NULL) |
| 3624 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3625 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3626 | { |
| 3627 | SetPixelRed(image,ScaleShortToQuantum(*p++),q); |
| 3628 | SetPixelGreen(image,ScaleShortToQuantum(*p++),q); |
| 3629 | SetPixelBlue(image,ScaleShortToQuantum(*p++),q); |
| 3630 | p++; |
| 3631 | q+=GetPixelChannels(image); |
| 3632 | } |
| 3633 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3634 | break; |
| 3635 | } |
| 3636 | return; |
| 3637 | } |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3638 | length=strlen(map); |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3639 | for (y=0; y < (ssize_t) roi->height; y++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3640 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3641 | q=GetAuthenticPixels(image,roi->x,roi->y+y,roi->width,1,exception); |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3642 | if (q == (Quantum *) NULL) |
| 3643 | break; |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3644 | for (x=0; x < (ssize_t) roi->width; x++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3645 | { |
| 3646 | register ssize_t |
| 3647 | i; |
| 3648 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3649 | for (i=0; i < (ssize_t) length; i++) |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3650 | { |
| 3651 | switch (quantum_map[i]) |
| 3652 | { |
| 3653 | case RedQuantum: |
| 3654 | case CyanQuantum: |
| 3655 | { |
| 3656 | SetPixelRed(image,ScaleShortToQuantum(*p),q); |
| 3657 | break; |
| 3658 | } |
| 3659 | case GreenQuantum: |
| 3660 | case MagentaQuantum: |
| 3661 | { |
| 3662 | SetPixelGreen(image,ScaleShortToQuantum(*p),q); |
| 3663 | break; |
| 3664 | } |
| 3665 | case BlueQuantum: |
| 3666 | case YellowQuantum: |
| 3667 | { |
| 3668 | SetPixelBlue(image,ScaleShortToQuantum(*p),q); |
| 3669 | break; |
| 3670 | } |
| 3671 | case AlphaQuantum: |
| 3672 | { |
| 3673 | SetPixelAlpha(image,ScaleShortToQuantum(*p),q); |
| 3674 | break; |
| 3675 | } |
| 3676 | case OpacityQuantum: |
| 3677 | { |
| 3678 | SetPixelAlpha(image,ScaleShortToQuantum(*p),q); |
| 3679 | break; |
| 3680 | } |
| 3681 | case BlackQuantum: |
| 3682 | { |
| 3683 | SetPixelBlack(image,ScaleShortToQuantum(*p),q); |
| 3684 | break; |
| 3685 | } |
| 3686 | case IndexQuantum: |
| 3687 | { |
| 3688 | SetPixelGray(image,ScaleShortToQuantum(*p),q); |
| 3689 | break; |
| 3690 | } |
| 3691 | default: |
| 3692 | break; |
| 3693 | } |
| 3694 | p++; |
| 3695 | } |
| 3696 | q+=GetPixelChannels(image); |
| 3697 | } |
| 3698 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 3699 | break; |
| 3700 | } |
| 3701 | } |
| 3702 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3703 | MagickExport MagickBooleanType ImportImagePixels(Image *image,const ssize_t x, |
| 3704 | const ssize_t y,const size_t width,const size_t height,const char *map, |
| 3705 | const StorageType type,const void *pixels,ExceptionInfo *exception) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3706 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3707 | QuantumType |
| 3708 | *quantum_map; |
| 3709 | |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3710 | RectangleInfo |
| 3711 | roi; |
| 3712 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3713 | register ssize_t |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3714 | i; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3715 | |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3716 | size_t |
| 3717 | length; |
| 3718 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3719 | /* |
| 3720 | Allocate image structure. |
| 3721 | */ |
| 3722 | assert(image != (Image *) NULL); |
| 3723 | assert(image->signature == MagickSignature); |
| 3724 | if (image->debug != MagickFalse) |
| 3725 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3726 | length=strlen(map); |
| 3727 | quantum_map=(QuantumType *) AcquireQuantumMemory(length,sizeof(*quantum_map)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3728 | if (quantum_map == (QuantumType *) NULL) |
| 3729 | ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", |
| 3730 | image->filename); |
cristy | 14d7129 | 2012-05-20 16:48:13 +0000 | [diff] [blame] | 3731 | for (i=0; i < (ssize_t) length; i++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3732 | { |
| 3733 | switch (map[i]) |
| 3734 | { |
| 3735 | case 'a': |
| 3736 | case 'A': |
| 3737 | { |
| 3738 | quantum_map[i]=AlphaQuantum; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 3739 | image->alpha_trait=BlendPixelTrait; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3740 | break; |
| 3741 | } |
| 3742 | case 'B': |
| 3743 | case 'b': |
| 3744 | { |
| 3745 | quantum_map[i]=BlueQuantum; |
| 3746 | break; |
| 3747 | } |
| 3748 | case 'C': |
| 3749 | case 'c': |
| 3750 | { |
| 3751 | quantum_map[i]=CyanQuantum; |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 3752 | (void) SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3753 | break; |
| 3754 | } |
| 3755 | case 'g': |
| 3756 | case 'G': |
| 3757 | { |
| 3758 | quantum_map[i]=GreenQuantum; |
| 3759 | break; |
| 3760 | } |
| 3761 | case 'K': |
| 3762 | case 'k': |
| 3763 | { |
| 3764 | quantum_map[i]=BlackQuantum; |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 3765 | (void) SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3766 | break; |
| 3767 | } |
| 3768 | case 'I': |
| 3769 | case 'i': |
| 3770 | { |
| 3771 | quantum_map[i]=IndexQuantum; |
cristy | b7b3da6 | 2012-07-05 15:43:37 +0000 | [diff] [blame] | 3772 | (void) SetImageColorspace(image,GRAYColorspace,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3773 | break; |
| 3774 | } |
| 3775 | case 'm': |
| 3776 | case 'M': |
| 3777 | { |
| 3778 | quantum_map[i]=MagentaQuantum; |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 3779 | (void) SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3780 | break; |
| 3781 | } |
| 3782 | case 'O': |
| 3783 | case 'o': |
| 3784 | { |
| 3785 | quantum_map[i]=OpacityQuantum; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 3786 | image->alpha_trait=BlendPixelTrait; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3787 | break; |
| 3788 | } |
| 3789 | case 'P': |
| 3790 | case 'p': |
| 3791 | { |
| 3792 | quantum_map[i]=UndefinedQuantum; |
| 3793 | break; |
| 3794 | } |
| 3795 | case 'R': |
| 3796 | case 'r': |
| 3797 | { |
| 3798 | quantum_map[i]=RedQuantum; |
| 3799 | break; |
| 3800 | } |
| 3801 | case 'Y': |
| 3802 | case 'y': |
| 3803 | { |
| 3804 | quantum_map[i]=YellowQuantum; |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 3805 | (void) SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3806 | break; |
| 3807 | } |
| 3808 | default: |
| 3809 | { |
| 3810 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 3811 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 3812 | "UnrecognizedPixelMap","'%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3813 | return(MagickFalse); |
| 3814 | } |
| 3815 | } |
| 3816 | } |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 3817 | if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3818 | return(MagickFalse); |
| 3819 | /* |
cristy | e537094 | 2012-01-06 03:49:31 +0000 | [diff] [blame] | 3820 | Transfer the pixels from the pixel data to the image. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3821 | */ |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3822 | roi.width=width; |
| 3823 | roi.height=height; |
| 3824 | roi.x=x; |
| 3825 | roi.y=y; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3826 | switch (type) |
| 3827 | { |
| 3828 | case CharPixel: |
| 3829 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3830 | ImportCharPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3831 | break; |
| 3832 | } |
| 3833 | case DoublePixel: |
| 3834 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3835 | ImportDoublePixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3836 | break; |
| 3837 | } |
| 3838 | case FloatPixel: |
| 3839 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3840 | ImportFloatPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3841 | break; |
| 3842 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3843 | case LongPixel: |
| 3844 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3845 | ImportLongPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3846 | break; |
| 3847 | } |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 3848 | case LongLongPixel: |
| 3849 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3850 | ImportLongLongPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 6c9e168 | 2012-01-07 21:37:44 +0000 | [diff] [blame] | 3851 | break; |
| 3852 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3853 | case QuantumPixel: |
| 3854 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3855 | ImportQuantumPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3856 | break; |
| 3857 | } |
| 3858 | case ShortPixel: |
| 3859 | { |
cristy | cafe041 | 2012-01-10 13:29:58 +0000 | [diff] [blame] | 3860 | ImportShortPixel(image,&roi,map,quantum_map,pixels,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3861 | break; |
| 3862 | } |
| 3863 | default: |
| 3864 | { |
| 3865 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 3866 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 3867 | "UnrecognizedPixelMap","'%s'",map); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3868 | break; |
| 3869 | } |
| 3870 | } |
| 3871 | quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map); |
| 3872 | return(MagickTrue); |
| 3873 | } |
| 3874 | |
| 3875 | /* |
| 3876 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3877 | % % |
| 3878 | % % |
| 3879 | % % |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 3880 | + 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 % |
| 3881 | % % |
| 3882 | % % |
| 3883 | % % |
| 3884 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3885 | % |
| 3886 | % InitializePixelChannelMap() defines the standard pixel component map. |
| 3887 | % |
| 3888 | % The format of the InitializePixelChannelMap() method is: |
| 3889 | % |
| 3890 | % void InitializePixelChannelMap(Image *image) |
| 3891 | % |
| 3892 | % A description of each parameter follows: |
| 3893 | % |
| 3894 | % o image: the image. |
| 3895 | % |
| 3896 | */ |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3897 | MagickExport void InitializePixelChannelMap(Image *image) |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 3898 | { |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3899 | PixelTrait |
| 3900 | trait; |
| 3901 | |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 3902 | register ssize_t |
| 3903 | i; |
| 3904 | |
cristy | d26338f | 2011-12-14 02:39:30 +0000 | [diff] [blame] | 3905 | ssize_t |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 3906 | n; |
| 3907 | |
| 3908 | assert(image != (Image *) NULL); |
| 3909 | assert(image->signature == MagickSignature); |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3910 | (void) ResetMagickMemory(image->channel_map,0,MaxPixelChannels* |
| 3911 | sizeof(*image->channel_map)); |
| 3912 | trait=UpdatePixelTrait; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 3913 | if (image->alpha_trait == BlendPixelTrait) |
cristy | 61f18ad | 2011-12-08 21:12:37 +0000 | [diff] [blame] | 3914 | trait=(PixelTrait) (trait | BlendPixelTrait); |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 3915 | n=0; |
cristy | c06c580 | 2011-12-31 23:36:16 +0000 | [diff] [blame] | 3916 | if (image->colorspace == GRAYColorspace) |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 3917 | { |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 3918 | SetPixelChannelAttributes(image,BluePixelChannel,trait,n); |
| 3919 | SetPixelChannelAttributes(image,GreenPixelChannel,trait,n); |
| 3920 | SetPixelChannelAttributes(image,RedPixelChannel,trait,n++); |
cristy | 3c31628 | 2011-12-15 15:43:24 +0000 | [diff] [blame] | 3921 | } |
| 3922 | else |
| 3923 | { |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 3924 | SetPixelChannelAttributes(image,RedPixelChannel,trait,n++); |
| 3925 | SetPixelChannelAttributes(image,GreenPixelChannel,trait,n++); |
| 3926 | SetPixelChannelAttributes(image,BluePixelChannel,trait,n++); |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 3927 | } |
| 3928 | if (image->colorspace == CMYKColorspace) |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 3929 | SetPixelChannelAttributes(image,BlackPixelChannel,trait,n++); |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 3930 | if (image->alpha_trait != UndefinedPixelTrait) |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 3931 | SetPixelChannelAttributes(image,AlphaPixelChannel,CopyPixelTrait,n++); |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3932 | if (image->storage_class == PseudoClass) |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 3933 | SetPixelChannelAttributes(image,IndexPixelChannel,CopyPixelTrait,n++); |
cristy | 183a5c7 | 2012-01-30 01:40:35 +0000 | [diff] [blame] | 3934 | if (image->mask != MagickFalse) |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 3935 | SetPixelChannelAttributes(image,MaskPixelChannel,CopyPixelTrait,n++); |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3936 | assert((n+image->number_meta_channels) < MaxPixelChannels); |
| 3937 | for (i=0; i < (ssize_t) image->number_meta_channels; i++) |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 3938 | SetPixelChannelAttributes(image,(PixelChannel) (MetaPixelChannel+i), |
| 3939 | CopyPixelTrait,n++); |
cristy | d26338f | 2011-12-14 02:39:30 +0000 | [diff] [blame] | 3940 | image->number_channels=(size_t) n; |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 3941 | if (image->debug != MagickFalse) |
| 3942 | LogPixelChannels(image); |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 3943 | (void) SetImageChannelMask(image,image->channel_mask); |
cristy | 77c30f5 | 2011-10-24 18:56:57 +0000 | [diff] [blame] | 3944 | } |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 3945 | |
| 3946 | /* |
| 3947 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3948 | % % |
| 3949 | % % |
| 3950 | % % |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 3951 | % I n t e r p o l a t e P i x e l C h a n n e l % |
| 3952 | % % |
| 3953 | % % |
| 3954 | % % |
| 3955 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3956 | % |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 3957 | % InterpolatePixelChannel() applies a pixel interpolation method between a |
| 3958 | % floating point coordinate and the pixels surrounding that coordinate. No |
| 3959 | % pixel area resampling, or scaling of the result is performed. |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 3960 | % |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 3961 | % Interpolation is restricted to just the specified channel. |
| 3962 | % |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 3963 | % The format of the InterpolatePixelChannel method is: |
| 3964 | % |
| 3965 | % MagickBooleanType InterpolatePixelChannel(const Image *image, |
cristy | 444eda6 | 2011-08-10 02:07:46 +0000 | [diff] [blame] | 3966 | % const CacheView *image_view,const PixelChannel channel, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 3967 | % const PixelInterpolateMethod method,const double x,const double y, |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 3968 | % double *pixel,ExceptionInfo *exception) |
| 3969 | % |
| 3970 | % A description of each parameter follows: |
| 3971 | % |
| 3972 | % o image: the image. |
| 3973 | % |
| 3974 | % o image_view: the image view. |
| 3975 | % |
| 3976 | % o channel: the pixel channel to interpolate. |
| 3977 | % |
| 3978 | % o method: the pixel color interpolation method. |
| 3979 | % |
| 3980 | % o x,y: A double representing the current (x,y) position of the pixel. |
| 3981 | % |
| 3982 | % o pixel: return the interpolated pixel here. |
| 3983 | % |
| 3984 | % o exception: return any errors or warnings in this structure. |
| 3985 | % |
| 3986 | */ |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 3987 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3988 | static inline double MagickMax(const double x,const double y) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 3989 | { |
| 3990 | if (x > y) |
| 3991 | return(x); |
| 3992 | return(y); |
| 3993 | } |
| 3994 | |
cristy | b0a657e | 2012-08-29 00:45:37 +0000 | [diff] [blame] | 3995 | static inline void CatromWeights(const double x,double (*weights)[4]) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 3996 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3997 | double |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 3998 | alpha, |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 3999 | beta, |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4000 | gamma; |
| 4001 | |
cristy | 5a5e4d9 | 2012-08-29 00:06:25 +0000 | [diff] [blame] | 4002 | /* |
| 4003 | Nicolas Robidoux' 10 flops (4* + 5- + 1+) refactoring of the computation |
| 4004 | of the standard four 1D Catmull-Rom weights. The sampling location is |
| 4005 | assumed between the second and third input pixel locations, and x is the |
| 4006 | position relative to the second input pixel location. Formulas originally |
| 4007 | derived for the VIPS (Virtual Image Processing System) library. |
| 4008 | */ |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4009 | alpha=(double) 1.0-x; |
| 4010 | beta=(double) (-0.5)*x*alpha; |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4011 | (*weights)[0]=alpha*beta; |
| 4012 | (*weights)[3]=x*beta; |
| 4013 | /* |
cristy | 5a5e4d9 | 2012-08-29 00:06:25 +0000 | [diff] [blame] | 4014 | The following computation of the inner weights from the outer ones work |
| 4015 | for all Keys cubics. |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4016 | */ |
| 4017 | gamma=(*weights)[3]-(*weights)[0]; |
| 4018 | (*weights)[1]=alpha-(*weights)[0]+gamma; |
| 4019 | (*weights)[2]=x-(*weights)[3]-gamma; |
| 4020 | } |
| 4021 | |
cristy | b0a657e | 2012-08-29 00:45:37 +0000 | [diff] [blame] | 4022 | static inline void SplineWeights(const double x,double (*weights)[4]) |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4023 | { |
cristy | 5a5e4d9 | 2012-08-29 00:06:25 +0000 | [diff] [blame] | 4024 | double |
| 4025 | alpha, |
| 4026 | beta; |
| 4027 | |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4028 | /* |
| 4029 | Nicolas Robidoux' 12 flops (6* + 5- + 1+) refactoring of the |
| 4030 | computation of the standard four 1D cubic B-spline smoothing |
| 4031 | weights. The sampling location is assumed between the second and |
| 4032 | third input pixel locations, and x is the position relative to the |
| 4033 | second input pixel location. |
| 4034 | */ |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4035 | alpha=(double) 1.0-x; |
| 4036 | (*weights)[3]=(double) (1.0/6.0)*x*x*x; |
| 4037 | (*weights)[0]=(double) (1.0/6.0)*alpha*alpha*alpha; |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4038 | beta=(*weights)[3]-(*weights)[0]; |
| 4039 | (*weights)[1]=alpha-(*weights)[0]+beta; |
| 4040 | (*weights)[2]=x-(*weights)[3]-beta; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4041 | } |
| 4042 | |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4043 | static inline double MeshInterpolate(const PointInfo *delta,const double p, |
| 4044 | const double x,const double y) |
| 4045 | { |
| 4046 | return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p); |
| 4047 | } |
| 4048 | |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4049 | /* |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4050 | static inline ssize_t NearestNeighbor(const double x) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4051 | { |
| 4052 | if (x >= 0.0) |
| 4053 | return((ssize_t) (x+0.5)); |
| 4054 | return((ssize_t) (x-0.5)); |
| 4055 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4056 | */ |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4057 | |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4058 | MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image, |
| 4059 | const CacheView *image_view,const PixelChannel channel, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4060 | const PixelInterpolateMethod method,const double x,const double y, |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4061 | double *pixel,ExceptionInfo *exception) |
| 4062 | { |
| 4063 | MagickBooleanType |
| 4064 | status; |
| 4065 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4066 | double |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4067 | alpha[16], |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4068 | gamma, |
| 4069 | pixels[16]; |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4070 | |
| 4071 | PixelTrait |
| 4072 | traits; |
| 4073 | |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4074 | register const Quantum |
| 4075 | *p; |
| 4076 | |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4077 | register ssize_t |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4078 | i; |
| 4079 | |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4080 | ssize_t |
| 4081 | x_offset, |
| 4082 | y_offset; |
| 4083 | |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4084 | PixelInterpolateMethod |
| 4085 | interpolate; |
| 4086 | |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4087 | assert(image != (Image *) NULL); |
| 4088 | assert(image != (Image *) NULL); |
| 4089 | assert(image->signature == MagickSignature); |
| 4090 | assert(image_view != (CacheView *) NULL); |
| 4091 | status=MagickTrue; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4092 | *pixel=0.0; |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4093 | traits=GetPixelChannelTraits(image,channel); |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4094 | x_offset=(ssize_t) floor(x); |
| 4095 | y_offset=(ssize_t) floor(y); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4096 | interpolate = method; |
| 4097 | if ( interpolate == UndefinedInterpolatePixel ) |
| 4098 | interpolate = image->interpolate; |
| 4099 | switch (interpolate) |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4100 | { |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4101 | case AverageInterpolatePixel: /* nearest 4 neighbours */ |
| 4102 | case Average9InterpolatePixel: /* nearest 9 neighbours */ |
| 4103 | case Average16InterpolatePixel: /* nearest 16 neighbours */ |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4104 | { |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4105 | ssize_t |
| 4106 | count; |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4107 | |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4108 | count=2; /* size of the area to average - default nearest 4 */ |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4109 | if (interpolate == Average9InterpolatePixel) |
| 4110 | { |
| 4111 | count=3; |
| 4112 | x_offset=(ssize_t) (floor(x+0.5)-1); |
| 4113 | y_offset=(ssize_t) (floor(y+0.5)-1); |
| 4114 | } |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4115 | else |
| 4116 | if (interpolate == Average16InterpolatePixel) |
| 4117 | { |
| 4118 | count=4; |
| 4119 | x_offset--; |
| 4120 | y_offset--; |
| 4121 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4122 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,count,count, |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4123 | exception); |
| 4124 | if (p == (const Quantum *) NULL) |
| 4125 | { |
| 4126 | status=MagickFalse; |
| 4127 | break; |
| 4128 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4129 | count*=count; /* Number of pixels to Average */ |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 4130 | if ((traits & BlendPixelTrait) == 0) |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4131 | for (i=0; i < (ssize_t) count; i++) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4132 | { |
| 4133 | alpha[i]=1.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4134 | pixels[i]=(double) p[i*GetPixelChannels(image)+channel]; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4135 | } |
| 4136 | else |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4137 | for (i=0; i < (ssize_t) count; i++) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4138 | { |
| 4139 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4140 | GetPixelChannels(image)); |
| 4141 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4142 | } |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4143 | for (i=0; i < (ssize_t) count; i++) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4144 | { |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4145 | gamma=PerceptibleReciprocal(alpha[i])/count; |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4146 | *pixel+=gamma*pixels[i]; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4147 | } |
| 4148 | break; |
| 4149 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4150 | case BilinearInterpolatePixel: |
| 4151 | default: |
| 4152 | { |
| 4153 | PointInfo |
| 4154 | delta, |
| 4155 | epsilon; |
| 4156 | |
| 4157 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
| 4158 | if (p == (const Quantum *) NULL) |
| 4159 | { |
| 4160 | status=MagickFalse; |
| 4161 | break; |
| 4162 | } |
| 4163 | if ((traits & BlendPixelTrait) == 0) |
| 4164 | for (i=0; i < 4; i++) |
| 4165 | { |
| 4166 | alpha[i]=1.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4167 | pixels[i]=(double) p[i*GetPixelChannels(image)+channel]; |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4168 | } |
| 4169 | else |
| 4170 | for (i=0; i < 4; i++) |
| 4171 | { |
| 4172 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4173 | GetPixelChannels(image)); |
| 4174 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4175 | } |
| 4176 | delta.x=x-x_offset; |
| 4177 | delta.y=y-y_offset; |
| 4178 | epsilon.x=1.0-delta.x; |
| 4179 | epsilon.y=1.0-delta.y; |
| 4180 | gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y* |
| 4181 | (epsilon.x*alpha[2]+delta.x*alpha[3]))); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4182 | gamma=PerceptibleReciprocal(gamma); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4183 | *pixel=gamma*(epsilon.y*(epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y* |
| 4184 | (epsilon.x*pixels[2]+delta.x*pixels[3])); |
| 4185 | break; |
| 4186 | } |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 4187 | case BlendInterpolatePixel: |
| 4188 | { |
| 4189 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
| 4190 | if (p == (const Quantum *) NULL) |
| 4191 | { |
| 4192 | status=MagickFalse; |
| 4193 | break; |
| 4194 | } |
| 4195 | if ((traits & BlendPixelTrait) == 0) |
| 4196 | for (i=0; i < 4; i++) |
| 4197 | { |
| 4198 | alpha[i]=1.0; |
| 4199 | pixels[i]=(MagickRealType) p[i*GetPixelChannels(image)+channel]; |
| 4200 | } |
| 4201 | else |
| 4202 | for (i=0; i < 4; i++) |
| 4203 | { |
| 4204 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4205 | GetPixelChannels(image)); |
| 4206 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4207 | } |
| 4208 | gamma=1.0; /* number of pixels blended together (its variable) */ |
| 4209 | for (i=0; i <= 1L; i++) { |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4210 | if ((y-y_offset) >= 0.75) |
| 4211 | { |
| 4212 | alpha[i]=alpha[i+2]; /* take right pixels */ |
| 4213 | pixels[i]=pixels[i+2]; |
| 4214 | } |
| 4215 | else |
| 4216 | if ((y-y_offset) > 0.25) |
| 4217 | { |
| 4218 | gamma=2.0; /* blend both pixels in row */ |
| 4219 | alpha[i]+=alpha[i+2]; /* add up alpha weights */ |
| 4220 | pixels[i]+=pixels[i+2]; |
| 4221 | } |
| 4222 | } |
| 4223 | if ((x-x_offset) >= 0.75) |
| 4224 | { |
| 4225 | alpha[0]=alpha[1]; /* take bottom row blend */ |
| 4226 | pixels[0]=pixels[1]; |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 4227 | } |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4228 | else |
| 4229 | if ((x-x_offset) > 0.25) |
| 4230 | { |
| 4231 | gamma*=2.0; /* blend both rows */ |
| 4232 | alpha[0]+=alpha[1]; /* add up alpha weights */ |
| 4233 | pixels[0]+=pixels[1]; |
| 4234 | } |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 4235 | if (channel != AlphaPixelChannel) |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4236 | gamma=PerceptibleReciprocal(alpha[0]); /* (color) 1/alpha_weights */ |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 4237 | else |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4238 | gamma=PerceptibleReciprocal(gamma); /* (alpha) 1/number_of_pixels */ |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 4239 | *pixel=gamma*pixels[0]; |
| 4240 | break; |
| 4241 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4242 | case CatromInterpolatePixel: |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4243 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4244 | double |
cristy | 380a11c | 2012-06-02 15:15:22 +0000 | [diff] [blame] | 4245 | cx[4], |
nicolas | 6676f5a | 2012-06-12 16:01:15 +0000 | [diff] [blame] | 4246 | cy[4]; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4247 | |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4248 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 4249 | exception); |
| 4250 | if (p == (const Quantum *) NULL) |
| 4251 | { |
| 4252 | status=MagickFalse; |
| 4253 | break; |
| 4254 | } |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 4255 | if ((traits & BlendPixelTrait) == 0) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4256 | for (i=0; i < 16; i++) |
| 4257 | { |
| 4258 | alpha[i]=1.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4259 | pixels[i]=(double) p[i*GetPixelChannels(image)+channel]; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4260 | } |
| 4261 | else |
| 4262 | for (i=0; i < 16; i++) |
| 4263 | { |
| 4264 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4265 | GetPixelChannels(image)); |
| 4266 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4267 | } |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4268 | CatromWeights((double) (x-x_offset),&cx); |
| 4269 | CatromWeights((double) (y-y_offset),&cy); |
| 4270 | gamma=(channel == AlphaPixelChannel ? (double) 1.0 : |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4271 | PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]* |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4272 | alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]* |
| 4273 | alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]* |
| 4274 | alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+ |
| 4275 | cx[2]*alpha[14]+cx[3]*alpha[15]))); |
cristy | 380a11c | 2012-06-02 15:15:22 +0000 | [diff] [blame] | 4276 | *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+ |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4277 | cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]* |
| 4278 | pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+ |
| 4279 | cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]* |
| 4280 | pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15])); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4281 | break; |
| 4282 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4283 | #if 0 |
nicolas | 20075dc | 2012-06-12 20:47:38 +0000 | [diff] [blame] | 4284 | /* deprecated useless and very slow interpolator */ |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4285 | case FilterInterpolatePixel: |
| 4286 | { |
| 4287 | CacheView |
| 4288 | *filter_view; |
| 4289 | |
| 4290 | Image |
| 4291 | *excerpt_image, |
| 4292 | *filter_image; |
| 4293 | |
| 4294 | RectangleInfo |
| 4295 | geometry; |
| 4296 | |
| 4297 | geometry.width=4L; |
| 4298 | geometry.height=4L; |
| 4299 | geometry.x=x_offset-1; |
| 4300 | geometry.y=y_offset-1; |
| 4301 | excerpt_image=ExcerptImage(image,&geometry,exception); |
| 4302 | if (excerpt_image == (Image *) NULL) |
| 4303 | { |
| 4304 | status=MagickFalse; |
| 4305 | break; |
| 4306 | } |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4307 | filter_image=ResizeImage(excerpt_image,1,1,image->filter,exception); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4308 | excerpt_image=DestroyImage(excerpt_image); |
| 4309 | if (filter_image == (Image *) NULL) |
| 4310 | break; |
cristy | 4bc5202 | 2012-12-13 14:15:41 +0000 | [diff] [blame] | 4311 | filter_view=AcquireVirtualCacheView(filter_image); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4312 | p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception); |
| 4313 | if (p == (const Quantum *) NULL) |
| 4314 | status=MagickFalse; |
| 4315 | else |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 4316 | *pixel=(double) GetPixelChannel(image,channel,p); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4317 | filter_view=DestroyCacheView(filter_view); |
| 4318 | filter_image=DestroyImage(filter_image); |
| 4319 | break; |
| 4320 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4321 | #endif |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4322 | case IntegerInterpolatePixel: |
| 4323 | { |
| 4324 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception); |
| 4325 | if (p == (const Quantum *) NULL) |
| 4326 | { |
| 4327 | status=MagickFalse; |
| 4328 | break; |
| 4329 | } |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 4330 | *pixel=(double) GetPixelChannel(image,channel,p); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4331 | break; |
| 4332 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4333 | case NearestInterpolatePixel: |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4334 | { |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4335 | x_offset=(ssize_t) floor(x+0.5); |
| 4336 | y_offset=(ssize_t) floor(y+0.5); |
| 4337 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4338 | if (p == (const Quantum *) NULL) |
| 4339 | { |
| 4340 | status=MagickFalse; |
| 4341 | break; |
| 4342 | } |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 4343 | *pixel=(double) GetPixelChannel(image,channel,p); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4344 | break; |
| 4345 | } |
| 4346 | case MeshInterpolatePixel: |
| 4347 | { |
| 4348 | PointInfo |
| 4349 | delta, |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4350 | luminance; |
| 4351 | |
| 4352 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
| 4353 | if (p == (const Quantum *) NULL) |
| 4354 | { |
| 4355 | status=MagickFalse; |
| 4356 | break; |
| 4357 | } |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 4358 | if ((traits & BlendPixelTrait) == 0) |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4359 | for (i=0; i < 4; i++) |
| 4360 | { |
| 4361 | alpha[i]=1.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4362 | pixels[i]=(double) p[i*GetPixelChannels(image)+channel]; |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4363 | } |
| 4364 | else |
| 4365 | for (i=0; i < 4; i++) |
| 4366 | { |
| 4367 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4368 | GetPixelChannels(image)); |
| 4369 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4370 | } |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4371 | delta.x=x-x_offset; |
| 4372 | delta.y=y-y_offset; |
| 4373 | luminance.x=GetPixelLuminance(image,p)-(double) |
| 4374 | GetPixelLuminance(image,p+3*GetPixelChannels(image)); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 4375 | luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4376 | GetPixelLuminance(image,p+2*GetPixelChannels(image)); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4377 | if (fabs(luminance.x) < fabs(luminance.y)) |
| 4378 | { |
| 4379 | /* |
| 4380 | Diagonal 0-3 NW-SE. |
| 4381 | */ |
| 4382 | if (delta.x <= delta.y) |
| 4383 | { |
| 4384 | /* |
| 4385 | Bottom-left triangle (pixel: 2, diagonal: 0-3). |
| 4386 | */ |
| 4387 | delta.y=1.0-delta.y; |
| 4388 | gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4389 | gamma=PerceptibleReciprocal(gamma); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4390 | *pixel=gamma*MeshInterpolate(&delta,pixels[2],pixels[3], |
| 4391 | pixels[0]); |
| 4392 | } |
| 4393 | else |
| 4394 | { |
| 4395 | /* |
| 4396 | Top-right triangle (pixel: 1, diagonal: 0-3). |
| 4397 | */ |
| 4398 | delta.x=1.0-delta.x; |
| 4399 | gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4400 | gamma=PerceptibleReciprocal(gamma); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4401 | *pixel=gamma*MeshInterpolate(&delta,pixels[1],pixels[0], |
| 4402 | pixels[3]); |
| 4403 | } |
| 4404 | } |
| 4405 | else |
| 4406 | { |
| 4407 | /* |
| 4408 | Diagonal 1-2 NE-SW. |
| 4409 | */ |
| 4410 | if (delta.x <= (1.0-delta.y)) |
| 4411 | { |
| 4412 | /* |
| 4413 | Top-left triangle (pixel: 0, diagonal: 1-2). |
| 4414 | */ |
| 4415 | gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4416 | gamma=PerceptibleReciprocal(gamma); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4417 | *pixel=gamma*MeshInterpolate(&delta,pixels[0],pixels[1], |
| 4418 | pixels[2]); |
| 4419 | } |
| 4420 | else |
| 4421 | { |
| 4422 | /* |
| 4423 | Bottom-right triangle (pixel: 3, diagonal: 1-2). |
| 4424 | */ |
| 4425 | delta.x=1.0-delta.x; |
| 4426 | delta.y=1.0-delta.y; |
| 4427 | gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4428 | gamma=PerceptibleReciprocal(gamma); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 4429 | *pixel=gamma*MeshInterpolate(&delta,pixels[3],pixels[2], |
| 4430 | pixels[1]); |
| 4431 | } |
| 4432 | } |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4433 | break; |
| 4434 | } |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4435 | case SplineInterpolatePixel: |
| 4436 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4437 | double |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4438 | cx[4], |
nicolas | 6676f5a | 2012-06-12 16:01:15 +0000 | [diff] [blame] | 4439 | cy[4]; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4440 | |
| 4441 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 4442 | exception); |
| 4443 | if (p == (const Quantum *) NULL) |
| 4444 | { |
| 4445 | status=MagickFalse; |
| 4446 | break; |
| 4447 | } |
cristy | 222b19c | 2011-08-04 01:35:11 +0000 | [diff] [blame] | 4448 | if ((traits & BlendPixelTrait) == 0) |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4449 | for (i=0; i < 16; i++) |
| 4450 | { |
| 4451 | alpha[i]=1.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4452 | pixels[i]=(double) p[i*GetPixelChannels(image)+channel]; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4453 | } |
| 4454 | else |
| 4455 | for (i=0; i < 16; i++) |
| 4456 | { |
| 4457 | alpha[i]=QuantumScale*GetPixelAlpha(image,p+i* |
| 4458 | GetPixelChannels(image)); |
| 4459 | pixels[i]=alpha[i]*p[i*GetPixelChannels(image)+channel]; |
| 4460 | } |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4461 | SplineWeights((double) (x-x_offset),&cx); |
| 4462 | SplineWeights((double) (y-y_offset),&cy); |
| 4463 | gamma=(channel == AlphaPixelChannel ? (double) 1.0 : |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4464 | PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]* |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4465 | alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]* |
| 4466 | alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]* |
| 4467 | alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+ |
| 4468 | cx[2]*alpha[14]+cx[3]*alpha[15]))); |
| 4469 | *pixel=gamma*(cy[0]*(cx[0]*pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+ |
| 4470 | cx[3]*pixels[3])+cy[1]*(cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]* |
| 4471 | pixels[6]+cx[3]*pixels[7])+cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+ |
| 4472 | cx[2]*pixels[10]+cx[3]*pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]* |
| 4473 | pixels[13]+cx[2]*pixels[14]+cx[3]*pixels[15])); |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 4474 | break; |
| 4475 | } |
cristy | a085a43 | 2011-07-30 01:39:32 +0000 | [diff] [blame] | 4476 | } |
| 4477 | return(status); |
| 4478 | } |
| 4479 | |
| 4480 | /* |
| 4481 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4482 | % % |
| 4483 | % % |
| 4484 | % % |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4485 | % I n t e r p o l a t e P i x e l C h a n n e l s % |
| 4486 | % % |
| 4487 | % % |
| 4488 | % % |
| 4489 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4490 | % |
| 4491 | % InterpolatePixelChannels() applies a pixel interpolation method between a |
| 4492 | % floating point coordinate and the pixels surrounding that coordinate. No |
| 4493 | % pixel area resampling, or scaling of the result is performed. |
| 4494 | % |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4495 | % Interpolation is restricted to just the current channel setting of the |
| 4496 | % destination image into which the color is to be stored |
| 4497 | % |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4498 | % The format of the InterpolatePixelChannels method is: |
| 4499 | % |
| 4500 | % MagickBooleanType InterpolatePixelChannels(const Image *source, |
| 4501 | % const CacheView *source_view,const Image *destination, |
| 4502 | % const PixelInterpolateMethod method,const double x,const double y, |
| 4503 | % Quantum *pixel,ExceptionInfo *exception) |
| 4504 | % |
| 4505 | % A description of each parameter follows: |
| 4506 | % |
| 4507 | % o source: the source. |
| 4508 | % |
| 4509 | % o source_view: the source view. |
| 4510 | % |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4511 | % o destination: the destination image, for the interpolated color |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4512 | % |
| 4513 | % o method: the pixel color interpolation method. |
| 4514 | % |
| 4515 | % o x,y: A double representing the current (x,y) position of the pixel. |
| 4516 | % |
| 4517 | % o pixel: return the interpolated pixel here. |
| 4518 | % |
| 4519 | % o exception: return any errors or warnings in this structure. |
| 4520 | % |
| 4521 | */ |
| 4522 | MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source, |
| 4523 | const CacheView *source_view,const Image *destination, |
| 4524 | const PixelInterpolateMethod method,const double x,const double y, |
| 4525 | Quantum *pixel,ExceptionInfo *exception) |
| 4526 | { |
| 4527 | MagickBooleanType |
| 4528 | status; |
| 4529 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4530 | double |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4531 | alpha[16], |
| 4532 | gamma, |
| 4533 | pixels[16]; |
| 4534 | |
| 4535 | PixelChannel |
| 4536 | channel; |
| 4537 | |
| 4538 | PixelTrait |
| 4539 | destination_traits, |
| 4540 | traits; |
| 4541 | |
| 4542 | register const Quantum |
| 4543 | *p; |
| 4544 | |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4545 | register ssize_t |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4546 | i; |
| 4547 | |
| 4548 | ssize_t |
| 4549 | x_offset, |
| 4550 | y_offset; |
| 4551 | |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4552 | PixelInterpolateMethod |
| 4553 | interpolate; |
| 4554 | |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4555 | assert(source != (Image *) NULL); |
| 4556 | assert(source != (Image *) NULL); |
| 4557 | assert(source->signature == MagickSignature); |
| 4558 | assert(source_view != (CacheView *) NULL); |
| 4559 | status=MagickTrue; |
| 4560 | x_offset=(ssize_t) floor(x); |
| 4561 | y_offset=(ssize_t) floor(y); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4562 | interpolate = method; |
| 4563 | if ( interpolate == UndefinedInterpolatePixel ) |
| 4564 | interpolate = source->interpolate; |
| 4565 | switch (interpolate) |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4566 | { |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4567 | case AverageInterpolatePixel: /* nearest 4 neighbours */ |
| 4568 | case Average9InterpolatePixel: /* nearest 9 neighbours */ |
| 4569 | case Average16InterpolatePixel: /* nearest 16 neighbours */ |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4570 | { |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4571 | ssize_t |
| 4572 | count; |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4573 | |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4574 | count=2; /* size of the area to average - default nearest 4 */ |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4575 | if (interpolate == Average9InterpolatePixel) |
| 4576 | { |
| 4577 | count=3; |
| 4578 | x_offset=(ssize_t) (floor(x+0.5)-1); |
| 4579 | y_offset=(ssize_t) (floor(y+0.5)-1); |
| 4580 | } |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4581 | else |
| 4582 | if (interpolate == Average16InterpolatePixel) |
| 4583 | { |
| 4584 | count=4; |
| 4585 | x_offset--; |
| 4586 | y_offset--; |
| 4587 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4588 | p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,count,count, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4589 | exception); |
| 4590 | if (p == (const Quantum *) NULL) |
| 4591 | { |
| 4592 | status=MagickFalse; |
| 4593 | break; |
| 4594 | } |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4595 | count*=count; /* Number of pixels to Average */ |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4596 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4597 | { |
| 4598 | double |
| 4599 | sum; |
| 4600 | |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4601 | register ssize_t |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4602 | j; |
| 4603 | |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4604 | channel=GetPixelChannelChannel(source,i); |
| 4605 | traits=GetPixelChannelTraits(source,channel); |
| 4606 | destination_traits=GetPixelChannelTraits(destination,channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4607 | if ((traits == UndefinedPixelTrait) || |
| 4608 | (destination_traits == UndefinedPixelTrait)) |
| 4609 | continue; |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4610 | for (j=0; j < (ssize_t) count; j++) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4611 | pixels[j]=(double) p[j*GetPixelChannels(source)+i]; |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4612 | sum=0.0; |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4613 | if ((traits & BlendPixelTrait) == 0) |
| 4614 | { |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4615 | for (j=0; j < (ssize_t) count; j++) |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4616 | sum+=pixels[j]; |
| 4617 | sum/=count; |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4618 | SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4619 | continue; |
| 4620 | } |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4621 | for (j=0; j < (ssize_t) count; j++) |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4622 | { |
| 4623 | alpha[j]=QuantumScale*GetPixelAlpha(source,p+j* |
| 4624 | GetPixelChannels(source)); |
| 4625 | pixels[j]*=alpha[j]; |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4626 | gamma=PerceptibleReciprocal(alpha[j]); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4627 | sum+=gamma*pixels[j]; |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4628 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4629 | sum/=count; |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4630 | SetPixelChannel(destination,channel,ClampToQuantum(sum),pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4631 | } |
| 4632 | break; |
| 4633 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4634 | case BilinearInterpolatePixel: |
| 4635 | default: |
| 4636 | { |
| 4637 | p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception); |
| 4638 | if (p == (const Quantum *) NULL) |
| 4639 | { |
| 4640 | status=MagickFalse; |
| 4641 | break; |
| 4642 | } |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4643 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4644 | { |
| 4645 | PointInfo |
| 4646 | delta, |
| 4647 | epsilon; |
| 4648 | |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4649 | channel=GetPixelChannelChannel(source,i); |
| 4650 | traits=GetPixelChannelTraits(source,channel); |
| 4651 | destination_traits=GetPixelChannelTraits(destination,channel); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4652 | if ((traits == UndefinedPixelTrait) || |
| 4653 | (destination_traits == UndefinedPixelTrait)) |
| 4654 | continue; |
| 4655 | delta.x=x-x_offset; |
| 4656 | delta.y=y-y_offset; |
| 4657 | epsilon.x=1.0-delta.x; |
| 4658 | epsilon.y=1.0-delta.y; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4659 | pixels[0]=(double) p[i]; |
| 4660 | pixels[1]=(double) p[GetPixelChannels(source)+i]; |
| 4661 | pixels[2]=(double) p[2*GetPixelChannels(source)+i]; |
| 4662 | pixels[3]=(double) p[3*GetPixelChannels(source)+i]; |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4663 | if ((traits & BlendPixelTrait) == 0) |
| 4664 | { |
| 4665 | gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x))); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4666 | gamma=PerceptibleReciprocal(gamma); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4667 | SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y* |
| 4668 | (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x* |
| 4669 | pixels[2]+delta.x*pixels[3]))),pixel); |
| 4670 | continue; |
| 4671 | } |
| 4672 | alpha[0]=QuantumScale*GetPixelAlpha(source,p); |
| 4673 | alpha[1]=QuantumScale*GetPixelAlpha(source,p+GetPixelChannels(source)); |
| 4674 | alpha[2]=QuantumScale*GetPixelAlpha(source,p+2* |
| 4675 | GetPixelChannels(source)); |
| 4676 | alpha[3]=QuantumScale*GetPixelAlpha(source,p+3* |
| 4677 | GetPixelChannels(source)); |
| 4678 | pixels[0]*=alpha[0]; |
| 4679 | pixels[1]*=alpha[1]; |
| 4680 | pixels[2]*=alpha[2]; |
| 4681 | pixels[3]*=alpha[3]; |
| 4682 | gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y* |
| 4683 | (epsilon.x*alpha[2]+delta.x*alpha[3]))); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4684 | gamma=PerceptibleReciprocal(gamma); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4685 | SetPixelChannel(destination,channel,ClampToQuantum(gamma*(epsilon.y* |
| 4686 | (epsilon.x*pixels[0]+delta.x*pixels[1])+delta.y*(epsilon.x*pixels[2]+ |
| 4687 | delta.x*pixels[3]))),pixel); |
| 4688 | } |
| 4689 | break; |
| 4690 | } |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 4691 | case BlendInterpolatePixel: |
| 4692 | { |
| 4693 | p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception); |
| 4694 | if (p == (const Quantum *) NULL) |
| 4695 | { |
| 4696 | status=MagickFalse; |
| 4697 | break; |
| 4698 | } |
| 4699 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
| 4700 | { |
| 4701 | register ssize_t |
| 4702 | j; |
| 4703 | |
| 4704 | channel=GetPixelChannelChannel(source,i); |
| 4705 | traits=GetPixelChannelTraits(source,channel); |
| 4706 | destination_traits=GetPixelChannelTraits(destination,channel); |
| 4707 | if ((traits == UndefinedPixelTrait) || |
| 4708 | (destination_traits == UndefinedPixelTrait)) |
| 4709 | continue; |
| 4710 | if ((traits & BlendPixelTrait) == 0) |
| 4711 | for (j=0; j < 4; j++) |
| 4712 | { |
| 4713 | alpha[j]=1.0; |
| 4714 | pixels[j]=(MagickRealType) p[j*GetPixelChannels(source)+channel]; |
| 4715 | } |
| 4716 | else |
| 4717 | for (j=0; j < 4; j++) |
| 4718 | { |
| 4719 | alpha[j]=QuantumScale*GetPixelAlpha(source,p+j* |
| 4720 | GetPixelChannels(source)); |
| 4721 | pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+channel]; |
| 4722 | } |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4723 | gamma=1.0; /* number of pixels blended together (its variable) */ |
| 4724 | for (j=0; j <= 1L; j++) |
| 4725 | { |
| 4726 | if ((y-y_offset) >= 0.75) |
| 4727 | { |
| 4728 | alpha[j]=alpha[j+2]; /* take right pixels */ |
| 4729 | pixels[j]=pixels[j+2]; |
| 4730 | } |
| 4731 | else |
| 4732 | if ((y-y_offset) > 0.25) |
| 4733 | { |
| 4734 | gamma=2.0; /* blend both pixels in row */ |
| 4735 | alpha[j]+=alpha[j+2]; /* add up alpha weights */ |
| 4736 | pixels[j]+=pixels[j+2]; |
| 4737 | } |
| 4738 | } |
| 4739 | if ((x-x_offset) >= 0.75) |
| 4740 | { |
| 4741 | alpha[0]=alpha[1]; /* take bottom row blend */ |
| 4742 | pixels[0]=pixels[1]; |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 4743 | } |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4744 | else |
| 4745 | if ((x-x_offset) > 0.25) |
| 4746 | { |
| 4747 | gamma*=2.0; /* blend both rows */ |
| 4748 | alpha[0]+=alpha[1]; /* add up alpha weights */ |
| 4749 | pixels[0]+=pixels[1]; |
| 4750 | } |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 4751 | if ((traits & BlendPixelTrait) == 0) |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4752 | gamma=PerceptibleReciprocal(alpha[0]); /* (color) 1/alpha_weights */ |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 4753 | else |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4754 | gamma=PerceptibleReciprocal(gamma); /* (alpha) 1/number_of_pixels */ |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 4755 | SetPixelChannel(destination,channel,ClampToQuantum(gamma*pixels[0]), |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4756 | pixel); |
anthony | 5f78bca | 2012-10-05 06:51:00 +0000 | [diff] [blame] | 4757 | } |
| 4758 | break; |
| 4759 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4760 | case CatromInterpolatePixel: |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4761 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4762 | double |
cristy | 380a11c | 2012-06-02 15:15:22 +0000 | [diff] [blame] | 4763 | cx[4], |
| 4764 | cy[4]; |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4765 | |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4766 | p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4, |
| 4767 | exception); |
| 4768 | if (p == (const Quantum *) NULL) |
| 4769 | { |
| 4770 | status=MagickFalse; |
| 4771 | break; |
| 4772 | } |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4773 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4774 | { |
| 4775 | register ssize_t |
| 4776 | j; |
| 4777 | |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4778 | channel=GetPixelChannelChannel(source,i); |
| 4779 | traits=GetPixelChannelTraits(source,channel); |
| 4780 | destination_traits=GetPixelChannelTraits(destination,channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4781 | if ((traits == UndefinedPixelTrait) || |
| 4782 | (destination_traits == UndefinedPixelTrait)) |
| 4783 | continue; |
| 4784 | if ((traits & BlendPixelTrait) == 0) |
| 4785 | for (j=0; j < 16; j++) |
| 4786 | { |
| 4787 | alpha[j]=1.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4788 | pixels[j]=(double) p[j*GetPixelChannels(source)+i]; |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4789 | } |
| 4790 | else |
| 4791 | for (j=0; j < 16; j++) |
| 4792 | { |
| 4793 | alpha[j]=QuantumScale*GetPixelAlpha(source,p+j* |
| 4794 | GetPixelChannels(source)); |
| 4795 | pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i]; |
| 4796 | } |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4797 | CatromWeights((double) (x-x_offset),&cx); |
| 4798 | CatromWeights((double) (y-y_offset),&cy); |
| 4799 | gamma=((traits & BlendPixelTrait) ? (double) (1.0) : |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4800 | PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]* |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4801 | alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]* |
| 4802 | alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]* |
| 4803 | alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+ |
| 4804 | cx[2]*alpha[14]+cx[3]*alpha[15]))); |
cristy | 380a11c | 2012-06-02 15:15:22 +0000 | [diff] [blame] | 4805 | SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]* |
| 4806 | pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]* |
| 4807 | (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+ |
| 4808 | cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]* |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 4809 | pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]* |
| 4810 | pixels[14]+cx[3]*pixels[15]))),pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4811 | } |
| 4812 | break; |
| 4813 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4814 | #if 0 |
nicolas | 20075dc | 2012-06-12 20:47:38 +0000 | [diff] [blame] | 4815 | /* deprecated useless and very slow interpolator */ |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4816 | case FilterInterpolatePixel: |
| 4817 | { |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4818 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4819 | { |
| 4820 | CacheView |
| 4821 | *filter_view; |
| 4822 | |
| 4823 | Image |
| 4824 | *excerpt_source, |
| 4825 | *filter_source; |
| 4826 | |
| 4827 | RectangleInfo |
| 4828 | geometry; |
| 4829 | |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4830 | channel=GetPixelChannelChannel(source,i); |
| 4831 | traits=GetPixelChannelTraits(source,channel); |
| 4832 | destination_traits=GetPixelChannelTraits(destination,channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4833 | if ((traits == UndefinedPixelTrait) || |
| 4834 | (destination_traits == UndefinedPixelTrait)) |
| 4835 | continue; |
| 4836 | geometry.width=4L; |
| 4837 | geometry.height=4L; |
| 4838 | geometry.x=x_offset-1; |
| 4839 | geometry.y=y_offset-1; |
| 4840 | excerpt_source=ExcerptImage(source,&geometry,exception); |
| 4841 | if (excerpt_source == (Image *) NULL) |
| 4842 | { |
| 4843 | status=MagickFalse; |
| 4844 | continue; |
| 4845 | } |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4846 | filter_source=ResizeImage(excerpt_source,1,1,source->filter,exception); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4847 | excerpt_source=DestroyImage(excerpt_source); |
| 4848 | if (filter_source == (Image *) NULL) |
| 4849 | continue; |
cristy | 4bc5202 | 2012-12-13 14:15:41 +0000 | [diff] [blame] | 4850 | filter_view=AcquireVirtualCacheView(filter_source); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4851 | p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception); |
| 4852 | if (p == (const Quantum *) NULL) |
| 4853 | status=MagickFalse; |
| 4854 | else |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 4855 | { |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4856 | SetPixelChannel(destination,channel,p[i],pixel); |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 4857 | } |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4858 | filter_view=DestroyCacheView(filter_view); |
| 4859 | filter_source=DestroyImage(filter_source); |
| 4860 | } |
| 4861 | break; |
| 4862 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4863 | #endif |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4864 | case IntegerInterpolatePixel: |
| 4865 | { |
| 4866 | p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception); |
| 4867 | if (p == (const Quantum *) NULL) |
| 4868 | { |
| 4869 | status=MagickFalse; |
| 4870 | break; |
| 4871 | } |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4872 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4873 | { |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4874 | channel=GetPixelChannelChannel(source,i); |
| 4875 | traits=GetPixelChannelTraits(source,channel); |
| 4876 | destination_traits=GetPixelChannelTraits(destination,channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4877 | if ((traits == UndefinedPixelTrait) || |
| 4878 | (destination_traits == UndefinedPixelTrait)) |
| 4879 | continue; |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4880 | SetPixelChannel(destination,channel,p[i],pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4881 | } |
| 4882 | break; |
| 4883 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4884 | case NearestInterpolatePixel: |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4885 | { |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4886 | x_offset=(ssize_t) floor(x+0.5); |
| 4887 | y_offset=(ssize_t) floor(y+0.5); |
| 4888 | p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,1,1,exception); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4889 | if (p == (const Quantum *) NULL) |
| 4890 | { |
| 4891 | status=MagickFalse; |
| 4892 | break; |
| 4893 | } |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4894 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4895 | { |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4896 | channel=GetPixelChannelChannel(source,i); |
| 4897 | traits=GetPixelChannelTraits(source,channel); |
| 4898 | destination_traits=GetPixelChannelTraits(destination,channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4899 | if ((traits == UndefinedPixelTrait) || |
| 4900 | (destination_traits == UndefinedPixelTrait)) |
| 4901 | continue; |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4902 | SetPixelChannel(destination,channel,p[i],pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4903 | } |
| 4904 | break; |
| 4905 | } |
| 4906 | case MeshInterpolatePixel: |
| 4907 | { |
| 4908 | p=GetCacheViewVirtualPixels(source_view,x_offset,y_offset,2,2,exception); |
| 4909 | if (p == (const Quantum *) NULL) |
| 4910 | { |
| 4911 | status=MagickFalse; |
| 4912 | break; |
| 4913 | } |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 4914 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4915 | { |
| 4916 | PointInfo |
| 4917 | delta, |
| 4918 | luminance; |
| 4919 | |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4920 | channel=GetPixelChannelChannel(source,i); |
| 4921 | traits=GetPixelChannelTraits(source,channel); |
| 4922 | destination_traits=GetPixelChannelTraits(destination,channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4923 | if ((traits == UndefinedPixelTrait) || |
| 4924 | (destination_traits == UndefinedPixelTrait)) |
| 4925 | continue; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4926 | pixels[0]=(double) p[i]; |
| 4927 | pixels[1]=(double) p[GetPixelChannels(source)+i]; |
| 4928 | pixels[2]=(double) p[2*GetPixelChannels(source)+i]; |
| 4929 | pixels[3]=(double) p[3*GetPixelChannels(source)+i]; |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 4930 | if ((traits & BlendPixelTrait) == 0) |
| 4931 | { |
| 4932 | alpha[0]=1.0; |
| 4933 | alpha[1]=1.0; |
| 4934 | alpha[2]=1.0; |
| 4935 | alpha[3]=1.0; |
| 4936 | } |
| 4937 | else |
| 4938 | { |
| 4939 | alpha[0]=QuantumScale*GetPixelAlpha(source,p); |
| 4940 | alpha[1]=QuantumScale*GetPixelAlpha(source,p+ |
| 4941 | GetPixelChannels(source)); |
| 4942 | alpha[2]=QuantumScale*GetPixelAlpha(source,p+2* |
| 4943 | GetPixelChannels(source)); |
| 4944 | alpha[3]=QuantumScale*GetPixelAlpha(source,p+3* |
| 4945 | GetPixelChannels(source)); |
| 4946 | } |
| 4947 | delta.x=x-x_offset; |
| 4948 | delta.y=y-y_offset; |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 4949 | luminance.x=fabs((double) (GetPixelLuminance(source,p)- |
| 4950 | GetPixelLuminance(source,p+3*GetPixelChannels(source)))); |
| 4951 | luminance.y=fabs((double) (GetPixelLuminance(source,p+ |
| 4952 | GetPixelChannels(source))-GetPixelLuminance(source,p+2* |
| 4953 | GetPixelChannels(source)))); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 4954 | if (luminance.x < luminance.y) |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 4955 | { |
| 4956 | /* |
| 4957 | Diagonal 0-3 NW-SE. |
| 4958 | */ |
| 4959 | if (delta.x <= delta.y) |
| 4960 | { |
| 4961 | /* |
| 4962 | Bottom-left triangle (pixel: 2, diagonal: 0-3). |
| 4963 | */ |
| 4964 | delta.y=1.0-delta.y; |
| 4965 | gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4966 | gamma=PerceptibleReciprocal(gamma); |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4967 | SetPixelChannel(destination,channel,ClampToQuantum(gamma* |
| 4968 | MeshInterpolate(&delta,pixels[2],pixels[3],pixels[0])),pixel); |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 4969 | } |
| 4970 | else |
| 4971 | { |
| 4972 | /* |
| 4973 | Top-right triangle (pixel: 1, diagonal: 0-3). |
| 4974 | */ |
| 4975 | delta.x=1.0-delta.x; |
| 4976 | gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4977 | gamma=PerceptibleReciprocal(gamma); |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4978 | SetPixelChannel(destination,channel,ClampToQuantum(gamma* |
| 4979 | MeshInterpolate(&delta,pixels[1],pixels[0],pixels[3])),pixel); |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 4980 | } |
| 4981 | } |
| 4982 | else |
| 4983 | { |
| 4984 | /* |
| 4985 | Diagonal 1-2 NE-SW. |
| 4986 | */ |
| 4987 | if (delta.x <= (1.0-delta.y)) |
| 4988 | { |
| 4989 | /* |
| 4990 | Top-left triangle (pixel: 0, diagonal: 1-2). |
| 4991 | */ |
| 4992 | gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4993 | gamma=PerceptibleReciprocal(gamma); |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 4994 | SetPixelChannel(destination,channel,ClampToQuantum(gamma* |
| 4995 | MeshInterpolate(&delta,pixels[0],pixels[1],pixels[2])),pixel); |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 4996 | } |
| 4997 | else |
| 4998 | { |
| 4999 | /* |
| 5000 | Bottom-right triangle (pixel: 3, diagonal: 1-2). |
| 5001 | */ |
| 5002 | delta.x=1.0-delta.x; |
| 5003 | delta.y=1.0-delta.y; |
| 5004 | gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5005 | gamma=PerceptibleReciprocal(gamma); |
cristy | 4a7ae69 | 2011-12-14 12:24:11 +0000 | [diff] [blame] | 5006 | SetPixelChannel(destination,channel,ClampToQuantum(gamma* |
| 5007 | MeshInterpolate(&delta,pixels[3],pixels[2],pixels[1])),pixel); |
cristy | 1861c90 | 2011-12-14 02:30:00 +0000 | [diff] [blame] | 5008 | } |
| 5009 | } |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5010 | } |
| 5011 | break; |
| 5012 | } |
| 5013 | case SplineInterpolatePixel: |
| 5014 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5015 | double |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 5016 | cx[4], |
| 5017 | cy[4]; |
| 5018 | |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5019 | p=GetCacheViewVirtualPixels(source_view,x_offset-1,y_offset-1,4,4, |
| 5020 | exception); |
| 5021 | if (p == (const Quantum *) NULL) |
| 5022 | { |
| 5023 | status=MagickFalse; |
| 5024 | break; |
| 5025 | } |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 5026 | for (i=0; i < (ssize_t) GetPixelChannels(source); i++) |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5027 | { |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5028 | register ssize_t |
| 5029 | j; |
| 5030 | |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 5031 | channel=GetPixelChannelChannel(source,i); |
| 5032 | traits=GetPixelChannelTraits(source,channel); |
| 5033 | destination_traits=GetPixelChannelTraits(destination,channel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5034 | if ((traits == UndefinedPixelTrait) || |
| 5035 | (destination_traits == UndefinedPixelTrait)) |
| 5036 | continue; |
| 5037 | if ((traits & BlendPixelTrait) == 0) |
| 5038 | for (j=0; j < 16; j++) |
| 5039 | { |
| 5040 | alpha[j]=1.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5041 | pixels[j]=(double) p[j*GetPixelChannels(source)+i]; |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5042 | } |
| 5043 | else |
| 5044 | for (j=0; j < 16; j++) |
| 5045 | { |
| 5046 | alpha[j]=QuantumScale*GetPixelAlpha(source,p+j* |
| 5047 | GetPixelChannels(source)); |
| 5048 | pixels[j]=alpha[j]*p[j*GetPixelChannels(source)+i]; |
| 5049 | } |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5050 | SplineWeights((double) (x-x_offset),&cx); |
| 5051 | SplineWeights((double) (y-y_offset),&cy); |
| 5052 | gamma=((traits & BlendPixelTrait) ? (double) (1.0) : |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5053 | PerceptibleReciprocal(cy[0]*(cx[0]*alpha[0]+cx[1]*alpha[1]+cx[2]* |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 5054 | alpha[2]+cx[3]*alpha[3])+cy[1]*(cx[0]*alpha[4]+cx[1]*alpha[5]+cx[2]* |
| 5055 | alpha[6]+cx[3]*alpha[7])+cy[2]*(cx[0]*alpha[8]+cx[1]*alpha[9]+cx[2]* |
| 5056 | alpha[10]+cx[3]*alpha[11])+cy[3]*(cx[0]*alpha[12]+cx[1]*alpha[13]+ |
| 5057 | cx[2]*alpha[14]+cx[3]*alpha[15]))); |
| 5058 | SetPixelChannel(destination,channel,ClampToQuantum(gamma*(cy[0]*(cx[0]* |
| 5059 | pixels[0]+cx[1]*pixels[1]+cx[2]*pixels[2]+cx[3]*pixels[3])+cy[1]* |
| 5060 | (cx[0]*pixels[4]+cx[1]*pixels[5]+cx[2]*pixels[6]+cx[3]*pixels[7])+ |
| 5061 | cy[2]*(cx[0]*pixels[8]+cx[1]*pixels[9]+cx[2]*pixels[10]+cx[3]* |
| 5062 | pixels[11])+cy[3]*(cx[0]*pixels[12]+cx[1]*pixels[13]+cx[2]* |
| 5063 | pixels[14]+cx[3]*pixels[15]))),pixel); |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5064 | } |
| 5065 | break; |
| 5066 | } |
| 5067 | } |
| 5068 | return(status); |
| 5069 | } |
| 5070 | |
| 5071 | /* |
| 5072 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5073 | % % |
| 5074 | % % |
| 5075 | % % |
cristy | 9075cdb | 2011-07-30 01:06:23 +0000 | [diff] [blame] | 5076 | % 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] | 5077 | % % |
| 5078 | % % |
| 5079 | % % |
| 5080 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5081 | % |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 5082 | % InterpolatePixelInfo() applies a pixel interpolation method between a |
| 5083 | % floating point coordinate and the pixels surrounding that coordinate. No |
| 5084 | % pixel area resampling, or scaling of the result is performed. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5085 | % |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5086 | % Interpolation is restricted to just RGBKA channels. |
| 5087 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5088 | % The format of the InterpolatePixelInfo method is: |
| 5089 | % |
| 5090 | % MagickBooleanType InterpolatePixelInfo(const Image *image, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5091 | % const CacheView *image_view,const PixelInterpolateMethod method, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5092 | % const double x,const double y,PixelInfo *pixel, |
| 5093 | % ExceptionInfo *exception) |
| 5094 | % |
| 5095 | % A description of each parameter follows: |
| 5096 | % |
| 5097 | % o image: the image. |
| 5098 | % |
| 5099 | % o image_view: the image view. |
| 5100 | % |
| 5101 | % o method: the pixel color interpolation method. |
| 5102 | % |
| 5103 | % o x,y: A double representing the current (x,y) position of the pixel. |
| 5104 | % |
| 5105 | % o pixel: return the interpolated pixel here. |
| 5106 | % |
| 5107 | % o exception: return any errors or warnings in this structure. |
| 5108 | % |
| 5109 | */ |
| 5110 | |
| 5111 | static inline void AlphaBlendPixelInfo(const Image *image, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5112 | const Quantum *pixel,PixelInfo *pixel_info,double *alpha) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5113 | { |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5114 | if (image->alpha_trait != BlendPixelTrait) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5115 | { |
| 5116 | *alpha=1.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5117 | pixel_info->red=(double) GetPixelRed(image,pixel); |
| 5118 | pixel_info->green=(double) GetPixelGreen(image,pixel); |
| 5119 | pixel_info->blue=(double) GetPixelBlue(image,pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5120 | pixel_info->black=0.0; |
| 5121 | if (image->colorspace == CMYKColorspace) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5122 | pixel_info->black=(double) GetPixelBlack(image,pixel); |
| 5123 | pixel_info->alpha=(double) GetPixelAlpha(image,pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5124 | return; |
| 5125 | } |
| 5126 | *alpha=QuantumScale*GetPixelAlpha(image,pixel); |
| 5127 | pixel_info->red=(*alpha*GetPixelRed(image,pixel)); |
| 5128 | pixel_info->green=(*alpha*GetPixelGreen(image,pixel)); |
| 5129 | pixel_info->blue=(*alpha*GetPixelBlue(image,pixel)); |
| 5130 | pixel_info->black=0.0; |
| 5131 | if (image->colorspace == CMYKColorspace) |
| 5132 | pixel_info->black=(*alpha*GetPixelBlack(image,pixel)); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5133 | pixel_info->alpha=(double) GetPixelAlpha(image,pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5134 | } |
| 5135 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5136 | MagickExport MagickBooleanType InterpolatePixelInfo(const Image *image, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5137 | const CacheView *image_view,const PixelInterpolateMethod method, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5138 | const double x,const double y,PixelInfo *pixel,ExceptionInfo *exception) |
| 5139 | { |
| 5140 | MagickBooleanType |
| 5141 | status; |
| 5142 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5143 | double |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5144 | alpha[16], |
| 5145 | gamma; |
| 5146 | |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5147 | PixelInfo |
| 5148 | pixels[16]; |
| 5149 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5150 | register const Quantum |
| 5151 | *p; |
| 5152 | |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 5153 | register ssize_t |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5154 | i; |
| 5155 | |
| 5156 | ssize_t |
| 5157 | x_offset, |
| 5158 | y_offset; |
| 5159 | |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5160 | PixelInterpolateMethod |
| 5161 | interpolate; |
| 5162 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5163 | assert(image != (Image *) NULL); |
| 5164 | assert(image->signature == MagickSignature); |
| 5165 | assert(image_view != (CacheView *) NULL); |
| 5166 | status=MagickTrue; |
| 5167 | x_offset=(ssize_t) floor(x); |
| 5168 | y_offset=(ssize_t) floor(y); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5169 | interpolate = method; |
| 5170 | if ( interpolate == UndefinedInterpolatePixel ) |
| 5171 | interpolate = image->interpolate; |
| 5172 | switch (interpolate) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5173 | { |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5174 | case AverageInterpolatePixel: /* nearest 4 neighbours */ |
| 5175 | case Average9InterpolatePixel: /* nearest 9 neighbours */ |
| 5176 | case Average16InterpolatePixel: /* nearest 16 neighbours */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5177 | { |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5178 | ssize_t |
| 5179 | count; |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5180 | |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5181 | count=2; /* size of the area to average - default nearest 4 */ |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5182 | if (interpolate == Average9InterpolatePixel) |
| 5183 | { |
| 5184 | count=3; |
| 5185 | x_offset=(ssize_t) (floor(x+0.5)-1); |
| 5186 | y_offset=(ssize_t) (floor(y+0.5)-1); |
| 5187 | } |
| 5188 | else if (interpolate == Average16InterpolatePixel) |
| 5189 | { |
| 5190 | count=4; |
| 5191 | x_offset--; |
| 5192 | y_offset--; |
| 5193 | } |
| 5194 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,count,count, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5195 | exception); |
| 5196 | if (p == (const Quantum *) NULL) |
| 5197 | { |
| 5198 | status=MagickFalse; |
| 5199 | break; |
| 5200 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5201 | pixel->red=0.0; |
| 5202 | pixel->green=0.0; |
| 5203 | pixel->blue=0.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5204 | pixel->black=0.0; |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5205 | pixel->alpha=0.0; |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5206 | count*=count; /* number of pixels - square of size */ |
cristy | 50e64b8 | 2012-06-22 17:46:19 +0000 | [diff] [blame] | 5207 | for (i=0; i < (ssize_t) count; i++) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5208 | { |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5209 | AlphaBlendPixelInfo(image,p,pixels,alpha); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5210 | gamma=PerceptibleReciprocal(alpha[0]); |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5211 | pixel->red+=gamma*pixels[0].red; |
| 5212 | pixel->green+=gamma*pixels[0].green; |
| 5213 | pixel->blue+=gamma*pixels[0].blue; |
| 5214 | pixel->black+=gamma*pixels[0].black; |
| 5215 | pixel->alpha+=pixels[0].alpha; |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5216 | p += GetPixelChannels(image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5217 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5218 | gamma=1.0/count; /* average weighting of each pixel in area */ |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5219 | pixel->red*=gamma; |
| 5220 | pixel->green*=gamma; |
| 5221 | pixel->blue*=gamma; |
| 5222 | pixel->black*=gamma; |
| 5223 | pixel->alpha*=gamma; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5224 | break; |
| 5225 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5226 | case BackgroundInterpolatePixel: |
| 5227 | { |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5228 | *pixel=image->background_color; /* Copy PixelInfo Structure */ |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5229 | break; |
| 5230 | } |
| 5231 | case BilinearInterpolatePixel: |
| 5232 | default: |
| 5233 | { |
| 5234 | PointInfo |
| 5235 | delta, |
| 5236 | epsilon; |
| 5237 | |
| 5238 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
| 5239 | if (p == (const Quantum *) NULL) |
| 5240 | { |
| 5241 | status=MagickFalse; |
| 5242 | break; |
| 5243 | } |
| 5244 | for (i=0; i < 4L; i++) |
| 5245 | AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i); |
| 5246 | delta.x=x-x_offset; |
| 5247 | delta.y=y-y_offset; |
| 5248 | epsilon.x=1.0-delta.x; |
| 5249 | epsilon.y=1.0-delta.y; |
| 5250 | gamma=((epsilon.y*(epsilon.x*alpha[0]+delta.x*alpha[1])+delta.y* |
| 5251 | (epsilon.x*alpha[2]+delta.x*alpha[3]))); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5252 | gamma=PerceptibleReciprocal(gamma); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5253 | pixel->red=gamma*(epsilon.y*(epsilon.x*pixels[0].red+delta.x* |
| 5254 | pixels[1].red)+delta.y*(epsilon.x*pixels[2].red+delta.x*pixels[3].red)); |
| 5255 | pixel->green=gamma*(epsilon.y*(epsilon.x*pixels[0].green+delta.x* |
| 5256 | pixels[1].green)+delta.y*(epsilon.x*pixels[2].green+delta.x* |
| 5257 | pixels[3].green)); |
| 5258 | pixel->blue=gamma*(epsilon.y*(epsilon.x*pixels[0].blue+delta.x* |
| 5259 | pixels[1].blue)+delta.y*(epsilon.x*pixels[2].blue+delta.x* |
| 5260 | pixels[3].blue)); |
| 5261 | if (image->colorspace == CMYKColorspace) |
| 5262 | pixel->black=gamma*(epsilon.y*(epsilon.x*pixels[0].black+delta.x* |
| 5263 | pixels[1].black)+delta.y*(epsilon.x*pixels[2].black+delta.x* |
| 5264 | pixels[3].black)); |
| 5265 | gamma=((epsilon.y*(epsilon.x+delta.x)+delta.y*(epsilon.x+delta.x))); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5266 | gamma=PerceptibleReciprocal(gamma); |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5267 | pixel->alpha=(epsilon.y*(epsilon.x*pixels[0].alpha+delta.x* |
| 5268 | pixels[1].alpha)+delta.y*(epsilon.x*pixels[2].alpha+delta.x* |
| 5269 | pixels[3].alpha)); |
| 5270 | break; |
| 5271 | } |
| 5272 | case BlendInterpolatePixel: |
| 5273 | { |
| 5274 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
| 5275 | if (p == (const Quantum *) NULL) |
| 5276 | { |
| 5277 | status=MagickFalse; |
| 5278 | break; |
| 5279 | } |
| 5280 | for (i=0; i < 4L; i++) |
| 5281 | AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i); |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5282 | gamma=1.0; /* number of pixels blended together (its variable) */ |
| 5283 | for (i=0; i <= 1L; i++) |
| 5284 | { |
| 5285 | if ((y-y_offset) >= 0.75) |
| 5286 | { |
| 5287 | alpha[i]=alpha[i+2]; /* take right pixels */ |
| 5288 | pixels[i]=pixels[i+2]; |
| 5289 | } |
| 5290 | else |
| 5291 | if ((y-y_offset) > 0.25) |
| 5292 | { |
| 5293 | gamma=2.0; /* blend both pixels in row */ |
| 5294 | alpha[i]+=alpha[i+2]; /* add up alpha weights */ |
| 5295 | pixels[i].red+=pixels[i+2].red; |
| 5296 | pixels[i].green+=pixels[i+2].green; |
| 5297 | pixels[i].blue+=pixels[i+2].blue; |
| 5298 | pixels[i].black+=pixels[i+2].black; |
| 5299 | pixels[i].alpha+=pixels[i+2].alpha; |
| 5300 | } |
| 5301 | } |
| 5302 | if ((x-x_offset) >= 0.75) |
| 5303 | { |
| 5304 | alpha[0]=alpha[1]; |
| 5305 | pixels[0]=pixels[1]; |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5306 | } |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5307 | else |
| 5308 | if ((x-x_offset) > 0.25) |
| 5309 | { |
| 5310 | gamma*=2.0; /* blend both rows */ |
| 5311 | alpha[0]+= alpha[1]; /* add up alpha weights */ |
| 5312 | pixels[0].red+=pixels[1].red; |
| 5313 | pixels[0].green+=pixels[1].green; |
| 5314 | pixels[0].blue+=pixels[1].blue; |
| 5315 | pixels[0].black+=pixels[1].black; |
| 5316 | pixels[0].alpha+=pixels[1].alpha; |
| 5317 | } |
| 5318 | gamma=1.0/gamma; |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5319 | alpha[0]=PerceptibleReciprocal(alpha[0]); |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5320 | pixel->red=alpha[0]*pixels[0].red; |
| 5321 | pixel->green=alpha[0]*pixels[0].green; /* divide by sum of alpha */ |
| 5322 | pixel->blue=alpha[0]*pixels[0].blue; |
| 5323 | pixel->black=alpha[0]*pixels[0].black; |
| 5324 | pixel->alpha=gamma*pixels[0].alpha; /* divide by number of pixels */ |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5325 | break; |
| 5326 | } |
| 5327 | case CatromInterpolatePixel: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5328 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5329 | double |
cristy | 380a11c | 2012-06-02 15:15:22 +0000 | [diff] [blame] | 5330 | cx[4], |
| 5331 | cy[4]; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5332 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5333 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 5334 | exception); |
| 5335 | if (p == (const Quantum *) NULL) |
| 5336 | { |
| 5337 | status=MagickFalse; |
| 5338 | break; |
| 5339 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5340 | for (i=0; i < 16L; i++) |
| 5341 | AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5342 | CatromWeights((double) (x-x_offset),&cx); |
| 5343 | CatromWeights((double) (y-y_offset),&cy); |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5344 | pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]* |
| 5345 | pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]* |
| 5346 | pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]* |
| 5347 | pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]* |
| 5348 | pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]* |
| 5349 | pixels[14].red+cx[3]*pixels[15].red)); |
| 5350 | pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]* |
| 5351 | pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+ |
| 5352 | cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+ |
| 5353 | cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]* |
| 5354 | pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]* |
| 5355 | pixels[12].green+cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]* |
| 5356 | pixels[15].green)); |
| 5357 | pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]* |
| 5358 | pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]* |
| 5359 | pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]* |
| 5360 | pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]* |
| 5361 | pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+ |
| 5362 | cx[2]*pixels[14].blue+cx[3]*pixels[15].blue)); |
cristy | 380a11c | 2012-06-02 15:15:22 +0000 | [diff] [blame] | 5363 | if (image->colorspace == CMYKColorspace) |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5364 | pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]* |
| 5365 | pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+ |
| 5366 | cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+ |
| 5367 | cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]* |
| 5368 | pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]* |
| 5369 | pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]* |
| 5370 | pixels[15].black)); |
| 5371 | pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]* |
| 5372 | pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+ |
| 5373 | cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+ |
| 5374 | cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]* |
| 5375 | pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+ |
| 5376 | cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5377 | break; |
| 5378 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5379 | #if 0 |
nicolas | 20075dc | 2012-06-12 20:47:38 +0000 | [diff] [blame] | 5380 | /* deprecated useless and very slow interpolator */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5381 | case FilterInterpolatePixel: |
| 5382 | { |
| 5383 | CacheView |
| 5384 | *filter_view; |
| 5385 | |
| 5386 | Image |
| 5387 | *excerpt_image, |
| 5388 | *filter_image; |
| 5389 | |
| 5390 | RectangleInfo |
| 5391 | geometry; |
| 5392 | |
| 5393 | geometry.width=4L; |
| 5394 | geometry.height=4L; |
| 5395 | geometry.x=x_offset-1; |
| 5396 | geometry.y=y_offset-1; |
| 5397 | excerpt_image=ExcerptImage(image,&geometry,exception); |
| 5398 | if (excerpt_image == (Image *) NULL) |
| 5399 | { |
| 5400 | status=MagickFalse; |
| 5401 | break; |
| 5402 | } |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 5403 | filter_image=ResizeImage(excerpt_image,1,1,image->filter,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5404 | excerpt_image=DestroyImage(excerpt_image); |
| 5405 | if (filter_image == (Image *) NULL) |
| 5406 | break; |
cristy | 4bc5202 | 2012-12-13 14:15:41 +0000 | [diff] [blame] | 5407 | filter_view=AcquireVirtualCacheView(filter_image); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5408 | p=GetCacheViewVirtualPixels(filter_view,0,0,1,1,exception); |
| 5409 | if (p != (const Quantum *) NULL) |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 5410 | GetPixelInfoPixel(image,p,pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5411 | filter_view=DestroyCacheView(filter_view); |
| 5412 | filter_image=DestroyImage(filter_image); |
| 5413 | break; |
| 5414 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5415 | #endif |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5416 | case IntegerInterpolatePixel: |
| 5417 | { |
| 5418 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception); |
| 5419 | if (p == (const Quantum *) NULL) |
| 5420 | { |
| 5421 | status=MagickFalse; |
| 5422 | break; |
| 5423 | } |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 5424 | GetPixelInfoPixel(image,p,pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5425 | break; |
| 5426 | } |
| 5427 | case MeshInterpolatePixel: |
| 5428 | { |
| 5429 | PointInfo |
| 5430 | delta, |
| 5431 | luminance; |
| 5432 | |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5433 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,2,2,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5434 | if (p == (const Quantum *) NULL) |
| 5435 | { |
| 5436 | status=MagickFalse; |
| 5437 | break; |
| 5438 | } |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5439 | delta.x=x-x_offset; |
| 5440 | delta.y=y-y_offset; |
cristy | 884f600 | 2011-07-31 00:51:45 +0000 | [diff] [blame] | 5441 | luminance.x=GetPixelLuminance(image,p)-(double) |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5442 | GetPixelLuminance(image,p+3*GetPixelChannels(image)); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5443 | luminance.y=GetPixelLuminance(image,p+GetPixelChannels(image))-(double) |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5444 | GetPixelLuminance(image,p+2*GetPixelChannels(image)); |
cristy | 5ce8df8 | 2011-07-07 14:52:23 +0000 | [diff] [blame] | 5445 | AlphaBlendPixelInfo(image,p,pixels+0,alpha+0); |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5446 | AlphaBlendPixelInfo(image,p+GetPixelChannels(image),pixels+1,alpha+1); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5447 | AlphaBlendPixelInfo(image,p+2*GetPixelChannels(image),pixels+2,alpha+2); |
| 5448 | AlphaBlendPixelInfo(image,p+3*GetPixelChannels(image),pixels+3,alpha+3); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5449 | if (fabs(luminance.x) < fabs(luminance.y)) |
| 5450 | { |
| 5451 | /* |
| 5452 | Diagonal 0-3 NW-SE. |
| 5453 | */ |
| 5454 | if (delta.x <= delta.y) |
| 5455 | { |
| 5456 | /* |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5457 | Bottom-left triangle (pixel: 2, diagonal: 0-3). |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5458 | */ |
| 5459 | delta.y=1.0-delta.y; |
| 5460 | gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5461 | gamma=PerceptibleReciprocal(gamma); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5462 | pixel->red=gamma*MeshInterpolate(&delta,pixels[2].red, |
| 5463 | pixels[3].red,pixels[0].red); |
| 5464 | pixel->green=gamma*MeshInterpolate(&delta,pixels[2].green, |
| 5465 | pixels[3].green,pixels[0].green); |
| 5466 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[2].blue, |
| 5467 | pixels[3].blue,pixels[0].blue); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5468 | if (image->colorspace == CMYKColorspace) |
| 5469 | pixel->black=gamma*MeshInterpolate(&delta,pixels[2].black, |
| 5470 | pixels[3].black,pixels[0].black); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5471 | gamma=MeshInterpolate(&delta,1.0,1.0,1.0); |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5472 | pixel->alpha=gamma*MeshInterpolate(&delta,pixels[2].alpha, |
| 5473 | pixels[3].alpha,pixels[0].alpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5474 | } |
| 5475 | else |
| 5476 | { |
| 5477 | /* |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5478 | Top-right triangle (pixel:1 , diagonal: 0-3). |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5479 | */ |
| 5480 | delta.x=1.0-delta.x; |
| 5481 | gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5482 | gamma=PerceptibleReciprocal(gamma); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5483 | pixel->red=gamma*MeshInterpolate(&delta,pixels[1].red, |
| 5484 | pixels[0].red,pixels[3].red); |
| 5485 | pixel->green=gamma*MeshInterpolate(&delta,pixels[1].green, |
| 5486 | pixels[0].green,pixels[3].green); |
| 5487 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[1].blue, |
| 5488 | pixels[0].blue,pixels[3].blue); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5489 | if (image->colorspace == CMYKColorspace) |
| 5490 | pixel->black=gamma*MeshInterpolate(&delta,pixels[1].black, |
| 5491 | pixels[0].black,pixels[3].black); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5492 | gamma=MeshInterpolate(&delta,1.0,1.0,1.0); |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5493 | pixel->alpha=gamma*MeshInterpolate(&delta,pixels[1].alpha, |
| 5494 | pixels[0].alpha,pixels[3].alpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5495 | } |
| 5496 | } |
| 5497 | else |
| 5498 | { |
| 5499 | /* |
| 5500 | Diagonal 1-2 NE-SW. |
| 5501 | */ |
| 5502 | if (delta.x <= (1.0-delta.y)) |
| 5503 | { |
| 5504 | /* |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5505 | Top-left triangle (pixel: 0, diagonal: 1-2). |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5506 | */ |
| 5507 | gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5508 | gamma=PerceptibleReciprocal(gamma); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5509 | pixel->red=gamma*MeshInterpolate(&delta,pixels[0].red, |
| 5510 | pixels[1].red,pixels[2].red); |
| 5511 | pixel->green=gamma*MeshInterpolate(&delta,pixels[0].green, |
| 5512 | pixels[1].green,pixels[2].green); |
| 5513 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[0].blue, |
| 5514 | pixels[1].blue,pixels[2].blue); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5515 | if (image->colorspace == CMYKColorspace) |
| 5516 | pixel->black=gamma*MeshInterpolate(&delta,pixels[0].black, |
| 5517 | pixels[1].black,pixels[2].black); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5518 | gamma=MeshInterpolate(&delta,1.0,1.0,1.0); |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5519 | pixel->alpha=gamma*MeshInterpolate(&delta,pixels[0].alpha, |
| 5520 | pixels[1].alpha,pixels[2].alpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5521 | } |
| 5522 | else |
| 5523 | { |
| 5524 | /* |
| 5525 | Bottom-right triangle (pixel: 3, diagonal: 1-2). |
| 5526 | */ |
| 5527 | delta.x=1.0-delta.x; |
| 5528 | delta.y=1.0-delta.y; |
| 5529 | gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]); |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 5530 | gamma=PerceptibleReciprocal(gamma); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5531 | pixel->red=gamma*MeshInterpolate(&delta,pixels[3].red, |
| 5532 | pixels[2].red,pixels[1].red); |
| 5533 | pixel->green=gamma*MeshInterpolate(&delta,pixels[3].green, |
| 5534 | pixels[2].green,pixels[1].green); |
| 5535 | pixel->blue=gamma*MeshInterpolate(&delta,pixels[3].blue, |
| 5536 | pixels[2].blue,pixels[1].blue); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5537 | if (image->colorspace == CMYKColorspace) |
| 5538 | pixel->black=gamma*MeshInterpolate(&delta,pixels[3].black, |
| 5539 | pixels[2].black,pixels[1].black); |
cristy | 94ea163 | 2011-07-30 20:40:25 +0000 | [diff] [blame] | 5540 | gamma=MeshInterpolate(&delta,1.0,1.0,1.0); |
cristy | 865d58d | 2011-07-09 00:44:52 +0000 | [diff] [blame] | 5541 | pixel->alpha=gamma*MeshInterpolate(&delta,pixels[3].alpha, |
| 5542 | pixels[2].alpha,pixels[1].alpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5543 | } |
| 5544 | } |
| 5545 | break; |
| 5546 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5547 | case NearestInterpolatePixel: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5548 | { |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5549 | x_offset=(ssize_t) floor(x+0.5); |
| 5550 | y_offset=(ssize_t) floor(y+0.5); |
| 5551 | p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset,1,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5552 | if (p == (const Quantum *) NULL) |
| 5553 | { |
| 5554 | status=MagickFalse; |
| 5555 | break; |
| 5556 | } |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 5557 | GetPixelInfoPixel(image,p,pixel); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5558 | break; |
| 5559 | } |
| 5560 | case SplineInterpolatePixel: |
| 5561 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5562 | double |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 5563 | cx[4], |
| 5564 | cy[4]; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5565 | |
| 5566 | p=GetCacheViewVirtualPixels(image_view,x_offset-1,y_offset-1,4,4, |
| 5567 | exception); |
| 5568 | if (p == (const Quantum *) NULL) |
| 5569 | { |
| 5570 | status=MagickFalse; |
| 5571 | break; |
| 5572 | } |
anthony | cf4e33d | 2012-06-08 07:33:23 +0000 | [diff] [blame] | 5573 | for (i=0; i < 16L; i++) |
| 5574 | AlphaBlendPixelInfo(image,p+i*GetPixelChannels(image),pixels+i,alpha+i); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5575 | SplineWeights((double) (x-x_offset),&cx); |
| 5576 | SplineWeights((double) (y-y_offset),&cy); |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5577 | pixel->red=(cy[0]*(cx[0]*pixels[0].red+cx[1]*pixels[1].red+cx[2]* |
| 5578 | pixels[2].red+cx[3]*pixels[3].red)+cy[1]*(cx[0]*pixels[4].red+cx[1]* |
| 5579 | pixels[5].red+cx[2]*pixels[6].red+cx[3]*pixels[7].red)+cy[2]*(cx[0]* |
| 5580 | pixels[8].red+cx[1]*pixels[9].red+cx[2]*pixels[10].red+cx[3]* |
| 5581 | pixels[11].red)+cy[3]*(cx[0]*pixels[12].red+cx[1]*pixels[13].red+cx[2]* |
| 5582 | pixels[14].red+cx[3]*pixels[15].red)); |
| 5583 | pixel->green=(cy[0]*(cx[0]*pixels[0].green+cx[1]*pixels[1].green+cx[2]* |
| 5584 | pixels[2].green+cx[3]*pixels[3].green)+cy[1]*(cx[0]*pixels[4].green+ |
| 5585 | cx[1]*pixels[5].green+cx[2]*pixels[6].green+cx[3]*pixels[7].green)+ |
| 5586 | cy[2]*(cx[0]*pixels[8].green+cx[1]*pixels[9].green+cx[2]* |
| 5587 | pixels[10].green+cx[3]*pixels[11].green)+cy[3]*(cx[0]*pixels[12].green+ |
| 5588 | cx[1]*pixels[13].green+cx[2]*pixels[14].green+cx[3]*pixels[15].green)); |
| 5589 | pixel->blue=(cy[0]*(cx[0]*pixels[0].blue+cx[1]*pixels[1].blue+cx[2]* |
| 5590 | pixels[2].blue+cx[3]*pixels[3].blue)+cy[1]*(cx[0]*pixels[4].blue+cx[1]* |
| 5591 | pixels[5].blue+cx[2]*pixels[6].blue+cx[3]*pixels[7].blue)+cy[2]*(cx[0]* |
| 5592 | pixels[8].blue+cx[1]*pixels[9].blue+cx[2]*pixels[10].blue+cx[3]* |
| 5593 | pixels[11].blue)+cy[3]*(cx[0]*pixels[12].blue+cx[1]*pixels[13].blue+ |
| 5594 | cx[2]*pixels[14].blue+cx[3]*pixels[15].blue)); |
nicolas | d32d5e5 | 2012-06-12 15:34:10 +0000 | [diff] [blame] | 5595 | if (image->colorspace == CMYKColorspace) |
cristy | fb12237 | 2012-10-17 23:31:21 +0000 | [diff] [blame] | 5596 | pixel->black=(cy[0]*(cx[0]*pixels[0].black+cx[1]*pixels[1].black+cx[2]* |
| 5597 | pixels[2].black+cx[3]*pixels[3].black)+cy[1]*(cx[0]*pixels[4].black+ |
| 5598 | cx[1]*pixels[5].black+cx[2]*pixels[6].black+cx[3]*pixels[7].black)+ |
| 5599 | cy[2]*(cx[0]*pixels[8].black+cx[1]*pixels[9].black+cx[2]* |
| 5600 | pixels[10].black+cx[3]*pixels[11].black)+cy[3]*(cx[0]* |
| 5601 | pixels[12].black+cx[1]*pixels[13].black+cx[2]*pixels[14].black+cx[3]* |
| 5602 | pixels[15].black)); |
| 5603 | pixel->alpha=(cy[0]*(cx[0]*pixels[0].alpha+cx[1]*pixels[1].alpha+cx[2]* |
| 5604 | pixels[2].alpha+cx[3]*pixels[3].alpha)+cy[1]*(cx[0]*pixels[4].alpha+ |
| 5605 | cx[1]*pixels[5].alpha+cx[2]*pixels[6].alpha+cx[3]*pixels[7].alpha)+ |
| 5606 | cy[2]*(cx[0]*pixels[8].alpha+cx[1]*pixels[9].alpha+cx[2]* |
| 5607 | pixels[10].alpha+cx[3]*pixels[11].alpha)+cy[3]*(cx[0]*pixels[12].alpha+ |
| 5608 | cx[1]*pixels[13].alpha+cx[2]*pixels[14].alpha+cx[3]*pixels[15].alpha)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5609 | break; |
| 5610 | } |
| 5611 | } |
| 5612 | return(status); |
| 5613 | } |
| 5614 | |
| 5615 | /* |
| 5616 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5617 | % % |
| 5618 | % % |
| 5619 | % % |
| 5620 | + I s F u z z y E q u i v a l e n c e P i x e l % |
| 5621 | % % |
| 5622 | % % |
| 5623 | % % |
| 5624 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5625 | % |
| 5626 | % IsFuzzyEquivalencePixel() returns MagickTrue if the distance between two |
| 5627 | % pixels is less than the specified distance in a linear three (or four)u |
| 5628 | % dimensional color space. |
| 5629 | % |
| 5630 | % The format of the IsFuzzyEquivalencePixel method is: |
| 5631 | % |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5632 | % void IsFuzzyEquivalencePixel(const Image *source,const Quantum *p, |
| 5633 | % const Image *destination,const Quantum *q) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5634 | % |
| 5635 | % A description of each parameter follows: |
| 5636 | % |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5637 | % o source: the source image. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5638 | % |
| 5639 | % o p: Pixel p. |
| 5640 | % |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5641 | % o destination: the destination image. |
| 5642 | % |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5643 | % o q: Pixel q. |
| 5644 | % |
| 5645 | */ |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5646 | MagickExport MagickBooleanType IsFuzzyEquivalencePixel(const Image *source, |
| 5647 | const Quantum *p,const Image *destination,const Quantum *q) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5648 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5649 | double |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5650 | fuzz, |
| 5651 | pixel; |
| 5652 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5653 | register double |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5654 | distance, |
| 5655 | scale; |
| 5656 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5657 | fuzz=MagickMax(source->fuzz,(double) MagickSQ1_2)*MagickMax( |
| 5658 | destination->fuzz,(double) MagickSQ1_2); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5659 | scale=1.0; |
| 5660 | distance=0.0; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5661 | if (source->alpha_trait == BlendPixelTrait) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5662 | { |
| 5663 | /* |
| 5664 | Transparencies are involved - set alpha distance |
| 5665 | */ |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5666 | pixel=GetPixelAlpha(source,p)-(double) |
cristy | 99abff3 | 2011-12-24 20:45:16 +0000 | [diff] [blame] | 5667 | GetPixelAlpha(destination,q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5668 | distance=pixel*pixel; |
| 5669 | if (distance > fuzz) |
| 5670 | return(MagickFalse); |
| 5671 | /* |
| 5672 | Generate a alpha scaling factor to generate a 4D cone on colorspace |
| 5673 | Note that if one color is transparent, distance has no color component. |
| 5674 | */ |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5675 | scale=QuantumScale*GetPixelAlpha(source,p); |
| 5676 | scale*=QuantumScale*GetPixelAlpha(destination,q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5677 | if (scale <= MagickEpsilon) |
| 5678 | return(MagickTrue); |
| 5679 | } |
| 5680 | /* |
| 5681 | RGB or CMY color cube |
| 5682 | */ |
| 5683 | distance*=3.0; /* rescale appropriately */ |
| 5684 | fuzz*=3.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5685 | pixel=GetPixelRed(source,p)-(double) GetPixelRed(destination,q); |
cristy | e4a4047 | 2011-12-22 02:56:19 +0000 | [diff] [blame] | 5686 | if ((source->colorspace == HSLColorspace) || |
| 5687 | (source->colorspace == HSBColorspace) || |
| 5688 | (source->colorspace == HWBColorspace)) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5689 | { |
| 5690 | /* |
| 5691 | Compute an arc distance for hue. It should be a vector angle of |
| 5692 | 'S'/'W' length with 'L'/'B' forming appropriate cones. |
| 5693 | */ |
| 5694 | if (fabs((double) pixel) > (QuantumRange/2)) |
| 5695 | pixel-=QuantumRange; |
| 5696 | pixel*=2; |
| 5697 | } |
| 5698 | distance+=scale*pixel*pixel; |
| 5699 | if (distance > fuzz) |
| 5700 | return(MagickFalse); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5701 | pixel=GetPixelGreen(source,p)-(double) GetPixelGreen(destination,q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5702 | distance+=scale*pixel*pixel; |
| 5703 | if (distance > fuzz) |
| 5704 | return(MagickFalse); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5705 | pixel=GetPixelBlue(source,p)-(double) GetPixelBlue(destination,q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5706 | distance+=scale*pixel*pixel; |
| 5707 | if (distance > fuzz) |
| 5708 | return(MagickFalse); |
| 5709 | return(MagickTrue); |
| 5710 | } |
| 5711 | |
| 5712 | /* |
| 5713 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5714 | % % |
| 5715 | % % |
| 5716 | % % |
| 5717 | + 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 % |
| 5718 | % % |
| 5719 | % % |
| 5720 | % % |
| 5721 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5722 | % |
| 5723 | % IsFuzzyEquivalencePixelInfo() returns true if the distance between two |
| 5724 | % colors is less than the specified distance in a linear three (or four) |
| 5725 | % dimensional color space. |
| 5726 | % |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5727 | % This implements the equivalent of: |
| 5728 | % fuzz < sqrt(color_distance^2 * u.a*v.a + alpha_distance^2) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5729 | % |
| 5730 | % Which produces a multi-dimensional cone for that colorspace along the |
| 5731 | % transparency vector. |
| 5732 | % |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5733 | % For example for an RGB: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5734 | % color_distance^2 = ( (u.r-v.r)^2 + (u.g-v.g)^2 + (u.b-v.b)^2 ) / 3 |
| 5735 | % |
| 5736 | % See http://www.imagemagick.org/Usage/bugs/fuzz_distance/ |
| 5737 | % |
| 5738 | % Hue colorspace distances need more work. Hue is not a distance, it is an |
| 5739 | % angle! |
| 5740 | % |
| 5741 | % A check that q is in the same color space as p should be made and the |
| 5742 | % appropriate mapping made. -- Anthony Thyssen 8 December 2010 |
| 5743 | % |
| 5744 | % The format of the IsFuzzyEquivalencePixelInfo method is: |
| 5745 | % |
| 5746 | % MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p, |
| 5747 | % const PixelInfo *q) |
| 5748 | % |
| 5749 | % A description of each parameter follows: |
| 5750 | % |
| 5751 | % o p: Pixel p. |
| 5752 | % |
| 5753 | % o q: Pixel q. |
| 5754 | % |
| 5755 | */ |
| 5756 | MagickExport MagickBooleanType IsFuzzyEquivalencePixelInfo(const PixelInfo *p, |
| 5757 | const PixelInfo *q) |
| 5758 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5759 | double |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5760 | fuzz, |
| 5761 | pixel; |
| 5762 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5763 | register double |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5764 | scale, |
| 5765 | distance; |
| 5766 | |
| 5767 | if ((p->fuzz == 0.0) && (q->fuzz == 0.0)) |
| 5768 | return(IsPixelInfoEquivalent(p,q)); |
| 5769 | if (p->fuzz == 0.0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5770 | fuzz=MagickMax(q->fuzz,(double) MagickSQ1_2)*MagickMax(q->fuzz, |
| 5771 | (double) MagickSQ1_2); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5772 | else if (q->fuzz == 0.0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5773 | fuzz=MagickMax(p->fuzz,(double) MagickSQ1_2)*MagickMax(p->fuzz, |
| 5774 | (double) MagickSQ1_2); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5775 | else |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5776 | fuzz=MagickMax(p->fuzz,(double) MagickSQ1_2)*MagickMax(q->fuzz, |
| 5777 | (double) MagickSQ1_2); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5778 | scale=1.0; |
| 5779 | distance=0.0; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5780 | if ((p->alpha_trait == BlendPixelTrait) || (q->alpha_trait == BlendPixelTrait)) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5781 | { |
| 5782 | /* |
| 5783 | Transparencies are involved - set alpha distance. |
| 5784 | */ |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5785 | pixel=(p->alpha_trait == BlendPixelTrait ? p->alpha : OpaqueAlpha)- |
| 5786 | (q->alpha_trait == BlendPixelTrait ? q->alpha : OpaqueAlpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5787 | distance=pixel*pixel; |
| 5788 | if (distance > fuzz) |
| 5789 | return(MagickFalse); |
| 5790 | /* |
| 5791 | Generate a alpha scaling factor to generate a 4D cone on colorspace. |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5792 | If one color is transparent, distance has no color component. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5793 | */ |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5794 | if (p->alpha_trait == BlendPixelTrait) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5795 | scale=(QuantumScale*p->alpha); |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5796 | if (q->alpha_trait == BlendPixelTrait) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5797 | scale*=(QuantumScale*q->alpha); |
| 5798 | if (scale <= MagickEpsilon ) |
| 5799 | return(MagickTrue); |
| 5800 | } |
| 5801 | /* |
| 5802 | CMYK create a CMY cube with a multi-dimensional cone toward black. |
| 5803 | */ |
| 5804 | if (p->colorspace == CMYKColorspace) |
| 5805 | { |
| 5806 | pixel=p->black-q->black; |
| 5807 | distance+=pixel*pixel*scale; |
| 5808 | if (distance > fuzz) |
| 5809 | return(MagickFalse); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5810 | scale*=(double) (QuantumScale*(QuantumRange-p->black)); |
| 5811 | scale*=(double) (QuantumScale*(QuantumRange-q->black)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5812 | } |
| 5813 | /* |
| 5814 | RGB or CMY color cube. |
| 5815 | */ |
| 5816 | distance*=3.0; /* rescale appropriately */ |
| 5817 | fuzz*=3.0; |
| 5818 | pixel=p->red-q->red; |
| 5819 | if ((p->colorspace == HSLColorspace) || (p->colorspace == HSBColorspace) || |
| 5820 | (p->colorspace == HWBColorspace)) |
| 5821 | { |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 5822 | /* |
| 5823 | This calculates a arc distance for hue-- it should be a vector angle |
| 5824 | of 'S'/'W' length with 'L'/'B' forming appropriate cones. In other |
| 5825 | words this is a hack - Anthony. |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5826 | */ |
| 5827 | if (fabs((double) pixel) > (QuantumRange/2)) |
| 5828 | pixel-=QuantumRange; |
| 5829 | pixel*=2; |
| 5830 | } |
| 5831 | distance+=pixel*pixel*scale; |
| 5832 | if (distance > fuzz) |
| 5833 | return(MagickFalse); |
| 5834 | pixel=p->green-q->green; |
| 5835 | distance+=pixel*pixel*scale; |
| 5836 | if (distance > fuzz) |
| 5837 | return(MagickFalse); |
| 5838 | pixel=p->blue-q->blue; |
| 5839 | distance+=pixel*pixel*scale; |
| 5840 | if (distance > fuzz) |
| 5841 | return(MagickFalse); |
| 5842 | return(MagickTrue); |
| 5843 | } |
| 5844 | |
| 5845 | /* |
| 5846 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5847 | % % |
| 5848 | % % |
| 5849 | % % |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 5850 | % 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] | 5851 | % % |
| 5852 | % % |
| 5853 | % % |
| 5854 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5855 | % |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 5856 | % SetPixelChannelMask() sets the pixel channel map from the specified |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 5857 | % channel mask. |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5858 | % |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 5859 | % The format of the SetPixelChannelMask method is: |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5860 | % |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 5861 | % void SetPixelChannelMask(Image *image,const ChannelType channel_mask) |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5862 | % |
| 5863 | % A description of each parameter follows: |
| 5864 | % |
| 5865 | % o image: the image. |
| 5866 | % |
cristy | dfdb19e | 2012-03-21 22:22:24 +0000 | [diff] [blame] | 5867 | % o channel_mask: the channel mask. |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5868 | % |
| 5869 | */ |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 5870 | MagickExport void SetPixelChannelMask(Image *image, |
cristy | 07a6785 | 2011-08-26 13:25:03 +0000 | [diff] [blame] | 5871 | const ChannelType channel_mask) |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5872 | { |
cristy | 6a917d6 | 2011-08-24 17:31:30 +0000 | [diff] [blame] | 5873 | #define GetChannelBit(mask,bit) (((size_t) (mask) >> (size_t) (bit)) & 0x01) |
cristy | dafd287 | 2011-07-24 22:06:13 +0000 | [diff] [blame] | 5874 | |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5875 | register ssize_t |
| 5876 | i; |
| 5877 | |
cristy | 177e41c | 2012-04-15 15:08:25 +0000 | [diff] [blame] | 5878 | if (image->debug != MagickFalse) |
| 5879 | (void) LogMagickEvent(PixelEvent,GetMagickModule(),"%s[%08x]", \ |
| 5880 | image->filename,channel_mask); \ |
cristy | 3c30981 | 2011-11-08 02:40:43 +0000 | [diff] [blame] | 5881 | image->channel_mask=channel_mask; |
cristy | dafd287 | 2011-07-24 22:06:13 +0000 | [diff] [blame] | 5882 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 5883 | { |
| 5884 | PixelChannel |
| 5885 | channel; |
| 5886 | |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 5887 | channel=GetPixelChannelChannel(image,i); |
cristy | 297e3a4 | 2012-08-26 21:27:29 +0000 | [diff] [blame] | 5888 | SetPixelChannelTraits(image,channel, |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 5889 | GetChannelBit(channel_mask,channel) == 0 ? CopyPixelTrait : |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5890 | image->alpha_trait != BlendPixelTrait || (channel == AlphaPixelChannel) ? |
| 5891 | UpdatePixelTrait : (PixelTrait) (UpdatePixelTrait | image->alpha_trait)); |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 5892 | } |
cristy | 1685e72 | 2011-09-06 00:04:19 +0000 | [diff] [blame] | 5893 | if (image->storage_class == PseudoClass) |
cristy | 297e3a4 | 2012-08-26 21:27:29 +0000 | [diff] [blame] | 5894 | SetPixelChannelTraits(image,IndexPixelChannel,CopyPixelTrait); |
cristy | 183a5c7 | 2012-01-30 01:40:35 +0000 | [diff] [blame] | 5895 | if (image->mask != MagickFalse) |
cristy | 297e3a4 | 2012-08-26 21:27:29 +0000 | [diff] [blame] | 5896 | SetPixelChannelTraits(image,MaskPixelChannel,CopyPixelTrait); |
cristy | 6dcb9b8 | 2011-10-23 23:21:25 +0000 | [diff] [blame] | 5897 | if (image->debug != MagickFalse) |
| 5898 | LogPixelChannels(image); |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 5899 | } |
| 5900 | |
| 5901 | /* |
| 5902 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5903 | % % |
| 5904 | % % |
| 5905 | % % |
cristy | 322d07d | 2012-03-18 21:17:23 +0000 | [diff] [blame] | 5906 | % S e t P i x e l M e t a C h a n n e l s % |
| 5907 | % % |
| 5908 | % % |
| 5909 | % % |
| 5910 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5911 | % |
| 5912 | % SetPixelMetaChannels() sets the image meta channels. |
| 5913 | % |
| 5914 | % The format of the SetPixelMetaChannels method is: |
| 5915 | % |
| 5916 | % MagickBooleanType SetPixelMetaChannels(Image *image, |
| 5917 | % const size_t number_meta_channels,ExceptionInfo *exception) |
| 5918 | % |
| 5919 | % A description of each parameter follows: |
| 5920 | % |
| 5921 | % o image: the image. |
| 5922 | % |
| 5923 | % o number_meta_channels: the number of meta channels. |
| 5924 | % |
| 5925 | % o exception: return any errors or warnings in this structure. |
| 5926 | % |
| 5927 | */ |
| 5928 | MagickExport MagickBooleanType SetPixelMetaChannels(Image *image, |
| 5929 | const size_t number_meta_channels,ExceptionInfo *exception) |
| 5930 | { |
| 5931 | image->number_meta_channels=number_meta_channels; |
| 5932 | return(SyncImagePixelCache(image,exception)); |
| 5933 | } |