Author: post
Date: 2010-03-21 12:51:20 +0100 (Sun, 21 Mar 2010)
New Revision: 204

Modified:
   RawSpeed/TiffEntry.cpp
   RawSpeed/TiffEntry.h
   RawSpeed/TiffEntryBE.cpp
   RawSpeed/TiffIFD.cpp
   RawSpeed/TiffIFD.h
Log:
Added a few more Tiff helpers

Modified: RawSpeed/TiffEntry.cpp
===================================================================
--- RawSpeed/TiffEntry.cpp      2010-03-19 22:14:51 UTC (rev 203)
+++ RawSpeed/TiffEntry.cpp      2010-03-21 11:51:20 UTC (rev 204)
@@ -44,7 +44,7 @@
     data = f->getDataWrt(data_offset);
   }
 #ifdef _DEBUG
-  debug_intVal = 0xC0C4C014;
+  debug_intVal = 0xC0CAC01A;
   debug_floatVal = sqrtf(-1);
 
   if (type == TIFF_LONG || type == TIFF_SHORT)
@@ -57,6 +57,10 @@
 TiffEntry::~TiffEntry(void) {
 }
 
+bool TiffEntry::isInt() {
+  return (type == TIFF_LONG || type == TIFF_SHORT);
+}
+
 unsigned int TiffEntry::getInt() {
   if (!(type == TIFF_LONG || type == TIFF_SHORT))
     throw TiffParserException("TIFF, getInt: Wrong type encountered. Expected 
Long");
@@ -89,14 +93,29 @@
   return data[0];
 }
 
+bool TiffEntry::isFloat() {
+  return (type == TIFF_FLOAT || type == TIFF_DOUBLE || type == TIFF_RATIONAL 
|| type == TIFF_SRATIONAL || type == TIFF_LONG || type == TIFF_SHORT);
+}
+
 float TiffEntry::getFloat() {
-  if (!(type == TIFF_FLOAT || type == TIFF_DOUBLE))
+  if (!(type == TIFF_FLOAT || type == TIFF_DOUBLE || type == TIFF_RATIONAL || 
type == TIFF_SRATIONAL || type == TIFF_LONG || type == TIFF_SHORT))
     throw TiffParserException("TIFF, getFloat: Wrong type encountered. 
Expected Float");
   if (type == TIFF_DOUBLE) {
     return (float)*(double*)&data[0];
-  } else {
+  } else if (type == TIFF_FLOAT) {
     return *(float*)&data[0];
+  } else if (type == TIFF_LONG || type == TIFF_SHORT) {
+    return (float)getInt();
+  } else if (type == TIFF_RATIONAL) {
+    const unsigned int* t = getIntArray();
+    if (t[1])
+      return (float)t[0]/t[1];
+  } else if (type == TIFF_SRATIONAL) {
+    const int* t = (const int*)getIntArray();
+    if (t[1])
+      return (float)t[0]/t[1];
   }
+  return 0.0f;
 }
 
 string TiffEntry::getString() {

Modified: RawSpeed/TiffEntry.h
===================================================================
--- RawSpeed/TiffEntry.h        2010-03-19 22:14:51 UTC (rev 203)
+++ RawSpeed/TiffEntry.h        2010-03-21 11:51:20 UTC (rev 204)
@@ -80,6 +80,8 @@
   TiffDataType type;
   guint count;
   guint getDataOffset() const { return data_offset; }
+  bool isFloat();
+  bool isInt();
 protected:
   unsigned char* data;
   guint data_offset;

Modified: RawSpeed/TiffEntryBE.cpp
===================================================================
--- RawSpeed/TiffEntryBE.cpp    2010-03-19 22:14:51 UTC (rev 203)
+++ RawSpeed/TiffEntryBE.cpp    2010-03-21 11:51:20 UTC (rev 204)
@@ -46,7 +46,7 @@
     data = f->getDataWrt(data_offset);
   }
 #ifdef _DEBUG
-  debug_intVal = 0xC0C4C014;
+  debug_intVal = 0xC0CAC01A;
   debug_floatVal = sqrtf(-1);
 
   if (type == TIFF_LONG || type == TIFF_SHORT)

Modified: RawSpeed/TiffIFD.cpp
===================================================================
--- RawSpeed/TiffIFD.cpp        2010-03-19 22:14:51 UTC (rev 203)
+++ RawSpeed/TiffIFD.cpp        2010-03-21 11:51:20 UTC (rev 204)
@@ -71,6 +71,16 @@
   mSubIFD.clear();
 }
 
+bool TiffIFD::hasEntryRecursive(TiffTag tag) {
+  if (mEntry.find(tag) != mEntry.end())
+    return TRUE;
+  for (vector<TiffIFD*>::iterator i = mSubIFD.begin(); i != mSubIFD.end(); 
++i) {
+    if ((*i)->hasEntryRecursive(tag))
+      return TRUE;
+  }
+  return false;
+}
+
 vector<TiffIFD*> TiffIFD::getIFDsWithTag(TiffTag tag) {
   vector<TiffIFD*> matchingIFDs;
   if (mEntry.find(tag) != mEntry.end()) {
@@ -86,6 +96,18 @@
   return matchingIFDs;
 }
 
+TiffEntry* TiffIFD::getEntryRecursive(TiffTag tag) {
+  if (mEntry.find(tag) != mEntry.end()) {
+    return mEntry[tag];
+  }
+  for (vector<TiffIFD*>::iterator i = mSubIFD.begin(); i != mSubIFD.end(); 
++i) {
+    TiffEntry* entry = (*i)->getEntryRecursive(tag);
+    if (entry)
+      return entry;
+  }
+  return NULL;
+}
+
 TiffEntry* TiffIFD::getEntry(TiffTag tag) {
   if (mEntry.find(tag) != mEntry.end()) {
     return mEntry[tag];

Modified: RawSpeed/TiffIFD.h
===================================================================
--- RawSpeed/TiffIFD.h  2010-03-19 22:14:51 UTC (rev 203)
+++ RawSpeed/TiffIFD.h  2010-03-21 11:51:20 UTC (rev 204)
@@ -44,6 +44,8 @@
   vector<TiffIFD*> getIFDsWithTag(TiffTag tag);
   TiffEntry* getEntry(TiffTag tag);
   bool hasEntry(TiffTag tag);
+  bool hasEntryRecursive(TiffTag tag);
+  TiffEntry* getEntryRecursive(TiffTag tag);
   Endianness endian;
 protected:
   gint nextIFD;


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to