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

version» Context lines:

pike.git/src/modules/Image/pnm.c:1: - /* $Id: pnm.c,v 1.2 1997/03/17 03:08:02 hubbe Exp $ */ + /* $Id: pnm.c,v 1.3 1997/04/03 07:00:37 mirar Exp $ */    -  + /* + **! module Image + **! class image + */ +    #include "global.h"      #include <math.h>   #include <ctype.h>      #include "stralloc.h"   #include "global.h"   #include "types.h"   #include "pike_macros.h"   #include "object.h"
pike.git/src/modules/Image/pnm.c:134:    }    }    }    if (THIS->img) free(THIS->img);    THIS->xsize=new.xsize;    THIS->ysize=new.ysize;    THIS->img=new.img;    return NULL;   }    + /* + **! method string toppm() + **! Returns PPM (P6, binary pixmap) data from the + **! current image object. + **! returns PPM data + **! see also: frompnm, fromgif + **! + **! method object|string frompnm(string pnm) + **! method object|string fromppm(string pnm) + **! Reads a PNM (PBM, PGM or PPM in ascii or binary) + **! to the called image object. + **! + **! The method accepts P1 through P6 type of PNM data. + **! + **! "fromppm" is an alias for "frompnm". + **! returns the called object or a hint of what wronged. + **! arg string pnm + **! pnm data, as a string + **! see also: toppm, fromgif + */ +    void image_toppm(INT32 args)   {    char buf[80];    struct pike_string *a,*b;       pop_n_elems(args);    if (!THIS->img) { error("no image\n"); return; }    sprintf(buf,"P6\n%d %d\n255\n",THIS->xsize,THIS->ysize);    a=make_shared_string(buf);    b=make_shared_binary_string((char*)THIS->img,    THIS->xsize*THIS->ysize*3);    push_string(add_shared_strings(a,b));    free_string(a);    free_string(b);   }    -  +    void image_frompnm(INT32 args)   {    char *s;    if (args<1||    sp[-args].type!=T_STRING)    error("Illegal argument to image->frompnm()\n");    s=img_frompnm(sp[-args].u.string);    pop_n_elems(args);    if (!s) { push_object(THISOBJ); THISOBJ->refs++; }    else push_string(make_shared_string(s));   }