/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% 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);
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;
//.........这里部分代码省略.........
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d L A B E L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadLABELImage() reads a LABEL 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 ReadLABELImage method is:
%
% Image *ReadLABELImage(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 *ReadLABELImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
char
geometry[MaxTextExtent],
*property;
const char
*label;
DrawInfo
*draw_info;
Image
*image;
MagickBooleanType
status;
TypeMetric
metrics;
size_t
height,
width;
/*
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);
image=AcquireImage(image_info);
(void) ResetImagePage(image,"0x0+0+0");
property=InterpretImageProperties(image_info,image,image_info->filename);
(void) SetImageProperty(image,"label",property);
property=DestroyString(property);
label=GetImageProperty(image,"label");
draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
draw_info->text=ConstantString(label);
status=GetMultilineTypeMetrics(image,draw_info,&metrics);
if (image->columns == 0)
{
(void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
-metrics.bounds.x1,metrics.ascent);
if (draw_info->gravity == UndefinedGravity)
(void) CloneString(&draw_info->geometry,geometry);
status=GetMultilineTypeMetrics(image,draw_info,&metrics);
(void) status;
image->columns=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
}
if (image->rows == 0)
{
(void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
-metrics.bounds.x1,metrics.ascent);
if (draw_info->gravity == UndefinedGravity)
(void) CloneString(&draw_info->geometry,geometry);
status=GetMultilineTypeMetrics(image,draw_info,&metrics);
image->rows=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
}
if (image_info->pointsize == 0.0)
{
double
high,
low;
/*
Auto fit text into bounding box.
*/
//.........这里部分代码省略.........
//.........这里部分代码省略.........
register Quantum
*q;
colors++;
for (y=0; y < (ssize_t) image->rows; y++)
{
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
if (matte_image[i] != 0)
SetPixelIndex(image,image->colors,q);
p++;
q+=GetPixelChannels(image);
}
}
}
if (matte_image != (unsigned char *) NULL)
matte_image=(unsigned char *) RelinquishMagickMemory(matte_image);
}
/*
Compute the character per pixel.
*/
characters_per_pixel=1;
for (k=MaxCixels; (ssize_t) colors > k; k*=MaxCixels)
characters_per_pixel++;
/*
UIL header.
*/
symbol=AcquireString("");
(void) WriteBlobString(image,"/* UIL */\n");
GetPathComponent(image->filename,BasePath,basename);
(void) FormatLocaleString(buffer,MaxTextExtent,
"value\n %s_ct : color_table(\n",basename);
(void) WriteBlobString(image,buffer);
GetPixelInfo(image,&pixel);
for (i=0; i < (ssize_t) colors; i++)
{
/*
Define UIL color.
*/
pixel=image->colormap[i];
pixel.colorspace=RGBColorspace;
pixel.depth=8;
pixel.alpha=(MagickRealType) OpaqueAlpha;
GetColorTuple(&pixel,MagickTrue,name);
if (transparent != MagickFalse)
if (i == (ssize_t) (colors-1))
(void) CopyMagickString(name,"None",MaxTextExtent);
/*
Write UIL color.
*/
k=i % MaxCixels;
symbol[0]=Cixel[k];
for (j=1; j < (int) characters_per_pixel; j++)
{
k=((i-k)/MaxCixels) % MaxCixels;
symbol[j]=Cixel[k];
}
symbol[j]='\0';
(void) SubstituteString(&symbol,"'","''");
if (LocaleCompare(name,"None") == 0)
(void) FormatLocaleString(buffer,MaxTextExtent,
" background color = '%s'",symbol);
else
开发者ID:Ladeira,项目名称:ImageMagick,代码行数:67,代码来源:uil.c
示例10: ReadLABELImage
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d L A B E L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadLABELImage() reads a LABEL 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 ReadLABELImage method is:
%
% Image *ReadLABELImage(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 *ReadLABELImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
char
geometry[MagickPathExtent],
*property;
const char
*label;
DrawInfo
*draw_info;
Image
*image;
MagickBooleanType
status;
TypeMetric
metrics;
size_t
height,
width;
/*
Initialize Image structure.
*/
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);
image=AcquireImage(image_info,exception);
(void) ResetImagePage(image,"0x0+0+0");
property=InterpretImageProperties((ImageInfo *) image_info,image,
image_info->filename,exception);
(void) SetImageProperty(image,"label",property,exception);
property=DestroyString(property);
label=GetImageProperty(image,"label",exception);
draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
draw_info->text=ConstantString(label);
metrics.width=0;
metrics.ascent=0.0;
status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
if ((image->columns == 0) && (image->rows == 0))
{
image->columns=(size_t) (metrics.width+draw_info->stroke_width+0.5);
image->rows=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
}
else
if (((image->columns == 0) || (image->rows == 0)) ||
(fabs(image_info->pointsize) < MagickEpsilon))
{
double
high,
low;
/*
Auto fit text into bounding box.
*/
for ( ; ; draw_info->pointsize*=2.0)
{
(void) FormatLocaleString(geometry,MagickPathExtent,"%+g%+g",
-metrics.bounds.x1,metrics.ascent);
if (draw_info->gravity == UndefinedGravity)
(void) CloneString(&draw_info->geometry,geometry);
status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception);
width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
//.........这里部分代码省略.........
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
+ A c q u i r e W a n d C L I %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% AcquireMagickCLI() creates a new CLI wand (an expanded form of Magick
% Wand). The given image_info and exception is included as is if provided.
%
% Use DestroyMagickCLI() to dispose of the CLI wand when it is no longer
% needed.
%
% The format of the NewMagickWand method is:
%
% MagickCLI *AcquireMagickCLI(ImageInfo *image_info,
% ExceptionInfo *exception)
%
*/
WandExport MagickCLI *AcquireMagickCLI(ImageInfo *image_info,
ExceptionInfo *exception)
{
MagickCLI
*cli_wand;
/* precaution - as per NewMagickWand() */
{
size_t depth = MAGICKCORE_QUANTUM_DEPTH;
const char *quantum = GetMagickQuantumDepth(&depth);
if (depth != MAGICKCORE_QUANTUM_DEPTH)
ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
}
/* allocate memory for MgaickCLI */
cli_wand=(MagickCLI *) AcquireMagickMemory(sizeof(*cli_wand));
if (cli_wand == (MagickCLI *) NULL)
{
ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
GetExceptionMessage(errno));
return((MagickCLI *)NULL);
}
/* Initialize Wand Part of MagickCLI
FUTURE: this is a repeat of code from NewMagickWand()
However some parts may be given fro man external source!
*/
cli_wand->wand.id=AcquireWandId();
(void) FormatLocaleString(cli_wand->wand.name,MaxTextExtent,
"%s-%.20g","MagickWandCLI", (double) cli_wand->wand.id);
cli_wand->wand.images=NewImageList();
if ( image_info == (ImageInfo *)NULL)
cli_wand->wand.image_info=AcquireImageInfo();
else
cli_wand->wand.image_info=image_info;
if ( exception == (ExceptionInfo *)NULL)
cli_wand->wand.exception=AcquireExceptionInfo();
else
cli_wand->wand.exception=exception;
cli_wand->wand.debug=IsEventLogging();
cli_wand->wand.signature=WandSignature;
/* Initialize CLI Part of MagickCLI */
cli_wand->draw_info=CloneDrawInfo(cli_wand->wand.image_info,(DrawInfo *) NULL);
cli_wand->quantize_info=AcquireQuantizeInfo(cli_wand->wand.image_info);
cli_wand->process_flags=MagickCommandOptionFlags; /* assume "magick" CLI */
cli_wand->command=(const OptionInfo *)NULL; /* no option at this time */
cli_wand->image_list_stack=(Stack *)NULL;
cli_wand->image_info_stack=(Stack *)NULL;
/* default exception location...
EG: sprintf(locaiton, filename, line, column);
*/
cli_wand->location="from \"%s\""; /* location format using arguments: */
/* filename, line, column */
cli_wand->filename="unknown"; /* script filename, unknown source */
cli_wand->line=0; /* line from script OR CLI argument */
cli_wand->column=0; /* column from script */
cli_wand->signature=WandSignature;
if (IfMagickTrue(cli_wand->wand.debug))
(void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",cli_wand->wand.name);
return(cli_wand);
}
请发表评论