Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/librawspeed/common/RawImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ class ImageMetaData final {

// ISO speed. If known the value is set, otherwise it will be '0'.
int isoSpeed = 0;

// The aspect ratio the camera was set to while shooting, as {width,
// height}, when the camera recorded one and left the raw data uncropped.
// Consumers are expected to center it on the image themselves; the crop
// the vendor describes is relative to the vendor's own output area, which
// is not necessarily the area we hand out.
Optional<std::array<int, 2>> cameraAspectRatio;
};

class RawImageData : public ErrorLog {
Expand Down
26 changes: 26 additions & 0 deletions src/librawspeed/decoders/RafDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,32 @@ void RafDecoder::decodeMetaDataInternal(const CameraMetaData* meta) {
mRaw->whitePoint = implicit_cast<int>((1UL << bps) - 1UL);
}

// The aspect ratio dialed in on the camera, kept in the same proprietary
// directory as the crop tags read by getDefaultCrop(). Stored as height
// then width, like the cropped size beside it. The raw data is left
// uncropped, so this is the only record of the framing chosen while
// shooting.
// getIFDWithTag() throws, and not every raf carries that directory
if (mRootIFD->hasEntryRecursive(TiffTag::FUJI_RAFDATA)) {
const TiffIFD* raw = mRootIFD->getIFDWithTag(TiffTag::FUJI_RAFDATA);
if (raw->hasEntry(TiffTag::FUJI_RAWIMAGEASPECTRATIO) &&
raw->hasEntry(TiffTag::FUJI_RAWIMAGECROPPEDSIZE)) {
const TiffEntry* ratio = raw->getEntry(TiffTag::FUJI_RAWIMAGEASPECTRATIO);
const TiffEntry* size = raw->getEntry(TiffTag::FUJI_RAWIMAGECROPPEDSIZE);
if (ratio->count == 2 && size->count == 2) {
const int height = ratio->getU16(0);
const int width = ratio->getU16(1);
const int fullHeight = size->getU16(0);
const int fullWidth = size->getU16(1);
// The tag is written whether or not a ratio was picked, so it is only
// of interest when it differs from the shape of the frame itself.
if (width > 0 && height > 0 && fullWidth > 0 && fullHeight > 0 &&
width * fullHeight != height * fullWidth)
mRaw->metadata.cameraAspectRatio = std::array<int, 2>{width, height};
}
}
}

// This is where we'd normally call setMetaData but since we may still need
// to rotate the image for SuperCCD cameras we do everything ourselves
auto id = mRootIFD->getID();
Expand Down
1 change: 1 addition & 0 deletions src/librawspeed/parsers/FiffParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ void FiffParser::parseData() {
case TiffTag::FUJI_RAWIMAGEFULLSIZE:
case TiffTag::FUJI_RAWIMAGECROPTOPLEFT:
case TiffTag::FUJI_RAWIMAGECROPPEDSIZE:
case TiffTag::FUJI_RAWIMAGEASPECTRATIO:
case TiffTag::FUJIOLDWB:
// also 0x121?
type = TiffDataType::SHORT;
Expand Down
1 change: 1 addition & 0 deletions src/librawspeed/tiff/TiffTag.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ enum class TiffTag : uint16_t {
FUJI_RAWIMAGECROPPEDSIZE = 0x0111,
ORIENTATION = 0x0112,
SAMPLESPERPIXEL = 0x0115,
FUJI_RAWIMAGEASPECTRATIO = 0x0115,
ROWSPERSTRIP = 0x0116,
STRIPBYTECOUNTS = 0x0117,
XRESOLUTION = 0x011A,
Expand Down