PTLib  Version 2.14.3
 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: 30106 $
29  * $Author: rjongbloed $
30  * $Date: 2013-07-04 18:12:37 +1000 (Thu, 04 Jul 2013) $
31  */
32 
33 #ifndef PTLIB_CONVERT_H
34 #define PTLIB_CONVERT_H
35 
36 #ifdef P_USE_PRAGMA
37 #pragma interface
38 #endif
39 
40 #include <ptlib.h>
41 
42 #if P_VIDEO
43 
44 #include <ptlib/videoio.h>
45 
46 struct jdec_private;
47 
48 
55 {
57  public:
59  const PString & srcColourFormat,
60  const PString & destColourFormat
61  );
62 
63  protected:
64  virtual PColourConverter * Create(
65  const PVideoFrameInfo & src,
66  const PVideoFrameInfo & dst
67  ) const = 0;
68 
70 
71  friend class PColourConverter;
72 };
73 
74 
78 class PColourConverter : public PObject
79 {
80  PCLASSINFO(PColourConverter, PObject);
81  public:
85  const PString & srcColourFormat,
86  const PString & dstColourFormat,
87  unsigned width,
88  unsigned height
89  );
91  const PVideoFrameInfo & src,
92  const PVideoFrameInfo & dst
93  );
94 
96  virtual void PrintOn(
97  ostream & strm
98  ) const;
99 
102  bool GetVFlipState() const
103  { return m_verticalFlip; }
104 
108  bool vFlipState
109  ) { m_verticalFlip = vFlipState; }
110 
115  virtual PBoolean SetFrameSize(
116  unsigned width,
117  unsigned height
118  );
119 
128  virtual PBoolean SetSrcFrameInfo(
129  const PVideoFrameInfo & info
130  );
131 
140  virtual PBoolean SetDstFrameInfo(
141  const PVideoFrameInfo & info
142  );
143 
146  virtual void GetSrcFrameInfo(
147  PVideoFrameInfo & info
148  );
149 
152  virtual void GetDstFrameInfo(
153  PVideoFrameInfo & info
154  );
155 
162  virtual PBoolean SetSrcFrameSize(
163  unsigned width,
164  unsigned height
165  );
166 
173  virtual PBoolean SetDstFrameSize(
174  unsigned width,
175  unsigned height
176  );
177  virtual PBoolean SetDstFrameSize(
178  unsigned width,
179  unsigned height,
180  PBoolean bScale
181  );
182 
185  const PString & GetSrcColourFormat() const { return m_srcColourFormat; }
186 
189  const PString & GetDstColourFormat() const { return m_dstColourFormat; }
190 
196  PINDEX GetMaxSrcFrameBytes() const { return m_srcFrameBytes; }
197 
203  void SetSrcFrameBytes(PINDEX frameBytes) { m_srcFrameBytes = frameBytes; }
204 
210  PINDEX GetMaxDstFrameBytes() const { return m_dstFrameBytes; }
211 
212 
222  virtual PBoolean Convert(
223  const BYTE * srcFrameBuffer,
224  BYTE * dstFrameBuffer,
225  PINDEX * bytesReturned = NULL
226  ) = 0;
227 
244  virtual PBoolean ConvertInPlace(
245  BYTE * frameBuffer,
246  PINDEX * bytesReturned = NULL,
247  PBoolean noIntermediateFrame = false
248  );
249 
250 
255  static PColourConverter * Create(
256  const PVideoFrameInfo & src,
257  const PVideoFrameInfo & dst
258  );
259  static PColourConverter * Create(
260  const PString & srcColourFormat,
261  const PString & destColourFormat,
262  unsigned width,
263  unsigned height
264  );
265 
269  unsigned & width,
270  unsigned & height
271  ) const;
272 
276  unsigned & width,
277  unsigned & height
278  ) const;
279 
280  unsigned GetSrcFrameWidth() const { return m_srcFrameWidth; }
281  unsigned GetSrcFrameHeight() const { return m_srcFrameHeight; }
282  unsigned GetDstFrameWidth() const { return m_dstFrameWidth; }
283  unsigned GetDstFrameHeight() const { return m_dstFrameHeight; }
284 
288  PVideoFrameInfo::ResizeMode mode
289  ) { if (mode < PVideoFrameInfo::eMaxResizeMode) m_resizeMode = mode; }
290 
293  PVideoFrameInfo::ResizeMode GetResizeMode() const { return m_resizeMode; }
294 
297  static void RGBtoYUV(
298  unsigned r, unsigned g, unsigned b,
299  unsigned & y, unsigned & u, unsigned & v
300  );
301  static void RGBtoYUV(
302  unsigned r, unsigned g, unsigned b,
303  BYTE & y, BYTE & u, BYTE & v
304  );
305 
309  static bool CopyYUV420P(
310  unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
311  unsigned srcFrameWidth, unsigned srcFrameHeight, const BYTE * srcYUV,
312  unsigned dstX, unsigned dstY, unsigned dstWidth, unsigned dstHeight,
313  unsigned dstFrameWidth, unsigned dstFrameHeight, BYTE * dstYUV,
314  PVideoFrameInfo::ResizeMode resizeMode
315  );
316 
323  static bool RotateYUV420P(
324  int angle, unsigned width, unsigned height, BYTE * srcYUV, BYTE * dstYUV = NULL
325  );
326 
329  static bool FillYUV420P(
330  unsigned x, unsigned y, unsigned width, unsigned height,
331  unsigned frameWidth, unsigned frameHeight, BYTE * yuv,
332  unsigned r, unsigned g, unsigned b
333  );
334 
335  protected:
336  void Construct(
337  const PVideoFrameInfo & src,
338  const PVideoFrameInfo & dst
339  );
340 
343  unsigned m_srcFrameWidth;
346 
347  // Needed for resizing
348  unsigned m_dstFrameWidth;
351 
352  PVideoFrameInfo::ResizeMode m_resizeMode;
354 
356 
357  P_REMOVE_VIRTUAL(PBoolean,Convert(const BYTE*,BYTE*,unsigned,PINDEX*),false);
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 }; \
375 static class cls##_Registration : public PColourConverterRegistration { \
376  public: cls##_Registration() \
377  : PColourConverterRegistration(srcFmt,dstFmt) { } \
378  protected: virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const; \
379 } p_##cls##_registration_instance; \
380 PColourConverter * cls##_Registration::Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const \
381  { return new cls(src, dst); } \
382 PBoolean cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, PINDEX * bytesReturned) \
383 
384 
390 #define PCOLOUR_CONVERTER(cls,src,dst) \
391  PCOLOUR_CONVERTER2(cls,PColourConverter,src,dst)
392 
393 
394 
400  public:
402  const PVideoFrameInfo & src,
403  const PVideoFrameInfo & dst
404  ) : PColourConverter(src, dst) { }
405  virtual PBoolean Convert(const BYTE *, BYTE *, PINDEX * = NULL);
406 };
407 
408 
414  public:
416  const char * srcFmt,
417  const char * dstFmt
418  );
419 
420  protected:
421  virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const;
422 };
423 
424 
429 #define PSYNONYM_COLOUR_CONVERTER(from,to) \
430  static PSynonymColourRegistration p_##from##_##to##_registration_instance(#from,#to)
431 
432 
433 #if P_JPEG_DECODER
434 
435 class PJPEGConverter : public PColourConverter
436 {
437  protected:
438  struct Context;
439  Context * m_context;
440 
441  public:
442  PJPEGConverter(const PVideoFrameInfo & src, const PVideoFrameInfo & dst);
443  ~PJPEGConverter();
444 
445  virtual PBoolean Convert(
446  const BYTE * srcFrameBuffer,
447  BYTE * dstFrameBuffer,
448  PINDEX * bytesReturned = NULL
449  );
450 
451  bool Load(
452  PFile & file,
453  PBYTEArray & dstFrameBuffer
454  );
455 };
456 
457 #endif // P_JPEG_DECODER
458 
459 #endif // P_VIDEO
460 
461 #endif // PTLIB_CONVERT_H
462 
463 
464 // End of file ///////////////////////////////////////////////////////////////