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

version» Context lines:

pike.git/src/modules/Image/layers.c:1:   /*   **! module Image   **! note - **! $Id: layers.c,v 1.30 1999/07/26 11:27:23 mirar Exp $ + **! $Id: layers.c,v 1.31 1999/08/09 14:46:41 mirar Exp $   **! class Layer   **! see also: layers   **!      **!   **!   **! <add_appendix name="layers" title="Image.Layer modes"><execute>   **! import Image;   **!   **! void write_image(string desc,
pike.git/src/modules/Image/layers.c:188:   **! }   **!   **! </execute>   **! </add_appendix>   */      #include "global.h"      #include <math.h> /* floor */    - RCSID("$Id: layers.c,v 1.30 1999/07/26 11:27:23 mirar Exp $"); + RCSID("$Id: layers.c,v 1.31 1999/08/09 14:46:41 mirar Exp $");      #include "image_machine.h"      #include "stralloc.h"   #include "pike_macros.h"   #include "object.h"   #include "constants.h"   #include "interpret.h"   #include "svalue.h"   #include "array.h"
pike.git/src/modules/Image/layers.c:257:    rgb_group fill; /* fill color ("outside" the layer) */    rgb_group fill_alpha; /* fill alpha */       rgb_group sfill[SNUMPIXS]; /* pre-calculated rows */    rgb_group sfill_alpha[SNUMPIXS];       int tiled; /* true if tiled */       lm_row_func *row_func;/* layer mode */    int optimize_alpha; +  int really_optimize_alpha;   };      #undef THIS   #define THIS ((struct layer *)(fp->current_storage))   #define THISOBJ (fp->current_object)      #define LMFUNC(X) \    static void X(rgb_group *s,rgb_group *l,rgb_group *d, \    rgb_group *sa,rgb_group *la,rgb_group *da, \    int len,double alpha)
pike.git/src/modules/Image/layers.c:624:    default: fatal("unhandled case\n");    }   #undef V   #undef i   #undef f   #undef p   #undef q   #undef t   }    + /*** helper ***********************************************/ +  + static int really_optimize_p(struct layer *l) + { +  return +  l->optimize_alpha && +  l->fill_alpha.r==0 && +  l->fill_alpha.g==0 && +  l->fill_alpha.b==0 && +  !l->tiled; + } +  +  +    /*** layer object : init and exit *************************/      static void init_layer(struct object *dummy)   {    THIS->xsize=0;    THIS->ysize=0;    THIS->xoffs=0;    THIS->yoffs=0;    THIS->image=NULL;    THIS->alpha=NULL;    THIS->img=NULL;    THIS->alp=NULL;    THIS->fill=black;    THIS->fill_alpha=black;    THIS->tiled=0;    THIS->alpha_value=1.0;    THIS->row_func=lm_normal;    THIS->optimize_alpha=1; -  +  THIS->really_optimize_alpha=1;       smear_color(THIS->sfill,THIS->fill,SNUMPIXS);    smear_color(THIS->sfill_alpha,THIS->fill_alpha,SNUMPIXS);   }      static void free_layer(struct layer *l)   {    if (THIS->image) free_object(THIS->image);    if (THIS->alpha) free_object(THIS->alpha);    THIS->image=NULL;
pike.git/src/modules/Image/layers.c:848:    if (args!=1)    SIMPLE_TOO_FEW_ARGS_ERROR("Image.Layer->set_mode",1);    if (sp[-args].type!=T_STRING)    SIMPLE_BAD_ARG_ERROR("Image.Layer->set_mode",1,"string");       for (i=0; i<LAYER_MODES; i++)    if (sp[-args].u.string==layer_mode[i].ps)    {    THIS->row_func=layer_mode[i].func;    THIS->optimize_alpha=layer_mode[i].optimize_alpha; +  THIS->really_optimize_alpha=really_optimize_p(THIS); +     pop_n_elems(args);    ref_push_object(THISOBJ);    return;    }       SIMPLE_BAD_ARG_ERROR("Image.Layer->set_mode",1,"existing mode");   }      static void image_layer_mode(INT32 args)   {
pike.git/src/modules/Image/layers.c:929: Inside #if 0
   int i;    for (i=0; i<SNUMPIXS; i++)    fprintf(stderr,"#%02x%02x%02x ",THIS->sfill_alpha[i].r,THIS->sfill_alpha[i].g,THIS->sfill_alpha[i].b);    fprintf(stderr,"\n");    for (i=0; i<SNUMPIXS; i++)    fprintf("stderr,#%02x%02x%02x ",THIS->sfill[i].r,THIS->sfill[i].g,THIS->sfill[i].b);    fprintf(stderr,"\n");    }   #endif    +  THIS->really_optimize_alpha=really_optimize_p(THIS); +     pop_n_elems(args);    ref_push_object(THISOBJ);   }      static void image_layer_fill(INT32 args)   {    pop_n_elems(args);    _image_make_rgb_color(THIS->fill.r,THIS->fill.g,THIS->fill.b);   }   
