typedef struct { int depth; /* profondeur: 8 16 ou 24 */ int w, h; /* largeur, hauteur */ union { byte *b; /* tableau 8 bits */ unsigned short *s; /* tableau 16 bits */ unsigned int *i; /* tableau 24 bits */ } buf; void *xima; /* usage interne */ } WinImage;
Exemple 3
#include <win.h> #include <math.h> #include <unistd.h> int main(int argc, char *argv[]) { WinImage ima; int i, x, y, a, b; winInit(256, 256, black); ima=winCreateImage(50, 50, 0); /* image vert dégradé */ switch (ima.depth){ case 8: for (a=0;a<50;a++) for (b=0;b<50;b++) ima.buf.b[a+50*+b]=winRGB[0][a*6/50][0]; break; case 16: for (a=0;a<50;a++) for (b=0;b<50;b++) ima.buf.s[a+50*b]=(a*64/50)<<5; break; case 24: for (a=0;a<50;a++) for (b=0;b<50;b++) ima.buf.i[a+50*b]=(a*256/50)<<8; break; } for (i=0;;i++){ x=128+50*cos(i/10.0); y=128+50*sin(i/10.0); winPutImage(ima, x, y); } return(0); }