[MPlayer-dev-eng] [PATCH] vo_gif89a improvements

Joey Parrish joey at nicewarrior.org
Wed Mar 5 15:59:53 CET 2003


On Wed, Mar 05, 2003 at 11:02:48AM +0100, Michael Niedermayer wrote:
> Hi
> 
> it seems the amount of unapplied patches is steeply increasing :(
> IMHO we should do something against that, ... like applying them ;)

I agree. :) Here's my latest improvements to vo_gif89a that didn't get
applied.  This patch adds support for frame duplication, without which
some movies will lose the correct framerate in gif output.  It also
removes yuv2rgb calls and implements slice support for RGB24.  This
makes gif output faster and simplifies the code.

> perhaps a karma point system would help
> so developers who apply a patch get 1 point
> dev. who flame loose 1 point
> dev. who flame because of a applied patch even though they didnt say a word 
> like "dont apply because ..." before should loose 5 points
> this could be extended to include the amount of fixed bugs too ...

I like this concept, by the way.

> sadly this is very likely not possible as counting flames automatically is 
> tricky, but applied patches / bugfixes could be counted relatvely easiely 
> after we have some patch-tracker (roundup)

Will roundup be up and working soon?
I would really like to start using it.

Thanks,
--Joey
-------------- next part --------------
--- 0_90.cvs/libvo/vo_gif89a.c	Mon Dec 30 16:24:20 2002
+++ 0_90.dev/libvo/vo_gif89a.c	Sun Feb 23 12:31:46 2003
@@ -58,7 +58,7 @@
 #include "../postproc/rgb2rgb.h"
 
 #define MPLAYER_VERSION 0.90
-#define VO_GIF_REVISION 4
+#define VO_GIF_REVISION 6
 
 static vo_info_t info = {
 	"animated GIF output",
@@ -95,8 +95,6 @@
 static uint32_t img_height;
 // image data for slice rendering
 static uint8_t *slice_data = NULL;
-// pointer for whole frame rendering
-static uint8_t *frame_data = NULL;
 // reduced image data for flip_page
 static uint8_t *reduce_data = NULL;
 // reduced color map for flip_page
@@ -198,21 +196,11 @@
 	// movies concatenated in one gif file.  the output
 	// gif will have the dimensions of the first movie.
 	
-	switch (format) {
-		case IMGFMT_RGB24: break;     
-		case IMGFMT_YV12:
-			yuv2rgb_init(24, MODE_BGR);
-			slice_data = malloc(img_width * img_height * 3);
-			if (slice_data == NULL) {
-				printf("GIF89a: malloc failed.\n");
-				return 1;
-			}
-			break;
-		default:
-			printf("GIF89a: Error - given unsupported colorspace.\n");
-			return 1;     
+	if (format != IMGFMT_RGB24) {
+		printf("GIF89a: Error - given unsupported colorspace.\n");
+		return 1;
 	}
-
+	
 	// the EGifSetGifVersion line causes segfaults in certain
 	// earlier versions of libungif.  i don't know exactly which,
 	// but certainly in all those before v4.  if you have problems,
@@ -230,6 +218,12 @@
 		return 1;
 	}
 
+	slice_data = malloc(img_width * img_height * 3);
+	if (slice_data == NULL) {
+		printf("GIF89a: malloc failed.\n");
+		return 1;
+	}
+
 	reduce_data = malloc(img_width * img_height);
 	if (reduce_data == NULL) {
 		printf("GIF89a: malloc failed.\n");
@@ -295,24 +289,13 @@
 	char CB[4]; // control block
 	int delay = 0;
 	int ret;
-	uint8_t *img_data;
 
 	cycle_pos++;
 	if (cycle_pos < frame_cycle - frame_adj)
 		return; // we are skipping this frame
 
-	// slice_data is used for per slice rendering,
-	// and frame_data is used for per frame rendering.
-	// i seperated these two because slice_data is
-	// ram i allocate, and frame_data is not.
-	// using one pointer for both can lead to
-	// either segfault (freeing ram that i'm not supposed
-	// to) or memory leaks (not freeing any ram at all)
-	if (slice_data != NULL) img_data = slice_data;
-	else img_data = frame_data;
-	
 	// quantize the image
-	ret = gif_reduce(img_width, img_height, img_data, reduce_data, reduce_cmap->Colors);
+	ret = gif_reduce(img_width, img_height, slice_data, reduce_data, reduce_cmap->Colors);
 	if (ret == GIF_ERROR) {
 		printf("GIF89a: Quantize failed.\n");
 		return;
@@ -342,26 +325,27 @@
 
 static uint32_t draw_frame(uint8_t *src[])
 {
-	frame_data = src[0];
-	return 0;
+	return 1;
 }
 
 static uint32_t draw_slice(uint8_t *src[], int stride[], int w, int h, int x, int y)
 {
-	uint8_t *dst;
+	uint8_t *dst, *frm;
+	int i;
 	dst = slice_data + (img_width * y + x) * 3;
-	yuv2rgb(dst, src[0], src[1], src[2], w, h, img_width * 3, stride[0], stride[1]);
+	frm = src[0];
+	for (i = 0; i < h; i++) {
+		memcpy(dst, frm, w * 3);
+		dst += (img_width * 3);
+		frm += stride[0];
+	}
 	return 0;
 }
 
 static uint32_t query_format(uint32_t format)
 {
-	switch (format) {
-		case IMGFMT_YV12:
-			return VFCAP_CSP_SUPPORTED | VFCAP_TIMER | VFCAP_ACCEPT_STRIDE;
-		case IMGFMT_RGB24:
-			return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_TIMER;
-	}
+	if (format == IMGFMT_RGB24)
+		return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_TIMER | VFCAP_ACCEPT_STRIDE;
 	return 0;
 }
 
@@ -369,6 +369,10 @@
 {
	if (request == VOCTRL_QUERY_FORMAT) {
		return query_format(*((uint32_t*)data));
+	}
+	if (request == VOCTRL_DUPLICATE_FRAME) {
+		flip_page();
+		return VO_TRUE;
	}
	return VO_NOTIMPL;
 }
@@ -397,7 +385,6 @@
 	// set the pointers back to null.
 	new_gif = NULL;
 	gif_filename = NULL;
-	frame_data = NULL;
 	slice_data = NULL;
 	reduce_data = NULL;
 	reduce_cmap = NULL;


More information about the MPlayer-dev-eng mailing list