pike.git/src/modules/Image/layers.c:1004:   **! Set/query <i>tiled</i> flag. If set, the   **! image and alpha channel will be tiled rather   **! then framed by the <ref>fill</ref> values.   */      static void image_layer_set_tiled(INT32 args)   {    get_all_args("Image.Layer->set_offset",args,"%i",    &(THIS->tiled));    THIS->tiled=!!THIS->tiled; +  THIS->really_optimize_alpha=really_optimize_p(THIS);    pop_n_elems(args);    ref_push_object(THISOBJ);   }      static void image_layer_tiled(INT32 args)   {    pop_n_elems(args);    push_int(THIS->tiled);   }   
pike.git/src/modules/Image/layers.c:2008:    rgb_group *d,    rgb_group *da,    int len)   {    if (l)    {    (ly->row_func)(s,l,d,sa,la,da,len,ly->alpha_value);    return;    }    -  if (!la && -  ly->fill_alpha.r==0 && -  ly->fill_alpha.g==0 && -  ly->fill_alpha.b==0 && -  ly->optimize_alpha) +  if (!la && ly->really_optimize_alpha)    { -  + /* fprintf(stderr,"fast skip ly->yoffs=%d\n",ly->yoffs); */    MEMCPY(d,s,len*sizeof(rgb_group));    MEMCPY(da,sa,len*sizeof(rgb_group));    return;    }       if (!la &&    ly->fill_alpha.r==COLORMAX &&    ly->fill_alpha.g==COLORMAX &&    ly->fill_alpha.b==COLORMAX)    {
pike.git/src/modules/Image/layers.c:2154:    if (xsize)    img_lay_stroke(ly,l,la,s,sa,d,da,xsize);    }   }         void img_lay(struct layer **layer,    int layers,    struct layer *dest)   { -  rgb_group *line1,*line2,*aline1,*aline2,*tmp; +  rgb_group *line1,*line2,*aline1,*aline2;    rgb_group *d,*da;    int width=dest->xsize;    int y,z;    int xoffs=dest->xoffs,xsize=dest->xsize;       line1=malloc(sizeof(rgb_group)*width);    line2=malloc(sizeof(rgb_group)*width);    aline1=malloc(sizeof(rgb_group)*width);    aline2=malloc(sizeof(rgb_group)*width);    if (!line1 || !line2 || !aline1 || !aline2)
pike.git/src/modules/Image/layers.c:2201:    }    else    {    smear_color(line1,black,xsize);    smear_color(aline1,black,xsize);    z=0;    }       /* loop over the rest of the layers, except the last */    for (; z<layers-1; z++) +  if (!layer[z]->really_optimize_alpha || +  (layer[z]->yoffs<=y+dest->yoffs && +  y+dest->yoffs<layer[z]->yoffs+layer[z]->ysize))    { -  +  rgb_group *tmp; +  + /* if (!layer[z]->really_optimize_alpha) */ + /* fprintf(stderr,"huh %d\n",z); */ + /* if (!(layer[z]->yoffs>=y+dest->yoffs && */ + /* y+dest->yoffs<layer[z]->yoffs+layer[z]->ysize)) */ + /* fprintf(stderr,"hmm %d %d<=%d<%d\n", */ + /* z, */ + /* layer[z]->yoffs, */ + /* y+dest->yoffs, */ + /* layer[z]->yoffs+layer[z]->ysize); */ +     img_lay_line(layer[z],line1,aline1, -  xoffs,xsize,y-layer[z]->yoffs,line2,aline2); +  xoffs,xsize, +  y+dest->yoffs-layer[z]->yoffs, +  line2,aline2);    /* swap buffers */    tmp=line1; line1=line2; line2=tmp;    tmp=aline1; aline1=aline2; aline2=tmp;    } -  + /* else */ + /* fprintf(stderr,"skip %d\n",z); */       /* make the last layer on the destionation */    img_lay_line(layer[layers-1],line1,aline1,    xoffs,xsize,y+dest->yoffs-layer[layers-1]->yoffs,d,da);    }    else    {    /* make the layer to destination*/    img_lay_first_line(layer[0],xoffs,xsize,    y+dest->yoffs-layer[0]->yoffs,d,da);
pike.git/src/modules/Image/layers.c:2379:    if (l->image) add_ref(l->image);    if (l->alpha) add_ref(l->alpha);    l->alpha_value=THIS->alpha_value;    l->fill=THIS->fill;    l->fill_alpha=THIS->fill_alpha;    MEMCPY(l->sfill,THIS->sfill,sizeof(rgb_group)*SNUMPIXS);    MEMCPY(l->sfill_alpha,THIS->sfill_alpha,sizeof(rgb_group)*SNUMPIXS);    l->tiled=THIS->tiled;    l->row_func=THIS->row_func;    l->optimize_alpha=THIS->optimize_alpha; +  l->really_optimize_alpha=THIS->really_optimize_alpha;    return l;   }      /*   **! module Image   **! class Layer   **! method object crop(int xoff,int yoff,int xsize,int ysize)   **! Crops this layer at this offset and size.   **! Offset is not relative the layer offset, so this   **! can be used to crop a number of layers simuntaneously.