29 void * memalign_(
void **aligned_p ,
size_t page ,
size_t n )
32 void * p = malloc( n + page + 1 ) ;
33 char *pp =
reinterpret_cast<char*
>(p) ;
34 while( (reinterpret_cast<unsigned long>(pp) % page) != 0 )
49 m_freeme = m_start = malloc( length ) ;
50 if( m_start ==
nullptr )
51 throw std::runtime_error(
"out of memory" ) ;
62 G_ASSERT( p !=
nullptr ) ;
67 m_length(size4(buffer_size)) ,
71 m_freeme = memalign_( &m_start , page_size , buffer_size ) ;
72 if( m_start ==
nullptr )
73 throw std::runtime_error(
"out of memory" ) ;
84 G_IGNORE_RETURN(
int , (*m_unmap)( m_start, m_length ) ) ;
95 void Gv::CaptureBuffer::checkFormat()
const
98 G_ASSERT( m_scale.m_dx > 0U && m_scale.m_dy > 1U ) ;
99 const size_t x_1 = m_scale.m_dx - 1U ;
100 const size_t y_1 = m_scale.m_dy - 1U ;
101 const size_t offset_0 = m_format->component(0).offset(x_1,y_1,m_scale) ;
102 const size_t offset_1 = m_format->component(1).offset(x_1,y_1,m_scale) ;
103 const size_t offset_2 = m_format->component(2).offset(x_1,y_1,m_scale) ;
104 const size_t max_offset = std::max(offset_0,std::max(offset_1,offset_2)) ;
105 G_ASSERT( max_offset < size() ) ;
107 if( max_offset >= size() )
108 throw std::runtime_error(
"pixelformat inconsistent with capture buffer size" ) ;
113 if( m_format->is_simple() && m_scale.is_simple(data.
dx(),data.
dy()) && data.
channels() == 3 )
115 G_ASSERT( data.
rowsize() == m_scale.m_linesize ) ;
116 const size_t rowsize = data.
rowsize() ;
117 const unsigned char * p_in = begin() ;
118 for(
size_t y = 0U ; y < m_scale.m_dy ; y++ , p_in += rowsize )
120 std::memcpy( data.
row(y) , p_in , rowsize ) ;
125 for(
size_t y = 0U ; y < m_scale.m_dy ; y++ )
128 for(
size_t x = 0U ; x < m_scale.m_dx ; x++ , ++bp )
131 const triple_t &
rgb = *bp ;
132 data.
rgb( x , y , rgb.r() , rgb.g() , rgb.b() ) ;
140 G_ASSERT( p_out !=
nullptr && dx > 0 && dy > 0 && n_out > 0U ) ;
141 G_ASSERT( n_out == (
size_t(dx)*
size_t(dy)*
size_t(3U)) ) ;
142 if( p_out ==
nullptr || n_out != (
size_t(dx)*
size_t(dy)*
size_t(3U)) )
143 throw std::runtime_error(
"capture buffer size mismatch" ) ;
145 if( m_format->is_simple() && m_scale.is_simple(dx,dy) )
147 G_ASSERT( n_out == size() ) ;
148 std::memcpy( p_out , begin() , std::min(n_out,size()) ) ;
152 unsigned char *
const p_end = p_out + n_out ;
153 for(
int y = 0 ; y < dy ; y++ )
156 if( (p_out+dx+dx+dx) > p_end ) break ;
157 for(
int x = 0 ; x < dx ; x++ , ++bp )
171 copy( dx , dy , reinterpret_cast<unsigned char *>(p_out) , n ) ;
185 m_linesize_shift(0) ,
191 size_t step_ ,
unsigned short depth_ ,
unsigned short shift_ , Type type_ ,
short linesize_shift_ ) :
193 m_x_shift(x_shift_) ,
194 m_y_shift(y_shift_) ,
200 m_linesize_shift(linesize_shift_) ,
201 m_simple(m_depth==8&&m_type==c_byte&&m_shift==0)
203 m_mask = (1U << m_depth) - 1U ;
228 return m_type ==
rgb && m_c[0].is_simple(0) && m_c[1].is_simple(1) && m_c[2].is_simple(2) ;
triple< unsigned char > rgb(triple< unsigned char > yuv) g__noexcept
A top-level function that calculates rgb from yuv with default implementation options.
size_t rowsize() const
Returns the row size, ie. dx()*channels().
int dx() const
Returns the width.
A holder for image data, having eight bits per sample and one or three channels.
A const iterator for a single row of Gv::CaptureBuffer pixels.
unsigned char * row(int y)
Returns a pointer to the y'th row.
CaptureBuffer(size_t length)
Constructor for a malloc()ed buffer suitable for "read()" i/o.
void setFormat(const CaptureBufferFormat &, const CaptureBufferScale &)
Used by the Gv::Capture class to imbue the buffer with a particular format description and scale...
~CaptureBuffer()
Destructor.
CaptureBufferComponent()
Default constructor for a simple step-three component.
int channels() const
Returns the number of channels (zero, one or three).
A structure holding capture buffer dimensions.
unsigned int rgb(int x, int y) const
Returns the colour of a pixel as rgb values packed into one integer.
void copyTo(Gr::ImageData &) const
Copies the image to a correctly-sized image data buffer.
int dy() const
Returns the height.
void copy(int dx, int dy, char *p_out, size_t out_size) const
Copies the image to an rgb output buffer.
A descriptor for one colour component in a Gv::CaptureBufferFormat structure.