diff options
author | Robin KAY <komadori@users.sourceforge.net> | 2004-04-11 12:25:35 +0000 |
---|---|---|
committer | Robin KAY <komadori@users.sourceforge.net> | 2004-04-11 12:25:35 +0000 |
commit | 6b7f877568cd1a32d8ca11ec8cf00447fafe8ab2 (patch) | |
tree | aba912d49c0e0bb02f266c86edf93799bbb9a0a1 /src | |
parent | 33f41cd9f5504072438e1263a89599ce358e6faf (diff) | |
download | xine-lib-6b7f877568cd1a32d8ca11ec8cf00447fafe8ab2.tar.gz xine-lib-6b7f877568cd1a32d8ca11ec8cf00447fafe8ab2.tar.bz2 |
Committed a modified version of Ian MacIntosh's patch.
CVS patchset: 6390
CVS date: 2004/04/11 12:25:35
Diffstat (limited to 'src')
-rw-r--r-- | src/video_out/yuv2rgb.c | 51 | ||||
-rw-r--r-- | src/video_out/yuv2rgb.h | 21 | ||||
-rw-r--r-- | src/video_out/yuv2rgb_mlib.c | 342 |
3 files changed, 152 insertions, 262 deletions
diff --git a/src/video_out/yuv2rgb.c b/src/video_out/yuv2rgb.c index 564b7f254..a8aa2d1fc 100644 --- a/src/video_out/yuv2rgb.c +++ b/src/video_out/yuv2rgb.c @@ -23,7 +23,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: yuv2rgb.c,v 1.50 2004/03/03 20:09:15 mroi Exp $ + * $Id: yuv2rgb.c,v 1.51 2004/04/11 12:25:35 komadori Exp $ */ #include "config.h" @@ -60,8 +60,8 @@ const int32_t Inverse_Table_6_9[8][4] = { }; -static void *my_malloc_aligned (size_t alignment, size_t size, void **chunk) { - +static void *my_malloc_aligned (size_t alignment, size_t size, void **chunk) +{ char *pMem; pMem = xine_xmalloc (size+alignment); @@ -75,7 +75,8 @@ static void *my_malloc_aligned (size_t alignment, size_t size, void **chunk) { } -static int yuv2rgb_next_slice (yuv2rgb_t *this, uint8_t **dest) { +static int yuv2rgb_next_slice (yuv2rgb_t *this, uint8_t **dest) +{ int y0, y1; if (dest == NULL) { @@ -100,11 +101,14 @@ static int yuv2rgb_next_slice (yuv2rgb_t *this, uint8_t **dest) { } } -static void yuv2rgb_dispose (yuv2rgb_t *this) { - +static void yuv2rgb_dispose (yuv2rgb_t *this) +{ free (this->y_chunk); free (this->u_chunk); free (this->v_chunk); +#ifdef HAVE_MLIB + free (this->mlib_chunk); +#endif free (this); } @@ -143,7 +147,17 @@ static int yuv2rgb_configure (yuv2rgb_t *this, this->v_buffer = this->v_chunk = NULL; } - +#ifdef HAVE_MLIB + if (this->mlib_chunk) { + free (this->mlib_chunk); + this->mlib_buffer = this->mlib_chunk = NULL; + } + if (this->mlib_resize_chunk) { + free (this->mlib_resize_chunk); + this->mlib_resize_buffer = this->mlib_resize_chunk = NULL; + } +#endif + this->step_dx = source_width * 32768 / dest_width; this->step_dy = source_height * 32768 / dest_height; /* @@ -185,11 +199,23 @@ static int yuv2rgb_configure (yuv2rgb_t *this, this->v_buffer = my_malloc_aligned (16, (dest_width+1)/2, &this->v_chunk); if (!this->v_buffer) return 0; + +#if HAVE_MLIB + /* Only need these if we are resizing and in mlib code */ + this->mlib_buffer = my_malloc_aligned (16, source_width*source_height*4, &this->mlib_chunk); + if (!this->mlib_buffer) + return 0; + /* Only need this one if we are 24 bit */ + if((rgb_stride / dest_width) == 3) { + this->mlib_resize_buffer = my_malloc_aligned (16, dest_width*dest_height*4, &this->mlib_resize_chunk); + if (!this->mlib_resize_buffer) + return 0; + } +#endif } return 1; } - static void scale_line_gen (uint8_t *source, uint8_t *dest, int width, int step) { @@ -3121,13 +3147,20 @@ static void yuy22rgb_c_init (yuv2rgb_factory_t *this) static yuv2rgb_t *yuv2rgb_create_converter (yuv2rgb_factory_t *factory) { yuv2rgb_t *this = xine_xmalloc (sizeof (yuv2rgb_t)); - + + this->swapped = factory->swapped; this->cmap = factory->cmap; this->y_chunk = this->y_buffer = NULL; this->u_chunk = this->u_buffer = NULL; this->v_chunk = this->v_buffer = NULL; +#ifdef HAVE_MLIB + this->mlib_chunk = this->mlib_buffer = NULL; + this->mlib_resize_chunk = this->mlib_resize_buffer = NULL; + this->mlib_filter_type = MLIB_BILINEAR; +#endif + this->table_rV = factory->table_rV; this->table_gU = factory->table_gU; this->table_gV = factory->table_gV; diff --git a/src/video_out/yuv2rgb.h b/src/video_out/yuv2rgb.h index 8beea99e9..dce0ade18 100644 --- a/src/video_out/yuv2rgb.h +++ b/src/video_out/yuv2rgb.h @@ -2,6 +2,12 @@ #ifndef HAVE_YUV2RGB_H #define HAVE_YUV2RGB_h +#include "config.h" + +#ifdef HAVE_MLIB +#include <mlib_video.h> +#endif + #include <inttypes.h> typedef struct yuv2rgb_s yuv2rgb_t; @@ -22,7 +28,6 @@ typedef void (*yuy22rgb_fun_t) (yuv2rgb_t *this, uint8_t * image, uint8_t * p); typedef uint32_t (*yuv2rgb_single_pixel_fun_t) (yuv2rgb_t *this, uint8_t y, uint8_t u, uint8_t v); - /* * modes supported - feel free to implement yours */ @@ -41,7 +46,6 @@ typedef uint32_t (*yuv2rgb_single_pixel_fun_t) (yuv2rgb_t *this, uint8_t y, uint #define MODE_PALETTE 12 struct yuv2rgb_s { - /* * configure converter for scaling factors */ @@ -86,7 +90,7 @@ struct yuv2rgb_s { int rgb_stride; int slice_height, slice_offset; int step_dx, step_dy; - int do_scale; + int do_scale, swapped; uint8_t *y_buffer; uint8_t *u_buffer; @@ -95,6 +99,14 @@ struct yuv2rgb_s { void *u_chunk; void *v_chunk; +#ifdef HAVE_MLIB + uint8_t *mlib_buffer; + uint8_t *mlib_resize_buffer; + void *mlib_chunk; + void *mlib_resize_chunk; + mlib_filter mlib_filter_type; +#endif + void **table_rV; void **table_gU; int *table_gV; @@ -103,7 +115,6 @@ struct yuv2rgb_s { uint8_t *cmap; scale_line_func_t scale_line; - } ; /* @@ -111,7 +122,6 @@ struct yuv2rgb_s { */ struct yuv2rgb_factory_s { - yuv2rgb_t* (*create_converter) (yuv2rgb_factory_t *this); /* @@ -146,7 +156,6 @@ struct yuv2rgb_factory_s { yuv2rgb_fun_t yuv2rgb_fun; yuy22rgb_fun_t yuy22rgb_fun; yuv2rgb_single_pixel_fun_t yuv2rgb_single_pixel_fun; - }; yuv2rgb_factory_t *yuv2rgb_factory_init (int mode, int swapped, uint8_t *colormap); diff --git a/src/video_out/yuv2rgb_mlib.c b/src/video_out/yuv2rgb_mlib.c index d1c0d1ff5..bbc8901e8 100644 --- a/src/video_out/yuv2rgb_mlib.c +++ b/src/video_out/yuv2rgb_mlib.c @@ -30,291 +30,140 @@ #include <stdlib.h> #include <string.h> #include <inttypes.h> + +#include <mlib_algebra.h> #include <mlib_video.h> #include "attributes.h" #include "xineutils.h" #include "yuv2rgb.h" +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) -static void scale_line (uint8_t *source, uint8_t *dest, - int width, int step) { - - unsigned p1; - unsigned p2; - int dx; - - p1 = *source++; - p2 = *source++; - dx = 0; - - while (width) { - - /* - printf ("scale_line, width = %d\n", width); - printf ("scale_line, dx = %d, p1 = %d, p2 = %d\n", dx, p1, p2); - */ - - *dest = (p1 * (32768 - dx) + p2 * dx) / 32768; - - dx += step; - while (dx > 32768) { - dx -= 32768; - p1 = p2; - p2 = *source++; - } - - dest ++; - width --; - } -} - - - -static void mlib_yuv420_rgb24 (yuv2rgb_t *this, - uint8_t * image, uint8_t * py, - uint8_t * pu, uint8_t * pv) +static void mlib_yuv420_rgb24(yuv2rgb_t *this, + uint8_t * image, uint8_t * py, + uint8_t * pu, uint8_t * pv) { + int src_height = MIN(this->slice_height, this->source_height-this->slice_offset) &~ 1; int dst_height; - int dy; - mlib_status mlib_stat; + dst_height = this->next_slice(this, &image); if (this->do_scale) { - dy = 0; - dst_height = this->next_slice (this, &image); - - /* mlib needs an even YUV2 width. */ - _x_assert((this->dest_width&1) == 0); - - for (;;) { - scale_line (pu, this->u_buffer, - this->dest_width >> 1, this->step_dx); - pu += this->uv_stride; - - scale_line (pv, this->v_buffer, - this->dest_width >> 1, this->step_dx); - pv += this->uv_stride; - - scale_line (py, this->y_buffer, - this->dest_width, this->step_dx); - py += this->y_stride; - scale_line (py, this->y_buffer + this->dest_width, - this->dest_width, this->step_dx); - py += this->y_stride; - - mlib_stat = mlib_VideoColorYUV2RGB420(image, - this->y_buffer, - this->u_buffer, - this->v_buffer, - this->dest_width & ~1, 2, - this->rgb_stride, - this->dest_width, - this->dest_width >> 1); - dy += this->step_dy; - image += this->rgb_stride; - - while (--dst_height > 0 && dy < 32768) { - memcpy (image, (uint8_t*)image-this->rgb_stride, this->dest_width*6); - dy += this->step_dy; - image += this->rgb_stride; - } - - if (dst_height <= 0) - break; - - dy -= 32768; - - dy += this->step_dy; + mlib_u8 *resize_buffer = this->mlib_resize_buffer; + mlib_s32 resize_stride = this->dest_width << 2; + + mlib_VideoColorYUV420seq_to_ARGBint((mlib_u32*)this->mlib_buffer, + py, pu, pv, py, 0, + this->source_width, + src_height, + this->source_width<<2, + this->y_stride, + this->uv_stride); + mlib_VideoColorResizeABGR((mlib_u32*)resize_buffer, + (mlib_u32*)this->mlib_buffer, + this->dest_width,dst_height,resize_stride, + this->source_width, src_height,this->source_width<<2, + this->mlib_filter_type); + + while(dst_height--) { + mlib_VideoColorABGR2RGB(image, resize_buffer, this->dest_width); image += this->rgb_stride; - - while (--dst_height > 0 && dy < 32768) { - memcpy (image, (uint8_t*)image-this->rgb_stride, this->dest_width*3); - dy += this->step_dy; - image += this->rgb_stride; - } - - if (dst_height <= 0) - break; - - dy -= 32768; + resize_buffer += resize_stride; } } else { - this->next_slice (this, &image); - - mlib_stat = mlib_VideoColorYUV2RGB420(image, py, pu, pv, - this->source_width, - this->slice_height, - this->rgb_stride, - this->y_stride, - this->uv_stride); + mlib_VideoColorYUV2RGB420(image, py, pu, pv, + this->source_width, + dst_height, + this->rgb_stride, + this->y_stride, + this->uv_stride); } } -static void mlib_yuv420_argb32 (yuv2rgb_t *this, - uint8_t * image, uint8_t * py, - uint8_t * pu, uint8_t * pv) +static void mlib_yuv420_argb32(yuv2rgb_t *this, + uint8_t * image, uint8_t * py, + uint8_t * pu, uint8_t * pv) { + int src_height = MIN(this->slice_height, this->source_height-this->slice_offset) &~ 1; int dst_height; - int dy; - mlib_status mlib_stat; + dst_height = this->next_slice(this, &image); if (this->do_scale) { - dy = 0; - dst_height = this->next_slice (this, &image); - - /* mlib needs an even YUV2 width */ - _x_assert((this->dest_width&1) == 0); - - for (;;) { - scale_line (pu, this->u_buffer, - this->dest_width >> 1, this->step_dx); - pu += this->uv_stride; - - scale_line (pv, this->v_buffer, - this->dest_width >> 1, this->step_dx); - pv += this->uv_stride; - - scale_line (py, this->y_buffer, - this->dest_width, this->step_dx); - py += this->y_stride; - scale_line (py, this->y_buffer + this->dest_width, - this->dest_width, this->step_dx); - py += this->y_stride; - - mlib_stat = mlib_VideoColorYUV2ARGB420(image, - this->y_buffer, - this->u_buffer, - this->v_buffer, - this->dest_width & ~1, 2, - this->rgb_stride, - this->dest_width, - this->dest_width >> 1); - dy += this->step_dy; - image += this->rgb_stride; - - while (--dst_height > 0 && dy < 32768) { - memcpy (image, (uint8_t*)image-this->rgb_stride, this->dest_width*8); - dy += this->step_dy; - image += this->rgb_stride; - } - - if (dst_height <= 0) - break; - - dy -= 32768; + mlib_VideoColorYUV420seq_to_ARGBint((mlib_u32*)this->mlib_buffer, + py, pu, pv, py, 0, + this->source_width, + src_height, + this->source_width<<2, + this->y_stride, + this->uv_stride); + mlib_VideoColorResizeABGR((mlib_u32*)image, + (mlib_u32*)this->mlib_buffer, + this->dest_width,dst_height,this->rgb_stride, + this->source_width, src_height,this->source_width<<2, + this->mlib_filter_type); + } else { + mlib_VideoColorYUV420seq_to_ARGBint((mlib_u32*)image, + py, pu, pv, py, 0, + this->source_width, + dst_height, + this->rgb_stride, + this->y_stride, + this->uv_stride); + } - dy += this->step_dy; + if (this->swapped) { + while (dst_height--) { + mlib_VectorReverseByteOrder_U32((mlib_u32*)image, this->dest_width); image += this->rgb_stride; - - while (--dst_height > 0 && dy < 32768) { - memcpy (image, (uint8_t*)image-this->rgb_stride, this->dest_width*4); - dy += this->step_dy; - image += this->rgb_stride; - } - - if (dst_height <= 0) - break; - - dy -= 32768; } - } else { - this->next_slice (this, &image); - - mlib_stat = mlib_VideoColorYUV2ARGB420(image, py, pu, pv, - this->source_width, - this->slice_height, - this->rgb_stride, - this->y_stride, - this->uv_stride); } } -static void mlib_yuv420_abgr32 (yuv2rgb_t *this, - uint8_t * image, uint8_t * py, - uint8_t * pu, uint8_t * pv) +static void mlib_yuv420_abgr32(yuv2rgb_t *this, + uint8_t * image, uint8_t * py, + uint8_t * pu, uint8_t * pv) { + int src_height = MIN(this->slice_height, this->source_height-this->slice_offset) &~ 1; int dst_height; - int dy; - mlib_status mlib_stat; + dst_height = this->next_slice (this, &image); if (this->do_scale) { - dy = 0; - dst_height = this->next_slice (this, &image); - - /* mlib needs an even YUV2 width */ - _x_assert((this->dest_width&1) == 0); - - for (;;) { - scale_line (pu, this->u_buffer, - this->dest_width >> 1, this->step_dx); - pu += this->uv_stride; - - scale_line (pv, this->v_buffer, - this->dest_width >> 1, this->step_dx); - pv += this->uv_stride; - - scale_line (py, this->y_buffer, - this->dest_width, this->step_dx); - py += this->y_stride; - scale_line (py, this->y_buffer + this->dest_width, - this->dest_width, this->step_dx); - py += this->y_stride; - - mlib_stat = mlib_VideoColorYUV2ABGR420(image, - this->y_buffer, - this->u_buffer, - this->v_buffer, - this->dest_width & ~1, 2, - this->rgb_stride, - this->dest_width, - this->dest_width >> 1); - dy += this->step_dy; - image += this->rgb_stride; - - while (--dst_height > 0 && dy < 32768) { - memcpy (image, (uint8_t*)image-this->rgb_stride, this->dest_width*8); - dy += this->step_dy; - image += this->rgb_stride; - } - - if (dst_height <= 0) - break; - - dy -= 32768; + mlib_VideoColorYUV420seq_to_ABGRint((mlib_u32*)this->mlib_buffer, + py, pu, pv, py, 0, + this->source_width, + src_height, + this->source_width<<2, + this->y_stride, + this->uv_stride); + mlib_VideoColorResizeABGR((mlib_u32*)image, + (mlib_u32*)this->mlib_buffer, + this->dest_width,dst_height,this->rgb_stride, + this->source_width, src_height, this->source_width<<2, + this->mlib_filter_type); + } + else { + mlib_VideoColorYUV420seq_to_ABGRint((mlib_u32*)image, + py, pu, pv, py, 0, + this->source_width, + dst_height, + this->rgb_stride, + this->y_stride, + this->uv_stride); + } - dy += this->step_dy; + if (this->swapped) { + while (dst_height--) { + mlib_VectorReverseByteOrder_U32((mlib_u32*)image, this->dest_width); image += this->rgb_stride; - - while (--dst_height > 0 && dy < 32768) { - memcpy (image, (uint8_t*)image-this->rgb_stride, this->dest_width*4); - dy += this->step_dy; - image += this->rgb_stride; - } - - if (dst_height <= 0) - break; - - dy -= 32768; } - } else { - this->next_slice (this, &image); - - mlib_stat = mlib_VideoColorYUV2ABGR420(image, py, pu, pv, - this->source_width, - this->slice_height, - this->rgb_stride, - this->y_stride, - this->uv_stride); } } - -void yuv2rgb_init_mlib (yuv2rgb_factory_t *this) { - - if (this->swapped) return; /*no swapped pixel output upto now*/ - +void yuv2rgb_init_mlib (yuv2rgb_factory_t *this) +{ switch (this->mode) { case MODE_24_RGB: + if (this->swapped) break; this->yuv2rgb_fun = mlib_yuv420_rgb24; break; case MODE_32_RGB: @@ -326,5 +175,4 @@ void yuv2rgb_init_mlib (yuv2rgb_factory_t *this) { } } - #endif /* HAVE_MLIB */ |