Exemplo n.º 1
0
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   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);
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
  char
    *xml;

  const char
    *acronym,
    *data_type,
    *description,
    *endian,
    *mask,
    *mime_type,
    *offset,
    *pattern,
    *priority,
    *match_type,
    *value;

  ExceptionInfo
    *exception;

  size_t
    length;
 
  static char
    *doc_type =
    {
      "<!DOCTYPE mimemap [\n"
      "  <!ELEMENT mimemap (mime+)>\n"
      "  <!ELEMENT mime (#PCDATA)>\n"
      "  <!ATTLIST mime type CDATA #REQUIRED>\n"
      "  <!ATTLIST mime acronym CDATA #IMPLIED>\n"
      "  <!ATTLIST mime description CDATA #IMPLIED>\n"
      "  <!ATTLIST mime pattern CDATA #IMPLIED>\n"
      "  <!ATTLIST mime offset CDATA #IMPLIED>\n"
      "  <!ATTLIST mime data-type (string|byte|short|ssize_t) #IMPLIED>\n"
      "  <!ATTLIST mime endian (lsb|msb) #IMPLIED>\n"
      "  <!ATTLIST mime magic CDATA #IMPLIED>\n"
      "  <!ATTLIST mime mask CDATA #IMPLIED>\n"
      "  <!ATTLIST mime priority CDATA #IMPLIED>\n"
      "]>"
    };

  XMLTreeInfo
    *comment,
    *expanded_acronym,
    *glob,
    *magic,
    *match,
    *type,
    *xml_info;

  if (argc != 2)
    return(fprintf(stderr,"usage: %s xml-file\n", argv[0]));
  exception=AcquireExceptionInfo();
  xml=(char *) FileToBlob(argv[1],~0UL,&length,exception);
  if (xml == (char *) NULL)
    return(fprintf(stderr,"%s: unable to read file\n",argv[1]));
  xml_info=NewXMLTree(xml,exception);
  xml=(char *) RelinquishWizardMemory(xml);
  if (xml_info == (XMLTreeInfo *) NULL)
    return(fprintf(stderr,"%s: unable to parse xml-file\n",argv[1]));
  (void) printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  (void) printf("%s\n",doc_type);
  (void) printf("<mimemap>\n");
  type=GetXMLTreeChild(xml_info,"mime-type");
	while (type != (XMLTreeInfo *) NULL)
  {
    mime_type=GetXMLTreeAttribute(type,"type");
    acronym=(const char *) NULL;
    expanded_acronym=GetXMLTreeChild(type,"acronym");
    if (expanded_acronym != (XMLTreeInfo *) NULL)
      acronym=GetXMLTreeContent(expanded_acronym);
    expanded_acronym=GetXMLTreeChild(type,"expanded-acronym");
    description=(const char *) NULL;
    comment=GetXMLTreeChild(type,"comment");
    if (comment != (XMLTreeInfo *) NULL)
      description=GetXMLTreeContent(comment);
    if (expanded_acronym != (XMLTreeInfo *) NULL)
      description=GetXMLTreeContent(expanded_acronym);
    magic=GetXMLTreeChild(type,"magic");
    priority=(char *) NULL;
    match=(XMLTreeInfo *) NULL;
    if (magic != (XMLTreeInfo *) NULL)
      {
        priority=GetXMLTreeAttribute(magic,"priority");
        match=GetXMLTreeChild(magic,"match");
      }
  	while (match != (XMLTreeInfo *) NULL)
    {
      value=(char *) NULL;
      match_type=(char *) NULL;
      mask=(char *) NULL;
      offset=(char *) NULL;
      if (match != (XMLTreeInfo *) NULL)
        {
          value=GetXMLTreeAttribute(match,"value");
          match_type=GetXMLTreeAttribute(match,"type");
          offset=GetXMLTreeAttribute(match,"offset");
          mask=GetXMLTreeAttribute(match,"mask");
        }
      (void) printf("  <mime");
      if (mime_type != (const char *) NULL)
        (void) printf(" type=\"%s\"",mime_type);
      if (description != (const char *) NULL)
        (void) printf(" description=\"%s\"",description);
      if (match_type != (const char *) NULL)
        {
          data_type="string";
          endian="undefined";
          if (strncmp(match_type,"little",6) == 0)
            endian="LSB";
          if (strncmp(match_type,"big",3) == 0)
            endian="MSB";
          if (strcmp(match_type,"byte") == 0)
            data_type="byte";
          if (strcmp(match_type+strlen(match_type)-2,"16") == 0)
            data_type="short";
          if (strcmp(match_type+strlen(match_type)-2,"32") == 0)
            data_type="ssize_t";
          (void) printf(" data-type=\"%s\"",data_type);
          if (strcmp(endian,"undefined") != 0)
            (void) printf(" endian=\"%s\"",endian);
        }
      if (offset != (const char *) NULL)
        (void) printf(" offset=\"%s\"",offset);
      if (mask != (const char *) NULL)
        (void) printf(" mask=\"%s\"",mask);
      if (value != (const char *) NULL)
        {
          char
            *magic;

          magic=AcquireString(value);
          SubstituteString(&magic,"<","&lt;");
          SubstituteString(&magic,">","&gt;");
          SubstituteString(&magic,"\"","&quot;");
          (void) printf(" magic=\"%s\"",magic);
          magic=(char *) RelinquishWizardMemory(magic);
        }
      if (priority != (const char *) NULL)
        (void) printf(" priority=\"%s\"",priority);
      (void) printf(" />\n");
		  match=GetNextXMLTreeTag(match);
    }
    glob=GetXMLTreeChild(type,"glob");
    while (glob != (XMLTreeInfo *) NULL)
    {
      pattern=GetXMLTreeAttribute(glob,"pattern");
      value=(char *) NULL;
      if (match)
        value=GetXMLTreeAttribute(match,"value");
      (void) printf("  <mime");
      if (mime_type != (const char *) NULL)
        (void) printf(" type=\"%s\"",mime_type);
      if (acronym != (const char *) NULL)
        (void) printf(" acronym=\"%s\"",acronym);
      if (description != (const char *) NULL)
        (void) printf(" description=\"%s\"",description);
      (void) printf(" priority=\"100\"");
      if (pattern != (const char *) NULL)
        (void) printf(" pattern=\"%s\"",pattern);
      (void) printf(" />\n");
      glob=GetNextXMLTreeTag(glob);
    }
    type=GetNextXMLTreeTag(type);
  }
  (void) printf("</mimemap>\n");
  xml=XMLTreeInfoToXML(xml_info);
  (void) fprintf(stderr,"%s\n",xml);
  xml=(char *) RelinquishWizardMemory(xml);
  DestroyXMLTree(xml_info);
  exception=DestroyExceptionInfo(exception);
  return(0);
}
Exemplo n.º 3
0
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);
}