| 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/colorspace.h" |
|---|
| 47 | #include "magick/exception.h" |
|---|
| 48 | #include "magick/exception-private.h" |
|---|
| 49 | #include "magick/image.h" |
|---|
| 50 | #include "magick/image-private.h" |
|---|
| 51 | #include "magick/list.h" |
|---|
| 52 | #include "magick/magick.h" |
|---|
| 53 | #include "magick/memory_.h" |
|---|
| 54 | #include "magick/monitor.h" |
|---|
| 55 | #include "magick/monitor-private.h" |
|---|
| 56 | #include "magick/quantum-private.h" |
|---|
| 57 | #include "magick/static.h" |
|---|
| 58 | #include "magick/string_.h" |
|---|
| 59 | #include "magick/module.h" |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | static MagickBooleanType |
|---|
| 65 | WriteAVSImage(const ImageInfo *,Image *); |
|---|
| 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 | static Image *ReadAVSImage(const ImageInfo *image_info,ExceptionInfo *exception) |
|---|
| 94 | { |
|---|
| 95 | Image |
|---|
| 96 | *image; |
|---|
| 97 | |
|---|
| 98 | long |
|---|
| 99 | y; |
|---|
| 100 | |
|---|
| 101 | MagickBooleanType |
|---|
| 102 | status; |
|---|
| 103 | |
|---|
| 104 | register long |
|---|
| 105 | x; |
|---|
| 106 | |
|---|
| 107 | register PixelPacket |
|---|
| 108 | *q; |
|---|
| 109 | |
|---|
| 110 | register unsigned char |
|---|
| 111 | *p; |
|---|
| 112 | |
|---|
| 113 | ssize_t |
|---|
| 114 | count; |
|---|
| 115 | |
|---|
| 116 | size_t |
|---|
| 117 | length; |
|---|
| 118 | |
|---|
| 119 | unsigned char |
|---|
| 120 | *pixels; |
|---|
| 121 | |
|---|
| 122 | unsigned long |
|---|
| 123 | height, |
|---|
| 124 | width; |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | assert(image_info != (const ImageInfo *) NULL); |
|---|
| 130 | assert(image_info->signature == MagickSignature); |
|---|
| 131 | if (image_info->debug != MagickFalse) |
|---|
| 132 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
|---|
| 133 | image_info->filename); |
|---|
| 134 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 135 | assert(exception->signature == MagickSignature); |
|---|
| 136 | image=AcquireImage(image_info); |
|---|
| 137 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
|---|
| 138 | if (status == MagickFalse) |
|---|
| 139 | { |
|---|
| 140 | image=DestroyImageList(image); |
|---|
| 141 | return((Image *) NULL); |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | width=ReadBlobMSBLong(image); |
|---|
| 147 | height=ReadBlobMSBLong(image); |
|---|
| 148 | if (EOFBlob(image) != MagickFalse) |
|---|
| 149 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
|---|
| 150 | if ((width == 0UL) || (height == 0UL)) |
|---|
| 151 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
|---|
| 152 | do |
|---|
| 153 | { |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | image->columns=width; |
|---|
| 158 | image->rows=height; |
|---|
| 159 | image->depth=8; |
|---|
| 160 | if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) |
|---|
| 161 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
|---|
| 162 | break; |
|---|
| 163 | pixels=(unsigned char *) AcquireQuantumMemory(image->columns, |
|---|
| 164 | 4*sizeof(*pixels)); |
|---|
| 165 | if (pixels == (unsigned char *) NULL) |
|---|
| 166 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
|---|
| 167 | length=(size_t) 4*image->columns; |
|---|
| 168 | for (y=0; y < (long) image->rows; y++) |
|---|
| 169 | { |
|---|
| 170 | count=ReadBlob(image,length,pixels); |
|---|
| 171 | if ((size_t) count != length) |
|---|
| 172 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
|---|
| 173 | p=pixels; |
|---|
| 174 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
|---|
| 175 | if (q == (PixelPacket *) NULL) |
|---|
| 176 | break; |
|---|
| 177 | for (x=0; x < (long) image->columns; x++) |
|---|
| 178 | { |
|---|
| 179 | q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(*p++)); |
|---|
| 180 | q->red=ScaleCharToQuantum(*p++); |
|---|
| 181 | q->green=ScaleCharToQuantum(*p++); |
|---|
| 182 | q->blue=ScaleCharToQuantum(*p++); |
|---|
| 183 | if (q->opacity != OpaqueOpacity) |
|---|
| 184 | image->matte=MagickTrue; |
|---|
| 185 | q++; |
|---|
| 186 | } |
|---|
| 187 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
|---|
| 188 | break; |
|---|
| 189 | if ((image->previous == (Image *) NULL) && |
|---|
| 190 | (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)) |
|---|
| 191 | break; |
|---|
| 192 | } |
|---|
| 193 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
|---|
| 194 | if (EOFBlob(image) != MagickFalse) |
|---|
| 195 | { |
|---|
| 196 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
|---|
| 197 | image->filename); |
|---|
| 198 | break; |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | if (image_info->number_scenes != 0) |
|---|
| 204 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
|---|
| 205 | break; |
|---|
| 206 | width=ReadBlobMSBLong(image); |
|---|
| 207 | height=ReadBlobMSBLong(image); |
|---|
| 208 | if ((width != 0UL) && (height != 0UL)) |
|---|
| 209 | { |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | AcquireNextImage(image_info,image); |
|---|
| 214 | if (GetNextImageInList(image) == (Image *) NULL) |
|---|
| 215 | { |
|---|
| 216 | image=DestroyImageList(image); |
|---|
| 217 | return((Image *) NULL); |
|---|
| 218 | } |
|---|
| 219 | image=SyncNextImageInList(image); |
|---|
| 220 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
|---|
| 221 | GetBlobSize(image)); |
|---|
| 222 | if (status == MagickFalse) |
|---|
| 223 | break; |
|---|
| 224 | } |
|---|
| 225 | } while ((width != 0UL) && (height != 0UL)); |
|---|
| 226 | (void) CloseBlob(image); |
|---|
| 227 | return(GetFirstImageInList(image)); |
|---|
| 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 | ModuleExport unsigned long RegisterAVSImage(void) |
|---|
| 253 | { |
|---|
| 254 | MagickInfo |
|---|
| 255 | *entry; |
|---|
| 256 | |
|---|
| 257 | entry=SetMagickInfo("AVS"); |
|---|
| 258 | entry->decoder=(DecodeImageHandler *) ReadAVSImage; |
|---|
| 259 | entry->encoder=(EncodeImageHandler *) WriteAVSImage; |
|---|
| 260 | entry->description=ConstantString("AVS X image"); |
|---|
| 261 | entry->module=ConstantString("AVS"); |
|---|
| 262 | (void) RegisterMagickInfo(entry); |
|---|
| 263 | return(MagickImageCoderSignature); |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | ModuleExport void UnregisterAVSImage(void) |
|---|
| 286 | { |
|---|
| 287 | (void) UnregisterMagickInfo("AVS"); |
|---|
| 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 | static MagickBooleanType WriteAVSImage(const ImageInfo *image_info,Image *image) |
|---|
| 315 | { |
|---|
| 316 | MagickBooleanType |
|---|
| 317 | status; |
|---|
| 318 | |
|---|
| 319 | MagickOffsetType |
|---|
| 320 | scene; |
|---|
| 321 | |
|---|
| 322 | register const PixelPacket |
|---|
| 323 | *p; |
|---|
| 324 | |
|---|
| 325 | register long |
|---|
| 326 | x, |
|---|
| 327 | y; |
|---|
| 328 | |
|---|
| 329 | register unsigned char |
|---|
| 330 | *q; |
|---|
| 331 | |
|---|
| 332 | ssize_t |
|---|
| 333 | count; |
|---|
| 334 | |
|---|
| 335 | unsigned char |
|---|
| 336 | *pixels; |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | |
|---|
| 341 | assert(image_info != (const ImageInfo *) NULL); |
|---|
| 342 | assert(image_info->signature == MagickSignature); |
|---|
| 343 | assert(image != (Image *) NULL); |
|---|
| 344 | assert(image->signature == MagickSignature); |
|---|
| 345 | if (image->debug != MagickFalse) |
|---|
| 346 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 347 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); |
|---|
| 348 | if (status == MagickFalse) |
|---|
| 349 | return(status); |
|---|
| 350 | scene=0; |
|---|
| 351 | do |
|---|
| 352 | { |
|---|
| 353 | |
|---|
| 354 | |
|---|
| 355 | |
|---|
| 356 | if (image->colorspace != RGBColorspace) |
|---|
| 357 | (void) TransformImageColorspace(image,RGBColorspace); |
|---|
| 358 | (void) WriteBlobMSBLong(image,(unsigned int) image->columns); |
|---|
| 359 | (void) WriteBlobMSBLong(image,(unsigned int) image->rows); |
|---|
| 360 | |
|---|
| 361 | |
|---|
| 362 | |
|---|
| 363 | pixels=(unsigned char *) AcquireQuantumMemory((size_t) image->columns, |
|---|
| 364 | 4*sizeof(*pixels)); |
|---|
| 365 | if (pixels == (unsigned char *) NULL) |
|---|
| 366 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
|---|
| 367 | |
|---|
| 368 | |
|---|
| 369 | |
|---|
| 370 | for (y=0; y < (long) image->rows; y++) |
|---|
| 371 | { |
|---|
| 372 | p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception); |
|---|
| 373 | if (p == (PixelPacket *) NULL) |
|---|
| 374 | break; |
|---|
| 375 | q=pixels; |
|---|
| 376 | for (x=0; x < (long) image->columns; x++) |
|---|
| 377 | { |
|---|
| 378 | *q++=ScaleQuantumToChar((Quantum) (QuantumRange- |
|---|
| 379 | (image->matte != MagickFalse ? p->opacity : OpaqueOpacity))); |
|---|
| 380 | *q++=ScaleQuantumToChar(p->red); |
|---|
| 381 | *q++=ScaleQuantumToChar(p->green); |
|---|
| 382 | *q++=ScaleQuantumToChar(p->blue); |
|---|
| 383 | p++; |
|---|
| 384 | } |
|---|
| 385 | count=WriteBlob(image,(size_t) (q-pixels),pixels); |
|---|
| 386 | if (count != (ssize_t) (q-pixels)) |
|---|
| 387 | break; |
|---|
| 388 | if ((image->previous == (Image *) NULL) && |
|---|
| 389 | (SetImageProgress(image,SaveImageTag,y,image->rows) == MagickFalse)) |
|---|
| 390 | break; |
|---|
| 391 | } |
|---|
| 392 | pixels=(unsigned char *) RelinquishMagickMemory(pixels); |
|---|
| 393 | if (GetNextImageInList(image) == (Image *) NULL) |
|---|
| 394 | break; |
|---|
| 395 | image=SyncNextImageInList(image); |
|---|
| 396 | status=SetImageProgress(image,SaveImagesTag,scene++, |
|---|
| 397 | GetImageListLength(image)); |
|---|
| 398 | if (status == MagickFalse) |
|---|
| 399 | break; |
|---|
| 400 | } while (image_info->adjoin != MagickFalse); |
|---|
| 401 | (void) CloseBlob(image); |
|---|
| 402 | return(MagickTrue); |
|---|
| 403 | } |
|---|