[PATCH] Optimization to reduce fetching calls in scaled up or =

Antoine Azar cairo at antoineazar.com
Wed Apr 23 18:33:48 PDT 2008


bilinear cases=0A=
=0A=
---=0A=
 pixman/pixman-transformed.c |  160 =
+++++++++++++++++++++++++++++++++----------=0A=
 1 files changed, 123 insertions(+), 37 deletions(-)=0A=
=0A=
diff --git a/pixman/pixman-transformed.c b/pixman/pixman-transformed.c=0A=
index f8c5ed5..ab70b6a 100644=0A=
--- a/pixman/pixman-transformed.c=0A=
+++ b/pixman/pixman-transformed.c=0A=
@@ -82,6 +82,8 @@ fbFetchTransformed_Nearest_Normal(bits_image_t * pict, =
int width, uint32_t *buff=0A=
     fetchPixelProc32   fetch;=0A=
     pixman_bool_t one_box;=0A=
     int x, y, i;=0A=
+    int oldX =3D -2147483648;=0A=
+    int oldY =3D oldX;=0A=
 =0A=
     /* initialize the two function pointers */=0A=
     fetch =3D ACCESS(pixman_fetchPixelProcForPicture32)(pict);=0A=
@@ -109,7 +111,16 @@ fbFetchTransformed_Nearest_Normal(bits_image_t * =
pict, int width, uint32_t *buff=0A=
                     x =3D MOD(v.vector[0]>>16, pict->width);=0A=
                 }=0A=
 =0A=
-                *(buffer + i) =3D fetch_general(pict, x, y, fetch, box);=0A=
+                if(x !=3D oldX || y !=3D oldY)=0A=
+                {=0A=
+                    oldX =3D x;=0A=
+                    oldY =3D y;=0A=
+                    *(buffer + i) =3D fetch_general(pict, x, y, fetch, =
one_box);=0A=
+                }=0A=
+                else=0A=
+                {=0A=
+                    *(buffer + i) =3D *(buffer + i - 1);=0A=
+                }=0A=
             }=0A=
         }=0A=
 =0A=
@@ -125,6 +136,8 @@ fbFetchTransformed_Nearest_Pad(bits_image_t * pict, =
int width, uint32_t *buffer,=0A=
     pixman_bool_t one_box;=0A=
     fetchPixelProc32   fetch;=0A=
     int x, y, i;=0A=
+    int oldX =3D -2147483648;=0A=
+    int oldY =3D oldX;=0A=
 =0A=
     /* initialize the two function pointers */=0A=
     fetch =3D ACCESS(pixman_fetchPixelProcForPicture32)(pict);=0A=
@@ -152,8 +165,17 @@ fbFetchTransformed_Nearest_Pad(bits_image_t * pict, =
int width, uint32_t *buffer,=0A=
                     x =3D CLIP(v.vector[0]>>16, 0, pict->width-1);=0A=
                 }=0A=
 =0A=
+                if(x !=3D oldX || y !=3D oldY)=0A=
+                {=0A=
+                    oldX =3D x;=0A=
+                    oldY =3D y;=0A=
                 *(buffer + i) =3D fetch_general(pict, x, y, fetch, =
one_box);=0A=
             }=0A=
+                else=0A=
+                {=0A=
+                    *(buffer + i) =3D *(buffer + i - 1);=0A=
+                }=0A=
+            }=0A=
         }=0A=
 =0A=
         v.vector[0] +=3D unit.vector[0];=0A=
