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
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;

Attachment: msg01524/pgp00000.pgp
Description: PGP signature

Reply via email to