[q-lang-cvs] q/modules/magick README-Magick,1.1,1.2 magick.c,1.2,1.3 magick.q,1.2,1.3
Brought to you by:
agraef
From: <ag...@us...> - 2003-12-23 13:14:47
|
Update of /cvsroot/q-lang/q/modules/magick In directory sc8-pr-cvs1:/tmp/cvs-serv30573/modules/magick Modified Files: README-Magick magick.c magick.q Log Message: added blob conversion operations, new MAGICK field in INFO structure Index: README-Magick =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/README-Magick,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** README-Magick 16 Dec 2003 19:11:16 -0000 1.1 --- README-Magick 23 Dec 2003 13:14:43 -0000 1.2 *************** *** 14,21 **** create, load and save images, and to retrieve and change image pixels are already in place. Things that still remain to be done are additional options ! for write_image (compression etc.), operations to convert between images and ! "blobs" (for external storage, e.g., in databases), operations to handle image ! lists (i.e., animations), and, last but not least, support for the advanced ! image manipulation operations provided by libMagick. The module requires that you have ImageMagick installed, which should be --- 14,20 ---- create, load and save images, and to retrieve and change image pixels are already in place. Things that still remain to be done are additional options ! for write_image (compression etc.), operations to handle image lists (i.e., ! animations), and, last but not least, support for the advanced image ! manipulation operations provided by libMagick. The module requires that you have ImageMagick installed, which should be *************** *** 34,38 **** Enjoy! :) ! Dec 16 2003 Albert Graef ag...@mu..., Dr....@t-... --- 33,37 ---- Enjoy! :) ! Dec 23 2003 Albert Graef ag...@mu..., Dr....@t-... Index: magick.c =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** magick.c 23 Dec 2003 01:15:02 -0000 1.2 --- magick.c 23 Dec 2003 13:14:43 -0000 1.3 *************** *** 223,226 **** --- 223,227 ---- int i = 0; unsigned long width, height, depth; + char *magick; static char geom[100]; if (i >= n) return 1; *************** *** 236,240 **** if (depth > 0) info->depth = depth; ! return 1; } --- 237,247 ---- if (depth > 0) info->depth = depth; ! if (i >= n) return 1; ! if (!istrue(xv[i]) && !isfalse(xv[i])) return 0; ! if (++i >= n) return 1; ! if (!isstr(xv[i++], &magick)) return 0; ! strncpy(info->magick, magick, MaxTextExtent-1); ! if (i >= n) return 1; ! return 0; } *************** *** 242,249 **** --- 249,260 ---- { int i = 3; + char *magick; if (i >= n) return 1; if (!istrue(xv[i]) && !isfalse(xv[i])) return 0; img->matte = istrue(xv[i++])!=0; if (i >= n) return 1; + if (!isstr(xv[i++], &magick)) return 0; + if (!*img->magick) strncpy(img->magick, magick, MaxTextExtent-1); + if (i >= n) return 1; return 0; } *************** *** 328,332 **** int n = 0; if (argc == 1 && (istuple(argv[0], &n, &xv) || isvoid(argv[0])) && ! n <= 7) { ImageInfo *info = CloneImageInfo(NULL); Image *img; --- 339,343 ---- int n = 0; if (argc == 1 && (istuple(argv[0], &n, &xv) || isvoid(argv[0])) && ! n <= 5) { ImageInfo *info = CloneImageInfo(NULL); Image *img; *************** *** 372,376 **** if (argc == 2 && isstr(argv[0], &s) && (istuple(argv[1], &n, &xv) || isvoid(argv[1])) && ! n <= 7) { ImageInfo *info = CloneImageInfo(NULL); Image *img; --- 383,387 ---- if (argc == 2 && isstr(argv[0], &s) && (istuple(argv[1], &n, &xv) || isvoid(argv[1])) && ! n <= 5) { ImageInfo *info = CloneImageInfo(NULL); Image *img; *************** *** 424,430 **** Image *img; if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) ! return mktuplel(4, mkuint(img->columns), mkuint(img->rows), mkuint(img->depth), ! img->matte?mktrue:mkfalse); else return __FAIL; --- 435,442 ---- Image *img; if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) ! return mktuplel(5, mkuint(img->columns), mkuint(img->rows), mkuint(img->depth), ! img->matte?mktrue:mkfalse, ! mkstr(strdup(img->magick))); else return __FAIL; *************** *** 557,560 **** --- 569,644 ---- else return __FAIL; + } else + return __FAIL; + } + + FUNCTION(magick,image_to_blob,argc,argv) + { + char *s = NULL; + Image *img; + if (argc == 2 && + isobj(argv[1], type(Image), (void**)&img) && + img->columns > 0 && img->rows > 0 && + (isvoid(argv[0]) && *img->magick || isstr(argv[0], &s) && *s)) { + ImageInfo *info = CloneImageInfo(NULL); + size_t len; + void *blob; + bstr_t *m; + char magick[MaxTextExtent]; + if (!info) return __ERROR; + if (s) { + strncpy(magick, img->magick, MaxTextExtent-1); + strncpy(img->magick, s, MaxTextExtent-1); + } + blob = ImageToBlob(info, img, &len, &exception); + if (s) + strncpy(img->magick, magick, MaxTextExtent-1); + DestroyImageInfo(info); + if (check_exception(&exception)) + return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); + else if (!blob) + return __FAIL; + else if ((int)len < 0 || !(m = malloc(sizeof(bstr_t)))) { + free(blob); + return __ERROR; + } else { + m->size = (int)len; + m->v = (char*)blob; + return mkobj(type(ByteStr), m); + } + } else + return __FAIL; + } + + FUNCTION(magick,blob_to_image,argc,argv) + { + 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 = CloneImageInfo(NULL); + Image *img; + size_t len = (size_t)m->size; + void *blob = m->v; + if (!info) return __ERROR; + if (!parse_info(n, xv, info)) { + DestroyImageInfo(info); + return __FAIL; + } + img = BlobToImage(info, blob, len, &exception); + DestroyImageInfo(info); + if (check_exception(&exception)) + return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); + if (img && !parse_info2(n, xv, img)) { + DestroyImage(img); + return __FAIL; + } + if (!img) + return __FAIL; + else + return mkobj(type(Image), img); } else return __FAIL; Index: magick.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.q,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** magick.q 23 Dec 2003 01:15:02 -0000 1.2 --- magick.q 23 Dec 2003 13:14:43 -0000 1.3 *************** *** 24,29 **** progress. The basic operations to create, load and save images, and to retrieve and change image pixels are already in place. TODO: additional ! options for write_image (compression etc.); blob conversion; image list ! handling (animations); image manipulation operations. */ import clib; --- 24,29 ---- progress. The basic operations to create, load and save images, and to retrieve and change image pixels are already in place. TODO: additional ! options for write_image (compression etc.); image list handling ! (animations); image manipulation operations. */ import clib; *************** *** 66,74 **** /* Operations to create, read and write an image. The create_image function creates a new image, given an INFO tuple of the form (WIDTH, HEIGHT, DEPTH, ! MATTE), where (WIDTH, HEIGHT) denotes the dimensions of the image, DEPTH is ! the bit depth of the color values (usually 8 or 16), and MATTE is a Bool ! value indicating whether the image has an alpha channel. All fields of the ! INFO tuple are optional; suitable defaults will be provided for fields ! which are omitted. The clone_image function creates an exact copy of the given image. --- 66,75 ---- /* Operations to create, read and write an image. The create_image function creates a new image, given an INFO tuple of the form (WIDTH, HEIGHT, DEPTH, ! MATTE, MAGICK), where (WIDTH, HEIGHT) denotes the dimensions of the image, ! DEPTH is the bit depth of the color values (usually 8 or 16), MATTE is a ! Bool value indicating whether the image has an alpha channel, and MAGICK is ! a string naming one of the image formats understood by ImageMagick. All ! fields of the INFO tuple are optional; suitable defaults will be provided ! for fields which are omitted. The clone_image function creates an exact copy of the given image. *************** *** 79,85 **** for details. Additional image properties may optionally be specified in the INFO argument, which has the same form as for create_image. (Note that for ! raw image data you will have to specify at least the image type in the ! filename -- e.g., "rgb:file.rgb" for raw RGB data -- and the dimensions of ! the image in the INFO tuple.) The write_image function writes the given image to the given target, --- 80,85 ---- for details. Additional image properties may optionally be specified in the INFO argument, which has the same form as for create_image. (Note that for ! raw image data you will have to specify at least the image format and ! dimensions in the INFO tuple.) The write_image function writes the given image to the given target, *************** *** 89,95 **** public extern read_image NAME INFO, write_image NAME IMG; /* Retrieve the attributes of an image. The image_info function returns the attributes of an image encoded as an INFO tuple of the form (WIDTH, HEIGHT, ! DEPTH, MATTE). */ public extern image_info IMG; --- 89,108 ---- public extern read_image NAME INFO, write_image NAME IMG; + /* Convert an image to a "blob" ("binary large object", represented as a byte + string), and vice versa. This is useful, e.g., if an image is to be stored + in a database, or if it is to be manipulated as raw data. The desired + target format can be indicated with the MAGICK parameter of image_to_blob; + you only have to specify this if the output blob should have a different + format than the input image, otherwise just use () for this parameter. The + blob_to_image function expects an INFO structure like the one passed to + create_image and read_image, 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; + /* Retrieve the attributes of an image. The image_info function returns the attributes of an image encoded as an INFO tuple of the form (WIDTH, HEIGHT, ! DEPTH, MATTE, MAGICK). */ public extern image_info IMG; *************** *** 98,107 **** info structure. */ ! public image_width IMG, image_height IMG, image_depth IMG, image_matte IMG; ! image_width IMG = W where (W,H,D,M) = image_info IMG; ! image_height IMG = H where (W,H,D,M) = image_info IMG; ! image_depth IMG = D where (W,H,D,M) = image_info IMG; ! image_matte IMG = M where (W,H,D,M) = image_info IMG; /* Retrieve various other useful information about an image. The count_image_ --- 111,122 ---- info structure. */ ! public image_width IMG, image_height IMG, image_depth IMG, image_matte IMG, ! image_magick IMG; ! image_width IMG = W where (W,H,D,A,M) = image_info IMG; ! image_height IMG = H where (W,H,D,A,M) = image_info IMG; ! image_depth IMG = D where (W,H,D,A,M) = image_info IMG; ! image_matte IMG = A where (W,H,D,A,M) = image_info IMG; ! image_magick IMG = M where (W,H,D,A,M) = image_info IMG; /* Retrieve various other useful information about an image. The count_image_ |