void MCScreenDC::create_stipple() { graystipple = XCreatePixmap(dpy, getroot(), 32, 32, 1); gc1 = XCreateGC(dpy, graystipple, 0, NULL); XSetGraphicsExposures(dpy, gc1, False); XSetForeground(dpy, gc1, 1); XSetBackground(dpy, gc1, 0); Boolean oldshm = MCshm; MCBitmap *im = createimage(1, 64, 64, False, 0x0, True, False); int2 i; uint4 *dptr = (uint4 *)im->data; for (i = 0 ; i < 16 ; i++) { *dptr++ = 0xAAAAAAAA; *dptr++ = 0xAAAAAAAA; *dptr++ = 0x55555555; *dptr++ = 0x55555555; } putimage(graystipple, im, 0, 0, 0, 0, 32, 32); XSync(dpy, False); if (oldshm != MCshm) putimage(graystipple, im, 0, 0, 0, 0, 32, 32); destroyimage(im); }
/*----------------------------------------------------------------------------*/ int sobel_image(my1Image *src, my1Image *dst_mag, my1Image *dst_ang) { my1Image buff1, buff2; int irow, icol, x, y, temp; // create temporary buffer if(!createimage(&buff1,src->height,src->width)) { //printf("Cannot allocate buff1 memory\n"); return -1; } if(!createimage(&buff2,src->height,src->width)) { freeimage(&buff1); //printf("Cannot allocate buff2 memory\n"); return -1; } // calculate directional edge sobel_x_image(src, &buff1); sobel_y_image(src, &buff2); // calculate angle for 3x3 neighbourhood for(irow=0;irow<src->height;irow++) { for(icol=0;icol<src->width;icol++) { x = imagepixel(&buff1,irow,icol); y = imagepixel(&buff2,irow,icol); setimagepixel(dst_mag,irow,icol,iabs(y)+iabs(x)); if(!dst_ang) continue; if(x>0) { if(y>0) { // q1 y = iabs(y); x = iabs(x); if(y>2*x) temp = 90; else if(x>2*y) temp = 0; else temp = 45; } else if(y<0) { // q4 y = iabs(y); x = iabs(x); if(y>2*x) temp = 270; else if(x>2*y) temp = 0; else temp = 315; } else { temp = 0; // +ve x-axis } } else if(x<0) { if(y>0) { // q2 y = iabs(y); x = iabs(x); if(y>2*x) temp = 90; else if(x>2*y) temp = 180; else temp = 135; } else if(y<0) { // q3 y = iabs(y); x = iabs(x); if(y>2*x) temp = 270; else if(x>2*y) temp = 180; else temp = 225; } else { temp = 180; // -ve x-axis } } else { if(y>0) { temp = 90; // +ve y-axis } else if(y<0) { temp = 270; // -ve y-axis } else { temp = 0; // origin! no edge? } } setimagepixel(dst_ang,irow,icol,temp); } } /* clean-up */ freeimage(&buff1); freeimage(&buff2); return 0; }
/*----------------------------------------------------------------------------*/ int main(int argc, char* argv[]) { int loop, test = 0, error = 0, command = COMMAND_NONE; int gray = 0, view = 1, help = 0; char *psave = 0x0, *pname = 0x0, *pdata = 0x0; my1Image currimage, tempimage, *pimage; my1IFrame currframe, tempframe; /* print tool info */ printf("\n%s - %s (%s)\n",MY1APP_PROGNAME,MY1APP_PROGINFO,MY1APP_PROGVERS); printf(" => by [email protected]\n\n"); /* check program arguments */ if(argc>1) { for(loop=1;loop<argc;loop++) { if(argv[loop][0]=='-') /* options! */ { if(!strcmp(argv[loop],"--save")) { loop++; if(loop<argc) psave = argv[loop]; else printf("Cannot get save file name - NOT saving!\n"); } else if(!strcmp(argv[loop],"--cdata")) { loop++; if(loop<argc) pdata = argv[loop]; else printf("Cannot get C data file name - NOT writing!\n"); } else if(!strcmp(argv[loop],"--gray")) { gray = 1; } else if(!strcmp(argv[loop],"--hide")) { view = 0; } else if(!strcmp(argv[loop],"--help")) { help = 1; } else { printf("Unknown option '%s'!\n",argv[loop]); } } else /* not an option? */ { /* first non-option must be file name! */ if(!pname) { pname = argv[loop]; continue; } /* then check for command! */ if(!strcmp(argv[loop],"laplace1")) { command = COMMAND_LAPLACE1; gray = 1; } else if(!strcmp(argv[loop],"sobelx")) { command = COMMAND_SOBELX; gray = 1; } else if(!strcmp(argv[loop],"sobely")) { command = COMMAND_SOBELY; gray = 1; } else if(!strcmp(argv[loop],"sobelall")) { command = COMMAND_SOBELALL; gray = 1; } else if(!strcmp(argv[loop],"laplace2")) { command = COMMAND_LAPLACE2; gray = 1; } else if(!strcmp(argv[loop],"gauss")) { command = COMMAND_GAUSS; gray = 1; } else { printf("Unknown parameter %s!\n",argv[loop]); continue; } /* warn if overriding previous command! */ if(command) { printf("Warning! Command '%s' overrides '%s'!\n", argv[loop],argv[test]); } test = loop; } } } /* check if user requested help */ if(help) { about(); return 0; } /** check input filename */ if(!pname) { printf("No filename given! Aborting!\n"); return ERROR_GENERAL; } /* initialize image & frame*/ initimage(&currimage); initimage(&tempimage); initframe(&currframe); initframe(&tempframe); /* try to open file */ if((error=load_image(&currimage,pname))<0) { return error; } /* display basic info */ printf("Input image: %s\n",pname); print_image_info(&currimage); /* convert grayscale if requested/required */ if(gray) grayscale_image(&currimage); /* process command */ switch(command) { case COMMAND_LAPLACE1: { createimage(&tempimage,currimage.height,currimage.width); laplace_image(&currimage,&tempimage); break; } case COMMAND_SOBELX: { createimage(&tempimage,currimage.height,currimage.width); sobel_x_image(&currimage,&tempimage); break; } case COMMAND_SOBELY: { createimage(&tempimage,currimage.height,currimage.width); sobel_y_image(&currimage,&tempimage); break; } case COMMAND_SOBELALL: { createimage(&tempimage,currimage.height,currimage.width); sobel_image(&currimage,&tempimage,0x0); break; } case COMMAND_LAPLACE2: { createimage(&tempimage,currimage.height,currimage.width); createframe(&currframe,currimage.height,currimage.width); createframe(&tempframe,currimage.height,currimage.width); image2frame(&currimage,&currframe,0); laplace_frame(&currframe,&tempframe); frame2image(&tempframe,&tempimage,1); break; } case COMMAND_GAUSS: { createimage(&tempimage,currimage.height,currimage.width); createframe(&currframe,currimage.height,currimage.width); createframe(&tempframe,currimage.height,currimage.width); image2frame(&currimage,&currframe,0); gauss_frame(&currframe,&tempframe,1.0,0x0); frame2image(&tempframe,&tempimage,1); break; } } if(!tempimage.length) pimage = &currimage; else pimage = &tempimage; printf("Check image:\n"); print_image_info(pimage); /** save results if requested */ if(psave) { printf("Saving image data to %s...\n",psave); error=save_image(pimage,psave); view = 0; } if(pdata) { printf("Saving C data to %s...\n",pdata); error=cdata_image(pimage,pdata); } /* view image if no request to hide! .. and NOT saving! */ if(view) view_image(pimage); /* cleanup */ freeframe(&currframe); freeframe(&tempframe); freeimage(&currimage); freeimage(&tempimage); return error; }