void TiffParser::parseData() { if (mInput->getSize() < 16) throw TiffParserException("Not a TIFF file (size too small)"); const unsigned char* data = mInput->getData(0, 4); if (data[0] != 0x49 || data[1] != 0x49) { tiff_endian = big; if (data[0] != 0x4D || data[1] != 0x4D) throw TiffParserException("Not a TIFF file (ID)"); if (data[3] != 42 && data[2] != 0x4f) // ORF sometimes has 0x4f, Lovely! throw TiffParserException("Not a TIFF file (magic 42)"); } else { tiff_endian = little; if (data[2] != 42 && data[2] != 0x52 && data[2] != 0x55) // ORF has 0x52, RW2 0x55 - Brillant! throw TiffParserException("Not a TIFF file (magic 42)"); } if (mRootIFD) delete mRootIFD; if (tiff_endian == host_endian) mRootIFD = new TiffIFD(); else mRootIFD = new TiffIFDBE(); uint32 nextIFD; data = mInput->getData(4, 4); if (tiff_endian == host_endian) { nextIFD = *(int*)data; } else { nextIFD = (unsigned int)data[0] << 24 | (unsigned int)data[1] << 16 | (unsigned int)data[2] << 8 | (unsigned int)data[3]; } while (nextIFD) { if (tiff_endian == host_endian) mRootIFD->mSubIFD.push_back(new TiffIFD(mInput, nextIFD)); else mRootIFD->mSubIFD.push_back(new TiffIFDBE(mInput, nextIFD)); if (mRootIFD->mSubIFD.size() > 100) throw TiffParserException("TIFF file has too many SubIFDs, probably broken"); nextIFD = mRootIFD->mSubIFD.back()->getNextIFD(); } }
void ThrowTPE(const char* fmt, ...) { va_list val; va_start(val, fmt); char buf[8192]; vsprintf_s(buf, 8192, fmt, val); va_end(val); _RPT1(0, "EXCEPTION: %s\n", buf); throw TiffParserException(buf); }
void TiffParserHeaderless::parseData(uint32 firstIfdOffset) { if (mInput->getSize() < 12) throw TiffParserException("Not a TIFF file (size too small)"); if (tiff_endian == host_endian) mRootIFD = new TiffIFD(); else mRootIFD = new TiffIFDBE(); uint32 nextIFD = firstIfdOffset; do { CHECKSIZE(nextIFD); if (tiff_endian == host_endian) mRootIFD->mSubIFD.push_back(new TiffIFD(mInput, nextIFD)); else mRootIFD->mSubIFD.push_back(new TiffIFDBE(mInput, nextIFD)); nextIFD = mRootIFD->mSubIFD.back()->getNextIFD(); } while (nextIFD); }
RawDecoder* TiffParser::getDecoder() { if (!mRootIFD) parseData(); vector<TiffIFD*> potentials; potentials = mRootIFD->getIFDsWithTag(DNGVERSION); /* Copy, so we can pass it on and not have it destroyed with ourselves */ TiffIFD* root = mRootIFD; if (!potentials.empty()) { // We have a dng image entry TiffIFD *t = potentials[0]; const unsigned char* c = t->getEntry(DNGVERSION)->getData(); if (c[0] > 1) throw TiffParserException("DNG version too new."); mRootIFD = NULL; return new DngDecoder(root, mInput); } potentials = mRootIFD->getIFDsWithTag(MAKE); if (!potentials.empty()) { // We have make entry for (vector<TiffIFD*>::iterator i = potentials.begin(); i != potentials.end(); ++i) { string make = (*i)->getEntry(MAKE)->getString(); TrimSpaces(make); string model = ""; if ((*i)->hasEntry(MODEL)) { model = (*i)->getEntry(MODEL)->getString(); TrimSpaces(model); } if (!make.compare("Canon")) { mRootIFD = NULL; return new Cr2Decoder(root, mInput); } if (!make.compare("FUJIFILM")) { mRootIFD = NULL; return new RafDecoder(root, mInput); } if (!make.compare("NIKON CORPORATION")) { mRootIFD = NULL; return new NefDecoder(root, mInput); } if (!make.compare("NIKON")) { mRootIFD = NULL; return new NefDecoder(root, mInput); } if (!make.compare("OLYMPUS IMAGING CORP.") || !make.compare("OLYMPUS CORPORATION") || !make.compare("OLYMPUS OPTICAL CO.,LTD") ) { mRootIFD = NULL; return new OrfDecoder(root, mInput); } if (!make.compare("SONY")) { mRootIFD = NULL; return new ArwDecoder(root, mInput); } if (!make.compare("PENTAX Corporation") || !make.compare("RICOH IMAGING COMPANY, LTD.")) { mRootIFD = NULL; return new PefDecoder(root, mInput); } if (!make.compare("PENTAX")) { mRootIFD = NULL; return new PefDecoder(root, mInput); } if (!make.compare("Panasonic") || !make.compare("LEICA")) { mRootIFD = NULL; return new Rw2Decoder(root, mInput); } if (!make.compare("SAMSUNG")) { mRootIFD = NULL; return new SrwDecoder(root, mInput); } if (!make.compare("Mamiya-OP Co.,Ltd.")) { mRootIFD = NULL; return new MefDecoder(root, mInput); } if (!make.compare("Kodak")) { mRootIFD = NULL; if (!model.compare("DCS560C")) return new Cr2Decoder(root, mInput); else return new DcrDecoder(root, mInput); } if (!make.compare("KODAK")) { mRootIFD = NULL; return new DcsDecoder(root, mInput); } if (!make.compare("EASTMAN KODAK COMPANY")) { mRootIFD = NULL; return new KdcDecoder(root, mInput); } if (!make.compare("SEIKO EPSON CORP.")) { mRootIFD = NULL; return new ErfDecoder(root, mInput); } if (!make.compare("Hasselblad")) { mRootIFD = NULL; return new ThreefrDecoder(root, mInput); } if (!make.compare("Leaf")) { mRootIFD = NULL; return new MosDecoder(root, mInput); } if (!make.compare("Phase One A/S")) { mRootIFD = NULL; return new MosDecoder(root, mInput); } } } // Last ditch effort to identify Leaf cameras that don't have a Tiff Make set potentials = mRootIFD->getIFDsWithTag(SOFTWARE); if (!potentials.empty()) { string software = potentials[0]->getEntry(SOFTWARE)->getString(); TrimSpaces(software); if (!software.compare("Camera Library")) { mRootIFD = NULL; return new MosDecoder(root, mInput); } } throw TiffParserException("No decoder found. Sorry."); return NULL; }
RawDecoder* TiffParser::getDecoder() { if (!mRootIFD) parseData(); vector<TiffIFD*> potentials; potentials = mRootIFD->getIFDsWithTag(DNGVERSION); /* Copy, so we can pass it on and not have it destroyed with ourselves */ TiffIFD* root = mRootIFD; if (!potentials.empty()) { // We have a dng image entry TiffIFD *t = potentials[0]; const unsigned char* c = t->getEntry(DNGVERSION)->getData(); if (c[0] > 1) throw TiffParserException("DNG version too new."); mRootIFD = NULL; return new DngDecoder(root, mInput); } potentials = mRootIFD->getIFDsWithTag(MAKE); if (!potentials.empty()) { // We have make entry for (vector<TiffIFD*>::iterator i = potentials.begin(); i != potentials.end(); ++i) { string make = (*i)->getEntry(MAKE)->getString(); TrimSpaces(make); if (!make.compare("Canon")) { mRootIFD = NULL; return new Cr2Decoder(root, mInput); } if (!make.compare("NIKON CORPORATION")) { mRootIFD = NULL; return new NefDecoder(root, mInput); } if (!make.compare("NIKON")) { mRootIFD = NULL; return new NefDecoder(root, mInput); } if (!make.compare("OLYMPUS IMAGING CORP.")) { mRootIFD = NULL; return new OrfDecoder(root, mInput); } if (!make.compare("SONY")) { mRootIFD = NULL; return new ArwDecoder(root, mInput); } if (!make.compare("PENTAX Corporation ")) { mRootIFD = NULL; return new PefDecoder(root, mInput); } if (!make.compare("PENTAX")) { mRootIFD = NULL; return new PefDecoder(root, mInput); } if (!make.compare("Panasonic")) { mRootIFD = NULL; return new Rw2Decoder(root, mInput); } if (!make.compare("SAMSUNG")) { mRootIFD = NULL; return new SrwDecoder(root, mInput); } } } throw TiffParserException("No decoder found. Sorry."); return NULL; }