/*
* Authors:
* Daniel Wagenaar <daw@caltech.edu>
*
* Copyright (C) 2012 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "image-resolution.h"
#include <png.h>
#ifdef HAVE_EXIF
#include <math.h>
#include <libexif/exif-data.h>
#endif
#define IR_TRY_EXIV 0
#ifdef HAVE_JPEG
#include <jpeglib.h>
#include <setjmp.h>
#endif
#ifdef WITH_IMAGE_MAGICK
#include <Magick++.h>
#endif
#define noIMAGE_RESOLUTION_DEBUG
#ifdef IMAGE_RESOLUTION_DEBUG
g_print(f, ## a); \
g_print("\n"); \
}
#else
#endif
namespace Inkscape {
namespace Extension {
namespace Internal {
ok_ = false;
if (!ok_) {
}
if (!ok_) {
}
if (!ok_) {
}
if (!ok_) {
readmagick(fn);
}
}
return ok_;
}
double ImageResolution::x() const {
return x_;
}
double ImageResolution::y() const {
return y_;
}
#if IR_TRY_PNG
return false;
}
return false;
}
return true;
}
// Implementation using libpng
if (!fp)
return;
if (!haspngheader(fp)) {
return;
}
if (!png_ptr)
return;
if (!info_ptr) {
png_destroy_read_struct(&png_ptr, 0, 0);
return;
}
return;
}
debug("PNG_INCH_CONVERSIONS_SUPPORTED");
ok_ = true;
}
#else
debug("PNG_RESOLUTION_METER");
int unit_type;
// FIXME: png_get_pHYs() fails to return expected values
// with clang (based on LLVM 3.2svn) from Xcode 4.6.3 (OS X 10.7.5)
if (unit_type == PNG_RESOLUTION_METER) {
ok_ = true;
}
#endif
if (ok_) {
} else {
debug("FAILED");
}
}
#else
// Dummy implementation
}
#endif
#if IR_TRY_EXIF
case EXIF_FORMAT_BYTE: {
}
case EXIF_FORMAT_SHORT: {
}
case EXIF_FORMAT_LONG: {
}
case EXIF_FORMAT_RATIONAL: {
return double(r.numerator) / double(r.denominator);
}
case EXIF_FORMAT_SBYTE: {
}
case EXIF_FORMAT_SSHORT: {
}
case EXIF_FORMAT_SLONG: {
}
case EXIF_FORMAT_SRATIONAL: {
return double(r.numerator) / double(r.denominator);
}
case EXIF_FORMAT_FLOAT: {
}
case EXIF_FORMAT_DOUBLE: {
}
default: {
return nan(0);
}
}
}
// Implementation using libexif
if (!ed)
return;
if (unit) {
if ( u == 3 ) {
x_ *= 2.54;
y_ *= 2.54;
}
}
ok_ = true;
}
if (ok_) {
} else {
debug("FAILED");
}
}
#else
// Dummy implementation
}
#endif
#if IR_TRY_EXIV
return;
image->readMetadata();
return;
bool havex = false;
bool havey = false;
bool haveunit = false;
int unit;
if (ok_)
break;
if ( i->tag() == 0x011a ) {
// X Resolution
havex = true;
} else if ( i->tag() == 0x011b ) {
// Y Resolution
havey = true;
} else if ( i->tag() == 0x0128 ) {
}
}
if (haveunit) {
if ( unit == 3 ) {
x_ *= 2.54;
y_ *= 2.54;
}
}
if (ok_) {
} else {
debug("FAILED");
}
}
#else
// Dummy implementation
}
#endif
#if IR_TRY_JFIF
}
}
}
}
}
if (!ifd) {
return;
}
return;
}
debug("cinfo.[XY]_density");
ok_ = true;
ok_ = true;
}
/* According to http://www.jpeg.org/public/jfif.pdf (page 7):
* "Xdensity and Ydensity should always be non-zero".
* but in some cases, they are (see LP bug #1275443) */
ok_ = false;
}
}
if (ok_) {
} else {
debug("FAILED");
}
}
#else
// Dummy implementation
}
#endif
#ifdef WITH_IMAGE_MAGICK
debug("Trying image.read");
try {
return;
return;
}
debug("image.[xy]Resolution");
// TODO: find out why the hell the following convertion is necessary
if (type == "BMP") {
}
ok_ = true;
}
if (ok_) {
} else {
debug("FAILED");
debug("Using default Inkscape import resolution");
}
}
#else
// Dummy implementation
}
#endif /* WITH_IMAGE_MAGICK */
}
}
}