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

version» Context lines:

pike.git/src/modules/Image/blit.c:1: - /* $Id: blit.c,v 1.16 1997/10/27 22:41:16 mirar Exp $ */ + /* $Id: blit.c,v 1.17 1997/11/06 19:25:50 mirar Exp $ */   #include "global.h"      /*   **! module Image   **! note - **! $Id: blit.c,v 1.16 1997/10/27 22:41:16 mirar Exp $ + **! $Id: blit.c,v 1.17 1997/11/06 19:25:50 mirar 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:222:   }      /*   **! method object paste(object image)   **! method object paste(object image,int x,int y)   **! Pastes a given image over the current image.   **!   **! returns the object called   **!   **! arg object image - **! image to paste + **! image to paste (may be empty, needs to be an image object)   **! arg int x   **! arg int y   **! where to paste the image; default is 0,0   **!   **! see also: paste_mask, paste_alpha, paste_alpha_color   */      void image_paste(INT32 args)   {    struct image *img;    INT32 x1,y1,x2,y2,blitwidth,blitheight;       if (args<1    || sp[-args].type!=T_OBJECT -  || !sp[-args].u.object -  || sp[-args].u.object->prog!=image_program) +  || !(img=(struct image*)get_storage(sp[-args].u.object,image_program)))    error("illegal argument 1 to image->paste()\n");    if (!THIS->img) return;    -  img=(struct image*)sp[-args].u.object->storage; -  if (!img) return; +  if (!img->img) return;    -  if (args>=3) +  if (args>1)    { -  if (sp[1-args].type!=T_INT +  if (args<3 +  || sp[1-args].type!=T_INT    || sp[2-args].type!=T_INT)    error("illegal arguments to image->paste()\n");    x1=sp[1-args].u.integer;    y1=sp[2-args].u.integer;    }    else x1=y1=0;       if(x1 >= THIS->xsize || y1 >= THIS->ysize) /* Per */    {    pop_n_elems(args);
pike.git/src/modules/Image/blit.c:313:   **! arg int x   **! arg int y   **! where to paste the image; default is 0,0   **!   **! see also: paste_mask, paste, paste_alpha_color   */      void image_paste_alpha(INT32 args)   {    struct image *img; -  INT32 x1,y1,x,y; +  INT32 x1,y1;       if (args<2    || sp[-args].type!=T_OBJECT    || !sp[-args].u.object -  || sp[-args].u.object->prog!=image_program +  || !(img=(struct image*)get_storage(sp[-args].u.object,image_program))    || sp[1-args].type!=T_INT)    error("illegal arguments to image->paste_alpha()\n");    if (!THIS->img) return; -  -  img=(struct image*)sp[-args].u.object->storage; -  if (!img) return; +  if (!img->img) return;    THIS->alpha=(unsigned char)(sp[1-args].u.integer);       if (args>=4)    {    if (sp[2-args].type!=T_INT    || sp[3-args].type!=T_INT)    error("illegal arguments to image->paste_alpha()\n");    x1=sp[2-args].u.integer;    y1=sp[3-args].u.integer;    }
pike.git/src/modules/Image/blit.c:408:    struct image *img,*mask;    INT32 x1,y1,x,y,x2,y2,smod,dmod,mmod;    rgb_group *s,*d,*m;    float q;      CHRONO("image_paste_mask init");       if (args<2)    error("illegal number of arguments to image->paste_mask()\n");    if (sp[-args].type!=T_OBJECT -  || !sp[-args].u.object -  || sp[-args].u.object->prog!=image_program) +  || !(img=(struct image*)get_storage(sp[-args].u.object,image_program)))    error("illegal argument 1 to image->paste_mask()\n");    if (sp[1-args].type!=T_OBJECT -  || !sp[1-args].u.object -  || sp[1-args].u.object->prog!=image_program) +  || !(mask=(struct image*)get_storage(sp[1-args].u.object,image_program)))    error("illegal argument 2 to image->paste_mask()\n");    if (!THIS->img) return;    -  img=(struct image*)sp[-args].u.object->storage; -  mask=(struct image*)sp[1-args].u.object->storage; -  if ((!img)||(!img->img)) error("argument 1 has no image\n"); -  if ((!mask)||(!mask->img)) error("argument 2 (alpha) has no image\n"); +  if (!mask->img) return; +  if (!img->img) return;       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;
pike.git/src/modules/Image/blit.c:514:    struct image *mask;    INT32 x1,y1,x,y,x2,y2;    rgb_group rgb,*d,*m;    INT32 mmod,dmod;    float q;       if (args!=1 && args!=4 && args!=6 && args!=3)    error("illegal number of arguments to image->paste_alpha_color()\n");    if (sp[-args].type!=T_OBJECT    || !sp[-args].u.object -  || sp[-args].u.object->prog!=image_program) +  || !(mask=(struct image*)get_storage(sp[-args].u.object,image_program)))    error("illegal argument 1 to image->paste_alpha_color()\n");    if (!THIS->img) return; -  +  if (!mask->img) return;       if (args==6 || args==4) /* colors at arg 2..4 */    getrgb(THIS,1,args,"image->paste_alpha_color()\n");    if (args==3) /* coords at 2..3 */    {    if (sp[1-args].type!=T_INT    || sp[2-args].type!=T_INT)    error("illegal coordinate arguments to image->paste_alpha_color()\n");    x1=sp[1-args].u.integer;    y1=sp[2-args].u.integer;
pike.git/src/modules/Image/blit.c:538:    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;    -  mask=(struct image*)sp[-args].u.object->storage; -  if (!mask||!mask->img) error("argument 1 (alpha) has no image\n"); -  +     x2=min(THIS->xsize-x1,mask->xsize);    y2=min(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);    mmod=mask->xsize-(x2-x);    dmod=THIS->xsize-(x2-x);
pike.git/src/modules/Image/blit.c:721:    free(layer);    error("Illegal argument(s) to image->add_layers()\n");    }    a=sp[-i].u.array;    if (a->size<2)    {    free(layer);    error("Illegal size of array argument to image->add_layers()\n");    }    -  if (a->item[0].type!=T_OBJECT -  || !a->item[0].u.object -  || a->item[0].u.object->prog!=image_program) +  if (a->item[0].type!=T_OBJECT)    {    free(layer);    error("Illegal array contents, layer %d (argument %d) (wrong or no image) to image->add_layers()\n",layers-i,args-i+1);    } -  img=(struct image*)a->item[0].u.object->storage; -  if (!img->img +  img=(struct image*)get_storage(a->item[0].u.object,image_program); +  if (!img +  || !img->img    || img->xsize != THIS->xsize    || img->ysize != THIS->ysize)    {    free(layer);    error("Illegal array contents, layer %d (argument %d) (no image or wrong image size) to image->add_layers()\n",layers-i,args-i+1);    }    layer[j].s=img->img;       if (a->item[1].type==T_INT    && a->item[1].u.integer==0)    {    layer[j].m=NULL;    }    else    { -  if (a->item[1].type!=T_OBJECT -  || !a->item[1].u.object -  || a->item[1].u.object->prog!=image_program) +  if (a->item[1].type!=T_OBJECT)    {    free(layer);    error("Illegal array contents, layer %d (argument %d) (wrong or no image for mask) to image->add_layers()\n",layers-i,args-i+1);    } -  img=(struct image*)a->item[1].u.object->storage; -  if (!img->img +  img=(struct image*)get_storage(a->item[1].u.object,image_program); +  if (!img +  || !img->img    || img->xsize != THIS->xsize    || img->ysize != THIS->ysize)    {    free(layer);    error("Illegal array contents, layer %d (argument %d) (no mask or wrong mask size) to image->add_layers()\n",layers-i,args-i+1);    }    layer[j].m=img->img;    }       if (a->size>=3)
pike.git/src/modules/Image/blit.c:791:    }    layer[j].method=a->item[3].u.integer;    }    else    layer[j].method=LAYER_NOP;    }       push_int(1+x2-x1);    push_int(1+y2-y1);    o=clone_object(image_program,2); -  d=((struct image*)(o->storage))->img; +  d=((struct image*)get_storage(o,image_program))->img;          mod=THIS->xsize-(x2-x1+1);    s+=x1+THIS->xsize*y1;    for (i=0; i<layers; i++)    {    layer[i].s+=x1+THIS->xsize*y1;    if (layer[i].m) layer[i].m+=x1+THIS->xsize*y1;    else allmask=0;    if (layer[i].opaque!=255) allopaque255=0;