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

version» Context lines:

pike.git/src/modules/Image/encodings/pnm.c:64:         #define sp Pike_sp      extern struct program *image_colortable_program;   extern struct program *image_program;         /* internal read foo */    - static INLINE unsigned char getnext(struct pike_string *s,INT32 *pos) + static inline unsigned char getnext(struct pike_string *s,INT32 *pos)   {    if (*pos>=s->len) return 0;    if (s->str[(*pos)]=='#') -  for (;*pos<s->len && ISSPACE(((unsigned char *)(s->str))[*pos]);(*pos)++); +  for (;*pos<s->len && isspace(((unsigned char *)(s->str))[*pos]);(*pos)++);    return s->str[(*pos)++];   }    - static INLINE void skip_to_eol(struct pike_string *s,INT32 *pos) + static inline void skip_to_eol(struct pike_string *s,INT32 *pos)   {    for (;*pos<s->len && s->str[*pos]!=10;(*pos)++);   }    - static INLINE unsigned char getnext_skip_comment(struct pike_string *s,INT32 *pos) + static inline unsigned char getnext_skip_comment(struct pike_string *s,INT32 *pos)   {    unsigned char c;    while ((c=getnext(s,pos))=='#')    skip_to_eol(s,pos);    return c;   }    - static INLINE void skipwhite(struct pike_string *s,INT32 *pos) + static inline void skipwhite(struct pike_string *s,INT32 *pos)   {    while (*pos<s->len && -  ( ISSPACE(((unsigned char *)(s->str))[*pos]) || +  ( isspace(((unsigned char *)(s->str))[*pos]) ||    s->str[*pos]=='#'))    getnext_skip_comment(s,pos);   }    - static INLINE INT32 getnextnum(struct pike_string *s,INT32 *pos) + static inline INT32 getnextnum(struct pike_string *s,INT32 *pos)   {    INT32 i;    skipwhite(s,pos);    i=0;    while (*pos<s->len &&    s->str[*pos]>='0' && s->str[*pos]<='9')    {    i=(i*10)+s->str[*pos]-'0';    getnext(s,pos);    }
pike.git/src/modules/Image/encodings/pnm.c:145:    if (getnext(s,&pos)!='P')    Pike_error("Image.PNM.decode(): given string is not a pnm file\n");    type=getnext(s,&pos);    if (type<'1'||type>'6')    Pike_error("Image.PNM.decode(): given pnm data has illegal or unknown type\n");    x=getnextnum(s,&pos);    y=getnextnum(s,&pos);    if (x<=0||y<=0)    Pike_error("Image.PNM.decode(): given pnm data has illegal size\n");    if (type=='3'||type=='2'||type=='6'||type=='5') +  {    maxval=getnextnum(s,&pos); -  +  if (maxval==0) +  Pike_error("Image.PNM.decode(): Color maxvalue was 0.\n"); +  }       push_int(x);    push_int(y);       o=clone_object(image_program,2); -  new=(struct image*)get_storage(o,image_program); +  new=get_storage(o,image_program);    if (!new)    Pike_error("Image.PNM.decode(): cloned image object isn't an image (internal)\n");       if (type=='1'||type=='2'||type=='3')    {    skipwhite(s,&pos);    }    else    {   /* skip_to_eol(s,&pos); */
pike.git/src/modules/Image/encodings/pnm.c:181:    }    d=new->img;    n=x*y;    i=0;       nx=x;       if (type=='6' && maxval==255 && sizeof(rgb_group)==3) /* optimize */    {    if (pos<s->len) -  MEMCPY(d,s->str+pos,MINIMUM(n*3,s->len-pos)); +  memcpy(d,s->str+pos,MINIMUM(n*3,s->len-pos));    }    else while (n--)    {    switch (type)    {    case '1':    c=getnextnum(s,&pos);    d->r=d->g=d->b=    (unsigned char)~(c*255);    break;
pike.git/src/modules/Image/encodings/pnm.c:272:   void img_pnm_encode_P1(INT32 args) /* ascii PBM */   {    char buf[80];    struct pike_string *a,*b;    struct image *img = NULL;    unsigned char *c;    int x,y;    rgb_group *s;       if (args<1 || 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.PNM.encode_P1(): Illegal arguments\n");    if (!img->img)    Pike_error("Image.PNM.encode_P1(): Given image is empty\n");       sprintf(buf,"P1\n%"PRINTPIKEINT"d %"PRINTPIKEINT"d\n",img->xsize,img->ysize);    a=make_shared_string(buf);       y=img->ysize;    s=img->img;    c=(unsigned char*)((b=begin_shared_string((img->xsize*2)*
pike.git/src/modules/Image/encodings/pnm.c:314:   void img_pnm_encode_P2(INT32 args) /* ascii PGM */   {    char buf[80];    struct image *img = NULL;    int y,x;    rgb_group *s;    int n;    struct object *o = NULL;       if (args<1 || TYPEOF(sp[-args]) != T_OBJECT || -  !(img=(struct image*)get_storage((o=sp[-args].u.object),image_program))) +  !(img=get_storage((o=sp[-args].u.object),image_program)))    Pike_error("Image.PNM.encode_P2(): Illegal arguments\n");    if (!img->img)    Pike_error("Image.PNM.encode_P2(): Given image is empty\n");       add_ref(o);    pop_n_elems(args);       sprintf(buf,"P2\n%"PRINTPIKEINT"d %"PRINTPIKEINT"d\n255\n",img->xsize,img->ysize);    push_text(buf);    n=1;
pike.git/src/modules/Image/encodings/pnm.c:354:   void img_pnm_encode_P3(INT32 args) /* ascii PPM */   {    char buf[80];    struct image *img = NULL;    int y,x;    rgb_group *s;    int n;    struct object *o = NULL;       if (args<1 || TYPEOF(sp[-args]) != T_OBJECT || -  !(img=(struct image*)get_storage((o=sp[-args].u.object),image_program))) +  !(img=get_storage((o=sp[-args].u.object),image_program)))    Pike_error("Image.PNM.encode_P3(): Illegal arguments\n");    if (!img->img)    Pike_error("Image.PNM.encode_P3(): Given image is empty\n");       add_ref(o);    pop_n_elems(args);       sprintf(buf,"P3\n%"PRINTPIKEINT"d %"PRINTPIKEINT"d\n255\n",img->xsize,img->ysize);    push_text(buf);    n=1;
pike.git/src/modules/Image/encodings/pnm.c:394:   void img_pnm_encode_P4(INT32 args) /* binary PBM */   {    char buf[80];    struct pike_string *a,*b;    struct image *img=NULL;    unsigned char *c;    int y,x,bit;    rgb_group *s;       if (args<1 || 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.PNM.encode_P4(): Illegal arguments\n");    if (!img->img)    Pike_error("Image.PNM.encode_P4(): Given image is empty\n");       sprintf(buf,"P4\n%"PRINTPIKEINT"d %"PRINTPIKEINT"d\n",img->xsize,img->ysize);    a=make_shared_string(buf);       y=img->ysize;    s=img->img;   
pike.git/src/modules/Image/encodings/pnm.c:439:   void img_pnm_encode_P5(INT32 args) /* binary PGM */   {    char buf[80];    struct pike_string *a,*b;    struct image *img=NULL;    unsigned char *c;    int n;    rgb_group *s;       if (args<1 || 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.PNM.encode_P5(): Illegal arguments\n");    if (!img->img)    Pike_error("Image.PNM.encode_P5(): Given image is empty\n");       sprintf(buf,"P5\n%"PRINTPIKEINT"d %"PRINTPIKEINT"d\n255\n",img->xsize,img->ysize);    a=make_shared_string(buf);       n=img->xsize*img->ysize;    s=img->img;    c=(unsigned char*)((b=begin_shared_string(n))->str);
pike.git/src/modules/Image/encodings/pnm.c:470:    free_string(b);   }      void img_pnm_encode_P6(INT32 args)   {    char buf[80];    struct pike_string *a,*b;    struct image *img=NULL;       if (args<1 || 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.PNM.encode_P6(): Illegal arguments\n");    if (!img->img)    Pike_error("Image.PNM.encode_P6(): Given image is empty\n");       sprintf(buf,"P6\n%"PRINTPIKEINT"d %"PRINTPIKEINT"d\n255\n",img->xsize,img->ysize);    a=make_shared_string(buf);    if (sizeof(rgb_group)==3)    b=make_shared_binary_string((char*)img->img,    img->xsize*img->ysize*3);    else
pike.git/src/modules/Image/encodings/pnm.c:510:         void img_pnm_encode_ascii(INT32 args)   {    struct image *img=NULL;    rgb_group *s;    int n;    void (*func)(INT32);       if (args<1 || 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.PNM.encode_ascii(): Illegal arguments\n");    if (!img->img)    Pike_error("Image.PNM.encode_ascii(): Given image is empty\n");       func=img_pnm_encode_P1; /* PBM */    n=img->xsize*img->ysize;    s=img->img;    while (n--)    {    if (s->r!=s->g || s->g!=s->b)
pike.git/src/modules/Image/encodings/pnm.c:543:   }      void img_pnm_encode_binary(INT32 args)   {    struct image *img=NULL;    rgb_group *s;    int n;    void (*func)(INT32);       if (args<1 || 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.PNM.encode_binary(): Illegal arguments\n");    if (!img->img)    Pike_error("Image.PNM.encode_binary(): Given image is empty\n");       func=img_pnm_encode_P4; /* PBM */    n=img->xsize*img->ysize;    s=img->img;    while (n--)    {    if (s->r!=s->g || s->g!=s->b)