@@ -168,6 +190,8 @@ fbFetchTransformed_Nearest_General(bits_image_t * =
pict, int width, uint32_t *buf=0A=
     fetchPixelProc32   fetch;=0A=
     pixman_box32_t *box;=0A=
     int x, y, i;=0A=
+    int oldX =3D -2147483648;=0A=
+    int oldY =3D oldX;=0A=
 =0A=
     /* initialize the two function pointers */=0A=
     fetch =3D ACCESS(pixman_fetchPixelProcForPicture32)(pict);=0A=
@@ -191,8 +215,17 @@ fbFetchTransformed_Nearest_General(bits_image_t * =
pict, int width, uint32_t *buf=0A=
                     x =3D v.vector[0]>>16;=0A=
                 }=0A=
 =0A=
+                if(x !=3D oldX || y !=3D oldY)=0A=
+                {=0A=
+                    oldX =3D x;=0A=
+                    oldY =3D y;=0A=
                 *(buffer + i) =3D fetch_from_box (pict, x, y, fetch, =
box);=0A=
             }=0A=
+                else=0A=
+                {=0A=
+                    *(buffer + i) =3D *(buffer + i - 1);=0A=
+                }=0A=
+            }=0A=
         }=0A=
         v.vector[0] +=3D unit.vector[0];=0A=
         v.vector[1] +=3D unit.vector[1];=0A=
