#include <msp/io/file.h>
#include <msp/io/memory.h>
#endif
-#include <msp/core/except.h>
#include "image.h"
using namespace std;
info = png_create_info_struct(png);
if(setjmp(png_jmpbuf(png)))
- throw Exception("Error loading PNG image");
+ throw bad_image_data("PNG error");
png_set_read_fn(png, &in, read);
png_read_info(png, info);
priv.width = width;
priv.height = height;
if(depth!=8)
- throw Exception("Only 8-bit PNG images are supported");
+ throw unsupported_image_format("depth!=8");
switch(color)
{
case PNG_COLOR_TYPE_PALETTE: priv.fmt = COLOR_INDEX; break;
case PNG_COLOR_TYPE_GRAY_ALPHA: priv.fmt = LUMINANCE_ALPHA; break;
case PNG_COLOR_TYPE_RGB: priv.fmt = RGB; break;
case PNG_COLOR_TYPE_RGB_ALPHA: priv.fmt = RGBA; break;
- default: throw Exception("Unknown color type");
+ default: throw unsupported_image_format("unknown color type");
}
unsigned nchans = png_get_channels(png, info);
priv(new Private)
{
#if !defined(WITH_DEVIL) && !defined(WITH_LIBPNG)
- throw Exception("Image needs either DevIL or libpng support");
+ throw runtime_error("no image support");
#endif
}
ensure_devil_image(priv->id);
ilBindImage(priv->id);
if(!ilLoadImage(const_cast<char *>(fn.c_str())))
- throw Exception("Error loading image "+fn);
+ throw bad_image_data("IL error");
#else
- throw Exception("Not a PNG image and DevIL support not compiled in");
+ throw unsupported_image_format("DevIL needed for non-PNG images");
#endif
}
(void)fn;
ensure_devil_image(priv->id);
ilBindImage(priv->id);
if(!ilLoadL(IL_TYPE_UNKNOWN, const_cast<void *>(data), size))
- throw Exception("Error loading image from memory");
+ throw bad_image_data("IL error");
#else
- throw Exception("Not a PNG image and DevIL support not compiled in");
+ throw unsupported_image_format("DevIL needed for non-PNG images");
#endif
}
(void)data;
case IL_RGBA: return RGBA;
case IL_BGR: return BGR;
case IL_BGRA: return BGRA;
- default: throw InvalidParameterValue("Unknown pixel format in image");
+ // XXX bad, should throw when loading
+ default: throw invalid_argument("unknown pixel format in image");
}
}
#endif