[q-lang-cvs] q/modules/magick magick.c,1.20,1.21 magick.q,1.18,1.19
Brought to you by:
agraef
From: <ag...@us...> - 2003-12-29 12:02:26
|
Update of /cvsroot/q-lang/q/modules/magick In directory sc8-pr-cvs1:/tmp/cvs-serv5974 Modified Files: magick.c magick.q Log Message: added offset field to info structure, code cleanup Index: magick.c =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.c,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** magick.c 29 Dec 2003 04:20:47 -0000 1.20 --- magick.c 29 Dec 2003 12:02:21 -0000 1.21 *************** *** 343,347 **** { int i = 0; ! unsigned long width, height, depth, matte; char *magick; static char geom[100]; --- 343,347 ---- { int i = 0; ! unsigned long width, height, depth, offset, matte; char *magick; static char geom[100]; *************** *** 356,359 **** --- 356,365 ---- } if (i >= n) return 1; + if (!isuint(xv[i++], &offset)) return 0; + if (offset > 0) { + sprintf(geom, "%ux%u+%u", width, height, offset); + info->size = geom; + } + if (i >= n) return 1; if (!isuint(xv[i++], &depth) || depth > QuantumDepth) return 0; if (depth > 0) *************** *** 369,372 **** --- 375,455 ---- } + FUNCTION(magick,image_info,argc,argv) + { + Image *img; + if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) + return mktuplel(6, mkuint(img->columns), mkuint(img->rows), + mkuint(img->offset), mkuint(img->depth), + mkuint((unsigned long)img->matte), + mkstr(strdup(img->magick))); + else + return __FAIL; + } + + FUNCTION(magick,count_image_colors,argc,argv) + { + Image *img; + if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) { + unsigned long colors = GetNumberColors(img, NULL, &exception); + if (check_exception(&exception)) + return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); + else + return mkuint(colors); + } else + return __FAIL; + } + + FUNCTION(magick,is_gray_image,argc,argv) + { + Image *img; + if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) { + unsigned res = IsGrayImage(img, &exception); + if (check_exception(&exception)) + return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); + else + return res?mktrue:mkfalse; + } else + return __FAIL; + } + + FUNCTION(magick,is_monochrome_image,argc,argv) + { + Image *img; + if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) { + unsigned res = IsMonochromeImage(img, &exception); + if (check_exception(&exception)) + return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); + else + return res?mktrue:mkfalse; + } else + return __FAIL; + } + + FUNCTION(magick,is_opaque_image,argc,argv) + { + Image *img; + if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) { + unsigned res = IsOpaqueImage(img, &exception); + if (check_exception(&exception)) + return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); + else + return res?mktrue:mkfalse; + } else + return __FAIL; + } + + FUNCTION(magick,is_palette_image,argc,argv) + { + Image *img; + if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) { + unsigned res = IsPaletteImage(img, &exception); + if (check_exception(&exception)) + return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); + else + return res?mktrue:mkfalse; + } else + return __FAIL; + } + FUNCTION(magick,magick_pixel,argc,argv) { *************** *** 745,825 **** return mkobj(type(Image), img); } - } else - return __FAIL; - } - - FUNCTION(magick,image_info,argc,argv) - { - Image *img; - if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) - return mktuplel(5, mkuint(img->columns), mkuint(img->rows), - mkuint(img->depth), - mkuint((unsigned long)img->matte), - mkstr(strdup(img->magick))); - else - return __FAIL; - } - - FUNCTION(magick,count_image_colors,argc,argv) - { - Image *img; - if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) { - unsigned long colors = GetNumberColors(img, NULL, &exception); - if (check_exception(&exception)) - return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); - else - return mkuint(colors); - } else - return __FAIL; - } - - FUNCTION(magick,is_gray_image,argc,argv) - { - Image *img; - if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) { - unsigned res = IsGrayImage(img, &exception); - if (check_exception(&exception)) - return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); - else - return res?mktrue:mkfalse; - } else - return __FAIL; - } - - FUNCTION(magick,is_monochrome_image,argc,argv) - { - Image *img; - if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) { - unsigned res = IsMonochromeImage(img, &exception); - if (check_exception(&exception)) - return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); - else - return res?mktrue:mkfalse; - } else - return __FAIL; - } - - FUNCTION(magick,is_opaque_image,argc,argv) - { - Image *img; - if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) { - unsigned res = IsOpaqueImage(img, &exception); - if (check_exception(&exception)) - return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); - else - return res?mktrue:mkfalse; - } else - return __FAIL; - } - - FUNCTION(magick,is_palette_image,argc,argv) - { - Image *img; - if (argc == 1 && isobj(argv[0], type(Image), (void**)&img)) { - unsigned res = IsPaletteImage(img, &exception); - if (check_exception(&exception)) - return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); - else - return res?mktrue:mkfalse; } else return __FAIL; --- 828,831 ---- Index: magick.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.q,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** magick.q 29 Dec 2003 04:20:47 -0000 1.18 --- magick.q 29 Dec 2003 12:02:21 -0000 1.19 *************** *** 72,87 **** /***************************************************************************/ ! /* 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 ! module. */ ! ! public extern type Image; ! ! public is_image X; ! ! is_image IMG:Image = true; ! is_image _ = false otherwise; ! ! /***************************************************************************/ /* Error handling. In case of failure, some operations use the following --- 72,76 ---- /***************************************************************************/ ! /* General ImageMagick properties and functions. */ /* Error handling. In case of failure, some operations use the following *************** *** 145,162 **** /***************************************************************************/ ! /* Operations to create and copy images. 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 1 if the ! image has an alpha channel and 0 otherwise, and MAGICK is a string naming ! one of the image formats understood by ImageMagick (such as EPS, GIF, RGB, ! etc.). ! Only the first two fields specifying the dimensions of the image are ! mandatory, the remaining fields will be filled with suitable defaults if ! they are omitted. The image will be created with the pixels initialized ! from the given PIXELS argument, a byte string of RGBA values representing ! either a single pixel or a pixel sequence whose length matches the ! dimensions of the image. The clone_image function creates an exact copy of the given image. This is --- 134,213 ---- /***************************************************************************/ ! /* The Image type. Objects of this type are created with the create_image, ! read_image, ping_image and blob_to_image operations, and processed by the ! other operations of this module. */ ! public extern type Image; ! ! public is_image X; ! ! is_image IMG:Image = true; ! is_image _ = false otherwise; ! ! /* The most important attributes of an image are summarized in its INFO ! structure, a tuple of the from (WIDTH, HEIGHT, OFFSET, DEPTH, MATTE, ! MAGICK) with the following components: ! ! - WIDTH, HEIGHT: The dimensions of the image, in pixel units. ! ! - 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. ! ! - DEPTH: The bit depth of the image (usually 8 or 16), denotes the number ! of bits used to represent each color component or "plane" (red, green, ! blue, opacity or "alpha"). ! ! - MATTE: An integer value which is 1 if the image has an alpha channel and ! 0 otherwise. ! ! - MAGICK: A string naming one of the image formats understood by ! ImageMagick (such as EPS, GIF, RGB, etc.). ! ! INFO tuples are used to specify the properties of an image when it is ! created, and the INFO tuple of an existing image can be retrieved with the ! image_info function. */ ! ! public extern image_info IMG; ! ! /* Convenience functions to retrieve the different components of an INFO ! structure. */ ! ! public image_width IMG, image_height IMG, image_offset IMG, image_depth IMG, ! image_matte IMG, image_magick IMG; ! ! image_width IMG = W where (W,H,O,D,A,M) = image_info IMG; ! image_height IMG = H where (W,H,O,D,A,M) = image_info IMG; ! image_offset IMG = O where (W,H,O,D,A,M) = image_info IMG; ! image_depth IMG = D where (W,H,O,D,A,M) = image_info IMG; ! image_matte IMG = A where (W,H,O,D,A,M) = image_info IMG; ! image_magick IMG = M where (W,H,O,D,A,M) = image_info IMG; ! ! // TODO: We need some additional operations here to retrieve and change ! // various other image parameters, such as compression options, ! // background/border/matte 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 ! remaining functions check whether the image belongs to one of the following ! image classes: gray (all RGB intensities equal), monochrome (all RGB ! intensities equal *and* each RGB value is either zero or max), opaque (all ! alpha values max), and palette (pseudo class image with at most 256 unique ! colors). */ ! ! public extern count_image_colors IMG; ! public extern is_gray_image IMG, is_monochrome_image IMG, is_opaque_image IMG, ! is_palette_image IMG; ! ! /***************************************************************************/ ! ! /* Operations to create and copy images. The create_image function creates a ! new image, given its INFO tuple. Only the first two fields specifying the ! dimensions of the image are mandatory, the remaining fields will be filled ! with suitable defaults if they are omitted or zero. The image will be ! created with the pixels initialized from the given PIXELS argument, a byte ! string of RGBA values representing either a single pixel or a pixel ! sequence whose length matches the dimensions of the image. The clone_image function creates an exact copy of the given image. This is *************** *** 170,177 **** "rgb:file") or indicate a special builtin image object (such as "logo:" or "xc:white"); see ImageMagick(1) for details. Additional image properties ! may be specified in the INFO argument, which has the same form as for ! create_image. For read_image, all fields in the INFO structure are ! optional, but note that for raw image data (e.g., RGB or RGBA) you will ! have to specify at least the dimensions of the image. Note that some image files (such as GIF animations or MPEG videos) actually --- 221,230 ---- "rgb:file") or indicate a special builtin image object (such as "logo:" or "xc:white"); see ImageMagick(1) for details. Additional image properties ! may be specified in the given INFO tuple. For read_image, all fields in the ! INFO structure are optional, but note that for raw image data (e.g., RGB or ! RGBA) you will have to specify at least the dimensions of the image. For ! STEGANO images ("watermark" images hidden in the main image, specified as ! "stegano:file") you also have to specify the offset of the stegano image in ! the file using the OFFSET field of the INFO structure. Note that some image files (such as GIF animations or MPEG videos) actually *************** *** 200,205 **** written, see again ImageMagick(1) for details. */ - // TODO: offset option for read_image; compression options for write_image - public extern read_image NAME INFO, ping_image NAME INFO; public extern write_image NAME IMG; --- 253,256 ---- *************** *** 210,217 **** 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 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; --- 261,267 ---- 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; *************** *** 219,257 **** /***************************************************************************/ - /* 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; - - /* Convenience functions to retrieve the different components of an image - 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; - - // TODO: We need some operations here to retrieve and change various other - // image parameters, such as background/border/matte 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 - remaining functions check whether the image belongs to one of the following - image classes: gray (all RGB intensities equal), monochrome (all RGB - intensities equal *and* each RGB value is either zero or max), opaque (all - alpha values max), and palette (pseudo class image with at most 256 unique - colors). */ - - public extern count_image_colors IMG; - public extern is_gray_image IMG, is_monochrome_image IMG, is_opaque_image IMG, - is_palette_image IMG; - - /***************************************************************************/ - /* Get and set the pixel data of an image. The affected area of the image is specified by its origin P = (X,Y) and dimension DIM = (W,H). All pixel data --- 269,272 ---- *************** *** 272,275 **** --- 287,294 ---- unchanged. + Most operations have the same name as in the C API (without the Image + suffix), with the following exceptions: `FlipImage' and `FlopImage' are + named `flipy' and `flipx', and `RaiseImage' is named `button'. + A note on parameters: IMG always denotes a singleton input image, IMGS an image list. Some operations also take a secondary image IMG2 as an *************** *** 284,297 **** 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 extern quantize IMG COLORSPACE DITHER; // BANG! --- 303,318 ---- manual. */ ! /* Quantization. */ ! ! /* NOTE: 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 extern quantize IMG COLORSPACE DITHER; // BANG! *************** *** 317,325 **** // TODO: montage ! /* Image enhancement. (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. */ --- 338,346 ---- // TODO: montage ! /* Image enhancement. */ ! public extern contrast IMG SHARPEN, equalize IMG; // BANG! ! public extern gamma IMG VAL, level IMG VAL, modulate IMG VAL; // BANG! ! public extern negate IMG, normalize IMG; // BANG! /* Effects. */ *************** *** 351,355 **** public extern oil_paint IMG RADIUS; public extern solarize IMG THRESHOLD; // BANG! ! public extern stegano IMG IMG2 OFFS; public extern stereo IMG IMG2; public extern swirl IMG ANGLE; --- 372,376 ---- public extern oil_paint IMG RADIUS; public extern solarize IMG THRESHOLD; // BANG! ! public extern stegano IMG IMG2 OFFSET; public extern stereo IMG IMG2; public extern swirl IMG ANGLE; |