pike.git / src / modules / Image / blit.c

version» Context lines:

pike.git/src/modules/Image/blit.c:1: - /* $Id: blit.c,v 1.24 1997/11/24 16:11:55 mirar Exp $ */ + /* $Id: blit.c,v 1.25 1997/12/22 23:26:43 hubbe Exp $ */   #include "global.h"      /*   **! module Image   **! note - **! $Id: blit.c,v 1.24 1997/11/24 16:11:55 mirar Exp $ + **! $Id: blit.c,v 1.25 1997/12/22 23:26:43 hubbe Exp $   **! class image   */      #include <math.h>   #include <ctype.h>      #include "stralloc.h"   #include "global.h"   #include "pike_macros.h"   #include "object.h"
pike.git/src/modules/Image/blit.c:22:   #include "error.h"   #include "threads.h"      #include "image.h"      extern struct program *image_program;   #define THIS ((struct image *)(fp->current_storage))   #define THISOBJ (fp->current_object)      #define absdiff(a,b) ((a)<(b)?((b)-(a)):((a)-(b))) - #define min(a,b) ((a)<(b)?(a):(b)) - #define max(a,b) ((a)<(b)?(b):(a)) +       #if 0   #include <sys/resource.h>   #define CHRONO(X) chrono(X)      static void chrono(char *x)   {    struct rusage r;    static struct rusage rold;    getrusage(RUSAGE_SELF,&r);
pike.git/src/modules/Image/blit.c:51:    );       rold=r;   }   #else   #define CHRONO(X)   #endif      /***************** internals ***********************************/    - #define testrange(x) max(min((x),255),0) + #define testrange(x) MAXIMUM(MINIMUM((x),255),0)      #define apply_alpha(x,y,alpha) \    ((unsigned char)((y*(255L-(alpha))+x*(alpha))/255L))      #define set_rgb_group_alpha(dest,src,alpha) \    (((dest).r=apply_alpha((dest).r,(src).r,alpha)), \    ((dest).g=apply_alpha((dest).g,(src).g,alpha)), \    ((dest).b=apply_alpha((dest).b,(src).b,alpha)))      #define pixel(_img,x,y) ((_img)->img[(x)+(y)*(_img)->xsize])
pike.git/src/modules/Image/blit.c:212:       new=malloc( (x2-x1+1)*(y2-y1+1)*sizeof(rgb_group) +1);    if (!new)    error("Out of memory.\n");       img_clear(new,THIS->rgb,(x2-x1+1)*(y2-y1+1));       dest->xsize=x2-x1+1;    dest->ysize=y2-y1+1;    -  xp=max(0,-x1); -  yp=max(0,-y1); -  xs=max(0,x1); -  ys=max(0,y1); +  xp=MAXIMUM(0,-x1); +  yp=MAXIMUM(0,-y1); +  xs=MAXIMUM(0,x1); +  ys=MAXIMUM(0,y1);       if (x1<0) x1=0; else if (x1>=img->xsize) x1=img->xsize-1;    if (y1<0) y1=0; else if (y1>=img->ysize) y1=img->ysize-1;    if (x2<0) x2=0; else if (x2>=img->xsize) x2=img->xsize-1;    if (y2<0) y2=0; else if (y2>=img->ysize) y2=img->ysize-1;       img_blit(new+xp+yp*dest->xsize,    img->img+xs+(img->xsize)*ys,    x2-x1+1,    y2-y1+1,
pike.git/src/modules/Image/blit.c:302:    x2=x1+img->xsize-1;    y2=y1+img->ysize-1;       if(x2 < 0 || y2 < 0) /* Per */    {    pop_n_elems(args);    THISOBJ->refs++;    push_object(THISOBJ);    return;    } -  blitwidth=min(x2,THIS->xsize-1)-max(x1,0)+1; -  blitheight=min(y2,THIS->ysize-1)-max(y1,0)+1; +  blitwidth=MINIMUM(x2,THIS->xsize-1)-MAXIMUM(x1,0)+1; +  blitheight=MINIMUM(y2,THIS->ysize-1)-MAXIMUM(y1,0)+1;    -  img_blit(THIS->img+max(0,x1)+(THIS->xsize)*max(0,y1), -  img->img+max(0,-x1)+(x2-x1+1)*max(0,-y1), +  img_blit(THIS->img+MAXIMUM(0,x1)+(THIS->xsize)*MAXIMUM(0,y1), +  img->img+MAXIMUM(0,-x1)+(x2-x1+1)*MAXIMUM(0,-y1),    blitwidth,    blitheight,    THIS->xsize,    img->xsize);       pop_n_elems(args);    THISOBJ->refs++;    push_object(THISOBJ);   }   
pike.git/src/modules/Image/blit.c:456:    if (args>=4)    {    if (sp[2-args].type!=T_INT    || sp[3-args].type!=T_INT)    error("illegal coordinate arguments to image->paste_mask()\n");    x1=sp[2-args].u.integer;    y1=sp[3-args].u.integer;    }    else x1=y1=0;    -  x2=min(THIS->xsize-x1,min(img->xsize,mask->xsize)); -  y2=min(THIS->ysize-y1,min(img->ysize,mask->ysize)); +  x2=MINIMUM(THIS->xsize-x1,MINIMUM(img->xsize,mask->xsize)); +  y2=MINIMUM(THIS->ysize-y1,MINIMUM(img->ysize,mask->ysize));      CHRONO("image_paste_mask begin");    -  s=img->img+max(0,-x1)+max(0,-y1)*img->xsize; -  m=mask->img+max(0,-x1)+max(0,-y1)*mask->xsize; -  d=THIS->img+max(0,-x1)+x1+(y1+max(0,-y1))*THIS->xsize; -  x=max(0,-x1); +  s=img->img+MAXIMUM(0,-x1)+MAXIMUM(0,-y1)*img->xsize; +  m=mask->img+MAXIMUM(0,-x1)+MAXIMUM(0,-y1)*mask->xsize; +  d=THIS->img+MAXIMUM(0,-x1)+x1+(y1+MAXIMUM(0,-y1))*THIS->xsize; +  x=MAXIMUM(0,-x1);    smod=img->xsize-(x2-x);    mmod=mask->xsize-(x2-x);    dmod=THIS->xsize-(x2-x);       q=1.0/255;       THREADS_ALLOW(); -  for (y=max(0,-y1); y<y2; y++) +  for (y=MAXIMUM(0,-y1); y<y2; y++)    { -  for (x=max(0,-x1); x<x2; x++) +  for (x=MAXIMUM(0,-x1); x<x2; x++)    {    if (m->r==255) d->r=s->r;    else if (m->r==0) {}    else d->r=(unsigned char)(((d->r*(255-m->r))+(s->r*m->r))*q);    if (m->g==255) d->g=s->g;    else if (m->g==0) {}    else d->g=(unsigned char)(((d->g*(255-m->g))+(s->g*m->g))*q);    if (m->b==255) d->b=s->b;    else if (m->b==0) {}    else d->b=(unsigned char)(((d->b*(255-m->b))+(s->b*m->b))*q);
pike.git/src/modules/Image/blit.c:563:    else if (args==6) /* at 5..6 */    {    if (sp[4-args].type!=T_INT    || sp[5-args].type!=T_INT)    error("illegal coordinate arguments to image->paste_alpha_color()\n");    x1=sp[4-args].u.integer;    y1=sp[5-args].u.integer;    }    else x1=y1=0;    -  x2=min(THIS->xsize-x1,mask->xsize); -  y2=min(THIS->ysize-y1,mask->ysize); +  x2=MINIMUM(THIS->xsize-x1,mask->xsize); +  y2=MINIMUM(THIS->ysize-y1,mask->ysize);      CHRONO("image_paste_alpha_color begin");    -  m=mask->img+max(0,-x1)+max(0,-y1)*mask->xsize; -  d=THIS->img+max(0,-x1)+x1+(y1+max(0,-y1))*THIS->xsize; -  x=max(0,-x1); +  m=mask->img+MAXIMUM(0,-x1)+MAXIMUM(0,-y1)*mask->xsize; +  d=THIS->img+MAXIMUM(0,-x1)+x1+(y1+MAXIMUM(0,-y1))*THIS->xsize; +  x=MAXIMUM(0,-x1);    mmod=mask->xsize-(x2-x);    dmod=THIS->xsize-(x2-x);       q=1.0/255;       rgb=THIS->rgb;       THREADS_ALLOW(); -  for (y=max(0,-y1); y<y2; y++) +  for (y=MAXIMUM(0,-y1); y<y2; y++)    { -  for (x=max(0,-x1); x<x2; x++) +  for (x=MAXIMUM(0,-x1); x<x2; x++)    {    if (m->r==255) d->r=rgb.r;    else if (m->r==0) ;    else d->r=(unsigned char)(((d->r*(255-m->r))+(rgb.r*m->r))*q);    if (m->g==255) d->g=rgb.g;    else if (m->g==0) ;    else d->g=(unsigned char)(((d->g*(255-m->g))+(rgb.g*m->g))*q);    if (m->b==255) d->b=rgb.b;    else if (m->b==0) ;    else d->b=(unsigned char)(((d->b*(255-m->b))+(rgb.b*m->b))*q);
pike.git/src/modules/Image/blit.c:613:      void img_box(INT32 x1,INT32 y1,INT32 x2,INT32 y2)   {    if (x1>x2) x1^=x2,x2^=x1,x1^=x2;    if (y1>y2) y1^=y2,y2^=y1,y1^=y2;    if (x2 >= THIS->xsize) x2 = THIS->xsize-1;    if (y2 >= THIS->ysize) y2 = THIS->ysize-1;    if (x2<0||y2<0||x1>=THIS->xsize||y1>=THIS->ysize) return;    if (x1<0) x1 = 0;    if (y1<0) y1 = 0; -  img_box_nocheck(max(x1,0),max(y1,0),min(x2,THIS->xsize-1),min(y2,THIS->ysize-1)); +  img_box_nocheck(MAXIMUM(x1,0),MAXIMUM(y1,0),MINIMUM(x2,THIS->xsize-1),MINIMUM(y2,THIS->ysize-1));   }         /*   **! method object add_layers(array(int|object)) layer0,...)   **! method object add_layers(int x1,int y1,int x2,int y2,array(int|object)) layer0,...)   **! Using the called object as base, adds layers using masks,   **! opaque channel values and special methods.   **!   **! The destination image can also be cropped, thus