cvs: gd /libgd/src gd.h gd_tga.c gd_tga.h

From: Date: Mon, 08 Oct 2007 07:21:41 +0000
Subject: cvs: gd /libgd/src gd.h gd_tga.c gd_tga.h
Groups: php.gd.cvs 
Request: Send a blank email to php-gd-cvs+get-310@lists.php.net to get a copy of this message
pajoye Mon Oct 8 07:21:41 2007 UTC Modified files: /gd/libgd/src gd.h gd_tga.c gd_tga.h Log: - #122: - export new TGA functions - fix alpha support (32bit) in TGA - Add EOF macro (will ease our work while merging to php) http://cvs.php.net/viewvc.cgi/gd/libgd/src/gd.h?r1=1.39&r2=1.40&diff_format=u Index: gd/libgd/src/gd.h diff -u gd/libgd/src/gd.h:1.39 gd/libgd/src/gd.h:1.40 --- gd/libgd/src/gd.h:1.39 Sat Oct 6 10:39:29 2007 +++ gd/libgd/src/gd.h Mon Oct 8 07:21:40 2007 @@ -292,6 +292,10 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffCtx(gdIOCtx *infile); BGD_DECLARE(gdImagePtr) gdImageCreateFromTiffPtr(int size, void *data); +BGD_DECLARE(gdImagePtr) gdImageCreateFromTga( FILE * fp ); +BGD_DECLARE(gdImagePtr) gdImageCreateFromTgaCtx(gdIOCtx* ctx); +BGD_DECLARE(gdImagePtr) gdImageCreateFromTgaPtr(int size, void *data); + /* A custom data source. */ /* The source function must return -1 on error, otherwise the number of bytes fetched. 0 is EOF, not an error! */ http://cvs.php.net/viewvc.cgi/gd/libgd/src/gd_tga.c?r1=1.1&r2=1.2&diff_format=u Index: gd/libgd/src/gd_tga.c diff -u gd/libgd/src/gd_tga.c:1.1 gd/libgd/src/gd_tga.c:1.2 --- gd/libgd/src/gd_tga.c:1.1 Sun Oct 7 19:41:52 2007 +++ gd/libgd/src/gd_tga.c Mon Oct 8 07:21:40 2007 @@ -79,27 +79,40 @@ /*! \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]; - if (tga->bits == TGA_BPP_32) { - *tpix = gdTrueColorAlpha(tga->bitmap[bitmap_caret + 2], tga->bitmap[bitmap_caret + 1], tga->bitmap[bitmap_caret], 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 pointer to our new image object return image; } @@ -113,29 +126,38 @@ unsigned char header[18]; - if (gdGetBuf(header, 18, ctx) < 18) { - printf("fail to read header"); + 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] * 256; - tga->colourmaplength = header[5] + header[6] * 256; + tga->colourmapstart = header[3] + (header[4] << 8); + tga->colourmaplength = header[5] + (header[6] << 8); tga->colourmapbits = header[7]; - tga->xstart = header[8] + header[9] * 256; - tga->ystart = header[10] + header[11] * 256; - tga->width = header[12] + header[13] * 256; - tga->height = header[14] + header[15] * 256; + 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->descriptor = header[17]; - tga->ident = (char *) gdMalloc(tga->identsize * sizeof( char )); if (tga->ident == NULL) { return -1; http://cvs.php.net/viewvc.cgi/gd/libgd/src/gd_tga.h?r1=1.1&r2=1.2&diff_format=u Index: gd/libgd/src/gd_tga.h diff -u gd/libgd/src/gd_tga.h:1.1 gd/libgd/src/gd_tga.h:1.2 --- gd/libgd/src/gd_tga.h:1.1 Sun Oct 7 19:41:52 2007 +++ gd/libgd/src/gd_tga.h Mon Oct 8 07:21:40 2007 @@ -52,15 +52,14 @@ int width; // image width in pixels int height; // image height in pixels byte bits; // image bits per pixel 8,16,24,32 - byte descriptor; // image descriptor bits (vh flip bits) - + 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

« previous php.gd.cvs (#310) next »