VCDisplay.cpp
Go to the documentation of this file.
1 // ****************************************************************************
2 // This file is part of the Integrating Vision Toolkit (IVT).
3 //
4 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
5 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
6 //
7 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
8 // All rights reserved.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 //
16 // 2. Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
19 //
20 // 3. Neither the name of the KIT nor the names of its contributors may be
21 // used to endorse or promote products derived from this software
22 // without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
25 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
28 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 // ****************************************************************************
35 // ****************************************************************************
36 // Filename: VCDisplay.cpp
37 // Author: Moritz Hassert
38 // Date: 9.12.2008
39 // ****************************************************************************
40 
41 
42 // ****************************************************************************
43 // Includes
44 // ****************************************************************************
45 
46 #include <new> // for explicitly using correct new/delete operators on VC DSPs
47 
48 #define NEW_IMAGE_VAR
49 #include <vcrt.h>
50 #include <macros.h>
51 #include <sysvar.h>
52 
53 
54 #include <algorithm>
55 
56 #include <Helpers/helpers.h>
57 #include <Image/ByteImage.h>
58 
59 #include "VCDisplay.h"
60 
61 
62 
63 // ****************************************************************************
64 // Global functions
65 // ****************************************************************************
66 
67 inline void wait_for_next_frame()
68 {
69  int res;
70  //wait for NEXT frame change, not the current one
71  while ( (res=wait(DISPLAY_EVT, 1000))==2) //while last change is reported
72  {
73  printf("res: %d\n", res);
74  }
75  printf("res: %d\n", res);
76 }
77 
78 
79 // ****************************************************************************
80 // Constructor / Destructor
81 // ****************************************************************************
82 
83 CVCDisplay::CVCDisplay(bool doubleBuffer, bool show_overlay): m_width(DispGetColumns), m_height(DispGetRows), m_pitch(DispGetPitch), m_doubleBuffer(doubleBuffer)
84 {
85  // alloc mem for display. for non VGA models the diplay is 0x0 sized!
86  m_allocated_buffer = DRAMDisplayMalloc();
87  //align display buffer to 1024 (hardware requirement)
88  m_display_front = (U8*)((m_allocated_buffer+1023)&(~1023));
89  //set everything to zero, including all border regions
90  std::fill_n(m_display_front, m_height*m_pitch, 128);
91 
92  if (m_doubleBuffer) {
93  // alloc mem for display. for non VGA models the diplay is 0x0 sized!
94  m_allocated_backbuffer = DRAMDisplayMalloc();
95  //align display buffer to 1024 (hardware requirement)
96  m_display_back = (U8*)((m_allocated_backbuffer+1023)&(~1023));
97  //set everything to zero, including all border regions
98  std::fill_n( m_display_back, m_height*m_pitch, 128);
99  }
100  else {
101  m_allocated_backbuffer = NULL;
102  m_display_back = NULL;
103  }
104 
105  make_current();
106 
107  if (show_overlay) {
108  enable_overlay();
109  std::fill_n( (unsigned char*)OvlGetPhysPage, OvlGetRows*OvlGetPitch, 0);
110  }
111  else {
112  disable_overlay();
113  }
114 
115  //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);
116 }
117 
119 {
120  //restore default diplay buffer before freeing memory
121  restore_default();
122 
123  //free this buffer
124  DRAMByteFree(m_allocated_buffer);
125 
126  if (m_doubleBuffer) {
127  DRAMByteFree(m_allocated_backbuffer);
128  }
129 
130  disable_overlay();
131 }
132 
133 
134 // ****************************************************************************
135 // Methods
136 // ****************************************************************************
137 
139 {
140  //make private buffer the current display buffer
141  ScrSetDispPage((int)m_display_front);
142  display_update(UPDATE_DISP);
143 }
144 
146 {
147  //use capture buffer for display, live mode
148  ScrSetDispPage(ScrGetCaptPage);
149  display_update(UPDATE_DISP);
150 }
151 
152 
153 
155 {
156  setvar(OVLY_ACTIVE,1);
157  sleep_ms(500);
158 }
159 
160 
162 {
163  setvar(OVLY_ACTIVE,0);
164  sleep_ms(500);
165 }
166 
168 {
169  if (m_doubleBuffer) {
170  std::swap(m_display_front, m_display_back);
171  }
172 
173  const unsigned char* restrict img_pixels = image->pixels;
174  unsigned char* restrict disp_pixels = m_display_front;
175 
176  int h = std::min(m_height, image->height);
177  int w = std::min(m_width, image->width);
178 
179  //copy row by row as width may differ and pitch most likely will
180  for (int row=0; row<h; row++) {
181  //for (int x=0; x<w; x++)
182  // disp_pixels[row*m_pitch + x] = img_pixels[row*image->width + x];
183 
184  std::copy(img_pixels, img_pixels+w, disp_pixels);
185  //std::memcpy(disp_pixels, img_pixels, w);
186 
187  img_pixels += image->width;
188  disp_pixels += m_pitch;
189  }
190 
191  //always set buffer address. someone might have changed it
192  ScrSetDispPage((int)m_display_front);
193  display_update(UPDATE_DISP);
194 
195  //printf("set: disp %x, front %x, back %x\n", ScrGetDispPage, m_display_front, m_display_back);
196 }
197 
199 {
200  const unsigned char* restrict img_pixels = image->pixels;
201  unsigned char* restrict ovl_pixels = (unsigned char*)OvlGetPhysPage;
202 
203 
204  int h = std::min(OvlGetRows, image->height);
205  int w = std::min(OvlGetColumns, image->width);
206  int ovl_pitch = OvlGetPitch;
207 
208  //copy row by row as width may differ and pitch most likely will
209  for (int row=0; row<h; row++) {
210  std::copy(img_pixels, img_pixels+w, ovl_pixels);
211 
212  img_pixels += image->width;
213  ovl_pixels += ovl_pitch;
214  }
215 }
bool m_doubleBuffer
Definition: VCDisplay.h:85
void disable_overlay() const
Definition: VCDisplay.cpp:161
int m_allocated_buffer
Definition: VCDisplay.h:86
int width
The width of the image in pixels.
Definition: ByteImage.h:257
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glext.h:3131
void show(const CByteImage *image)
Definition: VCDisplay.cpp:167
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
Definition: ByteImage.h:80
int m_allocated_backbuffer
Definition: VCDisplay.h:87
unsigned char * pixels
The pointer to the the pixels.
Definition: ByteImage.h:283
void overlay(const CByteImage *ovl)
Definition: VCDisplay.cpp:198
int m_height
Definition: VCDisplay.h:82
int m_pitch
Definition: VCDisplay.h:83
void make_current() const
Definition: VCDisplay.cpp:138
CVCDisplay(bool doubleBuffer, bool show_overlay=false)
Definition: VCDisplay.cpp:83
void enable_overlay() const
Definition: VCDisplay.cpp:154
int height
The height of the image in pixels.
Definition: ByteImage.h:264
void sleep_ms(unsigned int ms)
Definition: helpers.cpp:336
void wait_for_next_frame()
Definition: VCDisplay.cpp:67
GLenum GLenum GLvoid * row
Definition: glext.h:3142
unsigned char *restrict m_display_back
Definition: VCDisplay.h:89
int m_width
Definition: VCDisplay.h:81
GLuint res
Definition: glext.h:5889
void restore_default() const
Definition: VCDisplay.cpp:145
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:3571
unsigned char *restrict m_display_front
Definition: VCDisplay.h:88


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Mon Dec 2 2019 03:47:28