Shadowrun: Awakened 29 September 2011 - Build 871
Functions
ppm.cpp File Reference
#include <stdio.h>
#include "machine.h"
#include "types.h"
#include "util.h"
#include "imageio.h"
#include "ppm.h"
Include dependency graph for ppm.cpp:

Go to the source code of this file.

Functions

static int getint (FILE *dfile)
int readppm (char *name, int *xres, int *yres, unsigned char **imgdata)

Function Documentation

static int getint ( FILE *  dfile) [static]

Definition at line 75 of file ppm.cpp.

Referenced by readppm().

                                {
  char ch[200];
  int i;
  int num;

  num=0; 
  while (num==0) {
    fscanf(dfile, "%s", ch);
      while (ch[0]=='#') {
        fgets(ch, 200, dfile);
      }
    num=sscanf(ch, "%d", &i);
  }
  return i;
}
int readppm ( char *  name,
int *  xres,
int *  yres,
unsigned char **  imgdata 
)

Definition at line 91 of file ppm.cpp.

References getint(), IMAGEBADFILE, IMAGENOERR, IMAGEREADERR, IMAGEUNSUP, and rt_getmem().

Referenced by readimage().

                                                                          {
  char data[200];  
  FILE * ifp;
  int i, bytesread;
  int datasize;
 
  ifp=fopen(name, "r");  
  if (ifp==NULL) {
    return IMAGEBADFILE; /* couldn't open the file */
  }
  fscanf(ifp, "%s", data);
 
  if (strcmp(data, "P6")) {
     fclose(ifp);
     return IMAGEUNSUP; /* not a format we support */
  }

  *xres=getint(ifp);
  *yres=getint(ifp);
      i=getint(ifp); /* eat the maxval number */
  fread(&i, 1, 1, ifp); /* eat the newline */ 
  datasize = 3 * (*xres) * (*yres);

  *imgdata=(unsigned char *)rt_getmem(datasize); 

  bytesread=fread(*imgdata, 1, datasize, ifp);   

  fclose(ifp);

  if (bytesread != datasize) 
    return IMAGEREADERR;
  
  return IMAGENOERR;
}

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net