[q-lang-cvs] q/modules/magick magick.c,1.12,1.13 magick.q,1.10,1.11
Brought to you by:
agraef
From: <ag...@us...> - 2003-12-28 11:14:46
|
Update of /cvsroot/q-lang/q/modules/magick In directory sc8-pr-cvs1:/tmp/cvs-serv31440 Modified Files: magick.c magick.q Log Message: more image manipulation functions Index: magick.c =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** magick.c 28 Dec 2003 01:56:36 -0000 1.12 --- magick.c 28 Dec 2003 11:14:41 -0000 1.13 *************** *** 853,859 **** is_image_list(argv[0], &imgs)) && (isobj(argv[1], type(Image), (void**)&img2) || ! isuint(argv[1], &space) && space <= 2 || istuple(argv[1], &n, &xv) && n == 2 && ! isuint(xv[0], &space) && space <= 2 && isuint(xv[1], &ncolors) && ncolors <= MaxRGB) && isbool(argv[2], &dither)) { --- 853,859 ---- is_image_list(argv[0], &imgs)) && (isobj(argv[1], type(Image), (void**)&img2) || ! isuint(argv[1], &space) && space <= 1 || istuple(argv[1], &n, &xv) && n == 2 && ! isuint(xv[0], &space) && space <= 1 && isuint(xv[1], &ncolors) && ncolors <= MaxRGB) && isbool(argv[2], &dither)) { *************** *** 936,939 **** --- 936,959 ---- } + FUNCTION(magick,roll,argc,argv) + { + Image *img; + int n; + expr *xv; + long x, y; + if (argc == 2 && isobj(argv[0], type(Image), (void**)&img) && + istuple(argv[1], &n, &xv) && n == 2 && + isint(xv[0], &x) && isint(xv[1], &y)) { + img = RollImage(img, x, y, &exception); + if (check_exception(&exception)) + return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); + else if (!img) + return __FAIL; + else + return mkobj(type(Image), img); + } else + return __FAIL; + } + FUNCTION(magick,shave,argc,argv) { *************** *** 1097,1100 **** --- 1117,1253 ---- else return mkobj(type(Image), img); + } else + return __FAIL; + } + + FUNCTION(magick,rotate,argc,argv) + { + Image *img; + double angle; + if (argc == 2 && isobj(argv[0], type(Image), (void**)&img) && + (isfloat(argv[1], &angle) || ismpz_float(argv[1], &angle))) { + img = RotateImage(img, angle, &exception); + if (check_exception(&exception)) + return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); + else if (!img) + return __FAIL; + else + return mkobj(type(Image), img); + } else + return __FAIL; + } + + FUNCTION(magick,shear,argc,argv) + { + Image *img; + int n; + expr *xv; + double xshear, yshear; + if (argc == 2 && isobj(argv[0], type(Image), (void**)&img) && + istuple(argv[1], &n, &xv) && n == 2 && + (isfloat(xv[0], &xshear) || ismpz_float(xv[0], &xshear)) && + (isfloat(xv[1], &yshear) || ismpz_float(xv[1], &yshear))) { + img = ShearImage(img, xshear, yshear, &exception); + if (check_exception(&exception)) + return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); + else if (!img) + return __FAIL; + else + return mkobj(type(Image), img); + } else + return __FAIL; + } + + FUNCTION(magick,affine_transform,argc,argv) + { + Image *img; + int n; + expr *xv; + AffineMatrix matrix; + if (argc == 3 && isobj(argv[0], type(Image), (void**)&img) && + istuple(argv[1], &n, &xv) && n == 4 && + (isfloat(xv[0], &matrix.sx) || ismpz_float(xv[0], &matrix.sx)) && + (isfloat(xv[1], &matrix.rx) || ismpz_float(xv[1], &matrix.rx)) && + (isfloat(xv[2], &matrix.ry) || ismpz_float(xv[2], &matrix.ry)) && + (isfloat(xv[3], &matrix.sy) || ismpz_float(xv[3], &matrix.sy)) && + istuple(argv[2], &n, &xv) && n == 2 && + (isfloat(xv[0], &matrix.tx) || ismpz_float(xv[0], &matrix.tx)) && + (isfloat(xv[1], &matrix.ty) || ismpz_float(xv[1], &matrix.ty))) { + img = AffineTransformImage(img, &matrix, &exception); + if (check_exception(&exception)) + return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); + else if (!img) + return __FAIL; + else + return mkobj(type(Image), img); + } else + return __FAIL; + } + + FUNCTION(magick,coalesce,argc,argv) + { + Image *imgs; + if (argc == 1 && is_image_list(argv[0], &imgs) && imgs) { + Image *img = CoalesceImages(imgs, &exception); + decompose_image_list(imgs); + if (check_exception(&exception)) + return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); + else if (!img) + return __FAIL; + else + return mk_image_list(img); + } else + return __FAIL; + } + + FUNCTION(magick,flatten,argc,argv) + { + Image *imgs; + if (argc == 1 && is_image_list(argv[0], &imgs) && imgs) { + Image *img = FlattenImages(imgs, &exception); + decompose_image_list(imgs); + if (check_exception(&exception)) + return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); + else if (!img) + return __FAIL; + else + return mkobj(type(Image), img); + } else + return __FAIL; + } + + FUNCTION(magick,deconstruct,argc,argv) + { + Image *imgs; + if (argc == 1 && is_image_list(argv[0], &imgs) && imgs) { + Image *img = DeconstructImages(imgs, &exception); + decompose_image_list(imgs); + if (check_exception(&exception)) + return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); + else if (!img) + return __FAIL; + else + return mk_image_list(img); + } else + return __FAIL; + } + + FUNCTION(magick,segment,argc,argv) + { + Image *img; + unsigned long space; + int verbose; + double cluster, smooth; + if (argc == 5 && isobj(argv[0], type(Image), (void**)&img) && + isuint(argv[1], &space) && space <= 1 && + isbool(argv[2], &verbose) && + (isfloat(argv[3], &cluster) || ismpz_float(argv[3], &cluster)) && + (isfloat(argv[4], &smooth) || ismpz_float(argv[4], &smooth))) { + int res = SegmentImage(img, (space==0)?GRAYColorspace:RGBColorspace, + verbose, cluster, smooth); + if (!res) + return __FAIL; + else + return mkvoid; } else return __FAIL; Index: magick.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.q,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** magick.q 28 Dec 2003 01:56:36 -0000 1.10 --- magick.q 28 Dec 2003 11:14:41 -0000 1.11 *************** *** 192,195 **** --- 192,198 ---- image_magick IMG = M where (W,H,D,A,M) = image_info IMG; + // TODO: We also need some operations here to retrieve and change various + // other image parameters, such as default background color and page geometry. + /* Retrieve various other useful information about an image. The count_image_ colors function determines the number of unique colors in an image. The *************** *** 235,281 **** algorithms. These are explained in more detail in the ImageMagick manual. */ ! /* Quantization. The SPACE parameter designates the target colorspace, and can ! be either (1) one of the constant values GRAY and RGB, or (2) a pair ! (SPACE, COLORS) denoting both the colorspace SPACE and the desired maximum ! number of colors COLORS, or (3) a reference image IMG2 specifying the ! colormap to be applied to the target image. In case (1) the number of ! colors defaults to 256. The second parameter DITHER is a flag which ! specifies whether to apply Floyd/Steinberg dithering to the image. The ! target image IMG can also be a list of images which are to be mapped to the ! same colormap. Please note that this is a BANG! type operation, thus if you ! you want to retain the original image(s) you will have to clone them ! first. */ public var const GRAY, RGB; def GRAY = 0, RGB = 1; ! public extern quantize IMG SPACE DITHER; // BANG! ! /* Resizing and scaling. */ - public extern chop IMG P DIM, crop IMG P DIM, shave IMG DIM; public extern magnify IMG, minify IMG; public extern resize IMG DIM BLUR, sample IMG DIM, scale IMG DIM; public extern thumbnail IMG DIM; ! /* Transformations. MATRIX = (SX,RX,RY,SY,TX,TY) denotes an affine ! transformation matrix. */ public extern flipx IMG, flipy IMG; ! ! // TODO ! // public extern rotate IMG ANGLE; ! // public extern roll IMG P, shear IMG P; ! // public extern transform IMG MATRIX; /* Combining and deconstructing images. */ ! // TODO ! // public extern coalesce IMGS, flatten IMGS, deconstruct IMGS; ! // public extern segment IMG CLUSTER SMOOTH; // BANG! ! // TODO: montage??? ! /* Composite operations. These are all of the BANG! type. */ // TODO --- 238,282 ---- algorithms. These are explained in more detail in the ImageMagick manual. */ ! /* Quantization. The COLORSPACE parameter designates the target colorspace, ! and can be either (1) one of the constant values GRAY and RGB, or (2) a ! pair (COLORSPACE, COLORS) denoting both the colorspace and the desired ! maximum number of colors, or (3) a reference image specifying the colormap ! to be applied to the target image. In case (1) the number of colors ! defaults to 256. The DITHER flag determines whether to apply Floyd/ ! Steinberg dithering to the image. The target image IMG can also be a list ! of images which are to be mapped to the same colormap. Please note that ! this is a BANG! type operation, thus if you you want to retain the original ! 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! ! /* Resizing, scaling and transformations. */ ! ! public extern chop IMG P DIM, crop IMG P DIM, roll IMG P, shave IMG DIM; public extern magnify IMG, minify IMG; public extern resize IMG DIM BLUR, sample IMG DIM, scale IMG DIM; public extern thumbnail IMG DIM; ! /* SHEAR is a pair (XSHEAR,YSHEAR) of shearing angles, MATRIX = (SX,RX,RY,SY) ! a linear transform matrix. Please note that rotated images are usually ! larger than the originals and have 'empty' triangular corners filled with ! the background color set on the image. */ public extern flipx IMG, flipy IMG; ! public extern rotate IMG ANGLE, shear IMG SHEAR; ! 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 |