gfx/ycbcr/picture_region.patch
author ffxbld
Fri, 01 Oct 2010 19:06:11 -0700
branchGECKO20b7pre_20100929_RELBRANCH
changeset 54886 75deb7fd10124b1f452c736142a6b3e01b8738bb
parent 40462 f9a11b9b2b9fd4d081708217fac56e29ec23e8db
permissions -rw-r--r--
Added tag FENNEC_4_0b1_RELEASE for changeset 4791cfde3ca0. CLOSED TREE

diff --git a/gfx/ycbcr/yuv_convert.cpp b/gfx/ycbcr/yuv_convert.cpp
index c291d5c..ff7267e 100644
--- a/gfx/ycbcr/yuv_convert.cpp
+++ b/gfx/ycbcr/yuv_convert.cpp
@@ -25,42 +25,58 @@ namespace mozilla {
 
 namespace gfx {
 
 // Convert a frame of YUV to 32 bit ARGB.
 void ConvertYCbCrToRGB32(const uint8* y_buf,
                          const uint8* u_buf,
                          const uint8* v_buf,
                          uint8* rgb_buf,
-                         int width,
-                         int height,
+                         int pic_x,
+                         int pic_y,
+                         int pic_width,
+                         int pic_height,
                          int y_pitch,
                          int uv_pitch,
                          int rgb_pitch,
                          YUVType yuv_type) {
   unsigned int y_shift = yuv_type;
   bool has_mmx = supports_mmx();
-  for (int y = 0; y < height; ++y) {
-    uint8* rgb_row = rgb_buf + y * rgb_pitch;
-    const uint8* y_ptr = y_buf + y * y_pitch;
-    const uint8* u_ptr = u_buf + (y >> y_shift) * uv_pitch;
-    const uint8* v_ptr = v_buf + (y >> y_shift) * uv_pitch;
+  bool odd_pic_x = pic_x % 2 != 0;
+  int x_width = odd_pic_x ? pic_width - 1 : pic_width;
+
+  for (int y = pic_y; y < pic_height + pic_y; ++y) {
+    uint8* rgb_row = rgb_buf + (y - pic_y) * rgb_pitch;
+    const uint8* y_ptr = y_buf + y * y_pitch + pic_x;
+    const uint8* u_ptr = u_buf + (y >> y_shift) * uv_pitch + (pic_x >> 1);
+    const uint8* v_ptr = v_buf + (y >> y_shift) * uv_pitch + (pic_x >> 1);
+
+    if (odd_pic_x) {
+      // Handle the single odd pixel manually and use the
+      // fast routines for the remaining.
+      FastConvertYUVToRGB32Row_C(y_ptr++,
+                                 u_ptr++,
+                                 v_ptr++,
+                                 rgb_row,
+                                 1);
+      rgb_row += 4;
+    }
 
     if (has_mmx)
       FastConvertYUVToRGB32Row(y_ptr,
                                u_ptr,
                                v_ptr,
                                rgb_row,
-                               width);
+                               x_width);
     else
       FastConvertYUVToRGB32Row_C(y_ptr,
                                  u_ptr,
                                  v_ptr,
                                  rgb_row,
-                                 width);
+                                 x_width);
   }
 
   // MMX used for FastConvertYUVToRGB32Row requires emms instruction.
   if (has_mmx)
     EMMS();
 }
 
 // Scale a frame of YUV to 32 bit ARGB.
diff --git a/gfx/ycbcr/yuv_convert.h b/gfx/ycbcr/yuv_convert.h
index 9d148a6..77ca8e6 100644
--- a/gfx/ycbcr/yuv_convert.h
+++ b/gfx/ycbcr/yuv_convert.h
@@ -32,18 +32,20 @@ enum Rotate {
 };
 
 // Convert a frame of YUV to 32 bit ARGB.
 // Pass in YV16/YV12 depending on source format
 void ConvertYCbCrToRGB32(const uint8* yplane,
                          const uint8* uplane,
                          const uint8* vplane,
                          uint8* rgbframe,
-                         int frame_width,
-                         int frame_height,
+                         int pic_x,
+                         int pic_y,
+                         int pic_width,
+                         int pic_height,
                          int ystride,
                          int uvstride,
                          int rgbstride,
                          YUVType yuv_type);
 
 // Scale a frame of YUV to 32 bit ARGB.
 // Supports rotation and mirroring.
 void ScaleYCbCrToRGB32(const uint8* yplane,