install includes in DIST_DIR/include/vpx, move vpx_codec/ to vpx/
[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 PLANE_PACKED 0   /**< To be used for all packed formats */
114 #define PLANE_Y   0      /**< Y (Luminance) plane */
115 #define PLANE_U   1      /**< U (Chroma) plane */
116 #define PLANE_V   2      /**< V (Chroma) plane */
117 #define PLANE_ALPHA 3    /**< A (Transparancy) plane */
118         unsigned char *planes[4];  /**< pointer to the top left pixel for each plane */
119         int      stride[4];  /**< stride between rows for each plane */
120
121         int     bps; /**< bits per sample (for packed formats) */
122
123         /* The following member may be set by the application to associate data
124          * with this image.
125          */
126         void    *user_priv; /**< may be set by the application to associate data
127                          *   with this image. */
128
129         /* The following members should be treated as private. */
130         unsigned char *img_data;       /**< private */
131         int      img_data_owner; /**< private */
132         int      self_allocd;    /**< private */
133     } vpx_image_t; /**< alias for struct vpx_image */
134
135     /**\brief Representation of a rectangle on a surface */
136     typedef struct vpx_image_rect
137     {
138         unsigned int x; /**< leftmost column */
139         unsigned int y; /**< topmost row */
140         unsigned int w; /**< width */
141         unsigned int h; /**< height */
142     } vpx_image_rect_t; /**< alias for struct vpx_image_rect */
143
144     /*!\brief Open a descriptor, allocating storage for the underlying image
145      *
146      * Returns a descriptor for storing an image of the given format. The
147      * storage for the descriptor is allocated on the heap.
148      *
149      * \param[in]    img       Pointer to storage for descriptor. If this parameter
150      *                         is NULL, the storage for the descriptor will be
151      *                         allocated on the heap.
152      * \param[in]    fmt       Format for the image
153      * \param[in]    d_w       Width of the image
154      * \param[in]    d_h       Height of the image
155      * \param[in]    align     Alignment, in bytes, of each row in the image.
156      *
157      * \return Returns a pointer to the initialized image descriptor. If the img
158      *         parameter is non-null, the value of the img parameter will be
159      *         returned.
160      */
161     vpx_image_t *vpx_img_alloc(vpx_image_t  *img,
162                                vpx_img_fmt_t fmt,
163                                unsigned int d_w,
164                                unsigned int d_h,
165                                unsigned int align);
166
167     /*!\brief Open a descriptor, using existing storage for the underlying image
168      *
169      * Returns a descriptor for storing an image of the given format. The
170      * storage for descriptor has been allocated elsewhere, and a descriptor is
171      * desired to "wrap" that storage.
172      *
173      * \param[in]    img       Pointer to storage for descriptor. If this parameter
174      *                         is NULL, the storage for the descriptor will be
175      *                         allocated on the heap.
176      * \param[in]    fmt       Format for the image
177      * \param[in]    d_w       Width of the image
178      * \param[in]    d_h       Height of the image
179      * \param[in]    align     Alignment, in bytes, of each row in the image.
180      * \param[in]    img_data  Storage to use for the image
181      *
182      * \return Returns a pointer to the initialized image descriptor. If the img
183      *         parameter is non-null, the value of the img parameter will be
184      *         returned.
185      */
186     vpx_image_t *vpx_img_wrap(vpx_image_t  *img,
187                               vpx_img_fmt_t fmt,
188                               unsigned int d_w,
189                               unsigned int d_h,
190                               unsigned int align,
191                               unsigned char      *img_data);
192
193
194     /*!\brief Set the rectangle identifying the displayed portion of the image
195      *
196      * Updates the displayed rectangle (aka viewport) on the image surface to
197      * match the specified coordinates and size.
198      *
199      * \param[in]    img       Image descriptor
200      * \param[in]    x         leftmost column
201      * \param[in]    y         topmost row
202      * \param[in]    w         width
203      * \param[in]    h         height
204      *
205      * \return 0 if the requested rectangle is valid, nonzero otherwise.
206      */
207     int vpx_img_set_rect(vpx_image_t  *img,
208                          unsigned int  x,
209                          unsigned int  y,
210                          unsigned int  w,
211                          unsigned int  h);
212
213
214     /*!\brief Flip the image vertically (top for bottom)
215      *
216      * Adjusts the image descriptor's pointers and strides to make the image
217      * be referenced upside-down.
218      *
219      * \param[in]    img       Image descriptor
220      */
221     void vpx_img_flip(vpx_image_t *img);
222
223     /*!\brief Close an image descriptor
224      *
225      * Frees all allocated storage associated with an image descriptor.
226      *
227      * \param[in]    img       Image descriptor
228      */
229     void vpx_img_free(vpx_image_t *img);
230
231 #endif
232 #ifdef __cplusplus
233 }
234 #endif