Shadowrun: Awakened 29 September 2011 - Build 871
Defines | Functions
imageio.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define IMAGEALLOCERR   3
#define IMAGEBADFILE   1
#define IMAGENOERR   0
#define IMAGEREADERR   4
#define IMAGEUNSUP   2

Functions

int readimage (rawimage *)

Define Documentation

#define IMAGEALLOCERR   3

Definition at line 70 of file imageio.h.

#define IMAGEBADFILE   1

Definition at line 68 of file imageio.h.

Referenced by readppm(), and readtga().

#define IMAGENOERR   0

Definition at line 67 of file imageio.h.

Referenced by fakeimage(), readimage(), readppm(), and readtga().

#define IMAGEREADERR   4

Definition at line 71 of file imageio.h.

Referenced by readimage(), readppm(), and readtga().

#define IMAGEUNSUP   2

Definition at line 69 of file imageio.h.

Referenced by readimage(), readjpeg(), readppm(), and readtga().


Function Documentation

int readimage ( rawimage )

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