cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % TTTTT GGGG AAA % |
| 7 | % T G A A % |
| 8 | % T G GG AAAAA % |
| 9 | % T G G A A % |
| 10 | % T GGG A A % |
| 11 | % % |
| 12 | % % |
| 13 | % Read/Write Truevision Targa Image Format % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | 1454be7 | 2011-12-19 01:52:48 +0000 | [diff] [blame^] | 20 | % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 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. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 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" |
cristy | 510d06a | 2011-07-06 23:43:54 +0000 | [diff] [blame] | 51 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 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" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | Forward declarations. |
| 70 | */ |
| 71 | static MagickBooleanType |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 72 | WriteTGAImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 76 | % % |
| 77 | % % |
| 78 | % % |
| 79 | % R e a d T G A I m a g e % |
| 80 | % % |
| 81 | % % |
| 82 | % % |
| 83 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 84 | % |
| 85 | % ReadTGAImage() reads a Truevision TGA image file and returns it. |
| 86 | % It allocates the memory necessary for the new Image structure and returns |
| 87 | % a pointer to the new image. |
| 88 | % |
| 89 | % The format of the ReadTGAImage method is: |
| 90 | % |
| 91 | % Image *ReadTGAImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 92 | % |
| 93 | % A description of each parameter follows: |
| 94 | % |
| 95 | % o image_info: the image info. |
| 96 | % |
| 97 | % o exception: return any errors or warnings in this structure. |
| 98 | % |
| 99 | */ |
| 100 | static Image *ReadTGAImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 101 | { |
| 102 | #define TGAColormap 1 |
| 103 | #define TGARGB 2 |
| 104 | #define TGAMonochrome 3 |
| 105 | #define TGARLEColormap 9 |
| 106 | #define TGARLERGB 10 |
| 107 | #define TGARLEMonochrome 11 |
| 108 | |
| 109 | typedef struct _TGAInfo |
| 110 | { |
| 111 | unsigned char |
| 112 | id_length, |
| 113 | colormap_type, |
| 114 | image_type; |
| 115 | |
| 116 | unsigned short |
| 117 | colormap_index, |
| 118 | colormap_length; |
| 119 | |
| 120 | unsigned char |
| 121 | colormap_size; |
| 122 | |
| 123 | unsigned short |
| 124 | x_origin, |
| 125 | y_origin, |
| 126 | width, |
| 127 | height; |
| 128 | |
| 129 | unsigned char |
| 130 | bits_per_pixel, |
| 131 | attributes; |
| 132 | } TGAInfo; |
| 133 | |
| 134 | Image |
| 135 | *image; |
| 136 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 137 | MagickBooleanType |
| 138 | status; |
| 139 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 140 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 141 | pixel; |
| 142 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 143 | Quantum |
| 144 | index; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 145 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 146 | register Quantum |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 147 | *q; |
| 148 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 149 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 150 | i, |
| 151 | x; |
| 152 | |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 153 | size_t |
| 154 | base, |
| 155 | flag, |
| 156 | offset, |
| 157 | real, |
| 158 | skip; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 159 | |
| 160 | ssize_t |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 161 | count, |
| 162 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 163 | |
| 164 | TGAInfo |
| 165 | tga_info; |
| 166 | |
| 167 | unsigned char |
| 168 | j, |
| 169 | k, |
cristy | 5dd83a5 | 2011-11-24 01:54:17 +0000 | [diff] [blame] | 170 | pixels[4], |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 171 | runlength; |
| 172 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 173 | /* |
| 174 | Open image file. |
| 175 | */ |
| 176 | assert(image_info != (const ImageInfo *) NULL); |
| 177 | assert(image_info->signature == MagickSignature); |
| 178 | if (image_info->debug != MagickFalse) |
| 179 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 180 | image_info->filename); |
| 181 | assert(exception != (ExceptionInfo *) NULL); |
| 182 | assert(exception->signature == MagickSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 183 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 184 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 185 | if (status == MagickFalse) |
| 186 | { |
| 187 | image=DestroyImageList(image); |
| 188 | return((Image *) NULL); |
| 189 | } |
| 190 | /* |
| 191 | Read TGA header information. |
| 192 | */ |
| 193 | count=ReadBlob(image,1,&tga_info.id_length); |
| 194 | tga_info.colormap_type=(unsigned char) ReadBlobByte(image); |
| 195 | tga_info.image_type=(unsigned char) ReadBlobByte(image); |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 196 | if ((count != 1) || |
| 197 | ((tga_info.image_type != TGAColormap) && |
| 198 | (tga_info.image_type != TGARGB) && |
| 199 | (tga_info.image_type != TGAMonochrome) && |
| 200 | (tga_info.image_type != TGARLEColormap) && |
| 201 | (tga_info.image_type != TGARLERGB) && |
| 202 | (tga_info.image_type != TGARLEMonochrome)) || |
| 203 | (((tga_info.image_type == TGAColormap) || |
| 204 | (tga_info.image_type == TGARLEColormap)) && |
| 205 | (tga_info.colormap_type == 0))) |
| 206 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 207 | tga_info.colormap_index=ReadBlobLSBShort(image); |
| 208 | tga_info.colormap_length=ReadBlobLSBShort(image); |
| 209 | tga_info.colormap_size=(unsigned char) ReadBlobByte(image); |
| 210 | tga_info.x_origin=ReadBlobLSBShort(image); |
| 211 | tga_info.y_origin=ReadBlobLSBShort(image); |
| 212 | tga_info.width=(unsigned short) ReadBlobLSBShort(image); |
| 213 | tga_info.height=(unsigned short) ReadBlobLSBShort(image); |
| 214 | tga_info.bits_per_pixel=(unsigned char) ReadBlobByte(image); |
| 215 | tga_info.attributes=(unsigned char) ReadBlobByte(image); |
| 216 | if (EOFBlob(image) != MagickFalse) |
| 217 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
| 218 | if ((((tga_info.bits_per_pixel <= 1) || (tga_info.bits_per_pixel >= 17)) && |
| 219 | (tga_info.bits_per_pixel != 24) && (tga_info.bits_per_pixel != 32))) |
| 220 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 221 | /* |
| 222 | Initialize image structure. |
| 223 | */ |
| 224 | image->columns=tga_info.width; |
| 225 | image->rows=tga_info.height; |
| 226 | image->matte=(tga_info.attributes & 0x0FU) != 0 ? MagickTrue : MagickFalse; |
| 227 | if ((tga_info.image_type != TGAColormap) && |
| 228 | (tga_info.image_type != TGARLEColormap)) |
| 229 | image->depth=(size_t) ((tga_info.bits_per_pixel <= 8) ? 8 : |
| 230 | (tga_info.bits_per_pixel <= 16) ? 5 : |
| 231 | (tga_info.bits_per_pixel == 24) ? 8 : |
| 232 | (tga_info.bits_per_pixel == 32) ? 8 : 8); |
| 233 | else |
| 234 | image->depth=(size_t) ((tga_info.colormap_size <= 8) ? 8 : |
| 235 | (tga_info.colormap_size <= 16) ? 5 : |
| 236 | (tga_info.colormap_size == 24) ? 8 : |
| 237 | (tga_info.colormap_size == 32) ? 8 : 8); |
| 238 | if ((tga_info.image_type == TGAColormap) || |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 239 | (tga_info.image_type == TGAMonochrome) || |
| 240 | (tga_info.image_type == TGARLEColormap) || |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 241 | (tga_info.image_type == TGARLEMonochrome)) |
| 242 | image->storage_class=PseudoClass; |
| 243 | image->compression=NoCompression; |
| 244 | if ((tga_info.image_type == TGARLEColormap) || |
| 245 | (tga_info.image_type == TGARLEMonochrome)) |
| 246 | image->compression=RLECompression; |
| 247 | if (image->storage_class == PseudoClass) |
| 248 | { |
| 249 | if (tga_info.colormap_type != 0) |
| 250 | image->colors=tga_info.colormap_length; |
| 251 | else |
| 252 | { |
| 253 | size_t |
| 254 | one; |
| 255 | |
| 256 | one=1; |
| 257 | image->colors=one << tga_info.bits_per_pixel; |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 258 | if (AcquireImageColormap(image,image->colors,exception) == MagickFalse) |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 259 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 260 | } |
| 261 | } |
| 262 | if (tga_info.id_length != 0) |
| 263 | { |
| 264 | char |
| 265 | *comment; |
| 266 | |
| 267 | size_t |
| 268 | length; |
| 269 | |
| 270 | /* |
| 271 | TGA image comment. |
| 272 | */ |
| 273 | length=(size_t) tga_info.id_length; |
| 274 | comment=(char *) NULL; |
cristy | 37e0b38 | 2011-06-07 13:31:21 +0000 | [diff] [blame] | 275 | if (~length >= (MaxTextExtent-1)) |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 276 | comment=(char *) AcquireQuantumMemory(length+MaxTextExtent, |
| 277 | sizeof(*comment)); |
| 278 | if (comment == (char *) NULL) |
| 279 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 280 | count=ReadBlob(image,tga_info.id_length,(unsigned char *) comment); |
| 281 | comment[tga_info.id_length]='\0'; |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 282 | (void) SetImageProperty(image,"comment",comment,exception); |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 283 | comment=DestroyString(comment); |
| 284 | } |
| 285 | (void) ResetMagickMemory(&pixel,0,sizeof(pixel)); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 286 | pixel.alpha=(Quantum) OpaqueAlpha; |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 287 | if (tga_info.colormap_type != 0) |
| 288 | { |
| 289 | /* |
| 290 | Read TGA raster colormap. |
| 291 | */ |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 292 | if (AcquireImageColormap(image,image->colors,exception) == MagickFalse) |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 293 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 294 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 295 | { |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 296 | switch (tga_info.colormap_size) |
| 297 | { |
| 298 | case 8: |
| 299 | default: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 300 | { |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 301 | /* |
| 302 | Gray scale. |
| 303 | */ |
| 304 | pixel.red=ScaleCharToQuantum((unsigned char) ReadBlobByte(image)); |
| 305 | pixel.green=pixel.red; |
| 306 | pixel.blue=pixel.red; |
| 307 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 308 | } |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 309 | case 15: |
| 310 | case 16: |
| 311 | { |
| 312 | QuantumAny |
| 313 | range; |
| 314 | |
| 315 | /* |
| 316 | 5 bits each of red green and blue. |
| 317 | */ |
| 318 | j=(unsigned char) ReadBlobByte(image); |
| 319 | k=(unsigned char) ReadBlobByte(image); |
| 320 | range=GetQuantumRange(5UL); |
| 321 | pixel.red=ScaleAnyToQuantum(1UL*(k & 0x7c) >> 2,range); |
| 322 | pixel.green=ScaleAnyToQuantum((1UL*(k & 0x03) << 3)+ |
| 323 | (1UL*(j & 0xe0) >> 5),range); |
| 324 | pixel.blue=ScaleAnyToQuantum(1UL*(j & 0x1f),range); |
| 325 | break; |
| 326 | } |
| 327 | case 24: |
| 328 | case 32: |
| 329 | { |
| 330 | /* |
| 331 | 8 bits each of blue, green and red. |
| 332 | */ |
| 333 | pixel.blue=ScaleCharToQuantum((unsigned char) ReadBlobByte(image)); |
| 334 | pixel.green=ScaleCharToQuantum((unsigned char) ReadBlobByte(image)); |
| 335 | pixel.red=ScaleCharToQuantum((unsigned char) ReadBlobByte(image)); |
| 336 | break; |
| 337 | } |
| 338 | } |
| 339 | image->colormap[i]=pixel; |
| 340 | } |
| 341 | } |
| 342 | /* |
| 343 | Convert TGA pixels to pixel packets. |
| 344 | */ |
| 345 | base=0; |
| 346 | flag=0; |
| 347 | skip=MagickFalse; |
| 348 | real=0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 349 | index=0; |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 350 | runlength=0; |
| 351 | offset=0; |
| 352 | for (y=0; y < (ssize_t) image->rows; y++) |
| 353 | { |
| 354 | real=offset; |
| 355 | if (((unsigned char) (tga_info.attributes & 0x20) >> 5) == 0) |
| 356 | real=image->rows-real-1; |
| 357 | q=QueueAuthenticPixels(image,0,(ssize_t) real,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 358 | if (q == (Quantum *) NULL) |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 359 | break; |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 360 | for (x=0; x < (ssize_t) image->columns; x++) |
| 361 | { |
| 362 | if ((tga_info.image_type == TGARLEColormap) || |
| 363 | (tga_info.image_type == TGARLERGB) || |
| 364 | (tga_info.image_type == TGARLEMonochrome)) |
| 365 | { |
| 366 | if (runlength != 0) |
| 367 | { |
| 368 | runlength--; |
| 369 | skip=flag != 0; |
| 370 | } |
| 371 | else |
| 372 | { |
| 373 | count=ReadBlob(image,1,&runlength); |
| 374 | if (count == 0) |
| 375 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
| 376 | flag=runlength & 0x80; |
| 377 | if (flag != 0) |
| 378 | runlength-=128; |
| 379 | skip=MagickFalse; |
| 380 | } |
| 381 | } |
| 382 | if (skip == MagickFalse) |
| 383 | switch (tga_info.bits_per_pixel) |
| 384 | { |
| 385 | case 8: |
| 386 | default: |
| 387 | { |
| 388 | /* |
| 389 | Gray scale. |
| 390 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 391 | index=(Quantum) ReadBlobByte(image); |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 392 | if (tga_info.colormap_type != 0) |
| 393 | pixel=image->colormap[(ssize_t) ConstrainColormapIndex(image, |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 394 | 1UL*index,exception)]; |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 395 | else |
| 396 | { |
| 397 | pixel.red=ScaleCharToQuantum((unsigned char) index); |
| 398 | pixel.green=ScaleCharToQuantum((unsigned char) index); |
| 399 | pixel.blue=ScaleCharToQuantum((unsigned char) index); |
| 400 | } |
| 401 | break; |
| 402 | } |
| 403 | case 15: |
| 404 | case 16: |
| 405 | { |
| 406 | QuantumAny |
| 407 | range; |
| 408 | |
| 409 | /* |
cristy | 5dd83a5 | 2011-11-24 01:54:17 +0000 | [diff] [blame] | 410 | 5 bits each of RGB. |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 411 | */ |
cristy | 5dd83a5 | 2011-11-24 01:54:17 +0000 | [diff] [blame] | 412 | if (ReadBlob(image,2,pixels) != 2) |
| 413 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
| 414 | j=pixels[0]; |
| 415 | k=pixels[1]; |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 416 | range=GetQuantumRange(5UL); |
| 417 | pixel.red=ScaleAnyToQuantum(1UL*(k & 0x7c) >> 2,range); |
| 418 | pixel.green=ScaleAnyToQuantum((1UL*(k & 0x03) << 3)+ |
| 419 | (1UL*(j & 0xe0) >> 5),range); |
| 420 | pixel.blue=ScaleAnyToQuantum(1UL*(j & 0x1f),range); |
| 421 | if (image->matte != MagickFalse) |
cristy | 5dd83a5 | 2011-11-24 01:54:17 +0000 | [diff] [blame] | 422 | pixel.alpha=(k & 0x80) == 0 ? (Quantum) OpaqueAlpha : (Quantum) |
| 423 | TransparentAlpha; |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 424 | if (image->storage_class == PseudoClass) |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 425 | index=ConstrainColormapIndex(image,((size_t) k << 8)+j,exception); |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 426 | break; |
| 427 | } |
| 428 | case 24: |
cristy | 5dd83a5 | 2011-11-24 01:54:17 +0000 | [diff] [blame] | 429 | { |
| 430 | /* |
| 431 | BGR pixels. |
| 432 | */ |
| 433 | if (ReadBlob(image,3,pixels) != 3) |
| 434 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
| 435 | pixel.blue=ScaleCharToQuantum(pixels[0]); |
| 436 | pixel.green=ScaleCharToQuantum(pixels[1]); |
| 437 | pixel.red=ScaleCharToQuantum(pixels[2]); |
| 438 | break; |
| 439 | } |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 440 | case 32: |
| 441 | { |
| 442 | /* |
cristy | 5dd83a5 | 2011-11-24 01:54:17 +0000 | [diff] [blame] | 443 | BGRA pixels. |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 444 | */ |
cristy | 5dd83a5 | 2011-11-24 01:54:17 +0000 | [diff] [blame] | 445 | if (ReadBlob(image,4,pixels) != 4) |
| 446 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
| 447 | pixel.blue=ScaleCharToQuantum(pixels[0]); |
| 448 | pixel.green=ScaleCharToQuantum(pixels[1]); |
| 449 | pixel.red=ScaleCharToQuantum(pixels[2]); |
| 450 | pixel.alpha=ScaleCharToQuantum(pixels[3]); |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 451 | break; |
| 452 | } |
| 453 | } |
| 454 | if (status == MagickFalse) |
| 455 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
| 456 | if (image->storage_class == PseudoClass) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 457 | SetPixelIndex(image,index,q); |
| 458 | SetPixelRed(image,pixel.red,q); |
| 459 | SetPixelGreen(image,pixel.green,q); |
| 460 | SetPixelBlue(image,pixel.blue,q); |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 461 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 462 | SetPixelAlpha(image,pixel.alpha,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 463 | q+=GetPixelChannels(image); |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 464 | } |
| 465 | if (((unsigned char) (tga_info.attributes & 0xc0) >> 6) == 4) |
| 466 | offset+=4; |
| 467 | else |
| 468 | if (((unsigned char) (tga_info.attributes & 0xc0) >> 6) == 2) |
| 469 | offset+=2; |
| 470 | else |
| 471 | offset++; |
| 472 | if (offset >= image->rows) |
| 473 | { |
| 474 | base++; |
| 475 | offset=base; |
| 476 | } |
| 477 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 478 | break; |
| 479 | if (image->previous == (Image *) NULL) |
| 480 | { |
| 481 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 482 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 483 | if (status == MagickFalse) |
| 484 | break; |
| 485 | } |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 486 | } |
| 487 | if (EOFBlob(image) != MagickFalse) |
| 488 | ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", |
| 489 | image->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 490 | (void) CloseBlob(image); |
| 491 | return(GetFirstImageInList(image)); |
| 492 | } |
| 493 | |
| 494 | /* |
| 495 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 496 | % % |
| 497 | % % |
| 498 | % % |
| 499 | % R e g i s t e r T G A I m a g e % |
| 500 | % % |
| 501 | % % |
| 502 | % % |
| 503 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 504 | % |
| 505 | % RegisterTGAImage() adds properties for the TGA image format to |
| 506 | % the list of supported formats. The properties include the image format |
| 507 | % tag, a method to read and/or write the format, whether the format |
| 508 | % supports the saving of more than one frame to the same file or blob, |
| 509 | % whether the format supports native in-memory I/O, and a brief |
| 510 | % description of the format. |
| 511 | % |
| 512 | % The format of the RegisterTGAImage method is: |
| 513 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 514 | % size_t RegisterTGAImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 515 | % |
| 516 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 517 | ModuleExport size_t RegisterTGAImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 518 | { |
| 519 | MagickInfo |
| 520 | *entry; |
| 521 | |
| 522 | entry=SetMagickInfo("ICB"); |
| 523 | entry->decoder=(DecodeImageHandler *) ReadTGAImage; |
| 524 | entry->encoder=(EncodeImageHandler *) WriteTGAImage; |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 525 | entry->adjoin=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 526 | entry->description=ConstantString("Truevision Targa image"); |
| 527 | entry->module=ConstantString("TGA"); |
| 528 | (void) RegisterMagickInfo(entry); |
| 529 | entry=SetMagickInfo("TGA"); |
| 530 | entry->decoder=(DecodeImageHandler *) ReadTGAImage; |
| 531 | entry->encoder=(EncodeImageHandler *) WriteTGAImage; |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 532 | entry->adjoin=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 533 | entry->description=ConstantString("Truevision Targa image"); |
| 534 | entry->module=ConstantString("TGA"); |
| 535 | (void) RegisterMagickInfo(entry); |
| 536 | entry=SetMagickInfo("VDA"); |
| 537 | entry->decoder=(DecodeImageHandler *) ReadTGAImage; |
| 538 | entry->encoder=(EncodeImageHandler *) WriteTGAImage; |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 539 | entry->adjoin=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 540 | entry->description=ConstantString("Truevision Targa image"); |
| 541 | entry->module=ConstantString("TGA"); |
| 542 | (void) RegisterMagickInfo(entry); |
| 543 | entry=SetMagickInfo("VST"); |
| 544 | entry->decoder=(DecodeImageHandler *) ReadTGAImage; |
| 545 | entry->encoder=(EncodeImageHandler *) WriteTGAImage; |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 546 | entry->adjoin=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 547 | entry->description=ConstantString("Truevision Targa image"); |
| 548 | entry->module=ConstantString("TGA"); |
| 549 | (void) RegisterMagickInfo(entry); |
| 550 | return(MagickImageCoderSignature); |
| 551 | } |
| 552 | |
| 553 | /* |
| 554 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 555 | % % |
| 556 | % % |
| 557 | % % |
| 558 | % U n r e g i s t e r T G A I m a g e % |
| 559 | % % |
| 560 | % % |
| 561 | % % |
| 562 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 563 | % |
| 564 | % UnregisterTGAImage() removes format registrations made by the |
| 565 | % TGA module from the list of supported formats. |
| 566 | % |
| 567 | % The format of the UnregisterTGAImage method is: |
| 568 | % |
| 569 | % UnregisterTGAImage(void) |
| 570 | % |
| 571 | */ |
| 572 | ModuleExport void UnregisterTGAImage(void) |
| 573 | { |
| 574 | (void) UnregisterMagickInfo("ICB"); |
| 575 | (void) UnregisterMagickInfo("TGA"); |
| 576 | (void) UnregisterMagickInfo("VDA"); |
| 577 | (void) UnregisterMagickInfo("VST"); |
| 578 | } |
| 579 | |
| 580 | /* |
| 581 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 582 | % % |
| 583 | % % |
| 584 | % % |
| 585 | % W r i t e T G A I m a g e % |
| 586 | % % |
| 587 | % % |
| 588 | % % |
| 589 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 590 | % |
| 591 | % WriteTGAImage() writes a image in the Truevision Targa rasterfile |
| 592 | % format. |
| 593 | % |
| 594 | % The format of the WriteTGAImage method is: |
| 595 | % |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 596 | % MagickBooleanType WriteTGAImage(const ImageInfo *image_info, |
| 597 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 598 | % |
| 599 | % A description of each parameter follows. |
| 600 | % |
| 601 | % o image_info: the image info. |
| 602 | % |
| 603 | % o image: The image. |
| 604 | % |
| 605 | */ |
| 606 | |
| 607 | static inline size_t MagickMin(const size_t x,const size_t y) |
| 608 | { |
| 609 | if (x < y) |
| 610 | return(x); |
| 611 | return(y); |
| 612 | } |
| 613 | |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 614 | static MagickBooleanType WriteTGAImage(const ImageInfo *image_info,Image *image, |
| 615 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 616 | { |
| 617 | #define TargaColormap 1 |
| 618 | #define TargaRGB 2 |
| 619 | #define TargaMonochrome 3 |
| 620 | #define TargaRLEColormap 9 |
| 621 | #define TargaRLERGB 10 |
| 622 | #define TargaRLEMonochrome 11 |
| 623 | |
| 624 | typedef struct _TargaInfo |
| 625 | { |
| 626 | unsigned char |
| 627 | id_length, |
| 628 | colormap_type, |
| 629 | image_type; |
| 630 | |
| 631 | unsigned short |
| 632 | colormap_index, |
| 633 | colormap_length; |
| 634 | |
| 635 | unsigned char |
| 636 | colormap_size; |
| 637 | |
| 638 | unsigned short |
| 639 | x_origin, |
| 640 | y_origin, |
| 641 | width, |
| 642 | height; |
| 643 | |
| 644 | unsigned char |
| 645 | bits_per_pixel, |
| 646 | attributes; |
| 647 | } TargaInfo; |
| 648 | |
| 649 | const char |
| 650 | *value; |
| 651 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 652 | MagickBooleanType |
| 653 | status; |
| 654 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 655 | register const Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 656 | *p; |
| 657 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 658 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 659 | x; |
| 660 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 661 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 662 | i; |
| 663 | |
| 664 | register unsigned char |
| 665 | *q; |
| 666 | |
| 667 | ssize_t |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 668 | count, |
| 669 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 670 | |
| 671 | TargaInfo |
| 672 | targa_info; |
| 673 | |
| 674 | unsigned char |
| 675 | *targa_pixels; |
| 676 | |
| 677 | /* |
| 678 | Open output image file. |
| 679 | */ |
| 680 | assert(image_info != (const ImageInfo *) NULL); |
| 681 | assert(image_info->signature == MagickSignature); |
| 682 | assert(image != (Image *) NULL); |
| 683 | assert(image->signature == MagickSignature); |
| 684 | if (image->debug != MagickFalse) |
| 685 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 686 | assert(exception != (ExceptionInfo *) NULL); |
| 687 | assert(exception->signature == MagickSignature); |
| 688 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 689 | if (status == MagickFalse) |
| 690 | return(status); |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 691 | /* |
| 692 | Initialize TGA raster file header. |
| 693 | */ |
| 694 | if ((image->columns > 65535L) || (image->rows > 65535L)) |
| 695 | ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit"); |
cristy | 510d06a | 2011-07-06 23:43:54 +0000 | [diff] [blame] | 696 | if (IsRGBColorspace(image->colorspace) == MagickFalse) |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 697 | (void) TransformImageColorspace(image,RGBColorspace,exception); |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 698 | targa_info.id_length=0; |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 699 | value=GetImageProperty(image,"comment",exception); |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 700 | if (value != (const char *) NULL) |
| 701 | targa_info.id_length=(unsigned char) MagickMin(strlen(value),255); |
| 702 | targa_info.colormap_type=0; |
| 703 | targa_info.colormap_index=0; |
| 704 | targa_info.colormap_length=0; |
| 705 | targa_info.colormap_size=0; |
| 706 | targa_info.x_origin=0; |
| 707 | targa_info.y_origin=0; |
| 708 | targa_info.width=(unsigned short) image->columns; |
| 709 | targa_info.height=(unsigned short) image->rows; |
| 710 | targa_info.bits_per_pixel=8; |
| 711 | targa_info.attributes=0; |
| 712 | if ((image_info->type != TrueColorType) && |
| 713 | (image_info->type != TrueColorMatteType) && |
| 714 | (image_info->type != PaletteType) && |
| 715 | (image->matte == MagickFalse) && |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 716 | (IsImageGray(image,exception) != MagickFalse)) |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 717 | targa_info.image_type=TargaMonochrome; |
| 718 | else |
| 719 | if ((image->storage_class == DirectClass) || (image->colors > 256)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 720 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 721 | /* |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 722 | Full color TGA raster. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 723 | */ |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 724 | targa_info.image_type=TargaRGB; |
| 725 | targa_info.bits_per_pixel=24; |
| 726 | if (image->matte != MagickFalse) |
| 727 | { |
| 728 | targa_info.bits_per_pixel=32; |
| 729 | targa_info.attributes=8; /* # of alpha bits */ |
| 730 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 731 | } |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 732 | else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 733 | { |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 734 | /* |
| 735 | Colormapped TGA raster. |
| 736 | */ |
| 737 | targa_info.image_type=TargaColormap; |
| 738 | targa_info.colormap_type=1; |
| 739 | targa_info.colormap_length=(unsigned short) image->colors; |
| 740 | targa_info.colormap_size=24; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 741 | } |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 742 | /* |
| 743 | Write TGA header. |
| 744 | */ |
| 745 | (void) WriteBlobByte(image,targa_info.id_length); |
| 746 | (void) WriteBlobByte(image,targa_info.colormap_type); |
| 747 | (void) WriteBlobByte(image,targa_info.image_type); |
| 748 | (void) WriteBlobLSBShort(image,targa_info.colormap_index); |
| 749 | (void) WriteBlobLSBShort(image,targa_info.colormap_length); |
| 750 | (void) WriteBlobByte(image,targa_info.colormap_size); |
| 751 | (void) WriteBlobLSBShort(image,targa_info.x_origin); |
| 752 | (void) WriteBlobLSBShort(image,targa_info.y_origin); |
| 753 | (void) WriteBlobLSBShort(image,targa_info.width); |
| 754 | (void) WriteBlobLSBShort(image,targa_info.height); |
| 755 | (void) WriteBlobByte(image,targa_info.bits_per_pixel); |
| 756 | (void) WriteBlobByte(image,targa_info.attributes); |
| 757 | if (targa_info.id_length != 0) |
| 758 | (void) WriteBlob(image,targa_info.id_length,(unsigned char *) |
| 759 | value); |
| 760 | if (targa_info.image_type == TargaColormap) |
| 761 | { |
| 762 | unsigned char |
| 763 | *targa_colormap; |
| 764 | |
| 765 | /* |
| 766 | Dump colormap to file (blue, green, red byte order). |
| 767 | */ |
| 768 | targa_colormap=(unsigned char *) AcquireQuantumMemory((size_t) |
| 769 | targa_info.colormap_length,3UL*sizeof(*targa_colormap)); |
| 770 | if (targa_colormap == (unsigned char *) NULL) |
| 771 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 772 | q=targa_colormap; |
| 773 | for (i=0; i < (ssize_t) image->colors; i++) |
| 774 | { |
| 775 | *q++=ScaleQuantumToChar(image->colormap[i].blue); |
| 776 | *q++=ScaleQuantumToChar(image->colormap[i].green); |
| 777 | *q++=ScaleQuantumToChar(image->colormap[i].red); |
| 778 | } |
| 779 | (void) WriteBlob(image,(size_t) (3*targa_info.colormap_length), |
| 780 | targa_colormap); |
| 781 | targa_colormap=(unsigned char *) RelinquishMagickMemory(targa_colormap); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 782 | } |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 783 | /* |
| 784 | Convert MIFF to TGA raster pixels. |
| 785 | */ |
| 786 | count=(ssize_t) (targa_info.bits_per_pixel*targa_info.width)/8; |
| 787 | targa_pixels=(unsigned char *) AcquireQuantumMemory((size_t) count, |
| 788 | sizeof(*targa_pixels)); |
| 789 | if (targa_pixels == (unsigned char *) NULL) |
| 790 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 791 | for (y=(ssize_t) (image->rows-1); y >= 0; y--) |
| 792 | { |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 793 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 794 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 795 | break; |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 796 | q=targa_pixels; |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 797 | for (x=0; x < (ssize_t) image->columns; x++) |
| 798 | { |
| 799 | if (targa_info.image_type == TargaColormap) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 800 | *q++=(unsigned char) GetPixelIndex(image,p); |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 801 | else |
| 802 | if (targa_info.image_type == TargaMonochrome) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 803 | *q++=(unsigned char) ScaleQuantumToChar(GetPixelIntensity(image,p)); |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 804 | else |
| 805 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 806 | *q++=ScaleQuantumToChar(GetPixelBlue(image,p)); |
| 807 | *q++=ScaleQuantumToChar(GetPixelGreen(image,p)); |
| 808 | *q++=ScaleQuantumToChar(GetPixelRed(image,p)); |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 809 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 810 | *q++=(unsigned char) ScaleQuantumToChar(GetPixelAlpha(image,p)); |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 811 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 812 | p+=GetPixelChannels(image); |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 813 | } |
| 814 | (void) WriteBlob(image,(size_t) (q-targa_pixels),targa_pixels); |
| 815 | if (image->previous == (Image *) NULL) |
| 816 | { |
| 817 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
cristy | c6da28e | 2011-04-28 01:41:35 +0000 | [diff] [blame] | 818 | image->rows); |
cristy | 9814091 | 2011-04-20 14:11:45 +0000 | [diff] [blame] | 819 | if (status == MagickFalse) |
| 820 | break; |
| 821 | } |
| 822 | } |
| 823 | targa_pixels=(unsigned char *) RelinquishMagickMemory(targa_pixels); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 824 | (void) CloseBlob(image); |
| 825 | return(MagickTrue); |
| 826 | } |