summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/nullvideo.c2
-rw-r--r--noncore/multimedia/opieplayer2/yuv2rgb.c4
2 files changed, 4 insertions, 2 deletions
diff --git a/noncore/multimedia/opieplayer2/nullvideo.c b/noncore/multimedia/opieplayer2/nullvideo.c
index a49f9d3..095f206 100644
--- a/noncore/multimedia/opieplayer2/nullvideo.c
+++ b/noncore/multimedia/opieplayer2/nullvideo.c
@@ -1,502 +1,504 @@
/*
                This file is part of the Opie Project
              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org>
Copyright (c) 2002 LJP <>
Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
=.
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <xine.h>
#include <xine/video_out.h>
#include <xine/xine_internal.h>
#include <xine/xineutils.h>
#include <xine/vo_scale.h>
#include <xine/buffer.h>
#include <pthread.h>
#include "alphablend.h"
#include "yuv2rgb.h"
#define printf(x,...)
/*
#define LOG
*/
/* the caller for our event draw handler */
typedef void (*display_xine_frame_t) (void *user_data, uint8_t* frame,
int width, int height,int bytes );
typedef struct null_driver_s null_driver_t;
struct null_driver_s {
vo_driver_t vo_driver;
uint32_t m_capabilities;
int m_show_video;
int m_video_fullscreen;
int m_is_scaling;
int depth, bpp, bytes_per_pixel;
int yuv2rgb_mode;
int yuv2rgb_swap;
int yuv2rgb_gamma;
uint8_t *yuv2rgb_cmap;
yuv2rgb_factory_t *yuv2rgb_factory;
vo_overlay_t *overlay;
vo_scale_t sc;
int gui_width;
int gui_height;
int gui_changed;
double display_ratio;
void* caller;
display_xine_frame_t frameDis;
};
typedef struct opie_frame_s opie_frame_t;
struct opie_frame_s {
vo_frame_t frame;
int format;
int flags;
vo_scale_t sc;
uint8_t *chunk[3];
uint8_t *data; /* rgb */
int bytes_per_line;
yuv2rgb_t *yuv2rgb;
uint8_t *rgb_dst;
int yuv_stride;
int stripe_height, stripe_inc;
null_driver_t *output;
};
static uint32_t null_get_capabilities( vo_driver_t *self ){
null_driver_t* this = (null_driver_t*)self;
return this->m_capabilities;
}
static void null_frame_copy (vo_frame_t *vo_img, uint8_t **src) {
opie_frame_t *frame = (opie_frame_t *) vo_img ;
+ vo_img->copy_called = 1;
+
if (!frame->output->m_show_video) {
/* printf("nullvideo: no video\n"); */
return;
}
if (frame->format == XINE_IMGFMT_YV12) {
frame->yuv2rgb->yuv2rgb_fun (frame->yuv2rgb, frame->rgb_dst,
src[0], src[1], src[2]);
} else {
frame->yuv2rgb->yuy22rgb_fun (frame->yuv2rgb, frame->rgb_dst,
src[0]);
}
frame->rgb_dst += frame->stripe_inc;
}
static void null_frame_field (vo_frame_t *vo_img, int which_field) {
opie_frame_t *frame = (opie_frame_t *) vo_img ;
switch (which_field) {
case VO_TOP_FIELD:
frame->rgb_dst = (uint8_t *)frame->data;
frame->stripe_inc = 2*frame->stripe_height * frame->bytes_per_line;
break;
case VO_BOTTOM_FIELD:
frame->rgb_dst = (uint8_t *)frame->data + frame->bytes_per_line ;
frame->stripe_inc = 2*frame->stripe_height * frame->bytes_per_line;
break;
case VO_BOTH_FIELDS:
frame->rgb_dst = (uint8_t *)frame->data;
break;
}
}
/* take care of the frame*/
static void null_frame_dispose( vo_frame_t* vo_img){
opie_frame_t* frame = (opie_frame_t*)vo_img;
if (frame->data)
free( frame->data );
free (frame);
}
/* end take care of frames*/
static vo_frame_t* null_alloc_frame( vo_driver_t* self ){
null_driver_t* this = (null_driver_t*)self;
opie_frame_t* frame;
#ifdef LOG
fprintf (stderr, "nullvideo: alloc_frame\n");
#endif
frame = (opie_frame_t*)malloc ( sizeof(opie_frame_t) );
memset( frame, 0, sizeof( opie_frame_t) );
memcpy (&frame->sc, &this->sc, sizeof(vo_scale_t));
pthread_mutex_init (&frame->frame.mutex, NULL);
frame->output = this;
/* initialize the frame*/
frame->frame.driver = self;
frame->frame.copy = null_frame_copy;
frame->frame.field = null_frame_field;
frame->frame.dispose = null_frame_dispose;
/*
* colorspace converter for this frame
*/
frame->yuv2rgb = this->yuv2rgb_factory->create_converter (this->yuv2rgb_factory);
return (vo_frame_t*) frame;
}
static void null_update_frame_format( vo_driver_t* self, vo_frame_t* img,
uint32_t width, uint32_t height,
int ratio_code, int format, int flags ){
null_driver_t* this = (null_driver_t*) self;
opie_frame_t* frame = (opie_frame_t*)img;
/* not needed now */
#ifdef LOG
fprintf (stderr, "nullvideo: update_frame_format\n");
#endif
flags &= VO_BOTH_FIELDS;
/* find out if we need to adapt this frame */
if ((width != frame->sc.delivered_width)
|| (height != frame->sc.delivered_height)
|| (ratio_code != frame->sc.delivered_ratio_code)
|| (flags != frame->flags)
|| (format != frame->format)
|| (this->sc.user_ratio != frame->sc.user_ratio)
|| (this->gui_width != frame->sc.gui_width)
|| (this->gui_height != frame->sc.gui_height)) {
frame->sc.delivered_width = width;
frame->sc.delivered_height = height;
frame->sc.delivered_ratio_code = ratio_code;
frame->flags = flags;
frame->format = format;
frame->sc.user_ratio = this->sc.user_ratio;
frame->sc.gui_width = this->gui_width;
frame->sc.gui_height = this->gui_height;
frame->sc.gui_pixel_aspect = 1.0;
vo_scale_compute_ideal_size ( &frame->sc );
vo_scale_compute_output_size( &frame->sc );
#ifdef LOG
fprintf (stderr, "nullvideo: gui %dx%d delivered %dx%d output %dx%d\n",
frame->sc.gui_width, frame->sc.gui_height,
frame->sc.delivered_width, frame->sc.delivered_height,
frame->sc.output_width, frame->sc.output_height);
#endif
/*
* (re-) allocate
*/
if( frame->data ) {
if( frame->chunk[0] ){
free( frame->chunk[0] );
frame->chunk[0] = NULL;
}
if( frame->chunk[1] ){
free ( frame->chunk[1] );
frame->chunk[1] = NULL;
}
if( frame->chunk[2] ){
free ( frame->chunk[2] );
frame->chunk[2] = NULL;
}
free ( frame->data );
}
frame->data = xine_xmalloc (frame->sc.output_width
* frame->sc.output_height
* this->bytes_per_pixel );
if( format == XINE_IMGFMT_YV12 ) {
frame->frame.pitches[0] = 8*((width + 7) / 8);
frame->frame.pitches[1] = 8*((width + 15) / 16);
frame->frame.pitches[2] = 8*((width + 15) / 16);
frame->frame.base[0] = xine_xmalloc_aligned (16, frame->frame.pitches[0] * height,(void **)&frame->chunk[0]);
frame->frame.base[1] = xine_xmalloc_aligned (16, frame->frame.pitches[1] * ((height+ 1)/2), (void **)&frame->chunk[1]);
frame->frame.base[2] = xine_xmalloc_aligned (16, frame->frame.pitches[2] * ((height+ 1)/2), (void **)&frame->chunk[2]);
}else{
frame->frame.pitches[0] = 8*((width + 3) / 4);
frame->frame.base[0] = xine_xmalloc_aligned (16, frame->frame.pitches[0] * height,
(void **)&frame->chunk[0]);
frame->chunk[1] = NULL;
frame->chunk[2] = NULL;
}
frame->stripe_height = 16 * frame->sc.output_height / frame->sc.delivered_height;
frame->bytes_per_line = frame->sc.output_width * this->bytes_per_pixel;
/*
* set up colorspace converter
*/
switch (flags) {
case VO_TOP_FIELD:
case VO_BOTTOM_FIELD:
frame->yuv2rgb->configure (frame->yuv2rgb,
frame->sc.delivered_width,
16,
2*frame->frame.pitches[0],
2*frame->frame.pitches[1],
frame->sc.output_width,
frame->stripe_height,
frame->bytes_per_line*2);
frame->yuv_stride = frame->bytes_per_line*2;
break;
case VO_BOTH_FIELDS:
frame->yuv2rgb->configure (frame->yuv2rgb,
frame->sc.delivered_width,
16,
frame->frame.pitches[0],
frame->frame.pitches[1],
frame->sc.output_width,
frame->stripe_height,
frame->bytes_per_line);
frame->yuv_stride = frame->bytes_per_line;
break;
}
#ifdef LOG
fprintf (stderr, "nullvideo: colorspace converter configured.\n");
#endif
}
/*
* reset dest pointers
*/
if (frame->data) {
switch (flags) {
case VO_TOP_FIELD:
frame->rgb_dst = (uint8_t *)frame->data;
frame->stripe_inc = 2 * frame->stripe_height * frame->bytes_per_line;
break;
case VO_BOTTOM_FIELD:
frame->rgb_dst = (uint8_t *)frame->data + frame->bytes_per_line ;
frame->stripe_inc = 2 * frame->stripe_height * frame->bytes_per_line;
break;
case VO_BOTH_FIELDS:
frame->rgb_dst = (uint8_t *)frame->data;
frame->stripe_inc = frame->stripe_height * frame->bytes_per_line;
break;
}
}
}
static void null_display_frame( vo_driver_t* self, vo_frame_t *frame_gen ){
null_driver_t* this = (null_driver_t*) self;
opie_frame_t* frame = (opie_frame_t*)frame_gen;
display_xine_frame_t display = this->frameDis;
if (!this->m_show_video)
return;
if( display != NULL ) {
(*display)(this->caller, frame->data,
frame->sc.output_width, frame->sc.output_height,
frame->bytes_per_line );
}
frame->frame.displayed (&frame->frame);
}
/* blending related */
static void null_overlay_clut_yuv2rgb (null_driver_t *this,
vo_overlay_t *overlay,
opie_frame_t *frame) {
int i;
clut_t* clut = (clut_t*) overlay->color;
if (!overlay->rgb_clut) {
for (i = 0; i < sizeof(overlay->color)/sizeof(overlay->color[0]); i++) {
*((uint32_t *)&clut[i]) =
frame->yuv2rgb->yuv2rgb_single_pixel_fun (frame->yuv2rgb,
clut[i].y, clut[i].cb, clut[i].cr);
}
overlay->rgb_clut++;
}
if (!overlay->clip_rgb_clut) {
clut = (clut_t*) overlay->clip_color;
for (i = 0; i < sizeof(overlay->color)/sizeof(overlay->color[0]); i++) {
*((uint32_t *)&clut[i]) =
frame->yuv2rgb->yuv2rgb_single_pixel_fun(frame->yuv2rgb,
clut[i].y, clut[i].cb, clut[i].cr);
}
overlay->clip_rgb_clut++;
}
}
static void null_overlay_blend ( vo_driver_t *this_gen, vo_frame_t *frame_gen, vo_overlay_t *overlay) {
null_driver_t *this = (null_driver_t *) this_gen;
opie_frame_t *frame = (opie_frame_t *) frame_gen;
if(!this->m_show_video || frame->sc.output_width == 0
|| frame->sc.output_height== 0)
return;
/* Alpha Blend here */
if (overlay->rle) {
if( !overlay->rgb_clut || !overlay->clip_rgb_clut)
null_overlay_clut_yuv2rgb(this,overlay,frame);
switch(this->bpp) {
case 16:
blend_rgb16( (uint8_t *)frame->data, overlay,
frame->sc.output_width, frame->sc.output_height,
frame->sc.delivered_width, frame->sc.delivered_height);
break;
case 24:
blend_rgb24( (uint8_t *)frame->data, overlay,
frame->sc.output_width, frame->sc.output_height,
frame->sc.delivered_width, frame->sc.delivered_height);
break;
case 32:
blend_rgb32( (uint8_t *)frame->data, overlay,
frame->sc.output_width, frame->sc.output_height,
frame->sc.delivered_width, frame->sc.delivered_height);
break;
default:
/* It should never get here */
break;
}
}
}
static int null_get_property( vo_driver_t* self,
int property ){
return 0;
}
static int null_set_property( vo_driver_t* self,
int property,
int value ){
return value;
}
static void null_get_property_min_max( vo_driver_t* self,
int property, int *min,
int *max ){
*max = 0;
*min = 0;
}
static int null_gui_data_exchange( vo_driver_t* self,
int data_type,
void *data ){
return 0;
}
static void null_dispose ( vo_driver_t* self ){
null_driver_t* this = (null_driver_t*)self;
free ( this );
}
static int null_redraw_needed( vo_driver_t* self ){
return 0;
}
xine_vo_driver_t* init_video_out_plugin( xine_t *xine,
void* video, display_xine_frame_t frameDisplayFunc, void *userData ){
null_driver_t *vo;
vo = (null_driver_t*)malloc( sizeof(null_driver_t ) );
/* memset? */
memset(vo,0, sizeof(null_driver_t ) );
vo_scale_init (&vo->sc, 0, 0, xine->config);
vo->sc.gui_pixel_aspect = 1.0;
vo->m_show_video = 0; // false
vo->m_video_fullscreen = 0;
vo->m_is_scaling = 0;
vo->display_ratio = 1.0;
vo->gui_width = 16;
vo->gui_height = 8;
vo->frameDis = NULL;
/* install callback handlers*/
vo->vo_driver.get_capabilities = null_get_capabilities;
vo->vo_driver.alloc_frame = null_alloc_frame;
vo->vo_driver.update_frame_format = null_update_frame_format;
vo->vo_driver.display_frame = null_display_frame;
vo->vo_driver.overlay_blend = null_overlay_blend;
vo->vo_driver.get_property = null_get_property;
vo->vo_driver.set_property = null_set_property;
vo->vo_driver.get_property_min_max = null_get_property_min_max;
vo->vo_driver.gui_data_exchange = null_gui_data_exchange;
vo->vo_driver.dispose = null_dispose;
vo->vo_driver.redraw_needed = null_redraw_needed;
/* capabilities */
vo->m_capabilities = VO_CAP_COPIES_IMAGE | VO_CAP_YUY2 | VO_CAP_YV12;
vo->yuv2rgb_factory = yuv2rgb_factory_init (MODE_16_RGB, vo->yuv2rgb_swap,
vo->yuv2rgb_cmap);
vo->caller = userData;
vo->frameDis = frameDisplayFunc;
/* return ( vo_driver_t*) vo; */
return vo_new_port( xine, ( vo_driver_t* )vo );
}
#if 0
static vo_info_t vo_info_null = {
5,
XINE_VISUAL_TYPE_FB
};
diff --git a/noncore/multimedia/opieplayer2/yuv2rgb.c b/noncore/multimedia/opieplayer2/yuv2rgb.c
index e8e86e6..8e34052 100644
--- a/noncore/multimedia/opieplayer2/yuv2rgb.c
+++ b/noncore/multimedia/opieplayer2/yuv2rgb.c
@@ -826,773 +826,773 @@ static void scale_line_9_16 (uint8_t *source, uint8_t *dest,
dest[2] = (7*p2 + 1*p1) >> 3;
dest[3] = (3*p2 + 5*p1) >> 3;
p2 = source[3];
dest[4] = (3*p1 + 1*p2) >> 2;
dest[5] = (1*p1 + 3*p2) >> 2;
p1 = source[4];
dest[6] = (5*p2 + 3*p1) >> 3;
dest[7] = (1*p2 + 7*p1) >> 3;
p2 = source[5];
dest[8] = (1*p1 + 1*p2) >> 1;
p1 = source[6];
dest[9] = p2;
dest[10] = (3*p2 + 5*p1) >> 3;
p2 = source[7];
dest[11] = (7*p1 + 1*p2) >> 3;
dest[12] = (1*p1 + 3*p2) >> 2;
p1 = source[8];
dest[13] = (3*p2 + 1*p1) >> 2;
dest[14] = (1*p2 + 7*p1) >> 3;
p2 = source[9];
dest[15] = (5*p1 + 3*p2) >> 3;
source += 9;
dest += 16;
}
if ((width += 16) <= 0) goto done;
*dest++ = source[0];
if (--width <= 0) goto done;
*dest++ = (1*source[0] + 1*source[1]) >> 1;
if (--width <= 0) goto done;
*dest++ = (7*source[1] + 1*source[2]) >> 3;
if (--width <= 0) goto done;
*dest++ = (3*source[1] + 5*source[2]) >> 3;
if (--width <= 0) goto done;
*dest++ = (3*source[2] + 1*source[3]) >> 2;
if (--width <= 0) goto done;
*dest++ = (1*source[2] + 3*source[3]) >> 2;
if (--width <= 0) goto done;
*dest++ = (5*source[3] + 3*source[4]) >> 3;
if (--width <= 0) goto done;
*dest++ = (1*source[3] + 7*source[4]) >> 3;
if (--width <= 0) goto done;
*dest++ = (1*source[4] + 1*source[5]) >> 1;
if (--width <= 0) goto done;
*dest++ = source[5];
if (--width <= 0) goto done;
*dest++ = (3*source[5] + 5*source[6]) >> 3;
if (--width <= 0) goto done;
*dest++ = (7*source[6] + 1*source[7]) >> 3;
if (--width <= 0) goto done;
*dest++ = (1*source[6] + 3*source[7]) >> 2;
if (--width <= 0) goto done;
*dest++ = (3*source[7] + 1*source[8]) >> 2;
if (--width <= 0) goto done;
*dest++ = (1*source[7] + 7*source[8]) >> 3;
done:
xine_profiler_stop_count(prof_scale_line);
}
/*
* Interpolates 12 output pixels from 11 source pixels using shifts.
* Useful for scaling a PAL vcd input source to 4:3 display format.
*/
static void scale_line_11_12 (uint8_t *source, uint8_t *dest,
int width, int step) {
int p1, p2;
xine_profiler_start_count(prof_scale_line);
while ((width -= 12) >= 0) {
p1 = source[0];
p2 = source[1];
dest[0] = p1;
dest[1] = (1*p1 + 7*p2) >> 3;
p1 = source[2];
dest[2] = (1*p2 + 7*p1) >> 3;
p2 = source[3];
dest[3] = (1*p1 + 3*p2) >> 2;
p1 = source[4];
dest[4] = (3*p2 + 5*p1) >> 3;
p2 = source[5];
dest[5] = (3*p1 + 5*p2) >> 3;
p1 = source[6];
dest[6] = (1*p2 + 1*p1) >> 1;
p2 = source[7];
dest[7] = (5*p1 + 3*p2) >> 3;
p1 = source[8];
dest[8] = (5*p2 + 3*p1) >> 3;
p2 = source[9];
dest[9] = (3*p1 + 1*p2) >> 2;
p1 = source[10];
dest[10] = (7*p2 + 1*p1) >> 3;
p2 = source[11];
dest[11] = (7*p1 + 1*p2) >> 3;
source += 11;
dest += 12;
}
if ((width += 12) <= 0) goto done;
*dest++ = source[0];
if (--width <= 0) goto done;
*dest++ = (1*source[0] + 7*source[1]) >> 3;
if (--width <= 0) goto done;
*dest++ = (1*source[1] + 7*source[2]) >> 3;
if (--width <= 0) goto done;
*dest++ = (1*source[2] + 3*source[3]) >> 2;
if (--width <= 0) goto done;
*dest++ = (3*source[3] + 5*source[4]) >> 3;
if (--width <= 0) goto done;
*dest++ = (3*source[4] + 5*source[5]) >> 3;
if (--width <= 0) goto done;
*dest++ = (1*source[5] + 1*source[6]) >> 1;
if (--width <= 0) goto done;
*dest++ = (5*source[6] + 3*source[7]) >> 3;
if (--width <= 0) goto done;
*dest++ = (5*source[7] + 3*source[8]) >> 3;
if (--width <= 0) goto done;
*dest++ = (3*source[8] + 1*source[9]) >> 2;
if (--width <= 0) goto done;
*dest++ = (7*source[9] + 1*source[10]) >> 3;
done:
xine_profiler_stop_count(prof_scale_line);
}
/*
* Interpolates 24 output pixels from 11 source pixels using shifts.
* Useful for scaling a PAL vcd input source to 4:3 display format
* at 2*zoom.
*/
static void scale_line_11_24 (uint8_t *source, uint8_t *dest,
int width, int step) {
int p1, p2;
xine_profiler_start_count(prof_scale_line);
while ((width -= 24) >= 0) {
p1 = source[0];
p2 = source[1];
dest[0] = p1;
dest[1] = (1*p1 + 1*p2) >> 1;
dest[2] = (1*p1 + 7*p2) >> 3;
p1 = source[2];
dest[3] = (5*p2 + 3*p1) >> 3;
dest[4] = (1*p2 + 7*p1) >> 3;
p2 = source[3];
dest[5] = (3*p1 + 1*p2) >> 2;
dest[6] = (1*p1 + 3*p2) >> 2;
p1 = source[4];
dest[7] = (3*p2 + 1*p1) >> 2;
dest[8] = (3*p2 + 5*p1) >> 3;
p2 = source[5];
dest[9] = (7*p1 + 1*p2) >> 3;
dest[10] = (3*p1 + 5*p2) >> 3;
p1 = source[6];
dest[11] = p2;
dest[12] = (1*p2 + 1*p1) >> 1;
dest[13] = p1;
p2 = source[7];
dest[14] = (5*p1 + 3*p2) >> 3;
dest[15] = (1*p1 + 7*p2) >> 3;
p1 = source[8];
dest[16] = (5*p2 + 3*p1) >> 3;
dest[17] = (1*p2 + 3*p1) >> 2;
p2 = source[9];
dest[18] = (3*p1 + 1*p2) >> 2;
dest[19] = (1*p1 + 3*p2) >> 2;
p1 = source[10];
dest[20] = (7*p2 + 1*p1) >> 3;
dest[21] = (3*p2 + 5*p1) >> 3;
p2 = source[11];
dest[22] = (7*p1 + 1*p2) >> 3;
dest[23] = (1*p1 + 1*p2) >> 1;
source += 11;
dest += 24;
}
if ((width += 24) <= 0) goto done;
*dest++ = source[0];
if (--width <= 0) goto done;
*dest++ = (1*source[0] + 1*source[1]) >> 1;
if (--width <= 0) goto done;
*dest++ = (1*source[0] + 7*source[1]) >> 3;
if (--width <= 0) goto done;
*dest++ = (5*source[1] + 3*source[2]) >> 3;
if (--width <= 0) goto done;
*dest++ = (1*source[1] + 7*source[2]) >> 3;
if (--width <= 0) goto done;
*dest++ = (3*source[2] + 1*source[3]) >> 2;
if (--width <= 0) goto done;
*dest++ = (1*source[2] + 3*source[3]) >> 2;
if (--width <= 0) goto done;
*dest++ = (3*source[3] + 1*source[4]) >> 2;
if (--width <= 0) goto done;
*dest++ = (3*source[3] + 5*source[4]) >> 3;
if (--width <= 0) goto done;
*dest++ = (7*source[4] + 1*source[5]) >> 3;
if (--width <= 0) goto done;
*dest++ = (3*source[4] + 5*source[5]) >> 3;
if (--width <= 0) goto done;
*dest++ = source[5];
if (--width <= 0) goto done;
*dest++ = (1*source[5] + 1*source[6]) >> 1;
if (--width <= 0) goto done;
*dest++ = source[6];
if (--width <= 0) goto done;
*dest++ = (5*source[6] + 3*source[7]) >> 3;
if (--width <= 0) goto done;
*dest++ = (1*source[6] + 7*source[7]) >> 3;
if (--width <= 0) goto done;
*dest++ = (5*source[7] + 3*source[8]) >> 3;
if (--width <= 0) goto done;
*dest++ = (1*source[7] + 3*source[8]) >> 2;
if (--width <= 0) goto done;
*dest++ = (3*source[8] + 1*source[9]) >> 2;
if (--width <= 0) goto done;
*dest++ = (1*source[8] + 3*source[9]) >> 2;
if (--width <= 0) goto done;
*dest++ = (7*source[9] + 1*source[10]) >> 3;
if (--width <= 0) goto done;
*dest++ = (3*source[9] + 5*source[10]) >> 3;
if (--width <= 0) goto done;
*dest++ = (7*source[10] + 1*source[11]) >> 3;
done:
xine_profiler_stop_count(prof_scale_line);
}
/*
* Interpolates 8 output pixels from 5 source pixels using shifts.
* Useful for scaling a PAL svcd input source to 4:3 display format.
*/
static void scale_line_5_8 (uint8_t *source, uint8_t *dest,
int width, int step) {
int p1, p2;
xine_profiler_start_count(prof_scale_line);
while ((width -= 8) >= 0) {
p1 = source[0];
p2 = source[1];
dest[0] = p1;
dest[1] = (3*p1 + 5*p2) >> 3;
p1 = source[2];
dest[2] = (3*p2 + 1*p1) >> 2;
dest[3] = (1*p2 + 7*p1) >> 3;
p2 = source[3];
dest[4] = (1*p1 + 1*p2) >> 1;
p1 = source[4];
dest[5] = (7*p2 + 1*p1) >> 3;
dest[6] = (1*p2 + 3*p1) >> 2;
p2 = source[5];
dest[7] = (5*p1 + 3*p2) >> 3;
source += 5;
dest += 8;
}
if ((width += 8) <= 0) goto done;
*dest++ = source[0];
if (--width <= 0) goto done;
*dest++ = (3*source[0] + 5*source[1]) >> 3;
if (--width <= 0) goto done;
*dest++ = (3*source[1] + 1*source[2]) >> 2;
if (--width <= 0) goto done;
*dest++ = (1*source[1] + 7*source[2]) >> 3;
if (--width <= 0) goto done;
*dest++ = (1*source[2] + 1*source[3]) >> 1;
if (--width <= 0) goto done;
*dest++ = (7*source[3] + 1*source[4]) >> 3;
if (--width <= 0) goto done;
*dest++ = (1*source[3] + 3*source[4]) >> 2;
done:
xine_profiler_stop_count(prof_scale_line);
}
/*
* Interpolates 4 output pixels from 3 source pixels using shifts.
* Useful for scaling a NTSC svcd input source to 4:3 display format.
*/
static void scale_line_3_4 (uint8_t *source, uint8_t *dest,
int width, int step) {
int p1, p2;
xine_profiler_start_count(prof_scale_line);
while ((width -= 4) >= 0) {
p1 = source[0];
p2 = source[1];
dest[0] = p1;
dest[1] = (1*p1 + 3*p2) >> 2;
p1 = source[2];
dest[2] = (1*p2 + 1*p1) >> 1;
p2 = source[3];
dest[3] = (3*p1 + 1*p2) >> 2;
source += 3;
dest += 4;
}
if ((width += 4) <= 0) goto done;
*dest++ = source[0];
if (--width <= 0) goto done;
*dest++ = (1*source[0] + 3*source[1]) >> 2;
if (--width <= 0) goto done;
*dest++ = (1*source[1] + 1*source[2]) >> 1;
done:
xine_profiler_stop_count(prof_scale_line);
}
/* Interpolate 2 output pixels from one source pixel. */
static void scale_line_1_2 (uint8_t *source, uint8_t *dest,
int width, int step) {
int p1, p2;
xine_profiler_start_count(prof_scale_line);
p1 = *source;
while ((width -= 4) >= 0) {
*dest++ = p1;
p2 = *++source;
*dest++ = (p1 + p2) >> 1;
*dest++ = p2;
p1 = *++source;
*dest++ = (p2 + p1) >> 1;
}
if ((width += 4) <= 0) goto done;
*dest++ = source[0];
if (--width <= 0) goto done;
*dest++ = (source[0] + source[1]) >> 1;
if (--width <= 0) goto done;
*dest++ = source[1];
done:
xine_profiler_stop_count(prof_scale_line);
}
/*
* Scale line with no horizontal scaling. For NTSC mpeg2 dvd input in
* 4:3 output format (720x480 -> 720x540)
*/
static void scale_line_1_1 (uint8_t *source, uint8_t *dest,
int width, int step) {
xine_profiler_start_count(prof_scale_line);
xine_fast_memcpy(dest, source, width);
xine_profiler_stop_count(prof_scale_line);
}
static scale_line_func_t find_scale_line_func(int step) {
static struct {
int src_step;
int dest_step;
scale_line_func_t func;
char *desc;
} scale_line[] = {
{ 15, 16, scale_line_15_16, "dvd 4:3(pal)" },
{ 45, 64, scale_line_45_64, "dvd 16:9(pal), fullscreen(1024x768)" },
{ 9, 16, scale_line_9_16, "dvd fullscreen(1280x1024)" },
{ 45, 53, scale_line_45_53, "dvd 16:9(ntsc)" },
{ 11, 12, scale_line_11_12, "vcd 4:3(pal)" },
{ 11, 24, scale_line_11_24, "vcd 4:3(pal) 2*zoom" },
{ 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;
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);
+ //printf("yuv2rgb: using %s optimized scale_line\n", scale_line[i].desc);
return scale_line[i].func;
}
}
- printf("yuv2rgb: using generic scale_line with interpolation\n");
+ //printf("yuv2rgb: using generic scale_line with interpolation\n");
return scale_line_gen;
}
static void scale_line_2 (uint8_t *source, uint8_t *dest,
int width, int step) {
int p1;
int p2;
int dx;
p1 = *source; source+=2;
p2 = *source; source+=2;
dx = 0;
while (width) {
*dest = (p1 * (32768 - dx) + p2 * dx) / 32768;
dx += step;
while (dx > 32768) {
dx -= 32768;
p1 = p2;
p2 = *source;
source+=2;
}
dest ++;
width --;
}
}
static void scale_line_4 (uint8_t *source, uint8_t *dest,
int width, int step) {
int p1;
int p2;
int dx;
p1 = *source; source+=4;
p2 = *source; source+=4;
dx = 0;
while (width) {
*dest = (p1 * (32768 - dx) + p2 * dx) / 32768;
dx += step;
while (dx > 32768) {
dx -= 32768;
p1 = p2;
p2 = *source;
source+=4;
}
dest ++;
width --;
}
}
#define 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];
#define DST1(i) \
Y = py_1[2*i]; \
dst_1[2*i] = r[Y] + g[Y] + b[Y]; \
Y = py_1[2*i+1]; \
dst_1[2*i+1] = r[Y] + g[Y] + b[Y];
#define DST2(i) \
Y = py_2[2*i]; \
dst_2[2*i] = r[Y] + g[Y] + b[Y]; \
Y = py_2[2*i+1]; \
dst_2[2*i+1] = r[Y] + g[Y] + b[Y];
#define DST1RGB(i) \
Y = py_1[2*i]; \
dst_1[6*i] = r[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = b[Y]; \
Y = py_1[2*i+1]; \
dst_1[6*i+3] = r[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = b[Y];
#define DST2RGB(i) \
Y = py_2[2*i]; \
dst_2[6*i] = r[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = b[Y]; \
Y = py_2[2*i+1]; \
dst_2[6*i+3] = r[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = b[Y];
#define DST1BGR(i) \
Y = py_1[2*i]; \
dst_1[6*i] = b[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = r[Y]; \
Y = py_1[2*i+1]; \
dst_1[6*i+3] = b[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = r[Y];
#define DST2BGR(i) \
Y = py_2[2*i]; \
dst_2[6*i] = b[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = r[Y]; \
Y = py_2[2*i+1]; \
dst_2[6*i+3] = b[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = r[Y];
#define DST1CMAP(i) \
Y = py_1[2*i]; \
dst_1[2*i] = this->cmap[r[Y] + g[Y] + b[Y]]; \
Y = py_1[2*i+1]; \
dst_1[2*i+1] = this->cmap[r[Y] + g[Y] + b[Y]];
#define DST2CMAP(i) \
Y = py_2[2*i]; \
dst_2[2*i] = this->cmap[r[Y] + g[Y] + b[Y]]; \
Y = py_2[2*i+1]; \
dst_2[2*i+1] = this->cmap[r[Y] + g[Y] + b[Y]];
static void yuv2rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst,
uint8_t * _py, uint8_t * _pu, uint8_t * _pv)
{
int U, V, Y;
uint8_t * py_1, * py_2, * pu, * pv;
uint32_t * r, * g, * b;
uint32_t * dst_1, * dst_2;
int width, height, dst_height;
int dy;
if (this->do_scale) {
scale_line_func_t scale_line = this->scale_line;
scale_line (_pu, this->u_buffer,
this->dest_width >> 1, this->step_dx);
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;
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);
DST1(0);
RGB(1);
DST1(1);
RGB(2);
DST1(2);
RGB(3);
DST1(3);
pu += 4;
pv += 4;
py_1 += 8;
dst_1 += 8;
} while (--width);
dy += this->step_dy;
_dst += this->rgb_stride;
while (--dst_height > 0 && dy < 32768) {
xine_fast_memcpy (_dst, (uint8_t*)_dst-this->rgb_stride, this->dest_width*4);
dy += this->step_dy;
_dst += this->rgb_stride;
}
if (dst_height <= 0)
break;
do {
dy -= 32768;
_py += this->y_stride;
scale_line (_py, this->y_buffer,
this->dest_width, this->step_dx);
if (height & 1) {
_pu += this->uv_stride;
_pv += this->uv_stride;
scale_line (_pu, this->u_buffer,
this->dest_width >> 1, this->step_dx);
scale_line (_pv, this->v_buffer,
this->dest_width >> 1, this->step_dx);
}
height++;
} while( dy>=32768);
}
} else {
height = this->source_height >> 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);
DST1(0);
DST2(0);
RGB(1);
DST2(1);
DST1(1);
RGB(2);
DST1(2);
DST2(2);
RGB(3);
DST2(3);
DST1(3);
pu += 4;
pv += 4;
py_1 += 8;
py_2 += 8;
dst_1 += 8;
dst_2 += 8;
} while (--width);
_dst += 2 * this->rgb_stride;
_py += 2 * this->y_stride;
_pu += this->uv_stride;
_pv += this->uv_stride;
} while (--height);
}
}
/* This is very near from the yuv2rgb_c_32 code */
static void yuv2rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst,
uint8_t * _py, uint8_t * _pu, uint8_t * _pv)
{
int U, V, Y;
uint8_t * py_1, * py_2, * pu, * pv;
uint8_t * r, * g, * b;
uint8_t * dst_1, * dst_2;
int width, height, dst_height;
int dy;
if (this->do_scale) {
scale_line_func_t scale_line = this->scale_line;
scale_line (_pu, this->u_buffer,
this->dest_width >> 1, this->step_dx);
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;
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);
DST1RGB(0);
RGB(1);
DST1RGB(1);
RGB(2);
DST1RGB(2);
RGB(3);
DST1RGB(3);
pu += 4;
pv += 4;
py_1 += 8;
dst_1 += 24;
} while (--width);
dy += this->step_dy;
_dst += this->rgb_stride;
while (--dst_height > 0 && dy < 32768) {
xine_fast_memcpy (_dst, _dst-this->rgb_stride, this->dest_width*3);
dy += this->step_dy;
_dst += this->rgb_stride;
}
if (dst_height <= 0)
break;
do {
dy -= 32768;
_py += this->y_stride;
scale_line (_py, this->y_buffer,
this->dest_width, this->step_dx);
if (height & 1) {
_pu += this->uv_stride;
_pv += this->uv_stride;
scale_line (_pu, this->u_buffer,
this->dest_width >> 1, this->step_dx);
scale_line (_pv, this->v_buffer,
this->dest_width >> 1, this->step_dx);
}
height++;
} while (dy>=32768);
}
} else {
height = this->source_height >> 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);
DST1RGB(0);
DST2RGB(0);
RGB(1);
DST2RGB(1);
DST1RGB(1);
RGB(2);
DST1RGB(2);
DST2RGB(2);
RGB(3);
DST2RGB(3);
DST1RGB(3);
pu += 4;
pv += 4;
py_1 += 8;
py_2 += 8;
dst_1 += 24;
dst_2 += 24;
} while (--width);
_dst += 2 * this->rgb_stride;
_py += 2 * this->y_stride;
_pu += this->uv_stride;
_pv += this->uv_stride;
} while (--height);
}
}
/* only trivial mods from yuv2rgb_c_24_rgb */
static void yuv2rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst,
uint8_t * _py, uint8_t * _pu, uint8_t * _pv)
{
int U, V, Y;
uint8_t * py_1, * py_2, * pu, * pv;
uint8_t * r, * g, * b;
uint8_t * dst_1, * dst_2;
int width, height, dst_height;