Re: Bitmap rotation

Olivier Bornet <[email protected]>
Newsgroups gmane.comp.video.picogui.devel
Message-ID <[email protected]>
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);

Unfortunately, if w != h, this don't work. For having this working, we
need to patch gcore/render.c with the attached patch. Mainly, it get the
bitmap width and height always correctly, and not swap them if we rotate
of 90 or 270. I think the patch is OK, because we don't need to have the
rotate values, but the original values.

If this is OK, I will apply the patch. If not, it may be because I don't
use the pgWriteCmd correctly for rotate the bitmap, so, if anyone has a
tip...

Good day.

		Olivier

PS. Here are the values to change for other angles:

    switch (angle) {
    case 0:
      pgWriteCmd (canvas,
                  PGCANVAS_GROP, 6,
                  PG_GROP_ROTATEBITMAP, 0, 0, w, h, image);
      break;
    case 90:
      pgWriteCmd (canvas,
                  PGCANVAS_GROP, 6,
                  PG_GROP_ROTATEBITMAP, 0, w, h, w, image);
      break;
    case 180:
      pgWriteCmd (canvas,
                  PGCANVAS_GROP, 6,
                  PG_GROP_ROTATEBITMAP, w, h, w, h, image);
      break;
    case 270:
      pgWriteCmd (canvas,
                  PGCANVAS_GROP, 6,
                  PG_GROP_ROTATEBITMAP, h, 0, h, w, image);
      break;
    default:
    }
-- 
Olivier Bornet                      http://www.smartdata.ch/
[email protected]         SMARTDATA SA
Phone: +41-27-723'55'03             Rue du Collège 5A
GPG key ID: C53D9218                CH-1920 Martigny
patch_render_bitmap_rotation.txt (text/plain, 649 B)
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;
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (GNU/Linux)

iD8DBQE+JVz9dj3R/MU9khgRAncNAKCqwH9IXNts/394yADy3qPMz2AnGACgpgzE
/uvmBdoO94dN3KwecLeXY0U=
=rYs4
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.