summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2010-12-12 16:45:52 +0100
committerTomas Bzatek <tbzatek@users.sourceforge.net>2010-12-12 16:45:52 +0100
commit0c518f173d0081f442a7647774bd7d8dd370a28c (patch)
tree70b75e718097d0c4e4e05bdb8e56880654e3ea82 /src
parent1d41b37da1a0f30205dae234e91af28c05e77127 (diff)
downloadcataract-0c518f173d0081f442a7647774bd7d8dd370a28c.tar.xz
jpeg-utils: Get rid of error handling macros
Diffstat (limited to 'src')
-rw-r--r--src/jpeg-utils.cpp170
1 files changed, 79 insertions, 91 deletions
diff --git a/src/jpeg-utils.cpp b/src/jpeg-utils.cpp
index 330b597..55e3442 100644
--- a/src/jpeg-utils.cpp
+++ b/src/jpeg-utils.cpp
@@ -43,7 +43,7 @@ get_exif (const gchar *filename)
try
{
- Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(filename);
+ Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open (filename);
g_assert (image.get() != 0);
image->readMetadata();
@@ -67,7 +67,7 @@ get_exif (const gchar *filename)
try {
val = exifData["Exif.Photo.DateTimeOriginal"].toString().c_str();
} catch (...) { }
- if ((! val) || (strlen (val) == 0))
+ if (! val || strlen (val) == 0)
try {
val = exifData["Exif.Image.DateTime"].toString().c_str();
} catch (...) { }
@@ -101,7 +101,7 @@ get_exif (const gchar *filename)
/* EXIF::Flash */
try {
long int val = exifData["Exif.Photo.Flash"].toLong();
- if ((val > 0) && ((val & 1) == 1))
+ if (val > 0 && (val & 1) == 1)
data->flash = g_strdup ("Flash fired");
else
data->flash = g_strdup ("--");
@@ -235,57 +235,55 @@ resize_image (const gchar *src, const gchar *dst,
gboolean thumbnail,
ThumbnailSquareType squared_thumbnail_type)
{
- #define ThrowWandException(wand) \
- { \
- gchar *description; \
- ExceptionType severity; \
- \
- description = MagickGetException (wand, &severity); \
- log_error ("Error converting image: %s %s %ld %s\n", GetMagickModule(), description); \
- description = (gchar*) MagickRelinquishMemory (description); \
- return FALSE; \
- }
-
- MagickBooleanType status;
MagickWand *magick_wand;
+ ExceptionType severity;
unsigned long w;
unsigned long h;
unsigned long amount;
+ gchar *description;
/* Read an image. */
magick_wand = NewMagickWand();
- status = MagickReadImage (magick_wand, src);
- if (status == MagickFalse)
- ThrowWandException (magick_wand);
-
+ if (MagickReadImage (magick_wand, src) == MagickFalse) {
+ description = MagickGetException (magick_wand, &severity);
+ log_error ("Error reading image: %s %s %ld %s\n", GetMagickModule(), description);
+ MagickRelinquishMemory (description);
+ return FALSE;
+ }
/* Don't resize if smaller than desired size */
- if (MagickGetImageWidth (magick_wand) > size_x || MagickGetImageHeight (magick_wand) > size_y) {
- /* Process thumbnail if required */
- if (thumbnail) {
- switch (squared_thumbnail_type) {
- case THUMBNAIL_SQUARE_TYPE_SIMPLE:
- w = MagickGetImageWidth (magick_wand);
- h = MagickGetImageHeight (magick_wand);
- amount = MAX (w, h) * SQUARED_SIMPLE_SHAVE_AMOUNT / 100;
- amount = MIN (w - 2*amount, h - 2*amount);
- MagickCropImage (magick_wand, amount, amount, (w - amount) / 2, (h - amount) / 2);
- break;
- default:
- break;
- }
- MagickThumbnailImage (magick_wand, size_x, size_y);
+ if (MagickGetImageWidth (magick_wand) > size_x ||
+ MagickGetImageHeight (magick_wand) > size_y)
+ {
+ /* Process thumbnail if required */
+ if (thumbnail) {
+ switch (squared_thumbnail_type) {
+ case THUMBNAIL_SQUARE_TYPE_SIMPLE:
+ w = MagickGetImageWidth (magick_wand);
+ h = MagickGetImageHeight (magick_wand);
+ amount = MAX (w, h) * SQUARED_SIMPLE_SHAVE_AMOUNT / 100;
+ amount = MIN (w - 2*amount, h - 2*amount);
+ MagickCropImage (magick_wand, amount, amount, (w - amount) / 2, (h - amount) / 2);
+ break;
+ default:
+ break;
}
- else
- MagickResizeImage (magick_wand, size_x, size_y, LanczosFilter, 1.0);
+ MagickThumbnailImage (magick_wand, size_x, size_y);
+ }
+ else
+ MagickResizeImage (magick_wand, size_x, size_y, LanczosFilter, 1.0);
}
MagickSetImageCompressionQuality (magick_wand, quality);
/* Write the image and destroy it. */
- status = MagickWriteImage (magick_wand, dst);
- if (status == MagickFalse)
- ThrowWandException (magick_wand);
+ if (MagickWriteImage (magick_wand, dst) == MagickFalse) {
+ description = MagickGetException (magick_wand, &severity);
+ log_error ("Error writing image: %s %s %ld %s\n", GetMagickModule(), description);
+ MagickRelinquishMemory (description);
+ return FALSE;
+ }
+
magick_wand = DestroyMagickWand (magick_wand);
return TRUE;
@@ -299,28 +297,21 @@ void
get_image_sizes (const gchar *img,
unsigned long *width, unsigned long *height)
{
- #define xThrowWandException(wand) \
- { \
- gchar *description; \
- ExceptionType severity; \
- \
- description = MagickGetException (wand, &severity); \
- log_error ("Error reading image info: %s %s %ld %s\n", GetMagickModule(), description); \
- description = (gchar*) MagickRelinquishMemory(description); \
- return; \
- }
-
- MagickBooleanType status;
MagickWand *magick_wand;
+ ExceptionType severity;
+ gchar *description;
*width = -1;
*height = -1;
/* Read an image. */
magick_wand = NewMagickWand();
- status = MagickPingImage (magick_wand, img);
- if (status == MagickFalse)
- xThrowWandException (magick_wand);
+ if (MagickPingImage (magick_wand, img) == MagickFalse) {
+ description = MagickGetException (magick_wand, &severity);
+ log_error ("Error reading image info: %s %s %ld %s\n", GetMagickModule(), description);
+ MagickRelinquishMemory(description);
+ return;
+ }
*width = MagickGetImageWidth (magick_wand);
*height = MagickGetImageHeight (magick_wand);
@@ -335,22 +326,19 @@ void
calculate_sizes (const unsigned long max_width, const unsigned long max_height,
unsigned long *width, unsigned long *height)
{
- if ((max_width > *width) && (max_height > *height))
+ if (max_width > *width && max_height > *height)
return;
double max_ratio = (double) max_width / (double) max_height;
double real_ratio = (double) *width / (double) *height;
- if ((*width > *height) && (max_ratio <= real_ratio))
- {
- *height = (unsigned long) (max_width / real_ratio);
- *width = max_width;
- }
- else
- {
- *width = (unsigned long) (max_height * real_ratio);
- *height = max_height;
- }
+ if (*width > *height && max_ratio <= real_ratio) {
+ *height = (unsigned long) (max_width / real_ratio);
+ *width = max_width;
+ } else {
+ *width = (unsigned long) (max_height * real_ratio);
+ *height = max_height;
+ }
}
@@ -361,44 +349,44 @@ calculate_sizes (const unsigned long max_width, const unsigned long max_height,
void
modify_exif (const gchar *filename, gboolean strip_thumbnail, const gchar *add_copyright)
{
- bool was_modified = false;
+ gboolean modified;
- if ((! strip_thumbnail) && (add_copyright == NULL))
+ if (! strip_thumbnail && add_copyright == NULL)
return;
- try
- {
- Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(filename);
- g_assert (image.get() != 0);
-
- image->readMetadata();
- Exiv2::ExifData &exifData = image->exifData();
- if (add_copyright) {
- exifData["Exif.Image.Copyright"] = add_copyright;
- image->iptcData()["Iptc.Application2.Copyright"] = add_copyright;
- was_modified = true;
- }
+ modified = FALSE;
+ try {
+ Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open (filename);
+ g_assert (image.get() != 0);
+
+ image->readMetadata();
+ Exiv2::ExifData &exifData = image->exifData();
+ if (add_copyright) {
+ exifData["Exif.Image.Copyright"] = add_copyright;
+ image->iptcData()["Iptc.Application2.Copyright"] = add_copyright;
+ modified = TRUE;
+ }
- if (strip_thumbnail && (! exifData.empty())) {
+ if (strip_thumbnail && ! exifData.empty()) {
#ifdef HAVE_EXIFTHUMB
- Exiv2::ExifThumb exifThumb(image->exifData());
- std::string thumbExt = exifThumb.extension();
+ Exiv2::ExifThumb exifThumb(image->exifData());
+ std::string thumbExt = exifThumb.extension();
#else
- std::string thumbExt = exifData.thumbnailExtension();
+ std::string thumbExt = exifData.thumbnailExtension();
#endif
- if (! thumbExt.empty()) {
+ if (! thumbExt.empty()) {
#ifdef HAVE_EXIFTHUMB
- exifThumb.erase();
+ exifThumb.erase();
#else
- exifData.eraseThumbnail();
+ exifData.eraseThumbnail();
#endif
- was_modified = true;
- }
- }
+ modified = TRUE;
+ }
+ }
- if (was_modified)
- image->writeMetadata();
+ if (modified)
+ image->writeMetadata();
}
catch (Exiv2::AnyError& e)
{