PTLib  Version 2.10.11
vconvert.h
Go to the documentation of this file.
1 /*
2  * vconvert.h
3  *
4  * Classes to support streaming video input (grabbing) and output.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-2000 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Contributor(s): Derek Smithies (derek@indranet.co.nz)
25  * Thorsten Westheider (thorsten.westheider@teleos-web.de)
26  * Mark Cooke (mpc@star.sr.bham.ac.uk)
27  *
28  * $Revision: 26686 $
29  * $Author: rjongbloed $
30  * $Date: 2011-11-23 20:22:20 -0600 (Wed, 23 Nov 2011) $
31  */
32 
33 #ifndef PTLIB_CONVERT_H
34 #define PTLIB_CONVERT_H
35 
36 #ifdef P_USE_PRAGMA
37 #ifndef P_MACOSX
38 #pragma interface
39 #endif
40 #endif
41 
42 #include <ptbuildopts.h>
43 
44 #if P_VIDEO
45 
46 #include <ptlib/videoio.h>
47 
48 struct jdec_private;
49 
50 
57 {
59  public:
61  const PString & srcColourFormat,
62  const PString & destColourFormat
63  );
64 
65  protected:
66  virtual PColourConverter * Create(
67  const PVideoFrameInfo & src,
68  const PVideoFrameInfo & dst
69  ) const = 0;
70 
72 
73  friend class PColourConverter;
74 };
75 
76 
80 class PColourConverter : public PObject
81 {
83  public:
87  const PString & srcColourFormat,
88  const PString & dstColourFormat,
89  unsigned width,
90  unsigned height
91  );
93  const PVideoFrameInfo & src,
94  const PVideoFrameInfo & dst
95  );
96 
98  virtual void PrintOn(
99  ostream & strm
100  ) const;
101 
105  { return verticalFlip; }
106 
110  PBoolean vFlipState
111  ) { verticalFlip = vFlipState; }
112 
117  virtual PBoolean SetFrameSize(
118  unsigned width,
119  unsigned height
120  );
121 
130  virtual PBoolean SetSrcFrameInfo(
131  const PVideoFrameInfo & info
132  );
133 
142  virtual PBoolean SetDstFrameInfo(
143  const PVideoFrameInfo & info
144  );
145 
148  virtual void GetSrcFrameInfo(
149  PVideoFrameInfo & info
150  );
151 
154  virtual void GetDstFrameInfo(
155  PVideoFrameInfo & info
156  );
157 
164  virtual PBoolean SetSrcFrameSize(
165  unsigned width,
166  unsigned height
167  );
168 
175  virtual PBoolean SetDstFrameSize(
176  unsigned width,
177  unsigned height
178  );
179  virtual PBoolean SetDstFrameSize(
180  unsigned width,
181  unsigned height,
182  PBoolean bScale
183  );
184 
187  const PString & GetSrcColourFormat() { return srcColourFormat; }
188 
191  const PString & GetDstColourFormat() { return dstColourFormat; }
192 
198  PINDEX GetMaxSrcFrameBytes() { return srcFrameBytes; }
199 
205  PINDEX GetMaxDstFrameBytes() { return dstFrameBytes; }
206 
207 
217  virtual PBoolean Convert(
218  const BYTE * srcFrameBuffer,
219  BYTE * dstFrameBuffer,
220  PINDEX * bytesReturned = NULL
221  ) = 0;
222 
223  virtual PBoolean Convert(
224  const BYTE * srcFrameBuffer,
225  BYTE * dstFrameBuffer,
226  unsigned int srcFrameBytes,
227  PINDEX * bytesReturned = NULL
228  ) = 0;
229 
246  virtual PBoolean ConvertInPlace(
247  BYTE * frameBuffer,
248  PINDEX * bytesReturned = NULL,
249  PBoolean noIntermediateFrame = false
250  );
251 
252 
257  static PColourConverter * Create(
258  const PVideoFrameInfo & src,
259  const PVideoFrameInfo & dst
260  );
261  static PColourConverter * Create(
262  const PString & srcColourFormat,
263  const PString & destColourFormat,
264  unsigned width,
265  unsigned height
266  );
267 
270  PBoolean GetDstFrameSize(
271  unsigned & width,
272  unsigned & height
273  ) const;
274 
277  PBoolean GetSrcFrameSize(
278  unsigned & width,
279  unsigned & height
280  ) const;
281 
282  unsigned GetSrcFrameWidth() const { return srcFrameWidth; }
283  unsigned GetSrcFrameHeight() const { return srcFrameHeight; }
284  unsigned GetDstFrameWidth() const { return dstFrameWidth; }
285  unsigned GetDstFrameHeight() const { return dstFrameHeight; }
286 
291  ) { if (mode < PVideoFrameInfo::eMaxResizeMode) resizeMode = mode; }
292 
295  PVideoFrameInfo::ResizeMode GetResizeMode() const { return resizeMode; }
296 
299  static void RGBtoYUV(
300  unsigned r, unsigned g, unsigned b,
301  unsigned & y, unsigned & u, unsigned & v
302  );
303  static void RGBtoYUV(
304  unsigned r, unsigned g, unsigned b,
305  BYTE & y, BYTE & u, BYTE & v
306  );
307 
311  static bool CopyYUV420P(
312  unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
313  unsigned srcFrameWidth, unsigned srcFrameHeight, const BYTE * srcYUV,
314  unsigned dstX, unsigned dstY, unsigned dstWidth, unsigned dstHeight,
315  unsigned dstFrameWidth, unsigned dstFrameHeight, BYTE * dstYUV,
316  PVideoFrameInfo::ResizeMode resizeMode
317  );
318 
319  static bool FillYUV420P(
320  unsigned x, unsigned y, int width, int height,
321  unsigned frameWidth, unsigned frameHeight, BYTE * yuv,
322  unsigned r, unsigned g, unsigned b
323  );
324 
325  protected:
326  void Construct(
327  const PVideoFrameInfo & src,
328  const PVideoFrameInfo & dst
329  );
330 
333  unsigned srcFrameWidth;
334  unsigned srcFrameHeight;
335  unsigned srcFrameBytes;
336 
337  // Needed for resizing
338  unsigned dstFrameWidth;
339  unsigned dstFrameHeight;
340  unsigned dstFrameBytes;
341 
343 
345 
347 
348 #ifndef P_MACOSX
349  /* Use by the jpeg decompressor */
350  struct jdec_private *jdec;
351 #endif
352 
354 };
355 
356 
362 #define PCOLOUR_CONVERTER2(cls,ancestor,srcFmt,dstFmt) \
363 class cls : public ancestor { \
364  public: \
365  cls(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) \
366  : ancestor(src, dst) { } \
367  virtual PBoolean Convert(const BYTE *, BYTE *, PINDEX * = NULL); \
368  virtual PBoolean Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL); \
369 }; \
370 static class cls##_Registration : public PColourConverterRegistration { \
371  public: cls##_Registration() \
372  : PColourConverterRegistration(srcFmt,dstFmt) { } \
373  protected: virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const; \
374 } p_##cls##_registration_instance; \
375 PColourConverter * cls##_Registration::Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const \
376  { return new cls(src, dst); } \
377 PBoolean cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, unsigned int p_srcFrameBytes, PINDEX * bytesReturned) \
378  { srcFrameBytes = p_srcFrameBytes;return Convert(srcFrameBuffer, dstFrameBuffer, bytesReturned); } \
379 PBoolean cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, PINDEX * bytesReturned)
380 
381 
387 #define PCOLOUR_CONVERTER(cls,src,dst) \
388  PCOLOUR_CONVERTER2(cls,PColourConverter,src,dst)
389 
390 
391 
397  public:
399  const PVideoFrameInfo & src,
400  const PVideoFrameInfo & dst
401  ) : PColourConverter(src, dst) { }
402  virtual PBoolean Convert(const BYTE *, BYTE *, PINDEX * = NULL);
403  virtual PBoolean Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL);
404 };
405 
406 
412  public:
414  const char * srcFmt,
415  const char * dstFmt
416  );
417 
418  protected:
419  virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const;
420 };
421 
422 
427 #define PSYNONYM_COLOUR_CONVERTER(from,to) \
428  static PSynonymColourRegistration p_##from##_##to##_registration_instance(#from,#to)
429 
430 
431 #endif // P_VIDEO
432 
433 #endif // PTLIB_CONVERT_H
434 
435 
436 // End of file ///////////////////////////////////////////////////////////////
virtual void PrintOn(ostream &strm) const
Output the string to the specified stream.
ResizeMode
Definition: videoio.h:54
unsigned dstFrameWidth
Definition: vconvert.h:338
PColourConverterRegistration * link
Definition: vconvert.h:71
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
PINDEX GetMaxDstFrameBytes()
Get the maximum frame size in bytes for destination frames.
Definition: vconvert.h:205
friend class PColourConverter
Definition: vconvert.h:73
const PString & GetDstColourFormat()
Get the destination colour format.
Definition: vconvert.h:191
unsigned GetDstFrameHeight() const
Definition: vconvert.h:285
PSynonymColour(const PVideoFrameInfo &src, const PVideoFrameInfo &dst)
Definition: vconvert.h:398
PBoolean GetVFlipState()
Get the video conversion vertical flip state.
Definition: vconvert.h:104
PBYTEArray intermediateFrameStore
Definition: vconvert.h:346
This class is a variation of a string that ignores case.
Definition: pstring.h:1708
Definition: videoio.h:59
PBoolean verticalFlip
Definition: vconvert.h:344
unsigned srcFrameHeight
Definition: vconvert.h:334
unsigned srcFrameWidth
Definition: vconvert.h:333
unsigned srcFrameBytes
Definition: vconvert.h:335
BOOL PBoolean
Definition: object.h:102
Definition: videoio.h:49
Array of unsigned characters.
Definition: array.h:670
void SetVFlipState(PBoolean vFlipState)
Set the video conversion vertical flip state.
Definition: vconvert.h:109
void SetResizeMode(PVideoFrameInfo::ResizeMode mode)
Set the resize mode to be used.
Definition: vconvert.h:289
virtual PColourConverter * Create(const PVideoFrameInfo &src, const PVideoFrameInfo &dst) const =0
Define synonym colour format registration.
Definition: vconvert.h:411
const PString & GetSrcColourFormat()
Get the source colour format.
Definition: vconvert.h:187
PVideoFrameInfo::ResizeMode GetResizeMode() const
Get the resize mode to be used.
Definition: vconvert.h:295
PColourConverterRegistration(const PString &srcColourFormat, const PString &destColourFormat)
The character string class.
Definition: pstring.h:108
Define synonym colour format converter.
Definition: vconvert.h:396
PString srcColourFormat
Definition: vconvert.h:331
This class registers a colour conversion class.
Definition: vconvert.h:56
This class defines a means to convert an image from one colour format to another. ...
Definition: vconvert.h:80
unsigned dstFrameHeight
Definition: vconvert.h:339
PINDEX GetMaxSrcFrameBytes()
Get the maximum frame size in bytes for source frames.
Definition: vconvert.h:198
unsigned dstFrameBytes
Definition: vconvert.h:340
unsigned GetSrcFrameWidth() const
Definition: vconvert.h:282
PVideoFrameInfo::ResizeMode resizeMode
Definition: vconvert.h:342
unsigned GetSrcFrameHeight() const
Definition: vconvert.h:283
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PString dstColourFormat
Definition: vconvert.h:332
unsigned GetDstFrameWidth() const
Definition: vconvert.h:284
struct jdec_private * jdec
Definition: vconvert.h:350