[Sumover-dev] [svn commit] r4344 - vic/branches/mpeg4/render

sumover-dev at cs.ucl.ac.uk sumover-dev at cs.ucl.ac.uk
Tue Jan 13 02:43:00 GMT 2009


Author: douglask
Date: Tue Jan 13 02:42:55 2009
New Revision: 4344

Modified:
   vic/branches/mpeg4/render/color-swscale.cpp

Log:
Add support for YUV422P in swscaler renderer

Minor whitespace consistency fixes


Modified: vic/branches/mpeg4/render/color-swscale.cpp
==============================================================================
--- vic/branches/mpeg4/render/color-swscale.cpp	(original)
+++ vic/branches/mpeg4/render/color-swscale.cpp	Tue Jan 13 02:42:55 2009
@@ -19,20 +19,20 @@
 class X11WindowRenderer : public WindowDitherer {
 public:
 	X11WindowRenderer(VideoWindow* vw, int decimation, int depth_) :
-	WindowDitherer(vw, decimation) { 
+	WindowDitherer(vw, decimation) {
 	i_width = i_height = o_width = o_height = -1;
 	sws_context = NULL;
-	  
+
 	  // 15, 16, 24, or 32 bits
 	  switch (depth_) {
 	    case 15:
 	    case 16:
 		// printf("16\n");
 	        //out_format = PIX_FMT_RGB565;
-		out_format = PIX_FMT_BGR565;
-	        bytes_per_pixel	= 2;
-	    	break;
-	    	
+	        out_format = PIX_FMT_BGR565;
+	        bytes_per_pixel = 2;
+	        break;
+
 	    case 24:
 		//	printf("24\n");
 		out_format = PIX_FMT_RGB24;
@@ -41,34 +41,38 @@
 	    case 32:
 			// printf("32\n");
 	        out_format = PIX_FMT_RGB32;
-	        bytes_per_pixel	= 4;
-  	  }
+	        bytes_per_pixel = 4;
+	  }
 	}
 
-	~X11WindowRenderer() { 
+	~X11WindowRenderer() {
 	  if(sws_context) sws_freeContext(sws_context);
 	}
-	
+
 	inline bool resized(){
 	  return (i_width != width_ || i_height != height_ || o_width != outw_ || o_height != outh_);
 	}
-	
+
 	void render(const u_char* frm, int off, int x, int w, int h) {
-				
+
 	  if(enable_xv){
-	    memcpy(pixbuf_, frm, framesize_*3/2);	  
-	  }else{ 
-	    if(!outw_ || !outh_	|| !width_ || !height_)
+	      if (decimation_ == 422) {
+		memcpy(pixbuf_, frm, framesize_*2);
+	      } else {
+		memcpy(pixbuf_, frm, framesize_*3/2);
+	      }
+	  }else{
+	    if(!outw_ || !outh_ || !width_ || !height_)
 	        return;
 
 	    if(resized()){
 	      if(sws_context){
-	        sws_freeContext(sws_context);	
-			sws_context = NULL;
+	        sws_freeContext(sws_context);
+	        sws_context = NULL;
 	      }
 	      int flags = SWS_FAST_BILINEAR;
 
-#ifdef RUNTIME_CPUDETECT	    
+#ifdef RUNTIME_CPUDETECT
 	      flags |= (available_cpu_flags & FF_CPU_MMX ? SWS_CPU_CAPS_MMX : 0);
 	      flags |= (available_cpu_flags & FF_CPU_MMXEXT ? SWS_CPU_CAPS_MMX2 : 0);
 	      flags |= (available_cpu_flags & FF_CPU_3DNOW ? SWS_CPU_CAPS_3DNOW : 0);
@@ -77,7 +81,7 @@
 		  flags |= SWS_CPU_CAPS_MMX;
 	#if defined(HAVE_MMX2)
 		  flags |= SWS_CPU_CAPS_MMX2;
-	#endif 
+	#endif
 #elif defined(HAVE_3DNOW)
 		  flags |= SWS_CPU_CAPS_3DNOW;
 #elif defined(HAVE_ALTIVEC)
@@ -85,28 +89,33 @@
 #endif
 
 	      if(!outw_ || !outh_ || !width_ || !height_) return;
+	      int in_format = PIX_FMT_YUV420P;
+	      if (decimation_ == 422) {
+	        in_format = PIX_FMT_YUV422P;
+	      }
+
+	      // Accelerated Colour conversion routines
+	      sws_context = sws_getContext(width_, height_, in_format,
+	             outw_, outh_, out_format, flags, NULL, NULL, NULL);
 
-		  // Accelerated Colour conversion routines
-	      sws_context = sws_getContext(width_, height_, PIX_FMT_YUV420P,
-	             outw_, outh_, out_format, flags, NULL, NULL, NULL); 	   
 	      // printf("X11WindowRenderer: %dx%d ==> %dx%d\n", width_, height_, outw_, outh_);
-	      
+
 	      if(sws_context == NULL){
-	          debug_msg("X11WindowRenderer: error! cannot allocate memory for swscontext!\n");
+		  debug_msg("X11WindowRenderer: error! cannot allocate memory for swscontext!\n");
 		  return;
 	      }
-		      
-			    
+
+
 	      sws_src_stride[0] = width_;
 	      sws_src_stride[1] = sws_src_stride[2] = width_/2;
-	    
-  	      sws_tar[0] = pixbuf_;
-  	      sws_tar[1] = sws_tar[2] = NULL;
-  	      sws_tar_stride[0] = outw_*bytes_per_pixel;
-  	      sws_tar_stride[1] = sws_tar_stride[2] = 0;	  	      
+
+	      sws_tar[0] = pixbuf_;
+	      sws_tar[1] = sws_tar[2] = NULL;
+	      sws_tar_stride[0] = outw_*bytes_per_pixel;
+	      sws_tar_stride[1] = sws_tar_stride[2] = 0;
         }
 
-	    i_width = width_; i_height = height_; o_width = outw_; o_height = outh_;	  		 	
+	    i_width = width_; i_height = height_; o_width = outw_; o_height = outh_;
 	    sws_src[0] = (uint8_t*)frm;
 	    sws_src[1] = sws_src[0] + framesize_;
 	    sws_src[2] = sws_src[1] + framesize_/4;
@@ -116,7 +125,7 @@
 #else
      	sws_scale_ordered(sws_context, sws_src, sws_src_stride, 0, height_, sws_tar, sws_tar_stride);
 #endif
-	  }	
+	  }
 	}
 protected:
 	virtual void update() { }
@@ -126,24 +135,24 @@
 	int i_width, i_height, o_width, o_height;
 	SwsContext *sws_context;
 	uint8_t *sws_src[3];
-  	uint8_t *sws_tar[3];
-  	int sws_src_stride[3];
-  	int sws_tar_stride[3];	
-  	int out_format;
-  	int bytes_per_pixel;
+	uint8_t *sws_tar[3];
+	int sws_src_stride[3];
+	int sws_tar_stride[3];
+	int out_format;
+	int bytes_per_pixel;
 };
 
 
 class X11ColorModel : public TclObject {
 public:
 	virtual int command(int argc, const char*const* argv){
-	  Tcl& tcl = Tcl::instance();	
-	  
+	  Tcl& tcl = Tcl::instance();
+
 	  if (argc == 4 && strcmp(argv[1], "renderer") == 0) {
 
 		VideoWindow* vw = VideoWindow::lookup(argv[2]);
 		int decimation = atoi(argv[3]);
-		
+
 		Renderer* r = new X11WindowRenderer(vw, decimation, vw->bpp());
 		tcl.result(r->name());
 		return (TCL_OK);
@@ -164,7 +173,7 @@
 			tcl.result("1");
 			return (TCL_OK);
 		}
-	}	  
+	}
 	  return (TclObject::command(argc, argv));
 	}
 };
@@ -179,11 +188,11 @@
 		     strcasecmp(id, "truecolor/24") == 0 ||
 		     strcasecmp(id, "truecolor/32") == 0 ){
 			return (new X11ColorModel());
-		}		
+		}
 		return (0);
 	}
 } matcher_x11;
 
-					       
+
 
 #endif // HAVE_SWSCALE



More information about the Sumover-dev mailing list