- Modifications to compile ImageMagick

This commit is contained in:
Santi Noreña 2013-02-19 18:37:48 +01:00
parent 615ec83706
commit 83522c16c3
3442 changed files with 57 additions and 412926 deletions

File diff suppressed because it is too large Load diff

414
ImageMagick/coders/aai.c Normal file
View file

@ -0,0 +1,414 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% AAA AAA IIIII %
% A A A A I %
% AAAAA AAAAA I %
% A A A A I %
% A A A A IIIII %
% %
% %
% Read/Write AAI X Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteAAIImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d A A I I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadAAIImage() reads an AAI Dune 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 ReadAAIImage method is:
%
% Image *ReadAAIImage(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 *ReadAAIImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
Image
*image;
MagickBooleanType
status;
register ssize_t
x;
register PixelPacket
*q;
register unsigned char
*p;
size_t
height,
length,
width;
ssize_t
count,
y;
unsigned char
*pixels;
/*
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);
}
/*
Read AAI Dune image.
*/
width=ReadBlobLSBLong(image);
height=ReadBlobLSBLong(image);
if (EOFBlob(image) != MagickFalse)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
if ((width == 0UL) || (height == 0UL))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
do
{
/*
Convert AAI raster image to pixel packets.
*/
image->columns=width;
image->rows=height;
image->depth=8;
if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
pixels=(unsigned char *) AcquireQuantumMemory(image->columns,
4*sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
length=(size_t) 4*image->columns;
for (y=0; y < (ssize_t) image->rows; y++)
{
count=ReadBlob(image,length,pixels);
if ((size_t) count != length)
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
p=pixels;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelBlue(q,ScaleCharToQuantum(*p++));
SetPixelGreen(q,ScaleCharToQuantum(*p++));
SetPixelRed(q,ScaleCharToQuantum(*p++));
if (*p == 254)
*p=255;
SetPixelAlpha(q,ScaleCharToQuantum(*p++));
if (q->opacity != OpaqueOpacity)
image->matte=MagickTrue;
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (EOFBlob(image) != MagickFalse)
{
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
break;
}
/*
Proceed to next image.
*/
if (image_info->number_scenes != 0)
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
width=ReadBlobLSBLong(image);
height=ReadBlobLSBLong(image);
if ((width != 0UL) && (height != 0UL))
{
/*
Allocate next image structure.
*/
AcquireNextImage(image_info,image);
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
image=SyncNextImageInList(image);
status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
GetBlobSize(image));
if (status == MagickFalse)
break;
}
} while ((width != 0UL) && (height != 0UL));
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r A A I I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterAAIImage() adds attributes for the AAI Dune image format to the list
% of supported formats. The attributes include the image format tag, a
% method to read and/or write the format, whether the format supports the
% saving of more than one frame to the same file or blob, whether the format
% supports native in-memory I/O, and a brief description of the format.
%
% The format of the RegisterAAIImage method is:
%
% size_t RegisterAAIImage(void)
%
*/
ModuleExport size_t RegisterAAIImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("AAI");
entry->decoder=(DecodeImageHandler *) ReadAAIImage;
entry->encoder=(EncodeImageHandler *) WriteAAIImage;
entry->description=ConstantString("AAI Dune image");
entry->module=ConstantString("AAI");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r A A I I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterAAIImage() removes format registrations made by the
% AAI module from the list of supported formats.
%
% The format of the UnregisterAAIImage method is:
%
% UnregisterAAIImage(void)
%
*/
ModuleExport void UnregisterAAIImage(void)
{
(void) UnregisterMagickInfo("AAI");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e A A I I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteAAIImage() writes an image to a file in AAI Dune image format.
%
% The format of the WriteAAIImage method is:
%
% MagickBooleanType WriteAAIImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteAAIImage(const ImageInfo *image_info,Image *image)
{
MagickBooleanType
status;
MagickOffsetType
scene;
register const PixelPacket
*restrict p;
register ssize_t
x;
register unsigned char
*restrict q;
ssize_t
count,
y;
unsigned char
*pixels;
/*
Open output image file.
*/
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);
scene=0;
do
{
/*
Write AAI header.
*/
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
(void) WriteBlobLSBLong(image,(unsigned int) image->columns);
(void) WriteBlobLSBLong(image,(unsigned int) image->rows);
/*
Allocate memory for pixels.
*/
pixels=(unsigned char *) AcquireQuantumMemory((size_t) image->columns,
4*sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
/*
Convert MIFF to AAI raster pixels.
*/
for (y=0; y < (ssize_t) image->rows; y++)
{
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (PixelPacket *) NULL)
break;
q=pixels;
for (x=0; x < (ssize_t) image->columns; x++)
{
*q++=ScaleQuantumToChar(GetPixelBlue(p));
*q++=ScaleQuantumToChar(GetPixelGreen(p));
*q++=ScaleQuantumToChar(GetPixelRed(p));
*q=ScaleQuantumToChar((Quantum) (QuantumRange-(image->matte !=
MagickFalse ? GetPixelOpacity(p) : OpaqueOpacity)));
if (*q == 255)
*q=254;
p++;
q++;
}
count=WriteBlob(image,(size_t) (q-pixels),pixels);
if (count != (ssize_t) (q-pixels))
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (GetNextImageInList(image) == (Image *) NULL)
break;
image=SyncNextImageInList(image);
status=SetImageProgress(image,SaveImagesTag,scene++,
GetImageListLength(image));
if (status == MagickFalse)
break;
} while (image_info->adjoin != MagickFalse);
(void) CloseBlob(image);
return(MagickTrue);
}

357
ImageMagick/coders/art.c Normal file
View file

@ -0,0 +1,357 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% AAA RRRR TTTTT %
% A A R R T %
% AAAAA RRRR T %
% A A R R T %
% A A R R T %
% %
% %
% Support PFS: 1st Publisher Clip Art Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/attribute.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/color-private.h"
#include "magick/colormap.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteARTImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d A R T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadARTImage() reads an image of raw bits in LSB order 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 ReadARTImage method is:
%
% Image *ReadARTImage(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 *ReadARTImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
Image
*image;
QuantumInfo
*quantum_info;
QuantumType
quantum_type;
MagickBooleanType
status;
size_t
length;
ssize_t
count,
y;
unsigned char
*pixels;
/*
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);
}
image->depth=1;
image->endian=MSBEndian;
(void) ReadBlobLSBShort(image);
image->columns=(size_t) ReadBlobLSBShort(image);
(void) ReadBlobLSBShort(image);
image->rows=(size_t) ReadBlobLSBShort(image);
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
/*
Initialize image colormap.
*/
if (AcquireImageColormap(image,2) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
Convert bi-level image to pixel packets.
*/
SetImageColorspace(image,GRAYColorspace);
quantum_type=IndexQuantum;
quantum_info=AcquireQuantumInfo(image_info,image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
pixels=GetQuantumPixels(quantum_info);
length=GetQuantumExtent(image,quantum_info,quantum_type);
for (y=0; y < (ssize_t) image->rows; y++)
{
register PixelPacket
*restrict q;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
count=ReadBlob(image,length,pixels);
if (count != (ssize_t) length)
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
quantum_type,pixels,exception);
count=ReadBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
SetQuantumImageType(image,quantum_type);
quantum_info=DestroyQuantumInfo(quantum_info);
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r A R T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterARTImage() adds attributes for the ART image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterARTImage method is:
%
% size_t RegisterARTImage(void)
%
*/
ModuleExport size_t RegisterARTImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("ART");
entry->decoder=(DecodeImageHandler *) ReadARTImage;
entry->encoder=(EncodeImageHandler *) WriteARTImage;
entry->raw=MagickTrue;
entry->adjoin=MagickFalse;
entry->description=ConstantString("PFS: 1st Publisher Clip Art");
entry->module=ConstantString("ART");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r A R T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterARTImage() removes format registrations made by the
% ART module from the list of supported formats.
%
% The format of the UnregisterARTImage method is:
%
% UnregisterARTImage(void)
%
*/
ModuleExport void UnregisterARTImage(void)
{
(void) UnregisterMagickInfo("ART");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e A R T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteARTImage() writes an image of raw bits in LSB order to a file.
%
% The format of the WriteARTImage method is:
%
% MagickBooleanType WriteARTImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteARTImage(const ImageInfo *image_info,Image *image)
{
MagickBooleanType
status;
QuantumInfo
*quantum_info;
register const PixelPacket
*p;
size_t
length;
ssize_t
count,
y;
unsigned char
*pixels;
/*
Open output image file.
*/
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);
if ((image->columns > 65535UL) || (image->rows > 65535UL))
ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
image->endian=MSBEndian;
image->depth=1;
(void) WriteBlobLSBShort(image,0);
(void) WriteBlobLSBShort(image,(unsigned short) image->columns);
(void) WriteBlobLSBShort(image,0);
(void) WriteBlobLSBShort(image,(unsigned short) image->rows);
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
length=(image->columns+7)/8;
pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
/*
Convert image to a bi-level image.
*/
(void) SetImageType(image,BilevelType);
quantum_info=AcquireQuantumInfo(image_info,image);
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;
(void) ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
GrayQuantum,pixels,&image->exception);
count=WriteBlob(image,length,pixels);
if (count != (ssize_t) length)
ThrowWriterException(CorruptImageError,"UnableToWriteImageData");
count=WriteBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels);
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
quantum_info=DestroyQuantumInfo(quantum_info);
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
(void) CloseBlob(image);
return(MagickTrue);
}

409
ImageMagick/coders/avs.c Normal file
View file

@ -0,0 +1,409 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% AAA V V SSSSS %
% A A V V SS %
% AAAAA V V SSS %
% A A V V SS %
% A A V SSSSS %
% %
% %
% Read/Write AVS X Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteAVSImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d A V S I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadAVSImage() reads an AVS X 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 ReadAVSImage method is:
%
% Image *ReadAVSImage(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 *ReadAVSImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
Image
*image;
MagickBooleanType
status;
register PixelPacket
*q;
register ssize_t
x;
register unsigned char
*p;
size_t
height,
length,
width;
ssize_t
count,
y;
unsigned char
*pixels;
/*
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);
}
/*
Read AVS X image.
*/
width=ReadBlobMSBLong(image);
height=ReadBlobMSBLong(image);
if (EOFBlob(image) != MagickFalse)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
if ((width == 0UL) || (height == 0UL))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
do
{
/*
Convert AVS raster image to pixel packets.
*/
image->columns=width;
image->rows=height;
image->depth=8;
if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
pixels=(unsigned char *) AcquireQuantumMemory(image->columns,
4*sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
length=(size_t) 4*image->columns;
for (y=0; y < (ssize_t) image->rows; y++)
{
count=ReadBlob(image,length,pixels);
if ((size_t) count != length)
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
p=pixels;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelAlpha(q,ScaleCharToQuantum(*p++));
SetPixelRed(q,ScaleCharToQuantum(*p++));
SetPixelGreen(q,ScaleCharToQuantum(*p++));
SetPixelBlue(q,ScaleCharToQuantum(*p++));
if (q->opacity != OpaqueOpacity)
image->matte=MagickTrue;
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (EOFBlob(image) != MagickFalse)
{
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
break;
}
/*
Proceed to next image.
*/
if (image_info->number_scenes != 0)
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
width=ReadBlobMSBLong(image);
height=ReadBlobMSBLong(image);
if ((width != 0UL) && (height != 0UL))
{
/*
Allocate next image structure.
*/
AcquireNextImage(image_info,image);
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
image=SyncNextImageInList(image);
status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
GetBlobSize(image));
if (status == MagickFalse)
break;
}
} while ((width != 0UL) && (height != 0UL));
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r A V S I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterAVSImage() adds attributes for the AVS X image format to the list
% of supported formats. The attributes include the image format tag, a
% method to read and/or write the format, whether the format supports the
% saving of more than one frame to the same file or blob, whether the format
% supports native in-memory I/O, and a brief description of the format.
%
% The format of the RegisterAVSImage method is:
%
% size_t RegisterAVSImage(void)
%
*/
ModuleExport size_t RegisterAVSImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("AVS");
entry->decoder=(DecodeImageHandler *) ReadAVSImage;
entry->encoder=(EncodeImageHandler *) WriteAVSImage;
entry->description=ConstantString("AVS X image");
entry->module=ConstantString("AVS");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r A V S I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterAVSImage() removes format registrations made by the
% AVS module from the list of supported formats.
%
% The format of the UnregisterAVSImage method is:
%
% UnregisterAVSImage(void)
%
*/
ModuleExport void UnregisterAVSImage(void)
{
(void) UnregisterMagickInfo("AVS");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e A V S I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteAVSImage() writes an image to a file in AVS X image format.
%
% The format of the WriteAVSImage method is:
%
% MagickBooleanType WriteAVSImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteAVSImage(const ImageInfo *image_info,Image *image)
{
MagickBooleanType
status;
MagickOffsetType
scene;
register const PixelPacket
*restrict p;
register ssize_t
x;
register unsigned char
*restrict q;
ssize_t
count,
y;
unsigned char
*pixels;
/*
Open output image file.
*/
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);
scene=0;
do
{
/*
Write AVS header.
*/
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
(void) WriteBlobMSBLong(image,(unsigned int) image->columns);
(void) WriteBlobMSBLong(image,(unsigned int) image->rows);
/*
Allocate memory for pixels.
*/
pixels=(unsigned char *) AcquireQuantumMemory((size_t) image->columns,
4*sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
/*
Convert MIFF to AVS raster pixels.
*/
for (y=0; y < (ssize_t) image->rows; y++)
{
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (PixelPacket *) NULL)
break;
q=pixels;
for (x=0; x < (ssize_t) image->columns; x++)
{
*q++=ScaleQuantumToChar((Quantum) (QuantumRange-(image->matte !=
MagickFalse ? GetPixelOpacity(p) : OpaqueOpacity)));
*q++=ScaleQuantumToChar(GetPixelRed(p));
*q++=ScaleQuantumToChar(GetPixelGreen(p));
*q++=ScaleQuantumToChar(GetPixelBlue(p));
p++;
}
count=WriteBlob(image,(size_t) (q-pixels),pixels);
if (count != (ssize_t) (q-pixels))
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (GetNextImageInList(image) == (Image *) NULL)
break;
image=SyncNextImageInList(image);
status=SetImageProgress(image,SaveImagesTag,scene++,
GetImageListLength(image));
if (status == MagickFalse)
break;
} while (image_info->adjoin != MagickFalse);
(void) CloseBlob(image);
return(MagickTrue);
}

1426
ImageMagick/coders/bgr.c Normal file

File diff suppressed because it is too large Load diff

2090
ImageMagick/coders/bmp.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,346 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% BBBB RRRR AAA IIIII L L EEEEE %
% B B R R A A I L L E %
% BBBB RRRR AAAAA I L L EEE %
% B B R R A A I L L E %
% BBBB R R A A IIIII LLLLL LLLLL EEEEE %
% %
% %
% Read/Write Braille Format %
% %
% Samuel Thibault %
% February 2008 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/attribute.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/color-private.h"
#include "magick/colorspace.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/module.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/pixel-accessor.h"
#include "magick/property.h"
#include "magick/quantize.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/utility.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteBRAILLEImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r B R A I L L E I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterBRAILLEImage() adds values for the Braille format to
% the list of supported formats. The values include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterBRAILLEImage method is:
%
% size_t RegisterBRAILLEImage(void)
%
*/
ModuleExport size_t RegisterBRAILLEImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("BRF");
entry->encoder=(EncodeImageHandler *) WriteBRAILLEImage;
entry->adjoin=MagickFalse;
entry->description=AcquireString("BRF ASCII Braille format");
entry->module=AcquireString("BRAILLE");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("UBRL");
entry->encoder=(EncodeImageHandler *) WriteBRAILLEImage;
entry->adjoin=MagickFalse;
entry->description=AcquireString("Unicode Text format");
entry->module=AcquireString("BRAILLE");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("ISOBRL");
entry->encoder=(EncodeImageHandler *) WriteBRAILLEImage;
entry->adjoin=MagickFalse;
entry->description=AcquireString("ISO/TR 11548-1 format");
entry->module=AcquireString("BRAILLE");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r B R A I L L E I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterBRAILLEImage() removes format registrations made by the
% BRAILLE module from the list of supported formats.
%
% The format of the UnregisterBRAILLEImage method is:
%
% UnregisterBRAILLEImage(void)
%
*/
ModuleExport void UnregisterBRAILLEImage(void)
{
(void) UnregisterMagickInfo("BRF");
(void) UnregisterMagickInfo("UBRL");
(void) UnregisterMagickInfo("ISOBRL");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e B R A I L L E I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteBRAILLEImage() writes an image to a file in the Braille format.
%
% The format of the WriteBRAILLEImage method is:
%
% MagickBooleanType WriteBRAILLEImage(const ImageInfo *image_info,
% Image *image)
%
% A description of each parameter follows.
%
% o image_info: The image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteBRAILLEImage(const ImageInfo *image_info,
Image *image)
{
char
buffer[MaxTextExtent];
const char
*value;
IndexPacket
polarity;
int
unicode = 0,
iso_11548_1 = 0;
MagickBooleanType
status;
register const IndexPacket
*indexes;
register const PixelPacket
*p;
register ssize_t
x;
size_t
cell_height = 4;
ssize_t
y;
/*
Open output image file.
*/
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickSignature);
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (LocaleCompare(image_info->magick, "UBRL") == 0)
unicode=1;
else
if (LocaleCompare(image_info->magick, "ISOBRL") == 0)
iso_11548_1=1;
else
cell_height=3;
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
if (status == MagickFalse)
return(status);
if (!iso_11548_1)
{
value=GetImageProperty(image,"label");
if (value != (const char *) NULL)
{
(void) FormatLocaleString(buffer,MaxTextExtent,"Title: %s\n", value);
(void) WriteBlobString(image,buffer);
}
if (image->page.x != 0)
{
(void) FormatLocaleString(buffer,MaxTextExtent,"X: %.20g\n",(double)
image->page.x);
(void) WriteBlobString(image,buffer);
}
if (image->page.y != 0)
{
(void) FormatLocaleString(buffer,MaxTextExtent,"Y: %.20g\n",(double)
image->page.y);
(void) WriteBlobString(image,buffer);
}
(void) FormatLocaleString(buffer,MaxTextExtent,"Width: %.20g\n",(double)
(image->columns+(image->columns % 2)));
(void) WriteBlobString(image,buffer);
(void) FormatLocaleString(buffer,MaxTextExtent,"Height: %.20g\n",(double)
image->rows);
(void) WriteBlobString(image,buffer);
(void) WriteBlobString(image,"\n");
}
(void) SetImageType(image,BilevelType);
polarity = 0;
if (image->storage_class == PseudoClass) {
polarity=(IndexPacket) (PixelIntensityToQuantum(image,&image->colormap[0]) >=
(Quantum) (QuantumRange/2));
if (image->colors == 2)
polarity=(IndexPacket) (PixelIntensityToQuantum(image,&image->colormap[0]) >=
PixelIntensityToQuantum(image,&image->colormap[1]));
}
for (y=0; y < (ssize_t) image->rows; y+=(ssize_t) cell_height)
{
if ((y+cell_height) > image->rows)
cell_height = (size_t) (image->rows-y);
p=GetVirtualPixels(image,0,y,image->columns,cell_height,&image->exception);
if (p == (const PixelPacket *) NULL)
break;
indexes=GetVirtualIndexQueue(image);
for (x=0; x < (ssize_t) image->columns; x+=2)
{
unsigned char cell = 0;
int two_columns = x+1 < (ssize_t) image->columns;
do
{
#define do_cell(dx,dy,bit) do { \
if (image->storage_class == PseudoClass) \
cell |= (GetPixelIndex(indexes+x+dx+dy*image->columns) == polarity) << bit; \
else \
cell |= (GetPixelGreen(p+x+dx+dy*image->columns) == 0) << bit; \
} while (0)
do_cell(0,0,0);
if (two_columns)
do_cell(1,0,3);
if (cell_height < 2)
break;
do_cell(0,1,1);
if (two_columns)
do_cell(1,1,4);
if (cell_height < 3)
break;
do_cell(0,2,2);
if (two_columns)
do_cell(1,2,5);
if (cell_height < 4)
break;
do_cell(0,3,6);
if (two_columns)
do_cell(1,3,7);
} while(0);
if (unicode)
{
unsigned char utf8[3];
/* Unicode text */
utf8[0] = (unsigned char) (0xe0|((0x28>>4)&0x0f));
utf8[1] = 0x80|((0x28<<2)&0x3f)|(cell>>6);
utf8[2] = 0x80|(cell&0x3f);
(void) WriteBlob(image,3,utf8);
}
else if (iso_11548_1)
{
/* ISO/TR 11548-1 binary */
(void) WriteBlobByte(image,cell);
}
else
{
/* BRF */
static const unsigned char iso_to_brf[64] = {
' ', 'A', '1', 'B', '\'', 'K', '2', 'L',
'@', 'C', 'I', 'F', '/', 'M', 'S', 'P',
'"', 'E', '3', 'H', '9', 'O', '6', 'R',
'^', 'D', 'J', 'G', '>', 'N', 'T', 'Q',
',', '*', '5', '<', '-', 'U', '8', 'V',
'.', '%', '[', '$', '+', 'X', '!', '&',
';', ':', '4', '\\', '0', 'Z', '7', '(',
'_', '?', 'W', ']', '#', 'Y', ')', '='
};
(void) WriteBlobByte(image,iso_to_brf[cell]);
}
}
if (iso_11548_1 == 0)
(void) WriteBlobByte(image,'\n');
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
(void) CloseBlob(image);
return(MagickTrue);
}

584
ImageMagick/coders/cals.c Normal file
View file

@ -0,0 +1,584 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% CCCC AAA L SSSSS %
% C A A L SS %
% C AAAAA L SSS %
% C A A L SS %
% CCCC A A LLLLL SSSSS %
% %
% %
% Read/Write CALS Raster Group 1 Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% The CALS raster format is a standard developed by the Computer Aided
% Acquisition and Logistics Support (CALS) office of the United States
% Department of Defense to standardize graphics data interchange for
% electronic publishing, especially in the areas of technical graphics,
% CAD/CAM, and image processing applications.
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colorspace.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/geometry.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/option.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/resource_.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#if defined(MAGICKCORE_TIFF_DELEGATE)
/*
Forward declarations.
*/
static MagickBooleanType
WriteCALSImage(const ImageInfo *,Image *);
#endif
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s C A L S %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsCALS() returns MagickTrue if the image format type, identified by the
% magick string, is CALS Raster Group 1.
%
% The format of the IsCALS method is:
%
% MagickBooleanType IsCALS(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsCALS(const unsigned char *magick,const size_t length)
{
if (length < 128)
return(MagickFalse);
if (LocaleNCompare((const char *) magick,"version: MIL-STD-1840",21) == 0)
return(MagickTrue);
if (LocaleNCompare((const char *) magick,"srcdocid:",9) == 0)
return(MagickTrue);
if (LocaleNCompare((const char *) magick,"rorient:",8) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d C A L S I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadCALSImage() reads an CALS Raster Group 1 image format 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 ReadCALSImage method is:
%
% Image *ReadCALSImage(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 *ReadCALSImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
char
filename[MaxTextExtent],
header[129],
message[MaxTextExtent];
FILE
*file;
Image
*image;
ImageInfo
*read_info;
int
c,
unique_file;
MagickBooleanType
status;
register ssize_t
i;
unsigned long
density,
direction,
height,
orientation,
pel_path,
type,
width;
/*
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);
}
/*
Read CALS header.
*/
(void) ResetMagickMemory(header,0,sizeof(header));
density=0;
direction=0;
orientation=1;
pel_path=0;
type=1;
width=0;
height=0;
for (i=0; i < 16; i++)
{
if (ReadBlob(image,128,(unsigned char *) header) != 128)
break;
switch (*header)
{
case 'R':
case 'r':
{
if (LocaleNCompare(header,"rdensty:",8) == 0)
{
(void) sscanf(header+8,"%lu",&density);
break;
}
if (LocaleNCompare(header,"rpelcnt:",8) == 0)
{
(void) sscanf(header+8,"%lu,%lu",&width,&height);
break;
}
if (LocaleNCompare(header,"rorient:",8) == 0)
{
(void) sscanf(header+8,"%lu,%lu",&pel_path,&direction);
if (pel_path == 90)
orientation=5;
else
if (pel_path == 180)
orientation=3;
else
if (pel_path == 270)
orientation=7;
if (direction == 90)
orientation++;
break;
}
if (LocaleNCompare(header,"rtype:",6) == 0)
{
(void) sscanf(header+6,"%lu",&type);
break;
}
break;
}
}
}
/*
Read CALS pixels.
*/
file=(FILE *) NULL;
unique_file=AcquireUniqueFileResource(filename);
if (unique_file != -1)
file=fdopen(unique_file,"wb");
if ((unique_file == -1) || (file == (FILE *) NULL))
ThrowImageException(FileOpenError,"UnableToCreateTemporaryFile");
while ((c=ReadBlobByte(image)) != EOF)
(void) fputc(c,file);
(void) fclose(file);
(void) CloseBlob(image);
image=DestroyImage(image);
read_info=CloneImageInfo(image_info);
SetImageInfoBlob(read_info,(void *) NULL,0);
(void) FormatLocaleString(read_info->filename,MaxTextExtent,"group4:%s",
filename);
(void) FormatLocaleString(message,MaxTextExtent,"%lux%lu",width,height);
read_info->size=ConstantString(message);
(void) FormatLocaleString(message,MaxTextExtent,"%lu",density);
read_info->density=ConstantString(message);
read_info->orientation=(OrientationType) orientation;
image=ReadImage(read_info,exception);
if (image != (Image *) NULL)
{
(void) CopyMagickString(image->filename,image_info->filename,
MaxTextExtent);
(void) CopyMagickString(image->magick_filename,image_info->filename,
MaxTextExtent);
(void) CopyMagickString(image->magick,"CALS",MaxTextExtent);
}
read_info=DestroyImageInfo(read_info);
(void) RelinquishUniqueFileResource(filename);
return(image);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r C A L S I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterCALSImage() adds attributes for the CALS Raster Group 1 image file
% image format to the list of supported formats. The attributes include the
% image format tag, a method to read and/or write the format, whether the
% format supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief description
% of the format.
%
% The format of the RegisterCALSImage method is:
%
% size_t RegisterCALSImage(void)
%
*/
ModuleExport size_t RegisterCALSImage(void)
{
MagickInfo
*entry;
static const char
*CALSDescription=
{
"Continuous Acquisition and Life-cycle Support Type 1"
},
*CALSNote=
{
"Specified in MIL-R-28002 and MIL-PRF-28002"
};
entry=SetMagickInfo("CAL");
entry->decoder=(DecodeImageHandler *) ReadCALSImage;
#if defined(MAGICKCORE_TIFF_DELEGATE)
entry->encoder=(EncodeImageHandler *) WriteCALSImage;
#endif
entry->adjoin=MagickFalse;
entry->magick=(IsImageFormatHandler *) IsCALS;
entry->description=ConstantString(CALSDescription);
entry->note=ConstantString(CALSNote);
entry->module=ConstantString("CALS");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("CALS");
entry->decoder=(DecodeImageHandler *) ReadCALSImage;
#if defined(MAGICKCORE_TIFF_DELEGATE)
entry->encoder=(EncodeImageHandler *) WriteCALSImage;
#endif
entry->adjoin=MagickFalse;
entry->magick=(IsImageFormatHandler *) IsCALS;
entry->description=ConstantString(CALSDescription);
entry->note=ConstantString(CALSNote);
entry->module=ConstantString("CALS");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r C A L S I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterCALSImage() removes format registrations made by the
% CALS module from the list of supported formats.
%
% The format of the UnregisterCALSImage method is:
%
% UnregisterCALSImage(void)
%
*/
ModuleExport void UnregisterCALSImage(void)
{
(void) UnregisterMagickInfo("CAL");
(void) UnregisterMagickInfo("CALS");
}
#if defined(MAGICKCORE_TIFF_DELEGATE)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e C A L S I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteCALSImage() writes an image to a file in CALS Raster Group 1 image
% format.
%
% The format of the WriteCALSImage method is:
%
% MagickBooleanType WriteCALSImage(const ImageInfo *image_info,
% Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static ssize_t WriteCALSRecord(Image *image,const char *data)
{
char
pad[128];
register const char
*p;
register ssize_t
i;
ssize_t
count;
i=0;
count=0;
if (data != (const char *) NULL)
{
p=data;
for (i=0; (i < 128) && (p[i] != '\0'); i++);
count=WriteBlob(image,(size_t) i,(const unsigned char *) data);
}
if (i < 128)
{
i=128-i;
(void) ResetMagickMemory(pad,' ',(size_t) i);
count=WriteBlob(image,(size_t) i,(const unsigned char *) pad);
}
return(count);
}
static MagickBooleanType WriteCALSImage(const ImageInfo *image_info,
Image *image)
{
char
header[129];
Image
*group4_image;
ImageInfo
*write_info;
MagickBooleanType
status;
register ssize_t
i;
size_t
density,
length,
orient_x,
orient_y;
ssize_t
count;
unsigned char
*group4;
/*
Open output image file.
*/
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);
/*
Create standard CALS header.
*/
count=WriteCALSRecord(image,"srcdocid: NONE");
(void) count;
count=WriteCALSRecord(image,"dstdocid: NONE");
count=WriteCALSRecord(image,"txtfilid: NONE");
count=WriteCALSRecord(image,"figid: NONE");
count=WriteCALSRecord(image,"srcgph: NONE");
count=WriteCALSRecord(image,"docls: NONE");
count=WriteCALSRecord(image,"rtype: 1");
orient_x=0;
orient_y=0;
switch (image->orientation)
{
case TopRightOrientation:
{
orient_x=180;
orient_y=270;
break;
}
case BottomRightOrientation:
{
orient_x=180;
orient_y=90;
break;
}
case BottomLeftOrientation:
{
orient_y=90;
break;
}
case LeftTopOrientation:
{
orient_x=270;
break;
}
case RightTopOrientation:
{
orient_x=270;
orient_y=180;
break;
}
case RightBottomOrientation:
{
orient_x=90;
orient_y=180;
break;
}
case LeftBottomOrientation:
{
orient_x=90;
break;
}
default:
{
orient_y=270;
}
}
(void) FormatLocaleString(header,MaxTextExtent,"rorient: %03ld,%03ld",
(long) orient_x,(long) orient_y);
count=WriteCALSRecord(image,header);
(void) FormatLocaleString(header,MaxTextExtent,"rpelcnt: %06lu,%06lu",
(unsigned long) image->columns,(unsigned long) image->rows);
count=WriteCALSRecord(image,header);
density=200;
if (image_info->density != (char *) NULL)
{
GeometryInfo
geometry_info;
(void) ParseGeometry(image_info->density,&geometry_info);
density=(size_t) floor(geometry_info.rho+0.5);
}
(void) FormatLocaleString(header,MaxTextExtent,"rdensty: %04lu",
(unsigned long) density);
count=WriteCALSRecord(image,header);
count=WriteCALSRecord(image,"notes: NONE");
(void) ResetMagickMemory(header,' ',128);
for (i=0; i < 5; i++)
(void) WriteBlob(image,128,(unsigned char *) header);
/*
Write CALS pixels.
*/
write_info=CloneImageInfo(image_info);
(void) CopyMagickString(write_info->filename,"GROUP4:",MaxTextExtent);
(void) CopyMagickString(write_info->magick,"GROUP4",MaxTextExtent);
group4_image=CloneImage(image,0,0,MagickTrue,&image->exception);
if (group4_image == (Image *) NULL)
{
(void) CloseBlob(image);
return(MagickFalse);
}
group4=(unsigned char *) ImageToBlob(write_info,group4_image,&length,
&image->exception);
group4_image=DestroyImage(group4_image);
if (group4 == (unsigned char *) NULL)
{
(void) CloseBlob(image);
return(MagickFalse);
}
write_info=DestroyImageInfo(write_info);
if (WriteBlob(image,length,group4) != (ssize_t) length)
status=MagickFalse;
group4=(unsigned char *) RelinquishMagickMemory(group4);
(void) CloseBlob(image);
return(status);
}
#endif

View file

@ -0,0 +1,328 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% CCCC AAA PPPP TTTTT IIIII OOO N N %
% C A A P P T I O O NN N %
% C AAAAA PPPP T I O O N N N %
% C A A P T I O O N NN %
% CCCC A A P T IIIII OOO N N %
% %
% %
% Read Text Caption. %
% %
% Software Design %
% John Cristy %
% February 2002 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/annotate.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/composite-private.h"
#include "magick/draw.h"
#include "magick/draw-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/module.h"
#include "magick/option.h"
#include "magick/pixel-accessor.h"
#include "magick/property.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/string-private.h"
#include "magick/utility.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d C A P T I O N I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadCAPTIONImage() reads a CAPTION 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 ReadCAPTIONImage method is:
%
% Image *ReadCAPTIONImage(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 *ReadCAPTIONImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
char
*caption,
geometry[MaxTextExtent],
*property;
const char
*gravity,
*option;
DrawInfo
*draw_info;
Image
*image;
MagickBooleanType
status;
register ssize_t
i;
size_t
height,
width;
TypeMetric
metrics;
/*
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);
if (image->columns == 0)
ThrowReaderException(OptionError,"MustSpecifyImageSize");
(void) ResetImagePage(image,"0x0+0+0");
/*
Format caption.
*/
option=GetImageOption(image_info,"filename");
if (option == (const char *) NULL)
property=InterpretImageProperties(image_info,image,image_info->filename);
else
if (LocaleNCompare(option,"caption:",8) == 0)
property=InterpretImageProperties(image_info,image,option+8);
else
property=InterpretImageProperties(image_info,image,option);
(void) SetImageProperty(image,"caption",property);
property=DestroyString(property);
caption=ConstantString(GetImageProperty(image,"caption"));
draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
(void) CloneString(&draw_info->text,caption);
gravity=GetImageOption(image_info,"gravity");
if (gravity != (char *) NULL)
draw_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
MagickFalse,gravity);
if ((*caption != '\0') && (image->rows != 0) &&
(image_info->pointsize == 0.0))
{
char
*text;
double
high,
low;
/*
Auto fit text into bounding box.
*/
for ( ; ; draw_info->pointsize*=2.0)
{
text=AcquireString(caption);
i=FormatMagickCaption(image,draw_info,MagickTrue,&metrics,&text);
(void) CloneString(&draw_info->text,text);
text=DestroyString(text);
(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;
width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
if ((width > image->columns) && (height > image->rows))
break;
}
high=draw_info->pointsize/2.0;
for (low=high/2.0; (high-low) > 1.0; )
{
draw_info->pointsize=(low+high)/2.0;
text=AcquireString(caption);
i=FormatMagickCaption(image,draw_info,MagickTrue,&metrics,&text);
(void) CloneString(&draw_info->text,text);
text=DestroyString(text);
(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);
width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
if ((width <= image->columns) && (height <= image->rows))
low=draw_info->pointsize+1.0;
else
high=draw_info->pointsize-1.0;
}
for (draw_info->pointsize=(low+high)/2.0; ; draw_info->pointsize--)
{
text=AcquireString(caption);
i=FormatMagickCaption(image,draw_info,MagickTrue,&metrics,&text);
(void) CloneString(&draw_info->text,text);
text=DestroyString(text);
(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);
width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
if ((width <= image->columns) && (height <= image->rows))
break;
}
draw_info->pointsize=floor(draw_info->pointsize);
}
i=FormatMagickCaption(image,draw_info,MagickTrue,&metrics,&caption);
if (image->rows == 0)
image->rows=(size_t) ((i+1)*(metrics.ascent-metrics.descent+
draw_info->interline_spacing+draw_info->stroke_width)+0.5);
if (image->rows == 0)
image->rows=(size_t) ((i+1)*draw_info->pointsize+
draw_info->interline_spacing+draw_info->stroke_width+0.5);
if (SetImageBackgroundColor(image) == MagickFalse)
{
InheritException(exception,&image->exception);
image=DestroyImageList(image);
return((Image *) NULL);
}
/*
Draw caption.
*/
(void) CloneString(&draw_info->text,caption);
status=GetMultilineTypeMetrics(image,draw_info,&metrics);
if ((draw_info->gravity != UndefinedGravity) &&
(draw_info->direction != RightToLeftDirection))
image->page.x=(ssize_t) (metrics.bounds.x1-draw_info->stroke_width/2.0);
else
{
(void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
-metrics.bounds.x1+draw_info->stroke_width/2.0,metrics.ascent+
draw_info->stroke_width/2.0);
if (draw_info->direction == RightToLeftDirection)
(void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
image->columns-(metrics.bounds.x2+draw_info->stroke_width/2.0),
metrics.ascent+draw_info->stroke_width/2.0);
draw_info->geometry=AcquireString(geometry);
}
status=AnnotateImage(image,draw_info);
draw_info=DestroyDrawInfo(draw_info);
caption=DestroyString(caption);
if (status == MagickFalse)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r C A P T I O N I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterCAPTIONImage() adds attributes for the CAPTION image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterCAPTIONImage method is:
%
% size_t RegisterCAPTIONImage(void)
%
*/
ModuleExport size_t RegisterCAPTIONImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("CAPTION");
entry->decoder=(DecodeImageHandler *) ReadCAPTIONImage;
entry->description=ConstantString("Caption");
entry->adjoin=MagickFalse;
entry->module=ConstantString("CAPTION");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r C A P T I O N I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterCAPTIONImage() removes format registrations made by the
% CAPTION module from the list of supported formats.
%
% The format of the UnregisterCAPTIONImage method is:
%
% UnregisterCAPTIONImage(void)
%
*/
ModuleExport void UnregisterCAPTIONImage(void)
{
(void) UnregisterMagickInfo("CAPTION");
}

1175
ImageMagick/coders/cin.c Normal file

File diff suppressed because it is too large Load diff

270
ImageMagick/coders/cip.c Normal file
View file

@ -0,0 +1,270 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% CCCC IIIII PPPP %
% C I P P %
% C I PPPP %
% C I P %
% CCCC IIIII P %
% %
% %
% Read/Write Cisco IP Phone Image Format %
% %
% Software Design %
% John Cristy %
% April 2004 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/color-private.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/property.h"
#include "magick/quantize.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/utility.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteCIPImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r C I P I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterCIPImage() adds properties for the CIP IP phone image format to
% the list of supported formats. The properties include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterCIPImage method is:
%
% size_t RegisterCIPImage(void)
%
*/
ModuleExport size_t RegisterCIPImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("CIP");
entry->encoder=(EncodeImageHandler *) WriteCIPImage;
entry->adjoin=MagickFalse;
entry->description=ConstantString("Cisco IP phone image format");
entry->module=ConstantString("CIP");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r C I P I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterCIPImage() removes format registrations made by the
% CIP module from the list of supported formats.
%
% The format of the UnregisterCIPImage method is:
%
% UnregisterCIPImage(void)
%
*/
ModuleExport void UnregisterCIPImage(void)
{
(void) UnregisterMagickInfo("CIP");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e C I P I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Procedure WriteCIPImage() writes an image to a file in the Cisco IP phone
% image format.
%
% The format of the WriteCIPImage method is:
%
% MagickBooleanType WriteCIPImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static inline ssize_t MagickMin(const ssize_t x,const ssize_t y)
{
if (x < y)
return(x);
return(y);
}
static MagickBooleanType WriteCIPImage(const ImageInfo *image_info,Image *image)
{
char
buffer[MaxTextExtent];
const char
*value;
MagickBooleanType
status;
register const PixelPacket
*p;
register ssize_t
i,
x;
ssize_t
y;
unsigned char
byte;
/*
Open output image file.
*/
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) WriteBlobString(image,"<CiscoIPPhoneImage>\n");
value=GetImageProperty(image,"label");
if (value != (const char *) NULL)
(void) FormatLocaleString(buffer,MaxTextExtent,"<Title>%s</Title>\n",value);
else
{
char
basename[MaxTextExtent];
GetPathComponent(image->filename,BasePath,basename);
(void) FormatLocaleString(buffer,MaxTextExtent,"<Title>%s</Title>\n",
basename);
}
(void) WriteBlobString(image,buffer);
(void) FormatLocaleString(buffer,MaxTextExtent,
"<LocationX>%.20g</LocationX>\n",(double) image->page.x);
(void) WriteBlobString(image,buffer);
(void) FormatLocaleString(buffer,MaxTextExtent,
"<LocationY>%.20g</LocationY>\n",(double) image->page.y);
(void) WriteBlobString(image,buffer);
(void) FormatLocaleString(buffer,MaxTextExtent,"<Width>%.20g</Width>\n",
(double) (image->columns+(image->columns % 2)));
(void) WriteBlobString(image,buffer);
(void) FormatLocaleString(buffer,MaxTextExtent,"<Height>%.20g</Height>\n",
(double) image->rows);
(void) WriteBlobString(image,buffer);
(void) FormatLocaleString(buffer,MaxTextExtent,"<Depth>2</Depth>\n");
(void) WriteBlobString(image,buffer);
(void) WriteBlobString(image,"<Data>");
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
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;
for (x=0; x < ((ssize_t) image->columns-3); x+=4)
{
byte=(unsigned char)
((((size_t) (4*PixelIntensityToQuantum(image,p+3)/QuantumRange) & 0x03) << 6) |
(((size_t) (4*PixelIntensityToQuantum(image,p+2)/QuantumRange) & 0x03) << 4) |
(((size_t) (4*PixelIntensityToQuantum(image,p+1)/QuantumRange) & 0x03) << 2) |
(((size_t) (4*PixelIntensityToQuantum(image,p+0)/QuantumRange) & 0x03) << 0));
(void) FormatLocaleString(buffer,MaxTextExtent,"%02x",byte);
(void) WriteBlobString(image,buffer);
p+=4;
}
if ((image->columns % 4) != 0)
{
i=(ssize_t) image->columns % 4;
byte=(unsigned char)
((((size_t) (4*PixelIntensityToQuantum(image,p+MagickMin(i,3))/QuantumRange) & 0x03) << 6) |
(((size_t) (4*PixelIntensityToQuantum(image,p+MagickMin(i,2))/QuantumRange) & 0x03) << 4) |
(((size_t) (4*PixelIntensityToQuantum(image,p+MagickMin(i,1))/QuantumRange) & 0x03) << 2) |
(((size_t) (4*PixelIntensityToQuantum(image,p+MagickMin(i,0))/QuantumRange) & 0x03) << 0));
(void) FormatLocaleString(buffer,MaxTextExtent,"%02x",~byte);
(void) WriteBlobString(image,buffer);
}
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
(void) WriteBlobString(image,"</Data>\n");
(void) WriteBlobString(image,"</CiscoIPPhoneImage>\n");
(void) CloseBlob(image);
return(MagickTrue);
}

181
ImageMagick/coders/clip.c Normal file
View file

@ -0,0 +1,181 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% CCCC L IIIII PPPP %
% C L I P P %
% C L I PPPP %
% C L I P %
% CCCC LLLLL IIIII P %
% %
% %
% Write Clip Mask To MIFF File. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/attribute.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteCLIPImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r C L I P I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterCLIPImage() adds attributes for the CLIP image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterCLIPImage method is:
%
% size_t RegisterCLIPImage(void)
%
*/
ModuleExport size_t RegisterCLIPImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("CLIP");
entry->encoder=(EncodeImageHandler *) WriteCLIPImage;
entry->description=ConstantString("Image Clip Mask");
entry->module=ConstantString("CLIP");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r C L I P I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterCLIPImage() removes format registrations made by the
% CLIP module from the list of supported formats.
%
% The format of the UnregisterCLIPImage method is:
%
% UnregisterCLIPImage(void)
%
*/
ModuleExport void UnregisterCLIPImage(void)
{
(void) UnregisterMagickInfo("CLIP");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e C L I P I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteCLIPImage() writes an image of clip bytes to a file. It consists of
% data from the clip mask of the image.
%
% The format of the WriteCLIPImage method is:
%
% MagickBooleanType WriteCLIPImage(const ImageInfo *image_info,
% Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteCLIPImage(const ImageInfo *image_info,
Image *image)
{
Image
*clip_image;
ImageInfo
*write_info;
MagickBooleanType
status;
if (image->clip_mask == (Image *) NULL)
(void) ClipImage(image);
if (image->clip_mask == (Image *) NULL)
ThrowWriterException(CoderError,"ImageDoesNotHaveAClipMask");
clip_image=CloneImage(image->clip_mask,0,0,MagickTrue,&image->exception);
if (clip_image == (Image *) NULL)
return(MagickFalse);
(void) SetImageType(clip_image,TrueColorType);
(void) CopyMagickString(clip_image->filename,image->filename,MaxTextExtent);
write_info=CloneImageInfo(image_info);
(void) SetImageInfo(write_info,1,&image->exception);
if (LocaleCompare(write_info->magick,"CLIP") == 0)
(void) FormatLocaleString(clip_image->filename,MaxTextExtent,"miff:%s",
write_info->filename);
status=WriteImage(write_info,clip_image);
clip_image=DestroyImage(clip_image);
write_info=DestroyImageInfo(write_info);
return(status);
}

View file

@ -0,0 +1,352 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% CCCC L IIIII PPPP BBBB OOO AAA RRRR DDDD %
% C L I P P B B O O A A R R D D %
% C L I PPP BBBB O O AAAAA RRRR D D %
% C L I P B B O O A A R R D D %
% CCCC LLLLL IIIII P BBBB OOO A A R R DDDD %
% %
% %
% Read/Write Windows Clipboard. %
% %
% Software Design %
% Leonard Rosenthol %
% May 2002 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#if defined(MAGICKCORE_WINGDI32_DELEGATE)
# if defined(__CYGWIN__)
# include <windows.h>
# else
/* All MinGW needs ... */
# include <wingdi.h>
# endif
#endif
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/nt-feature.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
#if defined(MAGICKCORE_WINGDI32_DELEGATE)
static MagickBooleanType
WriteCLIPBOARDImage(const ImageInfo *,Image *);
#endif
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d C L I P B O A R D I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadCLIPBOARDImage() reads an image from the system clipboard 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 ReadCLIPBOARDImage method is:
%
% Image *ReadCLIPBOARDImage(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.
%
*/
#if defined(MAGICKCORE_WINGDI32_DELEGATE)
static Image *ReadCLIPBOARDImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
Image
*image;
register ssize_t
x;
register PixelPacket
*q;
ssize_t
y;
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);
{
HBITMAP
bitmapH;
HPALETTE
hPal;
OpenClipboard(NULL);
bitmapH=(HBITMAP) GetClipboardData(CF_BITMAP);
hPal=(HPALETTE) GetClipboardData(CF_PALETTE);
CloseClipboard();
if ( bitmapH == NULL )
ThrowReaderException(CoderError,"NoBitmapOnClipboard");
{
BITMAPINFO
DIBinfo;
BITMAP
bitmap;
HBITMAP
hBitmap,
hOldBitmap;
HDC
hDC,
hMemDC;
RGBQUAD
*pBits,
*ppBits;
/* create an offscreen DC for the source */
hMemDC=CreateCompatibleDC(NULL);
hOldBitmap=(HBITMAP) SelectObject(hMemDC,bitmapH);
GetObject(bitmapH,sizeof(BITMAP),(LPSTR) &bitmap);
if ((image->columns == 0) || (image->rows == 0))
{
image->rows=bitmap.bmHeight;
image->columns=bitmap.bmWidth;
}
/*
Initialize the bitmap header info.
*/
(void) ResetMagickMemory(&DIBinfo,0,sizeof(BITMAPINFO));
DIBinfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
DIBinfo.bmiHeader.biWidth=(LONG) image->columns;
DIBinfo.bmiHeader.biHeight=(-1)*(LONG) image->rows;
DIBinfo.bmiHeader.biPlanes=1;
DIBinfo.bmiHeader.biBitCount=32;
DIBinfo.bmiHeader.biCompression=BI_RGB;
hDC=GetDC(NULL);
if (hDC == 0)
ThrowReaderException(CoderError,"UnableToCreateADC");
hBitmap=CreateDIBSection(hDC,&DIBinfo,DIB_RGB_COLORS,(void **) &ppBits,
NULL,0);
ReleaseDC(NULL,hDC);
if (hBitmap == 0)
ThrowReaderException(CoderError,"UnableToCreateBitmap");
/* create an offscreen DC */
hDC=CreateCompatibleDC(NULL);
if (hDC == 0)
{
DeleteObject(hBitmap);
ThrowReaderException(CoderError,"UnableToCreateADC");
}
hOldBitmap=(HBITMAP) SelectObject(hDC,hBitmap);
if (hOldBitmap == 0)
{
DeleteDC(hDC);
DeleteObject(hBitmap);
ThrowReaderException(CoderError,"UnableToCreateBitmap");
}
if (hPal != NULL)
{
/* Kenichi Masuko says this needed */
SelectPalette(hDC, hPal, FALSE);
RealizePalette(hDC);
}
/* bitblt from the memory to the DIB-based one */
BitBlt(hDC,0,0,(int) image->columns,(int) image->rows,hMemDC,0,0,SRCCOPY);
/* finally copy the pixels! */
pBits=ppBits;
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelRed(q,ScaleCharToQuantum(pBits->rgbRed));
SetPixelGreen(q,ScaleCharToQuantum(pBits->rgbGreen));
SetPixelBlue(q,ScaleCharToQuantum(pBits->rgbBlue));
SetPixelOpacity(q,OpaqueOpacity);
pBits++;
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
DeleteDC(hDC);
DeleteObject(hBitmap);
}
}
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
#endif /* MAGICKCORE_WINGDI32_DELEGATE */
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r C L I P B O A R D I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterCLIPBOARDImage() adds attributes for the clipboard "image format" to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterCLIPBOARDImage method is:
%
% size_t RegisterCLIPBOARDImage(void)
%
*/
ModuleExport size_t RegisterCLIPBOARDImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("CLIPBOARD");
#if defined(MAGICKCORE_WINGDI32_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadCLIPBOARDImage;
entry->encoder=(EncodeImageHandler *) WriteCLIPBOARDImage;
#endif
entry->adjoin=MagickFalse;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("The system clipboard");
entry->module=ConstantString("CLIPBOARD");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r C L I P B O A R D I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterCLIPBOARDImage() removes format registrations made by the
% RGB module from the list of supported formats.
%
% The format of the UnregisterCLIPBOARDImage method is:
%
% UnregisterCLIPBOARDImage(void)
%
*/
ModuleExport void UnregisterCLIPBOARDImage(void)
{
(void) UnregisterMagickInfo("CLIPBOARD");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e C L I P B O A R D I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteCLIPBOARDImage() writes an image to the system clipboard.
%
% The format of the WriteCLIPBOARDImage method is:
%
% MagickBooleanType WriteCLIPBOARDImage(const ImageInfo *image_info,
% Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
#if defined(MAGICKCORE_WINGDI32_DELEGATE)
static MagickBooleanType WriteCLIPBOARDImage(const ImageInfo *image_info,
Image *image)
{
/*
Allocate memory for pixels.
*/
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);
{
HBITMAP
bitmapH;
OpenClipboard(NULL);
EmptyClipboard();
bitmapH=(HBITMAP) ImageToHBITMAP(image);
SetClipboardData(CF_BITMAP,bitmapH);
CloseClipboard();
}
return(MagickTrue);
}
#endif /* MAGICKCORE_WINGDI32_DELEGATE */

1634
ImageMagick/coders/cmyk.c Normal file

File diff suppressed because it is too large Load diff

665
ImageMagick/coders/cut.c Normal file
View file

@ -0,0 +1,665 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% CCC U U TTTTT %
% C U U T %
% C U U T %
% C U U T %
% CCC UUU T %
% %
% %
% Read DR Halo Image Format %
% %
% Software Design %
% Jaroslav Fojtik %
% June 2000 %
% %
% %
% Permission is hereby granted, free of charge, to any person obtaining a %
% copy of this software and associated documentation files ("ImageMagick"), %
% to deal in ImageMagick without restriction, including without limitation %
% the rights to use, copy, modify, merge, publish, distribute, sublicense, %
% and/or sell copies of ImageMagick, and to permit persons to whom the %
% ImageMagick is furnished to do so, subject to the following conditions: %
% %
% The above copyright notice and this permission notice shall be included in %
% all copies or substantial portions of ImageMagick. %
% %
% The software is provided "as is", without warranty of any kind, express or %
% implied, including but not limited to the warranties of merchantability, %
% fitness for a particular purpose and noninfringement. In no event shall %
% ImageMagick Studio be liable for any claim, damages or other liability, %
% whether in an action of contract, tort or otherwise, arising from, out of %
% or in connection with ImageMagick or the use or other dealings in %
% ImageMagick. %
% %
% Except as contained in this notice, the name of the ImageMagick Studio %
% shall not be used in advertising or otherwise to promote the sale, use or %
% other dealings in ImageMagick without prior written authorization from the %
% ImageMagick Studio. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.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/colormap.h"
#include "magick/colormap-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/utility.h"
#include "magick/utility-private.h"
typedef struct
{
unsigned Width;
unsigned Height;
unsigned Reserved;
} CUTHeader;
typedef struct
{
char FileId[2];
unsigned Version;
unsigned Size;
char FileType;
char SubType;
unsigned BoardID;
unsigned GraphicsMode;
unsigned MaxIndex;
unsigned MaxRed;
unsigned MaxGreen;
unsigned MaxBlue;
char PaletteId[20];
} CUTPalHeader;
static void InsertRow(ssize_t depth,unsigned char *p,ssize_t y,Image *image)
{
ExceptionInfo
*exception;
size_t bit; ssize_t x;
register PixelPacket *q;
IndexPacket index;
register IndexPacket *indexes;
index=(IndexPacket) 0;
exception=(&image->exception);
switch (depth)
{
case 1: /* Convert bitmap scanline. */
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < ((ssize_t) image->columns-7); x+=8)
{
for (bit=0; bit < 8; bit++)
{
index=(IndexPacket) ((((*p) & (0x80 >> bit)) != 0) ? 0x01 : 0x00);
SetPixelIndex(indexes+x+bit,index);
}
p++;
}
if ((image->columns % 8) != 0)
{
for (bit=0; bit < (image->columns % 8); bit++)
{
index=(IndexPacket) ((((*p) & (0x80 >> bit)) != 0) ? 0x01 : 0x00);
SetPixelIndex(indexes+x+bit,index);
}
p++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
break;
}
case 2: /* Convert PseudoColor scanline. */
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < ((ssize_t) image->columns-1); x+=2)
{
index=ConstrainColormapIndex(image,(*p >> 6) & 0x3);
SetPixelIndex(indexes+x,index);
index=ConstrainColormapIndex(image,(*p >> 4) & 0x3);
SetPixelIndex(indexes+x,index);
index=ConstrainColormapIndex(image,(*p >> 2) & 0x3);
SetPixelIndex(indexes+x,index);
index=ConstrainColormapIndex(image,(*p) & 0x3);
SetPixelIndex(indexes+x+1,index);
p++;
}
if ((image->columns % 4) != 0)
{
index=ConstrainColormapIndex(image,(*p >> 6) & 0x3);
SetPixelIndex(indexes+x,index);
if ((image->columns % 4) >= 1)
{
index=ConstrainColormapIndex(image,(*p >> 4) & 0x3);
SetPixelIndex(indexes+x,index);
if ((image->columns % 4) >= 2)
{
index=ConstrainColormapIndex(image,(*p >> 2) & 0x3);
SetPixelIndex(indexes+x,index);
}
}
p++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
break;
}
case 4: /* Convert PseudoColor scanline. */
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < ((ssize_t) image->columns-1); x+=2)
{
index=ConstrainColormapIndex(image,(*p >> 4) & 0xf);
SetPixelIndex(indexes+x,index);
index=ConstrainColormapIndex(image,(*p) & 0xf);
SetPixelIndex(indexes+x+1,index);
p++;
}
if ((image->columns % 2) != 0)
{
index=ConstrainColormapIndex(image,(*p >> 4) & 0xf);
SetPixelIndex(indexes+x,index);
p++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
break;
}
case 8: /* Convert PseudoColor scanline. */
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL) break;
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < (ssize_t) image->columns; x++)
{
index=ConstrainColormapIndex(image,*p);
SetPixelIndex(indexes+x,index);
p++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
break;
}
}
/*
Compute the number of colors in Grayed R[i]=G[i]=B[i] image
*/
static int GetCutColors(Image *image)
{
ExceptionInfo
*exception;
Quantum
intensity,
scale_intensity;
register PixelPacket
*q;
ssize_t
x,
y;
exception=(&image->exception);
intensity=0;
scale_intensity=ScaleCharToQuantum(16);
for (y=0; y < (ssize_t) image->rows; y++)
{
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
for (x=0; x < (ssize_t) image->columns; x++)
{
if (intensity < GetPixelRed(q))
intensity=GetPixelRed(q);
if (intensity >= scale_intensity)
return(255);
q++;
}
}
if (intensity < ScaleCharToQuantum(2))
return(2);
if (intensity < ScaleCharToQuantum(16))
return(16);
return((int) intensity);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d C U T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadCUTImage() reads an CUT X 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 ReadCUTImage method is:
%
% Image *ReadCUTImage(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 *ReadCUTImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
Image *image,*palette;
ImageInfo *clone_info;
MagickBooleanType status;
MagickOffsetType
offset;
size_t EncodedByte;
unsigned char RunCount,RunValue,RunCountMasked;
CUTHeader Header;
CUTPalHeader PalHeader;
ssize_t depth;
ssize_t i,j;
ssize_t ldblk;
unsigned char *BImgBuff=NULL,*ptrB;
PixelPacket *q;
/*
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);
}
/*
Read CUT image.
*/
palette=NULL;
clone_info=NULL;
Header.Width=ReadBlobLSBShort(image);
Header.Height=ReadBlobLSBShort(image);
Header.Reserved=ReadBlobLSBShort(image);
if (Header.Width==0 || Header.Height==0 || Header.Reserved!=0)
CUT_KO: ThrowReaderException(CorruptImageError,"ImproperImageHeader");
/*---This code checks first line of image---*/
EncodedByte=ReadBlobLSBShort(image);
RunCount=(unsigned char) ReadBlobByte(image);
RunCountMasked=RunCount & 0x7F;
ldblk=0;
while((int) RunCountMasked!=0) /*end of line?*/
{
i=1;
if((int) RunCount<0x80) i=(ssize_t) RunCountMasked;
offset=SeekBlob(image,TellBlob(image)+i,SEEK_SET);
if (offset < 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
if(EOFBlob(image) != MagickFalse) goto CUT_KO; /*wrong data*/
EncodedByte-=i+1;
ldblk+=(ssize_t) RunCountMasked;
RunCount=(unsigned char) ReadBlobByte(image);
if(EOFBlob(image) != MagickFalse) goto CUT_KO; /*wrong data: unexpected eof in line*/
RunCountMasked=RunCount & 0x7F;
}
if(EncodedByte!=1) goto CUT_KO; /*wrong data: size incorrect*/
i=0; /*guess a number of bit planes*/
if(ldblk==(int) Header.Width) i=8;
if(2*ldblk==(int) Header.Width) i=4;
if(8*ldblk==(int) Header.Width) i=1;
if(i==0) goto CUT_KO; /*wrong data: incorrect bit planes*/
depth=i;
image->columns=Header.Width;
image->rows=Header.Height;
image->depth=8;
image->colors=(size_t) (GetQuantumRange(1UL*i)+1);
if (image_info->ping) goto Finish;
/* ----- Do something with palette ----- */
if ((clone_info=CloneImageInfo(image_info)) == NULL) goto NoPalette;
i=(ssize_t) strlen(clone_info->filename);
j=i;
while(--i>0)
{
if(clone_info->filename[i]=='.')
{
break;
}
if(clone_info->filename[i]=='/' || clone_info->filename[i]=='\\' ||
clone_info->filename[i]==':' )
{
i=j;
break;
}
}
(void) CopyMagickString(clone_info->filename+i,".PAL",(size_t)
(MaxTextExtent-i));
if((clone_info->file=fopen_utf8(clone_info->filename,"rb"))==NULL)
{
(void) CopyMagickString(clone_info->filename+i,".pal",(size_t)
(MaxTextExtent-i));
if((clone_info->file=fopen_utf8(clone_info->filename,"rb"))==NULL)
{
clone_info->filename[i]='\0';
if((clone_info->file=fopen_utf8(clone_info->filename,"rb"))==NULL)
{
clone_info=DestroyImageInfo(clone_info);
clone_info=NULL;
goto NoPalette;
}
}
}
if( (palette=AcquireImage(clone_info))==NULL ) goto NoPalette;
status=OpenBlob(clone_info,palette,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
ErasePalette:
palette=DestroyImage(palette);
palette=NULL;
goto NoPalette;
}
if(palette!=NULL)
{
(void) ReadBlob(palette,2,(unsigned char *) PalHeader.FileId);
if(strncmp(PalHeader.FileId,"AH",2) != 0) goto ErasePalette;
PalHeader.Version=ReadBlobLSBShort(palette);
PalHeader.Size=ReadBlobLSBShort(palette);
PalHeader.FileType=(char) ReadBlobByte(palette);
PalHeader.SubType=(char) ReadBlobByte(palette);
PalHeader.BoardID=ReadBlobLSBShort(palette);
PalHeader.GraphicsMode=ReadBlobLSBShort(palette);
PalHeader.MaxIndex=ReadBlobLSBShort(palette);
PalHeader.MaxRed=ReadBlobLSBShort(palette);
PalHeader.MaxGreen=ReadBlobLSBShort(palette);
PalHeader.MaxBlue=ReadBlobLSBShort(palette);
(void) ReadBlob(palette,20,(unsigned char *) PalHeader.PaletteId);
if(PalHeader.MaxIndex<1) goto ErasePalette;
image->colors=PalHeader.MaxIndex+1;
if (AcquireImageColormap(image,image->colors) == MagickFalse) goto NoMemory;
if(PalHeader.MaxRed==0) PalHeader.MaxRed=(unsigned int) QuantumRange; /*avoid division by 0*/
if(PalHeader.MaxGreen==0) PalHeader.MaxGreen=(unsigned int) QuantumRange;
if(PalHeader.MaxBlue==0) PalHeader.MaxBlue=(unsigned int) QuantumRange;
for(i=0;i<=(int) PalHeader.MaxIndex;i++)
{ /*this may be wrong- I don't know why is palette such strange*/
j=(ssize_t) TellBlob(palette);
if((j % 512)>512-6)
{
j=((j / 512)+1)*512;
offset=SeekBlob(palette,j,SEEK_SET);
if (offset < 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
}
image->colormap[i].red=(Quantum) ReadBlobLSBShort(palette);
if (QuantumRange != (Quantum) PalHeader.MaxRed)
{
image->colormap[i].red=ClampToQuantum(((double)
image->colormap[i].red*QuantumRange+(PalHeader.MaxRed>>1))/
PalHeader.MaxRed);
}
image->colormap[i].green=(Quantum) ReadBlobLSBShort(palette);
if (QuantumRange != (Quantum) PalHeader.MaxGreen)
{
image->colormap[i].green=ClampToQuantum
(((double) image->colormap[i].green*QuantumRange+(PalHeader.MaxGreen>>1))/PalHeader.MaxGreen);
}
image->colormap[i].blue=(Quantum) ReadBlobLSBShort(palette);
if (QuantumRange != (Quantum) PalHeader.MaxBlue)
{
image->colormap[i].blue=ClampToQuantum
(((double)image->colormap[i].blue*QuantumRange+(PalHeader.MaxBlue>>1))/PalHeader.MaxBlue);
}
}
}
NoPalette:
if(palette==NULL)
{
image->colors=256;
if (AcquireImageColormap(image,image->colors) == MagickFalse)
{
NoMemory:
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
for (i=0; i < (ssize_t)image->colors; i++)
{
image->colormap[i].red=ScaleCharToQuantum((unsigned char) i);
image->colormap[i].green=ScaleCharToQuantum((unsigned char) i);
image->colormap[i].blue=ScaleCharToQuantum((unsigned char) i);
}
}
/* ----- Load RLE compressed raster ----- */
BImgBuff=(unsigned char *) AcquireQuantumMemory((size_t) ldblk,
sizeof(*BImgBuff)); /*Ldblk was set in the check phase*/
if(BImgBuff==NULL) goto NoMemory;
offset=SeekBlob(image,6 /*sizeof(Header)*/,SEEK_SET);
if (offset < 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
for (i=0; i < (int) Header.Height; i++)
{
EncodedByte=ReadBlobLSBShort(image);
ptrB=BImgBuff;
j=ldblk;
RunCount=(unsigned char) ReadBlobByte(image);
RunCountMasked=RunCount & 0x7F;
while ((int) RunCountMasked != 0)
{
if((ssize_t) RunCountMasked>j)
{ /*Wrong Data*/
RunCountMasked=(unsigned char) j;
if(j==0)
{
break;
}
}
if((int) RunCount>0x80)
{
RunValue=(unsigned char) ReadBlobByte(image);
(void) ResetMagickMemory(ptrB,(int) RunValue,(size_t) RunCountMasked);
}
else {
(void) ReadBlob(image,(size_t) RunCountMasked,ptrB);
}
ptrB+=(int) RunCountMasked;
j-=(int) RunCountMasked;
if (EOFBlob(image) != MagickFalse) goto Finish; /* wrong data: unexpected eof in line */
RunCount=(unsigned char) ReadBlobByte(image);
RunCountMasked=RunCount & 0x7F;
}
InsertRow(depth,BImgBuff,i,image);
}
(void) SyncImage(image);
/*detect monochrome image*/
if(palette==NULL)
{ /*attempt to detect binary (black&white) images*/
if ((image->storage_class == PseudoClass) &&
(IsGrayImage(image,&image->exception) != MagickFalse))
{
if(GetCutColors(image)==2)
{
for (i=0; i < (ssize_t)image->colors; i++)
{
register Quantum
sample;
sample=ScaleCharToQuantum((unsigned char) i);
if(image->colormap[i].red!=sample) goto Finish;
if(image->colormap[i].green!=sample) goto Finish;
if(image->colormap[i].blue!=sample) goto Finish;
}
image->colormap[1].red=image->colormap[1].green=
image->colormap[1].blue=QuantumRange;
for (i=0; i < (ssize_t)image->rows; i++)
{
q=QueueAuthenticPixels(image,0,i,image->columns,1,exception);
for (j=0; j < (ssize_t)image->columns; j++)
{
if (GetPixelRed(q) == ScaleCharToQuantum(1))
{
SetPixelRed(q,QuantumRange);
SetPixelGreen(q,QuantumRange);
SetPixelBlue(q,QuantumRange);
}
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse) goto Finish;
}
}
}
}
Finish:
if (BImgBuff != NULL)
BImgBuff=(unsigned char *) RelinquishMagickMemory(BImgBuff);
if (palette != NULL)
palette=DestroyImage(palette);
if (clone_info != NULL)
clone_info=DestroyImageInfo(clone_info);
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r C U T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterCUTImage() adds attributes for the CUT image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterCUTImage method is:
%
% size_t RegisterCUTImage(void)
%
*/
ModuleExport size_t RegisterCUTImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("CUT");
entry->decoder=(DecodeImageHandler *) ReadCUTImage;
entry->seekable_stream=MagickTrue;
entry->description=ConstantString("DR Halo");
entry->module=ConstantString("CUT");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r C U T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterCUTImage() removes format registrations made by the
% CUT module from the list of supported formats.
%
% The format of the UnregisterCUTImage method is:
%
% UnregisterCUTImage(void)
%
*/
ModuleExport void UnregisterCUTImage(void)
{
(void) UnregisterMagickInfo("CUT");
}

4187
ImageMagick/coders/dcm.c Normal file

File diff suppressed because it is too large Load diff

1023
ImageMagick/coders/dds.c Normal file

File diff suppressed because it is too large Load diff

271
ImageMagick/coders/debug.c Normal file
View file

@ -0,0 +1,271 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% DDDD EEEEE BBBB U U GGGG %
% D D E B B U U G %
% D D EEE BBBB U U G GG %
% D D E B B U U G G %
% DDDD EEEEE BBBB UUU GGG %
% %
% %
% Image Pixel Values for Debugging. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/annotate.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/constitute.h"
#include "magick/draw.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/geometry.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/option.h"
#include "magick/pixel-private.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/statistic.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteDEBUGImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r D E B U G I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterDEBUGImage() adds attributes for the DEBUG image format to the
% list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterDEBUGImage method is:
%
% size_t RegisterDEBUGImage(void)
%
*/
ModuleExport size_t RegisterDEBUGImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("DEBUG");
entry->encoder=(EncodeImageHandler *) WriteDEBUGImage;
entry->raw=MagickTrue;
entry->stealth=MagickTrue;
entry->description=ConstantString("Image pixel values for debugging");
entry->module=ConstantString("DEBUG");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r D E B U G I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterDEBUGImage() removes format registrations made by the
% DEBUG module from the list of supported format.
%
% The format of the UnregisterDEBUGImage method is:
%
% UnregisterDEBUGImage(void)
%
*/
ModuleExport void UnregisterDEBUGImage(void)
{
(void) UnregisterMagickInfo("DEBUG");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e D E B U G I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteDEBUGImage writes the image pixel values with 20 places of precision.
%
% The format of the WriteDEBUGImage method is:
%
% MagickBooleanType WriteDEBUGImage(const ImageInfo *image_info,
% Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteDEBUGImage(const ImageInfo *image_info,
Image *image)
{
char
buffer[MaxTextExtent],
colorspace[MaxTextExtent],
tuple[MaxTextExtent];
ssize_t
y;
MagickBooleanType
status;
MagickOffsetType
scene;
MagickPixelPacket
pixel;
register const IndexPacket
*indexes;
register const PixelPacket
*p;
register ssize_t
x;
/*
Open output image file.
*/
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,WriteBlobMode,&image->exception);
if (status == MagickFalse)
return(status);
scene=0;
do
{
(void) CopyMagickString(colorspace,CommandOptionToMnemonic(
MagickColorspaceOptions,(ssize_t) image->colorspace),MaxTextExtent);
LocaleLower(colorspace);
image->depth=GetImageQuantumDepth(image,MagickTrue);
if (image->matte != MagickFalse)
(void) ConcatenateMagickString(colorspace,"a",MaxTextExtent);
(void) FormatLocaleString(buffer,MaxTextExtent,
"# ImageMagick pixel debugging: %.20g,%.20g,%.20g,%s\n",(double)
image->columns,(double) image->rows,(double) ((MagickOffsetType)
GetQuantumRange(image->depth)),colorspace);
(void) WriteBlobString(image,buffer);
GetMagickPixelPacket(image,&pixel);
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);
for (x=0; x < (ssize_t) image->columns; x++)
{
(void) FormatLocaleString(buffer,MaxTextExtent,"%.20g,%.20g: ",(double)
x,(double) y);
(void) WriteBlobString(image,buffer);
SetMagickPixelPacket(image,p,indexes+x,&pixel);
(void) FormatLocaleString(tuple,MaxTextExtent,"%.20g,%.20g,%.20g ",
(double) pixel.red,(double) pixel.green,(double) pixel.blue);
if (pixel.colorspace == CMYKColorspace)
{
char
black[MaxTextExtent];
(void) FormatLocaleString(black,MaxTextExtent,",%.20g ",
(double) pixel.index);
(void) ConcatenateMagickString(tuple,black,MaxTextExtent);
}
if (pixel.matte != MagickFalse)
{
char
alpha[MaxTextExtent];
(void) FormatLocaleString(alpha,MaxTextExtent,",%.20g ",
(double) (QuantumRange-pixel.opacity));
(void) ConcatenateMagickString(tuple,alpha,MaxTextExtent);
}
(void) WriteBlobString(image,tuple);
(void) WriteBlobString(image,"\n");
p++;
}
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
if (GetNextImageInList(image) == (Image *) NULL)
break;
image=SyncNextImageInList(image);
status=SetImageProgress(image,SaveImagesTag,scene++,
GetImageListLength(image));
if (status == MagickFalse)
break;
} while (image_info->adjoin != MagickFalse);
(void) CloseBlob(image);
return(MagickTrue);
}

1288
ImageMagick/coders/dib.c Normal file

File diff suppressed because it is too large Load diff

993
ImageMagick/coders/djvu.c Normal file
View file

@ -0,0 +1,993 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% DDDD J V V U U %
% D D J V V U U %
% D D J V V U U %
% D D J J V V U U %
% DDDD JJJ V UUU %
% %
% %
% Read DjVu Images. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colormap.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#if defined(MAGICKCORE_DJVU_DELEGATE)
#include <libdjvu/ddjvuapi.h>
#endif
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s D J V U %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsDJVU() returns MagickTrue if the image format type, identified by the
% magick string, is DJVU.
%
% The format of the IsDJVU method is:
%
% MagickBooleanType IsDJVU(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsDJVU(const unsigned char *magick,const size_t length)
{
if (length < 8)
return(MagickFalse);
if (memcmp(magick,"AT&TFORM",8) == 0)
return(MagickTrue);
return(MagickFalse);
}
#if defined(MAGICKCORE_DJVU_DELEGATE)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d D J V U I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadDJVUImage() reads DJVU image and returns it. It allocates the memory
% necessary for the new Image structure and returns a pointer to the new
% image or set of images.
%
% The format of the ReadDJVUImage method is:
%
% Image *ReadDJVUImage(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.
%
*/
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
typedef struct _LoadContext
LoadContext;
struct _LoadContext
{
ddjvu_context_t* context;
ddjvu_document_t *document;
ddjvu_page_t *page;
int streamid;
int pages;
Image *image;
};
#define BLOCKSIZE 65536
#if 0
static void
pump_data(Image *image, LoadContext* lc)
{
int blocksize = BLOCKSIZE;
char data[BLOCKSIZE];
int size;
/* i might check for a condition! */
while ((size = (size_t) ReadBlob(image,(size_t) blocksize,data)) == blocksize) {
ddjvu_stream_write(lc->document, lc->streamid, data, size);
}
if (size)
ddjvu_stream_write(lc->document, lc->streamid, data, size);
ddjvu_stream_close(lc->document, lc->streamid, 0);
}
#endif
/* returns NULL only after all is delivered! */
static ddjvu_message_t*
pump_data_until_message(LoadContext *lc,Image *image) /* ddjvu_context_t *context, type ddjvu_document_type_t */
{
size_t blocksize = BLOCKSIZE;
unsigned char data[BLOCKSIZE];
size_t size;
ddjvu_message_t *message;
/* i might check for a condition! */
size=0;
while (!(message = ddjvu_message_peek(lc->context))
&& (size = (size_t) ReadBlob(image,(size_t) blocksize,data)) == blocksize) {
ddjvu_stream_write(lc->document, lc->streamid, (char *) data, size);
}
if (message)
return message;
if (size)
ddjvu_stream_write(lc->document, lc->streamid, (char *) data, size);
ddjvu_stream_close(lc->document, lc->streamid, 0);
return NULL;
}
#define DEBUG 0
#if DEBUG
static const char*
message_tag_name(ddjvu_message_tag_t tag)
{
static char* names[] =
{
"ERROR",
"INFO",
"NEWSTREAM",
"DOCINFO",
"PAGEINFO",
"RELAYOUT",
"REDISPLAY",
"CHUNK",
"THUMBNAIL",
"PROGRESS",
};
if (tag <= DDJVU_PROGRESS)
return names[tag];
else {
/* bark! */
return 0;
}
}
#endif
/* write out nice info on the message,
* and store in *user* data the info on progress.
* */
int
process_message(ddjvu_message_t *message)
{
#if 0
ddjvu_context_t* context= message->m_any.context;
#endif
if (! message)
return(-1);
#if DEBUG
printf("*** %s: %s.\n",__FUNCTION__, message_tag_name(message->m_any.tag));
#endif
switch (message->m_any.tag){
case DDJVU_DOCINFO:
{
ddjvu_document_t* document= message->m_any.document;
/* ddjvu_document_decoding_status is set by libdjvu! */
/* we have some info on the document */
LoadContext *lc = (LoadContext *) ddjvu_document_get_user_data(document);
lc->pages = ddjvu_document_get_pagenum(document);
#if DEBUG
printf("the doc has %d pages\n", ddjvu_document_get_pagenum(document));
#endif
break;
}
case DDJVU_CHUNK:
#if DEBUG
printf("the name of the chunk is: %s\n", message->m_chunk.chunkid);
#endif
break;
case DDJVU_RELAYOUT:
case DDJVU_PAGEINFO:
{
#if 0
ddjvu_page_t* page = message->m_any.page;
page_info* info = ddjvu_page_get_user_data(page);
printf("page decoding status: %d %s%s%s\n",
ddjvu_page_decoding_status(page),
status_color, status_name(ddjvu_page_decoding_status(page)), color_reset);
printf("the page LAYOUT changed: width x height: %d x %d @ %d dpi. Version %d, type %d\n",
// printf("page info:\n width x height: %d x %d @ %d dpi, version %d, type %d\n",
ddjvu_page_get_width(page),
ddjvu_page_get_height(page),
ddjvu_page_get_resolution(page),
ddjvu_page_get_version(page),
/* DDJVU_PAGETYPE_BITONAL */
ddjvu_page_get_type(page));
info->info = 1;
#endif
break;
}
case DDJVU_REDISPLAY:
{
#if 0
ddjvu_page_t* page = message->m_any.page;
page_info* info = ddjvu_page_get_user_data(page);
printf("the page can/should be REDISPLAYED\n");
info->display = 1;
#endif
break;
}
case DDJVU_PROGRESS:
#if DEBUG
printf("PROGRESS:\n");
#endif
break;
case DDJVU_ERROR:
printf("simply ERROR!\n message:\t%s\nfunction:\t%s(file %s)\nlineno:\t%d\n",
message->m_error.message,
message->m_error.function,
message->m_error.filename,
message->m_error.lineno);
break;
case DDJVU_INFO:
#if DEBUG
printf("INFO: %s!\n", message->m_info.message);
#endif
break;
default:
printf("unexpected\n");
};
return(message->m_any.tag);
}
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
#define RGB 1
/*
* DjVu advertised readiness to provide bitmap: So get it!
* we use the RGB format!
*/
static void
get_page_image(LoadContext *lc, ddjvu_page_t *page, int x, int y, int w, int h, const ImageInfo *image_info ) {
ddjvu_format_t
*format;
ddjvu_page_type_t
type;
Image
*image;
int
ret,
stride;
unsigned char
*q;
ddjvu_rect_t rect;
rect.x = x;
rect.y = y;
rect.w = (unsigned int) w; /* /10 */
rect.h = (unsigned int) h; /* /10 */
image = lc->image;
type = ddjvu_page_get_type(lc->page);
/* stride of this temporary buffer: */
stride = (type == DDJVU_PAGETYPE_BITONAL)?
(image->columns + 7)/8 : image->columns *3;
q = (unsigned char *) AcquireQuantumMemory(image->rows,stride);
if (q == (unsigned char *) NULL)
return;
format = ddjvu_format_create(
(type == DDJVU_PAGETYPE_BITONAL)?DDJVU_FORMAT_LSBTOMSB : DDJVU_FORMAT_RGB24,
/* DDJVU_FORMAT_RGB24
* DDJVU_FORMAT_RGBMASK32*/
/* DDJVU_FORMAT_RGBMASK32 */
0, NULL);
#if 0
/* fixme: ThrowReaderException is a macro, which uses `exception' variable */
if (format == NULL)
{
abort();
/* ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); */
}
#endif
ddjvu_format_set_row_order(format, 1);
ddjvu_format_set_y_direction(format, 1);
ret = ddjvu_page_render(page,
DDJVU_RENDER_COLOR, /* ddjvu_render_mode_t */
&rect,
&rect, /* mmc: ?? */
format,
stride, /* ?? */
(char*)q);
(void) ret;
ddjvu_format_release(format);
if (type == DDJVU_PAGETYPE_BITONAL) {
/* */
#if DEBUG
printf("%s: expanding BITONAL page/image\n", __FUNCTION__);
#endif
register IndexPacket *indexes;
size_t bit, byte;
for (y=0; y < (ssize_t) image->rows; y++)
{
PixelPacket * o = QueueAuthenticPixels(image,0,y,image->columns,1,&image->exception);
if (o == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
bit=0;
byte=0;
/* fixme: the non-aligned, last =<7 bits ! that's ok!!!*/
for (x= 0; x < (ssize_t) image->columns; x++)
{
if (bit == 0) byte= (size_t) q[(y * stride) + (x / 8)];
if (indexes != (IndexPacket *) NULL)
SetPixelIndex(indexes+x,(IndexPacket) (((byte & 0x01) != 0) ? 0x00 : 0x01));
bit++;
if (bit == 8)
bit=0;
byte>>=1;
}
if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
break;
}
if (!image->ping)
SyncImage(image);
} else {
#if DEBUG
printf("%s: expanding PHOTO page/image\n", __FUNCTION__);
#endif
/* now transfer line-wise: */
ssize_t i;
#if 0
/* old: */
char* r;
#else
register PixelPacket *r;
unsigned char *s;
#endif
s=q;
for (i = 0;i< (ssize_t) image->rows; i++)
{
#if DEBUG
if (i % 1000 == 0) printf("%d\n",i);
#endif
r = QueueAuthenticPixels(image,0,i,image->columns,1,&image->exception);
if (r == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelRed(r,ScaleCharToQuantum(*s++));
SetPixelGreen(r,ScaleCharToQuantum(*s++));
SetPixelBlue(r,ScaleCharToQuantum(*s++));
r++;
}
SyncAuthenticPixels(image,&image->exception);
}
}
q=(unsigned char *) RelinquishMagickMemory(q);
}
#if defined(MAGICKCORE_DJVU_DELEGATE)
#if 0
static int
get_page_line(LoadContext *lc, int row, QuantumInfo* quantum_info)
{
ddjvu_format_t
*format;
int
ret;
size_t
stride;
unsigned char
*q;
ddjvu_rect_t rect, pagerect;
rect.x = 0;
rect.y = row;
rect.w = lc->image->columns; /* /10 */
rect.h = 1; /* /10 */
pagerect.x = 0;
pagerect.y = 0;
pagerect.w = lc->image->columns;
pagerect.h = lc->image->rows;
format = ddjvu_format_create(
#if RGB
DDJVU_FORMAT_RGB24
#else
DDJVU_FORMAT_GREY8
#endif
,
0, NULL);
ddjvu_format_set_row_order(format, 1);
ddjvu_format_set_y_direction(format, 1);
stride=1;
#if RGB
stride=3;
#endif
q = (unsigned char *) AcquireQuantumMemory(lc->image->columns,stride);
ret = ddjvu_page_render(lc->page,
DDJVU_RENDER_COLOR, /* ddjvu_render_mode_t */
&pagerect,
&rect, /* mmc: ?? */
format,
pagerect.w * 3, /* ?? */
(char*)q);
ImportQuantumPixels(lc->image,
(CacheView *) NULL,
quantum_info,
#if RGB
RGBQuantum
#else
GrayQuantum
#endif
,q,&lc->image->exception);
q=(unsigned char *) RelinquishMagickMemory(q);
ddjvu_format_release(format);
return ret;
}
#endif
#endif
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d O n e D J V U I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadOneDJVUImage() reads a Portable Network Graphics (DJVU) image file
% (minus the 8-byte signature) 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 ReadOneDJVUImage method is:
%
% Image *ReadOneDJVUImage(MngInfo *mng_info, const ImageInfo *image_info,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o mng_info: Specifies a pointer to a MngInfo structure.
%
% o image_info: the image info.
%
% o exception: return any errors or warnings in this structure.
%
*/
static inline double MagickMax(const double x,const double y)
{
if (x > y)
return(x);
return(y);
}
static Image *ReadOneDJVUImage(LoadContext* lc,const int pagenum,
const ImageInfo *image_info,ExceptionInfo *exception)
{
ddjvu_page_type_t
type;
ddjvu_pageinfo_t info;
ddjvu_message_t *message;
Image *image;
int logging;
int tag;
/* so, we know that the page is there! Get its dimension, and */
/* Read one DJVU image */
image = lc->image;
/* register PixelPacket *q; */
logging=LogMagickEvent(CoderEvent,GetMagickModule(), " enter ReadOneDJVUImage()");
(void) logging;
#if DEBUG
printf("==== Loading the page %d\n", pagenum);
#endif
lc->page = ddjvu_page_create_by_pageno(lc->document, pagenum); /* 0? */
/* pump data untill the page is ready for rendering. */
tag=(-1);
do {
while ((message = ddjvu_message_peek(lc->context)))
{
tag=process_message(message);
if (tag == 0) break;
ddjvu_message_pop(lc->context);
}
/* fixme: maybe exit? */
/* if (lc->error) break; */
message = pump_data_until_message(lc,image);
if (message)
do {
tag=process_message(message);
if (tag == 0) break;
ddjvu_message_pop(lc->context);
} while ((message = ddjvu_message_peek(lc->context)));
} while (!ddjvu_page_decoding_done(lc->page));
ddjvu_document_get_pageinfo(lc->document, pagenum, &info);
image->x_resolution = (float) info.dpi;
image->y_resolution =(float) info.dpi;
if (image_info->density != (char *) NULL)
{
int
flags;
GeometryInfo
geometry_info;
/*
Set rendering resolution.
*/
flags=ParseGeometry(image_info->density,&geometry_info);
image->x_resolution=geometry_info.rho;
image->y_resolution=geometry_info.sigma;
if ((flags & SigmaValue) == 0)
image->y_resolution=image->x_resolution;
info.width=(int) (info.width*image->x_resolution/info.dpi);
info.height=(int) (info.height*image->y_resolution/info.dpi);
info.dpi=(int) MagickMax(image->x_resolution,image->y_resolution);
}
type = ddjvu_page_get_type(lc->page);
/* double -> float! */
/* image->gamma = (float)ddjvu_page_get_gamma(lc->page); */
/* mmc: set image->depth */
/* mmc: This from the type */
image->columns=(size_t) info.width;
image->rows=(size_t) info.height;
/* mmc: bitonal should be palettized, and compressed! */
if (type == DDJVU_PAGETYPE_BITONAL){
image->colorspace = GRAYColorspace;
image->storage_class = PseudoClass;
image->depth = 8UL; /* i only support that? */
image->colors= 2;
if (AcquireImageColormap(image,image->colors) == MagickFalse)
ThrowReaderException(ResourceLimitError,
"MemoryAllocationFailed");
} else {
image->colorspace = RGBColorspace;
image->storage_class = DirectClass;
/* fixme: MAGICKCORE_QUANTUM_DEPTH ?*/
image->depth = 8UL; /* i only support that? */
image->matte = MagickTrue;
/* is this useful? */
}
#if DEBUG
printf("now filling %.20g x %.20g\n",(double) image->columns,(double)
image->rows);
#endif
#if 1 /* per_line */
/* q = QueueAuthenticPixels(image,0,0,image->columns,image->rows); */
get_page_image(lc, lc->page, 0, 0, info.width, info.height, image_info);
#else
int i;
for (i = 0;i< image->rows; i++)
{
printf("%d\n",i);
q = QueueAuthenticPixels(image,0,i,image->columns,1);
get_page_line(lc, i, quantum_info);
SyncAuthenticPixels(image);
}
#endif /* per_line */
#if DEBUG
printf("END: finished filling %.20g x %.20g\n",(double) image->columns,
(double) image->rows);
#endif
if (!image->ping)
SyncImage(image);
/* indexes=GetAuthenticIndexQueue(image); */
/* mmc: ??? Convert PNM pixels to runlength-encoded MIFF packets. */
/* image->colors = */
/* how is the line padding / stride? */
if (lc->page) {
ddjvu_page_release(lc->page);
lc->page = NULL;
}
/* image->page.y=mng_info->y_off[mng_info->object_id]; */
if (tag == 0)
image=DestroyImage(image);
return image;
/* end of reading one DJVU page/image */
}
#if 0
/* palette */
if (AcquireImageColormap(image,2) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
/*
Monochrome colormap. mmc: this the default!
*/
image->colormap[0].red=QuantumRange;
image->colormap[0].green=QuantumRange;
image->colormap[0].blue=QuantumRange;
image->colormap[1].red=0;
image->colormap[1].green=0;
image->colormap[1].blue=0;
#endif
static void djvu_close_lc(LoadContext* lc)
{
if (lc->document)
ddjvu_document_release(lc->document);
if (lc->context)
ddjvu_context_release(lc->context);
if (lc->page)
ddjvu_page_release(lc->page);
RelinquishMagickMemory(lc);
}
static Image *ReadDJVUImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
const char
*url;
ddjvu_message_t
*message;
Image
*image,
*images;
int
logging,
use_cache;
LoadContext
*lc;
MagickBooleanType
status;
register ssize_t
i;
/*
* 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);
logging = LogMagickEvent(CoderEvent,GetMagickModule(),"enter ReadDJVUImage()");
(void) logging;
image = AcquireImage(image_info); /* mmc: ?? */
lc = (LoadContext *) NULL;
status = OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
ThrowReaderException(FileOpenError,"UnableToOpenFile");
/*
Verify DJVU signature.
*/
#if 0
count = ReadBlob(image,8,(unsigned char *) magic_number);
/* IsDJVU(const unsigned char *magick,const size_t length) */
if (memcmp(magic_number,"AT&TFORM",8) != 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
#endif
/*
* Allocate a LoadContext structure.
*/
lc = (LoadContext *) AcquireMagickMemory(sizeof(*lc));
if (lc == NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
/*
* Initialize members of the MngInfo structure.
*/
(void) ResetMagickMemory(lc,0,sizeof(LoadContext));
lc->image = image;
lc->pages = 0;
lc->context = ddjvu_context_create("ImageMagick djvu loader"); /* g_program_name */
ddjvu_cache_set_size(lc->context, 1); /* right? */
use_cache = 0;
/* document: here we don't have a filename, but, for the sake of generality, a FILE* ! */
url="http://www.imagemagick.org/fake.djvu";
lc->document = ddjvu_document_create(lc->context, url, use_cache); /* don't cache */
ddjvu_document_set_user_data(lc->document, lc);
/* now we wait the message-request for data: */
message = ddjvu_message_wait(lc->context);
if (message->m_any.tag != DDJVU_NEWSTREAM) {
/* fixme: the djvu context, document! */
ddjvu_document_release(lc->document);
ddjvu_context_release(lc->context);
RelinquishMagickMemory(lc);
ThrowReaderException(ResourceLimitError,"Djvu initial message: unexpected type");
return NULL; /* error! */
};
lc->streamid = message->m_newstream.streamid;
ddjvu_message_pop(lc->context);
message = pump_data_until_message(lc,image);
/* now process the messages: */
if (message) do {
process_message(message);
ddjvu_message_pop(lc->context);
} while ((message = ddjvu_message_peek(lc->context)));
/* fixme: i hope we have not read any messages pertinent(?) related to the page itself! */
while (lc->pages == 0) {
message = ddjvu_message_wait(lc->context);
process_message(message);
ddjvu_message_pop(lc->context);
}
images=NewImageList();
i=0;
if (image_info->number_scenes != 0)
i=image_info->scene;
for ( ; i < (ssize_t) lc->pages; i++)
{
image=ReadOneDJVUImage(lc,i,image_info,exception);
if (image == (Image *) NULL)
break;
image->scene=i;
AppendImageToList(&images,CloneImageList(image,exception));
images->extent=GetBlobSize(image);
if (image_info->number_scenes != 0)
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
}
djvu_close_lc(lc);
(void) CloseBlob(images);
if (image != (Image *) NULL)
image=DestroyImageList(image);
#if 0
if ((image->page.width == 0) && (image->page.height == 0))
{
image->page.width = image->columns+image->page.x;
image->page.height = image->rows+image->page.y;
}
if (image->columns == 0 || image->rows == 0)
{
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
"exit ReadDJVUImage() with error.");
ThrowReaderException(CorruptImageError,"CorruptImage");
}
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"exit ReadDJVUImage()");
#endif
return(GetFirstImageInList(images));
}
#endif
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r D J V U I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterDJVUImage() adds attributes for the DJVU image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterDJVUImage method is:
%
% size_t RegisterDJVUImage(void)
%
*/
ModuleExport size_t RegisterDJVUImage(void)
{
char
version[MaxTextExtent];
MagickInfo
*entry;
static const char
*DJVUNote =
{
"See http://www.djvuzone.org/ for details about the DJVU format. The\n"
"DJVU 1.2 specification is available there and at\n"
"ftp://swrinde.nde.swri.edu/pub/djvu/documents/."
};
*version='\0';
#if defined(DJVU_LIBDJVU_VER_STRING)
(void) ConcatenateMagickString(version,"libdjvu ",MaxTextExtent);
(void) ConcatenateMagickString(version,DJVU_LIBDJVU_VER_STRING,MaxTextExtent);
#endif
entry=SetMagickInfo("DJVU");
#if defined(MAGICKCORE_DJVU_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadDJVUImage;
#endif
entry->raw=MagickTrue;
entry->magick=(IsImageFormatHandler *) IsDJVU;
entry->adjoin=MagickFalse;
entry->thread_support=MagickTrue;
entry->description=AcquireString("Déjà vu");
entry->module=AcquireString("DJVU");
if (*version != '\0')
entry->version=AcquireString(version);
entry->note=AcquireString(DJVUNote);
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r D J V U I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterDJVUImage() removes format registrations made by the
% DJVU module from the list of supported formats.
%
% The format of the UnregisterDJVUImage method is:
%
% UnregisterDJVUImage(void)
%
*/
ModuleExport void UnregisterDJVUImage(void)
{
(void) UnregisterMagickInfo("DJVU");
}

446
ImageMagick/coders/dng.c Normal file
View file

@ -0,0 +1,446 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% DDDD N N GGGG %
% D D NN N GS %
% D D N N N G GG %
% D D N NN G G %
% DDDD N N GGGG %
% %
% %
% Read the Digital Negative Image Format %
% %
% Software Design %
% John Cristy %
% July 1999 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/constitute.h"
#include "magick/delegate.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/geometry.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/layer.h"
#include "magick/list.h"
#include "magick/log.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/resource_.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/transform.h"
#include "magick/utility.h"
#include "magick/xml-tree.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% 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;
/*
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);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r D N G I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterDNGImage() adds attributes for the DNG image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterDNGImage method is:
%
% size_t RegisterDNGImage(void)
%
*/
ModuleExport size_t RegisterDNGImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("3FR");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Hasselblad CFV/H3D39II");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("ARW");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Sony Alpha Raw Image Format");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("DNG");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Digital Negative");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("CR2");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Canon Digital Camera Raw Image Format");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("CRW");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Canon Digital Camera Raw Image Format");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("DCR");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Kodak Digital Camera Raw Image File");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("ERF");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Epson RAW Format");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("KDC");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Kodak Digital Camera Raw Image Format");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("K25");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Kodak Digital Camera Raw Image Format");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("MEF");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Mamiya Raw Image File");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("MRW");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Sony (Minolta) Raw Image File");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("NEF");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Nikon Digital SLR Camera Raw Image File");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("NRW");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Nikon Digital SLR Camera Raw Image File");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("ORF");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Olympus Digital Camera Raw Image File");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("PEF");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Pentax Electronic File");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("RAF");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Fuji CCD-RAW Graphic File");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("RW2");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Panasonic Lumix Raw Image");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("SRF");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Sony Raw Format");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("SR2");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Sony Raw Format 2");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("X3F");
entry->decoder=(DecodeImageHandler *) ReadDNGImage;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("Sigma Camera RAW Picture File");
entry->module=ConstantString("DNG");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r D N G I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterDNGImage() removes format registrations made by the
% BIM module from the list of supported formats.
%
% The format of the UnregisterBIMImage method is:
%
% UnregisterDNGImage(void)
%
*/
ModuleExport void UnregisterDNGImage(void)
{
(void) UnregisterMagickInfo("X3F");
(void) UnregisterMagickInfo("SR2");
(void) UnregisterMagickInfo("SRF");
(void) UnregisterMagickInfo("RW2");
(void) UnregisterMagickInfo("RAF");
(void) UnregisterMagickInfo("PEF");
(void) UnregisterMagickInfo("ORF");
(void) UnregisterMagickInfo("NRW");
(void) UnregisterMagickInfo("NEF");
(void) UnregisterMagickInfo("MRW");
(void) UnregisterMagickInfo("MEF");
(void) UnregisterMagickInfo("K25");
(void) UnregisterMagickInfo("KDC");
(void) UnregisterMagickInfo("DCR");
(void) UnregisterMagickInfo("CRW");
(void) UnregisterMagickInfo("CR2");
(void) UnregisterMagickInfo("DNG");
(void) UnregisterMagickInfo("ARW");
(void) UnregisterMagickInfo("3FR");
}

242
ImageMagick/coders/dot.c Normal file
View file

@ -0,0 +1,242 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% DDDD OOO TTTTT %
% D D O O T %
% D D O O T %
% D D O O T %
% DDDD OOO T %
% %
% %
% Read/Write Graphviz DOT Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/client.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/option.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/resource_.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/utility.h"
#include "magick/xwindow-private.h"
#if defined(MAGICKCORE_GVC_DELEGATE)
#undef HAVE_CONFIG_H
#include <gvc.h>
static GVC_t
*graphic_context;
#endif
#if defined(MAGICKCORE_GVC_DELEGATE)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% 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[MaxTextExtent];
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 == 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)
return((Image *) NULL);
read_info=CloneImageInfo(image_info);
SetImageInfoBlob(read_info,(void *) NULL,0);
(void) CopyMagickString(read_info->magick,"SVG",MaxTextExtent);
(void) AcquireUniqueFilename(read_info->filename);
(void) FormatLocaleString(command,MaxTextExtent,"-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)
return ((Image *) NULL);
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);
/*
Read SVG graph.
*/
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));
}
#endif
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r D O T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterDOTImage() adds attributes for the Display Postscript image
% format to the list of supported formats. The attributes include the image
% format tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterDOTImage method is:
%
% size_t RegisterDOTImage(void)
%
*/
ModuleExport size_t RegisterDOTImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("DOT");
#if defined(MAGICKCORE_GVC_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadDOTImage;
#endif
entry->blob_support=MagickFalse;
entry->description=ConstantString("Graphviz");
entry->module=ConstantString("DOT");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("GV");
#if defined(MAGICKCORE_GVC_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadDOTImage;
#endif
entry->blob_support=MagickFalse;
entry->description=ConstantString("Graphviz");
entry->module=ConstantString("DOT");
(void) RegisterMagickInfo(entry);
#if defined(MAGICKCORE_GVC_DELEGATE)
graphic_context=gvContext();
#endif
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r D O T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterDOTImage() removes format registrations made by the
% DOT module from the list of supported formats.
%
% The format of the UnregisterDOTImage method is:
%
% UnregisterDOTImage(void)
%
*/
ModuleExport void UnregisterDOTImage(void)
{
(void) UnregisterMagickInfo("GV");
(void) UnregisterMagickInfo("DOT");
#if defined(MAGICKCORE_GVC_DELEGATE)
gvFreeContext(graphic_context);
#endif
}

588
ImageMagick/coders/dps.c Normal file
View file

@ -0,0 +1,588 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% DDDD PPPP SSSSS %
% D D P P SS %
% D D PPPP SSS %
% D D P SS %
% DDDD P SSSSS %
% %
% %
% Read Postscript Using the Display Postscript System. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/client.h"
#include "magick/colormap.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/utility.h"
#include "magick/xwindow-private.h"
#if defined(MAGICKCORE_DPS_DELEGATE)
#include <DPS/dpsXclient.h>
#include <DPS/dpsXpreview.h>
#endif
#if defined(MAGICKCORE_DPS_DELEGATE)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d D P S I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadDPSImage() reads a Adobe Postscript 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 ReadDPSImage method is:
%
% Image *ReadDPSImage(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 inline double MagickMin(const double x,const double y)
{
if (x < y)
return(x);
return(y);
}
static Image *ReadDPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
const char
*client_name;
Display
*display;
float
pixels_per_point;
Image
*image;
int
sans,
status;
Pixmap
pixmap;
register IndexPacket
*indexes;
register ssize_t
i;
register PixelPacket
*q;
register size_t
pixel;
Screen
*screen;
ssize_t
x,
y;
XColor
*colors;
XImage
*dps_image;
XRectangle
page,
bits_per_pixel;
XResourceInfo
resource_info;
XrmDatabase
resource_database;
XStandardColormap
*map_info;
XVisualInfo
*visual_info;
/*
Open X server connection.
*/
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);
display=XOpenDisplay(image_info->server_name);
if (display == (Display *) NULL)
return((Image *) NULL);
/*
Set our forgiving exception handler.
*/
(void) XSetErrorHandler(XError);
/*
Open image file.
*/
image=AcquireImage(image_info);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
return((Image *) NULL);
/*
Get user defaults from X resource database.
*/
client_name=GetClientName();
resource_database=XGetResourceDatabase(display,client_name);
XGetResourceInfo(image_info,resource_database,client_name,&resource_info);
/*
Allocate standard colormap.
*/
map_info=XAllocStandardColormap();
visual_info=(XVisualInfo *) NULL;
if (map_info == (XStandardColormap *) NULL)
ThrowReaderException(ResourceLimitError,"UnableToCreateStandardColormap")
else
{
/*
Initialize visual info.
*/
(void) CloneString(&resource_info.visual_type,"default");
visual_info=XBestVisualInfo(display,map_info,&resource_info);
map_info->colormap=(Colormap) NULL;
}
if ((map_info == (XStandardColormap *) NULL) ||
(visual_info == (XVisualInfo *) NULL))
{
image=DestroyImage(image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
return((Image *) NULL);
}
/*
Create a pixmap the appropriate size for the image.
*/
screen=ScreenOfDisplay(display,visual_info->screen);
pixels_per_point=XDPSPixelsPerPoint(screen);
if ((image->x_resolution != 0.0) && (image->y_resolution != 0.0))
pixels_per_point=MagickMin(image->x_resolution,image->y_resolution)/
DefaultResolution;
status=XDPSCreatePixmapForEPSF((DPSContext) NULL,screen,
GetBlobFileHandle(image),visual_info->depth,pixels_per_point,&pixmap,
&bits_per_pixel,&page);
if ((status == dps_status_failure) || (status == dps_status_no_extension))
{
image=DestroyImage(image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
return((Image *) NULL);
}
/*
Rasterize the file into the pixmap.
*/
status=XDPSImageFileIntoDrawable((DPSContext) NULL,screen,pixmap,
GetBlobFileHandle(image),(int) bits_per_pixel.height,visual_info->depth,
&page,-page.x,-page.y,pixels_per_point,MagickTrue,MagickFalse,MagickTrue,
&sans);
if (status != dps_status_success)
{
image=DestroyImage(image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
return((Image *) NULL);
}
/*
Initialize DPS X image.
*/
dps_image=XGetImage(display,pixmap,0,0,bits_per_pixel.width,
bits_per_pixel.height,AllPlanes,ZPixmap);
(void) XFreePixmap(display,pixmap);
if (dps_image == (XImage *) NULL)
{
image=DestroyImage(image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
return((Image *) NULL);
}
/*
Get the colormap colors.
*/
colors=(XColor *) AcquireQuantumMemory(visual_info->colormap_size,
sizeof(*colors));
if (colors == (XColor *) NULL)
{
image=DestroyImage(image);
XDestroyImage(dps_image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
return((Image *) NULL);
}
if ((visual_info->klass != DirectColor) && (visual_info->klass != TrueColor))
for (i=0; i < visual_info->colormap_size; i++)
{
colors[i].pixel=(size_t) i;
colors[i].pad=0;
}
else
{
size_t
blue,
blue_bit,
green,
green_bit,
red,
red_bit;
/*
DirectColor or TrueColor visual.
*/
red=0;
green=0;
blue=0;
red_bit=visual_info->red_mask & (~(visual_info->red_mask)+1);
green_bit=visual_info->green_mask & (~(visual_info->green_mask)+1);
blue_bit=visual_info->blue_mask & (~(visual_info->blue_mask)+1);
for (i=0; i < visual_info->colormap_size; i++)
{
colors[i].pixel=red | green | blue;
colors[i].pad=0;
red+=red_bit;
if (red > visual_info->red_mask)
red=0;
green+=green_bit;
if (green > visual_info->green_mask)
green=0;
blue+=blue_bit;
if (blue > visual_info->blue_mask)
blue=0;
}
}
(void) XQueryColors(display,XDefaultColormap(display,visual_info->screen),
colors,visual_info->colormap_size);
/*
Convert X image to MIFF format.
*/
if ((visual_info->klass != TrueColor) && (visual_info->klass != DirectColor))
image->storage_class=PseudoClass;
image->columns=(size_t) dps_image->width;
image->rows=(size_t) dps_image->height;
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
switch (image->storage_class)
{
case DirectClass:
default:
{
register size_t
color,
index;
size_t
blue_mask,
blue_shift,
green_mask,
green_shift,
red_mask,
red_shift;
/*
Determine shift and mask for red, green, and blue.
*/
red_mask=visual_info->red_mask;
red_shift=0;
while ((red_mask != 0) && ((red_mask & 0x01) == 0))
{
red_mask>>=1;
red_shift++;
}
green_mask=visual_info->green_mask;
green_shift=0;
while ((green_mask != 0) && ((green_mask & 0x01) == 0))
{
green_mask>>=1;
green_shift++;
}
blue_mask=visual_info->blue_mask;
blue_shift=0;
while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
{
blue_mask>>=1;
blue_shift++;
}
/*
Convert X image to DirectClass packets.
*/
if ((visual_info->colormap_size > 0) &&
(visual_info->klass == DirectColor))
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
pixel=XGetPixel(dps_image,x,y);
index=(pixel >> red_shift) & red_mask;
SetPixelRed(q,ScaleShortToQuantum(colors[index].red));
index=(pixel >> green_shift) & green_mask;
SetPixelGreen(q,ScaleShortToQuantum(colors[index].green));
index=(pixel >> blue_shift) & blue_mask;
SetPixelBlue(q,ScaleShortToQuantum(colors[index].blue));
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
break;
}
else
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
pixel=XGetPixel(dps_image,x,y);
color=(pixel >> red_shift) & red_mask;
color=(color*65535L)/red_mask;
SetPixelRed(q,ScaleShortToQuantum((unsigned short) color));
color=(pixel >> green_shift) & green_mask;
color=(color*65535L)/green_mask;
SetPixelGreen(q,ScaleShortToQuantum((unsigned short)
color));
color=(pixel >> blue_shift) & blue_mask;
color=(color*65535L)/blue_mask;
SetPixelBlue(q,ScaleShortToQuantum((unsigned short)
color));
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
break;
}
break;
}
case PseudoClass:
{
/*
Create colormap.
*/
if (AcquireImageColormap(image,(size_t) visual_info->colormap_size) == MagickFalse)
{
image=DestroyImage(image);
colors=(XColor *) RelinquishMagickMemory(colors);
XDestroyImage(dps_image);
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
return((Image *) NULL);
}
for (i=0; i < (ssize_t) image->colors; i++)
{
image->colormap[colors[i].pixel].red=ScaleShortToQuantum(colors[i].red);
image->colormap[colors[i].pixel].green=
ScaleShortToQuantum(colors[i].green);
image->colormap[colors[i].pixel].blue=
ScaleShortToQuantum(colors[i].blue);
}
/*
Convert X image to PseudoClass packets.
*/
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < (ssize_t) image->columns; x++)
SetPixelIndex(indexes+x,(unsigned short)
XGetPixel(dps_image,x,y));
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
break;
}
break;
}
}
colors=(XColor *) RelinquishMagickMemory(colors);
XDestroyImage(dps_image);
if (image->storage_class == PseudoClass)
(void) SyncImage(image);
/*
Rasterize matte image.
*/
status=XDPSCreatePixmapForEPSF((DPSContext) NULL,screen,
GetBlobFileHandle(image),1,pixels_per_point,&pixmap,&bits_per_pixel,&page);
if ((status != dps_status_failure) && (status != dps_status_no_extension))
{
status=XDPSImageFileIntoDrawable((DPSContext) NULL,screen,pixmap,
GetBlobFileHandle(image),(int) bits_per_pixel.height,1,&page,-page.x,
-page.y,pixels_per_point,MagickTrue,MagickTrue,MagickTrue,&sans);
if (status == dps_status_success)
{
XImage
*matte_image;
/*
Initialize image matte.
*/
matte_image=XGetImage(display,pixmap,0,0,bits_per_pixel.width,
bits_per_pixel.height,AllPlanes,ZPixmap);
(void) XFreePixmap(display,pixmap);
if (matte_image != (XImage *) NULL)
{
image->storage_class=DirectClass;
image->matte=MagickTrue;
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelOpacity(q,OpaqueOpacity);
if (XGetPixel(matte_image,x,y) == 0)
SetPixelOpacity(q,TransparentOpacity);
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
XDestroyImage(matte_image);
}
}
}
/*
Relinquish resources.
*/
XFreeResources(display,visual_info,map_info,(XPixelInfo *) NULL,
(XFontStruct *) NULL,&resource_info,(XWindowInfo *) NULL);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
#endif
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r D P S I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterDPSImage() adds attributes for the Display Postscript image
% format to the list of supported formats. The attributes include the image
% format tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterDPSImage method is:
%
% size_t RegisterDPSImage(void)
%
*/
ModuleExport size_t RegisterDPSImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("DPS");
#if defined(MAGICKCORE_DPS_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadDPSImage;
#endif
entry->blob_support=MagickFalse;
entry->description=ConstantString("Display Postscript Interpreter");
entry->module=ConstantString("DPS");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r D P S I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterDPSImage() removes format registrations made by the
% DPS module from the list of supported formats.
%
% The format of the UnregisterDPSImage method is:
%
% UnregisterDPSImage(void)
%
*/
ModuleExport void UnregisterDPSImage(void)
{
(void) UnregisterMagickInfo("DPS");
}

1978
ImageMagick/coders/dpx.c Normal file

File diff suppressed because it is too large Load diff

712
ImageMagick/coders/emf.c Normal file
View file

@ -0,0 +1,712 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% EEEEE M M FFFFF %
% E MM MM F %
% EEE M M M FFF %
% E M M F %
% EEEEE M M F %
% %
% %
% Read Windows Enahanced Metafile Format %
% %
% Software Design %
% Bill Radcliffe %
% 2001 %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
/*
* Include declarations.
*/
#include "magick/studio.h"
#if defined(MAGICKCORE_WINGDI32_DELEGATE) && defined(__CYGWIN__)
# define MAGICKCORE_EMF_DELEGATE
#endif
#if defined(MAGICKCORE_EMF_DELEGATE)
# if defined(__CYGWIN__)
# include <windows.h>
# else
# include <wingdi.h>
# endif
#endif
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/geometry.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/pixel.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s E F M %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsEMF() returns MagickTrue if the image format type, identified by the
% magick string, is a Microsoft Windows Enhanced MetaFile (EMF) file.
%
% The format of the ReadEMFImage method is:
%
% MagickBooleanType IsEMF(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsEMF(const unsigned char *magick,const size_t length)
{
if (length < 48)
return(MagickFalse);
if (memcmp(magick+40,"\040\105\115\106\000\000\001\000",8) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s W M F %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsWMF() returns MagickTrue if the image format type, identified by the
% magick string, is a Windows MetaFile (WMF) file.
%
% The format of the ReadEMFImage method is:
%
% MagickBooleanType IsEMF(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsWMF(const unsigned char *magick,const size_t length)
{
if (length < 4)
return(MagickFalse);
if (memcmp(magick,"\327\315\306\232",4) == 0)
return(MagickTrue);
if (memcmp(magick,"\001\000\011\000",4) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d E M F I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadEMFImage() reads an Microsoft Windows Enhanced MetaFile (EMF) or
% Windows MetaFile (WMF) file using the Windows API 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 ReadEMFImage method is:
%
% Image *ReadEMFImage(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.
%
*/
#if defined(MAGICKCORE_HAVE__WFOPEN)
static size_t UTF8ToUTF16(const unsigned char *utf8,wchar_t *utf16)
{
register const unsigned char
*p;
if (utf16 != (wchar_t *) NULL)
{
register wchar_t
*q;
wchar_t
c;
/*
Convert UTF-8 to UTF-16.
*/
q=utf16;
for (p=utf8; *p != '\0'; p++)
{
if ((*p & 0x80) == 0)
*q=(*p);
else
if ((*p & 0xE0) == 0xC0)
{
c=(*p);
*q=(c & 0x1F) << 6;
p++;
if ((*p & 0xC0) != 0x80)
return(0);
*q|=(*p & 0x3F);
}
else
if ((*p & 0xF0) == 0xE0)
{
c=(*p);
*q=c << 12;
p++;
if ((*p & 0xC0) != 0x80)
return(0);
c=(*p);
*q|=(c & 0x3F) << 6;
p++;
if ((*p & 0xC0) != 0x80)
return(0);
*q|=(*p & 0x3F);
}
else
return(0);
q++;
}
*q++='\0';
return(q-utf16);
}
/*
Compute UTF-16 string length.
*/
for (p=utf8; *p != '\0'; p++)
{
if ((*p & 0x80) == 0)
;
else
if ((*p & 0xE0) == 0xC0)
{
p++;
if ((*p & 0xC0) != 0x80)
return(0);
}
else
if ((*p & 0xF0) == 0xE0)
{
p++;
if ((*p & 0xC0) != 0x80)
return(0);
p++;
if ((*p & 0xC0) != 0x80)
return(0);
}
else
return(0);
}
return(p-utf8);
}
static wchar_t *ConvertUTF8ToUTF16(const unsigned char *source)
{
size_t
length;
wchar_t
*utf16;
length=UTF8ToUTF16(source,(wchar_t *) NULL);
if (length == 0)
{
register ssize_t
i;
/*
Not UTF-8, just copy.
*/
length=strlen((char *) source);
utf16=(wchar_t *) AcquireQuantumMemory(length+1,sizeof(*utf16));
if (utf16 == (wchar_t *) NULL)
return((wchar_t *) NULL);
for (i=0; i <= (ssize_t) length; i++)
utf16[i]=source[i];
return(utf16);
}
utf16=(wchar_t *) AcquireQuantumMemory(length+1,sizeof(*utf16));
if (utf16 == (wchar_t *) NULL)
return((wchar_t *) NULL);
length=UTF8ToUTF16(source,utf16);
return(utf16);
}
#endif
/*
This method reads either an enhanced metafile, a regular 16bit Windows
metafile, or an Aldus Placeable metafile and converts it into an enhanced
metafile. Width and height are returned in .01mm units.
*/
#if defined(MAGICKCORE_EMF_DELEGATE)
static HENHMETAFILE ReadEnhMetaFile(const char *path,ssize_t *width,
ssize_t *height)
{
#pragma pack( push, 2 )
typedef struct
{
DWORD dwKey;
WORD hmf;
SMALL_RECT bbox;
WORD wInch;
DWORD dwReserved;
WORD wCheckSum;
} APMHEADER, *PAPMHEADER;
#pragma pack( pop )
DWORD
dwSize;
ENHMETAHEADER
emfh;
HANDLE
hFile;
HDC
hDC;
HENHMETAFILE
hTemp;
LPBYTE
pBits;
METAFILEPICT
mp;
HMETAFILE
hOld;
*width=512;
*height=512;
hTemp=GetEnhMetaFile(path);
#if defined(MAGICKCORE_HAVE__WFOPEN)
if (hTemp == (HENHMETAFILE) NULL)
{
wchar_t
*unicode_path;
unicode_path=ConvertUTF8ToUTF16((const unsigned char *) path);
if (unicode_path != (wchar_t *) NULL)
{
hTemp=GetEnhMetaFileW(unicode_path);
unicode_path=(wchar_t *) RelinquishMagickMemory(unicode_path);
}
}
#endif
if (hTemp != (HENHMETAFILE) NULL)
{
/*
Enhanced metafile.
*/
GetEnhMetaFileHeader(hTemp,sizeof(ENHMETAHEADER),&emfh);
*width=emfh.rclFrame.right-emfh.rclFrame.left;
*height=emfh.rclFrame.bottom-emfh.rclFrame.top;
return(hTemp);
}
hOld=GetMetaFile(path);
if (hOld != (HMETAFILE) NULL)
{
/*
16bit windows metafile.
*/
dwSize=GetMetaFileBitsEx(hOld,0,NULL);
if (dwSize == 0)
{
DeleteMetaFile(hOld);
return((HENHMETAFILE) NULL);
}
pBits=(LPBYTE) AcquireQuantumMemory(dwSize,sizeof(*pBits));
if (pBits == (LPBYTE) NULL)
{
DeleteMetaFile(hOld);
return((HENHMETAFILE) NULL);
}
if (GetMetaFileBitsEx(hOld,dwSize,pBits) == 0)
{
pBits=(BYTE *) DestroyString((char *) pBits);
DeleteMetaFile(hOld);
return((HENHMETAFILE) NULL);
}
/*
Make an enhanced metafile from the windows metafile.
*/
mp.mm=MM_ANISOTROPIC;
mp.xExt=1000;
mp.yExt=1000;
mp.hMF=NULL;
hDC=GetDC(NULL);
hTemp=SetWinMetaFileBits(dwSize,pBits,hDC,&mp);
ReleaseDC(NULL,hDC);
DeleteMetaFile(hOld);
pBits=(BYTE *) DestroyString((char *) pBits);
GetEnhMetaFileHeader(hTemp,sizeof(ENHMETAHEADER),&emfh);
*width=emfh.rclFrame.right-emfh.rclFrame.left;
*height=emfh.rclFrame.bottom-emfh.rclFrame.top;
return(hTemp);
}
/*
Aldus Placeable metafile.
*/
hFile=CreateFile(path,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
return(NULL);
dwSize=GetFileSize(hFile,NULL);
pBits=(LPBYTE) AcquireQuantumMemory(dwSize,sizeof(*pBits));
ReadFile(hFile,pBits,dwSize,&dwSize,NULL);
CloseHandle(hFile);
if (((PAPMHEADER) pBits)->dwKey != 0x9ac6cdd7l)
{
pBits=(BYTE *) DestroyString((char *) pBits);
return((HENHMETAFILE) NULL);
}
/*
Make an enhanced metafile from the placable metafile.
*/
mp.mm=MM_ANISOTROPIC;
mp.xExt=((PAPMHEADER) pBits)->bbox.Right-((PAPMHEADER) pBits)->bbox.Left;
*width=mp.xExt;
mp.xExt=(mp.xExt*2540l)/(DWORD) (((PAPMHEADER) pBits)->wInch);
mp.yExt=((PAPMHEADER)pBits)->bbox.Bottom-((PAPMHEADER) pBits)->bbox.Top;
*height=mp.yExt;
mp.yExt=(mp.yExt*2540l)/(DWORD) (((PAPMHEADER) pBits)->wInch);
mp.hMF=NULL;
hDC=GetDC(NULL);
hTemp=SetWinMetaFileBits(dwSize,&(pBits[sizeof(APMHEADER)]),hDC,&mp);
ReleaseDC(NULL,hDC);
pBits=(BYTE *) DestroyString((char *) pBits);
return(hTemp);
}
#define CENTIMETERS_INCH 2.54
static Image *ReadEMFImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
BITMAPINFO
DIBinfo;
HBITMAP
hBitmap,
hOldBitmap;
HDC
hDC;
HENHMETAFILE
hemf;
Image
*image;
RECT
rect;
register ssize_t
x;
register PixelPacket
*q;
RGBQUAD
*pBits,
*ppBits;
ssize_t
height,
width,
y;
image=AcquireImage(image_info);
hemf=ReadEnhMetaFile(image_info->filename,&width,&height);
if (hemf == (HENHMETAFILE) NULL)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
if ((image->columns == 0) || (image->rows == 0))
{
double
y_resolution,
x_resolution;
y_resolution=DefaultResolution;
x_resolution=DefaultResolution;
if (image->y_resolution > 0)
{
y_resolution=image->y_resolution;
if (image->units == PixelsPerCentimeterResolution)
y_resolution*=CENTIMETERS_INCH;
}
if (image->x_resolution > 0)
{
x_resolution=image->x_resolution;
if (image->units == PixelsPerCentimeterResolution)
x_resolution*=CENTIMETERS_INCH;
}
image->rows=(size_t) ((height/1000.0/CENTIMETERS_INCH)*y_resolution+0.5);
image->columns=(size_t) ((width/1000.0/CENTIMETERS_INCH)*
x_resolution+0.5);
}
if (image_info->size != (char *) NULL)
{
ssize_t
x;
image->columns=width;
image->rows=height;
x=0;
y=0;
(void) GetGeometry(image_info->size,&x,&y,&image->columns,&image->rows);
}
if (image_info->page != (char *) NULL)
{
char
*geometry;
register char
*p;
MagickStatusType
flags;
ssize_t
sans;
geometry=GetPageGeometry(image_info->page);
p=strchr(geometry,'>');
if (p == (char *) NULL)
{
flags=ParseMetaGeometry(geometry,&sans,&sans,&image->columns,
&image->rows);
if (image->x_resolution != 0.0)
image->columns=(size_t) floor((image->columns*image->x_resolution)+
0.5);
if (image->y_resolution != 0.0)
image->rows=(size_t) floor((image->rows*image->y_resolution)+0.5);
}
else
{
*p='\0';
flags=ParseMetaGeometry(geometry,&sans,&sans,&image->columns,
&image->rows);
if (image->x_resolution != 0.0)
image->columns=(size_t) floor(((image->columns*image->x_resolution)/
DefaultResolution)+0.5);
if (image->y_resolution != 0.0)
image->rows=(size_t) floor(((image->rows*image->y_resolution)/
DefaultResolution)+0.5);
}
(void) flags;
geometry=DestroyString(geometry);
}
hDC=GetDC(NULL);
if (hDC == (HDC) NULL)
{
DeleteEnhMetaFile(hemf);
ThrowReaderException(ResourceLimitError,"UnableToCreateADC");
}
/*
Initialize the bitmap header info.
*/
(void) ResetMagickMemory(&DIBinfo,0,sizeof(BITMAPINFO));
DIBinfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
DIBinfo.bmiHeader.biWidth=(LONG) image->columns;
DIBinfo.bmiHeader.biHeight=(-1)*(LONG) image->rows;
DIBinfo.bmiHeader.biPlanes=1;
DIBinfo.bmiHeader.biBitCount=32;
DIBinfo.bmiHeader.biCompression=BI_RGB;
hBitmap=CreateDIBSection(hDC,&DIBinfo,DIB_RGB_COLORS,(void **) &ppBits,NULL,
0);
ReleaseDC(NULL,hDC);
if (hBitmap == (HBITMAP) NULL)
{
DeleteEnhMetaFile(hemf);
ThrowReaderException(ResourceLimitError,"UnableToCreateBitmap");
}
hDC=CreateCompatibleDC(NULL);
if (hDC == (HDC) NULL)
{
DeleteEnhMetaFile(hemf);
DeleteObject(hBitmap);
ThrowReaderException(ResourceLimitError,"UnableToCreateADC");
}
hOldBitmap=(HBITMAP) SelectObject(hDC,hBitmap);
if (hOldBitmap == (HBITMAP) NULL)
{
DeleteEnhMetaFile(hemf);
DeleteDC(hDC);
DeleteObject(hBitmap);
ThrowReaderException(ResourceLimitError,"UnableToCreateBitmap");
}
/*
Initialize the bitmap to the image background color.
*/
pBits=ppBits;
for (y=0; y < (ssize_t) image->rows; y++)
{
for (x=0; x < (ssize_t) image->columns; x++)
{
pBits->rgbRed=ScaleQuantumToChar(image->background_color.red);
pBits->rgbGreen=ScaleQuantumToChar(image->background_color.green);
pBits->rgbBlue=ScaleQuantumToChar(image->background_color.blue);
pBits++;
}
}
rect.top=0;
rect.left=0;
rect.right=(LONG) image->columns;
rect.bottom=(LONG) image->rows;
/*
Convert metafile pixels.
*/
PlayEnhMetaFile(hDC,hemf,&rect);
pBits=ppBits;
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelRed(q,ScaleCharToQuantum(pBits->rgbRed));
SetPixelGreen(q,ScaleCharToQuantum(pBits->rgbGreen));
SetPixelBlue(q,ScaleCharToQuantum(pBits->rgbBlue));
SetPixelOpacity(q,OpaqueOpacity);
pBits++;
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
DeleteEnhMetaFile(hemf);
SelectObject(hDC,hOldBitmap);
DeleteDC(hDC);
DeleteObject(hBitmap);
return(GetFirstImageInList(image));
}
#endif /* MAGICKCORE_EMF_DELEGATE */
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r E M F I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterEMFImage() adds attributes for the EMF image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterEMFImage method is:
%
% size_t RegisterEMFImage(void)
%
*/
ModuleExport size_t RegisterEMFImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("EMF");
#if defined(MAGICKCORE_EMF_DELEGATE)
entry->decoder=ReadEMFImage;
#endif
entry->description=ConstantString(
"Windows WIN32 API rendered Enhanced Meta File");
entry->magick=(IsImageFormatHandler *) IsEMF;
entry->blob_support=MagickFalse;
entry->module=ConstantString("WMF");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("WMFWIN32");
#if defined(MAGICKCORE_EMF_DELEGATE)
entry->decoder=ReadEMFImage;
#endif
entry->description=ConstantString("Windows WIN32 API rendered Meta File");
entry->magick=(IsImageFormatHandler *) IsWMF;
entry->blob_support=MagickFalse;
entry->module=ConstantString("WMFWIN32");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r E M F I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterEMFImage() removes format registrations made by the
% EMF module from the list of supported formats.
%
% The format of the UnregisterEMFImage method is:
%
% UnregisterEMFImage(void)
%
*/
ModuleExport void UnregisterEMFImage(void)
{
(void) UnregisterMagickInfo("EMF");
(void) UnregisterMagickInfo("WMFWIN32");
}

464
ImageMagick/coders/ept.c Normal file
View file

@ -0,0 +1,464 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% EEEEE PPPP TTTTT %
% E P P T %
% EEE PPPP T %
% E P T %
% EEEEE P T %
% %
% %
% Read/Write Encapsulated Postscript Format (with preview). %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/color.h"
#include "magick/constitute.h"
#include "magick/draw.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/delegate.h"
#include "magick/geometry.h"
#include "magick/histogram.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantize.h"
#include "magick/quantum-private.h"
#include "magick/resource_.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/transform.h"
#include "magick/utility.h"
/*
Typedef declarations.
*/
typedef struct _EPTInfo
{
size_t
magick;
MagickOffsetType
postscript_offset,
tiff_offset;
size_t
postscript_length,
tiff_length;
unsigned char
*postscript,
*tiff;
} EPTInfo;
/*
Forward declarations.
*/
static MagickBooleanType
WriteEPTImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s E P T %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsEPT() returns MagickTrue if the image format type, identified by the
% magick string, is EPT.
%
% The format of the IsEPT method is:
%
% MagickBooleanType IsEPT(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsEPT(const unsigned char *magick,const size_t length)
{
if (length < 4)
return(MagickFalse);
if (memcmp(magick,"\305\320\323\306",4) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d E P T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadEPTImage() reads a binary Postscript 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 ReadEPTImage method is:
%
% Image *ReadEPTImage(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 *ReadEPTImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
EPTInfo
ept_info;
Image
*image;
ImageInfo
*read_info;
MagickBooleanType
status;
MagickOffsetType
offset;
ssize_t
count;
/*
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);
}
ept_info.magick=ReadBlobLSBLong(image);
if (ept_info.magick != 0xc6d3d0c5ul)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
ept_info.postscript_offset=(MagickOffsetType) ReadBlobLSBLong(image);
ept_info.postscript_length=ReadBlobLSBLong(image);
(void) ReadBlobLSBLong(image);
(void) ReadBlobLSBLong(image);
ept_info.tiff_offset=(MagickOffsetType) ReadBlobLSBLong(image);
ept_info.tiff_length=ReadBlobLSBLong(image);
(void) ReadBlobLSBShort(image);
ept_info.postscript=(unsigned char *) AcquireQuantumMemory(
ept_info.postscript_length+1,sizeof(*ept_info.postscript));
if (ept_info.postscript == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
(void) ResetMagickMemory(ept_info.postscript,0,(ept_info.postscript_length+1)*
sizeof(*ept_info.postscript));
ept_info.tiff=(unsigned char *) AcquireQuantumMemory(ept_info.tiff_length+1,
sizeof(*ept_info.tiff));
if (ept_info.tiff == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
(void) ResetMagickMemory(ept_info.tiff,0,(ept_info.tiff_length+1)*
sizeof(*ept_info.tiff));
offset=SeekBlob(image,ept_info.tiff_offset,SEEK_SET);
if (offset < 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
count=ReadBlob(image,ept_info.tiff_length,ept_info.tiff);
if (count != (ssize_t) (ept_info.tiff_length))
(void) ThrowMagickException(exception,GetMagickModule(),CorruptImageWarning,
"InsufficientImageDataInFile","`%s'",image->filename);
offset=SeekBlob(image,ept_info.postscript_offset,SEEK_SET);
if (offset < 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
count=ReadBlob(image,ept_info.postscript_length,ept_info.postscript);
if (count != (ssize_t) (ept_info.postscript_length))
(void) ThrowMagickException(exception,GetMagickModule(),CorruptImageWarning,
"InsufficientImageDataInFile","`%s'",image->filename);
(void) CloseBlob(image);
image=DestroyImage(image);
read_info=CloneImageInfo(image_info);
(void) CopyMagickString(read_info->magick,"EPS",MaxTextExtent);
image=BlobToImage(read_info,ept_info.postscript,ept_info.postscript_length,
exception);
if (image == (Image *) NULL)
{
(void) CopyMagickString(read_info->magick,"TIFF",MaxTextExtent);
image=BlobToImage(read_info,ept_info.tiff,ept_info.tiff_length,exception);
}
read_info=DestroyImageInfo(read_info);
if (image != (Image *) NULL)
(void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
ept_info.tiff=(unsigned char *) RelinquishMagickMemory(ept_info.tiff);
ept_info.postscript=(unsigned char *) RelinquishMagickMemory(
ept_info.postscript);
return(image);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r E P T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterEPTImage() adds attributes for the EPT image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterEPTImage method is:
%
% size_t RegisterEPTImage(void)
%
*/
ModuleExport size_t RegisterEPTImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("EPT");
entry->decoder=(DecodeImageHandler *) ReadEPTImage;
entry->encoder=(EncodeImageHandler *) WriteEPTImage;
entry->magick=(IsImageFormatHandler *) IsEPT;
entry->seekable_stream=MagickTrue;
entry->adjoin=MagickFalse;
entry->blob_support=MagickFalse;
entry->description=ConstantString(
"Encapsulated PostScript with TIFF preview");
entry->module=ConstantString("EPT");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("EPT2");
entry->decoder=(DecodeImageHandler *) ReadEPTImage;
entry->encoder=(EncodeImageHandler *) WriteEPTImage;
entry->magick=(IsImageFormatHandler *) IsEPT;
entry->adjoin=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->blob_support=MagickFalse;
entry->description=ConstantString(
"Encapsulated PostScript Level II with TIFF preview");
entry->module=ConstantString("EPT");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("EPT3");
entry->decoder=(DecodeImageHandler *) ReadEPTImage;
entry->encoder=(EncodeImageHandler *) WriteEPTImage;
entry->magick=(IsImageFormatHandler *) IsEPT;
entry->seekable_stream=MagickTrue;
entry->blob_support=MagickFalse;
entry->description=ConstantString(
"Encapsulated PostScript Level III with TIFF preview");
entry->module=ConstantString("EPT");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r E P T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterEPTImage() removes format registrations made by the
% EPT module from the list of supported formats.
%
% The format of the UnregisterEPTImage method is:
%
% UnregisterEPTImage(void)
%
*/
ModuleExport void UnregisterEPTImage(void)
{
(void) UnregisterMagickInfo("EPT");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e E P T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteEPTImage() writes an image in the Encapsulated Postscript format
% with a TIFF preview.
%
% The format of the WriteEPTImage method is:
%
% MagickBooleanType WriteEPTImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteEPTImage(const ImageInfo *image_info,Image *image)
{
char
filename[MaxTextExtent];
EPTInfo
ept_info;
Image
*write_image;
ImageInfo
*write_info;
MagickBooleanType
status;
/*
Write EPT image.
*/
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);
write_image=CloneImage(image,0,0,MagickTrue,&image->exception);
if (write_image == (Image *) NULL)
return(MagickFalse);
write_info=CloneImageInfo(image_info);
(void) CopyMagickString(write_info->magick,"EPS",MaxTextExtent);
if (LocaleCompare(image_info->magick,"EPT2") == 0)
(void) CopyMagickString(write_info->magick,"EPS2",MaxTextExtent);
if (LocaleCompare(image_info->magick,"EPT3") == 0)
(void) CopyMagickString(write_info->magick,"EPS3",MaxTextExtent);
(void) ResetMagickMemory(&ept_info,0,sizeof(ept_info));
ept_info.magick=0xc6d3d0c5ul;
ept_info.postscript=(unsigned char *) ImageToBlob(write_info,write_image,
&ept_info.postscript_length,&image->exception);
write_image=DestroyImage(write_image);
write_info=DestroyImageInfo(write_info);
if (ept_info.postscript == (void *) NULL)
return(MagickFalse);
write_image=CloneImage(image,0,0,MagickTrue,&image->exception);
if (write_image == (Image *) NULL)
return(MagickFalse);
write_info=CloneImageInfo(image_info);
(void) CopyMagickString(write_info->magick,"TIFF",MaxTextExtent);
(void) FormatLocaleString(filename,MaxTextExtent,"tiff:%s",
write_info->filename);
(void) CopyMagickString(write_info->filename,filename,MaxTextExtent);
(void) TransformImage(&write_image,(char *) NULL,"512x512>");
if ((write_image->storage_class == DirectClass) ||
(write_image->colors > 256))
{
QuantizeInfo
quantize_info;
/*
EPT preview requires that the image is colormapped.
*/
GetQuantizeInfo(&quantize_info);
quantize_info.dither=IsPaletteImage(write_image,&image->exception) ==
MagickFalse ? MagickTrue : MagickFalse;
(void) QuantizeImage(&quantize_info,write_image);
}
write_info->compression=NoCompression;
ept_info.tiff=(unsigned char *) ImageToBlob(write_info,write_image,
&ept_info.tiff_length,&image->exception);
write_image=DestroyImage(write_image);
write_info=DestroyImageInfo(write_info);
if (ept_info.tiff == (void *) NULL)
{
ept_info.postscript=(unsigned char *) RelinquishMagickMemory(
ept_info.postscript);
return(MagickFalse);
}
/*
Write EPT image.
*/
(void) WriteBlobLSBLong(image,(unsigned int) ept_info.magick);
(void) WriteBlobLSBLong(image,30);
(void) WriteBlobLSBLong(image,(unsigned int) ept_info.postscript_length);
(void) WriteBlobLSBLong(image,0);
(void) WriteBlobLSBLong(image,0);
(void) WriteBlobLSBLong(image,(unsigned int) ept_info.postscript_length+30);
(void) WriteBlobLSBLong(image,(unsigned int) ept_info.tiff_length);
(void) WriteBlobLSBShort(image,0xffff);
(void) WriteBlob(image,ept_info.postscript_length,ept_info.postscript);
(void) WriteBlob(image,ept_info.tiff_length,ept_info.tiff);
/*
Relinquish resources.
*/
ept_info.postscript=(unsigned char *) RelinquishMagickMemory(
ept_info.postscript);
ept_info.tiff=(unsigned char *) RelinquishMagickMemory(ept_info.tiff);
(void) CloseBlob(image);
return(MagickTrue);
}

462
ImageMagick/coders/exr.c Normal file
View file

@ -0,0 +1,462 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% EEEEE X X RRRR %
% E X X R R %
% EEE X RRRR %
% E X X R R %
% EEEEE X X R R %
% %
% %
% Read/Write High Dynamic-Range (HDR) Image File Format %
% %
% Software Design %
% John Cristy %
% April 2007 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/pixel-accessor.h"
#include "magick/property.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/resource_.h"
#include "magick/utility.h"
#if defined(MAGICKCORE_OPENEXR_DELEGATE)
#include <ImfCRgbaFile.h>
/*
Forward declarations.
*/
static MagickBooleanType
WriteEXRImage(const ImageInfo *,Image *);
#endif
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s E X R %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsEXR() returns MagickTrue if the image format type, identified by the
% magick string, is EXR.
%
% The format of the IsEXR method is:
%
% MagickBooleanType IsEXR(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsEXR(const unsigned char *magick,const size_t length)
{
if (length < 4)
return(MagickFalse);
if (memcmp(magick,"\166\057\061\001",4) == 0)
return(MagickTrue);
return(MagickFalse);
}
#if defined(MAGICKCORE_OPENEXR_DELEGATE)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d E X R I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadEXRImage reads an image in the high dynamic-range (HDR) file format
% developed by Industrial Light & Magic. It allocates the memory necessary
% for the new Image structure and returns a pointer to the new image.
%
% The format of the ReadEXRImage method is:
%
% Image *ReadEXRImage(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 *ReadEXRImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
const ImfHeader
*hdr_info;
Image
*image;
ImageInfo
*read_info;
ImfInputFile
*file;
ImfRgba
*scanline;
int
max_x,
max_y,
min_x,
min_y;
MagickBooleanType
status;
register ssize_t
x;
register PixelPacket
*q;
ssize_t
y;
/*
Open image.
*/
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);
}
read_info=CloneImageInfo(image_info);
if (IsPathAccessible(read_info->filename) == MagickFalse)
{
(void) AcquireUniqueFilename(read_info->filename);
(void) ImageToFile(image,read_info->filename,exception);
}
file=ImfOpenInputFile(read_info->filename);
if (file == (ImfInputFile *) NULL)
{
ThrowFileException(exception,BlobError,"UnableToOpenBlob",
ImfErrorMessage());
read_info=DestroyImageInfo(read_info);
return((Image *) NULL);
}
hdr_info=ImfInputHeader(file);
ImfHeaderDisplayWindow(hdr_info,&min_x,&min_y,&max_x,&max_y);
image->columns=max_x-min_x+1UL;
image->rows=max_y-min_y+1UL;
image->matte=MagickTrue;
SetImageColorspace(image,RGBColorspace);
if (image_info->ping != MagickFalse)
{
(void) ImfCloseInputFile(file);
if (LocaleCompare(image_info->filename,read_info->filename) != 0)
(void) RelinquishUniqueFileResource(read_info->filename);
read_info=DestroyImageInfo(read_info);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
scanline=(ImfRgba *) AcquireQuantumMemory(image->columns,sizeof(*scanline));
if (scanline == (ImfRgba *) NULL)
{
(void) ImfCloseInputFile(file);
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
ImfInputSetFrameBuffer(file,scanline-min_x-image->columns*(min_y+y),1,
image->columns);
ImfInputReadPixels(file,min_y+y,min_y+y);
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelRed(q,ClampToQuantum((MagickRealType) QuantumRange*
ImfHalfToFloat(scanline[x].r)));
SetPixelGreen(q,ClampToQuantum((MagickRealType) QuantumRange*
ImfHalfToFloat(scanline[x].g)));
SetPixelBlue(q,ClampToQuantum((MagickRealType) QuantumRange*
ImfHalfToFloat(scanline[x].b)));
SetPixelAlpha(q,ClampToQuantum((MagickRealType) QuantumRange*
ImfHalfToFloat(scanline[x].a)));
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
scanline=(ImfRgba *) RelinquishMagickMemory(scanline);
(void) ImfCloseInputFile(file);
if (LocaleCompare(image_info->filename,read_info->filename) != 0)
(void) RelinquishUniqueFileResource(read_info->filename);
read_info=DestroyImageInfo(read_info);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
#endif
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r E X R I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterEXRImage() adds properties for the EXR image format
% to the list of supported formats. The properties include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterEXRImage method is:
%
% size_t RegisterEXRImage(void)
%
*/
ModuleExport size_t RegisterEXRImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("EXR");
#if defined(MAGICKCORE_OPENEXR_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadEXRImage;
entry->encoder=(EncodeImageHandler *) WriteEXRImage;
#endif
entry->magick=(IsImageFormatHandler *) IsEXR;
entry->adjoin=MagickFalse;
entry->description=ConstantString("High Dynamic-range (HDR)");
entry->blob_support=MagickFalse;
entry->module=ConstantString("EXR");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r E X R I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterEXRImage() removes format registrations made by the
% EXR module from the list of supported formats.
%
% The format of the UnregisterEXRImage method is:
%
% UnregisterEXRImage(void)
%
*/
ModuleExport void UnregisterEXRImage(void)
{
(void) UnregisterMagickInfo("EXR");
}
#if defined(MAGICKCORE_OPENEXR_DELEGATE)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e E X R I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteEXRImage() writes an image to a file the in the high dynamic-range
% (HDR) file format developed by Industrial Light & Magic.
%
% The format of the WriteEXRImage method is:
%
% MagickBooleanType WriteEXRImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteEXRImage(const ImageInfo *image_info,Image *image)
{
ImageInfo
*write_info;
ImfHalf
half_quantum;
ImfHeader
*hdr_info;
ImfOutputFile
*file;
ImfRgba
*scanline;
int
compression;
MagickBooleanType
status;
register const PixelPacket
*p;
register ssize_t
x;
ssize_t
y;
/*
Open output image file.
*/
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) SetImageColorspace(image,RGBColorspace);
write_info=CloneImageInfo(image_info);
(void) AcquireUniqueFilename(write_info->filename);
hdr_info=ImfNewHeader();
ImfHeaderSetDataWindow(hdr_info,0,0,(int) image->columns-1,(int)
image->rows-1);
ImfHeaderSetDisplayWindow(hdr_info,0,0,(int) image->columns-1,(int)
image->rows-1);
compression=IMF_NO_COMPRESSION;
if (write_info->compression == ZipSCompression)
compression=IMF_ZIPS_COMPRESSION;
if (write_info->compression == ZipCompression)
compression=IMF_ZIP_COMPRESSION;
if (write_info->compression == PizCompression)
compression=IMF_PIZ_COMPRESSION;
if (write_info->compression == Pxr24Compression)
compression=IMF_PXR24_COMPRESSION;
#if defined(B44Compression)
if (write_info->compression == B44Compression)
compression=IMF_B44_COMPRESSION;
#endif
#if defined(B44ACompression)
if (write_info->compression == B44ACompression)
compression=IMF_B44A_COMPRESSION;
#endif
ImfHeaderSetCompression(hdr_info,compression);
ImfHeaderSetLineOrder(hdr_info,IMF_INCREASING_Y);
file=ImfOpenOutputFile(write_info->filename,hdr_info,IMF_WRITE_RGBA);
ImfDeleteHeader(hdr_info);
if (file == (ImfOutputFile *) NULL)
{
ThrowFileException(&image->exception,BlobError,"UnableToOpenBlob",
ImfErrorMessage());
write_info=DestroyImageInfo(write_info);
return(MagickFalse);
}
scanline=(ImfRgba *) AcquireQuantumMemory(image->columns,sizeof(*scanline));
if (scanline == (ImfRgba *) NULL)
{
(void) ImfCloseOutputFile(file);
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
}
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;
for (x=0; x < (ssize_t) image->columns; x++)
{
ImfFloatToHalf(QuantumScale*GetPixelRed(p),&half_quantum);
scanline[x].r=half_quantum;
ImfFloatToHalf(QuantumScale*GetPixelGreen(p),&half_quantum);
scanline[x].g=half_quantum;
ImfFloatToHalf(QuantumScale*GetPixelBlue(p),&half_quantum);
scanline[x].b=half_quantum;
if (image->matte == MagickFalse)
ImfFloatToHalf(1.0,&half_quantum);
else
ImfFloatToHalf(1.0-QuantumScale*GetPixelOpacity(p),
&half_quantum);
scanline[x].a=half_quantum;
p++;
}
ImfOutputSetFrameBuffer(file,scanline-(y*image->columns),1,image->columns);
ImfOutputWritePixels(file,1);
}
(void) ImfCloseOutputFile(file);
scanline=(ImfRgba *) RelinquishMagickMemory(scanline);
(void) FileToImage(image,write_info->filename);
(void) RelinquishUniqueFileResource(write_info->filename);
write_info=DestroyImageInfo(write_info);
(void) CloseBlob(image);
return(MagickTrue);
}
#endif

342
ImageMagick/coders/fax.c Normal file
View file

@ -0,0 +1,342 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% FFFFF AAA X X %
% F A A X X %
% FFF AAAAA X %
% F A A X X %
% F A A X X %
% %
% %
% Read/Write Group 3 Fax Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/colormap.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/compress.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteFAXImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s F A X %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsFAX() returns MagickTrue if the image format type, identified by the
% magick string, is FAX.
%
% The format of the IsFAX method is:
%
% MagickBooleanType IsFAX(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
%
*/
static MagickBooleanType IsFAX(const unsigned char *magick,const size_t length)
{
if (length < 4)
return(MagickFalse);
if (LocaleNCompare((char *) magick,"DFAX",4) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d F A X I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadFAXImage() reads a Group 3 FAX 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 ReadFAXImage method is:
%
% Image *ReadFAXImage(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 *ReadFAXImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
Image
*image;
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);
}
/*
Initialize image structure.
*/
image->storage_class=PseudoClass;
if (image->columns == 0)
image->columns=2592;
if (image->rows == 0)
image->rows=3508;
image->depth=8;
if (AcquireImageColormap(image,2) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
/*
Monochrome colormap.
*/
image->colormap[0].red=QuantumRange;
image->colormap[0].green=QuantumRange;
image->colormap[0].blue=QuantumRange;
image->colormap[1].red=(Quantum) 0;
image->colormap[1].green=(Quantum) 0;
image->colormap[1].blue=(Quantum) 0;
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
status=HuffmanDecodeImage(image);
if (status == MagickFalse)
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r F A X I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterFAXImage() adds attributes for the FAX image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterFAXImage method is:
%
% size_t RegisterFAXImage(void)
%
*/
ModuleExport size_t RegisterFAXImage(void)
{
MagickInfo
*entry;
static const char
*Note=
{
"FAX machines use non-square pixels which are 1.5 times wider than\n"
"they are tall but computer displays use square pixels, therefore\n"
"FAX images may appear to be narrow unless they are explicitly\n"
"resized using a geometry of \"150x100%\".\n"
};
entry=SetMagickInfo("FAX");
entry->decoder=(DecodeImageHandler *) ReadFAXImage;
entry->encoder=(EncodeImageHandler *) WriteFAXImage;
entry->magick=(IsImageFormatHandler *) IsFAX;
entry->description=ConstantString("Group 3 FAX");
entry->note=ConstantString(Note);
entry->module=ConstantString("FAX");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("G3");
entry->decoder=(DecodeImageHandler *) ReadFAXImage;
entry->encoder=(EncodeImageHandler *) WriteFAXImage;
entry->magick=(IsImageFormatHandler *) IsFAX;
entry->adjoin=MagickFalse;
entry->description=ConstantString("Group 3 FAX");
entry->module=ConstantString("FAX");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r F A X I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterFAXImage() removes format registrations made by the
% FAX module from the list of supported formats.
%
% The format of the UnregisterFAXImage method is:
%
% UnregisterFAXImage(void)
%
*/
ModuleExport void UnregisterFAXImage(void)
{
(void) UnregisterMagickInfo("FAX");
(void) UnregisterMagickInfo("G3");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e F A X I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteFAXImage() writes an image to a file in 1 dimensional Huffman encoded
% format.
%
% The format of the WriteFAXImage method is:
%
% MagickBooleanType WriteFAXImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteFAXImage(const ImageInfo *image_info,Image *image)
{
ImageInfo
*write_info;
MagickBooleanType
status;
MagickOffsetType
scene;
/*
Open output image file.
*/
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);
write_info=CloneImageInfo(image_info);
(void) CopyMagickString(write_info->magick,"FAX",MaxTextExtent);
scene=0;
do
{
/*
Convert MIFF to monochrome.
*/
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
status=HuffmanEncodeImage(write_info,image,image);
if (GetNextImageInList(image) == (Image *) NULL)
break;
image=SyncNextImageInList(image);
status=SetImageProgress(image,SaveImagesTag,scene++,
GetImageListLength(image));
if (status == MagickFalse)
break;
} while (write_info->adjoin != MagickFalse);
write_info=DestroyImageInfo(write_info);
(void) CloseBlob(image);
return(status);
}

187
ImageMagick/coders/fd.c Normal file
View file

@ -0,0 +1,187 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% FFFFF DDDD %
% F D D %
% FFF D D %
% F D D %
% F DDDD %
% %
% %
% Retrieve An Image Via a File Descriptor. %
% %
% Software Design %
% John Cristy %
% Bill Radcliffe %
% March 2000 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/module.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/resource_.h"
#include "magick/string_.h"
#include "magick/string-private.h"
#include "magick/utility.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d F D I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadFDImage retrieves an image via a file descriptor, decodes the image,
% 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 ReadFDImage method is:
%
% Image *ReadFDImage(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 *ReadFDImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
Image
*image;
ImageInfo
*read_info;
/*
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);
read_info=CloneImageInfo(image_info);
read_info->file=fdopen(StringToLong(image_info->filename),"rb");
if (read_info->file == (FILE *) NULL)
{
ThrowFileException(exception,BlobError,"UnableToOpenBlob",
image_info->filename);
return((Image *) NULL);
}
*read_info->magick='\0';
image=ReadImage(read_info,exception);
(void) fclose(read_info->file);
read_info=DestroyImageInfo(read_info);
if (image == (Image *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),CoderError,
"NoDataReturned","`%s'",image_info->filename);
return((Image *) NULL);
}
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r F D I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterFDImage() adds attributes for the FD image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterFDImage method is:
%
% size_t RegisterFDImage(void)
%
*/
ModuleExport size_t RegisterFDImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("FD");
entry->decoder=(DecodeImageHandler *) ReadFDImage;
entry->description=ConstantString("Read image from a file descriptor");
entry->module=ConstantString("FD");
entry->stealth=MagickTrue;
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r F D I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterFDImage() removes format registrations made by the FD module from
% the list of supported formats.
%
% The format of the UnregisterFDImage method is:
%
% UnregisterFDImage(void)
%
*/
ModuleExport void UnregisterFDImage(void)
{
(void) UnregisterMagickInfo("FD");
}

830
ImageMagick/coders/fits.c Normal file
View file

@ -0,0 +1,830 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% FFFFF IIIII TTTTT SSSSS %
% F I T SS %
% FFF I T SSS %
% F I T SS %
% F IIIII T SSSSS %
% %
% %
% Read/Write Flexible Image Transport System Images. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/attribute.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/color-private.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/module.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/pixel-accessor.h"
#include "magick/pixel-private.h"
#include "magick/property.h"
#include "magick/static.h"
#include "magick/statistic.h"
#include "magick/string_.h"
#include "magick/string-private.h"
#include "magick/module.h"
/*
Forward declarations.
*/
#define FITSBlocksize 2880UL
/*
Forward declarations.
*/
static MagickBooleanType
WriteFITSImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s F I T S %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsFITS() returns MagickTrue if the image format type, identified by the
% magick string, is FITS.
%
% The format of the IsFITS method is:
%
% MagickBooleanType IsFITS(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsFITS(const unsigned char *magick,const size_t length)
{
if (length < 6)
return(MagickFalse);
if (LocaleNCompare((const char *) magick,"IT0",3) == 0)
return(MagickTrue);
if (LocaleNCompare((const char *) magick,"SIMPLE",6) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d F I T S I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadFITSImage() reads a FITS 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 ReadFITSImage method is:
%
% Image *ReadFITSImage(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 inline double GetFITSPixel(Image *image,int bits_per_pixel)
{
switch (image->depth >> 3)
{
case 1:
return((double) ReadBlobByte(image));
case 2:
return((double) ((short) ReadBlobShort(image)));
case 4:
{
if (bits_per_pixel > 0)
return((double) ((int) ReadBlobLong(image)));
return((double) ReadBlobFloat(image));
}
case 8:
{
if (bits_per_pixel > 0)
return((double) ((MagickOffsetType) ReadBlobLongLong(image)));
}
default:
break;
}
return(ReadBlobDouble(image));
}
static void GetFITSPixelExtrema(Image *image,const int bits_per_pixel,
double *minima,double *maxima)
{
double
pixel;
MagickOffsetType
offset;
MagickSizeType
number_pixels;
register MagickOffsetType
i;
offset=TellBlob(image);
number_pixels=(MagickSizeType) image->columns*image->rows;
*minima=GetFITSPixel(image,bits_per_pixel);
*maxima=(*minima);
for (i=1; i < (MagickOffsetType) number_pixels; i++)
{
pixel=GetFITSPixel(image,bits_per_pixel);
if (pixel < *minima)
*minima=pixel;
if (pixel > *maxima)
*maxima=pixel;
}
(void) SeekBlob(image,offset,SEEK_SET);
}
static inline double GetFITSPixelRange(const size_t depth)
{
return((double) ((MagickOffsetType) GetQuantumRange(depth)));
}
static void SetFITSUnsignedPixels(const size_t length,
const size_t bits_per_pixel,const EndianType endian,unsigned char *pixels)
{
register ssize_t
i;
if (endian != MSBEndian)
pixels+=(bits_per_pixel >> 3)-1;
for (i=0; i < (ssize_t) length; i++)
{
*pixels^=0x80;
pixels+=bits_per_pixel >> 3;
}
}
static Image *ReadFITSImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
typedef struct _FITSInfo
{
MagickBooleanType
extend,
simple;
int
bits_per_pixel,
columns,
rows,
number_axes,
number_planes;
double
min_data,
max_data,
zero,
scale;
EndianType
endian;
} FITSInfo;
char
*comment,
keyword[9],
property[MaxTextExtent],
value[73];
double
pixel,
scale;
FITSInfo
fits_info;
Image
*image;
int
c;
MagickBooleanType
status;
MagickSizeType
number_pixels;
register ssize_t
i,
x;
register PixelPacket
*q;
ssize_t
count,
scene,
y;
/*
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);
}
/*
Initialize image header.
*/
(void) ResetMagickMemory(&fits_info,0,sizeof(fits_info));
fits_info.extend=MagickFalse;
fits_info.simple=MagickFalse;
fits_info.bits_per_pixel=8;
fits_info.columns=1;
fits_info.rows=1;
fits_info.rows=1;
fits_info.number_planes=1;
fits_info.min_data=0.0;
fits_info.max_data=0.0;
fits_info.zero=0.0;
fits_info.scale=1.0;
fits_info.endian=MSBEndian;
/*
Decode image header.
*/
for (comment=(char *) NULL; EOFBlob(image) == MagickFalse; )
{
for ( ; EOFBlob(image) == MagickFalse; )
{
register char
*p;
count=ReadBlob(image,8,(unsigned char *) keyword);
if (count != 8)
break;
for (i=0; i < 8; i++)
{
if (isspace((int) ((unsigned char) keyword[i])) != 0)
break;
keyword[i]=tolower((int) ((unsigned char) keyword[i]));
}
keyword[i]='\0';
count=ReadBlob(image,72,(unsigned char *) value);
if (count != 72)
break;
value[72]='\0';
p=value;
if (*p == '=')
{
p+=2;
while (isspace((int) ((unsigned char) *p)) != 0)
p++;
}
if (LocaleCompare(keyword,"end") == 0)
break;
if (LocaleCompare(keyword,"extend") == 0)
fits_info.extend=(*p == 'T') || (*p == 't') ? MagickTrue : MagickFalse;
if (LocaleCompare(keyword,"simple") == 0)
fits_info.simple=(*p == 'T') || (*p == 't') ? MagickTrue : MagickFalse;
if (LocaleCompare(keyword,"bitpix") == 0)
fits_info.bits_per_pixel=StringToLong(p);
if (LocaleCompare(keyword,"naxis") == 0)
fits_info.number_axes=StringToLong(p);
if (LocaleCompare(keyword,"naxis1") == 0)
fits_info.columns=StringToLong(p);
if (LocaleCompare(keyword,"naxis2") == 0)
fits_info.rows=StringToLong(p);
if (LocaleCompare(keyword,"naxis3") == 0)
fits_info.number_planes=StringToLong(p);
if (LocaleCompare(keyword,"datamax") == 0)
fits_info.max_data=StringToDouble(p,(char **) NULL);
if (LocaleCompare(keyword,"datamin") == 0)
fits_info.min_data=StringToDouble(p,(char **) NULL);
if (LocaleCompare(keyword,"bzero") == 0)
fits_info.zero=StringToDouble(p,(char **) NULL);
if (LocaleCompare(keyword,"bscale") == 0)
fits_info.scale=StringToDouble(p,(char **) NULL);
if (LocaleCompare(keyword,"comment") == 0)
{
if (comment == (char *) NULL)
comment=ConstantString(p);
else
(void) ConcatenateString(&comment,p);
}
if (LocaleCompare(keyword,"xendian") == 0)
{
if (LocaleNCompare(p,"big",3) == 0)
fits_info.endian=MSBEndian;
else
fits_info.endian=LSBEndian;
}
(void) FormatLocaleString(property,MaxTextExtent,"fits:%s",keyword);
(void) SetImageProperty(image,property,p);
}
c=0;
while (((TellBlob(image) % FITSBlocksize) != 0) && (c != EOF))
c=ReadBlobByte(image);
if (fits_info.extend == MagickFalse)
break;
number_pixels=(MagickSizeType) fits_info.columns*fits_info.rows;
if ((fits_info.simple != MagickFalse) && (fits_info.number_axes >= 1) &&
(fits_info.number_axes <= 4) && (number_pixels != 0))
break;
}
/*
Verify that required image information is defined.
*/
if (comment != (char *) NULL)
{
(void) SetImageProperty(image,"comment",comment);
comment=DestroyString(comment);
}
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
number_pixels=(MagickSizeType) fits_info.columns*fits_info.rows;
if ((fits_info.simple == MagickFalse) || (fits_info.number_axes < 1) ||
(fits_info.number_axes > 4) || (number_pixels == 0))
ThrowReaderException(CorruptImageError,"ImageTypeNotSupported");
for (scene=0; scene < (ssize_t) fits_info.number_planes; scene++)
{
image->columns=(size_t) fits_info.columns;
image->rows=(size_t) fits_info.rows;
image->depth=(size_t) (fits_info.bits_per_pixel < 0 ? -1 : 1)*
fits_info.bits_per_pixel;
image->endian=fits_info.endian;
image->scene=(size_t) scene;
if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
/*
Initialize image structure.
*/
(void) SetImageColorspace(image,GRAYColorspace);
if ((fits_info.min_data == 0.0) && (fits_info.max_data == 0.0))
{
if (fits_info.zero == 0.0)
GetFITSPixelExtrema(image,fits_info.bits_per_pixel,
&fits_info.min_data,&fits_info.max_data);
else
fits_info.max_data=GetFITSPixelRange((size_t)
fits_info.bits_per_pixel);
}
else
fits_info.max_data=GetFITSPixelRange((size_t) fits_info.bits_per_pixel);
/*
Convert FITS pixels to pixel packets.
*/
scale=QuantumRange/(fits_info.max_data-fits_info.min_data);
for (y=(ssize_t) image->rows-1; y >= 0; y--)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
pixel=GetFITSPixel(image,fits_info.bits_per_pixel);
if ((image->depth == 16) || (image->depth == 32) ||
(image->depth == 64))
SetFITSUnsignedPixels(1,image->depth,image->endian,(unsigned char *)
&pixel);
SetPixelRed(q,ClampToQuantum(scale*(fits_info.scale*(pixel-
fits_info.min_data)+fits_info.zero)));
SetPixelGreen(q,GetPixelRed(q));
SetPixelBlue(q,GetPixelRed(q));
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
if (EOFBlob(image) != MagickFalse)
{
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
break;
}
/*
Proceed to next image.
*/
if (image_info->number_scenes != 0)
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
if (scene < (ssize_t) (fits_info.number_planes-1))
{
/*
Allocate next image structure.
*/
AcquireNextImage(image_info,image);
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
image=SyncNextImageInList(image);
status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
GetBlobSize(image));
if (status == MagickFalse)
break;
}
}
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r F I T S I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterFITSImage() adds attributes for the FITS image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterFITSImage method is:
%
% size_t RegisterFITSImage(void)
%
*/
ModuleExport size_t RegisterFITSImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("FITS");
entry->decoder=(DecodeImageHandler *) ReadFITSImage;
entry->encoder=(EncodeImageHandler *) WriteFITSImage;
entry->magick=(IsImageFormatHandler *) IsFITS;
entry->adjoin=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->description=ConstantString("Flexible Image Transport System");
entry->module=ConstantString("FITS");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("FTS");
entry->decoder=(DecodeImageHandler *) ReadFITSImage;
entry->encoder=(EncodeImageHandler *) WriteFITSImage;
entry->magick=(IsImageFormatHandler *) IsFITS;
entry->adjoin=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->description=ConstantString("Flexible Image Transport System");
entry->module=ConstantString("FTS");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r F I T S I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterFITSImage() removes format registrations made by the
% FITS module from the list of supported formats.
%
% The format of the UnregisterFITSImage method is:
%
% UnregisterFITSImage(void)
%
*/
ModuleExport void UnregisterFITSImage(void)
{
(void) UnregisterMagickInfo("FITS");
(void) UnregisterMagickInfo("FTS");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e F I T S I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteFITSImage() writes a Flexible Image Transport System image to a
% file as gray scale intensities [0..255].
%
% The format of the WriteFITSImage method is:
%
% MagickBooleanType WriteFITSImage(const ImageInfo *image_info,
% Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteFITSImage(const ImageInfo *image_info,
Image *image)
{
char
header[FITSBlocksize],
*fits_info;
MagickBooleanType
status;
QuantumInfo
*quantum_info;
register const PixelPacket
*p;
size_t
length;
ssize_t
count,
offset,
y;
unsigned char
*pixels;
/*
Open output image file.
*/
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);
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
/*
Allocate image memory.
*/
fits_info=(char *) AcquireQuantumMemory(FITSBlocksize,sizeof(*fits_info));
if (fits_info == (char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
(void) ResetMagickMemory(fits_info,' ',FITSBlocksize*sizeof(*fits_info));
/*
Initialize image header.
*/
image->depth=GetImageQuantumDepth(image,MagickFalse);
image->endian=MSBEndian;
quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
offset=0;
(void) FormatLocaleString(header,FITSBlocksize,
"SIMPLE = T");
(void) strncpy(fits_info+offset,header,strlen(header));
offset+=80;
(void) FormatLocaleString(header,FITSBlocksize,"BITPIX = %10ld",
(long) (quantum_info->format == FloatingPointQuantumFormat ? -1 : 1)*
image->depth);
(void) strncpy(fits_info+offset,header,strlen(header));
offset+=80;
(void) FormatLocaleString(header,FITSBlocksize,"NAXIS = %10lu",
IsGrayImage(image,&image->exception) != MagickFalse ? 2UL : 3UL);
(void) strncpy(fits_info+offset,header,strlen(header));
offset+=80;
(void) FormatLocaleString(header,FITSBlocksize,"NAXIS1 = %10lu",
(unsigned long) image->columns);
(void) strncpy(fits_info+offset,header,strlen(header));
offset+=80;
(void) FormatLocaleString(header,FITSBlocksize,"NAXIS2 = %10lu",
(unsigned long) image->rows);
(void) strncpy(fits_info+offset,header,strlen(header));
offset+=80;
if (IsGrayImage(image,&image->exception) == MagickFalse)
{
(void) FormatLocaleString(header,FITSBlocksize,
"NAXIS3 = %10lu",3UL);
(void) strncpy(fits_info+offset,header,strlen(header));
offset+=80;
}
(void) FormatLocaleString(header,FITSBlocksize,"BSCALE = %E",1.0);
(void) strncpy(fits_info+offset,header,strlen(header));
offset+=80;
(void) FormatLocaleString(header,FITSBlocksize,"BZERO = %E",
image->depth > 8 ? GetFITSPixelRange(image->depth)/2.0 : 0.0);
(void) strncpy(fits_info+offset,header,strlen(header));
offset+=80;
(void) FormatLocaleString(header,FITSBlocksize,"DATAMAX = %E",
1.0*((MagickOffsetType) GetQuantumRange(image->depth)));
(void) strncpy(fits_info+offset,header,strlen(header));
offset+=80;
(void) FormatLocaleString(header,FITSBlocksize,"DATAMIN = %E",0.0);
(void) strncpy(fits_info+offset,header,strlen(header));
offset+=80;
if (image->endian == LSBEndian)
{
(void) FormatLocaleString(header,FITSBlocksize,"XENDIAN = 'SMALL'");
(void) strncpy(fits_info+offset,header,strlen(header));
offset+=80;
}
(void) FormatLocaleString(header,FITSBlocksize,"HISTORY %.72s",
GetMagickVersion((size_t *) NULL));
(void) strncpy(fits_info+offset,header,strlen(header));
offset+=80;
(void) strncpy(header,"END",FITSBlocksize);
(void) strncpy(fits_info+offset,header,strlen(header));
offset+=80;
(void) WriteBlob(image,FITSBlocksize,(unsigned char *) fits_info);
/*
Convert image to fits scale PseudoColor class.
*/
pixels=GetQuantumPixels(quantum_info);
if (IsGrayImage(image,&image->exception) != MagickFalse)
{
length=GetQuantumExtent(image,quantum_info,GrayQuantum);
for (y=(ssize_t) image->rows-1; y >= 0; y--)
{
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (const PixelPacket *) NULL)
break;
length=ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
GrayQuantum,pixels,&image->exception);
if (image->depth == 16)
SetFITSUnsignedPixels(image->columns,image->depth,image->endian,
pixels);
if (((image->depth == 32) || (image->depth == 64)) &&
(quantum_info->format != FloatingPointQuantumFormat))
SetFITSUnsignedPixels(image->columns,image->depth,image->endian,
pixels);
count=WriteBlob(image,length,pixels);
if (count != (ssize_t) length)
break;
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
else
{
length=GetQuantumExtent(image,quantum_info,RedQuantum);
for (y=(ssize_t) image->rows-1; y >= 0; y--)
{
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (const PixelPacket *) NULL)
break;
length=ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
RedQuantum,pixels,&image->exception);
if (image->depth == 16)
SetFITSUnsignedPixels(image->columns,image->depth,image->endian,
pixels);
if (((image->depth == 32) || (image->depth == 64)) &&
(quantum_info->format != FloatingPointQuantumFormat))
SetFITSUnsignedPixels(image->columns,image->depth,image->endian,
pixels);
count=WriteBlob(image,length,pixels);
if (count != (ssize_t) length)
break;
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
length=GetQuantumExtent(image,quantum_info,GreenQuantum);
for (y=(ssize_t) image->rows-1; y >= 0; y--)
{
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (const PixelPacket *) NULL)
break;
length=ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
GreenQuantum,pixels,&image->exception);
if (image->depth == 16)
SetFITSUnsignedPixels(image->columns,image->depth,image->endian,
pixels);
if (((image->depth == 32) || (image->depth == 64)) &&
(quantum_info->format != FloatingPointQuantumFormat))
SetFITSUnsignedPixels(image->columns,image->depth,image->endian,
pixels);
count=WriteBlob(image,length,pixels);
if (count != (ssize_t) length)
break;
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
length=GetQuantumExtent(image,quantum_info,BlueQuantum);
for (y=(ssize_t) image->rows-1; y >= 0; y--)
{
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (const PixelPacket *) NULL)
break;
length=ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
BlueQuantum,pixels,&image->exception);
if (image->depth == 16)
SetFITSUnsignedPixels(image->columns,image->depth,image->endian,
pixels);
if (((image->depth == 32) || (image->depth == 64)) &&
(quantum_info->format != FloatingPointQuantumFormat))
SetFITSUnsignedPixels(image->columns,image->depth,image->endian,
pixels);
count=WriteBlob(image,length,pixels);
if (count != (ssize_t) length)
break;
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
quantum_info=DestroyQuantumInfo(quantum_info);
length=(size_t) (FITSBlocksize-TellBlob(image) % FITSBlocksize);
if (length != 0)
{
(void) ResetMagickMemory(fits_info,0,length*sizeof(*fits_info));
(void) WriteBlob(image,length,(unsigned char *) fits_info);
}
fits_info=DestroyString(fits_info);
(void) CloseBlob(image);
return(MagickTrue);
}

1136
ImageMagick/coders/fpx.c Normal file

File diff suppressed because it is too large Load diff

1914
ImageMagick/coders/gif.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,243 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% GGGG RRRR AAA DDDD IIIII EEEEE N N TTTTT %
% G R R A A D D I E NN N T %
% G GG RRRR AAAAA D D I EEE N N N T %
% G G R R A A D D I E N NN T %
% GGG R R A A DDDD IIIII EEEEE N N T %
% %
% %
% Read An Image Filled Using Gradient. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/channel.h"
#include "magick/color.h"
#include "magick/color-private.h"
#include "magick/colorspace-private.h"
#include "magick/draw.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/paint.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/studio.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d G R A D I E N T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadGRADIENTImage creates a gradient image and initializes it to
% the color range as specified by the filename. It allocates the memory
% necessary for the new Image structure and returns a pointer to the new
% image.
%
% The format of the ReadGRADIENTImage method is:
%
% Image *ReadGRADIENTImage(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 *ReadGRADIENTImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
char
colorname[MaxTextExtent];
MagickBooleanType
icc_color,
status;
MagickPixelPacket
start_pixel,
stop_pixel;
PixelPacket
start_color,
stop_color;
Image
*image;
/*
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);
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(OptionError,"MustSpecifyImageSize");
(void) SetImageOpacity(image,(Quantum) TransparentOpacity);
(void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
(void) CopyMagickString(colorname,image_info->filename,MaxTextExtent);
(void) sscanf(image_info->filename,"%[^-]",colorname);
icc_color=MagickFalse;
if (LocaleCompare(colorname,"icc") == 0)
{
(void) ConcatenateMagickString(colorname,"-",MaxTextExtent);
(void) sscanf(image_info->filename,"%*[^-]-%[^-]",colorname+4);
icc_color=MagickTrue;
}
if (QueryColorDatabase(colorname,&start_color,exception) == MagickFalse)
{
image=DestroyImage(image);
return((Image *) NULL);
}
(void) QueryMagickColor(colorname,&start_pixel,exception);
(void) CopyMagickString(colorname,"white",MaxTextExtent);
if (PixelIntensityToQuantum(image,&start_color) > (Quantum) (QuantumRange/2))
(void) CopyMagickString(colorname,"black",MaxTextExtent);
if (icc_color == MagickFalse)
(void) sscanf(image_info->filename,"%*[^-]-%s",colorname);
else
(void) sscanf(image_info->filename,"%*[^-]-%*[^-]-%s",colorname);
if (QueryColorDatabase(colorname,&stop_color,exception) == MagickFalse)
{
image=DestroyImage(image);
return((Image *) NULL);
}
(void) QueryMagickColor(colorname,&stop_pixel,exception);
(void) SetImageColorspace(image,start_pixel.colorspace);
status=GradientImage(image,LocaleCompare(image_info->magick,"GRADIENT") == 0 ?
LinearGradient : RadialGradient,PadSpread,&start_color,&stop_color);
if (status == MagickFalse)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
if ((start_pixel.matte == MagickFalse) && (stop_pixel.matte == MagickFalse))
(void) SetImageAlphaChannel(image,DeactivateAlphaChannel);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r G R A D I E N T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterGRADIENTImage() adds attributes for the GRADIENT image format
% to the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterGRADIENTImage method is:
%
% size_t RegisterGRADIENTImage(void)
%
*/
ModuleExport size_t RegisterGRADIENTImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("GRADIENT");
entry->decoder=(DecodeImageHandler *) ReadGRADIENTImage;
entry->adjoin=MagickFalse;
entry->raw=MagickTrue;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Gradual linear passing from one shade to "
"another");
entry->module=ConstantString("GRADIENT");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("RADIAL-GRADIENT");
entry->decoder=(DecodeImageHandler *) ReadGRADIENTImage;
entry->adjoin=MagickFalse;
entry->raw=MagickTrue;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Gradual radial passing from one shade to "
"another");
entry->module=ConstantString("GRADIENT");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r G R A D I E N T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterGRADIENTImage() removes format registrations made by the
% GRADIENT module from the list of supported formats.
%
% The format of the UnregisterGRADIENTImage method is:
%
% UnregisterGRADIENTImage(void)
%
*/
ModuleExport void UnregisterGRADIENTImage(void)
{
(void) UnregisterMagickInfo("RADIAL-GRADIENT");
(void) UnregisterMagickInfo("GRADIENT");
}

453
ImageMagick/coders/gray.c Normal file
View file

@ -0,0 +1,453 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% GGGG RRRR AAA Y Y %
% G R R A A Y Y %
% G GG RRRR AAAAA Y %
% G G R R A A Y %
% GGG R R A A Y %
% %
% %
% Read/Write RAW Gray Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/channel.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/pixel.h"
#include "magick/pixel-accessor.h"
#include "magick/pixel-private.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/statistic.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteGRAYImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d G R A Y I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadGRAYImage() reads an image of raw grayscale samples 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 ReadGRAYImage method is:
%
% Image *ReadGRAYImage(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 *ReadGRAYImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
Image
*canvas_image,
*image;
MagickBooleanType
status;
MagickOffsetType
scene;
QuantumInfo
*quantum_info;
QuantumType
quantum_type;
size_t
length;
ssize_t
count,
y;
unsigned char
*pixels;
/*
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);
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(OptionError,"MustSpecifyImageSize");
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
if (DiscardBlobBytes(image,(size_t) image->offset) == MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
/*
Create virtual canvas to support cropping (i.e. image.gray[100x100+10+20]).
*/
SetImageColorspace(image,GRAYColorspace);
canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse,
exception);
(void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod);
quantum_type=GrayQuantum;
quantum_info=AcquireQuantumInfo(image_info,canvas_image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
pixels=GetQuantumPixels(quantum_info);
if (image_info->number_scenes != 0)
while (image->scene < image_info->scene)
{
/*
Skip to next image.
*/
image->scene++;
length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
for (y=0; y < (ssize_t) image->rows; y++)
{
count=ReadBlob(image,length,pixels);
if (count != (ssize_t) length)
break;
}
}
scene=0;
count=0;
length=0;
do
{
/*
Read pixels to virtual canvas image then push to image.
*/
if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
SetImageColorspace(image,GRAYColorspace);
if (scene == 0)
{
length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
count=ReadBlob(image,length,pixels);
}
for (y=0; y < (ssize_t) image->extract_info.height; y++)
{
register const PixelPacket
*restrict p;
register ssize_t
x;
register PixelPacket
*restrict q;
if (count != (ssize_t) length)
{
ThrowFileException(exception,CorruptImageError,
"UnexpectedEndOfFile",image->filename);
break;
}
q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,quantum_info,
quantum_type,pixels,exception);
if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
break;
if (((y-image->extract_info.y) >= 0) &&
((y-image->extract_info.y) < (ssize_t) image->rows))
{
p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
image->columns,1,exception);
q=QueueAuthenticPixels(image,0,y-image->extract_info.y,image->columns,
1,exception);
if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelRed(q,GetPixelRed(p));
SetPixelGreen(q,GetPixelGreen(p));
SetPixelBlue(q,GetPixelBlue(p));
p++;
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
count=ReadBlob(image,length,pixels);
}
SetQuantumImageType(image,quantum_type);
/*
Proceed to next image.
*/
if (image_info->number_scenes != 0)
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
if (count == (ssize_t) length)
{
/*
Allocate next image structure.
*/
AcquireNextImage(image_info,image);
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
image=SyncNextImageInList(image);
status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
GetBlobSize(image));
if (status == MagickFalse)
break;
}
scene++;
} while (count == (ssize_t) length);
quantum_info=DestroyQuantumInfo(quantum_info);
InheritException(&image->exception,&canvas_image->exception);
canvas_image=DestroyImage(canvas_image);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r G R A Y I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterGRAYImage() adds attributes for the GRAY image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterGRAYImage method is:
%
% size_t RegisterGRAYImage(void)
%
*/
ModuleExport size_t RegisterGRAYImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("GRAY");
entry->decoder=(DecodeImageHandler *) ReadGRAYImage;
entry->encoder=(EncodeImageHandler *) WriteGRAYImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->description=ConstantString("Raw gray samples");
entry->module=ConstantString("GRAY");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r G R A Y I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterGRAYImage() removes format registrations made by the
% GRAY module from the list of supported formats.
%
% The format of the UnregisterGRAYImage method is:
%
% UnregisterGRAYImage(void)
%
*/
ModuleExport void UnregisterGRAYImage(void)
{
(void) UnregisterMagickInfo("GRAY");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e G R A Y I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteGRAYImage() writes an image to a file as gray scale intensity
% values.
%
% The format of the WriteGRAYImage method is:
%
% MagickBooleanType WriteGRAYImage(const ImageInfo *image_info,
% Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteGRAYImage(const ImageInfo *image_info,
Image *image)
{
MagickBooleanType
status;
MagickOffsetType
scene;
QuantumInfo
*quantum_info;
QuantumType
quantum_type;
size_t
length;
ssize_t
count,
y;
unsigned char
*pixels;
/*
Open output image file.
*/
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);
scene=0;
do
{
/*
Write grayscale pixels.
*/
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
quantum_type=GrayQuantum;
quantum_info=AcquireQuantumInfo(image_info,image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
pixels=GetQuantumPixels(quantum_info);
for (y=0; y < (ssize_t) image->rows; y++)
{
register const PixelPacket
*restrict p;
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (const PixelPacket *) NULL)
break;
length=ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
quantum_type,pixels,&image->exception);
count=WriteBlob(image,length,pixels);
if (count != (ssize_t) length)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
quantum_info=DestroyQuantumInfo(quantum_info);
if (GetNextImageInList(image) == (Image *) NULL)
break;
image=SyncNextImageInList(image);
status=SetImageProgress(image,SaveImagesTag,scene++,
GetImageListLength(image));
if (status == MagickFalse)
break;
} while (image_info->adjoin != MagickFalse);
(void) CloseBlob(image);
return(MagickTrue);
}

229
ImageMagick/coders/hald.c Normal file
View file

@ -0,0 +1,229 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% H H AAA L DDDD %
% H H A A L D D %
% HHHHH AAAAA L D D %
% H H A A L D D %
% H H A A LLLLL DDDD %
% %
% %
% Create Identity Hald CLUT Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colorspace.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/module.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/resource_.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/string-private.h"
#include "magick/thread-private.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d H A L D I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadHALDImage() creates a Hald color lookup table image 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 ReadHALDImage method is:
%
% Image *ReadHALDImage(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 *ReadHALDImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
Image
*image;
MagickBooleanType
status;
size_t
cube_size,
level;
ssize_t
y;
/*
Create HALD color lookup table image.
*/
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);
level=0;
if (*image_info->filename != '\0')
level=StringToUnsignedLong(image_info->filename);
if (level < 2)
level=8;
status=MagickTrue;
cube_size=level*level;
image->columns=(size_t) (level*cube_size);
image->rows=(size_t) (level*cube_size);
for (y=0; y < (ssize_t) image->rows; y+=(ssize_t) level)
{
ssize_t
blue,
green,
red;
register PixelPacket
*restrict q;
if (status == MagickFalse)
continue;
q=QueueAuthenticPixels(image,0,y,image->columns,(size_t) level,
exception);
if (q == (PixelPacket *) NULL)
{
status=MagickFalse;
continue;
}
blue=y/(ssize_t) level;
for (green=0; green < (ssize_t) cube_size; green++)
{
for (red=0; red < (ssize_t) cube_size; red++)
{
SetPixelRed(q,ClampToQuantum((MagickRealType)
(QuantumRange*red/(cube_size-1.0))));
SetPixelGreen(q,ClampToQuantum((MagickRealType)
(QuantumRange*green/(cube_size-1.0))));
SetPixelBlue(q,ClampToQuantum((MagickRealType)
(QuantumRange*blue/(cube_size-1.0))));
SetPixelOpacity(q,OpaqueOpacity);
q++;
}
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
status=MagickFalse;
}
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r H A L D I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterHALDImage() adds attributes for the Hald color lookup table image
% format to the list of supported formats. The attributes include the image
% format tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob, whether
% the format supports native in-memory I/O, and a brief description of the
% format.
%
% The format of the RegisterHALDImage method is:
%
% size_t RegisterHALDImage(void)
%
*/
ModuleExport size_t RegisterHALDImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("HALD");
entry->decoder=(DecodeImageHandler *) ReadHALDImage;
entry->adjoin=MagickFalse;
entry->format_type=ImplicitFormatType;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->description=ConstantString("Identity Hald color lookup table image");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r H A L D I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterHALDImage() removes format registrations made by the
% HALD module from the list of supported formats.
%
% The format of the UnregisterHALDImage method is:
%
% UnregisterHALDImage(void)
%
*/
ModuleExport void UnregisterHALDImage(void)
{
(void) UnregisterMagickInfo("HALD");
}

809
ImageMagick/coders/hdr.c Normal file
View file

@ -0,0 +1,809 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% H H DDDD RRRR %
% H H D D R R %
% HHHHH D D RRRR %
% H H D D R R %
% H H DDDD R R %
% %
% %
% Read/Write Radiance RGBE Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/property.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/string-private.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteHDRImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s H D R %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsHDR() returns MagickTrue if the image format type, identified by the
% magick string, is Radiance RGBE image format.
%
% The format of the IsHDR method is:
%
% MagickBooleanType IsHDR(const unsigned char *magick,
% const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsHDR(const unsigned char *magick,
const size_t length)
{
if (length < 10)
return(MagickFalse);
if (LocaleNCompare((const char *) magick,"#?RADIANCE",10) == 0)
return(MagickTrue);
if (LocaleNCompare((const char *) magick,"#?RGBE",6) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d H D R I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadHDRImage() reads the Radiance RGBE image 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 ReadHDRImage method is:
%
% Image *ReadHDRImage(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 *ReadHDRImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
char
format[MaxTextExtent],
keyword[MaxTextExtent],
tag[MaxTextExtent],
value[MaxTextExtent];
double
gamma;
Image
*image;
int
c;
MagickBooleanType
status,
value_expected;
register PixelPacket
*q;
register unsigned char
*p;
register ssize_t
i,
x;
ssize_t
count,
y;
unsigned char
*end,
pixel[4],
*pixels;
/*
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);
}
/*
Decode image header.
*/
image->columns=0;
image->rows=0;
*format='\0';
c=ReadBlobByte(image);
if (c == EOF)
{
image=DestroyImage(image);
return((Image *) NULL);
}
while (isgraph(c) && (image->columns == 0) && (image->rows == 0))
{
if (c == (int) '#')
{
char
*comment;
register char
*p;
size_t
length;
/*
Read comment-- any text between # and end-of-line.
*/
length=MaxTextExtent;
comment=AcquireString((char *) NULL);
for (p=comment; comment != (char *) NULL; p++)
{
c=ReadBlobByte(image);
if ((c == EOF) || (c == (int) '\n'))
break;
if ((size_t) (p-comment+1) >= length)
{
*p='\0';
length<<=1;
comment=(char *) ResizeQuantumMemory(comment,length+
MaxTextExtent,sizeof(*comment));
if (comment == (char *) NULL)
break;
p=comment+strlen(comment);
}
*p=(char) c;
}
if (comment == (char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
*p='\0';
(void) SetImageProperty(image,"comment",comment);
comment=DestroyString(comment);
c=ReadBlobByte(image);
}
else
if (isalnum(c) == MagickFalse)
c=ReadBlobByte(image);
else
{
register char
*p;
/*
Determine a keyword and its value.
*/
p=keyword;
do
{
if ((size_t) (p-keyword) < (MaxTextExtent-1))
*p++=c;
c=ReadBlobByte(image);
} while (isalnum(c) || (c == '_'));
*p='\0';
value_expected=MagickFalse;
while ((isspace((int) ((unsigned char) c)) != 0) || (c == '='))
{
if (c == '=')
value_expected=MagickTrue;
c=ReadBlobByte(image);
}
if (LocaleCompare(keyword,"Y") == 0)
value_expected=MagickTrue;
if (value_expected == MagickFalse)
continue;
p=value;
while ((c != '\n') && (c != '\0'))
{
if ((size_t) (p-value) < (MaxTextExtent-1))
*p++=c;
c=ReadBlobByte(image);
}
*p='\0';
/*
Assign a value to the specified keyword.
*/
switch (*keyword)
{
case 'F':
case 'f':
{
if (LocaleCompare(keyword,"format") == 0)
{
(void) CopyMagickString(format,value,MaxTextExtent);
break;
}
(void) FormatLocaleString(tag,MaxTextExtent,"hdr:%s",keyword);
(void) SetImageProperty(image,tag,value);
break;
}
case 'G':
case 'g':
{
if (LocaleCompare(keyword,"gamma") == 0)
{
image->gamma=StringToDouble(value,(char **) NULL);
break;
}
(void) FormatLocaleString(tag,MaxTextExtent,"hdr:%s",keyword);
(void) SetImageProperty(image,tag,value);
break;
}
case 'P':
case 'p':
{
if (LocaleCompare(keyword,"primaries") == 0)
{
float
chromaticity[6],
white_point[2];
(void) sscanf(value,"%g %g %g %g %g %g %g %g",
&chromaticity[0],&chromaticity[1],&chromaticity[2],
&chromaticity[3],&chromaticity[4],&chromaticity[5],
&white_point[0],&white_point[1]);
image->chromaticity.red_primary.x=chromaticity[0];
image->chromaticity.red_primary.y=chromaticity[1];
image->chromaticity.green_primary.x=chromaticity[2];
image->chromaticity.green_primary.y=chromaticity[3];
image->chromaticity.blue_primary.x=chromaticity[4];
image->chromaticity.blue_primary.y=chromaticity[5];
image->chromaticity.white_point.x=white_point[0],
image->chromaticity.white_point.y=white_point[1];
break;
}
(void) FormatLocaleString(tag,MaxTextExtent,"hdr:%s",keyword);
(void) SetImageProperty(image,tag,value);
break;
}
case 'Y':
case 'y':
{
if (strcmp(keyword,"Y") == 0)
{
int
height,
width;
(void) sscanf(value,"%d +X %d",&height,&width);
image->columns=(size_t) width;
image->rows=(size_t) height;
break;
}
(void) FormatLocaleString(tag,MaxTextExtent,"hdr:%s",keyword);
(void) SetImageProperty(image,tag,value);
break;
}
default:
{
(void) FormatLocaleString(tag,MaxTextExtent,"hdr:%s",keyword);
(void) SetImageProperty(image,tag,value);
break;
}
}
}
if ((image->columns == 0) && (image->rows == 0))
while (isspace((int) ((unsigned char) c)) != 0)
c=ReadBlobByte(image);
}
if ((LocaleCompare(format,"32-bit_rle_rgbe") != 0) &&
(LocaleCompare(format,"32-bit_rle_xyze") != 0))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(CorruptImageError,"NegativeOrZeroImageSize");
(void) SetImageColorspace(image,RGBColorspace);
if (LocaleCompare(format,"32-bit_rle_xyze") == 0)
(void) SetImageColorspace(image,XYZColorspace);
image->compression=(image->columns < 8) || (image->columns > 0x7ffff) ?
NoCompression : RLECompression;
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
Read RGBE (red+green+blue+exponent) pixels.
*/
pixels=(unsigned char *) AcquireQuantumMemory(image->columns,4*
sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
for (y=0; y < (ssize_t) image->rows; y++)
{
if (image->compression != RLECompression)
{
count=ReadBlob(image,4*image->columns*sizeof(*pixels),pixels);
if (count != (ssize_t) (4*image->columns*sizeof(*pixels)))
break;
}
else
{
count=ReadBlob(image,4*sizeof(*pixel),pixel);
if (count != 4)
break;
if ((size_t) ((((size_t) pixel[2]) << 8) | pixel[3]) != image->columns)
{
(void) memcpy(pixels,pixel,4*sizeof(*pixel));
count=ReadBlob(image,4*(image->columns-1)*sizeof(*pixels),pixels+4);
image->compression=NoCompression;
}
else
{
p=pixels;
for (i=0; i < 4; i++)
{
end=&pixels[(i+1)*image->columns];
while (p < end)
{
count=ReadBlob(image,2*sizeof(*pixel),pixel);
if (count < 1)
break;
if (pixel[0] > 128)
{
count=(ssize_t) pixel[0]-128;
if ((count == 0) || (count > (ssize_t) (end-p)))
break;
while (count-- > 0)
*p++=pixel[1];
}
else
{
count=(ssize_t) pixel[0];
if ((count == 0) || (count > (ssize_t) (end-p)))
break;
*p++=pixel[1];
if (--count > 0)
{
count=ReadBlob(image,(size_t) count*sizeof(*p),p);
if (count < 1)
break;
p+=count;
}
}
}
}
}
}
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
i=0;
for (x=0; x < (ssize_t) image->columns; x++)
{
if (image->compression == RLECompression)
{
pixel[0]=pixels[x];
pixel[1]=pixels[x+image->columns];
pixel[2]=pixels[x+2*image->columns];
pixel[3]=pixels[x+3*image->columns];
}
else
{
pixel[0]=pixels[i++];
pixel[1]=pixels[i++];
pixel[2]=pixels[i++];
pixel[3]=pixels[i++];
}
SetPixelRed(q,0);
SetPixelGreen(q,0);
SetPixelBlue(q,0);
if (pixel[3] != 0)
{
gamma=pow(2.0,pixel[3]-(128.0+8.0));
SetPixelRed(q,ClampToQuantum(QuantumRange*gamma*pixel[0]));
SetPixelGreen(q,ClampToQuantum(QuantumRange*gamma*pixel[1]));
SetPixelBlue(q,ClampToQuantum(QuantumRange*gamma*pixel[2]));
}
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r H D R I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterHDRImage() adds attributes for the Radiance RGBE image format to the
% list of supported formats. The attributes include the image format tag, a
% method to read and/or write the format, whether the format supports the
% saving of more than one frame to the same file or blob, whether the format
% supports native in-memory I/O, and a brief description of the format.
%
% The format of the RegisterHDRImage method is:
%
% size_t RegisterHDRImage(void)
%
*/
ModuleExport size_t RegisterHDRImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("HDR");
entry->decoder=(DecodeImageHandler *) ReadHDRImage;
entry->encoder=(EncodeImageHandler *) WriteHDRImage;
entry->description=ConstantString("Radiance RGBE image format");
entry->module=ConstantString("HDR");
entry->magick=(IsImageFormatHandler *) IsHDR;
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r H D R I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterHDRImage() removes format registrations made by the
% HDR module from the list of supported formats.
%
% The format of the UnregisterHDRImage method is:
%
% UnregisterHDRImage(void)
%
*/
ModuleExport void UnregisterHDRImage(void)
{
(void) UnregisterMagickInfo("HDR");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e H D R I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteHDRImage() writes an image in the Radience RGBE image format.
%
% The format of the WriteHDRImage method is:
%
% MagickBooleanType WriteHDRImage(const ImageInfo *image_info,
% Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static size_t HDRWriteRunlengthPixels(Image *image,unsigned char *pixels)
{
#define MinimumRunlength 4
register size_t
p,
q;
size_t
runlength;
ssize_t
count,
previous_count;
unsigned char
pixel[2];
for (p=0; p < image->columns; )
{
q=p;
runlength=0;
previous_count=0;
while ((runlength < MinimumRunlength) && (q < image->columns))
{
q+=runlength;
previous_count=(ssize_t) runlength;
runlength=1;
while ((pixels[q] == pixels[q+runlength]) &&
((q+runlength) < image->columns) && (runlength < 127))
runlength++;
}
if ((previous_count > 1) && (previous_count == (ssize_t) (q-p)))
{
pixel[0]=(unsigned char) (128+previous_count);
pixel[1]=pixels[p];
if (WriteBlob(image,2*sizeof(*pixel),pixel) < 1)
break;
p=q;
}
while (p < q)
{
count=(ssize_t) (q-p);
if (count > 128)
count=128;
pixel[0]=(unsigned char) count;
if (WriteBlob(image,sizeof(*pixel),pixel) < 1)
break;
if (WriteBlob(image,(size_t) count*sizeof(*pixel),&pixels[p]) < 1)
break;
p+=count;
}
if (runlength >= MinimumRunlength)
{
pixel[0]=(unsigned char) (128+runlength);
pixel[1]=pixels[q];
if (WriteBlob(image,2*sizeof(*pixel),pixel) < 1)
break;
p+=runlength;
}
}
return(p);
}
static MagickBooleanType WriteHDRImage(const ImageInfo *image_info,Image *image)
{
char
header[MaxTextExtent];
const char
*property;
MagickBooleanType
status;
register const PixelPacket
*p;
register ssize_t
i,
x;
size_t
length;
ssize_t
count,
y;
unsigned char
pixel[4],
*pixels;
/*
Open output image file.
*/
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);
if (IsRGBColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
/*
Write header.
*/
(void) ResetMagickMemory(header,' ',MaxTextExtent);
length=CopyMagickString(header,"#?RGBE\n",MaxTextExtent);
(void) WriteBlob(image,length,(unsigned char *) header);
property=GetImageProperty(image,"comment");
if ((property != (const char *) NULL) &&
(strchr(property,'\n') == (char *) NULL))
{
count=FormatLocaleString(header,MaxTextExtent,"#%s\n",property);
(void) WriteBlob(image,(size_t) count,(unsigned char *) header);
}
property=GetImageProperty(image,"hdr:exposure");
if (property != (const char *) NULL)
{
count=FormatLocaleString(header,MaxTextExtent,"EXPOSURE=%g\n",
atof(property));
(void) WriteBlob(image,(size_t) count,(unsigned char *) header);
}
if (image->gamma != 0.0)
{
count=FormatLocaleString(header,MaxTextExtent,"GAMMA=%g\n",image->gamma);
(void) WriteBlob(image,(size_t) count,(unsigned char *) header);
}
count=FormatLocaleString(header,MaxTextExtent,
"PRIMARIES=%g %g %g %g %g %g %g %g\n",
image->chromaticity.red_primary.x,image->chromaticity.red_primary.y,
image->chromaticity.green_primary.x,image->chromaticity.green_primary.y,
image->chromaticity.blue_primary.x,image->chromaticity.blue_primary.y,
image->chromaticity.white_point.x,image->chromaticity.white_point.y);
(void) WriteBlob(image,(size_t) count,(unsigned char *) header);
length=CopyMagickString(header,"FORMAT=32-bit_rle_rgbe\n\n",MaxTextExtent);
(void) WriteBlob(image,length,(unsigned char *) header);
count=FormatLocaleString(header,MaxTextExtent,"-Y %.20g +X %.20g\n",
(double) image->rows,(double) image->columns);
(void) WriteBlob(image,(size_t) count,(unsigned char *) header);
/*
Write HDR pixels.
*/
pixels=(unsigned char *) AcquireQuantumMemory(image->columns,4*
sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
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;
if ((image->columns >= 8) && (image->columns <= 0x7ffff))
{
pixel[0]=2;
pixel[1]=2;
pixel[2]=(unsigned char) (image->columns >> 8);
pixel[3]=(unsigned char) (image->columns & 0xff);
count=WriteBlob(image,4*sizeof(*pixel),pixel);
if (count != (ssize_t) (4*sizeof(*pixel)))
break;
}
i=0;
for (x=0; x < (ssize_t) image->columns; x++)
{
double
gamma;
pixel[0]=0;
pixel[1]=0;
pixel[2]=0;
pixel[3]=0;
gamma=QuantumScale*GetPixelRed(p);
if ((QuantumScale*GetPixelGreen(p)) > gamma)
gamma=QuantumScale*GetPixelGreen(p);
if ((QuantumScale*GetPixelBlue(p)) > gamma)
gamma=QuantumScale*GetPixelBlue(p);
if (gamma > MagickEpsilon)
{
int
exponent;
gamma=frexp(gamma,&exponent)*256.0/gamma;
pixel[0]=(unsigned char) (gamma*QuantumScale*GetPixelRed(p));
pixel[1]=(unsigned char) (gamma*QuantumScale*GetPixelGreen(p));
pixel[2]=(unsigned char) (gamma*QuantumScale*GetPixelBlue(p));
pixel[3]=(unsigned char) (exponent+128);
}
if ((image->columns >= 8) && (image->columns <= 0x7ffff))
{
pixels[x]=pixel[0];
pixels[x+image->columns]=pixel[1];
pixels[x+2*image->columns]=pixel[2];
pixels[x+3*image->columns]=pixel[3];
}
else
{
pixels[i++]=pixel[0];
pixels[i++]=pixel[1];
pixels[i++]=pixel[2];
pixels[i++]=pixel[3];
}
p++;
}
if ((image->columns >= 8) && (image->columns <= 0x7ffff))
{
for (i=0; i < 4; i++)
length=HDRWriteRunlengthPixels(image,&pixels[i*image->columns]);
}
else
{
count=WriteBlob(image,4*image->columns*sizeof(*pixel),pixel);
if (count != (ssize_t) (4*image->columns*sizeof(*pixel)))
break;
}
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
(void) CloseBlob(image);
return(MagickTrue);
}

View file

@ -0,0 +1,393 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% H H IIIII SSSSS TTTTT OOO GGGG RRRR AAA M M %
% H H I SS T O O G R R A A MM MM %
% HHHHH I SSS T O O G GG RRRR AAAAA M M M %
% H H I SS T O O G G R R A A M M %
% H H IIIII SSSSS T OOO GGG R R A A M M %
% %
% %
% Write A Histogram Image. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/property.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/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/geometry.h"
#include "magick/histogram.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/option.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/resource_.h"
#include "magick/static.h"
#include "magick/statistic.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/token.h"
#include "magick/utility.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteHISTOGRAMImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r H I S T O G R A M I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterHISTOGRAMImage() adds attributes for the Histogram image format
% to the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterHISTOGRAMImage method is:
%
% size_t RegisterHISTOGRAMImage(void)
%
*/
ModuleExport size_t RegisterHISTOGRAMImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("HISTOGRAM");
entry->encoder=(EncodeImageHandler *) WriteHISTOGRAMImage;
entry->adjoin=MagickFalse;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Histogram of the image");
entry->module=ConstantString("HISTOGRAM");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r H I S T O G R A M I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterHISTOGRAMImage() removes format registrations made by the
% HISTOGRAM module from the list of supported formats.
%
% The format of the UnregisterHISTOGRAMImage method is:
%
% UnregisterHISTOGRAMImage(void)
%
*/
ModuleExport void UnregisterHISTOGRAMImage(void)
{
(void) UnregisterMagickInfo("HISTOGRAM");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e H I S T O G R A M I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteHISTOGRAMImage() writes an image to a file in Histogram format.
% The image shows a histogram of the color (or gray) values in the image. The
% image consists of three overlaid histograms: a red one for the red channel,
% a green one for the green channel, and a blue one for the blue channel. The
% image comment contains a list of unique pixel values and the number of times
% each occurs in the image.
%
% This method is strongly based on a similar one written by
% muquit@warm.semcor.com which in turn is based on ppmhistmap of netpbm.
%
% The format of the WriteHISTOGRAMImage method is:
%
% MagickBooleanType WriteHISTOGRAMImage(const ImageInfo *image_info,
% Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static inline size_t MagickMax(const size_t x,const size_t y)
{
if (x > y)
return(x);
return(y);
}
static MagickBooleanType WriteHISTOGRAMImage(const ImageInfo *image_info,
Image *image)
{
#define HistogramDensity "256x200"
ChannelType
channel;
char
filename[MaxTextExtent];
const char
*option;
ExceptionInfo
*exception;
Image
*histogram_image;
ImageInfo
*write_info;
MagickBooleanType
status;
MagickPixelPacket
*histogram;
MagickRealType
maximum,
scale;
RectangleInfo
geometry;
register const PixelPacket
*p;
register PixelPacket
*q,
*r;
register ssize_t
x;
size_t
length;
ssize_t
y;
/*
Allocate histogram image.
*/
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_info->filename);
SetGeometry(image,&geometry);
if (image_info->density == (char *) NULL)
(void) ParseAbsoluteGeometry(HistogramDensity,&geometry);
else
(void) ParseAbsoluteGeometry(image_info->density,&geometry);
histogram_image=CloneImage(image,geometry.width,geometry.height,MagickTrue,
&image->exception);
if (histogram_image == (Image *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
(void) SetImageStorageClass(histogram_image,DirectClass);
/*
Allocate histogram count arrays.
*/
length=MagickMax((size_t) ScaleQuantumToChar(QuantumRange)+1UL,
histogram_image->columns);
histogram=(MagickPixelPacket *) AcquireQuantumMemory(length,
sizeof(*histogram));
if (histogram == (MagickPixelPacket *) NULL)
{
histogram_image=DestroyImage(histogram_image);
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
}
/*
Initialize histogram count arrays.
*/
channel=image_info->channel;
(void) ResetMagickMemory(histogram,0,length*sizeof(*histogram));
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;
for (x=0; x < (ssize_t) image->columns; x++)
{
if ((channel & RedChannel) != 0)
histogram[ScaleQuantumToChar(GetPixelRed(p))].red++;
if ((channel & GreenChannel) != 0)
histogram[ScaleQuantumToChar(GetPixelGreen(p))].green++;
if ((channel & BlueChannel) != 0)
histogram[ScaleQuantumToChar(GetPixelBlue(p))].blue++;
p++;
}
}
maximum=histogram[0].red;
for (x=0; x < (ssize_t) histogram_image->columns; x++)
{
if (((channel & RedChannel) != 0) && (maximum < histogram[x].red))
maximum=histogram[x].red;
if (((channel & GreenChannel) != 0) && (maximum < histogram[x].green))
maximum=histogram[x].green;
if (((channel & BlueChannel) != 0) && (maximum < histogram[x].blue))
maximum=histogram[x].blue;
}
scale=(MagickRealType) histogram_image->rows/maximum;
/*
Initialize histogram image.
*/
exception=(&image->exception);
(void) QueryColorDatabase("#000",&histogram_image->background_color,
&image->exception);
(void) SetImageBackgroundColor(histogram_image);
for (x=0; x < (ssize_t) histogram_image->columns; x++)
{
q=GetAuthenticPixels(histogram_image,x,0,1,histogram_image->rows,exception);
if (q == (PixelPacket *) NULL)
break;
if ((channel & RedChannel) != 0)
{
y=(ssize_t) ceil(histogram_image->rows-scale*histogram[x].red-0.5);
r=q+y;
for ( ; y < (ssize_t) histogram_image->rows; y++)
{
SetPixelRed(r,QuantumRange);
r++;
}
}
if ((channel & GreenChannel) != 0)
{
y=(ssize_t) ceil(histogram_image->rows-scale*histogram[x].green-0.5);
r=q+y;
for ( ; y < (ssize_t) histogram_image->rows; y++)
{
SetPixelGreen(r,QuantumRange);
r++;
}
}
if ((channel & BlueChannel) != 0)
{
y=(ssize_t) ceil(histogram_image->rows-scale*histogram[x].blue-0.5);
r=q+y;
for ( ; y < (ssize_t) histogram_image->rows; y++)
{
SetPixelBlue(r,QuantumRange);
r++;
}
}
if (SyncAuthenticPixels(histogram_image,exception) == MagickFalse)
break;
status=SetImageProgress(image,SaveImageTag,y,histogram_image->rows);
if (status == MagickFalse)
break;
}
/*
Relinquish resources.
*/
histogram=(MagickPixelPacket *) RelinquishMagickMemory(histogram);
option=GetImageOption(image_info,"histogram:unique-colors");
if ((option == (const char *) NULL) || (IsMagickTrue(option) != MagickFalse))
{
FILE
*file;
int
unique_file;
/*
Add a unique colors as an image comment.
*/
file=(FILE *) NULL;
unique_file=AcquireUniqueFileResource(filename);
if (unique_file != -1)
file=fdopen(unique_file,"wb");
if ((unique_file != -1) && (file != (FILE *) NULL))
{
char
*property;
(void) GetNumberColors(image,file,&image->exception);
(void) fclose(file);
property=FileToString(filename,~0UL,&image->exception);
if (property != (char *) NULL)
{
(void) SetImageProperty(histogram_image,"comment",property);
property=DestroyString(property);
}
}
(void) RelinquishUniqueFileResource(filename);
}
/*
Write Histogram image.
*/
(void) CopyMagickString(histogram_image->filename,image_info->filename,
MaxTextExtent);
write_info=CloneImageInfo(image_info);
(void) SetImageInfo(write_info,1,&image->exception);
if (LocaleCompare(write_info->magick,"HISTOGRAM") == 0)
(void) FormatLocaleString(histogram_image->filename,MaxTextExtent,
"miff:%s",write_info->filename);
status=WriteImage(write_info,histogram_image);
histogram_image=DestroyImage(histogram_image);
write_info=DestroyImageInfo(write_info);
return(status);
}

344
ImageMagick/coders/hrz.c Normal file
View file

@ -0,0 +1,344 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% H H RRRR ZZZZZ %
% H H R R ZZ %
% HHHHH RRRR Z %
% H H R R ZZ %
% H H R R ZZZZZ %
% %
% %
% Read/Write Slow Scan TeleVision Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteHRZImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d H R Z I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadHRZImage() reads a Slow Scan TeleVision 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 ReadHRZImage method is:
%
% Image *ReadHRZImage(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 *ReadHRZImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
Image
*image;
MagickBooleanType
status;
register ssize_t
x;
register PixelPacket
*q;
register unsigned char
*p;
ssize_t
count,
y;
size_t
length;
unsigned char
*pixels;
/*
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);
}
/*
Convert HRZ raster image to pixel packets.
*/
image->columns=256;
image->rows=240;
image->depth=8;
pixels=(unsigned char *) AcquireQuantumMemory(image->columns,3*
sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
length=(size_t) (3*image->columns);
for (y=0; y < (ssize_t) image->rows; y++)
{
count=ReadBlob(image,length,pixels);
if ((size_t) count != length)
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
p=pixels;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelRed(q,ScaleCharToQuantum(4**p++));
SetPixelGreen(q,ScaleCharToQuantum(4**p++));
SetPixelBlue(q,ScaleCharToQuantum(4**p++));
SetPixelOpacity(q,OpaqueOpacity);
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
break;
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r H R Z I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterHRZImage() adds attributes for the HRZ X image format to the list
% of supported formats. The attributes include the image format tag, a
% method to read and/or write the format, whether the format supports the
% saving of more than one frame to the same file or blob, whether the format
% supports native in-memory I/O, and a brief description of the format.
%
% The format of the RegisterHRZImage method is:
%
% size_t RegisterHRZImage(void)
%
*/
ModuleExport size_t RegisterHRZImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("HRZ");
entry->decoder=(DecodeImageHandler *) ReadHRZImage;
entry->encoder=(EncodeImageHandler *) WriteHRZImage;
entry->adjoin=MagickFalse;
entry->description=ConstantString("Slow Scan TeleVision");
entry->module=ConstantString("HRZ");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r H R Z I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterHRZImage() removes format registrations made by the
% HRZ module from the list of supported formats.
%
% The format of the UnregisterHRZImage method is:
%
% UnregisterHRZImage(void)
%
*/
ModuleExport void UnregisterHRZImage(void)
{
(void) UnregisterMagickInfo("HRZ");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e H R Z I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteHRZImage() writes an image to a file in HRZ X image format.
%
% The format of the WriteHRZImage method is:
%
% MagickBooleanType WriteHRZImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteHRZImage(const ImageInfo *image_info,Image *image)
{
Image
*hrz_image;
MagickBooleanType
status;
register const PixelPacket
*p;
register ssize_t
x,
y;
register unsigned char
*q;
ssize_t
count;
unsigned char
*pixels;
/*
Open output image file.
*/
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);
hrz_image=ResizeImage(image,256,240,image->filter,image->blur,
&image->exception);
if (hrz_image == (Image *) NULL)
return(MagickFalse);
if (IssRGBCompatibleColorspace(hrz_image->colorspace) == MagickFalse)
(void) TransformImageColorspace(hrz_image,sRGBColorspace);
/*
Allocate memory for pixels.
*/
pixels=(unsigned char *) AcquireQuantumMemory((size_t) hrz_image->columns,
3*sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
{
hrz_image=DestroyImage(hrz_image);
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
}
/*
Convert MIFF to HRZ raster pixels.
*/
for (y=0; y < (ssize_t) hrz_image->rows; y++)
{
p=GetVirtualPixels(hrz_image,0,y,hrz_image->columns,1,&image->exception);
if (p == (PixelPacket *) NULL)
break;
q=pixels;
for (x=0; x < (ssize_t) hrz_image->columns; x++)
{
*q++=ScaleQuantumToChar(GetPixelRed(p)/4);
*q++=ScaleQuantumToChar(GetPixelGreen(p)/4);
*q++=ScaleQuantumToChar(GetPixelBlue(p)/4);
p++;
}
count=WriteBlob(image,(size_t) (q-pixels),pixels);
if (count != (ssize_t) (q-pixels))
break;
status=SetImageProgress(image,SaveImageTag,y,hrz_image->rows);
if (status == MagickFalse)
break;
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
hrz_image=DestroyImage(hrz_image);
(void) CloseBlob(image);
return(MagickTrue);
}

452
ImageMagick/coders/html.c Normal file
View file

@ -0,0 +1,452 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% H H TTTTT M M L %
% H H T MM MM L %
% HHHHH T M M M L %
% H H T M M L %
% H H T M M LLLLL %
% %
% %
% Write A Client-Side Image Map Using %
% Image Montage & Directory Information. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/color-private.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/geometry.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/paint.h"
#include "magick/pixel-accessor.h"
#include "magick/property.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/utility.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteHTMLImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s H T M L %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsHTML() returns MagickTrue if the image format type, identified by the
% magick string, is HTML.
%
% The format of the IsHTML method is:
%
% MagickBooleanType IsHTML(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsHTML(const unsigned char *magick,const size_t length)
{
if (length < 5)
return(MagickFalse);
if (LocaleNCompare((char *) magick,"<html",5) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r H T M L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterHTMLImage() adds properties for the HTML image format to
% the list of supported formats. The properties include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterHTMLImage method is:
%
% size_t RegisterHTMLImage(void)
%
*/
ModuleExport size_t RegisterHTMLImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("HTM");
entry->encoder=(EncodeImageHandler *) WriteHTMLImage;
entry->magick=(IsImageFormatHandler *) IsHTML;
entry->adjoin=MagickFalse;
entry->description=ConstantString(
"Hypertext Markup Language and a client-side image map");
entry->module=ConstantString("HTML");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("HTML");
entry->encoder=(EncodeImageHandler *) WriteHTMLImage;
entry->magick=(IsImageFormatHandler *) IsHTML;
entry->adjoin=MagickFalse;
entry->description=ConstantString(
"Hypertext Markup Language and a client-side image map");
entry->module=ConstantString("HTML");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("SHTML");
entry->encoder=(EncodeImageHandler *) WriteHTMLImage;
entry->magick=(IsImageFormatHandler *) IsHTML;
entry->adjoin=MagickFalse;
entry->description=ConstantString(
"Hypertext Markup Language and a client-side image map");
entry->module=ConstantString("HTML");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r H T M L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterHTMLImage() removes format registrations made by the
% HTML module from the list of supported formats.
%
% The format of the UnregisterHTMLImage method is:
%
% UnregisterHTMLImage(void)
%
*/
ModuleExport void UnregisterHTMLImage(void)
{
(void) UnregisterMagickInfo("HTM");
(void) UnregisterMagickInfo("HTML");
(void) UnregisterMagickInfo("SHTML");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e H T M L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteHTMLImage() writes an image in the HTML encoded image format.
%
% The format of the WriteHTMLImage method is:
%
% MagickBooleanType WriteHTMLImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
%
*/
static MagickBooleanType WriteHTMLImage(const ImageInfo *image_info,
Image *image)
{
char
basename[MaxTextExtent],
buffer[MaxTextExtent],
filename[MaxTextExtent],
mapname[MaxTextExtent],
url[MaxTextExtent];
Image
*next;
ImageInfo
*write_info;
MagickBooleanType
status;
RectangleInfo
geometry;
register char
*p;
/*
Open image.
*/
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_info->filename);
status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
if (status == MagickFalse)
return(status);
(void) CloseBlob(image);
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
*url='\0';
if ((LocaleCompare(image_info->magick,"FTP") == 0) ||
(LocaleCompare(image_info->magick,"HTTP") == 0))
{
/*
Extract URL base from filename.
*/
p=strrchr(image->filename,'/');
if (p != (char *) NULL)
{
p++;
(void) CopyMagickString(url,image_info->magick,MaxTextExtent);
(void) ConcatenateMagickString(url,":",MaxTextExtent);
url[strlen(url)+p-image->filename]='\0';
(void) ConcatenateMagickString(url,image->filename,
p-image->filename+2);
(void) CopyMagickString(image->filename,p,MaxTextExtent);
}
}
/*
Refer to image map file.
*/
(void) CopyMagickString(filename,image->filename,MaxTextExtent);
AppendImageFormat("map",filename);
GetPathComponent(filename,BasePath,basename);
(void) CopyMagickString(mapname,basename,MaxTextExtent);
(void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
(void) CopyMagickString(filename,image->filename,MaxTextExtent);
write_info=CloneImageInfo(image_info);
write_info->adjoin=MagickTrue;
status=MagickTrue;
if (LocaleCompare(image_info->magick,"SHTML") != 0)
{
const char
*value;
/*
Open output image file.
*/
status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
if (status == MagickFalse)
return(status);
/*
Write the HTML image file.
*/
(void) WriteBlobString(image,"<?xml version=\"1.0\" "
"encoding=\"US-ASCII\"?>\n");
(void) WriteBlobString(image,"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML "
"1.0 Strict//EN\" "
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n");
(void) WriteBlobString(image,"<html>\n");
(void) WriteBlobString(image,"<head>\n");
value=GetImageProperty(image,"label");
if (value != (const char *) NULL)
(void) FormatLocaleString(buffer,MaxTextExtent,"<title>%s</title>\n",
value);
else
{
GetPathComponent(filename,BasePath,basename);
(void) FormatLocaleString(buffer,MaxTextExtent,
"<title>%s</title>\n",basename);
}
(void) WriteBlobString(image,buffer);
(void) WriteBlobString(image,"</head>\n");
(void) WriteBlobString(image,"<body style=\"text-align: center;\">\n");
(void) FormatLocaleString(buffer,MaxTextExtent,"<h1>%s</h1>\n",
image->filename);
(void) WriteBlobString(image,buffer);
(void) WriteBlobString(image,"<div>\n");
(void) CopyMagickString(filename,image->filename,MaxTextExtent);
AppendImageFormat("png",filename);
(void) FormatLocaleString(buffer,MaxTextExtent,"<img usemap=\"#%s\" "
"src=\"%s\" style=\"border: 0;\" alt=\"Image map\" />\n",mapname,
filename);
(void) WriteBlobString(image,buffer);
/*
Determine the size and location of each image tile.
*/
SetGeometry(image,&geometry);
if (image->montage != (char *) NULL)
(void) ParseAbsoluteGeometry(image->montage,&geometry);
/*
Write an image map.
*/
(void) FormatLocaleString(buffer,MaxTextExtent,
"<map id=\"%s\" name=\"%s\">\n",mapname,mapname);
(void) WriteBlobString(image,buffer);
(void) FormatLocaleString(buffer,MaxTextExtent," <area href=\"%s",url);
(void) WriteBlobString(image,buffer);
if (image->directory == (char *) NULL)
{
(void) FormatLocaleString(buffer,MaxTextExtent,
"%s\" shape=\"rect\" coords=\"0,0,%.20g,%.20g\" alt=\"\" />\n",
image->filename,(double) geometry.width-1,(double) geometry.height-
1);
(void) WriteBlobString(image,buffer);
}
else
for (p=image->directory; *p != '\0'; p++)
if (*p != '\n')
(void) WriteBlobByte(image,(unsigned char) *p);
else
{
(void) FormatLocaleString(buffer,MaxTextExtent,"\" shape="
"\"rect\" coords=\"%.20g,%.20g,%.20g,%.20g\" alt=\"\" />\n",
(double) geometry.x,(double) geometry.y,(double) (geometry.x+
geometry.width-1),(double) (geometry.y+geometry.height-1));
(void) WriteBlobString(image,buffer);
if (*(p+1) != '\0')
{
(void) FormatLocaleString(buffer,MaxTextExtent,
" <area href=%s\"",url);
(void) WriteBlobString(image,buffer);
}
geometry.x+=(ssize_t) geometry.width;
if ((geometry.x+4) >= (ssize_t) image->columns)
{
geometry.x=0;
geometry.y+=(ssize_t) geometry.height;
}
}
(void) WriteBlobString(image,"</map>\n");
(void) CopyMagickString(filename,image->filename,MaxTextExtent);
(void) WriteBlobString(image,"</div>\n");
(void) WriteBlobString(image,"</body>\n");
(void) WriteBlobString(image,"</html>\n");
(void) CloseBlob(image);
/*
Write the image as PNG.
*/
(void) CopyMagickString(image->filename,filename,MaxTextExtent);
AppendImageFormat("png",image->filename);
next=GetNextImageInList(image);
image->next=NewImageList();
(void) CopyMagickString(image->magick,"PNG",MaxTextExtent);
(void) WriteImage(write_info,image);
image->next=next;
/*
Determine image map filename.
*/
GetPathComponent(image->filename,BasePath,filename);
(void) ConcatenateMagickString(filename,"_map.shtml",MaxTextExtent);
(void) CopyMagickString(image->filename,filename,MaxTextExtent);
}
/*
Open image map.
*/
status=OpenBlob(write_info,image,WriteBinaryBlobMode,&image->exception);
if (status == MagickFalse)
return(status);
write_info=DestroyImageInfo(write_info);
/*
Determine the size and location of each image tile.
*/
SetGeometry(image,&geometry);
if (image->montage != (char *) NULL)
(void) ParseAbsoluteGeometry(image->montage,&geometry);
/*
Write an image map.
*/
(void) FormatLocaleString(buffer,MaxTextExtent,
"<map id=\"%s\" name=\"%s\">\n",mapname,mapname);
(void) WriteBlobString(image,buffer);
(void) FormatLocaleString(buffer,MaxTextExtent," <area href=\"%s",url);
(void) WriteBlobString(image,buffer);
if (image->directory == (char *) NULL)
{
(void) FormatLocaleString(buffer,MaxTextExtent,
"%s\" shape=\"rect\" coords=\"0,0,%.20g,%.20g\" alt=\"\" />\n",
image->filename,(double) geometry.width-1,(double) geometry.height-1);
(void) WriteBlobString(image,buffer);
}
else
for (p=image->directory; *p != '\0'; p++)
if (*p != '\n')
(void) WriteBlobByte(image,(unsigned char) *p);
else
{
(void) FormatLocaleString(buffer,MaxTextExtent,"\" shape=\"rect\""
" coords=\"%.20g,%.20g,%.20g,%.20g\" alt=\"\" />\n",
(double) geometry.x,(double) geometry.y,geometry.x+(double)
geometry.width-1,geometry.y+(double) geometry.height-1);
(void) WriteBlobString(image,buffer);
if (*(p+1) != '\0')
{
(void) FormatLocaleString(buffer,MaxTextExtent,
" <area href=%s\"",url);
(void) WriteBlobString(image,buffer);
}
geometry.x+=(ssize_t) geometry.width;
if ((geometry.x+4) >= (ssize_t) image->columns)
{
geometry.x=0;
geometry.y+=(ssize_t) geometry.height;
}
}
(void) WriteBlobString(image,"</map>\n");
(void) CloseBlob(image);
(void) CopyMagickString(image->filename,filename,MaxTextExtent);
return(status);
}

1264
ImageMagick/coders/icon.c Normal file

File diff suppressed because it is too large Load diff

217
ImageMagick/coders/info.c Normal file
View file

@ -0,0 +1,217 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% IIIII N N FFFFF OOO %
% I NN N F O O %
% I N N N FFF O O %
% I N NN F O O %
% IIIII N N F OOO %
% %
% %
% Write Info About the Image. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/property.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/colorspace.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/identify.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/option.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/utility.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteINFOImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r I N F O I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterINFOImage() adds attributes for the INFO image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterINFOImage method is:
%
% size_t RegisterINFOImage(void)
%
*/
ModuleExport size_t RegisterINFOImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("INFO");
entry->encoder=(EncodeImageHandler *) WriteINFOImage;
entry->blob_support=MagickFalse;
entry->description=ConstantString("The image format and characteristics");
entry->module=ConstantString("INFO");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r I N F O I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterINFOImage() removes format registrations made by the
% INFO module from the list of supported formats.
%
% The format of the UnregisterINFOImage method is:
%
% UnregisterINFOImage(void)
%
*/
ModuleExport void UnregisterINFOImage(void)
{
(void) UnregisterMagickInfo("INFO");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e I N F O I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteINFOImage writes the pixel values as text numbers.
%
% The format of the WriteINFOImage method is:
%
% MagickBooleanType WriteINFOImage(const ImageInfo *image_info,
% Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteINFOImage(const ImageInfo *image_info,
Image *image)
{
const char
*format;
MagickBooleanType
status;
MagickOffsetType
scene;
/*
Open output image file.
*/
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,WriteBlobMode,&image->exception);
if (status == MagickFalse)
return(status);
scene=0;
do
{
format=GetImageOption(image_info,"format");
if (format == (char *) NULL)
{
(void) CopyMagickString(image->filename,image->magick_filename,
MaxTextExtent);
image->magick_columns=image->columns;
image->magick_rows=image->rows;
(void) IdentifyImage(image,GetBlobFileHandle(image),
image_info->verbose);
}
else
{
char
*text;
text=InterpretImageProperties(image_info,image,format);
if (text != (char *) NULL)
{
(void) WriteBlobString(image,text);
(void) WriteBlobString(image,"\n");
text=DestroyString(text);
}
}
if (GetNextImageInList(image) == (Image *) NULL)
break;
image=SyncNextImageInList(image);
status=SetImageProgress(image,SaveImagesTag,scene++,
GetImageListLength(image));
if (status == MagickFalse)
break;
} while (image_info->adjoin != MagickFalse);
(void) CloseBlob(image);
return(MagickTrue);
}

230
ImageMagick/coders/inline.c Normal file
View file

@ -0,0 +1,230 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% IIIII N N L IIIII N N EEEEE %
% I NN N L I NN N E %
% I N N N L I N N N EEE %
% I N NN L I N NN E %
% IIIII N N LLLLL IIIII N N EEEEE %
% %
% %
% Read Inline Images %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/client.h"
#include "magick/display.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/option.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/utility.h"
#include "magick/xwindow.h"
#include "magick/xwindow-private.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d I N L I N E I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadINLINEImage() reads base64-encoded inlines images.
%
% The format of the ReadINLINEImage method is:
%
% Image *ReadINLINEImage(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 inline size_t MagickMin(const size_t x,const size_t y)
{
if (x < y)
return(x);
return(y);
}
static Image *ReadINLINEImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
Image
*image;
MagickBooleanType
status;
register size_t
i;
size_t
quantum;
ssize_t
count;
unsigned char
*inline_image;
/*
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);
if (LocaleNCompare(image_info->filename,"data:",5) == 0)
return(ReadInlineImage(image_info,image_info->filename,exception));
image=AcquireImage(image_info);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
quantum=MagickMin((size_t) GetBlobSize(image),MagickMaxBufferExtent);
inline_image=(unsigned char *) AcquireQuantumMemory(quantum,
sizeof(*inline_image));
count=0;
for (i=0; inline_image != (unsigned char *) NULL; i+=count)
{
count=(ssize_t) ReadBlob(image,quantum,inline_image+i);
if (count <= 0)
{
count=0;
if (errno != EINTR)
break;
}
if (~((size_t) i) < (quantum+1))
{
inline_image=(unsigned char *) RelinquishMagickMemory(inline_image);
break;
}
inline_image=(unsigned char *) ResizeQuantumMemory(inline_image,i+quantum+1,
sizeof(*inline_image));
}
if (inline_image == (unsigned char *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
return((Image *) NULL);
}
inline_image[i+count]='\0';
image=DestroyImageList(image);
image=ReadInlineImage(image_info,(char *) inline_image,exception);
inline_image=(unsigned char *) RelinquishMagickMemory(inline_image);
return(image);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r I N L I N E I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterINLINEImage() adds attributes for the INLINE image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterINLINEImage method is:
%
% size_t RegisterINLINEImage(void)
%
*/
ModuleExport size_t RegisterINLINEImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("INLINE");
entry->decoder=(DecodeImageHandler *) ReadINLINEImage;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Base64-encoded inline images");
entry->module=ConstantString("INLINE");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r I N L I N E I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterINLINEImage() removes format registrations made by the
% INLINE module from the list of supported formats.
%
% The format of the UnregisterINLINEImage method is:
%
% UnregisterINLINEImage(void)
%
*/
ModuleExport void UnregisterINLINEImage(void)
{
(void) UnregisterMagickInfo("INLINE");
}

686
ImageMagick/coders/ipl.c Normal file
View file

@ -0,0 +1,686 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% IIIIIIIIII PPPPPPPP LL %
% II PP PP LL %
% II PP PP LL %
% II PP PP LL %
% II PPPPPPPP LL %
% II PP LL %
% II PP LL %
% IIIIIIIIII PP LLLLLLLL %
% %
% %
% %
% Read/Write Scanalytics IPLab Image Format %
% Sean Burke %
% 2008.05.07 %
% v 0.9 %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/option.h"
#include "magick/pixel-accessor.h"
#include "magick/property.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Typedef declarations.
*/
typedef struct _IPLInfo
{
unsigned int
tag,
size,
time,
z,
width,
height,
colors,
depth,
byteType;
} IPLInfo;
static MagickBooleanType
WriteIPLImage(const ImageInfo *,Image *);
void increase (void *pixel, int byteType){
switch(byteType){
case 0:(*((unsigned char *) pixel))++; break;
case 1:(*((signed int *) pixel))++; break;
case 2:(*((unsigned int *) pixel))++; break;
case 3:(*((signed long *) pixel))++; break;
default:(*((unsigned int *) pixel))++; break;
}
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s I P L %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsIPL() returns MagickTrue if the image format type, identified by the
% magick string, is IPL.
%
% The format of the IsIPL method is:
%
% MagickBooleanType IsIPL(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsIPL(const unsigned char *magick,const size_t length)
{
if (length < 4)
return(MagickFalse);
if (LocaleNCompare((const char *) magick,"data",4) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d I P L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadIPLImage() reads a Scanalytics IPLab image file and returns it. It
% allocates the memory necessary for the new Image structure and returns a
% pointer to the new image.
%
% According to the IPLab spec, the data is blocked out in five dimensions:
% { t, z, c, y, x }. When we return the image, the latter three are folded
% into the standard "Image" structure. The "scenes" (image_info->scene)
% correspond to the order: { {t0,z0}, {t0, z1}, ..., {t1,z0}, {t1,z1}... }
% The number of scenes is t*z.
%
% The format of the ReadIPLImage method is:
%
% Image *ReadIPLImage(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.
%
*/
void SetHeaderFromIPL(Image *image, IPLInfo *ipl){
image->columns = ipl->width;
image->rows = ipl->height;
image->depth = ipl->depth;
image->x_resolution = 1;
image->y_resolution = 1;
}
static Image *ReadIPLImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
/*
Declare variables.
*/
Image *image;
MagickBooleanType status;
register PixelPacket *q;
unsigned char magick[12], *pixels;
ssize_t count;
ssize_t y;
size_t t_count=0;
size_t length;
IPLInfo
ipl_info;
QuantumFormatType
quantum_format;
QuantumInfo
*quantum_info;
QuantumType
quantum_type;
/*
Open Image
*/
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);
}
/*
Read IPL image
*/
/*
Determine endianness
If we get back "iiii", we have LSB,"mmmm", MSB
*/
count=ReadBlob(image,4,magick);
(void) count;
if((LocaleNCompare((char *) magick,"iiii",4) == 0))
image->endian=LSBEndian;
else{
if((LocaleNCompare((char *) magick,"mmmm",4) == 0))
image->endian=MSBEndian;
else{
ThrowReaderException(CorruptImageError, "ImproperImageHeader");
}
}
/* Skip o'er the next 8 bytes (garbage) */
count=ReadBlob(image, 8, magick);
/*
Excellent, now we read the header unimpeded.
*/
count=ReadBlob(image,4,magick);
if((LocaleNCompare((char *) magick,"data",4) != 0))
ThrowReaderException(CorruptImageError, "ImproperImageHeader");
ipl_info.size=ReadBlobLong(image);
ipl_info.width=ReadBlobLong(image);
ipl_info.height=ReadBlobLong(image);
if((ipl_info.width == 0UL) || (ipl_info.height == 0UL))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
ipl_info.colors=ReadBlobLong(image);
if(ipl_info.colors == 3){ SetImageColorspace(image,sRGBColorspace);}
else { image->colorspace = GRAYColorspace; }
ipl_info.z=ReadBlobLong(image);
ipl_info.time=ReadBlobLong(image);
ipl_info.byteType=ReadBlobLong(image);
/* Initialize Quantum Info */
switch (ipl_info.byteType) {
case 0:
ipl_info.depth=8;
quantum_format = UnsignedQuantumFormat;
break;
case 1:
ipl_info.depth=16;
quantum_format = SignedQuantumFormat;
break;
case 2:
ipl_info.depth=16;
quantum_format = UnsignedQuantumFormat;
break;
case 3:
ipl_info.depth=32;
quantum_format = SignedQuantumFormat;
break;
case 4: ipl_info.depth=32;
quantum_format = FloatingPointQuantumFormat;
break;
case 5:
ipl_info.depth=8;
quantum_format = UnsignedQuantumFormat;
break;
case 6:
ipl_info.depth=16;
quantum_format = UnsignedQuantumFormat;
break;
case 10:
ipl_info.depth=64;
quantum_format = FloatingPointQuantumFormat;
break;
default:
ipl_info.depth=16;
quantum_format = UnsignedQuantumFormat;
break;
}
/*
Set number of scenes of image
*/
SetHeaderFromIPL(image, &ipl_info);
/* Thats all we need if we are pinging. */
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
length=image->columns;
quantum_type=GetQuantumType(image,exception);
do
{
SetHeaderFromIPL(image, &ipl_info);
if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
/*
printf("Length: %.20g, Memory size: %.20g\n", (double) length,(double)
image->depth);
*/
quantum_info=AcquireQuantumInfo(image_info,image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
status=SetQuantumFormat(image,quantum_info,quantum_format);
if (status == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
pixels=GetQuantumPixels(quantum_info);
if(image->columns != ipl_info.width){
/*
printf("Columns not set correctly! Wanted: %.20g, got: %.20g\n",
(double) ipl_info.width, (double) image->columns);
*/
}
/*
Covert IPL binary to pixel packets
*/
if(ipl_info.colors == 1){
for(y = 0; y < (ssize_t) image->rows; y++){
(void) ReadBlob(image, length*image->depth/8, pixels);
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
GrayQuantum,pixels,exception);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
}
else{
for(y = 0; y < (ssize_t) image->rows; y++){
(void) ReadBlob(image, length*image->depth/8, pixels);
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
RedQuantum,pixels,exception);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
for(y = 0; y < (ssize_t) image->rows; y++){
(void) ReadBlob(image, length*image->depth/8, pixels);
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
GreenQuantum,pixels,exception);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
for(y = 0; y < (ssize_t) image->rows; y++){
(void) ReadBlob(image, length*image->depth/8, pixels);
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
(void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
BlueQuantum,pixels,exception);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
}
SetQuantumImageType(image,quantum_type);
t_count++;
quantum_info = DestroyQuantumInfo(quantum_info);
if (EOFBlob(image) != MagickFalse)
{
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
break;
}
if(t_count < ipl_info.z * ipl_info.time){
/*
Proceed to next image.
*/
AcquireNextImage(image_info, image);
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
image=SyncNextImageInList(image);
status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
GetBlobSize(image));
if (status == MagickFalse)
break;
}
} while (t_count < ipl_info.z*ipl_info.time);
CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r I P L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterIPLImage() add attributes for the Scanalytics IPL image format to the
% list of supported formats.
%
%
*/
ModuleExport size_t RegisterIPLImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("IPL");
entry->decoder=(DecodeImageHandler *) ReadIPLImage;
entry->encoder=(EncodeImageHandler *) WriteIPLImage;
entry->magick=(IsImageFormatHandler *) IsIPL;
entry->adjoin=MagickTrue;
entry->description=ConstantString("IPL Image Sequence");
entry->module=ConstantString("IPL");
entry->endian_support=MagickTrue;
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r I P L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterIPLImage() removes format registrations made by the
% IPL module from the list of supported formats.
%
% The format of the UnregisterIPLImage method is:
%
% UnregisterIPLImage(void)
%
*/
ModuleExport void UnregisterIPLImage(void)
{
(void) UnregisterMagickInfo("IPL");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e I P L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteIPLImage() writes an image to a file in Scanalytics IPLabimage format.
%
% The format of the WriteIPLImage method is:
%
% MagickBooleanType WriteIPLImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: The image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteIPLImage(const ImageInfo *image_info,Image *image)
{
ExceptionInfo
*exception;
IPLInfo
ipl_info;
MagickBooleanType
status;
MagickOffsetType
scene;
register const PixelPacket
*p;
QuantumInfo
*quantum_info;
ssize_t
y;
unsigned char
*pixels;
/*
Open output image file.
*/
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);
scene=0;
quantum_info=AcquireQuantumInfo(image_info, image);
if ((quantum_info->format == UndefinedQuantumFormat) &&
(IsHighDynamicRangeImage(image,&image->exception) != MagickFalse))
SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat);
switch(quantum_info->depth){
case 8:
ipl_info.byteType = 0;
break;
case 16:
if(quantum_info->format == SignedQuantumFormat){
ipl_info.byteType = 2;
}
else{
ipl_info.byteType = 1;
}
break;
case 32:
if(quantum_info->format == FloatingPointQuantumFormat){
ipl_info.byteType = 3;
}
else{
ipl_info.byteType = 4;
}
break;
case 64:
ipl_info.byteType = 10;
break;
default:
ipl_info.byteType = 2;
break;
}
ipl_info.z = (unsigned int) GetImageListLength(image);
/* There is no current method for detecting whether we have T or Z stacks */
ipl_info.time = 1;
ipl_info.width = (unsigned int) image->columns;
ipl_info.height = (unsigned int) image->rows;
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
if(IssRGBCompatibleColorspace(image->colorspace) == MagickTrue) { ipl_info.colors = 3; }
else{ ipl_info.colors = 1; }
ipl_info.size = (unsigned int) (28 +
((image->depth)/8)*ipl_info.height*ipl_info.width*ipl_info.colors*ipl_info.z);
/* Ok! Calculations are done. Lets write this puppy down! */
/*
Write IPL header.
*/
/* Shockingly (maybe not if you have used IPLab), IPLab itself CANNOT read MSBEndian
files! The reader above can, but they cannot. For compatability reasons, I will leave
the code in here, but it is all but useless if you want to use IPLab. */
if(image_info->endian == MSBEndian)
(void) WriteBlob(image, 4, (const unsigned char *) "mmmm");
else{
image->endian = LSBEndian;
(void) WriteBlob(image, 4, (const unsigned char *) "iiii");
}
(void) WriteBlobLong(image, 4);
(void) WriteBlob(image, 4, (const unsigned char *) "100f");
(void) WriteBlob(image, 4, (const unsigned char *) "data");
(void) WriteBlobLong(image, ipl_info.size);
(void) WriteBlobLong(image, ipl_info.width);
(void) WriteBlobLong(image, ipl_info.height);
(void) WriteBlobLong(image, ipl_info.colors);
if(image_info->adjoin == MagickFalse)
(void) WriteBlobLong(image, 1);
else
(void) WriteBlobLong(image, ipl_info.z);
(void) WriteBlobLong(image, ipl_info.time);
(void) WriteBlobLong(image, ipl_info.byteType);
exception=(&image->exception);
do
{
/*
Convert MIFF to IPL raster pixels.
*/
pixels=GetQuantumPixels(quantum_info);
if(ipl_info.colors == 1){
/* Red frame */
for(y = 0; y < (ssize_t) ipl_info.height; y++){
p=GetAuthenticPixels(image,0,y,image->columns,1,exception);
if (p == (PixelPacket *) NULL)
break;
(void) ExportQuantumPixels(image,(const CacheView *) NULL, quantum_info,
GrayQuantum, pixels,&image->exception);
(void) WriteBlob(image, image->columns*image->depth/8, pixels);
}
}
if(ipl_info.colors == 3){
/* Red frame */
for(y = 0; y < (ssize_t) ipl_info.height; y++){
p=GetAuthenticPixels(image,0,y,image->columns,1,exception);
if (p == (PixelPacket *) NULL)
break;
(void) ExportQuantumPixels(image,(const CacheView *) NULL, quantum_info,
RedQuantum, pixels,&image->exception);
(void) WriteBlob(image, image->columns*image->depth/8, pixels);
}
/* Green frame */
for(y = 0; y < (ssize_t) ipl_info.height; y++){
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (PixelPacket *) NULL)
break;
(void) ExportQuantumPixels(image,(const CacheView *) NULL, quantum_info,
GreenQuantum, pixels,&image->exception);
(void) WriteBlob(image, image->columns*image->depth/8, pixels);
}
/* Blue frame */
for(y = 0; y < (ssize_t) ipl_info.height; y++){
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (PixelPacket *) NULL)
break;
(void) ExportQuantumPixels(image,(const CacheView *) NULL, quantum_info,
BlueQuantum, pixels,&image->exception);
(void) WriteBlob(image, image->columns*image->depth/8, pixels);
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
}
quantum_info=DestroyQuantumInfo(quantum_info);
if (GetNextImageInList(image) == (Image *) NULL)
break;
image=SyncNextImageInList(image);
status=SetImageProgress(image,SaveImagesTag,scene++,
GetImageListLength(image));
if (status == MagickFalse)
break;
}while (image_info->adjoin != MagickFalse);
(void) WriteBlob(image, 4, (const unsigned char *) "fini");
(void) WriteBlobLong(image, 0);
CloseBlob(image);
return(MagickTrue);
}

551
ImageMagick/coders/jbig.c Normal file
View file

@ -0,0 +1,551 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% JJJJJ BBBB IIIII GGGG %
% J B B I G %
% J BBBB I G GG %
% J J B B I G G %
% JJJ BBBB IIIII GGG %
% %
% %
% Read/Write JBIG Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/attribute.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/color-private.h"
#include "magick/colormap.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/geometry.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/nt-feature.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/string-private.h"
#include "magick/module.h"
#if defined(MAGICKCORE_JBIG_DELEGATE)
#include "jbig.h"
#endif
/*
Forward declarations.
*/
#if defined(MAGICKCORE_JBIG_DELEGATE)
static MagickBooleanType
WriteJBIGImage(const ImageInfo *,Image *);
#endif
#if defined(MAGICKCORE_JBIG_DELEGATE)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d J B I G I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadJBIGImage() reads a JBIG 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 ReadJBIGImage method is:
%
% Image *ReadJBIGImage(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 *ReadJBIGImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
Image
*image;
IndexPacket
index;
MagickStatusType
status;
register IndexPacket
*indexes;
register ssize_t
x;
register PixelPacket
*q;
register unsigned char
*p;
ssize_t
length,
y;
struct jbg_dec_state
jbig_info;
unsigned char
bit,
*buffer,
byte;
/*
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);
}
/*
Initialize JBIG toolkit.
*/
jbg_dec_init(&jbig_info);
jbg_dec_maxsize(&jbig_info,(unsigned long) image->columns,(unsigned long)
image->rows);
image->columns=jbg_dec_getwidth(&jbig_info);
image->rows=jbg_dec_getheight(&jbig_info);
image->depth=8;
image->storage_class=PseudoClass;
image->colors=2;
/*
Read JBIG file.
*/
buffer=(unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent,
sizeof(*buffer));
if (buffer == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
status=JBG_EAGAIN;
do
{
length=(ssize_t) ReadBlob(image,MagickMaxBufferExtent,buffer);
if (length == 0)
break;
p=buffer;
while ((length > 0) && ((status == JBG_EAGAIN) || (status == JBG_EOK)))
{
size_t
count;
status=jbg_dec_in(&jbig_info,p,length,&count);
p+=count;
length-=(ssize_t) count;
}
} while ((status == JBG_EAGAIN) || (status == JBG_EOK));
/*
Create colormap.
*/
image->columns=jbg_dec_getwidth(&jbig_info);
image->rows=jbg_dec_getheight(&jbig_info);
image->compression=JBIG2Compression;
if (AcquireImageColormap(image,2) == MagickFalse)
{
buffer=(unsigned char *) RelinquishMagickMemory(buffer);
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
image->colormap[0].red=0;
image->colormap[0].green=0;
image->colormap[0].blue=0;
image->colormap[1].red=QuantumRange;
image->colormap[1].green=QuantumRange;
image->colormap[1].blue=QuantumRange;
image->x_resolution=300;
image->y_resolution=300;
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
Convert X bitmap image to pixel packets.
*/
p=jbg_dec_getimage(&jbig_info,0);
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
bit=0;
byte=0;
for (x=0; x < (ssize_t) image->columns; x++)
{
if (bit == 0)
byte=(*p++);
index=(byte & 0x80) ? 0 : 1;
bit++;
byte<<=1;
if (bit == 8)
bit=0;
SetPixelIndex(indexes+x,index);
SetPixelRGBO(q,image->colormap+(ssize_t) index);
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
/*
Free scale resource.
*/
jbg_dec_free(&jbig_info);
buffer=(unsigned char *) RelinquishMagickMemory(buffer);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
#endif
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r J B I G I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterJBIGImage() adds attributes for the JBIG image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterJBIGImage method is:
%
% size_t RegisterJBIGImage(void)
%
*/
ModuleExport size_t RegisterJBIGImage(void)
{
#define JBIGDescription "Joint Bi-level Image experts Group interchange format"
char
version[MaxTextExtent];
MagickInfo
*entry;
*version='\0';
#if defined(JBG_VERSION)
(void) CopyMagickString(version,JBG_VERSION,MaxTextExtent);
#endif
entry=SetMagickInfo("BIE");
#if defined(MAGICKCORE_JBIG_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadJBIGImage;
entry->encoder=(EncodeImageHandler *) WriteJBIGImage;
#endif
entry->adjoin=MagickFalse;
entry->description=ConstantString(JBIGDescription);
if (*version != '\0')
entry->version=ConstantString(version);
entry->module=ConstantString("JBIG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("JBG");
#if defined(MAGICKCORE_JBIG_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadJBIGImage;
entry->encoder=(EncodeImageHandler *) WriteJBIGImage;
#endif
entry->description=ConstantString(JBIGDescription);
if (*version != '\0')
entry->version=ConstantString(version);
entry->module=ConstantString("JBIG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("JBIG");
#if defined(MAGICKCORE_JBIG_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadJBIGImage;
entry->encoder=(EncodeImageHandler *) WriteJBIGImage;
#endif
entry->description=ConstantString(JBIGDescription);
if (*version != '\0')
entry->version=ConstantString(version);
entry->module=ConstantString("JBIG");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r J B I G I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterJBIGImage() removes format registrations made by the
% JBIG module from the list of supported formats.
%
% The format of the UnregisterJBIGImage method is:
%
% UnregisterJBIGImage(void)
%
*/
ModuleExport void UnregisterJBIGImage(void)
{
(void) UnregisterMagickInfo("BIE");
(void) UnregisterMagickInfo("JBG");
(void) UnregisterMagickInfo("JBIG");
}
#if defined(MAGICKCORE_JBIG_DELEGATE)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e J B I G I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteJBIGImage() writes an image in the JBIG encoded image format.
%
% The format of the WriteJBIGImage method is:
%
% MagickBooleanType WriteJBIGImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
%
*/
static void JBIGEncode(unsigned char *pixels,size_t length,void *data)
{
Image
*image;
image=(Image *) data;
(void) WriteBlob(image,length,pixels);
}
static MagickBooleanType WriteJBIGImage(const ImageInfo *image_info,
Image *image)
{
double
version;
MagickBooleanType
status;
MagickOffsetType
scene;
register const PixelPacket
*p;
register ssize_t
x;
register unsigned char
*q;
size_t
number_packets;
ssize_t
y;
struct jbg_enc_state
jbig_info;
unsigned char
bit,
byte,
*pixels;
/*
Open image file.
*/
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);
version=StringToDouble(JBG_VERSION,(char **) NULL);
scene=0;
do
{
/*
Allocate pixel data.
*/
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
number_packets=(image->columns+7)/8;
pixels=(unsigned char *) AcquireQuantumMemory(number_packets,
image->rows*sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
/*
Convert pixels to a bitmap.
*/
(void) SetImageType(image,BilevelType);
q=pixels;
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;
bit=0;
byte=0;
for (x=0; x < (ssize_t) image->columns; x++)
{
byte<<=1;
if (GetPixelIntensity(image,p) < (QuantumRange/2.0))
byte|=0x01;
bit++;
if (bit == 8)
{
*q++=byte;
bit=0;
byte=0;
}
p++;
}
if (bit != 0)
*q++=byte << (8-bit);
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
/*
Initialize JBIG info structure.
*/
jbg_enc_init(&jbig_info,(unsigned long) image->columns,(unsigned long)
image->rows,1,&pixels,(void (*)(unsigned char *,size_t,void *))
JBIGEncode,image);
if (image_info->scene != 0)
jbg_enc_layers(&jbig_info,(int) image_info->scene);
else
{
size_t
x_resolution,
y_resolution;
x_resolution=640;
y_resolution=480;
if (image_info->density != (char *) NULL)
{
GeometryInfo
geometry_info;
MagickStatusType
flags;
flags=ParseGeometry(image_info->density,&geometry_info);
x_resolution=geometry_info.rho;
y_resolution=geometry_info.sigma;
if ((flags & SigmaValue) == 0)
y_resolution=x_resolution;
}
if (image->units == PixelsPerCentimeterResolution)
{
x_resolution=(size_t) (100.0*2.54*x_resolution+0.5)/100.0;
y_resolution=(size_t) (100.0*2.54*y_resolution+0.5)/100.0;
}
(void) jbg_enc_lrlmax(&jbig_info,(unsigned long) x_resolution,
(unsigned long) y_resolution);
}
(void) jbg_enc_lrange(&jbig_info,-1,-1);
jbg_enc_options(&jbig_info,JBG_ILEAVE | JBG_SMID,JBG_TPDON | JBG_TPBON |
JBG_DPON,version < 1.6 ? -1 : 0,-1,-1);
/*
Write JBIG image.
*/
jbg_enc_out(&jbig_info);
jbg_enc_free(&jbig_info);
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (GetNextImageInList(image) == (Image *) NULL)
break;
image=SyncNextImageInList(image);
status=SetImageProgress(image,SaveImagesTag,scene++,
GetImageListLength(image));
if (status == MagickFalse)
break;
} while (image_info->adjoin != MagickFalse);
(void) CloseBlob(image);
return(MagickTrue);
}
#endif

386
ImageMagick/coders/jnx.c Normal file
View file

@ -0,0 +1,386 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% JJJ N N X X %
% J NN N X X %
% J N N N X %
% J J N NN X X %
% JJ N N X X %
% %
% %
% Read/Write Garmin Image Format %
% %
% John Cristy %
% July 2012 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/draw.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/module.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/pixel-accessor.h"
#include "magick/property.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
typedef struct _JNXInfo
{
int
version,
serial;
PointInfo
northeast,
southwest;
int
levels,
expire,
id,
crc,
signature;
unsigned int
offset;
int
order;
} JNXInfo;
typedef struct _JNXLevelInfo
{
int
count,
offset;
unsigned int
scale;
unsigned short
copyright[MaxTextExtent];
} JNXLevelInfo;
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d J N X I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadJNXImage() reads an image in the Garmin tile storage 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 ReadJNXImage method is:
%
% Image *ReadJNXImage(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 *ReadJNXImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
#define JNXMaxLevels 20
Image
*image,
*images;
JNXInfo
jnx_info;
JNXLevelInfo
jnx_level_info[JNXMaxLevels];
MagickBooleanType
status;
register ssize_t
i;
/*
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);
}
/*
Read JNX header.
*/
(void) ResetMagickMemory(&jnx_info,0,sizeof(jnx_info));
jnx_info.version=(int) ReadBlobLSBLong(image);
if ((jnx_info.version != 3) && (jnx_info.version != 4))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
jnx_info.serial=(int) ReadBlobLSBLong(image);
jnx_info.northeast.x=180.0*((int) ReadBlobLSBLong(image))/0x7fffffff;
jnx_info.northeast.y=180.0*((int) ReadBlobLSBLong(image))/0x7fffffff;
jnx_info.southwest.x=180.0*((int) ReadBlobLSBLong(image))/0x7fffffff;
jnx_info.southwest.y=180.0*((int) ReadBlobLSBLong(image))/0x7fffffff;
jnx_info.levels=(int) ReadBlobLSBLong(image);
if (jnx_info.levels > JNXMaxLevels)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
jnx_info.expire=(int) ReadBlobLSBLong(image);
jnx_info.id=(int) ReadBlobLSBLong(image);
jnx_info.crc=(int) ReadBlobLSBLong(image);
jnx_info.signature=(int) ReadBlobLSBLong(image);
jnx_info.offset=ReadBlobLSBLong(image);
if (jnx_info.version > 3)
jnx_info.order=(int) ReadBlobLSBLong(image);
else
if (jnx_info.version == 3)
jnx_info.order=30;
/*
Read JNX levels.
*/
(void) ResetMagickMemory(&jnx_level_info,0,sizeof(jnx_level_info));
for (i=0; i < (ssize_t) jnx_info.levels; i++)
{
jnx_level_info[i].count=(int) ReadBlobLSBLong(image);
if (jnx_level_info[i].count > 50000)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
jnx_level_info[i].offset=(int) ReadBlobLSBLong(image);
jnx_level_info[i].scale=ReadBlobLSBLong(image);
if (jnx_info.version > 3)
{
register ssize_t
j;
unsigned short
c;
(void) ReadBlobLSBLong(image);
j=0;
while ((c=ReadBlobLSBShort(image)) != 0)
if (j < (MaxTextExtent-1))
jnx_level_info[i].copyright[j++]=c;
jnx_level_info[i].copyright[j]=0;
}
}
/*
Read JNX tiles.
*/
images=NewImageList();
for (i=0; i < (ssize_t) jnx_info.levels; i++)
{
MagickOffsetType
offset;
register ssize_t
j;
offset=SeekBlob(image,(MagickOffsetType) jnx_level_info[i].offset,SEEK_SET);
if (offset != (MagickOffsetType) jnx_level_info[i].offset)
continue;
for (j=0; j < (ssize_t) jnx_level_info[i].count; j++)
{
Image
*tile_image;
ImageInfo
*read_info;
int
tile_offset;
MagickOffsetType
restore_offset;
PointInfo
northeast,
southwest;
ssize_t
count;
unsigned char
*blob;
unsigned int
tile_length;
northeast.x=180.0*((int) ReadBlobLSBLong(image))/0x7fffffff;
northeast.y=180.0*((int) ReadBlobLSBLong(image))/0x7fffffff;
southwest.x=180.0*((int) ReadBlobLSBLong(image))/0x7fffffff;
southwest.y=180.0*((int) ReadBlobLSBLong(image))/0x7fffffff;
(void) ReadBlobLSBShort(image); /* width */
(void) ReadBlobLSBShort(image); /* height */
tile_length=ReadBlobLSBLong(image);
tile_offset=(int) ReadBlobLSBLong(image);
restore_offset=TellBlob(image);
offset=SeekBlob(image,(MagickOffsetType) tile_offset,SEEK_SET);
if (offset != (MagickOffsetType) tile_offset)
continue;
/*
Read a tile.
*/
blob=(unsigned char *) AcquireQuantumMemory((size_t) tile_length+2,
sizeof(*blob));
if (blob == (unsigned char *) NULL)
{
if (images != (Image *) NULL)
images=DestroyImageList(images);
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
blob[0]=0xFF;
blob[1]=0xD8;
count=ReadBlob(image,tile_length,blob+2);
if (count != (ssize_t) tile_length)
{
if (images != (Image *) NULL)
images=DestroyImageList(images);
blob=(unsigned char *) RelinquishMagickMemory(blob);
ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
}
read_info=CloneImageInfo(image_info);
(void) CopyMagickString(read_info->magick,"JPEG",MaxTextExtent);
tile_image=BlobToImage(read_info,blob,tile_length+2,exception);
read_info=DestroyImageInfo(read_info);
blob=(unsigned char *) RelinquishMagickMemory(blob);
offset=SeekBlob(image,restore_offset,SEEK_SET);
if (tile_image == (Image *) NULL)
continue;
(void) CopyMagickString(tile_image->magick,image->magick,MaxTextExtent);
(void) FormatImageProperty(tile_image,"jnx:northeast","%.20g,%.20g",
northeast.x,northeast.y);
(void) FormatImageProperty(tile_image,"jnx:southwest","%.20g,%.20g",
southwest.x,southwest.y);
AppendImageToList(&images,tile_image);
}
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
MagickBooleanType
proceed;
proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) i,
(MagickSizeType) jnx_info.levels);
if (proceed == MagickFalse)
status=MagickFalse;
}
}
(void) CloseBlob(image);
image=DestroyImage(image);
if (images == (Image *) NULL)
return((Image *) NULL);
return(GetFirstImageInList(images));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r J N X I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterJNXImage() adds attributes for the JNX image format to the list
% of supported formats. The attributes include the image format tag, a
% method to read and/or write the format, whether the format supports the
% saving of more than one frame to the same file or blob, whether the format
% supports native in-memory I/O, and a brief description of the format.
%
% The format of the RegisterJNXImage method is:
%
% size_t RegisterJNXImage(void)
%
*/
ModuleExport size_t RegisterJNXImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("JNX");
entry->decoder=(DecodeImageHandler *) ReadJNXImage;
entry->description=ConstantString("Garmin tile format");
entry->seekable_stream=MagickTrue;
entry->module=ConstantString("JNX");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r J N X I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterJNXImage() removes format registrations made by the
% JNX module from the list of supported formats.
%
% The format of the UnregisterJNXImage method is:
%
% UnregisterJNXImage(void)
%
*/
ModuleExport void UnregisterJNXImage(void)
{
(void) UnregisterMagickInfo("JNX");
}

1143
ImageMagick/coders/jp2.c Normal file

File diff suppressed because it is too large Load diff

2740
ImageMagick/coders/jpeg.c Normal file

File diff suppressed because it is too large Load diff

300
ImageMagick/coders/label.c Normal file
View file

@ -0,0 +1,300 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% L AAA BBBB EEEEE L %
% L A A B B E L %
% L AAAAA BBBB EEE L %
% L A A B B E L %
% LLLLL A A BBBB EEEEE LLLLL %
% %
% %
% Read ASCII String As An Image. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/annotate.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/draw.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/pixel-accessor.h"
#include "magick/property.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/utility.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% 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);
if ((*label != '\0') && (image->rows != 0) && (image_info->pointsize == 0.0))
{
double
high,
low;
/*
Auto fit text into bounding box.
*/
status=GetMultilineTypeMetrics(image,draw_info,&metrics);
for ( ; ; )
{
(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;
width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
if ((width > image->columns) && (height > image->rows))
break;
draw_info->pointsize*=2.0;
}
high=draw_info->pointsize/2.0;
low=high/2.0;
while ((high-low) > 1.0)
{
draw_info->pointsize=(low+high)/2.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);
width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
if ((width <= image->columns) && (height <= image->rows))
low=draw_info->pointsize+1.0;
else
high=draw_info->pointsize-1.0;
}
for (draw_info->pointsize=(low+high)/2.0; (high-low) > 1.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);
width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5);
height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
if ((width <= image->columns) && (height <= image->rows))
break;
draw_info->pointsize--;
}
draw_info->pointsize=floor(draw_info->pointsize);
}
status=GetMultilineTypeMetrics(image,draw_info,&metrics);
if (status == MagickFalse)
{
InheritException(exception,&image->exception);
image=DestroyImageList(image);
return((Image *) NULL);
}
if (image->columns == 0)
image->columns=(size_t) (metrics.width+draw_info->stroke_width+1.5);
if (image->columns == 0)
image->columns=(size_t) (draw_info->pointsize+draw_info->stroke_width+1.5);
if (draw_info->gravity == UndefinedGravity)
{
(void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
-metrics.bounds.x1+draw_info->stroke_width/2.0,metrics.ascent+
draw_info->stroke_width/2.0);
(void) CloneString(&draw_info->geometry,geometry);
}
if (draw_info->direction == RightToLeftDirection)
{
if (draw_info->direction == RightToLeftDirection)
(void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",
image->columns-(metrics.bounds.x2+draw_info->stroke_width/2.0),
metrics.ascent+draw_info->stroke_width/2.0);
(void) CloneString(&draw_info->geometry,geometry);
}
if (image->rows == 0)
image->rows=(size_t) floor(metrics.height+draw_info->stroke_width+0.5);
if (image->rows == 0)
image->rows=(size_t) floor(draw_info->pointsize+draw_info->stroke_width+
0.5);
if (SetImageBackgroundColor(image) == MagickFalse)
{
InheritException(exception,&image->exception);
image=DestroyImageList(image);
return((Image *) NULL);
}
(void) AnnotateImage(image,draw_info);
if (image_info->pointsize == 0.0)
{
char
pointsize[MaxTextExtent];
(void) FormatLocaleString(pointsize,MaxTextExtent,"%.20g",
draw_info->pointsize);
(void) SetImageProperty(image,"label:pointsize",pointsize);
}
draw_info=DestroyDrawInfo(draw_info);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r L A B E L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterLABELImage() adds properties for the LABEL image format to
% the list of supported formats. The properties include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterLABELImage method is:
%
% size_t RegisterLABELImage(void)
%
*/
ModuleExport size_t RegisterLABELImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("LABEL");
entry->decoder=(DecodeImageHandler *) ReadLABELImage;
entry->adjoin=MagickFalse;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Image label");
entry->module=ConstantString("LABEL");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r L A B E L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterLABELImage() removes format registrations made by the
% LABEL module from the list of supported formats.
%
% The format of the UnregisterLABELImage method is:
%
% UnregisterLABELImage(void)
%
*/
ModuleExport void UnregisterLABELImage(void)
{
(void) UnregisterMagickInfo("LABEL");
}

308
ImageMagick/coders/mac.c Normal file
View file

@ -0,0 +1,308 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% %
% M M AAA CCCC %
% MM MM A A C %
% M M M AAAAA C %
% M M A A C %
% M M A A CCCC %
% %
% %
% Read MacPaint Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colormap.h"
#include "magick/colorspace.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d M A C I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadMACImage() reads an MacPaint 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 ReadMACImage method is:
%
% Image *ReadMACImage(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 *ReadMACImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
Image
*image;
MagickBooleanType
status;
register IndexPacket
*indexes;
register PixelPacket
*q;
register ssize_t
x;
register unsigned char
*p;
size_t
length;
ssize_t
offset,
y;
unsigned char
count,
bit,
byte,
*pixels;
/*
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);
}
/*
Read MAC X image.
*/
length=ReadBlobLSBShort(image);
if ((length & 0xff) != 0)
ThrowReaderException(CorruptImageError,"CorruptImage");
for (x=0; x < (ssize_t) 638; x++)
if (ReadBlobByte(image) == EOF)
ThrowReaderException(CorruptImageError,"CorruptImage");
image->columns=576;
image->rows=720;
image->depth=1;
if (AcquireImageColormap(image,2) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
Convert MAC raster image to pixel packets.
*/
length=(image->columns+7)/8;
pixels=(unsigned char *) AcquireQuantumMemory(length+1,sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
p=pixels;
offset=0;
for (y=0; y < (ssize_t) image->rows; )
{
count=(unsigned char) ReadBlobByte(image);
if (EOFBlob(image) != MagickFalse)
break;
if ((count <= 0) || (count >= 128))
{
byte=(unsigned char) (~ReadBlobByte(image));
count=(~count)+2;
while (count != 0)
{
*p++=byte;
offset++;
count--;
if (offset >= (ssize_t) length)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
p=pixels;
bit=0;
byte=0;
for (x=0; x < (ssize_t) image->columns; x++)
{
if (bit == 0)
byte=(*p++);
SetPixelIndex(indexes+x,((byte & 0x80) != 0 ?
0x01 : 0x00));
bit++;
byte<<=1;
if (bit == 8)
bit=0;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
offset=0;
p=pixels;
y++;
}
}
continue;
}
count++;
while (count != 0)
{
byte=(unsigned char) (~ReadBlobByte(image));
*p++=byte;
offset++;
count--;
if (offset >= (ssize_t) length)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
p=pixels;
bit=0;
byte=0;
for (x=0; x < (ssize_t) image->columns; x++)
{
if (bit == 0)
byte=(*p++);
SetPixelIndex(indexes+x,((byte & 0x80) != 0 ?
0x01 : 0x00));
bit++;
byte<<=1;
if (bit == 8)
bit=0;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
offset=0;
p=pixels;
y++;
}
}
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r M A C I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterMACImage() adds attributes for the MAC X image format to the list
% of supported formats. The attributes include the image format tag, a
% method to read and/or write the format, whether the format supports the
% saving of more than one frame to the same file or blob, whether the format
% supports native in-memory I/O, and a brief description of the format.
%
% The format of the RegisterMACImage method is:
%
% size_t RegisterMACImage(void)
%
*/
ModuleExport size_t RegisterMACImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("MAC");
entry->decoder=(DecodeImageHandler *) ReadMACImage;
entry->description=ConstantString("MAC Paint");
entry->module=ConstantString("MAC");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r M A C I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterMACImage() removes format registrations made by the
% MAC module from the list of supported formats.
%
% The format of the UnregisterMACImage method is:
%
% UnregisterMACImage(void)
%
*/
ModuleExport void UnregisterMACImage(void)
{
(void) UnregisterMagickInfo("MAC");
}

13564
ImageMagick/coders/magick.c Normal file

File diff suppressed because it is too large Load diff

439
ImageMagick/coders/map.c Normal file
View file

@ -0,0 +1,439 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M M AAA PPPP %
% MM MM A A P P %
% M M M AAAAA PPPP %
% M M A A P %
% M M A A P %
% %
% %
% Read/Write Image Colormaps As An Image File. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#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/colormap.h"
#include "magick/colormap-private.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/histogram.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/statistic.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteMAPImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d M A P I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadMAPImage() reads an image of raw RGB colormap and colormap index
% bytes 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 ReadMAPImage method is:
%
% Image *ReadMAPImage(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 *ReadMAPImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
Image
*image;
IndexPacket
index;
MagickBooleanType
status;
register IndexPacket
*indexes;
register ssize_t
x;
register PixelPacket
*q;
register ssize_t
i;
register unsigned char
*p;
size_t
depth,
packet_size,
quantum;
ssize_t
count,
y;
unsigned char
*colormap,
*pixels;
/*
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);
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(OptionError,"MustSpecifyImageSize");
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
/*
Initialize image structure.
*/
image->storage_class=PseudoClass;
status=AcquireImageColormap(image,(size_t)
(image->offset != 0 ? image->offset : 256));
if (status == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
depth=GetImageQuantumDepth(image,MagickTrue);
packet_size=(size_t) (depth/8);
pixels=(unsigned char *) AcquireQuantumMemory(image->columns,packet_size*
sizeof(*pixels));
packet_size=(size_t) (image->colors > 256 ? 6UL : 3UL);
colormap=(unsigned char *) AcquireQuantumMemory(image->colors,packet_size*
sizeof(*colormap));
if ((pixels == (unsigned char *) NULL) ||
(colormap == (unsigned char *) NULL))
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
/*
Read image colormap.
*/
count=ReadBlob(image,packet_size*image->colors,colormap);
if (count != (ssize_t) (packet_size*image->colors))
ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
p=colormap;
if (image->depth <= 8)
for (i=0; i < (ssize_t) image->colors; i++)
{
image->colormap[i].red=ScaleCharToQuantum(*p++);
image->colormap[i].green=ScaleCharToQuantum(*p++);
image->colormap[i].blue=ScaleCharToQuantum(*p++);
}
else
for (i=0; i < (ssize_t) image->colors; i++)
{
quantum=(*p++ << 8);
quantum|=(*p++);
image->colormap[i].red=(Quantum) quantum;
quantum=(*p++ << 8);
quantum|=(*p++);
image->colormap[i].green=(Quantum) quantum;
quantum=(*p++ << 8);
quantum|=(*p++);
image->colormap[i].blue=(Quantum) quantum;
}
colormap=(unsigned char *) RelinquishMagickMemory(colormap);
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
Read image pixels.
*/
packet_size=(size_t) (depth/8);
for (y=0; y < (ssize_t) image->rows; y++)
{
p=pixels;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
count=ReadBlob(image,(size_t) packet_size*image->columns,pixels);
if (count != (ssize_t) (packet_size*image->columns))
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
index=ConstrainColormapIndex(image,*p);
p++;
if (image->colors > 256)
{
index=ConstrainColormapIndex(image,((size_t) index << 8)+(*p));
p++;
}
SetPixelIndex(indexes+x,index);
SetPixelRGBO(q,image->colormap+(ssize_t) index);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (y < (ssize_t) image->rows)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r M A P I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterMAPImage() adds attributes for the MAP image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterMAPImage method is:
%
% size_t RegisterMAPImage(void)
%
*/
ModuleExport size_t RegisterMAPImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("MAP");
entry->decoder=(DecodeImageHandler *) ReadMAPImage;
entry->encoder=(EncodeImageHandler *) WriteMAPImage;
entry->adjoin=MagickFalse;
entry->format_type=ExplicitFormatType;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->description=ConstantString("Colormap intensities and indices");
entry->module=ConstantString("MAP");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r M A P I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterMAPImage() removes format registrations made by the
% MAP module from the list of supported formats.
%
% The format of the UnregisterMAPImage method is:
%
% UnregisterMAPImage(void)
%
*/
ModuleExport void UnregisterMAPImage(void)
{
(void) UnregisterMagickInfo("MAP");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e M A P I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteMAPImage() writes an image to a file as red, green, and blue
% colormap bytes followed by the colormap indexes.
%
% The format of the WriteMAPImage method is:
%
% MagickBooleanType WriteMAPImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
%
*/
static MagickBooleanType WriteMAPImage(const ImageInfo *image_info,Image *image)
{
MagickBooleanType
status;
register const IndexPacket
*indexes;
register const PixelPacket
*p;
register ssize_t
i,
x;
register unsigned char
*q;
size_t
depth,
packet_size;
ssize_t
y;
unsigned char
*colormap,
*pixels;
/*
Open output image file.
*/
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);
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
/*
Allocate colormap.
*/
if (IsPaletteImage(image,&image->exception) == MagickFalse)
(void) SetImageType(image,PaletteType);
depth=GetImageQuantumDepth(image,MagickTrue);
packet_size=(size_t) (depth/8);
pixels=(unsigned char *) AcquireQuantumMemory(image->columns,packet_size*
sizeof(*pixels));
packet_size=(size_t) (image->colors > 256 ? 6UL : 3UL);
colormap=(unsigned char *) AcquireQuantumMemory(image->colors,packet_size*
sizeof(*colormap));
if ((pixels == (unsigned char *) NULL) ||
(colormap == (unsigned char *) NULL))
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
/*
Write colormap to file.
*/
q=colormap;
if (image->depth <= 8)
for (i=0; i < (ssize_t) image->colors; i++)
{
*q++=(unsigned char) image->colormap[i].red;
*q++=(unsigned char) image->colormap[i].green;
*q++=(unsigned char) image->colormap[i].blue;
}
else
for (i=0; i < (ssize_t) image->colors; i++)
{
*q++=(unsigned char) ((size_t) image->colormap[i].red >> 8);
*q++=(unsigned char) image->colormap[i].red;
*q++=(unsigned char) ((size_t) image->colormap[i].green >> 8);
*q++=(unsigned char) image->colormap[i].green;
*q++=(unsigned char) ((size_t) image->colormap[i].blue >> 8);
*q++=(unsigned char) image->colormap[i].blue;
}
(void) WriteBlob(image,packet_size*image->colors,colormap);
colormap=(unsigned char *) RelinquishMagickMemory(colormap);
/*
Write image pixels to file.
*/
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);
q=pixels;
for (x=0; x < (ssize_t) image->columns; x++)
{
if (image->colors > 256)
*q++=(unsigned char) ((size_t) GetPixelIndex(indexes+x) >> 8);
*q++=(unsigned char) GetPixelIndex(indexes+x);
}
(void) WriteBlob(image,(size_t) (q-pixels),pixels);
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
(void) CloseBlob(image);
return(status);
}

1306
ImageMagick/coders/mat.c Normal file

File diff suppressed because it is too large Load diff

218
ImageMagick/coders/matte.c Normal file
View file

@ -0,0 +1,218 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M M AAA TTTTT TTTTT EEEEE %
% MM MM A A T T E %
% M M M AAAAA T T EEE %
% M M A A T T E %
% M M A A T T EEEEE %
% %
% %
% Write Matte Channel To MIFF File. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/attribute.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteMATTEImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r M A T T E I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterMATTEImage() adds attributes for the MATTE image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterMATTEImage method is:
%
% size_t RegisterMATTEImage(void)
%
*/
ModuleExport size_t RegisterMATTEImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("MATTE");
entry->encoder=(EncodeImageHandler *) WriteMATTEImage;
entry->format_type=ExplicitFormatType;
entry->description=ConstantString("MATTE format");
entry->module=ConstantString("MATTE");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r M A T T E I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterMATTEImage() removes format registrations made by the
% MATTE module from the list of supported formats.
%
% The format of the UnregisterMATTEImage method is:
%
% UnregisterMATTEImage(void)
%
*/
ModuleExport void UnregisterMATTEImage(void)
{
(void) UnregisterMagickInfo("MATTE");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e M A T T E I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Function WriteMATTEImage() writes an image of matte bytes to a file. It
% consists of data from the matte component of the image [0..255].
%
% The format of the WriteMATTEImage method is:
%
% MagickBooleanType WriteMATTEImage(const ImageInfo *image_info,
% Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteMATTEImage(const ImageInfo *image_info,
Image *image)
{
ExceptionInfo
*exception;
Image
*matte_image;
MagickBooleanType
status;
register const PixelPacket
*p;
register ssize_t
x;
register PixelPacket
*q;
ssize_t
y;
if (image->matte == MagickFalse)
ThrowWriterException(CoderError,"ImageDoesNotHaveAAlphaChannel");
matte_image=CloneImage(image,image->columns,image->rows,MagickTrue,
&image->exception);
if (matte_image == (Image *) NULL)
return(MagickFalse);
(void) SetImageType(matte_image,TrueColorMatteType);
matte_image->matte=MagickFalse;
/*
Convert image to matte pixels.
*/
exception=(&image->exception);
for (y=0; y < (ssize_t) image->rows; y++)
{
p=GetVirtualPixels(image,0,y,image->columns,1,exception);
q=QueueAuthenticPixels(matte_image,0,y,matte_image->columns,1,exception);
if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelRed(q,GetPixelOpacity(p));
SetPixelGreen(q,GetPixelOpacity(p));
SetPixelBlue(q,GetPixelOpacity(p));
SetPixelOpacity(q,OpaqueOpacity);
p++;
q++;
}
if (SyncAuthenticPixels(matte_image,exception) == MagickFalse)
break;
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
(void) FormatLocaleString(matte_image->filename,MaxTextExtent,
"MIFF:%s",image->filename);
status=WriteImage(image_info,matte_image);
matte_image=DestroyImage(matte_image);
return(status);
}

2393
ImageMagick/coders/meta.c Normal file

File diff suppressed because it is too large Load diff

2656
ImageMagick/coders/miff.c Normal file

File diff suppressed because it is too large Load diff

358
ImageMagick/coders/mono.c Normal file
View file

@ -0,0 +1,358 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M M OOO N N OOO %
% MM MM O O NN N O O %
% M M M O O N N N O O %
% M M O O N NN O O %
% M M OOO N N OOO %
% %
% %
% Read/Write Raw Bi-Level Bitmap Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/attribute.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/color-private.h"
#include "magick/colormap.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteMONOImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d M O N O I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadMONOImage() reads an image of raw bites in LSB order 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 ReadMONOImage method is:
%
% Image *ReadMONOImage(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 *ReadMONOImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
Image
*image;
MagickBooleanType
status;
register IndexPacket
*indexes;
register PixelPacket
*q;
register ssize_t
x;
size_t
bit,
byte;
ssize_t
y;
/*
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);
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(OptionError,"MustSpecifyImageSize");
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
if (DiscardBlobBytes(image,image->offset) == MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
/*
Initialize image colormap.
*/
image->depth=1;
if (AcquireImageColormap(image,2) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
Convert bi-level image to pixel packets.
*/
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
bit=0;
byte=0;
for (x=0; x < (ssize_t) image->columns; x++)
{
if (bit == 0)
byte=(size_t) ReadBlobByte(image);
if (image_info->endian == LSBEndian)
SetPixelIndex(indexes+x,((byte & 0x01) != 0) ? 0x00 : 0x01);
else
SetPixelIndex(indexes+x,((byte & 0x01) != 0) ? 0x01 : 0x00);
bit++;
if (bit == 8)
bit=0;
byte>>=1;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
(void) SyncImage(image);
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r M O N O I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterMONOImage() adds attributes for the MONO image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterMONOImage method is:
%
% size_t RegisterMONOImage(void)
%
*/
ModuleExport size_t RegisterMONOImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("MONO");
entry->decoder=(DecodeImageHandler *) ReadMONOImage;
entry->encoder=(EncodeImageHandler *) WriteMONOImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->adjoin=MagickFalse;
entry->description=ConstantString("Raw bi-level bitmap");
entry->module=ConstantString("MONO");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r M O N O I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterMONOImage() removes format registrations made by the
% MONO module from the list of supported formats.
%
% The format of the UnregisterMONOImage method is:
%
% UnregisterMONOImage(void)
%
*/
ModuleExport void UnregisterMONOImage(void)
{
(void) UnregisterMagickInfo("MONO");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e M O N O I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteMONOImage() writes an image of raw bits in LSB order to a file.
%
% The format of the WriteMONOImage method is:
%
% MagickBooleanType WriteMONOImage(const ImageInfo *image_info,
% Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteMONOImage(const ImageInfo *image_info,
Image *image)
{
MagickBooleanType
status;
register const PixelPacket
*p;
register ssize_t
x;
size_t
bit,
byte;
ssize_t
y;
/*
Open output image file.
*/
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);
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
/*
Convert image to a bi-level image.
*/
(void) SetImageType(image,BilevelType);
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;
bit=0;
byte=0;
for (x=0; x < (ssize_t) image->columns; x++)
{
byte>>=1;
if (image->endian == LSBEndian)
{
if (GetPixelIntensity(image,p) < (QuantumRange/2.0))
byte|=0x80;
}
else
if (GetPixelIntensity(image,p) >= (QuantumRange/2.0))
byte|=0x80;
bit++;
if (bit == 8)
{
(void) WriteBlobByte(image,(unsigned char) byte);
bit=0;
byte=0;
}
p++;
}
if (bit != 0)
(void) WriteBlobByte(image,(unsigned char) (byte >> (8-bit)));
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
(void) CloseBlob(image);
return(MagickTrue);
}

1451
ImageMagick/coders/mpc.c Normal file

File diff suppressed because it is too large Load diff

625
ImageMagick/coders/mpeg.c Normal file
View file

@ -0,0 +1,625 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M M PPPP EEEEE GGGG %
% MM MM P P E G %
% M M M PPPP EEE G GG %
% M M P E G G %
% M M P EEEEE GGGG %
% %
% %
% Read/Write MPEG Image Format %
% %
% Software Design %
% John Cristy %
% July 1999 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/constitute.h"
#include "magick/delegate.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/geometry.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/layer.h"
#include "magick/list.h"
#include "magick/log.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/resource_.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/transform.h"
#include "magick/utility.h"
#include "magick/utility-private.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteMPEGImage(const ImageInfo *image_info,Image *image);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s A V I %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsAVI() returns MagickTrue if the image format type, identified by the
% magick string, is Audio/Video Interleaved file format.
%
% The format of the IsAVI method is:
%
% size_t IsAVI(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsAVI(const unsigned char *magick,const size_t length)
{
if (length < 4)
return(MagickFalse);
if (memcmp(magick,"RIFF",4) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s M P E G %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsMPEG() returns MagickTrue if the image format type, identified by the
% magick string, is MPEG.
%
% The format of the IsMPEG method is:
%
% MagickBooleanType IsMPEG(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsMPEG(const unsigned char *magick,const size_t length)
{
if (length < 4)
return(MagickFalse);
if (memcmp(magick,"\000\000\001\263",4) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d M P E G I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadMPEGImage() reads an binary file in the MPEG video stream 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 ReadMPEGImage method is:
%
% Image *ReadMPEGImage(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 *ReadMPEGImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
#define ReadMPEGIntermediateFormat "pam"
Image
*image,
*images;
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 MPEG to PAM with delegate.
*/
read_info=CloneImageInfo(image_info);
image=AcquireImage(image_info);
(void) InvokeDelegate(read_info,image,"mpeg:decode",(char *) NULL,exception);
image=DestroyImage(image);
(void) FormatLocaleString(read_info->filename,MaxTextExtent,"%s.%s",
read_info->unique,ReadMPEGIntermediateFormat);
images=ReadImage(read_info,exception);
(void) RelinquishUniqueFileResource(read_info->filename);
read_info=DestroyImageInfo(read_info);
return(images);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r M P E G I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterMPEGImage() adds attributes for the MPEG image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterMPEGImage method is:
%
% size_t RegisterMPEGImage(void)
%
*/
ModuleExport size_t RegisterMPEGImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("AVI");
entry->decoder=(DecodeImageHandler *) ReadMPEGImage;
entry->magick=(IsImageFormatHandler *) IsAVI;
entry->blob_support=MagickFalse;
entry->description=ConstantString("Microsoft Audio/Visual Interleaved");
entry->module=ConstantString("MPEG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("MOV");
entry->decoder=(DecodeImageHandler *) ReadMPEGImage;
entry->encoder=(EncodeImageHandler *) WriteMPEGImage;
entry->magick=(IsImageFormatHandler *) IsMPEG;
entry->blob_support=MagickFalse;
entry->description=ConstantString("MPEG Video Stream");
entry->module=ConstantString("MPEG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("MPEG");
entry->decoder=(DecodeImageHandler *) ReadMPEGImage;
entry->encoder=(EncodeImageHandler *) WriteMPEGImage;
entry->magick=(IsImageFormatHandler *) IsMPEG;
entry->blob_support=MagickFalse;
entry->description=ConstantString("MPEG Video Stream");
entry->module=ConstantString("MPEG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("MPG");
entry->decoder=(DecodeImageHandler *) ReadMPEGImage;
entry->encoder=(EncodeImageHandler *) WriteMPEGImage;
entry->magick=(IsImageFormatHandler *) IsMPEG;
entry->blob_support=MagickFalse;
entry->description=ConstantString("MPEG Video Stream");
entry->module=ConstantString("MPEG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("MP4");
entry->decoder=(DecodeImageHandler *) ReadMPEGImage;
entry->encoder=(EncodeImageHandler *) WriteMPEGImage;
entry->magick=(IsImageFormatHandler *) IsMPEG;
entry->blob_support=MagickFalse;
entry->description=ConstantString("MPEG-4 Video Stream");
entry->module=ConstantString("MPEG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("M2V");
entry->decoder=(DecodeImageHandler *) ReadMPEGImage;
entry->encoder=(EncodeImageHandler *) WriteMPEGImage;
entry->magick=(IsImageFormatHandler *) IsMPEG;
entry->blob_support=MagickFalse;
entry->description=ConstantString("MPEG Video Stream");
entry->module=ConstantString("MPEG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("M4V");
entry->decoder=(DecodeImageHandler *) ReadMPEGImage;
entry->encoder=(EncodeImageHandler *) WriteMPEGImage;
entry->magick=(IsImageFormatHandler *) IsMPEG;
entry->blob_support=MagickFalse;
entry->description=ConstantString("Raw MPEG-4 Video");
entry->module=ConstantString("MPEG");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("WMV");
entry->decoder=(DecodeImageHandler *) ReadMPEGImage;
entry->encoder=(EncodeImageHandler *) WriteMPEGImage;
entry->magick=(IsImageFormatHandler *) IsMPEG;
entry->blob_support=MagickFalse;
entry->description=ConstantString("Windows Media Video");
entry->module=ConstantString("MPEG");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r M P E G I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterMPEGImage() removes format registrations made by the
% BIM module from the list of supported formats.
%
% The format of the UnregisterBIMImage method is:
%
% UnregisterMPEGImage(void)
%
*/
ModuleExport void UnregisterMPEGImage(void)
{
(void) UnregisterMagickInfo("WMV");
(void) UnregisterMagickInfo("M4V");
(void) UnregisterMagickInfo("M2V");
(void) UnregisterMagickInfo("MP4");
(void) UnregisterMagickInfo("MPG");
(void) UnregisterMagickInfo("MPEG");
(void) UnregisterMagickInfo("MOV");
(void) UnregisterMagickInfo("AVI");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e M P E G I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteMPEGImage() writes an image to a file in MPEG video stream format.
% Lawrence Livermore National Laboratory (LLNL) contributed code to adjust
% the MPEG parameters to correspond to the compression quality setting.
%
% The format of the WriteMPEGImage method is:
%
% MagickBooleanType WriteMPEGImage(const ImageInfo *image_info,
% Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static inline double MagickMax(const double x,const double y)
{
if (x > y)
return(x);
return(y);
}
static inline double MagickMin(const double x,const double y)
{
if (x < y)
return(x);
return(y);
}
static MagickBooleanType CopyDelegateFile(const char *source,
const char *destination)
{
int
destination_file,
source_file;
MagickBooleanType
status;
register size_t
i;
size_t
length,
quantum;
ssize_t
count;
struct stat
attributes;
unsigned char
*buffer;
/*
Return if destination file already exists and is not empty.
*/
assert(source != (const char *) NULL);
assert(destination != (char *) NULL);
status=GetPathAttributes(destination,&attributes);
if ((status != MagickFalse) && (attributes.st_size != 0))
return(MagickTrue);
/*
Copy source file to destination.
*/
destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
if (destination_file == -1)
return(MagickFalse);
source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
if (source_file == -1)
{
(void) close(destination_file);
return(MagickFalse);
}
quantum=(size_t) MagickMaxBufferExtent;
if ((fstat(source_file,&attributes) == 0) && (attributes.st_size != 0))
quantum=(size_t) MagickMin((double) attributes.st_size,
MagickMaxBufferExtent);
buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer));
if (buffer == (unsigned char *) NULL)
{
(void) close(source_file);
(void) close(destination_file);
return(MagickFalse);
}
length=0;
for (i=0; ; i+=count)
{
count=(ssize_t) read(source_file,buffer,quantum);
if (count <= 0)
break;
length=(size_t) count;
count=(ssize_t) write(destination_file,buffer,length);
if ((size_t) count != length)
break;
}
(void) close(destination_file);
(void) close(source_file);
buffer=(unsigned char *) RelinquishMagickMemory(buffer);
return(i != 0 ? MagickTrue : MagickFalse);
}
static MagickBooleanType WriteMPEGImage(const ImageInfo *image_info,
Image *image)
{
#define WriteMPEGIntermediateFormat "jpg"
char
basename[MaxTextExtent],
filename[MaxTextExtent];
double
delay;
Image
*coalesce_image;
ImageInfo
*write_info;
int
file;
MagickBooleanType
status;
register Image
*p;
register ssize_t
i;
size_t
count,
length,
scene;
unsigned char
*blob;
/*
Open output image file.
*/
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) CloseBlob(image);
/*
Write intermediate files.
*/
coalesce_image=CoalesceImages(image,&image->exception);
if (coalesce_image == (Image *) NULL)
return(MagickFalse);
file=AcquireUniqueFileResource(basename);
if (file != -1)
file=close(file)-1;
(void) FormatLocaleString(coalesce_image->filename,MaxTextExtent,"%s",
basename);
count=0;
write_info=CloneImageInfo(image_info);
for (p=coalesce_image; p != (Image *) NULL; p=GetNextImageInList(p))
{
char
previous_image[MaxTextExtent];
blob=(unsigned char *) NULL;
length=0;
scene=p->scene;
delay=100.0*p->delay/MagickMax(1.0*p->ticks_per_second,1.0);
for (i=0; i < (ssize_t) MagickMax((1.0*delay+1.0)/3.0,1.0); i++)
{
p->scene=count;
count++;
status=MagickFalse;
switch (i)
{
case 0:
{
Image
*frame;
(void) FormatLocaleString(p->filename,MaxTextExtent,"%s%.20g.%s",
basename,(double) p->scene,WriteMPEGIntermediateFormat);
(void) FormatLocaleString(filename,MaxTextExtent,"%s%.20g.%s",
basename,(double) p->scene,WriteMPEGIntermediateFormat);
(void) FormatLocaleString(previous_image,MaxTextExtent,
"%s%.20g.%s",basename,(double) p->scene,
WriteMPEGIntermediateFormat);
frame=CloneImage(p,0,0,MagickTrue,&p->exception);
if (frame == (Image *) NULL)
break;
status=WriteImage(write_info,frame);
frame=DestroyImage(frame);
break;
}
case 1:
{
blob=(unsigned char *) FileToBlob(previous_image,~0UL,&length,
&image->exception);
}
default:
{
(void) FormatLocaleString(filename,MaxTextExtent,"%s%.20g.%s",
basename,(double) p->scene,WriteMPEGIntermediateFormat);
if (length > 0)
status=BlobToFile(filename,blob,length,&image->exception);
break;
}
}
if (image->debug != MagickFalse)
{
if (status != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
"%.20g. Wrote %s file for scene %.20g:",(double) i,
WriteMPEGIntermediateFormat,(double) p->scene);
else
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
"%.20g. Failed to write %s file for scene %.20g:",(double) i,
WriteMPEGIntermediateFormat,(double) p->scene);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"%s",filename);
}
}
p->scene=scene;
if (blob != (unsigned char *) NULL)
blob=(unsigned char *) RelinquishMagickMemory(blob);
if (status == MagickFalse)
break;
}
/*
Convert JPEG to MPEG.
*/
(void) CopyMagickString(coalesce_image->magick_filename,basename,
MaxTextExtent);
(void) CopyMagickString(coalesce_image->filename,basename,MaxTextExtent);
GetPathComponent(image_info->filename,ExtensionPath,coalesce_image->magick);
if (*coalesce_image->magick == '\0')
(void) CopyMagickString(coalesce_image->magick,image->magick,MaxTextExtent);
status=InvokeDelegate(write_info,coalesce_image,(char *) NULL,"mpeg:encode",
&image->exception);
(void) FormatLocaleString(write_info->filename,MaxTextExtent,"%s.%s",
write_info->unique,coalesce_image->magick);
status=CopyDelegateFile(write_info->filename,image->filename);
(void) RelinquishUniqueFileResource(write_info->filename);
write_info=DestroyImageInfo(write_info);
/*
Relinquish resources.
*/
count=0;
for (p=coalesce_image; p != (Image *) NULL; p=GetNextImageInList(p))
{
delay=100.0*p->delay/MagickMax(1.0*p->ticks_per_second,1.0);
for (i=0; i < (ssize_t) MagickMax((1.0*delay+1.0)/3.0,1.0); i++)
{
(void) FormatLocaleString(p->filename,MaxTextExtent,"%s%.20g.%s",
basename,(double) count++,WriteMPEGIntermediateFormat);
(void) RelinquishUniqueFileResource(p->filename);
}
(void) CopyMagickString(p->filename,image_info->filename,MaxTextExtent);
}
(void) RelinquishUniqueFileResource(basename);
coalesce_image=DestroyImageList(coalesce_image);
if (image->debug != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"exit");
return(status);
}

222
ImageMagick/coders/mpr.c Normal file
View file

@ -0,0 +1,222 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M M PPPP RRRR %
% MM MM P P R R %
% M M M PPPP RRRR %
% M M P R R %
% M M P R R %
% %
% %
% Read/Write the Magick Persistent Registry. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/registry.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteMPRImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d M P R I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadMPRImage() reads a Magick Persistent Registry image as a blob from
% memory. It allocates the memory necessary for the new Image structure and
% returns a pointer to the new image.
%
% The format of the ReadMPRImage method is:
%
% Image *ReadMPRImage(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 *ReadMPRImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
Image
*image;
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=(Image *) GetImageRegistry(ImageRegistryType,image_info->filename,
exception);
if (image != (Image *) NULL)
(void) SyncImageSettings(image_info,image);
return(image);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r M P R I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterMPRImage() adds attributes for the MPR image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterMPRImage method is:
%
% size_t RegisterMPRImage(void)
%
*/
ModuleExport size_t RegisterMPRImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("MPR");
entry->decoder=(DecodeImageHandler *) ReadMPRImage;
entry->encoder=(EncodeImageHandler *) WriteMPRImage;
entry->adjoin=MagickFalse;
entry->format_type=ImplicitFormatType;
entry->stealth=MagickTrue;
entry->description=ConstantString("Magick Persistent Registry");
entry->module=ConstantString("MPR");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("MPRI");
entry->decoder=(DecodeImageHandler *) ReadMPRImage;
entry->encoder=(EncodeImageHandler *) WriteMPRImage;
entry->adjoin=MagickFalse;
entry->format_type=ImplicitFormatType;
entry->stealth=MagickTrue;
entry->description=ConstantString("Magick Persistent Registry");
entry->module=ConstantString("MPRI");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r M P R I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterMPRImage() removes format registrations made by the
% MPR module from the list of supported formats.
%
% The format of the UnregisterMPRImage method is:
%
% UnregisterMPRImage(void)
%
*/
ModuleExport void UnregisterMPRImage(void)
{
(void) UnregisterMagickInfo("MPRI");
(void) UnregisterMagickInfo("MPR");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e M P R I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteMPRImage() writes an image into the Magick Persistent Registry
% image as a blob from memory. It allocates the memory necessary for the
% new Image structure and returns a pointer to the new image.
%
% The format of the WriteMPRImage method is:
%
% MagickBooleanType WriteMPRImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteMPRImage(const ImageInfo *image_info,Image *image)
{
MagickBooleanType
status;
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=SetImageRegistry(ImageRegistryType,image->filename,image,
&image->exception);
return(status);
}

8160
ImageMagick/coders/msl.c Normal file

File diff suppressed because it is too large Load diff

409
ImageMagick/coders/mtv.c Normal file
View file

@ -0,0 +1,409 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M M TTTTT V V %
% MM MM T V V %
% M M M T V V %
% M M T V V %
% M M T V %
% %
% %
% Read/Write MTV Raytracer Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteMTVImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d M T V I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadMTVImage() reads a MTV 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 ReadMTVImage method is:
%
% Image *ReadMTVImage(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 *ReadMTVImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
char
buffer[MaxTextExtent];
Image
*image;
MagickBooleanType
status;
register ssize_t
x;
register PixelPacket
*q;
register unsigned char
*p;
ssize_t
count,
y;
unsigned char
*pixels;
unsigned long
columns,
rows;
/*
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);
}
/*
Read MTV image.
*/
(void) ReadBlobString(image,buffer);
count=(ssize_t) sscanf(buffer,"%lu %lu\n",&columns,&rows);
if (count <= 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
do
{
/*
Initialize image structure.
*/
image->columns=columns;
image->rows=rows;
image->depth=8;
if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
/*
Convert MTV raster image to pixel packets.
*/
pixels=(unsigned char *) AcquireQuantumMemory((size_t) image->columns,
3UL*sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
for (y=0; y < (ssize_t) image->rows; y++)
{
count=(ssize_t) ReadBlob(image,(size_t) (3*image->columns),pixels);
if (count != (ssize_t) (3*image->columns))
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
p=pixels;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelRed(q,ScaleCharToQuantum(*p++));
SetPixelGreen(q,ScaleCharToQuantum(*p++));
SetPixelBlue(q,ScaleCharToQuantum(*p++));
SetPixelOpacity(q,OpaqueOpacity);
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (EOFBlob(image) != MagickFalse)
{
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
break;
}
/*
Proceed to next image.
*/
if (image_info->number_scenes != 0)
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
*buffer='\0';
(void) ReadBlobString(image,buffer);
count=(ssize_t) sscanf(buffer,"%lu %lu\n",&columns,&rows);
if (count > 0)
{
/*
Allocate next image structure.
*/
AcquireNextImage(image_info,image);
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
image=SyncNextImageInList(image);
status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
GetBlobSize(image));
if (status == MagickFalse)
break;
}
} while (count > 0);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r M T V I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterMTVImage() adds attributes for the MTV image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterMTVImage method is:
%
% size_t RegisterMTVImage(void)
%
*/
ModuleExport size_t RegisterMTVImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("MTV");
entry->decoder=(DecodeImageHandler *) ReadMTVImage;
entry->encoder=(EncodeImageHandler *) WriteMTVImage;
entry->description=ConstantString("MTV Raytracing image format");
entry->module=ConstantString("MTV");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r M T V I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterMTVImage() removes format registrations made by the
% MTV module from the list of supported formats.
%
% The format of the UnregisterMTVImage method is:
%
% UnregisterMTVImage(void)
%
*/
ModuleExport void UnregisterMTVImage(void)
{
(void) UnregisterMagickInfo("MTV");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e M T V I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteMTVImage() writes an image to a file in red, green, and blue MTV
% rasterfile format.
%
% The format of the WriteMTVImage method is:
%
% MagickBooleanType WriteMTVImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteMTVImage(const ImageInfo *image_info,Image *image)
{
char
buffer[MaxTextExtent];
MagickBooleanType
status;
MagickOffsetType
scene;
register const PixelPacket
*p;
register ssize_t
x;
register unsigned char
*q;
ssize_t
y;
unsigned char
*pixels;
/*
Open output image file.
*/
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);
scene=0;
do
{
/*
Allocate memory for pixels.
*/
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
pixels=(unsigned char *) AcquireQuantumMemory((size_t) image->columns,
3UL*sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
/*
Initialize raster file header.
*/
(void) FormatLocaleString(buffer,MaxTextExtent,"%.20g %.20g\n",(double)
image->columns,(double) image->rows);
(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;
q=pixels;
for (x=0; x < (ssize_t) image->columns; x++)
{
*q++=ScaleQuantumToChar(GetPixelRed(p));
*q++=ScaleQuantumToChar(GetPixelGreen(p));
*q++=ScaleQuantumToChar(GetPixelBlue(p));
p++;
}
(void) WriteBlob(image,(size_t) (q-pixels),pixels);
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (GetNextImageInList(image) == (Image *) NULL)
break;
image=SyncNextImageInList(image);
status=SetImageProgress(image,SaveImagesTag,scene,
GetImageListLength(image));
if (status == MagickFalse)
break;
scene++;
} while (image_info->adjoin != MagickFalse);
(void) CloseBlob(image);
return(MagickTrue);
}

334
ImageMagick/coders/mvg.c Normal file
View file

@ -0,0 +1,334 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% M M V V GGGG %
% MM MM V V G %
% M M M V V G GG %
% M M V V G G %
% M M V GGG %
% %
% %
% Read/Write Magick Vector Graphics Metafiles. %
% %
% Software Design %
% John Cristy %
% April 2000 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/artifact.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/draw.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/module.h"
#include "magick/pixel-accessor.h"
#include "magick/property.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteMVGImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s M V G %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsMVG() returns MagickTrue if the image format type, identified by the
% magick string, is MVG.
%
% The format of the IsMVG method is:
%
% MagickBooleanType IsMVG(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsMVG(const unsigned char *magick,const size_t length)
{
if (length < 20)
return(MagickFalse);
if (LocaleNCompare((const char *) magick,"push graphic-context",20) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d M V G I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadMVGImage creates a gradient image and initializes it to
% the X server color range as specified by the filename. It allocates the
% memory necessary for the new Image structure and returns a pointer to the
% new image.
%
% The format of the ReadMVGImage method is:
%
% Image *ReadMVGImage(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 *ReadMVGImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
#define BoundingBox "viewbox"
DrawInfo
*draw_info;
Image
*image;
MagickBooleanType
status;
/*
Open image.
*/
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);
}
if ((image->columns == 0) || (image->rows == 0))
{
char
primitive[MaxTextExtent];
register char
*p;
SegmentInfo
bounds;
/*
Determine size of image canvas.
*/
while (ReadBlobString(image,primitive) != (char *) NULL)
{
for (p=primitive; (*p == ' ') || (*p == '\t'); p++) ;
if (LocaleNCompare(BoundingBox,p,strlen(BoundingBox)) != 0)
continue;
(void) sscanf(p,"viewbox %lf %lf %lf %lf",&bounds.x1,&bounds.y1,
&bounds.x2,&bounds.y2);
image->columns=(size_t) floor((bounds.x2-bounds.x1)+0.5);
image->rows=(size_t) floor((bounds.y2-bounds.y1)+0.5);
break;
}
}
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(OptionError,"MustSpecifyImageSize");
draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
draw_info->affine.sx=image->x_resolution == 0.0 ? 1.0 : image->x_resolution/
DefaultResolution;
draw_info->affine.sy=image->y_resolution == 0.0 ? 1.0 : image->y_resolution/
DefaultResolution;
image->columns=(size_t) (draw_info->affine.sx*image->columns);
image->rows=(size_t) (draw_info->affine.sy*image->rows);
if (SetImageBackgroundColor(image) == MagickFalse)
{
InheritException(exception,&image->exception);
image=DestroyImageList(image);
return((Image *) NULL);
}
/*
Render drawing.
*/
if (GetBlobStreamData(image) == (unsigned char *) NULL)
draw_info->primitive=FileToString(image->filename,~0UL,exception);
else
{
draw_info->primitive=(char *) AcquireMagickMemory(GetBlobSize(image)+1);
if (draw_info->primitive != (char *) NULL)
{
CopyMagickMemory(draw_info->primitive,GetBlobStreamData(image),
GetBlobSize(image));
draw_info->primitive[GetBlobSize(image)]='\0';
}
}
(void) DrawImage(image,draw_info);
draw_info=DestroyDrawInfo(draw_info);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r M V G I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterMVGImage() adds properties for the MVG image format
% to the list of supported formats. The properties include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterMVGImage method is:
%
% size_t RegisterMVGImage(void)
%
*/
ModuleExport size_t RegisterMVGImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("MVG");
entry->decoder=(DecodeImageHandler *) ReadMVGImage;
entry->encoder=(EncodeImageHandler *) WriteMVGImage;
entry->magick=(IsImageFormatHandler *) IsMVG;
entry->adjoin=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->description=ConstantString("Magick Vector Graphics");
entry->module=ConstantString("MVG");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r M V G I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterMVGImage() removes format registrations made by the
% MVG module from the list of supported formats.
%
% The format of the UnregisterMVGImage method is:
%
% UnregisterMVGImage(void)
%
*/
ModuleExport void UnregisterMVGImage(void)
{
(void) UnregisterMagickInfo("MVG");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e M V G I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteMVGImage() writes an image to a file in MVG image format.
%
% The format of the WriteMVGImage method is:
%
% MagickBooleanType WriteMVGImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteMVGImage(const ImageInfo *image_info,Image *image)
{
const char
*value;
MagickBooleanType
status;
/*
Open output image file.
*/
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);
value=GetImageArtifact(image,"MVG");
if (value == (const char *) NULL)
ThrowWriterException(OptionError,"NoImageVectorGraphics");
status=OpenBlob(image_info,image,WriteBlobMode,&image->exception);
if (status == MagickFalse)
return(status);
(void) WriteBlob(image,strlen(value),(const unsigned char *) value);
(void) CloseBlob(image);
return(MagickTrue);
}

254
ImageMagick/coders/null.c Normal file
View file

@ -0,0 +1,254 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% N N U U L L %
% NN N U U L L %
% N N N U U L L %
% N NN U U L L %
% N N UUU LLLLL LLLLL %
% %
% %
% Read/Write Image Of Uniform Color. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.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-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/pixel-private.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteNULLImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d N U L L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadNULLImage creates a constant image and initializes it to the
% X server color as specified by the filename. It allocates the memory
% necessary for the new Image structure and returns a pointer to the new
% image.
%
% The format of the ReadNULLImage method is:
%
% Image *ReadNULLImage(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 *ReadNULLImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
Image
*image;
MagickPixelPacket
background;
register IndexPacket
*indexes;
register ssize_t
x;
register PixelPacket
*q;
ssize_t
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);
image=AcquireImage(image_info);
if (image->columns == 0)
image->columns=1;
if (image->rows == 0)
image->rows=1;
image->matte=MagickTrue;
GetMagickPixelPacket(image,&background);
background.opacity=(MagickRealType) TransparentOpacity;
if (image->colorspace == CMYKColorspace)
ConvertRGBToCMYK(&background);
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelPacket(image,&background,q,indexes);
q++;
indexes++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r N U L L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterNULLImage() adds attributes for the NULL image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterNULLImage method is:
%
% size_t RegisterNULLImage(void)
%
*/
ModuleExport size_t RegisterNULLImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("NULL");
entry->decoder=(DecodeImageHandler *) ReadNULLImage;
entry->encoder=(EncodeImageHandler *) WriteNULLImage;
entry->adjoin=MagickFalse;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Constant image of uniform color");
entry->module=ConstantString("NULL");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r N U L L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterNULLImage() removes format registrations made by the
% NULL module from the list of supported formats.
%
% The format of the UnregisterNULLImage method is:
%
% UnregisterNULLImage(void)
%
*/
ModuleExport void UnregisterNULLImage(void)
{
(void) UnregisterMagickInfo("NULL");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e N U L L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteNULLImage writes no output at all. It is useful when specified
% as an output format when profiling.
%
% The format of the WriteNULLImage method is:
%
% MagickBooleanType WriteNULLImage(const ImageInfo *image_info,
% Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteNULLImage(const ImageInfo *image_info,
Image *image)
{
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);
return(MagickTrue);
}

389
ImageMagick/coders/otb.c Normal file
View file

@ -0,0 +1,389 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% OOO TTTTT BBBB %
% O O T B B %
% O O T BBBB %
% O O T B B %
% OOO T BBBB %
% %
% %
% Read/Write On-The-Air Image Format %
% %
% Software Design %
% John Cristy %
% January 2000 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/attribute.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/color-private.h"
#include "magick/colormap.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteOTBImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d O T B I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadOTBImage() reads a on-the-air (level 0) bitmap 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 ReadOTBImage method is:
%
% Image *ReadOTBImage(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 *ReadOTBImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
#define GetBit(a,i) (((a) >> (i)) & 1L)
Image
*image;
int
byte;
MagickBooleanType
status;
register IndexPacket
*indexes;
register ssize_t
x;
register PixelPacket
*q;
ssize_t
y;
unsigned char
bit,
info,
depth;
/*
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);
}
/*
Initialize image structure.
*/
info=(unsigned char) ReadBlobByte(image);
if (GetBit(info,4) == 0)
{
image->columns=(size_t) ReadBlobByte(image);
image->rows=(size_t) ReadBlobByte(image);
}
else
{
image->columns=(size_t) ReadBlobMSBShort(image);
image->rows=(size_t) ReadBlobMSBShort(image);
}
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
depth=(unsigned char) ReadBlobByte(image);
if (depth != 1)
ThrowReaderException(CoderError,"OnlyLevelZerofilesSupported");
if (AcquireImageColormap(image,2) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
Convert bi-level image to pixel packets.
*/
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
bit=0;
byte=0;
for (x=0; x < (ssize_t) image->columns; x++)
{
if (bit == 0)
{
byte=ReadBlobByte(image);
if (byte == EOF)
ThrowReaderException(CorruptImageError,"CorruptImage");
}
SetPixelIndex(indexes+x,(byte & (0x01 << (7-bit))) ?
0x00 : 0x01);
bit++;
if (bit == 8)
bit=0;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
(void) SyncImage(image);
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r O T B I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterOTBImage() adds attributes for the OTB image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterOTBImage method is:
%
% size_t RegisterOTBImage(void)
%
*/
ModuleExport size_t RegisterOTBImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("OTB");
entry->decoder=(DecodeImageHandler *) ReadOTBImage;
entry->encoder=(EncodeImageHandler *) WriteOTBImage;
entry->adjoin=MagickFalse;
entry->description=ConstantString("On-the-air bitmap");
entry->module=ConstantString("OTB");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r O T B I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterOTBImage() removes format registrations made by the
% OTB module from the list of supported formats.
%
% The format of the UnregisterOTBImage method is:
%
% UnregisterOTBImage(void)
%
*/
ModuleExport void UnregisterOTBImage(void)
{
(void) UnregisterMagickInfo("OTB");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e O T B I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteOTBImage() writes an image to a file in the On-the-air Bitmap
% (level 0) image format.
%
% The format of the WriteOTBImage method is:
%
% MagickBooleanType WriteOTBImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
%
*/
static MagickBooleanType WriteOTBImage(const ImageInfo *image_info,Image *image)
{
#define SetBit(a,i,set) \
a=(unsigned char) ((set) ? (a) | (1L << (i)) : (a) & ~(1L << (i)))
MagickBooleanType
status;
register const PixelPacket
*p;
register ssize_t
x;
ssize_t
y;
unsigned char
bit,
byte,
info;
/*
Open output image file.
*/
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);
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
/*
Convert image to a bi-level image.
*/
(void) SetImageType(image,BilevelType);
info=0;
if ((image->columns >= 256) || (image->rows >= 256))
SetBit(info,4,1);
(void) WriteBlobByte(image,info);
if ((image->columns >= 256) || (image->rows >= 256))
{
(void) WriteBlobMSBShort(image,(unsigned short) image->columns);
(void) WriteBlobMSBShort(image,(unsigned short) image->rows);
}
else
{
(void) WriteBlobByte(image,(unsigned char) image->columns);
(void) WriteBlobByte(image,(unsigned char) image->rows);
}
(void) WriteBlobByte(image,1); /* depth */
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;
bit=0;
byte=0;
for (x=0; x < (ssize_t) image->columns; x++)
{
if (GetPixelIntensity(image,p) < (QuantumRange/2.0))
byte|=0x1 << (7-bit);
bit++;
if (bit == 8)
{
(void) WriteBlobByte(image,byte);
bit=0;
byte=0;
}
p++;
}
if (bit != 0)
(void) WriteBlobByte(image,byte);
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
(void) CloseBlob(image);
return(MagickTrue);
}

993
ImageMagick/coders/palm.c Normal file
View file

@ -0,0 +1,993 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% PPPP AAA L M M %
% P P A A L MM MM %
% PPPP AAAAA L M M M %
% P A A L M M %
% P A A LLLLL M M %
% %
% %
% Read/Write Palm Pixmap. %
% %
% %
% Software Design %
% Christopher R. Hawks %
% December 2001 %
% %
% Copyright 1999-2004 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Based on pnmtopalm by Bill Janssen and ppmtobmp by Ian Goldberg.
%
*/
/*
Include declarations.
*/
#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/colormap.h"
#include "magick/colormap-private.h"
#include "magick/color-private.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/histogram.h"
#include "magick/image.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/paint.h"
#include "magick/pixel-accessor.h"
#include "magick/pixel-private.h"
#include "magick/property.h"
#include "magick/quantize.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/utility.h"
/*
Define declarations.
*/
#define PALM_IS_COMPRESSED_FLAG 0x8000
#define PALM_HAS_COLORMAP_FLAG 0x4000
#define PALM_HAS_FOUR_BYTE_FIELD 0x0200
#define PALM_HAS_TRANSPARENCY_FLAG 0x2000
#define PALM_IS_INDIRECT 0x1000
#define PALM_IS_FOR_SCREEN 0x0800
#define PALM_IS_DIRECT_COLOR 0x0400
#define PALM_COMPRESSION_SCANLINE 0x00
#define PALM_COMPRESSION_RLE 0x01
#define PALM_COMPRESSION_NONE 0xFF
/*
The 256 color system palette for Palm Computing Devices.
*/
static unsigned char
PalmPalette[256][3] =
{
{255, 255,255}, {255, 204,255}, {255, 153,255}, {255, 102,255},
{255, 51,255}, {255, 0,255}, {255, 255,204}, {255, 204,204},
{255, 153,204}, {255, 102,204}, {255, 51,204}, {255, 0,204},
{255, 255,153}, {255, 204,153}, {255, 153,153}, {255, 102,153},
{255, 51,153}, {255, 0,153}, {204, 255,255}, {204, 204,255},
{204, 153,255}, {204, 102,255}, {204, 51,255}, {204, 0,255},
{204, 255,204}, {204, 204,204}, {204, 153,204}, {204, 102,204},
{204, 51,204}, {204, 0,204}, {204, 255,153}, {204, 204,153},
{204, 153,153}, {204, 102,153}, {204, 51,153}, {204, 0,153},
{153, 255,255}, {153, 204,255}, {153, 153,255}, {153, 102,255},
{153, 51,255}, {153, 0,255}, {153, 255,204}, {153, 204,204},
{153, 153,204}, {153, 102,204}, {153, 51,204}, {153, 0,204},
{153, 255,153}, {153, 204,153}, {153, 153,153}, {153, 102,153},
{153, 51,153}, {153, 0,153}, {102, 255,255}, {102, 204,255},
{102, 153,255}, {102, 102,255}, {102, 51,255}, {102, 0,255},
{102, 255,204}, {102, 204,204}, {102, 153,204}, {102, 102,204},
{102, 51,204}, {102, 0,204}, {102, 255,153}, {102, 204,153},
{102, 153,153}, {102, 102,153}, {102, 51,153}, {102, 0,153},
{ 51, 255,255}, { 51, 204,255}, { 51, 153,255}, { 51, 102,255},
{ 51, 51,255}, { 51, 0,255}, { 51, 255,204}, { 51, 204,204},
{ 51, 153,204}, { 51, 102,204}, { 51, 51,204}, { 51, 0,204},
{ 51, 255,153}, { 51, 204,153}, { 51, 153,153}, { 51, 102,153},
{ 51, 51,153}, { 51, 0,153}, { 0, 255,255}, { 0, 204,255},
{ 0, 153,255}, { 0, 102,255}, { 0, 51,255}, { 0, 0,255},
{ 0, 255,204}, { 0, 204,204}, { 0, 153,204}, { 0, 102,204},
{ 0, 51,204}, { 0, 0,204}, { 0, 255,153}, { 0, 204,153},
{ 0, 153,153}, { 0, 102,153}, { 0, 51,153}, { 0, 0,153},
{255, 255,102}, {255, 204,102}, {255, 153,102}, {255, 102,102},
{255, 51,102}, {255, 0,102}, {255, 255, 51}, {255, 204, 51},
{255, 153, 51}, {255, 102, 51}, {255, 51, 51}, {255, 0, 51},
{255, 255, 0}, {255, 204, 0}, {255, 153, 0}, {255, 102, 0},
{255, 51, 0}, {255, 0, 0}, {204, 255,102}, {204, 204,102},
{204, 153,102}, {204, 102,102}, {204, 51,102}, {204, 0,102},
{204, 255, 51}, {204, 204, 51}, {204, 153, 51}, {204, 102, 51},
{204, 51, 51}, {204, 0, 51}, {204, 255, 0}, {204, 204, 0},
{204, 153, 0}, {204, 102, 0}, {204, 51, 0}, {204, 0, 0},
{153, 255,102}, {153, 204,102}, {153, 153,102}, {153, 102,102},
{153, 51,102}, {153, 0,102}, {153, 255, 51}, {153, 204, 51},
{153, 153, 51}, {153, 102, 51}, {153, 51, 51}, {153, 0, 51},
{153, 255, 0}, {153, 204, 0}, {153, 153, 0}, {153, 102, 0},
{153, 51, 0}, {153, 0, 0}, {102, 255,102}, {102, 204,102},
{102, 153,102}, {102, 102,102}, {102, 51,102}, {102, 0,102},
{102, 255, 51}, {102, 204, 51}, {102, 153, 51}, {102, 102, 51},
{102, 51, 51}, {102, 0, 51}, {102, 255, 0}, {102, 204, 0},
{102, 153, 0}, {102, 102, 0}, {102, 51, 0}, {102, 0, 0},
{ 51, 255,102}, { 51, 204,102}, { 51, 153,102}, { 51, 102,102},
{ 51, 51,102}, { 51, 0,102}, { 51, 255, 51}, { 51, 204, 51},
{ 51, 153, 51}, { 51, 102, 51}, { 51, 51, 51}, { 51, 0, 51},
{ 51, 255, 0}, { 51, 204, 0}, { 51, 153, 0}, { 51, 102, 0},
{ 51, 51, 0}, { 51, 0, 0}, { 0, 255,102}, { 0, 204,102},
{ 0, 153,102}, { 0, 102,102}, { 0, 51,102}, { 0, 0,102},
{ 0, 255, 51}, { 0, 204, 51}, { 0, 153, 51}, { 0, 102, 51},
{ 0, 51, 51}, { 0, 0, 51}, { 0, 255, 0}, { 0, 204, 0},
{ 0, 153, 0}, { 0, 102, 0}, { 0, 51, 0}, { 17, 17, 17},
{ 34, 34, 34}, { 68, 68, 68}, { 85, 85, 85}, {119, 119,119},
{136, 136,136}, {170, 170,170}, {187, 187,187}, {221, 221,221},
{238, 238,238}, {192, 192,192}, {128, 0, 0}, {128, 0,128},
{ 0, 128, 0}, { 0, 128,128}, { 0, 0, 0}, { 0, 0, 0},
{ 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
{ 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
{ 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
{ 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
{ 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0},
{ 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}
};
/*
Forward declarations.
*/
static MagickBooleanType
WritePALMImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% F i n d C o l o r %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% FindColor() returns the index of the matching entry from PalmPalette for a
% given PixelPacket.
%
% The format of the FindColor method is:
%
% int FindColor(PixelPacket *pixel)
%
% A description of each parameter follows:
%
% o int: the index of the matching color or -1 if not found/
%
% o pixel: a pointer to the PixelPacket to be matched.
%
*/
static int FindColor(PixelPacket *pixel)
{
register ssize_t
i;
for (i=0; i < 256; i++)
if (ScaleQuantumToChar(GetPixelRed(pixel)) == PalmPalette[i][0] &&
ScaleQuantumToChar(GetPixelGreen(pixel)) == PalmPalette[i][1] &&
ScaleQuantumToChar(GetPixelBlue(pixel)) == PalmPalette[i][2])
return(i);
return(-1);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d P A L M I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadPALMImage() reads an image of raw bites in LSB order 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 ReadPALMImage method is:
%
% Image *ReadPALMImage(const ImageInfo *image_info,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o image_info: Specifies a pointer to an ImageInfo structure.
%
% o exception: return any errors or warnings in this structure.
%
*/
static inline size_t MagickMax(const size_t x,const size_t y)
{
if (x > y)
return(x);
return(y);
}
static inline ssize_t MagickMin(const ssize_t x,const ssize_t y)
{
if (x < y)
return(x);
return(y);
}
static Image *ReadPALMImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
Image
*image;
IndexPacket
index;
MagickBooleanType
status;
MagickOffsetType
totalOffset,
seekNextDepth;
MagickPixelPacket
transpix;
register IndexPacket
*indexes;
register ssize_t
i,
x;
register PixelPacket
*q;
ssize_t
count,
y;
size_t
bytes_per_row,
flags,
bits_per_pixel,
version,
nextDepthOffset,
transparentIndex,
compressionType,
byte,
mask,
redbits,
greenbits,
bluebits,
one,
pad,
size,
bit;
unsigned char
*lastrow,
*one_row,
*ptr;
unsigned short
color16;
/*
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)
{
(void) DestroyImageList(image);
return((Image *) NULL);
}
totalOffset=0;
do
{
image->columns=ReadBlobMSBShort(image);
image->rows=ReadBlobMSBShort(image);
if (EOFBlob(image) != MagickFalse)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(CorruptImageError,"NegativeOrZeroImageSize");
bytes_per_row=ReadBlobMSBShort(image);
flags=ReadBlobMSBShort(image);
bits_per_pixel=(size_t) ReadBlobByte(image);
if (bits_per_pixel > 16)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
version=(size_t) ReadBlobByte(image);
(void) version;
nextDepthOffset=(size_t) ReadBlobMSBShort(image);
transparentIndex=(size_t) ReadBlobByte(image);
compressionType=(size_t) ReadBlobByte(image);
pad=ReadBlobMSBShort(image);
(void) pad;
/*
Initialize image colormap.
*/
one=1;
if ((bits_per_pixel < 16) &&
(AcquireImageColormap(image,one << bits_per_pixel) == MagickFalse))
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
GetMagickPixelPacket(image,&transpix);
if (bits_per_pixel == 16) /* Direct Color */
{
redbits=(size_t) ReadBlobByte(image); /* # of bits of red */
(void) redbits;
greenbits=(size_t) ReadBlobByte(image); /* # of bits of green */
(void) greenbits;
bluebits=(size_t) ReadBlobByte(image); /* # of bits of blue */
(void) bluebits;
ReadBlobByte(image); /* reserved by Palm */
ReadBlobByte(image); /* reserved by Palm */
transpix.red=(MagickRealType) (QuantumRange*ReadBlobByte(image)/31);
transpix.green=(MagickRealType) (QuantumRange*ReadBlobByte(image)/63);
transpix.blue=(MagickRealType) (QuantumRange*ReadBlobByte(image)/31);
}
if (bits_per_pixel == 8)
{
IndexPacket
index;
if (flags & PALM_HAS_COLORMAP_FLAG)
{
count=(ssize_t) ReadBlobMSBShort(image);
for (i=0; i < (ssize_t) count; i++)
{
ReadBlobByte(image);
index=ConstrainColormapIndex(image,255-i);
image->colormap[(int) index].red=
ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
image->colormap[(int) index].green=
ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
image->colormap[(int) index].blue=
ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
}
}
else
{
for (i=0; i < (ssize_t) (1L << bits_per_pixel); i++)
{
index=ConstrainColormapIndex(image,255-i);
image->colormap[(int) index].red=
ScaleCharToQuantum(PalmPalette[i][0]);
image->colormap[(int) index].green=
ScaleCharToQuantum(PalmPalette[i][1]);
image->colormap[(int) index].blue=
ScaleCharToQuantum(PalmPalette[i][2]);
}
}
}
if (flags & PALM_IS_COMPRESSED_FLAG)
size=ReadBlobMSBShort(image);
(void) size;
image->storage_class=DirectClass;
if (bits_per_pixel < 16)
{
image->storage_class=PseudoClass;
image->depth=8;
}
one_row=(unsigned char *) AcquireQuantumMemory(bytes_per_row,
sizeof(*one_row));
if (one_row == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
lastrow=(unsigned char *) NULL;
if (compressionType == PALM_COMPRESSION_SCANLINE) {
lastrow=(unsigned char *) AcquireQuantumMemory(bytes_per_row,
sizeof(*lastrow));
if (lastrow == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
mask=(1l << bits_per_pixel)-1;
for (y = 0; y < (ssize_t) image->rows; y++)
{
if ((flags & PALM_IS_COMPRESSED_FLAG) == 0)
{
/* TODO move out of loop! */
image->compression=NoCompression;
count=ReadBlob(image,bytes_per_row,one_row);
}
else
{
if (compressionType == PALM_COMPRESSION_RLE)
{
/* TODO move out of loop! */
image->compression=RLECompression;
for (i=0; i < (ssize_t) bytes_per_row; )
{
count=(ssize_t) ReadBlobByte(image);
count=MagickMin(count,(ssize_t) bytes_per_row-i);
byte=(size_t) ReadBlobByte(image);
(void) ResetMagickMemory(one_row+i,(int) byte,(size_t) count);
i+=count;
}
}
else
if (compressionType == PALM_COMPRESSION_SCANLINE)
{
size_t
one;
/* TODO move out of loop! */
one=1;
image->compression=FaxCompression;
for (i=0; i < (ssize_t) bytes_per_row; i+=8)
{
count=(ssize_t) ReadBlobByte(image);
byte=1UL*MagickMin((ssize_t) bytes_per_row-i,8);
for (bit=0; bit < byte; bit++)
{
if ((y == 0) || (count & (one << (7 - bit))))
one_row[i+bit]=(unsigned char) ReadBlobByte(image);
else
one_row[i+bit]=lastrow[i+bit];
}
}
(void) CopyMagickMemory(lastrow, one_row, bytes_per_row);
}
}
ptr=one_row;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
if (bits_per_pixel == 16)
{
if (image->columns > (2*bytes_per_row))
ThrowReaderException(CorruptImageError,"CorruptImage");
for (x=0; x < (ssize_t) image->columns; x++)
{
color16=(*ptr++ << 8);
color16|=(*ptr++);
SetPixelRed(q,(QuantumRange*((color16 >> 11) & 0x1f))/
0x1f);
SetPixelGreen(q,(QuantumRange*((color16 >> 5) & 0x3f))/
0x3f);
SetPixelBlue(q,(QuantumRange*((color16 >> 0) & 0x1f))/
0x1f);
SetPixelOpacity(q,OpaqueOpacity);
q++;
}
}
else
{
bit=8-bits_per_pixel;
for (x=0; x < (ssize_t) image->columns; x++)
{
if ((size_t) (ptr-one_row) >= bytes_per_row)
ThrowReaderException(CorruptImageError,"CorruptImage");
index=(IndexPacket) (mask-(((*ptr) & (mask << bit)) >> bit));
SetPixelIndex(indexes+x,index);
SetPixelRGBO(q,image->colormap+(ssize_t) index);
if (bit)
bit-=bits_per_pixel;
else
{
ptr++;
bit=8-bits_per_pixel;
}
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
if (flags & PALM_HAS_TRANSPARENCY_FLAG)
{
if (bits_per_pixel != 16)
SetMagickPixelPacket(image,image->colormap+(mask-transparentIndex),
(const IndexPacket *) NULL,&transpix);
(void) TransparentPaintImage(image,&transpix,(Quantum)
TransparentOpacity,MagickFalse);
}
one_row=(unsigned char *) RelinquishMagickMemory(one_row);
if (compressionType == PALM_COMPRESSION_SCANLINE)
lastrow=(unsigned char *) RelinquishMagickMemory(lastrow);
/*
Proceed to next image. Copied from coders/pnm.c
*/
if (image_info->number_scenes != 0)
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
if (nextDepthOffset != 0)
{
/*
Skip to next image.
*/
totalOffset+=(MagickOffsetType) (nextDepthOffset*4);
if (totalOffset >= (MagickOffsetType) GetBlobSize(image))
{
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
}
else
{
seekNextDepth=SeekBlob(image,totalOffset,SEEK_SET);
}
if (seekNextDepth != totalOffset)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
/*
Allocate next image structure. Copied from coders/pnm.c
*/
AcquireNextImage(image_info,image);
if (GetNextImageInList(image) == (Image *) NULL)
{
(void) DestroyImageList(image);
return((Image *) NULL);
}
image=SyncNextImageInList(image);
status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
GetBlobSize(image));
if (status == MagickFalse)
break;
}
} while (nextDepthOffset != 0);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r P A L M I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterPALMImage() adds properties for the PALM image format to the list of
% supported formats. The properties include the image format tag, a method to
% read and/or write the format, whether the format supports the saving of more
% than one frame to the same file or blob, whether the format supports native
% in-memory I/O, and a brief description of the format.
%
% The format of the RegisterPALMImage method is:
%
% size_t RegisterPALMImage(void)
%
*/
ModuleExport size_t RegisterPALMImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("PALM");
entry->decoder=(DecodeImageHandler *) ReadPALMImage;
entry->encoder=(EncodeImageHandler *) WritePALMImage;
entry->seekable_stream=MagickTrue;
entry->description=ConstantString("Palm pixmap");
entry->module=ConstantString("PALM");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r P A L M I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterPALMImage() removes format registrations made by the PALM
% module from the list of supported formats.
%
% The format of the UnregisterPALMImage method is:
%
% UnregisterPALMImage(void)
%
*/
ModuleExport void UnregisterPALMImage(void)
{
(void) UnregisterMagickInfo("PALM");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e P A L M I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WritePALMImage() writes an image of raw bits in LSB order to a file.
%
% The format of the WritePALMImage method is:
%
% MagickBooleanType WritePALMImage(const ImageInfo *image_info,
% Image *image)
%
% A description of each parameter follows.
%
% o image_info: Specifies a pointer to an ImageInfo structure.
%
% o image: A pointer to a Image structure.
%
*/
static MagickBooleanType WritePALMImage(const ImageInfo *image_info,
Image *image)
{
int
y;
ExceptionInfo
exception;
MagickBooleanType
status;
MagickOffsetType
currentOffset,
offset,
scene;
MagickSizeType
cc;
PixelPacket
transpix;
QuantizeInfo
*quantize_info;
register IndexPacket
*indexes;
register ssize_t
x;
register PixelPacket
*p;
size_t
count,
bits_per_pixel,
bytes_per_row,
nextDepthOffset,
one;
unsigned char
bit,
byte,
color,
*lastrow,
*one_row,
*ptr,
version;
unsigned int
transparentIndex;
unsigned short
color16,
flags;
/*
Open output image file.
*/
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,&exception);
if (status == MagickFalse)
return(status);
GetExceptionInfo(&exception);
quantize_info=AcquireQuantizeInfo(image_info);
flags=0;
currentOffset=0;
transparentIndex=0;
transpix.red=0;
transpix.green=0;
transpix.blue=0;
transpix.opacity=0;
one=1;
version=0;
scene=0;
do
{
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
count=GetNumberColors(image,NULL,&exception);
for (bits_per_pixel=1; (one << bits_per_pixel) < count; bits_per_pixel*=2) ;
if (image_info->depth > 100)
bits_per_pixel=image_info->depth-100;
if (bits_per_pixel < 16)
(void) TransformImageColorspace(image,image->colorspace);
if (bits_per_pixel < 8)
{
(void) TransformImageColorspace(image,GRAYColorspace);
(void) SetImageType(image,PaletteType);
(void) SortColormapByIntensity(image);
}
if ((image->storage_class == PseudoClass) && (image->colors > 256))
(void) SetImageStorageClass(image,DirectClass);
if (image->storage_class == PseudoClass)
flags|=PALM_HAS_COLORMAP_FLAG;
else
flags|=PALM_IS_DIRECT_COLOR;
(void) WriteBlobMSBShort(image,(unsigned short) image->columns); /* width */
(void) WriteBlobMSBShort(image,(unsigned short) image->rows); /* height */
bytes_per_row=((image->columns+(16/bits_per_pixel-1))/(16/
bits_per_pixel))*2;
(void) WriteBlobMSBShort(image,(unsigned short) bytes_per_row);
if ((image_info->compression == RLECompression) ||
(image_info->compression == FaxCompression))
flags|=PALM_IS_COMPRESSED_FLAG;
(void) WriteBlobMSBShort(image, flags);
(void) WriteBlobByte(image,(unsigned char) bits_per_pixel);
if (bits_per_pixel > 1)
version=1;
if ((image_info->compression == RLECompression) ||
(image_info->compression == FaxCompression))
version=2;
(void) WriteBlobByte(image,version);
(void) WriteBlobMSBShort(image,0); /* nextDepthOffset */
(void) WriteBlobByte(image,(unsigned char) transparentIndex);
if (image_info->compression == RLECompression)
(void) WriteBlobByte(image,PALM_COMPRESSION_RLE);
else
if (image_info->compression == FaxCompression)
(void) WriteBlobByte(image,PALM_COMPRESSION_SCANLINE);
else
(void) WriteBlobByte(image,PALM_COMPRESSION_NONE);
(void) WriteBlobMSBShort(image,0); /* reserved */
offset=16;
if (bits_per_pixel == 16)
{
(void) WriteBlobByte(image,5); /* # of bits of red */
(void) WriteBlobByte(image,6); /* # of bits of green */
(void) WriteBlobByte(image,5); /* # of bits of blue */
(void) WriteBlobByte(image,0); /* reserved by Palm */
(void) WriteBlobMSBLong(image,0); /* no transparent color, YET */
offset+=8;
}
if (bits_per_pixel == 8)
{
if (flags & PALM_HAS_COLORMAP_FLAG) /* Write out colormap */
{
quantize_info->dither=IsPaletteImage(image,&image->exception);
quantize_info->number_colors=image->colors;
(void) QuantizeImage(quantize_info,image);
(void) WriteBlobMSBShort(image,(unsigned short) image->colors);
for (count = 0; count < image->colors; count++)
{
(void) WriteBlobByte(image,(unsigned char) count);
(void) WriteBlobByte(image,ScaleQuantumToChar(
image->colormap[count].red));
(void) WriteBlobByte(image,
ScaleQuantumToChar(image->colormap[count].green));
(void) WriteBlobByte(image,
ScaleQuantumToChar(image->colormap[count].blue));
}
offset+=2+count*4;
}
else /* Map colors to Palm standard colormap */
{
Image
*affinity_image;
affinity_image=ConstituteImage(256,1,"RGB",CharPixel,&PalmPalette,
&exception);
(void) TransformImageColorspace(affinity_image,
affinity_image->colorspace);
(void) RemapImage(quantize_info,image,affinity_image);
for (y=0; y < (ssize_t) image->rows; y++)
{
p=GetAuthenticPixels(image,0,y,image->columns,1,&exception);
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < (ssize_t) image->columns; x++)
SetPixelIndex(indexes+x,FindColor(&image->colormap[
(ssize_t) GetPixelIndex(indexes+x)]));
}
affinity_image=DestroyImage(affinity_image);
}
}
if (flags & PALM_IS_COMPRESSED_FLAG)
(void) WriteBlobMSBShort(image,0); /* fill in size later */
lastrow=(unsigned char *) NULL;
if (image_info->compression == FaxCompression)
lastrow=(unsigned char *) AcquireQuantumMemory(bytes_per_row,
sizeof(*lastrow));
/* TODO check whether memory really was acquired? */
one_row=(unsigned char *) AcquireQuantumMemory(bytes_per_row,
sizeof(*one_row));
if (one_row == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
for (y=0; y < (int) image->rows; y++)
{
ptr=one_row;
(void) ResetMagickMemory(ptr,0,bytes_per_row);
p=GetAuthenticPixels(image,0,y,image->columns,1,&exception);
if (p == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
if (bits_per_pixel == 16)
{
for (x=0; x < (int) image->columns; x++)
{
color16=(unsigned short) ((((31*(size_t) GetPixelRed(p))/
(size_t) QuantumRange) << 11) |
(((63*(size_t) GetPixelGreen(p))/(size_t) QuantumRange) << 5) |
((31*(size_t) GetPixelBlue(p))/(size_t) QuantumRange));
if (GetPixelOpacity(p) == (Quantum) TransparentOpacity)
{
transpix.red=GetPixelRed(p);
transpix.green=GetPixelGreen(p);
transpix.blue=GetPixelBlue(p);
transpix.opacity=GetPixelOpacity(p);
flags|=PALM_HAS_TRANSPARENCY_FLAG;
}
*ptr++=(unsigned char) ((color16 >> 8) & 0xff);
*ptr++=(unsigned char) (color16 & 0xff);
p++;
}
}
else
{
byte=0x00;
bit=(unsigned char) (8-bits_per_pixel);
for (x=0; x < (int) image->columns; x++)
{
if (bits_per_pixel >= 8)
color=(unsigned char) GetPixelIndex(indexes+x);
else
color=(unsigned char) (GetPixelIndex(indexes+x)*
((one << bits_per_pixel)-1)/MagickMax(1*image->colors-1,1));
byte|=color << bit;
if (bit != 0)
bit-=(unsigned char) bits_per_pixel;
else
{
*ptr++=byte;
byte=0x00;
bit=(unsigned char) (8-bits_per_pixel);
}
}
if ((image->columns % (8/bits_per_pixel)) != 0)
*ptr++=byte;
}
if (image_info->compression == RLECompression)
{
x=0;
while (x < (ssize_t) bytes_per_row)
{
byte=one_row[x];
count=1;
while ((one_row[++x] == byte) && (count < 255) &&
(x < (ssize_t) bytes_per_row))
count++;
(void) WriteBlobByte(image,(unsigned char) count);
(void) WriteBlobByte(image,(unsigned char) byte);
}
}
else
if (image_info->compression == FaxCompression)
{
char
tmpbuf[8],
*tptr;
for (x = 0; x < (ssize_t) bytes_per_row; x += 8)
{
tptr = tmpbuf;
for (bit=0, byte=0; bit < (unsigned char) MagickMin(8,(ssize_t) bytes_per_row-x); bit++)
{
if ((y == 0) || (lastrow[x + bit] != one_row[x + bit]))
{
byte |= (1 << (7 - bit));
*tptr++ = (char) one_row[x + bit];
}
}
(void) WriteBlobByte(image, byte);
(void) WriteBlob(image,tptr-tmpbuf,(unsigned char *) tmpbuf);
}
(void) CopyMagickMemory(lastrow,one_row,bytes_per_row);
}
else
(void) WriteBlob(image,bytes_per_row,one_row);
}
if (flags & PALM_HAS_TRANSPARENCY_FLAG)
{
offset=SeekBlob(image,currentOffset+6,SEEK_SET);
(void) WriteBlobMSBShort(image,flags);
offset=SeekBlob(image,currentOffset+12,SEEK_SET);
(void) WriteBlobByte(image,(unsigned char) transparentIndex); /* trans index */
}
if (bits_per_pixel == 16)
{
offset=SeekBlob(image,currentOffset+20,SEEK_SET);
(void) WriteBlobByte(image,0); /* reserved by Palm */
(void) WriteBlobByte(image,(unsigned char) ((31*transpix.red)/QuantumRange));
(void) WriteBlobByte(image,(unsigned char) ((63*transpix.green)/QuantumRange));
(void) WriteBlobByte(image,(unsigned char) ((31*transpix.blue)/QuantumRange));
}
if (flags & PALM_IS_COMPRESSED_FLAG) /* fill in size now */
{
offset=SeekBlob(image,currentOffset+offset,SEEK_SET);
(void) WriteBlobMSBShort(image,(unsigned short) (GetBlobSize(image)-
currentOffset-offset));
}
if (one_row != (unsigned char *) NULL)
one_row=(unsigned char *) RelinquishMagickMemory(one_row);
if (lastrow != (unsigned char *) NULL)
lastrow=(unsigned char *) RelinquishMagickMemory(lastrow);
if (GetNextImageInList(image) == (Image *) NULL)
break;
/* padding to 4 byte word */
for (cc = (GetBlobSize(image))%4; cc > 0; cc--)
{
(void) WriteBlobByte(image,0);
}
/* write nextDepthOffset and return to end of image */
offset=SeekBlob(image,currentOffset+10,SEEK_SET);
nextDepthOffset=(size_t) ((GetBlobSize(image)-currentOffset)/4);
(void) WriteBlobMSBShort(image,(unsigned short) nextDepthOffset);
currentOffset=(MagickOffsetType) GetBlobSize(image);
offset=SeekBlob(image,currentOffset,SEEK_SET);
image=SyncNextImageInList(image);
status=SetImageProgress(image,SaveImagesTag,scene++,
GetImageListLength(image));
if (status == MagickFalse)
break;
} while (image_info->adjoin != MagickFalse);
quantize_info=DestroyQuantizeInfo(quantize_info);
(void) CloseBlob(image);
(void) DestroyExceptionInfo(&exception);
return(MagickTrue);
}

527
ImageMagick/coders/pango.c Normal file
View file

@ -0,0 +1,527 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% PPPP AAA N N GGGG OOO %
% P P A A NN N G O O %
% PPPP AAAAA N N N G GGG O O %
% P M A A N NN G G O O %
% P A A N N GGGG OOO %
% %
% %
% Read Pango Markup Language Format %
% %
% Software Design %
% John Cristy %
% March 2012 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/annotate.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/composite-private.h"
#include "magick/draw.h"
#include "magick/draw-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/module.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/option.h"
#include "magick/pixel-accessor.h"
#include "magick/property.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/string-private.h"
#include "magick/token.h"
#include "magick/utility.h"
#if defined(MAGICKCORE_PANGOCAIRO_DELEGATE)
#include <pango/pango.h>
#include <pango/pangocairo.h>
#include <pango/pango-features.h>
#endif
#if defined(MAGICKCORE_PANGOCAIRO_DELEGATE)
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d P A N G O I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadPANGOImage() reads an image in the Pango Markup Language Format.
%
% The format of the ReadPANGOImage method is:
%
% Image *ReadPANGOImage(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 *ReadPANGOImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
cairo_font_options_t
*font_options;
cairo_surface_t
*surface;
char
*caption,
*property;
cairo_t
*cairo_image;
const char
*option;
DrawInfo
*draw_info;
Image
*image;
MagickBooleanType
status;
PangoAlignment
align;
PangoContext
*context;
PangoFontMap
*fontmap;
PangoGravity
gravity;
PangoLayout
*layout;
PangoRectangle
extent;
PixelPacket
fill_color;
RectangleInfo
page;
register unsigned char
*p;
size_t
stride;
ssize_t
y;
unsigned char
*pixels;
/*
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");
/*
Format caption.
*/
option=GetImageOption(image_info,"filename");
if (option == (const char *) NULL)
property=InterpretImageProperties(image_info,image,image_info->filename);
else
if (LocaleNCompare(option,"pango:",6) == 0)
property=InterpretImageProperties(image_info,image,option+6);
else
property=InterpretImageProperties(image_info,image,option);
(void) SetImageProperty(image,"caption",property);
property=DestroyString(property);
caption=ConstantString(GetImageProperty(image,"caption"));
/*
Get context.
*/
fontmap=pango_cairo_font_map_new();
pango_cairo_font_map_set_resolution(PANGO_CAIRO_FONT_MAP(fontmap),
image->x_resolution == 0.0 ? 90.0 : image->x_resolution);
font_options=cairo_font_options_create();
option=GetImageOption(image_info,"pango:hinting");
if (option != (const char *) NULL)
{
if (LocaleCompare(option,"none") != 0)
cairo_font_options_set_hint_style(font_options,CAIRO_HINT_STYLE_NONE);
if (LocaleCompare(option,"full") != 0)
cairo_font_options_set_hint_style(font_options,CAIRO_HINT_STYLE_FULL);
}
context=pango_font_map_create_context(fontmap);
pango_cairo_context_set_font_options(context,font_options);
cairo_font_options_destroy(font_options);
option=GetImageOption(image_info,"pango:language");
if (option != (const char *) NULL)
pango_context_set_language(context,pango_language_from_string(option));
draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
pango_context_set_base_dir(context,draw_info->direction ==
RightToLeftDirection ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR);
switch (draw_info->gravity)
{
case NorthGravity:
{
gravity=PANGO_GRAVITY_NORTH;
break;
}
case NorthWestGravity:
case WestGravity:
case SouthWestGravity:
{
gravity=PANGO_GRAVITY_WEST;
break;
}
case NorthEastGravity:
case EastGravity:
case SouthEastGravity:
{
gravity=PANGO_GRAVITY_EAST;
break;
}
case SouthGravity:
{
gravity=PANGO_GRAVITY_SOUTH;
break;
}
default:
{
gravity=PANGO_GRAVITY_AUTO;
break;
}
}
pango_context_set_base_gravity(context,gravity);
option=GetImageOption(image_info,"pango:gravity-hint");
if (option != (const char *) NULL)
{
if (LocaleCompare(option,"line") == 0)
pango_context_set_gravity_hint(context,PANGO_GRAVITY_HINT_LINE);
if (LocaleCompare(option,"natural") == 0)
pango_context_set_gravity_hint(context,PANGO_GRAVITY_HINT_NATURAL);
if (LocaleCompare(option,"strong") == 0)
pango_context_set_gravity_hint(context,PANGO_GRAVITY_HINT_STRONG);
}
/*
Configure layout.
*/
layout=pango_layout_new(context);
option=GetImageOption(image_info,"pango:auto-dir");
if (option != (const char *) NULL)
pango_layout_set_auto_dir(layout,1);
option=GetImageOption(image_info,"pango:ellipsize");
if (option != (const char *) NULL)
{
if (LocaleCompare(option,"end") == 0)
pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_END);
if (LocaleCompare(option,"middle") == 0)
pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_MIDDLE);
if (LocaleCompare(option,"none") == 0)
pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_NONE);
if (LocaleCompare(option,"start") == 0)
pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_START);
}
option=GetImageOption(image_info,"pango:justify");
if ((option != (const char *) NULL) && (IsMagickTrue(option) != MagickFalse))
pango_layout_set_justify(layout,1);
option=GetImageOption(image_info,"pango:single-paragraph");
if ((option != (const char *) NULL) && (IsMagickTrue(option) != MagickFalse))
pango_layout_set_single_paragraph_mode(layout,1);
option=GetImageOption(image_info,"pango:wrap");
if (option != (const char *) NULL)
{
if (LocaleCompare(option,"char") == 0)
pango_layout_set_wrap(layout,PANGO_WRAP_CHAR);
if (LocaleCompare(option,"word") == 0)
pango_layout_set_wrap(layout,PANGO_WRAP_WORD);
if (LocaleCompare(option,"word-char") == 0)
pango_layout_set_wrap(layout,PANGO_WRAP_WORD_CHAR);
}
option=GetImageOption(image_info,"pango:indent");
if (option != (const char *) NULL)
pango_layout_set_indent(layout,(int) ((StringToLong(option)*
(image->x_resolution == 0.0 ? 90.0 : image->x_resolution)*PANGO_SCALE+45)/
90.0+0.5));
switch (draw_info->align)
{
case CenterAlign: align=PANGO_ALIGN_CENTER; break;
case RightAlign: align=PANGO_ALIGN_RIGHT; break;
case LeftAlign: align=PANGO_ALIGN_LEFT; break;
default:
{
if (draw_info->gravity == CenterGravity)
{
align=PANGO_ALIGN_CENTER;
break;
}
align=PANGO_ALIGN_LEFT;
break;
}
}
if ((align != PANGO_ALIGN_CENTER) &&
(draw_info->direction == RightToLeftDirection))
align=(PangoAlignment) (PANGO_ALIGN_LEFT+PANGO_ALIGN_RIGHT-align);
pango_layout_set_alignment(layout,align);
if (draw_info->font != (char *) NULL)
{
PangoFontDescription
*description;
/*
Set font.
*/
description=pango_font_description_from_string(draw_info->font);
pango_font_description_set_size(description,(int) (PANGO_SCALE*
draw_info->pointsize+0.5));
pango_layout_set_font_description(layout,description);
pango_font_description_free(description);
}
option=GetImageOption(image_info,"pango:markup");
if ((option != (const char *) NULL) && (IsMagickTrue(option) == MagickFalse))
pango_layout_set_text(layout,caption,-1);
else
{
GError
*error;
error=(GError *) NULL;
if (pango_parse_markup(caption,-1,0,NULL,NULL,NULL,&error) == 0)
(void) ThrowMagickException(exception,GetMagickModule(),CoderError,
error->message,"`%s'",image_info->filename);
pango_layout_set_markup(layout,caption,-1);
}
pango_layout_context_changed(layout);
page.x=0;
page.y=0;
if (image_info->page != (char *) NULL)
(void) ParseAbsoluteGeometry(image_info->page,&page);
if (image->columns == 0)
{
pango_layout_get_extents(layout,NULL,&extent);
image->columns=(extent.x+extent.width+PANGO_SCALE/2)/PANGO_SCALE+2*page.x;
}
else
{
image->columns-=2*page.x;
pango_layout_set_width(layout,(int) ((PANGO_SCALE*image->columns*
(image->x_resolution == 0.0 ? 90.0 : image->x_resolution)+45.0)/90.0+
0.5));
}
if (image->rows == 0)
{
pango_layout_get_extents(layout,NULL,&extent);
image->rows=(extent.y+extent.height+PANGO_SCALE/2)/PANGO_SCALE+2*page.y;
}
else
{
image->rows-=2*page.y;
pango_layout_set_height(layout,(int) ((PANGO_SCALE*image->rows*
(image->y_resolution == 0.0 ? 90.0 : image->y_resolution)+45.0)/90.0+
0.5));
}
/*
Render markup.
*/
stride=(size_t) cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
image->columns);
pixels=(unsigned char *) AcquireQuantumMemory(image->rows,stride*
sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
{
draw_info=DestroyDrawInfo(draw_info);
caption=DestroyString(caption);
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
surface=cairo_image_surface_create_for_data(pixels,CAIRO_FORMAT_ARGB32,
image->columns,image->rows,stride);
cairo_image=cairo_create(surface);
cairo_set_operator(cairo_image,CAIRO_OPERATOR_CLEAR);
cairo_paint(cairo_image);
cairo_set_operator(cairo_image,CAIRO_OPERATOR_OVER);
cairo_translate(cairo_image,page.x,page.y);
pango_cairo_show_layout(cairo_image,layout);
cairo_destroy(cairo_image);
cairo_surface_destroy(surface);
g_object_unref(layout);
g_object_unref(fontmap);
/*
Convert surface to image.
*/
(void) SetImageBackgroundColor(image);
p=pixels;
for (y=0; y < (ssize_t) image->rows; y++)
{
register PixelPacket
*q;
register ssize_t
x;
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
double
gamma;
fill_color.blue=ScaleCharToQuantum(*p++);
fill_color.green=ScaleCharToQuantum(*p++);
fill_color.red=ScaleCharToQuantum(*p++);
fill_color.opacity=QuantumRange-ScaleCharToQuantum(*p++);
/*
Disassociate alpha.
*/
gamma=1.0-QuantumScale*fill_color.opacity;
gamma=PerceptibleReciprocal(gamma);
fill_color.blue*=gamma;
fill_color.green*=gamma;
fill_color.red*=gamma;
MagickCompositeOver(&fill_color,fill_color.opacity,q,(MagickRealType)
q->opacity,q);
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
/*
Relinquish resources.
*/
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
draw_info=DestroyDrawInfo(draw_info);
caption=DestroyString(caption);
return(GetFirstImageInList(image));
}
#endif
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r P A N G O I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterPANGOImage() adds attributes for the Pango Markup Language format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterPANGOImage method is:
%
% size_t RegisterPANGOImage(void)
%
*/
ModuleExport size_t RegisterPANGOImage(void)
{
char
version[MaxTextExtent];
MagickInfo
*entry;
*version='\0';
#if defined(PANGO_VERSION_STRING)
(void) FormatLocaleString(version,MaxTextExtent,"Pangocairo %s",
PANGO_VERSION_STRING);
#endif
entry=SetMagickInfo("PANGO");
#if defined(MAGICKCORE_PANGOCAIRO_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadPANGOImage;
#endif
entry->description=ConstantString("Pango Markup Language");
if (*version != '\0')
entry->version=ConstantString(version);
entry->adjoin=MagickFalse;
entry->module=ConstantString("PANGO");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r P A N G O I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterPANGOImage() removes format registrations made by the Pango module
% from the list of supported formats.
%
% The format of the UnregisterPANGOImage method is:
%
% UnregisterPANGOImage(void)
%
*/
ModuleExport void UnregisterPANGOImage(void)
{
(void) UnregisterMagickInfo("PANGO");
}

1058
ImageMagick/coders/pattern.c Normal file

File diff suppressed because it is too large Load diff

1141
ImageMagick/coders/pcd.c Normal file

File diff suppressed because it is too large Load diff

969
ImageMagick/coders/pcl.c Normal file
View file

@ -0,0 +1,969 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% PPPP CCCC L %
% P P C L %
% PPPP C L %
% P C L %
% P CCCC LLLLL %
% %
% %
% Read/Write HP PCL Printer Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/property.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/constitute.h"
#include "magick/delegate.h"
#include "magick/draw.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/geometry.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/option.h"
#include "magick/pixel-accessor.h"
#include "magick/profile.h"
#include "magick/quantum-private.h"
#include "magick/resource_.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/token.h"
#include "magick/transform.h"
#include "magick/utility.h"
/*
Forward declarations.
*/
static MagickBooleanType
WritePCLImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s P C L %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsPCL() returns MagickTrue if the image format type, identified by the
% magick string, is PCL.
%
% The format of the IsPCL method is:
%
% MagickBooleanType IsPCL(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsPCL(const unsigned char *magick,const size_t length)
{
if (length < 4)
return(MagickFalse);
if (memcmp(magick,"\033E\033&",4) == 0)
return(MagickFalse);
if (memcmp(magick,"\033E\033",3) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d P C L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadPCLImage() reads a Printer Control Language 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 ReadPCLImage method is:
%
% Image *ReadPCLImage(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 *ReadPCLImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
#define CropBox "CropBox"
#define DeviceCMYK "DeviceCMYK"
#define MediaBox "MediaBox"
#define RenderPCLText " Rendering PCL... "
char
command[MaxTextExtent],
density[MaxTextExtent],
filename[MaxTextExtent],
geometry[MaxTextExtent],
options[MaxTextExtent],
input_filename[MaxTextExtent];
const DelegateInfo
*delegate_info;
Image
*image,
*next_image;
ImageInfo
*read_info;
int
c;
MagickBooleanType
cmyk,
status;
PointInfo
delta;
RectangleInfo
bounding_box,
page;
register char
*p;
SegmentInfo
bounds;
size_t
height,
width;
ssize_t
count;
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);
/*
Open image file.
*/
image=AcquireImage(image_info);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
status=AcquireUniqueSymbolicLink(image_info->filename,input_filename);
if (status == MagickFalse)
{
ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
image_info->filename);
image=DestroyImageList(image);
return((Image *) NULL);
}
/*
Set the page density.
*/
delta.x=DefaultResolution;
delta.y=DefaultResolution;
if ((image->x_resolution == 0.0) || (image->y_resolution == 0.0))
{
GeometryInfo
geometry_info;
MagickStatusType
flags;
flags=ParseGeometry(PSDensityGeometry,&geometry_info);
image->x_resolution=geometry_info.rho;
image->y_resolution=geometry_info.sigma;
if ((flags & SigmaValue) == 0)
image->y_resolution=image->x_resolution;
}
/*
Determine page geometry from the PCL media box.
*/
cmyk=image->colorspace == CMYKColorspace ? MagickTrue : MagickFalse;
count=0;
(void) ResetMagickMemory(&bounding_box,0,sizeof(bounding_box));
(void) ResetMagickMemory(&bounds,0,sizeof(bounds));
(void) ResetMagickMemory(&page,0,sizeof(page));
(void) ResetMagickMemory(command,0,sizeof(command));
p=command;
for (c=ReadBlobByte(image); c != EOF; c=ReadBlobByte(image))
{
if (image_info->page != (char *) NULL)
continue;
/*
Note PCL elements.
*/
*p++=(char) c;
if ((c != (int) '/') && (c != '\n') &&
((size_t) (p-command) < (MaxTextExtent-1)))
continue;
*p='\0';
p=command;
/*
Is this a CMYK document?
*/
if (LocaleNCompare(DeviceCMYK,command,strlen(DeviceCMYK)) == 0)
cmyk=MagickTrue;
if (LocaleNCompare(CropBox,command,strlen(CropBox)) == 0)
{
/*
Note region defined by crop box.
*/
count=(ssize_t) sscanf(command,"CropBox [%lf %lf %lf %lf",
&bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
if (count != 4)
count=(ssize_t) sscanf(command,"CropBox[%lf %lf %lf %lf",
&bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
}
if (LocaleNCompare(MediaBox,command,strlen(MediaBox)) == 0)
{
/*
Note region defined by media box.
*/
count=(ssize_t) sscanf(command,"MediaBox [%lf %lf %lf %lf",
&bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
if (count != 4)
count=(ssize_t) sscanf(command,"MediaBox[%lf %lf %lf %lf",
&bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
}
if (count != 4)
continue;
/*
Set PCL render geometry.
*/
width=(size_t) floor(bounds.x2-bounds.x1+0.5);
height=(size_t) floor(bounds.y2-bounds.y1+0.5);
if (width > page.width)
page.width=width;
if (height > page.height)
page.height=height;
}
(void) CloseBlob(image);
/*
Render PCL with the GhostPCL delegate.
*/
if ((page.width == 0) || (page.height == 0))
(void) ParseAbsoluteGeometry(PSPageGeometry,&page);
if (image_info->page != (char *) NULL)
(void) ParseAbsoluteGeometry(image_info->page,&page);
(void) FormatLocaleString(geometry,MaxTextExtent,"%.20gx%.20g",(double)
page.width,(double) page.height);
if (image_info->monochrome != MagickFalse)
delegate_info=GetDelegateInfo("pcl:mono",(char *) NULL,exception);
else
if (cmyk != MagickFalse)
delegate_info=GetDelegateInfo("pcl:cmyk",(char *) NULL,exception);
else
delegate_info=GetDelegateInfo("pcl:color",(char *) NULL,exception);
if (delegate_info == (const DelegateInfo *) NULL)
return((Image *) NULL);
*options='\0';
if ((page.width == 0) || (page.height == 0))
(void) ParseAbsoluteGeometry(PSPageGeometry,&page);
if (image_info->page != (char *) NULL)
(void) ParseAbsoluteGeometry(image_info->page,&page);
(void) FormatLocaleString(density,MaxTextExtent,"%gx%g",
image->x_resolution,image->y_resolution);
page.width=(size_t) floor((double) page.width*image->x_resolution/delta.x+
0.5);
page.height=(size_t) floor((double) page.height*image->y_resolution/delta.y+
0.5);
(void) FormatLocaleString(options,MaxTextExtent,"-g%.20gx%.20g ",(double)
page.width,(double) page.height);
image=DestroyImage(image);
read_info=CloneImageInfo(image_info);
*read_info->magick='\0';
if (read_info->number_scenes != 0)
{
if (read_info->number_scenes != 1)
(void) FormatLocaleString(options,MaxTextExtent,"-dLastPage=%.20g",
(double) (read_info->scene+read_info->number_scenes));
else
(void) FormatLocaleString(options,MaxTextExtent,
"-dFirstPage=%.20g -dLastPage=%.20g",(double) read_info->scene+1,
(double) (read_info->scene+read_info->number_scenes));
read_info->number_scenes=0;
if (read_info->scenes != (char *) NULL)
*read_info->scenes='\0';
}
if (read_info->authenticate != (char *) NULL)
(void) FormatLocaleString(options+strlen(options),MaxTextExtent,
" -sPCLPassword=%s",read_info->authenticate);
(void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
(void) AcquireUniqueFilename(read_info->filename);
(void) FormatLocaleString(command,MaxTextExtent,
GetDelegateCommands(delegate_info),
read_info->antialias != MagickFalse ? 4 : 1,
read_info->antialias != MagickFalse ? 4 : 1,density,options,
read_info->filename,input_filename);
status=SystemCommand(MagickFalse,read_info->verbose,command,exception) != 0 ?
MagickTrue : MagickFalse;
image=ReadImage(read_info,exception);
(void) RelinquishUniqueFileResource(read_info->filename);
(void) RelinquishUniqueFileResource(input_filename);
read_info=DestroyImageInfo(read_info);
if (image == (Image *) NULL)
ThrowReaderException(DelegateError,"PCLDelegateFailed");
if (LocaleCompare(image->magick,"BMP") == 0)
{
Image
*cmyk_image;
cmyk_image=ConsolidateCMYKImages(image,&image->exception);
if (cmyk_image != (Image *) NULL)
{
image=DestroyImageList(image);
image=cmyk_image;
}
}
do
{
(void) CopyMagickString(image->filename,filename,MaxTextExtent);
image->page=page;
next_image=SyncNextImageInList(image);
if (next_image != (Image *) NULL)
image=next_image;
} while (next_image != (Image *) NULL);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r P C L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterPCLImage() adds attributes for the PCL image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the i file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterPCLImage method is:
%
% size_t RegisterPCLImage(void)
%
*/
ModuleExport size_t RegisterPCLImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("PCL");
entry->decoder=(DecodeImageHandler *) ReadPCLImage;
entry->encoder=(EncodeImageHandler *) WritePCLImage;
entry->magick=(IsImageFormatHandler *) IsPCL;
entry->blob_support=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->thread_support=EncoderThreadSupport;
entry->description=ConstantString("Printer Control Language");
entry->module=ConstantString("PCL");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r P C L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterPCLImage() removes format registrations made by the PCL module
% from the list of supported formats.
%
% The format of the UnregisterPCLImage method is:
%
% UnregisterPCLImage(void)
%
*/
ModuleExport void UnregisterPCLImage(void)
{
(void) UnregisterMagickInfo("PCL");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e P C L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WritePCLImage() writes an image in the Page Control Language encoded
% image format.
%
% The format of the WritePCLImage method is:
%
% MagickBooleanType WritePCLImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static size_t PCLDeltaCompressImage(const size_t length,
const unsigned char *previous_pixels,const unsigned char *pixels,
unsigned char *compress_pixels)
{
int
delta,
j,
replacement;
register ssize_t
i,
x;
register unsigned char
*q;
q=compress_pixels;
for (x=0; x < (ssize_t) length; )
{
j=0;
for (i=0; x < (ssize_t) length; x++)
{
if (*pixels++ != *previous_pixels++)
{
i=1;
break;
}
j++;
}
while (x < (ssize_t) length)
{
x++;
if (*pixels == *previous_pixels)
break;
i++;
previous_pixels++;
pixels++;
}
if (i == 0)
break;
replacement=j >= 31 ? 31 : j;
j-=replacement;
delta=i >= 8 ? 8 : i;
*q++=(unsigned char) (((delta-1) << 5) | replacement);
if (replacement == 31)
{
for (replacement=255; j != 0; )
{
if (replacement > j)
replacement=j;
*q++=(unsigned char) replacement;
j-=replacement;
}
if (replacement == 255)
*q++='\0';
}
for (pixels-=i; i != 0; )
{
for (i-=delta; delta != 0; delta--)
*q++=(*pixels++);
if (i == 0)
break;
delta=(int) i;
if (i >= 8)
delta=8;
*q++=(unsigned char) ((delta-1) << 5);
}
}
return((size_t) (q-compress_pixels));
}
static size_t PCLPackbitsCompressImage(const size_t length,
const unsigned char *pixels,unsigned char *compress_pixels)
{
int
count;
register ssize_t
x;
register unsigned char
*q;
ssize_t
j;
unsigned char
packbits[128];
/*
Compress pixels with Packbits encoding.
*/
q=compress_pixels;
for (x=(ssize_t) length; x != 0; )
{
switch (x)
{
case 1:
{
x--;
*q++=0;
*q++=(*pixels);
break;
}
case 2:
{
x-=2;
*q++=1;
*q++=(*pixels);
*q++=pixels[1];
break;
}
case 3:
{
x-=3;
if ((*pixels == *(pixels+1)) && (*(pixels+1) == *(pixels+2)))
{
*q++=(unsigned char) ((256-3)+1);
*q++=(*pixels);
break;
}
*q++=2;
*q++=(*pixels);
*q++=pixels[1];
*q++=pixels[2];
break;
}
default:
{
if ((*pixels == *(pixels+1)) && (*(pixels+1) == *(pixels+2)))
{
/*
Packed run.
*/
count=3;
while (((ssize_t) count < x) && (*pixels == *(pixels+count)))
{
count++;
if (count >= 127)
break;
}
x-=count;
*q++=(unsigned char) ((256-count)+1);
*q++=(*pixels);
pixels+=count;
break;
}
/*
Literal run.
*/
count=0;
while ((*(pixels+count) != *(pixels+count+1)) ||
(*(pixels+count+1) != *(pixels+count+2)))
{
packbits[count+1]=pixels[count];
count++;
if (((ssize_t) count >= (x-3)) || (count >= 127))
break;
}
x-=count;
*packbits=(unsigned char) (count-1);
for (j=0; j <= (ssize_t) count; j++)
*q++=packbits[j];
pixels+=count;
break;
}
}
}
*q++=128; /* EOD marker */
return((size_t) (q-compress_pixels));
}
static MagickBooleanType WritePCLImage(const ImageInfo *image_info,Image *image)
{
char
buffer[MaxTextExtent];
const char
*option;
MagickBooleanType
status;
MagickOffsetType
scene;
register const IndexPacket
*indexes;
register const PixelPacket *p; register ssize_t i, x; register unsigned char *q; size_t density, length,
one,
packets;
ssize_t
y;
unsigned char
bits_per_pixel,
*compress_pixels,
*pixels,
*previous_pixels;
/*
Open output image file.
*/
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);
density=75;
if (image_info->density != (char *) NULL)
{
GeometryInfo
geometry;
(void) ParseGeometry(image_info->density,&geometry);
density=(size_t) geometry.rho;
}
scene=0;
one=1;
do
{
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
/*
Initialize the printer.
*/
(void) WriteBlobString(image,"\033E"); /* printer reset */
(void) WriteBlobString(image,"\033*r3F"); /* set presentation mode */
(void) FormatLocaleString(buffer,MaxTextExtent,"\033*r%.20gs%.20gT",
(double) image->columns,(double) image->rows);
(void) WriteBlobString(image,buffer);
(void) FormatLocaleString(buffer,MaxTextExtent,"\033*t%.20gR",(double)
density);
(void) WriteBlobString(image,buffer);
(void) WriteBlobString(image,"\033&l0E"); /* top margin 0 */
if (IsMonochromeImage(image,&image->exception) != MagickFalse)
{
/*
Monochrome image: use default printer monochrome setup.
*/
bits_per_pixel=1;
}
else
if (image->storage_class == DirectClass)
{
/*
DirectClass image.
*/
bits_per_pixel=24;
(void) WriteBlobString(image,"\033*v6W"); /* set color mode */
(void) WriteBlobByte(image,0); /* RGB */
(void) WriteBlobByte(image,3); /* direct by pixel */
(void) WriteBlobByte(image,0); /* bits per index (ignored) */
(void) WriteBlobByte(image,8); /* bits per red component */
(void) WriteBlobByte(image,8); /* bits per green component */
(void) WriteBlobByte(image,8); /* bits per blue component */
}
else
{
/*
Colormapped image.
*/
bits_per_pixel=8;
(void) WriteBlobString(image,"\033*v6W"); /* set color mode... */
(void) WriteBlobByte(image,0); /* RGB */
(void) WriteBlobByte(image,1); /* indexed by pixel */
(void) WriteBlobByte(image,bits_per_pixel); /* bits per index */
(void) WriteBlobByte(image,8); /* bits per red component */
(void) WriteBlobByte(image,8); /* bits per green component */
(void) WriteBlobByte(image,8); /* bits per blue component */
for (i=0; i < (ssize_t) image->colors; i++)
{
(void) FormatLocaleString(buffer,MaxTextExtent,
"\033*v%da%db%dc%.20gI",
ScaleQuantumToChar(image->colormap[i].red),
ScaleQuantumToChar(image->colormap[i].green),
ScaleQuantumToChar(image->colormap[i].blue),(double) i);
(void) WriteBlobString(image,buffer);
}
for (one=1; i < (ssize_t) (one << bits_per_pixel); i++)
{
(void) FormatLocaleString(buffer,MaxTextExtent,"\033*v%.20gI",
(double) i);
(void) WriteBlobString(image,buffer);
}
}
option=GetImageOption(image_info,"pcl:fit-to-page");
if ((option != (const char *) NULL) &&
(IsMagickTrue(option) != MagickFalse))
(void) WriteBlobString(image,"\033*r3A");
else
(void) WriteBlobString(image,"\033*r1A"); /* start raster graphics */
(void) WriteBlobString(image,"\033*b0Y"); /* set y offset */
length=(image->columns*bits_per_pixel+7)/8;
pixels=(unsigned char *) AcquireQuantumMemory(length+1,sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
(void) ResetMagickMemory(pixels,0,(length+1)*sizeof(*pixels));
compress_pixels=(unsigned char *) NULL;
previous_pixels=(unsigned char *) NULL;
switch (image->compression)
{
case NoCompression:
{
(void) FormatLocaleString(buffer,MaxTextExtent,"\033*b0M");
(void) WriteBlobString(image,buffer);
break;
}
case RLECompression:
{
compress_pixels=(unsigned char *) AcquireQuantumMemory(length+256,
sizeof(*compress_pixels));
if (compress_pixels == (unsigned char *) NULL)
{
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
}
(void) ResetMagickMemory(compress_pixels,0,(length+256)*
sizeof(*compress_pixels));
(void) FormatLocaleString(buffer,MaxTextExtent,"\033*b2M");
(void) WriteBlobString(image,buffer);
break;
}
default:
{
compress_pixels=(unsigned char *) AcquireQuantumMemory(3*length+256,
sizeof(*compress_pixels));
if (compress_pixels == (unsigned char *) NULL)
{
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
}
(void) ResetMagickMemory(compress_pixels,0,(3*length+256)*
sizeof(*compress_pixels));
previous_pixels=(unsigned char *) AcquireQuantumMemory(length+1,
sizeof(*previous_pixels));
if (previous_pixels == (unsigned char *) NULL)
{
compress_pixels=(unsigned char *) RelinquishMagickMemory(
compress_pixels);
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
}
(void) ResetMagickMemory(previous_pixels,0,(length+1)*
sizeof(*previous_pixels));
(void) FormatLocaleString(buffer,MaxTextExtent,"\033*b3M");
(void) WriteBlobString(image,buffer);
break;
}
}
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=GetAuthenticIndexQueue(image);
q=pixels;
switch (bits_per_pixel)
{
case 1:
{
register unsigned char
bit,
byte;
/*
Monochrome image.
*/
bit=0;
byte=0;
for (x=0; x < (ssize_t) image->columns; x++)
{
byte<<=1;
if (GetPixelIntensity(image,p) < (QuantumRange/2.0))
byte|=0x01;
bit++;
if (bit == 8)
{
*q++=byte;
bit=0;
byte=0;
}
p++;
}
if (bit != 0)
*q++=byte << (8-bit);
break;
}
case 8:
{
/*
Colormapped image.
*/
for (x=0; x < (ssize_t) image->columns; x++)
*q++=(unsigned char) GetPixelIndex(indexes+x);
break;
}
case 24:
case 32:
{
/*
Truecolor image.
*/
for (x=0; x < (ssize_t) image->columns; x++)
{
*q++=ScaleQuantumToChar(GetPixelRed(p));
*q++=ScaleQuantumToChar(GetPixelGreen(p));
*q++=ScaleQuantumToChar(GetPixelBlue(p));
p++;
}
break;
}
}
switch (image->compression)
{
case NoCompression:
{
(void) FormatLocaleString(buffer,MaxTextExtent,"\033*b%.20gW",
(double) length);
(void) WriteBlobString(image,buffer);
(void) WriteBlob(image,length,pixels);
break;
}
case RLECompression:
{
packets=PCLPackbitsCompressImage(length,pixels,compress_pixels);
(void) FormatLocaleString(buffer,MaxTextExtent,"\033*b%.20gW",
(double) packets);
(void) WriteBlobString(image,buffer);
(void) WriteBlob(image,packets,compress_pixels);
break;
}
default:
{
if (y == 0)
for (i=0; i < (ssize_t) length; i++)
previous_pixels[i]=(~pixels[i]);
packets=PCLDeltaCompressImage(length,previous_pixels,pixels,
compress_pixels);
(void) FormatLocaleString(buffer,MaxTextExtent,"\033*b%.20gW",
(double) packets);
(void) WriteBlobString(image,buffer);
(void) WriteBlob(image,packets,compress_pixels);
(void) CopyMagickMemory(previous_pixels,pixels,length*
sizeof(*pixels));
break;
}
}
}
(void) WriteBlobString(image,"\033*rB"); /* end graphics */
switch (image->compression)
{
case NoCompression:
break;
case RLECompression:
{
compress_pixels=(unsigned char *) RelinquishMagickMemory(
compress_pixels);
break;
}
default:
{
previous_pixels=(unsigned char *) RelinquishMagickMemory(
previous_pixels);
compress_pixels=(unsigned char *) RelinquishMagickMemory(
compress_pixels);
break;
}
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (GetNextImageInList(image) == (Image *) NULL)
break;
image=SyncNextImageInList(image);
status=SetImageProgress(image,SaveImagesTag,scene++,
GetImageListLength(image));
if (status == MagickFalse)
break;
} while (image_info->adjoin != MagickFalse);
(void) WriteBlobString(image,"\033E");
(void) CloseBlob(image);
return(MagickTrue);
}

1181
ImageMagick/coders/pcx.c Normal file

File diff suppressed because it is too large Load diff

931
ImageMagick/coders/pdb.c Normal file
View file

@ -0,0 +1,931 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% PPPP DDDD BBBB %
% P P D D B B %
% PPPP D D BBBB %
% P D D B B %
% P DDDD BBBB %
% %
% %
% Read/Write Palm Database ImageViewer Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
20071202 TS * rewrote RLE decoder - old version could cause buffer overflows
* failure of RLE decoding now thows error RLEDecoderError
* fixed bug in RLE decoding - now all rows are decoded, not just
the first one
* fixed bug in reader - record offsets now handled correctly
* fixed bug in reader - only bits 0..2 indicate compression type
* in writer: now using image color count instead of depth
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/attribute.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colormap-private.h"
#include "magick/color-private.h"
#include "magick/colormap.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/property.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Typedef declarations.
*/
typedef struct _PDBInfo
{
char
name[32];
short int
attributes,
version;
size_t
create_time,
modify_time,
archive_time,
modify_number,
application_info,
sort_info;
char
type[4], /* database type identifier "vIMG" */
id[4]; /* database creator identifier "View" */
size_t
seed,
next_record;
short int
number_records;
} PDBInfo;
typedef struct _PDBImage
{
char
name[32],
version,
type;
size_t
reserved_1,
note;
short int
x_last,
y_last;
size_t
reserved_2;
short int
x_anchor,
y_anchor,
width,
height;
} PDBImage;
/*
Forward declarations.
*/
static MagickBooleanType
WritePDBImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% D e c o d e I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DecodeImage unpacks the packed image pixels into runlength-encoded
% pixel packets.
%
% The format of the DecodeImage method is:
%
% MagickBooleanType DecodeImage(Image *image,unsigned char *pixels,
% const size_t length)
%
% A description of each parameter follows:
%
% o image: the address of a structure of type Image.
%
% o pixels: The address of a byte (8 bits) array of pixel data created by
% the decoding process.
%
% o length: Number of bytes to read into buffer 'pixels'.
%
*/
static MagickBooleanType DecodeImage(Image *image, unsigned char *pixels,
const size_t length)
{
#define RLE_MODE_NONE -1
#define RLE_MODE_COPY 0
#define RLE_MODE_RUN 1
int data = 0, count = 0;
unsigned char *p;
int mode = RLE_MODE_NONE;
for (p = pixels; p < pixels + length; p++) {
if (0 == count) {
data = ReadBlobByte( image );
if (-1 == data) return MagickFalse;
if (data > 128) {
mode = RLE_MODE_RUN;
count = data - 128 + 1;
data = ReadBlobByte( image );
if (-1 == data) return MagickFalse;
} else {
mode = RLE_MODE_COPY;
count = data + 1;
}
}
if (RLE_MODE_COPY == mode) {
data = ReadBlobByte( image );
if (-1 == data) return MagickFalse;
}
*p = (unsigned char)data;
--count;
}
return MagickTrue;
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s P D B %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsPDB() returns MagickTrue if the image format type, identified by the
% magick string, is PDB.
%
% The format of the ReadPDBImage method is:
%
% MagickBooleanType IsPDB(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsPDB(const unsigned char *magick,const size_t length)
{
if (length < 68)
return(MagickFalse);
if (memcmp(magick+60,"vIMGView",8) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d P D B I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadPDBImage() reads an Pilot 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 ReadPDBImage method is:
%
% Image *ReadPDBImage(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 *ReadPDBImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
unsigned char
attributes, /* TS */
tag[3];
Image
*image;
IndexPacket
index;
MagickBooleanType
status;
PDBImage
pdb_image;
PDBInfo
pdb_info;
register IndexPacket
*indexes;
register ssize_t
x;
register PixelPacket
*q;
register unsigned char
*p;
size_t
bits_per_pixel,
num_pad_bytes, /* TS */
one,
packets;
ssize_t
count,
img_offset, /* TS */
comment_offset = 0,
y;
unsigned char
*pixels;
/*
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);
}
/*
Determine if this a PDB image file.
*/
count=ReadBlob(image,32,(unsigned char *) pdb_info.name);
pdb_info.attributes=(short) ReadBlobMSBShort(image);
pdb_info.version=(short) ReadBlobMSBShort(image);
pdb_info.create_time=ReadBlobMSBLong(image);
pdb_info.modify_time=ReadBlobMSBLong(image);
pdb_info.archive_time=ReadBlobMSBLong(image);
pdb_info.modify_number=ReadBlobMSBLong(image);
pdb_info.application_info=ReadBlobMSBLong(image);
pdb_info.sort_info=ReadBlobMSBLong(image);
count=ReadBlob(image,4,(unsigned char *) pdb_info.type);
count=ReadBlob(image,4,(unsigned char *) pdb_info.id);
if ((count == 0) || (memcmp(pdb_info.type,"vIMG",4) != 0) ||
(memcmp(pdb_info.id,"View",4) != 0))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
pdb_info.seed=ReadBlobMSBLong(image);
pdb_info.next_record=ReadBlobMSBLong(image);
pdb_info.number_records=(short) ReadBlobMSBShort(image);
if (pdb_info.next_record != 0)
ThrowReaderException(CoderError,"MultipleRecordListNotSupported");
/*
Read record header.
*/
img_offset=(int) ReadBlobMSBLong(image); /* TS */
attributes=(unsigned char) ReadBlobByte(image);
(void) attributes;
count=ReadBlob(image,3,(unsigned char *) tag);
if (count != 3 || memcmp(tag,"\x6f\x80\x00",3) != 0)
ThrowReaderException(CorruptImageError,"CorruptImage");
if (pdb_info.number_records > 1)
{
comment_offset=(int) ReadBlobMSBLong(image);
attributes=(unsigned char) ReadBlobByte(image);
count=ReadBlob(image,3,(unsigned char *) tag);
if (count != 3 || memcmp(tag,"\x6f\x80\x01",3) != 0)
ThrowReaderException(CorruptImageError,"CorruptImage");
}
num_pad_bytes = (size_t) (img_offset - TellBlob( image ));
while (num_pad_bytes--) ReadBlobByte( image );
/*
Read image header.
*/
count=ReadBlob(image,32,(unsigned char *) pdb_image.name);
pdb_image.version=ReadBlobByte(image);
pdb_image.type=ReadBlobByte(image);
pdb_image.reserved_1=ReadBlobMSBLong(image);
pdb_image.note=ReadBlobMSBLong(image);
pdb_image.x_last=(short) ReadBlobMSBShort(image);
pdb_image.y_last=(short) ReadBlobMSBShort(image);
pdb_image.reserved_2=ReadBlobMSBLong(image);
pdb_image.x_anchor=(short) ReadBlobMSBShort(image);
pdb_image.y_anchor=(short) ReadBlobMSBShort(image);
pdb_image.width=(short) ReadBlobMSBShort(image);
pdb_image.height=(short) ReadBlobMSBShort(image);
/*
Initialize image structure.
*/
image->columns=(size_t) pdb_image.width;
image->rows=(size_t) pdb_image.height;
image->depth=8;
image->storage_class=PseudoClass;
bits_per_pixel=pdb_image.type == 0 ? 2UL : pdb_image.type == 2 ? 4UL : 1UL;
one=1;
if (AcquireImageColormap(image,one << bits_per_pixel) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
packets=bits_per_pixel*image->columns/8;
pixels=(unsigned char *) AcquireQuantumMemory(packets+256UL,image->rows*
sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
switch (pdb_image.version & 7) /* TS */
{
case 0:
{
image->compression=NoCompression;
count=(ssize_t) ReadBlob(image, packets * image -> rows, pixels);
break;
}
case 1:
{
image->compression=RLECompression;
if (!DecodeImage(image, pixels, packets * image -> rows))
ThrowReaderException( CorruptImageError, "RLEDecoderError" ); /* TS */
break;
}
default:
ThrowReaderException(CorruptImageError,
"UnrecognizedImageCompressionType" );
}
p=pixels;
switch (bits_per_pixel)
{
case 1:
{
int
bit;
/*
Read 1-bit PDB image.
*/
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < ((ssize_t) image->columns-7); x+=8)
{
for (bit=0; bit < 8; bit++)
{
index=(IndexPacket) (*p & (0x80 >> bit) ? 0x00 : 0x01);
SetPixelIndex(indexes+x+bit,index);
}
p++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
(void) SyncImage(image);
break;
}
case 2:
{
/*
Read 2-bit PDB image.
*/
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < (ssize_t) image->columns; x+=4)
{
index=ConstrainColormapIndex(image,3UL-((*p >> 6) & 0x03));
SetPixelIndex(indexes+x,index);
index=ConstrainColormapIndex(image,3UL-((*p >> 4) & 0x03));
SetPixelIndex(indexes+x+1,index);
index=ConstrainColormapIndex(image,3UL-((*p >> 2) & 0x03));
SetPixelIndex(indexes+x+2,index);
index=ConstrainColormapIndex(image,3UL-((*p) & 0x03));
SetPixelIndex(indexes+x+3,index);
p++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
(void) SyncImage(image);
break;
}
case 4:
{
/*
Read 4-bit PDB image.
*/
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < (ssize_t) image->columns; x+=2)
{
index=ConstrainColormapIndex(image,15UL-((*p >> 4) & 0x0f));
SetPixelIndex(indexes+x,index);
index=ConstrainColormapIndex(image,15UL-((*p) & 0x0f));
SetPixelIndex(indexes+x+1,index);
p++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
(void) SyncImage(image);
break;
}
default:
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
if (pdb_info.number_records > 1) /* TS */
{
char
*comment;
int
c;
register char
*p;
size_t
length;
num_pad_bytes = (size_t) (comment_offset - TellBlob( image ));
while (num_pad_bytes--) ReadBlobByte( image );
/*
Read comment.
*/
c=ReadBlobByte(image);
length=MaxTextExtent;
comment=AcquireString((char *) NULL);
for (p=comment; c != EOF; p++)
{
if ((size_t) (p-comment+MaxTextExtent) >= length)
{
*p='\0';
length<<=1;
length+=MaxTextExtent;
comment=(char *) ResizeQuantumMemory(comment,length+MaxTextExtent,
sizeof(*comment));
if (comment == (char *) NULL)
break;
p=comment+strlen(comment);
}
*p=c;
c=ReadBlobByte(image);
}
*p='\0';
if (comment == (char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
(void) SetImageProperty(image,"comment",comment);
comment=DestroyString(comment);
}
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r P D B I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterPDBImage() adds properties for the PDB image format to
% the list of supported formats. The properties include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterPDBImage method is:
%
% size_t RegisterPDBImage(void)
%
*/
ModuleExport size_t RegisterPDBImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("PDB");
entry->decoder=(DecodeImageHandler *) ReadPDBImage;
entry->encoder=(EncodeImageHandler *) WritePDBImage;
entry->magick=(IsImageFormatHandler *) IsPDB;
entry->description=ConstantString("Palm Database ImageViewer Format");
entry->module=ConstantString("PDB");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r P D B I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterPDBImage() removes format registrations made by the
% PDB module from the list of supported formats.
%
% The format of the UnregisterPDBImage method is:
%
% UnregisterPDBImage(void)
%
*/
ModuleExport void UnregisterPDBImage(void)
{
(void) UnregisterMagickInfo("PDB");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e P D B I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WritePDBImage() writes an image
%
% The format of the WritePDBImage method is:
%
% MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
%
*/
static unsigned char *EncodeRLE(unsigned char *destination,
unsigned char *source,size_t literal,size_t repeat)
{
if (literal > 0)
*destination++=(unsigned char) (literal-1);
(void) CopyMagickMemory(destination,source,literal);
destination+=literal;
if (repeat > 0)
{
*destination++=(unsigned char) (0x80 | (repeat-1));
*destination++=source[literal];
}
return(destination);
}
static MagickBooleanType WritePDBImage(const ImageInfo *image_info,Image *image)
{
const char
*comment;
int
bits;
MagickBooleanType
status;
PDBImage
pdb_image;
PDBInfo
pdb_info;
QuantumInfo
*quantum_info;
register const PixelPacket
*p;
register ssize_t
x;
register unsigned char
*q;
size_t
bits_per_pixel,
literal,
packets,
packet_size,
repeat;
ssize_t
y;
unsigned char
*buffer,
*runlength,
*scanline;
/*
Open output image file.
*/
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);
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
if (image -> colors <= 2 || GetImageType( image, &image -> exception ) == BilevelType) { /* TS */
bits_per_pixel = 1;
} else if (image -> colors <= 4) {
bits_per_pixel = 2;
} else if (image -> colors <= 8) {
bits_per_pixel = 3;
} else {
bits_per_pixel = 4;
}
(void) ResetMagickMemory(pdb_info.name,0,32);
(void) CopyMagickString(pdb_info.name,image_info->filename,32);
pdb_info.attributes=0;
pdb_info.version=0;
pdb_info.create_time=time(NULL);
pdb_info.modify_time=pdb_info.create_time;
pdb_info.archive_time=0;
pdb_info.modify_number=0;
pdb_info.application_info=0;
pdb_info.sort_info=0;
(void) CopyMagickMemory(pdb_info.type,"vIMG",4);
(void) CopyMagickMemory(pdb_info.id,"View",4);
pdb_info.seed=0;
pdb_info.next_record=0;
comment=GetImageProperty(image,"comment");
pdb_info.number_records=(comment == (const char *) NULL ? 1 : 2);
(void) WriteBlob(image,32,(unsigned char *) pdb_info.name);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_info.attributes);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_info.version);
(void) WriteBlobMSBLong(image,(unsigned int) pdb_info.create_time);
(void) WriteBlobMSBLong(image,(unsigned int) pdb_info.modify_time);
(void) WriteBlobMSBLong(image,(unsigned int) pdb_info.archive_time);
(void) WriteBlobMSBLong(image,(unsigned int) pdb_info.modify_number);
(void) WriteBlobMSBLong(image,(unsigned int) pdb_info.application_info);
(void) WriteBlobMSBLong(image,(unsigned int) pdb_info.sort_info);
(void) WriteBlob(image,4,(unsigned char *) pdb_info.type);
(void) WriteBlob(image,4,(unsigned char *) pdb_info.id);
(void) WriteBlobMSBLong(image,(unsigned int) pdb_info.seed);
(void) WriteBlobMSBLong(image,(unsigned int) pdb_info.next_record);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_info.number_records);
(void) CopyMagickString(pdb_image.name,pdb_info.name,32);
pdb_image.version=1; /* RLE Compressed */
switch (bits_per_pixel)
{
case 1: pdb_image.type=(char) 0xff; break; /* monochrome */
case 2: pdb_image.type=(char) 0x00; break; /* 2 bit gray */
default: pdb_image.type=(char) 0x02; /* 4 bit gray */
}
pdb_image.reserved_1=0;
pdb_image.note=0;
pdb_image.x_last=0;
pdb_image.y_last=0;
pdb_image.reserved_2=0;
pdb_image.x_anchor=(short) 0xffff;
pdb_image.y_anchor=(short) 0xffff;
pdb_image.width=(short) image->columns;
if (image->columns % 16)
pdb_image.width=(short) (16*(image->columns/16+1));
pdb_image.height=(short) image->rows;
packets=(bits_per_pixel*image->columns/8)*image->rows;
runlength=(unsigned char *) AcquireQuantumMemory(2UL*packets,
sizeof(*runlength));
if (runlength == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
buffer=(unsigned char *) AcquireQuantumMemory(256UL,sizeof(*buffer));
if (buffer == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
packet_size=(size_t) (image->depth > 8 ? 2: 1);
scanline=(unsigned char *) AcquireQuantumMemory(image->columns,packet_size*
sizeof(*scanline));
if (scanline == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
/*
Convert to GRAY raster scanline.
*/
quantum_info=AcquireQuantumInfo(image_info,image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
bits=8/(int) bits_per_pixel-1; /* start at most significant bits */
literal=0;
repeat=0;
q=runlength;
buffer[0]=0x00;
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;
(void) ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
GrayQuantum,scanline,&image->exception);
for (x=0; x < pdb_image.width; x++)
{
if (x < (ssize_t) image->columns)
buffer[literal+repeat]|=(0xff-scanline[x*packet_size]) >>
(8-bits_per_pixel) << bits*bits_per_pixel;
bits--;
if (bits < 0)
{
if (((literal+repeat) > 0) &&
(buffer[literal+repeat] == buffer[literal+repeat-1]))
{
if (repeat == 0)
{
literal--;
repeat++;
}
repeat++;
if (0x7f < repeat)
{
q=EncodeRLE(q,buffer,literal,repeat);
literal=0;
repeat=0;
}
}
else
{
if (repeat >= 2)
literal+=repeat;
else
{
q=EncodeRLE(q,buffer,literal,repeat);
buffer[0]=buffer[literal+repeat];
literal=0;
}
literal++;
repeat=0;
if (0x7f < literal)
{
q=EncodeRLE(q,buffer,(literal < 0x80 ? literal : 0x80),0);
(void) CopyMagickMemory(buffer,buffer+literal+repeat,0x80);
literal-=0x80;
}
}
bits=8/(int) bits_per_pixel-1;
buffer[literal+repeat]=0x00;
}
}
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
q=EncodeRLE(q,buffer,literal,repeat);
scanline=(unsigned char *) RelinquishMagickMemory(scanline);
buffer=(unsigned char *) RelinquishMagickMemory(buffer);
quantum_info=DestroyQuantumInfo(quantum_info);
/*
Write the Image record header.
*/
(void) WriteBlobMSBLong(image,(unsigned int)
(TellBlob(image)+8*pdb_info.number_records));
(void) WriteBlobByte(image,0x40);
(void) WriteBlobByte(image,0x6f);
(void) WriteBlobByte(image,0x80);
(void) WriteBlobByte(image,0);
if (pdb_info.number_records > 1)
{
/*
Write the comment record header.
*/
(void) WriteBlobMSBLong(image,(unsigned int) (TellBlob(image)+8+58+q-
runlength));
(void) WriteBlobByte(image,0x40);
(void) WriteBlobByte(image,0x6f);
(void) WriteBlobByte(image,0x80);
(void) WriteBlobByte(image,1);
}
/*
Write the Image data.
*/
(void) WriteBlob(image,32,(unsigned char *) pdb_image.name);
(void) WriteBlobByte(image,(unsigned char) pdb_image.version);
(void) WriteBlobByte(image,(unsigned char) pdb_image.type);
(void) WriteBlobMSBLong(image,(unsigned int) pdb_image.reserved_1);
(void) WriteBlobMSBLong(image,(unsigned int) pdb_image.note);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_image.x_last);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_image.y_last);
(void) WriteBlobMSBLong(image,(unsigned int) pdb_image.reserved_2);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_image.x_anchor);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_image.y_anchor);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_image.width);
(void) WriteBlobMSBShort(image,(unsigned short) pdb_image.height);
(void) WriteBlob(image,(size_t) (q-runlength),runlength);
runlength=(unsigned char *) RelinquishMagickMemory(runlength);
if (pdb_info.number_records > 1)
(void) WriteBlobString(image,comment);
(void) CloseBlob(image);
return(MagickTrue);
}

2598
ImageMagick/coders/pdf.c Normal file

File diff suppressed because it is too large Load diff

732
ImageMagick/coders/pes.c Normal file
View file

@ -0,0 +1,732 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% PPPP EEEEE SSSSS %
% P P E SS %
% PPPP EEE SSS %
% P E SS %
% P EEEEE SSSSS %
% %
% %
% Read/Write Brother PES Image Format %
% %
% Software Design %
% John Cristy %
% July 2009 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% The PES format was derived from Robert Heel's PHP script (see
% http://bobosch.dyndns.org/embroidery/showFile.php?pes.php) and pesconvert
% (see http://torvalds-family.blogspot.com/2010/01/embroidery-gaah.html).
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/property.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/client.h"
#include "magick/colorspace.h"
#include "magick/constitute.h"
#include "magick/decorate.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/gem.h"
#include "magick/geometry.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/montage.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/resize.h"
#include "magick/shear.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/resource_.h"
#include "magick/transform.h"
#include "magick/utility.h"
/*
Typedef declarations.
*/
typedef struct _PESColorInfo
{
const unsigned char
red,
green,
blue,
alpha;
} PESColorInfo;
typedef struct _PESBlockInfo
{
const PESColorInfo
*color;
ssize_t
offset;
} PESBlockInfo;
/*
PES Colors.
*/
static const PESColorInfo
PESColor[256] =
{
{ 0, 0, 0, 1 },
{ 14, 31, 124, 1 },
{ 10, 85, 163, 1 },
{ 48, 135, 119, 1 },
{ 75, 107, 175, 1 },
{ 237, 23, 31, 1 },
{ 209, 92, 0, 1 },
{ 145, 54, 151, 1 },
{ 228, 154, 203, 1 },
{ 145, 95, 172, 1 },
{ 157, 214, 125, 1 },
{ 232, 169, 0, 1 },
{ 254, 186, 53, 1 },
{ 255, 255, 0, 1 },
{ 112, 188, 31, 1 },
{ 192, 148, 0, 1 },
{ 168, 168, 168, 1 },
{ 123, 111, 0, 1 },
{ 255, 255, 179, 1 },
{ 79, 85, 86, 1 },
{ 0, 0, 0, 1 },
{ 11, 61, 145, 1 },
{ 119, 1, 118, 1 },
{ 41, 49, 51, 1 },
{ 42, 19, 1, 1 },
{ 246, 74, 138, 1 },
{ 178, 118, 36, 1 },
{ 252, 187, 196, 1 },
{ 254, 55, 15, 1 },
{ 240, 240, 240, 1 },
{ 106, 28, 138, 1 },
{ 168, 221, 196, 1 },
{ 37, 132, 187, 1 },
{ 254, 179, 67, 1 },
{ 255, 240, 141, 1 },
{ 208, 166, 96, 1 },
{ 209, 84, 0, 1 },
{ 102, 186, 73, 1 },
{ 19, 74, 70, 1 },
{ 135, 135, 135, 1 },
{ 216, 202, 198, 1 },
{ 67, 86, 7, 1 },
{ 254, 227, 197, 1 },
{ 249, 147, 188, 1 },
{ 0, 56, 34, 1 },
{ 178, 175, 212, 1 },
{ 104, 106, 176, 1 },
{ 239, 227, 185, 1 },
{ 247, 56, 102, 1 },
{ 181, 76, 100, 1 },
{ 19, 43, 26, 1 },
{ 199, 1, 85, 1 },
{ 254, 158, 50, 1 },
{ 168, 222, 235, 1 },
{ 0, 103, 26, 1 },
{ 78, 41, 144, 1 },
{ 47, 126, 32, 1 },
{ 253, 217, 222, 1 },
{ 255, 217, 17, 1 },
{ 9, 91, 166, 1 },
{ 240, 249, 112, 1 },
{ 227, 243, 91, 1 },
{ 255, 200, 100, 1 },
{ 255, 200, 150, 1 },
{ 255, 200, 200, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 1 }
};
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s P E S %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsPES() returns MagickTrue if the image format type, identified by the
% magick string, is PES.
%
% The format of the IsPES method is:
%
% MagickBooleanType IsPES(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsPES(const unsigned char *magick,const size_t length)
{
if (length < 4)
return(MagickFalse);
if (LocaleNCompare((const char *) magick,"#PES",4) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d P E S I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadPESImage() reads a Brother PES 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 ReadPESImage method is:
%
% image=ReadPESImage(image_info)
%
% A description of each parameter follows:
%
% o image_info: the image info.
%
% o exception: return any errors or warnings in this structure.
%
*/
static Image *ReadPESImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
char
filename[MaxTextExtent];
FILE
*file;
Image
*image;
ImageInfo
*read_info;
int
delta_x,
delta_y,
j,
unique_file,
x,
y;
MagickBooleanType
status;
PESBlockInfo
blocks[256];
PointInfo
*stitches;
SegmentInfo
bounds;
register ssize_t
i;
size_t
number_blocks,
number_colors,
number_stitches;
ssize_t
count,
offset;
unsigned char
magick[4],
version[4];
/*
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);
}
/*
Verify PES identifier.
*/
count=ReadBlob(image,4,magick);
if ((count != 4) || (LocaleNCompare((char *) magick,"#PES",4) != 0))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
count=ReadBlob(image,4,version);
offset=(int) ReadBlobLSBLong(image);
if (DiscardBlobBytes(image,offset+36) == MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
if (EOFBlob(image) != MagickFalse)
ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
/*
Get PES colors.
*/
number_colors=(size_t) ReadBlobByte(image)+1;
for (i=0; i < (ssize_t) number_colors; i++)
{
j=(int) ReadBlobByte(image);
blocks[i].color=PESColor+j;
blocks[i].offset=0;
}
for ( ; i < 256L; i++)
blocks[i].offset=0;
if (DiscardBlobBytes(image,532L-number_colors-21) == MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
if (EOFBlob(image) != MagickFalse)
ThrowReaderException(CorruptImageError,"UnexpectedEndOfFile");
/*
Stitch away.
*/
number_stitches=64;
stitches=(PointInfo *) AcquireQuantumMemory(number_stitches,
sizeof(*stitches));
if (stitches == (PointInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
bounds.x1=65535.0;
bounds.y1=65535.0;
bounds.x2=(-65535.0);
bounds.y2=(-65535.0);
i=0;
j=0;
delta_x=0;
delta_y=0;
while (EOFBlob(image) != EOF)
{
x=(int) ReadBlobByte(image);
y=(int) ReadBlobByte(image);
if ((x == 0xff) && (y == 0))
break;
if ((x == 254) && (y == 176))
{
/*
Start a new stitch block.
*/
j++;
blocks[j].offset=(ssize_t) i;
if (j >= 256)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
(void) ReadBlobByte(image);
continue;
}
if ((x & 0x80) == 0)
{
/*
Normal stitch.
*/
if ((x & 0x40) != 0)
x-=0x80;
}
else
{
/*
Jump stitch.
*/
x=((x & 0x0f) << 8)+y;
if ((x & 0x800) != 0)
x-=0x1000;
y=ReadBlobByte(image);
}
if ((y & 0x80) == 0)
{
/*
Normal stitch.
*/
if ((y & 0x40) != 0)
y-=0x80;
}
else
{
/*
Jump stitch.
*/
y=((y & 0x0f) << 8)+ReadBlobByte(image);
if ((y & 0x800) != 0)
y-=0x1000;
}
/*
Note stitch (x,y).
*/
x+=delta_x;
y+=delta_y;
delta_x=x;
delta_y=y;
stitches[i].x=(double) x;
stitches[i].y=(double) y;
if ((double) x < bounds.x1)
bounds.x1=(double) x;
if ((double) x > bounds.x2)
bounds.x2=(double) x;
if ((double) y < bounds.y1)
bounds.y1=(double) y;
if ((double) y > bounds.y2)
bounds.y2=(double) y;
i++;
if (i >= (ssize_t) number_stitches)
{
/*
Make room for more stitches.
*/
number_stitches<<=1;
stitches=(PointInfo *) ResizeQuantumMemory(stitches,(size_t)
number_stitches,sizeof(*stitches));
if (stitches == (PointInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
}
j++;
blocks[j].offset=(ssize_t) i;
number_blocks=(size_t) j;
/*
Write stitches as SVG file.
*/
file=(FILE *) NULL;
unique_file=AcquireUniqueFileResource(filename);
if (unique_file != -1)
file=fdopen(unique_file,"wb");
if ((unique_file == -1) || (file == (FILE *) NULL))
ThrowImageException(FileOpenError,"UnableToCreateTemporaryFile");
(void) FormatLocaleFile(file,"<?xml version=\"1.0\"?>\n");
(void) FormatLocaleFile(file,"<svg xmlns=\"http://www.w3.org/2000/svg\" "
"xlink=\"http://www.w3.org/1999/xlink\" "
"ev=\"http://www.w3.org/2001/xml-events\" version=\"1.1\" "
"baseProfile=\"full\" width=\"%g\" height=\"%g\">\n",bounds.x2-bounds.x1,
bounds.y2-bounds.y1);
for (i=0; i < (ssize_t) number_blocks; i++)
{
offset=blocks[i].offset;
(void) FormatLocaleFile(file," <path stroke=\"#%02x%02x%02x\" "
"fill=\"none\" d=\"M %g %g",blocks[i].color->red,blocks[i].color->green,
blocks[i].color->blue,stitches[offset].x-bounds.x1,
stitches[offset].y-bounds.y1);
for (j=1; j < (ssize_t) (blocks[i+1].offset-offset); j++)
(void) FormatLocaleFile(file," L %g %g",stitches[offset+j].x-bounds.x1,
stitches[offset+j].y-bounds.y1);
(void) FormatLocaleFile(file,"\"/>\n");
}
(void) FormatLocaleFile(file,"</svg>\n");
(void) fclose(file);
(void) CloseBlob(image);
image=DestroyImage(image);
/*
Read SVG file.
*/
read_info=CloneImageInfo(image_info);
SetImageInfoBlob(read_info,(void *) NULL,0);
(void) FormatLocaleString(read_info->filename,MaxTextExtent,"svg:%s",
filename);
image=ReadImage(read_info,exception);
if (image != (Image *) NULL)
{
(void) CopyMagickString(image->filename,image_info->filename,
MaxTextExtent);
(void) CopyMagickString(image->magick_filename,image_info->filename,
MaxTextExtent);
(void) CopyMagickString(image->magick,"PES",MaxTextExtent);
}
read_info=DestroyImageInfo(read_info);
(void) RelinquishUniqueFileResource(filename);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r P E S I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterPESImage() adds attributes for the PES image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterPESImage method is:
%
% size_t RegisterPESImage(void)
%
*/
ModuleExport size_t RegisterPESImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("PES");
entry->decoder=(DecodeImageHandler *) ReadPESImage;
entry->magick=(IsImageFormatHandler *) IsPES;
entry->description=ConstantString("Embrid Embroidery Format");
entry->module=ConstantString("PES");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r P E S I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterPESImage() removes format registrations made by the
% PES module from the list of supported formats.
%
% The format of the UnregisterPESImage method is:
%
% UnregisterPESImage(void)
%
*/
ModuleExport void UnregisterPESImage(void)
{
(void) UnregisterMagickInfo("PES");
}

1985
ImageMagick/coders/pict.c Normal file

File diff suppressed because it is too large Load diff

311
ImageMagick/coders/pix.c Normal file
View file

@ -0,0 +1,311 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% PPPP IIIII X X %
% P P I X X %
% PPPP I X %
% P I X X %
% P IIIII X X %
% %
% %
% Read Alias/Wavefront RLE Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colormap.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d P I X I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadPIXImage() reads a Alias/Wavefront RLE 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 ReadPIXImage method is:
%
% Image *ReadPIXImage(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 *ReadPIXImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
Image
*image;
IndexPacket
index;
MagickBooleanType
status;
Quantum
blue,
green,
red;
register IndexPacket
*indexes;
register ssize_t
x;
register PixelPacket
*q;
size_t
bits_per_pixel,
height,
length,
width;
ssize_t
y;
/*
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);
}
/*
Read PIX image.
*/
width=ReadBlobMSBShort(image);
height=ReadBlobMSBShort(image);
(void) ReadBlobMSBShort(image); /* x-offset */
(void) ReadBlobMSBShort(image); /* y-offset */
bits_per_pixel=ReadBlobMSBShort(image);
if ((width == 0UL) || (height == 0UL) || ((bits_per_pixel != 8) &&
(bits_per_pixel != 24)))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
do
{
/*
Initialize image structure.
*/
image->columns=width;
image->rows=height;
if (bits_per_pixel == 8)
if (AcquireImageColormap(image,256) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
/*
Convert PIX raster image to pixel packets.
*/
red=(Quantum) 0;
green=(Quantum) 0;
blue=(Quantum) 0;
index=(IndexPacket) 0;
length=0;
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(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 (length == 0)
{
length=(size_t) ReadBlobByte(image);
if (bits_per_pixel == 8)
index=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
else
{
blue=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
green=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
red=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
}
}
if (image->storage_class == PseudoClass)
SetPixelIndex(indexes+x,index);
SetPixelBlue(q,blue);
SetPixelGreen(q,green);
SetPixelRed(q,red);
length--;
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
if (image->storage_class == PseudoClass)
(void) SyncImage(image);
if (EOFBlob(image) != MagickFalse)
{
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
break;
}
/*
Proceed to next image.
*/
if (image_info->number_scenes != 0)
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
width=ReadBlobMSBLong(image);
height=ReadBlobMSBLong(image);
(void) ReadBlobMSBShort(image);
(void) ReadBlobMSBShort(image);
bits_per_pixel=ReadBlobMSBShort(image);
status=(width != 0UL) && (height == 0UL) && ((bits_per_pixel == 8) ||
(bits_per_pixel == 24)) ? MagickTrue : MagickFalse;
if (status == MagickTrue)
{
/*
Allocate next image structure.
*/
AcquireNextImage(image_info,image);
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
image=SyncNextImageInList(image);
status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
GetBlobSize(image));
if (status == MagickFalse)
break;
}
} while (status == MagickTrue);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r P I X I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterPIXImage() adds attributes for the PIX image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterPIXImage method is:
%
% size_t RegisterPIXImage(void)
%
*/
ModuleExport size_t RegisterPIXImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("PIX");
entry->decoder=(DecodeImageHandler *) ReadPIXImage;
entry->description=ConstantString("Alias/Wavefront RLE image format");
entry->module=ConstantString("PIX");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r P I X I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterPIXImage() removes format registrations made by the
% PIX module from the list of supported formats.
%
% The format of the UnregisterPIXImage method is:
%
% UnregisterPIXImage(void)
%
*/
ModuleExport void UnregisterPIXImage(void)
{
(void) UnregisterMagickInfo("PIX");
}

293
ImageMagick/coders/plasma.c Normal file
View file

@ -0,0 +1,293 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% PPPP L AAA SSSSS M M AAA %
% P P L A A SS MM MM A A %
% PPPP L AAAAA SSS M M M AAAAA %
% P L A A SS M M A A %
% P LLLLL A A SSSSS M M A A %
% %
% %
% Read a Plasma Image. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/channel.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/fx.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/random_.h"
#include "magick/random-private.h"
#include "magick/signature-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d P L A S M A I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadPlasmaImage creates a plasma fractal image. The image is
% initialized to the X server color as specified by the filename.
%
% The format of the ReadPlasmaImage method is:
%
% Image *ReadPlasmaImage(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 inline size_t MagickMax(const size_t x,const size_t y)
{
if (x > y)
return(x);
return(y);
}
static inline void PlasmaPixel(Image *image,RandomInfo *random_info,double x,
double y)
{
ExceptionInfo
*exception;
register PixelPacket
*q;
exception=(&image->exception);
q=GetAuthenticPixels(image,(ssize_t) ceil(x-0.5),(ssize_t) ceil(y-0.5),1,1,
exception);
if (q == (PixelPacket *) NULL)
return;
SetPixelRed(q,ScaleShortToQuantum((unsigned short) (65535.0*
GetPseudoRandomValue(random_info)+0.5)));
SetPixelGreen(q,ScaleShortToQuantum((unsigned short) (65535.0*
GetPseudoRandomValue(random_info)+0.5)));
SetPixelBlue(q,ScaleShortToQuantum((unsigned short) (65535.0*
GetPseudoRandomValue(random_info)+0.5)));
(void) SyncAuthenticPixels(image,exception);
}
static Image *ReadPlasmaImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
Image
*image;
ImageInfo
*read_info;
MagickBooleanType
status;
register ssize_t
x;
register PixelPacket
*q;
register size_t
i;
SegmentInfo
segment_info;
size_t
depth,
max_depth;
ssize_t
y;
/*
Recursively apply plasma to the image.
*/
read_info=CloneImageInfo(image_info);
SetImageInfoBlob(read_info,(void *) NULL,0);
(void) FormatLocaleString(read_info->filename,MaxTextExtent,
"gradient:%s",image_info->filename);
image=ReadImage(read_info,exception);
read_info=DestroyImageInfo(read_info);
if (image == (Image *) NULL)
return((Image *) NULL);
image->storage_class=DirectClass;
for (y=0; y < (ssize_t) image->rows; y++)
{
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelOpacity(q,QuantumRange/2);
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
segment_info.x1=0;
segment_info.y1=0;
segment_info.x2=(double) image->columns-1;
segment_info.y2=(double) image->rows-1;
if (LocaleCompare(image_info->filename,"fractal") == 0)
{
RandomInfo
*random_info;
/*
Seed pixels before recursion.
*/
random_info=AcquireRandomInfo();
PlasmaPixel(image,random_info,segment_info.x1,segment_info.y1);
PlasmaPixel(image,random_info,segment_info.x1,(segment_info.y1+
segment_info.y2)/2);
PlasmaPixel(image,random_info,segment_info.x1,segment_info.y2);
PlasmaPixel(image,random_info,(segment_info.x1+segment_info.x2)/2,
segment_info.y1);
PlasmaPixel(image,random_info,(segment_info.x1+segment_info.x2)/2,
(segment_info.y1+segment_info.y2)/2);
PlasmaPixel(image,random_info,(segment_info.x1+segment_info.x2)/2,
segment_info.y2);
PlasmaPixel(image,random_info,segment_info.x2,segment_info.y1);
PlasmaPixel(image,random_info,segment_info.x2,(segment_info.y1+
segment_info.y2)/2);
PlasmaPixel(image,random_info,segment_info.x2,segment_info.y2);
random_info=DestroyRandomInfo(random_info);
}
i=(size_t) MagickMax(image->columns,image->rows)/2;
for (max_depth=0; i != 0; max_depth++)
i>>=1;
for (depth=1; ; depth++)
{
if (PlasmaImage(image,&segment_info,0,depth) != MagickFalse)
break;
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) depth,
max_depth);
if (status == MagickFalse)
break;
}
(void) SetImageAlphaChannel(image,SetAlphaChannel);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r P L A S M A I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterPLASMAImage() adds attributes for the Plasma image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterPLASMAImage method is:
%
% size_t RegisterPLASMAImage(void)
%
*/
ModuleExport size_t RegisterPLASMAImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("PLASMA");
entry->decoder=(DecodeImageHandler *) ReadPlasmaImage;
entry->adjoin=MagickFalse;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Plasma fractal image");
entry->module=ConstantString("PLASMA");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("FRACTAL");
entry->decoder=(DecodeImageHandler *) ReadPlasmaImage;
entry->adjoin=MagickFalse;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Plasma fractal image");
entry->module=ConstantString("PLASMA");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r P L A S M A I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterPLASMAImage() removes format registrations made by the
% PLASMA module from the list of supported formats.
%
% The format of the UnregisterPLASMAImage method is:
%
% UnregisterPLASMAImage(void)
%
*/
ModuleExport void UnregisterPLASMAImage(void)
{
(void) UnregisterMagickInfo("FRACTAL");
(void) UnregisterMagickInfo("PLASMA");
}

13471
ImageMagick/coders/png.c Normal file

File diff suppressed because it is too large Load diff

2217
ImageMagick/coders/pnm.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,199 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% PPPP RRRR EEEEE V V IIIII EEEEE W W %
% P P R R E V V I E W W %
% PPPP RRRR EEE V V I EEE W W %
% P R R E V V I E W W W %
% P R R EEEEE V IIIII EEEEE W W %
% %
% %
% Write A Preview Image. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/property.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/client.h"
#include "magick/constitute.h"
#include "magick/effect.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/resize.h"
#include "magick/resource_.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/transform.h"
#include "magick/utility.h"
/*
Forward declarations.
*/
static MagickBooleanType
WritePreviewImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r P R E V I E W I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterPREVIEWImage() adds attributes for the Preview image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterPREVIEWImage method is:
%
% size_t RegisterPREVIEWImage(void)
%
*/
ModuleExport size_t RegisterPREVIEWImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("PREVIEW");
entry->encoder=(EncodeImageHandler *) WritePreviewImage;
entry->adjoin=MagickFalse;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString(
"Show a preview an image enhancement, effect, or f/x");
entry->module=ConstantString("PREVIEW");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r P R E V I E W I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterPREVIEWImage() removes format registrations made by the
% PREVIEW module from the list of supported formats.
%
% The format of the UnregisterPREVIEWImage method is:
%
% UnregisterPREVIEWImage(void)
%
*/
ModuleExport void UnregisterPREVIEWImage(void)
{
(void) UnregisterMagickInfo("PREVIEW");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e P R E V I E W I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WritePreviewImage creates several tiles each with a varying
% stength of an image enhancement function (e.g. gamma). The image is written
% in the MIFF format.
%
% The format of the WritePreviewImage method is:
%
% MagickBooleanType WritePreviewImage(const ImageInfo *image_info,
% Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WritePreviewImage(const ImageInfo *image_info,
Image *image)
{
Image
*preview_image;
ImageInfo
*write_info;
MagickBooleanType
status;
/*
Open output image file.
*/
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);
preview_image=PreviewImage(image,image_info->preview_type,&image->exception);
if (preview_image == (Image *) NULL)
return(MagickFalse);
(void) CopyMagickString(preview_image->filename,image_info->filename,
MaxTextExtent);
write_info=CloneImageInfo(image_info);
(void) SetImageInfo(write_info,1,&image->exception);
if (LocaleCompare(write_info->magick,"PREVIEW") == 0)
(void) FormatLocaleString(preview_image->filename,MaxTextExtent,
"miff:%s",image_info->filename);
status=WriteImage(write_info,preview_image);
preview_image=DestroyImage(preview_image);
write_info=DestroyImageInfo(write_info);
return(status);
}

2178
ImageMagick/coders/ps.c Normal file

File diff suppressed because it is too large Load diff

1123
ImageMagick/coders/ps2.c Normal file

File diff suppressed because it is too large Load diff

1601
ImageMagick/coders/ps3.c Normal file

File diff suppressed because it is too large Load diff

2406
ImageMagick/coders/psd.c Normal file

File diff suppressed because it is too large Load diff

320
ImageMagick/coders/pwp.c Normal file
View file

@ -0,0 +1,320 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% PPPP W W PPPP %
% P P W W P P %
% PPPP W W PPPP %
% P W W W P %
% P W W P %
% %
% %
% Read Seattle Film Works Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/resource_.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s P W P %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsPWP() returns MagickTrue if the image format type, identified by the
% magick string, is PWP.
%
% The format of the IsPWP method is:
%
% MagickBooleanType IsPWP(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
%
*/
static MagickBooleanType IsPWP(const unsigned char *magick,const size_t length)
{
if (length < 5)
return(MagickFalse);
if (LocaleNCompare((char *) magick,"SFW95",5) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d P W P I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadPWPImage() reads a Seattle Film Works multi-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 ReadPWPImage method is:
%
% Image *ReadPWPImage(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 *ReadPWPImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
FILE
*file;
Image
*image,
*next_image,
*pwp_image;
ImageInfo
*read_info;
int
c,
unique_file;
MagickBooleanType
status;
register Image
*p;
register ssize_t
i;
size_t
filesize,
length;
ssize_t
count;
unsigned char
magick[MaxTextExtent];
/*
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));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r P W P I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterPWPImage() adds attributes for the PWP image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterPWPImage method is:
%
% size_t RegisterPWPImage(void)
%
*/
ModuleExport size_t RegisterPWPImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("PWP");
entry->decoder=(DecodeImageHandler *) ReadPWPImage;
entry->magick=(IsImageFormatHandler *) IsPWP;
entry->description=ConstantString("Seattle Film Works");
entry->module=ConstantString("PWP");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r P W P I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterPWPImage() removes format registrations made by the
% PWP module from the list of supported formats.
%
% The format of the UnregisterPWPImage method is:
%
% UnregisterPWPImage(void)
%
*/
ModuleExport void UnregisterPWPImage(void)
{
(void) UnregisterMagickInfo("PWP");
}

586
ImageMagick/coders/raw.c Normal file
View file

@ -0,0 +1,586 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% RRRR AAA W W %
% R R A A W W %
% RRRR AAAAA W W W %
% R R A A WW WW %
% R R A A W W %
% %
% %
% Read/Write RAW Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colorspace.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/statistic.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteRAWImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d R A W I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadRAWImage() reads an image of raw samples 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 ReadRAWImage method is:
%
% Image *ReadRAWImage(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 *ReadRAWImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
Image
*canvas_image,
*image;
MagickBooleanType
status;
MagickOffsetType
scene;
QuantumInfo
*quantum_info;
QuantumType
quantum_type;
size_t
length;
ssize_t
count,
y;
unsigned char
*pixels;
/*
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);
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(OptionError,"MustSpecifyImageSize");
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
if (DiscardBlobBytes(image,image->offset) == MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
/*
Create virtual canvas to support cropping (i.e. image.gray[100x100+10+20]).
*/
canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse,
exception);
(void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod);
quantum_type=GrayQuantum;
quantum_info=AcquireQuantumInfo(image_info,canvas_image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
pixels=GetQuantumPixels(quantum_info);
if (image_info->number_scenes != 0)
while (image->scene < image_info->scene)
{
/*
Skip to next image.
*/
image->scene++;
length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
for (y=0; y < (ssize_t) image->rows; y++)
{
count=ReadBlob(image,length,pixels);
if (count != (ssize_t) length)
break;
}
}
scene=0;
count=0;
length=0;
do
{
/*
Read pixels to virtual canvas image then push to image.
*/
if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
if (scene == 0)
{
length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
count=ReadBlob(image,length,pixels);
}
for (y=0; y < (ssize_t) image->extract_info.height; y++)
{
register const PixelPacket
*restrict p;
register PixelPacket
*restrict q;
register ssize_t
x;
if (count != (ssize_t) length)
{
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
break;
}
q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,quantum_info,
quantum_type,pixels,exception);
if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
break;
if (((y-image->extract_info.y) >= 0) &&
((y-image->extract_info.y) < (ssize_t) image->rows))
{
p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
image->columns,1,exception);
q=QueueAuthenticPixels(image,0,y-image->extract_info.y,image->columns,
1,exception);
if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelRed(q,GetPixelRed(p));
SetPixelGreen(q,GetPixelGreen(p));
SetPixelBlue(q,GetPixelBlue(p));
p++;
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
count=ReadBlob(image,length,pixels);
}
SetQuantumImageType(image,quantum_type);
/*
Proceed to next image.
*/
if (image_info->number_scenes != 0)
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
if (count == (ssize_t) length)
{
/*
Allocate next image structure.
*/
AcquireNextImage(image_info,image);
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
image=SyncNextImageInList(image);
status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
GetBlobSize(image));
if (status == MagickFalse)
break;
}
scene++;
} while (count == (ssize_t) length);
quantum_info=DestroyQuantumInfo(quantum_info);
InheritException(&image->exception,&canvas_image->exception);
canvas_image=DestroyImage(canvas_image);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r R A W I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterRAWImage() adds attributes for the RAW image format to the list of
% supported formats. The attributes include the image format tag, a method to
% read and/or write the format, whether the format supports the saving of
% more than one frame to the same file or blob, whether the format supports
% native in-memory I/O, and a brief description of the format.
%
% The format of the RegisterRAWImage method is:
%
% size_t RegisterRAWImage(void)
%
*/
ModuleExport size_t RegisterRAWImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("R");
entry->decoder=(DecodeImageHandler *) ReadRAWImage;
entry->encoder=(EncodeImageHandler *) WriteRAWImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->description=ConstantString("Raw red samples");
entry->module=ConstantString("RAW");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("C");
entry->decoder=(DecodeImageHandler *) ReadRAWImage;
entry->encoder=(EncodeImageHandler *) WriteRAWImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->description=ConstantString("Raw cyan samples");
entry->module=ConstantString("RAW");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("G");
entry->decoder=(DecodeImageHandler *) ReadRAWImage;
entry->encoder=(EncodeImageHandler *) WriteRAWImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->description=ConstantString("Raw green samples");
entry->module=ConstantString("RAW");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("M");
entry->decoder=(DecodeImageHandler *) ReadRAWImage;
entry->encoder=(EncodeImageHandler *) WriteRAWImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->description=ConstantString("Raw magenta samples");
entry->module=ConstantString("RAW");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("B");
entry->decoder=(DecodeImageHandler *) ReadRAWImage;
entry->encoder=(EncodeImageHandler *) WriteRAWImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->description=ConstantString("Raw blue samples");
entry->module=ConstantString("RAW");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("Y");
entry->decoder=(DecodeImageHandler *) ReadRAWImage;
entry->encoder=(EncodeImageHandler *) WriteRAWImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->description=ConstantString("Raw yellow samples");
entry->module=ConstantString("RAW");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("A");
entry->decoder=(DecodeImageHandler *) ReadRAWImage;
entry->encoder=(EncodeImageHandler *) WriteRAWImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->description=ConstantString("Raw alpha samples");
entry->module=ConstantString("RAW");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("O");
entry->decoder=(DecodeImageHandler *) ReadRAWImage;
entry->encoder=(EncodeImageHandler *) WriteRAWImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->description=ConstantString("Raw opacity samples");
entry->module=ConstantString("RAW");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("K");
entry->decoder=(DecodeImageHandler *) ReadRAWImage;
entry->encoder=(EncodeImageHandler *) WriteRAWImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->description=ConstantString("Raw black samples");
entry->module=ConstantString("RAW");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r R A W I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterRAWImage() removes format registrations made by the RAW module
% from the list of supported formats.
%
% The format of the UnregisterRAWImage method is:
%
% UnregisterRAWImage(void)
%
*/
ModuleExport void UnregisterRAWImage(void)
{
(void) UnregisterMagickInfo("R");
(void) UnregisterMagickInfo("C");
(void) UnregisterMagickInfo("G");
(void) UnregisterMagickInfo("M");
(void) UnregisterMagickInfo("B");
(void) UnregisterMagickInfo("Y");
(void) UnregisterMagickInfo("A");
(void) UnregisterMagickInfo("O");
(void) UnregisterMagickInfo("K");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e R A W I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteRAWImage() writes an image to a file as raw intensity values.
%
% The format of the WriteRAWImage method is:
%
% MagickBooleanType WriteRAWImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteRAWImage(const ImageInfo *image_info,Image *image)
{
MagickOffsetType
scene;
QuantumInfo
*quantum_info;
QuantumType
quantum_type;
MagickBooleanType
status;
register const PixelPacket
*p;
size_t
length;
ssize_t
count,
y;
unsigned char
*pixels;
/*
Open output image file.
*/
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);
switch (*image->magick)
{
case 'A':
case 'a':
{
quantum_type=AlphaQuantum;
break;
}
case 'B':
case 'b':
{
quantum_type=BlueQuantum;
break;
}
case 'C':
case 'c':
{
quantum_type=CyanQuantum;
if (image->colorspace == CMYKColorspace)
break;
ThrowWriterException(ImageError,"ColorSeparatedImageRequired");
}
case 'g':
case 'G':
{
quantum_type=GreenQuantum;
break;
}
case 'I':
case 'i':
{
quantum_type=IndexQuantum;
break;
}
case 'K':
case 'k':
{
quantum_type=BlackQuantum;
if (image->colorspace == CMYKColorspace)
break;
ThrowWriterException(ImageError,"ColorSeparatedImageRequired");
}
case 'M':
case 'm':
{
quantum_type=MagentaQuantum;
if (image->colorspace == CMYKColorspace)
break;
ThrowWriterException(ImageError,"ColorSeparatedImageRequired");
}
case 'o':
case 'O':
{
quantum_type=OpacityQuantum;
break;
}
case 'R':
case 'r':
{
quantum_type=RedQuantum;
break;
}
case 'Y':
case 'y':
{
quantum_type=YellowQuantum;
if (image->colorspace == CMYKColorspace)
break;
ThrowWriterException(ImageError,"ColorSeparatedImageRequired");
}
default:
{
quantum_type=GrayQuantum;
break;
}
}
scene=0;
do
{
/*
Convert image to RAW raster pixels.
*/
quantum_info=AcquireQuantumInfo(image_info,image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
pixels=GetQuantumPixels(quantum_info);
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;
length=ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info,
quantum_type,pixels,&image->exception);
count=WriteBlob(image,length,pixels);
if (count != (ssize_t) length)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
quantum_info=DestroyQuantumInfo(quantum_info);
if (GetNextImageInList(image) == (Image *) NULL)
break;
image=SyncNextImageInList(image);
status=SetImageProgress(image,SaveImagesTag,scene++,
GetImageListLength(image));
if (status == MagickFalse)
break;
} while (image_info->adjoin != MagickFalse);
(void) CloseBlob(image);
return(MagickTrue);
}

1447
ImageMagick/coders/rgb.c Normal file

File diff suppressed because it is too large Load diff

448
ImageMagick/coders/rla.c Normal file
View file

@ -0,0 +1,448 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% RRRR L AAA %
% R R L A A %
% RRRR L AAAAA %
% R R L A A %
% R R LLLLL A A %
% %
% %
% Read Alias/Wavefront Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/property.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d R L A I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadRLAImage() reads a run-length encoded Wavefront RLA image file
% and returns it. It allocates the memory necessary for the new Image
% structure and returns a pointer to the new image.
%
% Note: This module was contributed by Lester Vecsey (master@internexus.net).
%
% The format of the ReadRLAImage method is:
%
% Image *ReadRLAImage(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 *ReadRLAImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
typedef struct _WindowFrame
{
short
left,
right,
bottom,
top;
} WindowFrame;
typedef struct _RLAInfo
{
WindowFrame
window,
active_window;
short
frame,
storage_type,
number_channels,
number_matte_channels,
number_auxiliary_channels,
revision;
char
gamma[16],
red_primary[24],
green_primary[24],
blue_primary[24],
white_point[24];
ssize_t
job_number;
char
name[128],
description[128],
program[64],
machine[32],
user[32],
date[20],
aspect[24],
aspect_ratio[8],
chan[32];
short
field;
char
time[12],
filter[32];
short
bits_per_channel,
matte_type,
matte_bits,
auxiliary_type,
auxiliary_bits;
char
auxiliary[32],
space[36];
ssize_t
next;
} RLAInfo;
Image
*image;
int
channel,
length,
runlength;
MagickBooleanType
status;
MagickOffsetType
offset;
register ssize_t
i,
x;
register PixelPacket
*q;
ssize_t
count,
*scanlines,
y;
RLAInfo
rla_info;
unsigned char
byte;
/*
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);
}
rla_info.window.left=(short) ReadBlobMSBShort(image);
rla_info.window.right=(short) ReadBlobMSBShort(image);
rla_info.window.bottom=(short) ReadBlobMSBShort(image);
rla_info.window.top=(short) ReadBlobMSBShort(image);
rla_info.active_window.left=(short) ReadBlobMSBShort(image);
rla_info.active_window.right=(short) ReadBlobMSBShort(image);
rla_info.active_window.bottom=(short) ReadBlobMSBShort(image);
rla_info.active_window.top=(short) ReadBlobMSBShort(image);
rla_info.frame=(short) ReadBlobMSBShort(image);
rla_info.storage_type=(short) ReadBlobMSBShort(image);
rla_info.number_channels=(short) ReadBlobMSBShort(image);
rla_info.number_matte_channels=(short) ReadBlobMSBShort(image);
if (rla_info.number_channels == 0)
rla_info.number_channels=3;
rla_info.number_channels+=rla_info.number_matte_channels;
rla_info.number_auxiliary_channels=(short) ReadBlobMSBShort(image);
rla_info.revision=(short) ReadBlobMSBShort(image);
count=ReadBlob(image,16,(unsigned char *) rla_info.gamma);
count=ReadBlob(image,24,(unsigned char *) rla_info.red_primary);
count=ReadBlob(image,24,(unsigned char *) rla_info.green_primary);
count=ReadBlob(image,24,(unsigned char *) rla_info.blue_primary);
count=ReadBlob(image,24,(unsigned char *) rla_info.white_point);
rla_info.job_number=(int) ReadBlobMSBLong(image);
count=ReadBlob(image,128,(unsigned char *) rla_info.name);
count=ReadBlob(image,128,(unsigned char *) rla_info.description);
count=ReadBlob(image,64,(unsigned char *) rla_info.program);
count=ReadBlob(image,32,(unsigned char *) rla_info.machine);
count=ReadBlob(image,32,(unsigned char *) rla_info.user);
count=ReadBlob(image,20,(unsigned char *) rla_info.date);
count=ReadBlob(image,24,(unsigned char *) rla_info.aspect);
count=ReadBlob(image,8,(unsigned char *) rla_info.aspect_ratio);
count=ReadBlob(image,32,(unsigned char *) rla_info.chan);
rla_info.field=(short) ReadBlobMSBShort(image);
count=ReadBlob(image,12,(unsigned char *) rla_info.time);
count=ReadBlob(image,32,(unsigned char *) rla_info.filter);
rla_info.bits_per_channel=(short) ReadBlobMSBShort(image);
rla_info.matte_type=(short) ReadBlobMSBShort(image);
rla_info.matte_bits=(short) ReadBlobMSBShort(image);
rla_info.auxiliary_type=(short) ReadBlobMSBShort(image);
rla_info.auxiliary_bits=(short) ReadBlobMSBShort(image);
count=ReadBlob(image,32,(unsigned char *) rla_info.auxiliary);
count=ReadBlob(image,36,(unsigned char *) rla_info.space);
if ((size_t) count != 36)
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
rla_info.next=(int) ReadBlobMSBLong(image);
/*
Initialize image structure.
*/
image->matte=rla_info.number_matte_channels != 0 ? MagickTrue : MagickFalse;
image->columns=1UL*rla_info.active_window.right-rla_info.active_window.left+1;
image->rows=1UL*rla_info.active_window.top-rla_info.active_window.bottom+1;
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
scanlines=(ssize_t *) AcquireQuantumMemory(image->rows,sizeof(*scanlines));
if (scanlines == (ssize_t *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
if (*rla_info.description != '\0')
(void) SetImageProperty(image,"comment",rla_info.description);
/*
Read offsets to each scanline data.
*/
for (i=0; i < (ssize_t) image->rows; i++)
scanlines[i]=(int) ReadBlobMSBLong(image);
/*
Read image data.
*/
x=0;
for (y=0; y < (ssize_t) image->rows; y++)
{
offset=SeekBlob(image,scanlines[image->rows-y-1],SEEK_SET);
if (offset < 0)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
for (channel=0; channel < (int) rla_info.number_channels; channel++)
{
length=(int) ReadBlobMSBShort(image);
while (length > 0)
{
byte=(unsigned char) ReadBlobByte(image);
runlength=byte;
if (byte > 127)
runlength=byte-256;
length--;
if (length == 0)
break;
if (runlength < 0)
{
while (runlength < 0)
{
q=GetAuthenticPixels(image,(ssize_t) (x % image->columns),
(ssize_t) (y % image->rows),1,1,exception);
if (q == (PixelPacket *) NULL)
break;
byte=(unsigned char) ReadBlobByte(image);
length--;
switch (channel)
{
case 0:
{
SetPixelRed(q,ScaleCharToQuantum(byte));
break;
}
case 1:
{
SetPixelGreen(q,ScaleCharToQuantum(byte));
break;
}
case 2:
{
SetPixelBlue(q,ScaleCharToQuantum(byte));
break;
}
case 3:
default:
{
SetPixelAlpha(q,ScaleCharToQuantum(byte));
break;
}
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
x++;
runlength++;
}
continue;
}
byte=(unsigned char) ReadBlobByte(image);
length--;
runlength++;
do
{
q=GetAuthenticPixels(image,(ssize_t) (x % image->columns),
(ssize_t) (y % image->rows),1,1,exception);
if (q == (PixelPacket *) NULL)
break;
switch (channel)
{
case 0:
{
SetPixelRed(q,ScaleCharToQuantum(byte));
break;
}
case 1:
{
SetPixelGreen(q,ScaleCharToQuantum(byte));
break;
}
case 2:
{
SetPixelBlue(q,ScaleCharToQuantum(byte));
break;
}
case 3:
default:
{
SetPixelAlpha(q,ScaleCharToQuantum(byte));
break;
}
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
x++;
runlength--;
}
while (runlength > 0);
}
}
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r R L A I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterRLAImage() adds attributes for the RLA image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterRLAImage method is:
%
% size_t RegisterRLAImage(void)
%
*/
ModuleExport size_t RegisterRLAImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("RLA");
entry->decoder=(DecodeImageHandler *) ReadRLAImage;
entry->adjoin=MagickFalse;
entry->seekable_stream=MagickTrue;
entry->description=ConstantString("Alias/Wavefront image");
entry->module=ConstantString("RLA");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r R L A I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterRLAImage() removes format registrations made by the
% RLA module from the list of supported formats.
%
% The format of the UnregisterRLAImage method is:
%
% UnregisterRLAImage(void)
%
*/
ModuleExport void UnregisterRLAImage(void)
{
(void) UnregisterMagickInfo("RLA");
}

654
ImageMagick/coders/rle.c Normal file
View file

@ -0,0 +1,654 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% RRRR L EEEEE %
% R R L E %
% RRRR L EEE %
% R R L E %
% R R LLLLL EEEEE %
% %
% %
% Read URT RLE Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/property.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colormap.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/pixel.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s R L E %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsRLE() returns MagickTrue if the image format type, identified by the
% magick string, is RLE.
%
% The format of the ReadRLEImage method is:
%
% MagickBooleanType IsRLE(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
%
*/
static MagickBooleanType IsRLE(const unsigned char *magick,const size_t length)
{
if (length < 2)
return(MagickFalse);
if (memcmp(magick,"\122\314",2) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d R L E I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadRLEImage() reads a run-length encoded Utah Raster Toolkit
% 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 ReadRLEImage method is:
%
% Image *ReadRLEImage(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 *ReadRLEImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
#define SkipLinesOp 0x01
#define SetColorOp 0x02
#define SkipPixelsOp 0x03
#define ByteDataOp 0x05
#define RunDataOp 0x06
#define EOFOp 0x07
char
magick[12];
Image
*image;
int
opcode,
operand,
status;
MagickStatusType
flags;
MagickSizeType
number_pixels;
register IndexPacket
*indexes;
register ssize_t
x;
register PixelPacket
*q;
register ssize_t
i;
register unsigned char
*p;
size_t
bits_per_pixel,
map_length,
number_colormaps,
number_planes,
one;
ssize_t
count,
y;
unsigned char
background_color[256],
*colormap,
pixel,
plane,
*rle_pixels;
/*
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);
}
/*
Determine if this a RLE file.
*/
count=ReadBlob(image,2,(unsigned char *) magick);
if ((count == 0) || (memcmp(magick,"\122\314",2) != 0))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
do
{
/*
Read image header.
*/
(void) ReadBlobLSBShort(image);
(void) ReadBlobLSBShort(image);
image->columns=ReadBlobLSBShort(image);
image->rows=ReadBlobLSBShort(image);
flags=(MagickStatusType) ReadBlobByte(image);
image->matte=flags & 0x04 ? MagickTrue : MagickFalse;
number_planes=1UL*ReadBlobByte(image);
bits_per_pixel=1UL*ReadBlobByte(image);
number_colormaps=1UL*ReadBlobByte(image);
one=1;
map_length=one << ReadBlobByte(image);
if ((number_planes == 0) || (number_planes == 2) || (bits_per_pixel != 8) ||
(image->columns == 0))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
if (flags & 0x02)
{
/*
No background color-- initialize to black.
*/
for (i=0; i < (ssize_t) number_planes; i++)
background_color[i]=0;
(void) ReadBlobByte(image);
}
else
{
/*
Initialize background color.
*/
p=background_color;
for (i=0; i < (ssize_t) number_planes; i++)
*p++=(unsigned char) ReadBlobByte(image);
}
if ((number_planes & 0x01) == 0)
(void) ReadBlobByte(image);
colormap=(unsigned char *) NULL;
if (number_colormaps != 0)
{
/*
Read image colormaps.
*/
colormap=(unsigned char *) AcquireQuantumMemory(number_colormaps,
map_length*sizeof(*colormap));
if (colormap == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
p=colormap;
for (i=0; i < (ssize_t) number_colormaps; i++)
for (x=0; x < (ssize_t) map_length; x++)
*p++=(unsigned char) ScaleShortToQuantum(ReadBlobLSBShort(image));
}
if ((flags & 0x08) != 0)
{
char
*comment;
size_t
length;
/*
Read image comment.
*/
length=ReadBlobLSBShort(image);
if (length != 0)
{
comment=(char *) AcquireQuantumMemory(length,sizeof(*comment));
if (comment == (char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
count=ReadBlob(image,length-1,(unsigned char *) comment);
comment[length-1]='\0';
(void) SetImageProperty(image,"comment",comment);
comment=DestroyString(comment);
if ((length & 0x01) == 0)
(void) ReadBlobByte(image);
}
}
if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
/*
Allocate RLE pixels.
*/
if (image->matte != MagickFalse)
number_planes++;
number_pixels=(MagickSizeType) image->columns*image->rows;
if ((number_pixels*number_planes) != (size_t) (number_pixels*number_planes))
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
rle_pixels=(unsigned char *) AcquireQuantumMemory(image->columns,
image->rows*number_planes*sizeof(*rle_pixels));
if (rle_pixels == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
if ((flags & 0x01) && !(flags & 0x02))
{
ssize_t
j;
/*
Set background color.
*/
p=rle_pixels;
for (i=0; i < (ssize_t) number_pixels; i++)
{
if (image->matte == MagickFalse)
for (j=0; j < (ssize_t) number_planes; j++)
*p++=background_color[j];
else
{
for (j=0; j < (ssize_t) (number_planes-1); j++)
*p++=background_color[j];
*p++=0; /* initialize matte channel */
}
}
}
/*
Read runlength-encoded image.
*/
plane=0;
x=0;
y=0;
opcode=ReadBlobByte(image);
do
{
switch (opcode & 0x3f)
{
case SkipLinesOp:
{
operand=ReadBlobByte(image);
if (opcode & 0x40)
operand=(int) ReadBlobLSBShort(image);
x=0;
y+=operand;
break;
}
case SetColorOp:
{
operand=ReadBlobByte(image);
plane=(unsigned char) operand;
if (plane == 255)
plane=(unsigned char) (number_planes-1);
x=0;
break;
}
case SkipPixelsOp:
{
operand=ReadBlobByte(image);
if (opcode & 0x40)
operand=(int) ReadBlobLSBShort(image);
x+=operand;
break;
}
case ByteDataOp:
{
operand=ReadBlobByte(image);
if (opcode & 0x40)
operand=(int) ReadBlobLSBShort(image);
p=rle_pixels+((image->rows-y-1)*image->columns*number_planes)+
x*number_planes+plane;
operand++;
for (i=0; i < (ssize_t) operand; i++)
{
pixel=(unsigned char) ReadBlobByte(image);
if ((y < (ssize_t) image->rows) &&
((x+i) < (ssize_t) image->columns))
*p=pixel;
p+=number_planes;
}
if (operand & 0x01)
(void) ReadBlobByte(image);
x+=operand;
break;
}
case RunDataOp:
{
operand=ReadBlobByte(image);
if (opcode & 0x40)
operand=(int) ReadBlobLSBShort(image);
pixel=(unsigned char) ReadBlobByte(image);
(void) ReadBlobByte(image);
operand++;
p=rle_pixels+((image->rows-y-1)*image->columns*number_planes)+
x*number_planes+plane;
for (i=0; i < (ssize_t) operand; i++)
{
if ((y < (ssize_t) image->rows) &&
((x+i) < (ssize_t) image->columns))
*p=pixel;
p+=number_planes;
}
x+=operand;
break;
}
default:
break;
}
opcode=ReadBlobByte(image);
} while (((opcode & 0x3f) != EOFOp) && (opcode != EOF));
if (number_colormaps != 0)
{
MagickStatusType
mask;
/*
Apply colormap affineation to image.
*/
mask=(MagickStatusType) (map_length-1);
p=rle_pixels;
if (number_colormaps == 1)
for (i=0; i < (ssize_t) number_pixels; i++)
{
*p=colormap[*p & mask];
p++;
}
else
if ((number_planes >= 3) && (number_colormaps >= 3))
for (i=0; i < (ssize_t) number_pixels; i++)
for (x=0; x < (ssize_t) number_planes; x++)
{
*p=colormap[x*map_length+(*p & mask)];
p++;
}
}
/*
Initialize image structure.
*/
if (number_planes >= 3)
{
/*
Convert raster image to DirectClass pixel packets.
*/
p=rle_pixels;
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelRed(q,ScaleCharToQuantum(*p++));
SetPixelGreen(q,ScaleCharToQuantum(*p++));
SetPixelBlue(q,ScaleCharToQuantum(*p++));
if (image->matte != MagickFalse)
SetPixelAlpha(q,ScaleCharToQuantum(*p++));
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
}
else
{
/*
Create colormap.
*/
if (number_colormaps == 0)
map_length=256;
if (AcquireImageColormap(image,map_length) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
p=colormap;
if (number_colormaps == 1)
for (i=0; i < (ssize_t) image->colors; i++)
{
/*
Pseudocolor.
*/
image->colormap[i].red=ScaleCharToQuantum((unsigned char) i);
image->colormap[i].green=ScaleCharToQuantum((unsigned char) i);
image->colormap[i].blue=ScaleCharToQuantum((unsigned char) i);
}
else
if (number_colormaps > 1)
for (i=0; i < (ssize_t) image->colors; i++)
{
image->colormap[i].red=ScaleCharToQuantum(*p);
image->colormap[i].green=ScaleCharToQuantum(*(p+map_length));
image->colormap[i].blue=ScaleCharToQuantum(*(p+map_length*2));
p++;
}
p=rle_pixels;
if (image->matte == MagickFalse)
{
/*
Convert raster image to PseudoClass pixel packets.
*/
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < (ssize_t) image->columns; x++)
SetPixelIndex(indexes+x,*p++);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType)
y,image->rows);
if (status == MagickFalse)
break;
}
}
(void) SyncImage(image);
}
else
{
/*
Image has a matte channel-- promote to DirectClass.
*/
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelRed(q,image->colormap[*p++].red);
SetPixelGreen(q,image->colormap[*p++].green);
SetPixelBlue(q,image->colormap[*p++].blue);
SetPixelAlpha(q,ScaleCharToQuantum(*p++));
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType)
y,image->rows);
if (status == MagickFalse)
break;
}
}
image->colormap=(PixelPacket *) RelinquishMagickMemory(
image->colormap);
image->storage_class=DirectClass;
image->colors=0;
}
}
if (number_colormaps != 0)
colormap=(unsigned char *) RelinquishMagickMemory(colormap);
rle_pixels=(unsigned char *) RelinquishMagickMemory(rle_pixels);
if (EOFBlob(image) != MagickFalse)
{
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
break;
}
/*
Proceed to next image.
*/
if (image_info->number_scenes != 0)
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
(void) ReadBlobByte(image);
count=ReadBlob(image,2,(unsigned char *) magick);
if ((count != 0) && (memcmp(magick,"\122\314",2) == 0))
{
/*
Allocate next image structure.
*/
AcquireNextImage(image_info,image);
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
image=SyncNextImageInList(image);
status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
GetBlobSize(image));
if (status == MagickFalse)
break;
}
} while ((count != 0) && (memcmp(magick,"\122\314",2) == 0));
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r R L E I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterRLEImage() adds attributes for the RLE image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterRLEImage method is:
%
% size_t RegisterRLEImage(void)
%
*/
ModuleExport size_t RegisterRLEImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("RLE");
entry->decoder=(DecodeImageHandler *) ReadRLEImage;
entry->magick=(IsImageFormatHandler *) IsRLE;
entry->adjoin=MagickFalse;
entry->description=ConstantString("Utah Run length encoded image");
entry->module=ConstantString("RLE");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r R L E I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterRLEImage() removes format registrations made by the
% RLE module from the list of supported formats.
%
% The format of the UnregisterRLEImage method is:
%
% UnregisterRLEImage(void)
%
*/
ModuleExport void UnregisterRLEImage(void)
{
(void) UnregisterMagickInfo("RLE");
}

303
ImageMagick/coders/scr.c Normal file
View file

@ -0,0 +1,303 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% SSSSS CCCC RRRR %
% SS C R R %
% SSS C RRRR %
% SS C R R %
% SSSSS CCCC R R %
% %
% %
% Read ZX-Spectrum SCREEN$ Format %
% %
% Software Design %
% Catalin Mihaila %
% October 2003 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d S C R I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadSCRImage() reads a Scitex 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 ReadSCRImage method is:
%
% Image *ReadSCRImage(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 *ReadSCRImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
char zxscr[6144];
char zxattr[768];
int octetnr;
int octetline;
int zoneline;
int zonenr;
int octet_val;
int attr_nr;
int pix;
int piy;
int binar[8];
int attrbin[8];
int *pbin;
int *abin;
int z;
int one_nr;
int ink;
int paper;
int bright;
unsigned char colour_palette[] = {
0, 0, 0,
0, 0,192,
192, 0, 0,
192, 0,192,
0,192, 0,
0,192,192,
192,192, 0,
192,192,192,
0, 0, 0,
0, 0,255,
255, 0, 0,
255, 0,255,
0,255, 0,
0,255,255,
255,255, 0,
255,255,255
};
Image
*image;
MagickBooleanType
status;
register PixelPacket
*q;
ssize_t
count;
/*
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);
}
image->columns = 256;
image->rows = 192;
count=ReadBlob(image,6144,(unsigned char *) zxscr);
(void) count;
count=ReadBlob(image,768,(unsigned char *) zxattr);
for(zonenr=0;zonenr<3;zonenr++)
{
for(zoneline=0;zoneline<8;zoneline++)
{
for(octetline=0;octetline<8;octetline++)
{
for(octetnr=(zoneline*32);octetnr<((zoneline*32)+32);octetnr++)
{
octet_val = zxscr[octetnr+(256*octetline)+(zonenr*2048)];
attr_nr = zxattr[octetnr+(256*zonenr)];
pix = (((8*octetnr)-(256*zoneline)));
piy = ((octetline+(8*zoneline)+(zonenr*64)));
pbin = binar;
abin = attrbin;
one_nr=1;
for(z=0;z<8;z++)
{
if(octet_val&one_nr)
{
*pbin = 1;
} else {
*pbin = 0;
}
one_nr=one_nr*2;
pbin++;
}
one_nr = 1;
for(z=0;z<8;z++)
{
if(attr_nr&one_nr)
{
*abin = 1;
} else {
*abin = 0;
}
one_nr=one_nr*2;
abin++;
}
ink = (attrbin[0]+(2*attrbin[1])+(4*attrbin[2]));
paper = (attrbin[3]+(2*attrbin[4])+(4*attrbin[5]));
bright = attrbin[6];
if(bright) { ink=ink+8; paper=paper+8; }
for(z=7;z>-1;z--)
{
q=QueueAuthenticPixels(image,pix,piy,1,1,exception);
if(binar[z])
{
SetPixelRed(q,ScaleCharToQuantum(
colour_palette[3*ink]));
SetPixelGreen(q,ScaleCharToQuantum(
colour_palette[1+(3*ink)]));
SetPixelBlue(q,ScaleCharToQuantum(
colour_palette[2+(3*ink)]));
} else {
SetPixelRed(q,ScaleCharToQuantum(
colour_palette[3*paper]));
SetPixelGreen(q,ScaleCharToQuantum(
colour_palette[1+(3*paper)]));
SetPixelBlue(q,ScaleCharToQuantum(
colour_palette[2+(3*paper)]));
}
pix++;
}
}
}
}
}
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r S C R I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterSCRImage() adds attributes for the SCR image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterSCRImage method is:
%
% size_t RegisterSCRImage(void)
%
*/
ModuleExport size_t RegisterSCRImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("SCR");
entry->decoder=(DecodeImageHandler *) ReadSCRImage;
entry->adjoin=MagickFalse;
entry->description=ConstantString("ZX-Spectrum SCREEN$");
entry->module=ConstantString("SCR");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r S C R I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterSCRImage() removes format registrations made by the
% SCR module from the list of supported formats.
%
% The format of the UnregisterSCRImage method is:
%
% UnregisterSCRImage(void)
%
*/
ModuleExport void UnregisterSCRImage(void)
{
(void) UnregisterMagickInfo("SCR");
}

348
ImageMagick/coders/sct.c Normal file
View file

@ -0,0 +1,348 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% SSSSS CCCC TTTTT %
% SS C T %
% SSS C T %
% SS C T %
% SSSSS CCCC T %
% %
% %
% Read Scitex HandShake Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/module.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/string-private.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s S C T %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsSCT() returns MagickTrue if the image format type, identified by the
% magick string, is SCT.
%
% The format of the IsSCT method is:
%
% MagickBooleanType IsSCT(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsSCT(const unsigned char *magick,const size_t length)
{
if (length < 2)
return(MagickFalse);
if (LocaleNCompare((const char *) magick,"CT",2) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d S C T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadSCTImage() reads a Scitex 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 ReadSCTImage method is:
%
% Image *ReadSCTImage(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 *ReadSCTImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
char
magick[2];
Image
*image;
MagickBooleanType
status;
MagickRealType
height,
width;
Quantum
pixel;
register IndexPacket
*indexes;
register ssize_t
i,
x;
register PixelPacket
*q;
ssize_t
count,
y;
unsigned char
buffer[768];
size_t
separations,
separations_mask,
units;
/*
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);
}
/*
Read control block.
*/
count=ReadBlob(image,80,buffer);
(void) count;
count=ReadBlob(image,2,(unsigned char *) magick);
if ((LocaleNCompare((char *) magick,"CT",2) != 0) &&
(LocaleNCompare((char *) magick,"LW",2) != 0) &&
(LocaleNCompare((char *) magick,"BM",2) != 0) &&
(LocaleNCompare((char *) magick,"PG",2) != 0) &&
(LocaleNCompare((char *) magick,"TX",2) != 0))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
if ((LocaleNCompare((char *) magick,"LW",2) == 0) ||
(LocaleNCompare((char *) magick,"BM",2) == 0) ||
(LocaleNCompare((char *) magick,"PG",2) == 0) ||
(LocaleNCompare((char *) magick,"TX",2) == 0))
ThrowReaderException(CoderError,"OnlyContinuousTonePictureSupported");
count=ReadBlob(image,174,buffer);
count=ReadBlob(image,768,buffer);
/*
Read paramter block.
*/
units=1UL*ReadBlobByte(image);
if (units == 0)
image->units=PixelsPerCentimeterResolution;
separations=1UL*ReadBlobByte(image);
separations_mask=ReadBlobMSBShort(image);
count=ReadBlob(image,14,buffer);
buffer[14]='\0';
height=StringToDouble((char *) buffer,(char **) NULL);
count=ReadBlob(image,14,buffer);
width=StringToDouble((char *) buffer,(char **) NULL);
count=ReadBlob(image,12,buffer);
buffer[12]='\0';
image->rows=StringToUnsignedLong((char *) buffer);
count=ReadBlob(image,12,buffer);
image->columns=StringToUnsignedLong((char *) buffer);
count=ReadBlob(image,200,buffer);
count=ReadBlob(image,768,buffer);
if (separations_mask == 0x0f)
SetImageColorspace(image,CMYKColorspace);
image->x_resolution=1.0*image->columns/width;
image->y_resolution=1.0*image->rows/height;
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
Convert SCT raster image to pixel packets.
*/
for (y=0; y < (ssize_t) image->rows; y++)
{
for (i=0; i < (ssize_t) separations; i++)
{
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++)
{
pixel=(Quantum) ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
if (image->colorspace == CMYKColorspace)
pixel=(Quantum) (QuantumRange-pixel);
switch (i)
{
case 0:
{
SetPixelRed(q,pixel);
SetPixelGreen(q,pixel);
SetPixelBlue(q,pixel);
break;
}
case 1:
{
SetPixelGreen(q,pixel);
break;
}
case 2:
{
SetPixelBlue(q,pixel);
break;
}
case 3:
{
if (image->colorspace == CMYKColorspace)
SetPixelBlack(indexes+x,pixel);
break;
}
}
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if ((image->columns % 2) != 0)
(void) ReadBlobByte(image); /* pad */
}
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r S C T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterSCTImage() adds attributes for the SCT image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterSCTImage method is:
%
% size_t RegisterSCTImage(void)
%
*/
ModuleExport size_t RegisterSCTImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("SCT");
entry->decoder=(DecodeImageHandler *) ReadSCTImage;
entry->magick=(IsImageFormatHandler *) IsSCT;
entry->adjoin=MagickFalse;
entry->description=ConstantString("Scitex HandShake");
entry->module=ConstantString("SCT");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r S C T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterSCTImage() removes format registrations made by the
% SCT module from the list of supported formats.
%
% The format of the UnregisterSCTImage method is:
%
% UnregisterSCTImage(void)
%
*/
ModuleExport void UnregisterSCTImage(void)
{
(void) UnregisterMagickInfo("SCT");
}

433
ImageMagick/coders/sfw.c Normal file
View file

@ -0,0 +1,433 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% SSSSS FFFFF W W %
% SS F W W %
% SSS FFF W W %
% SS F W W W %
% SSSSS F W W %
% %
% %
% Read/Write ImageMagick Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/resource_.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
#include "magick/transform.h"
#include "magick/utility.h"
#include "magick/utility-private.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s S F W %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsSFW() returns MagickTrue if the image format type, identified by the
% magick string, is SFW.
%
% The format of the IsSFW method is:
%
% MagickBooleanType IsSFW(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsSFW(const unsigned char *magick,const size_t length)
{
if (length < 5)
return(MagickFalse);
if (LocaleNCompare((const char *) magick,"SFW94",5) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d S F W I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadSFWImage() reads a Seattle Film Works 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 ReadSFWImage method is:
%
% Image *ReadSFWImage(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 unsigned char *SFWScan(unsigned char *p,const unsigned char *q,
const unsigned char *target,const size_t length)
{
register ssize_t
i;
if ((p+length) < q)
while (p < q)
{
for (i=0; i < (ssize_t) length; i++)
if (p[i] != target[i])
break;
if (i == (ssize_t) length)
return((unsigned char *) p);
p++;
}
return((unsigned char *) NULL);
}
static void TranslateSFWMarker(unsigned char *marker)
{
switch (marker[1])
{
case 0xc8: marker[1]=0xd8; break; /* soi */
case 0xd0: marker[1]=0xe0; break; /* app */
case 0xcb: marker[1]=0xdb; break; /* dqt */
case 0xa0: marker[1]=0xc0; break; /* sof */
case 0xa4: marker[1]=0xc4; break; /* sof */
case 0xca: marker[1]=0xda; break; /* sos */
case 0xc9: marker[1]=0xd9; break; /* eoi */
default: break;
}
}
static Image *ReadSFWImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
static unsigned char
HuffmanTable[] =
{
0xFF, 0xC4, 0x01, 0xA2, 0x00, 0x00, 0x01, 0x05, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x10, 0x00, 0x02, 0x01,
0x03, 0x03, 0x02, 0x04, 0x03, 0x05, 0x05, 0x04, 0x04, 0x00, 0x00,
0x01, 0x7D, 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21,
0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32,
0x81, 0x91, 0xA1, 0x08, 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1,
0xF0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, 0x17, 0x18,
0x19, 0x1A, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x34, 0x35, 0x36,
0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64,
0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7A, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A,
0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3,
0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5,
0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9,
0xDA, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA,
0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0x11,
0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04,
0x04, 0x00, 0x01, 0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11, 0x04,
0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13,
0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xA1, 0xB1, 0xC1, 0x09,
0x23, 0x33, 0x52, 0xF0, 0x15, 0x62, 0x72, 0xD1, 0x0A, 0x16, 0x24,
0x34, 0xE1, 0x25, 0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26, 0x27, 0x28,
0x29, 0x2A, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45,
0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73,
0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x82, 0x83, 0x84, 0x85,
0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9,
0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2,
0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4,
0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6,
0xE7, 0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8,
0xF9, 0xFA
};
FILE
*file;
Image
*flipped_image,
*jpeg_image,
*image;
ImageInfo
*read_info;
int
unique_file;
MagickBooleanType
status;
register unsigned char
*header,
*data;
size_t
extent;
ssize_t
count;
unsigned char
*buffer,
*offset;
/*
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);
}
/*
Read image into a buffer.
*/
if (GetBlobSize(image) != (size_t) GetBlobSize(image))
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
buffer=(unsigned char *) AcquireQuantumMemory((size_t) GetBlobSize(image),
sizeof(*buffer));
if (buffer == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
count=ReadBlob(image,(size_t) GetBlobSize(image),buffer);
if ((count != (ssize_t) GetBlobSize(image)) ||
(LocaleNCompare((char *) buffer,"SFW",3) != 0))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
(void) CloseBlob(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+=(((unsigned int) offset[2]) << 8)+offset[3]+2;
for ( ; ; )
{
if ((offset+4) > (buffer+count-1))
{
buffer=(unsigned char *) RelinquishMagickMemory(buffer);
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
TranslateSFWMarker(offset);
if (offset[1] == 0xda)
break;
offset+=(((unsigned int) 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);
SetImageInfoBlob(read_info,(void *) NULL,0);
file=(FILE *) NULL;
unique_file=AcquireUniqueFileResource(read_info->filename);
if (unique_file != -1)
file=fopen_utf8(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);
(void) extent;
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_utf8(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.
*/
jpeg_image=ReadImage(read_info,exception);
(void) RelinquishUniqueFileResource(read_info->filename);
read_info=DestroyImageInfo(read_info);
if (jpeg_image == (Image *) NULL)
{
image=DestroyImageList(image);
return(jpeg_image);
}
(void) CopyMagickString(jpeg_image->filename,image->filename,MaxTextExtent);
(void) CopyMagickString(jpeg_image->magick,image->magick,MaxTextExtent);
image=DestroyImageList(image);
image=jpeg_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));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r S F W I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterSFWImage() adds attributes for the SFW image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterSFWImage method is:
%
% size_t RegisterSFWImage(void)
%
*/
ModuleExport size_t RegisterSFWImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("SFW");
entry->decoder=(DecodeImageHandler *) ReadSFWImage;
entry->magick=(IsImageFormatHandler *) IsSFW;
entry->adjoin=MagickFalse;
entry->description=ConstantString("Seattle Film Works");
entry->module=ConstantString("SFW");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r S F W I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterSFWImage() removes format registrations made by the
% SFW module from the list of supported formats.
%
% The format of the UnregisterSFWImage method is:
%
% UnregisterSFWImage(void)
%
*/
ModuleExport void UnregisterSFWImage(void)
{
(void) UnregisterMagickInfo("SFW");
}

1120
ImageMagick/coders/sgi.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,293 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% SSSSS TTTTT EEEEE GGGG AAA N N OOO %
% SS T E G A A NN N O O %
% SSS T EEE G GG AAAAA N N N O O %
% SS T E G G A A N NN O O %
% SSSSS T EEEEE GGG A A N N OOO %
% %
% %
% Write A Steganographic Image. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colormap.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d S T E G A N O I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadSTEGANOImage() reads a steganographic image hidden within another
% image type. It allocates the memory necessary for the new Image structure
% and returns a pointer to the new image.
%
% The format of the ReadSTEGANOImage method is:
%
% Image *ReadSTEGANOImage(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 inline size_t MagickMin(const size_t x,
const size_t y)
{
if (x < y)
return(x);
return(y);
}
static Image *ReadSTEGANOImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
#define GetBit(alpha,i) MagickMin((((size_t) (alpha) >> (size_t) \
(i)) & 0x01),16)
#define SetBit(indexes,i,set) SetPixelIndex(indexes,((set) != 0 ? \
(size_t) GetPixelIndex(indexes) | (one << (size_t) (i)) : (size_t) \
GetPixelIndex(indexes) & ~(one << (size_t) (i))))
Image
*image,
*watermark;
ImageInfo
*read_info;
int
c;
MagickBooleanType
status;
PixelPacket
pixel;
register IndexPacket
*indexes;
register PixelPacket
*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);
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) == 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) GetOneVirtualPixel(watermark,k % (ssize_t) watermark->columns,
k/(ssize_t) watermark->columns,&pixel,exception);
q=GetAuthenticPixels(image,x,y,1,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
switch (c)
{
case 0:
{
SetBit(indexes,i,GetBit(pixel.red,j));
break;
}
case 1:
{
SetBit(indexes,i,GetBit(pixel.green,j));
break;
}
case 2:
{
SetBit(indexes,i,GetBit(pixel.blue,j));
break;
}
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
c++;
if (c == 3)
c=0;
k++;
if (k == (ssize_t) (watermark->columns*watermark->columns))
k=0;
if (k == image->offset)
j++;
}
}
status=SetImageProgress(image,LoadImagesTag,(MagickOffsetType) i,depth);
if (status == MagickFalse)
break;
}
watermark=DestroyImage(watermark);
(void) SyncImage(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r S T E G A N O I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterSTEGANOImage() adds attributes for the STEGANO image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterSTEGANOImage method is:
%
% size_t RegisterSTEGANOImage(void)
%
*/
ModuleExport size_t RegisterSTEGANOImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("STEGANO");
entry->decoder=(DecodeImageHandler *) ReadSTEGANOImage;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Steganographic image");
entry->module=ConstantString("STEGANO");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r S T E G A N O I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterSTEGANOImage() removes format registrations made by the
% STEGANO module from the list of supported formats.
%
% The format of the UnregisterSTEGANOImage method is:
%
% UnregisterSTEGANOImage(void)
%
*/
ModuleExport void UnregisterSTEGANOImage(void)
{
(void) UnregisterMagickInfo("STEGANO");
}

974
ImageMagick/coders/sun.c Normal file
View file

@ -0,0 +1,974 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% SSSSS U U N N %
% SS U U NN N %
% SSS U U N N N %
% SS U U N NN %
% SSSSS UUU N N %
% %
% %
% Read/Write Sun Rasterfile Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#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/colormap.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteSUNImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s S U N %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsSUN() returns MagickTrue if the image format type, identified by the
% magick string, is SUN.
%
% The format of the IsSUN method is:
%
% MagickBooleanType IsSUN(const unsigned char *magick,const size_t length)
%
% A description of each parameter follows:
%
% o magick: compare image format pattern against these bytes.
%
% o length: Specifies the length of the magick string.
%
*/
static MagickBooleanType IsSUN(const unsigned char *magick,const size_t length)
{
if (length < 4)
return(MagickFalse);
if (memcmp(magick,"\131\246\152\225",4) == 0)
return(MagickTrue);
return(MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% D e c o d e I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DecodeImage unpacks the packed image pixels into runlength-encoded pixel
% packets.
%
% The format of the DecodeImage method is:
%
% MagickBooleanType DecodeImage(const unsigned char *compressed_pixels,
% const size_t length,unsigned char *pixels)
%
% A description of each parameter follows:
%
% o compressed_pixels: The address of a byte (8 bits) array of compressed
% pixel data.
%
% o length: An integer value that is the total number of bytes of the
% source image (as just read by ReadBlob)
%
% o pixels: The address of a byte (8 bits) array of pixel data created by
% the uncompression process. The number of bytes in this array
% must be at least equal to the number columns times the number of rows
% of the source pixels.
%
*/
static MagickBooleanType DecodeImage(const unsigned char *compressed_pixels,
const size_t length,unsigned char *pixels,size_t maxpixels)
{
register const unsigned char
*l,
*p;
register unsigned char
*q;
ssize_t
count;
unsigned char
byte;
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
assert(compressed_pixels != (unsigned char *) NULL);
assert(pixels != (unsigned char *) NULL);
p=compressed_pixels;
q=pixels;
l=q+maxpixels;
while (((size_t) (p-compressed_pixels) < length) && (q < l))
{
byte=(*p++);
if (byte != 128U)
*q++=byte;
else
{
/*
Runlength-encoded packet: <count><byte>
*/
count=(ssize_t) (*p++);
if (count > 0)
byte=(*p++);
while ((count >= 0) && (q < l))
{
*q++=byte;
count--;
}
}
}
return(MagickTrue);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d S U N I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadSUNImage() reads a SUN 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 ReadSUNImage method is:
%
% Image *ReadSUNImage(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 *ReadSUNImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
#define RMT_EQUAL_RGB 1
#define RMT_NONE 0
#define RMT_RAW 2
#define RT_STANDARD 1
#define RT_ENCODED 2
#define RT_FORMAT_RGB 3
typedef struct _SUNInfo
{
unsigned int
magic,
width,
height,
depth,
length,
type,
maptype,
maplength;
} SUNInfo;
Image
*image;
int
bit;
MagickBooleanType
status;
MagickSizeType
number_pixels;
register IndexPacket
*indexes;
register PixelPacket
*q;
register ssize_t
i,
x;
register unsigned char
*p;
size_t
length;
ssize_t
count,
y;
SUNInfo
sun_info;
unsigned char
*sun_data,
*sun_pixels;
unsigned int
bytes_per_line;
/*
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);
}
/*
Read SUN raster header.
*/
(void) ResetMagickMemory(&sun_info,0,sizeof(sun_info));
sun_info.magic=ReadBlobMSBLong(image);
do
{
/*
Verify SUN identifier.
*/
if (sun_info.magic != 0x59a66a95)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
sun_info.width=ReadBlobMSBLong(image);
sun_info.height=ReadBlobMSBLong(image);
sun_info.depth=ReadBlobMSBLong(image);
sun_info.length=ReadBlobMSBLong(image);
sun_info.type=ReadBlobMSBLong(image);
sun_info.maptype=ReadBlobMSBLong(image);
sun_info.maplength=ReadBlobMSBLong(image);
image->columns=sun_info.width;
image->rows=sun_info.height;
if ((sun_info.depth == 0) || (sun_info.depth > 32))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
image->depth=sun_info.depth <= 8 ? sun_info.depth :
MAGICKCORE_QUANTUM_DEPTH;
if (sun_info.depth < 24)
{
size_t
one;
image->storage_class=PseudoClass;
image->colors=sun_info.maplength;
one=1;
if (sun_info.maptype == RMT_NONE)
image->colors=one << sun_info.depth;
if (sun_info.maptype == RMT_EQUAL_RGB)
image->colors=sun_info.maplength/3;
}
switch (sun_info.maptype)
{
case RMT_NONE:
{
if (sun_info.depth < 24)
{
/*
Create linear color ramp.
*/
if (AcquireImageColormap(image,image->colors) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
break;
}
case RMT_EQUAL_RGB:
{
unsigned char
*sun_colormap;
/*
Read SUN raster colormap.
*/
if (AcquireImageColormap(image,image->colors) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
sun_colormap=(unsigned char *) AcquireQuantumMemory(image->colors,
sizeof(*sun_colormap));
if (sun_colormap == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
count=ReadBlob(image,image->colors,sun_colormap);
for (i=0; i < (ssize_t) image->colors; i++)
image->colormap[i].red=ScaleCharToQuantum(sun_colormap[i]);
count=ReadBlob(image,image->colors,sun_colormap);
for (i=0; i < (ssize_t) image->colors; i++)
image->colormap[i].green=ScaleCharToQuantum(sun_colormap[i]);
count=ReadBlob(image,image->colors,sun_colormap);
for (i=0; i < (ssize_t) image->colors; i++)
image->colormap[i].blue=ScaleCharToQuantum(sun_colormap[i]);
sun_colormap=(unsigned char *) RelinquishMagickMemory(sun_colormap);
break;
}
case RMT_RAW:
{
unsigned char
*sun_colormap;
/*
Read SUN raster colormap.
*/
sun_colormap=(unsigned char *) AcquireQuantumMemory(sun_info.maplength,
sizeof(*sun_colormap));
if (sun_colormap == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
count=ReadBlob(image,sun_info.maplength,sun_colormap);
sun_colormap=(unsigned char *) RelinquishMagickMemory(sun_colormap);
break;
}
default:
ThrowReaderException(CoderError,"ColormapTypeNotSupported");
}
image->matte=sun_info.depth == 32 ? MagickTrue : MagickFalse;
image->columns=sun_info.width;
image->rows=sun_info.height;
if (image_info->ping != MagickFalse)
{
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
if ((sun_info.length*sizeof(*sun_data))/sizeof(*sun_data) !=
sun_info.length || !sun_info.length)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
number_pixels=(MagickSizeType) image->columns*image->rows;
if ((sun_info.type != RT_ENCODED) && (sun_info.depth >= 8) &&
((number_pixels*((sun_info.depth+7)/8)) > sun_info.length))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
sun_data=(unsigned char *) AcquireQuantumMemory((size_t) sun_info.length,
sizeof(*sun_data));
if (sun_data == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
count=(ssize_t) ReadBlob(image,sun_info.length,sun_data);
if ((count == 0) && (sun_info.type != RT_ENCODED))
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
sun_pixels=sun_data;
bytes_per_line=0;
if (sun_info.type == RT_ENCODED)
{
size_t
height;
/*
Read run-length encoded raster pixels.
*/
height=sun_info.height;
bytes_per_line=sun_info.width*sun_info.depth;
if ((height == 0) || (sun_info.width == 0) || (sun_info.depth == 0) ||
((bytes_per_line/sun_info.depth) != sun_info.width))
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
bytes_per_line+=15;
bytes_per_line<<=1;
if ((bytes_per_line >> 1) != (sun_info.width*sun_info.depth+15))
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
bytes_per_line>>=4;
sun_pixels=(unsigned char *) AcquireQuantumMemory(height,
bytes_per_line*sizeof(*sun_pixels));
if (sun_pixels == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
(void) DecodeImage(sun_data,sun_info.length,sun_pixels,
bytes_per_line*height);
sun_data=(unsigned char *) RelinquishMagickMemory(sun_data);
}
/*
Convert SUN raster image to pixel packets.
*/
p=sun_pixels;
if (sun_info.depth == 1)
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < ((ssize_t) image->columns-7); x+=8)
{
for (bit=7; bit >= 0; bit--)
SetPixelIndex(indexes+x+7-bit,((*p) & (0x01 << bit) ?
0x00 : 0x01));
p++;
}
if ((image->columns % 8) != 0)
{
for (bit=7; bit >= (ssize_t) (8-(image->columns % 8)); bit--)
SetPixelIndex(indexes+x+7-bit,(*p) & (0x01 << bit) ?
0x00 : 0x01);
p++;
}
if ((((image->columns/8)+(image->columns % 8 ? 1 : 0)) % 2) != 0)
p++;
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
else
if (image->storage_class == PseudoClass)
{
length=image->rows*(image->columns+image->columns % 2);
if (((sun_info.type == RT_ENCODED) &&
(length > (bytes_per_line*image->rows))) ||
((sun_info.type != RT_ENCODED) && (length > sun_info.length)))
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < (ssize_t) image->columns; x++)
SetPixelIndex(indexes+x,*p++);
if ((image->columns % 2) != 0)
p++;
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
}
else
{
size_t
bytes_per_pixel;
bytes_per_pixel=3;
if (image->matte != MagickFalse)
bytes_per_pixel++;
length=image->rows*((bytes_per_line*image->columns)+
image->columns % 2);
if (((sun_info.type == RT_ENCODED) &&
(length > (bytes_per_line*image->rows))) ||
((sun_info.type != RT_ENCODED) && (length > sun_info.length)))
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
if (image->matte != MagickFalse)
SetPixelAlpha(q,ScaleCharToQuantum(*p++));
if (sun_info.type == RT_STANDARD)
{
SetPixelBlue(q,ScaleCharToQuantum(*p++));
SetPixelGreen(q,ScaleCharToQuantum(*p++));
SetPixelRed(q,ScaleCharToQuantum(*p++));
}
else
{
SetPixelRed(q,ScaleCharToQuantum(*p++));
SetPixelGreen(q,ScaleCharToQuantum(*p++));
SetPixelBlue(q,ScaleCharToQuantum(*p++));
}
if (image->colors != 0)
{
SetPixelRed(q,image->colormap[(ssize_t)
GetPixelRed(q)].red);
SetPixelGreen(q,image->colormap[(ssize_t)
GetPixelGreen(q)].green);
SetPixelBlue(q,image->colormap[(ssize_t)
GetPixelBlue(q)].blue);
}
q++;
}
if (((bytes_per_pixel*image->columns) % 2) != 0)
p++;
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
}
if (image->storage_class == PseudoClass)
(void) SyncImage(image);
sun_pixels=(unsigned char *) RelinquishMagickMemory(sun_pixels);
if (EOFBlob(image) != MagickFalse)
{
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
break;
}
/*
Proceed to next image.
*/
if (image_info->number_scenes != 0)
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
sun_info.magic=ReadBlobMSBLong(image);
if (sun_info.magic == 0x59a66a95)
{
/*
Allocate next image structure.
*/
AcquireNextImage(image_info,image);
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
image=SyncNextImageInList(image);
status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
GetBlobSize(image));
if (status == MagickFalse)
break;
}
} while (sun_info.magic == 0x59a66a95);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r S U N I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterSUNImage() adds attributes for the SUN image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterSUNImage method is:
%
% size_t RegisterSUNImage(void)
%
*/
ModuleExport size_t RegisterSUNImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("RAS");
entry->decoder=(DecodeImageHandler *) ReadSUNImage;
entry->encoder=(EncodeImageHandler *) WriteSUNImage;
entry->magick=(IsImageFormatHandler *) IsSUN;
entry->description=ConstantString("SUN Rasterfile");
entry->module=ConstantString("SUN");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("SUN");
entry->decoder=(DecodeImageHandler *) ReadSUNImage;
entry->encoder=(EncodeImageHandler *) WriteSUNImage;
entry->description=ConstantString("SUN Rasterfile");
entry->module=ConstantString("SUN");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r S U N I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterSUNImage() removes format registrations made by the
% SUN module from the list of supported formats.
%
% The format of the UnregisterSUNImage method is:
%
% UnregisterSUNImage(void)
%
*/
ModuleExport void UnregisterSUNImage(void)
{
(void) UnregisterMagickInfo("RAS");
(void) UnregisterMagickInfo("SUN");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e S U N I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteSUNImage() writes an image in the SUN rasterfile format.
%
% The format of the WriteSUNImage method is:
%
% MagickBooleanType WriteSUNImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteSUNImage(const ImageInfo *image_info,Image *image)
{
#define RMT_EQUAL_RGB 1
#define RMT_NONE 0
#define RMT_RAW 2
#define RT_STANDARD 1
#define RT_FORMAT_RGB 3
typedef struct _SUNInfo
{
unsigned int
magic,
width,
height,
depth,
length,
type,
maptype,
maplength;
} SUNInfo;
MagickBooleanType
status;
MagickOffsetType
scene;
MagickSizeType
number_pixels;
register const IndexPacket
*indexes;
register const PixelPacket
*p;
register ssize_t
i,
x;
ssize_t
y;
SUNInfo
sun_info;
/*
Open output image file.
*/
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);
scene=0;
do
{
/*
Initialize SUN raster file header.
*/
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
sun_info.magic=0x59a66a95;
if ((image->columns != (unsigned int) image->columns) ||
(image->rows != (unsigned int) image->rows))
ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
sun_info.width=(unsigned int) image->columns;
sun_info.height=(unsigned int) image->rows;
sun_info.type=(unsigned int) (image->storage_class == DirectClass ?
RT_FORMAT_RGB : RT_STANDARD);
sun_info.maptype=RMT_NONE;
sun_info.maplength=0;
number_pixels=(MagickSizeType) image->columns*image->rows;
if ((4*number_pixels) != (size_t) (4*number_pixels))
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
if (image->storage_class == DirectClass)
{
/*
Full color SUN raster.
*/
sun_info.depth=(unsigned int) image->matte ? 32U : 24U;
sun_info.length=(unsigned int) ((image->matte ? 4 : 3)*number_pixels);
sun_info.length+=sun_info.length & 0x01 ? (unsigned int) image->rows :
0;
}
else
if (IsMonochromeImage(image,&image->exception))
{
/*
Monochrome SUN raster.
*/
sun_info.depth=1;
sun_info.length=(unsigned int) (((image->columns+7) >> 3)*
image->rows);
sun_info.length+=(unsigned int) (((image->columns/8)+(image->columns %
8 ? 1 : 0)) % 2 ? image->rows : 0);
}
else
{
/*
Colormapped SUN raster.
*/
sun_info.depth=8;
sun_info.length=(unsigned int) number_pixels;
sun_info.length+=(unsigned int) (image->columns & 0x01 ? image->rows :
0);
sun_info.maptype=RMT_EQUAL_RGB;
sun_info.maplength=(unsigned int) (3*image->colors);
}
/*
Write SUN header.
*/
(void) WriteBlobMSBLong(image,sun_info.magic);
(void) WriteBlobMSBLong(image,sun_info.width);
(void) WriteBlobMSBLong(image,sun_info.height);
(void) WriteBlobMSBLong(image,sun_info.depth);
(void) WriteBlobMSBLong(image,sun_info.length);
(void) WriteBlobMSBLong(image,sun_info.type);
(void) WriteBlobMSBLong(image,sun_info.maptype);
(void) WriteBlobMSBLong(image,sun_info.maplength);
/*
Convert MIFF to SUN raster pixels.
*/
x=0;
y=0;
if (image->storage_class == DirectClass)
{
register unsigned char
*q;
size_t
bytes_per_pixel,
length;
unsigned char
*pixels;
/*
Allocate memory for pixels.
*/
bytes_per_pixel=3;
if (image->matte != MagickFalse)
bytes_per_pixel++;
length=image->columns;
pixels=(unsigned char *) AcquireQuantumMemory(length,4*sizeof(*pixels));
if (pixels == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
/*
Convert DirectClass packet to SUN RGB pixel.
*/
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;
q=pixels;
for (x=0; x < (ssize_t) image->columns; x++)
{
if (image->matte != MagickFalse)
*q++=ScaleQuantumToChar(GetPixelAlpha(p));
*q++=ScaleQuantumToChar(GetPixelRed(p));
*q++=ScaleQuantumToChar(GetPixelGreen(p));
*q++=ScaleQuantumToChar(GetPixelBlue(p));
p++;
}
if (((bytes_per_pixel*image->columns) & 0x01) != 0)
*q++='\0'; /* pad scanline */
(void) WriteBlob(image,(size_t) (q-pixels),pixels);
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
pixels=(unsigned char *) RelinquishMagickMemory(pixels);
}
else
if (IsMonochromeImage(image,&image->exception))
{
register unsigned char
bit,
byte;
/*
Convert PseudoClass image to a SUN monochrome image.
*/
(void) SetImageType(image,BilevelType);
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);
bit=0;
byte=0;
for (x=0; x < (ssize_t) image->columns; x++)
{
byte<<=1;
if (GetPixelIntensity(image,p) < (QuantumRange/2.0))
byte|=0x01;
bit++;
if (bit == 8)
{
(void) WriteBlobByte(image,byte);
bit=0;
byte=0;
}
p++;
}
if (bit != 0)
(void) WriteBlobByte(image,(unsigned char) (byte << (8-bit)));
if ((((image->columns/8)+
(image->columns % 8 ? 1 : 0)) % 2) != 0)
(void) WriteBlobByte(image,0); /* pad scanline */
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
}
else
{
/*
Dump colormap to file.
*/
for (i=0; i < (ssize_t) image->colors; i++)
(void) WriteBlobByte(image,ScaleQuantumToChar(
image->colormap[i].red));
for (i=0; i < (ssize_t) image->colors; i++)
(void) WriteBlobByte(image,ScaleQuantumToChar(
image->colormap[i].green));
for (i=0; i < (ssize_t) image->colors; i++)
(void) WriteBlobByte(image,ScaleQuantumToChar(
image->colormap[i].blue));
/*
Convert PseudoClass packet to SUN colormapped pixel.
*/
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);
for (x=0; x < (ssize_t) image->columns; x++)
{
(void) WriteBlobByte(image,(unsigned char)
GetPixelIndex(indexes+x));
p++;
}
if (image->columns & 0x01)
(void) WriteBlobByte(image,0); /* pad scanline */
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
}
if (GetNextImageInList(image) == (Image *) NULL)
break;
image=SyncNextImageInList(image);
status=SetImageProgress(image,SaveImagesTag,scene++,
GetImageListLength(image));
if (status == MagickFalse)
break;
} while (image_info->adjoin != MagickFalse);
(void) CloseBlob(image);
return(MagickTrue);
}

4612
ImageMagick/coders/svg.c Normal file

File diff suppressed because it is too large Load diff

838
ImageMagick/coders/tga.c Normal file
View file

@ -0,0 +1,838 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% TTTTT GGGG AAA %
% T G A A %
% T G GG AAAAA %
% T G G A A %
% T GGG A A %
% %
% %
% Read/Write Truevision Targa Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/color-private.h"
#include "magick/colormap.h"
#include "magick/colormap-private.h"
#include "magick/colorspace.h"
#include "magick/colorspace-private.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/property.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteTGAImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d T G A I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadTGAImage() reads a Truevision TGA 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 ReadTGAImage method is:
%
% Image *ReadTGAImage(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 *ReadTGAImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
#define TGAColormap 1
#define TGARGB 2
#define TGAMonochrome 3
#define TGARLEColormap 9
#define TGARLERGB 10
#define TGARLEMonochrome 11
typedef struct _TGAInfo
{
unsigned char
id_length,
colormap_type,
image_type;
unsigned short
colormap_index,
colormap_length;
unsigned char
colormap_size;
unsigned short
x_origin,
y_origin,
width,
height;
unsigned char
bits_per_pixel,
attributes;
} TGAInfo;
Image
*image;
IndexPacket
index;
MagickBooleanType
status;
PixelPacket
pixel;
register IndexPacket
*indexes;
register PixelPacket
*q;
register ssize_t
i,
x;
size_t
base,
flag,
offset,
real,
skip;
ssize_t
count,
y;
TGAInfo
tga_info;
unsigned char
j,
k,
pixels[4],
runlength;
unsigned int
alpha_bits;
/*
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);
}
/*
Read TGA header information.
*/
count=ReadBlob(image,1,&tga_info.id_length);
tga_info.colormap_type=(unsigned char) ReadBlobByte(image);
tga_info.image_type=(unsigned char) ReadBlobByte(image);
if ((count != 1) ||
((tga_info.image_type != TGAColormap) &&
(tga_info.image_type != TGARGB) &&
(tga_info.image_type != TGAMonochrome) &&
(tga_info.image_type != TGARLEColormap) &&
(tga_info.image_type != TGARLERGB) &&
(tga_info.image_type != TGARLEMonochrome)) ||
(((tga_info.image_type == TGAColormap) ||
(tga_info.image_type == TGARLEColormap)) &&
(tga_info.colormap_type == 0)))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
tga_info.colormap_index=ReadBlobLSBShort(image);
tga_info.colormap_length=ReadBlobLSBShort(image);
tga_info.colormap_size=(unsigned char) ReadBlobByte(image);
tga_info.x_origin=ReadBlobLSBShort(image);
tga_info.y_origin=ReadBlobLSBShort(image);
tga_info.width=(unsigned short) ReadBlobLSBShort(image);
tga_info.height=(unsigned short) ReadBlobLSBShort(image);
tga_info.bits_per_pixel=(unsigned char) ReadBlobByte(image);
tga_info.attributes=(unsigned char) ReadBlobByte(image);
if (EOFBlob(image) != MagickFalse)
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
if ((((tga_info.bits_per_pixel <= 1) || (tga_info.bits_per_pixel >= 17)) &&
(tga_info.bits_per_pixel != 24) && (tga_info.bits_per_pixel != 32)))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
/*
Initialize image structure.
*/
image->columns=tga_info.width;
image->rows=tga_info.height;
alpha_bits=(tga_info.attributes & 0x0FU);
image->matte=(alpha_bits > 0) || (tga_info.bits_per_pixel == 32) ?
MagickTrue : MagickFalse;
if ((tga_info.image_type != TGAColormap) &&
(tga_info.image_type != TGARLEColormap))
image->depth=(size_t) ((tga_info.bits_per_pixel <= 8) ? 8 :
(tga_info.bits_per_pixel <= 16) ? 5 :
(tga_info.bits_per_pixel == 24) ? 8 :
(tga_info.bits_per_pixel == 32) ? 8 : 8);
else
image->depth=(size_t) ((tga_info.colormap_size <= 8) ? 8 :
(tga_info.colormap_size <= 16) ? 5 :
(tga_info.colormap_size == 24) ? 8 :
(tga_info.colormap_size == 32) ? 8 : 8);
if ((tga_info.image_type == TGAColormap) ||
(tga_info.image_type == TGAMonochrome) ||
(tga_info.image_type == TGARLEColormap) ||
(tga_info.image_type == TGARLEMonochrome))
image->storage_class=PseudoClass;
image->compression=NoCompression;
if ((tga_info.image_type == TGARLEColormap) ||
(tga_info.image_type == TGARLEMonochrome))
image->compression=RLECompression;
if (image->storage_class == PseudoClass)
{
if (tga_info.colormap_type != 0)
image->colors=tga_info.colormap_length;
else
{
size_t
one;
one=1;
image->colors=one << tga_info.bits_per_pixel;
if (AcquireImageColormap(image,image->colors) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
}
}
if (tga_info.id_length != 0)
{
char
*comment;
size_t
length;
/*
TGA image comment.
*/
length=(size_t) tga_info.id_length;
comment=(char *) NULL;
if (~length >= (MaxTextExtent-1))
comment=(char *) AcquireQuantumMemory(length+MaxTextExtent,
sizeof(*comment));
if (comment == (char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
count=ReadBlob(image,tga_info.id_length,(unsigned char *) comment);
comment[tga_info.id_length]='\0';
(void) SetImageProperty(image,"comment",comment);
comment=DestroyString(comment);
}
(void) ResetMagickMemory(&pixel,0,sizeof(pixel));
pixel.opacity=(Quantum) OpaqueOpacity;
if (tga_info.colormap_type != 0)
{
/*
Read TGA raster colormap.
*/
if (AcquireImageColormap(image,image->colors) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
for (i=0; i < (ssize_t) image->colors; i++)
{
switch (tga_info.colormap_size)
{
case 8:
default:
{
/*
Gray scale.
*/
pixel.red=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
pixel.green=pixel.red;
pixel.blue=pixel.red;
break;
}
case 15:
case 16:
{
QuantumAny
range;
/*
5 bits each of red green and blue.
*/
j=(unsigned char) ReadBlobByte(image);
k=(unsigned char) ReadBlobByte(image);
range=GetQuantumRange(5UL);
pixel.red=ScaleAnyToQuantum(1UL*(k & 0x7c) >> 2,range);
pixel.green=ScaleAnyToQuantum((1UL*(k & 0x03) << 3)+
(1UL*(j & 0xe0) >> 5),range);
pixel.blue=ScaleAnyToQuantum(1UL*(j & 0x1f),range);
break;
}
case 24:
case 32:
{
/*
8 bits each of blue, green and red.
*/
pixel.blue=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
pixel.green=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
pixel.red=ScaleCharToQuantum((unsigned char) ReadBlobByte(image));
break;
}
}
image->colormap[i]=pixel;
}
}
/*
Convert TGA pixels to pixel packets.
*/
base=0;
flag=0;
skip=MagickFalse;
real=0;
index=(IndexPacket) 0;
runlength=0;
offset=0;
for (y=0; y < (ssize_t) image->rows; y++)
{
real=offset;
if (((unsigned char) (tga_info.attributes & 0x20) >> 5) == 0)
real=image->rows-real-1;
q=QueueAuthenticPixels(image,0,(ssize_t) real,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < (ssize_t) image->columns; x++)
{
if ((tga_info.image_type == TGARLEColormap) ||
(tga_info.image_type == TGARLERGB) ||
(tga_info.image_type == TGARLEMonochrome))
{
if (runlength != 0)
{
runlength--;
skip=flag != 0;
}
else
{
count=ReadBlob(image,1,&runlength);
if (count == 0)
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
flag=runlength & 0x80;
if (flag != 0)
runlength-=128;
skip=MagickFalse;
}
}
if (skip == MagickFalse)
switch (tga_info.bits_per_pixel)
{
case 8:
default:
{
/*
Gray scale.
*/
index=(IndexPacket) ReadBlobByte(image);
if (tga_info.colormap_type != 0)
pixel=image->colormap[(ssize_t) ConstrainColormapIndex(image,
1UL*index)];
else
{
pixel.red=ScaleCharToQuantum((unsigned char) index);
pixel.green=ScaleCharToQuantum((unsigned char) index);
pixel.blue=ScaleCharToQuantum((unsigned char) index);
}
break;
}
case 15:
case 16:
{
QuantumAny
range;
/*
5 bits each of RGB;
*/
if (ReadBlob(image,2,pixels) != 2)
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
j=pixels[0];
k=pixels[1];
range=GetQuantumRange(5UL);
pixel.red=ScaleAnyToQuantum(1UL*(k & 0x7c) >> 2,range);
pixel.green=ScaleAnyToQuantum((1UL*(k & 0x03) << 3)+
(1UL*(j & 0xe0) >> 5),range);
pixel.blue=ScaleAnyToQuantum(1UL*(j & 0x1f),range);
if (image->matte != MagickFalse)
pixel.opacity=(k & 0x80) == 0 ? (Quantum) OpaqueOpacity :
(Quantum) TransparentOpacity;
if (image->storage_class == PseudoClass)
index=ConstrainColormapIndex(image,((size_t) k << 8)+j);
break;
}
case 24:
{
/*
BGR pixels.
*/
if (ReadBlob(image,3,pixels) != 3)
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
pixel.blue=ScaleCharToQuantum(pixels[0]);
pixel.green=ScaleCharToQuantum(pixels[1]);
pixel.red=ScaleCharToQuantum(pixels[2]);
break;
}
case 32:
{
/*
BGRA pixels.
*/
if (ReadBlob(image,4,pixels) != 4)
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
pixel.blue=ScaleCharToQuantum(pixels[0]);
pixel.green=ScaleCharToQuantum(pixels[1]);
pixel.red=ScaleCharToQuantum(pixels[2]);
pixel.opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(
pixels[3]));
break;
}
}
if (status == MagickFalse)
ThrowReaderException(CorruptImageError,"UnableToReadImageData");
if (image->storage_class == PseudoClass)
SetPixelIndex(indexes+x,index);
SetPixelRed(q,pixel.red);
SetPixelGreen(q,pixel.green);
SetPixelBlue(q,pixel.blue);
if (image->matte != MagickFalse)
SetPixelOpacity(q,pixel.opacity);
q++;
}
if (((unsigned char) (tga_info.attributes & 0xc0) >> 6) == 4)
offset+=4;
else
if (((unsigned char) (tga_info.attributes & 0xc0) >> 6) == 2)
offset+=2;
else
offset++;
if (offset >= image->rows)
{
base++;
offset=base;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
if (EOFBlob(image) != MagickFalse)
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r T G A I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterTGAImage() adds properties for the TGA image format to
% the list of supported formats. The properties include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterTGAImage method is:
%
% size_t RegisterTGAImage(void)
%
*/
ModuleExport size_t RegisterTGAImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("ICB");
entry->decoder=(DecodeImageHandler *) ReadTGAImage;
entry->encoder=(EncodeImageHandler *) WriteTGAImage;
entry->adjoin=MagickFalse;
entry->description=ConstantString("Truevision Targa image");
entry->module=ConstantString("TGA");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("TGA");
entry->decoder=(DecodeImageHandler *) ReadTGAImage;
entry->encoder=(EncodeImageHandler *) WriteTGAImage;
entry->adjoin=MagickFalse;
entry->description=ConstantString("Truevision Targa image");
entry->module=ConstantString("TGA");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("VDA");
entry->decoder=(DecodeImageHandler *) ReadTGAImage;
entry->encoder=(EncodeImageHandler *) WriteTGAImage;
entry->adjoin=MagickFalse;
entry->description=ConstantString("Truevision Targa image");
entry->module=ConstantString("TGA");
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("VST");
entry->decoder=(DecodeImageHandler *) ReadTGAImage;
entry->encoder=(EncodeImageHandler *) WriteTGAImage;
entry->adjoin=MagickFalse;
entry->description=ConstantString("Truevision Targa image");
entry->module=ConstantString("TGA");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r T G A I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterTGAImage() removes format registrations made by the
% TGA module from the list of supported formats.
%
% The format of the UnregisterTGAImage method is:
%
% UnregisterTGAImage(void)
%
*/
ModuleExport void UnregisterTGAImage(void)
{
(void) UnregisterMagickInfo("ICB");
(void) UnregisterMagickInfo("TGA");
(void) UnregisterMagickInfo("VDA");
(void) UnregisterMagickInfo("VST");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e T G A I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteTGAImage() writes a image in the Truevision Targa rasterfile
% format.
%
% The format of the WriteTGAImage method is:
%
% MagickBooleanType WriteTGAImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static inline size_t MagickMin(const size_t x,const size_t y)
{
if (x < y)
return(x);
return(y);
}
static MagickBooleanType WriteTGAImage(const ImageInfo *image_info,Image *image)
{
#define TargaColormap 1
#define TargaRGB 2
#define TargaMonochrome 3
#define TargaRLEColormap 9
#define TargaRLERGB 10
#define TargaRLEMonochrome 11
typedef struct _TargaInfo
{
unsigned char
id_length,
colormap_type,
image_type;
unsigned short
colormap_index,
colormap_length;
unsigned char
colormap_size;
unsigned short
x_origin,
y_origin,
width,
height;
unsigned char
bits_per_pixel,
attributes;
} TargaInfo;
const char
*value;
MagickBooleanType
status;
register const IndexPacket
*indexes;
register const PixelPacket
*p;
register ssize_t
x;
register ssize_t
i;
register unsigned char
*q;
ssize_t
count,
y;
TargaInfo
targa_info;
unsigned char
*targa_pixels;
/*
Open output image file.
*/
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);
/*
Initialize TGA raster file header.
*/
if ((image->columns > 65535L) || (image->rows > 65535L))
ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace);
targa_info.id_length=0;
value=GetImageProperty(image,"comment");
if (value != (const char *) NULL)
targa_info.id_length=(unsigned char) MagickMin(strlen(value),255);
targa_info.colormap_type=0;
targa_info.colormap_index=0;
targa_info.colormap_length=0;
targa_info.colormap_size=0;
targa_info.x_origin=0;
targa_info.y_origin=0;
targa_info.width=(unsigned short) image->columns;
targa_info.height=(unsigned short) image->rows;
targa_info.bits_per_pixel=8;
targa_info.attributes=0;
if ((image_info->type != TrueColorType) &&
(image_info->type != TrueColorMatteType) &&
(image_info->type != PaletteType) &&
(image->matte == MagickFalse) &&
(IsGrayImage(image,&image->exception) != MagickFalse))
targa_info.image_type=TargaMonochrome;
else
if ((image->storage_class == DirectClass) || (image->colors > 256))
{
/*
Full color TGA raster.
*/
targa_info.image_type=TargaRGB;
targa_info.bits_per_pixel=24;
if (image->matte != MagickFalse)
{
targa_info.bits_per_pixel=32;
targa_info.attributes=8; /* # of alpha bits */
}
}
else
{
/*
Colormapped TGA raster.
*/
targa_info.image_type=TargaColormap;
targa_info.colormap_type=1;
targa_info.colormap_length=(unsigned short) image->colors;
targa_info.colormap_size=24;
}
/*
Write TGA header.
*/
(void) WriteBlobByte(image,targa_info.id_length);
(void) WriteBlobByte(image,targa_info.colormap_type);
(void) WriteBlobByte(image,targa_info.image_type);
(void) WriteBlobLSBShort(image,targa_info.colormap_index);
(void) WriteBlobLSBShort(image,targa_info.colormap_length);
(void) WriteBlobByte(image,targa_info.colormap_size);
(void) WriteBlobLSBShort(image,targa_info.x_origin);
(void) WriteBlobLSBShort(image,targa_info.y_origin);
(void) WriteBlobLSBShort(image,targa_info.width);
(void) WriteBlobLSBShort(image,targa_info.height);
(void) WriteBlobByte(image,targa_info.bits_per_pixel);
(void) WriteBlobByte(image,targa_info.attributes);
if (targa_info.id_length != 0)
(void) WriteBlob(image,targa_info.id_length,(unsigned char *)
value);
if (targa_info.image_type == TargaColormap)
{
unsigned char
*targa_colormap;
/*
Dump colormap to file (blue, green, red byte order).
*/
targa_colormap=(unsigned char *) AcquireQuantumMemory((size_t)
targa_info.colormap_length,3UL*sizeof(*targa_colormap));
if (targa_colormap == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
q=targa_colormap;
for (i=0; i < (ssize_t) image->colors; i++)
{
*q++=ScaleQuantumToChar(image->colormap[i].blue);
*q++=ScaleQuantumToChar(image->colormap[i].green);
*q++=ScaleQuantumToChar(image->colormap[i].red);
}
(void) WriteBlob(image,(size_t) (3*targa_info.colormap_length),
targa_colormap);
targa_colormap=(unsigned char *) RelinquishMagickMemory(targa_colormap);
}
/*
Convert MIFF to TGA raster pixels.
*/
count=(ssize_t) (targa_info.bits_per_pixel*targa_info.width)/8;
targa_pixels=(unsigned char *) AcquireQuantumMemory((size_t) count,
sizeof(*targa_pixels));
if (targa_pixels == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
for (y=(ssize_t) (image->rows-1); y >= 0; y--)
{
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (const PixelPacket *) NULL)
break;
q=targa_pixels;
indexes=GetVirtualIndexQueue(image);
for (x=0; x < (ssize_t) image->columns; x++)
{
if (targa_info.image_type == TargaColormap)
*q++=(unsigned char) GetPixelIndex(indexes+x);
else
if (targa_info.image_type == TargaMonochrome)
*q++=(unsigned char) ScaleQuantumToChar(PixelIntensityToQuantum(image,p));
else
{
*q++=ScaleQuantumToChar(GetPixelBlue(p));
*q++=ScaleQuantumToChar(GetPixelGreen(p));
*q++=ScaleQuantumToChar(GetPixelRed(p));
if (image->matte != MagickFalse)
*q++=(unsigned char) ScaleQuantumToChar(
GetPixelAlpha(p));
if (image->colorspace == CMYKColorspace)
*q++=ScaleQuantumToChar(GetPixelIndex(indexes+x));
}
p++;
}
(void) WriteBlob(image,(size_t) (q-targa_pixels),targa_pixels);
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
targa_pixels=(unsigned char *) RelinquishMagickMemory(targa_pixels);
(void) CloseBlob(image);
return(MagickTrue);
}

View file

@ -0,0 +1,220 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% TTTTT H H U U M M BBBB N N AAA IIIII L %
% T H H U U MM MM B B NN N A A I L %
% T HHHHH U U M M M BBBB N N N AAAAA I L %
% T H H U U M M B B N NN A A I L %
% T H H UUU M M BBBB N N A A IIIII LLLLL %
% %
% %
% Write EXIF Thumbnail To File. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/attribute.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/module.h"
#include "magick/monitor.h"
#include "magick/monitor-private.h"
#include "magick/pixel-accessor.h"
#include "magick/profile.h"
#include "magick/property.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/string-private.h"
/*
Forward declarations.
*/
static MagickBooleanType
WriteTHUMBNAILImage(const ImageInfo *,Image *);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r T H U M B N A I L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterTHUMBNAILImage() adds attributes for the THUMBNAIL image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterTHUMBNAILImage method is:
%
% size_t RegisterTHUMBNAILImage(void)
%
*/
ModuleExport size_t RegisterTHUMBNAILImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("THUMBNAIL");
entry->encoder=(EncodeImageHandler *) WriteTHUMBNAILImage;
entry->description=ConstantString("EXIF Profile Thumbnail");
entry->module=ConstantString("THUMBNAIL");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r T H U M B N A I L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterTHUMBNAILImage() removes format registrations made by the
% THUMBNAIL module from the list of supported formats.
%
% The format of the UnregisterTHUMBNAILImage method is:
%
% UnregisterTHUMBNAILImage(void)
%
*/
ModuleExport void UnregisterTHUMBNAILImage(void)
{
(void) UnregisterMagickInfo("THUMBNAIL");
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e T H U M B N A I L I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% WriteTHUMBNAILImage() extracts the EXIF thumbnail image and writes it.
%
% The format of the WriteTHUMBNAILImage method is:
%
% MagickBooleanType WriteTHUMBNAILImage(const ImageInfo *image_info,
% Image *image)
%
% A description of each parameter follows.
%
% o image_info: the image info.
%
% o image: The image.
%
*/
static MagickBooleanType WriteTHUMBNAILImage(const ImageInfo *image_info,
Image *image)
{
const char
*property;
const StringInfo
*profile;
Image
*thumbnail_image;
ImageInfo
*write_info;
MagickBooleanType
status;
register ssize_t
i;
size_t
length;
ssize_t
offset;
unsigned char
magick[MaxTextExtent];
profile=GetImageProfile(image,"exif");
if (profile == (const StringInfo *) NULL)
ThrowWriterException(CoderError,"ImageDoesNotHaveAThumbnail");
property=GetImageProperty(image,"exif:JPEGInterchangeFormat");
if (property == (const char *) NULL)
ThrowWriterException(CoderError,"ImageDoesNotHaveAThumbnail");
offset=(ssize_t) StringToLong(property);
property=GetImageProperty(image,"exif:JPEGInterchangeFormatLength");
if (property == (const char *) NULL)
ThrowWriterException(CoderError,"ImageDoesNotHaveAThumbnail");
length=(size_t) StringToLong(property);
(void) ResetMagickMemory(magick,0,sizeof(magick));
for (i=0; i < (ssize_t) length; i++)
{
magick[0]=magick[1];
magick[1]=magick[2];
magick[2]=GetStringInfoDatum(profile)[offset+i];
if (memcmp(magick,"\377\330\377",3) == 0)
break;
}
thumbnail_image=BlobToImage(image_info,GetStringInfoDatum(profile)+offset+i-2,
length,&image->exception);
if (thumbnail_image == (Image *) NULL)
return(MagickFalse);
(void) SetImageType(thumbnail_image,thumbnail_image->matte == MagickFalse ?
TrueColorType : TrueColorMatteType);
(void) CopyMagickString(thumbnail_image->filename,image->filename,
MaxTextExtent);
write_info=CloneImageInfo(image_info);
(void) SetImageInfo(write_info,1,&image->exception);
if (LocaleCompare(write_info->magick,"THUMBNAIL") == 0)
(void) FormatLocaleString(thumbnail_image->filename,MaxTextExtent,
"miff:%s",write_info->filename);
status=WriteImage(write_info,thumbnail_image);
thumbnail_image=DestroyImage(thumbnail_image);
write_info=DestroyImageInfo(write_info);
return(status);
}

3493
ImageMagick/coders/tiff.c Normal file

File diff suppressed because it is too large Load diff

198
ImageMagick/coders/tile.c Normal file
View file

@ -0,0 +1,198 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% TTTTT IIIII L EEEEE %
% T I L E %
% T I L EEE %
% T I L E %
% T IIIII LLLLL EEEEE %
% %
% %
% Return A Tiled Image Using Texture. %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d T I L E I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadTILEImage tiles a texture on an image. It allocates the
% memory necessary for the new Image structure and returns a pointer to the
% new image.
%
% The format of the ReadTILEImage method is:
%
% Image *ReadTILEImage(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 *ReadTILEImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
Image
*image,
*tile_image;
ImageInfo
*read_info;
/*
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);
read_info=CloneImageInfo(image_info);
SetImageInfoBlob(read_info,(void *) NULL,0);
*read_info->magick='\0';
tile_image=ReadImage(read_info,exception);
read_info=DestroyImageInfo(read_info);
if (tile_image == (Image *) NULL)
return((Image *) NULL);
image=AcquireImage(image_info);
if ((image->columns == 0) || (image->rows == 0))
ThrowReaderException(OptionError,"MustSpecifyImageSize");
if (*image_info->filename == '\0')
ThrowReaderException(OptionError,"MustSpecifyAnImageName");
image->colorspace=tile_image->colorspace;
image->matte=tile_image->matte;
if (image->matte != MagickFalse)
(void) SetImageBackgroundColor(image);
(void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
if (LocaleCompare(tile_image->magick,"PATTERN") == 0)
{
tile_image->tile_offset.x=0;
tile_image->tile_offset.y=0;
}
(void) TextureImage(image,tile_image);
tile_image=DestroyImage(tile_image);
if (image->colorspace == GRAYColorspace)
image->type=GrayscaleType;
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r T I L E I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterTILEImage() adds attributes for the TILE image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterTILEImage method is:
%
% size_t RegisterTILEImage(void)
%
*/
ModuleExport size_t RegisterTILEImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("TILE");
entry->decoder=(DecodeImageHandler *) ReadTILEImage;
entry->raw=MagickTrue;
entry->endian_support=MagickTrue;
entry->format_type=ImplicitFormatType;
entry->description=ConstantString("Tile image with a texture");
entry->module=ConstantString("TILE");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r T I L E I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterTILEImage() removes format registrations made by the
% TILE module from the list of supported formats.
%
% The format of the UnregisterTILEImage method is:
%
% UnregisterTILEImage(void)
%
*/
ModuleExport void UnregisterTILEImage(void)
{
(void) UnregisterMagickInfo("TILE");
}

476
ImageMagick/coders/tim.c Normal file
View file

@ -0,0 +1,476 @@
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% TTTTT IIIII M M %
% T I MM MM %
% T I M M M %
% T I M M %
% T IIIII M M %
% %
% %
% Read PSX TIM Image Format %
% %
% Software Design %
% John Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2013 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 %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/cache.h"
#include "magick/colormap.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.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/quantum-private.h"
#include "magick/static.h"
#include "magick/string_.h"
#include "magick/module.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d T I M I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ReadTIMImage() reads a PSX TIM image file and returns it. It
% allocates the memory necessary for the new Image structure and returns a
% pointer to the new image.
%
% Contributed by os@scee.sony.co.uk.
%
% The format of the ReadTIMImage method is:
%
% Image *ReadTIMImage(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 *ReadTIMImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
typedef struct _TIMInfo
{
size_t
id,
flag;
} TIMInfo;
TIMInfo
tim_info;
Image
*image;
int
bits_per_pixel,
has_clut;
MagickBooleanType
status;
register IndexPacket
*indexes;
register ssize_t
x;
register PixelPacket
*q;
register ssize_t
i;
register unsigned char
*p;
size_t
bytes_per_line,
height,
image_size,
pixel_mode,
width;
ssize_t
count,
y;
unsigned char
*tim_data,
*tim_pixels;
unsigned short
word;
/*
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);
}
/*
Determine if this a TIM file.
*/
tim_info.id=ReadBlobLSBLong(image);
do
{
/*
Verify TIM identifier.
*/
if (tim_info.id != 0x00000010)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
tim_info.flag=ReadBlobLSBLong(image);
has_clut=tim_info.flag & (1 << 3) ? 1 : 0;
pixel_mode=tim_info.flag & 0x07;
switch ((int) pixel_mode)
{
case 0: bits_per_pixel=4; break;
case 1: bits_per_pixel=8; break;
case 2: bits_per_pixel=16; break;
case 3: bits_per_pixel=24; break;
default: bits_per_pixel=4; break;
}
if (has_clut)
{
unsigned char
*tim_colormap;
/*
Read TIM raster colormap.
*/
(void)ReadBlobLSBLong(image);
(void)ReadBlobLSBShort(image);
(void)ReadBlobLSBShort(image);
width=ReadBlobLSBShort(image);
height=ReadBlobLSBShort(image);
image->columns=width;
image->rows=height;
if (AcquireImageColormap(image,pixel_mode == 1 ? 256UL : 16UL) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
tim_colormap=(unsigned char *) AcquireQuantumMemory(image->colors,
2UL*sizeof(*tim_colormap));
if (tim_colormap == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
count=ReadBlob(image,2*image->colors,tim_colormap);
if (count != (ssize_t) (2*image->colors))
ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
p=tim_colormap;
for (i=0; i < (ssize_t) image->colors; i++)
{
word=(*p++);
word|=(unsigned short) (*p++ << 8);
image->colormap[i].blue=ScaleCharToQuantum(
ScaleColor5to8(1UL*(word >> 10) & 0x1f));
image->colormap[i].green=ScaleCharToQuantum(
ScaleColor5to8(1UL*(word >> 5) & 0x1f));
image->colormap[i].red=ScaleCharToQuantum(
ScaleColor5to8(1UL*word & 0x1f));
}
tim_colormap=(unsigned char *) RelinquishMagickMemory(tim_colormap);
}
if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
/*
Read image data.
*/
(void) ReadBlobLSBLong(image);
(void) ReadBlobLSBShort(image);
(void) ReadBlobLSBShort(image);
width=ReadBlobLSBShort(image);
height=ReadBlobLSBShort(image);
image_size=2*width*height;
bytes_per_line=width*2;
width=(width*16)/bits_per_pixel;
tim_data=(unsigned char *) AcquireQuantumMemory(image_size,
sizeof(*tim_data));
if (tim_data == (unsigned char *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
count=ReadBlob(image,image_size,tim_data);
if (count != (ssize_t) (image_size))
ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile");
tim_pixels=tim_data;
/*
Initialize image structure.
*/
image->columns=width;
image->rows=height;
/*
Convert TIM raster image to pixel packets.
*/
switch (bits_per_pixel)
{
case 4:
{
/*
Convert PseudoColor scanline.
*/
for (y=(ssize_t) image->rows-1; y >= 0; y--)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
p=tim_pixels+y*bytes_per_line;
for (x=0; x < ((ssize_t) image->columns-1); x+=2)
{
SetPixelIndex(indexes+x,(*p) & 0x0f);
SetPixelIndex(indexes+x+1,(*p >> 4) & 0x0f);
p++;
}
if ((image->columns % 2) != 0)
{
SetPixelIndex(indexes+x,(*p >> 4) & 0x0f);
p++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
break;
}
case 8:
{
/*
Convert PseudoColor scanline.
*/
for (y=(ssize_t) image->rows-1; y >= 0; y--)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
indexes=GetAuthenticIndexQueue(image);
p=tim_pixels+y*bytes_per_line;
for (x=0; x < (ssize_t) image->columns; x++)
SetPixelIndex(indexes+x,*p++);
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
break;
}
case 16:
{
/*
Convert DirectColor scanline.
*/
for (y=(ssize_t) image->rows-1; y >= 0; y--)
{
p=tim_pixels+y*bytes_per_line;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
word=(*p++);
word|=(*p++ << 8);
SetPixelBlue(q,ScaleCharToQuantum(ScaleColor5to8(
(1UL*word >> 10) & 0x1f)));
SetPixelGreen(q,ScaleCharToQuantum(ScaleColor5to8(
(1UL*word >> 5) & 0x1f)));
SetPixelRed(q,ScaleCharToQuantum(ScaleColor5to8(
(1UL*word >> 0) & 0x1f)));
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
break;
}
case 24:
{
/*
Convert DirectColor scanline.
*/
for (y=(ssize_t) image->rows-1; y >= 0; y--)
{
p=tim_pixels+y*bytes_per_line;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
SetPixelRed(q,ScaleCharToQuantum(*p++));
SetPixelGreen(q,ScaleCharToQuantum(*p++));
SetPixelBlue(q,ScaleCharToQuantum(*p++));
q++;
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
break;
}
default:
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
}
if (image->storage_class == PseudoClass)
(void) SyncImage(image);
tim_pixels=(unsigned char *) RelinquishMagickMemory(tim_pixels);
if (EOFBlob(image) != MagickFalse)
{
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
image->filename);
break;
}
/*
Proceed to next image.
*/
tim_info.id=ReadBlobLSBLong(image);
if (tim_info.id == 0x00000010)
{
/*
Allocate next image structure.
*/
AcquireNextImage(image_info,image);
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
return((Image *) NULL);
}
image=SyncNextImageInList(image);
status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
GetBlobSize(image));
if (status == MagickFalse)
break;
}
} while (tim_info.id == 0x00000010);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r T I M I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RegisterTIMImage() adds attributes for the TIM image format to
% the list of supported formats. The attributes include the image format
% tag, a method to read and/or write the format, whether the format
% supports the saving of more than one frame to the same file or blob,
% whether the format supports native in-memory I/O, and a brief
% description of the format.
%
% The format of the RegisterTIMImage method is:
%
% size_t RegisterTIMImage(void)
%
*/
ModuleExport size_t RegisterTIMImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("TIM");
entry->decoder=(DecodeImageHandler *) ReadTIMImage;
entry->description=ConstantString("PSX TIM");
entry->module=ConstantString("TIM");
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r T I M I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% UnregisterTIMImage() removes format registrations made by the
% TIM module from the list of supported formats.
%
% The format of the UnregisterTIMImage method is:
%
% UnregisterTIMImage(void)
%
*/
ModuleExport void UnregisterTIMImage(void)
{
(void) UnregisterMagickInfo("TIM");
}

Some files were not shown because too many files have changed in this diff Show more