AVPKit
PixelFormat.h
1 /*******************************************************************************
2  * Copyright (c) 2024, 2026, Olivier Ayache. All rights reserved.
3  *
4  * This file is part of AVPKit.
5  *
6  * AVPKit is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * AVPKit is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with AVPKit. If not, see <http://www.gnu.org/licenses/>.
18  *******************************************************************************/
19 
20 #ifndef PIXELFORMAT_H_
21 #define PIXELFORMAT_H_
22 #include <com/avpkit/core/AVPKit.h>
23 #include <com/avpkit/core/IPixelFormat.h>
24 
25 namespace com { namespace avpkit { namespace core
26 {
27  class PixelFormat : public IPixelFormat {
28  public:
29 #ifndef SWIG
30  /*
31  * Inline version of prior function that does the same thing, but has no error
32  * checking.
33  *
34  * This code is very tricky; it relies on /2 shaving off odd digits.
35  *
36  */
37  static int getFastYUV420PPixelOffset(int width, int height,
38  int x, int y,
39  IPixelFormat::YUVColorComponent c)
40  {
41  int retval = 0;
42  switch(c)
43  {
44  case IPixelFormat::YUV_Y:
45  {
46  retval = y*width+x;
47  }
48  break;
49  case IPixelFormat::YUV_U:
50  {
51  int area = width*height;
52  int w2 = (width+1)>>1;
53  retval = (y>>1)*w2+(x>>1)+area;
54  }
55  break;
56  case IPixelFormat::YUV_V:
57  {
58  int area = width*height;
59  int w2 = (width+1)>>1;
60  int h2 = (height+1)>>1;
61  int area2 = w2*h2;
62  retval = (y>>1)*w2+(x>>1)+area+area2;
63  }
64  break;
65  }
66  return retval;
67  }
68 #endif
69  };
70 }}}
71 #endif // ! PIXELFORMAT_H_
72 
Information about how video data is formatted in an IVideoPicture object.
Definition: IPixelFormat.h:45
WARNING: Do not use logging in this class, and do not set any static file variables to values other t...