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

version» Context lines:

pike.git/src/modules/Image/layers.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: layers.c,v 1.94 2003/12/12 17:43:54 nilsson Exp $ + || $Id: layers.c,v 1.95 2004/02/03 17:34:38 grubba Exp $   */      /*   **! module Image   **! class Layer   **! see also: layers   */      #include "global.h"      #include <math.h> /* floor */    - RCSID("$Id: layers.c,v 1.94 2003/12/12 17:43:54 nilsson Exp $"); + RCSID("$Id: layers.c,v 1.95 2004/02/03 17:34:38 grubba 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:2860:   **! method Image.Layer lay(array(Image.Layer|mapping) layers)   **! method Image.Layer lay(array(Image.Layer|mapping) layers,int xoffset,int yoffset,int xsize,int ysize)   **! Combine layers.   **! returns a new layer object.   **!   **! see also: Image.Layer   */      void image_lay(INT32 args)   { -  int layers,i; +  int layers,i,j;    struct layer **l;    struct object *o;    struct layer *dest;    struct array *a;    INT_TYPE xoffset=0,yoffset=0,xsize=0,ysize=0; -  +  ONERROR err;       if (!args)    SIMPLE_TOO_FEW_ARGS_ERROR("Image.lay",1);       if (Pike_sp[-args].type!=T_ARRAY)    SIMPLE_BAD_ARG_ERROR("Image.lay",1,    "array(Image.Layer|mapping)");       if (args>1)    {
pike.git/src/modules/Image/layers.c:2895:       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);    -  for (i=0; i<layers; i++) +  SET_ONERROR(err, free, l); +  +  for (i=j=0; i<layers; i++)    {    if (a->item[i].type==T_OBJECT)    { -  if (!(l[i]=(struct layer*)get_storage(a->item[i].u.object, +  if (!(l[j]=(struct layer*)get_storage(a->item[i].u.object,    image_layer_program)))    SIMPLE_BAD_ARG_ERROR("Image.lay",1,    "array(Image.Layer|mapping)");    }    else if (a->item[i].type==T_MAPPING)    {    push_svalue(a->item+i);    push_object(o=clone_object(image_layer_program,1));    args++; -  l[i]=(struct layer*)get_storage(o,image_layer_program); +  l[j]=(struct layer*)get_storage(o,image_layer_program);    }    else    SIMPLE_BAD_ARG_ERROR("Image.lay",1,    "array(Image.Layer|mapping)"); -  +  if (l[j]->xsize && l[j]->ysize) +  j++;    }    -  +  if (!(layers = j)) /* dummy return empty layer */ +  { +  CALL_AND_UNSET_ONERROR(err); +  pop_n_elems(args); +  push_object(clone_object(image_layer_program,0)); +  return; +  } +     if (xsize==0) /* figure offset and size */    {    xoffset=l[0]->xoffs;    yoffset=l[0]->yoffs;    xsize=l[0]->xsize;    ysize=l[0]->ysize;    if (l[0]->tiled) /* set size from the first non-tiled */    {    for (i=1; i<layers; i++)    if (!l[i]->tiled)
pike.git/src/modules/Image/layers.c:2962:    push_int(ysize);    push_object(o=clone_object(image_layer_program,2));       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); +  CALL_AND_UNSET_ONERROR(err);       Pike_sp--;    pop_n_elems(args);    push_object(o);   }      /** image-object operations *************************/      static INLINE struct layer *push_new_layer(void)   {