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.43 2000/02/22 03:41:27 per Exp $ + **! $Id: layers.c,v 1.44 2000/07/07 00:40:19 hubbe Exp $   **! class Layer   **! see also: layers   **!      **!   **!   **! <add_appendix name="layers" title="Image.Layer modes">   **! <dl compact>   **! <dt><i>The variables in the expression:</i>   **! <dt>L<dd><i>The active layer</i>
pike.git/src/modules/Image/layers.c:208:   **! }   **!   **! </execute>   **! </add_appendix>   */      #include "global.h"      #include <math.h> /* floor */    - RCSID("$Id: layers.c,v 1.43 2000/02/22 03:41:27 per Exp $"); + RCSID("$Id: layers.c,v 1.44 2000/07/07 00:40:19 hubbe 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:289:       lm_row_func *row_func;/* layer mode */    int optimize_alpha;    int really_optimize_alpha;       struct mapping *misc; /* Misc associated data. Added by per,    rather useful for some things... */   };      #undef THIS - #define THIS ((struct layer *)(fp->current_storage)) - #define THISOBJ (fp->current_object) + #define THIS ((struct layer *)(Pike_fp->current_storage)) + #define THISOBJ (Pike_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)      LMFUNC(lm_normal);      LMFUNC(lm_add);   LMFUNC(lm_subtract);
pike.git/src/modules/Image/layers.c:579:      static INLINE void smear_color(rgb_group *d,rgb_group s,int len)   {    while (len--)    *(d++)=s;   }      #define MAX3(X,Y,Z) MAXIMUM(MAXIMUM(X,Y),Z)   #define MIN3(X,Y,Z) MINIMUM(MINIMUM(X,Y),Z)    - static INLINE void rgb_to_hsv(rgb_group color,double *hp,double *sp,double *vp) + /* Pike_sp was renamed to not_sp by hubbe */ + static INLINE void rgb_to_hsv(rgb_group color, +  double *hp, +  double *not_sp, +  double *vp)   {    double max,min,delta;    double r,g,b;       if (color.r==color.g && color.g==color.b)    { -  *hp=*sp=0.0; +  *hp=*not_sp=0.0;    *vp=C2F(color.r);    return;    }       r=C2F(color.r);    g=C2F(color.g);    b=C2F(color.b);       max = MAX3(r,g,b);    min = MIN3(r,g,b);       *vp = max;    -  *sp = (max - min)/max; +  *not_sp = (max - min)/max;       delta = max-min;       if(r==max) *hp = 6+(g-b)/delta;    else if(g==max) *hp = 2+(b-r)/delta;    else /*if(b==max)*/ *hp = 4+(r-g)/delta;   }      static INLINE void hsv_to_rgb(double h,double s,double v,rgb_group *colorp)   {
pike.git/src/modules/Image/layers.c:726:    free_object(THIS->image);    THIS->image=NULL;    THIS->img=NULL;       if (THIS->alpha)    free_object(THIS->alpha);    THIS->alpha=NULL;    THIS->alp=NULL;       if (args>=1) -  if ( sp[-args].type!=T_OBJECT ) +  if ( Pike_sp[-args].type!=T_OBJECT )    { -  if (sp[-args].type!=T_INT || -  sp[-args].u.integer!=0) +  if (Pike_sp[-args].type!=T_INT || +  Pike_sp[-args].u.integer!=0)    SIMPLE_BAD_ARG_ERROR("Image.Layer->set_image",1,    "object(Image)|int(0)");    }    else if ((img=(struct image*) -  get_storage(sp[-args].u.object,image_program))) +  get_storage(Pike_sp[-args].u.object,image_program)))    { -  THIS->image=sp[-args].u.object; +  THIS->image=Pike_sp[-args].u.object;    add_ref(THIS->image);    THIS->img=img;    THIS->xsize=img->xsize;    THIS->ysize=img->ysize;    }    else    SIMPLE_BAD_ARG_ERROR("Image.Layer->set_image",1,    "object(Image)|int(0)");       if (args>=2) -  if ( sp[1-args].type!=T_OBJECT ) +  if ( Pike_sp[1-args].type!=T_OBJECT )    { -  if (sp[1-args].type!=T_INT || -  sp[1-args].u.integer!=0) +  if (Pike_sp[1-args].type!=T_INT || +  Pike_sp[1-args].u.integer!=0)    SIMPLE_BAD_ARG_ERROR("Image.Layer->set_image",2,    "object(Image)|int(0)");    }    else if ((img=(struct image*) -  get_storage(sp[1-args].u.object,image_program))) +  get_storage(Pike_sp[1-args].u.object,image_program)))    {    if (THIS->img &&    (img->xsize!=THIS->xsize ||    img->ysize!=THIS->ysize))    SIMPLE_BAD_ARG_ERROR("Image.Layer->set_image",2,    "image of same size");    if (!THIS->img)    {    THIS->xsize=img->xsize;    THIS->ysize=img->ysize;    } -  THIS->alpha=sp[1-args].u.object; +  THIS->alpha=Pike_sp[1-args].u.object;    add_ref(THIS->alpha);    THIS->alp=img;    }    else    SIMPLE_BAD_ARG_ERROR("Image.Layer->set_image",2,    "object(Image)|int(0)");       pop_n_elems(args);    ref_push_object(THISOBJ);   }
pike.git/src/modules/Image/layers.c:809:   **! As an example, the XCF and PSD image decoders set the 'name' attribute   **! to the name the layer had in the source file.   */   static void image_layer_set_misc_value( INT32 args )   {    if( args != 2 )    error("Wrong number of arguments to set_misc_value\n");    if( !THIS->misc )    THIS->misc = allocate_mapping( 4 );    -  mapping_insert( THIS->misc, sp-2, sp-1 ); +  mapping_insert( THIS->misc, Pike_sp-2, Pike_sp-1 );    stack_swap();    pop_stack();   }      static void image_layer_image(INT32 args)   {    pop_n_elems(args);    if (THIS->image)    ref_push_object(THIS->image);    else
pike.git/src/modules/Image/layers.c:911:   **! note:   **! image and alpha channel must be of the same size,   **! or canceled.   */      static void image_layer_set_mode(INT32 args)   {    int i;    if (args!=1)    SIMPLE_TOO_FEW_ARGS_ERROR("Image.Layer->set_mode",1); -  if (sp[-args].type!=T_STRING) +  if (Pike_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) +  if (Pike_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;    }   
pike.git/src/modules/Image/layers.c:981:   **! Set/query fill color and alpha, ie the color used "outside" the   **! image. This is mostly useful if you want to "frame"   **! a layer.   */      static void image_layer_set_fill(INT32 args)   {    if (!args)    SIMPLE_TOO_FEW_ARGS_ERROR("Image.Layer->set_fill",1);    -  if (sp[-args].type==T_INT && !sp[-args].u.integer) +  if (Pike_sp[-args].type==T_INT && !Pike_sp[-args].u.integer)    THIS->fill=black;    else    if (!image_color_arg(-args,&(THIS->fill)))    SIMPLE_BAD_ARG_ERROR("Image.Layer->set_fill",1,"color");       smear_color(THIS->sfill,THIS->fill,SNUMPIXS);       THIS->fill_alpha=white;    if (args>1) -  if (sp[1-args].type==T_INT && !sp[1-args].u.integer) +  if (Pike_sp[1-args].type==T_INT && !Pike_sp[1-args].u.integer)    ; /* white is good */    else    if (!image_color_arg(1-args,&(THIS->fill_alpha)))    {    smear_color(THIS->sfill_alpha,THIS->fill_alpha,SNUMPIXS);    SIMPLE_BAD_ARG_ERROR("Image.Layer->set_fill",2,"color");    }    smear_color(THIS->sfill_alpha,THIS->fill_alpha,SNUMPIXS);      #if 0
pike.git/src/modules/Image/layers.c:1162:   **! image and alpha channel must be of the same size.   **!   */      static INLINE void try_parameter(char *a,void (*f)(INT32))   {    stack_dup();    push_text(a);    f_index(2);    -  if (!IS_UNDEFINED(sp-1)) +  if (!IS_UNDEFINED(Pike_sp-1))    f(1);    pop_stack();   }      static INLINE void try_parameter_pair(char *a,char *b,void (*f)(INT32))   {    stack_dup(); /* map map */    stack_dup(); /* map map map */    push_text(a); /* map map map a */    f_index(2); /* map map map[a] */    stack_swap(); /* map map[a] map */    push_text(b); /* map map[a] map b */    f_index(2); /* map map[a] map[b] */    -  if (!IS_UNDEFINED(sp-2) || -  !IS_UNDEFINED(sp-1)) +  if (!IS_UNDEFINED(Pike_sp-2) || +  !IS_UNDEFINED(Pike_sp-1))    {    f(2);    pop_stack();    }    else    pop_n_elems(2);   }      static void image_layer_create(INT32 args)   {    if (!args)    return; -  if (sp[-args].type==T_MAPPING) +  if (Pike_sp[-args].type==T_MAPPING)    {    pop_n_elems(args-1);    try_parameter_pair("image","alpha",image_layer_set_image);       try_parameter("mode",image_layer_set_mode);    try_parameter("alpha_value",image_layer_set_alpha_value);       try_parameter_pair("xoffset","yoffset",image_layer_set_offset);    try_parameter_pair("fill","fill_alpha",image_layer_set_fill);    try_parameter("tiled",image_layer_set_tiled);    pop_stack();    return;    } -  else if (sp[-args].type==T_INT && args>1 -  && sp[1-args].type==T_INT) +  else if (Pike_sp[-args].type==T_INT && args>1 +  && Pike_sp[1-args].type==T_INT)    {    rgb_group col=black,alpha=white;       get_all_args("Image.Layer",args,"%i%i",&(THIS->xsize),&(THIS->ysize));    if (args>2)    if (!image_color_arg(2-args,&col))    SIMPLE_BAD_ARG_ERROR("Image.Layer",3,"Image.Color");       if (args>3)    if (!image_color_arg(3-args,&alpha))
pike.git/src/modules/Image/layers.c:1237:    push_int(THIS->ysize);    push_int(alpha.r);    push_int(alpha.g);    push_int(alpha.b);    push_object(clone_object(image_program,5));       image_layer_set_image(2);       pop_n_elems(args);    } -  else if (sp[-args].type==T_OBJECT || args>1) +  else if (Pike_sp[-args].type==T_OBJECT || args>1)    {    if (args>2)    {    image_layer_set_mode(args-2);    pop_stack();    args=2;    }    image_layer_set_image(args);    pop_stack();    }    else    SIMPLE_BAD_ARG_ERROR("Image.Layer",1,"mapping|int|Image.Image");   }      /*** layer object *****************************************/      static void image_layer_cast(INT32 args)   {    if (!args)    SIMPLE_TOO_FEW_ARGS_ERROR("Image.Layer->cast",1); -  if (sp[-args].type==T_STRING||sp[-args].u.string->size_shift) +  if (Pike_sp[-args].type==T_STRING||Pike_sp[-args].u.string->size_shift)    { -  if (strncmp(sp[-args].u.string->str,"mapping",7)==0) +  if (strncmp(Pike_sp[-args].u.string->str,"mapping",7)==0)    {    int n=0;    pop_n_elems(args);       push_text("xsize"); push_int(THIS->xsize); n++;    push_text("ysize"); push_int(THIS->ysize); n++;    push_text("image"); image_layer_image(0); n++;    push_text("alpha"); image_layer_alpha(0); n++;    push_text("xoffset"); push_int(THIS->xoffs); n++;    push_text("yoffset"); push_int(THIS->yoffs); n++;
pike.git/src/modules/Image/layers.c:2519:    struct layer **l;    struct object *o;    struct layer *dest;    struct array *a;    int gotoffs;    int xoffset=0,yoffset=0,xsize=0,ysize=0;       if (!args)    SIMPLE_TOO_FEW_ARGS_ERROR("Image.lay",1);    -  if (sp[-args].type!=T_ARRAY) +  if (Pike_sp[-args].type!=T_ARRAY)    SIMPLE_BAD_ARG_ERROR("Image.lay",1,    "array(Image.Layer|mapping)");       if (args>1)    {    get_all_args("Image.lay",args-1,"%i%i%i%i",    &xoffset,&yoffset,&xsize,&ysize);    if (xsize<1)    SIMPLE_BAD_ARG_ERROR("Image.lay",4,"int(1..)");    if (ysize<1)    SIMPLE_BAD_ARG_ERROR("Image.lay",5,"int(1..)");    }    -  layers=(a=sp[-args].u.array)->size; +  layers=(a=Pike_sp[-args].u.array)->size;       if (!layers) /* dummy return empty layer */    {    pop_n_elems(args);    push_object(clone_object(image_layer_program,0));    return;    }       l=(struct layer**)xalloc(sizeof(struct layer)*layers);   
pike.git/src/modules/Image/layers.c:2613:       dest=(struct layer*)get_storage(o,image_layer_program);    dest->xoffs=xoffset;    dest->yoffs=yoffset;       /* ok, do it! */    img_lay(l,layers,dest);       free(l);    -  sp--; +  Pike_sp--;    pop_n_elems(args);    push_object(o);   }      /** image-object operations *************************/      static INLINE struct layer *push_new_layer()   {    push_object(clone_object(image_layer_program,0)); -  return (struct layer*)get_storage(sp[-1].u.object,image_layer_program); +  return (struct layer*)get_storage(Pike_sp[-1].u.object,image_layer_program);   }      static INLINE struct layer *clone_this_layer()   {    struct layer *l;    l=push_new_layer();    l->xsize=THIS->xsize;    l->ysize=THIS->ysize;    l->xoffs=THIS->xoffs;    l->yoffs=THIS->yoffs;
pike.git/src/modules/Image/layers.c:2715:    push_constant_text("copy");    f_index(2);    push_int(xi);    push_int(yi);    push_int(xz+xi-1);    push_int(yz+yi-1);    push_int(THIS->fill.r);    push_int(THIS->fill.g);    push_int(THIS->fill.b);    f_call_function(8); -  if (sp[-1].type!=T_OBJECT || -  !(img=(struct image*)get_storage(sp[-1].u.object,image_program))) +  if (Pike_sp[-1].type!=T_OBJECT || +  !(img=(struct image*)get_storage(Pike_sp[-1].u.object,image_program)))    error("No image returned from image->copy\n");    if (img->xsize!=xz || img->ysize!=yz)    error("Image returned from image->copy had "    "unexpected size (%d,%d, expected %d,%d)\n",    img->xsize,img->ysize,xz,yz);       free_object(l->image); -  l->image=sp[-1].u.object; -  sp--; -  dmalloc_touch_svalue(sp); +  l->image=Pike_sp[-1].u.object; +  Pike_sp--; +  dmalloc_touch_svalue(Pike_sp);    l->img=img;    }       if (zot && l->alpha)    {    ref_push_object(l->alpha);    push_constant_text("copy");    f_index(2);    push_int(xi);    push_int(yi);    push_int(xz+xi-1);    push_int(yz+yi-1);    push_int(THIS->fill_alpha.r);    push_int(THIS->fill_alpha.g);    push_int(THIS->fill_alpha.b);    f_call_function(8); -  if (sp[-1].type!=T_OBJECT || -  !(img=(struct image*)get_storage(sp[-1].u.object,image_program))) +  if (Pike_sp[-1].type!=T_OBJECT || +  !(img=(struct image*)get_storage(Pike_sp[-1].u.object,image_program)))    error("No image returned from alpha->copy\n");    if (img->xsize!=xz || img->ysize!=yz)    error("Image returned from alpha->copy had "    "unexpected size (%d,%d, expected %d,%d)\n",    img->xsize,img->ysize,xz,yz);    free_object(l->alpha); -  l->alpha=sp[-1].u.object; -  sp--; -  dmalloc_touch_svalue(sp); +  l->alpha=Pike_sp[-1].u.object; +  Pike_sp--; +  dmalloc_touch_svalue(Pike_sp);    l->alp=img;    }       l->xoffs=x;    l->yoffs=y;    l->xsize=xz;    l->ysize=yz;       stack_pop_n_elems_keep_top(args);   }
pike.git/src/modules/Image/layers.c:2835:    push_int(x1+THIS->xoffs);    push_int(y1+THIS->yoffs);    push_int(x2-x1+1);    push_int(y2-y1+1);    f_aggregate(4);   }      void image_layer_autocrop(INT32 args)   {    image_layer_find_autocrop(args); -  sp--; -  dmalloc_touch_svalue(sp); -  push_array_items(sp->u.array); /* frees */ +  Pike_sp--; +  dmalloc_touch_svalue(Pike_sp); +  push_array_items(Pike_sp->u.array); /* frees */    image_layer_crop(4);   }         /******************************************************/      void init_image_layers(void)   {    char buf[100];    char buf2[sizeof(INT32)];