author | zecke <zecke> | 2005-04-17 13:56:34 (UTC) |
---|---|---|
committer | zecke <zecke> | 2005-04-17 13:56:34 (UTC) |
commit | 3d5e5c098ccb686588380bc1f220beafbc5a6d76 (patch) (side-by-side diff) | |
tree | 92fad8a98ea341ec290dc7f9fca7759470b795f6 /noncore/multimedia/opieplayer2/yuv2rgb.c | |
parent | 49335d66d8e96b1fc86ecfe95cd343c8960126bc (diff) | |
download | opie-3d5e5c098ccb686588380bc1f220beafbc5a6d76.zip opie-3d5e5c098ccb686588380bc1f220beafbc5a6d76.tar.gz opie-3d5e5c098ccb686588380bc1f220beafbc5a6d76.tar.bz2 |
Opie Player2 XINE update:
-update xine code alphablend, yuv2rgb to be up to date
-XINELib:
-use the XINE infrastructure to change the gui width/height
-use the XINE infrastructure to change the brightness
-Update the NULL Video Driver:
-make use of frame_dest_cb and and dest_size_cb (callback)
to update the size of the gui
-use alphablend
-merge the video_out_fb xine driver
To Alwin: your testvideo now lockups op2. with valgrind I see
it has to do with the yuv2rgb conversion methods
Diffstat (limited to 'noncore/multimedia/opieplayer2/yuv2rgb.c') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/yuv2rgb.c | 436 |
1 files changed, 273 insertions, 163 deletions
diff --git a/noncore/multimedia/opieplayer2/yuv2rgb.c b/noncore/multimedia/opieplayer2/yuv2rgb.c index 8e34052..487ed20 100644 --- a/noncore/multimedia/opieplayer2/yuv2rgb.c +++ b/noncore/multimedia/opieplayer2/yuv2rgb.c @@ -1,10 +1,11 @@ /* * yuv2rgb.c * - * This file is part of xine, a unix video player. + * Copyright (C) 2003-2004 the xine project + * This file is part of xine, a free video player. * * based on work from mpeg2dec: * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> * * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. * @@ -28,14 +29,20 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <inttypes.h> #include "yuv2rgb.h" -#include <xine/xineutils.h> +#define LOG_MODULE "yuv2rgb" +#define LOG_VERBOSE +/* +#define LOG +*/ + +#include <xine/xineutils.h> static int prof_scale_line = -1; static scale_line_func_t find_scale_line_func(int step); @@ -48,27 +55,64 @@ const int32_t Inverse_Table_6_9[8][4] = { {104597, 132201, 25675, 53279}, /* ITU-R Rec. 624-4 System B, G */ {104597, 132201, 25675, 53279}, /* SMPTE 170M */ {117579, 136230, 16907, 35559} /* SMPTE 240M (1987) */ }; -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); *chunk = pMem; - while ((int) pMem % alignment) + while ((uintptr_t) pMem % alignment) pMem++; return pMem; } +static int yuv2rgb_next_slice (yuv2rgb_t *this, uint8_t **dest) +{ + int y0, y1; + + if (dest == NULL) { + this->slice_offset = 0; + this->slice_height = 16; + return 0; + } + if (this->slice_height == this->source_height) { + return this->dest_height; + } + + y0 = (this->slice_offset * this->dest_height) / this->source_height; + y1 = ((this->slice_offset + this->slice_height) * this->dest_height) / this->source_height; + *dest += (this->rgb_stride * y0); + + if ((this->slice_offset + this->slice_height) >= this->source_height) { + this->slice_offset = 0; + return (this->dest_height - y0); + } else { + this->slice_offset += this->slice_height; + return (y1 - y0); + } +} + +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); +} + static int yuv2rgb_configure (yuv2rgb_t *this, int source_width, int source_height, int y_stride, int uv_stride, int dest_width, int dest_height, int rgb_stride) { /* @@ -82,12 +126,14 @@ static int yuv2rgb_configure (yuv2rgb_t *this, this->source_height = source_height; this->y_stride = y_stride; this->uv_stride = uv_stride; this->dest_width = dest_width; this->dest_height = dest_height; this->rgb_stride = rgb_stride; + this->slice_height = source_height; + this->slice_offset = 0; if (this->y_chunk) { free (this->y_chunk); this->y_buffer = this->y_chunk = NULL; } if (this->u_chunk) { @@ -96,16 +142,29 @@ static int yuv2rgb_configure (yuv2rgb_t *this, } if (this->v_chunk) { free (this->v_chunk); 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; - +/* + printf("yuv2rgb config: src_ht=%i, dst_ht=%i\n",source_height, dest_height); + printf("yuv2rgb config: step_dy=%i %f\n",this->step_dy, (float)this->step_dy / 32768.0); +*/ this->scale_line = find_scale_line_func(this->step_dx); if ((source_width == dest_width) && (source_height == dest_height)) { this->do_scale = 0; /* @@ -135,17 +194,29 @@ static int yuv2rgb_configure (yuv2rgb_t *this, this->u_buffer = my_malloc_aligned (16, (dest_width+1)/2, &this->u_chunk); if (!this->u_buffer) return 0; 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) { /* * scales a yuv source row to a dest row, with interpolation * (good quality, but slow) @@ -1201,22 +1272,35 @@ static scale_line_func_t find_scale_line_func(int step) { { 5, 8, scale_line_5_8, "svcd 4:3(pal)" }, { 3, 4, scale_line_3_4, "svcd 4:3(ntsc)" }, { 1, 2, scale_line_1_2, "2*zoom" }, { 1, 1, scale_line_1_1, "non-scaled" }, }; int i; +#ifdef LOG + /* to filter out multiple messages about the scale_line variant we're using */ + static int reported_for_step; +#endif for (i = 0; i < sizeof(scale_line)/sizeof(scale_line[0]); i++) { if (step == scale_line[i].src_step*32768/scale_line[i].dest_step) { - //printf("yuv2rgb: using %s optimized scale_line\n", scale_line[i].desc); +#ifdef LOG + if (step != reported_for_step) + printf("yuv2rgb: using %s optimized scale_line\n", scale_line[i].desc); + reported_for_step = step; +#endif return scale_line[i].func; } } - //printf("yuv2rgb: using generic scale_line with interpolation\n"); - return scale_line_gen; +#ifdef LOG + if (step != reported_for_step) + printf("yuv2rgb: using generic scale_line with interpolation\n"); + reported_for_step = step; +#endif + + return scale_line_gen; } static void scale_line_2 (uint8_t *source, uint8_t *dest, int width, int step) { int p1; @@ -1269,13 +1353,13 @@ static void scale_line_4 (uint8_t *source, uint8_t *dest, dest ++; width --; } } -#define RGB(i) \ +#define X_RGB(i) \ U = pu[i]; \ V = pv[i]; \ r = this->table_rV[V]; \ g = (void *) (((uint8_t *)this->table_gU[U]) + this->table_gV[V]); \ b = this->table_bU[U]; @@ -1345,33 +1429,33 @@ static void yuv2rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst, scale_line (_pv, this->v_buffer, this->dest_width >> 1, this->step_dx); scale_line (_py, this->y_buffer, this->dest_width, this->step_dx); dy = 0; - dst_height = this->dest_height; + dst_height = this->next_slice (this, &_dst); for (height = 0;; ) { dst_1 = (uint32_t*)_dst; py_1 = this->y_buffer; pu = this->u_buffer; pv = this->v_buffer; width = this->dest_width >> 3; do { - RGB(0); + X_RGB(0); DST1(0); - RGB(1); + X_RGB(1); DST1(1); - RGB(2); + X_RGB(2); DST1(2); - RGB(3); + X_RGB(3); DST1(3); pu += 4; pv += 4; py_1 += 8; dst_1 += 8; @@ -1409,36 +1493,36 @@ static void yuv2rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst, } height++; } while( dy>=32768); } } else { - height = this->source_height >> 1; + height = this->next_slice (this, &_dst) >> 1; do { dst_1 = (uint32_t*)_dst; dst_2 = (void*)( (uint8_t *)_dst + this->rgb_stride ); py_1 = _py; py_2 = _py + this->y_stride; pu = _pu; pv = _pv; width = this->source_width >> 3; do { - RGB(0); + X_RGB(0); DST1(0); DST2(0); - RGB(1); + X_RGB(1); DST2(1); DST1(1); - RGB(2); + X_RGB(2); DST1(2); DST2(2); - RGB(3); + X_RGB(3); DST2(3); DST1(3); pu += 4; pv += 4; py_1 += 8; @@ -1476,33 +1560,33 @@ static void yuv2rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst, scale_line (_pv, this->v_buffer, this->dest_width >> 1, this->step_dx); scale_line (_py, this->y_buffer, this->dest_width, this->step_dx); dy = 0; - dst_height = this->dest_height; + dst_height = this->next_slice (this, &_dst); for (height = 0;; ) { dst_1 = _dst; py_1 = this->y_buffer; pu = this->u_buffer; pv = this->v_buffer; width = this->dest_width >> 3; do { - RGB(0); + X_RGB(0); DST1RGB(0); - RGB(1); + X_RGB(1); DST1RGB(1); - RGB(2); + X_RGB(2); DST1RGB(2); - RGB(3); + X_RGB(3); DST1RGB(3); pu += 4; pv += 4; py_1 += 8; dst_1 += 24; @@ -1540,36 +1624,36 @@ static void yuv2rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst, } height++; } while (dy>=32768); } } else { - height = this->source_height >> 1; + height = this->next_slice (this, &_dst) >> 1; do { dst_1 = _dst; dst_2 = (void*)( (uint8_t *)_dst + this->rgb_stride ); py_1 = _py; py_2 = _py + this->y_stride; pu = _pu; pv = _pv; width = this->source_width >> 3; do { - RGB(0); + X_RGB(0); DST1RGB(0); DST2RGB(0); - RGB(1); + X_RGB(1); DST2RGB(1); DST1RGB(1); - RGB(2); + X_RGB(2); DST1RGB(2); DST2RGB(2); - RGB(3); + X_RGB(3); DST2RGB(3); DST1RGB(3); pu += 4; pv += 4; py_1 += 8; @@ -1607,33 +1691,33 @@ static void yuv2rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst, scale_line (_pv, this->v_buffer, this->dest_width >> 1, this->step_dx); scale_line (_py, this->y_buffer, this->dest_width, this->step_dx); dy = 0; - dst_height = this->dest_height; + dst_height = this->next_slice (this, &_dst); for (height = 0;; ) { dst_1 = _dst; py_1 = this->y_buffer; pu = this->u_buffer; pv = this->v_buffer; width = this->dest_width >> 3; do { - RGB(0); + X_RGB(0); DST1BGR(0); - RGB(1); + X_RGB(1); DST1BGR(1); - RGB(2); + X_RGB(2); DST1BGR(2); - RGB(3); + X_RGB(3); DST1BGR(3); pu += 4; pv += 4; py_1 += 8; dst_1 += 24; @@ -1672,35 +1756,35 @@ static void yuv2rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst, } height++; } while( dy>=32768 ); } } else { - height = this->source_height >> 1; + height = this->next_slice (this, &_dst) >> 1; do { dst_1 = _dst; dst_2 = (void*)( (uint8_t *)_dst + this->rgb_stride ); py_1 = _py; py_2 = _py + this->y_stride; pu = _pu; pv = _pv; width = this->source_width >> 3; do { - RGB(0); + X_RGB(0); DST1BGR(0); DST2BGR(0); - RGB(1); + X_RGB(1); DST2BGR(1); DST1BGR(1); - RGB(2); + X_RGB(2); DST1BGR(2); DST2BGR(2); - RGB(3); + X_RGB(3); DST2BGR(3); DST1BGR(3); pu += 4; pv += 4; py_1 += 8; @@ -1738,33 +1822,33 @@ static void yuv2rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst, scale_line (_pv, this->v_buffer, this->dest_width >> 1, this->step_dx); scale_line (_py, this->y_buffer, this->dest_width, this->step_dx); dy = 0; - dst_height = this->dest_height; + dst_height = this->next_slice (this, &_dst); for (height = 0;; ) { dst_1 = (uint16_t*)_dst; py_1 = this->y_buffer; pu = this->u_buffer; pv = this->v_buffer; width = this->dest_width >> 3; do { - RGB(0); + X_RGB(0); DST1(0); - RGB(1); + X_RGB(1); DST1(1); - RGB(2); + X_RGB(2); DST1(2); - RGB(3); + X_RGB(3); DST1(3); pu += 4; pv += 4; py_1 += 8; dst_1 += 8; @@ -1802,35 +1886,35 @@ static void yuv2rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst, } height++; } while( dy>=32768); } } else { - height = this->source_height >> 1; + height = this->next_slice (this, &_dst) >> 1; do { dst_1 = (uint16_t*)_dst; dst_2 = (void*)( (uint8_t *)_dst + this->rgb_stride ); py_1 = _py; py_2 = _py + this->y_stride; pu = _pu; pv = _pv; width = this->source_width >> 3; do { - RGB(0); + X_RGB(0); DST1(0); DST2(0); - RGB(1); + X_RGB(1); DST2(1); DST1(1); - RGB(2); + X_RGB(2); DST1(2); DST2(2); - RGB(3); + X_RGB(3); DST2(3); DST1(3); pu += 4; pv += 4; py_1 += 8; @@ -1868,33 +1952,33 @@ static void yuv2rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst, scale_line (_pv, this->v_buffer, this->dest_width >> 1, this->step_dx); scale_line (_py, this->y_buffer, this->dest_width, this->step_dx); dy = 0; - dst_height = this->dest_height; + dst_height = this->next_slice (this, &_dst); for (height = 0;; ) { dst_1 = (uint8_t*)_dst; py_1 = this->y_buffer; pu = this->u_buffer; pv = this->v_buffer; width = this->dest_width >> 3; do { - RGB(0); + X_RGB(0); DST1(0); - RGB(1); + X_RGB(1); DST1(1); - RGB(2); + X_RGB(2); DST1(2); - RGB(3); + X_RGB(3); DST1(3); pu += 4; pv += 4; py_1 += 8; dst_1 += 8; @@ -1932,36 +2016,36 @@ static void yuv2rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst, } height++; } while( dy>=32768 ); } } else { - height = this->source_height >> 1; + height = this->next_slice (this, &_dst) >> 1; do { dst_1 = (uint8_t*)_dst; dst_2 = (void*)( (uint8_t *)_dst + this->rgb_stride ); py_1 = _py; py_2 = _py + this->y_stride; pu = _pu; pv = _pv; width = this->source_width >> 3; do { - RGB(0); + X_RGB(0); DST1(0); DST2(0); - RGB(1); + X_RGB(1); DST2(1); DST1(1); - RGB(2); + X_RGB(2); DST1(2); DST2(2); - RGB(3); + X_RGB(3); DST2(3); DST1(3); pu += 4; pv += 4; py_1 += 8; @@ -1987,13 +2071,13 @@ static void yuv2rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst, int dy; if (this->do_scale) { scale_line_func_t scale_line = this->scale_line; dy = 0; - dst_height = this->dest_height; + dst_height = this->next_slice (this, &_dst); for (;;) { scale_line (_py, _dst, this->dest_width, this->step_dx); dy += this->step_dy; _dst += this->rgb_stride; @@ -2013,13 +2097,13 @@ static void yuv2rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst, dy &= 32767; /* dy -= 32768; _py += this->y_stride; */ } } else { - for (height = this->source_height; --height >= 0; ) { + for (height = this->next_slice (this, &_dst); --height >= 0; ) { xine_fast_memcpy(_dst, _py, this->dest_width); _dst += this->rgb_stride; _py += this->y_stride; } } } @@ -2043,33 +2127,33 @@ static void yuv2rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst, scale_line (_pv, this->v_buffer, this->dest_width >> 1, this->step_dx); scale_line (_py, this->y_buffer, this->dest_width, this->step_dx); dy = 0; - dst_height = this->dest_height; + dst_height = this->next_slice (this, &_dst); for (height = 0;; ) { dst_1 = _dst; py_1 = this->y_buffer; pu = this->u_buffer; pv = this->v_buffer; width = this->dest_width >> 3; do { - RGB(0); + X_RGB(0); DST1CMAP(0); - RGB(1); + X_RGB(1); DST1CMAP(1); - RGB(2); + X_RGB(2); DST1CMAP(2); - RGB(3); + X_RGB(3); DST1CMAP(3); pu += 4; pv += 4; py_1 += 8; dst_1 += 8; @@ -2107,35 +2191,35 @@ static void yuv2rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst, } height++; } while( dy>=32768 ); } } else { - height = this->source_height >> 1; + height = this->next_slice (this, &_dst) >> 1; do { dst_1 = _dst; dst_2 = _dst + this->rgb_stride; py_1 = _py; py_2 = _py + this->y_stride; pu = _pu; pv = _pv; width = this->source_width >> 3; do { - RGB(0); + X_RGB(0); DST1CMAP(0); DST2CMAP(0); - RGB(1); + X_RGB(1); DST2CMAP(1); DST1CMAP(1); - RGB(2); + X_RGB(2); DST1CMAP(2); DST2CMAP(2); - RGB(3); + X_RGB(3); DST2CMAP(3); DST1CMAP(3); pu += 4; pv += 4; py_1 += 8; @@ -2158,13 +2242,14 @@ static int div_round (int dividend, int divisor) if (dividend > 0) return (dividend + (divisor>>1)) / divisor; else return -((-dividend + (divisor>>1)) / divisor); } -static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped) +static void yuv2rgb_set_csc_levels (yuv2rgb_factory_t *this, + int brightness, int contrast, int saturation) { int i; uint8_t table_Y[1024]; uint32_t * table_32 = 0; uint16_t * table_16 = 0; uint8_t * table_8 = 0; @@ -2174,24 +2259,30 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped int crv = Inverse_Table_6_9[this->matrix_coefficients][0]; int cbu = Inverse_Table_6_9[this->matrix_coefficients][1]; int cgu = -Inverse_Table_6_9[this->matrix_coefficients][2]; int cgv = -Inverse_Table_6_9[this->matrix_coefficients][3]; + int mode = this->mode; + int swapped = this->swapped; + for (i = 0; i < 1024; i++) { int j; - j = (76309 * (i - 384 - 16) + 32768) >> 16; + j = (76309 * (i - 384 - 16 + brightness) + 32768) >> 16; j = (j < 0) ? 0 : ((j > 255) ? 255 : j); table_Y[i] = j; } switch (mode) { case MODE_32_RGB: case MODE_32_BGR: - table_32 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t)); + if (this->table_base == NULL) { + this->table_base = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t)); + } + table_32 = this->table_base; entry_size = sizeof (uint32_t); table_r = table_32 + 197; table_b = table_32 + 197 + 685; table_g = table_32 + 197 + 2*682; @@ -2214,26 +2305,32 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped for (i = -232; i < 256+232; i++) ((uint32_t *) table_b)[i] = table_Y[i+384] << shift_b; break; case MODE_24_RGB: case MODE_24_BGR: - table_8 = malloc ((256 + 2*232) * sizeof (uint8_t)); + if (this->table_base == NULL) { + this->table_base = malloc ((256 + 2*232) * sizeof (uint8_t)); + } + table_8 = this->table_base; entry_size = sizeof (uint8_t); table_r = table_g = table_b = table_8 + 232; for (i = -232; i < 256+232; i++) ((uint8_t * )table_b)[i] = table_Y[i+384]; break; case MODE_15_BGR: case MODE_16_BGR: case MODE_15_RGB: case MODE_16_RGB: - table_16 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t)); + if (this->table_base == NULL) { + this->table_base = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t)); + } + table_16 = this->table_base; entry_size = sizeof (uint16_t); table_r = table_16 + 197; table_b = table_16 + 197 + 685; table_g = table_16 + 197 + 2*682; @@ -2267,13 +2364,16 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped ((uint16_t *)table_b)[i] = (table_Y[i+384] >> 3) << shift_b; break; case MODE_8_RGB: case MODE_8_BGR: - table_8 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t)); + if (this->table_base == NULL) { + this->table_base = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t)); + } + table_8 = this->table_base; entry_size = sizeof (uint8_t); table_r = table_8 + 197; table_b = table_8 + 197 + 685; table_g = table_8 + 197 + 2*682; @@ -2291,13 +2391,16 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped break; case MODE_8_GRAY: return; case MODE_PALETTE: - table_16 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t)); + if (this->table_base == NULL) { + this->table_base = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t)); + } + table_16 = this->table_base; entry_size = sizeof (uint16_t); table_r = table_16 + 197; table_b = table_16 + 197 + 685; table_g = table_16 + 197 + 2*682; @@ -2315,27 +2418,29 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped ((uint16_t *)table_b)[i] = (table_Y[i+384] >> 3) << 0; break; default: - fprintf (stderr, "mode %d not supported by yuv2rgb\n", mode); - abort(); + lprintf ("mode %d not supported by yuv2rgb\n", mode); + _x_abort(); } for (i = 0; i < 256; i++) { this->table_rV[i] = (((uint8_t *) table_r) + entry_size * div_round (crv * (i-128), 76309)); this->table_gU[i] = (((uint8_t *) table_g) + entry_size * div_round (cgu * (i-128), 76309)); this->table_gV[i] = entry_size * div_round (cgv * (i-128), 76309); this->table_bU[i] = (((uint8_t *)table_b) + entry_size * div_round (cbu * (i-128), 76309)); } - this->gamma = 0; - this->entry_size = entry_size; + +#if defined(ARCH_X86) || defined(ARCH_X86_64) + mmx_yuv2rgb_set_csc_levels (this, brightness, contrast, saturation); +#endif } static uint32_t yuv2rgb_single_pixel_32 (yuv2rgb_t *this, uint8_t y, uint8_t u, uint8_t v) { uint32_t * r, * g, * b; @@ -2445,14 +2550,14 @@ static void yuv2rgb_c_init (yuv2rgb_factory_t *this) case MODE_PALETTE: this->yuv2rgb_fun = yuv2rgb_c_palette; break; default: - printf ("yuv2rgb: mode %d not supported by yuv2rgb\n", this->mode); - abort(); + lprintf ("mode %d not supported by yuv2rgb\n", this->mode); + _x_abort(); } } static void yuv2rgb_single_pixel_init (yuv2rgb_factory_t *this) { @@ -2488,14 +2593,14 @@ static void yuv2rgb_single_pixel_init (yuv2rgb_factory_t *this) { case MODE_PALETTE: this->yuv2rgb_single_pixel_fun = yuv2rgb_single_pixel_palette; break; default: - printf ("yuv2rgb: mode %d not supported by yuv2rgb\n", this->mode); - abort(); + lprintf ("mode %d not supported by yuv2rgb\n", this->mode); + _x_abort(); } } /* * yuy2 stuff @@ -2517,34 +2622,34 @@ static void yuy22rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p) scale_line_4 (_p+3, this->v_buffer, this->dest_width >> 1, this->step_dx); scale_line_2 (_p, this->y_buffer, this->dest_width, this->step_dx); dy = 0; - height = this->dest_height; + height = this->next_slice (this, &_dst); for (;;) { dst_1 = (uint32_t*)_dst; py_1 = this->y_buffer; pu = this->u_buffer; pv = this->v_buffer; width = this->dest_width >> 3; do { - RGB(0); + X_RGB(0); DST1(0); - RGB(1); + X_RGB(1); DST1(1); - RGB(2); + X_RGB(2); DST1(2); - RGB(3); + X_RGB(3); DST1(3); pu += 4; pv += 4; py_1 += 8; dst_1 += 8; @@ -2561,13 +2666,13 @@ static void yuy22rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p) _dst += this->rgb_stride; } if (height <= 0) break; - _p += this->y_stride*2*(dy>>15); + _p += this->y_stride*(dy>>15); dy &= 32767; /* dy -= 32768; _p += this->y_stride*2; */ @@ -2596,33 +2701,33 @@ static void yuy22rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p) scale_line_4 (_p+3, this->v_buffer, this->dest_width >> 1, this->step_dx); scale_line_2 (_p, this->y_buffer, this->dest_width, this->step_dx); dy = 0; - height = this->dest_height; + height = this->next_slice (this, &_dst); for (;;) { dst_1 = _dst; py_1 = this->y_buffer; pu = this->u_buffer; pv = this->v_buffer; width = this->dest_width >> 3; do { - RGB(0); + X_RGB(0); DST1RGB(0); - RGB(1); + X_RGB(1); DST1RGB(1); - RGB(2); + X_RGB(2); DST1RGB(2); - RGB(3); + X_RGB(3); DST1RGB(3); pu += 4; pv += 4; py_1 += 8; dst_1 += 24; @@ -2639,13 +2744,13 @@ static void yuy22rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p) _dst += this->rgb_stride; } if (height <= 0) break; - _p += this->y_stride*2*(dy>>15); + _p += this->y_stride*(dy>>15); dy &= 32767; /* dy -= 32768; _p += this->y_stride*2; */ @@ -2674,33 +2779,33 @@ static void yuy22rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p) scale_line_4 (_p+3, this->v_buffer, this->dest_width >> 1, this->step_dx); scale_line_2 (_p, this->y_buffer, this->dest_width, this->step_dx); dy = 0; - height = this->dest_height; + height = this->next_slice (this, &_dst); for (;;) { dst_1 = _dst; py_1 = this->y_buffer; pu = this->u_buffer; pv = this->v_buffer; width = this->dest_width >> 3; do { - RGB(0); + X_RGB(0); DST1BGR(0); - RGB(1); + X_RGB(1); DST1BGR(1); - RGB(2); + X_RGB(2); DST1BGR(2); - RGB(3); + X_RGB(3); DST1BGR(3); pu += 4; pv += 4; py_1 += 8; dst_1 += 24; @@ -2717,13 +2822,13 @@ static void yuy22rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p) _dst += this->rgb_stride; } if (height <= 0) break; - _p += this->y_stride*2*(dy>>15); + _p += this->y_stride*(dy>>15); dy &= 32767; scale_line_4 (_p+1, this->u_buffer, this->dest_width >> 1, this->step_dx); scale_line_4 (_p+3, this->v_buffer, this->dest_width >> 1, this->step_dx); @@ -2748,33 +2853,33 @@ static void yuy22rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p) scale_line_4 (_p+3, this->v_buffer, this->dest_width >> 1, this->step_dx); scale_line_2 (_p, this->y_buffer, this->dest_width, this->step_dx); dy = 0; - height = this->dest_height; + height = this->next_slice (this, &_dst); for (;;) { dst_1 = (uint16_t*)_dst; py_1 = this->y_buffer; pu = this->u_buffer; pv = this->v_buffer; width = this->dest_width >> 3; do { - RGB(0); + X_RGB(0); DST1(0); - RGB(1); + X_RGB(1); DST1(1); - RGB(2); + X_RGB(2); DST1(2); - RGB(3); + X_RGB(3); DST1(3); pu += 4; pv += 4; py_1 += 8; dst_1 += 8; @@ -2791,13 +2896,13 @@ static void yuy22rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p) _dst += this->rgb_stride; } if (height <= 0) break; - _p += this->y_stride*2*(dy>>15); + _p += this->y_stride*(dy>>15); dy &= 32767; scale_line_4 (_p+1, this->u_buffer, this->dest_width >> 1, this->step_dx); scale_line_4 (_p+3, this->v_buffer, this->dest_width >> 1, this->step_dx); @@ -2822,33 +2927,33 @@ static void yuy22rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p) scale_line_4 (_p+3, this->v_buffer, this->dest_width >> 1, this->step_dx); scale_line_2 (_p, this->y_buffer, this->dest_width, this->step_dx); dy = 0; - height = this->dest_height; + height = this->next_slice (this, &_dst); for (;;) { dst_1 = _dst; py_1 = this->y_buffer; pu = this->u_buffer; pv = this->v_buffer; width = this->dest_width >> 3; do { - RGB(0); + X_RGB(0); DST1(0); - RGB(1); + X_RGB(1); DST1(1); - RGB(2); + X_RGB(2); DST1(2); - RGB(3); + X_RGB(3); DST1(3); pu += 4; pv += 4; py_1 += 8; dst_1 += 8; @@ -2865,13 +2970,13 @@ static void yuy22rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p) _dst += this->rgb_stride; } if (height <= 0) break; - _p += this->y_stride*2*(dy>>15); + _p += this->y_stride*(dy>>15); dy &= 32767; scale_line_4 (_p+1, this->u_buffer, this->dest_width >> 1, this->step_dx); scale_line_4 (_p+3, this->v_buffer, this->dest_width >> 1, this->step_dx); @@ -2886,13 +2991,13 @@ static void yuy22rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p) int dy; uint8_t * dst; uint8_t * y; if (this->do_scale) { dy = 0; - height = this->dest_height; + height = this->next_slice (this, &_dst); for (;;) { scale_line_2 (_p, _dst, this->dest_width, this->step_dx); dy += this->step_dy; _dst += this->rgb_stride; @@ -2905,25 +3010,25 @@ static void yuy22rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p) _dst += this->rgb_stride; } if (height <= 0) break; - _p += this->y_stride*2*(dy>>15); + _p += this->y_stride*(dy>>15); dy &= 32767; } } else { - for (height = this->source_height; --height >= 0; ) { + for (height = this->next_slice (this, &_dst); --height >= 0; ) { dst = _dst; y = _p; for (width = this->source_width; --width >= 0; ) { *dst++ = *y; y += 2; } _dst += this->rgb_stride; - _p += this->y_stride*2; + _p += this->y_stride; } } } static void yuy22rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p) { @@ -2939,33 +3044,33 @@ static void yuy22rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p) scale_line_4 (_p+3, this->v_buffer, this->dest_width >> 1, this->step_dx); scale_line_2 (_p, this->y_buffer, this->dest_width, this->step_dx); dy = 0; - height = this->dest_height; + height = this->next_slice (this, &_dst); for (;;) { dst_1 = _dst; py_1 = this->y_buffer; pu = this->u_buffer; pv = this->v_buffer; width = this->dest_width >> 3; do { - RGB(0); + X_RGB(0); DST1CMAP(0); - RGB(1); + X_RGB(1); DST1CMAP(1); - RGB(2); + X_RGB(2); DST1CMAP(2); - RGB(3); + X_RGB(3); DST1CMAP(3); pu += 4; pv += 4; py_1 += 8; dst_1 += 8; @@ -2982,13 +3087,13 @@ static void yuy22rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p) _dst += this->rgb_stride; } if (height <= 0) break; - _p += this->y_stride*2*(dy>>15); + _p += this->y_stride*(dy>>15); dy &= 32767; scale_line_4 (_p+1, this->u_buffer, this->dest_width >> 1, this->step_dx); scale_line_4 (_p+3, this->v_buffer, this->dest_width >> 1, this->step_dx); @@ -3030,125 +3135,131 @@ static void yuy22rgb_c_init (yuv2rgb_factory_t *this) case MODE_PALETTE: this->yuy22rgb_fun = yuy22rgb_c_palette; break; default: - printf ("yuv2rgb: mode %d not supported for yuy2\n", this->mode); + lprintf ("mode %d not supported for yuy2\n", this->mode); } } -yuv2rgb_t *yuv2rgb_create_converter (yuv2rgb_factory_t *factory) { +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; this->table_bU = factory->table_bU; + this->table_mmx = factory->table_mmx; this->yuv2rgb_fun = factory->yuv2rgb_fun; this->yuy22rgb_fun = factory->yuy22rgb_fun; this->yuv2rgb_single_pixel_fun = factory->yuv2rgb_single_pixel_fun; this->configure = yuv2rgb_configure; + this->next_slice = yuv2rgb_next_slice; + this->dispose = yuv2rgb_dispose; return this; } /* * factory functions */ -void yuv2rgb_set_gamma (yuv2rgb_factory_t *this, int gamma) { - - int i; - - for (i = 0; i < 256; i++) { - (uint8_t *)this->table_rV[i] += this->entry_size*(gamma - this->gamma); - (uint8_t *)this->table_gU[i] += this->entry_size*(gamma - this->gamma); - (uint8_t *)this->table_bU[i] += this->entry_size*(gamma - this->gamma); - } -#ifdef ARCH_X86 - mmx_yuv2rgb_set_gamma(gamma); -#endif - this->gamma = gamma; -} -int yuv2rgb_get_gamma (yuv2rgb_factory_t *this) { +static void yuv2rgb_factory_dispose (yuv2rgb_factory_t *this) { - return this->gamma; + free (this->table_base); + free (this->table_mmx_base); + free (this); } yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped, uint8_t *cmap) { yuv2rgb_factory_t *this; - -#ifdef ARCH_X86 uint32_t mm = xine_mm_accel(); -#endif this = malloc (sizeof (yuv2rgb_factory_t)); this->mode = mode; this->swapped = swapped; this->cmap = cmap; this->create_converter = yuv2rgb_create_converter; - this->set_gamma = yuv2rgb_set_gamma; - this->get_gamma = yuv2rgb_get_gamma; + this->set_csc_levels = yuv2rgb_set_csc_levels; + this->dispose = yuv2rgb_factory_dispose; this->matrix_coefficients = 6; + this->table_base = NULL; + this->table_mmx = NULL; + this->table_mmx_base = NULL; - yuv2rgb_setup_tables (this, mode, swapped); + yuv2rgb_set_csc_levels (this, 0, 128, 128); /* * auto-probe for the best yuv2rgb function */ this->yuv2rgb_fun = NULL; -#ifdef ARCH_X86 +#if defined(ARCH_X86) || defined(ARCH_X86_64) if ((this->yuv2rgb_fun == NULL) && (mm & MM_ACCEL_X86_MMXEXT)) { yuv2rgb_init_mmxext (this); +#ifdef LOG if (this->yuv2rgb_fun != NULL) printf ("yuv2rgb: using MMXEXT for colorspace transform\n"); +#endif } if ((this->yuv2rgb_fun == NULL) && (mm & MM_ACCEL_X86_MMX)) { yuv2rgb_init_mmx (this); +#ifdef LOG if (this->yuv2rgb_fun != NULL) printf ("yuv2rgb: using MMX for colorspace transform\n"); +#endif } +#ifdef __arm__ + if (this->yuv2rgb_fun == NULL) { + yuv2rgb_init_arm ( this ); + + if(this->yuv2rgb_fun != NULL) + printf("yuv2rgb: using arm4l assembler for colorspace transform\n" ); + } +#endif + #endif #if HAVE_MLIB - if (this->yuv2rgb_fun == NULL) { + if ((this->yuv2rgb_fun == NULL) && (mm & MM_ACCEL_MLIB)) { yuv2rgb_init_mlib (this); +#ifdef LOG if (this->yuv2rgb_fun != NULL) printf ("yuv2rgb: using medialib for colorspace transform\n"); - } #endif -#ifdef __arm__ - if (this->yuv2rgb_fun == NULL) { - yuv2rgb_init_arm ( this ); - - if(this->yuv2rgb_fun != NULL) - printf("yuv2rgb: using arm4l assembler for colorspace transform\n" ); } #endif if (this->yuv2rgb_fun == NULL) { - printf ("yuv2rgb: no accelerated colorspace conversion found\n"); + lprintf ("no accelerated colorspace conversion found\n"); + yuv2rgb_c_init (this); } /* * auto-probe for the best yuy22rgb function */ @@ -3161,7 +3272,6 @@ yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped, */ yuv2rgb_single_pixel_init (this); return this; } - |