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

Go to the source code of this file.

Functions

static int fakeimage (char *name, int *xres, int *yres, unsigned char **imgdata)
int readimage (rawimage *img)

Function Documentation

static int fakeimage ( char *  name,
int *  xres,
int *  yres,
unsigned char **  imgdata 
) [static]

Definition at line 78 of file imageio.cpp.

References IMAGENOERR, and rt_getmem().

Referenced by readimage().

                                                                             {
  int i, imgsize;

  fprintf(stderr, "Error loading image %s.  Faking it.\n", name);
   
  *xres = 2;
  *yres = 2;
  imgsize = 3 * (*xres) * (*yres);
  *imgdata = (unsigned char *)rt_getmem(imgsize);
  for (i=0; i<imgsize; i++) {
    (*imgdata)[i] = 255;
  }

  return IMAGENOERR;
}
int readimage ( rawimage img)

Definition at line 95 of file imageio.cpp.

References rawimage::bpp, rawimage::data, fakeimage(), IMAGENOERR, IMAGEREADERR, IMAGEUNSUP, rawimage::name, readjpeg(), readppm(), readtga(), rawimage::xres, and rawimage::yres.

Referenced by LoadImage().

                              {
  int rc;
  int xres, yres;
  unsigned char * imgdata;
  char * name = img->name;

  if (strstr(name, ".ppm")) { 
    rc = readppm(name, &xres, &yres, &imgdata);
  }
  else if (strstr(name, ".tga")) {
    rc = readtga(name, &xres, &yres, &imgdata);
  }
  else if (strstr(name, ".jpg")) {
    rc = readjpeg(name, &xres, &yres, &imgdata);
  }
  else if (strstr(name, ".gif")) {
    rc = IMAGEUNSUP; 
  }
  else if (strstr(name, ".png")) {
    rc = IMAGEUNSUP; 
  }
  else if (strstr(name, ".tiff")) {
    rc = IMAGEUNSUP; 
  }
  else if (strstr(name, ".rgb")) {
    rc = IMAGEUNSUP; 
  }
  else if (strstr(name, ".xpm")) {
    rc = IMAGEUNSUP; 
  }
  else {
    rc = readppm(name, &xres, &yres, &imgdata);
  } 

  switch (rc) {
    case IMAGEREADERR:
      fprintf(stderr, "Short read encountered while loading image %s\n", name);
      rc = IMAGENOERR; /* remap to non-fatal error */
      break;

    case IMAGEUNSUP:
      fprintf(stderr, "Cannot read unsupported image format for image %s\n", name);
      break;
  }    

  /* If the image load failed, create a tiny white colored image to fake it */ 
  /* this allows a scene to render even when a file can't be loaded */
  if (rc != IMAGENOERR) {
    rc = fakeimage(name, &xres, &yres, &imgdata);
  }

  /* If we succeeded in loading the image, return it. */
  if (rc == IMAGENOERR) { 
    img->xres = xres;
    img->yres = yres;
    img->bpp = 3;  
    img->data = imgdata;
  }

  return rc;
}

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