pike.git / src / modules / Image / encodings / xcf.c

version» Context lines:

pike.git/src/modules/Image/encodings/xcf.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$ +    */      #include "global.h"   #include "image_machine.h"      #include "pike_macros.h"   #include "object.h"   #include "module_support.h"   #include "interpret.h"   #include "object.h"   #include "svalue.h"   #include "threads.h"   #include "interpret.h"   #include "svalue.h"   #include "mapping.h"   #include "pike_error.h"   #include "stralloc.h"   #include "builtin_functions.h"   #include "bignum.h" -  + #include "pike_types.h"      #include "image.h"   #include "colortable.h"         #define sp Pike_sp   #define fp Pike_fp      extern struct program *image_colortable_program;   extern struct program *image_program;
pike.git/src/modules/Image/encodings/xcf.c:59:    struct pike_string *s;    ptrdiff_t offset;    ptrdiff_t len;   };      static struct program *substring_program;   #define SS(X) ((struct substring*)X->storage)      static void f_substring_cast( INT32 args )   { -  /* FIXME: assumes string */ +  struct pike_string *type = sp[-args].u.string; +  pop_n_elems(args); /* type have at least one more reference. */ +  +  if( type == literal_string_string ) +  {    struct substring *s = SS(fp->current_object); -  pop_n_elems( args ); +     push_string( make_shared_binary_string( (((char *)s->s->str)+s->offset),    s->len ) );    } -  +  else +  push_undefined(); + }      static void f_substring_index( INT32 args )   {    ptrdiff_t i = sp[-1].u.integer;    struct substring *s = SS(fp->current_object);    pop_n_elems( args );       if( i < 0 ) i = s->len + i;    if( i >= s->len ) { -  Pike_error("Index out of bounds, %ld > %ld\n", i, -  DO_NOT_WARN((long)s->len-1) ); +  Pike_error("Index out of bounds, %ld > %ld\n", i, (long)s->len-1 );    }    push_int( ((unsigned char *)s->s->str)[s->offset+i] );   }      static void f_substring__sprintf( INT32 args )   {    int x;    struct substring *s = SS(fp->current_object);       if (args != 2 )    SIMPLE_TOO_FEW_ARGS_ERROR("_sprintf",2);    if (TYPEOF(sp[-2]) != T_INT) -  SIMPLE_BAD_ARG_ERROR("_sprintf",0,"integer"); +  SIMPLE_BAD_ARG_ERROR("_sprintf",0,"int");    if (TYPEOF(sp[-1]) != T_MAPPING)    SIMPLE_BAD_ARG_ERROR("_sprintf",1,"mapping");    x = sp[-2].u.integer;    pop_n_elems( args );       switch( x )    {    case 't': -  push_constant_text("SubString"); +  push_static_text("SubString");    return;    case 'O': -  push_constant_text("SubString( %O /* [+%d .. %d] */ )" ); -  push_text("string"); f_substring_cast( 1 ); +  push_static_text("SubString( %O /* [+%d .. %d] */ )" ); +  ref_push_string(literal_string_string); f_substring_cast( 1 );       push_int64( s->len );    push_int64( s->offset );    f_sprintf( 4 );    return;    default:    push_int(0);    return;    }   }    - static void f_substring_get_int( INT32 args ) + static void f_substring_get_int( INT32 UNUSED(args) )   {    struct substring *s = SS(fp->current_object);    int res;    unsigned char *p;    int x = sp[-1].u.integer;    if( x > s->len>>2 )    Pike_error("Index %d out of range.\n", x );       p = ((unsigned char *)s->s->str) + s->offset + x*4;    res = (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];    push_int( res );   }       - static void f_substring_get_uint( INT32 args ) + static void f_substring_get_uint( INT32 UNUSED(args) )   {    struct substring *s = SS(fp->current_object);    unsigned int res;    unsigned char *p;    int x = sp[-1].u.integer;    if( x > s->len>>2 )    Pike_error("Index %d out of range.\n", x );       p = ((unsigned char *)s->s->str) + s->offset + x*4;    res = (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];    push_int64( res );   }    - static void f_substring_get_ushort( INT32 args ) + static void f_substring_get_ushort( INT32 UNUSED(args) )   {    struct substring *s = SS(fp->current_object);    unsigned short res;    unsigned char *p;    int x = sp[-1].u.integer;    if( x > s->len>>1 )    Pike_error("Index %d out of range.\n", x );       p = ((unsigned char *)s->s->str) + s->offset + x*2;    res = (p[2]<<8) | p[3];    push_int( res );   }    - static void f_substring_get_short( INT32 args ) + static void f_substring_get_short( INT32 UNUSED(args) )   {    struct substring *s = SS(fp->current_object);    short res;    unsigned char *p;    int x = sp[-1].u.integer;    if( x > s->len>>1 )    Pike_error("Index %d out of range.\n", x );       p = ((unsigned char *)s->s->str) + s->offset + x*2;    res = (p[2]<<8) | p[3];
pike.git/src/modules/Image/encodings/xcf.c:183:   {    struct object *o = clone_object( substring_program, 0 );    struct substring *ss = SS(o);    ss->s = s;    s->refs++;    ss->offset = offset;    ss->len = len;    push_object( o );   }    - static void free_substring(struct object *o) + static void free_substring(struct object *UNUSED(o))   {    if( SS(fp->current_object)->s )    {    free_string( SS(fp->current_object)->s );    SS(fp->current_object)->s = 0;    }   }         typedef enum
pike.git/src/modules/Image/encodings/xcf.c:308:      static int xcf_read_int( struct buffer *from )   {    return (int)read_uint( from );   }      static char *read_data( struct buffer *from, size_t len )   {    char *res;    if( from->len < len ) -  Pike_error("Not enough space for %lu bytes\n", -  DO_NOT_WARN((unsigned long)len)); +  Pike_error("Not enough space for %lu bytes\n", (unsigned long)len);    res = (char *)from->str;    from->str += len;    from->len -= len;    return res;   }      static struct buffer read_string( struct buffer *data )   {    struct buffer res = *data;    res.len = xcf_read_int( data );
pike.git/src/modules/Image/encodings/xcf.c:500:   }      static struct level read_level( struct buffer *buff,    struct buffer *initial )   {    struct level res;    ONERROR err;    int offset;    struct tile *last_tile = NULL;   /* int all_tiles_eq = 0; */ -  MEMSET(&res, 0, sizeof(res)); +  memset(&res, 0, sizeof(res));    res.width = read_uint( buff );    res.height = read_uint( buff );       SET_ONERROR( err, free_level, &res );    offset = read_uint( buff );    while(offset)    {    struct buffer ob = *initial;    int offset2 = read_uint( buff ); -  struct tile *tile = (struct tile *)xalloc(sizeof(struct tile)); +  struct tile *tile = xalloc(sizeof(struct tile));    read_data( &ob, offset );    if(last_tile)    last_tile->next = tile;    last_tile = tile;    if(!res.first_tile)    res.first_tile = tile;    tile->data = ob;    tile->next = NULL;    offset = offset2;    }
pike.git/src/modules/Image/encodings/xcf.c:532:    return res;   }      static struct hierarchy read_hierarchy( struct buffer *buff,    struct buffer *initial )   {    struct hierarchy res;    unsigned int offset;    struct buffer ob;    -  MEMSET(&res, 0, sizeof(res)); +  memset(&res, 0, sizeof(res));    res.width = read_uint( buff );    res.height = read_uint( buff );    res.bpp = read_uint( buff );    offset = read_uint( buff );    ob = *initial;    read_data( &ob, offset );    res.level = read_level( &ob, initial );    return res;   }      static struct layer_mask read_layer_mask( struct buffer *buff,    struct buffer *initial )   {    struct layer_mask res;    ONERROR err;    int offset;    struct property tmp;    -  MEMSET(&res, 0, sizeof(res)); +  memset(&res, 0, sizeof(res));    res.width = read_uint( buff );    res.height = read_uint( buff );    res.name = read_string( buff );       SET_ONERROR( err, free_layer_mask, &res );    do    {    tmp = read_property( buff );    if(tmp.type)    { -  struct property *s = (struct property *)xalloc(sizeof(struct property)); +  struct property *s = xalloc(sizeof(struct property));    *s = tmp;    s->next = res.first_property;    res.first_property = s;    }    } while(tmp.type);    offset = read_uint( buff );       if(offset)    {    struct buffer ob = *initial;
pike.git/src/modules/Image/encodings/xcf.c:588:   }      static struct channel read_channel( struct buffer *buff,    struct buffer *initial )   {    struct channel res;    ONERROR err;    int offset;    struct property tmp;    -  MEMSET(&res, 0, sizeof(res)); +  memset(&res, 0, sizeof(res));    res.width = read_uint( buff );    res.height = read_uint( buff );    res.name = read_string( buff );       SET_ONERROR( err, free_channel, &res );    do    {    tmp = read_property( buff );    if(tmp.type)    { -  struct property *s =(struct property *)xalloc( sizeof(struct property )); +  struct property *s = xalloc( sizeof(struct property ));    *s = tmp;    s->next = res.first_property;    res.first_property = s;    }    } while( tmp.type );    offset = read_uint( buff );       if(offset)    {    struct buffer ob = *initial;
pike.git/src/modules/Image/encodings/xcf.c:625:   }      static struct layer read_layer( struct buffer *buff, struct buffer *initial )   {    struct layer res;    struct property tmp;    int lm_offset;    int h_offset;    ONERROR err;    -  MEMSET(&res, 0, sizeof(res)); +  memset(&res, 0, sizeof(res));    SET_ONERROR( err, free_layer, &res );    res.width = read_uint( buff );    res.height = read_uint( buff );    res.type = xcf_read_int( buff );    res.name = read_string( buff );          do    {    tmp = read_property( buff );    if(tmp.type)    { -  struct property *s=(struct property *)xalloc( sizeof(struct property )); +  struct property *s=xalloc( sizeof(struct property ));    *s = tmp;    s->next = res.first_property;    res.first_property = s;    }    } while( tmp.type );       h_offset = xcf_read_int( buff );    lm_offset = xcf_read_int( buff );       if(lm_offset)    {    struct buffer loffset = *initial; -  struct layer_mask *m=(struct layer_mask *)xalloc(sizeof(struct layer_mask)); +  struct layer_mask *m=xalloc(sizeof(struct layer_mask));    res.mask = m;    read_data( &loffset, lm_offset ); -  MEMSET(m, 0, sizeof( struct layer_mask )); +  memset(m, 0, sizeof( struct layer_mask ));    *m = read_layer_mask( &loffset, initial );    }       if(h_offset)    {    struct buffer loffset = *initial;    read_data( &loffset, h_offset );    res.image_data = read_hierarchy( &loffset, initial );    }   
pike.git/src/modules/Image/encodings/xcf.c:678:         static struct gimp_image read_image( struct buffer * data )   {    struct gimp_image res;    struct property tmp;    struct buffer initial;    unsigned int offset;    ONERROR err;    -  MEMSET(&res, 0, sizeof(res)); +  memset(&res, 0, sizeof(res));    initial = *data;    if(data->len < 34)    Pike_error("This is not an xcf file (to little data)\n");    if(!(data->str[0] == 'g' &&    data->str[1] == 'i' &&    data->str[2] == 'm' &&    data->str[3] == 'p' &&    data->str[4] == ' '))    {    if(strlen((char *)data->str) == 13)
pike.git/src/modules/Image/encodings/xcf.c:706:    res.height = read_uint( data );    res.type = xcf_read_int( data );       SET_ONERROR( err, free_image, &res );       do    {    tmp = read_property( data );    if(tmp.type)    { -  struct property *s= (struct property *)xalloc( sizeof(struct property )); +  struct property *s=xalloc( sizeof(struct property ));    *s = tmp;    s->next = res.first_property;    res.first_property = s;    }    } while( tmp.type );       while( (offset = read_uint( data )) )    {    struct buffer layer_data = initial;    struct layer tmp;    read_data( &layer_data, offset );    tmp = read_layer( &layer_data, &initial );    if( tmp.width && tmp.height )    { -  struct layer *s = (struct layer *)xalloc( sizeof(struct layer)); +  struct layer *s = xalloc( sizeof(struct layer));    *s = tmp;    s->next = res.first_layer;    res.first_layer = s;    }    }       while( (offset = read_uint( data )) )    {    struct buffer channel_data = initial;    struct channel tmp;    read_data( &channel_data, offset );    tmp = read_channel( &channel_data, &initial );    if( tmp.width && tmp.height )    { -  struct channel *s = (struct channel *)xalloc( sizeof(struct channel)); +  struct channel *s = xalloc( sizeof(struct channel));    *s = tmp;    s->next = res.first_channel;    res.first_channel = s;    }    }    UNSET_ONERROR( err );    return res;   }      static void push_buffer( struct buffer *b )
pike.git/src/modules/Image/encodings/xcf.c:762:   static void push_properties( struct property *p )   {    struct svalue *osp = sp;    while(p)    {    ref_push_string( s_type ); push_int( p->type );    ref_push_string( s_data ); push_buffer( &p->data );    f_aggregate_mapping( 4 );    p = p->next;    } -  f_aggregate(DO_NOT_WARN((INT32)(sp - osp))); +  f_aggregate((INT32)(sp - osp));   }      static void push_tile( struct tile *t )   {    push_buffer( &t->data );   }      static void push_hierarchy( struct hierarchy * h )   {    struct tile *t = h->level.first_tile;
pike.git/src/modules/Image/encodings/xcf.c:789:    ref_push_string( s_height ); push_int( h->height );    ref_push_string( s_bpp ); push_int( h->bpp );       ref_push_string( s_tiles );    tsp = sp;    while(t)    {    push_tile( t );    t=t->next;    } -  f_aggregate(DO_NOT_WARN((INT32)(sp - tsp))); -  f_aggregate_mapping(DO_NOT_WARN((INT32)(sp - osp))); +  f_aggregate((INT32)(sp - tsp)); +  f_aggregate_mapping((INT32)(sp - osp));   }      static void push_layer_mask(struct layer_mask *i)   {    struct svalue *osp = sp;    ref_push_string( s_width ); push_int( i->width );    ref_push_string( s_height ); push_int( i->height );    ref_push_string( s_properties );    push_properties( i->first_property );    ref_push_string( s_name ); push_buffer( &i->name );    ref_push_string( s_image_data );    push_hierarchy( &i->image_data ); -  f_aggregate_mapping(DO_NOT_WARN((INT32)(sp-osp))); +  f_aggregate_mapping((INT32)(sp-osp));   }      static void push_channel(struct channel *i)   {    struct svalue *osp = sp;    ref_push_string( s_width ); push_int( i->width );    ref_push_string( s_height ); push_int( i->height );    ref_push_string( s_properties );    push_properties( i->first_property );    ref_push_string( s_name ); push_buffer( &i->name );    ref_push_string( s_image_data );    push_hierarchy( &i->image_data ); -  f_aggregate_mapping(DO_NOT_WARN((INT32)(sp-osp))); +  f_aggregate_mapping((INT32)(sp-osp));   }      static void push_layer(struct layer *i)   {    struct svalue *osp = sp;    ref_push_string( s_width ); push_int( i->width );    ref_push_string( s_height ); push_int( i->height );    ref_push_string( s_type ); push_int( i->type );    ref_push_string( s_properties );    push_properties( i->first_property );    ref_push_string( s_name ); push_buffer( &i->name );    ref_push_string( s_image_data );    push_hierarchy( &i->image_data );    if( i->mask )    {    ref_push_string( s_mask );    push_layer_mask( i->mask );    } -  f_aggregate_mapping(DO_NOT_WARN((INT32)(sp - osp))); +  f_aggregate_mapping((INT32)(sp - osp));   }         static void push_image( struct gimp_image *i )   {    struct layer *l;    struct channel *c;    int nitems = 0;    struct svalue *osp = sp;    ref_push_string( s_width ); push_int( i->width );
pike.git/src/modules/Image/encodings/xcf.c:870:    ref_push_string( s_channels );    nitems=0;    c = i->first_channel;    while(c)    {    nitems++;    push_channel( c );    c = c->next;    }    f_aggregate( nitems ); -  f_aggregate_mapping(DO_NOT_WARN((INT32)(sp-osp))); +  f_aggregate_mapping((INT32)(sp-osp));   }         static void image_xcf____decode( INT32 args )   {    struct pike_string *s;    struct buffer b;    struct gimp_image res;    ONERROR err;    get_all_args( "___decode", args, "%S", &s );
pike.git/src/modules/Image/encodings/xcf.c:1178:    rgb_group pix = {0,0,0};    rgb_group apix= {255,255,255}; /* avoid may use uninitialized warnings */       INT_TYPE rle, bpp, span, shrink;    unsigned int l, x=0, y=0, cx, cy;    ONERROR err;    get_all_args( "_decode_tiles", args, "%o%O%a%i%i%O%i%d%d",    &io, &ao, &tiles, &rle, &bpp, &cmapo, &shrink, &rxs, &rys);       -  if( !(i = (struct image *)get_storage( io, image_program ))) +  if( !(i = get_storage( io, image_program )))    Pike_error("Wrong type object argument 1 (image)\n");    -  if(ao && !(a = (struct image *)get_storage( ao, image_program ))) +  if(ao && !(a = get_storage( ao, image_program )))    Pike_error("Wrong type object argument 2 (image)\n");       if( cmapo && -  !(cmap=(struct neo_colortable *)get_storage(cmapo, -  image_colortable_program))) +  !(cmap=get_storage(cmapo, image_colortable_program)))    Pike_error("Wrong type object argument 4 (colortable)\n");       for(l=0; l<(unsigned int)tiles->size; l++)    if(TYPEOF(tiles->item[l]) != T_OBJECT)    Pike_error("Wrong type array argument 3 (tiles)\n");       if(a && ((i->xsize != a->xsize) || (i->ysize != a->ysize)))    Pike_error("Image and alpha objects are not identically sized.\n");       if(cmap)
pike.git/src/modules/Image/encodings/xcf.c:1233:    eheight = MINIMUM(TILE_HEIGHT, (rys-y));       if( (double)ewidth * eheight * bpp > INT_MAX )    Pike_error("Insanely large tiles not supported\n");    if(rle)    {    struct buffer s = tile, od, d;    int i;    od.s = NULL;    od.len = eheight*ewidth*bpp; /* Max and only size, really */ -  df = (char *)(od.str = (unsigned char *)xalloc( eheight*ewidth*bpp+1 )); +  df = (char *)(od.str = xalloc( eheight*ewidth*bpp+1 ));    d = od;       for(i=0; i<bpp; i++)    {    int nelems = ewidth*eheight;    int length;    while(nelems)    {    unsigned char val = read_char( &s );    if(!s.len)
pike.git/src/modules/Image/encodings/xcf.c:1401:    UNSET_ONERROR(err);    free( colortable );    }       pop_n_elems(args);    push_int(0);   }         static struct program *image_encoding_xcf_program=NULL; - void init_image_xcf() + void init_image_xcf(void)   {    ADD_FUNCTION( "___decode", image_xcf____decode, tFunc(tStr,tMapping), 0);       ADD_FUNCTION( "_decode_tiles", image_xcf_f__decode_tiles, tFunction, 0);       add_integer_constant( "PROP_END", PROP_END,0 );    add_integer_constant( "PROP_COLORMAP", PROP_COLORMAP, 0 );    add_integer_constant( "PROP_ACTIVE_LAYER", PROP_ACTIVE_LAYER, 0 );    add_integer_constant( "PROP_ACTIVE_CHANNEL", PROP_ACTIVE_CHANNEL, 0 );    add_integer_constant( "PROP_SELECTION", PROP_SELECTION, 0 );
pike.git/src/modules/Image/encodings/xcf.c:1484:    add_integer_constant( "GRAYA_GIMAGE", GRAYA_GIMAGE, 0 );    add_integer_constant( "INDEXED_GIMAGE", INDEXED_GIMAGE, 0 );    add_integer_constant( "INDEXEDA_GIMAGE", INDEXEDA_GIMAGE, 0 );      #define STRING(X) s_##X = make_shared_binary_string(#X,sizeof( #X )-sizeof(""))   #include "xcf_constant_strings.h"   #undef STRING       start_new_program();    ADD_STORAGE( struct substring ); -  ADD_FUNCTION("cast", f_substring_cast, tFunc(tStr,tMix), 0); +  ADD_FUNCTION("cast", f_substring_cast, tFunc(tStr,tStr), ID_PRIVATE);    ADD_FUNCTION("`[]", f_substring_index, tFunc(tInt,tInt), 0);    ADD_FUNCTION("get_short", f_substring_get_short, tFunc(tInt,tInt), 0 );    ADD_FUNCTION("get_ushort", f_substring_get_ushort, tFunc(tInt,tInt), 0 );    ADD_FUNCTION("get_int", f_substring_get_int, tFunc(tInt,tInt), 0 );    ADD_FUNCTION("get_uint", f_substring_get_uint, tFunc(tInt,tInt), 0 );    ADD_FUNCTION("_sprintf",f_substring__sprintf, tFunc(tInt tMapping,tMix), 0);      /* set_init_callback(init_substring); */    set_exit_callback(free_substring);    substring_program = end_program();   }       - void exit_image_xcf() + void exit_image_xcf(void)   {   #define STRING(X) free_string(s_##X)   #include "xcf_constant_strings.h"   #undef STRING    free_program( substring_program );   }