Branch: Tag:

2000-02-08

2000-02-08 03:38:56 by Per Hedbor <ph@opera.com>

Added two new functions - get_misc_value and set_misc_value, used by the XCF module to save layer info such as name etc. into the layer objects

Rev: src/modules/Image/layers.c:1.42

1:   /*   **! module Image   **! note - **! $Id: layers.c,v 1.41 2000/02/03 19:02:22 grubba Exp $ + **! $Id: layers.c,v 1.42 2000/02/08 03:38:56 per Exp $   **! class Layer   **! see also: layers   **!
215:      #include <math.h> /* floor */    - RCSID("$Id: layers.c,v 1.41 2000/02/03 19:02:22 grubba Exp $"); + RCSID("$Id: layers.c,v 1.42 2000/02/08 03:38:56 per Exp $");      #include "image_machine.h"   
290:    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
680:    THIS->row_func=lm_normal;    THIS->optimize_alpha=1;    THIS->really_optimize_alpha=1; +  THIS->misc=0;       smear_color(THIS->sfill,THIS->fill,SNUMPIXS);    smear_color(THIS->sfill_alpha,THIS->fill_alpha,SNUMPIXS);
689:   {    if (THIS->image) free_object(THIS->image);    if (THIS->alpha) free_object(THIS->alpha); +  if (THIS->misc) free_mapping(THIS->misc);    THIS->image=NULL;    THIS->alpha=NULL;    THIS->img=NULL;
781:    ref_push_object(THISOBJ);   }    + static void image_layer_get_misc_value( INT32 args ) + { +  if( args != 1 ) +  error("Wrong number of arguments to get_misc_value\n"); +  if( THIS->misc ) +  { +  ref_push_mapping( THIS->misc ); +  stack_swap(); +  f_index( 2 ); +  } else { +  pop_n_elems( args ); +  push_int( 0 ); +  } + } +  + /* + **! method mixed set_misc_value( mixed what, mixed to ) + **! method mixed get_misc_value( mixed what ) + **! Set or query misc. attributes for the layer. + **! + **! 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 ); +  stack_swap(); +  pop_stack(); + } +    static void image_layer_image(INT32 args)   {    pop_n_elems(args);
2844:    set_init_callback(init_layer);    set_exit_callback(exit_layer);    +     ADD_FUNCTION("create",image_layer_create,    tOr4(tFunc(tNone,tVoid),    tFunc(tObj tOr(tObj,tVoid) tOr(tString,tVoid),tVoid),
2870:    tFunc(tFloat,tObj),0);    ADD_FUNCTION("set_tiled",image_layer_set_tiled,tFunc(tInt,tObj),0);    +  ADD_FUNCTION("set_misc_value", image_layer_set_misc_value, +  tFunc(tMixed tMixed, tMixed),0 ); +  +     /* query */       ADD_FUNCTION("image",image_layer_image,tFunc(tNone,tObj),0);
2893:       ADD_FUNCTION("tiled",image_layer_tiled,tFunc(tNone,tInt01),0);    +  ADD_FUNCTION("get_misc_value", image_layer_get_misc_value, +  tFunc(tMixed, tMixed),0 ); +     /* image-object operations */       ADD_FUNCTION("crop",image_layer_crop,