void CrwMap::extract0x102a(const CiffComponent& ciffComponent, const CrwMapInfo* crwMapInfo, Image& image, ByteOrder byteOrder) { if (ciffComponent.typeId() != unsignedShort) { return extractBasic(ciffComponent, crwMapInfo, image, byteOrder); } long aperture = 0; long shutterSpeed = 0; std::string ifdItem(ExifTags::ifdItem(canonCs2IfdId)); uint16_t c = 1; while (uint32_t(c)*2 < ciffComponent.size()) { uint16_t n = 1; ExifKey key(c, ifdItem); UShortValue value; value.read(ciffComponent.pData() + c*2, n*2, byteOrder); image.exifData().add(key, &value); if (c == 21) aperture = value.toLong(); if (c == 22) shutterSpeed = value.toLong(); c += n; } // Exif.Photo.FNumber float f = fnumber(canonEv(aperture)); // Beware: primitive conversion algorithm uint32_t den = 1000000; uint32_t nom = static_cast<uint32_t>(f * den); uint32_t g = gcd(nom, den); URational ur(nom/g, den/g); URationalValue fn; fn.value_.push_back(ur); image.exifData().add(ExifKey("Exif.Photo.FNumber"), &fn); // Exif.Photo.ExposureTime ur = exposureTime(canonEv(shutterSpeed)); URationalValue et; et.value_.push_back(ur); image.exifData().add(ExifKey("Exif.Photo.ExposureTime"), &et); } // CrwMap::extract0x102a
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]); }