#include #include #include #include #include #include "mothra.h" #define NBIT 8 /* bits per uchar, a source of non-portability */ /* * Copy an 8 bit image into a newly allocated bitmap, using Floyd-Steinberg * if depth<8 */ Image *floyd(Rectangle r, int depth, uchar *pixels){ int wid=r.max.x-r.min.x; int hgt=r.max.y-r.min.y; int w=depth; int nval=1<8) depth=8; b=allocimage(display, r, w<8? CHAN1(CGrey, w) : CHAN1(CMap, 8), 0, DNofill); if(b==0) return 0; if(depth==8){ loadimage(b, r, pixels, bytesperline(r, w)*Dy(r)); return b; } data=malloc((wid*w+NBIT-1)/NBIT); error=malloc((wid+2)*sizeof(int)); if(error==0 || data==0){ if(error) free(error); if(data) free(data); freeimage(b); return 0; } eerror=error+wid+1; for(i=0,p=cmap;i!=1<