VCDisplay.cpp
Go to the documentation of this file.
00001 // ****************************************************************************
00002 // This file is part of the Integrating Vision Toolkit (IVT).
00003 //
00004 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
00005 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
00006 //
00007 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
00008 // All rights reserved.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are met:
00012 //
00013 // 1. Redistributions of source code must retain the above copyright
00014 //    notice, this list of conditions and the following disclaimer.
00015 //
00016 // 2. Redistributions in binary form must reproduce the above copyright
00017 //    notice, this list of conditions and the following disclaimer in the
00018 //    documentation and/or other materials provided with the distribution.
00019 //
00020 // 3. Neither the name of the KIT nor the names of its contributors may be
00021 //    used to endorse or promote products derived from this software
00022 //    without specific prior written permission.
00023 //
00024 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
00025 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00026 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
00028 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00031 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00033 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 // ****************************************************************************
00035 // ****************************************************************************
00036 // Filename:  VCDisplay.cpp
00037 // Author:    Moritz Hassert
00038 // Date:      9.12.2008
00039 // ****************************************************************************
00040 
00041 
00042 // ****************************************************************************
00043 // Includes
00044 // ****************************************************************************
00045 
00046 #include <new> // for explicitly using correct new/delete operators on VC DSPs
00047 
00048 #define NEW_IMAGE_VAR
00049 #include <vcrt.h>
00050 #include <macros.h>
00051 #include <sysvar.h>
00052 
00053 
00054 #include <algorithm>
00055 
00056 #include <Helpers/helpers.h>
00057 #include <Image/ByteImage.h>
00058 
00059 #include "VCDisplay.h"
00060 
00061 
00062 
00063 // ****************************************************************************
00064 // Global functions
00065 // ****************************************************************************
00066 
00067 inline void wait_for_next_frame()
00068 {
00069         int res;
00070         //wait for NEXT frame change, not the current one
00071         while ( (res=wait(DISPLAY_EVT, 1000))==2) //while last change is reported
00072         {
00073                 printf("res: %d\n", res);
00074         }
00075         printf("res: %d\n", res);
00076 }
00077 
00078 
00079 // ****************************************************************************
00080 // Constructor / Destructor
00081 // ****************************************************************************
00082 
00083 CVCDisplay::CVCDisplay(bool doubleBuffer, bool show_overlay): m_width(DispGetColumns), m_height(DispGetRows), m_pitch(DispGetPitch), m_doubleBuffer(doubleBuffer)
00084 {
00085         // alloc mem for display. for non VGA models the diplay is 0x0 sized!
00086         m_allocated_buffer = DRAMDisplayMalloc();
00087         //align display buffer to 1024 (hardware requirement)
00088         m_display_front = (U8*)((m_allocated_buffer+1023)&(~1023));
00089         //set everything to zero, including all border regions
00090         std::fill_n(m_display_front, m_height*m_pitch, 128);
00091 
00092         if (m_doubleBuffer) {
00093                 // alloc mem for display. for non VGA models the diplay is 0x0 sized!
00094                 m_allocated_backbuffer = DRAMDisplayMalloc();
00095                 //align display buffer to 1024 (hardware requirement)
00096                 m_display_back = (U8*)((m_allocated_backbuffer+1023)&(~1023));
00097                 //set everything to zero, including all border regions
00098                 std::fill_n( m_display_back, m_height*m_pitch, 128);
00099         }
00100         else {
00101                 m_allocated_backbuffer = NULL;
00102                 m_display_back = NULL;
00103         }
00104 
00105         make_current();
00106 
00107         if (show_overlay) {
00108                 enable_overlay();
00109                 std::fill_n( (unsigned char*)OvlGetPhysPage, OvlGetRows*OvlGetPitch, 0);
00110         }
00111         else {
00112                 disable_overlay();
00113         }
00114 
00115         //printf("create: cols %d, rows %d, pitch %d, disp %x, front %x(%x), back %x(%x)\n", m_width, m_height, m_pitch, ScrGetDispPage, m_allocated_buffer, m_display_front, m_allocated_backbuffer, m_display_back);
00116 }
00117 
00118 CVCDisplay::~CVCDisplay()
00119 {
00120         //restore default diplay buffer before freeing memory
00121         restore_default();
00122 
00123         //free this buffer
00124         DRAMByteFree(m_allocated_buffer);
00125 
00126         if (m_doubleBuffer) {
00127                 DRAMByteFree(m_allocated_backbuffer);
00128         }
00129         
00130         disable_overlay();
00131 }
00132 
00133 
00134 // ****************************************************************************
00135 // Methods
00136 // ****************************************************************************
00137 
00138 void CVCDisplay::make_current() const
00139 {
00140         //make private buffer the current display buffer
00141         ScrSetDispPage((int)m_display_front);
00142         display_update(UPDATE_DISP);
00143 }
00144         
00145 void CVCDisplay::restore_default() const
00146 {
00147         //use capture buffer for display, live mode
00148         ScrSetDispPage(ScrGetCaptPage);
00149         display_update(UPDATE_DISP);
00150 }
00151 
00152 
00153 
00154 void CVCDisplay::enable_overlay() const
00155 {
00156         setvar(OVLY_ACTIVE,1);
00157         sleep_ms(500);
00158 }
00159 
00160 
00161 void CVCDisplay::disable_overlay() const
00162 {
00163         setvar(OVLY_ACTIVE,0);
00164         sleep_ms(500);
00165 }
00166 
00167 void CVCDisplay::show(const CByteImage* image)
00168 {
00169         if (m_doubleBuffer) {
00170                 std::swap(m_display_front, m_display_back);
00171         }
00172 
00173         const unsigned char* restrict img_pixels = image->pixels;
00174         unsigned char* restrict disp_pixels = m_display_front;
00175 
00176         int h = std::min(m_height, image->height);
00177         int w = std::min(m_width,  image->width);
00178 
00179         //copy row by row as width may differ and pitch most likely will
00180         for (int row=0; row<h; row++) {
00181                 //for (int x=0; x<w; x++)
00182                 //      disp_pixels[row*m_pitch + x] = img_pixels[row*image->width + x];
00183                         
00184                 std::copy(img_pixels, img_pixels+w, disp_pixels);
00185                 //std::memcpy(disp_pixels, img_pixels, w);
00186 
00187                 img_pixels  += image->width;
00188                 disp_pixels += m_pitch;
00189         }
00190 
00191         //always set buffer address. someone might have changed it
00192         ScrSetDispPage((int)m_display_front);
00193         display_update(UPDATE_DISP);
00194 
00195         //printf("set: disp %x, front %x, back %x\n", ScrGetDispPage, m_display_front, m_display_back);
00196 }
00197 
00198 void CVCDisplay::overlay(const CByteImage *image)
00199 {
00200         const unsigned char* restrict img_pixels = image->pixels;
00201         unsigned char*       restrict ovl_pixels = (unsigned char*)OvlGetPhysPage;
00202 
00203 
00204         int h = std::min(OvlGetRows,    image->height);
00205         int w = std::min(OvlGetColumns, image->width);
00206         int ovl_pitch = OvlGetPitch;
00207 
00208         //copy row by row as width may differ and pitch most likely will
00209         for (int row=0; row<h; row++) {
00210                 std::copy(img_pixels, img_pixels+w, ovl_pixels);
00211 
00212                 img_pixels += image->width;
00213                 ovl_pixels += ovl_pitch;
00214         }
00215 }


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Thu Jun 6 2019 21:46:58