[q-lang-cvs] q/modules/magick magick.c,1.23,1.24 magick.q,1.21,1.22
Brought to you by:
agraef
From: <ag...@us...> - 2003-12-29 20:31:40
|
Update of /cvsroot/q-lang/q/modules/magick In directory sc8-pr-cvs1:/tmp/cvs-serv4183 Modified Files: magick.c magick.q Log Message: added compression options to write_image/image_to_blob, new image attribute ops Index: magick.c =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.c,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** magick.c 29 Dec 2003 13:08:32 -0000 1.23 --- magick.c 29 Dec 2003 20:31:36 -0000 1.24 *************** *** 137,141 **** if (argc != 0) return __FAIL; return mktuplel ! (52, mkuint(PointFilter), mkuint(BoxFilter), --- 137,151 ---- if (argc != 0) return __FAIL; return mktuplel ! (61, ! mkuint(NoCompression), ! mkuint(BZipCompression), ! mkuint(FaxCompression), ! mkuint(Group4Compression), ! mkuint(JPEGCompression), ! mkuint(LosslessJPEGCompression), ! mkuint(LZWCompression), ! mkuint(RLECompression), ! mkuint(ZipCompression), ! mkuint(PointFilter), mkuint(BoxFilter), *************** *** 375,378 **** --- 385,408 ---- } + /* compression info used by write_image and image_to_blob */ + + static int parse_info2(int n, expr *xv, ImageInfo *info) + { + int i = 0; + unsigned long compression, quality; + char *sampling_factor; + if (i >= n) return 1; + if (!isuint(xv[i++], &compression)) return 0; + info->compression = compression; + if (i >= n) return 1; + if (!isuint(xv[i++], &quality)) return 0; + info->quality = quality; + if (i >= n) return 1; + if (!isstr(xv[i++], &sampling_factor)) return 0; + info->sampling_factor = sampling_factor; + if (i >= n) return 1; + return 0; + } + FUNCTION(magick,image_info,argc,argv) { *************** *** 468,471 **** --- 498,563 ---- } + FUNCTION(magick,image_page,argc,argv) + { + Image *img; + if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) + return mktuplel(4, mkint(img->page.x), mkint(img->page.y), + mkuint(img->page.width), mkuint(img->page.height)); + else + return __FAIL; + } + + FUNCTION(magick,set_image_page,argc,argv) + { + Image *img; + int n; + expr *xv; + long x, y; + unsigned long w, h; + if (argc == 2 && isobj(argv[0], type(Image), (void**)&img) && + istuple(argv[1], &n, &xv)) { + if (n == 2) + if (isint(xv[0], &x) && isint(xv[1], &y)) { + img->page.x = x; + img->page.y = y; + } else + return __FAIL; + else if (n == 4) + if (isint(xv[0], &x) && isint(xv[1], &y) && + isuint(xv[2], &w) && isuint(xv[3], &h)) { + img->page.x = x; + img->page.y = y; + img->page.width = w; + img->page.height = h; + } else + return __FAIL; + else + return __FAIL; + return mkvoid; + } else + return __FAIL; + } + + FUNCTION(magick,image_compression,argc,argv) + { + Image *img; + if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) + return mkuint(img->compression); + else + return __FAIL; + } + + FUNCTION(magick,set_image_compression,argc,argv) + { + Image *img; + unsigned long compression; + if (argc == 2 && isobj(argv[0], type(Image), (void**)&img) && + isuint(argv[1], &compression)) { + img->compression = compression; + return mkvoid; + } else + return __FAIL; + } + FUNCTION(magick,count_image_colors,argc,argv) { *************** *** 609,617 **** FUNCTION(magick,create_image,argc,argv) { ! expr *xv; int n = 0; bstr_t *m; unsigned long w, h; ! if (argc == 2 && istuple(argv[0], &n, &xv) && n >= 2 && n <= 5 && isuint(xv[0], &w) && isuint(xv[1], &h) && w > 0 && h > 0 && isobj(argv[1], type(ByteStr), (void**)&m)) { --- 701,709 ---- FUNCTION(magick,create_image,argc,argv) { ! expr *xv = NULL; int n = 0; bstr_t *m; unsigned long w, h; ! if (argc == 2 && istuple(argv[0], &n, &xv) && n >= 2 && isuint(xv[0], &w) && isuint(xv[1], &h) && w > 0 && h > 0 && isobj(argv[1], type(ByteStr), (void**)&m)) { *************** *** 707,715 **** { char *s; ! expr *xv; int n = 0; if (argc == 2 && isstr(argv[0], &s) && ! (istuple(argv[1], &n, &xv) || isvoid(argv[1])) && ! n <= 5) { ImageInfo info; Image *img; --- 799,806 ---- { char *s; ! expr *xv = NULL; int n = 0; if (argc == 2 && isstr(argv[0], &s) && ! (istuple(argv[1], &n, &xv) || isvoid(argv[1]))) { ImageInfo info; Image *img; *************** *** 741,749 **** { char *s; ! expr *xv; int n = 0; if (argc == 2 && isstr(argv[0], &s) && ! (istuple(argv[1], &n, &xv) || isvoid(argv[1])) && ! n <= 5) { ImageInfo info; Image *img; --- 832,839 ---- { char *s; ! expr *xv = NULL; int n = 0; if (argc == 2 && isstr(argv[0], &s) && ! (istuple(argv[1], &n, &xv) || isvoid(argv[1]))) { ImageInfo info; Image *img; *************** *** 809,813 **** { char *s; ! if (argc == 2 && isstr(argv[0], &s)) { Image *img = NULL; ImageInfo info; --- 899,905 ---- { char *s; ! expr *xv = NULL; ! int n = 0; ! if (argc == 3 && isstr(argv[0], &s)) { Image *img = NULL; ImageInfo info; *************** *** 816,819 **** --- 908,917 ---- return __FAIL; GetImageInfo(&info); + if (!isvoid(argv[2]) && !istuple(argv[2], &n, &xv)) { + xv = argv+2; + n = 1; + } + if (!parse_info2(n, xv, &info)) + return __FAIL; if (is_image_list(argv[1], &img)) { res = WriteImages(&info, img, s, &exception); *************** *** 842,846 **** char *s = NULL; Image *img; ! if (argc == 2 && (isobj(argv[1], type(Image), (void**)&img) || is_image_list(argv[1], &img)) && --- 940,946 ---- char *s = NULL; Image *img; ! expr *xv; ! int n = 0; ! if (argc == 3 && (isobj(argv[1], type(Image), (void**)&img) || is_image_list(argv[1], &img)) && *************** *** 853,856 **** --- 953,962 ---- char magick[MaxTextExtent]; GetImageInfo(&info); + if (!isvoid(argv[2]) && !istuple(argv[2], &n, &xv)) { + xv = argv+2; + n = 1; + } + if (!parse_info2(n, xv, &info)) + return __FAIL; if (s) { strncpy(magick, img->magick, MaxTextExtent-1); *************** *** 880,889 **** { bstr_t *m; ! expr *xv; int n = 0; if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m) && m->size > 0 && ! (istuple(argv[1], &n, &xv) || isvoid(argv[1])) && ! n <= 5) { ImageInfo info; Image *img; --- 986,994 ---- { bstr_t *m; ! expr *xv = NULL; int n = 0; if (argc == 2 && isobj(argv[0], type(ByteStr), (void**)&m) && m->size > 0 && ! (istuple(argv[1], &n, &xv) || isvoid(argv[1]))) { ImageInfo info; Image *img; *************** *** 1168,1172 **** isuint(xv[0], &w) && isuint(xv[1], &h) && isuint(argv[2], &filter) && - filter != UndefinedFilter && filter <= SincFilter && (isfloat(argv[3], &blur) || ismpz_float(argv[3], &blur))) { img = ResizeImage(img, w, h, filter, blur, &exception); --- 1273,1276 ---- *************** *** 1413,1417 **** if (argc == 4 && isobj(argv[0], type(Image), (void**)&img) && isuint(argv[1], &op) && - op != UndefinedCompositeOp && op <= OverlayCompositeOp && isobj(argv[2], type(Image), (void**)&img2) && istuple(argv[3], &n, &xv) && --- 1517,1520 ---- *************** *** 1539,1543 **** unsigned long noise; if (argc == 2 && isobj(argv[0], type(Image), (void**)&img) && ! isuint(argv[1], &noise) && noise <= PoissonNoise) { img = AddNoiseImage(img, noise, &exception); if (check_exception(&exception)) --- 1642,1646 ---- unsigned long noise; if (argc == 2 && isobj(argv[0], type(Image), (void**)&img) && ! isuint(argv[1], &noise)) { img = AddNoiseImage(img, noise, &exception); if (check_exception(&exception)) Index: magick.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.q,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** magick.q 29 Dec 2003 13:08:32 -0000 1.21 --- magick.q 29 Dec 2003 20:31:36 -0000 1.22 *************** *** 36,40 **** --- 36,47 ---- def GRAY = 0, RGB = 1; + /* This is used to indicate the default value for various options. */ + public var const DEFAULT; + def DEFAULT = 0; + public var const + /* Compression types for the write_image and image_to_blob functions. */ + NONE, BZIP, FAX, GROUP4, JPEG, LOSSLESS, LZW, RLE, ZIP, + /* Filter types for the resize function. */ POINT_FILTER, BOX_FILTER, TRIANGLE_FILTER, HERMITE_FILTER, *************** *** 55,59 **** private extern magick_vars; ! def (POINT_FILTER, BOX_FILTER, TRIANGLE_FILTER, HERMITE_FILTER, HANNING_FILTER, HAMMING_FILTER, BLACKMAN_FILTER, GAUSSIAN_FILTER, QUADRATIC_FILTER, CUBIC_FILTER, CATROM_FILTER, MITCHELL_FILTER, --- 62,68 ---- private extern magick_vars; ! def (NONE, BZIP, FAX, GROUP4, JPEG, LOSSLESS, LZW, RLE, ZIP, ! ! POINT_FILTER, BOX_FILTER, TRIANGLE_FILTER, HERMITE_FILTER, HANNING_FILTER, HAMMING_FILTER, BLACKMAN_FILTER, GAUSSIAN_FILTER, QUADRATIC_FILTER, CUBIC_FILTER, CATROM_FILTER, MITCHELL_FILTER, *************** *** 153,157 **** - OFFSET: A number of initial bytes to be skipped when reading an image. Usually, this is set to zero, but there are some special image ! formats (in particular: STEGANO) which use a non-zero value for this field. --- 162,166 ---- - OFFSET: A number of initial bytes to be skipped when reading an image. Usually, this is set to zero, but there are some special image ! formats (in particular: STEGANO) which may use a non-zero value for this field. *************** *** 188,200 **** following operations. */ ! public extern image_background_color IMG, ! image_border_color IMG, image_matte_color IMG; ! ! public extern set_image_background_color IMG PIXEL, ! set_image_border_color IMG PIXEL, set_image_matte_color IMG PIXEL; ! ! // TODO: We need some additional operations here to retrieve and change ! // various other image parameters, such as compression options and page ! // geometry. /* Retrieve various other useful information about an image. The count_image_ --- 197,205 ---- following operations. */ ! public extern image_background_color IMG, set_image_background_color IMG PIXEL; ! public extern image_border_color IMG, set_image_border_color IMG PIXEL; ! public extern image_matte_color IMG, set_image_matte_color IMG PIXEL; ! public extern image_page IMG, set_image_page IMG PAGE; ! public extern image_compression IMG, set_image_compression IMG COMPRESSION; /* Retrieve various other useful information about an image. The count_image_ *************** *** 258,267 **** file, if the image format supports that, or to a sequence of files with attached frame numbers otherwise. You can also use a %d printf ! specification in the output filename (e.g., "image%02d.miff") which ! expands to the zero-based frame number when the individual frames are ! written, see again ImageMagick(1) for details. */ public extern read_image NAME INFO, ping_image NAME INFO; ! public extern write_image NAME IMG; /* Convert an image or image sequence to a "blob" ("binary large object", --- 263,284 ---- file, if the image format supports that, or to a sequence of files with attached frame numbers otherwise. You can also use a %d printf ! specification in the output filename (e.g., "image%02d.miff") which expands ! to the zero-based frame number when the individual frames are written, see ! again ImageMagick(1) for details. ! ! The compression type and quality of write_image can optionally be indicated ! with the INFO parameter, which can be a singleton COMPRESSION value, or a ! tuple with up to 3 fields which takes the form (COMPRESSION, QUALITY, ! SAMPLING_FACTOR). COMPRESSION can be any of the compression type values ! defined in the "manifest constants" section, QUALITY is an integer (ranging ! from 0 to 100 a.k.a. "worst/fastest" to "best/slowest", with 75 being the ! default) which corresponds to ImageMagick's -quality option, and ! SAMPLING_FACTOR is a string in the same format as ImageMagick's ! -sampling-factor option, see ImageMagick(1) for details. All fields are ! optional. If no compression type is specified (COMPRESSION = 0 or INFO = ! ()) then the default compression type for the image format is used. */ public extern read_image NAME INFO, ping_image NAME INFO; ! public extern write_image NAME IMG INFO; /* Convert an image or image sequence to a "blob" ("binary large object", *************** *** 270,278 **** data. The MAGICK parameter of image_to_blob can be used to indicate the desired target format; if it is () then the format of the image is used as ! the target format. The blob_to_image function takes an INFO structure to ! specify image properties which cannot be deduced from the blob itself; this ! is necessary, e.g., if the blob is just raw RGB data. */ ! public extern image_to_blob MAGICK IMG, blob_to_image BLOB INFO; /***************************************************************************/ --- 287,297 ---- data. The MAGICK parameter of image_to_blob can be used to indicate the desired target format; if it is () then the format of the image is used as ! the target format. The INFO parameter of image_to_blob can be used to ! denote the desired compression method, and has the same format and meaning ! as with the write_image function. The blob_to_image function takes an image ! INFO structure to specify image properties which cannot be deduced from the ! blob itself; this is necessary, e.g., if the blob is just raw RGB data. */ ! public extern image_to_blob MAGICK IMG INFO, blob_to_image BLOB INFO; /***************************************************************************/ |