PTLib  Version 2.12.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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: 28399 $
29  * $Author: rjongbloed $
30  * $Date: 2012-09-25 18:35:40 +1000 (Tue, 25 Sep 2012) $
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 {
82  PCLASSINFO(PColourConverter, PObject);
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 
104  bool GetVFlipState() const
105  { return m_verticalFlip; }
106 
110  bool vFlipState
111  ) { m_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 
188 
192 
199 
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 
271  unsigned & width,
272  unsigned & height
273  ) const;
274 
278  unsigned & width,
279  unsigned & height
280  ) const;
281 
282  unsigned GetSrcFrameWidth() const { return m_srcFrameWidth; }
283  unsigned GetSrcFrameHeight() const { return m_srcFrameHeight; }
284  unsigned GetDstFrameWidth() const { return m_dstFrameWidth; }
285  unsigned GetDstFrameHeight() const { return m_dstFrameHeight; }
286 
290  PVideoFrameInfo::ResizeMode mode
291  ) { if (mode < PVideoFrameInfo::eMaxResizeMode) m_resizeMode = mode; }
292 
295  PVideoFrameInfo::ResizeMode GetResizeMode() const { return m_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 
325  static bool RotateYUV420P(
326  int angle, unsigned width, unsigned height, BYTE * srcYUV, BYTE * dstYUV = NULL
327  );
328 
331  static bool FillYUV420P(
332  unsigned x, unsigned y, unsigned width, unsigned height,
333  unsigned frameWidth, unsigned frameHeight, BYTE * yuv,
334  unsigned r, unsigned g, unsigned b
335  );
336 
337  protected:
338  void Construct(
339  const PVideoFrameInfo & src,
340  const PVideoFrameInfo & dst
341  );
342 
345  unsigned m_srcFrameWidth;
348 
349  // Needed for resizing
350  unsigned m_dstFrameWidth;
353 
354  PVideoFrameInfo::ResizeMode m_resizeMode;
356 
358 
360 };
361 
362 
368 #define PCOLOUR_CONVERTER2(cls,ancestor,srcFmt,dstFmt) \
369 class cls : public ancestor { \
370  public: \
371  cls(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) \
372  : ancestor(src, dst) { } \
373  virtual PBoolean Convert(const BYTE *, BYTE *, PINDEX * = NULL); \
374  virtual PBoolean Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL); \
375 }; \
376 static class cls##_Registration : public PColourConverterRegistration { \
377  public: cls##_Registration() \
378  : PColourConverterRegistration(srcFmt,dstFmt) { } \
379  protected: virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const; \
380 } p_##cls##_registration_instance; \
381 PColourConverter * cls##_Registration::Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const \
382  { return new cls(src, dst); } \
383 PBoolean cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, unsigned int srcFrameBytes, PINDEX * bytesReturned) \
384  { m_srcFrameBytes = srcFrameBytes;return Convert(srcFrameBuffer, dstFrameBuffer, bytesReturned); } \
385 PBoolean cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, PINDEX * bytesReturned)
386 
387 
393 #define PCOLOUR_CONVERTER(cls,src,dst) \
394  PCOLOUR_CONVERTER2(cls,PColourConverter,src,dst)
395 
396 
397 
403  public:
405  const PVideoFrameInfo & src,
406  const PVideoFrameInfo & dst
407  ) : PColourConverter(src, dst) { }
408  virtual PBoolean Convert(const BYTE *, BYTE *, PINDEX * = NULL);
409  virtual PBoolean Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL);
410 };
411 
412 
418  public:
420  const char * srcFmt,
421  const char * dstFmt
422  );
423 
424  protected:
425  virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const;
426 };
427 
428 
433 #define PSYNONYM_COLOUR_CONVERTER(from,to) \
434  static PSynonymColourRegistration p_##from##_##to##_registration_instance(#from,#to)
435 
436 
437 #endif // P_VIDEO
438 
439 #endif // PTLIB_CONVERT_H
440 
441 
442 // End of file ///////////////////////////////////////////////////////////////