display_canvas.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) Massimo Cora' 2006 <maxcvs@gmail.com>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #include "display_canvas.h"
00020 
00021 
00022 // implement message map
00023 BEGIN_EVENT_TABLE(DisplayCanvas, wxWindow)
00024   EVT_PAINT( DisplayCanvas::OnPaint )
00025 END_EVENT_TABLE()
00026 
00027 
00028 
00029 DisplayCanvas::DisplayCanvas( wxWindow *frame, const wxSize& size ):
00030                         wxWindow(frame, -1, wxDefaultPosition, size, wxSIMPLE_BORDER )
00031 {
00032         _new_image_available = false;
00033         _drawing = false;
00034 
00035         _canvas_width = size.GetWidth ();
00036         _canvas_height = size.GetHeight ();
00037 }
00038 
00039 DisplayCanvas::~DisplayCanvas( )
00040 {
00041 
00042 }
00043 
00044 
00045 void DisplayCanvas::OnPaint(wxPaintEvent& event)
00046 {
00047         wxPaintDC dc(this);
00048         Draw( dc );
00049 }
00050 
00051 void DisplayCanvas::DrawIplImage( IplImage* ipl_image )
00052 {
00053         if( _drawing == true ) 
00054                 return;
00055 
00056         if ( ipl_image->width != _canvas_width || ipl_image->height != _canvas_height )
00057                 return;
00058 
00059         _drawing = true;
00060 
00061         unsigned char *raw_data;
00062         CvSize roiSize;
00063         int step = 0;
00064         
00065         cvGetRawData( ipl_image, &raw_data, &step, &roiSize );
00066 
00067         // the data is static, i.e. it DOES NOT HAVE TO BE RELEASED by wxImage when destroyed.
00068         wxImage pWxImg = wxImage( ipl_image->width, ipl_image->height, raw_data, true );
00069         _new_wxbitmap = wxBitmap( pWxImg );
00070 
00071         _new_image_available = true;
00072         //cvReleaseImage( &ipl_image );
00073         _drawing = false;
00074 
00075         // yeah, here it is. Refresh the canvas!
00076         Refresh( FALSE );
00077 }
00078 
00079 void DisplayCanvas::Draw( wxDC& dc )
00080 {
00081         // check if dc available
00082         if( !dc.Ok() ){ 
00083                 return; 
00084         }
00085 
00086         _drawing = true;
00087 
00088         int x,y,w,h;
00089         dc.GetClippingBox( &x, &y, &w, &h );
00090         // if there is a new image to draw
00091         if( _new_image_available == true )
00092         {
00093                 dc.DrawBitmap( _new_wxbitmap, x, y );
00094                 _new_image_available = false;
00095         } else
00096         {
00097                 // draw inter frame ?
00098         }
00099 
00100         _drawing = false;
00101 
00102         return;
00103 }
00104 
00105 

Generated on Tue Dec 26 10:32:38 2006 for Omnimeeting by  doxygen 1.4.7