changeset 7960:050d235f40b6 libavcodec

Merge (vp3|theora)_calculate_pixel_addresses
author conrad
date Tue, 30 Sep 2008 19:50:43 +0000
parents 16b5311fd5c7
children ef0616549c16
files vp3.c
diffstat 1 files changed, 6 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/vp3.c	Tue Sep 30 19:22:20 2008 +0000
+++ b/vp3.c	Tue Sep 30 19:50:43 2008 +0000
@@ -1617,13 +1617,16 @@
  */
 static void vp3_calculate_pixel_addresses(Vp3DecodeContext *s)
 {
+#define Y_INITIAL(chroma_shift)  s->flipped_image ? 1  : s->fragment_height >> chroma_shift
+#define Y_FINISHED(chroma_shift) s->flipped_image ? y <= s->fragment_height >> chroma_shift : y > 0
 
     int i, x, y;
+    const int y_inc = s->flipped_image ? 1 : -1;
 
     /* figure out the first pixel addresses for each of the fragments */
     /* Y plane */
     i = 0;
-    for (y = s->fragment_height; y > 0; y--) {
+    for (y = Y_INITIAL(0); Y_FINISHED(0); y += y_inc) {
         for (x = 0; x < s->fragment_width; x++) {
             s->all_fragments[i++].first_pixel =
                 s->golden_frame.linesize[0] * y * FRAGMENT_PIXELS -
@@ -1634,7 +1637,7 @@
 
     /* U plane */
     i = s->fragment_start[1];
-    for (y = s->fragment_height / 2; y > 0; y--) {
+    for (y = Y_INITIAL(1); Y_FINISHED(1); y += y_inc) {
         for (x = 0; x < s->fragment_width / 2; x++) {
             s->all_fragments[i++].first_pixel =
                 s->golden_frame.linesize[1] * y * FRAGMENT_PIXELS -
@@ -1645,48 +1648,7 @@
 
     /* V plane */
     i = s->fragment_start[2];
-    for (y = s->fragment_height / 2; y > 0; y--) {
-        for (x = 0; x < s->fragment_width / 2; x++) {
-            s->all_fragments[i++].first_pixel =
-                s->golden_frame.linesize[2] * y * FRAGMENT_PIXELS -
-                    s->golden_frame.linesize[2] +
-                    x * FRAGMENT_PIXELS;
-        }
-    }
-}
-
-/* FIXME: this should be merged with the above! */
-static void theora_calculate_pixel_addresses(Vp3DecodeContext *s)
-{
-
-    int i, x, y;
-
-    /* figure out the first pixel addresses for each of the fragments */
-    /* Y plane */
-    i = 0;
-    for (y = 1; y <= s->fragment_height; y++) {
-        for (x = 0; x < s->fragment_width; x++) {
-            s->all_fragments[i++].first_pixel =
-                s->golden_frame.linesize[0] * y * FRAGMENT_PIXELS -
-                    s->golden_frame.linesize[0] +
-                    x * FRAGMENT_PIXELS;
-        }
-    }
-
-    /* U plane */
-    i = s->fragment_start[1];
-    for (y = 1; y <= s->fragment_height / 2; y++) {
-        for (x = 0; x < s->fragment_width / 2; x++) {
-            s->all_fragments[i++].first_pixel =
-                s->golden_frame.linesize[1] * y * FRAGMENT_PIXELS -
-                    s->golden_frame.linesize[1] +
-                    x * FRAGMENT_PIXELS;
-        }
-    }
-
-    /* V plane */
-    i = s->fragment_start[2];
-    for (y = 1; y <= s->fragment_height / 2; y++) {
+    for (y = Y_INITIAL(1); Y_FINISHED(1); y += y_inc) {
         for (x = 0; x < s->fragment_width / 2; x++) {
             s->all_fragments[i++].first_pixel =
                 s->golden_frame.linesize[2] * y * FRAGMENT_PIXELS -
@@ -1958,10 +1920,7 @@
         /* time to figure out pixel addresses? */
         if (!s->pixel_addresses_initialized)
         {
-            if (!s->flipped_image)
                 vp3_calculate_pixel_addresses(s);
-            else
-                theora_calculate_pixel_addresses(s);
             s->pixel_addresses_initialized = 1;
         }
     } else {