cvs: gd /libgd/src gd_tga.c gd_tga.h gd_tiff.c
[email protected] ("Scott MacVicar") Sat, 13 Oct 2007 18:18:27 -0000
| Newsgroups | php.gd.cvs |
|---|---|
| Message-ID | <cvsscottmac1192299507@cvsserver> |
scottmac Sat Oct 13 18:18:27 2007 UTC
Modified files:
/gd/libgd/src gd_tga.c gd_tga.h gd_tiff.c
Log:
Make the spelling of color consistent with the rest of libgd, though colour is the correct way... :)
scottmac-20071013181827.txt
(text/plain, 27.1 KB)
http://cvs.php.net/viewvc.cgi/gd/libgd/src/gd_tga.c?r1=1.2&r2=1.3&diff_format=u
Index: gd/libgd/src/gd_tga.c
diff -u gd/libgd/src/gd_tga.c:1.2 gd/libgd/src/gd_tga.c:1.3
--- gd/libgd/src/gd_tga.c:1.2 Mon Oct 8 07:21:40 2007
+++ gd/libgd/src/gd_tga.c Sat Oct 13 18:18:27 2007
@@ -1,323 +1,323 @@
-#include <stdio.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "gd_tga.h"
-#include "gd.h"
-#include "gdhelpers.h"
-
-/*! \brief Creates a gdImage from a TGA file
- * Creates a gdImage from a TGA binary file via a gdIOCtx.
- * \param infile Pointer to TGA binary file
- * \return gdImagePtr
- */
-BGD_DECLARE(gdImagePtr) gdImageCreateFromTga(FILE * fp)
-{
- gdImagePtr image;
- gdIOCtx* in = gdNewFileCtx(fp);
- image = gdImageCreateFromTgaCtx(in);
- in->gd_free( in );
- return image;
-}
-
-BGD_DECLARE(gdImagePtr) gdImageCreateFromTgaPtr(int size, void *data)
-{
- gdImagePtr im;
- gdIOCtx *in = gdNewDynamicCtxEx (size, data, 0);
- im = gdImageCreateFromTgaCtx(in);
- in->gd_free(in);
- return im;
-}
-
-
-/*! \brief Creates a gdImage from a gdIOCtx
- * Creates a gdImage from a gdIOCtx referencing a TGA binary file.
- * \param ctx Pointer to a gdIOCtx structure
- * \return gdImagePtr
- */
-BGD_DECLARE(gdImagePtr) gdImageCreateFromTgaCtx(gdIOCtx* ctx)
-{
-
- int bitmap_caret = 0;
- int i = 0;
- oTga *tga = NULL;
- int pixel_block_size = 0;
- int image_block_size = 0;
- volatile gdImagePtr image = NULL;
- int x = 0;
- int y = 0;
- int color = 0;
-
- tga = (oTga *) gdMalloc(sizeof(oTga));
- if (!tga) {
- return NULL;
- }
-
- tga->bitmap = NULL;
- tga->ident = NULL;
-
- if (!read_header_tga(ctx, tga)) {
- free_tga(tga);
- return NULL;
- }
-
- pixel_block_size = tga->bits / 8;
- image_block_size = (tga->width * tga->height) * pixel_block_size;
-
- if (read_image_tga(ctx, tga)) {
- free_tga(tga);
- return NULL;
- }
-
- image = gdImageCreateTrueColor((int)tga->width, (int)tga->height );
-
- if (image == 0) {
- free_tga( tga );
- return NULL;
- }
-
- /*! \brief Populate GD image object
- * Copy the pixel data from our tga bitmap buffer into the GD image
- * Disable blending and save the alpha channel per default
- */
- if (tga->alphabits) {
- gdImageAlphaBlending(image, 0);
- gdImageSaveAlpha(image, 1);
- }
-
- /* TODO: use alphabits as soon as we support 24bit and other alpha bps (ie != 8bits) */
- for (y = 0; y < tga->height; y++) {
- register int *tpix = image->tpixels[y];
- for ( x = 0; x < tga->width; x++, tpix++) {
- if (tga->bits == TGA_BPP_24) {
- *tpix = gdTrueColor(tga->bitmap[bitmap_caret + 2], tga->bitmap[bitmap_caret + 1], tga->bitmap[bitmap_caret]);
- bitmap_caret += 3;
- } else if (tga->bits == TGA_BPP_32 || tga->alphabits) {
- register int a = tga->bitmap[bitmap_caret + 3];
-
- *tpix = gdTrueColorAlpha(tga->bitmap[bitmap_caret + 2], tga->bitmap[bitmap_caret + 1], tga->bitmap[bitmap_caret], gdAlphaMax - (a >> 1));
- bitmap_caret += 4;
- }
- }
- }
-/* TODO: enable this part as soon as the flip functions have been commited*/
-#if 0
- if (tga->flipv && tga->fliph) {
- gdImageFlip(image, GD_FLIP_BOTH);
- } else if (tga->flipv) {
- gdImageFlip(image, GD_FLIP_HORIZONTAL);
- } else if (tga->fliph) {
- gdImageFlip(image, GD_FLIP_VERTICAL);
- }
-#endif
- free_tga(tga);
-
- return image;
-}
-
-/*! \brief Reads a TGA header.
- * Reads the header block from a binary TGA file populating the referenced TGA structure.
- * \param ctx Pointer to TGA binary file
- * \param tga Pointer to TGA structure
- * \return int 1 on sucess, -1 on failure
- */
-int read_header_tga(gdIOCtx *ctx, oTga *tga) {
-
- unsigned char header[18];
-
- if (gdGetBuf(header, sizeof(header), ctx) < 18) {
- fprintf(stderr, "fail to read header");
- return -1;
- }
-
- tga->identsize = header[0];
- tga->colourmaptype = header[1];
- tga->imagetype = header[2];
- tga->colourmapstart = header[3] + (header[4] << 8);
- tga->colourmaplength = header[5] + (header[6] << 8);
- tga->colourmapbits = header[7];
- tga->xstart = header[8] + (header[9] << 8);
- tga->ystart = header[10] + (header[11] << 8);
- tga->width = header[12] + (header[13] << 8);
- tga->height = header[14] + (header[15] << 8);
- tga->bits = header[16];
- tga->alphabits = header[17] & 0x0f;
- tga->fliph = (header[17] & 0x10) ? 1 : 0;
- tga->flipv = (header[17] & 0x20) ? 0 : 1;
-
-#if DEBUG
- printf("format bps: %i\n", tga->bits);
- printf("flip h/v: %i / %i\n", tga->fliph, tga->flipv);
- printf("alpha: %i\n", tga->alphabits);
- printf("wxh: %i %i\n", tga->width, tga->height);
-#endif
-
- if (tga->bits != 8 && tga->bits != 24 && tga->bits != 16 && tga->bits != 32) {
- fprintf(stderr, "bps %i not supported", tga->bits);
- return -1;
- }
-
- tga->ident = (char *) gdMalloc(tga->identsize * sizeof( char ));
- if (tga->ident == NULL) {
- return -1;
- }
-
- if (tga->identsize > 0) {
- gdGetBuf( &( tga->ident ), tga->identsize, ctx );
- }
-
- return 1;
-}
-
-/*! \brief Reads a TGA image data into buffer.
- * Reads the image data block from a binary TGA file populating the referenced TGA structure.
- * \param ctx Pointer to TGA binary file
- * \param tga Pointer to TGA structure
- * \return int 0 on sucess, -1 on failure
- */
-int read_image_tga( gdIOCtx *ctx, oTga *tga ) {
- int pixel_block_size = (tga->bits / 8);
- int image_block_size = (tga->width * tga->height) * pixel_block_size;
- byte* decompression_buffer = NULL;
- unsigned char* conversion_buffer = NULL;
- int buffer_caret = 0;
- int bitmap_caret = 0;
- int i = 0;
- int j = 0;
- byte encoded_pixels;
-
- /*! \brief Allocate memmory for image block
- * Allocate a chunk of memory for the image block to be passed into.
- */
- tga->bitmap = (byte *) gdMalloc(image_block_size * sizeof(byte));
- if (tga->bitmap == NULL) {
- return -1;
- }
-
- /*! \todo Add image type support
- * Add support for this image type.
- */
- if (tga->imagetype == TGA_TYPE_INDEXED) {
- return -1;
- }
-
- /*! \todo Add image type support
- * Add support for this image type.
- */
- if (tga->imagetype == TGA_TYPE_INDEXED_RLE) {
- return -1;
- }
-
- /*! \brief Read in uncompressed RGB TGA
- * Chunk load the pixel data from an uncompressed RGB type TGA.
- */
- if (tga->imagetype == TGA_TYPE_RGB) {
- conversion_buffer = (unsigned char *) gdMalloc(image_block_size * sizeof(unsigned char));
- if (conversion_buffer == NULL) {
- gdFree(conversion_buffer);
- return -1;
- }
-
- gdGetBuf(conversion_buffer, image_block_size, ctx);
-
- while (buffer_caret < image_block_size) {
- tga->bitmap[buffer_caret] = (int) conversion_buffer[buffer_caret];
- buffer_caret++;
- }
-
- gdFree( conversion_buffer );
- }
-
- /*! \brief Read in RLE compressed RGB TGA
- * Chunk load the pixel data from an RLE compressed RGB type TGA.
- */
- if (tga->imagetype == TGA_TYPE_RGB_RLE) {
- decompression_buffer = (byte*) gdMalloc(image_block_size * sizeof(byte));
- if (decompression_buffer == NULL) {
- gdFree( decompression_buffer );
- return -1;
- }
- conversion_buffer = (unsigned char *) gdMalloc(image_block_size * sizeof(unsigned char));
- if (conversion_buffer == NULL) {
- gdFree( decompression_buffer );
- gdFree( conversion_buffer );
- return -1;
- }
-
- gdGetBuf( conversion_buffer, image_block_size, ctx );
-
- buffer_caret = 0;
-
- while( buffer_caret < image_block_size ) {
- decompression_buffer[buffer_caret] = (int)conversion_buffer[buffer_caret];
- buffer_caret++;
- }
-
- buffer_caret = 0;
-
- while( bitmap_caret < image_block_size ) {
-
- if ((decompression_buffer[buffer_caret] & TGA_RLE_FLAG) == TGA_RLE_FLAG) {
- encoded_pixels = ( ( decompression_buffer[ buffer_caret ] & 127 ) + 1 );
- buffer_caret++;
-
- for (i = 0; i < encoded_pixels; i++) {
- for (j = 0; j < pixel_block_size; j++, bitmap_caret++) {
- tga->bitmap[ bitmap_caret ] = decompression_buffer[ buffer_caret + j ];
- }
- }
- buffer_caret += pixel_block_size;
- } else {
- encoded_pixels = decompression_buffer[ buffer_caret ] + 1;
- buffer_caret++;
-
- for (i = 0; i < encoded_pixels; i++) {
- for( j = 0; j < pixel_block_size; j++, bitmap_caret++ ) {
- tga->bitmap[ bitmap_caret ] = decompression_buffer[ buffer_caret + j ];
- }
- buffer_caret += pixel_block_size;
- }
- }
- }
-
- gdFree( decompression_buffer );
- gdFree( conversion_buffer );
-
- }
-
- /*! \todo Add image type support
- * Add support for this image type.
- */
- if( tga->imagetype == TGA_TYPE_GREYSCALE ) {
- return -1;
- }
-
- /*! \todo Add image type support
- * Add support for this image type.
- */
- if( tga->imagetype == TGA_TYPE_GREYSCALE_RLE ) {
- return -1;
- }
-
- return 0;
-}
-
-/*! \brief Cleans up a TGA structure.
- * Dereferences the bitmap referenced in a TGA structure, then the structure itself
- * \param tga Pointer to TGA structure
- */
-void free_tga(oTga * tga) {
- if (tga) {
- if (tga->ident) {
- gdFree(tga->ident);
- tga->ident = NULL;
- }
- if (tga->bitmap) {
- gdFree(tga->bitmap);
- tga->bitmap = NULL;
- }
- gdFree(tga);
- tga = NULL;
- }
-}
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gd_tga.h"
+#include "gd.h"
+#include "gdhelpers.h"
+
+/*! \brief Creates a gdImage from a TGA file
+ * Creates a gdImage from a TGA binary file via a gdIOCtx.
+ * \param infile Pointer to TGA binary file
+ * \return gdImagePtr
+ */
+BGD_DECLARE(gdImagePtr) gdImageCreateFromTga(FILE * fp)
+{
+ gdImagePtr image;
+ gdIOCtx* in = gdNewFileCtx(fp);
+ image = gdImageCreateFromTgaCtx(in);
+ in->gd_free( in );
+ return image;
+}
+
+BGD_DECLARE(gdImagePtr) gdImageCreateFromTgaPtr(int size, void *data)
+{
+ gdImagePtr im;
+ gdIOCtx *in = gdNewDynamicCtxEx (size, data, 0);
+ im = gdImageCreateFromTgaCtx(in);
+ in->gd_free(in);
+ return im;
+}
+
+
+/*! \brief Creates a gdImage from a gdIOCtx
+ * Creates a gdImage from a gdIOCtx referencing a TGA binary file.
+ * \param ctx Pointer to a gdIOCtx structure
+ * \return gdImagePtr
+ */
+BGD_DECLARE(gdImagePtr) gdImageCreateFromTgaCtx(gdIOCtx* ctx)
+{
+
+ int bitmap_caret = 0;
+ int i = 0;
+ oTga *tga = NULL;
+ int pixel_block_size = 0;
+ int image_block_size = 0;
+ volatile gdImagePtr image = NULL;
+ int x = 0;
+ int y = 0;
+ int color = 0;
+
+ tga = (oTga *) gdMalloc(sizeof(oTga));
+ if (!tga) {
+ return NULL;
+ }
+
+ tga->bitmap = NULL;
+ tga->ident = NULL;
+
+ if (!read_header_tga(ctx, tga)) {
+ free_tga(tga);
+ return NULL;
+ }
+
+ pixel_block_size = tga->bits / 8;
+ image_block_size = (tga->width * tga->height) * pixel_block_size;
+
+ if (read_image_tga(ctx, tga)) {
+ free_tga(tga);
+ return NULL;
+ }
+
+ image = gdImageCreateTrueColor((int)tga->width, (int)tga->height );
+
+ if (image == 0) {
+ free_tga( tga );
+ return NULL;
+ }
+
+ /*! \brief Populate GD image object
+ * Copy the pixel data from our tga bitmap buffer into the GD image
+ * Disable blending and save the alpha channel per default
+ */
+ if (tga->alphabits) {
+ gdImageAlphaBlending(image, 0);
+ gdImageSaveAlpha(image, 1);
+ }
+
+ /* TODO: use alphabits as soon as we support 24bit and other alpha bps (ie != 8bits) */
+ for (y = 0; y < tga->height; y++) {
+ register int *tpix = image->tpixels[y];
+ for ( x = 0; x < tga->width; x++, tpix++) {
+ if (tga->bits == TGA_BPP_24) {
+ *tpix = gdTrueColor(tga->bitmap[bitmap_caret + 2], tga->bitmap[bitmap_caret + 1], tga->bitmap[bitmap_caret]);
+ bitmap_caret += 3;
+ } else if (tga->bits == TGA_BPP_32 || tga->alphabits) {
+ register int a = tga->bitmap[bitmap_caret + 3];
+
+ *tpix = gdTrueColorAlpha(tga->bitmap[bitmap_caret + 2], tga->bitmap[bitmap_caret + 1], tga->bitmap[bitmap_caret], gdAlphaMax - (a >> 1));
+ bitmap_caret += 4;
+ }
+ }
+ }
+/* TODO: enable this part as soon as the flip functions have been commited*/
+#if 0
+ if (tga->flipv && tga->fliph) {
+ gdImageFlip(image, GD_FLIP_BOTH);
+ } else if (tga->flipv) {
+ gdImageFlip(image, GD_FLIP_HORIZONTAL);
+ } else if (tga->fliph) {
+ gdImageFlip(image, GD_FLIP_VERTICAL);
+ }
+#endif
+ free_tga(tga);
+
+ return image;
+}
+
+/*! \brief Reads a TGA header.
+ * Reads the header block from a binary TGA file populating the referenced TGA structure.
+ * \param ctx Pointer to TGA binary file
+ * \param tga Pointer to TGA structure
+ * \return int 1 on sucess, -1 on failure
+ */
+int read_header_tga(gdIOCtx *ctx, oTga *tga) {
+
+ unsigned char header[18];
+
+ if (gdGetBuf(header, sizeof(header), ctx) < 18) {
+ fprintf(stderr, "fail to read header");
+ return -1;
+ }
+
+ tga->identsize = header[0];
+ tga->colormaptype = header[1];
+ tga->imagetype = header[2];
+ tga->colormapstart = header[3] + (header[4] << 8);
+ tga->colormaplength = header[5] + (header[6] << 8);
+ tga->colormapbits = header[7];
+ tga->xstart = header[8] + (header[9] << 8);
+ tga->ystart = header[10] + (header[11] << 8);
+ tga->width = header[12] + (header[13] << 8);
+ tga->height = header[14] + (header[15] << 8);
+ tga->bits = header[16];
+ tga->alphabits = header[17] & 0x0f;
+ tga->fliph = (header[17] & 0x10) ? 1 : 0;
+ tga->flipv = (header[17] & 0x20) ? 0 : 1;
+
+#if DEBUG
+ printf("format bps: %i\n", tga->bits);
+ printf("flip h/v: %i / %i\n", tga->fliph, tga->flipv);
+ printf("alpha: %i\n", tga->alphabits);
+ printf("wxh: %i %i\n", tga->width, tga->height);
+#endif
+
+ if (tga->bits != 8 && tga->bits != 24 && tga->bits != 16 && tga->bits != 32) {
+ fprintf(stderr, "bps %i not supported", tga->bits);
+ return -1;
+ }
+
+ tga->ident = (char *) gdMalloc(tga->identsize * sizeof( char ));
+ if (tga->ident == NULL) {
+ return -1;
+ }
+
+ if (tga->identsize > 0) {
+ gdGetBuf( &( tga->ident ), tga->identsize, ctx );
+ }
+
+ return 1;
+}
+
+/*! \brief Reads a TGA image data into buffer.
+ * Reads the image data block from a binary TGA file populating the referenced TGA structure.
+ * \param ctx Pointer to TGA binary file
+ * \param tga Pointer to TGA structure
+ * \return int 0 on sucess, -1 on failure
+ */
+int read_image_tga( gdIOCtx *ctx, oTga *tga ) {
+ int pixel_block_size = (tga->bits / 8);
+ int image_block_size = (tga->width * tga->height) * pixel_block_size;
+ byte* decompression_buffer = NULL;
+ unsigned char* conversion_buffer = NULL;
+ int buffer_caret = 0;
+ int bitmap_caret = 0;
+ int i = 0;
+ int j = 0;
+ byte encoded_pixels;
+
+ /*! \brief Allocate memmory for image block
+ * Allocate a chunk of memory for the image block to be passed into.
+ */
+ tga->bitmap = (byte *) gdMalloc(image_block_size * sizeof(byte));
+ if (tga->bitmap == NULL) {
+ return -1;
+ }
+
+ /*! \todo Add image type support
+ * Add support for this image type.
+ */
+ if (tga->imagetype == TGA_TYPE_INDEXED) {
+ return -1;
+ }
+
+ /*! \todo Add image type support
+ * Add support for this image type.
+ */
+ if (tga->imagetype == TGA_TYPE_INDEXED_RLE) {
+ return -1;
+ }
+
+ /*! \brief Read in uncompressed RGB TGA
+ * Chunk load the pixel data from an uncompressed RGB type TGA.
+ */
+ if (tga->imagetype == TGA_TYPE_RGB) {
+ conversion_buffer = (unsigned char *) gdMalloc(image_block_size * sizeof(unsigned char));
+ if (conversion_buffer == NULL) {
+ gdFree(conversion_buffer);
+ return -1;
+ }
+
+ gdGetBuf(conversion_buffer, image_block_size, ctx);
+
+ while (buffer_caret < image_block_size) {
+ tga->bitmap[buffer_caret] = (int) conversion_buffer[buffer_caret];
+ buffer_caret++;
+ }
+
+ gdFree( conversion_buffer );
+ }
+
+ /*! \brief Read in RLE compressed RGB TGA
+ * Chunk load the pixel data from an RLE compressed RGB type TGA.
+ */
+ if (tga->imagetype == TGA_TYPE_RGB_RLE) {
+ decompression_buffer = (byte*) gdMalloc(image_block_size * sizeof(byte));
+ if (decompression_buffer == NULL) {
+ gdFree( decompression_buffer );
+ return -1;
+ }
+ conversion_buffer = (unsigned char *) gdMalloc(image_block_size * sizeof(unsigned char));
+ if (conversion_buffer == NULL) {
+ gdFree( decompression_buffer );
+ gdFree( conversion_buffer );
+ return -1;
+ }
+
+ gdGetBuf( conversion_buffer, image_block_size, ctx );
+
+ buffer_caret = 0;
+
+ while( buffer_caret < image_block_size ) {
+ decompression_buffer[buffer_caret] = (int)conversion_buffer[buffer_caret];
+ buffer_caret++;
+ }
+
+ buffer_caret = 0;
+
+ while( bitmap_caret < image_block_size ) {
+
+ if ((decompression_buffer[buffer_caret] & TGA_RLE_FLAG) == TGA_RLE_FLAG) {
+ encoded_pixels = ( ( decompression_buffer[ buffer_caret ] & 127 ) + 1 );
+ buffer_caret++;
+
+ for (i = 0; i < encoded_pixels; i++) {
+ for (j = 0; j < pixel_block_size; j++, bitmap_caret++) {
+ tga->bitmap[ bitmap_caret ] = decompression_buffer[ buffer_caret + j ];
+ }
+ }
+ buffer_caret += pixel_block_size;
+ } else {
+ encoded_pixels = decompression_buffer[ buffer_caret ] + 1;
+ buffer_caret++;
+
+ for (i = 0; i < encoded_pixels; i++) {
+ for( j = 0; j < pixel_block_size; j++, bitmap_caret++ ) {
+ tga->bitmap[ bitmap_caret ] = decompression_buffer[ buffer_caret + j ];
+ }
+ buffer_caret += pixel_block_size;
+ }
+ }
+ }
+
+ gdFree( decompression_buffer );
+ gdFree( conversion_buffer );
+
+ }
+
+ /*! \todo Add image type support
+ * Add support for this image type.
+ */
+ if( tga->imagetype == TGA_TYPE_GREYSCALE ) {
+ return -1;
+ }
+
+ /*! \todo Add image type support
+ * Add support for this image type.
+ */
+ if( tga->imagetype == TGA_TYPE_GREYSCALE_RLE ) {
+ return -1;
+ }
+
+ return 0;
+}
+
+/*! \brief Cleans up a TGA structure.
+ * Dereferences the bitmap referenced in a TGA structure, then the structure itself
+ * \param tga Pointer to TGA structure
+ */
+void free_tga(oTga * tga) {
+ if (tga) {
+ if (tga->ident) {
+ gdFree(tga->ident);
+ tga->ident = NULL;
+ }
+ if (tga->bitmap) {
+ gdFree(tga->bitmap);
+ tga->bitmap = NULL;
+ }
+ gdFree(tga);
+ tga = NULL;
+ }
+}
http://cvs.php.net/viewvc.cgi/gd/libgd/src/gd_tga.h?r1=1.2&r2=1.3&diff_format=u
Index: gd/libgd/src/gd_tga.h
diff -u gd/libgd/src/gd_tga.h:1.2 gd/libgd/src/gd_tga.h:1.3
--- gd/libgd/src/gd_tga.h:1.2 Mon Oct 8 07:21:40 2007
+++ gd/libgd/src/gd_tga.h Sat Oct 13 18:18:27 2007
@@ -1,87 +1,87 @@
-/*
- * TGA Image read support
- * Copyright (C) 2005 Andrew Ireland, Jon Keto, Michael Beal
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#define TGA_LINE_LENGTH 1024
-
-#ifndef __TGA_H
-#define __TGA_H 1
-
-
-#include "gd.h"
-#include "gdhelpers.h"
-
-
-#ifndef O_BYTE
-#define O_BYTE 1
- typedef int byte;
-#endif
-#ifndef O_SHORT_INT
-#define O_SHORT_INT 1
- typedef int short_int;
-#endif
-
-typedef struct oTga_
-{
- byte identsize; // size of ID field that follows 18 byte header (0 usually)
- byte colourmaptype; // type of colour map 0=none, 1=has palette [IGNORED] Adrian requested no support
- byte imagetype; // type of image 0=none,1=indexed,2=rgb,3=grey,+8=rle packed
-
- int colourmapstart; // first colour map entry in palette [IGNORED] Adrian requested no support
- int colourmaplength; // number of colours in palette [IGNORED] Adrian requested no support
- byte colourmapbits; // number of bits per palette entry 15,16,24,32 [IGNORED] Adrian requested no support
-
- int xstart; // image x origin
- int ystart; // image y origin
- int width; // image width in pixels
- int height; // image height in pixels
- byte bits; // image bits per pixel 8,16,24,32
- byte alphabits; // alpha bits (low 4bits of header 17)
- byte fliph; // horizontal or vertical
- byte flipv; // flip
- char *ident; // identifcation tag string
- int *bitmap; // bitmap data
-
-} oTga;
-
-#define TGA_TYPE_NO_IMAGE 0
-#define TGA_TYPE_INDEXED 1
-#define TGA_TYPE_RGB 2
-#define TGA_TYPE_GREYSCALE 3
-#define TGA_TYPE_INDEXED_RLE 9
-#define TGA_TYPE_RGB_RLE 10
-#define TGA_TYPE_GREYSCALE_RLE 11
-#define TGA_TYPE_INDEXED_HUFFMAN_DELTA_RLE 32
-#define TGA_TYPE_RGB_HUFFMAN_DELTA_QUADTREE_RLE 33
-
-#define TGA_BPP_8 8
-#define TGA_BPP_16 16
-#define TGA_BPP_24 24
-#define TGA_BPP_32 32
-
-#define TGA_RLE_FLAG 128
-
-gdImagePtr gdImageCreateFromTGA( FILE * fp );
-gdImagePtr gdImageCreateFromTGACtx( gdIOCtx* ctx );
-
-int read_header_tga(gdIOCtx *ctx, oTga *tga);
-int read_image_tga(gdIOCtx *ctx, oTga *tga);
-void free_tga(oTga * tga);
-
-#endif //__TGA_H
+/*
+ * TGA Image read support
+ * Copyright (C) 2005 Andrew Ireland, Jon Keto, Michael Beal
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#define TGA_LINE_LENGTH 1024
+
+#ifndef __TGA_H
+#define __TGA_H 1
+
+
+#include "gd.h"
+#include "gdhelpers.h"
+
+
+#ifndef O_BYTE
+#define O_BYTE 1
+ typedef int byte;
+#endif
+#ifndef O_SHORT_INT
+#define O_SHORT_INT 1
+ typedef int short_int;
+#endif
+
+typedef struct oTga_
+{
+ byte identsize; // size of ID field that follows 18 byte header (0 usually)
+ byte colormaptype; // type of colour map 0=none, 1=has palette [IGNORED] Adrian requested no support
+ byte imagetype; // type of image 0=none,1=indexed,2=rgb,3=grey,+8=rle packed
+
+ int colormapstart; // first colour map entry in palette [IGNORED] Adrian requested no support
+ int colormaplength; // number of colours in palette [IGNORED] Adrian requested no support
+ byte colormapbits; // number of bits per palette entry 15,16,24,32 [IGNORED] Adrian requested no support
+
+ int xstart; // image x origin
+ int ystart; // image y origin
+ int width; // image width in pixels
+ int height; // image height in pixels
+ byte bits; // image bits per pixel 8,16,24,32
+ byte alphabits; // alpha bits (low 4bits of header 17)
+ byte fliph; // horizontal or vertical
+ byte flipv; // flip
+ char *ident; // identifcation tag string
+ int *bitmap; // bitmap data
+
+} oTga;
+
+#define TGA_TYPE_NO_IMAGE 0
+#define TGA_TYPE_INDEXED 1
+#define TGA_TYPE_RGB 2
+#define TGA_TYPE_GREYSCALE 3
+#define TGA_TYPE_INDEXED_RLE 9
+#define TGA_TYPE_RGB_RLE 10
+#define TGA_TYPE_GREYSCALE_RLE 11
+#define TGA_TYPE_INDEXED_HUFFMAN_DELTA_RLE 32
+#define TGA_TYPE_RGB_HUFFMAN_DELTA_QUADTREE_RLE 33
+
+#define TGA_BPP_8 8
+#define TGA_BPP_16 16
+#define TGA_BPP_24 24
+#define TGA_BPP_32 32
+
+#define TGA_RLE_FLAG 128
+
+gdImagePtr gdImageCreateFromTGA( FILE * fp );
+gdImagePtr gdImageCreateFromTGACtx( gdIOCtx* ctx );
+
+int read_header_tga(gdIOCtx *ctx, oTga *tga);
+int read_image_tga(gdIOCtx *ctx, oTga *tga);
+void free_tga(oTga * tga);
+
+#endif //__TGA_H
http://cvs.php.net/viewvc.cgi/gd/libgd/src/gd_tiff.c?r1=1.12&r2=1.13&diff_format=u
Index: gd/libgd/src/gd_tiff.c
diff -u gd/libgd/src/gd_tiff.c:1.12 gd/libgd/src/gd_tiff.c:1.13
--- gd/libgd/src/gd_tiff.c:1.12 Sun Oct 7 17:23:56 2007
+++ gd/libgd/src/gd_tiff.c Sat Oct 13 18:18:27 2007
@@ -27,7 +27,7 @@
----------------------------------------------------------------------------
*/
-/* $Id: gd_tiff.c,v 1.12 2007/10/07 17:23:56 pajoye Exp $ */
+/* $Id: gd_tiff.c,v 1.13 2007/10/13 18:18:27 scottmac Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -217,14 +217,14 @@
int r, g, b, a;
TIFF *tiff;
int width, height;
- int colour;
+ int color;
char *scan;
int rowsperstrip;
int samplesPerPixel = 3;
int bitsPerSample;
- int transparentColourR = -1;
- int transparentColourG = -1;
- int transparentColourB = -1;
+ int transparentColorR = -1;
+ int transparentColorG = -1;
+ int transparentColorB = -1;
uint16 extraSamples[1];
uint16 *colorMapRed;
uint16 *colorMapGreen;
@@ -248,9 +248,9 @@
/* handle old-style single-colour mapping to 100% transparency */
if(image->transparent != 0xffffffff) {
/* set our 100% transparent colour value */
- transparentColourR = gdImageRed(image, image->transparent);
- transparentColourG = gdImageGreen(image, image->transparent);
- transparentColourB = gdImageBlue(image, image->transparent);
+ transparentColorR = gdImageRed(image, image->transparent);
+ transparentColorG = gdImageGreen(image, image->transparent);
+ transparentColorB = gdImageBlue(image, image->transparent);
}
/* Open tiff file writing routines, but use special read/write/seek
@@ -328,19 +328,19 @@
for(y = 0; y < height; y++) {
for(x = 0; x < width; x++) {
/* generate scan line for writing to tiff */
- colour = gdImageGetPixel(image, x, y);
+ color = gdImageGetPixel(image, x, y);
- a = (127 - gdImageAlpha(image, colour)) * 2;
+ a = (127 - gdImageAlpha(image, color)) * 2;
a = (a == 0xfe) ? 0xff : a & 0xff;
- b = gdImageBlue(image, colour);
- g = gdImageGreen(image, colour);
- r = gdImageRed(image, colour);
+ b = gdImageBlue(image, color);
+ g = gdImageGreen(image, color);
+ r = gdImageRed(image, color);
/* if this pixel has the same RGB as the transparent colour,
* then set alpha fully transparent */
- if( transparentColourR == r &&
- transparentColourG == g &&
- transparentColourB == b
+ if( transparentColorR == r &&
+ transparentColorG == g &&
+ transparentColorB == b
) {
a = 0x00;
}
@@ -348,7 +348,7 @@
if(bitDepth != 24) {
/* write out 1 or 8 bit value in 1 byte
* (currently treats 1bit as 8bit) */
- scan[(x * samplesPerPixel) + 0] = colour;
+ scan[(x * samplesPerPixel) + 0] = color;
} else {
/* write out 24 bit value in 3 (or 4 if transparent) bytes */
if(image->saveAlphaFlag || image->transparent != 0xffffffff) {
@@ -720,7 +720,7 @@
int r, g, b, a;
int x, y;
int alphaBlendingFlag = 0;
- int colour;
+ int color;
int width = im->sx;
int height = im->sy;
uint32 *buffer;
@@ -745,10 +745,10 @@
* else use existing one */
rgba = buffer[(y * width + x)];
a = (0xff - TIFFGetA(rgba)) / 2;
- colour = gdTrueColorAlpha(TIFFGetR(rgba), TIFFGetG(rgba), TIFFGetB(rgba), a);
+ color = gdTrueColorAlpha(TIFFGetR(rgba), TIFFGetG(rgba), TIFFGetB(rgba), a);
/* set pixel colour to this colour */
- gdImageSetPixel(im, x, height - y - 1, colour);
+ gdImageSetPixel(im, x, height - y - 1, color);
}
}