image-resolution.cpp revision d2ac881b8a3bc4613547b9173681ff1752eaa0e2
/*
* 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
#ifdef HAVE_EXIF
#define IR_TRY_EXIF 1
#endif
#define IR_TRY_EXIV 0
#ifdef HAVE_JPEG
#define IR_TRY_JFIF 1
#endif
namespace Inkscape {
namespace Extension {
namespace Internal {
ok_ = false;
if (!ok_) {
}
if (!ok_) {
}
if (!ok_) {
}
}
bool ImageResolution::ok() const {
return ok_;
}
double ImageResolution::x() const {
return x_;
}
double ImageResolution::y() const {
return y_;
}
#if IR_TRY_PNG
#include <png.h>
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
#include <math.h>
#include <libexif/exif-data.h>
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
#include <jpeglib.h>
#include <setjmp.h>
}
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;
}
}
}
#else
// Dummy implementation
void ImageResolution::readjfif(char const *) {
}
#endif
}
}
}