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