Merge "examples: use I420 input for encoders"
[profile/ivi/libvpx.git] / vpx / vpx_image.h
1 /*
2  *  Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license and patent
5  *  grant that can be found in the LICENSE file in the root of the source
6  *  tree. All contributing project authors may be found in the AUTHORS
7  *  file in the root of the source tree.
8  */
9
10
11 /*!\file vpx_image.h
12  * \brief Describes the vpx image descriptor and associated operations
13  *
14  */
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 #ifndef VPX_IMAGE_H
20 #define VPX_IMAGE_H
21
22     /*!\brief Current ABI version number
23      *
24      * \internal
25      * If this file is altered in any way that changes the ABI, this value
26      * must be bumped.  Examples include, but are not limited to, changing
27      * types, removing or reassigning enums, adding/removing/rearranging
28      * fields to structures
29      */
30 #define VPX_IMAGE_ABI_VERSION (1) /**<\hideinitializer*/
31
32
33 #define VPX_IMG_FMT_PLANAR     0x100  /**< Image is a planar format */
34 #define VPX_IMG_FMT_UV_FLIP    0x200  /**< V plane precedes U plane in memory */
35 #define VPX_IMG_FMT_HAS_ALPHA  0x400  /**< Image has an alpha channel componnent */
36
37
38     /*!\brief List of supported image formats */
39     typedef enum vpx_img_fmt {
40         VPX_IMG_FMT_NONE,
41         VPX_IMG_FMT_RGB24,   /**< 24 bit per pixel packed RGB */
42         VPX_IMG_FMT_RGB32,   /**< 32 bit per pixel packed 0RGB */
43         VPX_IMG_FMT_RGB565,  /**< 16 bit per pixel, 565 */
44         VPX_IMG_FMT_RGB555,  /**< 16 bit per pixel, 555 */
45         VPX_IMG_FMT_UYVY,    /**< UYVY packed YUV */
46         VPX_IMG_FMT_YUY2,    /**< YUYV packed YUV */
47         VPX_IMG_FMT_YVYU,    /**< YVYU packed YUV */
48         VPX_IMG_FMT_BGR24,   /**< 24 bit per pixel packed BGR */
49         VPX_IMG_FMT_RGB32_LE, /**< 32 bit packed BGR0 */
50         VPX_IMG_FMT_ARGB,     /**< 32 bit packed ARGB, alpha=255 */
51         VPX_IMG_FMT_ARGB_LE,  /**< 32 bit packed BGRA, alpha=255 */
52         VPX_IMG_FMT_RGB565_LE,  /**< 16 bit per pixel, gggbbbbb rrrrrggg */
53         VPX_IMG_FMT_RGB555_LE,  /**< 16 bit per pixel, gggbbbbb 0rrrrrgg */
54         VPX_IMG_FMT_YV12    = VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_UV_FLIP | 1, /**< planar YVU */
55         VPX_IMG_FMT_I420    = VPX_IMG_FMT_PLANAR | 2,
56         VPX_IMG_FMT_VPXYV12 = VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_UV_FLIP | 3, /** < planar 4:2:0 format with vpx color space */
57         VPX_IMG_FMT_VPXI420 = VPX_IMG_FMT_PLANAR | 4,  /** < planar 4:2:0 format with vpx color space */
58     }
59     vpx_img_fmt_t; /**< alias for enum vpx_img_fmt */
60
61 #if !defined(VPX_CODEC_DISABLE_COMPAT) || !VPX_CODEC_DISABLE_COMPAT
62 #define IMG_FMT_PLANAR         VPX_IMG_FMT_PLANAR     /**< \deprecated Use #VPX_IMG_FMT_PLANAR */
63 #define IMG_FMT_UV_FLIP        VPX_IMG_FMT_UV_FLIP    /**< \deprecated Use #VPX_IMG_FMT_UV_FLIP */
64 #define IMG_FMT_HAS_ALPHA      VPX_IMG_FMT_HAS_ALPHA  /**< \deprecated Use #VPX_IMG_FMT_HAS_ALPHA */
65
66     /*!\brief Deprecated list of supported image formats
67      * \deprecated New code should use #vpx_img_fmt
68      */
69 #define img_fmt   vpx_img_fmt
70     /*!\brief alias for enum img_fmt.
71      * \deprecated New code should use #vpx_img_fmt_t
72      */
73 #define img_fmt_t vpx_img_fmt_t
74
75 #define IMG_FMT_NONE       VPX_IMG_FMT_NONE       /**< \deprecated Use #VPX_IMG_FMT_NONE */
76 #define IMG_FMT_RGB24      VPX_IMG_FMT_RGB24      /**< \deprecated Use #VPX_IMG_FMT_RGB24 */
77 #define IMG_FMT_RGB32      VPX_IMG_FMT_RGB32      /**< \deprecated Use #VPX_IMG_FMT_RGB32 */
78 #define IMG_FMT_RGB565     VPX_IMG_FMT_RGB565     /**< \deprecated Use #VPX_IMG_FMT_RGB565 */
79 #define IMG_FMT_RGB555     VPX_IMG_FMT_RGB555     /**< \deprecated Use #VPX_IMG_FMT_RGB555 */
80 #define IMG_FMT_UYVY       VPX_IMG_FMT_UYVY       /**< \deprecated Use #VPX_IMG_FMT_UYVY */
81 #define IMG_FMT_YUY2       VPX_IMG_FMT_YUY2       /**< \deprecated Use #VPX_IMG_FMT_YUY2 */
82 #define IMG_FMT_YVYU       VPX_IMG_FMT_YVYU       /**< \deprecated Use #VPX_IMG_FMT_YVYU */
83 #define IMG_FMT_BGR24      VPX_IMG_FMT_BGR24      /**< \deprecated Use #VPX_IMG_FMT_BGR24 */
84 #define IMG_FMT_RGB32_LE   VPX_IMG_FMT_RGB32_LE   /**< \deprecated Use #VPX_IMG_FMT_RGB32_LE */
85 #define IMG_FMT_ARGB       VPX_IMG_FMT_ARGB       /**< \deprecated Use #VPX_IMG_FMT_ARGB */
86 #define IMG_FMT_ARGB_LE    VPX_IMG_FMT_ARGB_LE    /**< \deprecated Use #VPX_IMG_FMT_ARGB_LE */
87 #define IMG_FMT_RGB565_LE  VPX_IMG_FMT_RGB565_LE  /**< \deprecated Use #VPX_IMG_FMT_RGB565_LE */
88 #define IMG_FMT_RGB555_LE  VPX_IMG_FMT_RGB555_LE  /**< \deprecated Use #VPX_IMG_FMT_RGB555_LE */
89 #define IMG_FMT_YV12       VPX_IMG_FMT_YV12       /**< \deprecated Use #VPX_IMG_FMT_YV12 */
90 #define IMG_FMT_I420       VPX_IMG_FMT_I420       /**< \deprecated Use #VPX_IMG_FMT_I420 */
91 #define IMG_FMT_VPXYV12    VPX_IMG_FMT_VPXYV12    /**< \deprecated Use #VPX_IMG_FMT_VPXYV12 */
92 #define IMG_FMT_VPXI420    VPX_IMG_FMT_VPXI420    /**< \deprecated Use #VPX_IMG_FMT_VPXI420 */
93 #endif /* VPX_CODEC_DISABLE_COMPAT */
94
95     /**\brief Image Descriptor */
96     typedef struct vpx_image
97     {
98         vpx_img_fmt_t fmt; /**< Image Format */
99
100         /* Image storage dimensions */
101         unsigned int  w;   /**< Stored image width */
102         unsigned int  h;   /**< Stored image height */
103
104         /* Image display dimensions */
105         unsigned int  d_w;   /**< Displayed image width */
106         unsigned int  d_h;   /**< Displayed image height */
107
108         /* Chroma subsampling info */
109         unsigned int  x_chroma_shift;   /**< subsampling order, X */
110         unsigned int  y_chroma_shift;   /**< subsampling order, Y */
111
112         /* Image data pointers. */
113 #define VPX_PLANE_PACKED 0   /**< To be used for all packed formats */
114 #define VPX_PLANE_Y      0   /**< Y (Luminance) plane */
115 #define VPX_PLANE_U      1   /**< U (Chroma) plane */
116 #define VPX_PLANE_V      2   /**< V (Chroma) plane */
117 #define VPX_PLANE_ALPHA  3   /**< A (Transparancy) plane */
118 #if !defined(VPX_CODEC_DISABLE_COMPAT) || !VPX_CODEC_DISABLE_COMPAT
119 #define PLANE_PACKED     VPX_PLANE_PACKED 
120 #define PLANE_Y          VPX_PLANE_Y
121 #define PLANE_U          VPX_PLANE_U
122 #define PLANE_V          VPX_PLANE_V
123 #define PLANE_ALPHA      VPX_PLANE_ALPHA 
124 #endif
125         unsigned char *planes[4];  /**< pointer to the top left pixel for each plane */
126         int      stride[4];  /**< stride between rows for each plane */
127
128         int     bps; /**< bits per sample (for packed formats) */
129
130         /* The following member may be set by the application to associate data
131          * with this image.
132          */
133         void    *user_priv; /**< may be set by the application to associate data
134                          *   with this image. */
135
136         /* The following members should be treated as private. */
137         unsigned char *img_data;       /**< private */
138         int      img_data_owner; /**< private */
139         int      self_allocd;    /**< private */
140     } vpx_image_t; /**< alias for struct vpx_image */
141
142     /**\brief Representation of a rectangle on a surface */
143     typedef struct vpx_image_rect
144     {
145         unsigned int x; /**< leftmost column */
146         unsigned int y; /**< topmost row */
147         unsigned int w; /**< width */
148         unsigned int h; /**< height */
149     } vpx_image_rect_t; /**< alias for struct vpx_image_rect */
150
151     /*!\brief Open a descriptor, allocating storage for the underlying image
152      *
153      * Returns a descriptor for storing an image of the given format. The
154      * storage for the descriptor is allocated on the heap.
155      *
156      * \param[in]    img       Pointer to storage for descriptor. If this parameter
157      *                         is NULL, the storage for the descriptor will be
158      *                         allocated on the heap.
159      * \param[in]    fmt       Format for the image
160      * \param[in]    d_w       Width of the image
161      * \param[in]    d_h       Height of the image
162      * \param[in]    align     Alignment, in bytes, of each row in the image.
163      *
164      * \return Returns a pointer to the initialized image descriptor. If the img
165      *         parameter is non-null, the value of the img parameter will be
166      *         returned.
167      */
168     vpx_image_t *vpx_img_alloc(vpx_image_t  *img,
169                                vpx_img_fmt_t fmt,
170                                unsigned int d_w,
171                                unsigned int d_h,
172                                unsigned int align);
173
174     /*!\brief Open a descriptor, using existing storage for the underlying image
175      *
176      * Returns a descriptor for storing an image of the given format. The
177      * storage for descriptor has been allocated elsewhere, and a descriptor is
178      * desired to "wrap" that storage.
179      *
180      * \param[in]    img       Pointer to storage for descriptor. If this parameter
181      *                         is NULL, the storage for the descriptor will be
182      *                         allocated on the heap.
183      * \param[in]    fmt       Format for the image
184      * \param[in]    d_w       Width of the image
185      * \param[in]    d_h       Height of the image
186      * \param[in]    align     Alignment, in bytes, of each row in the image.
187      * \param[in]    img_data  Storage to use for the image
188      *
189      * \return Returns a pointer to the initialized image descriptor. If the img
190      *         parameter is non-null, the value of the img parameter will be
191      *         returned.
192      */
193     vpx_image_t *vpx_img_wrap(vpx_image_t  *img,
194                               vpx_img_fmt_t fmt,
195                               unsigned int d_w,
196                               unsigned int d_h,
197                               unsigned int align,
198                               unsigned char      *img_data);
199
200
201     /*!\brief Set the rectangle identifying the displayed portion of the image
202      *
203      * Updates the displayed rectangle (aka viewport) on the image surface to
204      * match the specified coordinates and size.
205      *
206      * \param[in]    img       Image descriptor
207      * \param[in]    x         leftmost column
208      * \param[in]    y         topmost row
209      * \param[in]    w         width
210      * \param[in]    h         height
211      *
212      * \return 0 if the requested rectangle is valid, nonzero otherwise.
213      */
214     int vpx_img_set_rect(vpx_image_t  *img,
215                          unsigned int  x,
216                          unsigned int  y,
217                          unsigned int  w,
218                          unsigned int  h);
219
220
221     /*!\brief Flip the image vertically (top for bottom)
222      *
223      * Adjusts the image descriptor's pointers and strides to make the image
224      * be referenced upside-down.
225      *
226      * \param[in]    img       Image descriptor
227      */
228     void vpx_img_flip(vpx_image_t *img);
229
230     /*!\brief Close an image descriptor
231      *
232      * Frees all allocated storage associated with an image descriptor.
233      *
234      * \param[in]    img       Image descriptor
235      */
236     void vpx_img_free(vpx_image_t *img);
237
238 #endif
239 #ifdef __cplusplus
240 }
241 #endif