On Wed, Jan 15, 2003 at 02:07:09PM +0100, Olivier Bornet wrote:
> Hello,
>
> > In our app, we want to turn an image from 90 or 270 degres.
> > To achieve this we thought about displaying the bitmap in a canvas and
> > using the PG_GROP_ROTATEBITMAP parameter with something like :
>
> After some tests, I have found the solution. This require 3 calls to
> pgWriteCmd (). Here are they for a rotation of 90, assuming h and w are
> height and width of the original image:
>
> pgWriteCmd (canvas,
> PGCANVAS_GROP, 2,
> PG_GROP_SETANGLE, 90);
>
> pgWriteCmd (canvas,
> PGCANVAS_GROP, 5,
> PG_GROP_SETSRC, 0, 0, w, h);
>
> pgWriteCmd (canvas,
> PGCANVAS_GROP, 6,
> PG_GROP_ROTATEBITMAP, 0, w, h, w, image);
The source rectangle is always in unrotated coordinates, on the source bitmap.
The destination rectangle for the rotatebitmap gropnode has the unrotated top-left
as its top-left coordinate, and the unrotated width and height.
So, if with all other parameters the same you change the rotation angle, the
bitmap will appear to rotate around it's original top-left corner. This was done
so the primitive could unambiguously handle non-multiple-of-90 angles for devices
that support them.
In your example of rotating 90 degrees, the rotatebitmap line should look like:
pgWriteCmd (canvas,
PGCANVAS_GROP, 6,
PG_GROP_ROTATEBITMAP, 0, w-1, w, h, image);
If you want to project the rotated bitmap into a rectangle with the rotated
top-left at a particular point, you'll have to place the unrotated top-left
coordinate at a different corner of that rectangle depending on the rotation.
There's a good example of this in action in the pgserver code for rotating
bitmaps when entering and leaving a rotated mode. The syntax is different
since it doesn't go through the gropnode layer, but semantically it's
the same. On line 518 of video/video_drivers.c, the bitmap_rotate function
does exactly this to copy a bitmap while rotating it.
> Index: render.c
> ===================================================================
> RCS file: /cvsroot/pgui/pgserver/gcore/render.c,v
> retrieving revision 1.48
> diff -u -r1.48 render.c
> --- render.c 1 Jan 2003 03:42:59 -0000 1.48
> +++ render.c 15 Jan 2003 13:00:22 -0000
> @@ -879,10 +879,7 @@
> case PG_GROP_ROTATEBITMAP:
> if (iserror(rdhandle((void**)&bit,PG_TYPE_BITMAP,-1,
> n->param[0])) || !bit) break;
> - if (r->angle == 90 || r->angle==270)
> - VID(bitmap_getsize) (bit,&bh,&bw);
> - else
> - VID(bitmap_getsize) (bit,&bw,&bh);
> + VID(bitmap_getsize) (bit,&bw,&bh);
>
> /* Source rect clipping */
> clipsrc = r->src;
This code is a kludge, but it should have the right effect. The clipping rectangle
is always in the unrotated (logical screen) coordinates. The bitmap's size is rotated
relative to that by the inverse of the rotation angle. This patch should -not- be
applied.
Hope this fixes your problem,
--Micah
--
Only you can prevent creeping featurism!
-------------------------------------------------------
This SF.NET email is sponsored by: Thawte.com
Understand how to protect your customers personal information by implementing
SSL on your Apache Web Server. Click here to get our FREE Thawte Apache
Guide: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0029en
_______________________________________________
Pgui-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/pgui-devel