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

version» Context lines:

pike.git/src/modules/Image/encodings/xbm.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.   */    - #define NO_PIKE_SHORTHAND -  +    #include "global.h"   #include "image_machine.h"      #include "interpret.h"   #include "svalue.h"   #include "object.h"   #include "program.h"   #include "pike_error.h"   #include "mapping.h"   #include "stralloc.h"
pike.git/src/modules/Image/encodings/xbm.c:26:            extern struct program *image_colortable_program;   extern struct program *image_program;      /*   **! module Image   **! submodule XBM   **! + **! Decode and encode X BitMap images. + **! + **! This is a monochrome format historically used in the X Window + **! System. It is a plain text image format, mainly used for storing + **! cursor and icon bitmaps used in the X GUI. The XBM format was + **! officially deprecated in 1989, replaced with the XPM format.   */         #define SWAP_S(x) ((unsigned short)((((x)&0x00ff)<<8) | ((x)&0xff00)>>8))   #define SWAP_L(x) (SWAP_S((x)>>16)|SWAP_S((x)&0xffff)<<16)      struct buffer   {    size_t len;    char *str;
pike.git/src/modules/Image/encodings/xbm.c:108:    if(height <= 0)    Pike_error("This is not a XBM image!\n");       if(!buf_search( b, '{' ))    Pike_error("This is not a XBM image!\n");          push_int( width );    push_int( height );    io = clone_object( image_program, 2 ); -  dest = ((struct image *)get_storage(io, image_program))->img; +  dest = ((struct image*)get_storage(io, image_program))->img;    /* .. the code below asumes black if the read fails.. */    for(y=0; y<height; y++)    {    int next_byte, cnt;    for(x=0; x<width;)    {    if(buf_search( b, 'x' ))    {    next_byte = (hextoint(buf_getc( b ))*0x10) | hextoint(buf_getc( b ));    for(cnt=0; cnt<8&&x<width; cnt++,x++)
pike.git/src/modules/Image/encodings/xbm.c:133:    }    } else    Pike_error("This is not a XBM image!\n");    }    }    return io;   }      static struct pike_string *save_xbm( struct image *i, struct pike_string *name )   { -  dynamic_buffer buf; +  struct byte_buffer buf;    char size[32];    int x, y, first=-1;    - #define ccat( X ) low_my_binary_strcat( X, (sizeof(X)-sizeof("")), &buf ); + #define ccat( X ) buffer_memcpy(&buf, X, (sizeof(X)-sizeof("")))      #define cname() do{ \    if(name) \ -  low_my_binary_strcat( name->str, name->len, &buf ); \ +  buffer_memcpy( &buf, name->str, name->len ); \    else \    ccat( "image" ); \    } while(0) \            #define OUTPUT_BYTE(X) do{ \    if(!++first) \    sprintf( size, " 0x%02x", (X) ); \    else \    sprintf( size, ",%s0x%02x", (first%12?" ":"\n "), (X) ); \    (X)=0; \ -  low_my_binary_strcat( size, strlen(size), &buf ); \ +  buffer_add_str( &buf, size ); \    } while(0)       -  initialize_buf(&buf); +  buffer_init(&buf);    ccat( "#define "); cname(); ccat( "_width " );    sprintf( size, "%"PRINTPIKEINT"d\n", i->xsize ); -  low_my_binary_strcat( size, strlen(size), &buf ); +  buffer_add_str( &buf, size );       ccat( "#define "); cname(); ccat( "_height " );    sprintf( size, "%"PRINTPIKEINT"d\n", i->ysize ); -  low_my_binary_strcat( size, strlen(size), &buf ); +  buffer_add_str( &buf, size );       ccat( "static char " ); cname(); ccat( "_bits[] = {\n" );       for(y=0; y<i->ysize; y++)    {    rgb_group *p = i->img+y*i->xsize;    int next_byte = 0;    for(x=0; x<i->xsize; x++)    {    if((p->r || p->g || p->b ))    next_byte |= (1<<(x%8));    if((x % 8) == 7)    OUTPUT_BYTE( next_byte );    p++;    }    if(i->xsize%8)    OUTPUT_BYTE( next_byte );    }    ccat( "};\n" ); -  return low_free_buf(&buf); +  return buffer_finish_pike_string(&buf);   }            /*   **! method object decode(string data)   **! Decodes a XBM image.   **!   **! note   **! Throws upon error in data.   */   static void image_xbm_decode( INT32 args )   {    struct pike_string *data;    struct object *o; -  get_all_args( "Image.XBM.decode", args, "%S", &data ); +  get_all_args( NULL, args, "%S", &data );    o = load_xbm( data );    pop_n_elems(args);    push_object( o );   }         /*   **! method object _decode(string data)   **! method object _decode(string data, mapping options)   **! Decodes a XBM image to a mapping.
pike.git/src/modules/Image/encodings/xbm.c:237:   static struct pike_string *param_fg;   static struct pike_string *param_bg;   static struct pike_string *param_invert;   static void image_xbm__decode( INT32 args )   {    struct array *fg = NULL;    struct array *bg = NULL;    int invert=0, ele;    struct pike_string *data;    struct object *i=NULL, *a; -  get_all_args( "Image.XBM.decode", args, "%S", &data ); +  get_all_args( NULL, args, "%S", &data );          if (args>1)    {    if (TYPEOF(Pike_sp[1-args]) != PIKE_T_MAPPING)    Pike_error("Image.XBM._decode: illegal argument 2\n");       push_svalue(Pike_sp+1-args);    ref_push_string(param_fg);    f_index(2);
pike.git/src/modules/Image/encodings/xbm.c:334:    i = clone_object( image_program, 5 );    ref_push_object( i );    push_int( fg->item[0].u.integer );    push_int( fg->item[1].u.integer );    push_int( fg->item[2].u.integer );       apply( i, "paste_alpha_color", 4 );    }       pop_n_elems(args); -  push_constant_text( "alpha" ); +  push_static_text( "alpha" );    push_object( a ); -  push_constant_text( "image" ); +  push_static_text( "image" );    if(i)    push_object( i );    else    push_int( 0 );    f_aggregate_mapping(4);   }            
pike.git/src/modules/Image/encodings/xbm.c:371:      static struct pike_string *param_name;   void image_xbm_encode( INT32 args )   {    struct image *img = NULL;    struct pike_string *name = NULL, *buf;    if (!args)    Pike_error("Image.XBM.encode: too few arguments\n");       if (TYPEOF(Pike_sp[-args]) != PIKE_T_OBJECT || -  !(img=(struct image*) -  get_storage(Pike_sp[-args].u.object,image_program))) +  !(img=get_storage(Pike_sp[-args].u.object,image_program)))    Pike_error("Image.XBM.encode: illegal argument 1\n");       if (!img->img)    Pike_error("Image.XBM.encode: no image\n");       if (args>1)    {    if (TYPEOF(Pike_sp[1-args]) != PIKE_T_MAPPING)    Pike_error("Image.XBM.encode: illegal argument 2\n");