shithub: riscv

Download patch

ref: a89aca24b9323ffd70f8d761c72840ef2ab80d4c
parent: 1f8313acc14d1a1f95bd775c86a12fda6639b3fb
author: ftrvxmtrx <[email protected]>
date: Sun Jan 20 06:27:03 EST 2013

readtga: clean-up

--- a/sys/src/cmd/jpg/readtga.c
+++ b/sys/src/cmd/jpg/readtga.c
@@ -17,17 +17,17 @@
 };
 
 typedef struct {
-	int idlen;		/* length of string after header */
-	int cmaptype;		/* 1 =>  datatype = 1 => colourmapped */
+	int idlen;			/* length of string after header */
+	int cmaptype;		/* 1 => datatype = 1 => colourmapped */
 	int datatype;		/* see below */
 	int cmaporigin;		/* index of first entry in colour map */
-	int cmaplen;		/* length of olour map */
-	int cmapbpp;		/* bips per pixel of colour map: 16, 24, or 32 */
+	int cmaplen;		/* length of colour map */
+	int cmapbpp;		/* bits per pixel of colour map: 16, 24, or 32 */
 	int xorigin;		/* source image origin */
 	int yorigin;
 	int width;
 	int height;
-	int bpp;		/* bits per pixel of image: 16, 24, or 32 */
+	int bpp;			/* bits per pixel of image: 16, 24, or 32 */
 	int descriptor;
 	uchar *cmap;		/* colour map (optional) */
 } Tga;
@@ -41,13 +41,13 @@
  */
 
 char *datatype[] = {
-	[0]	"No image data",
-	[1]	"color mapped",
-	[2]	"RGB",
-	[3]	"B&W",
-	[9]	"RLE color-mapped",
+	[0]		"No image data",
+	[1]		"Color mapped",
+	[2]		"RGB",
+	[3]		"B&W",
+	[9]		"RLE color mapped",
 	[10]	"RLE RGB",
-	[11]	"Compressed B&W",
+	[11]	"RLE B&W",
 	[32]	"Compressed color",
 	[33]	"Quadtree compressed color",
 };
@@ -352,28 +352,16 @@
 	num = h->width*h->height;
 	switch(h->datatype){
 	case 2:
-		if(rgba(bp, h->bpp, r, g, b, num) != num){
-			werrstr("ReadTGA: decode fail - %r\n");
-			goto Error;
-		}
+		n = rgba(bp, h->bpp, r, g, b, num);
 		break;
 	case 3:
-		if(luma(bp, r, num) != num){
-			werrstr("ReadTGA: decode fail - %r\n");
-			goto Error;
-		}
+		n = luma(bp, r, num);
 		break;
 	case 10:
-		if((n = rgba_rle(bp, h->bpp, r, g, b, num)) != num){
-			werrstr("ReadTGA: decode fail (%d!=%d) - %r\n", n, num);
-			goto Error;
-		}
+		n = rgba_rle(bp, h->bpp, r, g, b, num);
 		break;
 	case 11:
-		if(luma_rle(bp, r, num) != num){
-			werrstr("ReadTGA: decode fail - %r\n");
-			goto Error;
-		}
+		n = luma_rle(bp, r, num);
 		break;
 	default:
 		werrstr("ReadTGA: type=%d (%s) unsupported\n", h->datatype, datatype[h->datatype]);
@@ -380,11 +368,15 @@
 		goto Error;	
  	}
 
+	if(n != num){
+		werrstr("ReadTGA: decode fail (%d!=%d) - %r\n", n, num);
+		goto Error;
+	}
 	if(h->xorigin != 0)
 		reflect(ar);
 	if(h->yorigin == 0)
 		flip(ar);
-	
+
 	free(h->cmap);
 	free(h);
 	return array;