hi,
I am new with gtk and hope to get help here.
My application is a simulation in ADA which is calling some image processing functions written in C.
Within the C-functions images shall be displayed and lines plotted on the images. I read several tutorials but cannot get it run.
There is an initialization, the simulation loop processing sequences of images and a finalization.
In the simulation loop the images shall be displayed.
Initialization:
Code:
#define WIN_SIZE 512
static GtkWidget *gtkPlotWindow;
int InitPlotWindow()
{
char* args[] = { "" };
int argc = 1;
char** argv = args;
gtk_init( &argc, &argv );
gtkPlotWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtk_widget_set_size_request( gtkPlotWindow, WIN_SIZE, WIN_SIZE);
gtk_window_set_title( (GtkWindow*)gtkPlotWindow,"Monitor" );
gtk_widget_set_app_paintable(gtkPlotWindow, TRUE);
gtk_widget_show_all( gtkPlotWindow );
return 0;
};
For display of images and lines in the simulation loop there are two C-functions.
PlotBitMap() is called first then PlotLine():
Code:
int PlotBitmap( unsigned short *img)
{ /*img is pointing to an array of gray values*/
static unsigned char im[ WIN_SIZE][ WIN_SIZE][ 4 ];
...
int w, h;
cairo_surface_t *image;
...
/* here the image of gray values, img, is converted to an RGB24-image, im */
...
/*with the following code, here commented out, the images are displayed
but the lines are not visible */
// gdk_draw_rgb_image(gtkPlotWindow->window,
// gtkPlotWindow->style->fg_gc[GTK_STATE_NORMAL],
// 4,4, /* x , y */
// WIN_SIZE,WIN_SIZE ,/* width,height */
// GDK_RGB_DITHER_NORMAL,
// (guchar*)im,
// WIN_SIZE*3);
/* using cairo for display of the images: */
image = cairo_image_surface_create_for_data((guchar*)im,CAIRO_FORMAT_RGB24,512,512,512);
cairo_t* cairoWindowHandler = gdk_cairo_create ( gtkPlotWindow->window );
cairo_set_source_surface (cairoWindowHandler, image, 0, 0);
cairo_paint (cairoWindowHandler);
cairo_surface_destroy (image);
cairo_destroy( cairoWindowHandler );
return 0;
};
Code:
int PlotLine( int x1, int y1, int x2, int y2, int color )
{
cairo_t* cairoWindowHandler = gdk_cairo_create ( gtkPlotWindow->window );
if( color == 1 )
{
cairo_set_source_rgb( cairoWindowHandler, 1, 0, 0 );
}
else if( color == 2 )
...
cairo_set_line_width ( cairoWindowHandler, 1.0 );
cairo_move_to ( cairoWindowHandler, x1, y1 );
cairo_line_to ( cairoWindowHandler , x2, y2 );
cairo_stroke ( cairoWindowHandler );
cairo_destroy( cairoWindowHandler );
return 0;
}
With the code shown above nothing at all is displayed.
Replacing within cairo_image_surface_create_for_data() the image format CAIRO_FORMAT_RGB24 by CAIRO_FORMAT_A8 shows a gray window and the plotted lines.
Any help is welcome
gtkNiko