void PipeDevice::ParseCommand(const std::string& command) { std::vector<std::string> tokens; SplitString(command, ' ', tokens); if (tokens.size() < 2 || tokens.size() > 4) return; if (tokens[0] == "PRESS" || tokens[0] == "RELEASE") { auto search = m_buttons.find(tokens[1]); if (search != m_buttons.end()) search->second->SetState(tokens[0] == "PRESS" ? 1.0 : 0.0); } else if (tokens[0] == "SET") { if (tokens.size() == 3) { double value = StringToDouble(tokens[2]); SetAxis(tokens[1], (value / 2.0) + 0.5); } else if (tokens.size() == 4) { double x = StringToDouble(tokens[2]); double y = StringToDouble(tokens[3]); SetAxis(tokens[1] + " X", x); SetAxis(tokens[1] + " Y", y); } } }
void DoubleCoerce (FProduction *&prod1, FProduction *&prod2) { if (prod1->Type == PROD_String) { prod1 = StringToDouble (prod1); } if (prod2->Type == PROD_String) { prod2 = StringToDouble (prod2); } }
void ChoiceForm::AutotuneButton_Clicked(GraphicsUI::UI_Base *) { if (currentShaderName.Length()) { Autotune((float)StringToDouble(timeBudgetTextBox->GetText())); } }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t Q u a n t u m I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetQuantumInfo() initializes the QuantumInfo structure to default values. % % The format of the GetQuantumInfo method is: % % GetQuantumInfo(const ImageInfo *image_info,QuantumInfo *quantum_info) % % A description of each parameter follows: % % o image_info: the image info. % % o quantum_info: the quantum info. % */ MagickExport void GetQuantumInfo(const ImageInfo *image_info, QuantumInfo *quantum_info) { const char *option; assert(quantum_info != (QuantumInfo *) NULL); (void) ResetMagickMemory(quantum_info,0,sizeof(*quantum_info)); quantum_info->quantum=8; quantum_info->maximum=1.0; quantum_info->scale=QuantumRange; quantum_info->pack=MagickTrue; quantum_info->semaphore=AllocateSemaphoreInfo(); quantum_info->signature=MagickSignature; if (image_info == (const ImageInfo *) NULL) return; option=GetImageOption(image_info,"quantum:format"); if (option != (char *) NULL) quantum_info->format=(QuantumFormatType) ParseCommandOption( MagickQuantumFormatOptions,MagickFalse,option); option=GetImageOption(image_info,"quantum:minimum"); if (option != (char *) NULL) quantum_info->minimum=StringToDouble(option,(char **) NULL); option=GetImageOption(image_info,"quantum:maximum"); if (option != (char *) NULL) quantum_info->maximum=StringToDouble(option,(char **) NULL); if ((quantum_info->minimum == 0.0) && (quantum_info->maximum == 0.0)) quantum_info->scale=0.0; else if (quantum_info->minimum == quantum_info->maximum) { quantum_info->scale=(MagickRealType) QuantumRange/quantum_info->minimum; quantum_info->minimum=0.0; } else quantum_info->scale=(MagickRealType) QuantumRange/(quantum_info->maximum- quantum_info->minimum); option=GetImageOption(image_info,"quantum:scale"); if (option != (char *) NULL) quantum_info->scale=StringToDouble(option,(char **) NULL); option=GetImageOption(image_info,"quantum:polarity"); if (option != (char *) NULL) quantum_info->min_is_white=LocaleCompare(option,"min-is-white") == 0 ? MagickTrue : MagickFalse; quantum_info->endian=image_info->endian; ResetQuantumState(quantum_info); }
double Utils::GetDoubleFromJsonValue(Json::Value &value, double defaultValue) { double res = defaultValue; /* some json responses have doubles formated as strings, or an expected double is formated as an int */ if (value.isString()) res = StringToDouble(value.asString()); else if (value.isInt() || value.isDouble()) res = value.asDouble(); return res; }
Value* JSONReader::DecodeNumber(const Token& token) { const std::wstring num_string(token.begin, token.length); int num_int; if(StringToInt(WideToUTF8(num_string), &num_int)) { return Value::CreateIntegerValue(num_int); } double num_double; if(StringToDouble(WideToUTF8(num_string), &num_double) && base::IsFinite(num_double)) { return Value::CreateDoubleValue(num_double); } return NULL; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + I s S c e n e G e o m e t r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % IsSceneGeometry() returns MagickTrue if the geometry is a valid scene % specification (e.g. [1], [1-9], [1,7,4]). % % The format of the IsSceneGeometry method is: % % MagickBooleanType IsSceneGeometry(const char *geometry, % const MagickBooleanType pedantic) % % A description of each parameter follows: % % o geometry: This string is the geometry specification. % % o pedantic: A value other than 0 invokes a more restrictive set of % conditions for a valid specification (e.g. [1], [1-4], [4-1]). % */ MagickExport MagickBooleanType IsSceneGeometry(const char *geometry, const MagickBooleanType pedantic) { char *p; double value; if (geometry == (const char *) NULL) return(MagickFalse); p=(char *) geometry; value=StringToDouble(geometry,&p); (void) value; if (p == geometry) return(MagickFalse); if (strspn(geometry,"0123456789-, ") != strlen(geometry)) return(MagickFalse); if ((pedantic != MagickFalse) && (strchr(geometry,',') != (char *) NULL)) return(MagickFalse); return(MagickTrue); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % P a r s e A f f i n e G e o m e t r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ParseAffineGeometry() returns an affine matrix as defined by the geometry % string. % % The format of the ParseAffineGeometry method is: % % MagickStatusType ParseAffineGeometry(const char *geometry, % AffineMatrix *affine_matrix,ExceptionInfo *exception) % % A description of each parameter follows: % % o geometry: The geometry (e.g. 1.0,0.0,0.0,1.0,3.2,1.2). % % o affine_matrix: the affine matrix as defined by the geometry string. % % o exception: return any errors or warnings in this structure. % */ MagickExport MagickStatusType ParseAffineGeometry(const char *geometry, AffineMatrix *affine_matrix,ExceptionInfo *exception) { char token[MaxTextExtent]; const char *p; double determinant; MagickStatusType flags; register ssize_t i; GetAffineMatrix(affine_matrix); flags=NoValue; p=(char *) geometry; for (i=0; (*p != '\0') && (i < 6); i++) { GetMagickToken(p,&p,token); if (*token == ',') GetMagickToken(p,&p,token); switch (i) { case 0: affine_matrix->sx=StringToDouble(token); break; case 1: affine_matrix->rx=StringToDouble(token); break; case 2: affine_matrix->ry=StringToDouble(token); break; case 3: affine_matrix->sy=StringToDouble(token); break; case 4: affine_matrix->tx=StringToDouble(token); flags|=XValue; break; case 5: affine_matrix->ty=StringToDouble(token); flags|=YValue; break; } } determinant=(affine_matrix->sx*affine_matrix->sy-affine_matrix->rx* affine_matrix->ry); if (fabs(determinant) < MagickEpsilon) (void) ThrowMagickException(exception,GetMagickModule(),OptionError, "InvalidGeometry","`%s'",geometry); return(flags); }
MagickExport Image *ConnectedComponentsImage(const Image *image, const size_t connectivity,ExceptionInfo *exception) { #define ConnectedComponentsImageTag "ConnectedComponents/Image" CacheView *image_view, *component_view; const char *artifact; double area_threshold; Image *component_image; MagickBooleanType status; MagickOffsetType progress; MatrixInfo *equivalences; size_t size; ssize_t n, y; /* Initialize connected components image attributes. */ assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); component_image=CloneImage(image,image->columns,image->rows,MagickTrue, exception); if (component_image == (Image *) NULL) return((Image *) NULL); component_image->depth=MAGICKCORE_QUANTUM_DEPTH; component_image->colorspace=GRAYColorspace; if (SetImageStorageClass(component_image,DirectClass) == MagickFalse) { component_image=DestroyImage(component_image); return((Image *) NULL); } /* Initialize connected components equivalences. */ size=image->columns*image->rows; if (image->columns != (size/image->rows)) { component_image=DestroyImage(component_image); ThrowImageException(ResourceLimitError,"MemoryAllocationFailed"); } equivalences=AcquireMatrixInfo(size,1,sizeof(ssize_t),exception); if (equivalences == (MatrixInfo *) NULL) { component_image=DestroyImage(component_image); return((Image *) NULL); } for (n=0; n < (ssize_t) (image->columns*image->rows); n++) (void) SetMatrixElement(equivalences,n,0,&n); /* Find connected components. */ status=MagickTrue; progress=0; image_view=AcquireVirtualCacheView(image,exception); for (n=0; n < (ssize_t) (connectivity > 4 ? 4 : 2); n++) { ssize_t connect4[2][2] = { { -1, 0 }, { 0, -1 } }, connect8[4][2] = { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 } }, dx, dy; if (status == MagickFalse) continue; dy=connectivity > 4 ? connect8[n][0] : connect4[n][0]; dx=connectivity > 4 ? connect8[n][1] : connect4[n][1]; for (y=0; y < (ssize_t) image->rows; y++) { register const PixelPacket *restrict p; register ssize_t x; if (status == MagickFalse) continue; p=GetCacheViewVirtualPixels(image_view,0,y-1,image->columns,3,exception); if (p == (const PixelPacket *) NULL) { status=MagickFalse; continue; } p+=image->columns; for (x=0; x < (ssize_t) image->columns; x++) { ssize_t neighbor_offset, object, offset, ox, oy, root; /* Is neighbor an authentic pixel and a different color than the pixel? */ neighbor_offset=dy*image->columns+dx; if (((x+dx) < 0) || ((x+dx) >= (ssize_t) image->columns) || ((y+dy) < 0) || ((y+dy) >= (ssize_t) image->rows) || (IsColorSimilar(image,p,p+neighbor_offset) == MagickFalse)) { p++; continue; } /* Resolve this equivalence. */ offset=y*image->columns+x; ox=offset; status=GetMatrixElement(equivalences,ox,0,&object); while (object != ox) { ox=object; status=GetMatrixElement(equivalences,ox,0,&object); } oy=offset+neighbor_offset; status=GetMatrixElement(equivalences,oy,0,&object); while (object != oy) { oy=object; status=GetMatrixElement(equivalences,oy,0,&object); } if (ox < oy) { status=SetMatrixElement(equivalences,oy,0,&ox); root=ox; } else { status=SetMatrixElement(equivalences,ox,0,&oy); root=oy; } ox=offset; status=GetMatrixElement(equivalences,ox,0,&object); while (object != root) { status=GetMatrixElement(equivalences,ox,0,&object); status=SetMatrixElement(equivalences,ox,0,&root); } oy=offset+neighbor_offset; status=GetMatrixElement(equivalences,oy,0,&object); while (object != root) { status=GetMatrixElement(equivalences,oy,0,&object); status=SetMatrixElement(equivalences,oy,0,&root); } status=SetMatrixElement(equivalences,y*image->columns+x,0,&root); p++; } } } image_view=DestroyCacheView(image_view); /* Label connected components. */ n=0; component_view=AcquireAuthenticCacheView(component_image,exception); for (y=0; y < (ssize_t) component_image->rows; y++) { register PixelPacket *restrict q; register ssize_t x; if (status == MagickFalse) continue; q=QueueCacheViewAuthenticPixels(component_view,0,y,component_image->columns, 1,exception); if (q == (PixelPacket *) NULL) { status=MagickFalse; continue; } for (x=0; x < (ssize_t) component_image->columns; x++) { ssize_t id, offset; offset=y*image->columns+x; status=GetMatrixElement(equivalences,offset,0,&id); if (id == offset) { id=n++; status=SetMatrixElement(equivalences,offset,0,&id); } else { status=GetMatrixElement(equivalences,id,0,&id); status=SetMatrixElement(equivalences,offset,0,&id); } q->red=(Quantum) (id > (ssize_t) QuantumRange ? (ssize_t) QuantumRange : id); q->green=q->red; q->blue=q->red; q++; } if (SyncCacheViewAuthenticPixels(component_view,exception) == MagickFalse) status=MagickFalse; if (image->progress_monitor != (MagickProgressMonitor) NULL) { MagickBooleanType proceed; proceed=SetImageProgress(image,ConnectedComponentsImageTag,progress++, image->rows); if (proceed == MagickFalse) status=MagickFalse; } } component_view=DestroyCacheView(component_view); equivalences=DestroyMatrixInfo(equivalences); if (n > (ssize_t) QuantumRange) { component_image=DestroyImage(component_image); ThrowImageException(ResourceLimitError,"TooManyObjects"); } artifact=GetImageArtifact(image,"connected-components:area-threshold"); area_threshold=0.0; if (artifact != (const char *) NULL) area_threshold=StringToDouble(artifact,(char **) NULL); if (area_threshold > 0.0) status=MergeConnectedComponents(component_image,(size_t) n,area_threshold, exception); artifact=GetImageArtifact(image,"connected-components:verbose"); if (IsMagickTrue(artifact) != MagickFalse) status=StatisticsComponentsStatistics(image,component_image,(size_t) n, exception); if (status == MagickFalse) component_image=DestroyImage(component_image); return(component_image); }
WandExport MagickBooleanType StreamImageCommand(ImageInfo *image_info, int argc,char **argv,char **metadata,ExceptionInfo *exception) { #define DestroyStream() \ { \ DestroyImageStack(); \ stream_info=DestroyStreamInfo(stream_info); \ for (i=0; i < (ssize_t) argc; i++) \ argv[i]=DestroyString(argv[i]); \ argv=(char **) RelinquishMagickMemory(argv); \ } #define ThrowStreamException(asperity,tag,option) \ { \ (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \ option); \ DestroyStream(); \ return(MagickFalse); \ } #define ThrowStreamInvalidArgumentException(option,argument) \ { \ (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \ "InvalidArgument","'%s': %s",option,argument); \ DestroyStream(); \ return(MagickFalse); \ } char *filename, *option; const char *format; Image *image; ImageStack image_stack[MaxImageStackDepth+1]; MagickBooleanType fire, pend, respect_parenthesis; MagickStatusType status; register ssize_t i; ssize_t j, k; StreamInfo *stream_info; /* Set defaults. */ assert(image_info != (ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); assert(exception != (ExceptionInfo *) NULL); (void) metadata; if (argc == 2) { option=argv[1]; if ((LocaleCompare("version",option+1) == 0) || (LocaleCompare("-version",option+1) == 0)) { ListMagickVersion(stdout); return(MagickFalse); } } if (argc < 3) return(StreamUsage()); format="%w,%h,%m"; (void) format; j=1; k=0; NewImageStack(); option=(char *) NULL; pend=MagickFalse; respect_parenthesis=MagickFalse; stream_info=AcquireStreamInfo(image_info,exception); status=MagickTrue; /* Stream an image. */ ReadCommandlLine(argc,&argv); status=ExpandFilenames(&argc,&argv); if (status == MagickFalse) ThrowStreamException(ResourceLimitError,"MemoryAllocationFailed", GetExceptionMessage(errno)); status=OpenStream(image_info,stream_info,argv[argc-1],exception); if (status == MagickFalse) { DestroyStream(); return(MagickFalse); } for (i=1; i < (ssize_t) (argc-1); i++) { option=argv[i]; if (LocaleCompare(option,"(") == 0) { FireImageStack(MagickFalse,MagickTrue,pend); if (k == MaxImageStackDepth) ThrowStreamException(OptionError,"ParenthesisNestedTooDeeply",option); PushImageStack(); continue; } if (LocaleCompare(option,")") == 0) { FireImageStack(MagickFalse,MagickTrue,MagickTrue); if (k == 0) ThrowStreamException(OptionError,"UnableToParseExpression",option); PopImageStack(); continue; } if (IsCommandOption(option) == MagickFalse) { Image *images; /* Stream input image. */ FireImageStack(MagickFalse,MagickFalse,pend); filename=argv[i]; if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1))) filename=argv[++i]; (void) CopyMagickString(image_info->filename,filename,MaxTextExtent); images=StreamImage(image_info,stream_info,exception); status&=(images != (Image *) NULL) && (exception->severity < ErrorException); if (images == (Image *) NULL) continue; AppendImageStack(images); continue; } pend=image != (Image *) NULL ? MagickTrue : MagickFalse; switch (*(option+1)) { case 'a': { if (LocaleCompare("authenticate",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowStreamException(OptionError,"MissingArgument",option); break; } ThrowStreamException(OptionError,"UnrecognizedOption",option) } case 'c': { if (LocaleCompare("cache",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowStreamException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowStreamInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("channel",option+1) == 0) { ssize_t channel; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowStreamException(OptionError,"MissingArgument",option); channel=ParseChannelOption(argv[i]); if (channel < 0) ThrowStreamException(OptionError,"UnrecognizedChannelType", argv[i]); break; } if (LocaleCompare("colorspace",option+1) == 0) { ssize_t colorspace; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowStreamException(OptionError,"MissingArgument",option); colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse, argv[i]); if (colorspace < 0) ThrowStreamException(OptionError,"UnrecognizedColorspace", argv[i]); break; } if (LocaleCompare("compress",option+1) == 0) { ssize_t compress; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowStreamException(OptionError,"MissingArgument",option); compress=ParseCommandOption(MagickCompressOptions,MagickFalse, argv[i]); if (compress < 0) ThrowStreamException(OptionError,"UnrecognizedImageCompression", argv[i]); break; } if (LocaleCompare("concurrent",option+1) == 0) break; ThrowStreamException(OptionError,"UnrecognizedOption",option) } case 'd': { if (LocaleCompare("debug",option+1) == 0) { ssize_t event; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowStreamException(OptionError,"MissingArgument",option); event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]); if (event < 0) ThrowStreamException(OptionError,"UnrecognizedEventType",argv[i]); (void) SetLogEventMask(argv[i]); break; } if (LocaleCompare("define",option+1) == 0) { i++; if (i == (ssize_t) argc) ThrowStreamException(OptionError,"MissingArgument",option); if (*option == '+') { const char *define; define=GetImageOption(image_info,argv[i]); if (define == (const char *) NULL) ThrowStreamException(OptionError,"NoSuchOption",argv[i]); break; } break; } if (LocaleCompare("density",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowStreamException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowStreamInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("depth",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowStreamException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowStreamInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("duration",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowStreamException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowStreamInvalidArgumentException(option,argv[i]); break; } ThrowStreamException(OptionError,"UnrecognizedOption",option) } case 'e': { if (LocaleCompare("extract",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowStreamException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowStreamInvalidArgumentException(option,argv[i]); break; } ThrowStreamException(OptionError,"UnrecognizedOption",option) } case 'h': { if ((LocaleCompare("help",option+1) == 0) || (LocaleCompare("-help",option+1) == 0)) return(StreamUsage()); ThrowStreamException(OptionError,"UnrecognizedOption",option) } case 'i': { if (LocaleCompare("identify",option+1) == 0) break; if (LocaleCompare("interlace",option+1) == 0) { ssize_t interlace; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowStreamException(OptionError,"MissingArgument",option); interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse, argv[i]); if (interlace < 0) ThrowStreamException(OptionError,"UnrecognizedInterlaceType", argv[i]); break; } if (LocaleCompare("interpolate",option+1) == 0) { ssize_t interpolate; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowStreamException(OptionError,"MissingArgument",option); interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse, argv[i]); if (interpolate < 0) ThrowStreamException(OptionError,"UnrecognizedInterpolateMethod", argv[i]); break; } ThrowStreamException(OptionError,"UnrecognizedOption",option) } case 'l': { if (LocaleCompare("limit",option+1) == 0) { char *p; double value; ssize_t resource; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowStreamException(OptionError,"MissingArgument",option); resource=ParseCommandOption(MagickResourceOptions,MagickFalse, argv[i]); if (resource < 0) ThrowStreamException(OptionError,"UnrecognizedResourceType", argv[i]); i++; if (i == (ssize_t) argc) ThrowStreamException(OptionError,"MissingArgument",option); value=StringToDouble(argv[i],&p); (void) value; if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0)) ThrowStreamInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("list",option+1) == 0) { ssize_t list; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowStreamException(OptionError,"MissingArgument",option); list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]); if (list < 0) ThrowStreamException(OptionError,"UnrecognizedListType",argv[i]); status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **) argv+j,exception); DestroyStream(); return(status != 0 ? MagickFalse : MagickTrue); } if (LocaleCompare("log",option+1) == 0) { if (*option == '+') break; i++; if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL)) ThrowStreamException(OptionError,"MissingArgument",option); break; } ThrowStreamException(OptionError,"UnrecognizedOption",option) } case 'm': { if (LocaleCompare("map",option+1) == 0) { (void) CopyMagickString(argv[i]+1,"san",MaxTextExtent); if (*option == '+') break; i++; SetStreamInfoMap(stream_info,argv[i]); break; } if (LocaleCompare("monitor",option+1) == 0) break; ThrowStreamException(OptionError,"UnrecognizedOption",option) } case 'q': { if (LocaleCompare("quantize",option+1) == 0) { ssize_t colorspace; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowStreamException(OptionError,"MissingArgument",option); colorspace=ParseCommandOption(MagickColorspaceOptions, MagickFalse,argv[i]); if (colorspace < 0) ThrowStreamException(OptionError,"UnrecognizedColorspace", argv[i]); break; } if (LocaleCompare("quiet",option+1) == 0) break; ThrowStreamException(OptionError,"UnrecognizedOption",option) } case 'r': { if (LocaleCompare("regard-warnings",option+1) == 0) break; if (LocaleNCompare("respect-parentheses",option+1,17) == 0) { respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse; break; } ThrowStreamException(OptionError,"UnrecognizedOption",option) } case 's': { if (LocaleCompare("sampling-factor",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowStreamException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowStreamInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("seed",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowStreamException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowStreamInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("set",option+1) == 0) { i++; if (i == (ssize_t) argc) ThrowStreamException(OptionError,"MissingArgument",option); if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowStreamException(OptionError,"MissingArgument",option); break; } if (LocaleCompare("size",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowStreamException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowStreamInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("storage-type",option+1) == 0) { ssize_t type; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowStreamException(OptionError,"MissingArgument",option); type=ParseCommandOption(MagickStorageOptions,MagickFalse,argv[i]); if (type < 0) ThrowStreamException(OptionError,"UnrecognizedStorageType", argv[i]); SetStreamInfoStorageType(stream_info,(StorageType) type); break; } if (LocaleCompare("synchronize",option+1) == 0) break; ThrowStreamException(OptionError,"UnrecognizedOption",option) } case 't': { if (LocaleCompare("taint",option+1) == 0) break; if (LocaleCompare("transparent-color",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowStreamException(OptionError,"MissingArgument",option); break; } ThrowStreamException(OptionError,"UnrecognizedOption",option) } case 'v': { if (LocaleCompare("verbose",option+1) == 0) break; if ((LocaleCompare("version",option+1) == 0) || (LocaleCompare("-version",option+1) == 0)) { ListMagickVersion(stdout); break; } if (LocaleCompare("virtual-pixel",option+1) == 0) { ssize_t method; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowStreamException(OptionError,"MissingArgument",option); method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse, argv[i]); if (method < 0) ThrowStreamException(OptionError, "UnrecognizedVirtualPixelMethod",argv[i]); break; } ThrowStreamException(OptionError,"UnrecognizedOption",option) } case '?': break; default: ThrowStreamException(OptionError,"UnrecognizedOption",option) } fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) & FireOptionFlag) == 0 ? MagickFalse : MagickTrue; if (fire != MagickFalse) FireImageStack(MagickFalse,MagickTrue,MagickTrue); } if (k != 0) ThrowStreamException(OptionError,"UnbalancedParenthesis",argv[i]); if (i-- != (ssize_t) (argc-1)) ThrowStreamException(OptionError,"MissingAnImageFilename",argv[i]); if (image == (Image *) NULL) ThrowStreamException(OptionError,"MissingAnImageFilename",argv[i]); FinalizeImageSettings(image_info,image,MagickTrue); if (image == (Image *) NULL) ThrowStreamException(OptionError,"MissingAnImageFilename",argv[i]); DestroyStream(); return(status != 0 ? MagickTrue : MagickFalse); }
MagickExport Image *ConnectedComponentsImage(const Image *image, const size_t connectivity,CCObjectInfo **objects,ExceptionInfo *exception) { #define ConnectedComponentsImageTag "ConnectedComponents/Image" CacheView *image_view, *component_view; CCObjectInfo *object; char *p; const char *artifact; double area_threshold; Image *component_image; MagickBooleanType status; MagickOffsetType progress; MatrixInfo *equivalences; register ssize_t i; size_t size; ssize_t first, last, n, step, y; /* Initialize connected components image attributes. */ assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickCoreSignature); if (objects != (CCObjectInfo **) NULL) *objects=(CCObjectInfo *) NULL; component_image=CloneImage(image,image->columns,image->rows,MagickTrue, exception); if (component_image == (Image *) NULL) return((Image *) NULL); component_image->depth=MAGICKCORE_QUANTUM_DEPTH; if (AcquireImageColormap(component_image,MaxColormapSize,exception) == MagickFalse) { component_image=DestroyImage(component_image); ThrowImageException(ResourceLimitError,"MemoryAllocationFailed"); } /* Initialize connected components equivalences. */ size=image->columns*image->rows; if (image->columns != (size/image->rows)) { component_image=DestroyImage(component_image); ThrowImageException(ResourceLimitError,"MemoryAllocationFailed"); } equivalences=AcquireMatrixInfo(size,1,sizeof(ssize_t),exception); if (equivalences == (MatrixInfo *) NULL) { component_image=DestroyImage(component_image); return((Image *) NULL); } for (n=0; n < (ssize_t) (image->columns*image->rows); n++) (void) SetMatrixElement(equivalences,n,0,&n); object=(CCObjectInfo *) AcquireQuantumMemory(MaxColormapSize,sizeof(*object)); if (object == (CCObjectInfo *) NULL) { equivalences=DestroyMatrixInfo(equivalences); component_image=DestroyImage(component_image); ThrowImageException(ResourceLimitError,"MemoryAllocationFailed"); } (void) ResetMagickMemory(object,0,MaxColormapSize*sizeof(*object)); for (i=0; i < (ssize_t) MaxColormapSize; i++) { object[i].id=i; object[i].bounding_box.x=(ssize_t) image->columns; object[i].bounding_box.y=(ssize_t) image->rows; GetPixelInfo(image,&object[i].color); } /* Find connected components. */ status=MagickTrue; progress=0; image_view=AcquireVirtualCacheView(image,exception); for (n=0; n < (ssize_t) (connectivity > 4 ? 4 : 2); n++) { ssize_t connect4[2][2] = { { -1, 0 }, { 0, -1 } }, connect8[4][2] = { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 } }, dx, dy; if (status == MagickFalse) continue; dy=connectivity > 4 ? connect8[n][0] : connect4[n][0]; dx=connectivity > 4 ? connect8[n][1] : connect4[n][1]; for (y=0; y < (ssize_t) image->rows; y++) { register const Quantum *magick_restrict p; register ssize_t x; if (status == MagickFalse) continue; p=GetCacheViewVirtualPixels(image_view,0,y-1,image->columns,3,exception); if (p == (const Quantum *) NULL) { status=MagickFalse; continue; } p+=GetPixelChannels(image)*image->columns; for (x=0; x < (ssize_t) image->columns; x++) { PixelInfo pixel, target; ssize_t neighbor_offset, object, offset, ox, oy, root; /* Is neighbor an authentic pixel and a different color than the pixel? */ GetPixelInfoPixel(image,p,&pixel); neighbor_offset=dy*(GetPixelChannels(image)*image->columns)+dx* GetPixelChannels(image); GetPixelInfoPixel(image,p+neighbor_offset,&target); if (((x+dx) < 0) || ((x+dx) >= (ssize_t) image->columns) || ((y+dy) < 0) || ((y+dy) >= (ssize_t) image->rows) || (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse)) { p+=GetPixelChannels(image); continue; } /* Resolve this equivalence. */ offset=y*image->columns+x; neighbor_offset=dy*image->columns+dx; ox=offset; status=GetMatrixElement(equivalences,ox,0,&object); while (object != ox) { ox=object; status=GetMatrixElement(equivalences,ox,0,&object); } oy=offset+neighbor_offset; status=GetMatrixElement(equivalences,oy,0,&object); while (object != oy) { oy=object; status=GetMatrixElement(equivalences,oy,0,&object); } if (ox < oy) { status=SetMatrixElement(equivalences,oy,0,&ox); root=ox; } else { status=SetMatrixElement(equivalences,ox,0,&oy); root=oy; } ox=offset; status=GetMatrixElement(equivalences,ox,0,&object); while (object != root) { status=GetMatrixElement(equivalences,ox,0,&object); status=SetMatrixElement(equivalences,ox,0,&root); } oy=offset+neighbor_offset; status=GetMatrixElement(equivalences,oy,0,&object); while (object != root) { status=GetMatrixElement(equivalences,oy,0,&object); status=SetMatrixElement(equivalences,oy,0,&root); } status=SetMatrixElement(equivalences,y*image->columns+x,0,&root); p+=GetPixelChannels(image); } } } image_view=DestroyCacheView(image_view); /* Label connected components. */ n=0; image_view=AcquireVirtualCacheView(image,exception); component_view=AcquireAuthenticCacheView(component_image,exception); for (y=0; y < (ssize_t) component_image->rows; y++) { register const Quantum *magick_restrict p; register Quantum *magick_restrict q; register ssize_t x; if (status == MagickFalse) continue; p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); q=QueueCacheViewAuthenticPixels(component_view,0,y,component_image->columns, 1,exception); if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) { status=MagickFalse; continue; } for (x=0; x < (ssize_t) component_image->columns; x++) { ssize_t id, offset; offset=y*image->columns+x; status=GetMatrixElement(equivalences,offset,0,&id); if (id == offset) { id=n++; if (n > (ssize_t) MaxColormapSize) break; status=SetMatrixElement(equivalences,offset,0,&id); } else { status=GetMatrixElement(equivalences,id,0,&id); status=SetMatrixElement(equivalences,offset,0,&id); } if (x < object[id].bounding_box.x) object[id].bounding_box.x=x; if (x > (ssize_t) object[id].bounding_box.width) object[id].bounding_box.width=(size_t) x; if (y < object[id].bounding_box.y) object[id].bounding_box.y=y; if (y > (ssize_t) object[id].bounding_box.height) object[id].bounding_box.height=(size_t) y; object[id].color.red+=GetPixelRed(image,p); object[id].color.green+=GetPixelGreen(image,p); object[id].color.blue+=GetPixelBlue(image,p); object[id].color.black+=GetPixelBlack(image,p); object[id].color.alpha+=GetPixelAlpha(image,p); object[id].centroid.x+=x; object[id].centroid.y+=y; object[id].area++; SetPixelIndex(component_image,(Quantum) id,q); p+=GetPixelChannels(image); q+=GetPixelChannels(component_image); } if (n > (ssize_t) MaxColormapSize) break; if (SyncCacheViewAuthenticPixels(component_view,exception) == MagickFalse) status=MagickFalse; if (image->progress_monitor != (MagickProgressMonitor) NULL) { MagickBooleanType proceed; proceed=SetImageProgress(image,ConnectedComponentsImageTag,progress++, image->rows); if (proceed == MagickFalse) status=MagickFalse; } } component_view=DestroyCacheView(component_view); image_view=DestroyCacheView(image_view); equivalences=DestroyMatrixInfo(equivalences); if (n > (ssize_t) MaxColormapSize) { object=(CCObjectInfo *) RelinquishMagickMemory(object); component_image=DestroyImage(component_image); ThrowImageException(ResourceLimitError,"TooManyObjects"); } component_image->colors=(size_t) n; for (i=0; i < (ssize_t) component_image->colors; i++) { object[i].bounding_box.width-=(object[i].bounding_box.x-1); object[i].bounding_box.height-=(object[i].bounding_box.y-1); object[i].color.red=object[i].color.red/object[i].area; object[i].color.green=object[i].color.green/object[i].area; object[i].color.blue=object[i].color.blue/object[i].area; object[i].color.alpha=object[i].color.alpha/object[i].area; object[i].color.black=object[i].color.black/object[i].area; object[i].centroid.x=object[i].centroid.x/object[i].area; object[i].centroid.y=object[i].centroid.y/object[i].area; } artifact=GetImageArtifact(image,"connected-components:area-threshold"); area_threshold=0.0; if (artifact != (const char *) NULL) area_threshold=StringToDouble(artifact,(char **) NULL); if (area_threshold > 0.0) { /* Merge object below area threshold. */ component_view=AcquireAuthenticCacheView(component_image,exception); for (i=0; i < (ssize_t) component_image->colors; i++) { double census; RectangleInfo bounding_box; register ssize_t j; size_t id; if (status == MagickFalse) continue; if ((double) object[i].area >= area_threshold) continue; for (j=0; j < (ssize_t) component_image->colors; j++) object[j].census=0; bounding_box=object[i].bounding_box; for (y=0; y < (ssize_t) bounding_box.height+2; y++) { register const Quantum *magick_restrict p; register ssize_t x; if (status == MagickFalse) continue; p=GetCacheViewVirtualPixels(component_view,bounding_box.x-1, bounding_box.y+y-1,bounding_box.width+2,1,exception); if (p == (const Quantum *) NULL) { status=MagickFalse; continue; } for (x=0; x < (ssize_t) bounding_box.width+2; x++) { j=(ssize_t) GetPixelIndex(component_image,p); if (j != i) object[j].census++; } } census=0; id=0; for (j=0; j < (ssize_t) component_image->colors; j++) if (census < object[j].census) { census=object[j].census; id=(size_t) j; } object[id].area+=object[i].area; for (y=0; y < (ssize_t) bounding_box.height; y++) { register Quantum *magick_restrict q; register ssize_t x; if (status == MagickFalse) continue; q=GetCacheViewAuthenticPixels(component_view,bounding_box.x, bounding_box.y+y,bounding_box.width,1,exception); if (q == (Quantum *) NULL) { status=MagickFalse; continue; } for (x=0; x < (ssize_t) bounding_box.width; x++) { if ((ssize_t) GetPixelIndex(component_image,q) == i) SetPixelIndex(image,(Quantum) id,q); q+=GetPixelChannels(component_image); } if (SyncCacheViewAuthenticPixels(component_view,exception) == MagickFalse) status=MagickFalse; } } (void) SyncImage(component_image,exception); }
static void test_string_to_double(void) { assert_true(1234.1234 == StringToDouble("1234.1234")); }
WandExport MagickBooleanType ImportImageCommand(ImageInfo *image_info, int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception) { #if defined(MAGICKCORE_X11_DELEGATE) #define DestroyImport() \ { \ XDestroyResourceInfo(&resource_info); \ if (display != (Display *) NULL) \ { \ XCloseDisplay(display); \ display=(Display *) NULL; \ } \ DestroyImageStack(); \ if (target_window != (char *) NULL) \ target_window=DestroyString(target_window); \ for (i=0; i < (ssize_t) argc; i++) \ argv[i]=DestroyString(argv[i]); \ argv=(char **) RelinquishMagickMemory(argv); \ } #define ThrowImportException(asperity,tag,option) \ { \ (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \ option); \ DestroyImport(); \ return(MagickFalse); \ } #define ThrowImportInvalidArgumentException(option,argument) \ { \ (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \ "InvalidArgument","`%s': %s",option,argument); \ DestroyImport(); \ return(MagickFalse); \ } char *filename, *option, *resource_value, *server_name, *target_window; Display *display; Image *image; ImageStack image_stack[MaxImageStackDepth+1]; MagickBooleanType fire, pend, respect_parenthesis; MagickStatusType status; QuantizeInfo *quantize_info; register ssize_t i; ssize_t j, k, snapshots; XImportInfo ximage_info; XResourceInfo resource_info; XrmDatabase resource_database; wand_unreferenced(metadata); /* Set defaults. */ assert(image_info != (ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); assert(exception != (ExceptionInfo *) NULL); if (argc == 2) { option=argv[1]; if ((LocaleCompare("version",option+1) == 0) || (LocaleCompare("-version",option+1) == 0)) { ListMagickVersion(stdout); return(MagickFalse); } } display=(Display *) NULL; j=1; k=0; NewImageStack(); option=(char *) NULL; pend=MagickFalse; resource_database=(XrmDatabase) NULL; respect_parenthesis=MagickFalse; (void) ResetMagickMemory(&resource_info,0,sizeof(resource_info)); server_name=(char *) NULL; status=MagickTrue; SetNotifyHandlers; target_window=(char *) NULL; /* Check for server name specified on the command line. */ ReadCommandlLine(argc,&argv); status=ExpandFilenames(&argc,&argv); if (status == MagickFalse) ThrowImportException(ResourceLimitError,"MemoryAllocationFailed", GetExceptionMessage(errno)); for (i=1; i < (ssize_t) argc; i++) { /* Check command line for server name. */ option=argv[i]; if (LocaleCompare("display",option+1) == 0) { /* User specified server name. */ i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); server_name=argv[i]; } if ((LocaleCompare("help",option+1) == 0) || (LocaleCompare("-help",option+1) == 0)) return(ImportUsage()); } /* Get user defaults from X resource database. */ display=XOpenDisplay(server_name); if (display == (Display *) NULL) ThrowImportException(XServerError,"UnableToOpenXServer", XDisplayName(server_name)); (void) XSetErrorHandler(XError); resource_database=XGetResourceDatabase(display,GetClientName()); XGetImportInfo(&ximage_info); XGetResourceInfo(image_info,resource_database,GetClientName(), &resource_info); quantize_info=resource_info.quantize_info; resource_value=XGetResourceInstance(resource_database,GetClientName(), "border","False"); ximage_info.borders=IsMagickTrue(resource_value); resource_value=XGetResourceInstance(resource_database,GetClientName(), "delay","0"); resource_info.delay=(unsigned int) StringToUnsignedLong(resource_value); image_info->density=XGetResourceInstance(resource_database,GetClientName(), "density",(char *) NULL); resource_value=XGetResourceInstance(resource_database,GetClientName(), "descend","False"); ximage_info.descend=IsMagickTrue(resource_value); resource_value=XGetResourceInstance(resource_database,GetClientName(), "frame","False"); ximage_info.frame=IsMagickTrue(resource_value); resource_value=XGetResourceInstance(resource_database,GetClientName(), "interlace","none"); image_info->interlace=UndefinedInterlace; if (LocaleCompare("None",resource_value) == 0) image_info->interlace=NoInterlace; if (LocaleCompare("Line",resource_value) == 0) image_info->interlace=LineInterlace; if (LocaleCompare("Plane",resource_value) == 0) image_info->interlace=PlaneInterlace; if (LocaleCompare("Partition",resource_value) == 0) image_info->interlace=PartitionInterlace; if (image_info->interlace == UndefinedInterlace) ThrowImportException(OptionError,"Unrecognized interlace type", resource_value); image_info->page=XGetResourceInstance(resource_database,GetClientName(), "pageGeometry",(char *) NULL); resource_value=XGetResourceInstance(resource_database,GetClientName(), "pause","0"); resource_info.pause=(unsigned int) StringToUnsignedLong(resource_value); resource_value=XGetResourceInstance(resource_database,GetClientName(), "quality","85"); image_info->quality=StringToUnsignedLong(resource_value); resource_value=XGetResourceInstance(resource_database,GetClientName(), "screen","False"); ximage_info.screen=IsMagickTrue(resource_value); resource_value=XGetResourceInstance(resource_database,GetClientName(), "silent","False"); ximage_info.silent=IsMagickTrue(resource_value); resource_value=XGetResourceInstance(resource_database,GetClientName(), "verbose","False"); image_info->verbose=IsMagickTrue(resource_value); resource_value=XGetResourceInstance(resource_database,GetClientName(), "dither","True"); quantize_info->dither=IsMagickTrue(resource_value); snapshots=1; status=MagickTrue; filename=(char *) NULL; /* Check command syntax. */ for (i=1; i < (ssize_t) argc; i++) { option=argv[i]; if (LocaleCompare(option,"(") == 0) { FireImageStack(MagickFalse,MagickTrue,pend); if (k == MaxImageStackDepth) ThrowImportException(OptionError,"ParenthesisNestedTooDeeply", option); PushImageStack(); continue; } if (LocaleCompare(option,")") == 0) { FireImageStack(MagickFalse,MagickTrue,MagickTrue); if (k == 0) ThrowImportException(OptionError,"UnableToParseExpression",option); PopImageStack(); continue; } if (IsCommandOption(option) == MagickFalse) { Image *images; size_t scene; /* Read image from X server. */ FireImageStack(MagickFalse,MagickFalse,pend); filename=argv[i]; if (target_window != (char *) NULL) (void) CopyMagickString(image_info->filename,target_window, MaxTextExtent); for (scene=0; scene < (size_t) MagickMax(snapshots,1); scene++) { (void) sleep(resource_info.pause); images=XImportImage(image_info,&ximage_info); status&=(images != (Image *) NULL) && (exception->severity < ErrorException); if (images == (Image *) NULL) continue; (void) CopyMagickString(images->filename,filename,MaxTextExtent); (void) CopyMagickString(images->magick,"PS",MaxTextExtent); images->scene=scene; AppendImageStack(images); } continue; } pend=image != (Image *) NULL ? MagickTrue : MagickFalse; switch(*(option+1)) { case 'a': { if (LocaleCompare("adjoin",option+1) == 0) break; if (LocaleCompare("annotate",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); if (i == (ssize_t) (argc-1)) ThrowImportException(OptionError,"MissingArgument",option); i++; break; } ThrowImportException(OptionError,"UnrecognizedOption",option); } case 'b': { if (LocaleCompare("border",option+1) == 0) { (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent); ximage_info.borders=(*option == '-') ? MagickTrue : MagickFalse; break; } if (LocaleCompare("bordercolor",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); break; } ThrowImportException(OptionError,"UnrecognizedOption",option); } case 'c': { if (LocaleCompare("cache",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("channel",option+1) == 0) { ssize_t channel; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowImportException(OptionError,"MissingArgument",option); channel=ParseChannelOption(argv[i]); if (channel < 0) ThrowImportException(OptionError,"UnrecognizedChannelType", argv[i]); break; } if (LocaleCompare("colors",option+1) == 0) { quantize_info->number_colors=0; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); quantize_info->number_colors=StringToUnsignedLong(argv[i]); break; } if (LocaleCompare("colorspace",option+1) == 0) { ssize_t colorspace; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse, argv[i]); if (colorspace < 0) ThrowImportException(OptionError,"UnrecognizedColorspace", argv[i]); break; } if (LocaleCompare("comment",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); status=SetImageOption(image_info,"comment",argv[i]); if (status == MagickFalse) ThrowImportException(OptionError,"UnrecognizedOption",argv[i]); break; } if (LocaleCompare("compress",option+1) == 0) { ssize_t compress; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); compress=ParseCommandOption(MagickCompressOptions,MagickFalse, argv[i]); if (compress < 0) ThrowImportException(OptionError,"UnrecognizedImageCompression", argv[i]); break; } if (LocaleCompare("concurrent",option+1) == 0) break; if (LocaleCompare("crop",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); break; } ThrowImportException(OptionError,"UnrecognizedOption",option); } case 'd': { if (LocaleCompare("debug",option+1) == 0) { ssize_t event; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]); if (event < 0) ThrowImportException(OptionError,"UnrecognizedEventType",argv[i]); (void) SetLogEventMask(argv[i]); break; } if (LocaleCompare("define",option+1) == 0) { i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (*option == '+') { const char *define; define=GetImageOption(image_info,argv[i]); if (define == (char *) NULL) ThrowImportException(OptionError,"NoSuchOption",argv[i]); break; } break; } if (LocaleCompare("delay",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); status=SetImageOption(image_info,"delay",argv[i]); if (status == MagickFalse) ThrowImportException(OptionError,"UnrecognizedOption",argv[i]); break; } if (LocaleCompare("density",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("depth",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("descend",option+1) == 0) { ximage_info.descend=(*option == '-') ? MagickTrue : MagickFalse; break; } if (LocaleCompare("display",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); break; } if (LocaleCompare("dispose",option+1) == 0) { ssize_t dispose; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]); if (dispose < 0) ThrowImportException(OptionError,"UnrecognizedDisposeMethod", argv[i]); break; } if (LocaleCompare("dither",option+1) == 0) { ssize_t method; quantize_info->dither=MagickFalse; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]); if (method < 0) ThrowImportException(OptionError,"UnrecognizedDitherMethod", argv[i]); quantize_info->dither=MagickTrue; quantize_info->dither_method=(DitherMethod) method; break; } if (LocaleCompare("duration",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); break; } ThrowImportException(OptionError,"UnrecognizedOption",option); } case 'e': { if (LocaleCompare("encipher",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowImportException(OptionError,"MissingArgument",option); break; } if (LocaleCompare("encoding",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); break; } if (LocaleCompare("endian",option+1) == 0) { ssize_t endian; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); endian=ParseCommandOption(MagickEndianOptions,MagickFalse, argv[i]); if (endian < 0) ThrowImportException(OptionError,"UnrecognizedEndianType", argv[i]); break; } ThrowImportException(OptionError,"UnrecognizedOption",option); } case 'f': { if (LocaleCompare("filter",option+1) == 0) { ssize_t filter; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowImportException(OptionError,"MissingArgument",option); filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]); if (filter < 0) ThrowImportException(OptionError,"UnrecognizedImageFilter", argv[i]); break; } if (LocaleCompare("frame",option+1) == 0) { (void) CopyMagickString(argv[i]+1,"sans0",MaxTextExtent); ximage_info.frame=(*option == '-') ? MagickTrue : MagickFalse; break; } if (LocaleCompare("format",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowImportException(OptionError,"MissingArgument",option); break; } ThrowImportException(OptionError,"UnrecognizedOption",option); } case 'g': { if (LocaleCompare("geometry",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("gravity",option+1) == 0) { ssize_t gravity; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]); if (gravity < 0) ThrowImportException(OptionError,"UnrecognizedGravityType", argv[i]); break; } ThrowImportException(OptionError,"UnrecognizedOption",option); } case 'h': { if (LocaleCompare("help",option+1) == 0) break; ThrowImportException(OptionError,"UnrecognizedOption",option); } case 'i': { if (LocaleCompare("identify",option+1) == 0) break; if (LocaleCompare("interlace",option+1) == 0) { ssize_t interlace; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse, argv[i]); if (interlace < 0) ThrowImportException(OptionError,"UnrecognizedInterlaceType", argv[i]); break; } if (LocaleCompare("interpolate",option+1) == 0) { ssize_t interpolate; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse, argv[i]); if (interpolate < 0) ThrowImportException(OptionError,"UnrecognizedInterpolateMethod", argv[i]); break; } ThrowImportException(OptionError,"UnrecognizedOption",option); } case 'l': { if (LocaleCompare("label",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); status=SetImageOption(image_info,"label",argv[i]); if (status == MagickFalse) ThrowImportException(OptionError,"UnrecognizedOption",argv[i]); break; } if (LocaleCompare("limit",option+1) == 0) { char *p; double value; ssize_t resource; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); resource=ParseCommandOption(MagickResourceOptions,MagickFalse, argv[i]); if (resource < 0) ThrowImportException(OptionError,"UnrecognizedResourceType", argv[i]); i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); value=StringToDouble(argv[i],&p); (void) value; if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0)) ThrowImportInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("list",option+1) == 0) { ssize_t list; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]); if (list < 0) ThrowImportException(OptionError,"UnrecognizedListType",argv[i]); status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **) argv+j,exception); DestroyImport(); return(status != 0 ? MagickFalse : MagickTrue); } if (LocaleCompare("log",option+1) == 0) { if (*option == '+') break; i++; if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL)) ThrowImportException(OptionError,"MissingArgument",option); break; } ThrowImportException(OptionError,"UnrecognizedOption",option); } case 'm': { if (LocaleCompare("monitor",option+1) == 0) break; if (LocaleCompare("monochrome",option+1) == 0) { if (*option == '+') break; quantize_info->number_colors=2; quantize_info->colorspace=GRAYColorspace; break; } ThrowImportException(OptionError,"UnrecognizedOption",option); } case 'n': { if (LocaleCompare("negate",option+1) == 0) break; ThrowImportException(OptionError,"UnrecognizedOption",option); } case 'p': { if (LocaleCompare("page",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); status=SetImageOption(image_info,"page",argv[i]); if (status == MagickFalse) ThrowImportException(OptionError,"UnrecognizedOption",argv[i]); break; } if (LocaleCompare("pause",option+1) == 0) { resource_info.pause=0; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); resource_info.pause=(unsigned int) StringToUnsignedLong(argv[i]); break; } if (LocaleCompare("ping",option+1) == 0) break; /* deprecated option */ if (LocaleCompare("pointsize",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); break; } ThrowImportException(OptionError,"UnrecognizedOption",option); } case 'q': { if (LocaleCompare("quality",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("quantize",option+1) == 0) { ssize_t colorspace; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowImportException(OptionError,"MissingArgument",option); colorspace=ParseCommandOption(MagickColorspaceOptions, MagickFalse,argv[i]); if (colorspace < 0) ThrowImportException(OptionError,"UnrecognizedColorspace", argv[i]); break; } if (LocaleCompare("quiet",option+1) == 0) break; ThrowImportException(OptionError,"UnrecognizedOption",option); } case 'r': { if (LocaleCompare("regard-warnings",option+1) == 0) break; if (LocaleCompare("repage",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("resize",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); break; } if (LocaleNCompare("respect-parentheses",option+1,17) == 0) { respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse; break; } if (LocaleCompare("rotate",option+1) == 0) { i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); break; } ThrowImportException(OptionError,"UnrecognizedOption",option); } case 's': { if (LocaleCompare("sampling-factor",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("scene",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("set",option+1) == 0) { i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); break; } if (LocaleCompare("screen",option+1) == 0) { ximage_info.screen=(*option == '-') ? MagickTrue : MagickFalse; break; } if (LocaleCompare("seed",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("silent",option+1) == 0) { ximage_info.silent=(*option == '-') ? MagickTrue : MagickFalse; break; } if (LocaleCompare("snaps",option+1) == 0) { (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent); i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); snapshots=(ssize_t) StringToLong(argv[i]); break; } if (LocaleCompare("strip",option+1) == 0) break; if (LocaleCompare("support",option+1) == 0) { i++; /* deprecated */ break; } if (LocaleCompare("synchronize",option+1) == 0) break; ThrowImportException(OptionError,"UnrecognizedOption",option); } case 't': { if (LocaleCompare("taint",option+1) == 0) break; if (LocaleCompare("thumbnail",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("transparent",option+1) == 0) { i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); break; } if (LocaleCompare("transparent-color",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowImportException(OptionError,"MissingArgument",option); break; } if (LocaleCompare("treedepth",option+1) == 0) { quantize_info->tree_depth=0; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowImportInvalidArgumentException(option,argv[i]); quantize_info->tree_depth=StringToUnsignedLong(argv[i]); break; } if (LocaleCompare("trim",option+1) == 0) break; if (LocaleCompare("type",option+1) == 0) { ssize_t type; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]); if (type < 0) ThrowImportException(OptionError,"UnrecognizedImageType",argv[i]); break; } ThrowImportException(OptionError,"UnrecognizedOption",option); } case 'w': { i++; if (i == (ssize_t) argc) ThrowImportException(OptionError,"MissingArgument",option); (void) CloneString(&target_window,argv[i]); break; } case 'v': { if (LocaleCompare("verbose",option+1) == 0) break; if ((LocaleCompare("version",option+1) == 0) || (LocaleCompare("-version",option+1) == 0)) { ListMagickVersion(stdout); break; } ThrowImportException(OptionError,"UnrecognizedOption",option); } case '?': break; default: ThrowImportException(OptionError,"UnrecognizedOption",option); } fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) & FireOptionFlag) == 0 ? MagickFalse : MagickTrue; if (fire != MagickFalse) FireImageStack(MagickFalse,MagickTrue,MagickTrue); } if (k != 0) ThrowImportException(OptionError,"UnbalancedParenthesis",argv[i]); if (i-- != (ssize_t) argc) ThrowImportException(OptionError,"MissingAnImageFilename",argv[i]); if (image == (Image *) NULL) ThrowImportException(OptionError,"MissingAnImageFilename",argv[argc-1]); FinalizeImageSettings(image_info,image,MagickTrue); status&=WriteImages(image_info,image,filename,exception); DestroyImport(); return(status != 0 ? MagickTrue : MagickFalse); #else (void) argc; (void) argv; (void) ThrowMagickException(exception,GetMagickModule(),MissingDelegateError, "DelegateLibrarySupportNotBuiltIn","`%s' (X11)",image_info->filename); return(ImportUsage()); #endif }
WandExport MagickBooleanType CompareImageCommand(ImageInfo *image_info, int argc,char **argv,char **metadata,ExceptionInfo *exception) { #define DefaultDissimilarityThreshold 0.31830988618379067154 #define DestroyCompare() \ { \ if (similarity_image != (Image *) NULL) \ similarity_image=DestroyImageList(similarity_image); \ if (difference_image != (Image *) NULL) \ difference_image=DestroyImageList(difference_image); \ DestroyImageStack(); \ for (i=0; i < (ssize_t) argc; i++) \ argv[i]=DestroyString(argv[i]); \ argv=(char **) RelinquishMagickMemory(argv); \ } #define ThrowCompareException(asperity,tag,option) \ { \ if (exception->severity < (asperity)) \ (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag, \ "`%s'",option); \ DestroyCompare(); \ return(MagickFalse); \ } #define ThrowCompareInvalidArgumentException(option,argument) \ { \ (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \ "InvalidArgument","`%s': %s",option,argument); \ DestroyCompare(); \ return(MagickFalse); \ } char *filename, *option; const char *format; ChannelType channels; double dissimilarity_threshold, distortion, similarity_metric; Image *difference_image, *image, *reconstruct_image, *similarity_image; ImageStack image_stack[MaxImageStackDepth+1]; MagickBooleanType fire, pend, respect_parenthesis, subimage_search; MagickStatusType status; MetricType metric; RectangleInfo offset; register ssize_t i; ssize_t j, k; /* Set defaults. */ assert(image_info != (ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); assert(exception != (ExceptionInfo *) NULL); if (argc == 2) { option=argv[1]; if ((LocaleCompare("version",option+1) == 0) || (LocaleCompare("-version",option+1) == 0)) { (void) FormatLocaleFile(stdout,"Version: %s\n", GetMagickVersion((size_t *) NULL)); (void) FormatLocaleFile(stdout,"Copyright: %s\n", GetMagickCopyright()); (void) FormatLocaleFile(stdout,"Features: %s\n\n", GetMagickFeatures()); return(MagickFalse); } } if (argc < 3) return(CompareUsage()); channels=CompositeChannels; difference_image=NewImageList(); similarity_image=NewImageList(); dissimilarity_threshold=DefaultDissimilarityThreshold; distortion=0.0; format=(char *) NULL; j=1; k=0; metric=UndefinedMetric; NewImageStack(); option=(char *) NULL; pend=MagickFalse; reconstruct_image=NewImageList(); respect_parenthesis=MagickFalse; status=MagickTrue; subimage_search=MagickFalse; /* Compare an image. */ ReadCommandlLine(argc,&argv); status=ExpandFilenames(&argc,&argv); if (status == MagickFalse) ThrowCompareException(ResourceLimitError,"MemoryAllocationFailed", GetExceptionMessage(errno)); for (i=1; i < (ssize_t) (argc-1); i++) { option=argv[i]; if (LocaleCompare(option,"(") == 0) { FireImageStack(MagickTrue,MagickTrue,pend); if (k == MaxImageStackDepth) ThrowCompareException(OptionError,"ParenthesisNestedTooDeeply", option); PushImageStack(); continue; } if (LocaleCompare(option,")") == 0) { FireImageStack(MagickTrue,MagickTrue,MagickTrue); if (k == 0) ThrowCompareException(OptionError,"UnableToParseExpression",option); PopImageStack(); continue; } if (IsCommandOption(option) == MagickFalse) { Image *images; /* Read input image. */ FireImageStack(MagickFalse,MagickFalse,pend); filename=argv[i]; if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1))) filename=argv[++i]; (void) CopyMagickString(image_info->filename,filename,MaxTextExtent); images=ReadImages(image_info,exception); status&=(images != (Image *) NULL) && (exception->severity < ErrorException); if (images == (Image *) NULL) continue; AppendImageStack(images); continue; } pend=image != (Image *) NULL ? MagickTrue : MagickFalse; switch (*(option+1)) { case 'a': { if (LocaleCompare("alpha",option+1) == 0) { ssize_t type; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]); if (type < 0) ThrowCompareException(OptionError,"UnrecognizedAlphaChannelType", argv[i]); break; } if (LocaleCompare("authenticate",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); break; } ThrowCompareException(OptionError,"UnrecognizedOption",option); } case 'c': { if (LocaleCompare("cache",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowCompareInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("channel",option+1) == 0) { ssize_t channel; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowCompareException(OptionError,"MissingArgument",option); channel=ParseChannelOption(argv[i]); if (channel < 0) ThrowCompareException(OptionError,"UnrecognizedChannelType", argv[i]); channels=(ChannelType) channel; break; } if (LocaleCompare("colorspace",option+1) == 0) { ssize_t colorspace; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowCompareException(OptionError,"MissingArgument",option); colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse, argv[i]); if (colorspace < 0) ThrowCompareException(OptionError,"UnrecognizedColorspace", argv[i]); break; } if (LocaleCompare("compose",option+1) == 0) { ssize_t compose; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); compose=ParseCommandOption(MagickComposeOptions,MagickFalse, argv[i]); if (compose < 0) ThrowCompareException(OptionError,"UnrecognizedComposeOperator", argv[i]); break; } if (LocaleCompare("compress",option+1) == 0) { ssize_t compress; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowCompareException(OptionError,"MissingArgument",option); compress=ParseCommandOption(MagickCompressOptions,MagickFalse, argv[i]); if (compress < 0) ThrowCompareException(OptionError,"UnrecognizedImageCompression", argv[i]); break; } if (LocaleCompare("concurrent",option+1) == 0) break; ThrowCompareException(OptionError,"UnrecognizedOption",option) } case 'd': { if (LocaleCompare("debug",option+1) == 0) { LogEventType event_mask; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); event_mask=SetLogEventMask(argv[i]); if (event_mask == UndefinedEvents) ThrowCompareException(OptionError,"UnrecognizedEventType", argv[i]); break; } if (LocaleCompare("decipher",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowCompareException(OptionError,"MissingArgument",option); break; } if (LocaleCompare("define",option+1) == 0) { i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); if (*option == '+') { const char *define; define=GetImageOption(image_info,argv[i]); if (define == (const char *) NULL) ThrowCompareException(OptionError,"NoSuchOption",argv[i]); break; } break; } if (LocaleCompare("density",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowCompareInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("depth",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowCompareInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("dissimilarity-threshold",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowCompareInvalidArgumentException(option,argv[i]); if (*option == '+') dissimilarity_threshold=DefaultDissimilarityThreshold; else dissimilarity_threshold=StringToDouble(argv[i],(char **) NULL); break; } if (LocaleCompare("duration",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowCompareException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowCompareInvalidArgumentException(option,argv[i]); break; } ThrowCompareException(OptionError,"UnrecognizedOption",option) } case 'e': { if (LocaleCompare("encipher",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowCompareException(OptionError,"MissingArgument",option); break; } if (LocaleCompare("extract",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowCompareException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowCompareInvalidArgumentException(option,argv[i]); break; } ThrowCompareException(OptionError,"UnrecognizedOption",option) } case 'f': { if (LocaleCompare("format",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); format=argv[i]; break; } if (LocaleCompare("fuzz",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowCompareException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowCompareInvalidArgumentException(option,argv[i]); break; } ThrowCompareException(OptionError,"UnrecognizedOption",option) } case 'h': { if ((LocaleCompare("help",option+1) == 0) || (LocaleCompare("-help",option+1) == 0)) return(CompareUsage()); if (LocaleCompare("highlight-color",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowCompareException(OptionError,"MissingArgument",option); break; } ThrowCompareException(OptionError,"UnrecognizedOption",option) } case 'i': { if (LocaleCompare("identify",option+1) == 0) break; if (LocaleCompare("interlace",option+1) == 0) { ssize_t interlace; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse, argv[i]); if (interlace < 0) ThrowCompareException(OptionError,"UnrecognizedInterlaceType", argv[i]); break; } ThrowCompareException(OptionError,"UnrecognizedOption",option) } case 'l': { if (LocaleCompare("limit",option+1) == 0) { char *p; double value; ssize_t resource; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); resource=ParseCommandOption(MagickResourceOptions,MagickFalse, argv[i]); if (resource < 0) ThrowCompareException(OptionError,"UnrecognizedResourceType", argv[i]); i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); value=StringToDouble(argv[i],&p); (void) value; if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0)) ThrowCompareInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("list",option+1) == 0) { ssize_t list; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]); if (list < 0) ThrowCompareException(OptionError,"UnrecognizedListType",argv[i]); status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **) argv+j,exception); DestroyCompare(); return(status != 0 ? MagickFalse : MagickTrue); } if (LocaleCompare("log",option+1) == 0) { if (*option == '+') break; i++; if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL)) ThrowCompareException(OptionError,"MissingArgument",option); break; } if (LocaleCompare("lowlight-color",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowCompareException(OptionError,"MissingArgument",option); break; } ThrowCompareException(OptionError,"UnrecognizedOption",option) } case 'm': { if (LocaleCompare("matte",option+1) == 0) break; if (LocaleCompare("metric",option+1) == 0) { ssize_t type; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); type=ParseCommandOption(MagickMetricOptions,MagickTrue,argv[i]); if (type < 0) ThrowCompareException(OptionError,"UnrecognizedMetricType", argv[i]); metric=(MetricType) type; break; } if (LocaleCompare("monitor",option+1) == 0) break; ThrowCompareException(OptionError,"UnrecognizedOption",option) } case 'p': { if (LocaleCompare("passphrase",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); break; } if (LocaleCompare("profile",option+1) == 0) { i++; if (i == (ssize_t) (argc-1)) ThrowCompareException(OptionError,"MissingArgument",option); break; } ThrowCompareException(OptionError,"UnrecognizedOption",option) } case 'q': { if (LocaleCompare("quality",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowCompareException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowCompareInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("quantize",option+1) == 0) { ssize_t colorspace; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowCompareException(OptionError,"MissingArgument",option); colorspace=ParseCommandOption(MagickColorspaceOptions, MagickFalse,argv[i]); if (colorspace < 0) ThrowCompareException(OptionError,"UnrecognizedColorspace", argv[i]); break; } if (LocaleCompare("quiet",option+1) == 0) break; ThrowCompareException(OptionError,"UnrecognizedOption",option) } case 'r': { if (LocaleCompare("regard-warnings",option+1) == 0) break; if (LocaleNCompare("respect-parentheses",option+1,17) == 0) { respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse; break; } ThrowCompareException(OptionError,"UnrecognizedOption",option) } case 's': { if (LocaleCompare("sampling-factor",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowCompareInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("seed",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowCompareException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowCompareInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("set",option+1) == 0) { i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); break; } if (LocaleCompare("size",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowCompareInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("subimage-search",option+1) == 0) { if (*option == '+') { subimage_search=MagickFalse; break; } subimage_search=MagickTrue; break; } if (LocaleCompare("synchronize",option+1) == 0) break; ThrowCompareException(OptionError,"UnrecognizedOption",option) } case 't': { if (LocaleCompare("taint",option+1) == 0) break; if (LocaleCompare("transparent-color",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowCompareException(OptionError,"MissingArgument",option); break; } if (LocaleCompare("type",option+1) == 0) { ssize_t type; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowCompareException(OptionError,"MissingArgument",option); type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]); if (type < 0) ThrowCompareException(OptionError,"UnrecognizedImageType", argv[i]); break; } ThrowCompareException(OptionError,"UnrecognizedOption",option) } case 'v': { if (LocaleCompare("verbose",option+1) == 0) break; if ((LocaleCompare("version",option+1) == 0) || (LocaleCompare("-version",option+1) == 0)) { (void) FormatLocaleFile(stdout,"Version: %s\n", GetMagickVersion((size_t *) NULL)); (void) FormatLocaleFile(stdout,"Copyright: %s\n", GetMagickCopyright()); (void) FormatLocaleFile(stdout,"Features: %s\n\n", GetMagickFeatures()); break; } if (LocaleCompare("virtual-pixel",option+1) == 0) { ssize_t method; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowCompareException(OptionError,"MissingArgument",option); method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse, argv[i]); if (method < 0) ThrowCompareException(OptionError, "UnrecognizedVirtualPixelMethod",argv[i]); break; } ThrowCompareException(OptionError,"UnrecognizedOption",option) } case '?': break; default: ThrowCompareException(OptionError,"UnrecognizedOption",option) } fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) & FireOptionFlag) == 0 ? MagickFalse : MagickTrue; if (fire != MagickFalse) FireImageStack(MagickTrue,MagickTrue,MagickTrue); } if (k != 0) ThrowCompareException(OptionError,"UnbalancedParenthesis",argv[i]); if (i-- != (ssize_t) (argc-1)) ThrowCompareException(OptionError,"MissingAnImageFilename",argv[i]); if ((image == (Image *) NULL) || (GetImageListLength(image) < 2)) ThrowCompareException(OptionError,"MissingAnImageFilename",argv[i]); FinalizeImageSettings(image_info,image,MagickTrue); if ((image == (Image *) NULL) || (GetImageListLength(image) < 2)) ThrowCompareException(OptionError,"MissingAnImageFilename",argv[i]); image=GetImageFromList(image,0); reconstruct_image=GetImageFromList(image,1); if (subimage_search != MagickFalse) { similarity_image=SimilarityMetricImage(image,reconstruct_image,metric, &offset,&similarity_metric,exception); if (similarity_metric > dissimilarity_threshold) ThrowCompareException(ImageError,"ImagesTooDissimilar",image->filename); } if ((reconstruct_image->columns == image->columns) && (reconstruct_image->rows == image->rows)) difference_image=CompareImageChannels(image,reconstruct_image,channels, metric,&distortion,exception); else if (similarity_image == (Image *) NULL) ThrowCompareException(OptionError,"ImageWidthsOrHeightsDiffer", image->filename) else { Image *composite_image; /* Determine if reconstructed image is a subimage of the image. */ composite_image=CloneImage(image,0,0,MagickTrue,exception); if (composite_image == (Image *) NULL) difference_image=CompareImageChannels(image,reconstruct_image, channels,metric,&distortion,exception); else { (void) CompositeImage(composite_image,CopyCompositeOp, reconstruct_image,offset.x,offset.y); difference_image=CompareImageChannels(image,composite_image, channels,metric,&distortion,exception); if (difference_image != (Image *) NULL) { difference_image->page.x=offset.x; difference_image->page.y=offset.y; } composite_image=DestroyImage(composite_image); } if (difference_image != (Image *) NULL) { AppendImageToList(&difference_image,similarity_image); similarity_image=(Image *) NULL; } } if (difference_image == (Image *) NULL) status=0; else { if (image_info->verbose != MagickFalse) (void) IsImagesEqual(image,reconstruct_image); if (*difference_image->magick == '\0') (void) CopyMagickString(difference_image->magick,image->magick, MaxTextExtent); if (image_info->verbose == MagickFalse) { switch (metric) { case FuzzErrorMetric: case MeanAbsoluteErrorMetric: case MeanSquaredErrorMetric: case RootMeanSquaredErrorMetric: case PeakAbsoluteErrorMetric: { (void) FormatLocaleFile(stderr,"%g (%g)",QuantumRange*distortion, (double) distortion); if ((reconstruct_image->columns != image->columns) || (reconstruct_image->rows != image->rows)) (void) FormatLocaleFile(stderr," @ %.20g,%.20g",(double) difference_image->page.x,(double) difference_image->page.y); (void) FormatLocaleFile(stderr,"\n"); break; } case AbsoluteErrorMetric: case NormalizedCrossCorrelationErrorMetric: case PeakSignalToNoiseRatioMetric: { (void) FormatLocaleFile(stderr,"%g",distortion); if ((reconstruct_image->columns != image->columns) || (reconstruct_image->rows != image->rows)) (void) FormatLocaleFile(stderr," @ %.20g,%.20g",(double) difference_image->page.x,(double) difference_image->page.y); (void) FormatLocaleFile(stderr,"\n"); break; } case MeanErrorPerPixelMetric: { (void) FormatLocaleFile(stderr,"%g (%g, %g)",distortion, image->error.normalized_mean_error, image->error.normalized_maximum_error); if ((reconstruct_image->columns != image->columns) || (reconstruct_image->rows != image->rows)) (void) FormatLocaleFile(stderr," @ %.20g,%.20g",(double) difference_image->page.x,(double) difference_image->page.y); (void) FormatLocaleFile(stderr,"\n"); break; } case UndefinedMetric: break; } } else { double *channel_distortion; channel_distortion=GetImageChannelDistortions(image,reconstruct_image, metric,&image->exception); (void) FormatLocaleFile(stderr,"Image: %s\n",image->filename); if ((reconstruct_image->columns != image->columns) || (reconstruct_image->rows != image->rows)) (void) FormatLocaleFile(stderr,"Offset: %.20g,%.20g\n",(double) difference_image->page.x,(double) difference_image->page.y); (void) FormatLocaleFile(stderr," Channel distortion: %s\n", CommandOptionToMnemonic(MagickMetricOptions,(ssize_t) metric)); switch (metric) { case FuzzErrorMetric: case MeanAbsoluteErrorMetric: case MeanSquaredErrorMetric: case RootMeanSquaredErrorMetric: case PeakAbsoluteErrorMetric: { switch (image->colorspace) { case RGBColorspace: default: { (void) FormatLocaleFile(stderr," red: %g (%g)\n", QuantumRange*channel_distortion[RedChannel], channel_distortion[RedChannel]); (void) FormatLocaleFile(stderr," green: %g (%g)\n", QuantumRange*channel_distortion[GreenChannel], channel_distortion[GreenChannel]); (void) FormatLocaleFile(stderr," blue: %g (%g)\n", QuantumRange*channel_distortion[BlueChannel], channel_distortion[BlueChannel]); if (image->matte != MagickFalse) (void) FormatLocaleFile(stderr," alpha: %g (%g)\n", QuantumRange*channel_distortion[OpacityChannel], channel_distortion[OpacityChannel]); break; } case CMYKColorspace: { (void) FormatLocaleFile(stderr," cyan: %g (%g)\n", QuantumRange*channel_distortion[CyanChannel], channel_distortion[CyanChannel]); (void) FormatLocaleFile(stderr," magenta: %g (%g)\n", QuantumRange*channel_distortion[MagentaChannel], channel_distortion[MagentaChannel]); (void) FormatLocaleFile(stderr," yellow: %g (%g)\n", QuantumRange*channel_distortion[YellowChannel], channel_distortion[YellowChannel]); (void) FormatLocaleFile(stderr," black: %g (%g)\n", QuantumRange*channel_distortion[BlackChannel], channel_distortion[BlackChannel]); if (image->matte != MagickFalse) (void) FormatLocaleFile(stderr," alpha: %g (%g)\n", QuantumRange*channel_distortion[OpacityChannel], channel_distortion[OpacityChannel]); break; } case GRAYColorspace: { (void) FormatLocaleFile(stderr," gray: %g (%g)\n", QuantumRange*channel_distortion[GrayChannel], channel_distortion[GrayChannel]); if (image->matte != MagickFalse) (void) FormatLocaleFile(stderr," alpha: %g (%g)\n", QuantumRange*channel_distortion[OpacityChannel], channel_distortion[OpacityChannel]); break; } } (void) FormatLocaleFile(stderr," all: %g (%g)\n", QuantumRange*channel_distortion[CompositeChannels], channel_distortion[CompositeChannels]); break; } case AbsoluteErrorMetric: case NormalizedCrossCorrelationErrorMetric: case PeakSignalToNoiseRatioMetric: { switch (image->colorspace) { case RGBColorspace: default: { (void) FormatLocaleFile(stderr," red: %g\n", channel_distortion[RedChannel]); (void) FormatLocaleFile(stderr," green: %g\n", channel_distortion[GreenChannel]); (void) FormatLocaleFile(stderr," blue: %g\n", channel_distortion[BlueChannel]); if (image->matte != MagickFalse) (void) FormatLocaleFile(stderr," alpha: %g\n", channel_distortion[OpacityChannel]); break; } case CMYKColorspace: { (void) FormatLocaleFile(stderr," cyan: %g\n", channel_distortion[CyanChannel]); (void) FormatLocaleFile(stderr," magenta: %g\n", channel_distortion[MagentaChannel]); (void) FormatLocaleFile(stderr," yellow: %g\n", channel_distortion[YellowChannel]); (void) FormatLocaleFile(stderr," black: %g\n", channel_distortion[BlackChannel]); if (image->matte != MagickFalse) (void) FormatLocaleFile(stderr," alpha: %g\n", channel_distortion[OpacityChannel]); break; } case GRAYColorspace: { (void) FormatLocaleFile(stderr," gray: %g\n", channel_distortion[GrayChannel]); if (image->matte != MagickFalse) (void) FormatLocaleFile(stderr," alpha: %g\n", channel_distortion[OpacityChannel]); break; } } (void) FormatLocaleFile(stderr," all: %g\n", channel_distortion[CompositeChannels]); break; } case MeanErrorPerPixelMetric: { (void) FormatLocaleFile(stderr," %g (%g, %g)\n", channel_distortion[CompositeChannels], image->error.normalized_mean_error, image->error.normalized_maximum_error); break; } case UndefinedMetric: break; } channel_distortion=(double *) RelinquishMagickMemory( channel_distortion); } status&=WriteImages(image_info,difference_image,argv[argc-1],exception); if ((metadata != (char **) NULL) && (format != (char *) NULL)) { char *text; text=InterpretImageProperties(image_info,difference_image,format); if (text == (char *) NULL) ThrowCompareException(ResourceLimitError,"MemoryAllocationFailed", GetExceptionMessage(errno)); (void) ConcatenateString(&(*metadata),text); (void) ConcatenateString(&(*metadata),"\n"); text=DestroyString(text); } difference_image=DestroyImageList(difference_image); } DestroyCompare(); return(status != 0 ? MagickTrue : MagickFalse); }
static Image *ReadFITSImage(const ImageInfo *image_info, ExceptionInfo *exception) { typedef struct _FITSInfo { MagickBooleanType extend, simple; int bits_per_pixel, columns, rows, number_axes, number_planes; double min_data, max_data, zero, scale; EndianType endian; } FITSInfo; char *comment, keyword[9], property[MaxTextExtent], value[73]; double pixel, scale; FITSInfo fits_info; Image *image; int c; ssize_t scene, y; MagickBooleanType status; MagickSizeType number_pixels; register ssize_t i, x; register PixelPacket *q; ssize_t count; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AcquireImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } /* Initialize image header. */ (void) ResetMagickMemory(&fits_info,0,sizeof(fits_info)); fits_info.extend=MagickFalse; fits_info.simple=MagickFalse; fits_info.bits_per_pixel=8; fits_info.columns=1; fits_info.rows=1; fits_info.rows=1; fits_info.number_planes=1; fits_info.min_data=0.0; fits_info.max_data=0.0; fits_info.zero=0.0; fits_info.scale=1.0; fits_info.endian=MSBEndian; /* Decode image header. */ for (comment=(char *) NULL; EOFBlob(image) == MagickFalse; ) { for ( ; EOFBlob(image) == MagickFalse; ) { register char *p; count=ReadBlob(image,8,(unsigned char *) keyword); if (count != 8) break; for (i=0; i < 8; i++) { if (isspace((int) ((unsigned char) keyword[i])) != 0) break; keyword[i]=tolower((int) ((unsigned char) keyword[i])); } keyword[i]='\0'; count=ReadBlob(image,72,(unsigned char *) value); if (count != 72) break; value[72]='\0'; p=value; if (*p == '=') { p+=2; while (isspace((int) ((unsigned char) *p)) != 0) p++; } if (LocaleCompare(keyword,"end") == 0) break; if (LocaleCompare(keyword,"extend") == 0) fits_info.extend=(*p == 'T') || (*p == 't') ? MagickTrue : MagickFalse; if (LocaleCompare(keyword,"simple") == 0) fits_info.simple=(*p == 'T') || (*p == 't') ? MagickTrue : MagickFalse; if (LocaleCompare(keyword,"bitpix") == 0) fits_info.bits_per_pixel=StringToLong(p); if (LocaleCompare(keyword,"naxis") == 0) fits_info.number_axes=StringToLong(p); if (LocaleCompare(keyword,"naxis1") == 0) fits_info.columns=StringToLong(p); if (LocaleCompare(keyword,"naxis2") == 0) fits_info.rows=StringToLong(p); if (LocaleCompare(keyword,"naxis3") == 0) fits_info.number_planes=StringToLong(p); if (LocaleCompare(keyword,"datamax") == 0) fits_info.max_data=StringToDouble(p); if (LocaleCompare(keyword,"datamin") == 0) fits_info.min_data=StringToDouble(p); if (LocaleCompare(keyword,"bzero") == 0) fits_info.zero=StringToDouble(p); if (LocaleCompare(keyword,"bscale") == 0) fits_info.scale=StringToDouble(p); if (LocaleCompare(keyword,"comment") == 0) { if (comment == (char *) NULL) comment=ConstantString(p); else (void) ConcatenateString(&comment,p); } if (LocaleCompare(keyword,"xendian") == 0) { if (LocaleNCompare(p,"big",3) == 0) fits_info.endian=MSBEndian; else fits_info.endian=LSBEndian; } (void) FormatMagickString(property,MaxTextExtent,"fits:%s",keyword); (void) SetImageProperty(image,property,p); } c=0; while (((TellBlob(image) % FITSBlocksize) != 0) && (c != EOF)) c=ReadBlobByte(image); if (fits_info.extend == MagickFalse) break; number_pixels=(MagickSizeType) fits_info.columns*fits_info.rows; if ((fits_info.simple != MagickFalse) && (fits_info.number_axes >= 1) && (fits_info.number_axes <= 4) && (number_pixels != 0)) break; } /* Verify that required image information is defined. */ if (comment != (char *) NULL) { (void) SetImageProperty(image,"comment",comment); comment=DestroyString(comment); } if (EOFBlob(image) != MagickFalse) ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", image->filename); number_pixels=(MagickSizeType) fits_info.columns*fits_info.rows; if ((fits_info.simple == MagickFalse) || (fits_info.number_axes < 1) || (fits_info.number_axes > 4) || (number_pixels == 0)) ThrowReaderException(CorruptImageError,"ImageTypeNotSupported"); for (scene=0; scene < (ssize_t) fits_info.number_planes; scene++) { image->columns=(size_t) fits_info.columns; image->rows=(size_t) fits_info.rows; image->depth=(size_t) (fits_info.bits_per_pixel < 0 ? -1 : 1)* fits_info.bits_per_pixel; image->endian=fits_info.endian; image->scene=(size_t) scene; if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) if (image->scene >= (image_info->scene+image_info->number_scenes-1)) break; /* Initialize image structure. */ if ((fits_info.min_data != 0.0) || (fits_info.max_data != 0.0)) { if ((fits_info.bits_per_pixel != 0) && (fits_info.max_data == 0.0)) fits_info.max_data=GetFITSPixelRange((size_t) fits_info.bits_per_pixel); } else GetFITSPixelExtrema(image,fits_info.bits_per_pixel,&fits_info.min_data, &fits_info.max_data); /* Convert FITS pixels to pixel packets. */ scale=(double) QuantumRange/(fits_info.scale*(fits_info.max_data- fits_info.min_data)+fits_info.zero); for (y=(ssize_t) image->rows-1; y >= 0; y--) { q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); if (q == (PixelPacket *) NULL) break; for (x=0; x < (ssize_t) image->columns; x++) { pixel=GetFITSPixel(image,fits_info.bits_per_pixel); q->red=(Quantum) ClampToQuantum(scale*(fits_info.scale*(pixel- fits_info.min_data)+fits_info.zero)); q->green=q->red; q->blue=q->red; q++; } if (SyncAuthenticPixels(image,exception) == MagickFalse) break; if (image->previous == (Image *) NULL) { status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, image->rows); if (status == MagickFalse) break; } } if (EOFBlob(image) != MagickFalse) { ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", image->filename); break; } /* Proceed to next image. */ if (image_info->number_scenes != 0) if (image->scene >= (image_info->scene+image_info->number_scenes-1)) break; if (scene < (ssize_t) (fits_info.number_planes-1)) { /* Allocate next image structure. */ AcquireNextImage(image_info,image); if (GetNextImageInList(image) == (Image *) NULL) { image=DestroyImageList(image); return((Image *) NULL); } image=SyncNextImageInList(image); status=SetImageProgress(image,LoadImagesTag,TellBlob(image), GetBlobSize(image)); if (status == MagickFalse) break; } } (void) CloseBlob(image); return(GetFirstImageInList(image)); }
MagickExport MagickBooleanType GradientImage(Image *image, const GradientType type,const SpreadMethod method,const StopInfo *stops, const size_t number_stops,ExceptionInfo *exception) { const char *artifact; DrawInfo *draw_info; GeometryInfo geometry_info; GradientInfo *gradient; MagickBooleanType status; MagickStatusType flags; /* Set gradient start-stop end points. */ assert(image != (const Image *) NULL); assert(image->signature == MagickCoreSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(stops != (const StopInfo *) NULL); assert(number_stops > 0); draw_info=AcquireDrawInfo(); gradient=(&draw_info->gradient); gradient->type=type; gradient->bounding_box.width=image->columns; gradient->bounding_box.height=image->rows; artifact=GetImageArtifact(image,"gradient:bounding-box"); if (artifact != (const char *) NULL) (void) ParseAbsoluteGeometry(artifact,&gradient->bounding_box); gradient->gradient_vector.x2=(double) image->columns-1.0; gradient->gradient_vector.y2=(double) image->rows-1.0; if ((type == LinearGradient) && (gradient->gradient_vector.y2 != 0.0)) gradient->gradient_vector.x2=0.0; artifact=GetImageArtifact(image,"gradient:vector"); if (artifact != (const char *) NULL) { flags=ParseGeometry(artifact,&geometry_info); gradient->gradient_vector.x1=geometry_info.rho; if ((flags & SigmaValue) != 0) gradient->gradient_vector.y1=geometry_info.sigma; if ((flags & XiValue) != 0) gradient->gradient_vector.x2=geometry_info.xi; if ((flags & PsiValue) != 0) gradient->gradient_vector.y2=geometry_info.psi; } gradient->center.x=(double) gradient->gradient_vector.x2/2.0; gradient->center.y=(double) gradient->gradient_vector.y2/2.0; artifact=GetImageArtifact(image,"gradient:center"); if (artifact != (const char *) NULL) { flags=ParseGeometry(artifact,&geometry_info); gradient->center.x=geometry_info.rho; if ((flags & SigmaValue) != 0) gradient->center.y=geometry_info.sigma; } gradient->radius=MagickMax(gradient->center.x,gradient->center.y); artifact=GetImageArtifact(image,"gradient:radius"); if (artifact != (const char *) NULL) gradient->radius=StringToDouble(artifact,(char **) NULL); gradient->spread=method; /* Define the gradient to fill between the stops. */ gradient->number_stops=number_stops; gradient->stops=(StopInfo *) AcquireQuantumMemory(gradient->number_stops, sizeof(*gradient->stops)); if (gradient->stops == (StopInfo *) NULL) ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", image->filename); (void) CopyMagickMemory(gradient->stops,stops,(size_t) number_stops* sizeof(*stops)); /* Draw a gradient on the image. */ status=DrawGradientImage(image,draw_info,exception); draw_info=DestroyDrawInfo(draw_info); return(status); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + G e t M a g i c k T o k e n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetMagickToken() gets a token from the token stream. A token is defined as % a sequence of characters delimited by whitespace (e.g. clip-path), a % sequence delimited with quotes (.e.g "Quote me"), or a sequence enclosed in % parenthesis (e.g. rgb(0,0,0)). GetMagickToken() also recognizes these % separator characters: ':', '=', ',', and ';'. % % The format of the GetMagickToken method is: % % void GetMagickToken(const char *start,const char **end,char *token) % % A description of each parameter follows: % % o start: the start of the token sequence. % % o end: point to the end of the token sequence. % % o token: copy the token to this buffer. % */ MagickExport void GetMagickToken(const char *start,const char **end,char *token) { double value; register const char *p; register ssize_t i; assert(start != (const char *) NULL); assert(token != (char *) NULL); i=0; p=start; while ((isspace((int) ((unsigned char) *p)) != 0) && (*p != '\0')) p++; switch (*p) { case '\0': break; case '"': case '\'': case '`': case '{': { register char escape; switch (*p) { case '"': escape='"'; break; case '\'': escape='\''; break; case '`': escape='\''; break; case '{': escape='}'; break; default: escape=(*p); break; } for (p++; *p != '\0'; p++) { if ((*p == '\\') && ((*(p+1) == escape) || (*(p+1) == '\\'))) p++; else if (*p == escape) { p++; break; } token[i++]=(*p); } break; } case '/': { token[i++]=(*p++); if ((*p == '>') || (*p == '/')) token[i++]=(*p++); break; } default: { char *q; value=StringToDouble(p,&q); (void) value; if ((p != q) && (*p != ',')) { for ( ; (p < q) && (*p != ','); p++) token[i++]=(*p); if (*p == '%') token[i++]=(*p++); break; } if ((*p != '\0') && (isalpha((int) ((unsigned char) *p)) == 0) && (*p != *DirectorySeparator) && (*p != '#') && (*p != '<')) { token[i++]=(*p++); break; } for ( ; *p != '\0'; p++) { if (((isspace((int) ((unsigned char) *p)) != 0) || (*p == '=') || (*p == ':') || (*p == ',') || (*p == '|') || (*p == ';')) && (*(p-1) != '\\')) break; if ((i > 0) && (*p == '<')) break; token[i++]=(*p); if (*p == '>') break; if (*p == '(') for (p++; *p != '\0'; p++) { token[i++]=(*p); if ((*p == ')') && (*(p-1) != '\\')) break; } } break; } } token[i]='\0'; if (LocaleNCompare(token,"url(",4) == 0) { ssize_t offset; offset=4; if (token[offset] == '#') offset++; i=(ssize_t) strlen(token); (void) CopyMagickString(token,token+offset,MagickPathExtent); token[i-offset-1]='\0'; } while (isspace((int) ((unsigned char) *p)) != 0) p++; if (end != (const char **) NULL) *end=(const char *) p; }
int Utils::StringToInt(const std::string &value) { return (int) StringToDouble(value); }
//------------------------------------------------------------------------- // NavigationSyncer constructor using nav file and lev1 file to set up //------------------------------------------------------------------------- NavigationSyncer::NavigationSyncer(std::string navfilename, std::string lev1filename) { //Set to NULL here anyway just to be safe - they should all be none-null by the end of this function nscans=0; time=NULL; navfile=NULL; hdrsync=0; framerate=0; NOSYNCINHDR=-999; lev1firstscanmaxexpectedsize=30; //30 seconds if(navfilename.compare("NULL")!=0) { //Create a new Specim nav file object navfile=new SpecimFileChooser(navfilename); //Read in the nav file to get the time syncs navfile->Reader(); } //Need to read in the level1 file hdr info to get nscans BinFile bilin(lev1filename); //Get the number of scan lines nscans=StringToUINT(bilin.FromHeader("lines")); DEBUGPRINT("Number of scans: "<<nscans) //Get the NavSync timing from the hdr try { hdrsync=StringToUINT(TrimWhitespace(bilin.FromHeader("NavSync Timing",1,"true")))/1000.0; } catch(std::string e) { if(e.compare(0,bilin.MissingHeaderItemError().length(),bilin.MissingHeaderItemError())==0) { //Set to a value that means "no value in header" hdrsync=NOSYNCINHDR; } else { throw e; } } DEBUGPRINT("Sync from header:"<<hdrsync) //Get the acquisition date of the data acquisitiondate=bilin.FromHeader("acquisition date"); //Remove the start of the date string acquisitiondate=TrimWhitespace(acquisitiondate.substr(acquisitiondate.find_first_of(':')+1)); //Get the date format string for leap seconds dateformat=bilin.FromHeader("acquisition date"); size_t startofdateformat=dateformat.find_first_of("DATE(")+5; size_t lengthofdateformat=dateformat.find_first_of("):")-startofdateformat; dateformat=dateformat.substr(startofdateformat,lengthofdateformat); DEBUGPRINT("Date: "<<acquisitiondate) //Get the start and stop times from the header to use in case no sync messages //found in the specim nav file gpsstarttime=bilin.FromHeader("GPS Start Time"); gpsstarttime=RemoveAllBut(gpsstarttime,"1234567890.:"); gpsstarttime=TrimWhitespace(ReplaceAllWith(&gpsstarttime,':',' ')); gpsstoptime=bilin.FromHeader("GPS Stop Time"); gpsstoptime=RemoveAllBut(gpsstoptime,"1234567890.:"); gpsstoptime=TrimWhitespace(ReplaceAllWith(&gpsstoptime,':',' ')); //Get the frame rate from the hdr framerate=StringToDouble(bilin.FromHeader("fps")); DEBUGPRINT("Frame rate from header:"<<framerate) if((framerate <= 0)||(framerate>100000)) { throw "Frame rate (fps) in hdr file seems erroneous - will only process for frame rates >0 and <100000."; } //Get the Processed_crop_start from the header file - this tells us if //nav for the full line or crop of the line is required std::string cropstart=bilin.FromHeader("y start"); if(cropstart.compare("")==0) { Logger::Warning("No y start found in level 1 header, if data was cropped in previous stages navigation may be wrongly synced."); //Set the time offset to 0 croptimeoffset=0; } else { //Convert to a double croptimeoffset=StringToDouble(cropstart); //Get the number of dropped scans that occurred in the crop prior to y start (if y start = 0 so will this) std::string prevdropscans=bilin.FromHeader("dropped scans before y start"); if(prevdropscans.compare("")==0) { Logger::Warning("No 'dropped scans before y start' found in level 1 header, if y start is non-zero navigation may be wrongly synced."); //Set the time offset to 0 prevdropscans="0"; } double previousdroppedscans=StringToDouble(prevdropscans); //Convert the sum of the frames (cropstart and prevdropscans) to a time offset to add onto start time croptimeoffset=(croptimeoffset + previousdroppedscans)/framerate; Logger::Log("Using cropped level-1 data - will add a time offset relating to number of lines cropped (y start + dropped scans values in hdr): "+ToString(croptimeoffset)); } //Close the level 1 file bilin.Close(); //Create the scan time array time=new double[nscans]; //Get the number of leap seconds for the data LeapSecond leap; leapseconds=leap.GetLeapSeconds(acquisitiondate,dateformat); DEBUGPRINT("Using leap seconds of:"<<leapseconds); }
ImportNode XMLParser::ReadXMLNode() { ImportNode node; xmlChar *attribute = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"lat"); if (attribute != nullptr) { node.lat = static_cast<int>(COORDINATE_PRECISION * StringToDouble((const char *)attribute)); xmlFree(attribute); } attribute = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"lon"); if (attribute != nullptr) { node.lon = static_cast<int>(COORDINATE_PRECISION * StringToDouble((const char *)attribute)); xmlFree(attribute); } attribute = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"id"); if (attribute != nullptr) { node.node_id = StringToUint((const char *)attribute); xmlFree(attribute); } if (xmlTextReaderIsEmptyElement(inputReader) == 1) { return node; } const int depth = xmlTextReaderDepth(inputReader); while (xmlTextReaderRead(inputReader) == 1) { const int child_type = xmlTextReaderNodeType(inputReader); // 1 = Element, 15 = EndElement if (child_type != 1 && child_type != 15) { continue; } const int child_depth = xmlTextReaderDepth(inputReader); xmlChar *child_name = xmlTextReaderName(inputReader); if (child_name == nullptr) { continue; } if (depth == child_depth && child_type == 15 && xmlStrEqual(child_name, (const xmlChar *)"node") == 1) { xmlFree(child_name); break; } if (child_type != 1) { xmlFree(child_name); continue; } if (xmlStrEqual(child_name, (const xmlChar *)"tag") == 1) { xmlChar *key = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"k"); xmlChar *value = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"v"); if (key != nullptr && value != nullptr) { node.keyVals.Add(std::string((char *)(key)), std::string((char *)(value))); } if (key != nullptr) { xmlFree(key); } if (value != nullptr) { xmlFree(value); } } xmlFree(child_name); } return node; }
static MagickBooleanType WriteJBIGImage(const ImageInfo *image_info, Image *image,ExceptionInfo *exception) { double version; MagickBooleanType status; MagickOffsetType scene; register const Quantum *p; register ssize_t x; register unsigned char *q; size_t number_packets; ssize_t y; struct jbg_enc_state jbig_info; unsigned char bit, byte, *pixels; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); if (status == MagickFalse) return(status); version=StringToDouble(JBG_VERSION,(char **) NULL); scene=0; do { /* Allocate pixel data. */ if (IsRGBColorspace(image->colorspace) == MagickFalse) (void) TransformImageColorspace(image,RGBColorspace,exception); number_packets=(image->columns+7)/8; pixels=(unsigned char *) AcquireQuantumMemory(number_packets, image->rows*sizeof(*pixels)); if (pixels == (unsigned char *) NULL) ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); /* Convert pixels to a bitmap. */ (void) SetImageType(image,BilevelType,exception); q=pixels; for (y=0; y < (ssize_t) image->rows; y++) { p=GetVirtualPixels(image,0,y,image->columns,1,exception); if (p == (const Quantum *) NULL) break; bit=0; byte=0; for (x=0; x < (ssize_t) image->columns; x++) { byte<<=1; if (GetPixelIntensity(image,p) < (QuantumRange/2.0)) byte|=0x01; bit++; if (bit == 8) { *q++=byte; bit=0; byte=0; } p+=GetPixelChannels(image); } if (bit != 0) *q++=byte << (8-bit); if (image->previous == (Image *) NULL) { status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, image->rows); if (status == MagickFalse) break; } } /* Initialize JBIG info structure. */ jbg_enc_init(&jbig_info,(unsigned long) image->columns,(unsigned long) image->rows,1,&pixels,(void (*)(unsigned char *,size_t,void *)) JBIGEncode,image); if (image_info->scene != 0) jbg_enc_layers(&jbig_info,(int) image_info->scene); else { size_t x_resolution, y_resolution; x_resolution=640; y_resolution=480; if (image_info->density != (char *) NULL) { GeometryInfo geometry_info; MagickStatusType flags; flags=ParseGeometry(image_info->density,&geometry_info); x_resolution=geometry_info.rho; y_resolution=geometry_info.sigma; if ((flags & SigmaValue) == 0) y_resolution=x_resolution; } if (image->units == PixelsPerCentimeterResolution) { x_resolution=(size_t) (100.0*2.54*x_resolution+0.5)/100.0; y_resolution=(size_t) (100.0*2.54*y_resolution+0.5)/100.0; } (void) jbg_enc_lrlmax(&jbig_info,(unsigned long) x_resolution, (unsigned long) y_resolution); } (void) jbg_enc_lrange(&jbig_info,-1,-1); jbg_enc_options(&jbig_info,JBG_ILEAVE | JBG_SMID,JBG_TPDON | JBG_TPBON | JBG_DPON,version < 1.6 ? -1 : 0,-1,-1); /* Write JBIG image. */ jbg_enc_out(&jbig_info); jbg_enc_free(&jbig_info); pixels=(unsigned char *) RelinquishMagickMemory(pixels); if (GetNextImageInList(image) == (Image *) NULL) break; image=SyncNextImageInList(image); status=SetImageProgress(image,SaveImagesTag,scene++, GetImageListLength(image)); if (status == MagickFalse) break; } while (image_info->adjoin != MagickFalse); (void) CloseBlob(image); return(MagickTrue); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d S C T I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadSCTImage() reads a Scitex image file and returns it. It allocates % the memory necessary for the new Image structure and returns a pointer to % the new image. % % The format of the ReadSCTImage method is: % % Image *ReadSCTImage(const ImageInfo *image_info,ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: the image info. % % o exception: return any errors or warnings in this structure. % */ static Image *ReadSCTImage(const ImageInfo *image_info,ExceptionInfo *exception) { char magick[2]; Image *image; MagickBooleanType status; double height, width; Quantum pixel; register ssize_t i, x; register Quantum *q; ssize_t count, y; unsigned char buffer[768]; size_t separations, separations_mask, units; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AcquireImage(image_info,exception); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } /* Read control block. */ count=ReadBlob(image,80,buffer); (void) count; count=ReadBlob(image,2,(unsigned char *) magick); if ((LocaleNCompare((char *) magick,"CT",2) != 0) && (LocaleNCompare((char *) magick,"LW",2) != 0) && (LocaleNCompare((char *) magick,"BM",2) != 0) && (LocaleNCompare((char *) magick,"PG",2) != 0) && (LocaleNCompare((char *) magick,"TX",2) != 0)) ThrowReaderException(CorruptImageError,"ImproperImageHeader"); if ((LocaleNCompare((char *) magick,"LW",2) == 0) || (LocaleNCompare((char *) magick,"BM",2) == 0) || (LocaleNCompare((char *) magick,"PG",2) == 0) || (LocaleNCompare((char *) magick,"TX",2) == 0)) ThrowReaderException(CoderError,"OnlyContinuousTonePictureSupported"); count=ReadBlob(image,174,buffer); count=ReadBlob(image,768,buffer); /* Read paramter block. */ units=1UL*ReadBlobByte(image); if (units == 0) image->units=PixelsPerCentimeterResolution; separations=1UL*ReadBlobByte(image); separations_mask=ReadBlobMSBShort(image); count=ReadBlob(image,14,buffer); buffer[14]='\0'; height=StringToDouble((char *) buffer,(char **) NULL); count=ReadBlob(image,14,buffer); width=StringToDouble((char *) buffer,(char **) NULL); count=ReadBlob(image,12,buffer); buffer[12]='\0'; image->rows=StringToUnsignedLong((char *) buffer); count=ReadBlob(image,12,buffer); image->columns=StringToUnsignedLong((char *) buffer); count=ReadBlob(image,200,buffer); count=ReadBlob(image,768,buffer); if (separations_mask == 0x0f) SetImageColorspace(image,CMYKColorspace,exception); image->resolution.x=1.0*image->columns/width; image->resolution.y=1.0*image->rows/height; if (image_info->ping != MagickFalse) { (void) CloseBlob(image); return(GetFirstImageInList(image)); } /* Convert SCT raster image to pixel packets. */ for (y=0; y < (ssize_t) image->rows; y++) { for (i=0; i < (ssize_t) separations; i++) { q=GetAuthenticPixels(image,0,y,image->columns,1,exception); if (q == (Quantum *) NULL) break; for (x=0; x < (ssize_t) image->columns; x++) { pixel=(Quantum) ScaleCharToQuantum((unsigned char) ReadBlobByte(image)); if (image->colorspace == CMYKColorspace) pixel=(Quantum) (QuantumRange-pixel); switch (i) { case 0: { SetPixelRed(image,pixel,q); SetPixelGreen(image,pixel,q); SetPixelBlue(image,pixel,q); break; } case 1: { SetPixelGreen(image,pixel,q); break; } case 2: { SetPixelBlue(image,pixel,q); break; } case 3: { if (image->colorspace == CMYKColorspace) SetPixelBlack(image,pixel,q); break; } } q+=GetPixelChannels(image); } if (SyncAuthenticPixels(image,exception) == MagickFalse) break; if ((image->columns % 2) != 0) (void) ReadBlobByte(image); /* pad */ } status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, image->rows); if (status == MagickFalse) break; } if (EOFBlob(image) != MagickFalse) ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", image->filename); (void) CloseBlob(image); return(GetFirstImageInList(image)); }
bool wxPropertyValidator::StringToFloat (wxChar *s, float *number) { double num; bool ok = StringToDouble (s, &num); *number = (float) num; return ok; }
int main(int argc,char* argv[]) { //Set the precision of the data output to the terminal std::cout.precision(10); //A command line handling object CommandLine* cl=NULL; //Create a logger to output the data to terminal Logger log; //A stringstream object to store output information in std::stringstream strout; //Specim navigation filename std::string strSpecimNavFile=""; //Output filename to write results to std::string strOutputFile=""; //Level-1 data file name to read data properties from std::string strLevel1File=""; //Post-processed nav file name std::string strPostProcNavFile=""; //Pointer to a NavigationInterpolator NavigationInterpolator* interpolator=NULL; //Pointer to a boresight onject Boresight* boresight=NULL; //Pointer to a lever arm object Leverarm* leverarm=NULL; //String to hold interpolation choice std::string strinterpmethod=""; //Value to hold user specified time to use as first scan line time //double usersynctime=-1; //Scan offset time double scantimeoffset=0; //Position-Attitude time offset double posattoffset=0; //Smoothing filter kernel size unsigned int smoothkernelsize=0; //Shall we write out the navigation quality flags bool WRITE_QUALITY=false; std::string strOutputFlagFile; //String to contain info for output hdr file std::string info=""; //Get exe name without the path std::string niceexename=std::string(argv[0]); niceexename=niceexename.substr(niceexename.find_last_of("/\\")+1); //Output a "nice" header Logger::FormattedInformation(niceexename,VERSION,DESCRIPTION); try { //---------------------------------------------------------------------------- //Create the command line object //---------------------------------------------------------------------------- cl=new CommandLine(argv,argc); //---------------------------------------------------------------------------- //Check if anything went wrong (most likely an exception will have been thrown but lets be safe) //---------------------------------------------------------------------------- if(cl->IsGood()==false) { throw "An error has occurred with the command line\n"; //throw exception that an error has occurred } //---------------------------------------------------------------------- // Get some information about the system running the program and log it //---------------------------------------------------------------------- ComputerInfo cinfo; Logger::Log(cinfo.GetOutput()); //---------------------------------------------------------------------------- //check the command line options given against the list of available options in the software //---------------------------------------------------------------------------- std::string badoptions; int retval=cl->CheckAvailableOptions(availableopts,number_of_possible_options,&badoptions); if(retval<0) { //Options are on commnd line that are not available in this software strout<<"There are "<<(-retval)<<" unrecognised options on command line: "<<badoptions<<std::endl; throw CommandLine::CommandLineException(strout.str()); } Logger::Log("Command line used to run: "+cl->ReturnCLAsString()); //---------------------------------------------------------------------------- // Go through each possible option in turn and set up the required data / response //---------------------------------------------------------------------------- if(cl->OnCommandLine("-help")) { log.Add(cl->ProgramUsage(number_of_possible_options,availableopts,optsdescription)); log.Flush(); throw ""; } //------------------------------------------------------------------- // Is the Specim .nav file on the command line (IT MUST BE PRESENT) //------------------------------------------------------------------- if((cl->OnCommandLine("-nav"))&&(!cl->OnCommandLine("-nonav"))) { //Check that an argument follows the nav option - and get it if it exists if(cl->GetArg("-nav").compare(optiononly)!=0) { strSpecimNavFile=cl->GetArg("-nav"); log.Add("Will use Specim Navigation file: "+strSpecimNavFile); } else throw CommandLine::CommandLineException("Argument -nav must immediately precede the Specim .nav filename.\n"); } else if((!cl->OnCommandLine("-nav"))&&(cl->OnCommandLine("-nonav"))) { //Throw an exception //throw CommandLine::CommandLineException("Argument -nav [Specim navigation file] must be present on the command line.\n"); if(cl->GetArg("-nonav").compare(optiononly)!=0) { throw CommandLine::CommandLineException("Option -nonav does not take any arguments.\n"); } else strSpecimNavFile="NULL"; } else { //Throw an exception throw CommandLine::CommandLineException("Argument -nav [Specim navigation file] or -nonav must be present on the command line.\n"); } //------------------------------------------------------------------- // Is the output filename on the command line (IT MUST BE PRESENT) //------------------------------------------------------------------- if(cl->OnCommandLine("-output")) { //Check that an argument follows the output option - and get it if it exists if(cl->GetArg("-output").compare(optiononly)!=0) { strOutputFile=cl->GetArg("-output"); log.Add("Will write to output BIL file: "+strOutputFile); } else throw CommandLine::CommandLineException("Argument -output must immediately precede the output filename.\n"); } else { //Throw an exception throw CommandLine::CommandLineException("Argument -output [the file to write to] must be present on the command line.\n"); } //------------------------------------------------------------------- // Is the level 1 filename on the command line (IT MUST BE PRESENT) //------------------------------------------------------------------- if(cl->OnCommandLine("-lev1")) { //Check that an argument follows the lev1 option - and get it if it exists if(cl->GetArg("-lev1").compare(optiononly)!=0) { strLevel1File=cl->GetArg("-lev1"); log.Add("Will read the sensor data properties from the level-1 file: "+strLevel1File); } else throw CommandLine::CommandLineException("Argument -lev1 must immediately precede the level-1 filename.\n"); } else { //Throw an exception throw CommandLine::CommandLineException("Argument -lev1 [the level-1 hyperspectral file] must be present on the command line.\n"); } //------------------------------------------------------------------- // Is the lever arm on the command line (IT MUST BE PRESENT) //------------------------------------------------------------------- if(cl->OnCommandLine("-leverarm")) { //Check that 3 arguments follow the leverarm option if(cl->NumArgsOfOpt("-leverarm") != 3 ) throw CommandLine::CommandLineException("Error: There should be 3 arguments following the -leverarm option.\n"); //Get the 3 arguments into the leverarm parameters double lax=StringToDouble(cl->GetArg("-leverarm",0)); double lay=StringToDouble(cl->GetArg("-leverarm",1)); double laz=StringToDouble(cl->GetArg("-leverarm",2)); log.Add("Will apply lever arm corrections of (X,Y,Z): "+ToString(lax)+" "+ToString(lay)+" "+ToString(laz)); leverarm=new Leverarm(lax,lay,laz); } else { throw CommandLine::CommandLineException("Argument -leverarm [the sensor lever arm values] must be present on the command line.\n"); } //------------------------------------------------------------------- // Is the boresight on the command line (IT MUST BE PRESENT) //------------------------------------------------------------------- if(cl->OnCommandLine("-boresight")) { //Check that 3 arguments follow the boresight option if(cl->NumArgsOfOpt("-boresight") != 3 ) throw CommandLine::CommandLineException("Error: There should be 3 arguments following the -boresight option.\n"); //Get the 3 arguments into the boresight parameters double p=StringToDouble(cl->GetArg("-boresight",0)); double r=StringToDouble(cl->GetArg("-boresight",1)); double h=StringToDouble(cl->GetArg("-boresight",2)); log.Add("Will apply boresight corrections of (R,P,H): "+ToString(r)+" "+ToString(p)+" "+ToString(h)); boresight=new Boresight(r,p,h); } else { throw CommandLine::CommandLineException("Argument -boresight [the sensor boresight values] must be present on the command line.\n"); } //------------------------------------------------------------------- // Is the post-processed nav file on the command line (ITS OPTIONAL) //------------------------------------------------------------------- if(cl->OnCommandLine("-procnav")) { //Check that an argument follows the procnav option - and get it if it exists if(cl->GetArg("-procnav").compare(optiononly)!=0) { strPostProcNavFile=cl->GetArg("-procnav"); log.Add("Will read navigation data from SBET/SOL file: "+strPostProcNavFile); info=info+";Navigation from post-processed SBET/SOL file. \n"; } else throw CommandLine::CommandLineException("Argument -procnav must immediately precede the SBET/SOL filename.\n"); } else { log.Add("No SBET/SOL file has been given, therefore will read real-time navigation data from Specim .nav file: "+strSpecimNavFile); info=info+";Navigation from real-time Specim .nav file. \n"; } //------------------------------------------------------------------- // Is the ScanTime Offset on the command line (ITS OPTIONAL) //------------------------------------------------------------------- if(cl->OnCommandLine("-scantimeoffset")) { //Check that an argument follows the scantimeoffset option - and get it if it exists if(cl->GetArg("-scantimeoffset").compare(optiononly)!=0) { std::string cl_tmp=cl->GetArg("-scantimeoffset"); scantimeoffset=StringToDouble(cl_tmp.c_str()); if(errno==ERANGE) { throw "An error has occurred in the conversion of scan time offset in CommandLine of main()."; } log.Add("Will apply a user-specified scan offset of: "+cl_tmp); } else throw CommandLine::CommandLineException("Argument -scantimeoffset must immediately precede the scan time offset value."); } else { log.Add("No user-supplied scan time offset to be applied."); } //------------------------------------------------------------------- // Is smoothing requested on the command line (ITS OPTIONAL) //------------------------------------------------------------------- if(cl->OnCommandLine("-smooth")) { //Check that an argument follows the smooth option - and get it if it exists if(cl->GetArg("-smooth").compare(optiononly)!=0) { std::string cl_tmp=cl->GetArg("-smooth"); smoothkernelsize=StringToUINT(cl_tmp); if(errno==ERANGE) { throw "An error has occurred in the conversion of smooth kernel size in CommandLine of main()."; } if(smoothkernelsize%2==0) throw "Smoothing kernel size must be an odd number."; log.Add("Will apply a smoothing of kernel size: "+cl_tmp); } else throw CommandLine::CommandLineException("Argument -smooth must immediately precede the smoothing kernel size."); } else { log.Add("No smoothing of navigation data to be applied."); } //------------------------------------------------------------------- // What method of interpolation is to be used //------------------------------------------------------------------- if(cl->OnCommandLine("-interp")) { //Check that an argument follows the interp option - and get it if it exists if(cl->GetArg("-interp").compare(optiononly)!=0) { std::string cl_tmp=cl->GetArg("-interp"); strinterpmethod=cl_tmp; log.Add("Will use the interpolation method: "+cl_tmp); } else throw CommandLine::CommandLineException("Argument -interp must immediately precede the interpolation method keyword."); } else { strinterpmethod="Linear"; log.Add("No interpolation method of navigation data supplied, will use Linear."); } //------------------------------------------------------------------- // Add a Position-Attitude time offset //------------------------------------------------------------------- if(cl->OnCommandLine("-posattoff")) { //Check that an argument follows the posattoff option - and get it if it exists if(cl->GetArg("-posattoff").compare(optiononly)!=0) { std::string cl_tmp=cl->GetArg("-posattoff"); posattoffset=StringToDouble(cl_tmp.c_str()); if(errno==ERANGE) { throw "An error has occurred in the conversion of position attitude time offset in CommandLine of main()."; } log.Add("Will use the given position attitude offset: "+cl_tmp); } else throw CommandLine::CommandLineException("Argument -posattoff must immediately precede the position/attitude shift value."); } else { posattoffset=0; log.Add("Will not use a position-attitude offset."); } //------------------------------------------------------------------- // Output the quality flags //------------------------------------------------------------------- if(cl->OnCommandLine("-qualityfile")) { //Check that an argument follows the qualityfile option - and get it if it exists if(cl->GetArg("-qualityfile").compare(optiononly)!=0) { strOutputFlagFile=cl->GetArg("-qualityfile"); log.Add("Will write quality flags to: "+strOutputFlagFile); } else throw CommandLine::CommandLineException("Argument -qualityfile must immediately precede the output quality flag filename.\n"); //Set the bool to true WRITE_QUALITY=true; } else { WRITE_QUALITY=false; } //------------------------------------------------------------------- // Force processing of aplnav //------------------------------------------------------------------- if(cl->OnCommandLine("-force")) { if(cl->GetArg("-force").compare(optiononly)!=0) { throw CommandLine::CommandLineException("Option -force does not take any arguments.\n"); } else GLOBAL_FORCE=true; } else { GLOBAL_FORCE=false; } //------------------------------------------------------------------- // ENTER NEW COMMAND LINE OPTIONS HERE //------------------------------------------------------------------- } catch(CommandLine::CommandLineException e) { Logger::Error(std::string(e.what())+"\n"+e.info); delete cl; exit(1); } catch(std::string e) { Logger::Error(e); delete cl; exit(1); } catch(const char* e) { Logger::Error(e); delete cl; exit(1); } catch(BinaryReader::BRexception e) { Logger::Error(std::string(e.what())+"\n"+e.info); delete cl; exit(1); //exit the program } catch(std::exception &e) { Logger::Error(e.what()); delete cl; exit(1); } //Flush the log log.Flush(); //Output a blank line Logger::Log(""); //Add some information to the header files info=info+";Command line used to process data: "+cl->ReturnCLAsString()+"\n"; info=info+";boresight (P,R,H) = "+ToString(boresight->Pitch())+" "+ToString(boresight->Roll())+" "+ToString(boresight->Heading())+"\n"; info=info+";leverarm (X,Y,Z) = "+ToString(leverarm->X())+" "+ToString(leverarm->Y())+" "+ToString(leverarm->Z())+"\n"; try { //------------------------------------------------------------------- // In this section we deal with getting per scan times //------------------------------------------------------------------- //Set up navigation syncer to get per scan line times NavigationSyncer syncer(strSpecimNavFile,strLevel1File); //Add the y start value to the output header file. info=info+"y start = "+ToString(syncer.GetCropTimeOffset())+"\n"; //Get the perscan line times log.Add("Finding per-scan times..."); log.Flush(); syncer.FindScanTimes(); //Correct the times for GPS leapseconds if from SBET/SOL file //This is because the times from the Specim nav file are in GPS time //and SBET/SOL times are in UTC. So this adds leapseconds onto the times //which have been derived from the Specim data, making them relevant //for querying the data from the SBET/SOL file. //Ignore (for the moment) if from Specim Nav file - adds time on //to that data before writing out (see below) if(strPostProcNavFile!="") syncer.ApplyLeapSeconds(); //Apply a user-defined time offset to the scans if(scantimeoffset!=0) { log.Add("\nApplying user defined timing offset..."); log.Flush(); syncer.ApplyTimeShift(scantimeoffset); info=info+";User defined scan timing offset added onto data: "+ToString(scantimeoffset)+"\n"; } //------------------------------------------------------------------- // In this section we deal with getting per scan navigation data //------------------------------------------------------------------- //Set up an interpolator to interpolate the navigation to the scan lines log.Add("Creating Navigation Interpolation object..."); log.Flush(); if(strPostProcNavFile!="") interpolator=new NavigationInterpolator(strPostProcNavFile,strLevel1File); else interpolator=new NavigationInterpolator(strSpecimNavFile,strLevel1File); //Assign the scan times to the interpolator - these are just //pointing to the data so dont delete the syncer log.Add("\nSetting times to interpolation object..."); log.Flush(); double* scantimes=NULL; scantimes=syncer.PtrToTimes(); interpolator->SetTimes(scantimes); //Smooth the nav data if(smoothkernelsize!=0) { log.Add("Smoothing the data using a triangular low-pass filter..."); log.Flush(); info=info+";Smoothed input navigation data using a triangular low-pass filter with kernel size: "+ToString(smoothkernelsize)+"\n"; interpolator->SmoothNavData(Triangle,smoothkernelsize); } //Interpolate the data to the scan times log.Add("\nInterpolating navigation data to scan times..."); log.Flush(); if(strinterpmethod.compare("Linear")==0) { interpolator->Interpolate(Linear); if(posattoffset!=0) interpolator->PosAttShift(Linear,posattoffset); } else if(strinterpmethod.compare("Spline")==0) { interpolator->Interpolate(CubicSpline); if(posattoffset!=0) interpolator->PosAttShift(Linear,posattoffset); } else throw "Unknown interpolation method. Expected 'Linear' or 'Spline'"; //Apply the lever arm offsets to the interpolated position data log.Add("Adding leverarm correction..."); log.Flush(); interpolator->ApplyLeverarm(leverarm); //Apply the boresight offsets to the interpolated attitude data log.Add("Adding boresight correction..."); log.Flush(); interpolator->ApplyBoresight(boresight); //If the times are from the Specim nav file then they must be converted //from GPS time to UTC by adding on the leap seconds. if(strPostProcNavFile=="") syncer.ApplyLeapSeconds(); scantimes=syncer.PtrToTimes(); interpolator->SetTimes(scantimes); //Check the plausibilty of the interpolated data interpolator->CheckPlausibility(); //Write out the data log.Add("\nWriting data out..."); log.Flush(); interpolator->Writer(strOutputFile,info); //Write out the quality flags if(WRITE_QUALITY==true) { interpolator->WriteFlags(strOutputFlagFile); } //delete the interpolator delete interpolator; } catch(std::string e) { Logger::Error(e); exit(1); } catch(const char* e) { Logger::Error(e); exit(1); } catch(BinaryReader::BRexception e) { Logger::Error(std::string(e.what())+"\n"+e.info); exit(1); } catch(BILWriter::BILexception e) { Logger::Error(std::string(e.what())+"\n"+e.info); exit(1); } catch(std::exception &e) { Logger::Error(e.what()); exit(1); } Logger::Log("Navigation processing completed. \n \n"); //Delete the command line object if(cl!=NULL) delete cl; if(boresight!=NULL) delete boresight; if(leverarm!=NULL) delete leverarm; }
double CStringUtils::StringToDouble(const nstring & str) { return StringToDouble(str.c_str()); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % P a r s e G e o m e t r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ParseGeometry() parses a geometry specification and returns the sigma, % rho, xi, and psi values. It also returns flags that indicates which % of the four values (sigma, rho, xi, psi) were located in the string, and % whether the xi or pi values are negative. % % In addition, it reports if there are any of meta characters (%, !, <, >, @, % and ^) flags present. It does not report the location of the percentage % relative to the values. % % Values may also be separated by commas, colons, or slashes, and offsets. % Offsets may be prefixed by multiple signs to make offset string % substitutions easier to handle from shell scripts. % For example: "-10-10", "-+10-+10", or "+-10+-10" will generate negtive % offsets, while "+10+10", "++10++10", or "--10--10" will generate positive % offsets. % % The format of the ParseGeometry method is: % % MagickStatusType ParseGeometry(const char *geometry, % GeometryInfo *geometry_info) % % A description of each parameter follows: % % o geometry: The geometry string (e.g. "100x100+10+10"). % % o geometry_info: returns the parsed width/height/x/y in this structure. % */ MagickExport MagickStatusType ParseGeometry(const char *geometry, GeometryInfo *geometry_info) { char *p, pedantic_geometry[MagickPathExtent], *q; double value; int c; MagickStatusType flags; /* Remove whitespaces meta characters from geometry specification. */ assert(geometry_info != (GeometryInfo *) NULL); flags=NoValue; if ((geometry == (char *) NULL) || (*geometry == '\0')) return(flags); if (strlen(geometry) >= (MagickPathExtent-1)) return(flags); (void) CopyMagickString(pedantic_geometry,geometry,MagickPathExtent); for (p=pedantic_geometry; *p != '\0'; ) { if (isspace((int) ((unsigned char) *p)) != 0) { (void) CopyMagickString(p,p+1,MagickPathExtent); continue; } c=(int) ((unsigned char) *p); switch (c) { case '%': { flags|=PercentValue; (void) CopyMagickString(p,p+1,MagickPathExtent); break; } case '!': { flags|=AspectValue; (void) CopyMagickString(p,p+1,MagickPathExtent); break; } case '<': { flags|=LessValue; (void) CopyMagickString(p,p+1,MagickPathExtent); break; } case '>': { flags|=GreaterValue; (void) CopyMagickString(p,p+1,MagickPathExtent); break; } case '^': { flags|=MinimumValue; (void) CopyMagickString(p,p+1,MagickPathExtent); break; } case '@': { flags|=AreaValue; (void) CopyMagickString(p,p+1,MagickPathExtent); break; } case '(': case ')': { (void) CopyMagickString(p,p+1,MagickPathExtent); break; } case 'x': case 'X': { flags|=SeparatorValue; p++; break; } case '-': case '+': case ',': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '/': case ':': case 215: case 'e': case 'E': { p++; break; } case '.': { p++; flags|=DecimalValue; break; } default: return(flags); } } /* Parse rho, sigma, xi, psi, and optionally chi. */ p=pedantic_geometry; if (*p == '\0') return(flags); q=p; value=StringToDouble(p,&q); if (LocaleNCompare(p,"0x",2) == 0) value=(double) strtol(p,&q,10); c=(int) ((unsigned char) *q); if ((c == 215) || (*q == 'x') || (*q == 'X') || (*q == ',') || (*q == '/') || (*q == ':') || (*q =='\0')) { /* Parse rho. */ q=p; if (LocaleNCompare(p,"0x",2) == 0) value=(double) strtol(p,&p,10); else value=StringToDouble(p,&p); if (p != q) { flags|=RhoValue; geometry_info->rho=value; } } q=p; c=(int) ((unsigned char) *p); if ((c == 215) || (*p == 'x') || (*p == 'X') || (*p == ',') || (*p == '/') || (*p == ':')) { /* Parse sigma. */ p++; while (isspace((int) ((unsigned char) *p)) != 0) p++; c=(int) ((unsigned char) *q); if (((c != 215) && (*q != 'x') && (*q != 'X')) || ((*p != '+') && (*p != '-'))) { q=p; value=StringToDouble(p,&p); if (p != q) { flags|=SigmaValue; geometry_info->sigma=value; } } } while (isspace((int) ((unsigned char) *p)) != 0) p++; if ((*p == '+') || (*p == '-') || (*p == ',') || (*p == '/') || (*p == ':')) { /* Parse xi value. */ if ((*p == ',') || (*p == '/') || (*p == ':') ) p++; while ((*p == '+') || (*p == '-')) { if (*p == '-') flags^=XiNegative; /* negate sign */ p++; } q=p; value=StringToDouble(p,&p); if (p != q) { flags|=XiValue; if ((flags & XiNegative) != 0) value=(-value); geometry_info->xi=value; } while (isspace((int) ((unsigned char) *p)) != 0) p++; if ((*p == '+') || (*p == '-') || (*p == ',') || (*p == '/') || (*p == ':')) { /* Parse psi value. */ if ((*p == ',') || (*p == '/') || (*p == ':')) p++; while ((*p == '+') || (*p == '-')) { if (*p == '-') flags^=PsiNegative; /* negate sign */ p++; } q=p; value=StringToDouble(p,&p); if (p != q) { flags|=PsiValue; if ((flags & PsiNegative) != 0) value=(-value); geometry_info->psi=value; } } while (isspace((int) ((unsigned char) *p)) != 0) p++; if ((*p == '+') || (*p == '-') || (*p == ',') || (*p == '/') || (*p == ':')) { /* Parse chi value. */ if ((*p == ',') || (*p == '/') || (*p == ':')) p++; while ((*p == '+') || (*p == '-')) { if (*p == '-') flags^=ChiNegative; /* negate sign */ p++; } q=p; value=StringToDouble(p,&p); if (p != q) { flags|=ChiValue; if ((flags & ChiNegative) != 0) value=(-value); geometry_info->chi=value; } } } if (strchr(pedantic_geometry,':') != (char *) NULL) { /* Normalize sampling factor (e.g. 4:2:2 => 2x1). */ geometry_info->rho/=geometry_info->sigma; geometry_info->sigma=1.0; if (geometry_info->xi == 0.0) geometry_info->sigma=2.0; } if (((flags & SigmaValue) == 0) && ((flags & XiValue) != 0) && ((flags & PsiValue) == 0)) { /* Support negative height values (e.g. 30x-20). */ geometry_info->sigma=geometry_info->xi; geometry_info->xi=0.0; flags|=SigmaValue; flags&=(~XiValue); } if ((flags & PercentValue) != 0) { if (((flags & SeparatorValue) == 0) && ((flags & SigmaValue) == 0)) geometry_info->sigma=geometry_info->rho; if (((flags & SeparatorValue) != 0) && ((flags & RhoValue) == 0)) geometry_info->rho=geometry_info->sigma; } #if 0 /* Debugging Geometry */ (void) fprintf(stderr,"ParseGeometry...\n"); (void) fprintf(stderr,"Flags: %c %c %s %s %s\n", (flags & RhoValue) ? 'W' : ' ',(flags & SigmaValue) ? 'H' : ' ', (flags & XiValue) ? ((flags & XiNegative) ? "-X" : "+X") : " ", (flags & PsiValue) ? ((flags & PsiNegative) ? "-Y" : "+Y") : " ", (flags & ChiValue) ? ((flags & ChiNegative) ? "-Z" : "+Z") : " "); (void) fprintf(stderr,"Geometry: %lg,%lg,%lg,%lg,%lg\n",geometry_info->rho, geometry_info->sigma,geometry_info->xi,geometry_info->psi, geometry_info->chi); #endif return(flags); }
static MagickBooleanType WriteCINImage(const ImageInfo *image_info,Image *image, ExceptionInfo *exception) { const char *value; CINInfo cin; const StringInfo *profile; MagickBooleanType status; MagickOffsetType offset; QuantumInfo *quantum_info; QuantumType quantum_type; register const Quantum *p; register ssize_t i; size_t length; ssize_t count, y; struct tm local_time; time_t seconds; unsigned char *pixels; /* Open output image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); if (status == MagickFalse) return(status); if (image->colorspace != LogColorspace) (void) TransformImageColorspace(image,LogColorspace,exception); /* Write image information. */ (void) ResetMagickMemory(&cin,0,sizeof(cin)); offset=0; cin.file.magic=0x802A5FD7UL; offset+=WriteBlobLong(image,(unsigned int) cin.file.magic); cin.file.image_offset=0x800; offset+=WriteBlobLong(image,(unsigned int) cin.file.image_offset); cin.file.generic_length=0x400; offset+=WriteBlobLong(image,(unsigned int) cin.file.generic_length); cin.file.industry_length=0x400; offset+=WriteBlobLong(image,(unsigned int) cin.file.industry_length); cin.file.user_length=0x00; profile=GetImageProfile(image,"dpx:user.data"); if (profile != (StringInfo *) NULL) { cin.file.user_length+=(size_t) GetStringInfoLength(profile); cin.file.user_length=(((cin.file.user_length+0x2000-1)/0x2000)*0x2000); } offset+=WriteBlobLong(image,(unsigned int) cin.file.user_length); cin.file.file_size=4*image->columns*image->rows+0x2000; offset+=WriteBlobLong(image,(unsigned int) cin.file.file_size); (void) CopyMagickString(cin.file.version,"V4.5",sizeof(cin.file.version)); offset+=WriteBlob(image,sizeof(cin.file.version),(unsigned char *) cin.file.version); value=GetCINProperty(image_info,image,"dpx:file.filename",exception); if (value != (const char *) NULL) (void) CopyMagickString(cin.file.filename,value,sizeof(cin.file.filename)); else (void) CopyMagickString(cin.file.filename,image->filename, sizeof(cin.file.filename)); offset+=WriteBlob(image,sizeof(cin.file.filename),(unsigned char *) cin.file.filename); seconds=time((time_t *) NULL); #if defined(MAGICKCORE_HAVE_LOCALTIME_R) (void) localtime_r(&seconds,&local_time); #else (void) memcpy(&local_time,localtime(&seconds),sizeof(local_time)); #endif (void) strftime(cin.file.create_date,sizeof(cin.file.create_date),"%Y:%m:%d", &local_time); offset+=WriteBlob(image,sizeof(cin.file.create_date),(unsigned char *) cin.file.create_date); (void) strftime(cin.file.create_time,sizeof(cin.file.create_time), "%H:%M:%S%Z",&local_time); offset+=WriteBlob(image,sizeof(cin.file.create_time),(unsigned char *) cin.file.create_time); offset+=WriteBlob(image,sizeof(cin.file.reserve),(unsigned char *) cin.file.reserve); cin.image.orientation=0x00; offset+=WriteBlobByte(image,cin.image.orientation); cin.image.number_channels=3; offset+=WriteBlobByte(image,cin.image.number_channels); offset+=WriteBlob(image,sizeof(cin.image.reserve1),(unsigned char *) cin.image.reserve1); for (i=0; i < 8; i++) { cin.image.channel[i].designator[0]=0; /* universal metric */ offset+=WriteBlobByte(image,cin.image.channel[0].designator[0]); cin.image.channel[i].designator[1]=(unsigned char) (i > 3 ? 0 : i+1); /* channel color */; offset+=WriteBlobByte(image,cin.image.channel[1].designator[0]); cin.image.channel[i].bits_per_pixel=(unsigned char) image->depth; offset+=WriteBlobByte(image,cin.image.channel[0].bits_per_pixel); offset+=WriteBlobByte(image,cin.image.channel[0].reserve); cin.image.channel[i].pixels_per_line=image->columns; offset+=WriteBlobLong(image,(unsigned int) cin.image.channel[0].pixels_per_line); cin.image.channel[i].lines_per_image=image->rows; offset+=WriteBlobLong(image,(unsigned int) cin.image.channel[0].lines_per_image); cin.image.channel[i].min_data=0; offset+=WriteBlobFloat(image,cin.image.channel[0].min_data); cin.image.channel[i].min_quantity=0.0; offset+=WriteBlobFloat(image,cin.image.channel[0].min_quantity); cin.image.channel[i].max_data=(float) ((MagickOffsetType) GetQuantumRange(image->depth)); offset+=WriteBlobFloat(image,cin.image.channel[0].max_data); cin.image.channel[i].max_quantity=2.048f; offset+=WriteBlobFloat(image,cin.image.channel[0].max_quantity); } offset+=WriteBlobFloat(image,image->chromaticity.white_point.x); offset+=WriteBlobFloat(image,image->chromaticity.white_point.y); offset+=WriteBlobFloat(image,image->chromaticity.red_primary.x); offset+=WriteBlobFloat(image,image->chromaticity.red_primary.y); offset+=WriteBlobFloat(image,image->chromaticity.green_primary.x); offset+=WriteBlobFloat(image,image->chromaticity.green_primary.y); offset+=WriteBlobFloat(image,image->chromaticity.blue_primary.x); offset+=WriteBlobFloat(image,image->chromaticity.blue_primary.y); value=GetCINProperty(image_info,image,"dpx:image.label",exception); if (value != (const char *) NULL) (void) CopyMagickString(cin.image.label,value,sizeof(cin.image.label)); offset+=WriteBlob(image,sizeof(cin.image.label),(unsigned char *) cin.image.label); offset+=WriteBlob(image,sizeof(cin.image.reserve),(unsigned char *) cin.image.reserve); /* Write data format information. */ cin.data_format.interleave=0; /* pixel interleave (rgbrgbr...) */ offset+=WriteBlobByte(image,cin.data_format.interleave); cin.data_format.packing=5; /* packing ssize_tword (32bit) boundaries */ offset+=WriteBlobByte(image,cin.data_format.packing); cin.data_format.sign=0; /* unsigned data */ offset+=WriteBlobByte(image,cin.data_format.sign); cin.data_format.sense=0; /* image sense: positive image */ offset+=WriteBlobByte(image,cin.data_format.sense); cin.data_format.line_pad=0; offset+=WriteBlobLong(image,(unsigned int) cin.data_format.line_pad); cin.data_format.channel_pad=0; offset+=WriteBlobLong(image,(unsigned int) cin.data_format.channel_pad); offset+=WriteBlob(image,sizeof(cin.data_format.reserve),(unsigned char *) cin.data_format.reserve); /* Write origination information. */ cin.origination.x_offset=0UL; value=GetCINProperty(image_info,image,"dpx:origination.x_offset",exception); if (value != (const char *) NULL) cin.origination.x_offset=(ssize_t) StringToLong(value); offset+=WriteBlobLong(image,(unsigned int) cin.origination.x_offset); cin.origination.y_offset=0UL; value=GetCINProperty(image_info,image,"dpx:origination.y_offset",exception); if (value != (const char *) NULL) cin.origination.y_offset=(ssize_t) StringToLong(value); offset+=WriteBlobLong(image,(unsigned int) cin.origination.y_offset); value=GetCINProperty(image_info,image,"dpx:origination.filename",exception); if (value != (const char *) NULL) (void) CopyMagickString(cin.origination.filename,value, sizeof(cin.origination.filename)); else (void) CopyMagickString(cin.origination.filename,image->filename, sizeof(cin.origination.filename)); offset+=WriteBlob(image,sizeof(cin.origination.filename),(unsigned char *) cin.origination.filename); seconds=time((time_t *) NULL); (void) strftime(cin.origination.create_date, sizeof(cin.origination.create_date),"%Y:%m:%d",&local_time); offset+=WriteBlob(image,sizeof(cin.origination.create_date),(unsigned char *) cin.origination.create_date); (void) strftime(cin.origination.create_time, sizeof(cin.origination.create_time),"%H:%M:%S%Z",&local_time); offset+=WriteBlob(image,sizeof(cin.origination.create_time),(unsigned char *) cin.origination.create_time); value=GetCINProperty(image_info,image,"dpx:origination.device",exception); if (value != (const char *) NULL) (void) CopyMagickString(cin.origination.device,value, sizeof(cin.origination.device)); offset+=WriteBlob(image,sizeof(cin.origination.device),(unsigned char *) cin.origination.device); value=GetCINProperty(image_info,image,"dpx:origination.model",exception); if (value != (const char *) NULL) (void) CopyMagickString(cin.origination.model,value, sizeof(cin.origination.model)); offset+=WriteBlob(image,sizeof(cin.origination.model),(unsigned char *) cin.origination.model); value=GetCINProperty(image_info,image,"dpx:origination.serial",exception); if (value != (const char *) NULL) (void) CopyMagickString(cin.origination.serial,value, sizeof(cin.origination.serial)); offset+=WriteBlob(image,sizeof(cin.origination.serial),(unsigned char *) cin.origination.serial); cin.origination.x_pitch=0.0f; value=GetCINProperty(image_info,image,"dpx:origination.x_pitch",exception); if (value != (const char *) NULL) cin.origination.x_pitch=StringToDouble(value,(char **) NULL); offset+=WriteBlobFloat(image,cin.origination.x_pitch); cin.origination.y_pitch=0.0f; value=GetCINProperty(image_info,image,"dpx:origination.y_pitch",exception); if (value != (const char *) NULL) cin.origination.y_pitch=StringToDouble(value,(char **) NULL); offset+=WriteBlobFloat(image,cin.origination.y_pitch); cin.origination.gamma=image->gamma; offset+=WriteBlobFloat(image,cin.origination.gamma); offset+=WriteBlob(image,sizeof(cin.origination.reserve),(unsigned char *) cin.origination.reserve); /* Image film information. */ cin.film.id=0; value=GetCINProperty(image_info,image,"dpx:film.id",exception); if (value != (const char *) NULL) cin.film.id=(char) StringToLong(value); offset+=WriteBlobByte(image,(unsigned char) cin.film.id); cin.film.type=0; value=GetCINProperty(image_info,image,"dpx:film.type",exception); if (value != (const char *) NULL) cin.film.type=(char) StringToLong(value); offset+=WriteBlobByte(image,(unsigned char) cin.film.type); cin.film.offset=0; value=GetCINProperty(image_info,image,"dpx:film.offset",exception); if (value != (const char *) NULL) cin.film.offset=(char) StringToLong(value); offset+=WriteBlobByte(image,(unsigned char) cin.film.offset); offset+=WriteBlobByte(image,(unsigned char) cin.film.reserve1); cin.film.prefix=0UL; value=GetCINProperty(image_info,image,"dpx:film.prefix",exception); if (value != (const char *) NULL) cin.film.prefix=StringToUnsignedLong(value); offset+=WriteBlobLong(image,(unsigned int) cin.film.prefix); cin.film.count=0UL; value=GetCINProperty(image_info,image,"dpx:film.count",exception); if (value != (const char *) NULL) cin.film.count=StringToUnsignedLong(value); offset+=WriteBlobLong(image,(unsigned int) cin.film.count); value=GetCINProperty(image_info,image,"dpx:film.format",exception); if (value != (const char *) NULL) (void) CopyMagickString(cin.film.format,value,sizeof(cin.film.format)); offset+=WriteBlob(image,sizeof(cin.film.format),(unsigned char *) cin.film.format); cin.film.frame_position=0UL; value=GetCINProperty(image_info,image,"dpx:film.frame_position",exception); if (value != (const char *) NULL) cin.film.frame_position=StringToUnsignedLong(value); offset+=WriteBlobLong(image,(unsigned int) cin.film.frame_position); cin.film.frame_rate=0.0f; value=GetCINProperty(image_info,image,"dpx:film.frame_rate",exception); if (value != (const char *) NULL) cin.film.frame_rate=StringToDouble(value,(char **) NULL); offset+=WriteBlobFloat(image,cin.film.frame_rate); value=GetCINProperty(image_info,image,"dpx:film.frame_id",exception); if (value != (const char *) NULL) (void) CopyMagickString(cin.film.frame_id,value,sizeof(cin.film.frame_id)); offset+=WriteBlob(image,sizeof(cin.film.frame_id),(unsigned char *) cin.film.frame_id); value=GetCINProperty(image_info,image,"dpx:film.slate_info",exception); if (value != (const char *) NULL) (void) CopyMagickString(cin.film.slate_info,value, sizeof(cin.film.slate_info)); offset+=WriteBlob(image,sizeof(cin.film.slate_info),(unsigned char *) cin.film.slate_info); offset+=WriteBlob(image,sizeof(cin.film.reserve),(unsigned char *) cin.film.reserve); if (profile != (StringInfo *) NULL) offset+=WriteBlob(image,GetStringInfoLength(profile), GetStringInfoDatum(profile)); while (offset < (MagickOffsetType) cin.file.image_offset) offset+=WriteBlobByte(image,0x00); /* Convert pixel packets to CIN raster image. */ quantum_info=AcquireQuantumInfo(image_info,image); if (quantum_info == (QuantumInfo *) NULL) ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); quantum_info->quantum=32; quantum_info->pack=MagickFalse; quantum_type=RGBQuantum; pixels=GetQuantumPixels(quantum_info); length=GetBytesPerRow(image->columns,3,image->depth,MagickTrue); if (0) { quantum_type=GrayQuantum; length=GetBytesPerRow(image->columns,1,image->depth,MagickTrue); } for (y=0; y < (ssize_t) image->rows; y++) { p=GetVirtualPixels(image,0,y,image->columns,1,exception); if (p == (const Quantum *) NULL) break; (void) ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, quantum_type,pixels,exception); count=WriteBlob(image,length,pixels); if (count != (ssize_t) length) break; status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, image->rows); if (status == MagickFalse) break; } quantum_info=DestroyQuantumInfo(quantum_info); (void) CloseBlob(image); return(status); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t G e o m e t r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetGeometry() parses a geometry specification and returns the width, % height, x, and y values. It also returns flags that indicates which % of the four values (width, height, x, y) were located in the string, and % whether the x or y values are negative. In addition, there are flags to % report any meta characters (%, !, <, or >). % % The value must form a proper geometry style specification of WxH+X+Y % of integers only, and values can not be separated by comma, colon, or % slash charcaters. See ParseGeometry() below. % % Offsets may be prefixed by multiple signs to make offset string % substitutions easier to handle from shell scripts. % For example: "-10-10", "-+10-+10", or "+-10+-10" will generate negtive % offsets, while "+10+10", "++10++10", or "--10--10" will generate positive % offsets. % % The format of the GetGeometry method is: % % MagickStatusType GetGeometry(const char *geometry,ssize_t *x,ssize_t *y, % size_t *width,size_t *height) % % A description of each parameter follows: % % o geometry: The geometry. % % o x,y: The x and y offset as determined by the geometry specification. % % o width,height: The width and height as determined by the geometry % specification. % */ MagickExport MagickStatusType GetGeometry(const char *geometry,ssize_t *x, ssize_t *y,size_t *width,size_t *height) { char *p, pedantic_geometry[MagickPathExtent], *q; double value; int c; MagickStatusType flags; /* Remove whitespace and meta characters from geometry specification. */ flags=NoValue; if ((geometry == (char *) NULL) || (*geometry == '\0')) return(flags); if (strlen(geometry) >= (MagickPathExtent-1)) return(flags); (void) CopyMagickString(pedantic_geometry,geometry,MagickPathExtent); for (p=pedantic_geometry; *p != '\0'; ) { if (isspace((int) ((unsigned char) *p)) != 0) { (void) CopyMagickString(p,p+1,MagickPathExtent); continue; } c=(int)*p; switch (c) { case '%': { flags|=PercentValue; (void) CopyMagickString(p,p+1,MagickPathExtent); break; } case '!': { flags|=AspectValue; (void) CopyMagickString(p,p+1,MagickPathExtent); break; } case '<': { flags|=LessValue; (void) CopyMagickString(p,p+1,MagickPathExtent); break; } case '>': { flags|=GreaterValue; (void) CopyMagickString(p,p+1,MagickPathExtent); break; } case '^': { flags|=MinimumValue; (void) CopyMagickString(p,p+1,MagickPathExtent); break; } case '@': { flags|=AreaValue; (void) CopyMagickString(p,p+1,MagickPathExtent); break; } case '(': case ')': { (void) CopyMagickString(p,p+1,MagickPathExtent); break; } case 'x': case 'X': { flags|=SeparatorValue; p++; break; } case '-': case '.': case ',': case '+': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 215: case 'e': case 'E': { p++; break; } default: return(flags); } } /* Parse width, height, x, and y. */ p=pedantic_geometry; if (*p == '\0') return(flags); q=p; value=StringToDouble(p,&q); (void) value; if (LocaleNCompare(p,"0x",2) == 0) value=(double) strtol(p,&q,10); if ((*p != '+') && (*p != '-')) { c=(int) ((unsigned char) *q); if ((c == 215) || (*q == 'x') || (*q == 'X') || (*q == '\0')) { /* Parse width. */ q=p; if (LocaleNCompare(p,"0x",2) == 0) *width=(size_t) strtol(p,&p,10); else *width=(size_t) floor(StringToDouble(p,&p)+0.5); if (p != q) flags|=WidthValue; } } if ((*p != '+') && (*p != '-')) { c=(int) ((unsigned char) *p); if ((c == 215) || (*p == 'x') || (*p == 'X')) { p++; if ((*p != '+') && (*p != '-')) { /* Parse height. */ q=p; *height=(size_t) floor(StringToDouble(p,&p)+0.5); if (p != q) flags|=HeightValue; } } } if ((*p == '+') || (*p == '-')) { /* Parse x value. */ while ((*p == '+') || (*p == '-')) { if (*p == '-') flags^=XNegative; /* negate sign */ p++; } q=p; *x=(ssize_t) ceil(StringToDouble(p,&p)-0.5); if (p != q) { flags|=XValue; if ((flags & XNegative) != 0) *x=(-*x); } } if ((*p == '+') || (*p == '-')) { /* Parse y value. */ while ((*p == '+') || (*p == '-')) { if (*p == '-') flags^=YNegative; /* negate sign */ p++; } q=p; *y=(ssize_t) ceil(StringToDouble(p,&p)-0.5); if (p != q) { flags|=YValue; if ((flags & YNegative) != 0) *y=(-*y); } } if ((flags & PercentValue) != 0) { if (((flags & SeparatorValue) == 0) && ((flags & HeightValue) == 0)) { *height=(*width); flags|=HeightValue; } if (((flags & SeparatorValue) != 0) && ((flags & WidthValue) == 0)) *width=(*height); } #if 0 /* Debugging Geometry */ (void) fprintf(stderr,"GetGeometry...\n"); (void) fprintf(stderr,"Input: %s\n",geometry); (void) fprintf(stderr,"Flags: %c %c %s %s\n", (flags & WidthValue) ? 'W' : ' ',(flags & HeightValue) ? 'H' : ' ', (flags & XValue) ? ((flags & XNegative) ? "-X" : "+X") : " ", (flags & YValue) ? ((flags & YNegative) ? "-Y" : "+Y") : " "); (void) fprintf(stderr,"Geometry: %ldx%ld%+ld%+ld\n",(long) *width,(long) *height,(long) *x,(long) *y); #endif return(flags); }
WandExport MagickBooleanType IdentifyImageCommand(ImageInfo *image_info, int argc,char **argv,char **metadata,ExceptionInfo *exception) { #define DestroyIdentify() \ { \ DestroyImageStack(); \ for (i=0; i < (ssize_t) argc; i++) \ argv[i]=DestroyString(argv[i]); \ argv=(char **) RelinquishMagickMemory(argv); \ } #define ThrowIdentifyException(asperity,tag,option) \ { \ (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \ option); \ DestroyIdentify(); \ return(MagickFalse); \ } #define ThrowIdentifyInvalidArgumentException(option,argument) \ { \ (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \ "InvalidArgument","'%s': %s",option,argument); \ DestroyIdentify(); \ return(MagickFalse); \ } const char *format, *option; Image *image; ImageStack image_stack[MaxImageStackDepth+1]; MagickBooleanType fire, pend, respect_parenthesis; MagickStatusType status; register ssize_t i; size_t count; ssize_t j, k; /* Set defaults. */ assert(image_info != (ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); assert(exception != (ExceptionInfo *) NULL); if (argc == 2) { option=argv[1]; if ((LocaleCompare("version",option+1) == 0) || (LocaleCompare("-version",option+1) == 0)) { ListMagickVersion(stdout); return(MagickFalse); } } if (argc < 2) return(IdentifyUsage()); count=0; format=NULL; j=1; k=0; NewImageStack(); option=(char *) NULL; pend=MagickFalse; respect_parenthesis=MagickFalse; status=MagickTrue; /* Identify an image. */ ReadCommandlLine(argc,&argv); status=ExpandFilenames(&argc,&argv); if (status == MagickFalse) ThrowIdentifyException(ResourceLimitError,"MemoryAllocationFailed", GetExceptionMessage(errno)); image_info->ping=MagickTrue; for (i=1; i < (ssize_t) argc; i++) { option=argv[i]; if (LocaleCompare(option,"(") == 0) { FireImageStack(MagickFalse,MagickTrue,pend); if (k == MaxImageStackDepth) ThrowIdentifyException(OptionError,"ParenthesisNestedTooDeeply", option); PushImageStack(); continue; } if (LocaleCompare(option,")") == 0) { FireImageStack(MagickFalse,MagickTrue,MagickTrue); if (k == 0) ThrowIdentifyException(OptionError,"UnableToParseExpression",option); PopImageStack(); continue; } if (IsCommandOption(option) == MagickFalse) { char *filename; Image *images; ImageInfo *identify_info; /* Read input image. */ FireImageStack(MagickFalse,MagickFalse,pend); identify_info=CloneImageInfo(image_info); identify_info->verbose=MagickFalse; filename=argv[i]; if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1))) filename=argv[++i]; if (identify_info->ping != MagickFalse) images=PingImages(identify_info,filename,exception); else images=ReadImages(identify_info,filename,exception); identify_info=DestroyImageInfo(identify_info); status&=(images != (Image *) NULL) && (exception->severity < ErrorException); if (images == (Image *) NULL) continue; AppendImageStack(images); FinalizeImageSettings(image_info,image,MagickFalse); for ( ; image != (Image *) NULL; image=GetNextImageInList(image)) { if (image->scene == 0) image->scene=count++; if (format == (char *) NULL) { (void) IdentifyImage(image,stdout,image_info->verbose,exception); continue; } if (metadata != (char **) NULL) { char *text; text=InterpretImageProperties(image_info,image,format,exception); if (text == (char *) NULL) ThrowIdentifyException(ResourceLimitError, "MemoryAllocationFailed",GetExceptionMessage(errno)); (void) ConcatenateString(&(*metadata),text); text=DestroyString(text); if (LocaleCompare(format,"%n") == 0) break; } } RemoveAllImageStack(); continue; } pend=image != (Image *) NULL ? MagickTrue : MagickFalse; switch (*(option+1)) { case 'a': { if (LocaleCompare("alpha",option+1) == 0) { ssize_t type; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowIdentifyException(OptionError,"MissingArgument",option); type=ParseCommandOption(MagickAlphaChannelOptions,MagickFalse, argv[i]); if (type < 0) ThrowIdentifyException(OptionError, "UnrecognizedAlphaChannelOption",argv[i]); break; } if (LocaleCompare("antialias",option+1) == 0) break; if (LocaleCompare("authenticate",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowIdentifyException(OptionError,"MissingArgument",option); break; } ThrowIdentifyException(OptionError,"UnrecognizedOption",option) } case 'c': { if (LocaleCompare("cache",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowIdentifyException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowIdentifyInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("channel",option+1) == 0) { ssize_t channel; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowIdentifyException(OptionError,"MissingArgument",option); channel=ParseChannelOption(argv[i]); if (channel < 0) ThrowIdentifyException(OptionError,"UnrecognizedChannelType", argv[i]); break; } if (LocaleCompare("clip",option+1) == 0) break; if (LocaleCompare("clip-mask",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowIdentifyException(OptionError,"MissingArgument",option); break; } if (LocaleCompare("clip-path",option+1) == 0) { i++; if (i == (ssize_t) (argc-1)) ThrowIdentifyException(OptionError,"MissingArgument",option); break; } if (LocaleCompare("colorspace",option+1) == 0) { ssize_t colorspace; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowIdentifyException(OptionError,"MissingArgument",option); colorspace=ParseCommandOption(MagickColorspaceOptions, MagickFalse,argv[i]); if (colorspace < 0) ThrowIdentifyException(OptionError,"UnrecognizedColorspace", argv[i]); break; } if (LocaleCompare("crop",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowIdentifyException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowIdentifyInvalidArgumentException(option,argv[i]); image_info->ping=MagickFalse; break; } if (LocaleCompare("concurrent",option+1) == 0) break; ThrowIdentifyException(OptionError,"UnrecognizedOption",option) } case 'd': { if (LocaleCompare("debug",option+1) == 0) { ssize_t event; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowIdentifyException(OptionError,"MissingArgument",option); event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]); if (event < 0) ThrowIdentifyException(OptionError,"UnrecognizedEventType", argv[i]); (void) SetLogEventMask(argv[i]); break; } if (LocaleCompare("define",option+1) == 0) { i++; if (i == (ssize_t) argc) ThrowIdentifyException(OptionError,"MissingArgument",option); if (*option == '+') { const char *define; define=GetImageOption(image_info,argv[i]); if (define == (const char *) NULL) ThrowIdentifyException(OptionError,"NoSuchOption",argv[i]); break; } if (LocaleNCompare("identify:locate",argv[i],14) == 0) image_info->ping=MagickFalse; break; } if (LocaleCompare("density",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowIdentifyException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowIdentifyInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("depth",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowIdentifyException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowIdentifyInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("duration",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowIdentifyException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowIdentifyInvalidArgumentException(option,argv[i]); break; } ThrowIdentifyException(OptionError,"UnrecognizedOption",option) } case 'e': { if (LocaleCompare("endian",option+1) == 0) { ssize_t endian; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowIdentifyException(OptionError,"MissingArgument",option); endian=ParseCommandOption(MagickEndianOptions,MagickFalse, argv[i]); if (endian < 0) ThrowIdentifyException(OptionError,"UnrecognizedEndianType", argv[i]); break; } ThrowIdentifyException(OptionError,"UnrecognizedOption",option) } case 'f': { if (LocaleCompare("features",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowIdentifyException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowIdentifyInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("format",option+1) == 0) { format=(char *) NULL; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowIdentifyException(OptionError,"MissingArgument",option); format=argv[i]; break; } if (LocaleCompare("fuzz",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowIdentifyException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowIdentifyInvalidArgumentException(option,argv[i]); break; } ThrowIdentifyException(OptionError,"UnrecognizedOption",option) } case 'g': { if (LocaleCompare("gamma",option+1) == 0) { i++; if (i == (ssize_t) (argc-1)) ThrowIdentifyException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowIdentifyInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("grayscale",option+1) == 0) { ssize_t method; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowIdentifyException(OptionError,"MissingArgument",option); method=ParseCommandOption(MagickPixelIntensityOptions,MagickFalse, argv[i]); if (method < 0) ThrowIdentifyException(OptionError,"UnrecognizedIntensityMethod", argv[i]); break; } if (LocaleCompare("green-primary",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowIdentifyException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowIdentifyInvalidArgumentException(option,argv[i]); break; } ThrowIdentifyException(OptionError,"UnrecognizedOption",option) } case 'h': { if ((LocaleCompare("help",option+1) == 0) || (LocaleCompare("-help",option+1) == 0)) return(IdentifyUsage()); ThrowIdentifyException(OptionError,"UnrecognizedOption",option) } case 'i': { if (LocaleCompare("interlace",option+1) == 0) { ssize_t interlace; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowIdentifyException(OptionError,"MissingArgument",option); interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse, argv[i]); if (interlace < 0) ThrowIdentifyException(OptionError, "UnrecognizedInterlaceType",argv[i]); break; } if (LocaleCompare("interpolate",option+1) == 0) { ssize_t interpolate; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowIdentifyException(OptionError,"MissingArgument",option); interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse, argv[i]); if (interpolate < 0) ThrowIdentifyException(OptionError, "UnrecognizedInterpolateMethod",argv[i]); break; } ThrowIdentifyException(OptionError,"UnrecognizedOption",option) } case 'l': { if (LocaleCompare("limit",option+1) == 0) { char *p; double value; ssize_t resource; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowIdentifyException(OptionError,"MissingArgument",option); resource=ParseCommandOption(MagickResourceOptions,MagickFalse, argv[i]); if (resource < 0) ThrowIdentifyException(OptionError,"UnrecognizedResourceType", argv[i]); i++; if (i == (ssize_t) argc) ThrowIdentifyException(OptionError,"MissingArgument",option); value=StringToDouble(argv[i],&p); (void) value; if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0)) ThrowIdentifyInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("list",option+1) == 0) { ssize_t list; if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowIdentifyException(OptionError,"MissingArgument",option); list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]); if (list < 0) ThrowIdentifyException(OptionError,"UnrecognizedListType", argv[i]); status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **) argv+j,exception); DestroyIdentify(); return(status != 0 ? MagickFalse : MagickTrue); } if (LocaleCompare("log",option+1) == 0) { if (*option == '+') break; i++; if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL)) ThrowIdentifyException(OptionError,"MissingArgument",option); break; } ThrowIdentifyException(OptionError,"UnrecognizedOption",option) } case 'm': { if (LocaleCompare("mask",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowIdentifyException(OptionError,"MissingArgument",option); break; } if (LocaleCompare("matte",option+1) == 0) break; if (LocaleCompare("moments",option+1) == 0) break; if (LocaleCompare("monitor",option+1) == 0) break; ThrowIdentifyException(OptionError,"UnrecognizedOption",option) } case 'n': { if (LocaleCompare("negate",option+1) == 0) break; ThrowIdentifyException(OptionError,"UnrecognizedOption",option) } case 'p': { if (LocaleCompare("ping",option+1) == 0) break; if (LocaleCompare("precision",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowIdentifyException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowIdentifyInvalidArgumentException(option,argv[i]); break; } ThrowIdentifyException(OptionError,"UnrecognizedOption",option) } case 'q': { if (LocaleCompare("quiet",option+1) == 0) break; ThrowIdentifyException(OptionError,"UnrecognizedOption",option) } case 'r': { if (LocaleCompare("regard-warnings",option+1) == 0) break; if (LocaleNCompare("respect-parentheses",option+1,17) == 0) { respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse; break; } ThrowIdentifyException(OptionError,"UnrecognizedOption",option) } case 's': { if (LocaleCompare("sampling-factor",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowIdentifyException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowIdentifyInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("seed",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowIdentifyException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowIdentifyInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("set",option+1) == 0) { i++; if (i == (ssize_t) argc) ThrowIdentifyException(OptionError,"MissingArgument",option); if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowIdentifyException(OptionError,"MissingArgument",option); break; } if (LocaleCompare("size",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowIdentifyException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowIdentifyInvalidArgumentException(option,argv[i]); break; } if (LocaleCompare("strip",option+1) == 0) break; if (LocaleCompare("support",option+1) == 0) { if (*option == '+') break; i++; if (i == (ssize_t) argc) ThrowIdentifyException(OptionError,"MissingArgument",option); if (IsGeometry(argv[i]) == MagickFalse) ThrowIdentifyInvalidArgumentException(option,argv[i]); break; } ThrowIdentifyException(OptionError,"UnrecognizedOption",option) } case 'u': { if (LocaleCompare("unique",option+1) == 0) break; if (LocaleCompare("units",option+1) == 0) { ssize_t units; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowIdentifyException(OptionError,"MissingArgument",option); units=ParseCommandOption(MagickResolutionOptions,MagickFalse, argv[i]); if (units < 0) ThrowIdentifyException(OptionError,"UnrecognizedUnitsType", argv[i]); break; } ThrowIdentifyException(OptionError,"UnrecognizedOption",option) } case 'v': { if (LocaleCompare("verbose",option+1) == 0) break; if (LocaleCompare("virtual-pixel",option+1) == 0) { ssize_t method; if (*option == '+') break; i++; if (i == (ssize_t) (argc-1)) ThrowIdentifyException(OptionError,"MissingArgument",option); method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse, argv[i]); if (method < 0) ThrowIdentifyException(OptionError, "UnrecognizedVirtualPixelMethod",argv[i]); break; } ThrowIdentifyException(OptionError,"UnrecognizedOption",option) } case '?': break; default: ThrowIdentifyException(OptionError,"UnrecognizedOption",option) } fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) & FireOptionFlag) == 0 ? MagickFalse : MagickTrue; if (fire != MagickFalse) FireImageStack(MagickFalse,MagickTrue,MagickTrue); } if (k != 0) ThrowIdentifyException(OptionError,"UnbalancedParenthesis",argv[i]); if (i != (ssize_t) argc) ThrowIdentifyException(OptionError,"MissingAnImageFilename",argv[i]); DestroyIdentify(); return(status != 0 ? MagickTrue : MagickFalse); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d H D R I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadHDRImage() reads the Radiance RGBE image format and returns it. It % allocates the memory necessary for the new Image structure and returns a % pointer to the new image. % % The format of the ReadHDRImage method is: % % Image *ReadHDRImage(const ImageInfo *image_info,ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: the image info. % % o exception: return any errors or warnings in this structure. % */ static Image *ReadHDRImage(const ImageInfo *image_info,ExceptionInfo *exception) { char format[MaxTextExtent], keyword[MaxTextExtent], tag[MaxTextExtent], value[MaxTextExtent]; double gamma; Image *image; int c; MagickBooleanType status, value_expected; register PixelPacket *q; register unsigned char *p; register ssize_t i, x; ssize_t count, y; unsigned char *end, pixel[4], *pixels; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AcquireImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } /* Decode image header. */ image->columns=0; image->rows=0; *format='\0'; c=ReadBlobByte(image); if (c == EOF) { image=DestroyImage(image); return((Image *) NULL); } while (isgraph(c) && (image->columns == 0) && (image->rows == 0)) { if (c == (int) '#') { char *comment; register char *p; size_t length; /* Read comment-- any text between # and end-of-line. */ length=MaxTextExtent; comment=AcquireString((char *) NULL); for (p=comment; comment != (char *) NULL; p++) { c=ReadBlobByte(image); if ((c == EOF) || (c == (int) '\n')) break; if ((size_t) (p-comment+1) >= length) { *p='\0'; length<<=1; comment=(char *) ResizeQuantumMemory(comment,length+ MaxTextExtent,sizeof(*comment)); if (comment == (char *) NULL) break; p=comment+strlen(comment); } *p=(char) c; } if (comment == (char *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); *p='\0'; (void) SetImageProperty(image,"comment",comment); comment=DestroyString(comment); c=ReadBlobByte(image); } else if (isalnum(c) == MagickFalse) c=ReadBlobByte(image); else { register char *p; /* Determine a keyword and its value. */ p=keyword; do { if ((size_t) (p-keyword) < (MaxTextExtent-1)) *p++=c; c=ReadBlobByte(image); } while (isalnum(c) || (c == '_')); *p='\0'; value_expected=MagickFalse; while ((isspace((int) ((unsigned char) c)) != 0) || (c == '=')) { if (c == '=') value_expected=MagickTrue; c=ReadBlobByte(image); } if (LocaleCompare(keyword,"Y") == 0) value_expected=MagickTrue; if (value_expected == MagickFalse) continue; p=value; while ((c != '\n') && (c != '\0') && (c != EOF)) { if ((size_t) (p-value) < (MaxTextExtent-1)) *p++=c; c=ReadBlobByte(image); } *p='\0'; /* Assign a value to the specified keyword. */ switch (*keyword) { case 'F': case 'f': { if (LocaleCompare(keyword,"format") == 0) { (void) CopyMagickString(format,value,MaxTextExtent); break; } (void) FormatLocaleString(tag,MaxTextExtent,"hdr:%s",keyword); (void) SetImageProperty(image,tag,value); break; } case 'G': case 'g': { if (LocaleCompare(keyword,"gamma") == 0) { image->gamma=StringToDouble(value,(char **) NULL); break; } (void) FormatLocaleString(tag,MaxTextExtent,"hdr:%s",keyword); (void) SetImageProperty(image,tag,value); break; } case 'P': case 'p': { if (LocaleCompare(keyword,"primaries") == 0) { float chromaticity[6], white_point[2]; int count; count=sscanf(value,"%g %g %g %g %g %g %g %g",&chromaticity[0], &chromaticity[1],&chromaticity[2],&chromaticity[3], &chromaticity[4],&chromaticity[5],&white_point[0], &white_point[1]); if (count == 8) { image->chromaticity.red_primary.x=chromaticity[0]; image->chromaticity.red_primary.y=chromaticity[1]; image->chromaticity.green_primary.x=chromaticity[2]; image->chromaticity.green_primary.y=chromaticity[3]; image->chromaticity.blue_primary.x=chromaticity[4]; image->chromaticity.blue_primary.y=chromaticity[5]; image->chromaticity.white_point.x=white_point[0], image->chromaticity.white_point.y=white_point[1]; } break; } (void) FormatLocaleString(tag,MaxTextExtent,"hdr:%s",keyword); (void) SetImageProperty(image,tag,value); break; } case 'Y': case 'y': { char target[] = "Y"; if (strcmp(keyword,target) == 0) { int height, width; if (sscanf(value,"%d +X %d",&height,&width) == 2) { image->columns=(size_t) width; image->rows=(size_t) height; } break; } (void) FormatLocaleString(tag,MaxTextExtent,"hdr:%s",keyword); (void) SetImageProperty(image,tag,value); break; } default: { (void) FormatLocaleString(tag,MaxTextExtent,"hdr:%s",keyword); (void) SetImageProperty(image,tag,value); break; } } } if ((image->columns == 0) && (image->rows == 0)) while (isspace((int) ((unsigned char) c)) != 0) c=ReadBlobByte(image); } if ((LocaleCompare(format,"32-bit_rle_rgbe") != 0) && (LocaleCompare(format,"32-bit_rle_xyze") != 0)) ThrowReaderException(CorruptImageError,"ImproperImageHeader"); if ((image->columns == 0) || (image->rows == 0)) ThrowReaderException(CorruptImageError,"NegativeOrZeroImageSize"); (void) SetImageColorspace(image,RGBColorspace); if (LocaleCompare(format,"32-bit_rle_xyze") == 0) (void) SetImageColorspace(image,XYZColorspace); image->compression=(image->columns < 8) || (image->columns > 0x7ffff) ? NoCompression : RLECompression; if (image_info->ping != MagickFalse) { (void) CloseBlob(image); return(GetFirstImageInList(image)); } status=SetImageExtent(image,image->columns,image->rows); if (status == MagickFalse) { InheritException(exception,&image->exception); return(DestroyImageList(image)); } /* Read RGBE (red+green+blue+exponent) pixels. */ pixels=(unsigned char *) AcquireQuantumMemory(image->columns,4* sizeof(*pixels)); if (pixels == (unsigned char *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); for (y=0; y < (ssize_t) image->rows; y++) { if (image->compression != RLECompression) { count=ReadBlob(image,4*image->columns*sizeof(*pixels),pixels); if (count != (ssize_t) (4*image->columns*sizeof(*pixels))) break; } else { count=ReadBlob(image,4*sizeof(*pixel),pixel); if (count != 4) break; if ((size_t) ((((size_t) pixel[2]) << 8) | pixel[3]) != image->columns) { (void) memcpy(pixels,pixel,4*sizeof(*pixel)); (void) ReadBlob(image,4*(image->columns-1)*sizeof(*pixels),pixels+4); image->compression=NoCompression; } else { p=pixels; for (i=0; i < 4; i++) { end=&pixels[(i+1)*image->columns]; while (p < end) { count=ReadBlob(image,2*sizeof(*pixel),pixel); if (count < 1) break; if (pixel[0] > 128) { count=(ssize_t) pixel[0]-128; if ((count == 0) || (count > (ssize_t) (end-p))) break; while (count-- > 0) *p++=pixel[1]; } else { count=(ssize_t) pixel[0]; if ((count == 0) || (count > (ssize_t) (end-p))) break; *p++=pixel[1]; if (--count > 0) { count=ReadBlob(image,(size_t) count*sizeof(*p),p); if (count < 1) break; p+=count; } } } } } } q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); if (q == (PixelPacket *) NULL) break; i=0; for (x=0; x < (ssize_t) image->columns; x++) { if (image->compression == RLECompression) { pixel[0]=pixels[x]; pixel[1]=pixels[x+image->columns]; pixel[2]=pixels[x+2*image->columns]; pixel[3]=pixels[x+3*image->columns]; } else { pixel[0]=pixels[i++]; pixel[1]=pixels[i++]; pixel[2]=pixels[i++]; pixel[3]=pixels[i++]; } SetPixelRed(q,0); SetPixelGreen(q,0); SetPixelBlue(q,0); if (pixel[3] != 0) { gamma=pow(2.0,pixel[3]-(128.0+8.0)); SetPixelRed(q,ClampToQuantum(QuantumRange*gamma*pixel[0])); SetPixelGreen(q,ClampToQuantum(QuantumRange*gamma*pixel[1])); SetPixelBlue(q,ClampToQuantum(QuantumRange*gamma*pixel[2])); } q++; } if (SyncAuthenticPixels(image,exception) == MagickFalse) break; status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, image->rows); if (status == MagickFalse) break; } pixels=(unsigned char *) RelinquishMagickMemory(pixels); if (EOFBlob(image) != MagickFalse) ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", image->filename); (void) CloseBlob(image); return(GetFirstImageInList(image)); }