00001 /* --------------------------------------------------------------------------- 00002 Phission : 00003 Realtime Vision Processing System 00004 00005 Copyright (C) 2003-2006 Philip D.S. Thoren (pthoren@cs.uml.edu) 00006 University of Massachusetts at Lowell, 00007 Laboratory for Artificial Intelligence and Robotics 00008 00009 This file is part of Phission. 00010 00011 Phission is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU Lesser General Public License as published by 00013 the Free Software Foundation; either version 2 of the License, or 00014 (at your option) any later version. 00015 00016 Phission is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 GNU Lesser General Public License for more details. 00020 00021 You should have received a copy of the GNU Lesser General Public License 00022 along with Phission; if not, write to the Free Software 00023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00024 00025 ---------------------------------------------------------------------------*/ 00026 #ifdef HAVE_CONFIG_H 00027 #include <phissionconfig.h> 00028 #endif 00029 00030 #include <phStandard.h> 00031 00032 #include <phObject.h> 00033 #include <phMutex.h> 00034 #include <phSemaphore.h> 00035 #include <phCondition.h> 00036 #include <phRWLock.h> 00037 #include <phThread.h> 00038 #include <phList.h> 00039 #include <phTimeStamp.h> 00040 #include <phTimeInterval.h> 00041 #include <phLiveObject.h> 00042 #include <phDataObject.h> 00043 #include <phImage.h> 00044 #include <phImageWindow.h> 00045 00046 #include <phDisplayInterface.h> 00047 00048 #include <phError.h> 00049 #include <phMemory.h> 00050 #include <phPrint.h> 00051 00052 /* ---------------------------------------------------------------------- */ 00053 phDisplayInterface::phDisplayInterface(uint32_t width, 00054 uint32_t height, 00055 char *title ) 00056 { 00057 phFUNCTION("phDisplayInterface::phDisplayInterface") 00058 int locked = 0; 00059 00060 phTHIS_LOOSE_LOCK(locked); 00061 00062 setName("phDisplayInterface"); 00063 00064 this->m_imageWindow = NULL; 00065 this->m_liveSourceImage = NULL; 00066 this->m_tempImage = new phImage(); 00067 this->m_paused = 0; 00068 this->m_pause_wait = new phSemaphore(0,1); 00069 00070 phTHIS_LOOSE_UNLOCK(locked); 00071 } 00072 00073 /* ---------------------------------------------------------------------- */ 00074 phDisplayInterface::~phDisplayInterface() 00075 { 00076 phFUNCTION("phDisplayInterface::~phDisplayInterface") 00077 int locked = 0; 00078 00079 phTHIS_LOOSE_LOCK(locked); 00080 00081 /* close the window */ 00082 this->close(); 00083 00084 this->m_liveSourceImage = NULL; 00085 00086 phDelete(this->m_imageWindow); 00087 phDelete(this->m_tempImage); 00088 phDelete(this->m_pause_wait); 00089 00090 phTHIS_LOOSE_UNLOCK(locked); 00091 } 00092 00093 /* ---------------------------------------------------------------------- */ 00094 int phDisplayInterface::open(uint32_t width, uint32_t height, char *title ) 00095 { 00096 phFUNCTION("phDisplayInterface::open") 00097 int locked = 0; 00098 int spawn_locked = 0; 00099 00100 /* Keep everyone else from trying to spawn at the same time. This lock 00101 * is only needed because we unlock THIS below before we call 00102 * phThread::start() for the current phDisplayInterface thread. This 00103 * is necessary because we'd otherwise have two locks on THIS and the 00104 * spawning thread wouldn't be able to get the lock. */ 00105 phMUTEX_LOCK(this->m_spawn_lock,spawn_locked); 00106 00107 phTHIS_LOCK(locked); 00108 00109 /* rejoin with previous threads if window was closed */ 00110 if (this->isOpen() || (!this->threadStopped())) 00111 { 00112 this->close(); 00113 } 00114 00115 /* initialize values */ 00116 /* Also sets width, height to their proper values before opening */ 00117 rc = this->set(width,height,title); 00118 phCHECK_RC(rc,NULL,"set(width,height,title)"); 00119 00120 phTHIS_UNLOCK(locked); 00121 00122 rc = this->start(); 00123 phCHECK_RC(rc,NULL,"this->start()"); 00124 00125 /* These will get set if start doesn't fail */ 00126 /* this->m_windowOpen = this->m_windowVisible = 1; */ 00127 00128 /* This will let anyone who was trying to get 00129 * this lock get the lock */ 00130 phMUTEX_UNLOCK(this->m_spawn_lock,spawn_locked); 00131 00132 return phSUCCESS; 00133 00134 error: 00135 phTHIS_ERROR_UNLOCK(locked); 00136 00137 /* This will let anyone who was trying to get 00138 * this lock get the lock */ 00139 phMUTEX_ERROR_UNLOCK(this->m_spawn_lock,spawn_locked); 00140 00141 return phFAIL; 00142 } 00143 00144 /* ---------------------------------------------------------------------- */ 00145 int phDisplayInterface::close() 00146 { 00147 phFUNCTION("phDisplayInterface::close") 00148 int locked = 0; 00149 int spawn_locked= 0; 00150 00151 /* Keep everyone else from trying to spawn at the same time */ 00152 phMUTEX_LOCK(this->m_spawn_lock,spawn_locked); 00153 00154 phTHIS_LOCK(locked); 00155 00156 /* phThread::stop */ 00157 rc = this->stop(); 00158 phPRINT_RC(rc,NULL,"this->stop"); 00159 00160 phTHIS_UNLOCK(locked); 00161 00162 /* This will let anyone who was trying to get 00163 * this lock get the lock */ 00164 phMUTEX_UNLOCK(this->m_spawn_lock,spawn_locked); 00165 00166 return phSUCCESS; 00167 error: 00168 phTHIS_ERROR_UNLOCK(locked); 00169 00170 /* This will let anyone who was trying to get 00171 * this lock get the lock */ 00172 phMUTEX_ERROR_UNLOCK(this->m_spawn_lock,spawn_locked); 00173 00174 return phFAIL; 00175 } 00176 00177 /* ---------------------------------------------------------------------- */ 00178 int phDisplayInterface::error() 00179 { 00180 phFUNCTION("phDisplayInterface::error()") 00181 00182 if (this->m_imageWindow != NULL) 00183 { 00184 rc = this->m_imageWindow->stop(); 00185 phPRINT_RC(rc,NULL,"this->m_imageWindow->stop()"); 00186 } 00187 00188 return phSUCCESS; 00189 } 00190 00191 /* ---------------------------------------------------------------------- */ 00192 int phDisplayInterface::run() 00193 { 00194 phFUNCTION("phDisplayInterface::run") 00195 00196 phImage *pimage = NULL; 00197 phLiveObject *current_live_source = NULL; 00198 00199 int first_image = 1; 00200 int exit_now = 0; 00201 int updated = phSUCCESS; 00202 int resized = phSUCCESS; 00203 uint32_t min_w = 0; 00204 uint32_t min_h = 0; 00205 00206 phCHECK_NULLPTR(this->m_imageWindow,NULL, 00207 "this->m_imageWindow isn't set. Display needs a window."); 00208 00209 phCHECK_NULLPTR(this->m_liveSourceImage,NULL, 00210 "this->m_liveSourceImage isn't set. Display needs a live source."); 00211 00212 /* By using the m_tempImage with pimage, 00213 * it solves a deadlock condition that may 00214 * potentially occur between the ImageWindow's thread and this thread. 00215 * The min-size can be retrieved atomically and then the data can 00216 * be swapped with the pimage data. */ 00217 pimage = this->m_imageWindow->getImage(); 00218 00219 /* Spawn input thread */ 00220 /* input_params.update_done_sem = &(this->m_update_done_sem); */ 00221 rc = this->m_imageWindow->start(); 00222 phCHECK_RC(rc,NULL,"this->m_imageWindow->start()"); 00223 00224 rc = this->signal_running(); 00225 phPRINT_RC(rc,NULL,"this->signal_running()"); 00226 00227 /* End when screen_handler is done. */ 00228 while ((exit_now == 0) && 00229 this->isRunning() && 00230 this->m_imageWindow->isRunning()) 00231 { 00232 if (!this->m_paused) 00233 { 00234 /* This yield ensures that this loop doesn't become 00235 * so tight that other displays and threads are 00236 * prevented from processing anything */ 00237 /* It's all about throughput and equality */ 00238 phYield(); 00239 } 00240 else 00241 { 00242 rc = this->m_pause_wait->take(); 00243 phPRINT_RC(rc,NULL,"this->m_pause_wait->take()"); 00244 00245 continue; 00246 } 00247 00248 rc = phSUCCESS; 00249 updated = 0; 00250 resized = 0; 00251 00252 /* Check to make sure we're still connected to the live source 00253 * that is set in this display */ 00254 if ((current_live_source != this->m_liveSourceImage) && 00255 (this->m_liveSourceImage!= NULL)) 00256 { 00257 /* Connect the images: 00258 * Connects the image in the DisplayInterface to the input image that 00259 * is being listened to */ 00260 rc = this->m_tempImage->connect(this->m_liveSourceImage); 00261 phCHECK_RC(rc,NULL,"this->m_tempImage->connect() failed"); 00262 00263 current_live_source = this->m_liveSourceImage; 00264 } 00265 00266 /* blocking wait on refresh semaphore */ 00267 rc = this->m_tempImage->update(first_image ? phLiveObjectFORCE : phLiveObjectNOFLAG); 00268 phPRINT_RC(rc,NULL,"this->m_tempImage->update() failed"); 00269 if (rc == phLiveObjectNOUPDATE) continue; 00270 /* when update returns phSUCCESS, update succeeded */ 00271 if (rc == phSUCCESS) updated = 1; 00272 00273 #if 0 00274 /* Do a conversion for the ImageWindow; the 00275 * ImageWindow has to also enforce the conversion of 00276 * the image as well. */ 00277 /* TODO: Is this the right way to do this ? */ 00278 /* We don't want to do this all the time; For example, 00279 * if the format is JPEG and there are no clients. 00280 * OR if the ImageWindow is minimized and converting would 00281 * be useless */ 00282 if (updated) 00283 { 00284 rc = this->m_tempImage->convert(this->m_imageWindow->getFormats()); 00285 phCHECK_RC(rc,NULL,"this->m_tempImage->convert(0x%08x)\n", 00286 this->m_imageWindow->getFormats()); 00287 } 00288 #endif 00289 if (updated) 00290 { 00291 if (first_image == 1) first_image = 0; 00292 00293 min_w = this->m_tempImage->getWidth(); 00294 min_h = this->m_tempImage->getHeight(); 00295 00296 #if 1 00297 rc = pimage->swap(this->m_tempImage); 00298 phPRINT_RC(rc,NULL,"pimage->swap(this->m_tempImage)"); 00299 #else 00300 rc = pimage->copy(this->m_tempImage); 00301 phPRINT_RC(rc,NULL,"pimage->copy(this->m_tempImage)"); 00302 #endif 00303 00304 /* Adjust the minimum size to be the size of the image because 00305 * continued resizing of the live image to a smaller image can 00306 * hurt performance more than just copying the entire image */ 00307 /* We have to set the min size here because trying to set the 00308 min-size internal to the phImageWindow class so far has 00309 proven to be difficult. A resize can happen between the 00310 update made above and the call to phImageWindow::update which 00311 would be the current point of setting min-size. More 00312 thought needs to be put into solving this more cleanly. */ 00313 rc = this->m_imageWindow->setMinSize(min_w,min_h); 00314 phPRINT_RC(rc,NULL,"this->m_imageWindow->setMinSize"); 00315 /* when setMinSize returns phSUCCESS, resize succeeded */ 00316 if (rc == phSUCCESS) resized = 1; 00317 00318 /* If a semaphore was taken... copy the image */ 00319 /* [above] if rc != phSUCCESS, updated=0; 00320 * if rc == phSUCCESS, updated=1 */ 00321 /* [above] if rc != phSUCCESS, resized=0; 00322 * if rc == phSUCCESS, resized=1 */ 00323 if ((exit_now == 0) && 00324 (resized == 1) && 00325 this->isRunning() && 00326 this->m_imageWindow->isRunning()) 00327 { 00328 /* clear refresh done semaphore first */ 00329 rc = this->m_refresh_done_sem.tryTake(); 00330 phPRINT_RC(rc,NULL, 00331 "this->m_refresh_done_sem.tryTake() failed."); 00332 00333 if (this->m_imageWindow->isOpen()) 00334 { 00335 rc = this->m_imageWindow->update(); 00336 phPRINT_RC(rc,NULL,"this->m_imageWindow->update()"); 00337 } 00338 00339 /* post to the refresh done semaphore */ 00340 rc = this->m_refresh_done_sem.post(); 00341 phPRINT_RC(rc,NULL,"this->m_refresh_done_sem.post() failed."); 00342 } 00343 } 00344 00345 if (!this->m_imageWindow->isOpen()) 00346 { 00347 exit_now = 1; 00348 } 00349 } 00350 00351 if (this->m_tempImage->isConnected()) 00352 { 00353 rc = this->m_tempImage->disconnect(); 00354 phPRINT_RC(rc,NULL,"this->m_tempImage->disconnect()"); 00355 } 00356 00357 if (this->m_imageWindow != NULL) 00358 { 00359 /* Rejoin with the input thread */ 00360 rc = this->m_imageWindow->stop(); 00361 phPRINT_RC(rc,NULL,"this->m_imageWindow->stop()"); 00362 } 00363 00364 DEBUG_PRINT("Thread returning cleanly\n"); 00365 00366 return phSUCCESS; 00367 00368 error: 00369 00370 if (this->m_tempImage->isConnected()) 00371 { 00372 rc = this->m_tempImage->disconnect(); 00373 phPRINT_RC(rc,NULL,"this->m_tempImage->disconnect()"); 00374 } 00375 00376 if (this->m_imageWindow != NULL) 00377 { 00378 /* Rejoin with the input thread */ 00379 rc = this->m_imageWindow->stop(); 00380 phPRINT_RC(rc,NULL,"this->m_imageWindow->stop()"); 00381 } 00382 00383 rc = this->signal_error(); 00384 phPRINT_RC(rc,NULL,"this->signal_error()"); 00385 00386 phPROGRESS("Thread returning with error\n"); 00387 00388 return phFAIL; 00389 } 00390 /* ---------------------------------------------------------------------- */ 00391 int phDisplayInterface::cleanup() 00392 { 00393 /*phFUNCTION("phDisplayInterface::wakeup")*/ 00394 00395 return phSUCCESS; 00396 /* 00397 error: 00398 return phFAIL; 00399 */ 00400 } 00401 00402 /* ---------------------------------------------------------------------- */ 00403 int phDisplayInterface::wakeup() 00404 { 00405 phFUNCTION("phDisplayInterface::wakeup") 00406 int pause_locked = 0; 00407 00408 /* phTHIS_LOOSE_LOCK(locked); */ 00409 00410 phMUTEX_LOOSE_LOCK(this->m_pause_lock,pause_locked); 00411 00412 /* Stop the image window thread so the display interface can't 00413 * block on any of it's locks/etc. */ 00414 if (this->m_imageWindow != NULL) 00415 { 00416 this->m_imageWindow->stop(); 00417 } 00418 00419 rc = this->unpause(); 00420 phPRINT_RC(rc,NULL,"this->unpause"); 00421 00422 /* We can't call wakeup_clients on the liveSourceObj so we need to 00423 wake ourself up */ 00424 rc = this->m_tempImage->wakeup_self(); 00425 phPRINT_RC(rc,NULL,"this->m_tempImage->wakeup_self"); 00426 00427 phMUTEX_LOOSE_UNLOCK(this->m_pause_lock,pause_locked); 00428 00429 /* phTHIS_LOOSE_UNLOCK(locked); */ 00430 00431 return phSUCCESS; 00432 } 00433 00434 /* ---------------------------------------------------------------------- */ 00435 int phDisplayInterface::hide() 00436 { 00437 phFUNCTION("phDisplayInterface::hide") 00438 int locked = 0; 00439 int retrc = phSUCCESS; 00440 00441 phTHIS_LOCK(locked); 00442 00443 if (this->m_imageWindow != NULL) 00444 { 00445 this->m_imageWindow->hide(); 00446 } 00447 else 00448 { 00449 retrc = phFAIL; 00450 } 00451 00452 phTHIS_UNLOCK(locked); 00453 00454 return retrc; 00455 error: 00456 phTHIS_ERROR_UNLOCK(locked); 00457 00458 return phFAIL; 00459 } 00460 00461 /* ---------------------------------------------------------------------- */ 00462 int phDisplayInterface::show() 00463 { 00464 phFUNCTION("phDisplayInterface::show") 00465 int locked = 0; 00466 int retrc = phSUCCESS; 00467 00468 phTHIS_LOCK(locked); 00469 00470 if (this->m_imageWindow != NULL) 00471 { 00472 this->m_imageWindow->show(); 00473 } 00474 else 00475 { 00476 retrc = phFAIL; 00477 } 00478 00479 phTHIS_UNLOCK(locked); 00480 00481 return retrc; 00482 error: 00483 phTHIS_ERROR_UNLOCK(locked); 00484 00485 return phFAIL; 00486 } 00487 00488 /* ---------------------------------------------------------------------- */ 00489 int phDisplayInterface::resize( uint32_t w, uint32_t h) 00490 { 00491 phFUNCTION("phDisplayInterface::resize") 00492 int locked = 0; 00493 int retrc = phSUCCESS; 00494 00495 phTHIS_LOCK(locked); 00496 00497 if (this->m_imageWindow != NULL) 00498 { 00499 rc = this->m_imageWindow->resize(w,h); 00500 phCHECK_RC(rc,NULL,"m_imageWindow->resize(w:%d,h:%d)",w,h); 00501 } 00502 else 00503 { 00504 retrc = phFAIL; 00505 } 00506 phTHIS_UNLOCK(locked); 00507 00508 return retrc; 00509 error: 00510 phTHIS_ERROR_UNLOCK(locked); 00511 00512 return phFAIL; 00513 } 00514 00515 /* ---------------------------------------------------------------------- */ 00516 int phDisplayInterface::move( int32_t x, int32_t y) 00517 { 00518 phFUNCTION("phDisplayInterface::move") 00519 int locked = 0; 00520 int retrc = phSUCCESS; 00521 00522 phTHIS_LOCK(locked); 00523 00524 if (this->m_imageWindow != NULL) 00525 { 00526 rc = this->m_imageWindow->move(x,y); 00527 phCHECK_RC(rc,NULL,"m_imageWindow->move(x:%d,y:%d)",x,y); 00528 } 00529 else 00530 { 00531 retrc = phFAIL; 00532 } 00533 00534 phTHIS_UNLOCK(locked); 00535 00536 return retrc; 00537 error: 00538 phTHIS_ERROR_UNLOCK(locked); 00539 00540 return phFAIL; 00541 } 00542 00543 /* ---------------------------------------------------------------------- */ 00544 int phDisplayInterface::isOpen() 00545 { 00546 if (this->m_imageWindow != NULL) 00547 { 00548 return this->m_imageWindow->isOpen(); 00549 } 00550 00551 return 0; 00552 } 00553 00554 /* ---------------------------------------------------------------------- */ 00555 int phDisplayInterface::pause() 00556 { 00557 phFUNCTION("phDisplayInterface::pause") 00558 int pause_locked = 0; 00559 00560 phMUTEX_LOCK(this->m_pause_lock,pause_locked); 00561 00562 if (this->m_paused == 0) 00563 { 00564 /* make sure the semaphore isn't posted */ 00565 rc = this->m_pause_wait->tryTake(); 00566 phPRINT_RC(rc,NULL,"this->m_pause_wait->tryTake"); 00567 00568 this->m_paused = 1; 00569 } 00570 00571 phMUTEX_UNLOCK(this->m_pause_lock,pause_locked); 00572 00573 return phSUCCESS; 00574 error: 00575 return phFAIL; 00576 } 00577 00578 /* ---------------------------------------------------------------------- */ 00579 int phDisplayInterface::unpause() 00580 { 00581 phFUNCTION("phDisplayInterface::unpause") 00582 int pause_locked = 0; 00583 00584 phMUTEX_LOCK(this->m_pause_lock,pause_locked); 00585 00586 if (this->m_paused != 0) 00587 { 00588 this->m_paused = 0; 00589 00590 rc = this->m_pause_wait->post(); 00591 phCHECK_RC(rc,NULL,"this->m_pause_wait->post"); 00592 } 00593 00594 phMUTEX_UNLOCK(this->m_pause_lock,pause_locked); 00595 00596 return phSUCCESS; 00597 error: 00598 return phFAIL; 00599 } 00600 00601 00602 /* ---------------------------------------------------------------------- */ 00603 int phDisplayInterface::isPaused() 00604 { 00605 return this->m_paused; 00606 } 00607 00608 /* ---------------------------------------------------------------------- */ 00609 int phDisplayInterface::set( uint32_t w, uint32_t h, const char *t ) 00610 { 00611 phFUNCTION("phDisplayInterface::set") 00612 int locked = 0; 00613 int retrc = phSUCCESS; 00614 00615 phTHIS_LOCK(locked); 00616 00617 if (this->m_imageWindow != NULL) 00618 { 00619 rc = this->m_imageWindow->resize(w,h); 00620 phPRINT_RC(rc,NULL,"this->m_imageWindow->resize(w:%u,h:%u)",w,h); 00621 00622 rc = this->m_imageWindow->setTitle(t); 00623 phPRINT_RC(rc,NULL,"this->m_imageWindow->setTitle(t:%s)", 00624 ((t != NULL) ? t : "")); 00625 } 00626 else 00627 { 00628 retrc = phFAIL; 00629 } 00630 00631 phTHIS_UNLOCK(locked); 00632 00633 return retrc; 00634 error: 00635 phTHIS_ERROR_UNLOCK(locked); 00636 00637 return phFAIL; 00638 } 00639 00640 /* ---------------------------------------------------------------------- */ 00641 int phDisplayInterface::setTitle( const char *newtitle ) 00642 { 00643 phFUNCTION("phDisplayInterface::setTitle") 00644 int locked = 0; 00645 int retrc = phSUCCESS; 00646 00647 if (newtitle == NULL) return phFAIL; 00648 00649 phTHIS_LOCK(locked); 00650 00651 /* unlock image pointer ????? */ 00652 00653 if (this->m_imageWindow != NULL) 00654 { 00655 rc = this->m_imageWindow->setTitle(newtitle); 00656 phPRINT_RC(rc,NULL,"this->m_imageWindow->setTitle()"); 00657 } 00658 else 00659 { 00660 retrc = phFAIL; 00661 } 00662 00663 phTHIS_UNLOCK(locked); 00664 00665 return retrc; 00666 error: 00667 phTHIS_ERROR_UNLOCK(locked); 00668 00669 return phFAIL; 00670 } 00671 00672 /* ---------------------------------------------------------------------- */ 00673 const char *phDisplayInterface::getTitle() 00674 { 00675 if (this->m_imageWindow != NULL) 00676 { 00677 return this->m_imageWindow->getTitle(); 00678 } 00679 00680 /* return this->m_title; */ 00681 return NULL; 00682 } 00683 00684 /* ---------------------------------------------------------------------- */ 00685 int phDisplayInterface::setWidth( uint32_t w ) 00686 { 00687 phFUNCTION("phDisplayInterface::setWidth") 00688 int locked = 0; 00689 int retrc = phSUCCESS; 00690 00691 phTHIS_LOCK(locked); 00692 00693 if (this->m_imageWindow != NULL) 00694 { 00695 rc = this->m_imageWindow->resize(w,0); 00696 phCHECK_RC(rc,NULL,"this->m_imageWindow->resize(w:%u,0)",w); 00697 } 00698 else 00699 { 00700 retrc = phFAIL; 00701 } 00702 00703 phTHIS_UNLOCK(locked); 00704 00705 return retrc; 00706 error: 00707 phTHIS_ERROR_UNLOCK(locked); 00708 00709 return phFAIL; 00710 } 00711 00712 /* ---------------------------------------------------------------------- */ 00713 int phDisplayInterface::setHeight( uint32_t h ) 00714 { 00715 phFUNCTION("phDisplayInterface::setHeight") 00716 int locked = 0; 00717 int retrc = phSUCCESS; 00718 00719 phTHIS_LOCK(locked); 00720 00721 if (this->m_imageWindow != NULL) 00722 { 00723 rc = this->m_imageWindow->resize(0,h); 00724 phCHECK_RC(rc,NULL,"this->m_imageWindow->resize(0,h:%u)",h); 00725 } 00726 else 00727 { 00728 retrc = phFAIL; 00729 } 00730 00731 phTHIS_UNLOCK(locked); 00732 00733 return retrc; 00734 error: 00735 phTHIS_ERROR_UNLOCK(locked); 00736 00737 return phFAIL; 00738 } 00739 00740 /* ---------------------------------------------------------------------- */ 00741 uint32_t phDisplayInterface::getWidth() 00742 { 00743 phFUNCTION("phDisplayInterface::getWidth") 00744 int locked = 0; 00745 uint32_t returnval = 0; 00746 00747 phTHIS_LOOSE_LOCK(locked); 00748 00749 if (this->m_imageWindow != NULL) 00750 { 00751 returnval = this->m_imageWindow->getWidth(); 00752 } 00753 00754 phTHIS_LOOSE_UNLOCK(locked); 00755 00756 return returnval; 00757 } 00758 /* ---------------------------------------------------------------------- */ 00759 uint32_t phDisplayInterface::getHeight() 00760 { 00761 phFUNCTION("phDisplayInterface::getHeight") 00762 int locked = 0; 00763 uint32_t returnval = 0; 00764 00765 phTHIS_LOOSE_LOCK(locked); 00766 00767 if (this->m_imageWindow != NULL) 00768 { 00769 returnval = this->m_imageWindow->getHeight(); 00770 } 00771 00772 phTHIS_LOOSE_UNLOCK(locked); 00773 00774 return returnval; 00775 } 00776 00777 /* ---------------------------------------------------------------------- */ 00778 phUSize phDisplayInterface::getSize() 00779 { 00780 phFUNCTION("phDisplayInterface::getSize") 00781 int locked = 0; 00782 phUSize returnval = {0,0}; 00783 00784 phTHIS_LOOSE_LOCK(locked); 00785 00786 if (this->m_imageWindow != NULL) 00787 { 00788 returnval = this->m_imageWindow->getSize(); 00789 } 00790 00791 phTHIS_LOOSE_UNLOCK(locked); 00792 00793 return returnval; 00794 } 00795 00796 /* ---------------------------------------------------------------------- */ 00797 int32_t phDisplayInterface::getX() 00798 { 00799 phFUNCTION("phDisplayInterface::getX") 00800 int locked = 0; 00801 int32_t returnval = 0; 00802 00803 phTHIS_LOOSE_LOCK(locked); 00804 00805 if (this->m_imageWindow != NULL) 00806 { 00807 returnval = this->m_imageWindow->getX(); 00808 } 00809 00810 phTHIS_LOOSE_UNLOCK(locked); 00811 00812 return returnval; 00813 } 00814 00815 /* ---------------------------------------------------------------------- */ 00816 int32_t phDisplayInterface::getY() 00817 { 00818 phFUNCTION("phDisplayInterface::getY") 00819 int locked = 0; 00820 int32_t returnval = 0; 00821 00822 phTHIS_LOOSE_LOCK(locked); 00823 00824 if (this->m_imageWindow != NULL) 00825 { 00826 returnval = this->m_imageWindow->getY(); 00827 } 00828 00829 phTHIS_LOOSE_UNLOCK(locked); 00830 00831 return returnval; 00832 } 00833 00834 /* ---------------------------------------------------------------------- */ 00835 phPoint phDisplayInterface::getLocation() 00836 { 00837 phFUNCTION("phDisplayInterface::getLocation") 00838 int locked = 0; 00839 phPoint returnval = {0,0}; 00840 00841 phTHIS_LOOSE_LOCK(locked); 00842 00843 if (this->m_imageWindow != NULL) 00844 { 00845 returnval = this->m_imageWindow->getLocation(); 00846 } 00847 00848 phTHIS_LOOSE_UNLOCK(locked); 00849 00850 return returnval; 00851 } 00852 00853 /* ---------------------------------------------------------------------- */ 00854 phImageWindow *phDisplayInterface::getImageWindow() 00855 { 00856 return this->m_imageWindow; 00857 } 00858 00859 /* ---------------------------------------------------------------------- */ 00860 /* Live source stuff */ 00861 /* ---------------------------------------------------------------------- */ 00862 00863 /* ---------------------------------------------------------------------- */ 00864 int phDisplayInterface::isLiveSourceSet() 00865 { 00866 return (this->m_liveSourceImage == NULL ? 0 : 1); 00867 } 00868 00869 /* ---------------------------------------------------------------------- */ 00870 phLiveObject *phDisplayInterface::getLiveSourceInput() 00871 { 00872 return this->m_liveSourceImage; 00873 } 00874 00875 /* ---------------------------------------------------------------------- */ 00876 int phDisplayInterface::setLiveSourceInput( phLiveObject *img ) 00877 { 00878 phFUNCTION("phDisplayInterface::setLiveSourceInput") 00879 int locked = 0; 00880 00881 phTHIS_LOCK(locked); 00882 00883 if (img != NULL) 00884 { 00885 rc = img->isNamed("phImage"); 00886 phCHECK_RC(rc,NULL,"Invalid phLiveObject input object type: %s", 00887 img->getName()); 00888 00889 this->m_liveSourceImage = (phImage *)img; 00890 } 00891 else 00892 this->m_liveSourceImage = NULL; 00893 00894 phTHIS_UNLOCK(locked); 00895 00896 return phSUCCESS; 00897 error: 00898 00899 phTHIS_ERROR_UNLOCK(locked); 00900 00901 return phFAIL; 00902 } 00903 00904 /* ---------------------------------------------------------------------- */ 00905 int phDisplayInterface::setInput( phLiveObject *input ) 00906 { 00907 return this->setLiveSourceInput( input ); 00908 } 00909 00910 /* ---------------------------------------------------------------------- */ 00911 int phDisplayInterface::setLiveInput( phLiveObject *input ) 00912 { 00913 return this->setLiveSourceInput( input ); 00914 } 00915
Copyright (C) 2002 - 2007 |
Philip D.S. Thoren ( pthoren@users.sourceforge.net ) University Of Massachusetts at Lowell Robotics Lab |