q-lang-cvs Mailing List for Q - Equational Programming Language (Page 130)
Brought to you by:
agraef
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(106) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(219) |
Feb
(152) |
Mar
|
Apr
(92) |
May
(45) |
Jun
(3) |
Jul
|
Aug
(3) |
Sep
(111) |
Oct
(52) |
Nov
|
Dec
|
2005 |
Jan
|
Feb
(1) |
Mar
(1) |
Apr
(2) |
May
(23) |
Jun
(46) |
Jul
(158) |
Aug
(22) |
Sep
|
Oct
(26) |
Nov
(11) |
Dec
(49) |
2006 |
Jan
(57) |
Feb
(196) |
Mar
(10) |
Apr
(41) |
May
(149) |
Jun
(308) |
Jul
(11) |
Aug
(25) |
Sep
(15) |
Oct
|
Nov
|
Dec
(15) |
2007 |
Jan
|
Feb
|
Mar
|
Apr
(15) |
May
(204) |
Jun
(112) |
Jul
(7) |
Aug
(16) |
Sep
(134) |
Oct
(313) |
Nov
(262) |
Dec
(83) |
2008 |
Jan
(81) |
Feb
(83) |
Mar
(21) |
Apr
|
May
|
Jun
(1) |
Jul
(2) |
Aug
(6) |
Sep
|
Oct
|
Nov
|
Dec
(2) |
2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <ag...@us...> - 2003-12-27 03:26:53
|
Update of /cvsroot/q-lang/q/modules/magick In directory sc8-pr-cvs1:/tmp/cvs-serv7401 Modified Files: magick.c Log Message: turned image infos into automatic variables Index: magick.c =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** magick.c 26 Dec 2003 14:26:51 -0000 1.7 --- magick.c 27 Dec 2003 03:26:50 -0000 1.8 *************** *** 379,393 **** isobj(argv[1], type(ByteStr), (void**)&m)) { unsigned long size = w*h*8; ! ImageInfo *info = CloneImageInfo(NULL); Image *img; int matte; ! if (!info) return __ERROR; if (ULONG_MAX/8 < w*h || m->size != 8 && m->size != size || ! !parse_info(n, xv, info, &matte)) { ! DestroyImageInfo(info); return __FAIL; ! } ! img = AllocateImage(info); ! DestroyImageInfo(info); if (!img) return __ERROR; --- 379,390 ---- isobj(argv[1], type(ByteStr), (void**)&m)) { unsigned long size = w*h*8; ! ImageInfo info; Image *img; int matte; ! GetImageInfo(&info); if (ULONG_MAX/8 < w*h || m->size != 8 && m->size != size || ! !parse_info(n, xv, &info, &matte)) return __FAIL; ! img = AllocateImage(&info); if (!img) return __ERROR; *************** *** 442,456 **** (istuple(argv[1], &n, &xv) || isvoid(argv[1])) && n <= 5) { ! ImageInfo *info = CloneImageInfo(NULL); Image *img; int matte; ! if (!info) return __ERROR; ! if (!parse_info(n, xv, info, &matte)) { ! DestroyImageInfo(info); return __FAIL; ! } ! strncpy(info->filename, s, MaxTextExtent-1); ! img = ReadImage(info, &exception); ! DestroyImageInfo(info); if (check_exception(&exception)) return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); --- 439,450 ---- (istuple(argv[1], &n, &xv) || isvoid(argv[1])) && n <= 5) { ! ImageInfo info; Image *img; int matte; ! GetImageInfo(&info); ! if (!parse_info(n, xv, &info, &matte)) return __FAIL; ! strncpy(info.filename, s, MaxTextExtent-1); ! img = ReadImage(&info, &exception); if (check_exception(&exception)) return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); *************** *** 497,511 **** (istuple(argv[1], &n, &xv) || isvoid(argv[1])) && n <= 5) { ! ImageInfo *info = CloneImageInfo(NULL); Image *img; int matte; ! if (!info) return __ERROR; ! if (!parse_info(n, xv, info, &matte)) { ! DestroyImageInfo(info); return __FAIL; ! } ! strncpy(info->filename, s, MaxTextExtent-1); ! img = PingImage(info, &exception); ! DestroyImageInfo(info); if (check_exception(&exception)) return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); --- 491,502 ---- (istuple(argv[1], &n, &xv) || isvoid(argv[1])) && n <= 5) { ! ImageInfo info; Image *img; int matte; ! GetImageInfo(&info); ! if (!parse_info(n, xv, &info, &matte)) return __FAIL; ! strncpy(info.filename, s, MaxTextExtent-1); ! img = PingImage(&info, &exception); if (check_exception(&exception)) return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); *************** *** 549,571 **** if (argc == 2 && isstr(argv[0], &s)) { Image *img = NULL, *tmp, *tmp2; ! ImageInfo *info; int res; expr x, hd, tl; if (isnil(argv[1])) return __FAIL; ! info = CloneImageInfo(NULL); ! if (!info) return __ERROR; for (x = argv[1]; iscons(x, &hd, &tl); x = tl) { if (!(isobj(hd, type(Image), (void**)&tmp) && ! tmp->columns > 0 && tmp->rows > 0)) { ! DestroyImageInfo(info); return __FAIL; - } if (!img) img = tmp; } ! if (img && !isnil(x)) { ! DestroyImageInfo(info); return __FAIL; - } if (img) { /* build the image list */ --- 540,557 ---- if (argc == 2 && isstr(argv[0], &s)) { Image *img = NULL, *tmp, *tmp2; ! ImageInfo info; int res; expr x, hd, tl; if (isnil(argv[1])) return __FAIL; ! GetImageInfo(&info); for (x = argv[1]; iscons(x, &hd, &tl); x = tl) { if (!(isobj(hd, type(Image), (void**)&tmp) && ! tmp->columns > 0 && tmp->rows > 0)) return __FAIL; if (!img) img = tmp; } ! if (img && !isnil(x)) return __FAIL; if (img) { /* build the image list */ *************** *** 578,595 **** } tmp2 = tmp; ! res = WriteImages(info, img, s, &exception); } } else { /* must be a singleton image */ if (!(isobj(argv[1], type(Image), (void**)&img) && ! img->columns > 0 && img->rows > 0)) { ! DestroyImageInfo(info); return __FAIL; - } strncpy(img->filename, s, MaxTextExtent-1); ! res = WriteImage(info, img); exception = img->exception; } - DestroyImageInfo(info); /* break up image list */ for (tmp = img; tmp; tmp = tmp2) { --- 564,578 ---- } tmp2 = tmp; ! res = WriteImages(&info, img, s, &exception); } } else { /* must be a singleton image */ if (!(isobj(argv[1], type(Image), (void**)&img) && ! img->columns > 0 && img->rows > 0)) return __FAIL; strncpy(img->filename, s, MaxTextExtent-1); ! res = WriteImage(&info, img); exception = img->exception; } /* break up image list */ for (tmp = img; tmp; tmp = tmp2) { *************** *** 615,632 **** 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))); --- 598,614 ---- img->columns > 0 && img->rows > 0 && (isvoid(argv[0]) && *img->magick || isstr(argv[0], &s) && *s)) { ! ImageInfo info; size_t len; void *blob; bstr_t *m; char magick[MaxTextExtent]; ! GetImageInfo(&info); 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); if (check_exception(&exception)) return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); *************** *** 654,669 **** (istuple(argv[1], &n, &xv) || isvoid(argv[1])) && n <= 5) { ! ImageInfo *info = CloneImageInfo(NULL); Image *img; int matte; size_t len = (size_t)m->size; void *blob = m->v; ! if (!info) return __ERROR; ! if (!parse_info(n, xv, info, &matte)) { ! 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))); --- 636,648 ---- (istuple(argv[1], &n, &xv) || isvoid(argv[1])) && n <= 5) { ! ImageInfo info; Image *img; int matte; size_t len = (size_t)m->size; void *blob = m->v; ! GetImageInfo(&info); ! if (!parse_info(n, xv, &info, &matte)) return __FAIL; ! img = BlobToImage(&info, blob, len, &exception); if (check_exception(&exception)) return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); |
From: <ag...@us...> - 2003-12-26 14:26:54
|
Update of /cvsroot/q-lang/q/modules/magick In directory sc8-pr-cvs1:/tmp/cvs-serv23799 Modified Files: magick.c magick.q Log Message: new ping_image operation Index: magick.c =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** magick.c 26 Dec 2003 11:11:09 -0000 1.6 --- magick.c 26 Dec 2003 14:26:51 -0000 1.7 *************** *** 489,492 **** --- 489,547 ---- } + FUNCTION(magick,ping_image,argc,argv) + { + 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 = CloneImageInfo(NULL); + Image *img; + int matte; + if (!info) return __ERROR; + if (!parse_info(n, xv, info, &matte)) { + DestroyImageInfo(info); + return __FAIL; + } + strncpy(info->filename, s, MaxTextExtent-1); + img = PingImage(info, &exception); + DestroyImageInfo(info); + if (check_exception(&exception)) + return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); + if (!img) + return __FAIL; + else if (img->next) { + expr x = mknil; + Image *imgs; + if (matte >= 0) + for (imgs = img; imgs; imgs = imgs->next) + imgs->matte = (unsigned)matte; + /* convert image sequence into list of images */ + for (imgs = img; imgs->next; imgs = imgs->next) + ; + /* imgs now points at the last image in the sequence */ + while (x && imgs) { + Image *tmp = imgs->previous; + if (tmp) { + tmp->next = NULL; + imgs->previous = NULL; + } + x = mkcons(mkobj(type(Image), imgs), x); + imgs = tmp; + } + if (!x) { + DestroyImageList(img); + return __ERROR; + } + return x; + } else { + if (matte >= 0) img->matte = (unsigned)matte; + return mkobj(type(Image), img); + } + } else + return __FAIL; + } + FUNCTION(magick,write_image,argc,argv) { Index: magick.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.q,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** magick.q 26 Dec 2003 11:11:09 -0000 1.7 --- magick.q 26 Dec 2003 14:26:51 -0000 1.8 *************** *** 126,129 **** --- 126,134 ---- see ImageMagick(1) for details. + The ping_image function is like read_image, but does *not* read the actual + pixel data of an image. This is typically used in conjuction with + image_info, in order to inspect the properties of an image or image + sequence without wasting resources for reading the pixels into memory. + The write_image function writes the given image to the given target, designated by a name in the same syntax as for read_image. If the input *************** *** 135,139 **** written, see again ImageMagick(1) for details. */ ! public extern read_image NAME INFO, write_image NAME IMG; /* Convert an image to a "blob" ("binary large object", represented as a byte --- 140,145 ---- 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 to a "blob" ("binary large object", represented as a byte |
From: <ag...@us...> - 2003-12-26 11:11:13
|
Update of /cvsroot/q-lang/q/modules/magick In directory sc8-pr-cvs1:/tmp/cvs-serv31836 Modified Files: magick.c magick.q Log Message: new magick_info function Index: magick.c =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** magick.c 26 Dec 2003 03:10:48 -0000 1.5 --- magick.c 26 Dec 2003 11:11:09 -0000 1.6 *************** *** 168,171 **** --- 168,201 ---- #endif + FUNCTION(magick,magick_info,argc,argv) + { + const MagickInfo *info; + expr x; + if (argc != 0) return __FAIL; + info = GetMagickInfo("*", &exception); + if (check_exception(&exception)) + return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); + else if (!info) + return __FAIL; + while (info->next) info = info->next; + /* we're at the last info record now */ + x = mknil; + while (x && info) { + char mode[10]; + sprintf(mode, "%c%c%c%c", + info->blob_support?'*':'-', + info->decoder?'r':'-', + info->encoder?'w':'-', + info->adjoin?'+':'-'); + x = mkcons(mktuplel(4, mkstr(strdup(info->name?info->name:"")), + mkstr(strdup(mode)), + mkstr(strdup(info->description?info->description:"")), + mkstr(strdup(info->version?info->version:""))), + x); + info = info->previous; + } + return x; + } + /* image type */ Index: magick.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.q,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** magick.q 26 Dec 2003 03:21:38 -0000 1.6 --- magick.q 26 Dec 2003 11:11:09 -0000 1.7 *************** *** 46,49 **** --- 46,74 ---- public magick_error MSG; + /* ImageMagick file formats. The following operation retrieves general + information about the supported image file formats. It returns a list of + string tuples of the form (NAME, MODE, DESCRIPTION, VERSION) with the + following fields: + + - NAME: The name of the format under which it is known to ImageMagick, + which is also used as a format prefix in filenames and the value of the + MAGICK field in the image_info structure (see below). + + - MODE: A four-character string of the form "*rw+" specifying whether the + format supports native blobs, reading, writing, and multi-image files, + respectively. Unsupported capabilities will be represented by a '-' + character in the corresponding position. + + - DESCRIPTION: A more verbose description of the file format. + + - VERSION: Any additional version information about the format. + + E.g., to quickly list all supported formats, try something like + `do (printf "%9s %4s %s %s\n") magick_info'. We remark that some of the + listed formats (such as MPEG) require third-party software to make them + work, see ImageMagick(1) for details. */ + + public extern magick_info; + /* ENCODING OF COLOR VALUES. Regardless of the internal representation of an image, pixel data is always encoded as a byte string of 16 bit RGBA |
From: <ag...@us...> - 2003-12-26 03:21:42
|
Update of /cvsroot/q-lang/q/modules/magick In directory sc8-pr-cvs1:/tmp/cvs-serv11927 Modified Files: magick.q Log Message: code cleanup Index: magick.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.q,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** magick.q 26 Dec 2003 03:10:48 -0000 1.5 --- magick.q 26 Dec 2003 03:21:38 -0000 1.6 *************** *** 27,31 **** operations. */ ! import stdlib, clib; /* The Image type. Objects of this type are created with the create_image and --- 27,31 ---- operations. */ ! import clib; /* The Image type. Objects of this type are created with the create_image and |
From: <ag...@us...> - 2003-12-26 03:11:58
|
Update of /cvsroot/q-lang/q In directory sc8-pr-cvs1:/tmp/cvs-serv10930 Modified Files: ChangeLog Log Message: ChangeLog updated Index: ChangeLog =================================================================== RCS file: /cvsroot/q-lang/q/ChangeLog,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ChangeLog 24 Dec 2003 03:08:12 -0000 1.9 --- ChangeLog 26 Dec 2003 03:11:55 -0000 1.10 *************** *** 1,2 **** --- 1,7 ---- + 2003-12-26 Albert Graef <Dr....@t-...> + + * magick: read_image and write_image now fully support multi-frame + image files, which are represented as image lists in Q land + 2003-12-24 Albert Graef <Dr....@t-...> |
From: <ag...@us...> - 2003-12-26 03:10:52
|
Update of /cvsroot/q-lang/q/modules/magick/examples In directory sc8-pr-cvs1:/tmp/cvs-serv10788/examples Modified Files: Makefile.am magicktest.q Log Message: added image list support Index: Makefile.am =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/examples/Makefile.am,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile.am 24 Dec 2003 03:05:36 -0000 1.2 --- Makefile.am 26 Dec 2003 03:10:49 -0000 1.3 *************** *** 4,9 **** if GGI ! examples_DATA = *.q *.png *.rgba endif ! EXTRA_DIST = *.q *.png *.rgba --- 4,9 ---- if GGI ! examples_DATA = *.q mozilla* endif ! EXTRA_DIST = *.q mozilla* Index: magicktest.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/examples/magicktest.q,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** magicktest.q 24 Dec 2003 03:05:36 -0000 1.4 --- magicktest.q 26 Dec 2003 03:10:49 -0000 1.5 *************** *** 1,9 **** /* $Id$ ! magicktest.q: simple magick demonstration program, shows how to render an ! image on a GGI visual */ import ggi, magick; /* display IMG: Display the given image in a GGI visual. Returns the created visual. Some examples: --- 1,11 ---- /* $Id$ ! magicktest.q: A little demonstration program, shows how to render images ! on a GGI visual. */ import ggi, magick; + /****************************************************************************/ + /* display IMG: Display the given image in a GGI visual. Returns the created visual. Some examples: *************** *** 57,62 **** interested reader. :) */ - /* Implementation. */ - /* The simple case: our image is opaque. In this case we just render it on a screen visual: */ --- 59,62 ---- *************** *** 68,72 **** where (W,H|_) = image_info IMG, VIS = ggi_open (sprintf "%s:-keepcursor" target), ! () = ggi_set_mode VIS (sprintf "%dx%d" (W,H)), PIXELS = get_image_pixels IMG (0,0) (W,H) --- 68,73 ---- where (W,H|_) = image_info IMG, VIS = ggi_open (sprintf "%s:-keepcursor" target), ! () = ggi_set_flags VIS GGI_FLAG_ASYNC || ! ggi_set_mode VIS (sprintf "%dx%d" (W,H)), PIXELS = get_image_pixels IMG (0,0) (W,H) *************** *** 86,93 **** where (W,H|_) = image_info IMG, VIS = ggi_open (sprintf "%s:-keepcursor" target), ! () = ggi_set_mode VIS (sprintf "%dx%d.A16" (W,H)), PIXELS = get_image_pixels IMG (0,0) (W,H) otherwise; /* Display driver. Assume DirectX on Windows, X11 everywhere else. */ --- 87,146 ---- where (W,H|_) = image_info IMG, VIS = ggi_open (sprintf "%s:-keepcursor" target), ! () = ggi_set_flags VIS GGI_FLAG_ASYNC || ! ggi_set_mode VIS (sprintf "%dx%d.A16" (W,H)), PIXELS = get_image_pixels IMG (0,0) (W,H) otherwise; + + /****************************************************************************/ + + /* animate IMGS: Animate a list of images. Shows each image for 1/FPS seconds, + then displays the next one. You can abort the animation at any time by + hitting a key while the mouse cursor is in the GGI window. Note that, by + default, the frame rate FPS is set to 25 which is suitable, e.g., for MPEG + movies; you might wish to change this value as needed. + + To have some fun, download yourself jurannessic_176x104.mpg from + http://www.pocketmovies.net/ and watch the little caveman discover the + cinema: + + ==> animate (read_image "jurannessic_176x104.mpg" ()) + + You can also loop the animation loop by using the `repeat' function instead + of `animate'. Sit back and watch. Enjoy. :) */ + + def FPS = 25; + + animate IMGS + + = do (show VIS) IMGS || VIS + + where (W,H|_) = image_info (hd IMGS), + VIS = ggi_open (sprintf "%s:-keepcursor" target), + () = ggi_set_flags VIS GGI_FLAG_ASYNC || + ggi_set_mode VIS (sprintf "%dx%d" (W,H)); + + repeat IMGS + + = loop VIS IMGS + + where (W,H|_) = image_info (hd IMGS), + VIS = ggi_open (sprintf "%s:-keepcursor" target), + () = ggi_set_flags VIS GGI_FLAG_ASYNC || + ggi_set_mode VIS (sprintf "%dx%d" (W,H)); + + loop VIS IMGS = do (show VIS) IMGS || sleep 2 || loop VIS IMGS; + + show VIS IMG + + = ggi_getc VIS || halt if ggi_kbhit VIS; + // *FIXME* we should really take a more decent way out here + + = ggi_put_box VIS (0,0) (W,H) PIXELS || ggi_flush VIS || sleep (1/FPS) + + where (W,H|_) = image_info IMG, + PIXELS = get_image_pixels IMG (0,0) (W,H); + + /****************************************************************************/ /* Display driver. Assume DirectX on Windows, X11 everywhere else. */ |
From: <ag...@us...> - 2003-12-26 03:10:52
|
Update of /cvsroot/q-lang/q/modules/magick In directory sc8-pr-cvs1:/tmp/cvs-serv10788 Modified Files: README-Magick magick.c magick.q Log Message: added image list support Index: README-Magick =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/README-Magick,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** README-Magick 23 Dec 2003 13:14:43 -0000 1.2 --- README-Magick 26 Dec 2003 03:10:48 -0000 1.3 *************** *** 14,26 **** 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 readily available in most Linux distributions. The Windows Qpad package ! already includes all necessary support files. Currently a fairly recent ! ImageMagick version (>= 5.5) is required, but support for older versions will ! be added in the near future. Please see magick.q for a description of the functions provided by this --- 14,24 ---- 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.) and support for the advanced image manipulation operations provided by libMagick. The module requires that you have ImageMagick installed, which should be readily available in most Linux distributions. The Windows Qpad package ! already includes all necessary support files. At present a fairly recent ! ImageMagick version (>= 5.5) is required. Please see magick.q for a description of the functions provided by this *************** *** 33,37 **** Enjoy! :) ! Dec 23 2003 Albert Graef ag...@mu..., Dr....@t-... --- 31,35 ---- Enjoy! :) ! Dec 26 2003 Albert Graef ag...@mu..., Dr....@t-... Index: magick.c =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** magick.c 24 Dec 2003 03:05:36 -0000 1.4 --- magick.c 26 Dec 2003 03:10:48 -0000 1.5 *************** *** 427,431 **** if (!img) return __FAIL; ! else { if (matte >= 0) img->matte = (unsigned)matte; return mkobj(type(Image), img); --- 427,455 ---- if (!img) return __FAIL; ! else if (img->next) { ! expr x = mknil; ! Image *imgs; ! if (matte >= 0) ! for (imgs = img; imgs; imgs = imgs->next) ! imgs->matte = (unsigned)matte; ! /* convert image sequence into list of images */ ! for (imgs = img; imgs->next; imgs = imgs->next) ! ; ! /* imgs now points at the last image in the sequence */ ! while (x && imgs) { ! Image *tmp = imgs->previous; ! if (tmp) { ! tmp->next = NULL; ! imgs->previous = NULL; ! } ! x = mkcons(mkobj(type(Image), imgs), x); ! imgs = tmp; ! } ! if (!x) { ! DestroyImageList(img); ! return __ERROR; ! } ! return x; ! } else { if (matte >= 0) img->matte = (unsigned)matte; return mkobj(type(Image), img); *************** *** 438,452 **** { char *s; ! Image *img; ! if (argc == 2 && isstr(argv[0], &s) && ! isobj(argv[1], type(Image), (void**)&img) && ! img->columns > 0 && img->rows > 0) { ! ImageInfo *info = CloneImageInfo(NULL); int res; if (!info) return __ERROR; ! strncpy(img->filename, s, MaxTextExtent-1); ! res = WriteImage(info, img); DestroyImageInfo(info); ! if (check_exception(&img->exception)) return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); else if (!res) --- 462,516 ---- { char *s; ! if (argc == 2 && isstr(argv[0], &s)) { ! Image *img = NULL, *tmp, *tmp2; ! ImageInfo *info; int res; + expr x, hd, tl; + if (isnil(argv[1])) + return __FAIL; + info = CloneImageInfo(NULL); if (!info) return __ERROR; ! for (x = argv[1]; iscons(x, &hd, &tl); x = tl) { ! if (!(isobj(hd, type(Image), (void**)&tmp) && ! tmp->columns > 0 && tmp->rows > 0)) { ! DestroyImageInfo(info); ! return __FAIL; ! } ! if (!img) img = tmp; ! } ! if (img && !isnil(x)) { ! DestroyImageInfo(info); ! return __FAIL; ! } ! if (img) { ! /* build the image list */ ! tmp2 = NULL; ! for (x = argv[1]; iscons(x, &hd, &tl); x = tl) { ! isobj(hd, type(Image), (void**)&tmp); ! if (tmp2) { ! tmp->previous = tmp2; ! tmp2->next = tmp; ! } ! tmp2 = tmp; ! res = WriteImages(info, img, s, &exception); ! } ! } else { ! /* must be a singleton image */ ! if (!(isobj(argv[1], type(Image), (void**)&img) && ! img->columns > 0 && img->rows > 0)) { ! DestroyImageInfo(info); ! return __FAIL; ! } ! strncpy(img->filename, s, MaxTextExtent-1); ! res = WriteImage(info, img); ! exception = img->exception; ! } DestroyImageInfo(info); ! /* break up image list */ ! for (tmp = img; tmp; tmp = tmp2) { ! tmp2 = tmp->next; ! tmp->previous = tmp->next = NULL; ! } ! if (check_exception(&exception)) return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); else if (!res) Index: magick.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.q,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** magick.q 24 Dec 2003 03:05:36 -0000 1.4 --- magick.q 26 Dec 2003 03:10:48 -0000 1.5 *************** *** 24,31 **** 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; /* The Image type. Objects of this type are created with the create_image and --- 24,31 ---- 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 manipulation ! operations. */ ! import stdlib, clib; /* The Image type. Objects of this type are created with the create_image and *************** *** 64,75 **** public extern magick_pixel COLOR; ! /* 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 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 --- 64,74 ---- public extern magick_pixel COLOR; ! /* 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 *************** *** 80,98 **** dimensions of the image. ! The clone_image function creates an exact copy of the given image. ! The read_image function reads an image from the given source, which may ! also include a format prefix (such as "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. The write_image function writes the given image to the given target, ! designated by a name in the same syntax as for read_image. */ - public extern create_image INFO PIXELS, clone_image IMG; public extern read_image NAME INFO, write_image NAME IMG; --- 79,113 ---- dimensions of the image. ! The clone_image function creates an exact copy of the given image. This is ! useful if an image is to be modified but you want to retain the original ! image. */ ! public extern create_image INFO PIXELS, clone_image IMG; ! ! /* Operations to read and write images. The read_image function reads an image ! from the given source, which may also include a format prefix (such as ! "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 movies) actually ! contain an entire sequence of images (which are also called "frames") ! rather than a single image; in this case read_image returns a list with all ! the images that were read from the file. You can also specify a subrange of ! frames to be extracted in the input filename (e.g., "video.mpg[50-75]"), ! see ImageMagick(1) for details. The write_image function writes the given image to the given target, ! designated by a name in the same syntax as for read_image. If the input ! image is actually a list of images, it is written to a single multi-image ! file, if the image format supports that, or to a sequence of files with ! attached frame numbers otherwise. You can also specify 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, write_image NAME IMG; |
From: <ag...@us...> - 2003-12-24 03:08:15
|
Update of /cvsroot/q-lang/q In directory sc8-pr-cvs1:/tmp/cvs-serv15991 Modified Files: ChangeLog Log Message: ChangeLog updated Index: ChangeLog =================================================================== RCS file: /cvsroot/q-lang/q/ChangeLog,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ChangeLog 23 Dec 2003 13:14:43 -0000 1.8 --- ChangeLog 24 Dec 2003 03:08:12 -0000 1.9 *************** *** 1,5 **** 2003-12-23 Albert Graef <Dr....@t-...> ! * magick: added blob conversion operations, new MAGICK field in INFO structure 2003-12-22 Albert Graef <Dr....@t-...> --- 1,12 ---- + 2003-12-24 Albert Graef <Dr....@t-...> + + * magick: create_image now takes an additional PIXEL parameter + used to initialize the pixels of the image; improved magicktest.q + example; bug fixes + 2003-12-23 Albert Graef <Dr....@t-...> ! * magick: added blob conversion operations; new MAGICK field in ! INFO structure, MATTE field is now an integer 2003-12-22 Albert Graef <Dr....@t-...> |
From: <ag...@us...> - 2003-12-24 03:05:39
|
Update of /cvsroot/q-lang/q/modules/magick In directory sc8-pr-cvs1:/tmp/cvs-serv15621 Modified Files: magick.c magick.q Log Message: working on the magick module Index: magick.c =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** magick.c 23 Dec 2003 13:14:43 -0000 1.3 --- magick.c 24 Dec 2003 03:05:36 -0000 1.4 *************** *** 180,184 **** static void get_pixels(unsigned char *dest, PixelPacket *source, ! unsigned long count) { unsigned long i; --- 180,184 ---- static void get_pixels(unsigned char *dest, PixelPacket *source, ! unsigned long count, unsigned matte) { unsigned long i; *************** *** 188,198 **** p = source; q = (unsigned short*)dest; ! for (i = 0; i < count; i++) { ! *q++=ScaleQuantumToShort(p->red); ! *q++=ScaleQuantumToShort(p->green); ! *q++=ScaleQuantumToShort(p->blue); ! *q++=ScaleQuantumToShort(MaxRGB-p->opacity); ! p++; ! } } --- 188,207 ---- p = source; q = (unsigned short*)dest; ! if (matte) ! for (i = 0; i < count; i++) { ! *q++=ScaleQuantumToShort(p->red); ! *q++=ScaleQuantumToShort(p->green); ! *q++=ScaleQuantumToShort(p->blue); ! *q++=ScaleQuantumToShort(MaxRGB-p->opacity); ! p++; ! } ! else ! for (i = 0; i < count; i++) { ! *q++=ScaleQuantumToShort(p->red); ! *q++=ScaleQuantumToShort(p->green); ! *q++=ScaleQuantumToShort(p->blue); ! *q++=ScaleQuantumToShort(MaxRGB); ! p++; ! } } *************** *** 200,204 **** static void set_pixels(PixelPacket *dest, unsigned char *source, ! unsigned long count) { unsigned long i; --- 209,213 ---- static void set_pixels(PixelPacket *dest, unsigned char *source, ! unsigned long count, unsigned matte) { unsigned long i; *************** *** 208,232 **** p = (unsigned short*)source; q = dest; ! for (i = 0; i < count; i++) { ! q->red=ScaleShortToQuantum(*p++); ! q->green=ScaleShortToQuantum(*p++); ! q->blue=ScaleShortToQuantum(*p++); ! q->opacity=ScaleShortToQuantum(0xffff-*p++); ! q++; ! } } /* parse info tuples */ ! static int parse_info(int n, expr *xv, ImageInfo *info) { int i = 0; ! unsigned long width, height, depth; char *magick; static char geom[100]; if (i >= n) return 1; if (!isuint(xv[i++], &width)) return 0; if (i >= n) return 1; ! if (!isuint(xv[i++], &height)) height = 0; if (width > 0 && height > 0) { sprintf(geom, "%ux%u", width, height); --- 217,250 ---- p = (unsigned short*)source; q = dest; ! if (matte) ! for (i = 0; i < count; i++) { ! q->red=ScaleShortToQuantum(*p++); ! q->green=ScaleShortToQuantum(*p++); ! q->blue=ScaleShortToQuantum(*p++); ! q->opacity=ScaleShortToQuantum(0xffff-*p++); ! q++; ! } ! else ! for (i = 0; i < count; i++) { ! q->red=ScaleShortToQuantum(*p++); ! q->green=ScaleShortToQuantum(*p++); ! q->blue=ScaleShortToQuantum(*p++); ! q++; ! } } /* parse info tuples */ ! static int parse_info(int n, expr *xv, ImageInfo *info, int *_matte) { int i = 0; ! unsigned long width, height, depth, matte; char *magick; static char geom[100]; + *_matte = -1; if (i >= n) return 1; if (!isuint(xv[i++], &width)) return 0; if (i >= n) return 1; ! if (!isuint(xv[i++], &height)) return 0; if (width > 0 && height > 0) { sprintf(geom, "%ux%u", width, height); *************** *** 238,259 **** 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; ! } ! ! static int parse_info2(int n, expr *xv, Image *img) ! { ! 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; --- 256,264 ---- info->depth = depth; if (i >= n) return 1; ! if (!isuint(xv[i++], &matte) || matte > 1) return 0; ! *_matte = (int)matte; 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; *************** *** 291,295 **** } m->size = 8; ! get_pixels(m->v, &pixel, 1); return mkobj(type(ByteStr), m); skip: --- 296,300 ---- } m->size = 8; ! get_pixels(m->v, &pixel, 1, 1); return mkobj(type(ByteStr), m); skip: *************** *** 329,333 **** return __FAIL; } ! get_pixels(v, &pixel, 1); } return mkobj(type(ByteStr), m); --- 334,338 ---- return __FAIL; } ! get_pixels(v, &pixel, 1, 1); } return mkobj(type(ByteStr), m); *************** *** 338,347 **** expr *xv; int n = 0; ! if (argc == 1 && (istuple(argv[0], &n, &xv) || isvoid(argv[0])) && ! n <= 5) { ImageInfo *info = CloneImageInfo(NULL); Image *img; if (!info) return __ERROR; ! if (!parse_info(n, xv, info)) { DestroyImageInfo(info); return __FAIL; --- 343,358 ---- 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)) { ! unsigned long size = w*h*8; ImageInfo *info = CloneImageInfo(NULL); Image *img; + int matte; if (!info) return __ERROR; ! if (ULONG_MAX/8 < w*h || m->size != 8 && m->size != size || ! !parse_info(n, xv, info, &matte)) { DestroyImageInfo(info); return __FAIL; *************** *** 349,360 **** img = AllocateImage(info); DestroyImageInfo(info); - if (img && !parse_info2(n, xv, img)) { - DestroyImage(img); - return __FAIL; - } if (!img) return __ERROR; ! else ! return mkobj(type(Image), img); } else return __FAIL; --- 360,388 ---- img = AllocateImage(info); DestroyImageInfo(info); if (!img) return __ERROR; ! else { ! PixelPacket *pixels; ! if (matte >= 0) img->matte = (unsigned)matte; ! if (!(pixels = SetImagePixels(img, 0, 0, w, h))) { ! DestroyImage(img); ! return __FAIL; ! } ! if (m->size > 8) ! set_pixels(pixels, m->v, w*h, img->matte); ! else { ! unsigned long x, y; ! for (y = 0; y < h; y++, pixels += w) ! for (x = 0; x < w; x++) ! set_pixels(pixels+x, m->v, 1, img->matte); ! } ! img->storage_class = DirectClass; ! if (SyncImagePixels(img)) ! return mkobj(type(Image), img); ! else { ! DestroyImage(img); ! return __FAIL; ! } ! } } else return __FAIL; *************** *** 386,391 **** ImageInfo *info = CloneImageInfo(NULL); Image *img; if (!info) return __ERROR; ! if (!parse_info(n, xv, info)) { DestroyImageInfo(info); return __FAIL; --- 414,420 ---- ImageInfo *info = CloneImageInfo(NULL); Image *img; + int matte; if (!info) return __ERROR; ! if (!parse_info(n, xv, info, &matte)) { DestroyImageInfo(info); return __FAIL; *************** *** 396,407 **** 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; --- 425,434 ---- if (check_exception(&exception)) return mkapp(mksym(sym(magick_error)), mkstr(strdup(msg))); if (!img) return __FAIL; ! else { ! if (matte >= 0) img->matte = (unsigned)matte; return mkobj(type(Image), img); + } } else return __FAIL; *************** *** 431,434 **** --- 458,532 ---- } + 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; + int matte; + size_t len = (size_t)m->size; + void *blob = m->v; + if (!info) return __ERROR; + if (!parse_info(n, xv, info, &matte)) { + 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) + return __FAIL; + else { + if (matte >= 0) img->matte = (unsigned)matte; + return mkobj(type(Image), img); + } + } else + return __FAIL; + } + FUNCTION(magick,image_info,argc,argv) { *************** *** 437,441 **** return mktuplel(5, mkuint(img->columns), mkuint(img->rows), mkuint(img->depth), ! img->matte?mktrue:mkfalse, mkstr(strdup(img->magick))); else --- 535,539 ---- return mktuplel(5, mkuint(img->columns), mkuint(img->rows), mkuint(img->depth), ! mkuint((unsigned long)img->matte), mkstr(strdup(img->magick))); else *************** *** 535,539 **** } m->size = size; ! get_pixels(m->v, pixels, w*h); return mkobj(type(ByteStr), m); } else --- 633,637 ---- } m->size = size; ! get_pixels(m->v, pixels, w*h, img->matte); return mkobj(type(ByteStr), m); } else *************** *** 563,567 **** if (!(pixels = SetImagePixels(img, x, y, w, h))) return __FAIL; ! set_pixels(pixels, m->v, w*h); img->storage_class = DirectClass; if (SyncImagePixels(img)) --- 661,665 ---- if (!(pixels = SetImagePixels(img, x, y, w, h))) return __FAIL; ! set_pixels(pixels, m->v, w*h, img->matte); img->storage_class = DirectClass; if (SyncImagePixels(img)) *************** *** 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; --- 667,670 ---- Index: magick.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.q,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** magick.q 23 Dec 2003 13:14:43 -0000 1.3 --- magick.q 24 Dec 2003 03:05:36 -0000 1.4 *************** *** 51,56 **** intensity. Similarly, an alpha value of 0 denotes a fully transparent, 0xffff a fully opaque pixel. Note that this format matches the layout of ! GGI pixel values, which makes it easy to transfer pixel data between images ! and GGI visuals. */ /* The magick_pixel function returns the normalized RGBA color value, as a --- 51,56 ---- intensity. Similarly, an alpha value of 0 denotes a fully transparent, 0xffff a fully opaque pixel. Note that this format matches the layout of ! GGI pixel values, which makes it easy to transfer pixel data between ! ImageMagick images and GGI visuals. */ /* The magick_pixel function returns the normalized RGBA color value, as a *************** *** 59,108 **** the range 0..0xffff; the alpha value is optional and is assumed to be 0xffff if it is missing. The function also packs a list of such values into ! a single byte string. The result of magick_pixel is suitable to be used as ! the DATA argument in a call to set_image_pixels (see below). */ public extern magick_pixel COLOR; ! /* 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. The read_image function reads an image from the given source, which may ! also include a format prefix (such as "rgb:file.rgb") or indicate a special builtin image object (such as "logo:" or "xc:white"); see ImageMagick(1) ! 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, designated by a name in the same syntax as for read_image. */ ! public extern create_image INFO, clone_image IMG; 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; --- 59,115 ---- the range 0..0xffff; the alpha value is optional and is assumed to be 0xffff if it is missing. The function also packs a list of such values into ! a single byte string. The returned value can be passed as the PIXELS ! parameter of create_image and set_image_pixels. */ public extern magick_pixel COLOR; ! /* 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 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. The read_image function reads an image from the given source, which may ! also include a format prefix (such as "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. The write_image function writes the given image to the given target, designated by a name in the same syntax as for read_image. */ ! public extern create_image INFO PIXELS, clone_image IMG; 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 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; /* 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; *************** *** 137,139 **** public extern get_image_pixels IMG P DIM; ! public extern set_image_pixels IMG P DIM DATA; --- 144,146 ---- public extern get_image_pixels IMG P DIM; ! public extern set_image_pixels IMG P DIM PIXELS; |
From: <ag...@us...> - 2003-12-24 03:05:39
|
Update of /cvsroot/q-lang/q/modules/magick/examples In directory sc8-pr-cvs1:/tmp/cvs-serv15621/examples Modified Files: Makefile.am magicktest.q Added Files: mozilla_48x48.rgba Log Message: working on the magick module --- NEW FILE: mozilla_48x48.rgba --- (This appears to be a binary file; contents omitted.) Index: Makefile.am =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/examples/Makefile.am,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Makefile.am 16 Dec 2003 19:11:16 -0000 1.1 --- Makefile.am 24 Dec 2003 03:05:36 -0000 1.2 *************** *** 4,9 **** if GGI ! examples_DATA = *.q *.png endif ! EXTRA_DIST = *.q *.png --- 4,9 ---- if GGI ! examples_DATA = *.q *.png *.rgba endif ! EXTRA_DIST = *.q *.png *.rgba Index: magicktest.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/examples/magicktest.q,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** magicktest.q 23 Dec 2003 13:14:43 -0000 1.3 --- magicktest.q 24 Dec 2003 03:05:36 -0000 1.4 *************** *** 6,22 **** import ggi, magick; ! /* show NAME INFO: show an image in a GGI visual. Returns the created visual. ! For most purposes, NAME is just the name of an image file, and INFO is ! (). However, using appropriate NAME and INFO values, you can actually do a ! lot more than just displaying an image file, see magick.q and ! ImageMagick(1) for details. */ ! show NAME INFO = display IMG where IMG:Image = read_image NAME INFO; ! /* display IMG: display the given image in a GGI visual. Returns the created ! visual. */ /* The simple case: our image is opaque. In this case we just render it on a ! screen visual. */ display IMG --- 6,64 ---- import ggi, magick; ! /* display IMG: Display the given image in a GGI visual. Returns the created ! visual. Some examples: ! Display an image read from a file, use defaults: ! ==> display (read_image "mozilla.png" ()) ! ! Display raw RGBA file -- must specify the dimensions and depth here: ! ! ==> display (read_image "mozilla_48x48.rgba" (48,48,8)) ! ! Display a white image obtained from create_image: ! ! ==> display (create_image (100,100,8) (magick_pixel "white")) ! ! Same using read_image with the "xc:" source specifier: ! ! ==> display (read_image "xc:white" (100,100,8)) ! ! Now for something a little more interesting. Show some of the builtin ! ImageMagick images: ! ! ==> display (read_image "logo:" ()) ! ! ==> display (read_image "netscape:" ()) ! ! ==> display (read_image "plasma:" (320,240)) ! ! Display a screenshot of an X11 window: ! ! ==> display (read_image "x:" ()) ! ! (When the cross cursor appears, click on the window to capture. You can ! also use a specification like "x:0x1e00002" to denote the target window by ! its id. See ImageMagick(1) for more details.) ! ! As a final example, let's render some inline PostScript code: ! ! ==> def PS = "%!PS-Adobe-3.0 EPSF-3.0\n\ ! %%BoundingBox: 0 0 100 100\n\ ! 50 50 50 0 360 arc stroke showpage\n" ! ! ==> display (blob_to_image (bytestr PS) ()) ! ! Cute, isn't it? By these means, you can employ the full power of PostScript ! to draw complicated stuff in a GGI visual, which would be hard to do using ! only GGI's very basic drawing operations. Of course, we could also employ ! the graphics.q script in the standard library to create the PostScript ! source in a convenient manner. This is left as an exercise to the ! interested reader. :) */ ! ! /* Implementation. */ /* The simple case: our image is opaque. In this case we just render it on a ! screen visual: */ display IMG *************** *** 32,36 **** /* The complicated case: our image has transparency. In this case we clad the ! visual with an alpha buffer and draw the image over a background. */ def BACK = magick_pixel "gray"; --- 74,79 ---- /* The complicated case: our image has transparency. In this case we clad the ! visual with an alpha buffer and draw the image over a background. Actually, ! it's not *that* complicated, either: */ def BACK = magick_pixel "gray"; *************** *** 48,52 **** otherwise; ! /* Driver for display visual. */ target = "directx" if pos "mingw" sysinfo >= 0; --- 91,95 ---- otherwise; ! /* Display driver. Assume DirectX on Windows, X11 everywhere else. */ target = "directx" if pos "mingw" sysinfo >= 0; |
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_ |
From: <ag...@us...> - 2003-12-23 13:14:46
|
Update of /cvsroot/q-lang/q/modules/magick/examples In directory sc8-pr-cvs1:/tmp/cvs-serv30573/modules/magick/examples Modified Files: magicktest.q Log Message: added blob conversion operations, new MAGICK field in INFO structure Index: magicktest.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/examples/magicktest.q,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** magicktest.q 23 Dec 2003 01:15:02 -0000 1.2 --- magicktest.q 23 Dec 2003 13:14:43 -0000 1.3 *************** *** 14,17 **** --- 14,20 ---- show NAME INFO = display IMG where IMG:Image = read_image NAME INFO; + /* display IMG: display the given image in a GGI visual. Returns the created + visual. */ + /* The simple case: our image is opaque. In this case we just render it on a screen visual. */ |
From: <ag...@us...> - 2003-12-23 13:14:46
|
Update of /cvsroot/q-lang/q In directory sc8-pr-cvs1:/tmp/cvs-serv30573 Modified Files: ChangeLog Log Message: added blob conversion operations, new MAGICK field in INFO structure Index: ChangeLog =================================================================== RCS file: /cvsroot/q-lang/q/ChangeLog,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ChangeLog 23 Dec 2003 01:15:01 -0000 1.7 --- ChangeLog 23 Dec 2003 13:14:43 -0000 1.8 *************** *** 1,2 **** --- 1,6 ---- + 2003-12-23 Albert Graef <Dr....@t-...> + + * magick: added blob conversion operations, new MAGICK field in INFO structure + 2003-12-22 Albert Graef <Dr....@t-...> |
From: <ag...@us...> - 2003-12-23 02:01:08
|
Update of /cvsroot/q-lang/q/modules/ggi/examples In directory sc8-pr-cvs1:/tmp/cvs-serv31438 Modified Files: flying_ggis.q Log Message: code cleanup Index: flying_ggis.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/ggi/examples/flying_ggis.q,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** flying_ggis.q 23 Dec 2003 01:15:02 -0000 1.1 --- flying_ggis.q 23 Dec 2003 02:01:05 -0000 1.2 *************** *** 4,8 **** /* flying_ggis.q: Another variation of the "Flying GGIs" theme. This one uses a custom font to render the text and an alpha buffer to make it translucent. ! (Requires FreeType and the GGI buffer extension.) */ /* Say `demo' to run. */ --- 4,8 ---- /* flying_ggis.q: Another variation of the "Flying GGIs" theme. This one uses a custom font to render the text and an alpha buffer to make it translucent. ! Requires FreeType. */ /* Say `demo' to run. */ |
From: <ag...@us...> - 2003-12-23 01:41:27
|
Update of /cvsroot/q-lang/q/modules/ggi In directory sc8-pr-cvs1:/tmp/cvs-serv28198/modules/ggi Modified Files: README-GGI Log Message: updated READMEs Index: README-GGI =================================================================== RCS file: /cvsroot/q-lang/q/modules/ggi/README-GGI,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** README-GGI 23 Dec 2003 01:15:02 -0000 1.4 --- README-GGI 23 Dec 2003 01:41:23 -0000 1.5 *************** *** 18,22 **** need version 2 of the FreeType library (http://www.freetype.org/). ! Since the GGI project at SourceForge [http://sourceforge. net/projects/ggi/] only provides source tarballs at this time, and GGI is not yet included in the major Linux distributions, we provide some RPMs for the required libraries on --- 18,22 ---- need version 2 of the FreeType library (http://www.freetype.org/). ! Since the GGI project at SourceForge (http://sourceforge.net/projects/ggi/) only provides source tarballs at this time, and GGI is not yet included in the major Linux distributions, we provide some RPMs for the required libraries on |
From: <ag...@us...> - 2003-12-23 01:41:27
|
Update of /cvsroot/q-lang/q In directory sc8-pr-cvs1:/tmp/cvs-serv28198 Modified Files: README Log Message: updated READMEs Index: README =================================================================== RCS file: /cvsroot/q-lang/q/README,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** README 16 Dec 2003 19:02:29 -0000 1.5 --- README 23 Dec 2003 01:41:23 -0000 1.6 *************** *** 312,316 **** A binary release for all current 32 bit Windows systems, the Qpad package, is ! available from the Q homepage. It provides an msi installer package, a user-friendly Windows GUI frontend to the interpreter, extensive online documentation including the full Q language manual in html help format, and of --- 312,316 ---- A binary release for all current 32 bit Windows systems, the Qpad package, is ! available from the Q homepage. It provides an MSI installer package, a user-friendly Windows GUI frontend to the interpreter, extensive online documentation including the full Q language manual in html help format, and of *************** *** 372,375 **** --- 372,379 ---- create raster graphics on a variety of display devices. See README-GGI for more information. + + Please note that GGI itself doesn't provide any custom font support for text + rendering, but Q's `ggi' module does. To make this work, you'll also need + version 2 of the FreeType library, available from http://www.freetype.org/. IMAGEMAGICK |
From: <ag...@us...> - 2003-12-23 01:20:52
|
Update of /cvsroot/q-lang/q-audio/src In directory sc8-pr-cvs1:/tmp/cvs-serv25197/src Modified Files: Makefile.am Makefile.msc audio_player.q draw_wave.c Added Files: draw_line.c ggilib.c ggilib.h Log Message: update for latest Q-GGI --- NEW FILE: draw_line.c --- /* line clipping algorithm, pilfered from GGI sources ************************/ /* $Id: draw_line.c,v 1.1 2003/12/23 01:20:48 agraef Exp $ ****************************************************************************** Graphics library for GGI. Copyright (C) 1998 Alexander Larsson [al...@ly...] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************** */ #include <ggi/internal/ggi-dl.h> /* This is a line-clipper using the algorithm by cohen-sutherland. It is modified to do pixel-perfect clipping. This means that it will generate the same endpoints that would be drawn if an ordinary bresenham line-drawer where used and only visible pixels drawn. It can be used with a bresenham-like linedrawer if it is modified to start with a correct error-term. */ #define OC_LEFT 1 #define OC_RIGHT 2 #define OC_TOP 4 #define OC_BOTTOM 8 /* Outcodes: +-> x | | | V 0101 | 0100 | 0110 y --------------------- 0001 | 0000 | 0010 --------------------- 1001 | 1000 | 1010 | | */ #define outcode(code, xx, yy) \ {\ code = 0;\ if ((xx)<(LIBGGI_GC(vis)->cliptl.x))\ code |= OC_LEFT;\ else if ((xx)>=(LIBGGI_GC(vis)->clipbr.x))\ code |= OC_RIGHT;\ if ((yy)<(LIBGGI_GC(vis)->cliptl.y))\ code |= OC_TOP;\ else if ((yy)>=(LIBGGI_GC(vis)->clipbr.y))\ code |= OC_BOTTOM;\ } /* Calculates |_ a/b _| with mathematically correct floor */ static int FloorDiv(int a, int b) { int _floor; if (b>0) { if (a>0) { return a /b; } else { _floor = -((-a)/b); if ((-a)%b != 0) _floor--; } return _floor; } else { if (a>0) { _floor = -(a/(-b)); if (a%(-b) != 0) _floor--; return _floor; } else { return (-a)/(-b); } } } /* Calculates |^ a/b ^| with mathamatically correct floor */ static int CeilDiv(int a,int b) { if (b>0) return FloorDiv(a-1,b)+1; else return FloorDiv(-a-1,-b)+1; } static int _ggi_clip2d(ggi_visual *vis,int *_x0, int *_y0, int *_x1, int *_y1, int *clip_first, int *clip_last) { int first,last, code; int x0,y0,x1,y1; int x,y; int dx,dy; int xmajor; int slope; *clip_first = first = 0; *clip_last = last = 0; outcode(first,*_x0,*_y0); outcode(last,*_x1,*_y1); if ((first | last) == 0) { return 1; /* Trivially accepted! */ } if ((first & last) != 0) { return 0; /* Trivially rejected! */ } x0=*_x0; y0=*_y0; x1=*_x1; y1=*_y1; dx = x1 - x0; dy = y1 - y0; xmajor = (abs(dx) > abs(dy)); slope = ((dx>=0) && (dy>=0)) || ((dx<0) && (dy<0)); for (;;) { code = first; if (first==0) code = last; if (code&OC_LEFT) { x = LIBGGI_GC(vis)->cliptl.x; if (xmajor) { y = *_y0 + FloorDiv(dy*(x - *_x0)*2 + dx, 2*dx); } else { if (slope) { y = *_y0 + CeilDiv(dy*((x - *_x0)*2 - 1), 2*dx); } else { y = *_y0 + FloorDiv(dy*((x - *_x0)*2 - 1), 2*dx); } } } else if (code&OC_RIGHT) { x = LIBGGI_GC(vis)->clipbr.x - 1; if (xmajor) { y = *_y0 + FloorDiv(dy*(x - *_x0)*2 + dx, 2*dx); } else { if (slope) { y = *_y0 + CeilDiv(dy*((x - *_x0)*2 + 1), 2*dx)-1; } else { y = *_y0 + FloorDiv(dy*((x - *_x0)*2 + 1), 2*dx)+1; } } } else if (code&OC_TOP) { y = LIBGGI_GC(vis)->cliptl.y; if (xmajor) { if (slope) { x = *_x0 + CeilDiv(dx*((y - *_y0)*2 - 1), 2*dy); } else { x = *_x0 + FloorDiv(dx*((y - *_y0)*2 - 1), 2*dy); } } else { x = *_x0 + FloorDiv( dx*(y - *_y0)*2 + dy, 2*dy); } } else { /* OC_BOTTOM */ y = LIBGGI_GC(vis)->clipbr.y - 1; if (xmajor) { if (slope) { x = *_x0 + CeilDiv(dx*((y - *_y0)*2 + 1), 2*dy)-1; } else { x = *_x0 + FloorDiv(dx*((y - *_y0)*2 + 1), 2*dy)+1; } } else { x = *_x0 + FloorDiv(dx*(y - *_y0)*2 + dy, 2*dy); } } if (first!=0) { x0 = x; y0 = y; outcode(first,x0,y0); *clip_first = 1; } else { x1 = x; y1 = y; last = code; outcode(last,x1,y1); *clip_last = 1; } if ((first & last) != 0) { return 0; /* Trivially rejected! */ } if ((first | last) == 0) { *_x0=x0; *_y0=y0; *_x1=x1; *_y1=y1; return 1; /* Trivially accepted! */ } } } /* line drawing algorithm from GGI sources, slightly modified for Q-GGI ******/ /* $Id: draw_line.c,v 1.1 2003/12/23 01:20:48 agraef Exp $ ****************************************************************************** Graphics library for GGI. Copyright (C) 1995 Andreas Beck [be...@gg...] Copyright (C) 1997 Jason McMullan [jm...@gg...] Copyright (C) 1998 Alexander Larsson [al...@ly...] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************** */ typedef struct { ggi_visual_t vis; } visual_t; extern int draw_box(visual_t *v, int x, int y, int w, int h); static inline int DrawHLine(visual_t *v, int x, int y, int w) { return (draw_box(v,x,y,w,1) >= 0)?0:-1; } static inline int DrawVLine(visual_t *v, int x, int y, int h) { return (draw_box(v,x,y,1,h) >= 0)?0:-1; } static inline int DrawPixel(visual_t *v, int x, int y) { return (draw_box(v,x,y,1,1) >= 0)?0:-1; } int draw_line(visual_t *v, int orig_x1, int orig_y1, int orig_x2, int orig_y2) { ggi_visual *vis = v->vis; int orig_dx, orig_dy, sx, sy; int dx,dy; int i; int x1, y1, x2, y2; int clip_first, clip_last; x1 = orig_x1; y1 = orig_y1; x2 = orig_x2; y2 = orig_y2; /* clip x1,y1 and x2,y2. Set clip_first and clip_last if clipped */ if (!_ggi_clip2d(vis, &x1,&y1,&x2,&y2,&clip_first,&clip_last)) { return 0; /* Clipped */ } dy = y2 - y1; orig_dy = orig_y2 - orig_y1; sy = 1; if (orig_dy < 0) { orig_dy = -orig_dy; dy = -dy; sy = -1; } dx = x2-x1; orig_dx = orig_x2 - orig_x1; sx = 1; if (orig_dx < 0) { sx = -1; orig_dx = -orig_dx; dx = -dx; } if (dx == 0) { return (sy>0) ? DrawVLine(v,x1,y1,dy+1) : DrawVLine(v,x2,y2,dy+1); } if (dy == 0) { return (sx>0) ? DrawHLine(v,x1,y1,dx+1) : DrawHLine(v,x2,y2,dx+1); } if (orig_dx == orig_dy) { for (i=dx; i >= 0; i--) { DrawPixel(v, x1, y1); x1 += sx; y1 += sy; } return 0; } if (orig_dx >= orig_dy) { /* x major */ int runlen,adjup,adjdown,e,len; int firstlen,lastlen; runlen = orig_dx/orig_dy; adjup = orig_dx%orig_dy; lastlen = firstlen = (runlen>>1) + 1; if (clip_first) { /* clipped, Adjust firstlen */ int clip_dx = abs(x1 - orig_x1); int clip_dy = abs(y1 - orig_y1); int d = (2*clip_dy+1)*orig_dx; firstlen = d/(2*orig_dy) - clip_dx + 1; e = d%(2*orig_dy); if ((e==0) && (sy>0)) { /* Special case, arbitrary choise. Select lower pixel.(?) */ firstlen--; e += 2*orig_dy; } e -= (orig_dy*2); } else { /* Not clipped, calculate start error term */ e = adjup - (orig_dy<<1); /* initial errorterm == half a step */ if ((runlen&1) != 0) { e += orig_dy; } } if (clip_last) { /* Last endpoint clipped */ int clip_dx = abs(x2 - orig_x2); int clip_dy = abs(y2 - orig_y2); int d = (1+2*clip_dy)*orig_dx; lastlen = d/(2*orig_dy) - clip_dx + 1; if ((sy<0) && ((d%(2*orig_dy))==0)) { /* special arbitrary case */ lastlen--; } } adjup <<= 1; adjdown = orig_dy<<1; if (sy>0) { /* line goes down */ if ((adjup==0) && ((runlen&1)==0) && (!clip_first)) { firstlen--; } if (sx>0) { /* line goes right */ DrawHLine(v,x1,y1,firstlen); x1 += firstlen; y1 ++; for (i=dy-1; i>0; i--) { len = runlen; e += adjup; if (e>0) { len++; e -= adjdown; } DrawHLine(v,x1,y1,len); x1 += len; y1++; } DrawHLine(v,x1,y1,lastlen); return 0; } else { /* line goes left */ x1++; /* because ggiDrawHLine draws right */ x1 -= firstlen; DrawHLine(v,x1,y1,firstlen); y1++; for (i=dy-1; i>0; i--) { len = runlen; e += adjup; if (e>0) { len++; e -= adjdown; } x1 -= len; DrawHLine(v,x1,y1,len); y1 ++; } x1 -= lastlen; DrawHLine(v,x1,y1,lastlen); return 0; } } else { /* line goes up */ if ((adjup==0) && ((runlen&1)==0) && (!clip_last)) { lastlen--; } if (sx>0) { /* line goes right */ DrawHLine(v,x1,y1,firstlen); x1 += firstlen; y1--; for (i=dy-1; i>0; i--) { len = runlen; e += adjup; if (e>=0) { len++; e -= adjdown; } DrawHLine(v,x1,y1,len); x1 += len; y1--; } DrawHLine(v,x1,y1,lastlen); return 0; } else { /* line goes left */ x1++; /* because ggiDrawHLine draws right */ x1 -= firstlen; DrawHLine(v,x1,y1,firstlen); y1--; for (i=dy-1; i>0; i--) { len = runlen; e += adjup; if (e>=0) { len++; e -= adjdown; } x1 -= len; DrawHLine(v,x1,y1,len); y1--; } x1 -= lastlen; DrawHLine(v,x1,y1,lastlen); return 0; } } } else { /* y major */ int runlen,adjup,adjdown,e,len; int firstlen,lastlen; runlen = orig_dy/orig_dx; adjup = orig_dy%orig_dx; lastlen = firstlen = (runlen>>1) + 1; if (clip_first) { /* clipped, Adjust firstlen */ int clip_dx = abs(x1 - orig_x1); int clip_dy = abs(y1 - orig_y1); int d = (2*clip_dx+1)*orig_dy; firstlen = d/(2*orig_dx) - clip_dy + 1; e = d%(2*orig_dx); if ((e==0) && (sx>0)) { /* Special case, arbitrary choise. Select lower pixel.(?) */ firstlen--; e += 2*orig_dx; } e -= (orig_dx*2); } else { /* Not clipped, calculate start error term */ e = adjup - (orig_dx<<1); /* initial errorterm == half a step */ if ((runlen&1) != 0) { e += orig_dx; } } if (clip_last) { /* Last endpoint clipped */ int clip_dx = abs(x2 - orig_x2); int clip_dy = abs(y2 - orig_y2); int d = (1+2*clip_dx)*orig_dy; lastlen = d/(2*orig_dx) - clip_dy + 1; if ((sx<0) && ((d%(2*orig_dx))==0)) { /* special arbitrary case */ lastlen--; } } adjup <<= 1; adjdown = orig_dx<<1; if (sy>0) { /* Line goes DOWN */ if (sx>0) { /* line goes RIGHT */ if ((adjup==0) && ((runlen&1)==0) && (!clip_first)) { firstlen--; } DrawVLine(v,x1,y1,firstlen); y1 += firstlen; x1++; for (i=dx-1; i>0; i--) { len = runlen; e += adjup; if (e>0) { len++; e -= adjdown; } DrawVLine(v,x1,y1,len); y1 += len; x1++; } DrawVLine(v,x1,y1,lastlen); return 0; } else { /* line goes LEFT */ if ((adjup==0) && ((runlen&1)==0) && (!clip_last)) { lastlen--; } DrawVLine(v,x1,y1,firstlen); y1 += firstlen; x1--; for (i=dx-1; i>0; i--) { len = runlen; e += adjup; if (e>=0) { len++; e -= adjdown; } DrawVLine(v,x1,y1,len); y1 += len; x1--; } DrawVLine(v,x1,y1,lastlen); return 0; } } else { /* Line goes UP */ y1++; if (sx>0) { /* line goes RIGHT */ if ((adjup==0) && ((runlen&1)==0) && (!clip_first)) { firstlen--; } y1 -= firstlen; DrawVLine(v,x1,y1,firstlen); x1++; for (i=dx-1; i>0; i--) { len = runlen; e += adjup; if (e>0) { len++; e -= adjdown; } y1 -= len; DrawVLine(v,x1,y1,len); x1++; } y1 -= lastlen; DrawVLine(v,x1,y1,lastlen); return 0; } else { /* line goes LEFT */ if ((adjup==0) && ((runlen&1)==0) && (!clip_last)) { lastlen--; } y1 -= firstlen; DrawVLine(v,x1,y1,firstlen); x1--; for (i=dx-1; i>0; i--) { len = runlen; e += adjup; if (e>=0) { len++; e -= adjdown; } y1 -= len; DrawVLine(v,x1,y1,len); x1--; } y1 -= lastlen; DrawVLine(v,x1,y1,lastlen); return 0; } } } } /*****************************************************************************/ --- NEW FILE: ggilib.c --- /* This file is part of the Q programming system. The Q programming system is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. The Q programming system is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <limits.h> #include "ggilib.h" typedef struct { ggi_visual_t vis; void *abuf; unsigned char asz; unsigned short afg, abg; int stride, lines; } visual_t; /* calculate the size of a pixel pack */ static inline int pack_size(ggi_visual_t vis, int n) { int bpp, r; ggi_mode m; if (ggiGetMode(vis, &m)) return -1; bpp = GT_SIZE(m.graphtype); if (n > INT_MAX / bpp) return -1; r = ((bpp*n)%8>0)?1:0; return (bpp*n)/8+r; } /* clear clip area of alpha buffer */ int clear_alpha_buffer(void *_v) { visual_t *v = (visual_t*)_v; int x1, y1, x2, y2; if (ggiGetGCClipping(v->vis, &x1, &y1, &x2, &y2)) return -1; if (v->asz == 1) { unsigned char *abuf = (unsigned char*)v->abuf; int i, y; for (i = y1*v->stride+x1, y = y1; y < y2; y++, i += v->stride) memset(abuf+i, v->abg, x2-x1); } else { unsigned short *abuf = (unsigned short*)v->abuf; int i, j, x, y; for (i = y1*v->stride+x1, y = y1; y < y2; y++, i += v->stride) for (j = i, x = x1; x < x2; x++, j++) abuf[j] = v->abg; } return 0; } /* set alpha values, with clipping */ int set_alpha_box(void *_v, int x, int y, int w, int h, ggi_color *c) { visual_t *v = (visual_t*)_v; int x1, y1, x2, y2; int i, j, k, xx, yy; if (ggiGetGCClipping(v->vis, &x1, &y1, &x2, &y2)) return -1; if (v->asz == 1) { unsigned char *abuf = (unsigned char*)v->abuf; /* FIXME: optimize me! */ for (k = 0, i = y*v->stride+x, yy = y; yy < y+h; yy++, i += v->stride) for (j = i, xx = x; xx < x+w; xx++, j++, k++) if (xx >= x1 && xx < x2 && yy >= y1 && yy < y2) abuf[j] = c[k].a/0x101; } else { unsigned short *abuf = (unsigned short*)v->abuf; /* FIXME: optimize me! */ for (k = 0, i = y*v->stride+x, yy = y; yy < y+h; yy++, i += v->stride) for (j = i, xx = x; xx < x+w; xx++, j++, k++) if (xx >= x1 && xx < x2 && yy >= y1 && yy < y2) abuf[j] = c[k].a; } return 0; } /* same as above, but use current foreground color */ int draw_alpha_box(void *_v, int x, int y, int w, int h) { visual_t *v = (visual_t*)_v; int x1, y1, x2, y2; int i, j, xx, yy; if (ggiGetGCClipping(v->vis, &x1, &y1, &x2, &y2)) return -1; if (v->asz == 1) { unsigned char *abuf = (unsigned char*)v->abuf; /* FIXME: optimize me! */ for (i = y*v->stride+x, yy = y; yy < y+h; yy++, i += v->stride) for (j = i, xx = x; xx < x+w; xx++, j++) if (xx >= x1 && xx < x2 && yy >= y1 && yy < y2) abuf[j] = v->afg; } else { unsigned short *abuf = (unsigned short*)v->abuf; /* FIXME: optimize me! */ for (i = y*v->stride+x, yy = y; yy < y+h; yy++, i += v->stride) for (j = i, xx = x; xx < x+w; xx++, j++) if (xx >= x1 && xx < x2 && yy >= y1 && yy < y2) abuf[j] = v->afg; } return 0; } /* retrieve a rectangle of pixels from a visual, including alpha values */ int get_box(void *_v, int x, int y, int w, int h, ggi_color **c) { visual_t *v = (visual_t*)_v; int n = w*h, bpp, stride, ret; int xc = x, yc = y, wc = w, hc = h; int i, j, k, xx, yy; unsigned char *buf; ggi_mode m; *c = NULL; /* FIXME: we don't support packed non-byte-aligned pixels for now */ if (ggiGetMode(v->vis, &m) || (bpp = GT_SIZE(m.graphtype))%8 != 0) return 0; if (x >= v->stride || y >= v->lines || h <= 0 || w <= 0) return n; if (w > INT_MAX/h) return -1; if (!(buf = malloc(pack_size(v->vis, n)))) return -1; if (n > INT_MAX/sizeof(ggi_color) || !(*c = malloc(n*sizeof(ggi_color)))) { free(buf); return -1; } /* we do our own clipping here, since GGI doesn't handle it :( */ memset(buf, 0, n); memset(*c, 0, n*sizeof(ggi_color)); if (xc < 0) { wc += xc; xc = 0; } if (xc+wc > v->stride) wc = v->stride - xc; if (yc < 0) { hc += yc; yc = 0; } if (yc+hc > v->lines) hc = v->lines - yc; bpp /= 8; stride = w*bpp; if (xc == x && wc == w) { ret = ggiGetBox(v->vis, xc, yc, wc, hc, buf+(yc-y)*stride); } else { /* horizontal clipping, read the pixels line by line */ unsigned char *bufp; int off = (xc-x)*bpp; for (bufp = buf+(yc-y)*stride, yy = yc; yy < yc+hc; yy++, bufp += stride) if ((ret = ggiGetHLine(v->vis, xc, yy, wc, bufp+off))) break; } if (ret) { free(buf); free(*c); return 0; } if (ggiUnpackPixels(v->vis, buf, *c, n)) { free(buf); free(*c); return 0; } free(buf); /* get the alpha values from the alpha buffer if any */ if (v->abuf) { if (v->asz == 1) { unsigned char *abuf = (unsigned char*)v->abuf; /* FIXME: optimize me! */ for (i = y*v->stride+x, k = 0, yy = y; yy < y+h; yy++, i += v->stride) for (j = i, xx = x; xx < x+w; xx++, j++) if (xx >= 0 && xx < v->stride && yy >= 0 && yy < v->lines) (*c)[k++].a = abuf[j]*0x101; else (*c)[k++].a = 0xffff; } else { unsigned short *abuf = (unsigned short*)v->abuf; /* FIXME: optimize me! */ for (i = y*v->stride+x, k = 0, yy = y; yy < y+h; yy++, i += v->stride) for (j = i, xx = x; xx < x+w; xx++, j++) if (xx >= 0 && xx < v->stride && yy >= 0 && yy < v->lines) (*c)[k++].a = abuf[j]; else (*c)[k++].a = 0xffff; } } else { /* default alpha values */ int i; for (i = 0; i < n; i++) (*c)[i].a = 0xffff; } return n; } /* perform alpha blending */ static int blend_box(visual_t *v, int x, int y, int w, int h, ggi_color *c, ggi_color **d) { int i, n = w*h; *d = c; if (!v->abuf) return n; if ((n = get_box(v, x, y, w, h, d)) <= 0 || !(*d)) return n; for (i = 0; i < n; i++) { (*d)[i].r = (((unsigned long)c[i].a)*((unsigned long)c[i].r) + ((unsigned long)0xffff-c[i].a)*((unsigned long)(*d)[i].r))/0xffff; (*d)[i].g = (((unsigned long)c[i].a)*((unsigned long)c[i].g) + ((unsigned long)0xffff-c[i].a)*((unsigned long)(*d)[i].g))/0xffff; (*d)[i].b = (((unsigned long)c[i].a)*((unsigned long)c[i].b) + ((unsigned long)0xffff-c[i].a)*((unsigned long)(*d)[i].b))/0xffff; (*d)[i].a = (0xffffL*((unsigned long)c[i].a) + ((unsigned long)0xffff-c[i].a)*((unsigned long)(*d)[i].a))/0xffff; } return n; } /* same, for single source pixel */ static int blend_box1(visual_t *v, int x, int y, int w, int h, ggi_color *c, ggi_color **d) { int i, n = w*h; *d = NULL; if (!v->abuf || c->a == 0xffff) return n; if ((n = get_box(v, x, y, w, h, d)) <= 0 || !(*d)) return n; for (i = 0; i < n; i++) { (*d)[i].r = (((unsigned long)c->a)*((unsigned long)c->r) + ((unsigned long)0xffff-c->a)*((unsigned long)(*d)[i].r))/0xffff; (*d)[i].g = (((unsigned long)c->a)*((unsigned long)c->g) + ((unsigned long)0xffff-c->a)*((unsigned long)(*d)[i].g))/0xffff; (*d)[i].b = (((unsigned long)c->a)*((unsigned long)c->b) + ((unsigned long)0xffff-c->a)*((unsigned long)(*d)[i].b))/0xffff; (*d)[i].a = (0xffffL*((unsigned long)c->a) + ((unsigned long)0xffff-c->a)*((unsigned long)(*d)[i].a))/0xffff; } return n; } /* store a rectangle of pixels in a visual, with alpha blending */ int put_box(void *_v, int x, int y, int w, int h, ggi_color *c) { visual_t *v = (visual_t*)_v; int n = w*h, ret; unsigned char *buf; ggi_color *d = c; if (h <= 0 || w <= 0) return 0; if (w > INT_MAX/h) return -1; if ((ret = blend_box(v, x, y, w, h, c, &d)) <= 0 || !d) return ret; if (!(buf = malloc(pack_size(v->vis, n)))) return -1; ret = ggiPackColors(v->vis, buf, d, n) || ggiPutBox(v->vis, x, y, w, h, buf); free(buf); if (!ret && v->abuf) ret = set_alpha_box(v, x, y, w, h, d); if (d != c) free(d); if (ret) return 0; else return n; } /* same, with current foreground pixel */ int draw_box(void *_v, int x, int y, int w, int h) { visual_t *v = (visual_t*)_v; int n = w*h, ret; unsigned char *buf; ggi_pixel pix; ggi_color c, *d = NULL; if (h <= 0 || w <= 0) return 0; if (ggiGetGCForeground(v->vis, &pix) || ggiUnmapPixel(v->vis, pix, &c)) return 0; if (v->abuf) c.a = (v->asz==1)?(v->afg*0x101):v->afg; else c.a = 0xffff; if (w > INT_MAX/h) return -1; if ((ret = blend_box1(v, x, y, w, h, &c, &d)) <= 0) return ret; if (d) { if (!(buf = malloc(pack_size(v->vis, n)))) return -1; ret = ggiPackColors(v->vis, buf, d, n) || ggiPutBox(v->vis, x, y, w, h, buf); free(buf); if (!ret && v->abuf) ret = set_alpha_box(v, x, y, w, h, d); free(d); } else { ret = ggiDrawBox(v->vis, x, y, w, h); if (!ret && v->abuf) ret = draw_alpha_box(v, x, y, w, h); } if (ret) return 0; else return n; } --- NEW FILE: ggilib.h --- /* C interface to some of the internals of the Q-GGI module, to facilitate access for "third-party" extensions like the draw_wave module. 2003-12-23 AG */ /* This file is part of the Q programming system. The Q programming system is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. The Q programming system is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef __GGILIB_H__ #define __GGILIB_H__ 1 #include <ggi/ggi.h> /* NOTE: The v argument of the following operations must point to a valid GGIVisual object, as obtained from the object pointer of a GGIVisual expression. */ /* the following operations return a negative value on error, zero otherwise */ /* clear clip area of alpha buffer */ extern int clear_alpha_buffer(void *v); /* set alpha values, with clipping */ extern int set_alpha_box(void *v, int x, int y, int w, int h, ggi_color *c); /* same as above, but use current foreground color */ extern int draw_alpha_box(void *v, int x, int y, int w, int h); /* the following operations return the number of processed pixels if successful, negative otherwise */ /* retrieve a rectangle of pixels from a visual, including alpha values (storage pointed to by c is malloc'ed, user must free it) */ extern int get_box(void *v, int x, int y, int w, int h, ggi_color **c); /* store a rectangle of pixels in a visual, with alpha blending */ extern int put_box(void *v, int x, int y, int w, int h, ggi_color *c); /* same, with current foreground pixel */ extern int draw_box(void *v, int x, int y, int w, int h); /* for this one, you need to link in draw_line.c; returns nonzero iff error */ extern int draw_line(void *v, int x1, int y1, int x2, int y2); /* convenience inline functions, to process horizontal and vertical lines and single pixels */ static inline int set_alpha_hline(void *v, int x, int y, int w, ggi_color *c) { return set_alpha_box(v, x, y, w, 1, c); } static inline int set_alpha_vline(void *v, int x, int y, int h, ggi_color *c) { return set_alpha_box(v, x, y, 1, h, c); } static inline int set_alpha_pixel(void *v, int x, int y, ggi_color *c) { return set_alpha_box(v, x, y, 1, 1, c); } static inline int draw_alpha_hline(void *v, int x, int y, int w) { return draw_alpha_box(v, x, y, w, 1); } static inline int draw_alpha_vline(void *v, int x, int y, int h) { return draw_alpha_box(v, x, y, 1, h); } static inline int draw_alpha_pixel(void *v, int x, int y) { return draw_alpha_box(v, x, y, 1, 1); } static inline int get_hline(void *v, int x, int y, int w, ggi_color **c) { return get_box(v, x, y, w, 1, c); } static inline int get_vline(void *v, int x, int y, int h, ggi_color **c) { return get_box(v, x, y, 1, h, c); } static inline int get_pixel(void *v, int x, int y, ggi_color **c) { return get_box(v, x, y, 1, 1, c); } static inline int put_hline(void *v, int x, int y, int w, ggi_color *c) { return put_box(v, x, y, w, 1, c); } static inline int put_vline(void *v, int x, int y, int h, ggi_color *c) { return put_box(v, x, y, 1, h, c); } static inline int put_pixel(void *v, int x, int y, ggi_color *c) { return put_box(v, x, y, 1, 1, c); } static inline int draw_hline(void *v, int x, int y, int w) { return draw_box(v, x, y, w, 1); } static inline int draw_vline(void *v, int x, int y, int h) { return draw_box(v, x, y, 1, h); } static inline int draw_pixel(void *v, int x, int y) { return draw_box(v, x, y, 1, 1); } #endif Index: Makefile.am =================================================================== RCS file: /cvsroot/q-lang/q-audio/src/Makefile.am,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile.am 15 Dec 2003 12:25:16 -0000 1.2 --- Makefile.am 23 Dec 2003 01:20:48 -0000 1.3 *************** *** 40,44 **** sndfile_la_LIBADD = -lsndfile @LIBDMALLOCTH@ ! draw_wave_la_SOURCES = draw_wave.c draw_wave_la_LDFLAGS = -no-undefined -module -avoid-version draw_wave_la_LIBADD = -lggi @LIBDMALLOCTH@ --- 40,44 ---- sndfile_la_LIBADD = -lsndfile @LIBDMALLOCTH@ ! draw_wave_la_SOURCES = draw_wave.c ggilib.h ggilib.c draw_line.c draw_wave_la_LDFLAGS = -no-undefined -module -avoid-version draw_wave_la_LIBADD = -lggi @LIBDMALLOCTH@ Index: Makefile.msc =================================================================== RCS file: /cvsroot/q-lang/q-audio/src/Makefile.msc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile.msc 15 Dec 2003 12:25:16 -0000 1.2 --- Makefile.msc 23 Dec 2003 01:20:48 -0000 1.3 *************** *** 44,49 **** # NOTE: this one is compiled using mingw ! draw_wave.dll: draw_wave.c ! $(QCC) $(QCCFLAGS) -o draw_wave.dll draw_wave.c -- $(CFLAGS) $(DEFS) -I. -I../portaudio/pa_common -I../../ggi/include --link -L../../ggi/lib -lggi -L../../q-src/libq clean mostlyclean distclean maintainer-clean:: --- 44,49 ---- # NOTE: this one is compiled using mingw ! draw_wave.dll: draw_wave.c ggilib.h ggilib.c draw_line.c ! $(QCC) $(QCCFLAGS) -o draw_wave.dll draw_wave.c ggilib.c draw_line.c -- $(CFLAGS) $(DEFS) -I. -I../portaudio/pa_common -I../../ggi/include --link -L../../ggi/lib -lggi -L../../q-src/libq clean mostlyclean distclean maintainer-clean:: Index: audio_player.q =================================================================== RCS file: /cvsroot/q-lang/q-audio/src/audio_player.q,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** audio_player.q 15 Dec 2003 12:33:33 -0000 1.1 --- audio_player.q 23 Dec 2003 01:20:48 -0000 1.2 *************** *** 207,213 **** /* Initialize the display. */ ! init_display VIS = ggi_set_foreground VIS BACK || ! ggi_fill_screen VIS || ! ggi_flush VIS; /* Update the display. */ --- 207,211 ---- /* Initialize the display. */ ! init_display VIS = ggi_clear VIS || ggi_flush VIS; /* Update the display. */ Index: draw_wave.c =================================================================== RCS file: /cvsroot/q-lang/q-audio/src/draw_wave.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** draw_wave.c 15 Dec 2003 12:33:33 -0000 1.1 --- draw_wave.c 23 Dec 2003 01:20:48 -0000 1.2 *************** *** 65,69 **** #include <libq.h> #include <portaudio.h> ! #include <ggi/ggi.h> MODULE(draw_wave) --- 65,69 ---- #include <libq.h> #include <portaudio.h> ! #include "ggilib.h" MODULE(draw_wave) *************** *** 74,77 **** --- 74,81 ---- } bstr_t; + typedef struct { + ggi_visual_t vis; + } visual_t; + static void shade(ggi_color *c) { *************** *** 87,97 **** FUNCTION(draw_wave,draw_wave,argc,argv) { ! ggi_visual_t *vis; expr *xv; int n; long x, y, w, h, channels, format, chan; bstr_t *m; ! if (argc == 7 && isobj(argv[0], type(GGIVisual), (void**)&vis) && ! *vis && istuple(argv[1], &n, &xv) && n == 2 && isint(xv[0], &x) && isint(xv[1], &y) && istuple(argv[2], &n, &xv) && n == 2 && --- 91,102 ---- FUNCTION(draw_wave,draw_wave,argc,argv) { ! visual_t *v; ! ggi_visual_t vis; expr *xv; int n; long x, y, w, h, channels, format, chan; bstr_t *m; ! if (argc == 7 && isobj(argv[0], type(GGIVisual), (void**)&v) && ! (vis = v->vis) && istuple(argv[1], &n, &xv) && n == 2 && isint(xv[0], &x) && isint(xv[1], &y) && istuple(argv[2], &n, &xv) && n == 2 && *************** *** 125,131 **** int val = (int)((data[i+chan]+1.0f)/2.0f*(h-1)); int xe = (int)x+k*dx, ye = y+h-1-val; ! if (k > 0 && ggiDrawLine(*vis, xa, ya, xe, ye)) return __FAIL; ! if (show_dots && ggiDrawBox(*vis, xe-1, ye-1, 3, 3)) return __FAIL; xa = xe; ya = ye; --- 130,136 ---- int val = (int)((data[i+chan]+1.0f)/2.0f*(h-1)); int xe = (int)x+k*dx, ye = y+h-1-val; ! if (k > 0 && draw_line(v, xa, ya, xe, ye)) return __FAIL; ! if (show_dots && draw_box(v, xe-1, ye-1, 3, 3) < 0) return __FAIL; xa = xe; ya = ye; *************** *** 141,147 **** int val = (int)((samp+1.0)/2.0*(h-1)); int xe = (int)x+k*dx, ye = y+h-1-val; ! if (k > 0 && ggiDrawLine(*vis, xa, ya, xe, ye)) return __FAIL; ! if (show_dots && ggiDrawBox(*vis, xe-1, ye-1, 3, 3)) return __FAIL; xa = xe; ya = ye; --- 146,152 ---- int val = (int)((samp+1.0)/2.0*(h-1)); int xe = (int)x+k*dx, ye = y+h-1-val; ! if (k > 0 && draw_line(v, xa, ya, xe, ye)) return __FAIL; ! if (show_dots && draw_box(v, xe-1, ye-1, 3, 3) < 0) return __FAIL; xa = xe; ya = ye; *************** *** 157,163 **** int val = (int)((samp+1.0)/2.0*(h-1)); int xe = (int)x+k*dx, ye = y+h-1-val; ! if (k > 0 && ggiDrawLine(*vis, xa, ya, xe, ye)) return __FAIL; ! if (show_dots && ggiDrawBox(*vis, xe-1, ye-1, 3, 3)) return __FAIL; xa = xe; ya = ye; --- 162,168 ---- int val = (int)((samp+1.0)/2.0*(h-1)); int xe = (int)x+k*dx, ye = y+h-1-val; ! if (k > 0 && draw_line(v, xa, ya, xe, ye)) return __FAIL; ! if (show_dots && draw_box(v, xe-1, ye-1, 3, 3) < 0) return __FAIL; xa = xe; ya = ye; *************** *** 277,299 **** } } ! ggiGetGCForeground(*vis, &pix); ! if (ggiUnmapPixel(*vis, pix, &col)) return __FAIL; shade(&col); ! pix2 = ggiMapColor(*vis, &col); for (k = 0; k < vals; k++) { int xa, xe = (int)x+(k+1)*dx; for (xa = (int)x+k*dx; xa < xe; xa++) ! if (ggiDrawVLine(*vis, xa, y+h-1-max[k], max[k]-min[k]+1)) return __FAIL; } ! ggiSetGCForeground(*vis, pix2); for (k = 0; k < vals; k++) { int xa, xe = (int)x+(k+1)*dx; if (rmsl[k] <= rmsh[k]) for (xa = (int)x+k*dx; xa < xe; xa++) ! if (ggiDrawVLine(*vis, xa, y+h-1-rmsh[k], rmsh[k]-rmsl[k]+1)) return __FAIL; } ! ggiSetGCForeground(*vis, pix); free(min); free(max); free(rmsh); free(rmsl); #ifdef DEBUG --- 282,304 ---- } } ! ggiGetGCForeground(vis, &pix); ! if (ggiUnmapPixel(vis, pix, &col)) return __FAIL; shade(&col); ! pix2 = ggiMapColor(vis, &col); for (k = 0; k < vals; k++) { int xa, xe = (int)x+(k+1)*dx; for (xa = (int)x+k*dx; xa < xe; xa++) ! if (draw_vline(v, xa, y+h-1-max[k], max[k]-min[k]+1) < 0) return __FAIL; } ! ggiSetGCForeground(vis, pix2); for (k = 0; k < vals; k++) { int xa, xe = (int)x+(k+1)*dx; if (rmsl[k] <= rmsh[k]) for (xa = (int)x+k*dx; xa < xe; xa++) ! if (draw_vline(v, xa, y+h-1-rmsh[k], rmsh[k]-rmsl[k]+1) < 0) return __FAIL; } ! ggiSetGCForeground(vis, pix); free(min); free(max); free(rmsh); free(rmsl); #ifdef DEBUG |
From: <ag...@us...> - 2003-12-23 01:20:51
|
Update of /cvsroot/q-lang/q-audio In directory sc8-pr-cvs1:/tmp/cvs-serv25197 Modified Files: ChangeLog Log Message: update for latest Q-GGI Index: ChangeLog =================================================================== RCS file: /cvsroot/q-lang/q-audio/ChangeLog,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ChangeLog 15 Dec 2003 12:25:15 -0000 1.2 --- ChangeLog 23 Dec 2003 01:20:48 -0000 1.3 *************** *** 1,5 **** ! 2003-10-20 Albert Graef <ag...@mu...> +++ Release 1.2 +++ * images, src: added draw_wave module and audio_player script --- 1,9 ---- ! 2003-12-23 Albert Graef <Dr....@t-...> +++ Release 1.2 +++ + + * fixes for compatibility with latest Q-GGI + + 2003-10-20 Albert Graef <ag...@mu...> * images, src: added draw_wave module and audio_player script |
Update of /cvsroot/q-lang/q/modules/ggi In directory sc8-pr-cvs1:/tmp/cvs-serv23691/modules/ggi Modified Files: Makefile.am Makefile.mingw README-GGI ggi.c ggi.q Added Files: draw_line.c ggilib.c ggilib.h Log Message: major overhaul of GGI interface; see ChangeLog for details --- NEW FILE: draw_line.c --- /* line clipping algorithm, pilfered from GGI sources ************************/ /* $Id: draw_line.c,v 1.1 2003/12/23 01:15:02 agraef Exp $ ****************************************************************************** Graphics library for GGI. Copyright (C) 1998 Alexander Larsson [al...@ly...] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************** */ #include <ggi/internal/ggi-dl.h> /* This is a line-clipper using the algorithm by cohen-sutherland. It is modified to do pixel-perfect clipping. This means that it will generate the same endpoints that would be drawn if an ordinary bresenham line-drawer where used and only visible pixels drawn. It can be used with a bresenham-like linedrawer if it is modified to start with a correct error-term. */ #define OC_LEFT 1 #define OC_RIGHT 2 #define OC_TOP 4 #define OC_BOTTOM 8 /* Outcodes: +-> x | | | V 0101 | 0100 | 0110 y --------------------- 0001 | 0000 | 0010 --------------------- 1001 | 1000 | 1010 | | */ #define outcode(code, xx, yy) \ {\ code = 0;\ if ((xx)<(LIBGGI_GC(vis)->cliptl.x))\ code |= OC_LEFT;\ else if ((xx)>=(LIBGGI_GC(vis)->clipbr.x))\ code |= OC_RIGHT;\ if ((yy)<(LIBGGI_GC(vis)->cliptl.y))\ code |= OC_TOP;\ else if ((yy)>=(LIBGGI_GC(vis)->clipbr.y))\ code |= OC_BOTTOM;\ } /* Calculates |_ a/b _| with mathematically correct floor */ static int FloorDiv(int a, int b) { int _floor; if (b>0) { if (a>0) { return a /b; } else { _floor = -((-a)/b); if ((-a)%b != 0) _floor--; } return _floor; } else { if (a>0) { _floor = -(a/(-b)); if (a%(-b) != 0) _floor--; return _floor; } else { return (-a)/(-b); } } } /* Calculates |^ a/b ^| with mathamatically correct floor */ static int CeilDiv(int a,int b) { if (b>0) return FloorDiv(a-1,b)+1; else return FloorDiv(-a-1,-b)+1; } static int _ggi_clip2d(ggi_visual *vis,int *_x0, int *_y0, int *_x1, int *_y1, int *clip_first, int *clip_last) { int first,last, code; int x0,y0,x1,y1; int x,y; int dx,dy; int xmajor; int slope; *clip_first = first = 0; *clip_last = last = 0; outcode(first,*_x0,*_y0); outcode(last,*_x1,*_y1); if ((first | last) == 0) { return 1; /* Trivially accepted! */ } if ((first & last) != 0) { return 0; /* Trivially rejected! */ } x0=*_x0; y0=*_y0; x1=*_x1; y1=*_y1; dx = x1 - x0; dy = y1 - y0; xmajor = (abs(dx) > abs(dy)); slope = ((dx>=0) && (dy>=0)) || ((dx<0) && (dy<0)); for (;;) { code = first; if (first==0) code = last; if (code&OC_LEFT) { x = LIBGGI_GC(vis)->cliptl.x; if (xmajor) { y = *_y0 + FloorDiv(dy*(x - *_x0)*2 + dx, 2*dx); } else { if (slope) { y = *_y0 + CeilDiv(dy*((x - *_x0)*2 - 1), 2*dx); } else { y = *_y0 + FloorDiv(dy*((x - *_x0)*2 - 1), 2*dx); } } } else if (code&OC_RIGHT) { x = LIBGGI_GC(vis)->clipbr.x - 1; if (xmajor) { y = *_y0 + FloorDiv(dy*(x - *_x0)*2 + dx, 2*dx); } else { if (slope) { y = *_y0 + CeilDiv(dy*((x - *_x0)*2 + 1), 2*dx)-1; } else { y = *_y0 + FloorDiv(dy*((x - *_x0)*2 + 1), 2*dx)+1; } } } else if (code&OC_TOP) { y = LIBGGI_GC(vis)->cliptl.y; if (xmajor) { if (slope) { x = *_x0 + CeilDiv(dx*((y - *_y0)*2 - 1), 2*dy); } else { x = *_x0 + FloorDiv(dx*((y - *_y0)*2 - 1), 2*dy); } } else { x = *_x0 + FloorDiv( dx*(y - *_y0)*2 + dy, 2*dy); } } else { /* OC_BOTTOM */ y = LIBGGI_GC(vis)->clipbr.y - 1; if (xmajor) { if (slope) { x = *_x0 + CeilDiv(dx*((y - *_y0)*2 + 1), 2*dy)-1; } else { x = *_x0 + FloorDiv(dx*((y - *_y0)*2 + 1), 2*dy)+1; } } else { x = *_x0 + FloorDiv(dx*(y - *_y0)*2 + dy, 2*dy); } } if (first!=0) { x0 = x; y0 = y; outcode(first,x0,y0); *clip_first = 1; } else { x1 = x; y1 = y; last = code; outcode(last,x1,y1); *clip_last = 1; } if ((first & last) != 0) { return 0; /* Trivially rejected! */ } if ((first | last) == 0) { *_x0=x0; *_y0=y0; *_x1=x1; *_y1=y1; return 1; /* Trivially accepted! */ } } } /* line drawing algorithm from GGI sources, slightly modified for Q-GGI ******/ /* $Id: draw_line.c,v 1.1 2003/12/23 01:15:02 agraef Exp $ ****************************************************************************** Graphics library for GGI. Copyright (C) 1995 Andreas Beck [be...@gg...] Copyright (C) 1997 Jason McMullan [jm...@gg...] Copyright (C) 1998 Alexander Larsson [al...@ly...] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************** */ typedef struct { ggi_visual_t vis; } visual_t; extern int draw_box(visual_t *v, int x, int y, int w, int h); static inline int DrawHLine(visual_t *v, int x, int y, int w) { return (draw_box(v,x,y,w,1) >= 0)?0:-1; } static inline int DrawVLine(visual_t *v, int x, int y, int h) { return (draw_box(v,x,y,1,h) >= 0)?0:-1; } static inline int DrawPixel(visual_t *v, int x, int y) { return (draw_box(v,x,y,1,1) >= 0)?0:-1; } int draw_line(visual_t *v, int orig_x1, int orig_y1, int orig_x2, int orig_y2) { ggi_visual *vis = v->vis; int orig_dx, orig_dy, sx, sy; int dx,dy; int i; int x1, y1, x2, y2; int clip_first, clip_last; x1 = orig_x1; y1 = orig_y1; x2 = orig_x2; y2 = orig_y2; /* clip x1,y1 and x2,y2. Set clip_first and clip_last if clipped */ if (!_ggi_clip2d(vis, &x1,&y1,&x2,&y2,&clip_first,&clip_last)) { return 0; /* Clipped */ } dy = y2 - y1; orig_dy = orig_y2 - orig_y1; sy = 1; if (orig_dy < 0) { orig_dy = -orig_dy; dy = -dy; sy = -1; } dx = x2-x1; orig_dx = orig_x2 - orig_x1; sx = 1; if (orig_dx < 0) { sx = -1; orig_dx = -orig_dx; dx = -dx; } if (dx == 0) { return (sy>0) ? DrawVLine(v,x1,y1,dy+1) : DrawVLine(v,x2,y2,dy+1); } if (dy == 0) { return (sx>0) ? DrawHLine(v,x1,y1,dx+1) : DrawHLine(v,x2,y2,dx+1); } if (orig_dx == orig_dy) { for (i=dx; i >= 0; i--) { DrawPixel(v, x1, y1); x1 += sx; y1 += sy; } return 0; } if (orig_dx >= orig_dy) { /* x major */ int runlen,adjup,adjdown,e,len; int firstlen,lastlen; runlen = orig_dx/orig_dy; adjup = orig_dx%orig_dy; lastlen = firstlen = (runlen>>1) + 1; if (clip_first) { /* clipped, Adjust firstlen */ int clip_dx = abs(x1 - orig_x1); int clip_dy = abs(y1 - orig_y1); int d = (2*clip_dy+1)*orig_dx; firstlen = d/(2*orig_dy) - clip_dx + 1; e = d%(2*orig_dy); if ((e==0) && (sy>0)) { /* Special case, arbitrary choise. Select lower pixel.(?) */ firstlen--; e += 2*orig_dy; } e -= (orig_dy*2); } else { /* Not clipped, calculate start error term */ e = adjup - (orig_dy<<1); /* initial errorterm == half a step */ if ((runlen&1) != 0) { e += orig_dy; } } if (clip_last) { /* Last endpoint clipped */ int clip_dx = abs(x2 - orig_x2); int clip_dy = abs(y2 - orig_y2); int d = (1+2*clip_dy)*orig_dx; lastlen = d/(2*orig_dy) - clip_dx + 1; if ((sy<0) && ((d%(2*orig_dy))==0)) { /* special arbitrary case */ lastlen--; } } adjup <<= 1; adjdown = orig_dy<<1; if (sy>0) { /* line goes down */ if ((adjup==0) && ((runlen&1)==0) && (!clip_first)) { firstlen--; } if (sx>0) { /* line goes right */ DrawHLine(v,x1,y1,firstlen); x1 += firstlen; y1 ++; for (i=dy-1; i>0; i--) { len = runlen; e += adjup; if (e>0) { len++; e -= adjdown; } DrawHLine(v,x1,y1,len); x1 += len; y1++; } DrawHLine(v,x1,y1,lastlen); return 0; } else { /* line goes left */ x1++; /* because ggiDrawHLine draws right */ x1 -= firstlen; DrawHLine(v,x1,y1,firstlen); y1++; for (i=dy-1; i>0; i--) { len = runlen; e += adjup; if (e>0) { len++; e -= adjdown; } x1 -= len; DrawHLine(v,x1,y1,len); y1 ++; } x1 -= lastlen; DrawHLine(v,x1,y1,lastlen); return 0; } } else { /* line goes up */ if ((adjup==0) && ((runlen&1)==0) && (!clip_last)) { lastlen--; } if (sx>0) { /* line goes right */ DrawHLine(v,x1,y1,firstlen); x1 += firstlen; y1--; for (i=dy-1; i>0; i--) { len = runlen; e += adjup; if (e>=0) { len++; e -= adjdown; } DrawHLine(v,x1,y1,len); x1 += len; y1--; } DrawHLine(v,x1,y1,lastlen); return 0; } else { /* line goes left */ x1++; /* because ggiDrawHLine draws right */ x1 -= firstlen; DrawHLine(v,x1,y1,firstlen); y1--; for (i=dy-1; i>0; i--) { len = runlen; e += adjup; if (e>=0) { len++; e -= adjdown; } x1 -= len; DrawHLine(v,x1,y1,len); y1--; } x1 -= lastlen; DrawHLine(v,x1,y1,lastlen); return 0; } } } else { /* y major */ int runlen,adjup,adjdown,e,len; int firstlen,lastlen; runlen = orig_dy/orig_dx; adjup = orig_dy%orig_dx; lastlen = firstlen = (runlen>>1) + 1; if (clip_first) { /* clipped, Adjust firstlen */ int clip_dx = abs(x1 - orig_x1); int clip_dy = abs(y1 - orig_y1); int d = (2*clip_dx+1)*orig_dy; firstlen = d/(2*orig_dx) - clip_dy + 1; e = d%(2*orig_dx); if ((e==0) && (sx>0)) { /* Special case, arbitrary choise. Select lower pixel.(?) */ firstlen--; e += 2*orig_dx; } e -= (orig_dx*2); } else { /* Not clipped, calculate start error term */ e = adjup - (orig_dx<<1); /* initial errorterm == half a step */ if ((runlen&1) != 0) { e += orig_dx; } } if (clip_last) { /* Last endpoint clipped */ int clip_dx = abs(x2 - orig_x2); int clip_dy = abs(y2 - orig_y2); int d = (1+2*clip_dx)*orig_dy; lastlen = d/(2*orig_dx) - clip_dy + 1; if ((sx<0) && ((d%(2*orig_dx))==0)) { /* special arbitrary case */ lastlen--; } } adjup <<= 1; adjdown = orig_dx<<1; if (sy>0) { /* Line goes DOWN */ if (sx>0) { /* line goes RIGHT */ if ((adjup==0) && ((runlen&1)==0) && (!clip_first)) { firstlen--; } DrawVLine(v,x1,y1,firstlen); y1 += firstlen; x1++; for (i=dx-1; i>0; i--) { len = runlen; e += adjup; if (e>0) { len++; e -= adjdown; } DrawVLine(v,x1,y1,len); y1 += len; x1++; } DrawVLine(v,x1,y1,lastlen); return 0; } else { /* line goes LEFT */ if ((adjup==0) && ((runlen&1)==0) && (!clip_last)) { lastlen--; } DrawVLine(v,x1,y1,firstlen); y1 += firstlen; x1--; for (i=dx-1; i>0; i--) { len = runlen; e += adjup; if (e>=0) { len++; e -= adjdown; } DrawVLine(v,x1,y1,len); y1 += len; x1--; } DrawVLine(v,x1,y1,lastlen); return 0; } } else { /* Line goes UP */ y1++; if (sx>0) { /* line goes RIGHT */ if ((adjup==0) && ((runlen&1)==0) && (!clip_first)) { firstlen--; } y1 -= firstlen; DrawVLine(v,x1,y1,firstlen); x1++; for (i=dx-1; i>0; i--) { len = runlen; e += adjup; if (e>0) { len++; e -= adjdown; } y1 -= len; DrawVLine(v,x1,y1,len); x1++; } y1 -= lastlen; DrawVLine(v,x1,y1,lastlen); return 0; } else { /* line goes LEFT */ if ((adjup==0) && ((runlen&1)==0) && (!clip_last)) { lastlen--; } y1 -= firstlen; DrawVLine(v,x1,y1,firstlen); x1--; for (i=dx-1; i>0; i--) { len = runlen; e += adjup; if (e>=0) { len++; e -= adjdown; } y1 -= len; DrawVLine(v,x1,y1,len); x1--; } y1 -= lastlen; DrawVLine(v,x1,y1,lastlen); return 0; } } } } /*****************************************************************************/ --- NEW FILE: ggilib.c --- /* This file is part of the Q programming system. The Q programming system is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. The Q programming system is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <limits.h> #include "ggilib.h" typedef struct { ggi_visual_t vis; void *abuf; unsigned char asz; unsigned short afg, abg; int stride, lines; } visual_t; /* calculate the size of a pixel pack */ static inline int pack_size(ggi_visual_t vis, int n) { int bpp, r; ggi_mode m; if (ggiGetMode(vis, &m)) return -1; bpp = GT_SIZE(m.graphtype); if (n > INT_MAX / bpp) return -1; r = ((bpp*n)%8>0)?1:0; return (bpp*n)/8+r; } /* clear clip area of alpha buffer */ int clear_alpha_buffer(void *_v) { visual_t *v = (visual_t*)_v; int x1, y1, x2, y2; if (ggiGetGCClipping(v->vis, &x1, &y1, &x2, &y2)) return -1; if (v->asz == 1) { unsigned char *abuf = (unsigned char*)v->abuf; int i, y; for (i = y1*v->stride+x1, y = y1; y < y2; y++, i += v->stride) memset(abuf+i, v->abg, x2-x1); } else { unsigned short *abuf = (unsigned short*)v->abuf; int i, j, x, y; for (i = y1*v->stride+x1, y = y1; y < y2; y++, i += v->stride) for (j = i, x = x1; x < x2; x++, j++) abuf[j] = v->abg; } return 0; } /* set alpha values, with clipping */ int set_alpha_box(void *_v, int x, int y, int w, int h, ggi_color *c) { visual_t *v = (visual_t*)_v; int x1, y1, x2, y2; int i, j, k, xx, yy; if (ggiGetGCClipping(v->vis, &x1, &y1, &x2, &y2)) return -1; if (v->asz == 1) { unsigned char *abuf = (unsigned char*)v->abuf; /* FIXME: optimize me! */ for (k = 0, i = y*v->stride+x, yy = y; yy < y+h; yy++, i += v->stride) for (j = i, xx = x; xx < x+w; xx++, j++, k++) if (xx >= x1 && xx < x2 && yy >= y1 && yy < y2) abuf[j] = c[k].a/0x101; } else { unsigned short *abuf = (unsigned short*)v->abuf; /* FIXME: optimize me! */ for (k = 0, i = y*v->stride+x, yy = y; yy < y+h; yy++, i += v->stride) for (j = i, xx = x; xx < x+w; xx++, j++, k++) if (xx >= x1 && xx < x2 && yy >= y1 && yy < y2) abuf[j] = c[k].a; } return 0; } /* same as above, but use current foreground color */ int draw_alpha_box(void *_v, int x, int y, int w, int h) { visual_t *v = (visual_t*)_v; int x1, y1, x2, y2; int i, j, xx, yy; if (ggiGetGCClipping(v->vis, &x1, &y1, &x2, &y2)) return -1; if (v->asz == 1) { unsigned char *abuf = (unsigned char*)v->abuf; /* FIXME: optimize me! */ for (i = y*v->stride+x, yy = y; yy < y+h; yy++, i += v->stride) for (j = i, xx = x; xx < x+w; xx++, j++) if (xx >= x1 && xx < x2 && yy >= y1 && yy < y2) abuf[j] = v->afg; } else { unsigned short *abuf = (unsigned short*)v->abuf; /* FIXME: optimize me! */ for (i = y*v->stride+x, yy = y; yy < y+h; yy++, i += v->stride) for (j = i, xx = x; xx < x+w; xx++, j++) if (xx >= x1 && xx < x2 && yy >= y1 && yy < y2) abuf[j] = v->afg; } return 0; } /* retrieve a rectangle of pixels from a visual, including alpha values */ int get_box(void *_v, int x, int y, int w, int h, ggi_color **c) { visual_t *v = (visual_t*)_v; int n = w*h, bpp, stride, ret; int xc = x, yc = y, wc = w, hc = h; int i, j, k, xx, yy; unsigned char *buf; ggi_mode m; *c = NULL; /* FIXME: we don't support packed non-byte-aligned pixels for now */ if (ggiGetMode(v->vis, &m) || (bpp = GT_SIZE(m.graphtype))%8 != 0) return 0; if (x >= v->stride || y >= v->lines || h <= 0 || w <= 0) return n; if (w > INT_MAX/h) return -1; if (!(buf = malloc(pack_size(v->vis, n)))) return -1; if (n > INT_MAX/sizeof(ggi_color) || !(*c = malloc(n*sizeof(ggi_color)))) { free(buf); return -1; } /* we do our own clipping here, since GGI doesn't handle it :( */ memset(buf, 0, n); memset(*c, 0, n*sizeof(ggi_color)); if (xc < 0) { wc += xc; xc = 0; } if (xc+wc > v->stride) wc = v->stride - xc; if (yc < 0) { hc += yc; yc = 0; } if (yc+hc > v->lines) hc = v->lines - yc; bpp /= 8; stride = w*bpp; if (xc == x && wc == w) { ret = ggiGetBox(v->vis, xc, yc, wc, hc, buf+(yc-y)*stride); } else { /* horizontal clipping, read the pixels line by line */ unsigned char *bufp; int off = (xc-x)*bpp; for (bufp = buf+(yc-y)*stride, yy = yc; yy < yc+hc; yy++, bufp += stride) if ((ret = ggiGetHLine(v->vis, xc, yy, wc, bufp+off))) break; } if (ret) { free(buf); free(*c); return 0; } if (ggiUnpackPixels(v->vis, buf, *c, n)) { free(buf); free(*c); return 0; } free(buf); /* get the alpha values from the alpha buffer if any */ if (v->abuf) { if (v->asz == 1) { unsigned char *abuf = (unsigned char*)v->abuf; /* FIXME: optimize me! */ for (i = y*v->stride+x, k = 0, yy = y; yy < y+h; yy++, i += v->stride) for (j = i, xx = x; xx < x+w; xx++, j++) if (xx >= 0 && xx < v->stride && yy >= 0 && yy < v->lines) (*c)[k++].a = abuf[j]*0x101; else (*c)[k++].a = 0xffff; } else { unsigned short *abuf = (unsigned short*)v->abuf; /* FIXME: optimize me! */ for (i = y*v->stride+x, k = 0, yy = y; yy < y+h; yy++, i += v->stride) for (j = i, xx = x; xx < x+w; xx++, j++) if (xx >= 0 && xx < v->stride && yy >= 0 && yy < v->lines) (*c)[k++].a = abuf[j]; else (*c)[k++].a = 0xffff; } } else { /* default alpha values */ int i; for (i = 0; i < n; i++) (*c)[i].a = 0xffff; } return n; } /* perform alpha blending */ static int blend_box(visual_t *v, int x, int y, int w, int h, ggi_color *c, ggi_color **d) { int i, n = w*h; *d = c; if (!v->abuf) return n; if ((n = get_box(v, x, y, w, h, d)) <= 0 || !(*d)) return n; for (i = 0; i < n; i++) { (*d)[i].r = (((unsigned long)c[i].a)*((unsigned long)c[i].r) + ((unsigned long)0xffff-c[i].a)*((unsigned long)(*d)[i].r))/0xffff; (*d)[i].g = (((unsigned long)c[i].a)*((unsigned long)c[i].g) + ((unsigned long)0xffff-c[i].a)*((unsigned long)(*d)[i].g))/0xffff; (*d)[i].b = (((unsigned long)c[i].a)*((unsigned long)c[i].b) + ((unsigned long)0xffff-c[i].a)*((unsigned long)(*d)[i].b))/0xffff; (*d)[i].a = (0xffffL*((unsigned long)c[i].a) + ((unsigned long)0xffff-c[i].a)*((unsigned long)(*d)[i].a))/0xffff; } return n; } /* same, for single source pixel */ static int blend_box1(visual_t *v, int x, int y, int w, int h, ggi_color *c, ggi_color **d) { int i, n = w*h; *d = NULL; if (!v->abuf || c->a == 0xffff) return n; if ((n = get_box(v, x, y, w, h, d)) <= 0 || !(*d)) return n; for (i = 0; i < n; i++) { (*d)[i].r = (((unsigned long)c->a)*((unsigned long)c->r) + ((unsigned long)0xffff-c->a)*((unsigned long)(*d)[i].r))/0xffff; (*d)[i].g = (((unsigned long)c->a)*((unsigned long)c->g) + ((unsigned long)0xffff-c->a)*((unsigned long)(*d)[i].g))/0xffff; (*d)[i].b = (((unsigned long)c->a)*((unsigned long)c->b) + ((unsigned long)0xffff-c->a)*((unsigned long)(*d)[i].b))/0xffff; (*d)[i].a = (0xffffL*((unsigned long)c->a) + ((unsigned long)0xffff-c->a)*((unsigned long)(*d)[i].a))/0xffff; } return n; } /* store a rectangle of pixels in a visual, with alpha blending */ int put_box(void *_v, int x, int y, int w, int h, ggi_color *c) { visual_t *v = (visual_t*)_v; int n = w*h, ret; unsigned char *buf; ggi_color *d = c; if (h <= 0 || w <= 0) return 0; if (w > INT_MAX/h) return -1; if ((ret = blend_box(v, x, y, w, h, c, &d)) <= 0 || !d) return ret; if (!(buf = malloc(pack_size(v->vis, n)))) return -1; ret = ggiPackColors(v->vis, buf, d, n) || ggiPutBox(v->vis, x, y, w, h, buf); free(buf); if (!ret && v->abuf) ret = set_alpha_box(v, x, y, w, h, d); if (d != c) free(d); if (ret) return 0; else return n; } /* same, with current foreground pixel */ int draw_box(void *_v, int x, int y, int w, int h) { visual_t *v = (visual_t*)_v; int n = w*h, ret; unsigned char *buf; ggi_pixel pix; ggi_color c, *d = NULL; if (h <= 0 || w <= 0) return 0; if (ggiGetGCForeground(v->vis, &pix) || ggiUnmapPixel(v->vis, pix, &c)) return 0; if (v->abuf) c.a = (v->asz==1)?(v->afg*0x101):v->afg; else c.a = 0xffff; if (w > INT_MAX/h) return -1; if ((ret = blend_box1(v, x, y, w, h, &c, &d)) <= 0) return ret; if (d) { if (!(buf = malloc(pack_size(v->vis, n)))) return -1; ret = ggiPackColors(v->vis, buf, d, n) || ggiPutBox(v->vis, x, y, w, h, buf); free(buf); if (!ret && v->abuf) ret = set_alpha_box(v, x, y, w, h, d); free(d); } else { ret = ggiDrawBox(v->vis, x, y, w, h); if (!ret && v->abuf) ret = draw_alpha_box(v, x, y, w, h); } if (ret) return 0; else return n; } --- NEW FILE: ggilib.h --- /* C interface to some of the internals of the Q-GGI module, to facilitate access for "third-party" extensions like the draw_wave module. 2003-12-23 AG */ /* This file is part of the Q programming system. The Q programming system is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. The Q programming system is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef __GGILIB_H__ #define __GGILIB_H__ 1 #include <ggi/ggi.h> /* NOTE: The v argument of the following operations must point to a valid GGIVisual object, as obtained from the object pointer of a GGIVisual expression. */ /* the following operations return a negative value on error, zero otherwise */ /* clear clip area of alpha buffer */ extern int clear_alpha_buffer(void *v); /* set alpha values, with clipping */ extern int set_alpha_box(void *v, int x, int y, int w, int h, ggi_color *c); /* same as above, but use current foreground color */ extern int draw_alpha_box(void *v, int x, int y, int w, int h); /* the following operations return the number of processed pixels if successful, negative otherwise */ /* retrieve a rectangle of pixels from a visual, including alpha values (storage pointed to by c is malloc'ed, user must free it) */ extern int get_box(void *v, int x, int y, int w, int h, ggi_color **c); /* store a rectangle of pixels in a visual, with alpha blending */ extern int put_box(void *v, int x, int y, int w, int h, ggi_color *c); /* same, with current foreground pixel */ extern int draw_box(void *v, int x, int y, int w, int h); /* for this one, you need to link in draw_line.c; returns nonzero iff error */ extern int draw_line(void *v, int x1, int y1, int x2, int y2); /* convenience inline functions, to process horizontal and vertical lines and single pixels */ static inline int set_alpha_hline(void *v, int x, int y, int w, ggi_color *c) { return set_alpha_box(v, x, y, w, 1, c); } static inline int set_alpha_vline(void *v, int x, int y, int h, ggi_color *c) { return set_alpha_box(v, x, y, 1, h, c); } static inline int set_alpha_pixel(void *v, int x, int y, ggi_color *c) { return set_alpha_box(v, x, y, 1, 1, c); } static inline int draw_alpha_hline(void *v, int x, int y, int w) { return draw_alpha_box(v, x, y, w, 1); } static inline int draw_alpha_vline(void *v, int x, int y, int h) { return draw_alpha_box(v, x, y, 1, h); } static inline int draw_alpha_pixel(void *v, int x, int y) { return draw_alpha_box(v, x, y, 1, 1); } static inline int get_hline(void *v, int x, int y, int w, ggi_color **c) { return get_box(v, x, y, w, 1, c); } static inline int get_vline(void *v, int x, int y, int h, ggi_color **c) { return get_box(v, x, y, 1, h, c); } static inline int get_pixel(void *v, int x, int y, ggi_color **c) { return get_box(v, x, y, 1, 1, c); } static inline int put_hline(void *v, int x, int y, int w, ggi_color *c) { return put_box(v, x, y, w, 1, c); } static inline int put_vline(void *v, int x, int y, int h, ggi_color *c) { return put_box(v, x, y, 1, h, c); } static inline int put_pixel(void *v, int x, int y, ggi_color *c) { return put_box(v, x, y, 1, 1, c); } static inline int draw_hline(void *v, int x, int y, int w) { return draw_box(v, x, y, w, 1); } static inline int draw_vline(void *v, int x, int y, int h) { return draw_box(v, x, y, 1, h); } static inline int draw_pixel(void *v, int x, int y) { return draw_box(v, x, y, 1, 1); } #endif Index: Makefile.am =================================================================== RCS file: /cvsroot/q-lang/q/modules/ggi/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Makefile.am 19 Dec 2003 21:31:34 -0000 1.3 --- Makefile.am 23 Dec 2003 01:15:02 -0000 1.4 *************** *** 11,17 **** endif ! ggi_la_SOURCES = ggi.c ggi_la_LDFLAGS = -no-undefined -module -avoid-version ! ggi_la_LIBADD = -L$(top_builddir)/libq -lq @LIBGMP@ @GGI_LIBS@ @GGI_LIBBUF@ @FT2_LIBS@ @LIBDMALLOCTH@ stdlibdir = $(pkgdatadir)/lib --- 11,17 ---- endif ! ggi_la_SOURCES = ggi.c ggilib.h ggilib.c draw_line.c ggi_la_LDFLAGS = -no-undefined -module -avoid-version ! ggi_la_LIBADD = -L$(top_builddir)/libq -lq @LIBGMP@ @GGI_LIBS@ @FT2_LIBS@ @LIBDMALLOCTH@ stdlibdir = $(pkgdatadir)/lib Index: Makefile.mingw =================================================================== RCS file: /cvsroot/q-lang/q/modules/ggi/Makefile.mingw,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile.mingw 15 Dec 2003 12:07:14 -0000 1.2 --- Makefile.mingw 23 Dec 2003 01:15:02 -0000 1.3 *************** *** 13,18 **** all: ggi$(SHLEXT) ! ggi$(SHLEXT): ggi.c ! qcc -o ggi$(SHLEXT) ggi.c -- $(DEFS) -I. -I../../libq -I../../../ggi/include -I../../../gmp --link -L. -L../../../ggi/lib -lggi -lgii -lgg -lggibuf -lggigalloc -L../../../gmp -lgmp -L../../libq clean mostlyclean distclean maintainer-clean:: --- 13,18 ---- all: ggi$(SHLEXT) ! ggi$(SHLEXT): ggi.c ggilib.h ggilib.c draw_line.c ! qcc -o ggi$(SHLEXT) ggi.c ggilib.c draw_line.c -- $(DEFS) -I. -I../../libq -I../../../ggi/include -I../../../gmp --link -L. -L../../../ggi/lib -lggi -lgii -lgg -L../../../gmp -lgmp -L../../libq clean mostlyclean distclean maintainer-clean:: Index: README-GGI =================================================================== RCS file: /cvsroot/q-lang/q/modules/ggi/README-GGI,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** README-GGI 19 Dec 2003 21:31:34 -0000 1.3 --- README-GGI 23 Dec 2003 01:15:02 -0000 1.4 *************** *** 11,23 **** advanced features and extensions when these parts of GGI become stable. But the module is already quite usable for doing raster graphics on a wide variety ! of systems and output devices. Experimental support for alpha and z buffers ! via GGI's buffer extension, as well as advanced text rendering via FreeType2 ! is now also available. The module requires that you have libggi (version 2.0 or later) and libgii ! (version 0.8 or later) installed. To make the alpha/z buffer support work, you ! need the buffer extension (libggibuf+libggigalloc, currently only available ! from cvs). For the additional font support you also need to have FreeType2 ! (http://www.freetype.org/) installed. Since the GGI project at SourceForge [http://sourceforge. net/projects/ggi/] --- 11,20 ---- advanced features and extensions when these parts of GGI become stable. But the module is already quite usable for doing raster graphics on a wide variety ! of systems and output devices. Experimental support for simple alpha blending ! as well as advanced text rendering via FreeType2 is now also available. The module requires that you have libggi (version 2.0 or later) and libgii ! (version 0.8 or later) installed. For the additional font support you also ! need version 2 of the FreeType library (http://www.freetype.org/). Since the GGI project at SourceForge [http://sourceforge. net/projects/ggi/] *************** *** 33,37 **** Please see ggi.q for a description of the functions provided by this module. For more in-depth information about GGI please refer to the corresponding ! manual pages. A little demo can be found in the ggi_demo.q script. Acknowledgements --- 30,35 ---- Please see ggi.q for a description of the functions provided by this module. For more in-depth information about GGI please refer to the corresponding ! manual pages. A few sample scripts are also provided; you can find these, once ! installed, in the <q-prefix>/share/q/examples/ggi directory. Acknowledgements *************** *** 44,48 **** Enjoy! :) ! Nov 28 2003 Albert Graef ag...@mu..., Dr....@t-... --- 42,46 ---- Enjoy! :) ! Dec 22 2003 Albert Graef ag...@mu..., Dr....@t-... Index: ggi.c =================================================================== RCS file: /cvsroot/q-lang/q/modules/ggi/ggi.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ggi.c 21 Dec 2003 12:53:26 -0000 1.14 --- ggi.c 23 Dec 2003 01:15:02 -0000 1.15 *************** *** 64,71 **** #endif - #if defined(HAVE_GGIBUFINIT) && !defined(HAVE_GGIBUF) - #define HAVE_GGIBUF 1 - #endif - #if defined(HAVE_FT_INIT_FREETYPE) && !defined(HAVE_FT2) #define HAVE_FT2 1 --- 64,67 ---- *************** [...1577 lines suppressed...] - v->vis && v->b[1] && istuple(argv[1], &n, &xv) && n == 2 && - isint(xv[0], &x) && isint(xv[1], &y) && - x >= 0 && y >= 0 && - istuple(argv[2], &n, &xv) && n == 2 && - isint(xv[0], &w) && isint(xv[1], &h) && - isobj(argv[3], type(ByteStr), (void**)&m) && m->size%2 == 0) { - n = m->size/2; - if (w*h != n) return __FAIL; - if (n <= 0) return mkvoid; - if ((n = put_buf_box(v->b[1], x, y, w, h, (unsigned short*)m->v)) < 0) - return __ERROR; - else if (n == 0) - return __FAIL; - else - return mkvoid; - } else - #endif return __FAIL; } --- 1770,1773 ---- Index: ggi.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/ggi/ggi.q,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ggi.q 20 Dec 2003 22:06:16 -0000 1.7 --- ggi.q 23 Dec 2003 01:15:02 -0000 1.8 *************** *** 32,56 **** /* The following values, bitwise or'ed together, are used as flag values in the ggi_set_flags and ggi_get_flags operations. See ggiSetFlags(3) for an - explanation of these values. (NOTE: At this time, GGI_FLAG_TIDYBUF is only - supported in the development version of GGI.) */ - - public var const GGI_FLAG_ASYNC, GGI_FLAG_TIDYBUF; - - /* The following values, bitwise or'ed together, are used as flags for the - gii_set_{alpha,z}_flags operations. See ggiBufSetGCFlags(3) for an explanation of these values. */ ! public var const GGI_BUF_DISPOSE, GGI_BUF_PUTGET, ! GGI_BUF_CMP_GT, GGI_BUF_CMP_LT, GGI_BUF_CMP_EQ, ! GGI_BUF_CMP_GTE, GGI_BUF_CMP_LTE, ! GGI_BUF_BLEND_OVER, GGI_BUF_BLEND_UNDER, ! GGI_BUF_BLEND_SRC_OVER, GGI_BUF_BLEND_DST_OVER, ! GGI_BUF_BLEND_SRC_IN, GGI_BUF_BLEND_DST_IN, ! GGI_BUF_BLEND_SRC_OUT, GGI_BUF_BLEND_DST_OUT, ! GGI_BUF_BLEND_TOP, GGI_BUF_BLEND_BOTTOM, ! GGI_BUF_BLEND_XOR, GGI_BUF_BLEND_PLUS, ! GGI_BUF_ALTBLEND_SHIFT, ! GGI_BUF_BLEND_SRC_PREMULT, GGI_BUF_BLEND_DST_PREMULT, ! GGI_BUF_BLEND_POSTDIV; /* The following values describe various types of events and event masks. See --- 32,38 ---- /* The following values, bitwise or'ed together, are used as flag values in the ggi_set_flags and ggi_get_flags operations. See ggiSetFlags(3) for an explanation of these values. */ ! public var const GGI_FLAG_ASYNC; /* The following values describe various types of events and event masks. See *************** *** 139,156 **** def (/* visual flags */ ! GGI_FLAG_ASYNC, GGI_FLAG_TIDYBUF, ! /* buffer flags */ ! GGI_BUF_DISPOSE, GGI_BUF_PUTGET, ! GGI_BUF_CMP_GT, GGI_BUF_CMP_LT, GGI_BUF_CMP_EQ, ! GGI_BUF_CMP_GTE, GGI_BUF_CMP_LTE, ! GGI_BUF_BLEND_OVER, GGI_BUF_BLEND_UNDER, ! GGI_BUF_BLEND_SRC_OVER, GGI_BUF_BLEND_DST_OVER, ! GGI_BUF_BLEND_SRC_IN, GGI_BUF_BLEND_DST_IN, ! GGI_BUF_BLEND_SRC_OUT, GGI_BUF_BLEND_DST_OUT, ! GGI_BUF_BLEND_TOP, GGI_BUF_BLEND_BOTTOM, ! GGI_BUF_BLEND_XOR, GGI_BUF_BLEND_PLUS, ! GGI_BUF_ALTBLEND_SHIFT, ! GGI_BUF_BLEND_SRC_PREMULT, GGI_BUF_BLEND_DST_PREMULT, ! GGI_BUF_BLEND_POSTDIV, /* events */ GGI_EV_NOTHING, GGI_EV_COMMAND, GGI_EV_INFORMATION, --- 121,125 ---- def (/* visual flags */ ! GGI_FLAG_ASYNC, /* events */ GGI_EV_NOTHING, GGI_EV_COMMAND, GGI_EV_INFORMATION, *************** *** 234,271 **** K=greyscale and T=text). ! If the GGI buffer extension is available, the mode string can also specify ! an alpha and/or z buffer which is to be attached to the visual, see also ! the discussion of alpha and z buffers below. E.g.: ! ! "1152x921.V1152x921.F1.D1x1.[C24/32].A8.Z8" ! ! The number following the A and Z symbols denotes the desired bit depth of ! the alpha and z values, respectively. In the current implementation only ! depth 8 is supported. Also note that these specifications are a Q-GGI ! specific extension, and thus cannot be used in the GGI_DEFMODE environment ! variable. ! ! Alpha and z buffers are created with the following defaults, which can ! later be overridden with the appropriate functions discussed in the section ! on alpha and z buffers below: ! - Alpha buffers are created with GGI_BUF_BLEND_OVER mode, with all alpha ! values initialized to 0, and the current foreground and background alpha ! value set to the maximum possible value. This means that by default ! graphic objects will not be transparent, and will be drawn over existing ! objects, which matches the behaviour of a visual without an alpha ! buffer. To get transparent objects, you will have to reduce the ! foreground and background alpha values accordingly. You can also set the ! buffer to GGI_BUF_BLEND_UNDER mode in order to have new objects drawn ! below existing ones. (Alpha buffers can also operate in a number of other ! modes which are discussed in the GGI documentation.) ! - Z buffers are created with GGI_BUF_CMP_LTE mode, with all z values and ! the current foreground and background z value set to the maximum possible ! value. This means that by default new objects will be drawn above objects ! with larger (or equal) z values, and below objects with smaller z ! values. With the default foreground and background z value, new objects ! will just be drawn over existing ones, which matches the behaviour of a ! visual without z buffer. If the MODE argument of ggi_check_mode or ggi_set_mode is () then the --- 203,219 ---- K=greyscale and T=text). ! The mode string can also specify an alpha buffer which is to be attached to ! the visual. E.g.: ! "1152x921.V1152x921.F1.D1x1.[C24/32].A8" ! This means that the visual will be "clad" with an alpha buffer of the ! requested bit depth (8 in this example), and subsequent graphics operations ! will transparently perform alpha blending when pixels are written to the ! visual. This is useful for handling graphics involving transparent or ! translucent pixels. Please note that in the current implementation only the ! depth 0, 8 and 16 are supported. Also note that since this a Q-GGI ! specific extension, the .A mode cannot be used in the GGI_DEFMODE ! environment variable. If the MODE argument of ggi_check_mode or ggi_set_mode is () then the *************** *** 279,284 **** ggi_get_mode VIS; ! /* Set and get flag values of a visual. Currently, the flags GGI_FLAG_ASYNC ! and GGI_FLAG_TIDYBUF(?) are supported; see ggiSetFlags(3). */ public extern ggi_set_flags VIS FLAGS, ggi_get_flags VIS; --- 227,231 ---- ggi_get_mode VIS; ! /* Set and get flag values of a visual; see ggiSetFlags(3). */ public extern ggi_set_flags VIS FLAGS, ggi_get_flags VIS; *************** *** 338,344 **** /* Advanced text rendering using FreeType2. *********************************/ ! /* This is a Q-GGI-specific extension which allows you to set the font used ! for text rendering in a GGI visual. The FreeType2 library is required to ! make this work. */ /* Reset a visual to the default builtin font. */ --- 285,291 ---- /* Advanced text rendering using FreeType2. *********************************/ ! /* This is another Q-GGI specific extension which allows you to set the font ! used for text rendering in a GGI visual. The FreeType2 library is required ! to make this work. */ /* Reset a visual to the default builtin font. */ *************** *** 454,461 **** /* Clear the screen. That is, fill the current clip area (the entire virtual screen by default) with the current background color. Also clear the ! contents of attached buffers. */ public extern ggi_clear VIS; /* Basic drawing operations. These functions always use the foreground color currently set on the visual. You can draw single pixels, horizontal/ --- 401,413 ---- /* Clear the screen. That is, fill the current clip area (the entire virtual screen by default) with the current background color. Also clear the ! clip area of an attached alpha buffer. */ public extern ggi_clear VIS; + /* Clear the alpha buffer only. This works like ggi_clear but only affects the + alpha buffer of a visual. */ + + public extern ggi_clear_alpha VIS; + /* Basic drawing operations. These functions always use the foreground color currently set on the visual. You can draw single pixels, horizontal/ *************** *** 497,507 **** bounding box of the string in relationship to the baseline. For the default font, the XMIN and YMIN values are always zero, and the XMAX and YMAX ! values correspond to the width and height of the rendered string. For other ! fonts, the XMIN value described the initial offset of the first character ! in the string from adjacent characters. The YMIN value specifies the amount ! of vertical space between the lowest pixel in the rendered string and the ! baseline of the text; note that this value can be negative, indicating that ! the string extends *below* the baseline. The YMIN value is useful, in ! particular, if text is to be aligned properly w.r.t. the baseline. */ public extern ggi_get_string_bbox VIS S; --- 449,460 ---- bounding box of the string in relationship to the baseline. For the default font, the XMIN and YMIN values are always zero, and the XMAX and YMAX ! values correspond to the width and height of the rendered string. For ! FreeType-managed fonts, the XMIN value described the initial offset of the ! first character in the string from adjacent characters. The YMIN value ! specifies the amount of vertical space between the lowest pixel in the ! rendered string and the baseline of the text; note that this value can be ! negative, indicating that the string extends *below* the baseline. The YMIN ! value is useful, in particular, if text is to be aligned properly w.r.t. ! the baseline. */ public extern ggi_get_string_bbox VIS S; *************** *** 515,526 **** line or rectangle from a visual as an RGBA byte string. The retrieved value can then be placed back into another or the same visual with the ! corresponding put operations. For the put operations, pixels can also be ! specified as a color tuple or list of color tuples, respectively. ! ! Note that the put operations always render the given pixels using the ! current alpha foreground setting in the target visual, i.e., the inpixel ! alpha values are effectively thrown away. If you want to render an image ! with full alpha blending you should instead use the blitting operations ! below, with the GGI_BUF_PUTGET flag set on the source visual. */ public extern ggi_get_pixel VIS P, ggi_put_pixel VIS P PIXEL; --- 468,474 ---- line or rectangle from a visual as an RGBA byte string. The retrieved value can then be placed back into another or the same visual with the ! corresponding put operations (performing alpha blending if the target ! visual has an alpha buffer). For the put operations, pixels can also be ! specified as a color tuple or list of color tuples, respectively. */ public extern ggi_get_pixel VIS P, ggi_put_pixel VIS P PIXEL; *************** *** 549,560 **** rectangle is denoted by its source position P = (X1,Y1), dimensions DIM = (H,W) and target position Q = (X2,Y2). The rectangle is copied from the ! read frame of the source visual to the write frame of the target visual. ! Overlaps are handled if source and target are the same. If the source ! visual has the GGI_BUF_PUTGET flag set, then full blending of the source ! and target alpha and/or z values is performed. (*FIXME* With the current ! libggibuf version this works for alpha values only.) */ ! public extern ggi_copy_box VIS P DIM Q; ! public extern ggi_cross_blit PVIS P DIM QVIS Q; /* Flush the display. This causes pending output operations to be completed --- 497,512 ---- rectangle is denoted by its source position P = (X1,Y1), dimensions DIM = (H,W) and target position Q = (X2,Y2). The rectangle is copied from the ! read frame of the source visual to the write frame of the target visual. */ ! public ggi_copy_box VIS P DIM Q; ! public ggi_cross_blit PVIS P DIM QVIS Q; ! ! ggi_copy_box VIS P DIM Q ! = () ! where () = ggi_put_box VIS Q DIM (ggi_get_box VIS P DIM); ! ! ggi_cross_blit PVIS P DIM QVIS Q ! = () ! where () = ggi_put_box QVIS Q DIM (ggi_get_box PVIS P DIM); /* Flush the display. This causes pending output operations to be completed *************** *** 566,620 **** public extern ggi_flush VIS, ggi_flush_region VIS P DIM; - - /* Alpha and Z buffers. *****************************************************/ - - /* These operations provide access to GGI's buffer extension, which adds the - capability to handle transparency and the stacking order of graphic - objects. This functionality is enabled when a visual is "clad", i.e., has - an alpha and/or z buffer attached to it (see ggi_set_mode on how to - accomplish this). The following additional operations are provided to - operate directly on the alpha and z buffers of a visual. Please note that - no matter what the internal bit depth of an alpha or z buffer is (at - present it is always 8, but this might change in future libggibuf - implementations), all alpha/z values are represented as normalized 16 bit - values; the necessary conversions from/to the bit depth of the target - buffer will be handled automatically. */ - - /* Set and retrieve flag values affecting the behaviour of alpha blending and - z rendering. These operations use the GGI_BUF_* flag values declared at the - beginning of this module. */ - - public extern ggi_set_alpha_flags VIS FLAGS, ggi_get_alpha_flags VIS; - public extern ggi_set_z_flags VIS FLAGS, ggi_get_z_flags VIS; - - /* Set and retrieve the current foreground and background alpha/z values of a - visual, specified as unsigned 16 bit integer values. These work much like - the ggi_{set,get}_{foreground,background} operations but operate only on - the alpha/z settings. Note that the foreground/background alpha values can - also be set and retrieved with ggi_{set,get}_{foreground,background}. */ - - public extern ggi_set_alpha_foreground VIS VAL, ggi_get_alpha_foreground VIS; - public extern ggi_set_alpha_background VIS VAL, ggi_get_alpha_background VIS; - public extern ggi_set_z_foreground VIS VAL, ggi_get_z_foreground VIS; - public extern ggi_set_z_background VIS VAL, ggi_get_z_background VIS; - - /* Clearing alpha and z buffers. The following operations work like ggi_clear - but only affect the alpha and z buffers of a visual. They cause the clip - area to be filled with the current background alpha/z values. */ - - public extern ggi_clear_alpha VIS; - public extern ggi_clear_z VIS; - - /* Get and set single buffer values, specified as unsigned 16 bit integer - values. */ - - public extern ggi_get_alpha_val VIS P, ggi_put_alpha_val VIS P VAL; - public extern ggi_get_z_val VIS P, ggi_put_z_val VIS P VAL; - - /* Get and set ranges of buffer values, specified as byte strings of 16 bit - values. */ - - public extern ggi_get_alpha_box VIS P DIM, ggi_put_alpha_box VIS P DIM VALS; - public extern ggi_get_z_box VIS P DIM, ggi_put_z_box VIS P DIM VALS; /* Event handling. **********************************************************/ --- 518,521 ---- |
From: <ag...@us...> - 2003-12-23 01:15:06
|
Update of /cvsroot/q-lang/q/modules/magick In directory sc8-pr-cvs1:/tmp/cvs-serv23691/modules/magick Modified Files: magick.c magick.q Log Message: major overhaul of GGI interface; see ChangeLog for details Index: magick.c =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** magick.c 16 Dec 2003 19:11:16 -0000 1.1 --- magick.c 23 Dec 2003 01:15:02 -0000 1.2 *************** *** 217,252 **** } - /* Read/write alpha channel only. */ - - static void get_alpha(unsigned short *dest, PixelPacket *source, - unsigned long count) - { - unsigned long i; - register PixelPacket *p; - register unsigned short *q; - - p = source; - q = dest; - for (i = 0; i < count; i++) { - *q++=ScaleQuantumToShort(MaxRGB-p->opacity); - p++; - } - } - - static void set_alpha(PixelPacket *dest, unsigned short *source, - unsigned long count) - { - unsigned long i; - register unsigned short *p; - register PixelPacket *q; - - p = source; - q = dest; - for (i = 0; i < count; i++) { - q->opacity=ScaleShortToQuantum(0xffff-*p++); - q++; - } - } - /* parse info tuples */ --- 217,220 ---- *************** *** 355,407 **** } - FUNCTION(magick,magick_alpha,argc,argv) - { - expr *xv, x, hd, tl; - int n; - unsigned long a; - PixelPacket pixel; - bstr_t *m; - unsigned short *v; - if (argc != 1) return __FAIL; - pixel.red = pixel.green = pixel.blue = 0; - /* treat the case of a single alpha value: */ - if (isuint(argv[0], &a) && a <= 0xffff) - pixel.opacity = ScaleShortToQuantum(0xffff-a); - else - goto skip; - if (!(m = malloc(sizeof(bstr_t))) || !(m->v = malloc(2))) { - if (m) free(m); return __ERROR; - } - m->size = 2; - get_alpha((unsigned short*)m->v, &pixel, 1); - return mkobj(type(ByteStr), m); - skip: - /* if we come here, we should deal with a list of alpha values */ - for (n = 0, x = argv[0]; iscons(x, &hd, &tl); x = tl) n++; - if (!isnil(x)) return __FAIL; - if (n == 0) { - if (!(m = malloc(sizeof(bstr_t)))) return __ERROR; - m->size = 0; - m->v = NULL; - return mkobj(type(ByteStr), m); - } - if (n < 0 || n > INT_MAX/2) return __ERROR; - if (!(m = malloc(sizeof(bstr_t))) || !(m->v = malloc(n*2))) { - if (m) free(m); return __ERROR; - } - m->size = n*2; - for (v = (unsigned short*)m->v, x = argv[0]; iscons(x, &hd, &tl); - x = tl, v++) { - if (isuint(hd, &a) && a <= 0xffff) - pixel.opacity = ScaleShortToQuantum(0xffff-a); - else { - free(m->v); free(m); - return __FAIL; - } - get_alpha(v, &pixel, 1); - } - return mkobj(type(ByteStr), m); - } - FUNCTION(magick,create_image,argc,argv) { --- 323,326 ---- *************** *** 641,708 **** return __FAIL; } - - FUNCTION(magick,get_image_alpha,argc,argv) - { - Image *img; - expr *xv; - int n; - long x, y; - unsigned long w, h; - PixelPacket *pixels; - if (argc == 3 && isobj(argv[0], type(Image), (void**)&img) && - istuple(argv[1], &n, &xv) && n == 2 && - isint(xv[0], &x) && isint(xv[1], &y) && - istuple(argv[2], &n, &xv) && n == 2 && - isuint(xv[0], &w) && isint(xv[1], &h) && - (pixels = GetImagePixels(img, x, y, w, h))) { - unsigned long size = w*h; - bstr_t *m; - if (ULONG_MAX/2 < w*h) return __ERROR; - if (size == 0) { - m->size = 0; - m->v = NULL; - return mkobj(type(ByteStr), m); - } - if (!(m = malloc(sizeof(bstr_t))) || !(m->v = malloc(size*2))) { - if (m) free(m); - return __ERROR; - } - m->size = size*2; - get_alpha((unsigned short*)m->v, pixels, w*h); - return mkobj(type(ByteStr), m); - } else - return __FAIL; - } - - FUNCTION(magick,set_image_alpha,argc,argv) - { - Image *img; - expr *xv; - int n; - long x, y; - unsigned long w, h; - bstr_t *m; - PixelPacket *pixels; - if (argc == 4 && isobj(argv[0], type(Image), (void**)&img) && - istuple(argv[1], &n, &xv) && n == 2 && - isint(xv[0], &x) && isint(xv[1], &y) && - istuple(argv[2], &n, &xv) && n == 2 && - isuint(xv[0], &w) && isint(xv[1], &h) && - isobj(argv[3], type(ByteStr), (void**)&m) && m->size%2 == 0) { - unsigned long size = w*h; - if (ULONG_MAX/2 < w*h || 2*size != m->size) - return __FAIL; - else if (size == 0) - return mkvoid; - if (!(pixels = SetImagePixels(img, x, y, w, h))) - return __FAIL; - set_alpha(pixels, (unsigned short*)m->v, w*h); - img->storage_class = DirectClass; - if (SyncImagePixels(img)) - return mkvoid; - else - return __FAIL; - } else - return __FAIL; - } - --- 560,561 ---- Index: magick.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/magick.q,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** magick.q 16 Dec 2003 19:11:16 -0000 1.1 --- magick.q 23 Dec 2003 01:15:02 -0000 1.2 *************** *** 64,73 **** public extern magick_pixel COLOR; - /* The magick_alpha function packs a single alpha value in the range 0..0xffff - or a list of such values into a byte string, suitable as the DATA argument - of set_image_alpha (see below). */ - - public extern magick_alpha ALPHA; - /* 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, --- 64,67 ---- *************** *** 129,138 **** public extern get_image_pixels IMG P DIM; public extern set_image_pixels IMG P DIM DATA; - - /* Get and set the alpha channel of an image. The data is encoded as a byte - string of 16 bit alpha values. These functions can be used to transfer the - alpha plane of an image to the alpha buffer of a GGI visual and vice - versa. */ - - public extern get_image_alpha IMG P DIM; - public extern set_image_alpha IMG P DIM DATA; --- 123,124 ---- |
From: <ag...@us...> - 2003-12-23 01:15:06
|
Update of /cvsroot/q-lang/q/modules/ggi/examples In directory sc8-pr-cvs1:/tmp/cvs-serv23691/modules/ggi/examples Modified Files: bufdemo.q ggi_demo.q Added Files: flying_ggis.q Log Message: major overhaul of GGI interface; see ChangeLog for details --- NEW FILE: flying_ggis.q --- /* $Id: flying_ggis.q,v 1.1 2003/12/23 01:15:02 agraef Exp $ */ /* flying_ggis.q: Another variation of the "Flying GGIs" theme. This one uses a custom font to render the text and an alpha buffer to make it translucent. (Requires FreeType and the GGI buffer extension.) */ /* Say `demo' to run. */ import ggi; // config section def // name of font file; edit this as needed FONT = "/usr/X11R6/lib/X11/fonts/truetype/times.ttf", // for some font types you also have to set a font metric file here FONT_METRIC = (), // face index (0 will do for most purposes) INDEX = 0; // globals def WD = 640, HT = 480, BD = 10, SZ = 50, RES = 72, PROB = 0.1, MAXN = 5, MAXS = min WD HT/SZ, MINV = 5, MAXV = 15; // color palette def COL = map color (nums 0 255), BLACK = hd COL, WHITE = last COL; color I = (shr I 5 and 7 * 0xffff div 7, shr I 2 and 7 * 0xffff div 7, I and 3 * 0xffff div 3); // initialize the display def VIS = ggi_open (), _ = ggi_set_mode VIS (sprintf "%dx%d" (WD,HT)) || ggi_set_flags VIS GGI_FLAG_ASYNC, // use a memory visual to reduce flickering MEM = ggi_open "memory", _ = ggi_set_mode MEM (sprintf "%dx%d.[C24/32].A16" (WD,HT)) || ggi_set_font MEM FONT INDEX || ggi_set_font_metric MEM FONT_METRIC || size SZ || fg BLACK 0xffff || bg WHITE 0 || clr; // adapt the maximum stretch according to the font def (W,H) = ggi_get_string_size MEM "GGI", MAXS = min (WD/W) (HT/SZ); // image descriptor: P = position, S = stretch, V = velocity (%), C = color type Image = image P S V C; // update the image list update IMGS = new (filter valid (map update1 IMGS)); update1 (image P S V C) = image P (S+V/100) V C; valid (image P S V C) = S<=MAXS; new IMGS = append IMGS (image (X,Y) 1.0 V C) where X = rand BD (WD-BD), Y = rand BD (HT-BD), V = rand MINV MAXV, C = COL!rand 0 254 if null IMGS or else (#IMGS < MAXN) and then (random/0xffffffff <= PROB); = IMGS otherwise; rand MIN MAX = MIN + random mod (MAX-MIN+1); // draw the image list draw IMGS = clr || do draw1 IMGS || show; draw1 (image P S V C) = fg C (round (0xffff/alpha S)) || size (round (S*SZ)) || center P "GGI"; alpha S = 1+(S-1)/(MAXS-1); // display operations fg C A = ggi_set_foreground MEM (append C A); bg C A = ggi_set_background MEM (append C A); clr = ggi_clear MEM; show = ggi_cross_blit MEM (0,0) (WD,HT) VIS (0,0) || ggi_flush VIS; size SZ = ggi_set_char_size MEM SZ RES; center (X,Y) S = ggi_puts MEM P S where (W,H) = ggi_get_string_size MEM S, P = (X - W div 2, Y - H div 2); // main loop loop IMGS = ggi_getc VIS || () if ggi_kbhit VIS; = draw IMGS || sleep 0.05 || loop (update IMGS) otherwise; demo = writes "Hit any key in the GGI window to stop\n" || loop []; Index: bufdemo.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/ggi/examples/bufdemo.q,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** bufdemo.q 15 Dec 2003 12:09:11 -0000 1.1 --- bufdemo.q 23 Dec 2003 01:15:02 -0000 1.2 *************** *** 1,7 **** ! /* bufdemo.q: Little alpha buffer demo, draws random rectangles with ! transparency until the user hits a key. 12-14-03, AG. Say `bufdemo' to ! run. NOTE: This script only works if you have the GGI buffer extension ! installed. */ import ggi; --- 1,8 ---- ! /* $Id$ ! ! bufdemo.q: Little alpha buffer demo, draws random boxes or lines with ! transparency until the user hits a key. Say `box_demo' or `line_demo' to ! run. */ import ggi; *************** *** 20,51 **** def COL = map color (nums 0 255), BLACK = hd COL, WHITE = last COL; ! color I = ggi_pixel (shr I 5 and 7 * 0xffff div 7, ! shr I 2 and 7 * 0xffff div 7, ! I and 3 * 0xffff div 3); ! /* Draw a rectangle with the given color and transparency. */ ! draw P DIM C A = ggi_set_foreground VIS C || ! ggi_set_alpha_foreground VIS A || ggi_draw_box VIS P DIM; ! /* Draw a random rectangle with random color and alpha. */ ! draw_rand = draw (X,Y) (W,H) C A where X = rand 10 (W-100), Y = rand 10 (H-100), W = rand 30 (min (W div 2) (W-X-10)), H = rand 30 (min (H div 2) (H-Y-10)), ! C = COL!rand 1 255, A = rand 1 0xffff; rand MIN MAX = MIN + random mod (MAX-MIN+1); ! /* The main function: Draw random rectangles until the user hits a key. */ ! bufdemo = show_msg || loop || hide_msg; ! loop = ggi_getc VIS || () if ggi_kbhit VIS; ! = draw_rand || loop otherwise; def MSG = "Running, hit a key to stop"; --- 21,74 ---- def COL = map color (nums 0 255), BLACK = hd COL, WHITE = last COL; ! color I = (shr I 5 and 7 * 0xffff div 7, ! shr I 2 and 7 * 0xffff div 7, ! I and 3 * 0xffff div 3); ! /* Draw a box with the given color and transparency. */ ! draw_box P DIM C ! = ggi_set_foreground VIS C || ggi_draw_box VIS P DIM; ! /* Draw a random box with random color and alpha. */ ! draw_rand_box = draw_box (X,Y) (W,H) (R,G,B,A) where X = rand 10 (W-100), Y = rand 10 (H-100), W = rand 30 (min (W div 2) (W-X-10)), H = rand 30 (min (H div 2) (H-Y-10)), ! (R,G,B) = COL!rand 1 255, ! A = rand 1 0xffff; ! ! /* Draw a line with the given color and transparency. */ ! ! draw_line P Q C = ggi_set_foreground VIS C || ! ggi_draw_line VIS P Q; ! ! /* Draw a random line with random color and alpha. */ ! ! draw_rand_line = draw_line (X1,Y1) (X2,Y2) (R,G,B,A) ! where X1 = rand 10 (W-10), ! Y1 = rand 10 (H-10), ! X2 = rand 10 (W-10), ! Y2 = rand 10 (H-10), ! (R,G,B) = COL!rand 1 255, A = rand 1 0xffff; rand MIN MAX = MIN + random mod (MAX-MIN+1); ! /* Draw random boxes until the user hits a key. */ ! box_demo = show_msg || box_loop || hide_msg; ! box_loop = ggi_getc VIS || () if ggi_kbhit VIS; ! = draw_rand_box || box_loop otherwise; ! ! /* Draw random lines until the user hits a key. */ ! ! line_demo = show_msg || line_loop || hide_msg; ! ! line_loop = ggi_getc VIS || () if ggi_kbhit VIS; ! = draw_rand_line || line_loop otherwise; def MSG = "Running, hit a key to stop"; *************** *** 54,60 **** ggi_set_foreground VIS WHITE || ggi_puts VIS (0,H-D) MSG ! where (_,D) = ggi_get_char_size VIS; hide_msg = ggi_set_foreground VIS BLACK || ggi_puts VIS (0,H-D) MSG ! where (_,D) = ggi_get_char_size VIS; --- 77,83 ---- ggi_set_foreground VIS WHITE || ggi_puts VIS (0,H-D) MSG ! where (_,D) = ggi_get_string_size VIS MSG; hide_msg = ggi_set_foreground VIS BLACK || ggi_puts VIS (0,H-D) MSG ! where (_,D) = ggi_get_string_size VIS MSG; Index: ggi_demo.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/ggi/examples/ggi_demo.q,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ggi_demo.q 21 Dec 2003 11:05:29 -0000 1.3 --- ggi_demo.q 23 Dec 2003 01:15:02 -0000 1.4 *************** *** 1,5 **** /* ggi_demo.q: little demo of the ggi module, featuring a variation of the ! flying_ggis demo in the libggi distribution, 09-23-03, AG. */ /* Have CPU cycles to burn? ;-) Say `demo' to run. */ --- 1,6 ---- /* ggi_demo.q: little demo of the ggi module, featuring a variation of the ! flying_ggis demo in the libggi distribution. ! $Id$ */ /* Have CPU cycles to burn? ;-) Say `demo' to run. */ |
From: <ag...@us...> - 2003-12-23 01:15:06
|
Update of /cvsroot/q-lang/q In directory sc8-pr-cvs1:/tmp/cvs-serv23691 Modified Files: ChangeLog config.h.in configure.in Log Message: major overhaul of GGI interface; see ChangeLog for details Index: ChangeLog =================================================================== RCS file: /cvsroot/q-lang/q/ChangeLog,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ChangeLog 20 Dec 2003 22:17:50 -0000 1.6 --- ChangeLog 23 Dec 2003 01:15:01 -0000 1.7 *************** *** 1,2 **** --- 1,30 ---- + 2003-12-22 Albert Graef <Dr....@t-...> + + * ggi: yet another major overhaul of the ggi module + + Support for the GGI buffer extension has been dropped for now, as + the current libggibuf from cvs really isn't ready for prime time + yet. Support for simple alpha blending is now provided through our + own code, but no z buffers yet. The API has been simplified + accordingly, and has been dubbed "stable" now. + + Note that there a few incompatibilities between the new API and + the one from the Q 4.5 release, namely that ggi_fill_screen has + been replaced by ggi_clear (which now fills the screen with the + background instead of the foreground color), and that + ggi_get_char_size has been replaced by the more general + ggi_get_string_size (which takes a string to be measured as the + second argument, and also works for FreeType-managed fonts). + + TODO: 1. Optimizations. 2. Alpha blending for text rendered in the + builtin font -- probably not worth the effort, so please don't ask + for it. ;-) + + 2003-12-21 Albert Graef <Dr....@t-...> + + * ggi_demo.q: replaced ggi_get_char_size with ggi_get_string_size + + * ggi.c: more bug fixes in text renderer + 2003-12-20 Albert Graef <Dr....@t-...> Index: config.h.in =================================================================== RCS file: /cvsroot/q-lang/q/config.h.in,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** config.h.in 19 Dec 2003 21:31:34 -0000 1.3 --- config.h.in 23 Dec 2003 01:15:01 -0000 1.4 *************** *** 210,216 **** #undef HAVE_GETUID - /* Define if you have the `ggiBufInit' function. */ - #undef HAVE_GGIBUFINIT - /* Define if you have the `grantpt' function. */ #undef HAVE_GRANTPT --- 210,213 ---- Index: configure.in =================================================================== RCS file: /cvsroot/q-lang/q/configure.in,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** configure.in 19 Dec 2003 21:31:34 -0000 1.4 --- configure.in 23 Dec 2003 01:15:01 -0000 1.5 *************** *** 233,257 **** AC_SUBST(GGI_MODULE) - GGI_LIBBUF="yes" - AC_ARG_WITH(ggibuf, - [ --with-ggibuf[[=LIBS]] use the GGI buffer extension (alpha/z buffer support)], - [case "${withval}" in - no) GGI_LIBBUF="" ;; - *) GGI_LIBBUF="${withval}" ;; - esac]) - if test "${GGI_LIBS}" = ""; then - GGI_LIBBUF="" - fi - if test "${GGI_LIBBUF}" = "yes"; then - GGI_LIBBUF="" - AC_CHECK_LIB(ggibuf, ggiBufInit, [ GGI_LIBBUF="-lggibuf -lggigalloc" ]) - if test "${GGI_LIBBUF}" = ""; then - AC_MSG_WARN([could not find the GGI buffer extension, building without buffer support]) - else - AC_MSG_RESULT([defining GGI_LIBBUF to be ${GGI_LIBBUF}]) - fi - fi - AC_SUBST(GGI_LIBBUF) - GGI_INCLUDES="" AC_ARG_WITH(ggi-includes, --- 233,236 ---- *************** *** 585,592 **** AC_CHECK_FUNCS(pthread_atfork) LIBS=$OLDLIBS - dnl ggi buffer support - LIBS="$LIBS ${GGI_LIBBUF}" - AC_CHECK_FUNCS(ggiBufInit) - LIBS=$OLDLIBS dnl freetype2 support LIBS="$LIBS ${FT2_LIBS}" --- 564,567 ---- *************** *** 701,705 **** fi if test "${GGI_LIBS}" != ""; then ! AC_MSG_RESULT([ GGI: libraries: ${GGI_LIBS} ${GGI_LIBBUF}]) AC_MSG_RESULT([ includes : ${GGI_INCLUDES}]) else --- 676,680 ---- fi if test "${GGI_LIBS}" != ""; then ! AC_MSG_RESULT([ GGI: libraries: ${GGI_LIBS}]) AC_MSG_RESULT([ includes : ${GGI_INCLUDES}]) else |
From: <ag...@us...> - 2003-12-23 01:15:06
|
Update of /cvsroot/q-lang/q/modules/magick/examples In directory sc8-pr-cvs1:/tmp/cvs-serv23691/modules/magick/examples Modified Files: magicktest.q sprite.q Log Message: major overhaul of GGI interface; see ChangeLog for details Index: magicktest.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/examples/magicktest.q,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** magicktest.q 16 Dec 2003 19:11:16 -0000 1.1 --- magicktest.q 23 Dec 2003 01:15:02 -0000 1.2 *************** *** 1,10 **** import ggi, magick; ! /* show NAME INFO: show an image (designated by a valid ImageMagick source ! specification NAME and an INFO structure, see magick.q for details) in a ! GGI visual. Returns the created visual. */ ! show NAME INFO = display IMG where IMG:Image = read_image NAME INFO; /* The simple case: our image is opaque. In this case we just render it on a --- 1,16 ---- + /* $Id$ + magicktest.q: simple magick demonstration program, shows how to render an + image on a GGI visual */ + import ggi, magick; ! /* show NAME INFO: show an image in a GGI visual. Returns the created visual. ! For most purposes, NAME is just the name of an image file, and INFO is ! (). However, using appropriate NAME and INFO values, you can actually do a ! lot more than just displaying an image file, see magick.q and ! ImageMagick(1) for details. */ ! show NAME INFO = display IMG where IMG:Image = read_image NAME INFO; /* The simple case: our image is opaque. In this case we just render it on a *************** *** 16,20 **** where (W,H|_) = image_info IMG, ! VIS = ggi_open "x:-keepcursor", () = ggi_set_mode VIS (sprintf "%dx%d" (W,H)), PIXELS = get_image_pixels IMG (0,0) (W,H) --- 22,26 ---- where (W,H|_) = image_info IMG, ! VIS = ggi_open (sprintf "%s:-keepcursor" target), () = ggi_set_mode VIS (sprintf "%dx%d" (W,H)), PIXELS = get_image_pixels IMG (0,0) (W,H) *************** *** 22,28 **** if is_opaque_image IMG; ! /* The complicated case: our image has transparency. In this case we draw the ! image over a background. To these ends, we first render the image on a ! memory visual and crossblit that to the target visual on the screen. */ def BACK = magick_pixel "gray"; --- 28,33 ---- if is_opaque_image IMG; ! /* The complicated case: our image has transparency. In this case we clad the ! visual with an alpha buffer and draw the image over a background. */ def BACK = magick_pixel "gray"; *************** *** 30,52 **** display IMG ! = ggi_put_box MEM (0,0) (W,H) PIXELS || ! /* we need to also set the alpha values since these aren't transferred ! by ggi_put_box */ ! ggi_put_alpha_box MEM (0,0) (W,H) ALPHA || ! ggi_set_background VIS BACK || ggi_clear VIS || ! ggi_cross_blit MEM (0,0) (W,H) VIS (0,0) || ggi_flush VIS || ! VIS where (W,H|_) = image_info IMG, ! VIS = ggi_open "x:-keepcursor", ! () = ggi_set_mode VIS (sprintf "%dx%d.A8" (W,H)), ! () = ggi_set_alpha_flags VIS (ggi_get_alpha_flags VIS or GGI_BUF_PUTGET), ! (_,_,_,_,_,_,_,_,D,S) = ! sscanf (ggi_get_mode VIS) "%dx%d.V%dx%d.F%d.D%dx%d.[%c%d/%d]", ! MEM = ggi_open "memory", ! () = ggi_set_mode MEM (sprintf "%dx%d.[C%d/%d].A8" (W,H,D,S)), ! () = ggi_set_alpha_flags MEM (ggi_get_alpha_flags MEM or GGI_BUF_PUTGET), ! PIXELS = get_image_pixels IMG (0,0) (W,H), ! ALPHA = get_image_alpha IMG (0,0) (W,H) otherwise; --- 35,50 ---- display IMG ! = ggi_set_background VIS BACK || ggi_clear VIS || ! ggi_put_box VIS (0,0) (W,H) PIXELS || ggi_flush VIS || VIS where (W,H|_) = image_info IMG, ! VIS = ggi_open (sprintf "%s:-keepcursor" target), ! () = ggi_set_mode VIS (sprintf "%dx%d.A16" (W,H)), ! PIXELS = get_image_pixels IMG (0,0) (W,H) otherwise; + + /* Driver for display visual. */ + + target = "directx" if pos "mingw" sysinfo >= 0; + = "x" otherwise; Index: sprite.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/magick/examples/sprite.q,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** sprite.q 16 Dec 2003 19:11:16 -0000 1.1 --- sprite.q 23 Dec 2003 01:15:02 -0000 1.2 *************** *** 1,5 **** ! /* sprite.q: This is a tiny test program demonstrating how to move an image ! with transparency over a background image. 12-12-03 AG */ /* To use, evaluate `sprite', click left in the GGI window to show the sprite --- 1,6 ---- ! /* $Id$ ! sprite.q: This is a tiny test program demonstrating how to move an image ! with transparency over a background image. */ /* To use, evaluate `sprite', click left in the GGI window to show the sprite *************** *** 10,14 **** import ggi, magick; ! /* globals */ def --- 11,15 ---- import ggi, magick; ! /* Globals, infrastructure code. */ def *************** *** 19,24 **** GGI display visual */ (W,H|_) = image_info BACK_IMG, ! VIS = ggi_open "x:-keepcursor", _ = ggi_set_mode VIS (sprintf "%dx%d.A8" (W,H)) || ggi_set_flags VIS GGI_FLAG_ASYNC || ggi_put_box VIS (0,0) (W,H) (get_image_pixels BACK_IMG (0,0) (W,H)) || --- 20,26 ---- GGI display visual */ (W,H|_) = image_info BACK_IMG, ! VIS = ggi_open (sprintf "%s:-keepcursor" target), _ = ggi_set_mode VIS (sprintf "%dx%d.A8" (W,H)) || + /* make sure to set async mode here to reduce flickering */ ggi_set_flags VIS GGI_FLAG_ASYNC || ggi_put_box VIS (0,0) (W,H) (get_image_pixels BACK_IMG (0,0) (W,H)) || *************** *** 35,63 **** only have to store the pixels of the background image) */ _ = ggi_set_mode BACK (sprintf "%dx%d.[C%d/%d]" (W,H,D,S)), ! /* render the sprite image in another memory visual with alpha buffer, which ! will be crossblitted to the display */ ! SPRITE = ggi_open "memory", ! _ = ggi_set_mode SPRITE (sprintf "%dx%d.[C%d/%d].A8" (W,H,D,S)) || ! /* make sure GGI_BUF_PUTGET is set to enable full alpha blending */ ! ggi_set_alpha_flags SPRITE (ggi_get_alpha_flags SPRITE or GGI_BUF_PUTGET) || ! ggi_put_box SPRITE (0,0) (W,H) (get_image_pixels SPRITE_IMG (0,0) (W,H)) || ! ggi_put_alpha_box SPRITE (0,0) (W,H) ! (get_image_alpha SPRITE_IMG (0,0) (W,H)); ! /* save background pixels in the BACK visual */ save_back (X,Y) = ggi_put_box BACK (0,0) (W,H) (ggi_get_box VIS (X,Y) (W,H)); ! /* restore background from the BACK visual */ restore_back (X,Y) = ggi_put_box VIS (X,Y) (W,H) (ggi_get_box BACK (0,0) (W,H)); ! /* draw the sprite (crossblit from SPRITE visual) */ ! draw_sprite (X,Y) = ggi_cross_blit SPRITE (0,0) (W,H) VIS (X,Y); ! /* show, hide and move the sprite on the display */ show_sprite (X,Y) = save_back (X,Y) || --- 37,64 ---- only have to store the pixels of the background image) */ _ = ggi_set_mode BACK (sprintf "%dx%d.[C%d/%d]" (W,H,D,S)), ! /* get the pixels of the sprite image */ ! SPRITE = get_image_pixels SPRITE_IMG (0,0) (W,H); ! /* Driver for the display visual. We use the DirectX target on Windows, and ! assume the X11 target everywhere else. */ ! ! target = "directx" if pos "mingw" sysinfo >= 0; ! = "x" otherwise; ! ! /* Save background pixels in the BACK visual. */ save_back (X,Y) = ggi_put_box BACK (0,0) (W,H) (ggi_get_box VIS (X,Y) (W,H)); ! /* Restore background from the BACK visual. */ restore_back (X,Y) = ggi_put_box VIS (X,Y) (W,H) (ggi_get_box BACK (0,0) (W,H)); ! /* Draw the sprite. */ ! draw_sprite (X,Y) = ggi_put_box VIS (X,Y) (W,H) SPRITE; ! /* Show, hide and move the sprite on the display. */ show_sprite (X,Y) = save_back (X,Y) || *************** *** 73,81 **** ggi_flush VIS; ! /* the main function */ sprite = loop () (); ! /* the input loop; take appropriate actions on mouse events */ loop STATE POS = process STATE POS (ggi_read VIS GGI_EM_ALL); --- 74,82 ---- ggi_flush VIS; ! /* The main function. */ sprite = loop () (); ! /* The input loop; take appropriate actions on mouse events. */ loop STATE POS = process STATE POS (ggi_read VIS GGI_EM_ALL); |
From: <ag...@us...> - 2003-12-21 12:53:29
|
Update of /cvsroot/q-lang/q/modules/ggi In directory sc8-pr-cvs1:/tmp/cvs-serv15257 Modified Files: ggi.c Log Message: more bug fixes in text renderer Index: ggi.c =================================================================== RCS file: /cvsroot/q-lang/q/modules/ggi/ggi.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ggi.c 21 Dec 2003 10:54:35 -0000 1.13 --- ggi.c 21 Dec 2003 12:53:26 -0000 1.14 *************** *** 1410,1414 **** FT_BBox bbox; /* bounding box */ ggi_color fgcol, bgcol, *col = NULL; ! ggi_pixel pix, *pixel = NULL; unsigned fgalpha = 0xff, bgalpha = 0xff; --- 1410,1414 ---- FT_BBox bbox; /* bounding box */ ggi_color fgcol, bgcol, *col = NULL; ! ggi_pixel pix; unsigned fgalpha = 0xff, bgalpha = 0xff; *************** *** 1562,1566 **** /* blit the rendered string to the visual */ ! if (!error) { #ifdef HAVE_GGIBUF if (v->b[0]) { --- 1562,1566 ---- /* blit the rendered string to the visual */ ! if (!error) #ifdef HAVE_GGIBUF if (v->b[0]) { *************** *** 1578,1583 **** } ggiBufSetGCForeground(v->b[0], val); ! } else { #endif if (!(pixel = malloc(pack_size(v->vis, dim)))) { free(col); --- 1578,1585 ---- } ggiBufSetGCForeground(v->b[0], val); ! } else #endif + { + void *pixel = NULL; if (!(pixel = malloc(pack_size(v->vis, dim)))) { free(col); *************** *** 1586,1593 **** error = ggiPackColors(v->vis, pixel, col, dim) || ggiPutBox(v->vis, x, y, wd, ht, pixel); } - } free(col); - free(pixel); return !error; --- 1588,1594 ---- error = ggiPackColors(v->vis, pixel, col, dim) || ggiPutBox(v->vis, x, y, wd, ht, pixel); + free(pixel); } free(col); return !error; |
From: <ag...@us...> - 2003-12-21 11:05:38
|
Update of /cvsroot/q-lang/q/modules/ggi/examples In directory sc8-pr-cvs1:/tmp/cvs-serv1606 Modified Files: ggi_demo.q Log Message: replaced ggi_get_char_size with ggi_get_string_size in demo Index: ggi_demo.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/ggi/examples/ggi_demo.q,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ggi_demo.q 15 Dec 2003 12:07:14 -0000 1.2 --- ggi_demo.q 21 Dec 2003 11:05:29 -0000 1.3 *************** *** 138,146 **** ggi_set_foreground VIS WHITE || ggi_puts VIS (0,HEIGHT-H) MSG ! where (_,H) = ggi_get_char_size VIS; hide_msg = ggi_set_foreground VIS BLACK || ggi_puts VIS (0,HEIGHT-H) MSG ! where (_,H) = ggi_get_char_size VIS; /* The main function. */ --- 138,146 ---- ggi_set_foreground VIS WHITE || ggi_puts VIS (0,HEIGHT-H) MSG ! where (_,H) = ggi_get_string_size VIS MSG; hide_msg = ggi_set_foreground VIS BLACK || ggi_puts VIS (0,HEIGHT-H) MSG ! where (_,H) = ggi_get_string_size VIS MSG; /* The main function. */ |