[MPlayer-dev-eng] [PATCH] remove yuv2rgb from vo_gif, add rgb slice support

Joey Parrish joey at nicewarrior.org
Sun Feb 23 19:44:26 CET 2003


Hello,

Attached below is a patch to remove the calls to yuv2rgb from vo_gif89a.
It also adds support for rgb slices.  My only worry is under what
conditions mplayer will use draw_frame.  If there is only one supported
csp, and that csp has draw_slice support and ACCEPT_STRIDE set, will
draw_frame ever be used?  I assume it will never be called, so it is not
used after this patch is applied.  I did this to keep things as simple
as possible.  Is this okay?

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;
 }
 
@@ -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