21 #ifndef GV_AVC_READER__H
22 #define GV_AVC_READER__H
32 class AvcReaderStream ;
33 class AvcReaderStreamImp ;
104 unsigned char r(
int x ,
int y )
const ;
107 unsigned char g(
int x ,
int y )
const ;
110 unsigned char b(
int x ,
int y )
const ;
113 unsigned char luma(
int x ,
int y )
const ;
116 unsigned int rgb(
int x ,
int y )
const ;
119 Gr::ImageType fill( std::vector<char> & ,
int scale = 1 ,
bool monochrome =
false ) ;
132 void init(
const unsigned char * p ,
size_t n ) ;
133 unsigned char value(
int c ,
int x ,
int y )
const ;
134 unsigned char value(
int c ,
size_t offset )
const ;
135 unsigned int fullvalue(
int c ,
int x ,
int y )
const ;
136 unsigned int fullvalue(
int c ,
size_t offset )
const ;
137 size_t offset(
int c ,
int x ,
int y )
const ;
142 const unsigned char * data ;
146 unsigned short depth ;
148 unsigned short shift ;
150 unsigned short x_shift ;
151 unsigned short y_shift ;
153 unsigned int fullvalue(
const unsigned char * p ,
bool be )
const ;
154 unsigned char value(
const unsigned char * p ,
bool be )
const ;
155 unsigned char simplevalue(
const unsigned char * p )
const ;
156 size_t rowoffset(
int y )
const ;
157 size_t xoffset(
int x )
const ;
158 size_t simplexoffset(
int x )
const ;
159 bool simple()
const ;
167 unsigned short m_x_shift ;
168 unsigned short m_y_shift ;
174 unsigned char value0()
const ;
175 unsigned char value1()
const ;
176 unsigned char value2()
const ;
177 unsigned char r()
const ;
178 unsigned char g()
const ;
179 unsigned char b()
const ;
180 unsigned char luma()
const ;
189 const unsigned char * m_rp0 ;
190 const unsigned char * m_rp1 ;
191 const unsigned char * m_rp2 ;
193 size_t m_data_big_endian ;
198 unsigned char value0()
const ;
199 unsigned char value1()
const ;
200 unsigned char value2()
const ;
201 unsigned char r()
const ;
202 unsigned char g()
const ;
203 unsigned char b()
const ;
204 unsigned char luma()
const ;
213 const unsigned char * m_rp0 ;
214 const unsigned char * m_rp1 ;
215 const unsigned char * m_rp2 ;
228 init( reinterpret_cast<const unsigned char*>(p) , n ) ;
242 m_data.m_component[0].data !=
nullptr &&
243 m_data.m_component[1].data !=
nullptr &&
244 m_data.m_component[2].data != nullptr ;
251 m_data.m_component[0].simple() &&
252 m_data.m_component[1].simple() &&
253 m_data.m_component[2].simple() ;
271 return m_data.m_rgb ?
Gr::ColourSpace::y_int( value(0,x,y) , value(1,x,y) , value(2,x,y) ) : value(0,x,y) ;
275 unsigned int Gv::AvcReader::fullvalue(
int c ,
size_t offset )
const
278 const Component & comp = m_data.m_component[c] ;
279 return comp.fullvalue( comp.data+offset , m_data.m_big_endian ) ;
283 unsigned int Gv::AvcReader::Component::fullvalue(
const unsigned char * p ,
bool big_endian )
const
285 unsigned int v = *p ;
288 unsigned int v2 = p[1] ;
289 v = big_endian ? ((v<<8)|v2) : ((v2<<8)|v) ;
291 return ( v >> shift ) & mask ;
295 unsigned char Gv::AvcReader::Component::value(
const unsigned char * p ,
bool big_endian )
const
297 unsigned int v = fullvalue( p , big_endian ) ;
306 bool Gv::AvcReader::Component::simple()
const
308 return eightbit && shift == 0 && depth == 8 && step == 1 && ( x_shift == 0 || x_shift == 1 ) ;
312 unsigned char Gv::AvcReader::Component::simplevalue(
const unsigned char * p )
const
319 size_t Gv::AvcReader::Component::rowoffset(
int y )
const
321 size_t yy =
static_cast<size_t>(y) ;
323 return yy*linesize + offset ;
327 size_t Gv::AvcReader::Component::xoffset(
int x )
const
329 size_t xx =
static_cast<size_t>(x) ;
352 size_t Gv::AvcReader::Component::simplexoffset(
int x )
const
356 return x_shift == 0 ?
static_cast<size_t>(x) : static_cast<size_t>(x/2) ;
360 size_t Gv::AvcReader::offset(
int c ,
int x ,
int y )
const
362 const Component & comp = m_data.m_component[c] ;
363 return comp.rowoffset(y) + comp.xoffset(x) ;
367 unsigned int Gv::AvcReader::fullvalue(
int c ,
int x ,
int y )
const
369 return fullvalue( c , offset(c,x,y) ) ;
373 unsigned char Gv::AvcReader::value(
int c ,
size_t offset )
const
375 const Component & comp = m_data.m_component[c] ;
376 return comp.value( comp.data+offset , m_data.m_big_endian ) ;
380 unsigned char Gv::AvcReader::value(
int c ,
int x ,
int y )
const
382 const Component & comp = m_data.m_component[c] ;
383 unsigned int v = fullvalue( c , x , y ) ;
384 if( comp.depth <= 8U )
385 v <<= (8U-comp.depth) ;
387 v >>= (comp.depth-8U) ;
394 return m_data.m_rgb ? value(0,x,y) :
Gr::ColourSpace::r_int( value(0,x,y) , value(1,x,y) , value(2,x,y) ) ;
400 return m_data.m_rgb ? value(1,x,y) :
Gr::ColourSpace::g_int( value(0,x,y) , value(1,x,y) , value(2,x,y) ) ;
406 return m_data.m_rgb ? value(2,x,y) :
Gr::ColourSpace::b_int( value(0,x,y) , value(1,x,y) , value(2,x,y) ) ;
413 ( static_cast<unsigned int>(r(x,y)) << 16 ) |
414 (
static_cast<unsigned int>(g(x,y)) << 8 ) |
415 (
static_cast<unsigned int>(b(x,y)) ) ;
419 Gv::AvcReader::Iterator::Iterator(
const AvcReader & reader ,
int y ,
int scale ) :
423 m_c0(reader.m_data.m_component[0]) ,
424 m_c1(reader.m_data.m_component[1]) ,
425 m_c2(reader.m_data.m_component[2]) ,
426 m_rp0(m_c0.data+m_c0.rowoffset(y)) ,
427 m_rp1(m_c1.data+m_c1.rowoffset(y)) ,
428 m_rp2(m_c2.data+m_c2.rowoffset(y)) ,
429 m_data_rgb(reader.m_data.m_rgb) ,
430 m_data_big_endian(reader.m_data.m_big_endian)
435 Gv::AvcReader::SimpleIterator::SimpleIterator(
const AvcReader & reader ,
int y ,
int scale ) :
439 m_c0(reader.m_data.m_component[0]) ,
440 m_c1(reader.m_data.m_component[1]) ,
441 m_c2(reader.m_data.m_component[2]) ,
442 m_rp0(m_c0.data+m_c0.rowoffset(y)) ,
443 m_rp1(m_c1.data+m_c1.rowoffset(y)) ,
444 m_rp2(m_c2.data+m_c2.rowoffset(y)) ,
445 m_data_rgb(reader.m_data.m_rgb)
450 unsigned char Gv::AvcReader::Iterator::value0()
const
452 return m_c0.value( m_rp0+m_c0.xoffset(m_x) , m_data_big_endian ) ;
456 unsigned char Gv::AvcReader::SimpleIterator::value0()
const
458 return m_c0.simplevalue( m_rp0+m_c0.simplexoffset(m_x) ) ;
462 unsigned char Gv::AvcReader::Iterator::value1()
const
464 return m_c1.value( m_rp1+m_c1.xoffset(m_x) , m_data_big_endian ) ;
468 unsigned char Gv::AvcReader::SimpleIterator::value1()
const
470 return m_c1.simplevalue( m_rp1+m_c1.simplexoffset(m_x) ) ;
474 unsigned char Gv::AvcReader::Iterator::value2()
const
476 return m_c2.value( m_rp2+m_c2.xoffset(m_x) , m_data_big_endian ) ;
480 unsigned char Gv::AvcReader::SimpleIterator::value2()
const
482 return m_c2.simplevalue( m_rp2+m_c2.simplexoffset(m_x) ) ;
486 unsigned char Gv::AvcReader::Iterator::r()
const
488 return m_data_rgb ? value0() : Gr::ColourSpace::
r_int( value0() , value1() , value2() ) ;
492 unsigned char Gv::AvcReader::SimpleIterator::r()
const
494 return m_data_rgb ? value0() : Gr::ColourSpace::
r_int( value0() , value1() , value2() ) ;
498 unsigned char Gv::AvcReader::Iterator::g()
const
500 return m_data_rgb ? value1() : Gr::ColourSpace::
g_int( value0() , value1() , value2() ) ;
504 unsigned char Gv::AvcReader::SimpleIterator::g()
const
506 return m_data_rgb ? value1() : Gr::ColourSpace::
g_int( value0() , value1() , value2() ) ;
510 unsigned char Gv::AvcReader::Iterator::b()
const
512 return m_data_rgb ? value2() : Gr::ColourSpace::
b_int( value0() , value1() , value2() ) ;
516 unsigned char Gv::AvcReader::SimpleIterator::b()
const
518 return m_data_rgb ? value2() : Gr::ColourSpace::
b_int( value0() , value1() , value2() ) ;
522 unsigned char Gv::AvcReader::Iterator::luma()
const
528 unsigned char Gv::AvcReader::SimpleIterator::luma()
const
534 void Gv::AvcReader::Iterator::operator++()
540 void Gv::AvcReader::SimpleIterator::operator++()
static bool available()
Returns true if the decoder library is built in.
bool simple() const
Returns true if the data format is simple enough for the optimised iterator, Gv::AvcReader::SimpleIte...
A decoder for an AVC (aka H.264) video packet.
int dx() const
Returns the image width.
unsigned char b_int(unsigned char y, unsigned char u, unsigned char) g__noexcept
A fast conversion from yuv to b.
unsigned char luma(int x, int y) const
Returns a pixel luma value.
bool valid() const
Returns true if a picture was decoded successfully.
Contains AVC configuration parameters, initialised from an "avcC" file segment or from an SDP "fmtp" ...
An encapsulation of image type, including width, height and number of channels, with support for a st...
unsigned char g(int x, int y) const
Returns a pixel green value.
Describes one plane of a Gv::AvcReader image, and points to its data.
int dx() const
Returns the image width as indicated by the first SPS structure, or zero if default constructed...
int dy() const
Returns the image height.
~AvcReaderStream()
Destructor.
int dy() const
Returns the image height as indicated by the first SPS structure, or zero if default constructed...
unsigned char g_int(unsigned char y, unsigned char u, unsigned char v) g__noexcept
A fast conversion from yuv to g.
unsigned char b(int x, int y) const
Returns a pixel blue value.
AvcReaderStream()
Default constructor.
bool keyframe() const
Returns true if a key frame.
unsigned char r(int x, int y) const
Returns a pixel red value.
unsigned char r_int(unsigned char y, unsigned char, unsigned char v) g__noexcept
A fast conversion from yuv to r.
A private pimple class for Gv::AvcReaderStream, holding AVCode, AVCodecContext and AVFrame libav obje...
AvcReader(AvcReaderStream &stream, const char *p, size_t n)
Constructor taking a complete NALU data buffer, including a leading four-byte 00-00-00-01 start code...
unsigned char y_int(unsigned char r, unsigned char g, unsigned char b)
A fast conversion from rgb to y.
Holds state for an AVC (aka H.264) decoder.
A row iterator for Gv::AvcReader providing r/g/b or y/u/v across a row.
unsigned int rgb(int x, int y) const
Returns the three rgb values packed into one integer.
Gr::ImageType fill(std::vector< char > &, int scale=1, bool monochrome=false)
Fills the supplied buffer with RGB or greyscale image data and returns the raw image type...
Describes a Gv::AvcReader image, and points to its data via up to four Components.
An optimised row iterator for Gv::AvcReader when simple().