[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13311] trunk/blender/source/blender/imbuf /intern: == Sequencer / FFMPEG ==

Peter Schlaile peter at schlaile.de
Sun Jan 20 19:55:56 CET 2008


Revision: 13311
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13311
Author:   schlaile
Date:     2008-01-20 19:55:56 +0100 (Sun, 20 Jan 2008)

Log Message:
-----------
== Sequencer / FFMPEG ==

This fixes:

[#7989] Sequence editor preview and anim render output broken on Linux PPC

and also optimizes RGBA -> ABGR conversion function a little bit.
(Fixing also a crash, if there is no ibuf->rect available...)

Modified Paths:
--------------
    trunk/blender/source/blender/imbuf/intern/anim.c
    trunk/blender/source/blender/imbuf/intern/imageprocess.c

Modified: trunk/blender/source/blender/imbuf/intern/anim.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/anim.c	2008-01-20 17:53:58 UTC (rev 13310)
+++ trunk/blender/source/blender/imbuf/intern/anim.c	2008-01-20 18:55:56 UTC (rev 13311)
@@ -594,7 +594,7 @@
 	anim->pFrame = avcodec_alloc_frame();
 	anim->pFrameRGB = avcodec_alloc_frame();
 
-	if (avpicture_get_size(PIX_FMT_RGBA32, anim->x, anim->y)
+	if (avpicture_get_size(PIX_FMT_BGR32, anim->x, anim->y)
 	    != anim->x * anim->y * 4) {
 		fprintf (stderr,
 			 "ffmpeg has changed alloc scheme ... ARGHHH!\n");
@@ -617,7 +617,7 @@
 		anim->pCodecCtx->pix_fmt,
 		anim->pCodecCtx->width,
 		anim->pCodecCtx->height,
-		PIX_FMT_RGBA,
+		PIX_FMT_BGR32,
 		SWS_FAST_BILINEAR | SWS_PRINT_INFO,
 		NULL, NULL, NULL);
 				
@@ -637,7 +637,7 @@
 
 	avpicture_fill((AVPicture *)anim->pFrameRGB, 
 		       (unsigned char*) ibuf->rect, 
-		       PIX_FMT_RGBA32, anim->x, anim->y);
+		       PIX_FMT_BGR32, anim->x, anim->y);
 
 	if (position != anim->curposition + 1) { 
 		if (position > anim->curposition + 1 
@@ -714,34 +714,98 @@
 			} 
 
 			if(frameFinished && pos_found == 1) {
-				int * dstStride = anim->pFrameRGB->linesize;
-				uint8_t** dst = anim->pFrameRGB->data;
-				int dstStride2[4]= { -dstStride[0], 0, 0, 0 };
-				uint8_t* dst2[4]= {
-					dst[0] + (anim->y - 1)*dstStride[0],
-					0, 0, 0 };
-				int i;
-				unsigned char* r;
+				if (G.order == B_ENDIAN) {
+					int * dstStride 
+						= anim->pFrameRGB->linesize;
+					uint8_t** dst = anim->pFrameRGB->data;
+					int dstStride2[4]
+						= { dstStride[0], 0, 0, 0 };
+					uint8_t* dst2[4]= {
+						dst[0],	0, 0, 0 };
+					int x,y,h,w;
+					unsigned char* bottom;
+					unsigned char* top;
 
-				sws_scale(anim->img_convert_ctx,
-					  anim->pFrame->data,
-					  anim->pFrame->linesize,
-					  0,
-					  anim->pCodecCtx->height,
-					  dst2,
-					  dstStride2);
+					sws_scale(anim->img_convert_ctx,
+						  anim->pFrame->data,
+						  anim->pFrame->linesize,
+						  0,
+						  anim->pCodecCtx->height,
+						  dst2,
+						  dstStride2);
 				
-				/* workaround: sws_scale sets alpha = 0... */
+					/* workaround: sws_scale 
+					   sets alpha = 0 and compensate
+					   for altivec-bugs and flipy... */
 				
-				r = (unsigned char*) ibuf->rect;
+					bottom = (unsigned char*) ibuf->rect;
+					top = bottom 
+						+ ibuf->x * (ibuf->y-1) * 4;
 
-				for (i = 0; i < ibuf->x * ibuf->y; i++) {
-					r[3] = 0xff;
-					r+=4;
+					h = (ibuf->y + 1) / 2;
+					w = ibuf->x;
+
+					for (y = 0; y < h; y++) {
+						unsigned char tmp[4];
+						unsigned long * tmp_l =
+							(unsigned long*) tmp;
+						tmp[3] = 0xff;
+
+						for (x = 0; x < w; x++) {
+							tmp[0] = bottom[3];
+							tmp[1] = bottom[2];
+							tmp[2] = bottom[1];
+
+							bottom[0] = top[3];
+							bottom[1] = top[2];
+							bottom[2] = top[1];
+							bottom[3] = 0xff;
+								
+							*(unsigned long*) top
+								= *tmp_l;
+
+							bottom +=4;
+							top += 4;
+						}
+						top -= 8 * w;
+					}
+
+					av_free_packet(&packet);
+					break;
+				} else {
+					int * dstStride 
+						= anim->pFrameRGB->linesize;
+					uint8_t** dst = anim->pFrameRGB->data;
+					int dstStride2[4]
+						= { -dstStride[0], 0, 0, 0 };
+					uint8_t* dst2[4]= {
+						dst[0] 
+						+ (anim->y - 1)*dstStride[0],
+						0, 0, 0 };
+					int i;
+					unsigned char* r;
+
+					sws_scale(anim->img_convert_ctx,
+						  anim->pFrame->data,
+						  anim->pFrame->linesize,
+						  0,
+						  anim->pCodecCtx->height,
+						  dst2,
+						  dstStride2);
+				
+					/* workaround: sws_scale 
+					   sets alpha = 0... */
+				
+					r = (unsigned char*) ibuf->rect;
+
+					for (i = 0; i < ibuf->x * ibuf->y;i++){
+						r[3] = 0xff;
+						r+=4;
+					}
+
+					av_free_packet(&packet);
+					break;
 				}
-
-				av_free_packet(&packet);
-				break;
 			}
 		}
 

Modified: trunk/blender/source/blender/imbuf/intern/imageprocess.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/imageprocess.c	2008-01-20 17:53:58 UTC (rev 13310)
+++ trunk/blender/source/blender/imbuf/intern/imageprocess.c	2008-01-20 18:55:56 UTC (rev 13311)
@@ -51,22 +51,28 @@
 /* Only this one is used liberally here, and in imbuf */
 void IMB_convert_rgba_to_abgr(struct ImBuf *ibuf)
 {
-	int size, do_float=0;
+	int size;
 	unsigned char rt, *cp = (unsigned char *)ibuf->rect;
 	float rtf, *cpf = ibuf->rect_float;
-	
-	if (ibuf->rect_float)  do_float = 1;
-	size = ibuf->x * ibuf->y;
 
-	while(size-- > 0) {
-		rt= cp[0];
-		cp[0]= cp[3];
-		cp[3]= rt;
-		rt= cp[1];
-		cp[1]= cp[2];
-		cp[2]= rt;
-		cp+= 4;
-		if (do_float) {
+	if (ibuf->rect) {
+		size = ibuf->x * ibuf->y;
+
+		while(size-- > 0) {
+			rt= cp[0];
+			cp[0]= cp[3];
+			cp[3]= rt;
+			rt= cp[1];
+			cp[1]= cp[2];
+			cp[2]= rt;
+			cp+= 4;
+		}
+	}
+
+	if (ibuf->rect_float) {
+		size = ibuf->x * ibuf->y;
+
+		while(size-- > 0) {
 			rtf= cpf[0];
 			cpf[0]= cpf[3];
 			cpf[3]= rtf;





More information about the Bf-blender-cvs mailing list