本文整理汇总了C++中DestroyImageInfo函数的典型用法代码示例。如果您正苦于以下问题:C++ DestroyImageInfo函数的具体用法?C++ DestroyImageInfo怎么用?C++ DestroyImageInfo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DestroyImageInfo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GlobExpression
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% G l o b E x p r e s s i o n %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% GlobExpression() returns MagickTrue if the expression matches the pattern.
%
% The format of the GlobExpression function is:
%
% MagickBooleanType GlobExpression(const char *expression,
% const char *pattern)
%
% A description of each parameter follows:
%
% o expression: Specifies a pointer to a text string containing a file name.
%
% o pattern: Specifies a pointer to a text string containing a pattern.
%
%
*/
MagickExport MagickBooleanType GlobExpression(const char *expression,
const char *pattern)
{
MagickBooleanType
done;
register const char
*p;
/*
Return on empty pattern or '*'.
*/
if (pattern == (char *) NULL)
return(MagickTrue);
if (*pattern == '\0')
return(MagickTrue);
if (LocaleCompare(pattern,"*") == 0)
return(MagickTrue);
p=pattern+strlen(pattern)-1;
if ((*p == ']') && (strchr(pattern,'[') != (char *) NULL))
{
ExceptionInfo
exception;
ImageInfo
*image_info;
/*
Determine if pattern is a scene, i.e. img0001.pcd[2].
*/
image_info=CloneImageInfo((ImageInfo *) NULL);
(void) CopyMagickString(image_info->filename,pattern,MaxTextExtent);
GetExceptionInfo(&exception);
(void) SetImageInfo(image_info,MagickTrue,&exception);
DestroyExceptionInfo(&exception);
if (LocaleCompare(image_info->filename,pattern) != 0)
{
image_info=DestroyImageInfo(image_info);
return(MagickFalse);
}
image_info=DestroyImageInfo(image_info);
}
/*
Evaluate glob expression.
*/
done=MagickFalse;
while ((*pattern != '\0') && (done == MagickFalse))
{
if (*expression == '\0')
if ((*pattern != '{') && (*pattern != '*'))
break;
switch (*pattern)
{
case '\\':
{
pattern++;
if (*pattern != '\0')
pattern++;
break;
}
case '*':
{
MagickBooleanType
status;
pattern++;
status=MagickFalse;
while ((*expression != '\0') && (status == MagickFalse))
status=GlobExpression(expression++,pattern);
if (status != MagickFalse)
{
while (*expression != '\0')
expression++;
while (*pattern != '\0')
//.........这里部分代码省略.........
示例2: IdentifyImageCommand
//.........这里部分代码省略.........
if (LocaleCompare(option,")") == 0)
{
FireImageStack(MagickFalse,MagickTrue,MagickTrue);
if (k == 0)
ThrowIdentifyException(OptionError,"UnableToParseExpression",option);
PopImageStack();
continue;
}
if (IsMagickOption(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 < (argc-1)))
filename=argv[++i];
(void) CopyMagickString(identify_info->filename,filename,MaxTextExtent);
if (identify_info->ping != MagickFalse)
images=PingImages(identify_info,exception);
else
images=ReadImages(identify_info,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);
continue;
}
if (metadata != (char **) NULL)
{
char
*text;
text=InterpretImageProperties(image_info,image,format);
if (text == (char *) NULL)
ThrowIdentifyException(ResourceLimitError,
"MemoryAllocationFailed",GetExceptionMessage(errno));
(void) ConcatenateString(&(*metadata),text);
text=DestroyString(text);
if (LocaleCompare(format,"%n") == 0)
break;
}
}
RemoveAllImageStack();
continue;
示例3: DestroyImageInfo
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d X T R N I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Method ReadXTRNImage reads a XTRN 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 ReadXTRNImage method is:
%
% Image *ReadXTRNImage(const ImageInfo *image_info,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o image: Method ReadXTRNImage returns a pointer to the image after
% reading. A null image is returned if there is a memory shortage or
% if the image cannot be read.
%
% o image_info: Specifies a pointer to an ImageInfo structure.
%
% o exception: return any errors or warnings in this structure.
%
%
*/
static Image *ReadXTRNImage(const ImageInfo *image_info, ExceptionInfo *exception)
{
Image
*image;
ImageInfo
*clone_info;
void
*param1,
*param2,
*param3;
param1 = param2 = param3 = (void *) NULL;
image = (Image *) NULL;
clone_info=CloneImageInfo(image_info);
if (clone_info->filename == NULL)
{
DestroyImageInfo(clone_info);
ThrowReaderException(OptionError,MissingAnImageFilename,image);
}
/* DebugString("ReadXTRN CODER: %s\n",clone_info->filename); */
if (LocaleCompare(image_info->magick,"XTRNFILE") == 0)
{
image=ReadImage(clone_info,exception);
/* this should not be needed since the upstream code should catch any
excetpions thrown by ReadImage
*/
if (exception->severity != UndefinedException)
MagickWarning2(exception->severity,exception->reason,exception->description);
}
else if (LocaleCompare(image_info->magick,"XTRNIMAGE") == 0)
{
Image
**image_ptr;
#ifdef ALL_IMAGEINFO
ImageInfo
**image_info_ptr;
#endif
(void) sscanf(clone_info->filename,"%lx,%lx",¶m1,¶m2);
image_ptr=(Image **) param2;
if (*image_ptr != (Image *)NULL)
image=CloneImage(*image_ptr,0,0,False,&(*image_ptr)->exception);
#ifdef ALL_IMAGEINFO
image_info_ptr=(ImageInfo **) param1;
if (*image_info_ptr != (ImageInfo *)NULL)
image_info=*image_info_ptr;
#endif
}
else if (LocaleCompare(image_info->magick,"XTRNBLOB") == 0)
{
char
**blob_data;
size_t
*blob_length;
char
filename[MaxTextExtent];
(void) sscanf(clone_info->filename,"%lx,%lx,%s",¶m1,¶m2,&filename);
blob_data=(char **) param1;
blob_length=(size_t *) param2;
image=BlobToImage(clone_info,*blob_data,*blob_length,exception);
if (exception->severity != UndefinedException)
MagickWarning2(exception->severity,exception->reason,exception->description);
//.........这里部分代码省略.........
示例4: ReadDOTImage
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d D O T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadDOTImage() reads a Graphviz 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 ReadDOTImage method is:
%
% Image *ReadDOTImage(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 *ReadDOTImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
char
command[MagickPathExtent];
const char
*option;
graph_t
*graph;
Image
*image;
ImageInfo
*read_info;
MagickBooleanType
status;
/*
Open image file.
*/
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickCoreSignature);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickCoreSignature);
assert(graphic_context != (GVC_t *) NULL);
image=AcquireImage(image_info,exception);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
return(DestroyImageList(image));
read_info=CloneImageInfo(image_info);
SetImageInfoBlob(read_info,(void *) NULL,0);
(void) CopyMagickString(read_info->magick,"SVG",MagickPathExtent);
(void) AcquireUniqueFilename(read_info->filename);
(void) FormatLocaleString(command,MagickPathExtent,"-Tsvg -o%s %s",
read_info->filename,image_info->filename);
#if !defined(WITH_CGRAPH)
graph=agread(GetBlobFileHandle(image));
#else
graph=agread(GetBlobFileHandle(image),(Agdisc_t *) NULL);
#endif
if (graph == (graph_t *) NULL)
{
(void) RelinquishUniqueFileResource(read_info->filename);
return(DestroyImageList(image));
}
option=GetImageOption(image_info,"dot:layout-engine");
if (option == (const char *) NULL)
gvLayout(graphic_context,graph,(char *) "dot");
else
gvLayout(graphic_context,graph,(char *) option);
gvRenderFilename(graphic_context,graph,(char *) "svg",read_info->filename);
gvFreeLayout(graphic_context,graph);
agclose(graph);
image=DestroyImageList(image);
/*
Read SVG graph.
*/
(void) CopyMagickString(read_info->magick,"SVG",MaxTextExtent);
image=ReadImage(read_info,exception);
(void) RelinquishUniqueFileResource(read_info->filename);
read_info=DestroyImageInfo(read_info);
if (image == (Image *) NULL)
return((Image *) NULL);
return(GetFirstImageInList(image));
}
示例5: ReadPWPImage
//.........这里部分代码省略.........
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);
pwp_image=AcquireImage(image_info);
image=pwp_image;
status=OpenBlob(image_info,pwp_image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
return((Image *) NULL);
count=ReadBlob(pwp_image,5,magick);
if ((count == 0) || (LocaleNCompare((char *) magick,"SFW95",5) != 0))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
read_info=CloneImageInfo(image_info);
(void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
(void *) NULL);
SetImageInfoBlob(read_info,(void *) NULL,0);
unique_file=AcquireUniqueFileResource(read_info->filename);
for ( ; ; )
{
for (c=ReadBlobByte(pwp_image); c != EOF; c=ReadBlobByte(pwp_image))
{
for (i=0; i < 17; i++)
magick[i]=magick[i+1];
magick[17]=(unsigned char) c;
if (LocaleNCompare((char *) (magick+12),"SFW94A",6) == 0)
break;
}
if (c == EOF)
break;
if (LocaleNCompare((char *) (magick+12),"SFW94A",6) != 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
/*
Dump SFW image to a temporary file.
*/
file=(FILE *) NULL;
if (unique_file != -1)
file=fdopen(unique_file,"wb");
if ((unique_file == -1) || (file == (FILE *) NULL))
{
ThrowFileException(exception,FileOpenError,"UnableToWriteFile",
image->filename);
image=DestroyImageList(image);
return((Image *) NULL);
}
length=fwrite("SFW94A",1,6,file);
(void) length;
filesize=65535UL*magick[2]+256L*magick[1]+magick[0];
for (i=0; i < (ssize_t) filesize; i++)
{
c=ReadBlobByte(pwp_image);
(void) fputc(c,file);
}
(void) fclose(file);
next_image=ReadImage(read_info,exception);
if (next_image == (Image *) NULL)
break;
(void) FormatLocaleString(next_image->filename,MaxTextExtent,
"slide_%02ld.sfw",(long) next_image->scene);
if (image == (Image *) NULL)
image=next_image;
else
{
/*
Link image into image list.
*/
for (p=image; p->next != (Image *) NULL; p=GetNextImageInList(p)) ;
next_image->previous=p;
next_image->scene=p->scene+1;
p->next=next_image;
}
if (image_info->number_scenes != 0)
if (next_image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
status=SetImageProgress(image,LoadImagesTag,TellBlob(pwp_image),
GetBlobSize(pwp_image));
if (status == MagickFalse)
break;
}
(void) RelinquishUniqueFileResource(read_info->filename);
read_info=DestroyImageInfo(read_info);
(void) CloseBlob(pwp_image);
pwp_image=DestroyImage(pwp_image);
if (EOFBlob(image) != MagickFalse)
{
char
*message;
message=GetExceptionMessage(errno);
(void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
"UnexpectedEndOfFile","`%s': %s",image->filename,message);
message=DestroyString(message);
}
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
示例6: GetBit
static Image *ReadSTEGANOImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
#define GetBit(alpha,i) MagickMin((((size_t) (alpha) >> (size_t) \
(i)) & 0x01),16)
#define SetBit(i,set) SetPixelIndex(image,((set) != 0 ? \
(size_t) GetPixelIndex(image,q) | (one << (size_t) (i)) : \
(size_t) GetPixelIndex(image,q) & ~(one << (size_t) (i))),q)
Image
*image,
*watermark;
ImageInfo
*read_info;
int
c;
MagickBooleanType
status;
PixelInfo
pixel;
register Quantum
*q;
register ssize_t
x;
size_t
depth,
one;
ssize_t
i,
j,
k,
y;
/*
Initialize Image structure.
*/
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);
one=1;
image=AcquireImage(image_info,exception);
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(OptionError,"MustSpecifyImageSize");
read_info=CloneImageInfo(image_info);
SetImageInfoBlob(read_info,(void *) NULL,0);
*read_info->magick='\0';
watermark=ReadImage(read_info,exception);
read_info=DestroyImageInfo(read_info);
if (watermark == (Image *) NULL)
return((Image *) NULL);
watermark->depth=MAGICKCORE_QUANTUM_DEPTH;
if (AcquireImageColormap(image,MaxColormapSize,exception) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
Get hidden watermark from low-order bits of image.
*/
c=0;
i=0;
j=0;
i=(ssize_t) (watermark->depth-1);
depth=watermark->depth;
for (k=image->offset; (i >= 0) && (j < (ssize_t) depth); i--)
{
for (y=0; (y < (ssize_t) image->rows) && (j < (ssize_t) depth); y++)
{
x=0;
for ( ; (x < (ssize_t) image->columns) && (j < (ssize_t) depth); x++)
{
if ((k/(ssize_t) watermark->columns) >= (ssize_t) watermark->rows)
break;
(void) GetOneVirtualPixelInfo(watermark,UndefinedVirtualPixelMethod,
k % (ssize_t) watermark->columns,k/(ssize_t) watermark->columns,
&pixel,exception);
q=GetAuthenticPixels(image,x,y,1,1,exception);
if (q == (Quantum *) NULL)
break;
switch (c)
{
case 0:
{
SetBit(i,GetBit(pixel.red,j));
break;
}
//.........这里部分代码省略.........
示例7: ReadDNGImage
//.........这里部分代码省略.........
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);
SetImageInfoBlob(read_info,(void *) NULL,0);
(void) InvokeDelegate(read_info,image,"dng:decode",(char *) NULL,exception);
image=DestroyImage(image);
(void) FormatLocaleString(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) FormatLocaleString(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) FormatLocaleString(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) FormatLocaleString(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);
}
示例8: WriteImages
//.........这里部分代码省略.........
MagickExport MagickBooleanType WriteImages(const ImageInfo *image_info,
Image *images,const char *filename,ExceptionInfo *exception)
{
#define WriteImageTag "Write/Image"
ExceptionInfo
*sans_exception;
ImageInfo
*write_info;
MagickBooleanType
proceed;
MagickOffsetType
progress;
MagickProgressMonitor
progress_monitor;
MagickSizeType
number_images;
MagickStatusType
status;
register Image
*p;
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickCoreSignature);
assert(images != (Image *) NULL);
assert(images->signature == MagickCoreSignature);
if (images->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
assert(exception != (ExceptionInfo *) NULL);
write_info=CloneImageInfo(image_info);
*write_info->magick='\0';
images=GetFirstImageInList(images);
if (filename != (const char *) NULL)
for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
(void) CopyMagickString(p->filename,filename,MagickPathExtent);
(void) CopyMagickString(write_info->filename,images->filename,
MagickPathExtent);
sans_exception=AcquireExceptionInfo();
(void) SetImageInfo(write_info,(unsigned int) GetImageListLength(images),
sans_exception);
sans_exception=DestroyExceptionInfo(sans_exception);
if (*write_info->magick == '\0')
(void) CopyMagickString(write_info->magick,images->magick,MagickPathExtent);
p=images;
for ( ; GetNextImageInList(p) != (Image *) NULL; p=GetNextImageInList(p))
{
register Image
*next;
next=GetNextImageInList(p);
if (next == (Image *) NULL)
break;
if (p->scene >= next->scene)
{
register ssize_t
i;
/*
Generate consistent scene numbers.
*/
i=(ssize_t) images->scene;
for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
p->scene=(size_t) i++;
break;
}
}
/*
Write images.
*/
status=MagickTrue;
progress_monitor=(MagickProgressMonitor) NULL;
progress=0;
number_images=GetImageListLength(images);
for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
{
if (number_images != 1)
progress_monitor=SetImageProgressMonitor(p,(MagickProgressMonitor) NULL,
p->client_data);
status&=WriteImage(write_info,p,exception);
if (number_images != 1)
(void) SetImageProgressMonitor(p,progress_monitor,p->client_data);
if (write_info->adjoin != MagickFalse)
break;
if (number_images != 1)
{
proceed=SetImageProgress(p,WriteImageTag,progress++,number_images);
if (proceed == MagickFalse)
break;
}
}
write_info=DestroyImageInfo(write_info);
return(status != 0 ? MagickTrue : MagickFalse);
}
示例9: ReadImage
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadImage() reads an image or image sequence from a file or file handle.
% The method returns a NULL if there is a memory shortage or if the image
% cannot be read. On failure, a NULL image is returned and exception
% describes the reason for the failure.
%
% The format of the ReadImage method is:
%
% Image *ReadImage(const ImageInfo *image_info,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o image_info: Read the image defined by the file or filename members of
% this structure.
%
% o exception: return any errors or warnings in this structure.
%
*/
MagickExport Image *ReadImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
char
filename[MagickPathExtent],
magick[MagickPathExtent],
magick_filename[MagickPathExtent];
const char
*value;
const DelegateInfo
*delegate_info;
const MagickInfo
*magick_info;
ExceptionInfo
*sans_exception;
GeometryInfo
geometry_info;
Image
*image,
*next;
ImageInfo
*read_info;
MagickStatusType
flags;
PolicyDomain
domain;
PolicyRights
rights;
/*
Determine image type from filename prefix or suffix (e.g. image.jpg).
*/
assert(image_info != (ImageInfo *) NULL);
assert(image_info->signature == MagickCoreSignature);
assert(image_info->filename != (char *) NULL);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
assert(exception != (ExceptionInfo *) NULL);
read_info=CloneImageInfo(image_info);
(void) CopyMagickString(magick_filename,read_info->filename,MagickPathExtent);
(void) SetImageInfo(read_info,0,exception);
(void) CopyMagickString(filename,read_info->filename,MagickPathExtent);
(void) CopyMagickString(magick,read_info->magick,MagickPathExtent);
domain=CoderPolicyDomain;
rights=ReadPolicyRights;
if (IsRightsAuthorized(domain,rights,read_info->magick) == MagickFalse)
{
errno=EPERM;
(void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
"NotAuthorized","`%s'",read_info->filename);
read_info=DestroyImageInfo(read_info);
return((Image *) NULL);
}
/*
Call appropriate image reader based on image type.
*/
sans_exception=AcquireExceptionInfo();
magick_info=GetMagickInfo(read_info->magick,sans_exception);
sans_exception=DestroyExceptionInfo(sans_exception);
if (magick_info != (const MagickInfo *) NULL)
{
//.........这里部分代码省略.........
示例10: int_imread
/*----------------------------------------------------------
* int_imread:
* interface for imread function.
* should provide [RGB]=imread(name)
* [Index,Map]=imread(name) at Scilab level
*
* TO-DO
* - return on errors, even if exeption is NULL
*
* $Revision: 1.2 $ $Date: 2009-03-29 21:34:48 $
*----------------------------------------------------------*/
SipExport int
int_imread(char *fname)
{
/* Interface variables */
HyperMat *Img;
int m1, n1,l1, /* for name input argument */
m2, n2, /* for index output argument */
minlhs=1, maxlhs=2, minrhs=1, maxrhs=1, i;
double *l2;
/* Other variables */
unsigned long imgsize;
/* ImageMagick variables */
ExceptionInfo exception;
Image *image;
ImageInfo *image_info;
PixelPacket *pix;
ImageType imgtype;
bool stat;
CheckRhs(minrhs,maxrhs) ;
CheckLhs(minlhs,maxlhs) ;
/* Get name (#1) */
GetRhsVar(1, "c", &m1, &n1, &l1);
/* Initialize the image info structure and read an image. */
InitializeMagick(NULL);
GetExceptionInfo(&exception);
image_info=CloneImageInfo((ImageInfo *) NULL);
(void) strncpy(image_info->filename,cstk(l1),MaxTextExtent);
image=ReadImage(image_info,&exception);
if (image == (Image *) NULL) {
/* clean up */
if(exception.reason != NULL) {
char errmsg[50];
for (i=0; i<49; i++)
errmsg[i]=' ';
errmsg[49]='\0';
strncpy(errmsg,SipGetLocaleExceptionMessage(exception.severity,exception.reason),50);
DestroyImageInfo(image_info);
DestroyExceptionInfo(&exception);
DestroyMagick();
sip_error(errmsg);
}
DestroyImageInfo(image_info);
DestroyExceptionInfo(&exception);
DestroyMagick();
sip_error("unknown reason");
}
m2 = image->rows; n2 = image->columns;
if (sip_verbose == SIP_WORDY)
sciprint("Size:\t%ld rows X %ld columns\n\r", m2, n2);
imgsize = m2 * n2;
pix=GetImagePixels(image, 0, 0, n2, m2);
if(pix == (PixelPacket *) NULL)
SIP_MAGICK_ERROR;
switch(image->storage_class) {
case DirectClass: {
imgtype = GetImageType(image, &exception);
if(imgtype == BilevelType) {
stat = magick_binary_image_to_double_array(fname,pix,&l2, m2, n2);
if (!stat) return false;
CreateVarFromPtr(2, "d",&m2,&n2,&l2);
free(l2);
} else {
stat= magick_truecolor_image_to_double_hypermat(fname,pix,&Img,m2,n2);
if (!stat) return false;
CreateHMat(2,Img);
free_sci_tru_img(&Img);
}
m1 = n1 = 0;
CreateVar(3,"d",&m1,&n1,&l1);
break;
}
case PseudoClass: {
stat= magick_index_map_to_sci_dbl(fname,image,2);
//.........这里部分代码省略.........
示例11: ReadTEXTImage
//.........这里部分代码省略.........
image->resolution.y=geometry_info.sigma;
if ((flags & SigmaValue) == 0)
image->resolution.y=image->resolution.x;
}
page.width=612;
page.height=792;
page.x=43;
page.y=43;
if (image_info->page != (char *) NULL)
(void) ParseAbsoluteGeometry(image_info->page,&page);
/*
Initialize Image structure.
*/
image->columns=(size_t) floor((((double) page.width*image->resolution.x)/
delta.x)+0.5);
image->rows=(size_t) floor((((double) page.height*image->resolution.y)/
delta.y)+0.5);
status=SetImageExtent(image,image->columns,image->rows,exception);
if (status == MagickFalse)
return(DestroyImageList(image));
image->page.x=0;
image->page.y=0;
texture=(Image *) NULL;
if (image_info->texture != (char *) NULL)
{
ImageInfo
*read_info;
read_info=CloneImageInfo(image_info);
SetImageInfoBlob(read_info,(void *) NULL,0);
(void) CopyMagickString(read_info->filename,image_info->texture,
MagickPathExtent);
texture=ReadImage(read_info,exception);
read_info=DestroyImageInfo(read_info);
}
/*
Annotate the text image.
*/
(void) SetImageBackgroundColor(image,exception);
draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
(void) CloneString(&draw_info->text,image_info->filename);
(void) FormatLocaleString(geometry,MagickPathExtent,"%gx%g%+g%+g",(double)
image->columns,(double) image->rows,(double) page.x,(double) page.y);
(void) CloneString(&draw_info->geometry,geometry);
status=GetTypeMetrics(image,draw_info,&metrics,exception);
if (status == MagickFalse)
ThrowReaderException(TypeError,"UnableToGetTypeMetrics");
page.y=(ssize_t) ceil((double) page.y+metrics.ascent-0.5);
(void) FormatLocaleString(geometry,MagickPathExtent,"%gx%g%+g%+g",(double)
image->columns,(double) image->rows,(double) page.x,(double) page.y);
(void) CloneString(&draw_info->geometry,geometry);
(void) CopyMagickString(filename,image_info->filename,MagickPathExtent);
if (*draw_info->text != '\0')
*draw_info->text='\0';
p=text;
for (offset=2*page.y; p != (char *) NULL; )
{
/*
Annotate image with text.
*/
(void) ConcatenateString(&draw_info->text,text);
(void) ConcatenateString(&draw_info->text,"\n");
offset+=(ssize_t) (metrics.ascent-metrics.descent);
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) offset,
示例12: assert
//.........这里部分代码省略.........
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
count=ReadBlob(image,(size_t) GetBlobSize(image),buffer);
if ((count == 0) || (LocaleNCompare((char *) buffer,"SFW",3) != 0))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
(void) CloseBlob(image);
image=DestroyImage(image);
/*
Find the start of the JFIF data
*/
header=SFWScan(buffer,buffer+count-1,(const unsigned char *)
"\377\310\377\320",4);
if (header == (unsigned char *) NULL)
{
buffer=(unsigned char *) RelinquishMagickMemory(buffer);
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
}
TranslateSFWMarker(header); /* translate soi and app tags */
TranslateSFWMarker(header+2);
(void) CopyMagickMemory(header+6,"JFIF\0\001\0",7); /* JFIF magic */
/*
Translate remaining markers.
*/
offset=header+2;
offset+=(offset[2] << 8)+offset[3]+2;
for ( ; ; )
{
TranslateSFWMarker(offset);
if (offset[1] == 0xda)
break;
offset+=(offset[2] << 8)+offset[3]+2;
}
offset--;
data=SFWScan(offset,buffer+count-1,(const unsigned char *) "\377\311",2);
if (data == (unsigned char *) NULL)
{
buffer=(unsigned char *) RelinquishMagickMemory(buffer);
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
}
TranslateSFWMarker(data++); /* translate eoi marker */
/*
Write JFIF file.
*/
read_info=CloneImageInfo(image_info);
read_info->blob=(void *) NULL;
read_info->length=0;
file=(FILE *) NULL;
unique_file=AcquireUniqueFileResource(read_info->filename);
if (unique_file != -1)
file=OpenMagickStream(read_info->filename,"wb");
if ((unique_file == -1) || (file == (FILE *) NULL))
{
buffer=(unsigned char *) RelinquishMagickMemory(buffer);
read_info=DestroyImageInfo(read_info);
(void) CopyMagickString(image->filename,read_info->filename,
MaxTextExtent);
ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
image->filename);
image=DestroyImageList(image);
return((Image *) NULL);
}
extent=fwrite(header,(size_t) (offset-header+1),1,file);
extent=fwrite(HuffmanTable,1,sizeof(HuffmanTable)/sizeof(*HuffmanTable),file);
extent=fwrite(offset+1,(size_t) (data-offset),1,file);
status=ferror(file) == -1 ? MagickFalse : MagickTrue;
(void) fclose(file);
buffer=(unsigned char *) RelinquishMagickMemory(buffer);
if (status == MagickFalse)
{
char
*message;
(void) remove(read_info->filename);
read_info=DestroyImageInfo(read_info);
message=GetExceptionMessage(errno);
(void) ThrowMagickException(&image->exception,GetMagickModule(),
FileOpenError,"UnableToWriteFile","`%s': %s",image->filename,message);
message=DestroyString(message);
image=DestroyImageList(image);
return((Image *) NULL);
}
/*
Read JPEG image.
*/
image=ReadImage(read_info,exception);
(void) RelinquishUniqueFileResource(read_info->filename);
read_info=DestroyImageInfo(read_info);
if (image == (Image *) NULL)
return(GetFirstImageInList(image));
/*
Correct image orientation.
*/
flipped_image=FlipImage(image,exception);
if (flipped_image != (Image *) NULL)
{
DuplicateBlob(flipped_image,image);
image=DestroyImage(image);
image=flipped_image;
}
return(GetFirstImageInList(image));
}
示例13: dt_imageio_large_thumbnail
// load a full-res thumbnail:
int dt_imageio_large_thumbnail(const char *filename, uint8_t **buffer, int32_t *width, int32_t *height,
dt_colorspaces_color_profile_type_t *color_space)
{
int res = 1;
uint8_t *buf = NULL;
char *mime_type = NULL;
size_t bufsize;
// get the biggest thumb from exif
if(dt_exif_get_thumbnail(filename, &buf, &bufsize, &mime_type)) goto error;
if(strcmp(mime_type, "image/jpeg") == 0)
{
// Decompress the JPG into our own memory format
dt_imageio_jpeg_t jpg;
if(dt_imageio_jpeg_decompress_header(buf, bufsize, &jpg)) goto error;
*buffer = (uint8_t *)malloc((size_t)sizeof(uint8_t) * jpg.width * jpg.height * 4);
if(!*buffer) goto error;
*width = jpg.width;
*height = jpg.height;
// TODO: check if the embedded thumbs have a color space set! currently we assume that it's always sRGB
*color_space = DT_COLORSPACE_SRGB;
if(dt_imageio_jpeg_decompress(&jpg, *buffer))
{
free(*buffer);
*buffer = NULL;
goto error;
}
res = 0;
}
else
{
#ifdef HAVE_GRAPHICSMAGICK
ExceptionInfo exception;
Image *image = NULL;
ImageInfo *image_info = NULL;
GetExceptionInfo(&exception);
image_info = CloneImageInfo((ImageInfo *)NULL);
image = BlobToImage(image_info, buf, bufsize, &exception);
if(exception.severity != UndefinedException) CatchException(&exception);
if(!image)
{
fprintf(stderr, "[dt_imageio_large_thumbnail GM] thumbnail not found?\n");
goto error_gm;
}
*width = image->columns;
*height = image->rows;
*color_space = DT_COLORSPACE_SRGB; // FIXME: this assumes that embedded thumbnails are always srgb
*buffer = (uint8_t *)malloc((size_t)sizeof(uint8_t) * image->columns * image->rows * 4);
if(!*buffer) goto error_gm;
for(uint32_t row = 0; row < image->rows; row++)
{
uint8_t *bufprt = *buffer + (size_t)4 * row * image->columns;
int gm_ret = DispatchImage(image, 0, row, image->columns, 1, "RGBP", CharPixel, bufprt, &exception);
if(exception.severity != UndefinedException) CatchException(&exception);
if(gm_ret != MagickPass)
{
fprintf(stderr, "[dt_imageio_large_thumbnail GM] error_gm reading thumbnail\n");
free(*buffer);
*buffer = NULL;
goto error_gm;
}
}
// fprintf(stderr, "[dt_imageio_large_thumbnail GM] successfully decoded thumbnail\n");
res = 0;
error_gm:
if(image) DestroyImage(image);
if(image_info) DestroyImageInfo(image_info);
DestroyExceptionInfo(&exception);
if(res) goto error;
#else
fprintf(stderr, "[dt_imageio_large_thumbnail] error: The thumbnail image is not in JPEG format, but DT "
"was built without GraphicsMagick. Please rebuild DT with GraphicsMagick support "
"enabled.\n");
#endif
}
if(res)
{
fprintf(
stderr,
"[dt_imageio_large_thumbnail] error: Not a supported thumbnail image format or broken thumbnail: %s\n",
mime_type);
goto error;
}
//.........这里部分代码省略.........
示例14: WriteINLINEImage
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e I N L I N E I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteINLINEImage() writes an image to a file in INLINE format (Base64).
%
% The format of the WriteINLINEImage method is:
%
% MagickBooleanType WriteINLINEImage(const ImageInfo *image_info,
% Image *image,ExceptionInfo *exception)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
% o exception: return any errors or warnings in this structure.
%
*/
static MagickBooleanType WriteINLINEImage(const ImageInfo *image_info,
Image *image,ExceptionInfo *exception)
{
char
*base64,
message[MagickPathExtent];
const MagickInfo
*magick_info;
Image
*write_image;
ImageInfo
*write_info;
MagickBooleanType
status;
size_t
blob_length,
encode_length;
unsigned char
*blob;
/*
Convert image to base64-encoding.
*/
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickCoreSignature);
assert(image != (Image *) NULL);
assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
write_info=CloneImageInfo(image_info);
(void) SetImageInfo(write_info,1,exception);
if (LocaleCompare(write_info->magick,"INLINE") == 0)
(void) CopyMagickString(write_info->magick,image->magick,MagickPathExtent);
magick_info=GetMagickInfo(write_info->magick,exception);
if ((magick_info == (const MagickInfo *) NULL) ||
(GetMagickMimeType(magick_info) == (const char *) NULL))
ThrowWriterException(CorruptImageError,"ImageTypeNotSupported");
(void) CopyMagickString(image->filename,write_info->filename,
MagickPathExtent);
blob_length=2048;
write_image=CloneImage(image,0,0,MagickTrue,exception);
if (write_image == (Image *) NULL)
{
write_info=DestroyImageInfo(write_info);
return(MagickTrue);
}
blob=(unsigned char *) ImageToBlob(write_info,write_image,&blob_length,
exception);
write_image=DestroyImage(write_image);
write_info=DestroyImageInfo(write_info);
if (blob == (unsigned char *) NULL)
return(MagickFalse);
encode_length=0;
base64=Base64Encode(blob,blob_length,&encode_length);
blob=(unsigned char *) RelinquishMagickMemory(blob);
if (base64 == (char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
/*
Write base64-encoded image.
*/
status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
if (status == MagickFalse)
{
base64=DestroyString(base64);
return(status);
}
(void) FormatLocaleString(message,MagickPathExtent,"data:%s;base64,",
//.........这里部分代码省略.........
示例15: ReadImages
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d I m a g e s %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadImages() reads one or more images and returns them as an image list.
%
% The format of the ReadImage method is:
%
% Image *ReadImages(ImageInfo *image_info,const char *filename,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o image_info: the image info.
%
% o filename: the image filename.
%
% o exception: return any errors or warnings in this structure.
%
*/
MagickExport Image *ReadImages(ImageInfo *image_info,const char *filename,
ExceptionInfo *exception)
{
char
read_filename[MagickPathExtent];
Image
*image,
*images;
ImageInfo
*read_info;
/*
Read image list from a file.
*/
assert(image_info != (ImageInfo *) NULL);
assert(image_info->signature == MagickCoreSignature);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
image_info->filename);
assert(exception != (ExceptionInfo *) NULL);
read_info=CloneImageInfo(image_info);
*read_info->magick='\0';
(void) SetImageOption(read_info,"filename",filename);
(void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
(void) InterpretImageFilename(read_info,(Image *) NULL,filename,
(int) read_info->scene,read_filename,exception);
if (LocaleCompare(read_filename,read_info->filename) != 0)
{
ExceptionInfo
*sans;
ssize_t
extent,
scene;
/*
Images of the form image-%d.png[1-5].
*/
sans=AcquireExceptionInfo();
(void) SetImageInfo(read_info,0,sans);
sans=DestroyExceptionInfo(sans);
if (read_info->number_scenes == 0)
{
read_info=DestroyImageInfo(read_info);
return(ReadImage(image_info,exception));
}
(void) CopyMagickString(read_filename,read_info->filename,MagickPathExtent);
images=NewImageList();
extent=(ssize_t) (read_info->scene+read_info->number_scenes);
for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++)
{
(void) InterpretImageFilename(image_info,(Image *) NULL,read_filename,
(int) scene,read_info->filename,exception);
image=ReadImage(read_info,exception);
if (image == (Image *) NULL)
continue;
AppendImageToList(&images,image);
}
read_info=DestroyImageInfo(read_info);
return(images);
}
image=ReadImage(read_info,exception);
read_info=DestroyImageInfo(read_info);
return(image);
}