This source file includes following definitions.
- RegisterUILImage
- UnregisterUILImage
- WriteUILImage
#include "magick/studio.h"
#include "magick/attribute.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/color.h"
#include "magick/color-private.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image-private.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/pixel-accessor.h"
#include "magick/pixel-private.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/utility.h"
static MagickBooleanType
WriteUILImage(const ImageInfo *,Image *);
ModuleExport size_t RegisterUILImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("UIL");
entry->encoder=(EncodeImageHandler *) WriteUILImage;
entry->adjoin=MagickFalse;
entry->description=ConstantString("X-Motif UIL table");
entry->module=ConstantString("UIL");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
ModuleExport void UnregisterUILImage(void)
{
(void) UnregisterMagickInfo("UIL");
}
static MagickBooleanType WriteUILImage(const ImageInfo *image_info,Image *image)
{
#define MaxCixels 92
char
basename[MaxTextExtent],
buffer[MaxTextExtent],
name[MaxTextExtent],
*symbol;
ExceptionInfo
*exception;
int
j;
MagickBooleanType
status,
transparent;
MagickPixelPacket
pixel;
MagickSizeType
number_pixels;
register const IndexPacket
*indexes;
register const PixelPacket
*p;
register ssize_t
i,
x;
size_t
characters_per_pixel,
colors;
ssize_t
k,
y;
static const char
Cixel[MaxCixels+1] = " .XoO+@#$%&*=-;:>,<1234567890qwertyuipasdfghjk"
"lzxcvbnmMNBVCZASDFGHJKLPIUYTREWQ!~^/()_`'][{}|";
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickSignature);
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
if (status == MagickFalse)
return(status);
(void) TransformImageColorspace(image,sRGBColorspace);
exception=(&image->exception);
transparent=MagickFalse;
i=0;
p=(const PixelPacket *) NULL;
if (image->storage_class == PseudoClass)
colors=image->colors;
else
{
unsigned char
*matte_image;
matte_image=(unsigned char *) NULL;
if (image->matte != MagickFalse)
{
number_pixels=(MagickSizeType) image->columns*image->rows;
if (number_pixels != ((MagickSizeType) (size_t) number_pixels))
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
matte_image=(unsigned char *) AcquireQuantumMemory(image->columns,
image->rows*sizeof(*matte_image));
if (matte_image == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
for (y=0; y < (ssize_t) image->rows; y++)
{
p=GetVirtualPixels(image,0,y,image->columns,1,exception);
if (p == (const PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
matte_image[i]=(unsigned char) (GetPixelOpacity(p) ==
(Quantum) TransparentOpacity ? 1 : 0);
if (matte_image[i] != 0)
transparent=MagickTrue;
i++;
p++;
}
}
}
(void) SetImageType(image,PaletteType);
colors=image->colors;
if (transparent != MagickFalse)
{
register IndexPacket
*indexes;
register PixelPacket
*q;
colors++;
for (y=0; y < (ssize_t) image->rows; y++)
{
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < (ssize_t) image->columns; x++)
{
if (matte_image[i] != 0)
SetPixelIndex(indexes+x,image->colors);
}
}
}
if (matte_image != (unsigned char *) NULL)
matte_image=(unsigned char *) RelinquishMagickMemory(matte_image);
}
characters_per_pixel=1;
for (k=MaxCixels; (ssize_t) colors > k; k*=MaxCixels)
characters_per_pixel++;
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);
GetMagickPixelPacket(image,&pixel);
for (i=0; i < (ssize_t) colors; i++)
{
SetMagickPixelPacket(image,image->colormap+i,(IndexPacket *) NULL,&pixel);
pixel.colorspace=sRGBColorspace;
pixel.depth=8;
pixel.opacity=(MagickRealType) OpaqueOpacity;
GetColorTuple(&pixel,MagickTrue,name);
if (transparent != MagickFalse)
if (i == (ssize_t) (colors-1))
(void) CopyMagickString(name,"None",MaxTextExtent);
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
(void) FormatLocaleString(buffer,MaxTextExtent,
" color('%s',%s) = '%s'",name,
GetPixelLuma(image,image->colormap+i) < (QuantumRange/2.0) ?
"background" : "foreground",symbol);
(void) WriteBlobString(image,buffer);
(void) FormatLocaleString(buffer,MaxTextExtent,"%s",
(i == (ssize_t) (colors-1) ? ");\n" : ",\n"));
(void) WriteBlobString(image,buffer);
}
GetPathComponent(image->filename,BasePath,basename);
(void) FormatLocaleString(buffer,MaxTextExtent,
" %s_icon : icon(color_table = %s_ct,\n",basename,basename);
(void) WriteBlobString(image,buffer);
for (y=0; y < (ssize_t) image->rows; y++)
{
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (const PixelPacket *) NULL)
break;
indexes=GetVirtualIndexQueue(image);
(void) WriteBlobString(image," \"");
for (x=0; x < (ssize_t) image->columns; x++)
{
k=((ssize_t) GetPixelIndex(indexes+x) % MaxCixels);
symbol[0]=Cixel[k];
for (j=1; j < (int) characters_per_pixel; j++)
{
k=(((int) GetPixelIndex(indexes+x)-k)/MaxCixels) % MaxCixels;
symbol[j]=Cixel[k];
}
symbol[j]='\0';
(void) CopyMagickString(buffer,symbol,MaxTextExtent);
(void) WriteBlobString(image,buffer);
p++;
}
(void) FormatLocaleString(buffer,MaxTextExtent,"\"%s\n",
(y == (ssize_t) (image->rows-1) ? ");" : ","));
(void) WriteBlobString(image,buffer);
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
symbol=DestroyString(symbol);
(void) CloseBlob(image);
return(MagickTrue);
}