ImageResStruct.cpp

Go to the documentation of this file.
00001 /*
00002 *
00003 *       This file contains structures that store pointer to image
00004 *       and also information about used area in rectangle.
00005 *       Structures has reference counting.
00006 *
00007 *       There is also manager for this objects.
00008 *
00009 *       Author:
00010 *                       Tomas Mrkvicka
00011 *                       xmrkvi03@stud.fit.vutbr.cz
00012 *
00013 */
00014 
00015 #include <cassert>
00016 #include "simpleunit/ImageResStruct.h"
00017 
00018 ////////////////////////////////////////////////////////////////////////////////
00019 ////////////////////////////////////////////////////////////////////////////////
00020 ////////////////////////////////////////////////////////////////////////////////
00021 // TImageRGBResult
00022 
00023 /** Snizi pocet referenci na objekt.
00024 *
00025 *       Pokud pocet referenci klesne na 0 pak je objekt navracen do manageru kterym byl vytvoren.
00026 *
00027 *       Metoda je synchronizovana pro vicenasobny pristup.
00028 */
00029 void TImageRGBResult::Release(void)
00030 {
00031         m_cs.Enter();
00032                 m_refs--;
00033                 DWORD tmp_refs = m_refs;
00034         m_cs.Leave();
00035 
00036         if ( tmp_refs == 0 )
00037         {
00038                 //musime objekt navratit do manageru
00039                 m_manager->InsertObject( this );
00040         }
00041 }
00042 //OK 2007-08-25 23:41:56 B04-315B\Tom
00043 
00044 // TImageRGBResult
00045 ////////////////////////////////////////////////////////////////////////////////
00046 ////////////////////////////////////////////////////////////////////////////////
00047 ////////////////////////////////////////////////////////////////////////////////
00048 // TImageRGBResultManager
00049 
00050 /** Vytvori manager obrazku typu RGB.
00051 *
00052 *       \param  width           [in] sirka obrazku vytvarenych managerem
00053 *       \param  height          [in] vyska obrazku vytvarenych managerem
00054 *       \param  initSize        [in] pocet predalokovanych snimku
00055 */
00056 TImageRGBResultManager::TImageRGBResultManager( DWORD width, DWORD height, DWORD initSize)
00057 {
00058         m_width         = width;
00059         m_height        = height;
00060 
00061         m_exportCount = 0;              // zadny obrazek nebyl zatim exportovan
00062 
00063         //vytvorime predalokovane objekty
00064         for ( DWORD i = 0 ; i < initSize ; i++ )
00065         {
00066                 m_object.push_back( new TImageRGBResult( this, m_width, m_height ) );
00067         }
00068 }
00069 //OK 2007-08-25 23:42:12 B04-315B\Tom
00070 
00071 /** Zrusi manager.
00072 *
00073 *       \warning        V aplikaci se nesmi vyskytovat zadny objekt vytvoreny timto managerem.
00074 */
00075 TImageRGBResultManager::~TImageRGBResultManager( void )
00076 {
00077         assert( m_exportCount == 0 );
00078 
00079         //zrusime objekty
00080         while ( ! m_object.empty() )
00081         {
00082                 TImageRGBResult * obj = m_object.back();
00083                 m_object.pop_back();
00084 
00085                 delete obj;
00086         }
00087 }
00088 //OK 2007-08-25 23:42:14 B04-315B\Tom
00089 
00090 /** Vrati novy objekt.
00091 *
00092 *       Objekt ma jednu referenci a velikost platneho obdelnika je nastavena na cely obrazek.
00093 *
00094 *       Metoda je synchronizovana pro soubezny pristup.
00095 */
00096 TImageRGBResult* TImageRGBResultManager::GetObject( void )
00097 {
00098         TImageRGBResult * res = NULL;
00099 
00100         //zjistime jestli existuje nejaky volny objekt
00101         m_cs.Enter();
00102                 if ( ! m_object.empty() )
00103                 {
00104                         //mame objekt - pouzijeme
00105                         res = m_object.back();
00106                         m_object.pop_back();
00107                 }       
00108                 else
00109                 {
00110                         //vytvorime novy objekt
00111                         res = new TImageRGBResult( this, m_width, m_height );
00112                 }
00113 
00114                 res->Reset();
00115                 
00116                 m_exportCount++;
00117 
00118         m_cs.Leave();
00119 
00120         return res;
00121 }
00122 //OK 2007-08-25 23:42:29 B04-315B\Tom
00123 
00124 /** Metoda vrati objekt zpet do manageru.
00125 *
00126 *       Metoda je volana z metody Release vraceneho objektu v okamziku kdy pocet referenci klesne
00127 *       na 0.
00128 *
00129 *       Metoda je synchronizovana pro soubezny pristup.
00130 *
00131 *       \param  image   [in] vraceny obrazek
00132 */
00133 void TImageRGBResultManager::InsertObject( TImageRGBResult* image )
00134 {
00135         m_cs.Enter();
00136                 m_object.push_back( image );
00137                 m_exportCount--;
00138         m_cs.Leave();
00139 }
00140 //OK 2007-08-25 23:42:35 B04-315B\Tom
00141 
00142 // TImageRGBResultManager
00143 ////////////////////////////////////////////////////////////////////////////////
00144 ////////////////////////////////////////////////////////////////////////////////
00145 ////////////////////////////////////////////////////////////////////////////////

Generated on Sat Nov 17 16:23:26 2007 for Image Processing Pipeline by  doxygen 1.4.6-NO