image-resolution.cpp revision d0df615bc958478344759b7c24838541f3b2a38e
/*
* 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"
#define IR_TRY_PNG 1
#include <png.h>
#ifdef HAVE_EXIF
#include <math.h>
#include <libexif/exif-data.h>
#endif
#define IR_TRY_EXIV 0
#ifdef HAVE_JPEG
#define IR_TRY_JFIF 1
#include <jpeglib.h>
#include <setjmp.h>
#endif
#ifdef WITH_IMAGE_MAGICK
#include <Magick++.h>
#endif
namespace Inkscape {
namespace Extension {
namespace Internal {
ok_ = false;
if (!ok_) {
}
if (!ok_) {
}
if (!ok_) {
}
if (!ok_) {
readmagick(fn);
}
}
bool ImageResolution::ok() const {
return ok_;
}
double ImageResolution::x() const {
return x_;
}
double ImageResolution::y() const {
return y_;
}
#if IR_TRY_PNG
unsigned char header[8];
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;
}
int unit_type;
if (unit_type == PNG_RESOLUTION_METER) {
ok_ = true;
}
}
#else
// Dummy implementation
void ImageResolution::readpng(char const *) {
}
#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;
}
}
#else
// Dummy implementation
void ImageResolution::readexif(char const *) {
}
#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;
}
}
}
#else
// Dummy implementation
void ImageResolution::readexiv(char const *) {
}
#endif
#if IR_TRY_JFIF
}
static void irjfif_emit_message(j_common_ptr, int) {
}
static void irjfif_output_message(j_common_ptr) {
}
static void irjfif_format_message(j_common_ptr, char *) {
}
static void irjfif_reset(j_common_ptr) {
}
if (!ifd) {
return;
}
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
return;
}
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;
}
}
}
#else
// Dummy implementation
void ImageResolution::readjfif(char const *) {
}
#endif
#ifdef WITH_IMAGE_MAGICK
try {
return;
} catch (...) {
g_warning("ImageResolution::readmagick: Unknown error");
return;
}
// TODO: find out why the hell the following convertion is necessary
if (type == "BMP") {
}
ok_ = true;
}
}
#else
// Dummy implementation
void ImageResolution::readmagick(char const *) {
}
#endif /* WITH_IMAGE_MAGICK */
}
}
}