| 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 | #include "magick/studio.h" |
|---|
| 43 | #include "magick/blob.h" |
|---|
| 44 | #include "magick/blob-private.h" |
|---|
| 45 | #include "magick/cache.h" |
|---|
| 46 | #include "magick/color-private.h" |
|---|
| 47 | #include "magick/colorspace.h" |
|---|
| 48 | #include "magick/exception.h" |
|---|
| 49 | #include "magick/exception-private.h" |
|---|
| 50 | #include "magick/image.h" |
|---|
| 51 | #include "magick/image-private.h" |
|---|
| 52 | #include "magick/list.h" |
|---|
| 53 | #include "magick/magick.h" |
|---|
| 54 | #include "magick/memory_.h" |
|---|
| 55 | #include "magick/monitor.h" |
|---|
| 56 | #include "magick/monitor-private.h" |
|---|
| 57 | #include "magick/quantum-private.h" |
|---|
| 58 | #include "magick/static.h" |
|---|
| 59 | #include "magick/string_.h" |
|---|
| 60 | #include "magick/module.h" |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | static MagickBooleanType |
|---|
| 66 | WriteARTImage(const ImageInfo *,Image *); |
|---|
| 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 | static Image *ReadARTImage(const ImageInfo *image_info,ExceptionInfo *exception) |
|---|
| 96 | { |
|---|
| 97 | Image |
|---|
| 98 | *image; |
|---|
| 99 | |
|---|
| 100 | long |
|---|
| 101 | y; |
|---|
| 102 | |
|---|
| 103 | QuantumInfo |
|---|
| 104 | *quantum_info; |
|---|
| 105 | |
|---|
| 106 | QuantumType |
|---|
| 107 | quantum_type; |
|---|
| 108 | |
|---|
| 109 | MagickBooleanType |
|---|
| 110 | status; |
|---|
| 111 | |
|---|
| 112 | ssize_t |
|---|
| 113 | count; |
|---|
| 114 | |
|---|
| 115 | size_t |
|---|
| 116 | length; |
|---|
| 117 | |
|---|
| 118 | unsigned char |
|---|
| 119 | *pixels; |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | assert(image_info != (const ImageInfo *) NULL); |
|---|
| 125 | assert(image_info->signature == MagickSignature); |
|---|
| 126 | if (image_info->debug != MagickFalse) |
|---|
| 127 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
|---|
| 128 | image_info->filename); |
|---|
| 129 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 130 | assert(exception->signature == MagickSignature); |
|---|
| 131 | image=AcquireImage(image_info); |
|---|
| 132 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
|---|
| 133 | if (status == MagickFalse) |
|---|
| 134 | { |
|---|
| 135 | image=DestroyImageList(image); |
|---|
| 136 | return((Image *) NULL); |
|---|
| 137 | } |
|---|
| 138 | image->depth=1; |
|---|
| 139 | image->endian=MSBEndian; |
|---|
| 140 | (void) ReadBlobLSBShort(image); |
|---|
| 141 | image->columns=(unsigned long) ReadBlobLSBShort(image); |
|---|
| 142 | (void) ReadBlobLSBShort(image); |
|---|
| 143 | image->rows=(unsigned long) ReadBlobLSBShort(image); |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | if (AcquireImageColormap(image,2) == MagickFalse) |
|---|
| 148 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
|---|
| 149 | if (image_info->ping != MagickFalse) |
|---|
| 150 | { |
|---|
| 151 | (void) CloseBlob(image); |
|---|
| 152 | return(GetFirstImageInList(image)); |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | quantum_type=IndexQuantum; |
|---|
| 158 | quantum_info=AcquireQuantumInfo(image_info,image); |
|---|
| 159 | if (quantum_info == (QuantumInfo *) NULL) |
|---|
| 160 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
|---|
| 161 | pixels=GetQuantumPixels(quantum_info); |
|---|
| 162 | length=GetQuantumExtent(image,quantum_info,quantum_type); |
|---|
| 163 | for (y=0; y < (long) image->rows; y++) |
|---|
| 164 | { |
|---|
| 165 | register PixelPacket |
|---|
| 166 | *__restrict q; |
|---|
| 167 | |
|---|
| 168 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
|---|
| 169 | if (q == (PixelPacket *) NULL) |
|---|
| 170 | break; |
|---|
| 171 | count=ReadBlob(image,length,pixels); |
|---|
| 172 | if (count != (ssize_t) length) |
|---|
| 173 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
|---|
| 174 | (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
|---|
| 175 | quantum_type,pixels,exception); |
|---|
| 176 | count=ReadBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels); |
|---|
| 177 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
|---|
| 178 | break; |
|---|
| 179 | if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse) |
|---|
| 180 | break; |
|---|
| 181 | } |
|---|
| 182 | SetQuantumImageType(image,quantum_type); |
|---|
| 183 | quantum_info=DestroyQuantumInfo(quantum_info); |
|---|
| 184 | if (EOFBlob(image) != MagickFalse) |
|---|
| 185 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
|---|
| 186 | image->filename); |
|---|
| 187 | (void) CloseBlob(image); |
|---|
| 188 | return(GetFirstImageInList(image)); |
|---|
| 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 | ModuleExport unsigned long RegisterARTImage(void) |
|---|
| 215 | { |
|---|
| 216 | MagickInfo |
|---|
| 217 | *entry; |
|---|
| 218 | |
|---|
| 219 | entry=SetMagickInfo("ART"); |
|---|
| 220 | entry->decoder=(DecodeImageHandler *) ReadARTImage; |
|---|
| 221 | entry->encoder=(EncodeImageHandler *) WriteARTImage; |
|---|
| 222 | entry->raw=MagickTrue; |
|---|
| 223 | entry->adjoin=MagickFalse; |
|---|
| 224 | entry->description=ConstantString("PFS: 1st Publisher Clip Art"); |
|---|
| 225 | entry->module=ConstantString("ART"); |
|---|
| 226 | (void) RegisterMagickInfo(entry); |
|---|
| 227 | return(MagickImageCoderSignature); |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | ModuleExport void UnregisterARTImage(void) |
|---|
| 250 | { |
|---|
| 251 | (void) UnregisterMagickInfo("ART"); |
|---|
| 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 | static MagickBooleanType WriteARTImage(const ImageInfo *image_info,Image *image) |
|---|
| 279 | { |
|---|
| 280 | long |
|---|
| 281 | y; |
|---|
| 282 | |
|---|
| 283 | MagickBooleanType |
|---|
| 284 | status; |
|---|
| 285 | |
|---|
| 286 | QuantumInfo |
|---|
| 287 | *quantum_info; |
|---|
| 288 | |
|---|
| 289 | register const PixelPacket |
|---|
| 290 | *p; |
|---|
| 291 | |
|---|
| 292 | ssize_t |
|---|
| 293 | count; |
|---|
| 294 | |
|---|
| 295 | size_t |
|---|
| 296 | length; |
|---|
| 297 | |
|---|
| 298 | unsigned char |
|---|
| 299 | *pixels; |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | assert(image_info != (const ImageInfo *) NULL); |
|---|
| 305 | assert(image_info->signature == MagickSignature); |
|---|
| 306 | assert(image != (Image *) NULL); |
|---|
| 307 | assert(image->signature == MagickSignature); |
|---|
| 308 | if (image->debug != MagickFalse) |
|---|
| 309 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 310 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); |
|---|
| 311 | if (status == MagickFalse) |
|---|
| 312 | return(status); |
|---|
| 313 | if ((image->columns > 65535UL) || (image->rows > 65535UL)) |
|---|
| 314 | ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit"); |
|---|
| 315 | image->endian=MSBEndian; |
|---|
| 316 | image->depth=1; |
|---|
| 317 | (void) WriteBlobLSBShort(image,0); |
|---|
| 318 | (void) WriteBlobLSBShort(image,(unsigned short) image->columns); |
|---|
| 319 | (void) WriteBlobLSBShort(image,0); |
|---|
| 320 | (void) WriteBlobLSBShort(image,(unsigned short) image->rows); |
|---|
| 321 | if (image->colorspace != RGBColorspace) |
|---|
| 322 | (void) TransformImageColorspace(image,RGBColorspace); |
|---|
| 323 | length=(image->columns+7)/8; |
|---|
| 324 | pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels)); |
|---|
| 325 | if (pixels == (unsigned char *) NULL) |
|---|
| 326 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
|---|
| 327 | |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | (void) SetImageType(image,BilevelType); |
|---|
| 331 | quantum_info=AcquireQuantumInfo(image_info,image); |
|---|
| 332 | for (y=0; y < (long) image->rows; y++) |
|---|
| 333 | { |
|---|
| 334 | p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception); |
|---|
| 335 | if (p == (const PixelPacket *) NULL) |
|---|
| 336 | break; |
|---|
| 337 | (void) ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info, |
|---|
| 338 | GrayQuantum,pixels,&image->exception); |
|---|
| 339 | count=WriteBlob(image,length,pixels); |
|---|
| 340 | if (count != (ssize_t) length) |
|---|
| 341 | ThrowWriterException(CorruptImageError,"UnableToWriteImageData"); |
|---|
| 342 | count=WriteBlob(image,(size_t) (-(ssize_t) length) & 0x01,pixels); |
|---|
| 343 | if (SetImageProgress(image,SaveImageTag,y,image->rows) == MagickFalse) |
|---|
| 344 | break; |
|---|
| 345 | } |
|---|
| 346 | quantum_info=DestroyQuantumInfo(quantum_info); |
|---|
| 347 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
|---|
| 348 | (void) CloseBlob(image); |
|---|
| 349 | return(MagickTrue); |
|---|
| 350 | } |
|---|