]> git.tdb.fi Git - libs/gui.git/blobdiff - source/gbase/image.cpp
Exception changes
[libs/gui.git] / source / gbase / image.cpp
index 24b760e0aaedb33de123b495bcdb9ac52e79910b..3360b72e7610d0cdf68eb8d9e75a6993682e1a91 100644 (file)
@@ -6,7 +6,6 @@
 #include <msp/io/file.h>
 #include <msp/io/memory.h>
 #endif
-#include <msp/core/except.h>
 #include "image.h"
 
 using namespace std;
@@ -64,7 +63,7 @@ void load_png(IO::Base &in, Image::Private &priv)
                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);
@@ -76,7 +75,7 @@ void load_png(IO::Base &in, Image::Private &priv)
                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;
@@ -84,7 +83,7 @@ void load_png(IO::Base &in, Image::Private &priv)
                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);
@@ -133,7 +132,7 @@ Image::Image():
        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
 }
 
@@ -164,9 +163,9 @@ void Image::load_file(const string &fn)
                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;
@@ -187,9 +186,9 @@ void Image::load_memory(const void *data, unsigned size)
                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;
@@ -215,7 +214,8 @@ PixelFormat Image::get_format() const
                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