@@ -206,7 +239,11 @@ fbFetchTransformed_Bilinear_Normal(bits_image_t * =
pict, int width, uint32_t *buf=0A=
     pixman_bool_t one_box;=0A=
     pixman_box32_t *box;=0A=
     fetchPixelProc32   fetch;=0A=
-    int i;=0A=
+    int i, j;=0A=
+    int oldX1 =3D INT32_MIN;=0A=
+    int oldY1 =3D oldX1;=0A=
+    uint32_t tl, tr, bl, br, r;=0A=
+    uint16_t tlVec[4], trVec[4], blVec[4], brVec[4];=0A=
 =0A=
     /* initialize the two function pointers */=0A=
     fetch =3D ACCESS(pixman_fetchPixelProcForPicture32)(pict);=0A=
@@ -220,7 +257,6 @@ fbFetchTransformed_Bilinear_Normal(bits_image_t * =
pict, int width, uint32_t *buf=0A=
                 *(buffer + i) =3D 0;=0A=
             } else {=0A=
                 int x1, x2, y1, y2, distx, idistx, disty, idisty;=0A=
-                uint32_t tl, tr, bl, br, r;=0A=
                 uint32_t ft, fb;=0A=
 =0A=
                 if (!affine) {=0A=
@@ -237,12 +273,18 @@ fbFetchTransformed_Bilinear_Normal(bits_image_t * =
pict, int width, uint32_t *buf=0A=
                     y1 =3D v.vector[1] >> 16;=0A=
                     disty =3D (v.vector[1] >> 8) & 0xff;=0A=
                 }=0A=
-                x2 =3D x1 + 1;=0A=
-                y2 =3D y1 + 1;=0A=
 =0A=
                 idistx =3D 256 - distx;=0A=
                 idisty =3D 256 - disty;=0A=
 =0A=
+                if(x1 !=3D oldX1 || y1 !=3D oldY1)=0A=
+                {=0A=
+                    oldX1 =3D x1;=0A=
+                    oldY1 =3D y1;=0A=
+=0A=
+                    x2 =3D x1 + 1;=0A=
+                    y2 =3D y1 + 1;=0A=
+=0A=
                 x1 =3D MOD (x1, pict->width);=0A=
                 x2 =3D MOD (x2, pict->width);=0A=
                 y1 =3D MOD (y1, pict->height);=0A=
@@ -253,19 +295,29 @@ fbFetchTransformed_Bilinear_Normal(bits_image_t * =
pict, int width, uint32_t *buf=0A=
                 bl =3D fetch_general(pict, x1, y2, fetch, one_box);=0A=
                 br =3D fetch_general(pict, x2, y2, fetch, one_box);=0A=
 =0A=
-                ft =3D FbGet8(tl,0) * idistx + FbGet8(tr,0) * distx;=0A=
-                fb =3D FbGet8(bl,0) * idistx + FbGet8(br,0) * distx;=0A=
+                    for(j =3D 0; j < 4; j++)=0A=
+                    {=0A=
+                        tlVec[j] =3D FbGet8(tl,j*8);=0A=
+                        trVec[j] =3D FbGet8(tr,j*8);=0A=
+                        blVec[j] =3D FbGet8(bl,j*8);=0A=
+                        brVec[j] =3D FbGet8(br,j*8);=0A=
+                    }=0A=
+                }=0A=
+=0A=
+                ft =3D tlVec[0] * idistx + trVec[0] * distx;=0A=
+                fb =3D blVec[0] * idistx + brVec[0] * distx;=0A=
                 r =3D (((ft * idisty + fb * disty) >> 16) & 0xff);=0A=
-                ft =3D FbGet8(tl,8) * idistx + FbGet8(tr,8) * distx;=0A=
-                fb =3D FbGet8(bl,8) * idistx + FbGet8(br,8) * distx;=0A=
+                ft =3D tlVec[1] * idistx + trVec[1] * distx;=0A=
+                fb =3D blVec[1] * idistx + brVec[1] * distx;=0A=
                 r |=3D (((ft * idisty + fb * disty) >> 8) & 0xff00);=0A=
-                ft =3D FbGet8(tl,16) * idistx + FbGet8(tr,16) * distx;=0A=
-                fb =3D FbGet8(bl,16) * idistx + FbGet8(br,16) * distx;=0A=
+                ft =3D tlVec[2] * idistx + trVec[2] * distx;=0A=
+                fb =3D blVec[2] * idistx + brVec[2] * distx;=0A=
                 r |=3D (((ft * idisty + fb * disty)) & 0xff0000);=0A=
-                ft =3D FbGet8(tl,24) * idistx + FbGet8(tr,24) * distx;=0A=
-                fb =3D FbGet8(bl,24) * idistx + FbGet8(br,24) * distx;=0A=
+                ft =3D tlVec[3] * idistx + trVec[3] * distx;=0A=
+                fb =3D blVec[3] * idistx + brVec[3] * distx;=0A=
                 r |=3D (((ft * idisty + fb * disty) << 8) & 0xff000000);=0A=
                 *(buffer + i) =3D r;=0A=
+=0A=
             }=0A=
         }=0A=
         v.vector[0] +=3D unit.vector[0];=0A=
@@ -280,7 +332,11 @@ fbFetchTransformed_Bilinear_Pad(bits_image_t * =
pict, int width, uint32_t *buffer=0A=
     pixman_bool_t one_box;=0A=
     pixman_box32_t *box =3D NULL;=0A=
     fetchPixelProc32   fetch;=0A=
-    int i;=0A=
+    int i, j;=0A=
+    int oldX1 =3D INT32_MIN;=0A=
+    int oldY1 =3D oldX1;=0A=
+    uint32_t tl, tr, bl, br, r;=0A=
+    uint16_t tlVec[4], trVec[4], blVec[4], brVec[4];=0A=
 =0A=
     /* initialize the two function pointers */=0A=
     fetch =3D ACCESS(pixman_fetchPixelProcForPicture32)(pict);=0A=
@@ -294,7 +350,6 @@ fbFetchTransformed_Bilinear_Pad(bits_image_t * pict, =
int width, uint32_t *buffer=0A=
                 *(buffer + i) =3D 0;=0A=
             } else {=0A=
                 int x1, x2, y1, y2, distx, idistx, disty, idisty;=0A=
-                uint32_t tl, tr, bl, br, r;=0A=
                 uint32_t ft, fb;=0A=
 =0A=
                 if (!affine) {=0A=
@@ -311,12 +366,15 @@ fbFetchTransformed_Bilinear_Pad(bits_image_t * =
pict, int width, uint32_t *buffer=0A=
                     y1 =3D v.vector[1] >> 16;=0A=
                     disty =3D (v.vector[1] >> 8) & 0xff;=0A=
                 }=0A=
-                x2 =3D x1 + 1;=0A=
-                y2 =3D y1 + 1;=0A=
 =0A=
                 idistx =3D 256 - distx;=0A=
                 idisty =3D 256 - disty;=0A=
 =0A=
+                if(x1 !=3D oldX1 || y1 !=3D oldY1)=0A=
+                {=0A=
+                    x2 =3D x1 + 1;=0A=
+                    y2 =3D y1 + 1;=0A=
+=0A=
                 x1 =3D CLIP (x1, 0, pict->width-1);=0A=
                 x2 =3D CLIP (x2, 0, pict->width-1);=0A=
                 y1 =3D CLIP (y1, 0, pict->height-1);=0A=
@@ -327,17 +385,26 @@ fbFetchTransformed_Bilinear_Pad(bits_image_t * =
pict, int width, uint32_t *buffer=0A=
                 bl =3D fetch_general(pict, x1, y2, fetch, one_box);=0A=
                 br =3D fetch_general(pict, x2, y2, fetch, one_box);=0A=
 =0A=
-                ft =3D FbGet8(tl,0) * idistx + FbGet8(tr,0) * distx;=0A=
-                fb =3D FbGet8(bl,0) * idistx + FbGet8(br,0) * distx;=0A=
+                    for(j =3D 0; j < 4; j++)=0A=
+                    {=0A=
+                        tlVec[j] =3D FbGet8(tl,j*8);=0A=
+                        trVec[j] =3D FbGet8(tr,j*8);=0A=
+                        blVec[j] =3D FbGet8(bl,j*8);=0A=
+                        brVec[j] =3D FbGet8(br,j*8);=0A=
+                    }=0A=
+                }=0A=
+=0A=
+                ft =3D tlVec[0] * idistx + trVec[0] * distx;=0A=
+                fb =3D blVec[0] * idistx + brVec[0] * distx;=0A=
                 r =3D (((ft * idisty + fb * disty) >> 16) & 0xff);=0A=
-                ft =3D FbGet8(tl,8) * idistx + FbGet8(tr,8) * distx;=0A=
-                fb =3D FbGet8(bl,8) * idistx + FbGet8(br,8) * distx;=0A=
+                ft =3D tlVec[1] * idistx + trVec[1] * distx;=0A=
+                fb =3D blVec[1] * idistx + brVec[1] * distx;=0A=
                 r |=3D (((ft * idisty + fb * disty) >> 8) & 0xff00);=0A=
-                ft =3D FbGet8(tl,16) * idistx + FbGet8(tr,16) * distx;=0A=
-                fb =3D FbGet8(bl,16) * idistx + FbGet8(br,16) * distx;=0A=
+                ft =3D tlVec[2] * idistx + trVec[2] * distx;=0A=
+                fb =3D blVec[2] * idistx + brVec[2] * distx;=0A=
                 r |=3D (((ft * idisty + fb * disty)) & 0xff0000);=0A=
-                ft =3D FbGet8(tl,24) * idistx + FbGet8(tr,24) * distx;=0A=
-                fb =3D FbGet8(bl,24) * idistx + FbGet8(br,24) * distx;=0A=
+                ft =3D tlVec[3] * idistx + trVec[3] * distx;=0A=
+                fb =3D blVec[3] * idistx + brVec[3] * distx;=0A=
                 r |=3D (((ft * idisty + fb * disty) << 8) & 0xff000000);=0A=
                 *(buffer + i) =3D r;=0A=
             }=0A=
@@ -353,7 +420,11 @@ fbFetchTransformed_Bilinear_General(bits_image_t * =
pict, int width, uint32_t *bu=0A=
 {=0A=
     pixman_box32_t *box =3D NULL;=0A=
     fetchPixelProc32   fetch;=0A=
-    int i;=0A=
+    int i, j;=0A=
+    int oldX1 =3D INT32_MIN;=0A=
+    int oldY1 =3D oldX1;=0A=
+    uint32_t tl, tr, bl, br, r;=0A=
+    uint16_t tlVec[4], trVec[4], blVec[4], brVec[4];=0A=
 =0A=
     /* initialize the two function pointers */=0A=
     fetch =3D ACCESS(pixman_fetchPixelProcForPicture32)(pict);=0A=
@@ -371,7 +442,6 @@ fbFetchTransformed_Bilinear_General(bits_image_t * =
pict, int width, uint32_t *bu=0A=
                 *(buffer + i) =3D 0;=0A=
             } else {=0A=
                 int x1, x2, y1, y2, distx, idistx, disty, idisty;=0A=
-                uint32_t tl, tr, bl, br, r;=0A=
                 uint32_t ft, fb;=0A=
 =0A=
                 if (!affine) {=0A=
@@ -388,28 +458,44 @@ fbFetchTransformed_Bilinear_General(bits_image_t * =
pict, int width, uint32_t *bu=0A=
                     y1 =3D v.vector[1] >> 16;=0A=
                     disty =3D (v.vector[1] >> 8) & 0xff;=0A=
                 }=0A=
-                x2 =3D x1 + 1;=0A=
-                y2 =3D y1 + 1;=0A=
 =0A=
                 idistx =3D 256 - distx;=0A=
                 idisty =3D 256 - disty;=0A=
 =0A=
+                if(x1 !=3D oldX1 || y1 !=3D oldY1)=0A=
+                {=0A=
+                    oldX1 =3D x1;=0A=
+                    oldY1 =3D y1;=0A=
+=0A=
+                    x2 =3D x1 + 1;=0A=
+                    y2 =3D y1 + 1;=0A=
+=0A=
                 tl =3D fetch_from_box(pict, x1, y1, fetch, box);=0A=
                 tr =3D fetch_from_box(pict, x2, y1, fetch, box);=0A=
                 bl =3D fetch_from_box(pict, x1, y2, fetch, box);=0A=
                 br =3D fetch_from_box(pict, x2, y2, fetch, box);=0A=
 =0A=
-                ft =3D FbGet8(tl,0) * idistx + FbGet8(tr,0) * distx;=0A=
-                fb =3D FbGet8(bl,0) * idistx + FbGet8(br,0) * distx;=0A=
+                    for(j =3D 0; j < 4; j++)=0A=
+                    {=0A=
+                        tlVec[j] =3D FbGet8(tl,j*8);=0A=
+                        trVec[j] =3D FbGet8(tr,j*8);=0A=
+                        blVec[j] =3D FbGet8(bl,j*8);=0A=
+                        brVec[j] =3D FbGet8(br,j*8);=0A=
+                    }=0A=
+=0A=
+                }=0A=
+=0A=
+                ft =3D tlVec[0] * idistx + trVec[0] * distx;=0A=
+                fb =3D blVec[0] * idistx + brVec[0] * distx;=0A=
                 r =3D (((ft * idisty + fb * disty) >> 16) & 0xff);=0A=
-                ft =3D FbGet8(tl,8) * idistx + FbGet8(tr,8) * distx;=0A=
-                fb =3D FbGet8(bl,8) * idistx + FbGet8(br,8) * distx;=0A=
+                ft =3D tlVec[1] * idistx + trVec[1] * distx;=0A=
+                fb =3D blVec[1] * idistx + brVec[1] * distx;=0A=
                 r |=3D (((ft * idisty + fb * disty) >> 8) & 0xff00);=0A=
-                ft =3D FbGet8(tl,16) * idistx + FbGet8(tr,16) * distx;=0A=
-                fb =3D FbGet8(bl,16) * idistx + FbGet8(br,16) * distx;=0A=
+                ft =3D tlVec[2] * idistx + trVec[2] * distx;=0A=
+                fb =3D blVec[2] * idistx + brVec[2] * distx;=0A=
                 r |=3D (((ft * idisty + fb * disty)) & 0xff0000);=0A=
-                ft =3D FbGet8(tl,24) * idistx + FbGet8(tr,24) * distx;=0A=
-                fb =3D FbGet8(bl,24) * idistx + FbGet8(br,24) * distx;=0A=
+                ft =3D tlVec[3] * idistx + trVec[3] * distx;=0A=
+                fb =3D blVec[3] * idistx + brVec[3] * distx;=0A=
                 r |=3D (((ft * idisty + fb * disty) << 8) & 0xff000000);=0A=
                 *(buffer + i) =3D r;=0A=
             }=0A=
-- =0A=
1.5.5.1015.g9d258=0A=
=0A=

------=_NextPart_000_07AC_01C93F90.EE46FD00--



More information about the cairo mailing list