1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
|
/*
% Copyright (C) 2003-2020 GraphicsMagick Group
% Copyright (C) 2002 ImageMagick Studio
%
% This program is covered by multiple licenses, which are described in
% Copyright.txt. You should have received a copy of Copyright.txt with this
% package; otherwise see http://www.graphicsmagick.org/www/Copyright.html.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% AAA RRRR TTTTT %
% A A R R T %
% AAAAA RRRR T %
% A A R R T %
% A A R R T %
% %
% %
% Read/Write PFS: 1st Publisher Image Format. %
% %
% %
% Software Design %
% Jaroslav Fojtik %
% January 2001 - 2007 %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/colormap.h"
#include "magick/constitute.h"
#include "magick/log.h"
#include "magick/magick.h"
#include "magick/monitor.h"
#include "magick/pixel_cache.h"
#include "magick/utility.h"
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e a d A R T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Method ReadARTImage reads an ART 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 ReadARTImage method is:
%
% Image *ReadARTImage(const ImageInfo *image_info,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o image: Method ReadARTImage returns a pointer to the image after
% reading. A null image is returned if there is a memory shortage or if
% the image cannot be read.
%
% o image_info: Specifies a pointer to a ImageInfo structure.
%
% o exception: return any errors or warnings in this structure.
%
%
*/
static Image *ReadARTImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
Image *image;
unsigned int i;
unsigned int width,height,dummy;
long ldblk;
unsigned char *BImgBuff=NULL;
unsigned char Padding;
unsigned int status;
const PixelPacket *q;
/*
Open image file.
*/
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickSignature);
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
image=AllocateImage(image_info);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == False)
ThrowReaderException(FileOpenError,UnableToOpenFile,image);
/*
Read ART image.
*/
dummy=ReadBlobLSBShort(image);
width=ReadBlobLSBShort(image);
dummy=ReadBlobLSBShort(image);
height=ReadBlobLSBShort(image);
ldblk=(long) (((size_t) width+7) / 8);
Padding=(unsigned char) ((-ldblk) & 0x01);
image->columns=width;
image->rows=height;
if(GetBlobSize(image)!=(magick_off_t) (8+((size_t)ldblk+Padding)*image->rows))
ThrowReaderException(CorruptImageError,ImproperImageHeader,image);
if (CheckImagePixelLimits(image, exception) != MagickPass)
ThrowReaderException(ResourceLimitError,ImagePixelLimitExceeded,image);
image->depth=1;
image->colors=1l << image->depth;
/* printf("ART header checked OK %d,%d\n",image->colors,image->depth); */
if (!AllocateImageColormap(image,image->colors)) goto NoMemory;
/* If ping is true, then only set image size and colors without reading any image data. */
if (image_info->ping) goto DONE_READING;
BImgBuff=MagickAllocateResourceLimitedMemory(unsigned char *,((size_t) ldblk)); /*Ldblk was set in the check phase*/
if (BImgBuff==NULL)
NoMemory:
ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image);
for (i=0; i < height; i++)
{
if (ReadBlob(image,(size_t)ldblk,(char *)BImgBuff) != (size_t)ldblk)
break;
if (ReadBlob(image,Padding,(char *)&dummy) != Padding)
break;
q=SetImagePixelsEx(image,0,i,image->columns,1,exception);
if (q == (PixelPacket *)NULL) break;
(void)ImportImagePixelArea(image,GrayQuantum,1,BImgBuff,NULL,0);
if (!SyncImagePixelsEx(image,exception)) break;
}
MagickFreeResourceLimitedMemory(BImgBuff);
if (i != height)
ThrowReaderException(CorruptImageError,UnexpectedEndOfFile,image);
DONE_READING:
CloseBlob(image);
StopTimer(&image->timer);
return(image);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% W r i t e A R T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Function WriteARTImage writes an ART image to a file.
%
% The format of the WriteARTImage method is:
%
% unsigned int WriteARTImage(const ImageInfo *image_info,Image *image)
%
% A description of each parameter follows.
%
% o status: Function WriteARTImage return True if the image is written.
% False is returned is there is a memory shortage or if the image file
% fails to write.
%
% o image_info: Specifies a pointer to a ImageInfo structure.
%
% o image: A pointer to an Image structure.
%
*/
static MagickPassFail WriteARTImage(const ImageInfo *image_info,Image *image)
{
long y;
unsigned dummy = 0;
size_t DataSize;
unsigned int status;
unsigned char Padding;
int logging;
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);
logging=LogMagickEvent(CoderEvent,GetMagickModule(),"enter ART");
status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
if (status == MagickFail)
ThrowWriterException(FileOpenError,UnableToOpenFile,image);
DataSize = (long)((image->columns+7) / 8);
Padding = (unsigned char)((-(long) DataSize) & 0x01);
pixels=MagickAllocateResourceLimitedMemory(unsigned char *,(size_t) (DataSize));
if (pixels == (unsigned char *) NULL)
ThrowWriterException(ResourceLimitError,MemoryAllocationFailed,image);
/*
Write ART hader.
*/
(void) WriteBlobLSBShort(image,0);
(void) WriteBlobLSBShort(image,image->columns);
(void) WriteBlobLSBShort(image,0);
(void) WriteBlobLSBShort(image,image->rows);
/*
Store image data.
*/
for(y=0; y<(long)image->rows; y++)
{
if (AcquireImagePixels(image,0,y,image->columns,1,&image->exception)
== (const PixelPacket *) NULL)
{
status=MagickFail;
break;
}
if (ExportImagePixelArea(image,GrayQuantum,1,pixels,0,0) != MagickPass)
{
status=MagickFail;
break;
}
if (WriteBlob(image,DataSize,pixels) != DataSize)
{
status=MagickFail;
break;
}
if (WriteBlob(image,Padding,(char *)&dummy) != Padding)
{
status=MagickFail;
break;
}
}
status &= CloseBlob(image);
MagickFreeResourceLimitedMemory(pixels);
if (logging)
(void)LogMagickEvent(CoderEvent,GetMagickModule(),"return ART");
return(status);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e g i s t e r A R T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Method 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:
%
% RegisterARTImage(void)
%
*/
ModuleExport void RegisterARTImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("ART");
entry->decoder = (DecoderHandler)ReadARTImage;
entry->encoder = (EncoderHandler)WriteARTImage;
entry->description="PFS: 1st Publisher";
entry->module="ART";
entry->adjoin=False;
(void) RegisterMagickInfo(entry);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% U n r e g i s t e r A R T I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Method 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");
}
|