00001 #include <gtk/gtk.h>
00002 #include "vapiAux.h"
00003 #include "vapiImagesAux.h"
00004 #include "vapiGtkInterface.h"
00005 #include "vapiGtkAux.h"
00006
00007
00015 GdkPixbuf *
00016 vapiGtkPixbuf (GtkWidget * widget, IplImage * img, int rescale)
00017 {
00018
00019 GdkPixbuf *tempPixbuf;
00020 IplImage *tempImg;
00021
00022 switch (img->nChannels)
00023 {
00024
00025 case 1:
00026 tempImg = vapiImagesSameSize (img, 3);
00027 cvMerge (img, img, img, NULL, tempImg);
00028 break;
00029
00030 case 3:
00031 tempImg = vapiImagesSameSize (img, 3);
00032 cvConvertImage (img, tempImg, CV_CVTIMG_SWAP_RB);
00033 break;
00034
00035 default:
00036 v_error (" Erro, numero invalido de canais: %d .",
00037 img->nChannels);
00038 return 0;
00039 break;
00040 }
00041
00042 tempPixbuf = gdk_pixbuf_new_from_data ((uchar *) tempImg->imageData,
00043 GDK_COLORSPACE_RGB,
00044 0,
00045 8,
00046 tempImg->width,
00047 tempImg->height,
00048 tempImg->widthStep,
00049 NULL, NULL);
00050
00051 if (rescale > 0)
00052 {
00053 tempPixbuf = gdk_pixbuf_scale_simple (tempPixbuf,
00054 widget->allocation.
00055 width,
00056 widget->allocation.
00057 height,
00058 GDK_INTERP_BILINEAR);
00059 }
00060 else
00061 {
00062 tempPixbuf = gdk_pixbuf_scale_simple (tempPixbuf,
00063 img->width,
00064 img->height,
00065 GDK_INTERP_BILINEAR);
00066 }
00067
00068 cvReleaseImage (&tempImg);
00069 return tempPixbuf;
00070 }
00071
00072
00076 void
00077 vapiGtkPutImage (GtkWidget * Widget, IplImage * Image)
00078 {
00079
00080
00081 GdkPixbuf *buf_imagem;
00082
00083 buf_imagem = vapiGtkPixbuf (Widget, Image, 1);
00084
00085 if (buf_imagem == 0)
00086 {
00087 return;
00088 }
00089 gtk_image_set_from_pixbuf ((GtkImage *) Widget, buf_imagem);
00090
00091
00092
00093
00094
00095 if (buf_imagem != NULL)
00096 g_object_unref (buf_imagem);
00097
00098 }
00099
00100 void
00101 vapiGtkPutImageNotScaled (GtkWidget * Widget, IplImage * Image)
00102 {
00103
00104
00105 GdkPixbuf *buf_imagem;
00106
00107 gtk_widget_set_size_request (Widget, Image->width, Image->height);
00108 buf_imagem = vapiGtkPixbuf (Widget, Image, 0);
00109
00110 if (buf_imagem == 0)
00111 {
00112 return;
00113 }
00114
00115 gtk_image_set_from_pixbuf ((GtkImage *) Widget, buf_imagem);
00116
00117
00118
00119
00120
00121 if (buf_imagem != NULL)
00122 g_object_unref (buf_imagem);
00123
00124 }