ref: f7cd83ffe6a65578a9f1c89646facbcbfd7179a1
dir: /defs.c/
#include <u.h> #include <libc.h> #include "dat.h" #include "fns.h" char* prolog = "#include <u.h>\n" "#include <libc.h>\n" "#include <draw.h>\n" "#include <memdraw.h>\n" "\n" "Memimage*\n" "READ(char *file)\n" "{\n" " int fd;\n" " Memimage *m, *m1;\n" " if((fd = open(file, OREAD)) < 0)\n" " sysfatal(\"open: %r\");\n" " if((m = readmemimage(fd)) == nil)\n" " sysfatal(\"readmemimage: %r\");\n" " close(fd);\n" " if(m->chan != ABGR32){\n" " m1 = allocmemimage(m->r, ABGR32);\n" " memfillcolor(m1, DBlack);\n" " memimagedraw(m1, m1->r, m, m->r.min, memopaque, ZP, S);\n" " freememimage(m);\n" " m = m1;\n" " }\n" " return m;\n" "}\n\n" "void\n" "WRITE(Memimage *m, char *file)\n" "{\n" " int fd;\n" " if((fd = create(file, OWRITE, 0666)) < 0)\n" " sysfatal(\"create: %r\");\n" " if(writememimage(fd, m) < 0)\n" " sysfatal(\"writememimage: %r\");\n" " close(fd);\n" "}\n\n" "int\n" "POW(int a, int b)\n" "{\n" " int t;\n" " if(b <= 0) return 1;\n" " if(b == 1) return a;\n" " t = POW(a, b/2);\n" " t *= t;\n" " if(b%2) t *= a;\n" " return t;\n" "}\n" "\n" "int\n" "DIV(int a, int b)\n" "{\n" " if(b == 0) return 0;\n" " return a/b;\n" "}\n" "\n" "int\n" "MOD(int a, int b)\n" "{\n" " if(b == 0) return 0;\n" " return a%b;\n" "}\n" "\n" "#define Z 255\n" "\n" "uchar\n" "RIMAGE(Memimage *m, int x, int y, int z)\n" "{\n" " if(x < 0 || y < 0 || z < 0 || x >= Dx(m->r) || y >= Dy(m->r) || z > 3) return 0;\n" " return byteaddr(m, addpt(m->r.min, Pt(x,y)))[z];\n" "}\n" "\n" "uchar*\n" "WIMAGE(Memimage *m, int x, int y, int z)\n" "{\n" " static uchar devnull;\n" " if(x < 0 || y < 0 || z < 0 || x >= Dx(m->r) || y >= Dy(m->r) || z > 3) return &devnull;\n" " return byteaddr(m, addpt(m->r.min, Pt(x,y))) + z;\n" "}\n" "\n" "#define CLIP(x) ((x) < 0 ? 0 : (x) > 255 ? 255 : (x))\n" "\n" "void main(void) {\n" " int x, y, z, X, Y, T;\n" " Memimage *﹩new;\n" " if(memimageinit() < 0) sysfatal(\"initmemimage: %r\");\n" ; char *prepstr = " for(﹩i=﹩im; ﹩i<﹩im+nelem(﹩im); ﹩i++){\n" " if(*﹩i == nil) continue;\n" " if(X < Dx((*﹩i)->r)) X = Dx((*﹩i)->r);\n" " if(Y < Dy((*﹩i)->r)) Y = Dy((*﹩i)->r);\n" " }\n" " if((﹩new = allocmemimage(Rect(0,0,X,Y), ABGR32)) == nil)\n" " sysfatal(\"allocmemimage: %r\");\n" " for(z=0; z<4; z++) for(y=0; y<Y; y++) for(x=0; x<X; x++){\n" ; char *tailstr = ";\n" " *WIMAGE(﹩new, x,y,z) = CLIP(T);\n" " }\n" " WRITE(﹩new, out);\n" " exits(nil);\n" "}\n" ;