shithub: riscv

Download patch

ref: 558b9558d4d90c0dabaa57c9a3fe79f9f5f626d5
parent: 0a3eb7d6b1ef7e9ef569dcc8e73c98a8446b52fc
author: cinap_lenrek <[email protected]>
date: Thu Oct 18 16:17:12 EDT 2012

more generic way to deal with image chan conversion for resize/resample/rotate

this is to catch crazy color channels like k8a8 and the 15/16 bit
ones and CMAP. basically, just convert to RGBA32 or RGB24 depending
on if it has an alpha channel.

--- a/sys/src/cmd/resample.c
+++ b/sys/src/cmd/resample.c
@@ -203,7 +203,6 @@
 	Memimage *m, *new, *t1, *t2;
 	char *file;
 	ulong tchan;
-	char tmp[100];
 	double v;
 
 	for(i=-K2; i<=K2; i++){
@@ -278,8 +277,15 @@
 	if(xsize == 0)
 		xsize = (ysize * Dx(m->r)) / Dy(m->r);
 
-	new = nil;
 	switch(m->chan){
+	default:
+		for(tchan = m->chan; tchan; tchan >>= 8)
+			if(TYPE(tchan) == CAlpha){
+				tchan = RGBA32;
+				goto Convert;
+			}
+		tchan = RGB24;
+		goto Convert;
 
 	case GREY8:
 	case RGB24:
@@ -289,12 +295,6 @@
 		new = resample(xsize, ysize, m);
 		break;
 
-	case CMAP8:
-	case RGB15:
-	case RGB16:
-		tchan = RGB24;
-		goto Convert;
-
 	case GREY1:
 	case GREY2:
 	case GREY4:
@@ -314,9 +314,6 @@
 		memimagedraw(new, new->r, t2, t2->r.min, nil, ZP, S);
 		freememimage(t2);
 		break;
-
-	default:
-		sysfatal("can't handle channel type %s", chantostr(tmp, m->chan));
 	}
 
 	assert(new);
--- a/sys/src/cmd/resize.c
+++ b/sys/src/cmd/resize.c
@@ -97,7 +97,6 @@
 	int fd, xsize, ysize;
 	Memimage *im, *nim;
 	ulong ochan, tchan;
-	char buf[12];
 
 	xsize = ysize = 0;
 	ARGBEGIN{
@@ -134,7 +133,14 @@
 		ochan = im->chan;
 		switch(ochan){
 		default:
-			sysfatal("can't handle channel type %s", chantostr(buf, ochan));
+			for(tchan = ochan; tchan; tchan >>= 8)
+				if(TYPE(tchan) == CAlpha){
+					tchan = RGBA32;
+					break;
+				}
+			if(tchan == 0)
+				tchan = RGB24;
+			break;
 		case GREY8:
 		case RGB24:
 		case RGBA32:
@@ -141,11 +147,6 @@
 		case ARGB32:
 		case XRGB32:
 			tchan = ochan;
-			break;
-		case CMAP8:
-		case RGB16:
-		case RGB15:
-			tchan = RGB24;
 			break;
 		case GREY1:
 		case GREY2:
--- a/sys/src/cmd/rotate.c
+++ b/sys/src/cmd/rotate.c
@@ -10,27 +10,13 @@
 	ulong chan;
 	uchar *s, *d;
 	Memimage *w;
-	char buf[12];
 
-	bpp = m->depth/8;
+	bpp = (m->depth+7)/8;
 	chan = m->chan;
 	switch(chan){
-	default:
-		sysfatal("can't handle channel type %s", chantostr(buf, chan));
-	case RGB15:
-		bpp = 2;
-	case CMAP8:
-	case GREY8:
-	case RGB16:
-	case RGB24:
-	case RGBA32:
-	case ARGB32:
-	case XRGB32:
-		break;
 	case GREY1:
 	case GREY2:
 	case GREY4:
-		bpp = 1;
 		if((w = allocmemimage(m->r, GREY8)) == nil)
 			sysfatal("allocmemimage: %r");
 		memimagedraw(w, w->r, m, m->r.min, nil, ZP, S);