[q-lang-cvs] q/modules/magick magick.c,1.13,1.14 magick.q,1.11,1.12
Brought to you by:
agraef
From: <ag...@us...> - 2003-12-28 18:47:24
|
Update of /cvsroot/q-lang/q/modules/magick In directory sc8-pr-cvs1:/tmp/cvs-serv12172 Modified Files: magick.c magick.q Log Message: added composition and image enhancement operations Index: magick.c =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** magick.c 28 Dec 2003 11:14:41 -0000 1.13 --- magick.c 28 Dec 2003 18:47:19 -0000 1.14 *************** *** 134,139 **** } bstr_t; - #if 0 - /* manifest constants */ --- 134,137 ---- *************** *** 142,154 **** if (argc != 0) return __FAIL; return mktuplel ! (4, ! mkuint(FileResource), ! mkuint(MemoryResource), ! mkuint(MapResource), ! mkuint(DiskResource)); } - #endif - FUNCTION(magick,magick_info,argc,argv) { --- 140,177 ---- if (argc != 0) return __FAIL; return mktuplel ! (31, ! mkuint(OverCompositeOp), ! mkuint(InCompositeOp), ! mkuint(OutCompositeOp), ! mkuint(AtopCompositeOp), ! mkuint(XorCompositeOp), ! mkuint(PlusCompositeOp), ! mkuint(MinusCompositeOp), ! mkuint(AddCompositeOp), ! mkuint(SubtractCompositeOp), ! mkuint(DifferenceCompositeOp), ! mkuint(MultiplyCompositeOp), ! mkuint(BumpmapCompositeOp), ! mkuint(CopyCompositeOp), ! mkuint(CopyRedCompositeOp), ! mkuint(CopyGreenCompositeOp), ! mkuint(CopyBlueCompositeOp), ! mkuint(CopyOpacityCompositeOp), ! mkuint(ClearCompositeOp), ! mkuint(DissolveCompositeOp), ! mkuint(DisplaceCompositeOp), ! mkuint(ModulateCompositeOp), ! mkuint(ThresholdCompositeOp), ! mkuint(NoCompositeOp), ! mkuint(DarkenCompositeOp), ! mkuint(LightenCompositeOp), ! mkuint(HueCompositeOp), ! mkuint(SaturateCompositeOp), ! mkuint(ColorizeCompositeOp), ! mkuint(LuminizeCompositeOp), ! mkuint(ScreenCompositeOp), ! mkuint(OverlayCompositeOp)); } FUNCTION(magick,magick_info,argc,argv) { *************** *** 1246,1249 **** --- 1269,1379 ---- int res = SegmentImage(img, (space==0)?GRAYColorspace:RGBColorspace, verbose, cluster, smooth); + if (!res) + return __FAIL; + else + return mkvoid; + } else + return __FAIL; + } + + FUNCTION(magick,composite,argc,argv) + { + Image *img, *img2; + unsigned long op; + long x, y; + int n; + expr *xv; + if (argc == 4 && isobj(argv[0], type(Image), (void**)&img) && + isuint(argv[1], &op) && op > 0 && op <= OverlayCompositeOp && + isobj(argv[2], type(Image), (void**)&img2) && + istuple(argv[3], &n, &xv) && + isint(xv[0], &x) && isint(xv[1], &y)) { + int res = CompositeImage(img, op, img2, x, y); + if (!res) + return __FAIL; + else + return mkvoid; + } else + return __FAIL; + } + + FUNCTION(magick,contrast,argc,argv) + { + Image *img; + int sharpen; + if (argc == 2 && isobj(argv[0], type(Image), (void**)&img) && + isbool(argv[1], &sharpen)) { + /* With IM 5.5 this always returns false, bug? Therfore we just ignore the + return value. */ + ContrastImage(img, sharpen); + return mkvoid; + } else + return __FAIL; + } + + FUNCTION(magick,equalize,argc,argv) + { + Image *img; + if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) { + int res = EqualizeImage(img); + if (!res) + return __FAIL; + else + return mkvoid; + } else + return __FAIL; + } + + FUNCTION(magick,gamma,argc,argv) + { + Image *img; + char *val; + if (argc == 2 && isobj(argv[0], type(Image), (void**)&img) && + isstr(argv[1], &val) && GammaImage(img, val)) + return mkvoid; + else + return __FAIL; + } + + FUNCTION(magick,level,argc,argv) + { + Image *img; + char *val; + if (argc == 2 && isobj(argv[0], type(Image), (void**)&img) && + isstr(argv[1], &val) && LevelImage(img, val)) + return mkvoid; + else + return __FAIL; + } + + FUNCTION(magick,modulate,argc,argv) + { + Image *img; + char *val; + if (argc == 2 && isobj(argv[0], type(Image), (void**)&img) && + isstr(argv[1], &val) && ModulateImage(img, val)) + return mkvoid; + else + return __FAIL; + } + + FUNCTION(magick,negate,argc,argv) + { + Image *img; + if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) { + int res = NegateImage(img, 0); + if (!res) + return __FAIL; + else + return mkvoid; + } else + return __FAIL; + } + + FUNCTION(magick,normalize,argc,argv) + { + Image *img; + if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) { + int res = NormalizeImage(img); if (!res) return __FAIL; Index: magick.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.q,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** magick.q 28 Dec 2003 11:14:41 -0000 1.11 --- magick.q 28 Dec 2003 18:47:19 -0000 1.12 *************** *** 29,32 **** --- 29,53 ---- import clib; + /* Manifest constants. */ + + public var const GRAY, RGB; // colorspaces + def GRAY = 0, RGB = 1; + + public var const + // composite operators for the composite function + OVER_OP, IN_OP, OUT_OP, ATOP_OP, XOR_OP, PLUS_OP, MINUS_OP, ADD_OP, + SUBTRACT_OP, DIFFERENCE_OP, MULTIPLY_OP, BUMPMAP_OP, COPY_OP, COPYRED_OP, + COPYGREEN_OP, COPYBLUE_OP, COPYOPACITY_OP, CLEAR_OP, DISSOLVE_OP, + DISPLACE_OP, MODULATE_OP, THRESHOLD_OP, NO_OP, DARKEN_OP, LIGHTEN_OP, + HUE_OP, SATURATE_OP, COLORIZE_OP, LUMINIZE_OP, SCREEN_OP, OVERLAY_OP; + + private extern magick_vars; + def (OVER_OP, IN_OP, OUT_OP, ATOP_OP, XOR_OP, PLUS_OP, MINUS_OP, ADD_OP, + SUBTRACT_OP, DIFFERENCE_OP, MULTIPLY_OP, BUMPMAP_OP, COPY_OP, COPYRED_OP, + COPYGREEN_OP, COPYBLUE_OP, COPYOPACITY_OP, CLEAR_OP, DISSOLVE_OP, + DISPLACE_OP, MODULATE_OP, THRESHOLD_OP, NO_OP, DARKEN_OP, LIGHTEN_OP, + HUE_OP, SATURATE_OP, COLORIZE_OP, LUMINIZE_OP, SCREEN_OP, OVERLAY_OP) + = magick_vars; + /* The Image type. Objects of this type are created with the create_image and read_image operations, and processed by the other operations of this *************** *** 249,255 **** images you will have to clone them first. */ - public var const GRAY, RGB; - def GRAY = 0, RGB = 1; - public extern quantize IMG COLORSPACE DITHER; // BANG! --- 270,273 ---- *************** *** 271,323 **** public extern affine_transform IMG MATRIX P; ! /* Combining and deconstructing images. */ public extern coalesce IMGS, flatten IMGS, deconstruct IMGS; public extern segment IMG COLORSPACE VERBOSE CLUSTER SMOOTH; // BANG! // TODO: montage - /* Composition operations. These are all of the BANG! type. */ - - // TODO - // public extern composite_over IMG IMG2 P; - // public extern composite_in IMG IMG2 P; - // public extern composite_out IMG IMG2 P; - // public extern composite_atop IMG IMG2 P; - // public extern composite_xor IMG IMG2 P; - // public extern composite_plus IMG IMG2 P; - // public extern composite_minus IMG IMG2 P; - // public extern composite_add IMG IMG2 P; - // public extern composite_subtract IMG IMG2 P; - // public extern composite_difference IMG IMG2 P; - // public extern composite_multiply IMG IMG2 P; - // public extern composite_bumpmap IMG IMG2 P; - // public extern composite_copy IMG IMG2 P; - // public extern composite_copy_red IMG IMG2 P; - // public extern composite_copy_green IMG IMG2 P; - // public extern composite_copy_blue IMG IMG2 P; - // public extern composite_copy_matte IMG IMG2 P; - // public extern composite_dissolve IMG IMG2 P; - // public extern composite_clear IMG IMG2 P; - // public extern composite_displace IMG IMG2 P; - // public extern composite_modulate IMG IMG2 P; - // public extern composite_threshold IMG IMG2 P; - /* Image enhancement. SHARPEN = true or false, specifies whether to increase ! or decrease the contrast; GAMMA = either a singleton value or a triplet ! (R,G,B) of gamma correction values to be applied to the red, green and blue ! channels of an image; LEVEL = a singleton BLACK value, or a tuple of up to ! three values (BLACK,WHITE,GAMMA) used to adjust the contrast of an image; ! GRAY = true or false, specifies whether to negate only the intensities or ! the colors themselves. */ /* These are all of the BANG! type. */ ! // TODO ! // public extern contrast IMG SHARPEN, equalize IMG; ! // public extern gamma IMG GAMMA, level IMG LEVEL; ! // public extern modulate IMG BRIGHTNESS SATURATION HUE; ! // public extern negate IMG GRAY; ! // public extern normalize IMG; /* Effects. */ --- 289,313 ---- public extern affine_transform IMG MATRIX P; ! /* Combining and deconstructing images. The OP argument of composite can be ! any of the *_OP values defined in the manifest constants section. */ public extern coalesce IMGS, flatten IMGS, deconstruct IMGS; + public extern composite IMG OP IMG2 P; // BANG! public extern segment IMG COLORSPACE VERBOSE CLUSTER SMOOTH; // BANG! // TODO: montage /* Image enhancement. SHARPEN = true or false, specifies whether to increase ! or decrease the contrast. The VAL parameter of the gamma, level and ! modulate functions is a string specifying the gamma correction, contrast ! level and brightness/saturation/hue values in the same format as the ! parameters of the -gamma, -level and -modulate options of ImageMagick, see ! ImageMagick(1) for details. */ /* These are all of the BANG! type. */ ! public extern contrast IMG SHARPEN, equalize IMG; ! public extern gamma IMG VAL, level IMG VAL, modulate IMG VAL; ! public extern negate IMG, normalize IMG; /* Effects. */ |