1 /* 2 * imgconvert.h - defines for image format conversion routines 3 * Written by Andrew Church <achurch@achurch.org> 4 * 5 * This file is part of transcode, a video stream processing tool. 6 * transcode is free software, distributable under the terms of the GNU 7 * General Public License (version 2 or later). See the file COPYING 8 * for details. 9 */ 10 11 #ifndef ACLIB_IMGCONVERT_H 12 #define ACLIB_IMGCONVERT_H 13 14 /*************************************************************************/ 15 16 /* Image format defines */ 17 typedef enum { 18 IMG_UNKNOWN = 0, /* Unknown/unset (dummy value, guaranteed to be 0) */ 19 /* YUV formats */ 20 IMG_YUV_BASE = 0x1000, 21 IMG_YUV420P, /* YUV planar, 1 U/V per 2x2 Y pixels */ 22 IMG_YV12, /* YUV420P with U and V reversed */ 23 IMG_YUV411P, /* YUV planar, 1 U/V per 4x1 Y pixels */ 24 IMG_YUV422P, /* YUV planar, 1 U/V per 2x1 Y pixels */ 25 IMG_YUV444P, /* YUV planar, 1 U/V per 1x1 Y pixels */ 26 IMG_YUY2, /* YUV packed, 1 U/V per 2x1 Y pixels, Y:U:Y:V */ 27 IMG_UYVY, /* YUV packed, 1 U/V per 2x1 Y pixels, U:Y:V:Y */ 28 IMG_YVYU, /* YUV packed, 1 U/V per 2x1 Y pixels, Y:V:Y:U */ 29 IMG_Y8, /* Y-only 8-bit data */ 30 IMG_YUV_LAST, 31 /* RGB formats */ 32 IMG_RGB_BASE = 0x2000, 33 IMG_RGB24, /* RGB packed, 8 bits per component, R:G:B */ 34 IMG_BGR24, /* RGB packed, 8 bits per component, B:G:R */ 35 IMG_RGBA32, /* RGB+alpha packed, 8 bits per component, R:G:B:A */ 36 IMG_ABGR32, /* RGB+alpha packed, 8 bits per component, A:B:G:R */ 37 IMG_ARGB32, /* RGB+alpha packed, 8 bits per component, A:R:G:B */ 38 IMG_BGRA32, /* RGB+alpha packed, 8 bits per component, B:G:R:A */ 39 IMG_GRAY8, /* Grayscale 8-bit data */ 40 IMG_RGB_LAST, 41 } ImageFormat; 42 43 /* Alias */ 44 #define IMG_NONE IMG_UNKNOWN 45 46 /* Default YUV and RGB formats */ 47 #define IMG_YUV_DEFAULT IMG_YUV420P 48 #define IMG_RGB_DEFAULT IMG_RGB24 49 50 /* Is the given image format a YUV/RGB one? */ 51 #define IS_YUV_FORMAT(fmt) ((fmt) > IMG_YUV_BASE && (fmt) < IMG_YUV_LAST) 52 #define IS_RGB_FORMAT(fmt) ((fmt) > IMG_RGB_BASE && (fmt) < IMG_RGB_LAST) 53 54 /* U/V plane size for YUV planar formats (Y plane size is always w*h) */ 55 #define UV_PLANE_SIZE(fmt,w,h) \ 56 ((fmt)==IMG_YUV420P ? ((w)/2)*((h)/2) : \ 57 (fmt)==IMG_YV12 ? ((w)/2)*((h)/2) : \ 58 (fmt)==IMG_YUV411P ? ((w)/4)* (h) : \ 59 (fmt)==IMG_YUV422P ? ((w)/2)* (h) : \ 60 (fmt)==IMG_YUV444P ? (w) * (h) : 0) 61 62 /* Macro to initialize an array of planes from a buffer */ 63 #define YUV_INIT_PLANES(planes,buffer,fmt,w,h) \ 64 ((planes)[0] = (buffer), \ 65 (planes)[1] = (planes)[0] + (w)*(h), \ 66 (planes)[2] = (planes)[1] + UV_PLANE_SIZE((fmt),(w),(h))) 67 68 #if 0 69 /* Structure describing an image. FIXME: not currently used--this should 70 * eventually replace the (planes,format) pairs passed to ac_imgconvert. */ 71 typedef struct { 72 ImageFormat format; /* Format of image data */ 73 int width, height; /* Size of image */ 74 uint8_t *planes[4]; /* Data planes (use planes[0] for packed data) */ 75 int stride[4]; /* Length of one row in each plane, incl. padding */ 76 } Image; 77 #endif 78 79 /*************************************************************************/ 80 81 /* Initialization routine. Returns 1 on success, 0 on failure. */ 82 extern int ac_imgconvert_init(int accel); 83 84 /* Conversion routine. Returns 1 on success, 0 on failure. */ 85 extern int ac_imgconvert(uint8_t **src, /* Array of source planes */ 86 ImageFormat srcfmt, /* Source image format */ 87 uint8_t **dest, /* Array of dest planes */ 88 ImageFormat destfmt, /* Destination image format */ 89 int width, /* Image width in pixels */ 90 int height /* Image height in pixels */ 91 ); 92 93 /*************************************************************************/ 94 95 #endif /* ACLIB_IMGCONVERT_H */ 96 97 /* 98 * Local variables: 99 * c-file-style: "stroustrup" 100 * c-file-offsets: ((case-label . *) (statement-case-intro . *)) 101 * indent-tabs-mode: nil 102 * End: 103 * 104 * vim: expandtab shiftwidth=4: 105 */ 106