2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read/Write Truevision Targa Image Format %
20 % Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "MagickCore/studio.h"
43 #include "MagickCore/attribute.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/cache.h"
47 #include "MagickCore/color-private.h"
48 #include "MagickCore/colormap.h"
49 #include "MagickCore/colormap-private.h"
50 #include "MagickCore/colorspace.h"
51 #include "MagickCore/colorspace-private.h"
52 #include "MagickCore/exception.h"
53 #include "MagickCore/exception-private.h"
54 #include "MagickCore/image.h"
55 #include "MagickCore/image-private.h"
56 #include "MagickCore/list.h"
57 #include "MagickCore/magick.h"
58 #include "MagickCore/memory_.h"
59 #include "MagickCore/monitor.h"
60 #include "MagickCore/monitor-private.h"
61 #include "MagickCore/pixel-accessor.h"
62 #include "MagickCore/property.h"
63 #include "MagickCore/quantum-private.h"
64 #include "MagickCore/static.h"
65 #include "MagickCore/string_.h"
66 #include "MagickCore/module.h"
69 Enumerated declaractions.
82 Typedef declaractions.
84 typedef struct _TGAInfo
112 Forward declarations.
114 static MagickBooleanType
115 WriteTGAImage(const ImageInfo *,Image *,ExceptionInfo *);
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122 % R e a d T G A I m a g e %
126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 % ReadTGAImage() reads a Truevision TGA image file and returns it.
129 % It allocates the memory necessary for the new Image structure and returns
130 % a pointer to the new image.
132 % The format of the ReadTGAImage method is:
134 % Image *ReadTGAImage(const ImageInfo *image_info,ExceptionInfo *exception)
136 % A description of each parameter follows:
138 % o image_info: the image info.
140 % o exception: return any errors or warnings in this structure.
143 static Image *ReadTGAImage(const ImageInfo *image_info,
144 ExceptionInfo *exception)
191 assert(image_info != (const ImageInfo *) NULL);
192 assert(image_info->signature == MagickSignature);
193 if (image_info->debug != MagickFalse)
194 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
195 image_info->filename);
196 assert(exception != (ExceptionInfo *) NULL);
197 assert(exception->signature == MagickSignature);
198 image=AcquireImage(image_info,exception);
199 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
200 if (status == MagickFalse)
202 image=DestroyImageList(image);
203 return((Image *) NULL);
206 Read TGA header information.
208 count=ReadBlob(image,1,&tga_info.id_length);
209 tga_info.colormap_type=(unsigned char) ReadBlobByte(image);
210 tga_info.image_type=(TGAImageType) ReadBlobByte(image);
212 ((tga_info.image_type != TGAColormap) &&
213 (tga_info.image_type != TGARGB) &&
214 (tga_info.image_type != TGAMonochrome) &&
215 (tga_info.image_type != TGARLEColormap) &&
216 (tga_info.image_type != TGARLERGB) &&
217 (tga_info.image_type != TGARLEMonochrome)) ||
218 (((tga_info.image_type == TGAColormap) ||
219 (tga_info.image_type == TGARLEColormap)) &&
220 (tga_info.colormap_type == 0)))
221 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
222 tga_info.colormap_index=ReadBlobLSBShort(image);
223 tga_info.colormap_length=ReadBlobLSBShort(image);
224 tga_info.colormap_size=(unsigned char) ReadBlobByte(image);
225 tga_info.x_origin=ReadBlobLSBShort(image);
226 tga_info.y_origin=ReadBlobLSBShort(image);
227 tga_info.width=(unsigned short) ReadBlobLSBShort(image);
228 tga_info.height=(unsigned short) ReadBlobLSBShort(image);
229 tga_info.bits_per_pixel=(unsigned char) ReadBlobByte(image);
230 tga_info.attributes=(unsigned char) ReadBlobByte(image);
231 if (EOFBlob(image) != MagickFalse)
232 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
233 if ((((tga_info.bits_per_pixel <= 1) || (tga_info.bits_per_pixel >= 17)) &&
234 (tga_info.bits_per_pixel != 24) && (tga_info.bits_per_pixel != 32)))
235 ThrowReaderException(CorruptImageError,"ImproperImageHeader");
237 Initialize image structure.
239 image->columns=tga_info.width;
240 image->rows=tga_info.height;
241 alpha_bits=(tga_info.attributes & 0x0FU);
242 image->alpha_trait=(alpha_bits > 0) || (tga_info.bits_per_pixel == 32) ||
243 (tga_info.colormap_size == 32) ? BlendPixelTrait : UndefinedPixelTrait;
244 if ((tga_info.image_type != TGAColormap) &&
245 (tga_info.image_type != TGARLEColormap))
246 image->depth=(size_t) ((tga_info.bits_per_pixel <= 8) ? 8 :
247 (tga_info.bits_per_pixel <= 16) ? 5 :
248 (tga_info.bits_per_pixel == 24) ? 8 :
249 (tga_info.bits_per_pixel == 32) ? 8 : 8);
251 image->depth=(size_t) ((tga_info.colormap_size <= 8) ? 8 :
252 (tga_info.colormap_size <= 16) ? 5 :
253 (tga_info.colormap_size == 24) ? 8 :
254 (tga_info.colormap_size == 32) ? 8 : 8);
255 if ((tga_info.image_type == TGAColormap) ||
256 (tga_info.image_type == TGAMonochrome) ||
257 (tga_info.image_type == TGARLEColormap) ||
258 (tga_info.image_type == TGARLEMonochrome))
259 image->storage_class=PseudoClass;
260 image->compression=NoCompression;
261 if ((tga_info.image_type == TGARLEColormap) ||
262 (tga_info.image_type == TGARLEMonochrome))
263 image->compression=RLECompression;
264 if (image->storage_class == PseudoClass)
266 if (tga_info.colormap_type != 0)
267 image->colors=tga_info.colormap_length;
274 image->colors=one << tga_info.bits_per_pixel;
275 if (AcquireImageColormap(image,image->colors,exception) == MagickFalse)
276 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
279 if (tga_info.id_length != 0)
290 length=(size_t) tga_info.id_length;
291 comment=(char *) NULL;
292 if (~length >= (MaxTextExtent-1))
293 comment=(char *) AcquireQuantumMemory(length+MaxTextExtent,
295 if (comment == (char *) NULL)
296 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
297 count=ReadBlob(image,tga_info.id_length,(unsigned char *) comment);
298 comment[tga_info.id_length]='\0';
299 (void) SetImageProperty(image,"comment",comment,exception);
300 comment=DestroyString(comment);
302 if (image_info->ping != MagickFalse)
304 (void) CloseBlob(image);
307 (void) ResetMagickMemory(&pixel,0,sizeof(pixel));
308 pixel.alpha=(MagickRealType) OpaqueAlpha;
309 if (tga_info.colormap_type != 0)
312 Read TGA raster colormap.
314 if (AcquireImageColormap(image,image->colors,exception) == MagickFalse)
315 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
316 for (i=0; i < (ssize_t) image->colors; i++)
318 switch (tga_info.colormap_size)
326 pixel.red=(MagickRealType) ScaleCharToQuantum((unsigned char)
327 ReadBlobByte(image));
328 pixel.green=pixel.red;
329 pixel.blue=pixel.red;
339 5 bits each of red green and blue.
341 j=(unsigned char) ReadBlobByte(image);
342 k=(unsigned char) ReadBlobByte(image);
343 range=GetQuantumRange(5UL);
344 pixel.red=(MagickRealType) ScaleAnyToQuantum(1UL*(k & 0x7c) >> 2,
346 pixel.green=(MagickRealType) ScaleAnyToQuantum((1UL*(k & 0x03)
347 << 3)+(1UL*(j & 0xe0) >> 5),range);
348 pixel.blue=(MagickRealType) ScaleAnyToQuantum(1UL*(j & 0x1f),range);
354 8 bits each of blue, green and red.
356 pixel.blue=(MagickRealType) ScaleCharToQuantum((unsigned char)
357 ReadBlobByte(image));
358 pixel.green=(MagickRealType) ScaleCharToQuantum((unsigned char)
359 ReadBlobByte(image));
360 pixel.red=(MagickRealType) ScaleCharToQuantum((unsigned char)
361 ReadBlobByte(image));
367 8 bits each of blue, green, red, and alpha.
369 pixel.blue=(MagickRealType) ScaleCharToQuantum((unsigned char)
370 ReadBlobByte(image));
371 pixel.green=(MagickRealType) ScaleCharToQuantum((unsigned char)
372 ReadBlobByte(image));
373 pixel.red=(MagickRealType) ScaleCharToQuantum((unsigned char)
374 ReadBlobByte(image));
375 pixel.alpha=(MagickRealType) ScaleCharToQuantum((unsigned char)
376 ReadBlobByte(image));
380 image->colormap[i]=pixel;
384 Convert TGA pixels to pixel packets.
393 for (y=0; y < (ssize_t) image->rows; y++)
396 if (((unsigned char) (tga_info.attributes & 0x20) >> 5) == 0)
397 real=image->rows-real-1;
398 q=QueueAuthenticPixels(image,0,(ssize_t) real,image->columns,1,exception);
399 if (q == (Quantum *) NULL)
401 for (x=0; x < (ssize_t) image->columns; x++)
403 if ((tga_info.image_type == TGARLEColormap) ||
404 (tga_info.image_type == TGARLERGB) ||
405 (tga_info.image_type == TGARLEMonochrome))
414 count=ReadBlob(image,1,&runlength);
416 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
417 flag=runlength & 0x80;
423 if (skip == MagickFalse)
424 switch (tga_info.bits_per_pixel)
432 index=(Quantum) ReadBlobByte(image);
433 if (tga_info.colormap_type != 0)
434 pixel=image->colormap[(ssize_t) ConstrainColormapIndex(image,
435 1UL*index,exception)];
438 pixel.red=(MagickRealType) ScaleCharToQuantum((unsigned char)
440 pixel.green=(MagickRealType) ScaleCharToQuantum((unsigned char)
442 pixel.blue=(MagickRealType) ScaleCharToQuantum((unsigned char)
456 if (ReadBlob(image,2,pixels) != 2)
457 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
460 range=GetQuantumRange(5UL);
461 pixel.red=(MagickRealType) ScaleAnyToQuantum(1UL*(k & 0x7c) >> 2,
463 pixel.green=(MagickRealType) ScaleAnyToQuantum((1UL*(k & 0x03)
464 << 3)+(1UL*(j & 0xe0) >> 5),range);
465 pixel.blue=(MagickRealType) ScaleAnyToQuantum(1UL*(j & 0x1f),range);
466 if (image->alpha_trait == BlendPixelTrait)
467 pixel.alpha=(MagickRealType) ((k & 0x80) == 0 ? (Quantum)
468 OpaqueAlpha : (Quantum) TransparentAlpha);
469 if (image->storage_class == PseudoClass)
470 index=ConstrainColormapIndex(image,((size_t) k << 8)+j,exception);
478 if (ReadBlob(image,3,pixels) != 3)
479 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
480 pixel.blue=(MagickRealType) ScaleCharToQuantum(pixels[0]);
481 pixel.green=(MagickRealType) ScaleCharToQuantum(pixels[1]);
482 pixel.red=(MagickRealType) ScaleCharToQuantum(pixels[2]);
490 if (ReadBlob(image,4,pixels) != 4)
491 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
492 pixel.blue=(MagickRealType) ScaleCharToQuantum(pixels[0]);
493 pixel.green=(MagickRealType) ScaleCharToQuantum(pixels[1]);
494 pixel.red=(MagickRealType) ScaleCharToQuantum(pixels[2]);
495 pixel.alpha=(MagickRealType) ScaleCharToQuantum(pixels[3]);
499 if (status == MagickFalse)
500 ThrowReaderException(CorruptImageError,"UnableToReadImageData");
501 if (image->storage_class == PseudoClass)
502 SetPixelIndex(image,index,q);
503 SetPixelRed(image,ClampToQuantum(pixel.red),q);
504 SetPixelGreen(image,ClampToQuantum(pixel.green),q);
505 SetPixelBlue(image,ClampToQuantum(pixel.blue),q);
506 if (image->alpha_trait == BlendPixelTrait)
507 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q);
508 q+=GetPixelChannels(image);
510 if (((tga_info.attributes & 0xc0) >> 6) == 4)
513 if (((tga_info.attributes & 0xc0) >> 6) == 2)
517 if (offset >= image->rows)
522 if (SyncAuthenticPixels(image,exception) == MagickFalse)
524 if (image->previous == (Image *) NULL)
526 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
528 if (status == MagickFalse)
532 if (EOFBlob(image) != MagickFalse)
533 ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
535 (void) CloseBlob(image);
536 return(GetFirstImageInList(image));
540 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
544 % R e g i s t e r T G A I m a g e %
548 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
550 % RegisterTGAImage() adds properties for the TGA image format to
551 % the list of supported formats. The properties include the image format
552 % tag, a method to read and/or write the format, whether the format
553 % supports the saving of more than one frame to the same file or blob,
554 % whether the format supports native in-memory I/O, and a brief
555 % description of the format.
557 % The format of the RegisterTGAImage method is:
559 % size_t RegisterTGAImage(void)
562 ModuleExport size_t RegisterTGAImage(void)
567 entry=SetMagickInfo("ICB");
568 entry->decoder=(DecodeImageHandler *) ReadTGAImage;
569 entry->encoder=(EncodeImageHandler *) WriteTGAImage;
570 entry->adjoin=MagickFalse;
571 entry->description=ConstantString("Truevision Targa image");
572 entry->module=ConstantString("TGA");
573 (void) RegisterMagickInfo(entry);
574 entry=SetMagickInfo("TGA");
575 entry->decoder=(DecodeImageHandler *) ReadTGAImage;
576 entry->encoder=(EncodeImageHandler *) WriteTGAImage;
577 entry->adjoin=MagickFalse;
578 entry->description=ConstantString("Truevision Targa image");
579 entry->module=ConstantString("TGA");
580 (void) RegisterMagickInfo(entry);
581 entry=SetMagickInfo("VDA");
582 entry->decoder=(DecodeImageHandler *) ReadTGAImage;
583 entry->encoder=(EncodeImageHandler *) WriteTGAImage;
584 entry->adjoin=MagickFalse;
585 entry->description=ConstantString("Truevision Targa image");
586 entry->module=ConstantString("TGA");
587 (void) RegisterMagickInfo(entry);
588 entry=SetMagickInfo("VST");
589 entry->decoder=(DecodeImageHandler *) ReadTGAImage;
590 entry->encoder=(EncodeImageHandler *) WriteTGAImage;
591 entry->adjoin=MagickFalse;
592 entry->description=ConstantString("Truevision Targa image");
593 entry->module=ConstantString("TGA");
594 (void) RegisterMagickInfo(entry);
595 return(MagickImageCoderSignature);
599 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
603 % U n r e g i s t e r T G A I m a g e %
607 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
609 % UnregisterTGAImage() removes format registrations made by the
610 % TGA module from the list of supported formats.
612 % The format of the UnregisterTGAImage method is:
614 % UnregisterTGAImage(void)
617 ModuleExport void UnregisterTGAImage(void)
619 (void) UnregisterMagickInfo("ICB");
620 (void) UnregisterMagickInfo("TGA");
621 (void) UnregisterMagickInfo("VDA");
622 (void) UnregisterMagickInfo("VST");
626 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
630 % W r i t e T G A I m a g e %
634 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
636 % WriteTGAImage() writes a image in the Truevision Targa rasterfile
639 % The format of the WriteTGAImage method is:
641 % MagickBooleanType WriteTGAImage(const ImageInfo *image_info,
642 % Image *image,ExceptionInfo *exception)
644 % A description of each parameter follows.
646 % o image_info: the image info.
648 % o image: The image.
652 static inline size_t MagickMin(const size_t x,const size_t y)
659 static inline void WriteTGAPixel(Image *image,TGAImageType image_type,
662 if (image_type == TGAColormap || image_type == TGARLEColormap)
663 (void) WriteBlobByte(image,(unsigned char) GetPixelIndex(image,p));
666 if (image_type == TGAMonochrome || image_type == TGARLEMonochrome)
667 (void) WriteBlobByte(image,ScaleQuantumToChar(ClampToQuantum(
668 GetPixelLuma(image,p))));
671 (void) WriteBlobByte(image,ScaleQuantumToChar(GetPixelBlue(image,
673 (void) WriteBlobByte(image,ScaleQuantumToChar(GetPixelGreen(image,
675 (void) WriteBlobByte(image,ScaleQuantumToChar(GetPixelRed(image,p)));
676 if (image->alpha_trait == BlendPixelTrait)
677 (void) WriteBlobByte(image,ScaleQuantumToChar(GetPixelAlpha(image,
683 static MagickBooleanType WriteTGAImage(const ImageInfo *image_info,Image *image,
684 ExceptionInfo *exception)
695 register const Quantum
704 register unsigned char
718 Open output image file.
720 assert(image_info != (const ImageInfo *) NULL);
721 assert(image_info->signature == MagickSignature);
722 assert(image != (Image *) NULL);
723 assert(image->signature == MagickSignature);
724 if (image->debug != MagickFalse)
725 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
726 assert(exception != (ExceptionInfo *) NULL);
727 assert(exception->signature == MagickSignature);
728 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
729 if (status == MagickFalse)
732 Initialize TGA raster file header.
734 if ((image->columns > 65535L) || (image->rows > 65535L))
735 ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
736 (void) TransformImageColorspace(image,sRGBColorspace,exception);
737 compression=image->compression;
738 if (image_info->compression != UndefinedCompression)
739 compression=image_info->compression;
740 tga_info.id_length=0;
741 value=GetImageProperty(image,"comment",exception);
742 if (value != (const char *) NULL)
743 tga_info.id_length=(unsigned char) MagickMin(strlen(value),255);
744 tga_info.colormap_type=0;
745 tga_info.colormap_index=0;
746 tga_info.colormap_length=0;
747 tga_info.colormap_size=0;
750 tga_info.width=(unsigned short) image->columns;
751 tga_info.height=(unsigned short) image->rows;
752 tga_info.bits_per_pixel=8;
753 tga_info.attributes=0;
754 if ((image_info->type != TrueColorType) &&
755 (image_info->type != TrueColorMatteType) &&
756 (image_info->type != PaletteType) &&
757 (image->alpha_trait != BlendPixelTrait) &&
758 (IsImageGray(image,exception) != MagickFalse))
759 tga_info.image_type=compression == RLECompression ? TGARLEMonochrome :
762 if ((image->storage_class == DirectClass) || (image->colors > 256))
765 Full color TGA raster.
767 tga_info.image_type=compression == RLECompression ? TGARLERGB :
769 tga_info.bits_per_pixel=24;
770 if (image->alpha_trait == BlendPixelTrait)
772 tga_info.bits_per_pixel=32;
773 tga_info.attributes=8; /* # of alpha bits */
779 Colormapped TGA raster.
781 tga_info.image_type=compression == RLECompression ? TGARLEColormap :
783 tga_info.colormap_type=1;
784 tga_info.colormap_length=(unsigned short) image->colors;
785 tga_info.colormap_size=24;
790 (void) WriteBlobByte(image,tga_info.id_length);
791 (void) WriteBlobByte(image,tga_info.colormap_type);
792 (void) WriteBlobByte(image,(unsigned char) tga_info.image_type);
793 (void) WriteBlobLSBShort(image,tga_info.colormap_index);
794 (void) WriteBlobLSBShort(image,tga_info.colormap_length);
795 (void) WriteBlobByte(image,tga_info.colormap_size);
796 (void) WriteBlobLSBShort(image,tga_info.x_origin);
797 (void) WriteBlobLSBShort(image,tga_info.y_origin);
798 (void) WriteBlobLSBShort(image,tga_info.width);
799 (void) WriteBlobLSBShort(image,tga_info.height);
800 (void) WriteBlobByte(image,tga_info.bits_per_pixel);
801 (void) WriteBlobByte(image,tga_info.attributes);
802 if (tga_info.id_length != 0)
803 (void) WriteBlob(image,tga_info.id_length,(unsigned char *)
805 if (tga_info.colormap_type != 0)
811 Dump colormap to file (blue, green, red byte order).
813 targa_colormap=(unsigned char *) AcquireQuantumMemory((size_t)
814 tga_info.colormap_length,3UL*sizeof(*targa_colormap));
815 if (targa_colormap == (unsigned char *) NULL)
816 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
818 for (i=0; i < (ssize_t) image->colors; i++)
820 *q++=ScaleQuantumToChar(ClampToQuantum(image->colormap[i].blue));
821 *q++=ScaleQuantumToChar(ClampToQuantum(image->colormap[i].green));
822 *q++=ScaleQuantumToChar(ClampToQuantum(image->colormap[i].red));
824 (void) WriteBlob(image,(size_t) (3*tga_info.colormap_length),
826 targa_colormap=(unsigned char *) RelinquishMagickMemory(targa_colormap);
829 Convert MIFF to TGA raster pixels.
831 channels=GetPixelChannels(image);
832 for (y=(ssize_t) (image->rows-1); y >= 0; y--)
834 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
835 if (p == (const Quantum *) NULL)
837 if (compression == RLECompression)
841 while (x < (ssize_t) image->columns)
844 while ((i < 128) && (count + i < 128) &&
845 ((x + i) < (ssize_t) image->columns))
847 if (tga_info.image_type == TGARLEColormap)
849 if (GetPixelIndex(image,p+(i*channels)) !=
850 GetPixelIndex(image,p+((i-1)*channels)))
853 else if (tga_info.image_type == TGARLEMonochrome)
855 if (GetPixelLuma(image,p+(i*channels)) !=
856 GetPixelLuma(image,p+((i-1)*channels)))
861 if ((GetPixelBlue(image,p+(i*channels)) !=
862 GetPixelBlue(image,p+((i-1)*channels))) ||
863 (GetPixelGreen(image,p+(i*channels)) !=
864 GetPixelGreen(image,p+((i-1)*channels))) ||
865 (GetPixelRed(image,p+(i*channels)) !=
866 GetPixelRed(image,p+((i-1)*channels))))
868 if ((image->alpha_trait == BlendPixelTrait) &&
869 (GetPixelAlpha(image,p+(i*channels)) !=
870 GetPixelAlpha(image,p+(i-1)*channels)))
880 if ((i >= 3) || (count == 128) ||
881 ((x + i) == (ssize_t) image->columns))
885 (void) WriteBlobByte(image,(unsigned char) (--count));
888 WriteTGAPixel(image,tga_info.image_type,p-((count+1)*
897 WriteBlobByte(image,(unsigned char) ((i-1) | 0x80));
898 WriteTGAPixel(image,tga_info.image_type,p);
906 for (x=0; x < (ssize_t) image->columns; x++)
908 WriteTGAPixel(image,tga_info.image_type,p);
912 if (image->previous == (Image *) NULL)
914 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
916 if (status == MagickFalse)
920 (void) CloseBlob(image);