Esempio n. 1
0
my_image *load_image(boost::filesystem::path & aPath, int nbytes, bool for_bmp, bool inverse)
{
	if (aPath.extension().compare(".bmp") == 0) return loadBMP(  aPath, nbytes, inverse);
	if (aPath.extension().compare(".BMP") == 0) return loadBMP(  aPath, nbytes, inverse);
	if (aPath.extension().compare(".jpg") == 0) return loadJPEG( aPath, nbytes, for_bmp, inverse);
	if (aPath.extension().compare(".JPG") == 0) return loadJPEG( aPath, nbytes, for_bmp, inverse);
	if (aPath.extension().compare(".thb") == 0) return loadJPEG( aPath, nbytes, for_bmp, inverse);
	if (aPath.extension().compare(".THB") == 0) return loadJPEG( aPath, nbytes, for_bmp, inverse);
	if (aPath.extension().compare(".png") == 0) return loadPNG(  aPath, nbytes, for_bmp, inverse);
	if (aPath.extension().compare(".PNG") == 0) return loadPNG(  aPath, nbytes, for_bmp, inverse);
	if (aPath.extension().compare(".tif") == 0) return loadTIFF( aPath, nbytes, for_bmp, inverse);
	if (aPath.extension().compare(".TIF") == 0) return loadTIFF( aPath, nbytes, for_bmp, inverse);

	return NULL;
}
Esempio n. 2
0
RawImage::RawImage(const char *path) throw(ImageException) :
  _type(GL_RGB),
  _texId(0),
  _bytesPerPixel(0),
  _width(0),
  _height(0),
  _pixels(NULL)
{
  const char *filename = basename(const_cast<char *>(path));
  if (filename == NULL)
    throw ImageException("Invalid image filename: %s does not name a file.", filename);

  const char *ext = strrchr(filename, '.');
  if (ext == NULL)
    throw ImageException("Unknown image format.");

  FILE *file = fopen(path, "rb");
  if (file == NULL)
    throw ImageException("File not found: %s.", filename);

  try {
    if (strcasecmp(ext, ".bmp") == 0) {
      loadBMP(file);
    } else if (strcasecmp(ext, ".tga") == 0) {
      loadTGA(file);
    } else if (strcasecmp(ext, ".ppm") == 0) {
      loadPPM(file);
    } else if (strcasecmp(ext, ".jpg") == 0 || strcasecmp(ext, ".jpeg") == 0) {
      loadJPG(file);
    } else if (strcasecmp(ext, ".png") == 0) {
      loadPNG(file);
    } else if (strcasecmp(ext, ".tif") == 0 || strcasecmp(ext, ".tiff") == 0) {
      loadTIFF(path);
    } else {
      throw ImageException("Unknown image format: %s", ext);
    }
    fclose(file);
  } catch (ImageException& ex) {
    fclose(file);
    if (_pixels != NULL)
      delete _pixels;
    throw ex;
  }
}
Esempio n. 3
0
    /* Function to load a list of TIFF files, and stack them into a Volume image. */
    Volume loadTIFFStack(std::vector<std::string> filenames)
    {
      //Sort the filenames, as this order determines the stack
      std::sort(filenames.begin(), filenames.end());
  
      Volume vol;
      for (std::vector<std::string>::iterator fptr = filenames.begin(); fptr != filenames.end(); ++fptr)
	{
	  Image img = loadTIFF(*fptr);
	  if (vol.width == 0) {
	    vol.width = img.width;
	    vol.height = img.height;
	  }
      
	  if ((img.width != vol.width) || (img.height != vol.height))
	    throw std::runtime_error("Images have varying dimensions");
	  const size_t last_size = vol.pixels.size();
	  vol.pixels.resize(vol.pixels.size() + vol.width * vol.height);
	  std::copy(img.pixels.begin(), img.pixels.end(), vol.pixels.begin()+last_size);
	  ++vol.depth;
	}
      return vol;
    }