Hello,
I am having a problem while displaying a bitmap on a rotated display.
The attached code "bitmap.c" illustrates the problem:
- a PPM file is created in memory
- a bitmap is created from it
- a second bitmap is created, and the first bitmap is pgBitmap'ped into it
- a canvas widget is created, and the second bitmap is pgBitmap'ped into it
If the display is in 0 or 180 degrees before the code is started, and
rotated to any degrees afterwards, the display is correct. If the screen
is, however, in 90 or 270 degrees rotation before the code is started,
there is an area on the right of the bitmap that is drawn all black.
[ The reason the code seems somewhat convoluted is because it recreates
a sequence of instructions that are done in Waba when an Image object is
created and displayed on a Graphics object. ]
Some more little tests seem to indicate that the problem appears only when
the image's width and height are different, and the width of the blacked
area is (width - height).
I suspect there might be some little bug in the rotation code somewhere?
I am also attaching "rotate.c", the code I am using to test rotations.
Thank you very much for any help!
-Christian
--
Christian Grigis | SMARTDATA SA
Software Engineer | PSE-A / EPFL
Phone: +41-(21)-693-84-98 | CH - 1015 Lausanne
mailto:[EMAIL PROTECTED] | http://www.smartdata.ch
#include <stdio.h>
#include <picogui.h>
#define WIDTH 200
#define HEIGHT 150
int main (int argc, char * argv [])
{
pghandle bitmap, canvas, image_bitmap;
pgcontext canvas_context, image_context;
unsigned char * bitmap_data, * pos;
int i, j, size;
pgInit (argc, argv);
pgRegisterApp (PG_APP_NORMAL, "Bitmap Test", 0);
/* Create a binary PPM file in memory */
size = (WIDTH * HEIGHT * 3 + 20) * sizeof (unsigned char);
bitmap_data = (unsigned char *) malloc (size);
pos = bitmap_data + sprintf (bitmap_data, "P6 %d %d 255\n", WIDTH, HEIGHT);
for (i = 0; i < HEIGHT; i++)
{
for (j = 0; j < WIDTH; j++)
{
int val = (i * j) % 256;
*(pos++) = (unsigned char) val;
*(pos++) = (unsigned char) val;
*(pos++) = (unsigned char) val;
}
}
/* Create a bitmap from it */
bitmap = pgNewBitmap (pgFromTempMemory (bitmap_data, size));
/* Create another empty bitmap */
image_bitmap = pgCreateBitmap (WIDTH, HEIGHT);
/* Draw the first bitmap into it */
image_context = pgNewBitmapContext (image_bitmap);
pgBitmap (image_context, 0, 0, WIDTH, HEIGHT, bitmap);
/* Create a canvas widget */
canvas = pgNewWidget (PG_WIDGET_CANVAS, 0, 0);
pgSetWidget (PGDEFAULT,
PG_WP_SIDE, PG_S_TOP,
0);
/* Draw the second bitmap into it */
canvas_context = pgNewCanvasContext (canvas, PGFX_PERSISTENT);
pgBitmap (canvas_context, 0, 0, WIDTH, HEIGHT, image_bitmap);
pgEventLoop ();
}
#include <stdio.h>
#include <picogui.h>
int rotate_handler ()
{
static int current_rotation = 0;
int rotation_flag = -1;
switch (current_rotation)
{
case 0 :
rotation_flag = PG_VID_ROTATE90;
break;
case 1 :
rotation_flag = PG_VID_ROTATE180;
break;
case 2 :
rotation_flag = PG_VID_ROTATE270;
break;
case 3 :
break;
default :
printf ("Unknown current rotation: %d\n", current_rotation);
break;
}
pgSetVideoMode (PGDEFAULT, PGDEFAULT, PGDEFAULT, PG_FM_SET, PGDEFAULT);
if (rotation_flag >= 0)
{
pgSetVideoMode (PGDEFAULT, PGDEFAULT, PGDEFAULT, PG_FM_ON, rotation_flag);
}
current_rotation = (current_rotation + 1) % 4;
}
int main (int argc, char * argv [])
{
pghandle but;
pgInit (argc, argv);
pgRegisterApp (PG_APP_TOOLBAR, "Rotate test", 0);
but = pgNewWidget (PG_WIDGET_BUTTON, 0, 0);
pgSetWidget (PGDEFAULT,
PG_WP_TEXT, pgNewString ("Rotate"),
PG_WP_SIDE, PG_S_BOTTOM,
0);
pgBind (but, PGBIND_ANY, &rotate_handler, NULL);
pgEventLoop ();
}