RawImage CrwDecoder::decodeRawInternal() { CiffEntry *sensorInfo = mRootIFD->getEntryRecursive(CIFF_SENSORINFO); if (!sensorInfo || sensorInfo->count < 6 || sensorInfo->type != CIFF_SHORT) ThrowRDE("CRW: Couldn't find image sensor info"); uint32 width = sensorInfo->getShort(1); uint32 height = sensorInfo->getShort(2); CiffEntry *decTable = mRootIFD->getEntryRecursive(CIFF_DECODERTABLE); if (!decTable || decTable->type != CIFF_LONG) ThrowRDE("CRW: Couldn't find decoder table"); uint32 dec_table = decTable->getInt(); if (dec_table > 2) ThrowRDE("CRW: Unknown decoder table %d", dec_table); mRaw->dim = iPoint2D(width, height); mRaw->createData(); bool lowbits = hints.find("no_decompressed_lowbits") == hints.end(); decodeRaw(lowbits, dec_table, width, height); return mRaw; }
CiffEntry* CiffIFD::getEntryRecursiveWhere(CiffTag tag, uint32 isValue) { if (mEntry.find(tag) != mEntry.end()) { CiffEntry* entry = mEntry[tag]; if (entry->isInt() && entry->getInt() == isValue) return entry; } for (vector<CiffIFD*>::iterator i = mSubIFD.begin(); i != mSubIFD.end(); ++i) { CiffEntry* entry = (*i)->getEntryRecursive(tag); if (entry) return entry; } return NULL; }
CiffEntry* CiffIFD::getEntryRecursiveWhere(CiffTag tag, string isValue) { if (mEntry.find(tag) != mEntry.end()) { CiffEntry* entry = mEntry[tag]; if (entry->isString() && 0 == entry->getString().compare(isValue)) return entry; } for (vector<CiffIFD*>::iterator i = mSubIFD.begin(); i != mSubIFD.end(); ++i) { CiffEntry* entry = (*i)->getEntryRecursive(tag); if (entry) return entry; } return NULL; }
void CrwDecoder::decodeMetaDataInternal(CameraMetaData *meta) { int iso = 0; mRaw->cfa.setCFA(iPoint2D(2,2), CFA_RED, CFA_GREEN, CFA_GREEN2, CFA_BLUE); vector<CiffIFD*> data = mRootIFD->getIFDsWithTag(CIFF_MAKEMODEL); if (data.empty()) ThrowRDE("CRW Support check: Model name not found"); vector<string> makemodel = data[0]->getEntry(CIFF_MAKEMODEL)->getStrings(); if (makemodel.size() < 2) ThrowRDE("CRW Support check: wrong number of strings for make/model"); string make = makemodel[0]; string model = makemodel[1]; string mode = ""; if (mRootIFD->hasEntryRecursive(CIFF_SHOTINFO)) { CiffEntry *shot_info = mRootIFD->getEntryRecursive(CIFF_SHOTINFO); if (shot_info->type == CIFF_SHORT && shot_info->count >= 2) { // os << exp(canonEv(value.toLong()) * log(2.0)) * 100.0 / 32.0; ushort16 iso_index = shot_info->getShort(2); iso = expf(canonEv((long)iso_index) * logf(2.0)) * 100.0f / 32.0f; } } // Fetch the white balance try { if(mRootIFD->hasEntryRecursive((CiffTag)0x0032)) { CiffEntry *wb = mRootIFD->getEntryRecursive((CiffTag)0x0032); if (wb->type == CIFF_BYTE && wb->count == 768) { // We're in a D30 file, values are RGGB // This will probably not get used anyway as a 0x102c tag should exist mRaw->metadata.wbCoeffs[0] = (float) (1024.0 /wb->getByte(72)); mRaw->metadata.wbCoeffs[1] = (float) ((1024.0/wb->getByte(73))+(1024.0/wb->getByte(74)))/2.0f; mRaw->metadata.wbCoeffs[2] = (float) (1024.0 /wb->getByte(75)); } else if (wb->type == CIFF_BYTE && wb->count > 768) { // Other G series and S series cameras // correct offset for most cameras int offset = 120; // check for the hint that we need to use other offset if (hints.find("wb_offset") != hints.end()) { stringstream wb_offset(hints.find("wb_offset")->second); wb_offset >> offset; } ushort16 key[] = { 0x410, 0x45f3 }; if (hints.find("wb_mangle") == hints.end()) key[0] = key[1] = 0; offset /= 2; mRaw->metadata.wbCoeffs[0] = (float) (wb->getShort(offset+1) ^ key[1]); mRaw->metadata.wbCoeffs[1] = (float) (wb->getShort(offset+0) ^ key[0]); mRaw->metadata.wbCoeffs[2] = (float) (wb->getShort(offset+2) ^ key[0]); }
vector<CiffIFD*> CiffIFD::getIFDsWithTagWhere(CiffTag tag, string isValue) { vector<CiffIFD*> matchingIFDs; if (mEntry.find(tag) != mEntry.end()) { CiffEntry* entry = mEntry[tag]; if (entry->isString() && 0 == entry->getString().compare(isValue)) matchingIFDs.push_back(this); } for (vector<CiffIFD*>::iterator i = mSubIFD.begin(); i != mSubIFD.end(); ++i) { vector<CiffIFD*> t = (*i)->getIFDsWithTag(tag); for (uint32 j = 0; j < t.size(); j++) { matchingIFDs.push_back(t[j]); } } return matchingIFDs; }