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

version» Context lines:

pike.git/src/modules/Image/encodings/x.c:2:   || 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.   */      /*   **! module Image   **! submodule X   **!   **! This submodule handles encoding and decoding of - **! the binary formats of X11. + **! the binary formats of X11, and can also be used for other + **! non-compressed image formats.   **! - **! - **! +    **! see also: Image, Image.Image, Image.Colortable   */   #include "global.h"      #include <math.h>   #include <ctype.h>      #include "stralloc.h"    - #include <sys/types.h> +    #include <sys/stat.h>   #ifdef HAVE_NETINET_IN_H   #include <netinet/in.h>   #endif   #ifdef HAVE_SYS_SOCKET_H   #include <sys/socket.h>   #endif   #ifdef HAVE_WINSOCK2_H   #include <winsock2.h>   #elif defined(HAVE_WINSOCK_H)
pike.git/src/modules/Image/encodings/x.c:138:    unsigned char *d;    struct pike_string *dest;    ptrdiff_t x,y;    rgb_group *s,*tmp=NULL;    int swap_bytes=0;       if (args<10)    Pike_error("Image.X.encode_truecolor: too few arguments (expected 10 arguments)\n");       if (TYPEOF(sp[-args]) != T_OBJECT || -  !(img=(struct image*)get_storage(sp[-args].u.object,image_program))) +  !(img=get_storage(sp[-args].u.object,image_program)))    Pike_error("Image.X.encode_truecolor: illegal argument 1 (expected image object)\n");    if (args>10)    if (TYPEOF(sp[10-args]) != T_OBJECT || -  !(nct=(struct neo_colortable*) -  get_storage(sp[10-args].u.object,image_colortable_program))) +  !(nct=get_storage(sp[10-args].u.object,image_colortable_program)))    Pike_error("Image.X.encode_truecolor: illegal argument 10 (expected colortable object)\n");       if (TYPEOF(sp[1-args]) != T_INT)    Pike_error("Image.X.encode_truecolor: illegal argument 2 (expected integer)\n");    else    bpp=sp[1-args].u.integer;       if (TYPEOF(sp[2-args]) != T_INT)    Pike_error("Image.X.encode_truecolor: illegal argument 3 (expected integer)\n");    else
pike.git/src/modules/Image/encodings/x.c:195:    else    bbits=sp[8-args].u.integer;       if (TYPEOF(sp[9-args]) != T_INT)    Pike_error("Image.X.encode_truecolor: illegal argument 10 (expected integer)\n");    else    bshift=sp[9-args].u.integer;       if (nct)    { -  tmp=(rgb_group*)xalloc(sizeof(rgb_group)*img->xsize*img->ysize +RGB_VEC_PAD); +  tmp=xalloc(sizeof(rgb_group)*img->xsize*img->ysize +RGB_VEC_PAD);    if (!image_colortable_map_image(nct,img->img,tmp,    img->xsize*img->ysize,img->xsize))    {    free(tmp);    Pike_error("Image.X.encode_truecolor(): called colortable is not initiated\n");    }    s=tmp;    }    else    s=img->img;
pike.git/src/modules/Image/encodings/x.c:252:    while (y--)    {    x=img->xsize;    while (x--)    d+=3,d[rpos]=s->r,d[gpos]=s->g,d[bpos]=s->b,    s++;    }    }    else    { -  MEMSET(d,0,( ( (img->xsize*bpp+alignbits-1) / alignbits ) +  memset(d,0,( ( (img->xsize*bpp+alignbits-1) / alignbits )    * alignbits*img->ysize +7 ) / 8);    while (y--)    {    x=img->xsize;    while (x--)    d+=Bpp,d[rpos]=s->r,d[gpos]=s->g,d[bpos]=s->b,    s++;    d+=linemod;    }    }
pike.git/src/modules/Image/encodings/x.c:291:       bit=0;       while (y--)    {    ptrdiff_t bp;       x=img->xsize;    while (x--) /* write bits from this line */    { -  register unsigned long b = +  unsigned long b =    ((((s->r&rfmask)>>rzshift)<<rfshift)|    (((s->g&gfmask)>>gzshift)<<gfshift)|    (((s->b&bfmask)>>bzshift)<<bfshift))<<bpshift;    bp = bpp;    while (bp>8-bit)    {    *d|=(unsigned char)(b>>(24+bit));    b<<=8-bit;    bp-=8-bit;    *(++d)=0; bit=0;
pike.git/src/modules/Image/encodings/x.c:361:    }       THREADS_DISALLOW();       if (nct) free(tmp);       pop_n_elems(args);    push_string(end_shared_string(dest));   }    - static INLINE void image_x_examine_mask(struct svalue *mask, + static void image_x_examine_mask(struct svalue *mask,    const char *what,    int *bits,int *shift)   {    unsigned long x;    if (TYPEOF(*mask) != T_INT)    Pike_error("Image.X.encode_truecolor_masks: illegal %s (expected integer)\n",what);       x=(unsigned long)mask->u.integer;    x&=(unsigned long)((INT32)-1); /* i hope this works... */    /* what i _really_ want to do is cast INT32 to unsigned INT32... */
pike.git/src/modules/Image/encodings/x.c:522:    dest2=begin_shared_string((img->xsize+linemod)*img->ysize);       s=(unsigned char*)(dest->str);    d=(unsigned char*)(dest2->str);       y=img->ysize;    while (y--)    {    if (translate)    { x=img->xsize; while (x--) *(d++)=translate[(*(s++))&mask]; } -  else MEMCPY(d,s,img->xsize),d+=img->xsize,s+=img->xsize; +  else memcpy(d,s,img->xsize),d+=img->xsize,s+=img->xsize;    m=linemod;    while (m--) *(d++)=0;    }       do_free_unlinked_pike_string (dest);    pop_n_elems(args);    push_string(end_shared_string(dest2));    }    while (0);   }
pike.git/src/modules/Image/encodings/x.c:598:    *d|=b>>24;    bit+=bp;    if (bit==8) *(++d)=0,bit=0;    }    }    else    {    x=img->xsize;    while (x--)    { -  b = ((*(s++))<<(32-bpp)) & 0xffffffff; +  b = (((unsigned long)*(s++))<<(32-bpp)) & 0xffffffff;    bp = bpp;    while (bp>8-bit)    {   #ifdef BITDEBUG    fprintf(stderr," b=%08x *d=%02x bp=%d bit=%d\n",b,*d,bp,bit);   #endif    *d|=(unsigned char)(b>>(24+bit));    b<<=8-bit;    bp-=8-bit;   #ifdef BITDEBUG
pike.git/src/modules/Image/encodings/x.c:742:    if (TYPEOF(sp[2-args]) != T_INT)    Pike_error("Image.X.encode_pseudocolor: illegal argument 3 (expected integer)\n");    if (TYPEOF(sp[3-args]) != T_INT)    Pike_error("Image.X.encode_pseudocolor: illegal argument 4 (expected integer)\n");    bpp=sp[1-args].u.integer;    alignbits=sp[2-args].u.integer;    vbpp=sp[3-args].u.integer;    if (!alignbits) alignbits=1;       if (TYPEOF(sp[-args]) != T_OBJECT || -  !(img=(struct image*)get_storage(sp[-args].u.object,image_program))) +  !(img=get_storage(sp[-args].u.object,image_program)))    Pike_error("Image.X.encode_pseudocolor: illegal argument 1 (expected image object)\n");    if (TYPEOF(sp[4-args]) != T_OBJECT || -  !(nct=(struct neo_colortable*) -  get_storage(sp[4-args].u.object,image_colortable_program))) +  !(nct=get_storage(sp[4-args].u.object,image_colortable_program)))    Pike_error("Image.X.encode_pseudocolor: illegal argument 4 (expected colortable object)\n");       if (args>5) {    if (TYPEOF(sp[5-args]) != T_STRING)    Pike_error("Image.X.encode_pseudocolor: illegal argument 6 (expected string)\n");    else if (sp[5-args].u.string->len!=((vbpp>8)?2:1)<<vbpp)    Pike_error("Image.X.encode_pseudocolor: illegal argument 6 "    "(expected translate string of length %d, not %ld)\n", -  ((vbpp>8)?2:1)<<vbpp, -  DO_NOT_WARN((long)sp[5-args].u.string->len)); +  ((vbpp>8)?2:1)<<vbpp, (long)sp[5-args].u.string->len);    else    translate=sp[5-args].u.string->str;    }    if ( vbpp==8 && bpp==8 && !((bpp*img->xsize)%alignbits) )    image_x_encode_pseudocolor_1byte_exact(args,img,nct,bpp,vbpp,alignbits,    (unsigned char*)translate);    else if (vbpp<=8)    image_x_encode_pseudocolor_1byte(args,img,nct,bpp,vbpp,alignbits,    (unsigned char*)translate);    else if (vbpp<=16)
pike.git/src/modules/Image/encodings/x.c:825:    bshift=sp[11-args].u.integer;       if (rshift>=bpp || rshift<0 ||    gshift>=bpp || gshift<0 ||    bshift>=bpp || bshift<0)    Pike_error("Image.X.decode_truecolor: illegal colorshifts\n");       if (args>12)    {    if (TYPEOF(sp[12-args]) != T_OBJECT || -  !(nct=(struct neo_colortable*) -  get_storage(sp[12-args].u.object,image_colortable_program))) +  !(nct=get_storage(sp[12-args].u.object,image_colortable_program)))    Pike_error("Image.X.decode_truecolor: illegal argument 13, expected colortable\n");    if (nct->type!=NCT_FLAT)    Pike_error("Image.X.decode_truecolor: illegal argument 13, expected colortable in flat mode\n");       if (nct->u.flat.numentries<(1<<rbits) ||    nct->u.flat.numentries<(1<<gbits) ||    nct->u.flat.numentries<(1<<bbits))    Pike_error("Image.X.decode_truecolor: colortable too small\n");    }   
pike.git/src/modules/Image/encodings/x.c:855:    struct image *img;       if (swapbytes)    rpos=Bpp-1-rpos,    gpos=Bpp-1-gpos,    bpos=Bpp-1-bpos;       push_int(width);    push_int(height);    o=clone_object(image_program,2); -  img=(struct image*)get_storage(o,image_program); +  img=get_storage(o,image_program);       d=img->img;    n=width*height;       if (nct)    while (n--)    {    d->r=nct->u.flat.entries[s[rpos]].color.r;    d->g=nct->u.flat.entries[s[gpos]].color.g;    d->b=nct->u.flat.entries[s[bpos]].color.b;
pike.git/src/modules/Image/encodings/x.c:901:    {    struct object *o;    struct image *img;    int rmask=(1<<rbits)-1;    int gmask=(1<<gbits)-1;    int bmask=(1<<bbits)-1;       push_int(width);    push_int(height);    o=clone_object(image_program,2); -  img=(struct image*)get_storage(o,image_program); +  img=get_storage(o,image_program);       if (nct)    {    d=img->img;    n=width*height;    while (n-- && len>=2)    {    int x;    if (swapbytes)    x=s[0]+(((int)s[1])<<8);
pike.git/src/modules/Image/encodings/x.c:1041:    struct object *ncto = NULL;       if (args<7)    Pike_error("Image.X.decode_pseudocolor: too few arguments\n");    if (TYPEOF(sp[-args]) != T_STRING)    Pike_error("Image.X.decode_pseudocolor: illegal argument 1\n");    for (i=1; i<6; i++)    if (TYPEOF(sp[i-args]) != T_INT)    Pike_error("Image.X.decode_pseudocolor: illegal argument %d\n",i+1);    if (TYPEOF(sp[6-args]) != T_OBJECT || -  !(nct=(struct neo_colortable*) -  get_storage(ncto=sp[6-args].u.object,image_colortable_program))) +  !(nct=get_storage(ncto=sp[6-args].u.object,image_colortable_program)))    Pike_error("Image.X.decode_pseudocolor: illegal argument 7\n");       if (nct->type!=NCT_FLAT)    /* fix me some other day */    Pike_error("Image.X.decode_pseudocolor: argument 7, colortable, needs to be a flat colortable\n");       add_ref(ps=sp[-args].u.string);    s=(unsigned char*)ps->str;    len = ps->len;    width=sp[1-args].u.integer;
pike.git/src/modules/Image/encodings/x.c:1070:    pop_n_elems(args);       if (bpp==8)    {    struct object *o;    struct image *img;       push_int(width);    push_int(height);    o=clone_object(image_program,2); -  img=(struct image*)get_storage(o,image_program); +  img=get_storage(o,image_program);       d=img->img;    n=width*height;    while (n--)    {    if (*s>=nct->u.flat.numentries)    *d=nct->u.flat.entries[0].color;    else    *d=nct->u.flat.entries[*s].color;    d++;
pike.git/src/modules/Image/encodings/x.c:1100:    push_object(o);    }    else if (bpp<8)    {    struct object *o;    struct image *img;       push_int(width);    push_int(height);    o=clone_object(image_program,2); -  img=(struct image*)get_storage(o,image_program); +  img=get_storage(o,image_program);       d=img->img;    m=height;    while (m--)    {    int bits=0, x=0, p;    n=width;    while (n--)    {    if(bits<bpp && len>0)
pike.git/src/modules/Image/encodings/x.c:1147:   void image_x_encode_bitmap(INT32 args)   {    int xs;    int i,j,left,bit,dbits;    struct pike_string *res;    unsigned char *d;    rgb_group *s;    struct image *img = NULL;       if (!args) -  SIMPLE_TOO_FEW_ARGS_ERROR("Image.X.encode_bitmap",1); +  SIMPLE_WRONG_NUM_ARGS_ERROR("encode_bitmap",1);       if (TYPEOF(sp[-args]) != T_OBJECT || -  !(img=(struct image*)get_storage(sp[-args].u.object,image_program))) -  SIMPLE_BAD_ARG_ERROR("Image.X.encode_bitmap",1,"image object"); +  !(img=get_storage(sp[-args].u.object,image_program))) +  SIMPLE_ARG_TYPE_ERROR("encode_bitmap",1,"Image.Image");       if (!img->img) -  SIMPLE_BAD_ARG_ERROR("Image.X.encode_bitmap",1,"image object with image"); +  SIMPLE_ARG_TYPE_ERROR("encode_bitmap",1,"image object with image");       xs=(img->xsize+7)>>3;       res=begin_shared_string(xs*img->ysize);    d=(unsigned char *)res->str;       s=img->img;       j=img->ysize;    while (j--)