2
% Copyright (C) 2003, 2004 GraphicsMagick Group
3
% Copyright (C) 2002 ImageMagick Studio
4
% Copyright 1991-1999 E. I. du Pont de Nemours and Company
6
% This program is covered by multiple licenses, which are described in
7
% Copyright.txt. You should have received a copy of Copyright.txt with this
8
% package; otherwise see http://www.graphicsmagick.org/www/Copyright.html.
10
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21
% Read/Write Truevision Targa Image Format. %
30
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38
#include "magick/studio.h"
39
#include "magick/attribute.h"
40
#include "magick/blob.h"
41
#include "magick/cache.h"
42
#include "magick/color.h"
43
#include "magick/log.h"
44
#include "magick/magick.h"
45
#include "magick/monitor.h"
46
#include "magick/utility.h"
52
WriteTGAImage(const ImageInfo *,Image *);
55
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59
% R e a d T G A I m a g e %
63
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65
% Method ReadTGAImage reads a Truevision TGA image file and returns it.
66
% It allocates the memory necessary for the new Image structure and returns
67
% a pointer to the new image.
69
% The format of the ReadTGAImage method is:
71
% Image *ReadTGAImage(const ImageInfo *image_info,ExceptionInfo *exception)
73
% A description of each parameter follows:
75
% o image: Method ReadTGAImage returns a pointer to the image after
76
% reading. A null image is returned if there is a memory shortage or
77
% if the image cannot be read.
79
% o image_info: Specifies a pointer to a ImageInfo structure.
81
% o exception: return any errors or warnings in this structure.
85
static Image *ReadTGAImage(const ImageInfo *image_info,ExceptionInfo *exception)
87
#define TGAColormap 1 /* Colormapped image data */
88
#define TGARGB 2 /* Truecolor image data */
89
#define TGAMonochrome 3 /* Monochrome image data */
90
#define TGARLEColormap 9 /* Colormapped image data (encoded) */
91
#define TGARLERGB 10 /* Truecolor image data (encoded) */
92
#define TGARLEMonochrome 11 /* Monochrome image data (encoded) */
94
typedef struct _TGAInfo
97
id_length, /* Size of Image ID field */
98
colormap_type, /* Color map type */
99
image_type; /* Image type code */
102
colormap_index, /* Color map origin */
103
colormap_length; /* Color map length */
106
colormap_size; /* Color map entry depth */
109
x_origin, /* X origin of image */
110
y_origin, /* Y orgin of image */
111
width, /* Width of image */
112
height; /* Height of image */
115
bits_per_pixel, /* Image pixel size */
116
attributes; /* Image descriptor byte */
167
assert(image_info != (const ImageInfo *) NULL);
168
assert(image_info->signature == MagickSignature);
169
assert(exception != (ExceptionInfo *) NULL);
170
assert(exception->signature == MagickSignature);
171
image=AllocateImage(image_info);
172
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
174
ThrowReaderException(FileOpenError,UnableToOpenFile,image);
176
Read TGA header information.
178
count=ReadBlob(image,1,(char *) &tga_info.id_length);
179
tga_info.colormap_type=ReadBlobByte(image);
180
tga_info.image_type=ReadBlobByte(image);
184
((tga_info.image_type != TGAColormap) &&
185
(tga_info.image_type != TGARGB) &&
186
(tga_info.image_type != TGAMonochrome) &&
187
(tga_info.image_type != TGARLEColormap) &&
188
(tga_info.image_type != TGARLERGB) &&
189
(tga_info.image_type != TGARLEMonochrome)) ||
190
(((tga_info.image_type == TGAColormap) ||
191
(tga_info.image_type == TGARLEColormap)) &&
192
(tga_info.colormap_type == 0)))
193
ThrowReaderException(CorruptImageError,ImproperImageHeader,image);
194
tga_info.colormap_index=ReadBlobLSBShort(image);
195
tga_info.colormap_length=ReadBlobLSBShort(image);
196
tga_info.colormap_size=ReadBlobByte(image);
197
tga_info.x_origin=ReadBlobLSBShort(image);
198
tga_info.y_origin=ReadBlobLSBShort(image);
199
tga_info.width=ReadBlobLSBShort(image);
200
tga_info.height=ReadBlobLSBShort(image);
201
tga_info.bits_per_pixel=ReadBlobByte(image);
202
tga_info.attributes=ReadBlobByte(image);
203
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
204
"ImageType=%s CMapType=%u CMapStart=%u CMapLength=%u CMapDepth=%u\n XOffset=%u YOffset=%u Width=%u Height=%u PixelDepth=%u Attributes=0x%.2x",
205
((tga_info.image_type == TGAColormap) ? "Colormapped" :
206
(tga_info.image_type == TGARGB) ? "TrueColor" :
207
(tga_info.image_type == TGAMonochrome) ? "Monochrome" :
208
(tga_info.image_type == TGARLEColormap) ? "Colormapped-RLE" :
209
(tga_info.image_type == TGARLERGB) ? "Truecolor-RLE" :
210
(tga_info.image_type == TGARLEMonochrome) ? "Monochrome-RLE" :
212
(unsigned int) tga_info.colormap_type,
213
(unsigned int) tga_info.colormap_index,
214
(unsigned int) tga_info.colormap_length,
215
(unsigned int) tga_info.colormap_size,
216
tga_info.x_origin, tga_info.y_origin, tga_info.width, tga_info.height,
217
(unsigned int) tga_info.bits_per_pixel,
218
tga_info.attributes);
221
Initialize image structure.
223
alpha_bits=(tga_info.attributes & 0x0FU);
224
image->matte=(alpha_bits > 0);
225
image->columns=tga_info.width;
226
image->rows=tga_info.height;
227
if ((tga_info.image_type != TGAColormap) && (tga_info.image_type != TGARLEColormap))
230
TrueColor Quantum Depth
232
image->depth=((tga_info.bits_per_pixel <= 8) ? 8 :
233
(tga_info.bits_per_pixel <= 16) ? 5 :
234
(tga_info.bits_per_pixel == 24) ? 8 :
235
(tga_info.bits_per_pixel == 32) ? 8 : 8);
240
ColorMapped Palette Entry Quantum Depth
242
image->depth=((tga_info.colormap_size <= 8) ? 8 :
243
(tga_info.colormap_size <= 16) ? 5 :
244
(tga_info.colormap_size == 24) ? 8 :
245
(tga_info.colormap_size == 32) ? 8 : 8);
248
image->storage_class=DirectClass;
250
if ((tga_info.image_type == TGAColormap) ||
251
(tga_info.image_type == TGAMonochrome) ||
252
(tga_info.image_type == TGARLEColormap) ||
253
(tga_info.image_type == TGARLEMonochrome))
255
(void) LogMagickEvent(CoderEvent,GetMagickModule(),"Setting PseudoClass");
256
image->storage_class=PseudoClass;
259
if ((tga_info.image_type == TGARLEColormap) ||
260
(tga_info.image_type == TGARLEMonochrome))
261
image->compression=RLECompression;
263
is_grayscale=((tga_info.image_type == TGAMonochrome) ||
264
(tga_info.image_type == TGARLEMonochrome));
266
if (image->storage_class == PseudoClass)
268
if (tga_info.colormap_type != 0)
270
image->colors=tga_info.colormap_length;
271
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
272
"Using existing colormap with %lu colors.",image->colors);
278
Apply grayscale colormap.
280
image->colors=(0x01U << tga_info.bits_per_pixel);
281
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
282
"Applying grayscale colormap with %lu colors.",image->colors);
283
if (!AllocateImageColormap(image,image->colors))
284
ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,
289
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
290
"StorageClass=%s Matte=%s Depth=%lu Grayscale=%s",
291
((image->storage_class == DirectClass) ? "DirectClass" : "PseduoClass"),
292
(image->matte ? "True" : "False"), image->depth,
293
(is_grayscale ? "True" : "False"));
295
if (tga_info.id_length != 0)
303
comment=MagickAllocateMemory(char *,tga_info.id_length+1);
304
if (comment == (char *) NULL)
305
ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,
307
(void) ReadBlob(image,tga_info.id_length,comment);
308
comment[tga_info.id_length]='\0';
309
(void) SetImageAttribute(image,"comment",comment);
310
MagickFreeMemory(comment);
312
(void) memset(&pixel,0,sizeof(PixelPacket));
313
pixel.opacity=TransparentOpacity;
314
if (tga_info.colormap_type != 0)
317
Read TGA raster colormap.
319
if (!AllocateImageColormap(image,image->colors))
320
ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,
322
for (i=0; i < (long) image->colors; i++)
324
switch (tga_info.colormap_size)
332
pixel.red=ScaleCharToQuantum(ReadBlobByte(image));
333
pixel.green=pixel.red;
334
pixel.blue=pixel.red;
341
5 bits each of red green and blue.
346
packet = ReadBlobByte(image);
347
packet |= (((unsigned int) ReadBlobByte(image)) << 8);
349
pixel.red=(packet >> 10) & 0x1f;
350
pixel.red=ScaleCharToQuantum(ScaleColor5to8(pixel.red));
351
pixel.green=(packet >> 5) & 0x1f;
352
pixel.green=ScaleCharToQuantum(ScaleColor5to8(pixel.green));
353
pixel.blue=packet & 0x1f;
354
pixel.blue=ScaleCharToQuantum(ScaleColor5to8(pixel.blue));
361
8 bits each of blue, green and red.
363
pixel.blue=ScaleCharToQuantum(ReadBlobByte(image));
364
pixel.green=ScaleCharToQuantum(ReadBlobByte(image));
365
pixel.red=ScaleCharToQuantum(ReadBlobByte(image));
369
image->colormap[i]=pixel;
372
if (image_info->ping && (image_info->subrange != 0))
373
if (image->scene >= (image_info->subimage+image_info->subrange-1))
376
Convert TGA pixels to pixel packets.
385
pixel.opacity=OpaqueOpacity;
386
for (y=0; y < (long) image->rows; y++)
389
if (((unsigned char) (tga_info.attributes & 0x20) >> 5) == 0)
390
real=image->rows-real-1;
391
q=SetImagePixels(image,0,(long) real,image->columns,1);
392
if (q == (PixelPacket *) NULL)
394
indexes=GetIndexes(image);
395
for (x=0; x < (long) image->columns; x++)
397
if ((tga_info.image_type == TGARLEColormap) ||
398
(tga_info.image_type == TGARLERGB) ||
399
(tga_info.image_type == TGARLEMonochrome))
408
count=ReadBlob(image,1,(char *) &runlength);
410
ThrowReaderException(CorruptImageError,UnableToReadImageData,image);
411
flag=runlength & 0x80;
418
switch (tga_info.bits_per_pixel)
426
index=ReadBlobByte(image);
427
if (image->storage_class == PseudoClass)
429
VerifyColormapIndex(image,index);
430
pixel=image->colormap[index];
434
pixel.blue=pixel.green=pixel.red=ScaleCharToQuantum(index);
442
5 bits each of red green and blue.
447
packet = ReadBlobByte(image);
448
packet |= (((unsigned int) ReadBlobByte(image)) << 8);
450
pixel.red=(packet >> 10) & 0x1f;
451
pixel.red=ScaleCharToQuantum(ScaleColor5to8(pixel.red));
452
pixel.green=(packet >> 5) & 0x1f;
453
pixel.green=ScaleCharToQuantum(ScaleColor5to8(pixel.green));
454
pixel.blue=packet & 0x1f;
455
pixel.blue=ScaleCharToQuantum(ScaleColor5to8(pixel.blue));
458
if ((packet >> 15) & 0x01)
459
pixel.opacity=OpaqueOpacity;
461
pixel.opacity=TransparentOpacity;
464
if (image->storage_class == PseudoClass)
466
index=(IndexPacket) (packet & 0x7fff);
467
VerifyColormapIndex(image,index);
473
8 bits each of blue green and red.
475
pixel.blue=ScaleCharToQuantum(ReadBlobByte(image));
476
pixel.green=ScaleCharToQuantum(ReadBlobByte(image));
477
pixel.red=ScaleCharToQuantum(ReadBlobByte(image));
482
8 bits each of blue green and red.
484
pixel.blue=ScaleCharToQuantum(ReadBlobByte(image));
485
pixel.green=ScaleCharToQuantum(ReadBlobByte(image));
486
pixel.red=ScaleCharToQuantum(ReadBlobByte(image));
487
pixel.opacity=ScaleCharToQuantum(255-ReadBlobByte(image));
492
ThrowReaderException(CorruptImageError,UnableToReadImageData,image);
493
if (image->storage_class == PseudoClass)
497
if (((unsigned char) (tga_info.attributes & 0xc0) >> 6) == 4)
500
if (((unsigned char) (tga_info.attributes & 0xc0) >> 6) == 2)
504
if (offset >= image->rows)
509
if (!SyncImagePixels(image))
511
image->is_grayscale=is_grayscale;
512
if (image->previous == (Image *) NULL)
513
if (QuantumTick(y,image->rows))
514
if (!MagickMonitor(LoadImageText,y,image->rows,exception))
519
ThrowException(exception,CorruptImageError,UnexpectedEndOfFile,
524
Proceed to next image.
526
if (image_info->subrange != 0)
527
if (image->scene >= (image_info->subimage+image_info->subrange-1))
529
count=ReadBlob(image,1,(char *) &tga_info.id_length);
530
tga_info.colormap_type=ReadBlobByte(image);
531
tga_info.image_type=ReadBlobByte(image);
532
status=((tga_info.image_type == TGAColormap) ||
533
(tga_info.image_type == TGARGB) ||
534
(tga_info.image_type == TGAMonochrome) ||
535
(tga_info.image_type == TGARLEColormap) ||
536
(tga_info.image_type == TGARLERGB) ||
537
(tga_info.image_type == TGARLEMonochrome));
541
Allocate next image structure.
543
AllocateNextImage(image_info,image);
544
if (image->next == (Image *) NULL)
546
DestroyImageList(image);
547
return((Image *) NULL);
549
image=SyncNextImageInList(image);
550
if (!MagickMonitor(LoadImagesText,TellBlob(image),GetBlobSize(image),exception))
553
} while (status == True);
554
while (image->previous != (Image *) NULL)
555
image=image->previous;
561
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
565
% R e g i s t e r T G A I m a g e %
569
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
571
% Method RegisterTGAImage adds attributes for the TGA image format to
572
% the list of supported formats. The attributes include the image format
573
% tag, a method to read and/or write the format, whether the format
574
% supports the saving of more than one frame to the same file or blob,
575
% whether the format supports native in-memory I/O, and a brief
576
% description of the format.
578
% The format of the RegisterTGAImage method is:
580
% RegisterTGAImage(void)
583
ModuleExport void RegisterTGAImage(void)
588
entry=SetMagickInfo("ICB");
589
entry->decoder=(DecoderHandler) ReadTGAImage;
590
entry->encoder=(EncoderHandler) WriteTGAImage;
591
entry->description=AcquireString("Truevision Targa image");
592
entry->module=AcquireString("TGA");
593
(void) RegisterMagickInfo(entry);
594
entry=SetMagickInfo("TGA");
595
entry->decoder=(DecoderHandler) ReadTGAImage;
596
entry->encoder=(EncoderHandler) WriteTGAImage;
597
entry->description=AcquireString("Truevision Targa image");
598
entry->module=AcquireString("TGA");
599
(void) RegisterMagickInfo(entry);
600
entry=SetMagickInfo("VDA");
601
entry->decoder=(DecoderHandler) ReadTGAImage;
602
entry->encoder=(EncoderHandler) WriteTGAImage;
603
entry->description=AcquireString("Truevision Targa image");
604
entry->module=AcquireString("TGA");
605
(void) RegisterMagickInfo(entry);
606
entry=SetMagickInfo("VST");
607
entry->decoder=(DecoderHandler) ReadTGAImage;
608
entry->encoder=(EncoderHandler) WriteTGAImage;
609
entry->description=AcquireString("Truevision Targa image");
610
entry->module=AcquireString("TGA");
611
(void) RegisterMagickInfo(entry);
615
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
619
% U n r e g i s t e r T G A I m a g e %
623
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
625
% Method UnregisterTGAImage removes format registrations made by the
626
% TGA module from the list of supported formats.
628
% The format of the UnregisterTGAImage method is:
630
% UnregisterTGAImage(void)
633
ModuleExport void UnregisterTGAImage(void)
635
(void) UnregisterMagickInfo("ICB");
636
(void) UnregisterMagickInfo("TGA");
637
(void) UnregisterMagickInfo("VDA");
638
(void) UnregisterMagickInfo("VST");
642
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
646
% W r i t e T G A I m a g e %
650
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
652
% Method WriteTGAImage writes a image in the Truevision Targa rasterfile
655
% The format of the WriteTGAImage method is:
657
% unsigned int WriteTGAImage(const ImageInfo *image_info,Image *image)
659
% A description of each parameter follows.
661
% o status: Method WriteTGAImage return True if the image is written.
662
% False is returned is there is a memory shortage or if the image file
665
% o image_info: Specifies a pointer to a ImageInfo structure.
667
% o image: A pointer to an Image structure.
671
static unsigned int WriteTGAImage(const ImageInfo *image_info,Image *image)
673
#define TargaColormap 1
675
#define TargaMonochrome 3
676
#define TargaRLEColormap 9
677
#define TargaRLERGB 10
678
#define TargaRLEMonochrome 11
680
typedef struct _TargaInfo
712
register const PixelPacket
724
register unsigned char
741
Open output image file.
743
assert(image_info != (const ImageInfo *) NULL);
744
assert(image_info->signature == MagickSignature);
745
assert(image != (Image *) NULL);
746
assert(image->signature == MagickSignature);
747
status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
749
ThrowWriterException(FileOpenError,UnableToOpenFile,image);
753
write_grayscale=False;
756
If requested output is grayscale, then write grayscale.
758
if ((image_info->type == GrayscaleType) ||
759
(image_info->type == GrayscaleMatteType))
760
write_grayscale=True;
763
Convert colorspace to an RGB-compatible type.
765
(void) TransformColorspace(image,RGBColorspace);
768
If some other type has not been requested and the image is
769
grayscale, then write a grayscale image unless the image
770
contains an alpha channel.
772
if (((image_info->type != TrueColorType) &&
773
(image_info->type != TrueColorMatteType) &&
774
(image_info->type != PaletteType) &&
775
(image->matte == False)) &&
776
IsGrayImage(image,&image->exception))
777
write_grayscale=True;
780
If there are too many colors for colormapped output or the
781
image contains an alpha channel, then promote to TrueColor.
783
if (((write_grayscale == False) &&
784
(image->storage_class == PseudoClass) &&
785
(image->colors > 256)) ||
786
(image->matte == True))
789
image->storage_class=DirectClass;
793
Initialize TGA raster file header.
795
targa_info.id_length=0;
796
attribute=GetImageAttribute(image,"comment");
797
if (attribute != (const ImageAttribute *) NULL)
798
targa_info.id_length=Min(strlen(attribute->value),255);
799
targa_info.colormap_type=0;
800
targa_info.colormap_index=0;
801
targa_info.colormap_length=0;
802
targa_info.colormap_size=0;
803
targa_info.x_origin=0;
804
targa_info.y_origin=0;
805
targa_info.width=(unsigned short) image->columns;
806
targa_info.height=(unsigned short) image->rows;
807
targa_info.bits_per_pixel=8;
808
targa_info.attributes=0;
809
if (write_grayscale == True)
812
Grayscale without Colormap
814
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
815
"Writing Grayscale raster ...");
816
targa_info.image_type=TargaMonochrome;
817
targa_info.bits_per_pixel=8;
818
targa_info.colormap_type=0;
819
targa_info.colormap_index=0;
820
targa_info.colormap_length=0;
821
targa_info.colormap_size=0;
823
else if (image->storage_class == DirectClass)
826
Full color TGA raster.
828
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
829
"Writing TrueColor raster ...");
831
targa_info.image_type=TargaRGB;
832
targa_info.bits_per_pixel=24;
835
targa_info.bits_per_pixel=32;
836
targa_info.attributes=8; /* # of alpha bits */
842
Colormapped TGA raster.
844
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
845
"Writing ColorMapped raster ..." );
846
targa_info.image_type=TargaColormap;
847
targa_info.colormap_type=1;
848
targa_info.colormap_index=0;
849
targa_info.colormap_length=(unsigned short) image->colors;
850
targa_info.colormap_size=24;
855
(void) WriteBlobByte(image,targa_info.id_length);
856
(void) WriteBlobByte(image,targa_info.colormap_type);
857
(void) WriteBlobByte(image,targa_info.image_type);
858
(void) WriteBlobLSBShort(image,targa_info.colormap_index);
859
(void) WriteBlobLSBShort(image,targa_info.colormap_length);
860
(void) WriteBlobByte(image,targa_info.colormap_size);
861
(void) WriteBlobLSBShort(image,targa_info.x_origin);
862
(void) WriteBlobLSBShort(image,targa_info.y_origin);
863
(void) WriteBlobLSBShort(image,targa_info.width);
864
(void) WriteBlobLSBShort(image,targa_info.height);
865
(void) WriteBlobByte(image,targa_info.bits_per_pixel);
866
(void) WriteBlobByte(image,targa_info.attributes);
867
if (targa_info.id_length != 0)
868
(void) WriteBlob(image,targa_info.id_length,attribute->value);
869
if (targa_info.image_type == TargaColormap)
875
Dump colormap to file (blue, green, red byte order).
877
targa_colormap=MagickAllocateMemory(unsigned char *,
878
3*targa_info.colormap_length);
879
if (targa_colormap == (unsigned char *) NULL)
880
ThrowWriterException(ResourceLimitError,MemoryAllocationFailed,
883
for (i=0; i < (long) image->colors; i++)
885
*q++=ScaleQuantumToChar(image->colormap[i].blue);
886
*q++=ScaleQuantumToChar(image->colormap[i].green);
887
*q++=ScaleQuantumToChar(image->colormap[i].red);
889
(void) WriteBlob(image,3*targa_info.colormap_length,
890
(char *) targa_colormap);
891
MagickFreeMemory(targa_colormap);
894
Convert MIFF to TGA raster pixels.
896
count=(long) ((targa_info.bits_per_pixel*targa_info.width) >> 3);
897
targa_pixels=MagickAllocateMemory(unsigned char *,count);
898
if (targa_pixels == (unsigned char *) NULL)
899
ThrowWriterException(ResourceLimitError,MemoryAllocationFailed,image);
900
for (y=(long) (image->rows-1); y >= 0; y--)
902
p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
903
if (p == (const PixelPacket *) NULL)
906
indexes=GetIndexes(image);
907
for (x=0; x < (long) image->columns; x++)
909
if (targa_info.image_type == TargaColormap)
915
else if (targa_info.image_type == TargaMonochrome)
918
if (image->storage_class == PseudoClass)
920
if (image->is_grayscale)
921
*q++=ScaleQuantumToChar(image->colormap[*indexes].red);
923
*q++=PixelIntensityToQuantum(&image->colormap[*indexes]);
928
if (image->is_grayscale)
929
*q++=ScaleQuantumToChar(p->red);
931
*q++=PixelIntensityToQuantum(p);
937
*q++=ScaleQuantumToChar(p->blue);
938
*q++=ScaleQuantumToChar(p->green);
939
*q++=ScaleQuantumToChar(p->red);
941
*q++=ScaleQuantumToChar(MaxRGB-p->opacity);
945
(void) WriteBlob(image,q-targa_pixels,(char *) targa_pixels);
946
if (image->previous == (Image *) NULL)
947
if (QuantumTick(y,image->rows))
948
if (!MagickMonitor(SaveImageText,y,image->rows,&image->exception))
951
MagickFreeMemory(targa_pixels);
952
if (image->next == (Image *) NULL)
954
image=SyncNextImageInList(image);
955
if (!MagickMonitor(SaveImagesText,scene++,GetImageListLength(image),&image->exception))
957
} while (image_info->adjoin);
958
if (image_info->adjoin)
959
while (image->previous != (Image *) NULL)
960
image=image->previous;