% Render Text Onto A Canvas Image. %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% July 1992 %
% %
% %
-% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
% obtain a copy of the License at %
% %
-% http://www.imagemagick.org/script/license.php %
+% https://www.imagemagick.org/script/license.php %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
#define MagickID "# ImageMagick pixel enumeration:"
char
- colorspace[MaxTextExtent];
+ colorspace[MagickPathExtent];
ssize_t
count;
return(MagickFalse);
if (LocaleNCompare((const char *) magick,MagickID,strlen(MagickID)) != 0)
return(MagickFalse);
- count=(ssize_t) sscanf((const char *) magick+32,"%lu,%lu,%lu,%s",&columns,
+ count=(ssize_t) sscanf((const char *) magick+32,"%lu,%lu,%lu,%32s",&columns,
&rows,&depth,colorspace);
if (count != 4)
return(MagickFalse);
% o exception: return any errors or warnings in this structure.
%
*/
-static Image *ReadTEXTImage(const ImageInfo *image_info,Image *image,
- char *text,ExceptionInfo *exception)
+static Image *ReadTEXTImage(const ImageInfo *image_info,
+ ExceptionInfo *exception)
{
char
- filename[MaxTextExtent],
- geometry[MaxTextExtent],
- *p;
+ filename[MagickPathExtent],
+ geometry[MagickPathExtent],
+ *p,
+ text[MagickPathExtent];
DrawInfo
*draw_info;
Image
+ *image,
*texture;
MagickBooleanType
Open image file.
*/
assert(image_info != (const ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ 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 == MagickSignature);
+ assert(exception->signature == MagickCoreSignature);
+ image=AcquireImage(image_info,exception);
+ status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
+ if (status == MagickFalse)
+ {
+ image=DestroyImageList(image);
+ return((Image *) NULL);
+ }
+ (void) ResetMagickMemory(text,0,sizeof(text));
+ (void) ReadBlobString(image,text);
/*
Set the page geometry.
*/
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;
read_info=CloneImageInfo(image_info);
SetImageInfoBlob(read_info,(void *) NULL,0);
(void) CopyMagickString(read_info->filename,image_info->texture,
- MaxTextExtent);
+ MagickPathExtent);
texture=ReadImage(read_info,exception);
read_info=DestroyImageInfo(read_info);
}
(void) SetImageBackgroundColor(image,exception);
draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
(void) CloneString(&draw_info->text,image_info->filename);
- (void) FormatLocaleString(geometry,MaxTextExtent,"0x0%+ld%+ld",(long) page.x,
- (long) page.y);
+ (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,MaxTextExtent,"0x0%+ld%+ld",(long) page.x,
- (long) page.y);
+ (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,MaxTextExtent);
+ (void) CopyMagickString(filename,image_info->filename,MagickPathExtent);
if (*draw_info->text != '\0')
*draw_info->text='\0';
p=text;
offset+=(ssize_t) (metrics.ascent-metrics.descent);
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,LoadImageTag,offset,image->rows);
+ status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) offset,
+ image->rows);
if (status == MagickFalse)
break;
}
image->next->columns=image->columns;
image->next->rows=image->rows;
image=SyncNextImageInList(image);
- (void) CopyMagickString(image->filename,filename,MaxTextExtent);
+ (void) CopyMagickString(image->filename,filename,MagickPathExtent);
(void) SetImageBackgroundColor(image,exception);
status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
GetBlobSize(image));
static Image *ReadTXTImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
char
- colorspace[MaxTextExtent],
- text[MaxTextExtent];
+ colorspace[MagickPathExtent],
+ text[MagickPathExtent];
Image
*image;
long
- type,
x_offset,
- y,
y_offset;
PixelInfo
*q;
ssize_t
- count;
+ count,
+ type,
+ y;
unsigned long
depth,
Open image file.
*/
assert(image_info != (const ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ 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 == MagickSignature);
+ assert(exception->signature == MagickCoreSignature);
image=AcquireImage(image_info,exception);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
(void) ResetMagickMemory(text,0,sizeof(text));
(void) ReadBlobString(image,text);
if (LocaleNCompare((char *) text,MagickID,strlen(MagickID)) != 0)
- return(ReadTEXTImage(image_info,image,text,exception));
+ ThrowReaderException(CorruptImageError,"ImproperImageHeader");
do
{
+ width=0;
+ height=0;
+ max_value=0;
*colorspace='\0';
- count=(ssize_t) sscanf(text+32,"%lu,%lu,%lu,%s",&width,&height,&max_value,
+ count=(ssize_t) sscanf(text+32,"%lu,%lu,%lu,%32s",&width,&height,&max_value,
colorspace);
- if (count != 4)
+ if ((count != 4) || (width == 0) || (height == 0) || (max_value == 0))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
image->columns=width;
image->rows=height;
+ if ((max_value == 0) || (max_value > 4294967295UL))
+ ThrowReaderException(CorruptImageError,"ImproperImageHeader");
for (depth=1; (GetQuantumRange(depth)+1) < max_value; depth++) ;
image->depth=depth;
+ status=SetImageExtent(image,image->columns,image->rows,exception);
+ if (status == MagickFalse)
+ return(DestroyImageList(image));
LocaleLower(colorspace);
i=(ssize_t) strlen(colorspace)-1;
- image->matte=MagickFalse;
+ image->alpha_trait=UndefinedPixelTrait;
if ((i > 0) && (colorspace[i] == 'a'))
{
colorspace[i]='\0';
- image->matte=MagickTrue;
+ image->alpha_trait=BlendPixelTrait;
}
type=ParseCommandOption(MagickColorspaceOptions,MagickFalse,colorspace);
if (type < 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
- image->colorspace=(ColorspaceType) type;
- (void) ResetMagickMemory(&pixel,0,sizeof(pixel));
(void) SetImageBackgroundColor(image,exception);
+ (void) SetImageColorspace(image,(ColorspaceType) type,exception);
+ GetPixelInfo(image,&pixel);
range=GetQuantumRange(image->depth);
for (y=0; y < (ssize_t) image->rows; y++)
{
+ double
+ alpha,
+ black,
+ blue,
+ green,
+ red;
+
+ red=0.0;
+ green=0.0;
+ blue=0.0;
+ black=0.0;
+ alpha=0.0;
for (x=0; x < (ssize_t) image->columns; x++)
{
if (ReadBlobString(image,text) == (char *) NULL)
break;
- if (image->colorspace == CMYKColorspace)
+ switch (image->colorspace)
+ {
+ case GRAYColorspace:
{
- if (image->matte != MagickFalse)
- count=(ssize_t) sscanf(text,"%ld,%ld: (%lf,%lf,%lf,%lf,%lf",
- &x_offset,&y_offset,&pixel.red,&pixel.green,&pixel.blue,
- &pixel.black,&pixel.alpha);
- else
- count=(ssize_t) sscanf(text,"%ld,%ld: (%lf,%lf,%lf,%lf",&x_offset,
- &y_offset,&pixel.red,&pixel.green,&pixel.blue,&pixel.black);
+ if (image->alpha_trait != UndefinedPixelTrait)
+ {
+ count=(ssize_t) sscanf(text,"%ld,%ld: (%lf%*[%,]%lf%*[%,]",
+ &x_offset,&y_offset,&red,&alpha);
+ green=red;
+ blue=red;
+ break;
+ }
+ count=(ssize_t) sscanf(text,"%ld,%ld: (%lf%*[%,]",&x_offset,
+ &y_offset,&red);
+ green=red;
+ blue=red;
+ break;
}
- else
- if (image->matte != MagickFalse)
- count=(ssize_t) sscanf(text,"%ld,%ld: (%lf,%lf,%lf,%lf",&x_offset,
- &y_offset,&pixel.red,&pixel.green,&pixel.blue,&pixel.alpha);
- else
- count=(ssize_t) sscanf(text,"%ld,%ld: (%lf,%lf,%lf",&x_offset,
- &y_offset,&pixel.red,&pixel.green,&pixel.blue);
- if (count < 5)
- continue;
- q=GetAuthenticPixels(image,x_offset,y_offset,1,1,exception);
+ case CMYKColorspace:
+ {
+ if (image->alpha_trait != UndefinedPixelTrait)
+ {
+ count=(ssize_t) sscanf(text,
+ "%ld,%ld: (%lf%*[%,]%lf%*[%,]%lf%*[%,]%lf%*[%,]%lf%*[%,]",
+ &x_offset,&y_offset,&red,&green,&blue,&black,&alpha);
+ break;
+ }
+ count=(ssize_t) sscanf(text,
+ "%ld,%ld: (%lf%*[%,]%lf%*[%,]%lf%*[%,]%lf%*[%,]",&x_offset,
+ &y_offset,&red,&green,&blue,&black);
+ break;
+ }
+ default:
+ {
+ if (image->alpha_trait != UndefinedPixelTrait)
+ {
+ count=(ssize_t) sscanf(text,
+ "%ld,%ld: (%lf%*[%,]%lf%*[%,]%lf%*[%,]%lf%*[%,]",
+ &x_offset,&y_offset,&red,&green,&blue,&alpha);
+ break;
+ }
+ count=(ssize_t) sscanf(text,
+ "%ld,%ld: (%lf%*[%,]%lf%*[%,]%lf%*[%,]",&x_offset,
+ &y_offset,&red,&green,&blue);
+ break;
+ }
+ }
+ if (strchr(text,'%') != (char *) NULL)
+ {
+ red*=0.01*range;
+ green*=0.01*range;
+ blue*=0.01*range;
+ black*=0.01*range;
+ alpha*=0.01*range;
+ }
+ if (image->colorspace == LabColorspace)
+ {
+ green+=(range+1)/2.0;
+ blue+=(range+1)/2.0;
+ }
+ pixel.red=(MagickRealType) ScaleAnyToQuantum((QuantumAny) (red+0.5),
+ range);
+ pixel.green=(MagickRealType) ScaleAnyToQuantum((QuantumAny) (green+0.5),
+ range);
+ pixel.blue=(MagickRealType) ScaleAnyToQuantum((QuantumAny) (blue+0.5),
+ range);
+ pixel.black=(MagickRealType) ScaleAnyToQuantum((QuantumAny) (black+0.5),
+ range);
+ pixel.alpha=(MagickRealType) ScaleAnyToQuantum((QuantumAny) (alpha+0.5),
+ range);
+ q=GetAuthenticPixels(image,(ssize_t) x_offset,(ssize_t) y_offset,1,1,
+ exception);
if (q == (Quantum *) NULL)
continue;
- SetPixelRed(image,ScaleAnyToQuantum(pixel.red,range),q);
- SetPixelGreen(image,ScaleAnyToQuantum(pixel.green,range),q);
- SetPixelBlue(image,ScaleAnyToQuantum(pixel.blue,range),q);
- if (image->colorspace == CMYKColorspace)
- SetPixelBlack(image,ScaleAnyToQuantum(pixel.black,range),q);
- if (image->matte != MagickFalse)
- SetPixelAlpha(image,ScaleAnyToQuantum(pixel.alpha,range),q);
+ SetPixelViaPixelInfo(image,&pixel,q);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
MagickInfo
*entry;
- entry=SetMagickInfo("TEXT");
- entry->decoder=(DecodeImageHandler *) ReadTXTImage;
+ entry=AcquireMagickInfo("TXT","SPARSE-COLOR","Sparse Color");
entry->encoder=(EncodeImageHandler *) WriteTXTImage;
- entry->raw=MagickTrue;
- entry->endian_support=MagickTrue;
- entry->description=ConstantString("Text");
- entry->module=ConstantString("TXT");
+ entry->flags|=CoderRawSupportFlag;
+ entry->flags|=CoderEndianSupportFlag;
+ (void) RegisterMagickInfo(entry);
+ entry=AcquireMagickInfo("TXT","TEXT","Text");
+ entry->decoder=(DecodeImageHandler *) ReadTEXTImage;
+ entry->format_type=ImplicitFormatType;
+ entry->flags|=CoderRawSupportFlag;
+ entry->flags|=CoderEndianSupportFlag;
(void) RegisterMagickInfo(entry);
- entry=SetMagickInfo("TXT");
+ entry=AcquireMagickInfo("TXT","TXT","Text");
entry->decoder=(DecodeImageHandler *) ReadTXTImage;
entry->encoder=(EncodeImageHandler *) WriteTXTImage;
- entry->description=ConstantString("Text");
entry->magick=(IsImageFormatHandler *) IsTXT;
- entry->module=ConstantString("TXT");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
*/
ModuleExport void UnregisterTXTImage(void)
{
+ (void) UnregisterMagickInfo("SPARSE-COLOR");
(void) UnregisterMagickInfo("TEXT");
(void) UnregisterMagickInfo("TXT");
}
ExceptionInfo *exception)
{
char
- buffer[MaxTextExtent],
- colorspace[MaxTextExtent],
- tuple[MaxTextExtent];
+ buffer[MagickPathExtent],
+ colorspace[MagickPathExtent],
+ tuple[MagickPathExtent];
MagickBooleanType
status;
Open output image file.
*/
assert(image_info != (const ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ assert(image_info->signature == MagickCoreSignature);
assert(image != (Image *) NULL);
- assert(image->signature == MagickSignature);
+ assert(image->signature == MagickCoreSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
status=OpenBlob(image_info,image,WriteBlobMode,exception);
scene=0;
do
{
+ ComplianceType
+ compliance;
+
+ const char
+ *value;
+
(void) CopyMagickString(colorspace,CommandOptionToMnemonic(
- MagickColorspaceOptions,(ssize_t) image->colorspace),MaxTextExtent);
+ MagickColorspaceOptions,(ssize_t) image->colorspace),MagickPathExtent);
LocaleLower(colorspace);
image->depth=GetImageQuantumDepth(image,MagickTrue);
- if (image->matte != MagickFalse)
- (void) ConcatenateMagickString(colorspace,"a",MaxTextExtent);
- (void) FormatLocaleString(buffer,MaxTextExtent,
- "# ImageMagick pixel enumeration: %.20g,%.20g,%.20g,%s\n",(double)
- image->columns,(double) image->rows,(double)
- GetQuantumRange(image->depth),colorspace);
- (void) WriteBlobString(image,buffer);
+ if (image->alpha_trait != UndefinedPixelTrait)
+ (void) ConcatenateMagickString(colorspace,"a",MagickPathExtent);
+ compliance=NoCompliance;
+ value=GetImageOption(image_info,"txt:compliance");
+ if (value != (char *) NULL)
+ compliance=(ComplianceType) ParseCommandOption(MagickComplianceOptions,
+ MagickFalse,value);
+ if (LocaleCompare(image_info->magick,"SPARSE-COLOR") != 0)
+ {
+ size_t
+ depth;
+
+ depth=compliance == SVGCompliance ? image->depth :
+ MAGICKCORE_QUANTUM_DEPTH;
+ (void) FormatLocaleString(buffer,MagickPathExtent,
+ "# ImageMagick pixel enumeration: %.20g,%.20g,%.20g,%s\n",(double)
+ image->columns,(double) image->rows,(double) ((MagickOffsetType)
+ GetQuantumRange(depth)),colorspace);
+ (void) WriteBlobString(image,buffer);
+ }
GetPixelInfo(image,&pixel);
for (y=0; y < (ssize_t) image->rows; y++)
{
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
- (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g,%.20g: ",(double)
- x,(double) y);
- (void) WriteBlobString(image,buffer);
GetPixelInfoPixel(image,p,&pixel);
- (void) CopyMagickString(tuple,"(",MaxTextExtent);
- ConcatenateColorComponent(&pixel,RedPixelChannel,X11Compliance,
- tuple);
- (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
- ConcatenateColorComponent(&pixel,GreenPixelChannel,X11Compliance,
- tuple);
- (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
- ConcatenateColorComponent(&pixel,BluePixelChannel,X11Compliance,
- tuple);
+ if (pixel.colorspace == LabColorspace)
+ {
+ pixel.green-=(QuantumRange+1)/2.0;
+ pixel.blue-=(QuantumRange+1)/2.0;
+ }
+ if (LocaleCompare(image_info->magick,"SPARSE-COLOR") == 0)
+ {
+ /*
+ Sparse-color format.
+ */
+ if (GetPixelAlpha(image,p) == (Quantum) OpaqueAlpha)
+ {
+ GetColorTuple(&pixel,MagickFalse,tuple);
+ (void) FormatLocaleString(buffer,MagickPathExtent,
+ "%.20g,%.20g,",(double) x,(double) y);
+ (void) WriteBlobString(image,buffer);
+ (void) WriteBlobString(image,tuple);
+ (void) WriteBlobString(image," ");
+ }
+ p+=GetPixelChannels(image);
+ continue;
+ }
+ (void) FormatLocaleString(buffer,MagickPathExtent,"%.20g,%.20g: ",
+ (double) x,(double) y);
+ (void) WriteBlobString(image,buffer);
+ (void) CopyMagickString(tuple,"(",MagickPathExtent);
+ if (pixel.colorspace == GRAYColorspace)
+ ConcatenateColorComponent(&pixel,GrayPixelChannel,compliance,tuple);
+ else
+ {
+ ConcatenateColorComponent(&pixel,RedPixelChannel,compliance,tuple);
+ (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
+ ConcatenateColorComponent(&pixel,GreenPixelChannel,compliance,
+ tuple);
+ (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
+ ConcatenateColorComponent(&pixel,BluePixelChannel,compliance,tuple);
+ }
if (pixel.colorspace == CMYKColorspace)
{
- (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
- ConcatenateColorComponent(&pixel,BlackPixelChannel,X11Compliance,
+ (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
+ ConcatenateColorComponent(&pixel,BlackPixelChannel,compliance,
tuple);
}
- if (pixel.matte != MagickFalse)
+ if (pixel.alpha_trait != UndefinedPixelTrait)
{
- (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
- ConcatenateColorComponent(&pixel,AlphaPixelChannel,X11Compliance,
+ (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
+ ConcatenateColorComponent(&pixel,AlphaPixelChannel,compliance,
tuple);
}
- (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
+ (void) ConcatenateMagickString(tuple,")",MagickPathExtent);
(void) WriteBlobString(image,tuple);
(void) WriteBlobString(image," ");
GetColorTuple(&pixel,MagickTrue,tuple);
- (void) FormatLocaleString(buffer,MaxTextExtent,"%s",tuple);
+ (void) FormatLocaleString(buffer,MagickPathExtent,"%s",tuple);
(void) WriteBlobString(image,buffer);
(void) WriteBlobString(image," ");
(void) QueryColorname(image,&pixel,SVGCompliance,tuple,exception);