1 /*
2  *  frameinfo.h
3  *
4  *  Copyright (C) Georg Martius - June 2007 - 2011
5  *   georg dot martius at web dot de
6  *
7  *  This file is part of vid.stab video stabilization library
8  *
9  *  vid.stab is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License,
11  *  as published by the Free Software Foundation; either version 2, or
12  *  (at your option) any later version.
13  *
14  *  vid.stab is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with GNU Make; see the file COPYING.  If not, write to
21  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  */
24 #ifndef FRAMEINFO_H
25 #define FRAMEINFO_H
26 
27 #include <stddef.h>
28 #include <stdlib.h>
29 #include <inttypes.h>
30 
31 /// pixel formats
32 typedef enum {PF_NONE = -1,
33               PF_GRAY8,     ///<        Y        ,  8bpp
34               PF_YUV420P,   ///< planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
35               PF_YUV422P,   ///< planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
36               PF_YUV444P,   ///< planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
37               PF_YUV410P,   ///< planar YUV 4:1:0,  9bpp, (1 Cr & Cb sample per 4x4 Y samples)
38               PF_YUV411P,   ///< planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
39               PF_YUV440P,   ///< planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
40               PF_YUVA420P,  ///< planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
41               PF_PACKED,    ///< dummy: packed formats start here
42               PF_RGB24,     ///< packed RGB 8:8:8, 24bpp, RGBRGB...
43               PF_BGR24,     ///< packed RGB 8:8:8, 24bpp, BGRBGR...
44               PF_RGBA,      ///< packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
45               PF_NUMBER     ///< number of pixel formats
46 } VSPixelFormat;
47 
48 /** frame information for deshaking lib
49     This only works for planar image formats
50  */
51 typedef struct vsframeinfo {
52   int width, height;
53   int planes;        // number of planes (1 luma, 2,3 chroma, 4 alpha)
54   int log2ChromaW; // subsampling of width in chroma planes
55   int log2ChromaH; // subsampling of height in chroma planes
56   VSPixelFormat pFormat;
57   int bytesPerPixel; // number of bytes per pixel (for packed formats)
58 } VSFrameInfo;
59 
60 /** frame data according to frameinfo
61  */
62 typedef struct vsframe {
63   uint8_t* data[4]; // data in planes. For packed data everthing is in plane 0
64   int linesize[4]; // line size of each line in a the planes
65 } VSFrame;
66 
67 // use it to calculate the CHROMA sizes (rounding is correct)
68 #define CHROMA_SIZE(width,log2sub)  (-(-(width) >> (log2sub)))
69 
70 /// initializes the frameinfo for the given format
71 int vsFrameInfoInit(VSFrameInfo* fi, int width, int height, VSPixelFormat pFormat);
72 
73 
74 /// returns the subsampling shift amount, horizonatally for the given plane
75 int vsGetPlaneWidthSubS(const VSFrameInfo* fi, int plane);
76 
77 /// returns the subsampling shift amount, vertically for the given plane
78 int vsGetPlaneHeightSubS(const VSFrameInfo* fi, int plane);
79 
80 /// zero initialization
81 void vsFrameNull(VSFrame* frame);
82 
83 /// returns true if frame is null (data[0]==0)
84 int vsFrameIsNull(const VSFrame* frame);
85 
86 /// compares two frames for identity (based in data[0])
87 int vsFramesEqual(const VSFrame* frame1,const VSFrame* frame2);
88 
89 /// allocates memory for a frame
90 void vsFrameAllocate(VSFrame* frame, const VSFrameInfo* fi);
91 
92 
93 /// copies the given plane number from src to dest
94 void vsFrameCopyPlane(VSFrame* dest, const VSFrame* src,
95                     const VSFrameInfo* fi, int plane);
96 
97 /// copies src to dest
98 void vsFrameCopy(VSFrame* dest, const VSFrame* src, const VSFrameInfo* fi);
99 
100 /** fills the data pointer so that it corresponds to the img saved in the linear buffer.
101     No copying is performed.
102     Do not call vsFrameFree() on it.
103  */
104 void vsFrameFillFromBuffer(VSFrame* frame, uint8_t* img, const VSFrameInfo* fi);
105 
106 /// frees memory
107 void vsFrameFree(VSFrame* frame);
108 
109 #endif  /* FRAMEINFO_H */
110 
111 /*
112  * Local variables:
113  *   c-file-style: "stroustrup"
114  *   c-file-offsets: ((case-label . *) (statement-case-intro . *))
115  *   indent-tabs-mode: nil
116  *   c-basic-offset: 2 t
117  * End:
118  *
119  * vim: expandtab shiftwidth=2:
120  */
121