Re: [Pgui-devel] Bitmap rotation
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 - 1.48 > +++ render.c 15 Jan 2003 13:00:22 - > @@ -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
Re: [Pgui-devel] Bitmap rotation
Assuming this is the only problem, it's a bug- the bitmaps and canvas widget should render the same. If you have an example case demonstrating the bug, send it. Otherwise I'll take a look at this soon. On Wed, Jan 15, 2003 at 02:51:25PM +0100, Olivier Bornet wrote: > Hello again, > > another question is : can we use a bitmap instead of a canvas. This > mean, instead of: > > > pgWriteCmd (canvas, > > PGCANVAS_GROP, 6, > > PG_GROP_ROTATEBITMAP, 0, w, h, w, image); > > can I use: > pgRender (bitmap, > PGCANVAS_GROP, 6, > PG_GROP_ROTATEBITMAP, 0, w, h, w, image); > > assuming bitmap was created correctly before (with pgCreateBitmap). I > have try this without success (just a little time tough). I can do other > pgRender things, like PG_GROP_RECT or PG_GROP_LINE, but the use of > PG_GROP_ROTATEBITMAP or PG_GROP_BITMAP do nothing. > > Thanks in advance. > > Olivier > -- > Olivier Bornet http://www.smartdata.ch/ > [EMAIL PROTECTED] SMARTDATA SA > Phone: +41-27-723'55'03 Rue du Coll?ge 5A > GPG key ID: C53D9218CH-1920 Martigny -- 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
Re: [Pgui-devel] Bitmap rotation
Hi Micah, > 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. Thanks. I have get this portion of code, and adapted to use on gropnode with pgWriteCmd (). You say: > 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. and my patch was: > > diff -u -r1.48 render.c > > --- render.c1 Jan 2003 03:42:59 - 1.48 > > +++ render.c15 Jan 2003 13:00:22 - > > @@ -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; So, my patch seem OK for me. ;-) Because the bw and bh is the coordinates of the _source_ rectangle. And it is unrotated. If you compare the following rotating action: VID(rotateblit) (r->output,n->r.x,n->r.y, bit,clipsrc.x,clipsrc.y,clipsrc.w,clipsrc.h, &r->clip,r->angle,r->lgop); clipsrc is used on the _source_ rectangle. Here is a sample: we have a source bitmap of 100x50 pixels. You want to rotated it to 90. Without my patch, you will have: - bw = 50 - bh = 100 After that, you have the checks: if (clipsrc.x < 0) clipsrc.x = 0; if (clipsrc.y < 0) clipsrc.y = 0; if (clipsrc.w > (bw - clipsrc.x)) clipsrc.w = bw - clipsrc.x; if (clipsrc.h > (bh - clipsrc.y)) clipsrc.h = bh - clipsrc.y; This will result of : - clipsrc.x = 0 - clipsrc.x = 0 - clipsrc.w = 50 (because bw was set to 50) - clipsrc.h = 50 (because clipsrc.h is 50) So, the rotation is done correctly after that, but with only the first part of the source bitmap copyed (and an empty space just after it). Am I right ? Olivier -- Olivier Bornet http://www.smartdata.ch/ [EMAIL PROTECTED] SMARTDATA SA Phone: +41-27-723'55'03 Rue du Collège 5A GPG key ID: C53D9218CH-1920 Martigny msg01528/pgp0.pgp Description: PGP signature
Re: [Pgui-devel] bitmap rendering in bitmap (was: Bitmap rotation)
Hi again,
> Assuming this is the only problem, it's a bug- the bitmaps and canvas
> widget should render the same. If you have an example case demonstrating
> the bug, send it. Otherwise I'll take a look at this soon.
So, attached is a modified version of imgview, which do bitmap rotation
with either canvas or bitmap rendering. Uncomment the #define
__WITH_CANVAS__ at the top to test the canvas version.
The "bitmap" version also draw some lines in the bitmap, just to see it
is correctly displaying the bitmap. This is OK, but the image is not
displayed.
To use it, replace the imgview.c in your sources, compile it and use
like:
./imgview the_image.jpg 90
(or 0 or 180 or 270 as angle).
Of course, without my patch, only a part of the image is rotated and
visible on the screen with the canvas.
Thanks in advance for any help.
Olivier
--
Olivier Bornet http://www.smartdata.ch/
[EMAIL PROTECTED] SMARTDATA SA
Phone: +41-27-723'55'03 Rue du Collège 5A
GPG key ID: C53D9218CH-1920 Martigny
/*
* Modified version of imgview.c, for checking bitmap rendering
* problems. (and with rotation of image) -- Olivier Bornet
*
* Original comment:
*
* Simple image viewer, using a smidgen of custom themeing
*
* -- Micah Dowty <[EMAIL PROTECTED]>
*/
#include
#include
/* uncomment this if you want the CANVAS version */
/* commented result of the BITMAP version */
/* #define __WITH_CANVAS__ */
pghandle panel, bitmapwidget;
#ifdef __WITH_CANVAS__
pghandle canvaswidget;
#endif
void rotate_bitmap (pghandle bitmap, const int angle)
{
int w, h;
int rotated_w, rotated_h;
int rotated_x, rotated_y;
int clip_x1, clip_y1;
int clip_x2, clip_y2;
/* get the size of the given bitmap */
pgSizeBitmap (&w, &h, bitmap);
/* compute the needed x/y/w/h for the rotated bitmap */
switch (angle) {
case 90:
rotated_w = h;
rotated_h = w;
rotated_x = 0;
rotated_y = rotated_h-1;
break;
case 180:
rotated_w = w;
rotated_h = h;
rotated_x = rotated_w-1;
rotated_y = rotated_h-1;
break;
case 270:
rotated_w = h;
rotated_h = w;
rotated_x = rotated_w-1;
rotated_y = 0;
break;
case 0:
default:
rotated_w = w;
rotated_h = h;
rotated_x = 0;
rotated_y = 0;
break;
}
/* compute the clip of the source bitmap */
clip_x1 = 0;
clip_y1 = 0;
clip_x2 = rotated_w-1;
clip_y2 = rotated_h-1;
#ifdef __WITH_CANVAS__
/* set the clip of the original bitmap to get */
pgWriteCmd (canvaswidget,
PGCANVAS_GROP, 5,
PG_GROP_SETSRC,
0, 0, w-1, h-1);
/* set the wanted angle */
pgWriteCmd (canvaswidget,
PGCANVAS_GROP, 2,
PG_GROP_SETANGLE,
angle);
/* rotate the bitmap and render it */
pgWriteCmd (canvaswidget,
PGCANVAS_GROP, 6,
PG_GROP_ROTATEBITMAP,
rotated_x, rotated_y, rotated_w, rotated_h,
bitmap);
#else
{
pghandle dest_bitmap = pgCreateBitmap (rotated_w, rotated_h);
/* some things drawn in the destination bitmap, to see it's working OK */
pgRender (dest_bitmap, PG_GROP_SETCOLOR, 0xFF);
pgRender (dest_bitmap, PG_GROP_RECT, 0, 0, 100, 100);
pgRender (dest_bitmap, PG_GROP_SETCOLOR, 0x00);
pgRender (dest_bitmap, PG_GROP_LINE, 0, 0, 100, 100);
pgRender (dest_bitmap, PG_GROP_LINE, 100, 0, -100, 100);
/* set the clip of the original bitmap to get */
pgRender (dest_bitmap,
PGCANVAS_GROP, 5,
PG_GROP_SETSRC, 0, 0, w-1, h-1);
/* set the wanted angle */
pgRender (dest_bitmap,
PGCANVAS_GROP, 2,
PG_GROP_SETANGLE, angle);
/* rotate the bitmap and render it */
pgRender (dest_bitmap,
PGCANVAS_GROP, 6,
PG_GROP_ROTATEBITMAP,
rotated_x, rotated_y, rotated_w, rotated_h,
bitmap);
/* delete old image */
pgDelete (pgGetWidget (bitmapwidget, PG_WP_BITMAP));
/* set the image in the final widget */
pgSetWidget (bitmapwidget, PG_WP_BITMAP, dest_bitmap, 0);
}
#endif
}
void load_bitmap (const char *filename, const int angle) {
int w,h;
pghandle bitmap;
const char *name;
/* Find the actual name of the file */
name = strrchr(filename,'/');
if (name)
name++;
else
name = filename;
bitmap = pgNewBitmap(pgFromFile(filename));
rotate_bitmap (bitmap, angle);
}
int main(int argc, char **argv) {
pghandle titleLabel,box,toolbar;
/* usage check */
if (argc != 3) {
fprintf (stderr, "Usage: %s image angle\n", argv [0]);
return 1;
}
pgInit(argc,argv);
panel = pgRegisterApp(PG_APP_NORMAL,"Image Viewer",0);
pgSetWidget(PGDEFAULT,
PG_WP_THOBJ, pgFindThemeObject("imgview.panel"),
0);
box = pgNewWidget(PG_WIDGET_SCROLLBOX, 0, 0);
pgSetWidget(PGDEFAULT,
PG_WP_THOBJ, pgFindThemeObject("imgview.box"),
0);
bitmapwidget = pgNewWidget(PG_WIDGET_LABEL,PG_DERIVE_INSIDE,box);
pgSetWidget(PGDEFAULT,
Re: [Pgui-devel] Bitmap rotation
On Thu, Jan 16, 2003 at 12:42:27PM +0100, Olivier Bornet wrote: ... > > So, my patch seem OK for me. ;-) > Because the bw and bh is the coordinates of the _source_ rectangle. And > it is unrotated. If you compare the following rotating action: > > VID(rotateblit) (r->output,n->r.x,n->r.y, > bit,clipsrc.x,clipsrc.y,clipsrc.w,clipsrc.h, > &r->clip,r->angle,r->lgop); > > clipsrc is used on the _source_ rectangle. Here is a sample: we have a > source bitmap of 100x50 pixels. You want to rotated it to 90. Without my > patch, you will have: > - bw = 50 > - bh = 100 > After that, you have the checks: > if (clipsrc.x < 0) clipsrc.x = 0; > if (clipsrc.y < 0) clipsrc.y = 0; > if (clipsrc.w > (bw - clipsrc.x)) clipsrc.w = bw - clipsrc.x; > if (clipsrc.h > (bh - clipsrc.y)) clipsrc.h = bh - clipsrc.y; > This will result of : > - clipsrc.x = 0 > - clipsrc.x = 0 > - clipsrc.w = 50 (because bw was set to 50) > - clipsrc.h = 50 (because clipsrc.h is 50) > > So, the rotation is done correctly after that, but with only the first > part of the source bitmap copyed (and an empty space just after it). > > Am I right ? Ah, you're right! Sorry, I must have been too asleep last night to realize that was clipping the source rectangle, not the destination rectangle. > > Olivier > -- > Olivier Bornet http://www.smartdata.ch/ > [EMAIL PROTECTED] SMARTDATA SA > Phone: +41-27-723'55'03 Rue du Coll?ge 5A > GPG key ID: C53D9218CH-1920 Martigny -- 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
[Pgui-devel] Re: Pgui-devel digest, Vol 1 #515 - 2 msgs
Micah you wrote: Yeah, compile a new cli_c with sockets and recompile the apps. Done. Make sure you have a line like "input = r3912ts" in your [pgserver] section of /etc/pgserver.conf, and make sure you're running the calibrator. You can have pgserver run a calibrator when necessary by setting the 'tpcal' config variable to the command to use. pgserver.conf contains: [pgserver] input = r3912ts appmgr = panel "tpcal = cd /usr/bin; /usr/bin/tpcal" and calth.th is in /usr/bin When I run pgserver on the helio I get: # pgserver pgserver_init: operating system initpgserver_init: configuration filespgserver_init: command linepgserver_init: error message tablepgserver_init: input driverspgserver_init: input filterspgserver_init: videopgserver_init: fontspgserver_init: app managerpgserver_init: networkpgserver_init: globalsInit: globals: default font Init: globals: cursor sprite bitmaps Init: globals: cursor sprite Init: globals: strings Init: globals: success pgserver_init: timerspgserver_init: initial themestheme_lookup(0x,0x05E3) = (not found) theme_lookup(0x,0x05E4) = (not found) theme_lookup(0x,0x05E1) = (not found) theme_lookup(0x,0x05E2) = (not found) theme_lookup(0x,0x05E5) = (not found) theme_lookup(0x,0x05E6) = (not found) pgserver_init: touchscreen calibrationtheme_lookup(0x000D,0x0003) = (not found) theme_lookup(0x000D,0x0001) = (not found) pgserver_init: Initialization done If I put pgserver in the background and run tpcal from the command line, I get theme_lookup(0x0003,0x0009) = (not found) theme_lookup(0x0003,0x0005) = (not found) theme_lookup(0x0003,0x0014) = (not found) theme_lookup(0x0003,0x0015) = (not found) theme_lookup(0x0003,0x0018) = (not found) theme_lookup(0x0003,0x0019) = (not found) theme_lookup(0x0003,0x0007) = (not found) over and over and over. On the Helio, I get a PicoGUI Error saying "error of type CLIENT occurred in opening file in pgFromFile()" and asks me if I want to terminate the app. What do you suggest trying next? Mark _ Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963 --- 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
