plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

multichan.c (949B)


      1 #include <u.h>
      2 #include <libc.h>
      3 #include <draw.h>
      4 #include <memdraw.h>
      5 #include <bio.h>
      6 #include "imagefile.h"
      7 
      8 /* Separate colors, if not a grey scale or bitmap, into one byte per color per pixel, no alpha or X */
      9 /* Result is GREY[1248] or RGB24 */
     10 
     11 int drawlog2[] = {
     12 	0, 0, 1, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0,
     13 	4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     14 	5
     15 };
     16 
     17 static
     18 int
     19 notrans(ulong chan)
     20 {
     21 	switch(chan){
     22 	case GREY1:
     23 	case GREY2:
     24 	case GREY4:
     25 	case GREY8:
     26 	case RGB24:
     27 		return 1;
     28 	}
     29 	return 0;
     30 }
     31 
     32 Image*
     33 multichan(Image *i)
     34 {
     35 	Image *ni;
     36 
     37 	if(notrans(i->chan))
     38 		return i;
     39 
     40 	ni = allocimage(display, i->r, RGB24, 0, DNofill);
     41 	if(ni == nil)
     42 		return ni;
     43 	draw(ni, ni->r, i, nil, i->r.min);
     44 	return ni;
     45 }
     46 
     47 Memimage*
     48 memmultichan(Memimage *i)
     49 {
     50 	Memimage *ni;
     51 
     52 	if(notrans(i->chan))
     53 		return i;
     54 
     55 	ni = allocmemimage(i->r, RGB24);
     56 	if(ni == nil)
     57 		return ni;
     58 	memimagedraw(ni, ni->r, i, i->r.min, nil, i->r.min, S);
     59 	return ni;
     60 }