From: Arnar Mar Hrafnkelsson Date: Sun, 16 Sep 2001 21:16:14 +0000 (+0000) Subject: Adds reading of non colour mapped targa images. X-Git-Tag: Imager-0.48^2~567 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/7c58edfcb95e51e9aefdbbecef3fef143ba5e01e Adds reading of non colour mapped targa images. --- diff --git a/tga.c b/tga.c index 0f467ba4..495ca131 100644 --- a/tga.c +++ b/tga.c @@ -72,19 +72,17 @@ Retrieve an image and stores in the iolayer object. Returns NULL on fatal error. i_img * i_readtga_wiol(io_glue *ig, int length) { i_img* img; - int type; - int y, i; + int x, y, i; int width, height, channels; char *idstring; - unsigned char *uc; - i_color val; tga_header header; size_t palbsize; unsigned char *palbuf; unsigned char headbuf[18]; - unsigned char *linebuf; - + unsigned char *databuf; + i_color *linebuf; + i_clear_error(); mm_log((1,"i_readtga(ig %p, length %d)\n", ig, length)); @@ -187,14 +185,14 @@ i_readtga_wiol(io_glue *ig, int length) { /* read image data in */ - linebuf = mymalloc(width); + databuf = mymalloc(width); for(y=height-1;y>=0;y--) { - if (ig->readcb(ig, linebuf, width) != width) { + if (ig->readcb(ig, databuf, width) != width) { i_push_error(errno, "read for targa data failed"); - myfree(linebuf); + myfree(databuf); return NULL; } - i_ppal(img, 0, width, y, linebuf); + i_ppal(img, 0, width, y, databuf); } return img; @@ -202,7 +200,41 @@ i_readtga_wiol(io_glue *ig, int length) { case 2: /* Uncompressed, RGB images */ mm_log((1, "Uncompressed RGB image\n")); + + if (header.imagedescriptor != 0) { + i_push_error(0, "Targa: Imagedescriptor not 0, not supported internal format"); + return NULL; + } + + if (header.bitsperpixel != 24) { + i_push_error(0, "Targa: bpp is not 24, unsupported."); + return NULL; + } channels = 3; + + img = i_img_empty_ch(NULL, width, height, channels); + /* read image data in */ + databuf = mymalloc(width*channels); + linebuf = mymalloc(width*sizeof(i_color)); + + for(y=height-1;y>=0;y--) { + if (ig->readcb(ig, databuf, width*channels) != width*channels) { + i_push_error(errno, "read for targa data failed"); + myfree(linebuf); + myfree(databuf); + return NULL; + } + for(x=0; xtype == i_palette_type) { + + + + + } + + + + + + + + if (im->channels == 3) { sprintf(header,"P6\n#CREATOR: Imager\n%d %d\n255\n",im->xsize,im->ysize); if (ig->writecb(ig,header,strlen(header))<0) {