| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | #include "magick/studio.h" |
|---|
| 44 | #include "magick/blob.h" |
|---|
| 45 | #include "magick/blob-private.h" |
|---|
| 46 | #include "magick/cache.h" |
|---|
| 47 | #include "magick/cache-private.h" |
|---|
| 48 | #include "magick/color-private.h" |
|---|
| 49 | #include "magick/composite-private.h" |
|---|
| 50 | #include "magick/exception.h" |
|---|
| 51 | #include "magick/exception-private.h" |
|---|
| 52 | #include "magick/list.h" |
|---|
| 53 | #include "magick/log.h" |
|---|
| 54 | #include "magick/magick.h" |
|---|
| 55 | #include "magick/memory_.h" |
|---|
| 56 | #include "magick/pixel-private.h" |
|---|
| 57 | #include "magick/quantum.h" |
|---|
| 58 | #include "magick/random_.h" |
|---|
| 59 | #include "magick/resource_.h" |
|---|
| 60 | #include "magick/semaphore.h" |
|---|
| 61 | #include "magick/splay-tree.h" |
|---|
| 62 | #include "magick/string_.h" |
|---|
| 63 | #include "magick/utility.h" |
|---|
| 64 | #if defined(MAGICKCORE_ZLIB_DELEGATE) |
|---|
| 65 | #include "zlib.h" |
|---|
| 66 | #endif |
|---|
| 67 | #if defined(MAGICKCORE_HAVE_PTHREAD) |
|---|
| 68 | #include <pthread.h> |
|---|
| 69 | #endif |
|---|
| 70 | #if defined(__WINDOWS__) |
|---|
| 71 | #include <windows.h> |
|---|
| 72 | #endif |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | #define CacheViewReserve 256 |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | struct _NexusInfo |
|---|
| 83 | { |
|---|
| 84 | Â MagickBooleanType |
|---|
| 85 | Â Â reserve, |
|---|
| 86 | Â Â mapped; |
|---|
| 87 | |
|---|
| 88 |  unsigned long |
|---|
| 89 | Â Â columns, |
|---|
| 90 | Â Â rows; |
|---|
| 91 | |
|---|
| 92 | Â long |
|---|
| 93 | Â Â x, |
|---|
| 94 | Â Â y; |
|---|
| 95 | |
|---|
| 96 | Â MagickSizeType |
|---|
| 97 | Â Â length; |
|---|
| 98 | |
|---|
| 99 | Â PixelPacket |
|---|
| 100 | Â Â *cache, |
|---|
| 101 | Â Â *pixels; |
|---|
| 102 | |
|---|
| 103 | Â IndexPacket |
|---|
| 104 | Â Â *indexes; |
|---|
| 105 | }; |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | #if defined(__cplusplus) || defined(c_plusplus) |
|---|
| 111 | extern "C" { |
|---|
| 112 | #endif |
|---|
| 113 | |
|---|
| 114 | static const PixelPacket |
|---|
| 115 |  *AcquirePixelCache(const Image *,const VirtualPixelMethod,const long, |
|---|
| 116 |   const long,const unsigned long,const unsigned long,ExceptionInfo *); |
|---|
| 117 | |
|---|
| 118 | static IndexPacket |
|---|
| 119 |  *GetIndexesFromCache(const Image *); |
|---|
| 120 | |
|---|
| 121 | static MagickBooleanType |
|---|
| 122 |  OpenCache(Image *,const MapMode,ExceptionInfo *), |
|---|
| 123 | Â SyncCache(Image *), |
|---|
| 124 | Â SyncPixelCache(Image *); |
|---|
| 125 | |
|---|
| 126 | static PixelPacket |
|---|
| 127 |  AcquireOnePixelFromCache(const Image *,const VirtualPixelMethod,const long, |
|---|
| 128 |   const long,ExceptionInfo *), |
|---|
| 129 |  GetOnePixelFromCache(Image *,const long,const long), |
|---|
| 130 |  *GetPixelCache(Image *,const long,const long,const unsigned long, |
|---|
| 131 |   const unsigned long), |
|---|
| 132 |  *GetPixelsFromCache(const Image *), |
|---|
| 133 |  *SetPixelCache(Image *,const long,const long,const unsigned long, |
|---|
| 134 |   const unsigned long); |
|---|
| 135 | |
|---|
| 136 | static void |
|---|
| 137 | Â DestroyPixelCache(Image *); |
|---|
| 138 | |
|---|
| 139 | #if defined(__cplusplus) || defined(c_plusplus) |
|---|
| 140 | } |
|---|
| 141 | #endif |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | static PixelPacket |
|---|
| 147 |  *SetNexus(const Image *,const RectangleInfo *,const unsigned long); |
|---|
| 148 | |
|---|
| 149 | static MagickBooleanType |
|---|
| 150 |  ReadCacheIndexes(CacheInfo *,const unsigned long,ExceptionInfo *), |
|---|
| 151 |  ReadCachePixels(CacheInfo *,const unsigned long,ExceptionInfo *), |
|---|
| 152 |  WriteCacheIndexes(CacheInfo *,const unsigned long,ExceptionInfo *), |
|---|
| 153 |  WriteCachePixels(CacheInfo *,const unsigned long,ExceptionInfo *); |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | static MagickSizeType |
|---|
| 159 | Â serial_number = 0; |
|---|
| 160 | |
|---|
| 161 | static SemaphoreInfo |
|---|
| 162 | Â *cache_semaphore = (SemaphoreInfo *) NULL; |
|---|
| 163 | |
|---|
| 164 | static SplayTreeInfo |
|---|
| 165 | Â *cache_resources = (SplayTreeInfo *) NULL; |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | static long |
|---|
| 205 | Â DitherMatrix[64] = |
|---|
| 206 | Â { |
|---|
| 207 |    0, 48, 12, 60,  3, 51, 15, 63, |
|---|
| 208 |   32, 16, 44, 28, 35, 19, 47, 31, |
|---|
| 209 |    8, 56,  4, 52, 11, 59,  7, 55, |
|---|
| 210 |   40, 24, 36, 20, 43, 27, 39, 23, |
|---|
| 211 |    2, 50, 14, 62,  1, 49, 13, 61, |
|---|
| 212 |   34, 18, 46, 30, 33, 17, 45, 29, |
|---|
| 213 |   10, 58,  6, 54,  9, 57,  5, 53, |
|---|
| 214 |   42, 26, 38, 22, 41, 25, 37, 21 |
|---|
| 215 | Â }; |
|---|
| 216 | |
|---|
| 217 | static inline long DitherX(const unsigned long columns,const long x) |
|---|
| 218 | { |
|---|
| 219 | Â long |
|---|
| 220 | Â Â index; |
|---|
| 221 | |
|---|
| 222 | Â index=x+DitherMatrix[x & 0x07]-32L; |
|---|
| 223 |  if (index < 0L) |
|---|
| 224 | Â Â return(0L); |
|---|
| 225 |  if (index >= (long) columns) |
|---|
| 226 | Â Â return((long) columns-1L); |
|---|
| 227 | Â return(index); |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | static inline long DitherY(const unsigned long rows,const long y) |
|---|
| 231 | { |
|---|
| 232 | Â long |
|---|
| 233 | Â Â index; |
|---|
| 234 | |
|---|
| 235 | Â index=y+DitherMatrix[y & 0x07]-32L; |
|---|
| 236 |  if (index < 0L) |
|---|
| 237 | Â Â return(0L); |
|---|
| 238 |  if (index >= (long) rows) |
|---|
| 239 | Â Â return((long) rows-1L); |
|---|
| 240 | Â return(index); |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | static inline long EdgeX(const unsigned long columns,const long x) |
|---|
| 244 | { |
|---|
| 245 |  if (x < 0L) |
|---|
| 246 | Â Â return(0L); |
|---|
| 247 |  if (x >= (long) columns) |
|---|
| 248 | Â Â return((long) columns-1L); |
|---|
| 249 | Â return(x); |
|---|
| 250 | } |
|---|
| 251 | |
|---|
| 252 | static inline long EdgeY(const unsigned long rows,const long y) |
|---|
| 253 | { |
|---|
| 254 |  if (y < 0L) |
|---|
| 255 | Â Â return(0L); |
|---|
| 256 |  if (y >= (long) rows) |
|---|
| 257 | Â Â return((long) rows-1L); |
|---|
| 258 | Â return(y); |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | static inline MagickSizeType MagickMax(const MagickSizeType x, |
|---|
| 262 |  const MagickSizeType y) |
|---|
| 263 | { |
|---|
| 264 |  if (x > y) |
|---|
| 265 | Â Â return(x); |
|---|
| 266 | Â return(y); |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | static inline MagickSizeType MagickMin(const MagickSizeType x, |
|---|
| 270 |  const MagickSizeType y) |
|---|
| 271 | { |
|---|
| 272 |  if (x < y) |
|---|
| 273 | Â Â return(x); |
|---|
| 274 | Â return(y); |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | static inline long RandomX(const unsigned long columns) |
|---|
| 279 | { |
|---|
| 280 | Â long |
|---|
| 281 | Â Â x; |
|---|
| 282 | |
|---|
| 283 | Â x=(long) (columns*GetPseudoRandomValue()+0.5); |
|---|
| 284 |  if (x >= (long) columns) |
|---|
| 285 | Â Â return((long) columns-1L); |
|---|
| 286 | Â return(x); |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | static inline long RandomY(const unsigned long rows) |
|---|
| 290 | { |
|---|
| 291 | Â long |
|---|
| 292 | Â Â y; |
|---|
| 293 | |
|---|
| 294 | Â y=(long) (rows*GetPseudoRandomValue()+0.5); |
|---|
| 295 |  if (y >= (long) rows) |
|---|
| 296 | Â Â return((long) rows-1L); |
|---|
| 297 | Â return(y); |
|---|
| 298 | } |
|---|
| 299 | |
|---|
| 300 | static inline long TileX(const unsigned long columns,const long x) |
|---|
| 301 | { |
|---|
| 302 |  if (x < 0L) |
|---|
| 303 | Â Â return((long) columns+((x+1) % (long) columns)-1); |
|---|
| 304 |  if (x >= (long) columns) |
|---|
| 305 | Â Â return(x % (long) columns); |
|---|
| 306 | Â return(x); |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | static inline long TileY(const unsigned long rows,const long y) |
|---|
| 310 | { |
|---|
| 311 |  if (y < 0L) |
|---|
| 312 | Â Â return((long) rows+((y+1) % (long) rows)-1L); |
|---|
| 313 |  if (y >= (long) rows) |
|---|
| 314 | Â Â return(y % (long) rows); |
|---|
| 315 | Â return(y); |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | static inline long MirrorX(const unsigned long columns,const long x) |
|---|
| 319 | { |
|---|
| 320 |  if ((x < 0) || (x >= (long) columns)) |
|---|
| 321 | Â Â return((long) columns-TileX(columns,x)-1L); |
|---|
| 322 | Â return(x); |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | static inline long MirrorY(const unsigned long rows,const long y) |
|---|
| 326 | { |
|---|
| 327 |  if ((y < 0) || (y >= (long) rows)) |
|---|
| 328 | Â Â return((long) rows-TileX(rows,y)-1L); |
|---|
| 329 | Â return(y); |
|---|
| 330 | } |
|---|
| 331 | |
|---|
| 332 | static inline MagickBooleanType IsNexusInCore(const CacheInfo *cache_info, |
|---|
| 333 |  const unsigned long nexus) |
|---|
| 334 | { |
|---|
| 335 | Â MagickOffsetType |
|---|
| 336 | Â Â offset; |
|---|
| 337 | |
|---|
| 338 |  register NexusInfo |
|---|
| 339 | Â Â *nexus_info; |
|---|
| 340 | |
|---|
| 341 | Â nexus_info=cache_info->nexus_info+nexus; |
|---|
| 342 | Â offset=(MagickOffsetType) nexus_info->y*cache_info->columns+nexus_info->x; |
|---|
| 343 |  if (nexus_info->pixels != (cache_info->pixels+offset)) |
|---|
| 344 | Â Â return(MagickFalse); |
|---|
| 345 | Â return(MagickTrue); |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | MagickExport const PixelPacket *AcquireCacheNexus(const Image *image, |
|---|
| 349 |  const VirtualPixelMethod virtual_pixel_method,const long x,const long y, |
|---|
| 350 |  const unsigned long columns,const unsigned long rows, |
|---|
| 351 |  const unsigned long nexus,ExceptionInfo *exception) |
|---|
| 352 | { |
|---|
| 353 | Â CacheInfo |
|---|
| 354 | Â Â *cache_info; |
|---|
| 355 | |
|---|
| 356 | Â IndexPacket |
|---|
| 357 | Â Â *indexes, |
|---|
| 358 | Â Â *nexus_indexes; |
|---|
| 359 | |
|---|
| 360 | Â MagickOffsetType |
|---|
| 361 | Â Â offset; |
|---|
| 362 | |
|---|
| 363 | Â MagickSizeType |
|---|
| 364 | Â Â length, |
|---|
| 365 | Â Â number_pixels; |
|---|
| 366 | |
|---|
| 367 | Â PixelPacket |
|---|
| 368 | Â Â *pixels; |
|---|
| 369 | |
|---|
| 370 | Â RectangleInfo |
|---|
| 371 | Â Â region; |
|---|
| 372 | |
|---|
| 373 |  register const PixelPacket |
|---|
| 374 | Â Â *p; |
|---|
| 375 | |
|---|
| 376 |  register long |
|---|
| 377 | Â Â u, |
|---|
| 378 | Â Â v; |
|---|
| 379 | |
|---|
| 380 |  register PixelPacket |
|---|
| 381 | Â Â *q; |
|---|
| 382 | |
|---|
| 383 |  unsigned long |
|---|
| 384 | Â Â virtual_nexus; |
|---|
| 385 | |
|---|
| 386 | Â |
|---|
| 387 | |
|---|
| 388 | |
|---|
| 389 |  assert(image != (const Image *) NULL); |
|---|
| 390 | Â assert(image->signature == MagickSignature); |
|---|
| 391 |  if (image->debug != MagickFalse) |
|---|
| 392 | Â Â (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 393 | Â assert(image->cache != (Cache) NULL); |
|---|
| 394 | Â cache_info=(CacheInfo *) image->cache; |
|---|
| 395 |  if (cache_info->type == UndefinedCache) |
|---|
| 396 |   return((const PixelPacket *) NULL); |
|---|
| 397 | Â region.x=x; |
|---|
| 398 | Â region.y=y; |
|---|
| 399 | Â region.width=columns; |
|---|
| 400 | Â region.height=rows; |
|---|
| 401 | Â pixels=SetNexus(image,®ion,nexus); |
|---|
| 402 |  if (pixels == (PixelPacket *) NULL) |
|---|
| 403 |   return((const PixelPacket *) NULL); |
|---|
| 404 | Â offset=(MagickOffsetType) region.y*cache_info->columns+region.x; |
|---|
| 405 | Â length=(MagickSizeType) (region.height-1)*cache_info->columns+region.width-1; |
|---|
| 406 | Â number_pixels=(MagickSizeType) cache_info->columns*cache_info->rows; |
|---|
| 407 |  if ((offset >= 0) && (((MagickSizeType) offset+length) < number_pixels)) |
|---|
| 408 |   if ((x >= 0) && ((long) (x+columns) <= (long) cache_info->columns) && |
|---|
| 409 | Â Â Â Â (y >= 0) && ((long) (y+rows) <= (long) cache_info->rows)) |
|---|
| 410 | Â Â Â { |
|---|
| 411 | Â Â Â Â |
|---|
| 412 | |
|---|
| 413 | |
|---|
| 414 |     if (IsNexusInCore(cache_info,nexus) != MagickFalse) |
|---|
| 415 | Â Â Â Â Â return(pixels); |
|---|
| 416 |     if (ReadCachePixels(cache_info,nexus,exception) == MagickFalse) |
|---|
| 417 |      return((const PixelPacket *) NULL); |
|---|
| 418 |     if ((cache_info->storage_class == PseudoClass) || |
|---|
| 419 | Â Â Â Â Â Â (cache_info->colorspace == CMYKColorspace)) |
|---|
| 420 |      if (ReadCacheIndexes(cache_info,nexus,exception) == MagickFalse) |
|---|
| 421 |       return((const PixelPacket *) NULL); |
|---|
| 422 | Â Â Â Â return(pixels); |
|---|
| 423 | Â Â Â } |
|---|
| 424 | Â |
|---|
| 425 | |
|---|
| 426 | |
|---|
| 427 | Â q=pixels; |
|---|
| 428 | Â indexes=GetNexusIndexes(cache_info,nexus); |
|---|
| 429 | Â virtual_nexus=GetNexus(cache_info); |
|---|
| 430 |  if (virtual_nexus == 0) |
|---|
| 431 | Â Â { |
|---|
| 432 | Â Â Â (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
|---|
| 433 | Â Â Â Â "UnableToGetCacheNexus","`%s'",image->filename); |
|---|
| 434 |    return((const PixelPacket *) NULL); |
|---|
| 435 | Â Â } |
|---|
| 436 |  for (v=0; v < (long) rows; v++) |
|---|
| 437 | Â { |
|---|
| 438 |   for (u=0; u < (long) columns; u+=length) |
|---|
| 439 | Â Â { |
|---|
| 440 | Â Â Â length=(MagickSizeType) MagickMin(cache_info->columns-(x+u),columns-u); |
|---|
| 441 |    if ((((x+u) < 0) || ((x+u) >= (long) cache_info->columns)) || |
|---|
| 442 | Â Â Â Â Â (((y+v) < 0) || ((y+v) >= (long) cache_info->rows)) || (length == 0)) |
|---|
| 443 | Â Â Â Â { |
|---|
| 444 | Â Â Â Â Â |
|---|
| 445 | |
|---|
| 446 | |
|---|
| 447 | Â Â Â Â Â length=(MagickSizeType) 1; |
|---|
| 448 |      switch (virtual_pixel_method) |
|---|
| 449 | Â Â Â Â Â { |
|---|
| 450 |       case BackgroundVirtualPixelMethod: |
|---|
| 451 |       case ConstantVirtualPixelMethod: |
|---|
| 452 | Â Â Â Â Â Â { |
|---|
| 453 | Â Â Â Â Â Â Â p=AcquireCacheNexus(image,virtual_pixel_method, |
|---|
| 454 | Â Â Â Â Â Â Â Â EdgeX(cache_info->columns,x+u),EdgeY(cache_info->rows,y+v), |
|---|
| 455 | Â Â Â Â Â Â Â Â 1UL,1UL,virtual_nexus,exception); |
|---|
| 456 | Â Â Â Â Â Â Â cache_info->virtual_pixel=image->background_color; |
|---|
| 457 | Â Â Â Â Â Â Â p=(&cache_info->virtual_pixel); |
|---|
| 458 | Â Â Â Â Â Â Â break; |
|---|
| 459 | Â Â Â Â Â Â } |
|---|
| 460 |       case BlackVirtualPixelMethod: |
|---|
| 461 | Â Â Â Â Â Â { |
|---|
| 462 | Â Â Â Â Â Â Â p=AcquireCacheNexus(image,virtual_pixel_method, |
|---|
| 463 | Â Â Â Â Â Â Â Â EdgeX(cache_info->columns,x+u),EdgeY(cache_info->rows,y+v), |
|---|
| 464 | Â Â Â Â Â Â Â Â 1UL,1UL,virtual_nexus,exception); |
|---|
| 465 | Â Â Â Â Â Â Â cache_info->virtual_pixel.red=0; |
|---|
| 466 | Â Â Â Â Â Â Â cache_info->virtual_pixel.green=0; |
|---|
| 467 | Â Â Â Â Â Â Â cache_info->virtual_pixel.blue=0; |
|---|
| 468 | Â Â Â Â Â Â Â cache_info->virtual_pixel.opacity=OpaqueOpacity; |
|---|
| 469 | Â Â Â Â Â Â Â p=(&cache_info->virtual_pixel); |
|---|
| 470 | Â Â Â Â Â Â Â break; |
|---|
| 471 | Â Â Â Â Â Â } |
|---|
| 472 |       case DitherVirtualPixelMethod: |
|---|
| 473 | Â Â Â Â Â Â { |
|---|
| 474 | Â Â Â Â Â Â Â p=AcquireCacheNexus(image,virtual_pixel_method, |
|---|
| 475 | Â Â Â Â Â Â Â Â DitherX(cache_info->columns,x+u),DitherY(cache_info->rows,y+v), |
|---|
| 476 | Â Â Â Â Â Â Â Â 1UL,1UL,virtual_nexus,exception); |
|---|
| 477 | Â Â Â Â Â Â Â break; |
|---|
| 478 | Â Â Â Â Â Â } |
|---|
| 479 |       case EdgeVirtualPixelMethod: |
|---|
| 480 | Â Â Â Â Â Â default: |
|---|
| 481 | Â Â Â Â Â Â { |
|---|
| 482 | Â Â Â Â Â Â Â p=AcquireCacheNexus(image,virtual_pixel_method, |
|---|
| 483 | Â Â Â Â Â Â Â Â EdgeX(cache_info->columns,x+u),EdgeY(cache_info->rows,y+v), |
|---|
| 484 | Â Â Â Â Â Â Â Â 1UL,1UL,virtual_nexus,exception); |
|---|
| 485 | Â Â Â Â Â Â Â break; |
|---|
| 486 | Â Â Â Â Â Â } |
|---|
| 487 |       case GrayVirtualPixelMethod: |
|---|
| 488 | Â Â Â Â Â Â { |
|---|
| 489 | Â Â Â Â Â Â Â p=AcquireCacheNexus(image,virtual_pixel_method, |
|---|
| 490 | Â Â Â Â Â Â Â Â EdgeX(cache_info->columns,x+u),EdgeY(cache_info->rows,y+v), |
|---|
| 491 | Â Â Â Â Â Â Â Â 1UL,1UL,virtual_nexus,exception); |
|---|
| 492 | Â Â Â Â Â Â Â cache_info->virtual_pixel.red=(Quantum) QuantumRange/2; |
|---|
| 493 | Â Â Â Â Â Â Â cache_info->virtual_pixel.green=(Quantum) QuantumRange/2; |
|---|
| 494 | Â Â Â Â Â Â Â cache_info->virtual_pixel.blue=(Quantum) QuantumRange/2; |
|---|
| 495 | Â Â Â Â Â Â Â cache_info->virtual_pixel.opacity=(Quantum) OpaqueOpacity; |
|---|
| 496 | Â Â Â Â Â Â Â p=(&cache_info->virtual_pixel); |
|---|
| 497 | Â Â Â Â Â Â Â break; |
|---|
| 498 | Â Â Â Â Â Â } |
|---|
| 499 |       case HorizontalTileVirtualPixelMethod: |
|---|
| 500 | Â Â Â Â Â Â { |
|---|
| 501 | Â Â Â Â Â Â Â p=AcquireCacheNexus(image,virtual_pixel_method, |
|---|
| 502 | Â Â Â Â Â Â Â Â TileX(cache_info->columns,x+u),TileY(cache_info->rows,y+v), |
|---|
| 503 | Â Â Â Â Â Â Â Â 1UL,1UL,virtual_nexus,exception); |
|---|
| 504 |        if (((y+v) < 0) || ((y+v) >= (long) cache_info->rows)) |
|---|
| 505 | Â Â Â Â Â Â Â Â { |
|---|
| 506 | Â Â Â Â Â Â Â Â Â cache_info->virtual_pixel=image->background_color; |
|---|
| 507 | Â Â Â Â Â Â Â Â Â p=(&cache_info->virtual_pixel); |
|---|
| 508 | Â Â Â Â Â Â Â Â } |
|---|
| 509 | Â Â Â Â Â Â Â break; |
|---|
| 510 | Â Â Â Â Â Â } |
|---|
| 511 |       case MirrorVirtualPixelMethod: |
|---|
| 512 | Â Â Â Â Â Â { |
|---|
| 513 | Â Â Â Â Â Â Â p=AcquireCacheNexus(image,virtual_pixel_method, |
|---|
| 514 | Â Â Â Â Â Â Â Â MirrorX(cache_info->columns,x+u),MirrorY(cache_info->rows,y+v), |
|---|
| 515 | Â Â Â Â Â Â Â Â 1UL,1UL,virtual_nexus,exception); |
|---|
| 516 | Â Â Â Â Â Â Â break; |
|---|
| 517 | Â Â Â Â Â Â } |
|---|
| 518 |       case RandomVirtualPixelMethod: |
|---|
| 519 | Â Â Â Â Â Â { |
|---|
| 520 | Â Â Â Â Â Â Â p=AcquireCacheNexus(image,virtual_pixel_method, |
|---|
| 521 | Â Â Â Â Â Â Â Â RandomX(cache_info->columns),RandomY(cache_info->rows), |
|---|
| 522 | Â Â Â Â Â Â Â Â 1UL,1UL,virtual_nexus,exception); |
|---|
| 523 | Â Â Â Â Â Â Â break; |
|---|
| 524 | Â Â Â Â Â Â } |
|---|
| 525 |       case TileVirtualPixelMethod: |
|---|
| 526 | Â Â Â Â Â Â { |
|---|
| 527 | Â Â Â Â Â Â Â p=AcquireCacheNexus(image,virtual_pixel_method, |
|---|
| 528 | Â Â Â Â Â Â Â Â TileX(cache_info->columns,x+u),TileY(cache_info->rows,y+v), |
|---|
| 529 | Â Â Â Â Â Â Â Â 1UL,1UL,virtual_nexus,exception); |
|---|
| 530 | Â Â Â Â Â Â Â break; |
|---|
| 531 | Â Â Â Â Â Â } |
|---|
| 532 |       case TransparentVirtualPixelMethod: |
|---|
| 533 | Â Â Â Â Â Â { |
|---|
| 534 | Â Â Â Â Â Â Â p=AcquireCacheNexus(image,virtual_pixel_method, |
|---|
| 535 | Â Â Â Â Â Â Â Â EdgeX(cache_info->columns,x+u),EdgeY(cache_info->rows,y+v), |
|---|
| 536 | Â Â Â Â Â Â Â Â 1UL,1UL,virtual_nexus,exception); |
|---|
| 537 | Â Â Â Â Â Â Â cache_info->virtual_pixel.red=(Quantum) 0; |
|---|
| 538 | Â Â Â Â Â Â Â cache_info->virtual_pixel.green=(Quantum) 0; |
|---|
| 539 | Â Â Â Â Â Â Â cache_info->virtual_pixel.blue=(Quantum) 0; |
|---|
| 540 | Â Â Â Â Â Â Â cache_info->virtual_pixel.opacity=(Quantum) TransparentOpacity; |
|---|
| 541 | Â Â Â Â Â Â Â p=(&cache_info->virtual_pixel); |
|---|
| 542 | Â Â Â Â Â Â Â break; |
|---|
| 543 | Â Â Â Â Â Â } |
|---|
| 544 |       case VerticalTileVirtualPixelMethod: |
|---|
| 545 | Â Â Â Â Â Â { |
|---|
| 546 | Â Â Â Â Â Â Â p=AcquireCacheNexus(image,virtual_pixel_method, |
|---|
| 547 | Â Â Â Â Â Â Â Â TileX(cache_info->columns,x+u),TileY(cache_info->rows,y+v), |
|---|
| 548 | Â Â Â Â Â Â Â Â 1UL,1UL,virtual_nexus,exception); |
|---|
| 549 |        if (((x+u) < 0) || ((x+u) >= (long) cache_info->columns)) |
|---|
| 550 | Â Â Â Â Â Â Â Â { |
|---|
| 551 | Â Â Â Â Â Â Â Â Â cache_info->virtual_pixel=image->background_color; |
|---|
| 552 | Â Â Â Â Â Â Â Â Â p=(&cache_info->virtual_pixel); |
|---|
| 553 | Â Â Â Â Â Â Â Â } |
|---|
| 554 | Â Â Â Â Â Â Â break; |
|---|
| 555 | Â Â Â Â Â Â } |
|---|
| 556 |       case MaskVirtualPixelMethod: |
|---|
| 557 |       case WhiteVirtualPixelMethod: |
|---|
| 558 | Â Â Â Â Â Â { |
|---|
| 559 | Â Â Â Â Â Â Â p=AcquireCacheNexus(image,virtual_pixel_method, |
|---|
| 560 | Â Â Â Â Â Â Â Â EdgeX(cache_info->columns,x+u),EdgeY(cache_info->rows,y+v), |
|---|
| 561 | Â Â Â Â Â Â Â Â 1UL,1UL,virtual_nexus,exception); |
|---|
| 562 | Â Â Â Â Â Â Â cache_info->virtual_pixel.red=(Quantum) QuantumRange; |
|---|
| 563 | Â Â Â Â Â Â Â cache_info->virtual_pixel.green=(Quantum) QuantumRange; |
|---|
| 564 | Â Â Â Â Â Â Â cache_info->virtual_pixel.blue=(Quantum) QuantumRange; |
|---|
| 565 | Â Â Â Â Â Â Â cache_info->virtual_pixel.opacity=OpaqueOpacity; |
|---|
| 566 | Â Â Â Â Â Â Â p=(&cache_info->virtual_pixel); |
|---|
| 567 | Â Â Â Â Â Â Â break; |
|---|
| 568 | Â Â Â Â Â Â } |
|---|
| 569 | Â Â Â Â Â } |
|---|
| 570 |      if (p == (const PixelPacket *) NULL) |
|---|
| 571 | Â Â Â Â Â Â break; |
|---|
| 572 | Â Â Â Â Â *q++=(*p); |
|---|
| 573 |      if (indexes != (IndexPacket *) NULL) |
|---|
| 574 | Â Â Â Â Â Â { |
|---|
| 575 | Â Â Â Â Â Â Â nexus_indexes=GetNexusIndexes(cache_info,virtual_nexus); |
|---|
| 576 |        if (nexus_indexes != (IndexPacket *) NULL) |
|---|
| 577 | Â Â Â Â Â Â Â Â *indexes++=(*nexus_indexes); |
|---|
| 578 | Â Â Â Â Â Â } |
|---|
| 579 | Â Â Â Â Â continue; |
|---|
| 580 | Â Â Â Â } |
|---|
| 581 | Â Â Â |
|---|
| 582 | |
|---|
| 583 | |
|---|
| 584 |    p=AcquireCacheNexus(image,virtual_pixel_method,x+u,y+v,(unsigned long) |
|---|
| 585 | Â Â Â Â length,1UL,virtual_nexus,exception); |
|---|
| 586 |    if (p == (const PixelPacket *) NULL) |
|---|
| 587 | Â Â Â Â break; |
|---|
| 588 | Â Â Â (void) CopyMagickMemory(q,p,(size_t) length*sizeof(*q)); |
|---|
| 589 | Â Â Â q+=length; |
|---|
| 590 |    if (indexes != (IndexPacket *) NULL) |
|---|
| 591 | Â Â Â Â { |
|---|
| 592 | Â Â Â Â Â nexus_indexes=GetNexusIndexes(cache_info,virtual_nexus); |
|---|
| 593 |      if (nexus_indexes != (IndexPacket *) NULL) |
|---|
| 594 | Â Â Â Â Â Â { |
|---|
| 595 | Â Â Â Â Â Â Â (void) CopyMagickMemory(indexes,nexus_indexes,(size_t) length* |
|---|
| 596 | Â Â Â Â Â Â Â Â sizeof(*indexes)); |
|---|
| 597 | Â Â Â Â Â Â Â indexes+=length; |
|---|
| 598 | Â Â Â Â Â Â } |
|---|
| 599 | Â Â Â Â } |
|---|
| 600 | Â Â } |
|---|
| 601 | Â } |
|---|
| 602 | Â DestroyCacheNexus(cache_info,virtual_nexus); |
|---|
| 603 | Â return(pixels); |
|---|
| 604 | } |
|---|
| 605 | |
|---|
| 606 | |
|---|
| 607 | |
|---|
| 608 | |
|---|
| 609 | |
|---|
| 610 | |
|---|
| 611 | |
|---|
| 612 | |
|---|
| 613 | |
|---|
| 614 | |
|---|
| 615 | |
|---|
| 616 | |
|---|
| 617 | |
|---|
| 618 | |
|---|
| 619 | |
|---|
| 620 | |
|---|
| 621 | |
|---|
| 622 | |
|---|
| 623 | |
|---|
| 624 | |
|---|
| 625 | |
|---|
| 626 | |
|---|
| 627 | |
|---|
| 628 | |
|---|
| 629 | |
|---|
| 630 | |
|---|
| 631 | |
|---|
| 632 | |
|---|
| 633 | |
|---|
| 634 | |
|---|
| 635 | |
|---|
| 636 | |
|---|
| 637 | |
|---|
| 638 | |
|---|
| 639 | |
|---|
| 640 | |
|---|
| 641 | |
|---|
| 642 | |
|---|
| 643 | |
|---|
| 644 | |
|---|
| 645 | |
|---|
| 646 | |
|---|
| 647 | |
|---|
| 648 | |
|---|
| 649 | |
|---|
| 650 | |
|---|
| 651 | |
|---|
| 652 | |
|---|
| 653 | |
|---|
| 654 | MagickExport const PixelPacket *AcquireImagePixels(const Image *image, |
|---|
| 655 |  const long x,const long y,const unsigned long columns, |
|---|
| 656 |  const unsigned long rows,ExceptionInfo *exception) |
|---|
| 657 | { |
|---|
| 658 | Â CacheInfo |
|---|
| 659 | Â Â *cache_info; |
|---|
| 660 | |
|---|
| 661 |  const PixelPacket |
|---|
| 662 | Â Â *pixels; |
|---|
| 663 | |
|---|
| 664 |  assert(image != (const Image *) NULL); |
|---|
| 665 | Â assert(image->signature == MagickSignature); |
|---|
| 666 |  if (image->debug != MagickFalse) |
|---|
| 667 | Â Â (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 668 | Â assert(image->cache != (Cache) NULL); |
|---|
| 669 | Â cache_info=(CacheInfo *) image->cache; |
|---|
| 670 | Â assert(cache_info->signature == MagickSignature); |
|---|
| 671 |  if (cache_info->methods.acquire_pixel_handler == (AcquirePixelHandler) NULL) |
|---|
| 672 |   return((const PixelPacket *) NULL); |
|---|
| 673 | Â pixels=cache_info->methods.acquire_pixel_handler(image, |
|---|
| 674 | Â Â GetCacheVirtualPixelMethod(image),x,y,columns,rows,exception); |
|---|
| 675 | Â return(pixels); |
|---|
| 676 | } |
|---|
| 677 | |
|---|
| 678 | |
|---|
| 679 | |
|---|
| 680 | |
|---|
| 681 | |
|---|
| 682 | |
|---|
| 683 | |
|---|
| 684 | |
|---|
| 685 | |
|---|
| 686 | |
|---|
| 687 | |
|---|
| 688 | |
|---|
| 689 | |
|---|
| 690 | |
|---|
| 691 | |
|---|
| 692 | |
|---|
| 693 | |
|---|
| 694 | |
|---|
| 695 | |
|---|
| 696 | |
|---|
| 697 | |
|---|
| 698 | |
|---|
| 699 | |
|---|
| 700 | |
|---|
| 701 | |
|---|
| 702 | |
|---|
| 703 | |
|---|
| 704 | |
|---|
| 705 | MagickExport const IndexPacket *AcquireIndexes(const Image *image) |
|---|
| 706 | { |
|---|
| 707 | Â CacheInfo |
|---|
| 708 | Â Â *cache_info; |
|---|
| 709 | |
|---|
| 710 |  assert(image != (const Image *) NULL); |
|---|
| 711 | Â assert(image->signature == MagickSignature); |
|---|
| 712 |  if (image->debug != MagickFalse) |
|---|
| 713 | Â Â (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 714 | Â assert(image->cache != (Cache) NULL); |
|---|
| 715 | Â cache_info=(CacheInfo *) image->cache; |
|---|
| 716 | Â assert(cache_info->signature == MagickSignature); |
|---|
| 717 |  if (cache_info->methods.acquire_indexes_from_handler == |
|---|
| 718 | Â Â Â (AcquireIndexesFromHandler) NULL) |
|---|
| 719 | Â Â return((IndexPacket *) NULL); |
|---|
| 720 | Â return(cache_info->methods.acquire_indexes_from_handler(image)); |
|---|
| 721 | } |
|---|
| 722 | |
|---|
| 723 | |
|---|
| 724 | |
|---|
| 725 | |
|---|
| 726 | |
|---|
| 727 | |
|---|
| 728 | |
|---|
| 729 | |
|---|
| 730 | |
|---|
| 731 | |
|---|
| 732 | |
|---|
| 733 | |
|---|
| 734 | |
|---|
| 735 | |
|---|
| 736 | |
|---|
| 737 | |
|---|
| 738 | |
|---|
| 739 | |
|---|
| 740 | |
|---|
| 741 | |
|---|
| 742 | |
|---|
| 743 | |
|---|
| 744 | |
|---|
| 745 | |
|---|
| 746 | |
|---|
| 747 | |
|---|
| 748 | |
|---|
| 749 | static const IndexPacket *AcquireIndexesFromCache(const Image *image) |
|---|
| 750 | { |
|---|
| 751 | Â assert(image != (Image *) NULL); |
|---|
| 752 | Â assert(image->signature == MagickSignature); |
|---|
| 753 |  if (image->debug != MagickFalse) |
|---|
| 754 | Â Â (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 755 | Â assert(image->cache != (Cache) NULL); |
|---|
| 756 | Â return(AcquireNexusIndexes(image->cache,0)); |
|---|
| 757 | } |
|---|
| 758 | |
|---|
| 759 | |
|---|
| 760 | |
|---|
| 761 | |
|---|
| 762 | |
|---|
| 763 | |
|---|
| 764 | |
|---|
| 765 | |
|---|
| 766 | |
|---|
| 767 | |
|---|
| 768 | |
|---|
| 769 | |
|---|
| 770 | |
|---|
| 771 | |
|---|
| 772 | |
|---|
| 773 | |
|---|
| 774 | |
|---|
| 775 | |
|---|
| 776 | |
|---|
| 777 | |
|---|
| 778 | |
|---|
| 779 | |
|---|
| 780 | |
|---|
| 781 | |
|---|
| 782 | |
|---|
| 783 | |
|---|
| 784 | |
|---|
| 785 | |
|---|
| 786 | |
|---|
| 787 | |
|---|
| 788 | MagickExport const IndexPacket *AcquireNexusIndexes(const Cache cache, |
|---|
| 789 |  const unsigned long nexus) |
|---|
| 790 | { |
|---|
| 791 | Â CacheInfo |
|---|
| 792 | Â Â *cache_info; |
|---|
| 793 | |
|---|
| 794 |  register NexusInfo |
|---|
| 795 | Â Â *nexus_info; |
|---|
| 796 | |
|---|
| 797 |  if (cache == (Cache) NULL) |
|---|
| 798 | Â Â return((IndexPacket *) NULL); |
|---|
| 799 | Â cache_info=(CacheInfo *) cache; |
|---|
| 800 | Â assert(cache_info->signature == MagickSignature); |
|---|
| 801 |  if (cache_info->storage_class == UndefinedClass) |
|---|
| 802 | Â Â return((IndexPacket *) NULL); |
|---|
| 803 | Â nexus_info=cache_info->nexus_info+nexus; |
|---|
| 804 | Â return(nexus_info->indexes); |
|---|
| 805 | } |
|---|
| 806 | |
|---|
| 807 | |
|---|
| 808 | |
|---|
| 809 | |
|---|
| 810 | |
|---|
| 811 | |
|---|
| 812 | |
|---|
| 813 | |
|---|
| 814 | |
|---|
| 815 | |
|---|
| 816 | |
|---|
| 817 | |
|---|
| 818 | |
|---|
| 819 | |
|---|
| 820 | |
|---|
| 821 | |
|---|
| 822 | |
|---|
| 823 | |
|---|
| 824 | |
|---|
| 825 | |
|---|
| 826 | |
|---|
| 827 | |
|---|
| 828 | |
|---|
| 829 | |
|---|
| 830 | |
|---|
| 831 | |
|---|
| 832 | |
|---|
| 833 | |
|---|
| 834 | |
|---|
| 835 | |
|---|
| 836 | |
|---|
| 837 | |
|---|
| 838 | |
|---|
| 839 | |
|---|
| 840 | |
|---|
| 841 | static const PixelPacket *AcquirePixelCache(const Image *image, |
|---|
| 842 |  const VirtualPixelMethod virtual_pixel_method,const long x,const long y, |
|---|
| 843 |  const unsigned long columns,const unsigned long rows,ExceptionInfo *exception) |
|---|
| 844 | { |
|---|
| 845 |  const PixelPacket |
|---|
| 846 | Â Â *pixels; |
|---|
| 847 | |
|---|
| 848 |  if (image->debug != MagickFalse) |
|---|
| 849 | Â Â (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 850 | Â pixels=AcquireCacheNexus(image,virtual_pixel_method,x,y,columns, |
|---|
| 851 | Â Â rows,0,exception); |
|---|
| 852 | Â return(pixels); |
|---|
| 853 | } |
|---|
| 854 | |
|---|
| 855 | |
|---|
| 856 | |
|---|
| 857 | |
|---|
| 858 | |
|---|
| 859 | |
|---|
| 860 | |
|---|
| 861 | |
|---|
| 862 | |
|---|
| 863 | |
|---|
| 864 | |
|---|
| 865 | |
|---|
| 866 | |
|---|
| 867 | |
|---|
| 868 | |
|---|
| 869 | |
|---|
| 870 | |
|---|
| 871 | |
|---|
| 872 | |
|---|
| 873 | |
|---|
| 874 | |
|---|
| 875 | |
|---|
| 876 | |
|---|
| 877 | |
|---|
| 878 | |
|---|
| 879 | |
|---|
| 880 | |
|---|
| 881 | |
|---|
| 882 | |
|---|
| 883 | |
|---|
| 884 | |
|---|
| 885 | |
|---|
| 886 | |
|---|
| 887 | MagickExport MagickPixelPacket AcquireOneMagickPixel(const Image *image, |
|---|
| 888 |  const long x,const long y,ExceptionInfo *exception) |
|---|
| 889 | { |
|---|
| 890 | Â CacheInfo |
|---|
| 891 | Â Â *cache_info; |
|---|
| 892 | |
|---|
| 893 | Â MagickPixelPacket |
|---|
| 894 | Â Â pixel; |
|---|
| 895 | |
|---|
| 896 |  register const PixelPacket |
|---|
| 897 | Â Â *p; |
|---|
| 898 | |
|---|
| 899 |  register IndexPacket |
|---|
| 900 | Â Â *indexes; |
|---|
| 901 | |
|---|
| 902 |  assert(image != (const Image *) NULL); |
|---|
| 903 | Â assert(image->signature == MagickSignature); |
|---|
| 904 | Â assert(image->cache != (Cache) NULL); |
|---|
| 905 | Â cache_info=(CacheInfo *) image->cache; |
|---|
| 906 | Â assert(cache_info->signature == MagickSignature); |
|---|
| 907 | Â GetMagickPixelPacket(image,&pixel); |
|---|
| 908 | Â p=AcquirePixelCache(image,GetCacheVirtualPixelMethod(image),x,y,1,1, |
|---|
| 909 | Â Â exception); |
|---|
| 910 | Â indexes=GetIndexes(image); |
|---|
| 911 | Â SetMagickPixelPacket(image,p,indexes,&pixel); |
|---|
| 912 | Â return(pixel); |
|---|
| 913 | } |
|---|
| 914 | |
|---|
| 915 | |
|---|
| 916 | |
|---|
| 917 | |
|---|
| 918 | |
|---|
| 919 | |
|---|
| 920 | |
|---|
| 921 | |
|---|
| 922 | |
|---|
| 923 | |
|---|