/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d D N G I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadDNGImage() reads an binary file in the Digital Negative 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 ReadDNGImage method is: % % Image *ReadDNGImage(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 *ReadDNGImage(const ImageInfo *image_info,ExceptionInfo *exception) { ExceptionInfo *sans_exception; Image *image; ImageInfo *read_info; MagickBooleanType status; /* 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); } (void) CloseBlob(image); (void) DestroyImageList(image); /* Convert DNG to PPM with delegate. */ image=AcquireImage(image_info); read_info=CloneImageInfo(image_info); (void) InvokeDelegate(read_info,image,"dng:decode",(char *) NULL,exception); image=DestroyImage(image); (void) FormatMagickString(read_info->filename,MaxTextExtent,"%s.png", read_info->unique); sans_exception=AcquireExceptionInfo(); image=ReadImage(read_info,sans_exception); sans_exception=DestroyExceptionInfo(sans_exception); if (image == (Image *) NULL) { (void) FormatMagickString(read_info->filename,MaxTextExtent,"%s.ppm", read_info->unique); image=ReadImage(read_info,exception); } (void) RelinquishUniqueFileResource(read_info->filename); if (image != (Image *) NULL) { char filename[MaxTextExtent], *xml; ExceptionInfo *sans; (void) CopyMagickString(image->magick,read_info->magick,MaxTextExtent); (void) FormatMagickString(filename,MaxTextExtent,"%s.ufraw", read_info->unique); sans=AcquireExceptionInfo(); xml=FileToString(filename,MaxTextExtent,sans); (void) RelinquishUniqueFileResource(filename); if (xml != (char *) NULL) { XMLTreeInfo *ufraw; /* Inject */ ufraw=NewXMLTree(xml,sans); if (ufraw != (XMLTreeInfo *) NULL) { char *content, property[MaxTextExtent]; const char *tag; XMLTreeInfo *next; if (image->properties == (void *) NULL) ((Image *) image)->properties=NewSplayTree( CompareSplayTreeString,RelinquishMagickMemory, RelinquishMagickMemory); next=GetXMLTreeChild(ufraw,(const char *) NULL); while (next != (XMLTreeInfo *) NULL) { tag=GetXMLTreeTag(next); if (tag == (char *) NULL) tag="unknown"; (void) FormatMagickString(property,MaxTextExtent,"dng:%s",tag); content=ConstantString(GetXMLTreeContent(next)); StripString(content); if ((LocaleCompare(tag,"log") != 0) && (LocaleCompare(tag,"InputFilename") != 0) && (LocaleCompare(tag,"OutputFilename") != 0) && (LocaleCompare(tag,"OutputType") != 0) && (strlen(content) != 0)) (void) AddValueToSplayTree((SplayTreeInfo *) ((Image *) image)->properties,ConstantString(property), content); next=GetXMLTreeSibling(next); } ufraw=DestroyXMLTree(ufraw); } xml=DestroyString(xml); } sans=DestroyExceptionInfo(sans); } read_info=DestroyImageInfo(read_info); return(image); }
static MagickBooleanType TraverseLocaleMap(const char *filename, XMLTreeInfo **components,XMLTreeInfo *node,const unsigned long depth, ExceptionInfo *exception) { MagickBooleanType status; status=MagickTrue; if (depth >= MaxRecursionDepth) (void) ThrowMagickException(exception,GetMagickModule(),ConfigureError, "IncludeElementNestedTooDeeply","`%s'",filename); else if (node != (XMLTreeInfo *) NULL) { XMLTreeInfo *child, *sibling; components[depth]=node; if (strcmp(GetXMLTreeTag(node),"message") == 0) { char *message, *tag; const char *attribute, *content; LocaleInfo *locale_info; register long i; locale_info=(LocaleInfo *) AcquireMagickMemory( sizeof(*locale_info)); if (locale_info == (LocaleInfo *) NULL) ThrowFatalException(ResourceLimitFatalError, "MemoryAllocationFailed"); (void) ResetMagickMemory(locale_info,0,sizeof(*locale_info)); locale_info->path=ConstantString(filename); locale_info->signature=MagickSignature; tag=AcquireString((char *) NULL); for (i=1; i < (long) depth; i++) { (void) ConcatenateString(&tag,GetXMLTreeTag(components[i])); (void) ConcatenateString(&tag,"/"); } attribute=GetXMLTreeAttribute(node,"name"); if (attribute != (const char *) NULL) { (void) ConcatenateString(&tag,attribute); (void) ConcatenateString(&tag,"/"); } locale_info->tag=ConstantString(tag); tag=DestroyString(tag); message=AcquireString((char *) NULL); content=GetXMLTreeContent(node); if (content != (const char *) NULL) { (void) ConcatenateString(&message,content); StripString(message); } locale_info->message=ConstantString(message); message=DestroyString(message); status=AddValueToSplayTree(locale_list,locale_info->tag, locale_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",filename); } child=GetXMLTreeChild(node,(const char *) NULL); if (child != (XMLTreeInfo *) NULL) status=TraverseLocaleMap(filename,components,child,depth+1,exception); sibling=GetXMLTreeOrdered(node); if (sibling != (XMLTreeInfo *) NULL) status=TraverseLocaleMap(filename,components,sibling,depth,exception); } return(status); }