summaryrefslogtreecommitdiff
authorzecke <zecke>2005-04-17 13:56:34 (UTC)
committer zecke <zecke>2005-04-17 13:56:34 (UTC)
commit3d5e5c098ccb686588380bc1f220beafbc5a6d76 (patch) (side-by-side diff)
tree92fad8a98ea341ec290dc7f9fca7759470b795f6
parent49335d66d8e96b1fc86ecfe95cd343c8960126bc (diff)
downloadopie-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 (more/less context) (show whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/alphablend.c1469
-rw-r--r--noncore/multimedia/opieplayer2/alphablend.h91
-rw-r--r--noncore/multimedia/opieplayer2/lib.cpp74
-rw-r--r--noncore/multimedia/opieplayer2/lib.h4
-rw-r--r--noncore/multimedia/opieplayer2/mainTest.cpp16
-rw-r--r--noncore/multimedia/opieplayer2/nullvideo.c220
-rw-r--r--noncore/multimedia/opieplayer2/yuv2rgb.c436
-rw-r--r--noncore/multimedia/opieplayer2/yuv2rgb.h50
8 files changed, 1782 insertions, 578 deletions
diff --git a/noncore/multimedia/opieplayer2/alphablend.c b/noncore/multimedia/opieplayer2/alphablend.c
index cdd7b28..ab80531 100644
--- a/noncore/multimedia/opieplayer2/alphablend.c
+++ b/noncore/multimedia/opieplayer2/alphablend.c
@@ -1,5 +1 @@
-//TOAST_SPU will define ALL spu entries - no matter the tranparency
-//#define TOAST_SPU
-/* #define PRIV_CLUT */
-/* Currently only blend_yuv(..) works */
/*
@@ -9,2 +5,3 @@
* Copyright (C) 2000 Thomas Mirlacher
+ * 2002-2004 the xine project
*
@@ -32,2 +29,3 @@
#define LOG_BLEND_YUV
+#define LOG_BLEND_RGB16
*/
@@ -37,5 +35,3 @@
#include <stdio.h>
-#include <inttypes.h>
-#include <xine.h>
#include <xine/xine_internal.h>
@@ -43,2 +39,3 @@
#include "alphablend.h"
+#include "bswap.h"
@@ -73,15 +70,2 @@ static void mem_blend24(uint8_t *mem, uint8_t r, uint8_t g, uint8_t b,
-static void mem_blend24_32(uint8_t *mem, uint8_t r, uint8_t g, uint8_t b,
- uint8_t o, int len) {
- uint8_t *limit = mem + len*4;
- while (mem < limit) {
- *mem = BLEND_BYTE(*mem, r, o);
- mem++;
- *mem = BLEND_BYTE(*mem, g, o);
- mem++;
- *mem = BLEND_BYTE(*mem, b, o);
- mem += 2;
- }
-}
-
static void mem_blend32(uint8_t *mem, uint8_t *src, uint8_t o, int len) {
@@ -100,3 +84,2 @@ static void mem_blend32(uint8_t *mem, uint8_t *src, uint8_t o, int len) {
-
/*
@@ -129,9 +112,9 @@ rle_img_advance_line(rle_elem_t *rle, rle_elem_t *rle_limit, int w)
-
void blend_rgb16 (uint8_t * img, vo_overlay_t * img_overl,
int img_width, int img_height,
- int dst_width, int dst_height)
+ int dst_width, int dst_height,
+ alphablend_t *extra_data)
{
uint8_t *trans;
- clut_t* clut = (clut_t*) img_overl->clip_color;
+ clut_t *clut;
@@ -140,2 +123,3 @@ void blend_rgb16 (uint8_t * img, vo_overlay_t * img_overl,
rle_elem_t *rle = img_overl->rle;
+ rle_elem_t *rle_start = img_overl->rle;
rle_elem_t *rle_limit = rle + img_overl->num_rle;
@@ -145,11 +129,55 @@ void blend_rgb16 (uint8_t * img, vo_overlay_t * img_overl,
uint16_t *img_pix;
+ int rlelen;
+ int rle_this_bite;
+ int rle_remainder;
+ int zone_state=0;
+ uint8_t clr_next,clr;
+ uint16_t o;
+ double img_offset;
+ int stripe_height;
+/*
+ * Let zone_state keep state.
+ * 0 = Starting.
+ * 1 = Above button.
+ * 2 = Left of button.
+ * 3 = Inside of button.
+ * 4 = Right of button.
+ * 5 = Below button.
+ * 6 = Finished.
+ *
+ * Each time round the loop, update the state.
+ * We can do this easily and cheaply(fewer IF statements per cycle) as we are testing rle end position anyway.
+ * Possible optimization is to ensure that rle never overlaps from outside to inside a button.
+ * Possible optimization is to pre-scale the RLE overlay, so that no scaling is needed here.
+ */
- dy_step = INT_TO_SCALED(dst_height) / img_height;
- x_scale = INT_TO_SCALED(img_width) / dst_width;
+#ifdef LOG_BLEND_RGB16
+ printf("blend_rgb16: img_height=%i, dst_height=%i\n", img_height, dst_height);
+ printf("blend_rgb16: img_width=%i, dst_width=%i\n", img_width, dst_width);
+ if (img_width & 1) { printf("blend_rgb16s: odd\n");}
+ else { printf("blend_rgb16s: even\n");}
- img_pix = (uint16_t *) img
+#endif
+/* stripe_height is used in yuv2rgb scaling, so use the same scale factor here for overlays. */
+ stripe_height = 16 * img_height / dst_height;
+/* dy_step = INT_TO_SCALED(dst_height) / img_height; */
+ dy_step = INT_TO_SCALED(16) / stripe_height;
+ x_scale = INT_TO_SCALED(img_width) / dst_width;
+#ifdef LOG_BLEND_RGB16
+ printf("blend_rgb16: dy_step=%i, x_scale=%i\n", dy_step, x_scale);
+#endif
+ if (img_width & 1) img_width++;
+ img_offset = ( ( (img_overl->y * img_height) / dst_height) * img_width)
+ + ( (img_overl->x * img_width) / dst_width);
+#ifdef LOG_BLEND_RGB16
+ printf("blend_rgb16: x=%i, y=%i, w=%i, h=%i, img_offset=%lf\n", img_overl->x, img_overl->y,
+ img_overl->width,
+ img_overl->height,
+ img_offset);
+#endif
+ img_pix = (uint16_t *) img + (int)img_offset;
+/*
+ (img_overl->y * img_height / dst_height) * img_width
+ (img_overl->x * img_width / dst_width);
-
- trans = img_overl->clip_trans;
+*/
@@ -159,3 +187,3 @@ void blend_rgb16 (uint8_t * img, vo_overlay_t * img_overl,
else
- clip_right = dst_width - 1 - img_overl->x;
+ clip_right = dst_width - img_overl->x;
@@ -163,50 +191,294 @@ void blend_rgb16 (uint8_t * img, vo_overlay_t * img_overl,
if( (src_height + img_overl->y) >= dst_height )
- src_height = dst_height - 1 - img_overl->y;
+ src_height = dst_height - img_overl->y;
- for (y = dy = 0; y < src_height && rle < rle_limit;) {
- int mask = !(img_overl->clip_top > y || img_overl->clip_bottom < y);
- rle_elem_t *rle_start = rle;
+ rlelen = rle_remainder = rle_this_bite = 0;
+ rle_remainder = rlelen = rle->len;
+ clr_next = rle->color;
+ rle++;
+ y = dy = 0;
+ x = x1_scaled = x2_scaled = 0;
- for (x = x1_scaled = 0; x < src_width;) {
- uint8_t clr;
- uint16_t o;
- int rlelen;
+#ifdef LOG_BLEND_RGB16
+ printf("blend_rgb16 started\n");
+#endif
- clr = rle->color;
+ while (zone_state != 6) {
+ clr = clr_next;
+ switch (zone_state) {
+ case 0: /* Starting */
+ /* FIXME: Get libspudec to set clip_top to -1 if no button */
+ if (img_overl->clip_top < 0) {
+#ifdef LOG_BLEND_RGB16
+ printf("blend_rgb16: No button clip area\n");
+#endif
+
+ zone_state = 7;
+ break;
+ }
+#ifdef LOG_BLEND_RGB16
+ printf("blend_rgb16: Button clip area found. (%d,%d) .. (%d,%d)\n",
+ img_overl->clip_left,
+ img_overl->clip_top,
+ img_overl->clip_right,
+ img_overl->clip_bottom);
+#endif
+ if (y < img_overl->clip_top) {
+ zone_state = 1;
+ break;
+ } else if (y >= img_overl->clip_bottom) {
+ zone_state = 5;
+ break;
+ } else if (x < img_overl->clip_left) {
+ zone_state = 2;
+ break;
+ } else if (x >= img_overl->clip_right) {
+ zone_state = 4;
+ break;
+ } else {
+ zone_state = 3;
+ break;
+ }
+ break;
+ case 1: /* Above clip area */
+ clut = (clut_t*) img_overl->color;
+ trans = img_overl->trans;
o = trans[clr];
- rlelen = rle->len;
+ rle_this_bite = rle_remainder;
+ rle_remainder = 0;
+ rlelen -= rle_this_bite;
+ /*printf("(x,y) = (%03i,%03i), clr=%03x, len=%03i, zone=%i\n", x, y, clr, rle_this_bite, zone_state); */
+ if (o) {
+ x1_scaled = SCALED_TO_INT( x * x_scale );
+ x2_scaled = SCALED_TO_INT( (x + rle_this_bite) * x_scale);
+ mem_blend16(img_pix+x1_scaled, *((uint16_t *)&clut[clr]), o, x2_scaled-x1_scaled);
+ }
+ x += rle_this_bite;
+ if (x >= src_width ) {
+ x -= src_width;
+ img_pix += img_width;
- if (o && mask) {
- /* threat cases where clipping border is inside rle->len pixels */
- if ( img_overl->clip_left > x ) {
- if( img_overl->clip_left < x + rlelen ) {
- x1_scaled = SCALED_TO_INT( img_overl->clip_left * x_scale );
- rlelen -= img_overl->clip_left - x;
- x += img_overl->clip_left - x;
+ dy += dy_step;
+ if (dy >= INT_TO_SCALED(1)) {
+ dy -= INT_TO_SCALED(1);
+ ++y;
+ while (dy >= INT_TO_SCALED(1)) {
+ rle = rle_img_advance_line(rle, rle_limit, src_width);
+ dy -= INT_TO_SCALED(1);
+ ++y;
+ }
+ rle_start = rle;
} else {
- o = 0;
+ rle = rle_start; /* y-scaling, reuse the last rle encoded line */
}
- } else if( clip_right < x + rlelen ) {
- if( clip_right > x ) {
- x2_scaled = SCALED_TO_INT( clip_right * x_scale);
- mem_blend16(img_pix+x1_scaled, *((uint16_t *)&clut[clr]), o,
- x2_scaled-x1_scaled);
- o = 0;
+ }
+ rle_remainder = rlelen = rle->len;
+ clr_next = rle->color;
+ rle++;
+ if (rle >= rle_limit) {
+ zone_state = 6;
+ }
+ if (y >= img_overl->clip_top) {
+ zone_state = 2;
+#ifdef LOG_BLEND_RGB16
+ printf("blend_rgb16: Button clip top reached. y=%i, top=%i\n",
+ y, img_overl->clip_top);
+#endif
+ if (x >= img_overl->clip_left) {
+ zone_state = 3;
+ if (x >= img_overl->clip_right) {
+ zone_state = 4;
+ }
+ }
+ }
+ break;
+ case 2: /* Left of button */
+ clut = (clut_t*) img_overl->color;
+ trans = img_overl->trans;
+ o = trans[clr];
+ if (x + rle_remainder <= img_overl->clip_left) {
+ rle_this_bite = rle_remainder;
+ rle_remainder = rlelen = rle->len;
+ clr_next = rle->color;
+ rle++;
+ } else {
+ rle_this_bite = img_overl->clip_left - x;
+ rle_remainder -= rle_this_bite;
+ zone_state = 3;
+ }
+ if (o) {
+ x1_scaled = SCALED_TO_INT( x * x_scale );
+ x2_scaled = SCALED_TO_INT( (x + rle_this_bite) * x_scale);
+ mem_blend16(img_pix+x1_scaled, *((uint16_t *)&clut[clr]), o, x2_scaled-x1_scaled);
+ }
+ x += rle_this_bite;
+ if (x >= src_width ) {
+ x -= src_width;
+ img_pix += img_width;
+ dy += dy_step;
+ if (dy >= INT_TO_SCALED(1)) {
+ dy -= INT_TO_SCALED(1);
+ ++y;
+ while (dy >= INT_TO_SCALED(1)) {
+ rle = rle_img_advance_line(rle, rle_limit, src_width);
+ dy -= INT_TO_SCALED(1);
+ ++y;
+ }
+ rle_start = rle;
} else {
- o = 0;
+ rle = rle_start; /* y-scaling, reuse the last rle encoded line */
}
+ if (y >= img_overl->clip_bottom) {
+ zone_state = 5;
+ break;
}
}
-
- x2_scaled = SCALED_TO_INT((x + rlelen) * x_scale);
- if (o && mask) {
+ if (rle >= rle_limit) {
+ zone_state = 6;
+ }
+ break;
+ case 3: /* In button */
+ clut = (clut_t*) img_overl->clip_color;
+ trans = img_overl->clip_trans;
+ o = trans[clr];
+ if (x + rle_remainder <= img_overl->clip_right) {
+ rle_this_bite = rle_remainder;
+ rle_remainder = rlelen = rle->len;
+ clr_next = rle->color;
+ rle++;
+ } else {
+ rle_this_bite = img_overl->clip_right - x;
+ rle_remainder -= rle_this_bite;
+ zone_state = 4;
+ }
+ if (o) {
+ x1_scaled = SCALED_TO_INT( x * x_scale );
+ x2_scaled = SCALED_TO_INT( (x + rle_this_bite) * x_scale);
mem_blend16(img_pix+x1_scaled, *((uint16_t *)&clut[clr]), o, x2_scaled-x1_scaled);
}
-
- x1_scaled = x2_scaled;
- x += rlelen;
+ x += rle_this_bite;
+ if (x >= src_width ) {
+ x -= src_width;
+ img_pix += img_width;
+ dy += dy_step;
+ if (dy >= INT_TO_SCALED(1)) {
+ dy -= INT_TO_SCALED(1);
+ ++y;
+ while (dy >= INT_TO_SCALED(1)) {
+ rle = rle_img_advance_line(rle, rle_limit, src_width);
+ dy -= INT_TO_SCALED(1);
+ ++y;
+ }
+ rle_start = rle;
+ } else {
+ rle = rle_start; /* y-scaling, reuse the last rle encoded line */
+ }
+ if (y >= img_overl->clip_bottom) {
+ zone_state = 5;
+ break;
+ }
+ }
+ if (rle >= rle_limit) {
+ zone_state = 6;
+ }
+ break;
+ case 4: /* Right of button */
+ clut = (clut_t*) img_overl->color;
+ trans = img_overl->trans;
+ o = trans[clr];
+ if (x + rle_remainder <= src_width) {
+ rle_this_bite = rle_remainder;
+ rle_remainder = rlelen = rle->len;
+ clr_next = rle->color;
rle++;
- if (rle >= rle_limit) break;
+ } else {
+ rle_this_bite = src_width - x;
+ rle_remainder -= rle_this_bite;
+ zone_state = 2;
}
+ if (o) {
+ x1_scaled = SCALED_TO_INT( x * x_scale );
+ x2_scaled = SCALED_TO_INT( (x + rle_this_bite) * x_scale);
+ mem_blend16(img_pix+x1_scaled, *((uint16_t *)&clut[clr]), o, x2_scaled-x1_scaled);
+ }
+ x += rle_this_bite;
+ if (x >= src_width ) {
+ x -= src_width;
+ img_pix += img_width;
+ dy += dy_step;
+ if (dy >= INT_TO_SCALED(1)) {
+ dy -= INT_TO_SCALED(1);
+ ++y;
+ while (dy >= INT_TO_SCALED(1)) {
+ rle = rle_img_advance_line(rle, rle_limit, src_width);
+ dy -= INT_TO_SCALED(1);
+ ++y;
+ }
+ rle_start = rle;
+ } else {
+ rle = rle_start; /* y-scaling, reuse the last rle encoded line */
+ }
+ if (y >= img_overl->clip_bottom) {
+ zone_state = 5;
+ break;
+ }
+ }
+ if (rle >= rle_limit) {
+ zone_state = 6;
+ }
+ break;
+ case 5: /* Below button */
+ clut = (clut_t*) img_overl->color;
+ trans = img_overl->trans;
+ o = trans[clr];
+ rle_this_bite = rle_remainder;
+ rle_remainder = 0;
+ rlelen -= rle_this_bite;
+ if (o) {
+ x1_scaled = SCALED_TO_INT( x * x_scale );
+ x2_scaled = SCALED_TO_INT( (x + rle_this_bite) * x_scale);
+ mem_blend16(img_pix+x1_scaled, *((uint16_t *)&clut[clr]), o, x2_scaled-x1_scaled);
+ }
+ x += rle_this_bite;
+ if (x >= src_width ) {
+ x -= src_width;
+ img_pix += img_width;
+ dy += dy_step;
+ if (dy >= INT_TO_SCALED(1)) {
+ dy -= INT_TO_SCALED(1);
+ ++y;
+ while (dy >= INT_TO_SCALED(1)) {
+ rle = rle_img_advance_line(rle, rle_limit, src_width);
+ dy -= INT_TO_SCALED(1);
+ ++y;
+ }
+ rle_start = rle;
+ } else {
+ rle = rle_start; /* y-scaling, reuse the last rle encoded line */
+ }
+ }
+ rle_remainder = rlelen = rle->len;
+ clr_next = rle->color;
+ rle++;
+ if (rle >= rle_limit) {
+ zone_state = 6;
+ }
+ break;
+ case 6: /* Finished */
+ _x_abort();
+ case 7: /* No button */
+ clut = (clut_t*) img_overl->color;
+ trans = img_overl->trans;
+ o = trans[clr];
+ rle_this_bite = rle_remainder;
+ rle_remainder = 0;
+ rlelen -= rle_this_bite;
+ if (o) {
+ x1_scaled = SCALED_TO_INT( x * x_scale );
+ x2_scaled = SCALED_TO_INT( (x + rle_this_bite) * x_scale);
+ mem_blend16(img_pix+x1_scaled, *((uint16_t *)&clut[clr]), o, x2_scaled-x1_scaled);
+ }
+ x += rle_this_bite;
+ if (x >= src_width ) {
+ x -= src_width;
img_pix += img_width;
@@ -221,2 +493,3 @@ void blend_rgb16 (uint8_t * img, vo_overlay_t * img_overl,
}
+ rle_start = rle;
} else {
@@ -225,2 +498,17 @@ void blend_rgb16 (uint8_t * img, vo_overlay_t * img_overl,
}
+ rle_remainder = rlelen = rle->len;
+ clr_next = rle->color;
+ rle++;
+ if (rle >= rle_limit) {
+ zone_state = 6;
+ }
+ break;
+ default:
+ ;
+ }
+ }
+#ifdef LOG_BLEND_RGB16
+ printf("blend_rgb16 ended\n");
+#endif
+
}
@@ -229,6 +517,5 @@ void blend_rgb24 (uint8_t * img, vo_overlay_t * img_overl,
int img_width, int img_height,
- int dst_width, int dst_height)
+ int dst_width, int dst_height,
+ alphablend_t *extra_data)
{
- clut_t* clut = (clut_t*) img_overl->clip_color;
- uint8_t *trans;
int src_width = img_overl->width;
@@ -248,47 +535,87 @@ void blend_rgb24 (uint8_t * img, vo_overlay_t * img_overl,
- trans = img_overl->clip_trans;
-
/* avoid wraping overlay if drawing to small image */
- if( (img_overl->x + img_overl->clip_right) < dst_width )
+ if( (img_overl->x + img_overl->clip_right) <= dst_width )
clip_right = img_overl->clip_right;
else
- clip_right = dst_width - 1 - img_overl->x;
+ clip_right = dst_width - img_overl->x;
/* avoid buffer overflow */
- if( (src_height + img_overl->y) >= dst_height )
- src_height = dst_height - 1 - img_overl->y;
+ if( (src_height + img_overl->y) > dst_height )
+ src_height = dst_height - img_overl->y;
for (dy = y = 0; y < src_height && rle < rle_limit; ) {
- int mask = !(img_overl->clip_top > y || img_overl->clip_bottom < y);
+ int mask = !(y < img_overl->clip_top || y >= img_overl->clip_bottom);
rle_elem_t *rle_start = rle;
+ int rlelen = 0;
+ uint8_t clr = 0;
+
for (x = x1_scaled = 0; x < src_width;) {
- uint8_t clr;
+ int rle_bite;
+ clut_t *colors;
+ uint8_t *trans;
uint16_t o;
- int rlelen;
- clr = rle->color;
- o = trans[clr];
+ /* take next element from rle list everytime an element is finished */
+ if (rlelen <= 0) {
+ if (rle >= rle_limit)
+ break;
+
rlelen = rle->len;
+ clr = rle->color;
+ rle++;
+ }
- if (o && mask) {
- /* threat cases where clipping border is inside rle->len pixels */
- if ( img_overl->clip_left > x ) {
- if( img_overl->clip_left < x + rlelen ) {
- x1_scaled = SCALED_TO_INT( img_overl->clip_left * x_scale );
- rlelen -= img_overl->clip_left - x;
- x += img_overl->clip_left - x;
- } else {
- o = 0;
- }
- } else if( clip_right < x + rlelen ) {
- if( clip_right > x ) {
- x2_scaled = SCALED_TO_INT( clip_right * x_scale);
- mem_blend24(img_pix + x1_scaled*3, clut[clr].cb,
- clut[clr].cr, clut[clr].y,
- o, x2_scaled-x1_scaled);
- o = 0;
+ if (!mask) {
+ /* above or below clipping area */
+
+ rle_bite = rlelen;
+ /* choose palette for surrounding area */
+ colors = (clut_t*)img_overl->color;
+ trans = img_overl->trans;
+ } else {
+ /* treat cases where clipping border is inside rle->len pixels */
+ if ( x < img_overl->clip_left ) {
+ /* starts left */
+ if( x + rlelen > img_overl->clip_left ) {
+ /* ends not left */
+
+ /* choose the largest "bite" up to palette change */
+ rle_bite = img_overl->clip_left - x;
+ /* choose palette for surrounding area */
+ colors = (clut_t*)img_overl->color;
+ trans = img_overl->trans;
+ } else {
+ /* ends left */
+
+ rle_bite = rlelen;
+ /* choose palette for surrounding area */
+ colors = (clut_t*)img_overl->color;
+ trans = img_overl->trans;
+ }
+ } else if( x + rlelen > clip_right ) {
+ /* ends right */
+ if( x < clip_right ) {
+ /* starts not right */
+
+ /* choose the largest "bite" up to palette change */
+ rle_bite = clip_right - x;
+ /* we're in the center area so choose clip palette */
+ colors = (clut_t*)img_overl->clip_color;
+ trans = img_overl->clip_trans;
} else {
- o = 0;
+ /* starts right */
+
+ rle_bite = rlelen;
+ /* choose palette for surrounding area */
+ colors = (clut_t*)img_overl->color;
+ trans = img_overl->trans;
}
+ } else {
+ /* starts not left and ends not right */
+
+ rle_bite = rlelen;
+ /* we're in the center area so choose clip palette */
+ colors = (clut_t*)img_overl->clip_color;
+ trans = img_overl->clip_trans;
}
@@ -296,6 +623,8 @@ void blend_rgb24 (uint8_t * img, vo_overlay_t * img_overl,
- x2_scaled = SCALED_TO_INT((x + rlelen) * x_scale);
- if (o && mask) {
- mem_blend24(img_pix + x1_scaled*3, clut[clr].cb,
- clut[clr].cr, clut[clr].y,
+ x2_scaled = SCALED_TO_INT((x + rle_bite) * x_scale);
+
+ o = trans[clr];
+ if (o) {
+ mem_blend24(img_pix + x1_scaled*3,
+ colors[clr].cb, colors[clr].cr, colors[clr].y,
o, x2_scaled-x1_scaled);
@@ -304,5 +633,4 @@ void blend_rgb24 (uint8_t * img, vo_overlay_t * img_overl,
x1_scaled = x2_scaled;
- x += rlelen;
- rle++;
- if (rle >= rle_limit) break;
+ x += rle_bite;
+ rlelen -= rle_bite;
}
@@ -327,6 +655,5 @@ void blend_rgb32 (uint8_t * img, vo_overlay_t * img_overl,
int img_width, int img_height,
- int dst_width, int dst_height)
+ int dst_width, int dst_height,
+ alphablend_t *extra_data)
{
- clut_t* clut = (clut_t*) img_overl->clip_color;
- uint8_t *trans;
int src_width = img_overl->width;
@@ -346,47 +673,87 @@ void blend_rgb32 (uint8_t * img, vo_overlay_t * img_overl,
- trans = img_overl->clip_trans;
-
/* avoid wraping overlay if drawing to small image */
- if( (img_overl->x + img_overl->clip_right) < dst_width )
+ if( (img_overl->x + img_overl->clip_right) <= dst_width )
clip_right = img_overl->clip_right;
else
- clip_right = dst_width - 1 - img_overl->x;
+ clip_right = dst_width - img_overl->x;
/* avoid buffer overflow */
- if( (src_height + img_overl->y) >= dst_height )
- src_height = dst_height - 1 - img_overl->y;
+ if( (src_height + img_overl->y) > dst_height )
+ src_height = dst_height - img_overl->y;
for (y = dy = 0; y < src_height && rle < rle_limit; ) {
- int mask = !(img_overl->clip_top > y || img_overl->clip_bottom < y);
+ int mask = !(y < img_overl->clip_top || y >= img_overl->clip_bottom);
rle_elem_t *rle_start = rle;
+ int rlelen = 0;
+ uint8_t clr = 0;
+
for (x = x1_scaled = 0; x < src_width;) {
- uint8_t clr;
+ int rle_bite;
+ clut_t *colors;
+ uint8_t *trans;
uint16_t o;
- int rlelen;
- clr = rle->color;
- o = trans[clr];
+ /* take next element from rle list everytime an element is finished */
+ if (rlelen <= 0) {
+ if (rle >= rle_limit)
+ break;
+
rlelen = rle->len;
+ clr = rle->color;
+ rle++;
+ }
- if (o && mask) {
- /* threat cases where clipping border is inside rle->len pixels */
- if ( img_overl->clip_left > x ) {
- if( img_overl->clip_left < x + rlelen ) {
- x1_scaled = SCALED_TO_INT( img_overl->clip_left * x_scale );
- rlelen -= img_overl->clip_left - x;
- x += img_overl->clip_left - x;
- } else {
- o = 0;
- }
- } else if( clip_right < x + rlelen ) {
- if( clip_right > x ) {
- x2_scaled = SCALED_TO_INT( clip_right * x_scale);
- mem_blend24_32(img_pix + x1_scaled*4, clut[clr].cb,
- clut[clr].cr, clut[clr].y,
- o, x2_scaled-x1_scaled);
- o = 0;
+ if (!mask) {
+ /* above or below clipping area */
+
+ rle_bite = rlelen;
+ /* choose palette for surrounding area */
+ colors = (clut_t*)img_overl->color;
+ trans = img_overl->trans;
} else {
- o = 0;
+ /* treat cases where clipping border is inside rle->len pixels */
+ if ( x < img_overl->clip_left ) {
+ /* starts left */
+ if( x + rlelen > img_overl->clip_left ) {
+ /* ends not left */
+
+ /* choose the largest "bite" up to palette change */
+ rle_bite = img_overl->clip_left - x;
+ /* choose palette for surrounding area */
+ colors = (clut_t*)img_overl->color;
+ trans = img_overl->trans;
+ } else {
+ /* ends left */
+
+ rle_bite = rlelen;
+ /* choose palette for surrounding area */
+ colors = (clut_t*)img_overl->color;
+ trans = img_overl->trans;
+ }
+ } else if( x + rlelen > clip_right ) {
+ /* ends right */
+ if( x < clip_right ) {
+ /* starts not right */
+
+ /* choose the largest "bite" up to palette change */
+ rle_bite = clip_right - x;
+ /* we're in the center area so choose clip palette */
+ colors = (clut_t*)img_overl->clip_color;
+ trans = img_overl->clip_trans;
+ } else {
+ /* starts right */
+
+ rle_bite = rlelen;
+ /* choose palette for surrounding area */
+ colors = (clut_t*)img_overl->color;
+ trans = img_overl->trans;
}
+ } else {
+ /* starts not left and ends not right */
+
+ rle_bite = rlelen;
+ /* we're in the center area so choose clip palette */
+ colors = (clut_t*)img_overl->clip_color;
+ trans = img_overl->clip_trans;
}
@@ -394,7 +761,7 @@ void blend_rgb32 (uint8_t * img, vo_overlay_t * img_overl,
- x2_scaled = SCALED_TO_INT((x + rlelen) * x_scale);
- if (o && mask) {
- mem_blend24_32(img_pix + x1_scaled*4, clut[clr].cb,
- clut[clr].cr, clut[clr].y,
- o, x2_scaled-x1_scaled);
+ x2_scaled = SCALED_TO_INT((x + rle_bite) * x_scale);
+
+ o = trans[clr];
+ if (o) {
+ mem_blend32(img_pix + x1_scaled*4, (uint8_t *)&colors[clr], o, x2_scaled-x1_scaled);
}
@@ -402,5 +769,4 @@ void blend_rgb32 (uint8_t * img, vo_overlay_t * img_overl,
x1_scaled = x2_scaled;
- x += rlelen;
- rle++;
- if (rle >= rle_limit) break;
+ x += rle_bite;
+ rlelen -= rle_bite;
}
@@ -432,5 +798,105 @@ static void mem_blend8(uint8_t *mem, uint8_t val, uint8_t o, size_t sz)
+static void blend_yuv_exact(uint8_t *dst_cr, uint8_t *dst_cb,
+ int src_width, int x_odd,
+ uint8_t *(*blend_yuv_data)[ 3 ][ 2 ])
+{
+ int x;
+
+ for (x = 0; x < src_width; x += 2) {
+ /* get opacity of the 4 pixels that share chroma */
+ int o00 = (*blend_yuv_data)[ 0 ][ 0 ][ x + 0 ];
+ int o01 = (*blend_yuv_data)[ 0 ][ 0 ][ x + 1 ];
+ int o10 = (*blend_yuv_data)[ 0 ][ 1 ][ x + 0 ];
+ int o11 = (*blend_yuv_data)[ 0 ][ 1 ][ x + 1 ];
+
+ /* are there any pixels a little bit opaque? */
+ if (o00 || o01 || o10 || o11) {
+ /* get the chroma components of the 4 pixels */
+ int cr00 = -128 + (*blend_yuv_data)[ 1 ][ 0 ][ x + 0 ];
+ int cr01 = -128 + (*blend_yuv_data)[ 1 ][ 0 ][ x + 1 ];
+ int cr10 = -128 + (*blend_yuv_data)[ 1 ][ 1 ][ x + 0 ];
+ int cr11 = -128 + (*blend_yuv_data)[ 1 ][ 1 ][ x + 1 ];
+
+ int cb00 = -128 + (*blend_yuv_data)[ 2 ][ 0 ][ x + 0 ];
+ int cb01 = -128 + (*blend_yuv_data)[ 2 ][ 0 ][ x + 1 ];
+ int cb10 = -128 + (*blend_yuv_data)[ 2 ][ 1 ][ x + 0 ];
+ int cb11 = -128 + (*blend_yuv_data)[ 2 ][ 1 ][ x + 1 ];
+
+ /* are all pixels completely opaque? */
+ if (o00 >= 0xf && o01 >= 0xf && o10 >= 0xf && o11 >= 0xf) {
+ /* set the output chroma to the average of the four pixels */
+ *dst_cr = 128 + (cr00 + cr01 + cr10 + cr11) / 4;
+ *dst_cb = 128 + (cb00 + cb01 + cb10 + cb11) / 4;
+ } else {
+ int t4, cr, cb;
+
+ /* blending required, so clamp opacity values to allowed range */
+ if (o00 > 0xf) o00 = 0xf;
+ if (o01 > 0xf) o01 = 0xf;
+ if (o10 > 0xf) o10 = 0xf;
+ if (o11 > 0xf) o11 = 0xf;
+
+ /* calculate transparency of background over the four pixels */
+ t4 = (0xf - o00) + (0xf - o01) + (0xf - o10) + (0xf - o11);
+
+ /* get background chroma */
+ cr = -128 + *dst_cr;
+ cb = -128 + *dst_cb;
+
+ /* blend the output chroma to the average of the four pixels */
+ *dst_cr = 128 + (cr * t4 + cr00 * o00 + cr01 * o01 + cr10 * o10 + cr11 * o11) / (4 * 0xf);
+ *dst_cb = 128 + (cb * t4 + cb00 * o00 + cb01 * o01 + cb10 * o10 + cb11 * o11) / (4 * 0xf);
+ }
+ }
+
+ /* next chroma sample */
+ dst_cr++;
+ dst_cb++;
+ }
+}
+
+static uint8_t *(*blend_yuv_grow_extra_data(alphablend_t *extra_data, int osd_width))[ 3 ][ 2 ]
+{
+ struct __attribute__((packed)) header_s {
+ int id;
+ int max_width;
+ uint8_t *data[ 3 ][ 2 ];
+ } **header = (struct header_s **)&extra_data->buffer;
+
+ int needed_buffer_size = sizeof (**header) + sizeof (uint8_t[ 3 ][ 2 ][ osd_width ]);
+
+ if (extra_data->buffer_size < needed_buffer_size) {
+
+ free(extra_data->buffer);
+ extra_data->buffer = xine_xmalloc(needed_buffer_size);
+
+ if (!extra_data->buffer) {
+ extra_data->buffer_size = 0;
+ return 0;
+ }
+
+ extra_data->buffer_size = needed_buffer_size;
+ (*header)->max_width = 0;
+ }
+
+ if ((*header)->id != ME_FOURCC('y', 'u', 'v', 0) || (*header)->max_width < osd_width) {
+ (*header)->id = ME_FOURCC('y', 'u', 'v', 0);
+ (*header)->max_width = osd_width;
+
+ (*header)->data[ 0 ][ 0 ] = ((uint8_t *)extra_data->buffer) + sizeof (**header);
+ (*header)->data[ 0 ][ 1 ] = (*header)->data[ 0 ][ 0 ] + osd_width;
+ (*header)->data[ 1 ][ 0 ] = (*header)->data[ 0 ][ 1 ] + osd_width;
+ (*header)->data[ 1 ][ 1 ] = (*header)->data[ 1 ][ 0 ] + osd_width;
+ (*header)->data[ 2 ][ 0 ] = (*header)->data[ 1 ][ 1 ] + osd_width;
+ (*header)->data[ 2 ][ 1 ] = (*header)->data[ 2 ][ 0 ] + osd_width;
+ }
+
+ return &(*header)->data;
+}
+
void blend_yuv (uint8_t *dst_base[3], vo_overlay_t * img_overl,
- int dst_width, int dst_height)
+ int dst_width, int dst_height, int dst_pitches[3],
+ alphablend_t *extra_data)
{
+ int enable_exact_blending = !extra_data->disable_exact_blending;
clut_t *my_clut;
@@ -444,2 +910,4 @@ void blend_yuv (uint8_t *dst_base[3], vo_overlay_t * img_overl,
int y_off = img_overl->y;
+ int x_odd = x_off & 1;
+ int y_odd = y_off & 1;
int ymask,xmask;
@@ -452,7 +920,10 @@ void blend_yuv (uint8_t *dst_base[3], vo_overlay_t * img_overl,
- uint8_t *dst_y = dst_base[0] + dst_width * y_off + x_off;
- uint8_t *dst_cr = dst_base[2] +
- (y_off / 2) * (dst_width / 2) + (x_off / 2) + 1;
- uint8_t *dst_cb = dst_base[1] +
- (y_off / 2) * (dst_width / 2) + (x_off / 2) + 1;
+ int any_line_buffered = 0;
+ int exact_blend_width = ((src_width <= (dst_width - x_off)) ? src_width : (dst_width - x_off));
+ int exact_blend_width_m2 = (x_odd + exact_blend_width + 1) & ~1; /* make it a (larger) multiple of 2 */
+ uint8_t *(*blend_yuv_data)[ 3 ][ 2 ] = 0;
+
+ uint8_t *dst_y = dst_base[0] + dst_pitches[0] * y_off + x_off;
+ uint8_t *dst_cr = dst_base[2] + (y_off / 2) * dst_pitches[1] + (x_off / 2);
+ uint8_t *dst_cb = dst_base[1] + (y_off / 2) * dst_pitches[2] + (x_off / 2);
#ifdef LOG_BLEND_YUV
@@ -464,10 +935,26 @@ void blend_yuv (uint8_t *dst_base[3], vo_overlay_t * img_overl,
/* avoid wraping overlay if drawing to small image */
- if( (x_off + img_overl->clip_right) < dst_width )
+ if( (x_off + img_overl->clip_right) <= dst_width )
clip_right = img_overl->clip_right;
else
- clip_right = dst_width - 1 - x_off;
+ clip_right = dst_width - x_off;
/* avoid buffer overflow */
- if( (src_height + y_off) >= dst_height )
- src_height = dst_height - 1 - y_off;
+ if( (src_height + y_off) > dst_height )
+ src_height = dst_height - y_off;
+
+ if (src_height <= 0)
+ return;
+
+ if (enable_exact_blending) {
+ if (exact_blend_width <= 0)
+ return;
+
+ blend_yuv_data = blend_yuv_grow_extra_data(extra_data, exact_blend_width_m2);
+ if (!blend_yuv_data)
+ return;
+
+ /* make linebuffer transparent */
+ memset(&(*blend_yuv_data)[ 0 ][ 0 ][ 0 ], 0, exact_blend_width_m2);
+ memset(&(*blend_yuv_data)[ 0 ][ 1 ][ 0 ], 0, exact_blend_width_m2);
+ }
@@ -475,3 +962,10 @@ void blend_yuv (uint8_t *dst_base[3], vo_overlay_t * img_overl,
for (y = 0; y < src_height; y++) {
- ymask = ((img_overl->clip_top > y) || (img_overl->clip_bottom < y));
+ if (rle >= rle_limit) {
+#ifdef LOG_BLEND_YUV
+ printf("y-rle_limit\n");
+#endif
+ break;
+ }
+
+ ymask = ((y < img_overl->clip_top) || (y >= img_overl->clip_bottom));
xmask = 0;
@@ -483,2 +977,10 @@ void blend_yuv (uint8_t *dst_base[3], vo_overlay_t * img_overl,
uint16_t o;
+
+ if (rle >= rle_limit) {
+#ifdef LOG_BLEND_YUV
+ printf("x-rle_limit\n");
+#endif
+ break;
+ }
+
#ifdef LOG_BLEND_YUV
@@ -488,3 +990,5 @@ void blend_yuv (uint8_t *dst_base[3], vo_overlay_t * img_overl,
if ((rlelen < 0) || (rle_remainder < 0)) {
+#ifdef LOG_BLEND_YUV
printf("alphablend: major bug in blend_yuv < 0\n");
+#endif
}
@@ -501,3 +1005,2 @@ void blend_yuv (uint8_t *dst_base[3], vo_overlay_t * img_overl,
rle_remainder = src_width - x;
- ;
}
@@ -508,5 +1011,5 @@ void blend_yuv (uint8_t *dst_base[3], vo_overlay_t * img_overl,
if (ymask == 0) {
- if (x <= img_overl->clip_left) {
+ if (x < img_overl->clip_left) {
/* Starts outside clip area */
- if ((x + rle_remainder - 1) > img_overl->clip_left ) {
+ if ((x + rle_remainder) > img_overl->clip_left ) {
#ifdef LOG_BLEND_YUV
@@ -515,3 +1018,3 @@ void blend_yuv (uint8_t *dst_base[3], vo_overlay_t * img_overl,
/* Cutting needed, starts outside, ends inside */
- rle_this_bite = (img_overl->clip_left - x + 1);
+ rle_this_bite = (img_overl->clip_left - x);
rle_remainder -= rle_this_bite;
@@ -559,3 +1062,3 @@ void blend_yuv (uint8_t *dst_base[3], vo_overlay_t * img_overl,
} else if (x >= clip_right) {
- /* Starts outside clip area, ends outsite clip area */
+ /* Starts outside clip area, ends outside clip area */
if ((x + rle_remainder ) > src_width ) {
@@ -599,2 +1102,19 @@ void blend_yuv (uint8_t *dst_base[3], vo_overlay_t * img_overl,
#endif
+
+ if (x < (dst_width - x_off)) {
+ /* clip against right edge of destination area */
+ if ((x + rle_this_bite) > (dst_width - x_off)) {
+ int toClip = (x + rle_this_bite) - (dst_width - x_off);
+
+ rle_this_bite -= toClip;
+ rle_remainder += toClip;
+ rlelen += toClip;
+ }
+
+ if (enable_exact_blending) {
+ /* remember opacity of current line */
+ memset(&(*blend_yuv_data)[ 0 ][ (y + y_odd) & 1 ][ x + x_odd ], o, rle_this_bite);
+ any_line_buffered |= ((y + y_odd) & 1) ? 2 : 1;
+ }
+
if (o) {
@@ -602,5 +1122,7 @@ void blend_yuv (uint8_t *dst_base[3], vo_overlay_t * img_overl,
memset(dst_y + x, my_clut[clr].y, rle_this_bite);
- if (y & 1) {
- memset(dst_cr + (x >> 1), my_clut[clr].cr, (rle_this_bite+1) >> 1);
- memset(dst_cb + (x >> 1), my_clut[clr].cb, (rle_this_bite+1) >> 1);
+ if (!enable_exact_blending) {
+ if ((y + y_odd) & 1) {
+ memset(dst_cr + ((x + x_odd) >> 1), my_clut[clr].cr, (rle_this_bite+1) >> 1);
+ memset(dst_cb + ((x + x_odd) >> 1), my_clut[clr].cb, (rle_this_bite+1) >> 1);
+ }
}
@@ -608,6 +1130,8 @@ void blend_yuv (uint8_t *dst_base[3], vo_overlay_t * img_overl,
mem_blend8(dst_y + x, my_clut[clr].y, o, rle_this_bite);
- if (y & 1) {
+ if (!enable_exact_blending) {
+ if ((y + y_odd) & 1) {
/* Blending cr and cb should use a different function, with pre -128 to each sample */
- mem_blend8(dst_cr + (x >> 1), my_clut[clr].cr, o, (rle_this_bite+1) >> 1);
- mem_blend8(dst_cb + (x >> 1), my_clut[clr].cb, o, (rle_this_bite+1) >> 1);
+ mem_blend8(dst_cr + ((x + x_odd) >> 1), my_clut[clr].cr, o, (rle_this_bite+1) >> 1);
+ mem_blend8(dst_cb + ((x + x_odd) >> 1), my_clut[clr].cb, o, (rle_this_bite+1) >> 1);
+ }
}
@@ -615,2 +1139,8 @@ void blend_yuv (uint8_t *dst_base[3], vo_overlay_t * img_overl,
+ if (enable_exact_blending) {
+ /* remember chroma of current line */
+ memset(&(*blend_yuv_data)[ 1 ][ (y + y_odd) & 1 ][ x + x_odd ], my_clut[ clr ].cr, rle_this_bite);
+ memset(&(*blend_yuv_data)[ 2 ][ (y + y_odd) & 1 ][ x + x_odd ], my_clut[ clr ].cb, rle_this_bite);
+ }
+ }
}
@@ -620,23 +1150,38 @@ void blend_yuv (uint8_t *dst_base[3], vo_overlay_t * img_overl,
x += rle_this_bite;
- if (rle >= rle_limit) {
-#ifdef LOG_BLEND_YUV
- printf("x-rle_limit\n");
-#endif
- break;
}
+
+ if ((y + y_odd) & 1) {
+ if (enable_exact_blending) {
+ /* blend buffered lines */
+ if (any_line_buffered) {
+ if (!(any_line_buffered & 2)) {
+ /* make second line transparent */
+ memset(&(*blend_yuv_data)[ 0 ][ 1 ][ 0 ], 0, exact_blend_width_m2);
+ }
+
+ blend_yuv_exact(dst_cr, dst_cb, exact_blend_width, x_odd, blend_yuv_data);
+
+ any_line_buffered = 0;
}
- if (rle >= rle_limit) {
-#ifdef LOG_BLEND_YUV
- printf("x-rle_limit\n");
-#endif
- break;
}
- dst_y += dst_width;
+ dst_cr += dst_pitches[2];
+ dst_cb += dst_pitches[1];
+ }
- if (y & 1) {
- dst_cr += (dst_width + 1) / 2;
- dst_cb += (dst_width + 1) / 2;
+ dst_y += dst_pitches[0];
}
+
+ if (enable_exact_blending) {
+ /* blend buffered lines */
+ if (any_line_buffered) {
+ if (!(any_line_buffered & 2)) {
+ /* make second line transparent */
+ memset(&(*blend_yuv_data)[ 0 ][ 1 ][ 0 ], 0, exact_blend_width_m2);
}
+
+ blend_yuv_exact(dst_cr, dst_cb, exact_blend_width, x_odd, blend_yuv_data);
+ }
+ }
+
#ifdef LOG_BLEND_YUV
@@ -646,5 +1191,94 @@ void blend_yuv (uint8_t *dst_base[3], vo_overlay_t * img_overl,
+static void blend_yuy2_exact(uint8_t *dst_cr, uint8_t *dst_cb,
+ int src_width, int x_odd,
+ uint8_t *(*blend_yuy2_data)[ 3 ])
+{
+ int x;
+
+ for (x = 0; x < src_width; x += 2) {
+ /* get opacity of the 2 pixels that share chroma */
+ int o0 = (*blend_yuy2_data)[ 0 ][ x + 0 ];
+ int o1 = (*blend_yuy2_data)[ 0 ][ x + 1 ];
+
+ /* are there any pixels a little bit opaque? */
+ if (o0 || o1) {
+ /* get the chroma components of the 2 pixels */
+ int cr0 = -128 + (*blend_yuy2_data)[ 1 ][ x + 0 ];
+ int cr1 = -128 + (*blend_yuy2_data)[ 1 ][ x + 1 ];
+
+ int cb0 = -128 + (*blend_yuy2_data)[ 2 ][ x + 0 ];
+ int cb1 = -128 + (*blend_yuy2_data)[ 2 ][ x + 1 ];
+
+ /* are all pixels completely opaque? */
+ if (o0 >= 0xf && o1 >= 0xf) {
+ /* set the output chroma to the average of the two pixels */
+ *dst_cr = 128 + (cr0 + cr1) / 2;
+ *dst_cb = 128 + (cb0 + cb1) / 2;
+ } else {
+ int t2, cr, cb;
+
+ /* blending required, so clamp opacity values to allowed range */
+ if (o0 > 0xf) o0 = 0xf;
+ if (o1 > 0xf) o1 = 0xf;
+
+ /* calculate transparency of background over the two pixels */
+ t2 = (0xf - o0) + (0xf - o1);
+
+ /* get background chroma */
+ cr = -128 + *dst_cr;
+ cb = -128 + *dst_cb;
+
+ /* blend the output chroma to the average of the two pixels */
+ *dst_cr = 128 + (cr * t2 + cr0 * o0 + cr1 * o1) / (2 * 0xf);
+ *dst_cb = 128 + (cb * t2 + cb0 * o0 + cb1 * o1) / (2 * 0xf);
+ }
+ }
+
+ /* next chroma sample */
+ dst_cr += 4;
+ dst_cb += 4;
+ }
+}
+
+static uint8_t *(*blend_yuy2_grow_extra_data(alphablend_t *extra_data, int osd_width))[ 3 ]
+{
+ struct __attribute__((packed)) header_s {
+ int id;
+ int max_width;
+ uint8_t *data[ 3 ];
+ } **header = (struct header_s **)&extra_data->buffer;
+
+ int needed_buffer_size = sizeof (**header) + sizeof (uint8_t[ 3 ][ osd_width ]);
+
+ if (extra_data->buffer_size < needed_buffer_size) {
+
+ free(extra_data->buffer);
+ extra_data->buffer = xine_xmalloc(needed_buffer_size);
+
+ if (!extra_data->buffer) {
+ extra_data->buffer_size = 0;
+ return 0;
+ }
+
+ extra_data->buffer_size = needed_buffer_size;
+ (*header)->max_width = 0;
+ }
+
+ if ((*header)->id != ME_FOURCC('y', 'u', 'y', '2') || (*header)->max_width < osd_width) {
+ (*header)->id = ME_FOURCC('y', 'u', 'y', '2');
+ (*header)->max_width = osd_width;
+
+ (*header)->data[ 0 ] = ((uint8_t *)extra_data->buffer) + sizeof (**header);
+ (*header)->data[ 1 ] = (*header)->data[ 0 ] + osd_width;
+ (*header)->data[ 2 ] = (*header)->data[ 1 ] + osd_width;
+ }
+
+ return &(*header)->data;
+}
+
void blend_yuy2 (uint8_t * dst_img, vo_overlay_t * img_overl,
- int dst_width, int dst_height)
+ int dst_width, int dst_height, int dst_pitch,
+ alphablend_t *extra_data)
{
+ int enable_exact_blending = !extra_data->disable_exact_blending;
clut_t *my_clut;
@@ -658,9 +1292,25 @@ void blend_yuy2 (uint8_t * dst_img, vo_overlay_t * img_overl,
int y_off = img_overl->y;
- int mask;
+ int x_odd = x_off & 1;
+ int ymask;
+ int rle_this_bite;
+ int rle_remainder;
+ int rlelen;
int x, y;
- int l;
+ int l = 0;
int clip_right;
- uint32_t yuy2;
- uint8_t *dst_y = dst_img + 2 * (dst_width * y_off + x_off);
+ union {
+ uint32_t value;
+ uint8_t b[4];
+ uint16_t h[2];
+ } yuy2;
+
+ uint8_t clr = 0;
+
+ int any_line_buffered = 0;
+ int exact_blend_width = ((src_width <= (dst_width - x_off)) ? src_width : (dst_width - x_off));
+ int exact_blend_width_m2 = (x_odd + exact_blend_width + 1) & ~1; /* make it a (larger) multiple of 2 */
+ uint8_t *(*blend_yuy2_data)[ 3 ] = 0;
+
+ uint8_t *dst_y = dst_img + dst_pitch * y_off + 2 * x_off;
uint8_t *dst;
@@ -671,13 +1321,32 @@ void blend_yuy2 (uint8_t * dst_img, vo_overlay_t * img_overl,
/* avoid wraping overlay if drawing to small image */
- if( (x_off + img_overl->clip_right) < dst_width )
+ if( (x_off + img_overl->clip_right) <= dst_width )
clip_right = img_overl->clip_right;
else
- clip_right = dst_width - 1 - x_off;
+ clip_right = dst_width - x_off;
/* avoid buffer overflow */
- if( (src_height + y_off) >= dst_height )
- src_height = dst_height - 1 - y_off;
+ if( (src_height + y_off) > dst_height )
+ src_height = dst_height - y_off;
+
+ if (src_height <= 0)
+ return;
+
+ if (enable_exact_blending) {
+ if (exact_blend_width <= 0)
+ return;
+ blend_yuy2_data = blend_yuy2_grow_extra_data(extra_data, exact_blend_width_m2);
+ if (!blend_yuy2_data)
+ return;
+
+ /* make linebuffer transparent */
+ memset(&(*blend_yuy2_data)[ 0 ][ 0 ], 0, exact_blend_width_m2);
+ }
+
+ rlelen=rle_remainder=0;
for (y = 0; y < src_height; y++) {
- mask = !(img_overl->clip_top > y || img_overl->clip_bottom < y);
+ if (rle >= rle_limit)
+ break;
+
+ ymask = ((y < img_overl->clip_top) || (y >= img_overl->clip_bottom));
@@ -685,49 +1354,165 @@ void blend_yuy2 (uint8_t * dst_img, vo_overlay_t * img_overl,
for (x = 0; x < src_width;) {
- uint8_t clr;
uint16_t o;
- int rlelen;
+ if (rle >= rle_limit)
+ break;
+
+ if ((rlelen < 0) || (rle_remainder < 0)) {
+#ifdef LOG_BLEND_YUV
+ printf("alphablend: major bug in blend_yuv < 0\n");
+#endif
+ }
+ if (rlelen == 0) {
+ rle_remainder = rlelen = rle->len;
clr = rle->color;
- o = my_trans[clr];
- rlelen = rle->len;
+ rle++;
+ }
+ if (rle_remainder == 0) {
+ rle_remainder = rlelen;
+ }
+ if ((rle_remainder + x) > src_width) {
+ /* Do something for long rlelengths */
+ rle_remainder = src_width - x;
+ }
+#ifdef LOG_BLEND_YUV
+ printf("2:rle_len=%d, remainder=%d, x=%d\n",rlelen, rle_remainder, x);
+#endif
- if (o && mask) {
- /* threat cases where clipping border is inside rle->len pixels */
- if ( img_overl->clip_left > x ) {
- if( img_overl->clip_left < x + rlelen ) {
- rlelen -= img_overl->clip_left - x;
- x += img_overl->clip_left - x;
+ if (ymask == 0) {
+ if (x < img_overl->clip_left) {
+ /* Starts outside clip area */
+ if ((x + rle_remainder) > img_overl->clip_left ) {
+#ifdef LOG_BLEND_YUV
+ printf("Outside clip left %d, ending inside\n", img_overl->clip_left);
+#endif
+ /* Cutting needed, starts outside, ends inside */
+ rle_this_bite = (img_overl->clip_left - x);
+ rle_remainder -= rle_this_bite;
+ rlelen -= rle_this_bite;
+ my_clut = (clut_t*) img_overl->color;
+ my_trans = img_overl->trans;
+ } else {
+#ifdef LOG_BLEND_YUV
+ printf("Outside clip left %d, ending outside\n", img_overl->clip_left);
+#endif
+ /* no cutting needed, starts outside, ends outside */
+ rle_this_bite = rle_remainder;
+ rle_remainder = 0;
+ rlelen -= rle_this_bite;
+ my_clut = (clut_t*) img_overl->color;
+ my_trans = img_overl->trans;
+ }
+ } else if (x < clip_right) {
+ /* Starts inside clip area */
+ if ((x + rle_remainder) > clip_right ) {
+#ifdef LOG_BLEND_YUV
+ printf("Inside clip right %d, ending outside\n", clip_right);
+#endif
+ /* Cutting needed, starts inside, ends outside */
+ rle_this_bite = (clip_right - x);
+ rle_remainder -= rle_this_bite;
+ rlelen -= rle_this_bite;
+ my_clut = (clut_t*) img_overl->clip_color;
+ my_trans = img_overl->clip_trans;
} else {
- o = 0;
+#ifdef LOG_BLEND_YUV
+ printf("Inside clip right %d, ending inside\n", clip_right);
+#endif
+ /* no cutting needed, starts inside, ends inside */
+ rle_this_bite = rle_remainder;
+ rle_remainder = 0;
+ rlelen -= rle_this_bite;
+ my_clut = (clut_t*) img_overl->clip_color;
+ my_trans = img_overl->clip_trans;
}
- } else if( clip_right < x + rlelen ) {
- if( clip_right > x ) {
- /* fixme: case not implemented */
- o = 0;
+ } else if (x >= clip_right) {
+ /* Starts outside clip area, ends outsite clip area */
+ if ((x + rle_remainder ) > src_width ) {
+#ifdef LOG_BLEND_YUV
+ printf("Outside clip right %d, ending eol\n", clip_right);
+#endif
+ /* Cutting needed, starts outside, ends at right edge */
+ /* It should never reach here due to the earlier test of src_width */
+ rle_this_bite = (src_width - x );
+ rle_remainder -= rle_this_bite;
+ rlelen -= rle_this_bite;
+ my_clut = (clut_t*) img_overl->color;
+ my_trans = img_overl->trans;
} else {
- o = 0;
+ /* no cutting needed, starts outside, ends outside */
+#ifdef LOG_BLEND_YUV
+ printf("Outside clip right %d, ending outside\n", clip_right);
+#endif
+ rle_this_bite = rle_remainder;
+ rle_remainder = 0;
+ rlelen -= rle_this_bite;
+ my_clut = (clut_t*) img_overl->color;
+ my_trans = img_overl->trans;
+ }
}
+ } else {
+ /* Outside clip are due to y */
+ /* no cutting needed, starts outside, ends outside */
+ rle_this_bite = rle_remainder;
+ rle_remainder = 0;
+ rlelen -= rle_this_bite;
+ my_clut = (clut_t*) img_overl->color;
+ my_trans = img_overl->trans;
}
+ o = my_trans[clr];
+
+ if (x < (dst_width - x_off)) {
+ /* clip against right edge of destination area */
+ if ((x + rle_this_bite) > (dst_width - x_off)) {
+ int toClip = (x + rle_this_bite) - (dst_width - x_off);
+
+ rle_this_bite -= toClip;
+ rle_remainder += toClip;
+ rlelen += toClip;
}
+ if (enable_exact_blending) {
+ /* remember opacity of current line */
+ memset(&(*blend_yuy2_data)[ 0 ][ x + x_odd ], o, rle_this_bite);
+ any_line_buffered = 1;
+ }
- if (o && mask) {
- l = rlelen>>1;
- if( !(x & 1) ) {
- yuy2 = my_clut[clr].y + (my_clut[clr].cb << 8) +
- (my_clut[clr].y << 16) + (my_clut[clr].cr << 24);
+ if (o) {
+ if (!enable_exact_blending) {
+ l = rle_this_bite>>1;
+ if( !((x_odd+x) & 1) ) {
+ yuy2.b[0] = my_clut[clr].y;
+ yuy2.b[1] = my_clut[clr].cb;
+ yuy2.b[2] = my_clut[clr].y;
+ yuy2.b[3] = my_clut[clr].cr;
} else {
- yuy2 = my_clut[clr].y + (my_clut[clr].cr << 8) +
- (my_clut[clr].y << 16) + (my_clut[clr].cb << 24);
+ yuy2.b[0] = my_clut[clr].y;
+ yuy2.b[1] = my_clut[clr].cr;
+ yuy2.b[2] = my_clut[clr].y;
+ yuy2.b[3] = my_clut[clr].cb;
+ }
}
-
if (o >= 15) {
+ if (!enable_exact_blending) {
while(l--) {
- *((uint32_t *)dst)++ = yuy2;
+ *(uint16_t *)dst = yuy2.h[0];
+ dst += 2;
+ *(uint16_t *)dst = yuy2.h[1];
+ dst += 2;
+ }
+ if(rle_this_bite & 1) {
+ *(uint16_t *)dst = yuy2.h[0];
+ dst += 2;
}
- if(rlelen & 1)
- *((uint16_t *)dst)++ = yuy2 & 0xffff;
} else {
+ l = rle_this_bite;
+ while (l--) {
+ *dst = my_clut[clr].y;
+ dst += 2;
+ }
+ }
+ } else {
+ if (!enable_exact_blending) {
if( l ) {
- mem_blend32(dst, (uint8_t *)&yuy2, o, l);
+ mem_blend32(dst, &yuy2.b[0], o, l);
dst += 4*l;
@@ -735,14 +1520,224 @@ void blend_yuy2 (uint8_t * dst_img, vo_overlay_t * img_overl,
- if(rlelen & 1) {
- *dst = BLEND_BYTE(*dst, *((uint8_t *)&yuy2), o);
+ if(rle_this_bite & 1) {
+ *dst = BLEND_BYTE(*dst, yuy2.b[0], o);
dst++;
- *dst = BLEND_BYTE(*dst, *((uint8_t *)&yuy2+1), o);
+ *dst = BLEND_BYTE(*dst, yuy2.b[1], o);
dst++;
}
+ } else {
+ l = rle_this_bite;
+ while (l--) {
+ *dst = BLEND_BYTE(*dst, my_clut[clr].y, o);
+ dst += 2;
+ }
+ }
+ }
+
+ if (enable_exact_blending) {
+ /* remember chroma of current line */
+ memset(&(*blend_yuy2_data)[ 1 ][ x + x_odd ], my_clut[ clr ].cr, rle_this_bite);
+ memset(&(*blend_yuy2_data)[ 2 ][ x + x_odd ], my_clut[ clr ].cb, rle_this_bite);
}
} else {
- dst += rlelen*2;
+ dst += rle_this_bite*2;
+ }
+ }
+
+ x += rle_this_bite;
+ }
+
+ if (enable_exact_blending) {
+ /* blend buffered line */
+ if (any_line_buffered) {
+ blend_yuy2_exact(dst_y - x_odd * 2 + 3, dst_y - x_odd * 2 + 1, exact_blend_width, x_odd, blend_yuy2_data);
+
+ any_line_buffered = 0;
+ }
+ }
+
+ dst_y += dst_pitch;
+ }
+}
+
+void clear_xx44_palette(xx44_palette_t *p)
+{
+ register int i;
+ register uint32_t *cluts = p->cluts;
+ register int *ids = p->lookup_cache;
+
+ i= p->size;
+ while(i--)
+ *cluts++ = 0;
+ i = 2*OVL_PALETTE_SIZE;
+ while(i--)
+ *ids++ = -1;
+ p->max_used=1;
+}
+
+void init_xx44_palette(xx44_palette_t *p, unsigned num_entries)
+{
+ p->size = (num_entries > XX44_PALETTE_SIZE) ? XX44_PALETTE_SIZE : num_entries;
}
- x += rlelen;
+void dispose_xx44_palette(xx44_palette_t *p)
+{
+}
+
+static void colorToPalette(const uint32_t *icolor, unsigned char *palette_p,
+ unsigned num_xvmc_components, char *xvmc_components)
+{
+ const clut_t *color = (const clut_t *) icolor;
+ int i;
+ for (i=0; i<num_xvmc_components; ++i) {
+ switch(xvmc_components[i]) {
+ case 'V': *palette_p = color->cr; break;
+ case 'U': *palette_p = color->cb; break;
+ case 'Y':
+ default: *palette_p = color->y; break;
+ }
+ *palette_p++;
+ }
+}
+
+
+void xx44_to_xvmc_palette(const xx44_palette_t *p,unsigned char *xvmc_palette,
+ unsigned first_xx44_entry, unsigned num_xx44_entries,
+ unsigned num_xvmc_components, char *xvmc_components)
+{
+ register int i;
+ register const uint32_t *cluts = p->cluts + first_xx44_entry;
+
+ for (i=0; i<num_xx44_entries; ++i) {
+ if ((cluts - p->cluts) < p->size) {
+ colorToPalette(cluts++, xvmc_palette, num_xvmc_components, xvmc_components);
+ xvmc_palette += num_xvmc_components;
+ }
+ }
+}
+
+static int xx44_paletteIndex(xx44_palette_t *p, int color, uint32_t clut)
+{
+
+ register int i;
+ register uint32_t *cluts = p->cluts;
+ register int tmp;
+
+ if ((tmp = p->lookup_cache[color]) >= 0)
+ if (cluts[tmp] == clut) return tmp;
+
+ for (i=0; i<p->max_used; ++i) {
+ if (*cluts++ == clut) return p->lookup_cache[color] = i;
+ }
+
+ if (p->max_used == p->size -1) {
+ printf("video_out: Warning! Out of xx44 palette colors!\n");
+ return 1;
+ }
+ p->cluts[p->max_used] = clut;
+ return p->lookup_cache[color] = p->max_used++;
+}
+
+static void memblend_xx44(uint8_t *mem,uint8_t val, register size_t size, uint8_t mask)
+{
+ register uint8_t masked_val = val & mask;
+
+ while(size--) {
+ if ((*mem & mask) <= masked_val ) *mem = val;
+ mem++;
+ }
+}
+
+void blend_xx44 (uint8_t *dst_img, vo_overlay_t *img_overl,
+ int dst_width, int dst_height, int dst_pitch,
+ alphablend_t *extra_data,
+ xx44_palette_t *palette,int ia44)
+{
+ int src_width = img_overl->width;
+ int src_height = img_overl->height;
+ rle_elem_t *rle = img_overl->rle;
+ rle_elem_t *rle_limit = rle + img_overl->num_rle;
+ int mask;
+ int x_off = img_overl->x;
+ int y_off = img_overl->y;
+ int x, y;
+ uint8_t norm_pixel,clip_pixel;
+ uint8_t *dst_y;
+ uint8_t *dst;
+ uint8_t alphamask = (ia44) ? 0x0F : 0xF0;
+ int clip_right;
+
+ if (!img_overl)
+ return;
+
+ dst_y = dst_img + dst_pitch*y_off + x_off;
+
+ if( (x_off + img_overl->width) <= dst_width )
+ clip_right = img_overl->width;
+ else
+ clip_right = dst_width - x_off;
+
+ if ((src_height + y_off) > dst_height)
+ src_height = dst_height - y_off;
+
+ for (y = 0; y < src_height; y++) {
+
+ mask = !(y < img_overl->clip_top || y >= img_overl->clip_bottom);
+ dst = dst_y;
+
+ for (x = 0; x < src_width;) {
+ int len = (x + rle->len > clip_right) ? clip_right - x : rle->len;
+
+ if (len > 0) {
+ norm_pixel = (uint8_t)((xx44_paletteIndex(palette,rle->color,
+ img_overl->color[rle->color]) << 4) |
+ (img_overl->trans[rle->color] & 0x0F));
+ clip_pixel = (uint8_t)((xx44_paletteIndex(palette,rle->color+OVL_PALETTE_SIZE,
+ img_overl->clip_color[rle->color]) << 4) |
+ (img_overl->clip_trans[rle->color] & 0x0F));
+ if (!ia44) {
+ norm_pixel = ((norm_pixel & 0x0F) << 4) | ((norm_pixel & 0xF0) >> 4);
+ clip_pixel = ((clip_pixel & 0x0F) << 4) | ((clip_pixel & 0xF0) >> 4);
+ }
+ if (mask) {
+ if (x < img_overl->clip_left) {
+ if (x + len <= img_overl->clip_left) {
+ memblend_xx44(dst,norm_pixel,len, alphamask);
+ dst += len;
+ } else {
+ memblend_xx44(dst,norm_pixel,img_overl->clip_left -x, alphamask);
+ dst += img_overl->clip_left - x;
+ len -= img_overl->clip_left - x;
+ if (len <= img_overl->clip_right - img_overl->clip_left) {
+ memblend_xx44(dst,clip_pixel,len, alphamask);
+ dst += len;
+ } else {
+ memblend_xx44(dst,clip_pixel,img_overl->clip_right - img_overl->clip_left,
+ alphamask);
+ dst += img_overl->clip_right - img_overl->clip_left;
+ len -= img_overl->clip_right - img_overl->clip_left;
+ memblend_xx44(dst,norm_pixel,len, alphamask);
+ dst += len;
+ }
+ }
+ } else if (x < img_overl->clip_right) {
+ if (len <= img_overl->clip_right - x) {
+ memblend_xx44(dst,clip_pixel,len, alphamask);
+ dst += len;
+ } else {
+ memblend_xx44(dst,clip_pixel,img_overl->clip_right - x,alphamask);
+ dst += img_overl->clip_right - x;
+ len -= img_overl->clip_right - x;
+ memblend_xx44(dst,norm_pixel,len, alphamask);
+ dst += len;
+ }
+ } else {
+ memblend_xx44(dst,norm_pixel,len, alphamask);
+ dst += len;
+ }
+ } else {
+ memblend_xx44(dst,norm_pixel,len, alphamask);
+ dst += len;
+ }
+ }
+ x += rle->len;
rle++;
@@ -751,5 +1746,39 @@ void blend_yuy2 (uint8_t * dst_img, vo_overlay_t * img_overl,
if (rle >= rle_limit) break;
+ dst_y += dst_pitch;
+ }
+}
- dst_y += dst_width*2;
+static void alphablend_disable_exact_osd_alpha_blending_changed(void *user_data, xine_cfg_entry_t *entry)
+{
+ alphablend_t *extra_data = (alphablend_t *)user_data;
+
+ extra_data->disable_exact_blending = entry->num_value;
}
+
+void _x_alphablend_init(alphablend_t *extra_data, xine_t *xine)
+{
+ config_values_t *config = xine->config;
+
+ extra_data->buffer = 0;
+ extra_data->buffer_size = 0;
+
+ extra_data->disable_exact_blending =
+ config->register_bool(config, "video.output.disable_exact_alphablend", 0,
+ _("disable exact alpha blending of overlays"),
+ _("If you experience a performance impact when an On Screen Display or other "
+ "overlays like DVD subtitles are active, then you might want to enable this option.\n"
+ "The result is that alpha blending of overlays is less accurate than before, "
+ "but the CPU usage will be decreased as well."),
+ 10, alphablend_disable_exact_osd_alpha_blending_changed, extra_data);
}
+
+void _x_alphablend_free(alphablend_t *extra_data)
+{
+ if (extra_data->buffer) {
+ free(extra_data->buffer);
+ extra_data->buffer = NULL;
+ }
+
+ extra_data->buffer_size = 0;
+}
+
diff --git a/noncore/multimedia/opieplayer2/alphablend.h b/noncore/multimedia/opieplayer2/alphablend.h
index 7230f41..1edb5ba 100644
--- a/noncore/multimedia/opieplayer2/alphablend.h
+++ b/noncore/multimedia/opieplayer2/alphablend.h
@@ -29,2 +29,31 @@
+typedef struct {
+ void *buffer;
+ int buffer_size;
+
+ int disable_exact_blending;
+} alphablend_t;
+
+void _x_alphablend_init(alphablend_t *extra_data, xine_t *xine);
+void _x_alphablend_free(alphablend_t *extra_data);
+
+/* _MSC_VER port changes */
+#undef ATTRIBUTE_PACKED
+#undef PRAGMA_PACK_BEGIN
+#undef PRAGMA_PACK_END
+
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) || defined(__ICC)
+#define ATTRIBUTE_PACKED __attribute__ ((packed))
+#define PRAGMA_PACK 0
+#endif
+
+#if !defined(ATTRIBUTE_PACKED)
+#define ATTRIBUTE_PACKED
+#define PRAGMA_PACK 1
+#endif
+
+#if PRAGMA_PACK
+#pragma pack(8)
+#endif
+
typedef struct { /* CLUT == Color LookUp Table */
@@ -34,3 +63,19 @@ typedef struct { /* CLUT == Color LookUp Table */
uint8_t foo : 8;
-} __attribute__ ((packed)) clut_t;
+} ATTRIBUTE_PACKED clut_t;
+
+
+#if PRAGMA_PACK
+#pragma pack()
+#endif
+
+#define XX44_PALETTE_SIZE 32
+
+typedef struct {
+ unsigned size;
+ unsigned max_used;
+ uint32_t cluts[XX44_PALETTE_SIZE];
+ /* cache palette entries for both colors and clip_colors */
+ int lookup_cache[OVL_PALETTE_SIZE*2];
+} xx44_palette_t;
+
@@ -38,3 +83,4 @@ void blend_rgb16 (uint8_t * img, vo_overlay_t * img_overl,
int img_width, int img_height,
- int dst_width, int dst_height);
+ int dst_width, int dst_height,
+ alphablend_t *extra_data);
@@ -42,3 +88,4 @@ void blend_rgb24 (uint8_t * img, vo_overlay_t * img_overl,
int img_width, int img_height,
- int dst_width, int dst_height);
+ int dst_width, int dst_height,
+ alphablend_t *extra_data);
@@ -46,11 +93,41 @@ void blend_rgb32 (uint8_t * img, vo_overlay_t * img_overl,
int img_width, int img_height,
- int dst_width, int dst_height);
+ int dst_width, int dst_height,
+ alphablend_t *extra_data);
void blend_yuv (uint8_t *dst_base[3], vo_overlay_t * img_overl,
- int dst_width, int dst_height);
+ int dst_width, int dst_height, int dst_pitches[3],
+ alphablend_t *extra_data);
void blend_yuy2 (uint8_t * dst_img, vo_overlay_t * img_overl,
- int dst_width, int dst_height);
+ int dst_width, int dst_height, int dst_pitch,
+ alphablend_t *extra_data);
+
+/*
+ * This function isn't too smart about blending. We want to avoid creating new
+ * colors in the palette as a result from two non-zero colors needed to be
+ * blended. Instead we choose the color with the highest alpha value to be
+ * visible. Some parts of the code taken from the "VeXP" project.
+ */
+
+void blend_xx44 (uint8_t *dst_img, vo_overlay_t *img_overl,
+ int dst_width, int dst_height, int dst_pitch,
+ alphablend_t *extra_data,
+ xx44_palette_t *palette,int ia44);
+
+/*
+ * Functions to handle the xine-specific palette.
+ */
+
+void clear_xx44_palette(xx44_palette_t *p);
+void init_xx44_palette(xx44_palette_t *p, unsigned num_entries);
+void dispose_xx44_palette(xx44_palette_t *p);
+
+/*
+ * Convert the xine-specific palette to something useful.
+ */
+
+void xx44_to_xvmc_palette(const xx44_palette_t *p,unsigned char *xvmc_palette,
+ unsigned first_xx44_entry, unsigned num_xx44_entries,
+ unsigned num_xvmc_components, char *xvmc_components);
-void crop_overlay (vo_overlay_t * overlay);
diff --git a/noncore/multimedia/opieplayer2/lib.cpp b/noncore/multimedia/opieplayer2/lib.cpp
index 4ae8490..84d28ce 100644
--- a/noncore/multimedia/opieplayer2/lib.cpp
+++ b/noncore/multimedia/opieplayer2/lib.cpp
@@ -51,18 +51,13 @@ typedef void (*display_xine_frame_t) (void *user_data, uint8_t* frame,
int width, int height,int bytes );
+typedef void (*vo_scale_cb) (void*, int, int, double,
+ int*, int*, int*, int*, double*, int*, int* );
+typedef void (*dest_size_cb) (void*, int, int, double, int*, int*, double*);
+
extern "C" {
- xine_vo_driver_t* init_video_out_plugin( xine_t *xine, void* video, display_xine_frame_t, void * );
+ xine_vo_driver_t* init_video_out_plugin( xine_t *xine, void* video, display_xine_frame_t, void *, vo_scale_cb, dest_size_cb );
int null_is_showing_video( const xine_vo_driver_t* self );
void null_set_show_video( const xine_vo_driver_t* self, int show );
- int null_is_fullscreen( const xine_vo_driver_t* self );
- void null_set_fullscreen( const xine_vo_driver_t* self, int screen );
- int null_is_scaling( const xine_vo_driver_t* self );
- void null_set_scaling( const xine_vo_driver_t* self, int scale );
- void null_set_gui_width( const xine_vo_driver_t* self, int width );
- void null_set_gui_height( const xine_vo_driver_t* self, int height );
void null_set_mode( const xine_vo_driver_t* self, int depth, int rgb );
- void null_set_videoGamma( const xine_vo_driver_t* self , int value );
void null_display_handler( const xine_vo_driver_t* self, display_xine_frame_t t, void* user_data );
-
- void null_preload_decoders( xine_stream_t *stream );
}
@@ -129,3 +124,6 @@ void Lib::initialize()
m_audioOutput = xine_open_audio_driver( m_xine, "oss", NULL );
- m_videoOutput = ::init_video_out_plugin( m_xine, NULL, xine_display_frame, this );
+ m_videoOutput = ::init_video_out_plugin( m_xine, NULL,
+ xine_display_frame, this,
+ xine_vo_scale_cb,
+ xine_dest_cb );
@@ -141,4 +139,2 @@ void Lib::initialize()
- ::null_preload_decoders( m_stream );
-
m_duringInitialization = false;
@@ -167,6 +163,4 @@ void Lib::resize ( const QSize &s ) {
- if ( s. width ( ) && s. height ( ) ) {
- ::null_set_gui_width( m_videoOutput, s. width() );
- ::null_set_gui_height( m_videoOutput, s. height() );
- }
+ if ( s. width ( ) && s. height ( ) )
+ m_videoSize = s;
}
@@ -424,3 +418,3 @@ void Lib::showVideoFullScreen( bool fullScreen ) {
- ::null_set_fullscreen( m_videoOutput, fullScreen );
+ #warning use xine
}
@@ -430,3 +424,4 @@ bool Lib::isVideoFullScreen() const {
- return ::null_is_fullscreen( m_videoOutput );
+ #warning use xine
+ return false;
}
@@ -436,3 +431,4 @@ void Lib::setScaling( bool scale ) {
- ::null_set_scaling( m_videoOutput, scale );
+ xine_set_param( m_stream, XINE_PARAM_VO_ASPECT_RATIO,
+ scale ? XINE_VO_ASPECT_AUTO : XINE_VO_ASPECT_SQUARE );
}
@@ -441,4 +437,3 @@ void Lib::setGamma( int value ) {
assert( m_initialized );
-
- ::null_set_videoGamma( m_videoOutput, value );
+ xine_set_param( m_stream, XINE_PARAM_VO_BRIGHTNESS, value );
}
@@ -448,3 +443,4 @@ bool Lib::isScaling() const {
- return ::null_is_scaling( m_videoOutput );
+ int aratio = xine_get_param( m_stream, XINE_PARAM_VO_ASPECT_RATIO );
+ return aratio == XINE_VO_ASPECT_AUTO;
}
@@ -460,10 +456,34 @@ void Lib::xine_display_frame( void* user_data, uint8_t *frame,
-void Lib::drawFrame( uint8_t* frame, int width, int height, int bytes ) {
- assert( m_initialized );
+void Lib::xine_vo_scale_cb( void *user_data, int video_with, int video_height,
+ double video_pixel_aspect,
+ int *dest_x, int *dest_y, int *dest_width,
+ int *dest_height, double *dest_pixel_aspect,
+ int *win_x, int *win_y ) {
+ QSize size = ((Lib*)user_data)->m_videoSize;
+ if (!size.isValid())
+ return;
- if ( !m_video ) {
+ *dest_x = 0;
+ *dest_y = 0;
+ *dest_width = size.width();
+ *dest_height = size.height();
+ *win_x = 0;
+ *win_y = 0;
+}
+
+void Lib::xine_dest_cb( void* user_data, int, int, double,
+ int *dest_width, int* dest_height, double* ) {
+ QSize size = ((Lib*)user_data)->m_videoSize;
+ if ( !size.isValid() )
return;
+
+ *dest_width = size.width();
+ *dest_height = size.height();
}
-// assert( m_wid );
+void Lib::drawFrame( uint8_t* frame, int width, int height, int bytes ) {
+ assert( m_initialized );
+
+ if ( !m_video )
+ return;
diff --git a/noncore/multimedia/opieplayer2/lib.h b/noncore/multimedia/opieplayer2/lib.h
index 2607193..a6ac033 100644
--- a/noncore/multimedia/opieplayer2/lib.h
+++ b/noncore/multimedia/opieplayer2/lib.h
@@ -196,2 +196,3 @@ namespace XINE {
XineVideoWidget *m_wid;
+ QSize m_videoSize;
xine_t *m_xine;
@@ -210,2 +211,5 @@ namespace XINE {
int width, int height, int bytes );
+ static void xine_vo_scale_cb(void *, int, int, double,
+ int*,int*,int*,int*,double*,int*,int*);
+ static void xine_dest_cb(void*,int,int,double,int*,int*,double*);
};
diff --git a/noncore/multimedia/opieplayer2/mainTest.cpp b/noncore/multimedia/opieplayer2/mainTest.cpp
deleted file mode 100644
index e374c89..0000000
--- a/noncore/multimedia/opieplayer2/mainTest.cpp
+++ b/dev/null
@@ -1,16 +0,0 @@
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#include "lib.h"
-
-int main( int argc, char *argv[] ) {
- printf("FixME\n");
- //return 0;
- XINE::Lib lib;
- QString str = QString::fromLatin1( argv[1] );
- lib.play( str );
- for (;;) sleep( 60 );
- return 0;
-}
diff --git a/noncore/multimedia/opieplayer2/nullvideo.c b/noncore/multimedia/opieplayer2/nullvideo.c
index 6769a37..99fa329 100644
--- a/noncore/multimedia/opieplayer2/nullvideo.c
+++ b/noncore/multimedia/opieplayer2/nullvideo.c
@@ -4,3 +4,2 @@
              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org>
- Copyright (c) 2002 LJP <>
Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
@@ -42,3 +41,2 @@
#include <xine/xine_internal.h>
-//#include <xine/xineutils.h>
#include <xine/vo_scale.h>
@@ -53,3 +51,3 @@
/*
-#define LOG
+ * #define LOG
*/
@@ -59,2 +57,6 @@ typedef void (*display_xine_frame_t) (void *user_data, uint8_t* frame,
int width, int height,int bytes );
+typedef void (*vo_scale_cb) (void*, int, int, double,
+ int*, int*, int*, double*, int*, int* );
+typedef void (*dest_size_cb) (void*, int, int, double, int*, int*, double*);
+
@@ -65,6 +67,4 @@ struct null_driver_s {
- uint32_t m_capabilities;
int m_show_video;
int m_video_fullscreen;
- int m_is_scaling;
@@ -73,3 +73,3 @@ struct null_driver_s {
int yuv2rgb_swap;
- int yuv2rgb_gamma;
+ int yuv2rgb_brightness;
uint8_t *yuv2rgb_cmap;
@@ -80,9 +80,10 @@ struct null_driver_s {
- int gui_width;
- int gui_height;
- int gui_changed;
-
- double display_ratio;
- void* caller;
+ /*
+ * DISPLAY to widget...
+ */
display_xine_frame_t frameDis;
+ void *userData;
+
+ xine_t *xine;
+ alphablend_t alphablend_extra_data;
};
@@ -112,4 +113,4 @@ struct opie_frame_s {
static uint32_t null_get_capabilities( vo_driver_t *self ){
- null_driver_t* this = (null_driver_t*)self;
- return this->m_capabilities;
+ self = self;
+ return VO_CAP_YUY2 | VO_CAP_YV12;
}
@@ -121,4 +122,14 @@ static void null_frame_proc_slice (vo_frame_t *vo_img, uint8_t **src) {
- if (!frame->output->m_show_video) {
- /* printf("nullvideo: no video\n"); */
+ /*
+ * drop hard if we don't show the video
+ */
+ if (!frame->output->m_show_video)
+ return;
+
+ if( frame->frame.crop_left || frame->frame.crop_top ||
+ frame->frame.crop_right || frame->frame.crop_bottom )
+ {
+ /* we don't support crop, so don't even waste cpu cycles.
+ * cropping will be performed by video_out.c
+ */
return;
@@ -144,3 +155,3 @@ static void null_frame_field (vo_frame_t *vo_img, int which_field) {
case VO_TOP_FIELD:
- frame->rgb_dst = (uint8_t *)frame->data;
+ frame->rgb_dst = frame->data;
frame->stripe_inc = 2*frame->stripe_height * frame->bytes_per_line;
@@ -148,3 +159,3 @@ static void null_frame_field (vo_frame_t *vo_img, int which_field) {
case VO_BOTTOM_FIELD:
- frame->rgb_dst = (uint8_t *)frame->data + frame->bytes_per_line ;
+ frame->rgb_dst = frame->data + frame->bytes_per_line ;
frame->stripe_inc = 2*frame->stripe_height * frame->bytes_per_line;
@@ -152,3 +163,3 @@ static void null_frame_field (vo_frame_t *vo_img, int which_field) {
case VO_BOTH_FIELDS:
- frame->rgb_dst = (uint8_t *)frame->data;
+ frame->rgb_dst = frame->data;
break;
@@ -179,2 +190,4 @@ static vo_frame_t* null_alloc_frame( vo_driver_t* self ){
frame = (opie_frame_t*)xine_xmalloc ( sizeof(opie_frame_t) );
+ if(!frame)
+ return NULL;
@@ -189,2 +202,3 @@ static vo_frame_t* null_alloc_frame( vo_driver_t* self ){
frame->frame.proc_slice = null_frame_proc_slice;
+ frame->frame.proc_frame = NULL;
frame->frame.field = null_frame_field;
@@ -231,3 +245,2 @@ static void null_frame_reallocate( null_driver_t *this, opie_frame_t *frame,
*/
- if( frame->data ) {
if( frame->chunk[0] ){
@@ -244,4 +257,4 @@ static void null_frame_reallocate( null_driver_t *this, opie_frame_t *frame,
}
+ if(frame->data)
free ( frame->data );
- }
@@ -312,6 +325,13 @@ static void null_update_frame_format( vo_driver_t* self, vo_frame_t* img,
+ int gui_width = 0;
+ int gui_height = 0;
+ double gui_pixel_aspect = 0.0;
+
flags &= VO_BOTH_FIELDS;
- /* find out if we need to adapt this frame */
+ frame->sc.dest_size_cb(frame->sc.user_data, width, height,
+ frame->sc.video_pixel_aspect,
+ &gui_width, &gui_height, &gui_pixel_aspect);
+ /* find out if we need to adapt this frame */
if ((width != frame->sc.delivered_width)
@@ -322,5 +342,4 @@ static void null_update_frame_format( vo_driver_t* self, vo_frame_t* img,
|| (this->sc.user_ratio != frame->sc.user_ratio)
- || (this->gui_width != frame->sc.gui_width)
- || (this->gui_height != frame->sc.gui_height)) {
-
+ || (gui_width != frame->sc.gui_width)
+ || (gui_height != frame->sc.gui_height)) {
frame->sc.delivered_width = width;
@@ -331,5 +350,4 @@ static void null_update_frame_format( vo_driver_t* self, vo_frame_t* img,
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;
+ frame->sc.gui_width = gui_width;
+ frame->sc.gui_height = gui_height;
@@ -365,3 +383,3 @@ static void null_update_frame_format( vo_driver_t* self, vo_frame_t* img,
case VO_TOP_FIELD:
- frame->rgb_dst = (uint8_t *)frame->data;
+ frame->rgb_dst = frame->data;
frame->stripe_inc = 2 * frame->stripe_height * frame->bytes_per_line;
@@ -369,3 +387,3 @@ static void null_update_frame_format( vo_driver_t* self, vo_frame_t* img,
case VO_BOTTOM_FIELD:
- frame->rgb_dst = (uint8_t *)frame->data + frame->bytes_per_line ;
+ frame->rgb_dst = frame->data + frame->bytes_per_line ;
frame->stripe_inc = 2 * frame->stripe_height * frame->bytes_per_line;
@@ -373,3 +391,3 @@ static void null_update_frame_format( vo_driver_t* self, vo_frame_t* img,
case VO_BOTH_FIELDS:
- frame->rgb_dst = (uint8_t *)frame->data;
+ frame->rgb_dst = frame->data;
frame->stripe_inc = frame->stripe_height * frame->bytes_per_line;
@@ -389,3 +407,3 @@ static void null_display_frame( vo_driver_t* self, vo_frame_t *frame_gen ){
if( display != NULL ) {
- (*display)(this->caller, frame->data,
+ (*display)(this->userData, frame->data,
frame->sc.output_width, frame->sc.output_height,
@@ -444,3 +462,3 @@ static void null_overlay_blend ( vo_driver_t *this_gen, vo_frame_t *frame_gen,
case 16:
- blend_rgb16((uint8_t *)frame->data,
+ blend_rgb16(frame->data,
overlay,
@@ -449,6 +467,7 @@ static void null_overlay_blend ( vo_driver_t *this_gen, vo_frame_t *frame_gen,
frame->sc.delivered_width,
- frame->sc.delivered_height);
+ frame->sc.delivered_height,
+ &this->alphablend_extra_data);
break;
case 24:
- blend_rgb24((uint8_t *)frame->data,
+ blend_rgb24(frame->data,
overlay,
@@ -457,6 +476,7 @@ static void null_overlay_blend ( vo_driver_t *this_gen, vo_frame_t *frame_gen,
frame->sc.delivered_width,
- frame->sc.delivered_height);
+ frame->sc.delivered_height,
+ &this->alphablend_extra_data);
break;
case 32:
- blend_rgb32((uint8_t *)frame->data,
+ blend_rgb32(frame->data,
overlay,
@@ -465,3 +485,4 @@ static void null_overlay_blend ( vo_driver_t *this_gen, vo_frame_t *frame_gen,
frame->sc.delivered_width,
- frame->sc.delivered_height);
+ frame->sc.delivered_height,
+ &this->alphablend_extra_data);
break;
@@ -476,3 +497,2 @@ static void null_overlay_blend ( vo_driver_t *this_gen, vo_frame_t *frame_gen,
static int null_get_property( vo_driver_t* self, int property ){
-#if 0
null_driver_t *this = (null_driver_t *)self;
@@ -492,6 +512,2 @@ static int null_get_property( vo_driver_t* self, int property ){
}
-#else
- property = property;
- self = self;
-#endif
@@ -501,3 +517,2 @@ static int null_set_property( vo_driver_t* self, int property,
int value ){
-#if 0
null_driver_t *this = (null_driver_t *)self;
@@ -519,6 +534,2 @@ static int null_set_property( vo_driver_t* self, int property,
}
-#else
- self = self;
- property = property;
-#endif
@@ -529,7 +540,9 @@ static void null_get_property_min_max( vo_driver_t* self,
int *max ){
- self = self;
- property = property;
-
- *max = 0;
+ if(property == VO_PROP_BRIGHTNESS) {
+ *min = -100;
+ *max = +100;
+ }else {
*min = 0;
+ *max = 0;
+ }
}
@@ -538,6 +551,2 @@ static int null_gui_data_exchange( vo_driver_t* self,
void *data ){
- self = self;
- data_type = data_type;
- data = data;
-
return 0;
@@ -547,2 +556,3 @@ static void null_dispose ( vo_driver_t* self ){
null_driver_t* this = (null_driver_t*)self;
+ _x_alphablend_free(&this->alphablend_extra_data);
free ( this );
@@ -550,5 +560,4 @@ static void null_dispose ( vo_driver_t* self ){
static int null_redraw_needed( vo_driver_t* self ){
- self = self;
-
- return 0;
+ null_driver_t *this = (null_driver_t*)self;
+ return _x_vo_scale_redraw_needed(&this->sc);
}
@@ -559,23 +568,19 @@ xine_video_port_t* init_video_out_plugin( xine_t *xine,
display_xine_frame_t frameDisplayFunc,
- void *userData ){
- video = video;
-
-
+ void *userData, vo_scale_cb frame_cb,
+ dest_size_cb dest_cb) {
null_driver_t *vo;
- vo = (null_driver_t*)malloc( sizeof(null_driver_t ) );
-
- /* memset? */
- memset(vo,0, sizeof(null_driver_t ) );
+ vo = (null_driver_t*)xine_xmalloc(sizeof(null_driver_t ));
+ vo->xine = xine;
+ _x_alphablend_init(&vo->alphablend_extra_data, xine);
_x_vo_scale_init (&vo->sc, 0, 0, xine->config);
+ vo->sc.gui_width = 18;
+ vo->sc.gui_height = 6;
+ vo->sc.user_ratio = XINE_VO_ASPECT_AUTO;
+ vo->sc.user_data = userData;
+ vo->sc.frame_output_cb = frame_cb;
+ vo->sc.dest_size_cb = dest_cb;
- 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;
@@ -586,3 +591,5 @@ xine_video_port_t* init_video_out_plugin( xine_t *xine,
vo->vo_driver.display_frame = null_display_frame;
+ vo->vo_driver.overlay_begin = 0;
vo->vo_driver.overlay_blend = null_overlay_blend;
+ vo->vo_driver.overlay_end = 0;
vo->vo_driver.get_property = null_get_property;
@@ -594,9 +601,13 @@ xine_video_port_t* init_video_out_plugin( xine_t *xine,
-
/* capabilities */
- vo->m_capabilities = VO_CAP_YUY2 | VO_CAP_YV12;
- vo->yuv2rgb_factory = yuv2rgb_factory_init (MODE_16_RGB, vo->yuv2rgb_swap,
+ vo->yuv2rgb_mode = MODE_16_RGB;
+ vo->yuv2rgb_brightness = 0;
+ vo->yuv2rgb_factory = yuv2rgb_factory_init (vo->yuv2rgb_mode,
+ vo->yuv2rgb_swap,
vo->yuv2rgb_cmap);
+ vo->yuv2rgb_factory->set_csc_levels(vo->yuv2rgb_factory,
+ vo->yuv2rgb_brightness,
+ 128,128);
- vo->caller = userData;
+ vo->userData = userData;
vo->frameDis = frameDisplayFunc;
@@ -623,27 +634,2 @@ void null_set_show_video( xine_vo_driver_t* self, int show ) {
-int null_is_fullscreen( xine_vo_driver_t* self ){
- return ((null_driver_t*)self->driver)->m_video_fullscreen;
-}
-void null_set_fullscreen( xine_vo_driver_t* self, int screen ){
- ((null_driver_t*)self->driver)->m_video_fullscreen = screen;
-}
-int null_is_scaling( xine_vo_driver_t* self ){
- return ((null_driver_t*)self->driver)->m_is_scaling;
-}
-
-void null_set_videoGamma( xine_vo_driver_t* self , int value ) {
- ((null_driver_t*) self->driver) ->yuv2rgb_gamma = value;
- ((null_driver_t*) self->driver) ->yuv2rgb_factory->set_gamma( ((null_driver_t*) self->driver) ->yuv2rgb_factory, value );
-}
-
-void null_set_scaling( xine_vo_driver_t* self, int scale ) {
- ((null_driver_t*)self->driver)->m_is_scaling = scale;
-}
-
-void null_set_gui_width( xine_vo_driver_t* self, int width ) {
- ((null_driver_t*)self->driver)->gui_width = width;
-}
-void null_set_gui_height( xine_vo_driver_t* self, int height ) {
- ((null_driver_t*)self->driver)->gui_height = height;
-}
@@ -699,5 +685,2 @@ void null_set_mode( xine_vo_driver_t* self, int depth, int rgb ) {
};
- //free(this->yuv2rgb_factory );
- // this->yuv2rgb_factory = yuv2rgb_factory_init (this->yuv2rgb_mode, this->yuv2rgb_swap,
- // this->yuv2rgb_cmap);
};
@@ -707,3 +690,3 @@ void null_display_handler( xine_vo_driver_t* self, display_xine_frame_t t,
null_driver_t* this = (null_driver_t*) self->driver;
- this->caller = user_data;
+ this->userData = user_data;
this->frameDis = t;
@@ -711,25 +694,2 @@ void null_display_handler( xine_vo_driver_t* self, display_xine_frame_t t,
-void null_preload_decoders( xine_stream_t *stream )
-{
- static const uint32_t preloadedAudioDecoders[] = { BUF_AUDIO_MPEG, BUF_AUDIO_VORBIS };
- static const uint8_t preloadedAudioDecoderCount = sizeof( preloadedAudioDecoders ) / sizeof( preloadedAudioDecoders[ 0 ] );
- static const uint32_t preloadedVideoDecoders[] = { BUF_VIDEO_MPEG, BUF_VIDEO_MPEG4, BUF_VIDEO_DIVX5 };
- static const uint8_t preloadedVideoDecoderCount = sizeof( preloadedVideoDecoders ) / sizeof( preloadedVideoDecoders[ 0 ] );
-
- uint8_t i;
-#if 0
-
- for ( i = 0; i < preloadedAudioDecoderCount; ++i ) {
- audio_decoder_t *decoder = get_audio_decoder( stream, ( preloadedAudioDecoders[ i ] >> 16 ) & 0xff );
- decoder = decoder;
-/* free_audio_decoder( stream, decoder ); */
- }
-
- for ( i = 0; i < preloadedVideoDecoderCount; ++i ) {
- video_decoder_t *decoder = get_video_decoder( stream, ( preloadedVideoDecoders[ i ] >> 16 ) & 0xff );
- decoder = decoder;
-/* free_video_decoder( stream, decoder ); */
- }
-#endif
-}
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
@@ -3,3 +3,4 @@
*
- * 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.
*
@@ -33,4 +34,10 @@
#include "yuv2rgb.h"
-#include <xine/xineutils.h>
+#define LOG_MODULE "yuv2rgb"
+#define LOG_VERBOSE
+/*
+#define LOG
+*/
+
+#include <xine/xineutils.h>
@@ -53,4 +60,4 @@ 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;
@@ -61,3 +68,3 @@ static void *my_malloc_aligned (size_t alignment, size_t size, void **chunk) {
- while ((int) pMem % alignment)
+ while ((uintptr_t) pMem % alignment)
pMem++;
@@ -68,2 +75,39 @@ static void *my_malloc_aligned (size_t alignment, size_t size, void **chunk) {
+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,
@@ -87,2 +131,4 @@ static int yuv2rgb_configure (yuv2rgb_t *this,
this->rgb_stride = rgb_stride;
+ this->slice_height = source_height;
+ this->slice_offset = 0;
@@ -101,2 +147,12 @@ static int yuv2rgb_configure (yuv2rgb_t *this,
+#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
@@ -104,3 +160,6 @@ static int yuv2rgb_configure (yuv2rgb_t *this,
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);
@@ -140,2 +199,15 @@ static int yuv2rgb_configure (yuv2rgb_t *this,
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
}
@@ -144,3 +216,2 @@ static int yuv2rgb_configure (yuv2rgb_t *this,
-
static void scale_line_gen (uint8_t *source, uint8_t *dest,
@@ -1206,2 +1277,6 @@ static scale_line_func_t find_scale_line_func(int step) {
int i;
+#ifdef LOG
+ /* to filter out multiple messages about the scale_line variant we're using */
+ static int reported_for_step;
+#endif
@@ -1209,3 +1284,7 @@ static scale_line_func_t find_scale_line_func(int step) {
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;
@@ -1213,5 +1292,10 @@ static scale_line_func_t find_scale_line_func(int step) {
}
- //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;
}
@@ -1274,3 +1358,3 @@ static void scale_line_4 (uint8_t *source, uint8_t *dest,
-#define RGB(i) \
+#define X_RGB(i) \
U = pu[i]; \
@@ -1350,3 +1434,3 @@ static void yuv2rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst,
dy = 0;
- dst_height = this->dest_height;
+ dst_height = this->next_slice (this, &_dst);
@@ -1361,12 +1445,12 @@ static void yuv2rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst,
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);
@@ -1414,3 +1498,3 @@ static void yuv2rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst,
} else {
- height = this->source_height >> 1;
+ height = this->next_slice (this, &_dst) >> 1;
do {
@@ -1425,3 +1509,3 @@ static void yuv2rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst,
do {
- RGB(0);
+ X_RGB(0);
DST1(0);
@@ -1429,3 +1513,3 @@ static void yuv2rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst,
- RGB(1);
+ X_RGB(1);
DST2(1);
@@ -1433,3 +1517,3 @@ static void yuv2rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst,
- RGB(2);
+ X_RGB(2);
DST1(2);
@@ -1437,3 +1521,3 @@ static void yuv2rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst,
- RGB(3);
+ X_RGB(3);
DST2(3);
@@ -1481,3 +1565,3 @@ static void yuv2rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst,
dy = 0;
- dst_height = this->dest_height;
+ dst_height = this->next_slice (this, &_dst);
@@ -1492,12 +1576,12 @@ static void yuv2rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst,
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);
@@ -1545,3 +1629,3 @@ static void yuv2rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst,
} else {
- height = this->source_height >> 1;
+ height = this->next_slice (this, &_dst) >> 1;
do {
@@ -1556,3 +1640,3 @@ static void yuv2rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst,
do {
- RGB(0);
+ X_RGB(0);
DST1RGB(0);
@@ -1560,3 +1644,3 @@ static void yuv2rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst,
- RGB(1);
+ X_RGB(1);
DST2RGB(1);
@@ -1564,3 +1648,3 @@ static void yuv2rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst,
- RGB(2);
+ X_RGB(2);
DST1RGB(2);
@@ -1568,3 +1652,3 @@ static void yuv2rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst,
- RGB(3);
+ X_RGB(3);
DST2RGB(3);
@@ -1612,3 +1696,3 @@ static void yuv2rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst,
dy = 0;
- dst_height = this->dest_height;
+ dst_height = this->next_slice (this, &_dst);
@@ -1623,12 +1707,12 @@ static void yuv2rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst,
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);
@@ -1677,3 +1761,3 @@ static void yuv2rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst,
} else {
- height = this->source_height >> 1;
+ height = this->next_slice (this, &_dst) >> 1;
do {
@@ -1687,3 +1771,3 @@ static void yuv2rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst,
do {
- RGB(0);
+ X_RGB(0);
DST1BGR(0);
@@ -1691,3 +1775,3 @@ static void yuv2rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst,
- RGB(1);
+ X_RGB(1);
DST2BGR(1);
@@ -1695,3 +1779,3 @@ static void yuv2rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst,
- RGB(2);
+ X_RGB(2);
DST1BGR(2);
@@ -1699,3 +1783,3 @@ static void yuv2rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst,
- RGB(3);
+ X_RGB(3);
DST2BGR(3);
@@ -1743,3 +1827,3 @@ static void yuv2rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst,
dy = 0;
- dst_height = this->dest_height;
+ dst_height = this->next_slice (this, &_dst);
@@ -1754,12 +1838,12 @@ static void yuv2rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst,
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);
@@ -1807,3 +1891,3 @@ static void yuv2rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst,
} else {
- height = this->source_height >> 1;
+ height = this->next_slice (this, &_dst) >> 1;
do {
@@ -1817,3 +1901,3 @@ static void yuv2rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst,
do {
- RGB(0);
+ X_RGB(0);
DST1(0);
@@ -1821,3 +1905,3 @@ static void yuv2rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst,
- RGB(1);
+ X_RGB(1);
DST2(1);
@@ -1825,3 +1909,3 @@ static void yuv2rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst,
- RGB(2);
+ X_RGB(2);
DST1(2);
@@ -1829,3 +1913,3 @@ static void yuv2rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst,
- RGB(3);
+ X_RGB(3);
DST2(3);
@@ -1873,3 +1957,3 @@ static void yuv2rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst,
dy = 0;
- dst_height = this->dest_height;
+ dst_height = this->next_slice (this, &_dst);
@@ -1884,12 +1968,12 @@ static void yuv2rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst,
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);
@@ -1937,3 +2021,3 @@ static void yuv2rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst,
} else {
- height = this->source_height >> 1;
+ height = this->next_slice (this, &_dst) >> 1;
do {
@@ -1948,3 +2032,3 @@ static void yuv2rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst,
do {
- RGB(0);
+ X_RGB(0);
DST1(0);
@@ -1952,3 +2036,3 @@ static void yuv2rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst,
- RGB(1);
+ X_RGB(1);
DST2(1);
@@ -1956,3 +2040,3 @@ static void yuv2rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst,
- RGB(2);
+ X_RGB(2);
DST1(2);
@@ -1960,3 +2044,3 @@ static void yuv2rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst,
- RGB(3);
+ X_RGB(3);
DST2(3);
@@ -1992,3 +2076,3 @@ static void yuv2rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst,
dy = 0;
- dst_height = this->dest_height;
+ dst_height = this->next_slice (this, &_dst);
@@ -2018,3 +2102,3 @@ static void yuv2rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst,
} 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);
@@ -2048,3 +2132,3 @@ static void yuv2rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst,
dy = 0;
- dst_height = this->dest_height;
+ dst_height = this->next_slice (this, &_dst);
@@ -2059,12 +2143,12 @@ static void yuv2rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst,
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);
@@ -2112,3 +2196,3 @@ static void yuv2rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst,
} else {
- height = this->source_height >> 1;
+ height = this->next_slice (this, &_dst) >> 1;
do {
@@ -2122,3 +2206,3 @@ static void yuv2rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst,
do {
- RGB(0);
+ X_RGB(0);
DST1CMAP(0);
@@ -2126,3 +2210,3 @@ static void yuv2rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst,
- RGB(1);
+ X_RGB(1);
DST2CMAP(1);
@@ -2130,3 +2214,3 @@ static void yuv2rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst,
- RGB(2);
+ X_RGB(2);
DST1CMAP(2);
@@ -2134,3 +2218,3 @@ static void yuv2rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst,
- RGB(3);
+ X_RGB(3);
DST2CMAP(3);
@@ -2163,3 +2247,4 @@ static int div_round (int dividend, int 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)
{
@@ -2179,2 +2264,5 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
+ int mode = this->mode;
+ int swapped = this->swapped;
+
for (i = 0; i < 1024; i++) {
@@ -2182,3 +2270,3 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
- j = (76309 * (i - 384 - 16) + 32768) >> 16;
+ j = (76309 * (i - 384 - 16 + brightness) + 32768) >> 16;
j = (j < 0) ? 0 : ((j > 255) ? 255 : j);
@@ -2190,3 +2278,6 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
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;
@@ -2219,3 +2310,6 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
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;
@@ -2232,3 +2326,6 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
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;
@@ -2272,3 +2369,6 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
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;
@@ -2296,3 +2396,6 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
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;
@@ -2320,4 +2423,4 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
default:
- fprintf (stderr, "mode %d not supported by yuv2rgb\n", mode);
- abort();
+ lprintf ("mode %d not supported by yuv2rgb\n", mode);
+ _x_abort();
}
@@ -2333,4 +2436,6 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped
}
- 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
}
@@ -2450,4 +2555,4 @@ static void yuv2rgb_c_init (yuv2rgb_factory_t *this)
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();
}
@@ -2493,4 +2598,4 @@ static void yuv2rgb_single_pixel_init (yuv2rgb_factory_t *this) {
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();
}
@@ -2522,3 +2627,3 @@ static void yuy22rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
dy = 0;
- height = this->dest_height;
+ height = this->next_slice (this, &_dst);
@@ -2534,12 +2639,12 @@ static void yuy22rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
- 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);
@@ -2566,3 +2671,3 @@ static void yuy22rgb_c_32 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
- _p += this->y_stride*2*(dy>>15);
+ _p += this->y_stride*(dy>>15);
dy &= 32767;
@@ -2601,3 +2706,3 @@ static void yuy22rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
dy = 0;
- height = this->dest_height;
+ height = this->next_slice (this, &_dst);
@@ -2612,12 +2717,12 @@ static void yuy22rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
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);
@@ -2644,3 +2749,3 @@ static void yuy22rgb_c_24_rgb (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
- _p += this->y_stride*2*(dy>>15);
+ _p += this->y_stride*(dy>>15);
dy &= 32767;
@@ -2679,3 +2784,3 @@ static void yuy22rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
dy = 0;
- height = this->dest_height;
+ height = this->next_slice (this, &_dst);
@@ -2690,12 +2795,12 @@ static void yuy22rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
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);
@@ -2722,3 +2827,3 @@ static void yuy22rgb_c_24_bgr (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
- _p += this->y_stride*2*(dy>>15);
+ _p += this->y_stride*(dy>>15);
dy &= 32767;
@@ -2753,3 +2858,3 @@ static void yuy22rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
dy = 0;
- height = this->dest_height;
+ height = this->next_slice (this, &_dst);
@@ -2764,12 +2869,12 @@ static void yuy22rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
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);
@@ -2796,3 +2901,3 @@ static void yuy22rgb_c_16 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
- _p += this->y_stride*2*(dy>>15);
+ _p += this->y_stride*(dy>>15);
dy &= 32767;
@@ -2827,3 +2932,3 @@ static void yuy22rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
dy = 0;
- height = this->dest_height;
+ height = this->next_slice (this, &_dst);
@@ -2838,12 +2943,12 @@ static void yuy22rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
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);
@@ -2870,3 +2975,3 @@ static void yuy22rgb_c_8 (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
- _p += this->y_stride*2*(dy>>15);
+ _p += this->y_stride*(dy>>15);
dy &= 32767;
@@ -2891,3 +2996,3 @@ static void yuy22rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
dy = 0;
- height = this->dest_height;
+ height = this->next_slice (this, &_dst);
@@ -2910,3 +3015,3 @@ static void yuy22rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
- _p += this->y_stride*2*(dy>>15);
+ _p += this->y_stride*(dy>>15);
dy &= 32767;
@@ -2914,3 +3019,3 @@ static void yuy22rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
} else {
- for (height = this->source_height; --height >= 0; ) {
+ for (height = this->next_slice (this, &_dst); --height >= 0; ) {
dst = _dst;
@@ -2922,3 +3027,3 @@ static void yuy22rgb_c_gray (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
_dst += this->rgb_stride;
- _p += this->y_stride*2;
+ _p += this->y_stride;
}
@@ -2944,3 +3049,3 @@ static void yuy22rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
dy = 0;
- height = this->dest_height;
+ height = this->next_slice (this, &_dst);
@@ -2955,12 +3060,12 @@ static void yuy22rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
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);
@@ -2987,3 +3092,3 @@ static void yuy22rgb_c_palette (yuv2rgb_t *this, uint8_t * _dst, uint8_t * _p)
- _p += this->y_stride*2*(dy>>15);
+ _p += this->y_stride*(dy>>15);
dy &= 32767;
@@ -3035,3 +3140,3 @@ static void yuy22rgb_c_init (yuv2rgb_factory_t *this)
default:
- printf ("yuv2rgb: mode %d not supported for yuy2\n", this->mode);
+ lprintf ("mode %d not supported for yuy2\n", this->mode);
}
@@ -3039,3 +3144,3 @@ static void yuy22rgb_c_init (yuv2rgb_factory_t *this)
-yuv2rgb_t *yuv2rgb_create_converter (yuv2rgb_factory_t *factory) {
+static yuv2rgb_t *yuv2rgb_create_converter (yuv2rgb_factory_t *factory) {
@@ -3043,2 +3148,3 @@ yuv2rgb_t *yuv2rgb_create_converter (yuv2rgb_factory_t *factory) {
+ this->swapped = factory->swapped;
this->cmap = factory->cmap;
@@ -3049,2 +3155,8 @@ yuv2rgb_t *yuv2rgb_create_converter (yuv2rgb_factory_t *factory) {
+#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;
@@ -3053,2 +3165,3 @@ yuv2rgb_t *yuv2rgb_create_converter (yuv2rgb_factory_t *factory) {
this->table_bU = factory->table_bU;
+ this->table_mmx = factory->table_mmx;
@@ -3059,2 +3172,4 @@ yuv2rgb_t *yuv2rgb_create_converter (yuv2rgb_factory_t *factory) {
this->configure = yuv2rgb_configure;
+ this->next_slice = yuv2rgb_next_slice;
+ this->dispose = yuv2rgb_dispose;
return this;
@@ -3065,20 +3180,8 @@ yuv2rgb_t *yuv2rgb_create_converter (yuv2rgb_factory_t *factory) {
*/
-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);
}
@@ -3089,6 +3192,3 @@ yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped,
yuv2rgb_factory_t *this;
-
-#ifdef ARCH_X86
uint32_t mm = xine_mm_accel();
-#endif
@@ -3100,8 +3200,11 @@ yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped,
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);
@@ -3112,3 +3215,3 @@ yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped,
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)) {
@@ -3117,4 +3220,6 @@ yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped,
+#ifdef LOG
if (this->yuv2rgb_fun != NULL)
printf ("yuv2rgb: using MMXEXT for colorspace transform\n");
+#endif
}
@@ -3125,8 +3230,19 @@ yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped,
+#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)) {
@@ -3134,12 +3250,6 @@ yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped,
+#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" );
}
@@ -3147,3 +3257,4 @@ yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped,
if (this->yuv2rgb_fun == NULL) {
- printf ("yuv2rgb: no accelerated colorspace conversion found\n");
+ lprintf ("no accelerated colorspace conversion found\n");
+
yuv2rgb_c_init (this);
@@ -3166,2 +3277 @@ yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped,
}
-
diff --git a/noncore/multimedia/opieplayer2/yuv2rgb.h b/noncore/multimedia/opieplayer2/yuv2rgb.h
index e453243..1833889 100644
--- a/noncore/multimedia/opieplayer2/yuv2rgb.h
+++ b/noncore/multimedia/opieplayer2/yuv2rgb.h
@@ -4,2 +4,6 @@
+#ifdef HAVE_MLIB
+#include <mlib_video.h>
+#endif
+
#include <inttypes.h>
@@ -24,3 +28,2 @@ typedef uint32_t (*yuv2rgb_single_pixel_fun_t) (yuv2rgb_t *this, uint8_t y, uint
-
/*
@@ -43,3 +46,2 @@ typedef uint32_t (*yuv2rgb_single_pixel_fun_t) (yuv2rgb_t *this, uint8_t y, uint
struct yuv2rgb_s {
-
/*
@@ -54,2 +56,12 @@ struct yuv2rgb_s {
/*
+ * start a new field or frame if dest is NULL
+ */
+ int (*next_slice) (yuv2rgb_t *this, uint8_t **dest);
+
+ /*
+ * free resources
+ */
+ void (*dispose) (yuv2rgb_t *this);
+
+ /*
* this is the function to call for the yuv2rgb and scaling process
@@ -76,4 +88,5 @@ struct yuv2rgb_s {
int rgb_stride;
+ int slice_height, slice_offset;
int step_dx, step_dy;
- int do_scale;
+ int do_scale, swapped;
@@ -86,2 +99,10 @@ struct yuv2rgb_s {
+#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;
@@ -90,2 +111,3 @@ struct yuv2rgb_s {
void **table_bU;
+ void *table_mmx;
@@ -93,3 +115,2 @@ struct yuv2rgb_s {
scale_line_func_t scale_line;
-
} ;
@@ -101,3 +122,2 @@ struct yuv2rgb_s {
struct yuv2rgb_factory_s {
-
yuv2rgb_t* (*create_converter) (yuv2rgb_factory_t *this);
@@ -105,11 +125,12 @@ struct yuv2rgb_factory_s {
/*
- * adjust gamma (-100 to 100 looks fine)
+ * set color space conversion levels
* for all converters produced by this factory
*/
- void (*set_gamma) (yuv2rgb_factory_t *this, int gamma);
+ void (*set_csc_levels) (yuv2rgb_factory_t *this,
+ int brightness, int contrast, int saturation);
/*
- * get gamma value
+ * free resources
*/
- int (*get_gamma) (yuv2rgb_factory_t *this);
+ void (*dispose) (yuv2rgb_factory_t *this);
@@ -121,7 +142,5 @@ struct yuv2rgb_factory_s {
- int gamma;
- int entry_size;
-
uint32_t matrix_coefficients;
+ void *table_base;
void *table_rV[256];
@@ -130,2 +149,4 @@ struct yuv2rgb_factory_s {
void *table_bU[256];
+ void *table_mmx_base;
+ void *table_mmx;
@@ -135,3 +156,2 @@ struct yuv2rgb_factory_s {
yuv2rgb_single_pixel_fun_t yuv2rgb_single_pixel_fun;
-
};
@@ -145,3 +165,4 @@ yuv2rgb_factory_t *yuv2rgb_factory_init (int mode, int swapped, uint8_t *colorma
-void mmx_yuv2rgb_set_gamma(int gamma);
+void mmx_yuv2rgb_set_csc_levels(yuv2rgb_factory_t *this,
+ int brightness, int contrast, int saturation);
void yuv2rgb_init_mmxext (yuv2rgb_factory_t *this);
@@ -149,3 +170,2 @@ void yuv2rgb_init_mmx (yuv2rgb_factory_t *this);
void yuv2rgb_init_mlib (yuv2rgb_factory_t *this);
-void yuv2rgb_init_arm (yuv2rgb_factory_t *this);