From 719282fe335029c45c43a324098226f42b8cc453 Mon Sep 17 00:00:00 2001
From: Per Hedbor <ph@opera.com>
Date: Sun, 23 Nov 1997 07:03:49 +0100
Subject: [PATCH] optimized img_box

Rev: src/modules/Image/blit.c:1.20
Rev: src/modules/Image/image.c:1.66
---
 src/modules/Image/blit.c  | 45 ++++++++++++++++++++++++---------------
 src/modules/Image/image.c | 20 ++++++++---------
 2 files changed, 38 insertions(+), 27 deletions(-)

diff --git a/src/modules/Image/blit.c b/src/modules/Image/blit.c
index c414aa3621..0f859188c4 100644
--- a/src/modules/Image/blit.c
+++ b/src/modules/Image/blit.c
@@ -1,10 +1,10 @@
-/* $Id: blit.c,v 1.19 1997/11/23 05:28:27 per Exp $ */
+/* $Id: blit.c,v 1.20 1997/11/23 06:03:48 per Exp $ */
 #include "global.h"
 
 /*
 **! module Image
 **! note
-**!	$Id: blit.c,v 1.19 1997/11/23 05:28:27 per Exp $
+**!	$Id: blit.c,v 1.20 1997/11/23 06:03:48 per Exp $
 **! class image
 */
 
@@ -133,19 +133,27 @@ void img_box_nocheck(INT32 x1,INT32 y1,INT32 x2,INT32 y2)
    struct image *this;
 
    this=THIS;
-   
-   THREADS_ALLOW();
+   rgb=this->rgb;
    mod=this->xsize-(x2-x1)-1;
    foo=this->img+x1+y1*this->xsize;
    end=this->img+x1+y2*this->xsize;
-   rgb=this->rgb;
 
-
-   if (!this->alpha)
-      for (; foo<=end; foo+=mod) for (x=x1; x<=x2; x++) *(foo++)=rgb;
-   else
-      for (; foo<=end; foo+=mod) for (x=x1; x<=x2; x++,foo++) 
-	 set_rgb_group_alpha(*foo,rgb,this->alpha);
+   THREADS_ALLOW();
+   if(!this->alpha)
+   {
+     if(!mod)
+       img_clear(foo,rgb,end-foo);
+     else {
+       int length = x2-x1+1, xs=this->xsize, y=y2-y1+1;
+       rgb_group *from = foo;
+       if(!length) return;
+       for(x=0; x<length; x++)  *(foo+x) = rgb;
+       while(--y)  MEMCPY((foo+=xs), from, length*sizeof(rgb_group)); 
+     }
+   } else {
+     for (; foo<=end; foo+=mod) for (x=x1; x<=x2; x++,foo++) 
+       set_rgb_group_alpha(*foo,rgb,this->alpha);
+   }
    THREADS_DISALLOW();
 }
 
@@ -158,12 +166,15 @@ void img_blit(rgb_group *dest,rgb_group *src,INT32 width,
 CHRONO("image_blit begin");
 
    THREADS_ALLOW();
-   while (lines--)
-   {
-      MEMCPY(dest,src,sizeof(rgb_group)*width);
-      dest+=moddest;
-      src+=modsrc;
-   }
+   if(!moddest && !modsrc)
+     MEMCPY(dest,src,sizeof(rgb_group*width*lines));
+   else
+     while (lines--)
+     {
+       MEMCPY(dest,src,sizeof(rgb_group)*width);
+       dest+=moddest;
+       src+=modsrc;
+     }
    THREADS_DISALLOW();
 CHRONO("image_blit end");
 
diff --git a/src/modules/Image/image.c b/src/modules/Image/image.c
index 2b4454f8a7..ed9d38d7fd 100644
--- a/src/modules/Image/image.c
+++ b/src/modules/Image/image.c
@@ -1,9 +1,9 @@
-/* $Id: image.c,v 1.65 1997/11/23 05:28:28 per Exp $ */
+/* $Id: image.c,v 1.66 1997/11/23 06:03:49 per Exp $ */
 
 /*
 **! module Image
 **! note
-**!	$Id: image.c,v 1.65 1997/11/23 05:28:28 per Exp $
+**!	$Id: image.c,v 1.66 1997/11/23 06:03:49 per Exp $
 **! class image
 **!
 **!	The main object of the <ref>Image</ref> module, this object
@@ -82,7 +82,7 @@
 
 #include "stralloc.h"
 #include "global.h"
-RCSID("$Id: image.c,v 1.65 1997/11/23 05:28:28 per Exp $");
+RCSID("$Id: image.c,v 1.66 1997/11/23 06:03:49 per Exp $");
 #include "pike_macros.h"
 #include "object.h"
 #include "constants.h"
@@ -722,7 +722,7 @@ static void image_change_color(INT32 args)
    d=img->img;
    while (left--)
    {
-      if (s->r==from.r && s->g==from.g && s->b==from.b)
+      if (color_equal(*s,from))
          *d=to;
       else
          *d=*s;
@@ -1519,9 +1519,9 @@ void image_color(INT32 args)
    THREADS_ALLOW();
    while (x--)
    {
-      d->r=testrange( (((long)rgb.r*s->r)/255) );
-      d->g=testrange( (((long)rgb.g*s->g)/255) );
-      d->b=testrange( (((long)rgb.b*s->b)/255) );
+      d->r=( (((long)rgb.r*s->r)/255) );
+      d->g=( (((long)rgb.g*s->g)/255) );
+      d->b=( (((long)rgb.b*s->b)/255) );
       d++;
       s++;
    }
@@ -1574,9 +1574,9 @@ void image_invert(INT32 args)
    THREADS_ALLOW();
    while (x--)
    {
-      d->r=testrange( 255-s->r );
-      d->g=testrange( 255-s->g );
-      d->b=testrange( 255-s->b );
+      d->r=( 255-s->r );
+      d->g=( 255-s->g );
+      d->b=( 255-s->b );
       d++;
       s++;
    }
-- 
GitLab