| 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 | #include "magick/studio.h" |
|---|
| 51 | #include "magick/blob.h" |
|---|
| 52 | #include "magick/blob-private.h" |
|---|
| 53 | #include "magick/cache.h" |
|---|
| 54 | #include "magick/color.h" |
|---|
| 55 | #include "magick/colormap-private.h" |
|---|
| 56 | #include "magick/color-private.h" |
|---|
| 57 | #include "magick/exception.h" |
|---|
| 58 | #include "magick/exception-private.h" |
|---|
| 59 | #include "magick/image.h" |
|---|
| 60 | #include "magick/image-private.h" |
|---|
| 61 | #include "magick/list.h" |
|---|
| 62 | #include "magick/magick.h" |
|---|
| 63 | #include "magick/memory_.h" |
|---|
| 64 | #include "magick/quantum-private.h" |
|---|
| 65 | #include "magick/static.h" |
|---|
| 66 | #include "magick/string_.h" |
|---|
| 67 | #include "magick/module.h" |
|---|
| 68 | #include "magick/utility.h" |
|---|
| 69 | |
|---|
| 70 | typedef struct |
|---|
| 71 | { |
|---|
| 72 | unsigned Width; |
|---|
| 73 | unsigned Height; |
|---|
| 74 | unsigned Reserved; |
|---|
| 75 | } CUTHeader; |
|---|
| 76 | |
|---|
| 77 | typedef struct |
|---|
| 78 | { |
|---|
| 79 | char FileId[2]; |
|---|
| 80 | unsigned Version; |
|---|
| 81 | unsigned Size; |
|---|
| 82 | char FileType; |
|---|
| 83 | char SubType; |
|---|
| 84 | unsigned BoardID; |
|---|
| 85 | unsigned GraphicsMode; |
|---|
| 86 | unsigned MaxIndex; |
|---|
| 87 | unsigned MaxRed; |
|---|
| 88 | unsigned MaxGreen; |
|---|
| 89 | unsigned MaxBlue; |
|---|
| 90 | char PaletteId[20]; |
|---|
| 91 | } CUTPalHeader; |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | static void InsertRow(long depth,unsigned char *p,long y,Image *image) |
|---|
| 95 | { |
|---|
| 96 | ExceptionInfo |
|---|
| 97 | *exception; |
|---|
| 98 | |
|---|
| 99 | unsigned long bit; long x; |
|---|
| 100 | register PixelPacket *q; |
|---|
| 101 | IndexPacket index; |
|---|
| 102 | register IndexPacket *indexes; |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | index=(IndexPacket) 0; |
|---|
| 106 | exception=(&image->exception); |
|---|
| 107 | switch (depth) |
|---|
| 108 | { |
|---|
| 109 | case 1: |
|---|
| 110 | { |
|---|
| 111 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
|---|
| 112 | if (q == (PixelPacket *) NULL) |
|---|
| 113 | break; |
|---|
| 114 | indexes=GetAuthenticIndexQueue(image); |
|---|
| 115 | for (x=0; x < ((long) image->columns-7); x+=8) |
|---|
| 116 | { |
|---|
| 117 | for (bit=0; bit < 8; bit++) |
|---|
| 118 | { |
|---|
| 119 | index=(IndexPacket) ((((*p) & (0x80 >> bit)) != 0) ? 0x01 : 0x00); |
|---|
| 120 | indexes[x+bit]=index; |
|---|
| 121 | *q++=image->colormap[(long) index]; |
|---|
| 122 | } |
|---|
| 123 | p++; |
|---|
| 124 | } |
|---|
| 125 | if ((image->columns % 8) != 0) |
|---|
| 126 | { |
|---|
| 127 | for (bit=0; bit < (image->columns % 8); bit++) |
|---|
| 128 | { |
|---|
| 129 | index=(IndexPacket) ((((*p) & (0x80 >> bit)) != 0) ? 0x01 : 0x00); |
|---|
| 130 | indexes[x+bit]=index; |
|---|
| 131 | *q++=image->colormap[(long) index]; |
|---|
| 132 | } |
|---|
| 133 | p++; |
|---|
| 134 | } |
|---|
| 135 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
|---|
| 136 | break; |
|---|
| 137 | break; |
|---|
| 138 | } |
|---|
| 139 | case 2: |
|---|
| 140 | { |
|---|
| 141 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
|---|
| 142 | if (q == (PixelPacket *) NULL) |
|---|
| 143 | break; |
|---|
| 144 | indexes=GetAuthenticIndexQueue(image); |
|---|
| 145 | for (x=0; x < ((long) image->columns-1); x+=2) |
|---|
| 146 | { |
|---|
| 147 | index=ConstrainColormapIndex(image,(*p >> 6) & 0x3); |
|---|
| 148 | indexes[x]=index; |
|---|
| 149 | *q++=image->colormap[(long) index]; |
|---|
| 150 | index=ConstrainColormapIndex(image,(*p >> 4) & 0x3); |
|---|
| 151 | indexes[x]=index; |
|---|
| 152 | *q++=image->colormap[(long) index]; |
|---|
| 153 | index=ConstrainColormapIndex(image,(*p >> 2) & 0x3); |
|---|
| 154 | indexes[x]=index; |
|---|
| 155 | *q++=image->colormap[(long) index]; |
|---|
| 156 | index=ConstrainColormapIndex(image,(*p) & 0x3); |
|---|
| 157 | indexes[x+1]=index; |
|---|
| 158 | *q++=image->colormap[(long) index]; |
|---|
| 159 | p++; |
|---|
| 160 | } |
|---|
| 161 | if ((image->columns % 4) != 0) |
|---|
| 162 | { |
|---|
| 163 | index=ConstrainColormapIndex(image,(*p >> 6) & 0x3); |
|---|
| 164 | indexes[x]=index; |
|---|
| 165 | *q++=image->colormap[(long) index]; |
|---|
| 166 | if ((image->columns % 4) >= 1) |
|---|
| 167 | |
|---|
| 168 | { |
|---|
| 169 | index=ConstrainColormapIndex(image,(*p >> 4) & 0x3); |
|---|
| 170 | indexes[x]=index; |
|---|
| 171 | *q++=image->colormap[(long) index]; |
|---|
| 172 | if ((image->columns % 4) >= 2) |
|---|
| 173 | |
|---|
| 174 | { |
|---|
| 175 | index=ConstrainColormapIndex(image,(*p >> 2) & 0x3); |
|---|
| 176 | indexes[x]=index; |
|---|
| 177 | *q++=image->colormap[(long) index]; |
|---|
| 178 | } |
|---|
| 179 | } |
|---|
| 180 | p++; |
|---|
| 181 | } |
|---|
| 182 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
|---|
| 183 | break; |
|---|
| 184 | break; |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | case 4: |
|---|
| 188 | { |
|---|
| 189 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
|---|
| 190 | if (q == (PixelPacket *) NULL) |
|---|
| 191 | break; |
|---|
| 192 | indexes=GetAuthenticIndexQueue(image); |
|---|
| 193 | for (x=0; x < ((long) image->columns-1); x+=2) |
|---|
| 194 | { |
|---|
| 195 | index=ConstrainColormapIndex(image,(*p >> 4) & 0xf); |
|---|
| 196 | indexes[x]=index; |
|---|
| 197 | *q++=image->colormap[(long) index]; |
|---|
| 198 | index=ConstrainColormapIndex(image,(*p) & 0xf); |
|---|
| 199 | indexes[x+1]=index; |
|---|
| 200 | *q++=image->colormap[(long) index]; |
|---|
| 201 | p++; |
|---|
| 202 | } |
|---|
| 203 | if ((image->columns % 2) != 0) |
|---|
| 204 | { |
|---|
| 205 | index=ConstrainColormapIndex(image,(*p >> 4) & 0xf); |
|---|
| 206 | indexes[x]=index; |
|---|
| 207 | *q++=image->colormap[(long) index]; |
|---|
| 208 | p++; |
|---|
| 209 | } |
|---|
| 210 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
|---|
| 211 | break; |
|---|
| 212 | break; |
|---|
| 213 | } |
|---|
| 214 | case 8: |
|---|
| 215 | { |
|---|
| 216 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
|---|
| 217 | if (q == (PixelPacket *) NULL) break; |
|---|
| 218 | indexes=GetAuthenticIndexQueue(image); |
|---|
| 219 | |
|---|
| 220 | for (x=0; x < (long) image->columns; x++) |
|---|
| 221 | { |
|---|
| 222 | index=ConstrainColormapIndex(image,*p); |
|---|
| 223 | indexes[x]=index; |
|---|
| 224 | *q++=image->colormap[(long) index]; |
|---|
| 225 | p++; |
|---|
| 226 | } |
|---|
| 227 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
|---|
| 228 | break; |
|---|
| 229 | } |
|---|
| 230 | break; |
|---|
| 231 | |
|---|
| 232 | } |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | static int GetCutColors(Image *image) |
|---|
| 239 | { |
|---|
| 240 | ExceptionInfo |
|---|
| 241 | *exception; |
|---|
| 242 | |
|---|
| 243 | long |
|---|
| 244 | x, |
|---|
| 245 | y; |
|---|
| 246 | |
|---|
| 247 | PixelPacket |
|---|
| 248 | *q; |
|---|
| 249 | |
|---|
| 250 | Quantum |
|---|
| 251 | intensity, |
|---|
| 252 | scale_intensity; |
|---|
| 253 | |
|---|
| 254 | exception=(&image->exception); |
|---|
| 255 | intensity=0; |
|---|
| 256 | scale_intensity=ScaleCharToQuantum(16); |
|---|
| 257 | for (y=0; y < (long) image->rows; y++) |
|---|
| 258 | { |
|---|
| 259 | q=GetAuthenticPixels(image,0,y,image->columns,1,exception); |
|---|
| 260 | for (x=0; x < (long) image->columns; x++) |
|---|
| 261 | { |
|---|
| 262 | if (intensity < q->red) |
|---|
| 263 | intensity=q->red; |
|---|
| 264 | if (intensity >= scale_intensity) |
|---|
| 265 | return(255); |
|---|
| 266 | q++; |
|---|
| 267 | } |
|---|
| 268 | } |
|---|
| 269 | if (intensity < ScaleCharToQuantum(2)) |
|---|
| 270 | return(2); |
|---|
| 271 | if (intensity < ScaleCharToQuantum(16)) |
|---|
| 272 | return(16); |
|---|
| 273 | return((int) intensity); |
|---|
| 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 | static Image *ReadCUTImage(const ImageInfo *image_info,ExceptionInfo *exception) |
|---|
| 303 | { |
|---|
| 304 | Image *image,*palette; |
|---|
| 305 | ImageInfo *clone_info; |
|---|
| 306 | MagickBooleanType status; |
|---|
| 307 | |
|---|
| 308 | MagickOffsetType |
|---|
| 309 | offset; |
|---|
| 310 | |
|---|
| 311 | unsigned long EncodedByte; |
|---|
| 312 | unsigned char RunCount,RunValue,RunCountMasked; |
|---|
| 313 | CUTHeader Header; |
|---|
| 314 | CUTPalHeader PalHeader; |
|---|
| 315 | long depth; |
|---|
| 316 | long i,j; |
|---|
| 317 | long ldblk; |
|---|
| 318 | unsigned char *BImgBuff=NULL,*ptrB; |
|---|
| 319 | PixelPacket *q; |
|---|
| 320 | |
|---|
| 321 | ssize_t |
|---|
| 322 | count; |
|---|
| 323 | |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | |
|---|
| 327 | assert(image_info != (const ImageInfo *) NULL); |
|---|
| 328 | assert(image_info->signature == MagickSignature); |
|---|
| 329 | if (image_info->debug != MagickFalse) |
|---|
| 330 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
|---|
| 331 | image_info->filename); |
|---|
| 332 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 333 | assert(exception->signature == MagickSignature); |
|---|
| 334 | image=AcquireImage(image_info); |
|---|
| 335 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
|---|
| 336 | if (status == MagickFalse) |
|---|
| 337 | { |
|---|
| 338 | image=DestroyImageList(image); |
|---|
| 339 | return((Image *) NULL); |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | |
|---|
| 343 | |
|---|
| 344 | palette=NULL; |
|---|
| 345 | clone_info=NULL; |
|---|
| 346 | Header.Width=ReadBlobLSBShort(image); |
|---|
| 347 | Header.Height=ReadBlobLSBShort(image); |
|---|
| 348 | Header.Reserved=ReadBlobLSBShort(image); |
|---|
| 349 | |
|---|
| 350 | if (Header.Width==0 || Header.Height==0 || Header.Reserved!=0) |
|---|
| 351 | CUT_KO: ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
|---|
| 352 | |
|---|
| 353 | |
|---|
| 354 | EncodedByte=ReadBlobLSBShort(image); |
|---|
| 355 | RunCount=(unsigned char) ReadBlobByte(image); |
|---|
| 356 | RunCountMasked=RunCount & 0x7F; |
|---|
| 357 | ldblk=0; |
|---|
| 358 | while((int) RunCountMasked!=0) |
|---|
| 359 | { |
|---|
| 360 | i=1; |
|---|
| 361 | if((int) RunCount<0x80) i=(long) RunCountMasked; |
|---|
| 362 | offset=SeekBlob(image,TellBlob(image)+i,SEEK_SET); |
|---|
| 363 | if (offset < 0) |
|---|
| 364 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
|---|
| 365 | if(EOFBlob(image) != MagickFalse) goto CUT_KO; |
|---|
| 366 | EncodedByte-=i+1; |
|---|
| 367 | ldblk+=(long) RunCountMasked; |
|---|
| 368 | |
|---|
| 369 | RunCount=(unsigned char) ReadBlobByte(image); |
|---|
| 370 | if(EOFBlob(image) != MagickFalse) goto CUT_KO; |
|---|
| 371 | RunCountMasked=RunCount & 0x7F; |
|---|
| 372 | } |
|---|
| 373 | if(EncodedByte!=1) goto CUT_KO; |
|---|
| 374 | i=0; |
|---|
| 375 | if(ldblk==(int) Header.Width) i=8; |
|---|
| 376 | if(2*ldblk==(int) Header.Width) i=4; |
|---|
| 377 | if(8*ldblk==(int) Header.Width) i=1; |
|---|
| 378 | if(i==0) goto CUT_KO; |
|---|
| 379 | depth=i; |
|---|
| 380 | |
|---|
| 381 | image->columns=Header.Width; |
|---|
| 382 | image->rows=Header.Height; |
|---|
| 383 | image->depth=8; |
|---|
| 384 | image->colors=(unsigned long) (GetQuantumRange(1UL*i)+1); |
|---|
| 385 | |
|---|
| 386 | if (image_info->ping) goto Finish; |
|---|
| 387 | |
|---|
| 388 | |
|---|
| 389 | if ((clone_info=CloneImageInfo(image_info)) == NULL) goto NoPalette; |
|---|
| 390 | |
|---|
| 391 | |
|---|
| 392 | i=(long) strlen(clone_info->filename); |
|---|
| 393 | j=i; |
|---|
| 394 | while(--i>0) |
|---|
| 395 | { |
|---|
| 396 | if(clone_info->filename[i]=='.') |
|---|
| 397 | { |
|---|
| 398 | break; |
|---|
| 399 | } |
|---|
| 400 | if(clone_info->filename[i]=='/' || clone_info->filename[i]=='\\' || |
|---|
| 401 | clone_info->filename[i]==':' ) |
|---|
| 402 | { |
|---|
| 403 | i=j; |
|---|
| 404 | break; |
|---|
| 405 | } |
|---|
| 406 | } |
|---|
| 407 | |
|---|
| 408 | (void) CopyMagickString(clone_info->filename+i,".PAL",(size_t) |
|---|
| 409 | (MaxTextExtent-i)); |
|---|
| 410 | if((clone_info->file=OpenMagickStream(clone_info->filename,"rb"))==NULL) |
|---|
| 411 | { |
|---|
| 412 | (void) CopyMagickString(clone_info->filename+i,".pal",(size_t) |
|---|
| 413 | (MaxTextExtent-i)); |
|---|
| 414 | if((clone_info->file=OpenMagickStream(clone_info->filename,"rb"))==NULL) |
|---|
| 415 | { |
|---|
| 416 | clone_info->filename[i]='\0'; |
|---|
| 417 | if((clone_info->file=OpenMagickStream(clone_info->filename,"rb"))==NULL) |
|---|
| 418 | { |
|---|
| 419 | clone_info=DestroyImageInfo(clone_info); |
|---|
| 420 | clone_info=NULL; |
|---|
| 421 | goto NoPalette; |
|---|
| 422 | } |
|---|
| 423 | } |
|---|
| 424 | } |
|---|
| 425 | |
|---|
| 426 | if( (palette=AcquireImage(clone_info))==NULL ) goto NoPalette; |
|---|
| 427 | status=OpenBlob(clone_info,palette,ReadBinaryBlobMode,exception); |
|---|
| 428 | if (status == MagickFalse) |
|---|
| 429 | { |
|---|
| 430 | ErasePalette: |
|---|
| 431 | palette=DestroyImage(palette); |
|---|
| 432 | palette=NULL; |
|---|
| 433 | goto NoPalette; |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | |
|---|
| 437 | if(palette!=NULL) |
|---|
| 438 | { |
|---|
| 439 | count=ReadBlob(palette,2,(unsigned char *) PalHeader.FileId); |
|---|
| 440 | if(strncmp(PalHeader.FileId,"AH",2) != 0) goto ErasePalette; |
|---|
| 441 | PalHeader.Version=ReadBlobLSBShort(palette); |
|---|
| 442 | PalHeader.Size=ReadBlobLSBShort(palette); |
|---|
| 443 | PalHeader.FileType=(char) ReadBlobByte(palette); |
|---|
| 444 | PalHeader.SubType=(char) ReadBlobByte(palette); |
|---|
| 445 | PalHeader.BoardID=ReadBlobLSBShort(palette); |
|---|
| 446 | PalHeader.GraphicsMode=ReadBlobLSBShort(palette); |
|---|
| 447 | PalHeader.MaxIndex=ReadBlobLSBShort(palette); |
|---|
| 448 | PalHeader.MaxRed=ReadBlobLSBShort(palette); |
|---|
| 449 | PalHeader.MaxGreen=ReadBlobLSBShort(palette); |
|---|
| 450 | PalHeader.MaxBlue=ReadBlobLSBShort(palette); |
|---|
| 451 | count=ReadBlob(palette,20,(unsigned char *) PalHeader.PaletteId); |
|---|
| 452 | |
|---|
| 453 | if(PalHeader.MaxIndex<1) goto ErasePalette; |
|---|
| 454 | image->colors=PalHeader.MaxIndex+1; |
|---|
| 455 | if (AcquireImageColormap(image,image->colors) == MagickFalse) goto NoMemory; |
|---|
| 456 | |
|---|
| 457 | if(PalHeader.MaxRed==0) PalHeader.MaxRed=(unsigned int) QuantumRange; |
|---|
| 458 | if(PalHeader.MaxGreen==0) PalHeader.MaxGreen=(unsigned int) QuantumRange; |
|---|
| 459 | if(PalHeader.MaxBlue==0) PalHeader.MaxBlue=(unsigned int) QuantumRange; |
|---|
| 460 | |
|---|
| 461 | for(i=0;i<=(int) PalHeader.MaxIndex;i++) |
|---|
| 462 | { |
|---|
| 463 | j=(long) TellBlob(palette); |
|---|
| 464 | if((j % 512)>512-6) |
|---|
| 465 | { |
|---|
| 466 | j=((j / 512)+1)*512; |
|---|
| 467 | offset=SeekBlob(palette,j,SEEK_SET); |
|---|
| 468 | if (offset < 0) |
|---|
| 469 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
|---|
| 470 | } |
|---|
| 471 | image->colormap[i].red=(Quantum) ReadBlobLSBShort(palette); |
|---|
| 472 | if (QuantumRange != (Quantum) PalHeader.MaxRed) |
|---|
| 473 | { |
|---|
| 474 | image->colormap[i].red=ClampToQuantum(((double) |
|---|
| 475 | image->colormap[i].red*QuantumRange+(PalHeader.MaxRed>>1))/ |
|---|
| 476 | PalHeader.MaxRed); |
|---|
| 477 | } |
|---|
| 478 | image->colormap[i].green=(Quantum) ReadBlobLSBShort(palette); |
|---|
| 479 | if (QuantumRange != (Quantum) PalHeader.MaxGreen) |
|---|
| 480 | { |
|---|
| 481 | image->colormap[i].green=ClampToQuantum |
|---|
| 482 | (((double) image->colormap[i].green*QuantumRange+(PalHeader.MaxGreen>>1))/PalHeader.MaxGreen); |
|---|
| 483 | } |
|---|
| 484 | image->colormap[i].blue=(Quantum) ReadBlobLSBShort(palette); |
|---|
| 485 | if (QuantumRange != (Quantum) PalHeader.MaxBlue) |
|---|
| 486 | { |
|---|
| 487 | image->colormap[i].blue=ClampToQuantum |
|---|
| 488 | (((double)image->colormap[i].blue*QuantumRange+(PalHeader.MaxBlue>>1))/PalHeader.MaxBlue); |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | } |
|---|
| 492 | } |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | |
|---|
| 496 | NoPalette: |
|---|
| 497 | if(palette==NULL) |
|---|
| 498 | { |
|---|
| 499 | |
|---|
| 500 | image->colors=256; |
|---|
| 501 | if (AcquireImageColormap(image,image->colors) == MagickFalse) |
|---|
| 502 | { |
|---|
| 503 | NoMemory: |
|---|
| 504 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
|---|
| 505 | } |
|---|
| 506 | |
|---|
| 507 | for (i=0; i < (long)image->colors; i++) |
|---|
| 508 | { |
|---|
| 509 | image->colormap[i].red=ScaleCharToQuantum((unsigned char) i); |
|---|
| 510 | image->colormap[i].green=ScaleCharToQuantum((unsigned char) i); |
|---|
| 511 | image->colormap[i].blue=ScaleCharToQuantum((unsigned char) i); |
|---|
| 512 | } |
|---|
| 513 | } |
|---|
| 514 | |
|---|
| 515 | |
|---|
| 516 | |
|---|
| 517 | BImgBuff=(unsigned char *) AcquireQuantumMemory((size_t) ldblk, |
|---|
| 518 | sizeof(*BImgBuff)); |
|---|
| 519 | if(BImgBuff==NULL) goto NoMemory; |
|---|
| 520 | |
|---|
| 521 | offset=SeekBlob(image,6 ,SEEK_SET); |
|---|
| 522 | if (offset < 0) |
|---|
| 523 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
|---|
| 524 | for (i=0; i < (int) Header.Height; i++) |
|---|
| 525 | { |
|---|
| 526 | EncodedByte=ReadBlobLSBShort(image); |
|---|
| 527 | |
|---|
| 528 | ptrB=BImgBuff; |
|---|
| 529 | j=ldblk; |
|---|
| 530 | |
|---|
| 531 | RunCount=(unsigned char) ReadBlobByte(image); |
|---|
| 532 | RunCountMasked=RunCount & 0x7F; |
|---|
| 533 | |
|---|
| 534 | while((int) RunCountMasked!=0) |
|---|
| 535 | { |
|---|
| 536 | if((long) RunCountMasked>j) |
|---|
| 537 | { |
|---|
| 538 | RunCountMasked=(unsigned char) j; |
|---|
| 539 | if(j==0) |
|---|
| 540 | { |
|---|
| 541 | break; |
|---|
| 542 | } |
|---|
| 543 | } |
|---|
| 544 | |
|---|
| 545 | if((int) RunCount>0x80) |
|---|
| 546 | { |
|---|
| 547 | RunValue=(unsigned char) ReadBlobByte(image); |
|---|
| 548 | (void) ResetMagickMemory(ptrB,(int) RunValue,(size_t) RunCountMasked); |
|---|
| 549 | } |
|---|
| 550 | else { |
|---|
| 551 | count=ReadBlob(image,(size_t) RunCountMasked,ptrB); |
|---|
| 552 | } |
|---|
| 553 | |
|---|
| 554 | ptrB+=(int) RunCountMasked; |
|---|
| 555 | j-=(int) RunCountMasked; |
|---|
| 556 | |
|---|
| 557 | if (EOFBlob(image) != MagickFalse) goto Finish; |
|---|
| 558 | RunCount=(unsigned char) ReadBlobByte(image); |
|---|
| 559 | RunCountMasked=RunCount & 0x7F; |
|---|
| 560 | } |
|---|
| 561 | |
|---|
| 562 | InsertRow(depth,BImgBuff,i,image); |
|---|
| 563 | } |
|---|
| 564 | |
|---|
| 565 | |
|---|
| 566 | |
|---|
| 567 | |
|---|
| 568 | if(palette==NULL) |
|---|
| 569 | { |
|---|
| 570 | if ((image->storage_class == PseudoClass) && |
|---|
| 571 | (IsGrayImage(image,&image->exception) != MagickFalse)) |
|---|
| 572 | { |
|---|
| 573 | if(GetCutColors(image)==2) |
|---|
| 574 | { |
|---|
| 575 | for (i=0; i < (long)image->colors; i++) |
|---|
| 576 | { |
|---|
| 577 | register Quantum |
|---|
| 578 | sample; |
|---|
| 579 | sample=ScaleCharToQuantum((unsigned char) i); |
|---|
| 580 | if(image->colormap[i].red!=sample) goto Finish; |
|---|
| 581 | if(image->colormap[i].green!=sample) goto Finish; |
|---|
| 582 | if(image->colormap[i].blue!=sample) goto Finish; |
|---|
| 583 | } |
|---|
| 584 | |
|---|
| 585 | image->colormap[1].red=image->colormap[1].green=image->colormap[1].blue=(Quantum) QuantumRange; |
|---|
| 586 | for (i=0; i < (long)image->rows; i++) |
|---|
| 587 | { |
|---|
| 588 | q=QueueAuthenticPixels(image,0,i,image->columns,1,exception); |
|---|
| 589 | for (j=0; j < (long)image->columns; j++) |
|---|
| 590 | { |
|---|
| 591 | if(q->red==ScaleCharToQuantum(1)) |
|---|
| 592 | { |
|---|
| 593 | q->red=q->green=q->blue=(Quantum) QuantumRange; |
|---|
| 594 | } |
|---|
| 595 | q++; |
|---|
| 596 | } |
|---|
| 597 | if (SyncAuthenticPixels(image,exception) == MagickFalse) goto Finish; |
|---|
| 598 | } |
|---|
| 599 | } |
|---|
| 600 | } |
|---|
| 601 | } |
|---|
| 602 | |
|---|
| 603 | Finish: |
|---|
| 604 | if (BImgBuff != NULL) |
|---|
| 605 | BImgBuff=(unsigned char *) RelinquishMagickMemory(BImgBuff); |
|---|
| 606 | if (palette != NULL) |
|---|
| 607 | palette=DestroyImage(palette); |
|---|
| 608 | if (clone_info != NULL) |
|---|
| 609 | clone_info=DestroyImageInfo(clone_info); |
|---|
| 610 | if (EOFBlob(image) != MagickFalse) |
|---|
| 611 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
|---|
| 612 | image->filename); |
|---|
| 613 | (void) CloseBlob(image); |
|---|
| 614 | return(GetFirstImageInList(image)); |
|---|
| 615 | } |
|---|
| 616 | |
|---|
| 617 | |
|---|
| 618 | |
|---|
| 619 | |
|---|
| 620 | |
|---|
| 621 | |
|---|
| 622 | |
|---|
| 623 | |
|---|
| 624 | |
|---|
| 625 | |
|---|
| 626 | |
|---|
| 627 | |
|---|
| 628 | |
|---|
| 629 | |
|---|
| 630 | |
|---|
| 631 | |
|---|
| 632 | |
|---|
| 633 | |
|---|
| 634 | |
|---|
| 635 | |
|---|
| 636 | |
|---|
| 637 | |
|---|
| 638 | |
|---|
| 639 | |
|---|
| 640 | ModuleExport unsigned long RegisterCUTImage(void) |
|---|
| 641 | { |
|---|
| 642 | MagickInfo |
|---|
| 643 | *entry; |
|---|
| 644 | |
|---|
| 645 | entry=SetMagickInfo("CUT"); |
|---|
| 646 | entry->decoder=(DecodeImageHandler *) ReadCUTImage; |
|---|
| 647 | entry->seekable_stream=MagickTrue; |
|---|
| 648 | entry->description=ConstantString("DR Halo"); |
|---|
| 649 | entry->module=ConstantString("CUT"); |
|---|
| 650 | (void) RegisterMagickInfo(entry); |
|---|
| 651 | return(MagickImageCoderSignature); |
|---|
| 652 | } |
|---|
| 653 | |
|---|
| 654 | |
|---|
| 655 | |
|---|
| 656 | |
|---|
| 657 | |
|---|
| 658 | |
|---|
| 659 | |
|---|
| 660 | |
|---|
| 661 | |
|---|
| 662 | |
|---|
| 663 | |
|---|
| 664 | |
|---|
| 665 | |
|---|
| 666 | |
|---|
| 667 | |
|---|
| 668 | |
|---|
| 669 | |
|---|
| 670 | |
|---|
| 671 | |
|---|
| 672 | |
|---|
| 673 | ModuleExport void UnregisterCUTImage(void) |
|---|
| 674 | { |
|---|
| 675 | (void) UnregisterMagickInfo("CUT"); |
|---|
| 676 | } |
|---|