|
|
Definition at line 174 of file mpc.c.
References AcquireMagickMemory(), AcquireString(), AcquireStringInfo(), AllocateImage(), AllocateImageColormap(), AllocateNextImage(), AppendElementToLinkedList(), AppendImageFormat(), assert, _Image::background_color, _PixelPacket::blue, _ChromaticityInfo::blue_primary, _Image::border_color, CacheError, _Image::chromaticity, ClassType, _Image::client_data, CloneString(), CloseBlob(), _Image::colormap, _Image::colors, _Image::colorspace, ColorspaceType, _Image::columns, _Image::compression, CompressionType, CopyMagickString(), CorruptImageError, _StringInfo::datum, _ImageInfo::debug, _Image::delay, _Image::depth, DestroyImage(), DestroyImageList(), DestroyLinkedList(), DestroyStringInfo(), _Image::directory, _Image::dispose, DisposeType, EOFBlob(), _Image::error, _Image::filename, _ImageInfo::filename, _Image::gamma, GetBlobSize(), GetFirstImageInList(), GetImageProfile(), GetImageQuantumDepth(), GetMagickModule, GetNextElementInLinkedList(), GetPageGeometry(), _PixelPacket::green, _ChromaticityInfo::green_primary, _Image::iterations, _StringInfo::length, LoadImagesTag, LocaleCompare(), LocaleNCompare(), LogMagickEvent(), MagickBooleanOptions, MagickBooleanType, MagickClassOptions, MagickColorspaceOptions, MagickCompressionOptions, MagickDisposeOptions, MagickFalse, MagickIntentOptions, MagickOffsetType, MagickProgressMonitor, MagickResolutionOptions, MagickSignature, MagickStatusType, MagickTrue, _Image::matte, _Image::matte_color, MaxTextExtent, _ErrorInfo::mean_error_per_pixel, _Image::montage, name, NewLinkedList(), _Image::next, NoCompression, _ErrorInfo::normalized_maximum_error, _ErrorInfo::normalized_mean_error, _ImageInfo::number_scenes, OpenBlob(), _Image::page, ParseAbsoluteGeometry(), ParseGeometry(), ParseMagickOption(), PersistCache(), _ImageInfo::ping, _Image::progress_monitor, PseudoClass, PushCharPixel, PushLongPixel, PushShortPixel, QuantumDepth, QueryColorDatabase(), ReadBinaryBlobMode, ReadBlob(), ReadBlobByte(), _PixelPacket::red, _ChromaticityInfo::red_primary, RelinquishMagickMemory(), _Image::rendering_intent, RenderingIntent, ResetLinkedListIterator(), ResizeMagickMemory(), ResolutionType, ResourceLimitError, _GeometryInfo::rho, _Image::rows, ScaleCharToQuantum, ScaleLongToQuantum, ScaleShortToQuantum, _ImageInfo::scene, _Image::scene, SetImageAttribute(), SetImageProfile(), _GeometryInfo::sigma, SigmaValue, _ExceptionInfo::signature, _ImageInfo::signature, _Image::storage_class, SyncNextImageInList(), TellBlob(), ThrowFileException, ThrowReaderException, TraceEvent, UndefinedClass, UndefinedCompression, _Image::units, _ChromaticityInfo::white_point, _PrimaryInfo::x, _Image::x_resolution, _PrimaryInfo::y, and _Image::y_resolution.
Referenced by RegisterMPCImage().
00175 {
00176 char
00177 cache_filename[ MaxTextExtent],
00178 id[ MaxTextExtent],
00179 keyword[ MaxTextExtent],
00180 *options;
00181
00182 GeometryInfo
00183 geometry_info;
00184
00185 Image
00186 *image;
00187
00188 int
00189 c;
00190
00191 LinkedListInfo
00192 *profiles;
00193
00194 MagickBooleanType
00195 status;
00196
00197 MagickOffsetType
00198 offset;
00199
00200 MagickStatusType
00201 flags;
00202
00203 register long
00204 i;
00205
00206 register unsigned char
00207 *p;
00208
00209 size_t
00210 length;
00211
00212 StringInfo
00213 *profile;
00214
00215 unsigned long
00216 depth,
00217 quantum_depth;
00218
00219
00220
00221
00222 assert(image_info != ( const ImageInfo *) NULL);
00223 assert(image_info-> signature == MagickSignature);
00224 if (image_info-> debug != MagickFalse)
00225 ( void) LogMagickEvent(TraceEvent, GetMagickModule(),image_info-> filename);
00226 assert(exception != ( ExceptionInfo *) NULL);
00227 assert(exception-> signature == MagickSignature);
00228 image= AllocateImage(image_info);
00229 status= OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
00230 if (status == MagickFalse)
00231 {
00232 DestroyImageList(image);
00233 return(( Image *) NULL);
00234 }
00235 ( void) CopyMagickString(cache_filename,image-> filename,MaxTextExtent);
00236 AppendImageFormat( "cache",cache_filename);
00237 c= ReadBlobByte(image);
00238 if (c == EOF)
00239 {
00240 image= DestroyImage(image);
00241 return(( Image *) NULL);
00242 }
00243 * id= '\0';
00244 offset=0;
00245 do
00246 {
00247
00248
00249
00250 profiles=( LinkedListInfo *) NULL;
00251 length= MaxTextExtent;
00252 options= AcquireString(( char *) NULL);
00253 quantum_depth= QuantumDepth;
00254 image-> depth=8;
00255 image-> compression= NoCompression;
00256 while ((isgraph(c) != MagickFalse) && (c != ( int) ':'))
00257 {
00258 register char
00259 *p;
00260
00261 if (c == ( int) '{')
00262 {
00263 char
00264 *comment;
00265
00266
00267
00268
00269 length= MaxTextExtent;
00270 comment= AcquireString(( char *) NULL);
00271 for (p=comment; comment != ( char *) NULL; p++)
00272 {
00273 c= ReadBlobByte(image);
00274 if ((c == EOF) || (c == ( int) '}'))
00275 break;
00276 if ((size_t) (p-comment+1) >= length)
00277 {
00278 *p= '\0';
00279 length<<=1;
00280 comment=( char *) ResizeMagickMemory(comment,
00281 (length+MaxTextExtent)* sizeof(*comment));
00282 if (comment == ( char *) NULL)
00283 break;
00284 p=comment+strlen(comment);
00285 }
00286 *p=( char) c;
00287 }
00288 if (comment == ( char *) NULL)
00289 ThrowReaderException(ResourceLimitError, "MemoryAllocationFailed");
00290 *p= '\0';
00291 ( void) SetImageAttribute(image, "Comment",comment);
00292 comment=( char *) RelinquishMagickMemory(comment);
00293 c= ReadBlobByte(image);
00294 }
00295 else
00296 if (isalnum(c) != MagickFalse)
00297 {
00298
00299
00300
00301 p=keyword;
00302 do
00303 {
00304 if (isspace(( int) (( unsigned char) c)) != 0)
00305 break;
00306 if (c == ( int) '=')
00307 break;
00308 if ((size_t) (p-keyword) < ( MaxTextExtent-1))
00309 *p++=( char) c;
00310 c= ReadBlobByte(image);
00311 } while (c != EOF);
00312 *p= '\0';
00313 p=options;
00314 while (isspace(( int) (( unsigned char) c)) != 0)
00315 c= ReadBlobByte(image);
00316 if (c == ( int) '=')
00317 {
00318
00319
00320
00321 c= ReadBlobByte(image);
00322 while ((c != ( int) '}') && (c != EOF))
00323 {
00324 if ((size_t) (p-options+1) >= length)
00325 {
00326 *p= '\0';
00327 length<<=1;
00328 options=( char *) ResizeMagickMemory(options,
00329 (length+MaxTextExtent)* sizeof(*options));
00330 if (options == ( char *) NULL)
00331 break;
00332 p=options+strlen(options);
00333 }
00334 if (options == ( char *) NULL)
00335 ThrowReaderException(ResourceLimitError,
00336 "MemoryAllocationFailed");
00337 *p++=( char) c;
00338 c= ReadBlobByte(image);
00339 if (*options != '{')
00340 if (isspace(( int) (( unsigned char) c)) != 0)
00341 break;
00342 }
00343 }
00344 *p= '\0';
00345 if (*options == '{')
00346 ( void) CopyMagickString(options,options+1,MaxTextExtent);
00347
00348
00349
00350 switch (*keyword)
00351 {
00352 case 'b':
00353 case 'B':
00354 {
00355 if ( LocaleCompare(keyword, "background-color") == 0)
00356 {
00357 ( void) QueryColorDatabase(options,&image-> background_color,
00358 exception);
00359 break;
00360 }
00361 if ( LocaleCompare(keyword, "blue-primary") == 0)
00362 {
00363 flags= ParseGeometry(options,&geometry_info);
00364 image-> chromaticity. blue_primary. x=geometry_info. rho;
00365 image-> chromaticity. blue_primary. y=geometry_info. sigma;
00366 if ((flags & SigmaValue) == 0)
00367 image-> chromaticity. blue_primary. y=
00368 image-> chromaticity. blue_primary. x;
00369 break;
00370 }
00371 if ( LocaleCompare(keyword, "border-color") == 0)
00372 {
00373 ( void) QueryColorDatabase(options,&image-> border_color,
00374 exception);
00375 break;
00376 }
00377 ( void) SetImageAttribute(image,keyword,options);
00378 break;
00379 }
00380 case 'c':
00381 case 'C':
00382 {
00383 if ( LocaleCompare(keyword, "class") == 0)
00384 {
00385 image-> storage_class=( ClassType)
00386 ParseMagickOption(MagickClassOptions,MagickFalse,options);
00387 break;
00388 }
00389 if ( LocaleCompare(keyword, "colors") == 0)
00390 {
00391 image-> colors=( unsigned long) atol(options);
00392 break;
00393 }
00394 if ( LocaleCompare(keyword, "colorspace") == 0)
00395 {
00396 image-> colorspace=( ColorspaceType) ParseMagickOption(
00397 MagickColorspaceOptions,MagickFalse,options);
00398 break;
00399 }
00400 if ( LocaleCompare(keyword, "compression") == 0)
00401 {
00402 image-> compression=( CompressionType) ParseMagickOption(
00403 MagickCompressionOptions,MagickFalse,options);
00404 break;
00405 }
00406 if ( LocaleCompare(keyword, "columns") == 0)
00407 {
00408 image-> columns=( unsigned long) atol(options);
00409 break;
00410 }
00411 ( void) SetImageAttribute(image,keyword,options);
00412 break;
00413 }
00414 case 'd':
00415 case 'D':
00416 {
00417 if ( LocaleCompare(keyword, "delay") == 0)
00418 {
00419 image-> delay=( unsigned long) atol(options);
00420 break;
00421 }
00422 if ( LocaleCompare(keyword, "depth") == 0)
00423 {
00424 image-> depth=( unsigned long) atol(options);
00425 break;
00426 }
00427 if ( LocaleCompare(keyword, "dispose") == 0)
00428 {
00429 image-> dispose=( DisposeType) ParseMagickOption(
00430 MagickDisposeOptions,MagickFalse,options);
00431 break;
00432 }
00433 ( void) SetImageAttribute(image,keyword,options);
00434 break;
00435 }
00436 case 'e':
00437 case 'E':
00438 {
00439 if ( LocaleCompare(keyword, "error") == 0)
00440 {
00441 image-> error. mean_error_per_pixel=atof(options);
00442 break;
00443 }
00444 ( void) SetImageAttribute(image,keyword,options);
00445 break;
00446 }
00447 case 'g':
00448 case 'G':
00449 {
00450 if ( LocaleCompare(keyword, "gamma") == 0)
00451 {
00452 image-> gamma=atof(options);
00453 break;
00454 }
00455 if ( LocaleCompare(keyword, "green-primary") == 0)
00456 {
00457 flags= ParseGeometry(options,&geometry_info);
00458 image-> chromaticity. green_primary. x=geometry_info. rho;
00459 image-> chromaticity. green_primary. y=geometry_info. sigma;
00460 if ((flags & SigmaValue) == 0)
00461 image-> chromaticity. green_primary. y=
00462 image-> chromaticity. green_primary. x;
00463 break;
00464 }
00465 ( void) SetImageAttribute(image,keyword,options);
00466 break;
00467 }
00468 case 'i':
00469 case 'I':
00470 {
00471 if ( LocaleCompare(keyword, "id") == 0)
00472 {
00473 ( void) CopyMagickString( id,options,MaxTextExtent);
00474 break;
00475 }
00476 if ( LocaleCompare(keyword, "iterations") == 0)
00477 {
00478 image-> iterations=( unsigned long) atol(options);
00479 break;
00480 }
00481 ( void) SetImageAttribute(image,keyword,options);
00482 break;
00483 }
00484 case 'm':
00485 case 'M':
00486 {
00487 if ( LocaleCompare(keyword, "matte") == 0)
00488 {
00489 image-> matte=( MagickBooleanType) ParseMagickOption(
00490 MagickBooleanOptions,MagickFalse,options);
00491 break;
00492 }
00493 if ( LocaleCompare(keyword, "matte-color") == 0)
00494 {
00495 ( void) QueryColorDatabase(options,&image-> matte_color,
00496 exception);
00497 break;
00498 }
00499 if ( LocaleCompare(keyword, "maximum-error") == 0)
00500 {
00501 image-> error. normalized_maximum_error=atof(options);
00502 break;
00503 }
00504 if ( LocaleCompare(keyword, "mean-error") == 0)
00505 {
00506 image-> error. normalized_mean_error=atof(options);
00507 break;
00508 }
00509 if ( LocaleCompare(keyword, "montage") == 0)
00510 {
00511 ( void) CloneString(&image-> montage,options);
00512 break;
00513 }
00514 ( void) SetImageAttribute(image,keyword,options);
00515 break;
00516 }
00517 case 'p':
00518 case 'P':
00519 {
00520 if ( LocaleCompare(keyword, "page") == 0)
00521 {
00522 char
00523 *geometry;
00524
00525 geometry= GetPageGeometry(options);
00526 ( void) ParseAbsoluteGeometry(geometry,&image-> page);
00527 geometry=( char *) RelinquishMagickMemory(geometry);
00528 break;
00529 }
00530 if ( LocaleNCompare(keyword, "profile-",8) == 0)
00531 {
00532 if (profiles == ( LinkedListInfo *) NULL)
00533 profiles= NewLinkedList(0);
00534 ( void) AppendElementToLinkedList(profiles,
00535 AcquireString(keyword+8));
00536 profile= AcquireStringInfo((size_t) atol(options));
00537 ( void) SetImageProfile(image,keyword+8,profile);
00538 profile= DestroyStringInfo(profile);
00539 break;
00540 }
00541 ( void) SetImageAttribute(image,keyword,options);
00542 break;
00543 }
00544 case 'o':
00545 case 'O':
00546 {
00547 if ( LocaleCompare(keyword, "opaque") == 0)
00548 {
00549 image-> matte=( MagickBooleanType) ParseMagickOption(
00550 MagickBooleanOptions,MagickFalse,options);
00551 break;
00552 }
00553 ( void) SetImageAttribute(image,keyword,options);
00554 break;
00555 }
00556 case 'q':
00557 case 'Q':
00558 {
00559 if ( LocaleCompare(keyword, "quantum-depth") == 0)
00560 {
00561 quantum_depth=( unsigned long) atol(options);
00562 break;
00563 }
00564 ( void) SetImageAttribute(image,keyword,options);
00565 break;
00566 }
00567 case 'r':
00568 case 'R':
00569 {
00570 if ( LocaleCompare(keyword, "red-primary") == 0)
00571 {
00572 flags= ParseGeometry(options,&geometry_info);
00573 image-> chromaticity. red_primary. x=geometry_info. rho;
00574 if ((flags & SigmaValue) != 0)
00575 image-> chromaticity. red_primary. y=geometry_info. sigma;
00576 break;
00577 }
00578 if ( LocaleCompare(keyword, "rendering-intent") == 0)
00579 {
00580 image-> rendering_intent=( RenderingIntent) ParseMagickOption(
00581 MagickIntentOptions,MagickFalse,options);
00582 break;
00583 }
00584 if ( LocaleCompare(keyword, "resolution") == 0)
00585 {
00586 flags= ParseGeometry(options,&geometry_info);
00587 image-> x_resolution=geometry_info. rho;
00588 image-> y_resolution=geometry_info. sigma;
00589 if ((flags & SigmaValue) == 0)
00590 image-> y_resolution=image-> x_resolution;
00591 break;
00592 }
00593 if ( LocaleCompare(keyword, "rows") == 0)
00594 {
00595 image-> rows=( unsigned long) atol(options);
00596 break;
00597 }
00598 ( void) SetImageAttribute(image,keyword,options);
00599 break;
00600 }
00601 case 's':
00602 case 'S':
00603 {
00604 if ( LocaleCompare(keyword, "scene") == 0)
00605 {
00606 image-> scene=( unsigned long) atol(options);
00607 break;
00608 }
00609 ( void) SetImageAttribute(image,keyword,options);
00610 break;
00611 }
00612 case 'u':
00613 case 'U':
00614 {
00615 if ( LocaleCompare(keyword, "units") == 0)
00616 {
00617 image-> units=( ResolutionType) ParseMagickOption(
00618 MagickResolutionOptions,MagickFalse,options);
00619 break;
00620 }
00621 ( void) SetImageAttribute(image,keyword,options);
00622 break;
00623 }
00624 case 'w':
00625 case 'W':
00626 {
00627 if ( LocaleCompare(keyword, "white-point") == 0)
00628 {
00629 flags= ParseGeometry(options,&geometry_info);
00630 image-> chromaticity. white_point. x=geometry_info. rho;
00631 image-> chromaticity. white_point. y=geometry_info. sigma;
00632 if ((flags & SigmaValue) == 0)
00633 image-> chromaticity. white_point. y=
00634 image-> chromaticity. white_point. x;
00635 break;
00636 }
00637 ( void) SetImageAttribute(image,keyword,options);
00638 break;
00639 }
00640 default:
00641 {
00642 ( void) SetImageAttribute(image,keyword,options);
00643 break;
00644 }
00645 }
00646 }
00647 else
00648 c= ReadBlobByte(image);
00649 while (isspace(( int) (( unsigned char) c)) != 0)
00650 c= ReadBlobByte(image);
00651 }
00652 options=( char *) RelinquishMagickMemory(options);
00653 ( void) ReadBlobByte(image);
00654
00655
00656
00657 if (( LocaleCompare( id, "MagickCache") != 0) ||
00658 (image-> storage_class == UndefinedClass) ||
00659 (image-> compression == UndefinedCompression) || (image-> columns == 0) ||
00660 (image-> rows == 0))
00661 ThrowReaderException(CorruptImageError, "ImproperImageHeader");
00662 if (quantum_depth != QuantumDepth)
00663 ThrowReaderException(CacheError, "InconsistentPersistentCacheDepth");
00664 if (image-> montage != ( char *) NULL)
00665 {
00666 register char
00667 *p;
00668
00669
00670
00671
00672 length= MaxTextExtent;
00673 image-> directory= AcquireString(( char *) NULL);
00674 p=image-> directory;
00675 do
00676 {
00677 *p= '\0';
00678 if ((strlen(image-> directory)+ MaxTextExtent) >= length)
00679 {
00680
00681
00682
00683 length<<=1;
00684 image-> directory=( char *) ResizeMagickMemory(image-> directory,
00685 (length+MaxTextExtent)* sizeof(*image-> directory));
00686 if (image-> directory == ( char *) NULL)
00687 ThrowReaderException(CorruptImageError, "UnableToReadImageData");
00688 p=image-> directory+strlen(image-> directory);
00689 }
00690 c= ReadBlobByte(image);
00691 *p++=( char) c;
00692 } while (c != ( int) '\0');
00693 }
00694 if (profiles != ( LinkedListInfo *) NULL)
00695 {
00696 const char
00697 * name;
00698
00699
00700
00701
00702 ResetLinkedListIterator(profiles);
00703 name=( const char *) GetNextElementInLinkedList(profiles);
00704 while ( name != ( const char *) NULL)
00705 {
00706 profile= GetImageProfile(image,name);
00707 if (profile != ( StringInfo *) NULL)
00708 ( void) ReadBlob(image,profile-> length,profile-> datum);
00709 name=( const char *) GetNextElementInLinkedList(profiles);
00710 }
00711 profiles= DestroyLinkedList(profiles,RelinquishMagickMemory);
00712 }
00713 depth= GetImageQuantumDepth(image,MagickFalse);
00714 if (image-> storage_class == PseudoClass)
00715 {
00716
00717
00718
00719 if ( AllocateImageColormap(image,image-> colors) == MagickFalse)
00720 ThrowReaderException(ResourceLimitError, "MemoryAllocationFailed");
00721 if (image-> colors != 0)
00722 {
00723 size_t
00724 packet_size;
00725
00726 unsigned char
00727 *colormap;
00728
00729 unsigned long
00730 pixel;
00731
00732
00733
00734
00735 packet_size=(size_t) (3*depth/8);
00736 colormap=( unsigned char *)
00737 AcquireMagickMemory(packet_size*image-> colors);
00738 if (colormap == ( unsigned char *) NULL)
00739 ThrowReaderException(ResourceLimitError, "MemoryAllocationFailed");
00740 ( void) ReadBlob(image,packet_size*image-> colors,colormap);
00741 p=colormap;
00742 switch (depth)
00743 {
00744 default:
00745 ThrowReaderException(CorruptImageError,
00746 "ImageDepthNotSupported");
00747 case 8:
00748 {
00749 for (i=0; i < ( long) image-> colors; i++)
00750 {
00751 PushCharPixel(pixel,p);
00752 image-> colormap[i]. red= ScaleCharToQuantum(pixel);
00753 PushCharPixel(pixel,p);
00754 image-> colormap[i]. green= ScaleCharToQuantum(pixel);
00755 PushCharPixel(pixel,p);
00756 image-> colormap[i]. blue= ScaleCharToQuantum(pixel);
00757 }
00758 break;
00759 }
00760 case 16:
00761 {
00762 for (i=0; i < ( long) image-> colors; i++)
00763 {
00764 PushShortPixel(pixel,p);
00765 image-> colormap[i]. red= ScaleShortToQuantum(pixel);
00766 PushShortPixel(pixel,p);
00767 image-> colormap[i]. green= ScaleShortToQuantum(pixel);
00768 PushShortPixel(pixel,p);
00769 image-> colormap[i]. blue= ScaleShortToQuantum(pixel);
00770 }
00771 break;
00772 }
00773 case 32:
00774 {
00775 for (i=0; i < ( long) image-> colors; i++)
00776 {
00777 PushLongPixel(pixel,p);
00778 image-> colormap[i]. red= ScaleLongToQuantum(pixel);
00779 PushLongPixel(pixel,p);
00780 image-> colormap[i]. green= ScaleLongToQuantum(pixel);
00781 PushLongPixel(pixel,p);
00782 image-> colormap[i]. blue= ScaleLongToQuantum(pixel);
00783 }
00784 break;
00785 }
00786 }
00787 colormap=( unsigned char *) RelinquishMagickMemory(colormap);
00788 }
00789 }
00790 if ( EOFBlob(image) != MagickFalse)
00791 {
00792 ThrowFileException(exception,CorruptImageError, "UnexpectedEndOfFile",
00793 image-> filename);
00794 break;
00795 }
00796 if ((image_info-> ping != MagickFalse) && (image_info-> number_scenes != 0))
00797 if (image-> scene >= (image_info-> scene+image_info-> number_scenes-1))
00798 break;
00799
00800
00801
00802 status= PersistCache(image,cache_filename,MagickTrue,&offset,exception);
00803 if (status == MagickFalse)
00804 ThrowReaderException(CacheError, "UnableToPersistPixelCache");
00805
00806
00807
00808 do
00809 {
00810 c= ReadBlobByte(image);
00811 } while ((isgraph(c) == MagickFalse) && (c != EOF));
00812 if (c != EOF)
00813 {
00814
00815
00816
00817 AllocateNextImage(image_info,image);
00818 if (image-> next == ( Image *) NULL)
00819 {
00820 DestroyImageList(image);
00821 return(( Image *) NULL);
00822 }
00823 image= SyncNextImageInList(image);
00824 if (image-> progress_monitor != ( MagickProgressMonitor) NULL)
00825 {
00826 status=image-> progress_monitor(LoadImagesTag, TellBlob(image),
00827 GetBlobSize(image),image-> client_data);
00828 if (status == MagickFalse)
00829 break;
00830 }
00831 }
00832 } while (c != EOF);
00833 CloseBlob(image);
00834 return( GetFirstImageInList(image));
00835 }
Here is the call graph for this function:
|