Branch: Tag:

2014-08-18

2014-08-18 15:38:59 by Martin Nilsson <nilsson@opera.com>

Improved cast.

28:   #include "dmalloc.h"   #include "operators.h"   #include "module_support.h" + #include "pike_types.h"      #include "image.h"   
1424:    */   static void image_layer_cast(INT32 args)   { +  struct pike_string *type; +     if (!args)    SIMPLE_TOO_FEW_ARGS_ERROR("Image.Layer->cast",1); -  if (TYPEOF(Pike_sp[-args]) == T_STRING || -  Pike_sp[-args].u.string->size_shift) +  +  type = Pike_sp[-args].u.string; +  pop_n_elems(args); /* type have at least one more reference. */ +  +  if (type == literal_mapping_string)    { -  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++;
1447:    push_text("mode"); image_layer_mode(0); n++;       f_aggregate_mapping(n*2); -  -  return; +     } -  else if (strncmp(Pike_sp[-args].u.string->str,"string",6)==0) +  else if (type == literal_string_string)    {    size_t size = THIS->xsize*THIS->ysize, i;    struct pike_string *s = begin_shared_string(size*4);    rgb_group *img = 0;    rgb_group *alp = 0;    -  pop_n_elems(args); +     if(THIS->img)    img = THIS->img->img;    if(THIS->alp)
1488:    memset(s->str, 0, size*4);       push_string(end_shared_string(s)); -  return; +     } -  +  else +  push_undefined();   } -  SIMPLE_BAD_ARG_ERROR("Image.Colortable->cast",1, -  "string(\"mapping\"|\"string\")"); +     - } -  +    /*** layer mode definitions ***************************/      static void lm_normal(rgb_group *s,rgb_group *l,rgb_group *d,
3302:    ADD_FUNCTION("_sprintf",image_layer__sprintf,    tFunc(tInt tMapping,tString),0);    ADD_FUNCTION("cast",image_layer_cast, -  tFunc(tString,tMapping),0); +  tFunc(tString,tMapping),ID_PROTECTED);          ADD_FUNCTION("clone",image_layer_clone,