| 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/exception.h" |
|---|
| 46 | #include "magick/exception-private.h" |
|---|
| 47 | #include "magick/image.h" |
|---|
| 48 | #include "magick/image-private.h" |
|---|
| 49 | #include "magick/list.h" |
|---|
| 50 | #include "magick/magick.h" |
|---|
| 51 | #include "magick/memory_.h" |
|---|
| 52 | #include "magick/monitor.h" |
|---|
| 53 | #include "magick/monitor-private.h" |
|---|
| 54 | #include "magick/quantum-private.h" |
|---|
| 55 | #include "magick/static.h" |
|---|
| 56 | #include "magick/string_.h" |
|---|
| 57 | #include "magick/module.h" |
|---|
| 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 | static Image *ReadPIXImage(const ImageInfo *image_info,ExceptionInfo *exception) |
|---|
| 87 | { |
|---|
| 88 | Image |
|---|
| 89 | *image; |
|---|
| 90 | |
|---|
| 91 | IndexPacket |
|---|
| 92 | index; |
|---|
| 93 | |
|---|
| 94 | long |
|---|
| 95 | y; |
|---|
| 96 | |
|---|
| 97 | MagickBooleanType |
|---|
| 98 | status; |
|---|
| 99 | |
|---|
| 100 | Quantum |
|---|
| 101 | blue, |
|---|
| 102 | green, |
|---|
| 103 | red; |
|---|
| 104 | |
|---|
| 105 | register IndexPacket |
|---|
| 106 | *indexes; |
|---|
| 107 | |
|---|
| 108 | register long |
|---|
| 109 | x; |
|---|
| 110 | |
|---|
| 111 | register PixelPacket |
|---|
| 112 | *q; |
|---|
| 113 | |
|---|
| 114 | size_t |
|---|
| 115 | length; |
|---|
| 116 | |
|---|
| 117 | unsigned long |
|---|
| 118 | bits_per_pixel, |
|---|
| 119 | height, |
|---|
| 120 | width; |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | assert(image_info != (const ImageInfo *) NULL); |
|---|
| 126 | assert(image_info->signature == MagickSignature); |
|---|
| 127 | if (image_info->debug != MagickFalse) |
|---|
| 128 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
|---|
| 129 | image_info->filename); |
|---|
| 130 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 131 | assert(exception->signature == MagickSignature); |
|---|
| 132 | image=AcquireImage(image_info); |
|---|
| 133 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
|---|
| 134 | if (status == MagickFalse) |
|---|
| 135 | { |
|---|
| 136 | image=DestroyImageList(image); |
|---|
| 137 | return((Image *) NULL); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | width=ReadBlobMSBShort(image); |
|---|
| 143 | height=ReadBlobMSBShort(image); |
|---|
| 144 | (void) ReadBlobMSBShort(image); |
|---|
| 145 | (void) ReadBlobMSBShort(image); |
|---|
| 146 | bits_per_pixel=ReadBlobMSBShort(image); |
|---|
| 147 | if ((width == 0UL) || (height == 0UL) || ((bits_per_pixel != 8) && |
|---|
| 148 | (bits_per_pixel != 24))) |
|---|
| 149 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
|---|
| 150 | do |
|---|
| 151 | { |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | image->columns=width; |
|---|
| 156 | image->rows=height; |
|---|
| 157 | if (bits_per_pixel == 8) |
|---|
| 158 | if (AcquireImageColormap(image,256) == MagickFalse) |
|---|
| 159 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
|---|
| 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 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | if (SetImageExtent(image,0,0) == MagickFalse) |
|---|
| 167 | { |
|---|
| 168 | InheritException(exception,&image->exception); |
|---|
| 169 | return(DestroyImageList(image)); |
|---|
| 170 | } |
|---|
| 171 | red=(Quantum) 0; |
|---|
| 172 | green=(Quantum) 0; |
|---|
| 173 | blue=(Quantum) 0; |
|---|
| 174 | index=(IndexPacket) 0; |
|---|
| 175 | length=0; |
|---|
| 176 | for (y=0; y < (long) image->rows; y++) |
|---|
| 177 | { |
|---|
| 178 | q=SetImagePixels(image,0,y,image->columns,1); |
|---|
| 179 | if (q == (PixelPacket *) NULL) |
|---|
| 180 | break; |
|---|
| 181 | indexes=GetIndexes(image); |
|---|
| 182 | for (x=0; x < (long) image->columns; x++) |
|---|
| 183 | { |
|---|
| 184 | if (length == 0) |
|---|
| 185 | { |
|---|
| 186 | length=(size_t) ReadBlobByte(image); |
|---|
| 187 | if (bits_per_pixel == 8) |
|---|
| 188 | index=ScaleCharToQuantum((unsigned char) ReadBlobByte(image)); |
|---|
| 189 | else |
|---|
| 190 | { |
|---|
| 191 | blue=ScaleCharToQuantum((unsigned char) ReadBlobByte(image)); |
|---|
| 192 | green=ScaleCharToQuantum((unsigned char) ReadBlobByte(image)); |
|---|
| 193 | red=ScaleCharToQuantum((unsigned char) ReadBlobByte(image)); |
|---|
| 194 | } |
|---|
| 195 | } |
|---|
| 196 | if (image->storage_class == PseudoClass) |
|---|
| 197 | indexes[x]=index; |
|---|
| 198 | q->blue=blue; |
|---|
| 199 | q->green=green; |
|---|
| 200 | q->red=red; |
|---|
| 201 | length--; |
|---|
| 202 | q++; |
|---|
| 203 | } |
|---|
| 204 | if (SyncImagePixels(image) == MagickFalse) |
|---|
| 205 | break; |
|---|
| 206 | if (image->previous == (Image *) NULL) |
|---|
| 207 | { |
|---|
| 208 | status=SetImageProgress(image,LoadImageTag,y,image->rows); |
|---|
| 209 | if (status == MagickFalse) |
|---|
| 210 | break; |
|---|
| 211 | } |
|---|
| 212 | } |
|---|
| 213 | if (image->storage_class == PseudoClass) |
|---|
| 214 | (void) SyncImage(image); |
|---|
| 215 | if (EOFBlob(image) != MagickFalse) |
|---|
| 216 | { |
|---|
| 217 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
|---|
| 218 | image->filename); |
|---|
| 219 | break; |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | if (image_info->number_scenes != 0) |
|---|
| 225 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
|---|
| 226 | break; |
|---|
| 227 | width=ReadBlobMSBLong(image); |
|---|
| 228 | height=ReadBlobMSBLong(image); |
|---|
| 229 | (void) ReadBlobMSBShort(image); |
|---|
| 230 | (void) ReadBlobMSBShort(image); |
|---|
| 231 | bits_per_pixel=ReadBlobMSBShort(image); |
|---|
| 232 | status=(width != 0UL) && (height == 0UL) && ((bits_per_pixel == 8) || |
|---|
| 233 | (bits_per_pixel == 24)) ? MagickTrue : MagickFalse; |
|---|
| 234 | if (status == MagickTrue) |
|---|
| 235 | { |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | AcquireNextImage(image_info,image); |
|---|
| 240 | if (GetNextImageInList(image) == (Image *) NULL) |
|---|
| 241 | { |
|---|
| 242 | image=DestroyImageList(image); |
|---|
| 243 | return((Image *) NULL); |
|---|
| 244 | } |
|---|
| 245 | image=SyncNextImageInList(image); |
|---|
| 246 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
|---|
| 247 | GetBlobSize(image)); |
|---|
| 248 | if (status == MagickFalse) |
|---|
| 249 | break; |
|---|
| 250 | } |
|---|
| 251 | } while (status == MagickTrue); |
|---|
| 252 | (void) CloseBlob(image); |
|---|
| 253 | return(GetFirstImageInList(image)); |
|---|
| 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 | ModuleExport unsigned long RegisterPIXImage(void) |
|---|
| 280 | { |
|---|
| 281 | MagickInfo |
|---|
| 282 | *entry; |
|---|
| 283 | |
|---|
| 284 | entry=SetMagickInfo("PIX"); |
|---|
| 285 | entry->decoder=(DecodeImageHandler *) ReadPIXImage; |
|---|
| 286 | entry->description=ConstantString("Alias/Wavefront RLE image format"); |
|---|
| 287 | entry->module=ConstantString("PIX"); |
|---|
| 288 | (void) RegisterMagickInfo(entry); |
|---|
| 289 | return(MagickImageCoderSignature); |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | ModuleExport void UnregisterPIXImage(void) |
|---|
| 312 | { |
|---|
| 313 | (void) UnregisterMagickInfo("PIX"); |
|---|
| 314 | } |
|---|