Patch provided by (lynx3d) Mathias Wein,

It fixes endian issues with 16bit targa images.
this is fixing bug #4982

Kent
This commit is contained in:
Kent Mein 2006-11-07 17:32:29 +00:00
parent f3a7541365
commit 387f3b6a07

@ -408,7 +408,8 @@ static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, int psize)
} }
} else{ } else{
if (psize & 1){ if (psize & 1){
col = (mem[0] << 8) + mem[1]; cp[0] = mem[0];
cp[1] = mem[1];
mem += 2; mem += 2;
} else{ } else{
col = *mem++; col = *mem++;
@ -445,7 +446,8 @@ static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, int psize)
} }
} else{ } else{
if (psize & 1){ if (psize & 1){
col = (mem[0] << 8) + mem[1]; cp[0] = mem[0];
cp[1] = mem[1];
mem += 2; mem += 2;
} else{ } else{
col = *mem++; col = *mem++;
@ -496,7 +498,8 @@ static void ldtarga(struct ImBuf * ibuf,unsigned char * mem, int psize)
} }
} else{ } else{
if (psize & 1){ if (psize & 1){
col = (mem[1] << 8) + mem[0]; cp[0] = mem[0];
cp[1] = mem[1];
mem += 2; mem += 2;
} else{ } else{
col = *mem++; col = *mem++;
@ -599,11 +602,16 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, int flags)
if (tga.pixsize == 16 && ibuf->cmap == 0){ if (tga.pixsize == 16 && ibuf->cmap == 0){
rect = ibuf->rect; rect = ibuf->rect;
for (size = ibuf->x * ibuf->y; size > 0; size --){ for (size = ibuf->x * ibuf->y; size > 0; --size, ++rect){
col = *rect; col = *rect;
col = ((col & 0x1f) << 19) + ((col & 0x3e0) << 6) + ((col & 0x7c00) >> 7) ; uchar *cp = (uchar*)rect, *mem = (uchar*)&col;
col += (col & 0xe0e0e0) >> 5; cp[3] = ((mem[1] << 1) & 0xf8);
*rect++ = col + 0xff000000; cp[2] = ((mem[0] & 0xe0) >> 2) + ((mem[1] & 0x03) << 6);
cp[1] = ((mem[0] << 3) & 0xf8);
cp[1] += cp[1] >> 5;
cp[2] += cp[2] >> 5;
cp[3] += cp[3] >> 5;
cp[0] = 0xff;
} }
ibuf->depth = 24; ibuf->depth = 24;
} }