Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pr/690' into develop
Browse files Browse the repository at this point in the history
* upstream/pr/690:
  Remove explicit crop from Fujifilm X-Trans 4/5 cameras
  RafDecoder: support vendor crop from metadata
  • Loading branch information
LebedevRI committed Mar 5, 2024
2 parents 9d78034 + 449e9ea commit f09c4bd
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 31 deletions.
24 changes: 0 additions & 24 deletions data/cameras.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15420,7 +15420,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="12" width="-138" height="-12"/>
<Sensor black="1022" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand All @@ -15440,7 +15439,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="12" width="-138" height="-12"/>
<Sensor black="1022" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand Down Expand Up @@ -15659,7 +15657,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="12" width="-138" height="-6"/>
<Sensor black="1022" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand All @@ -15679,7 +15676,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="12" width="-138" height="-6"/>
<Sensor black="1022" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand Down Expand Up @@ -15742,7 +15738,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="12" width="-120" height="-12"/>
<Sensor black="1020" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand All @@ -15762,7 +15757,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="12" width="-120" height="-12"/>
<Sensor black="1020" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand All @@ -15782,7 +15776,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="12" width="-78" height="-12"/>
<Sensor black="1024" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand All @@ -15802,7 +15795,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="12" width="-78" height="-12"/>
<Sensor black="1024" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand Down Expand Up @@ -16064,7 +16056,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="12" width="-132" height="-6"/>
<Sensor black="1022" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand All @@ -16084,7 +16075,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="12" width="-132" height="-6"/>
<Sensor black="1022" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand All @@ -16104,7 +16094,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="6" width="-132" height="-6"/>
<Sensor black="1022" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand All @@ -16124,7 +16113,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="6" width="-132" height="-6"/>
<Sensor black="1022" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand All @@ -16144,7 +16132,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="12" width="-90" height="-6"/>
<Sensor black="1022" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand All @@ -16164,7 +16151,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="12" width="-90" height="-6"/>
<Sensor black="1022" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand Down Expand Up @@ -16244,7 +16230,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="8" width="-134" height="-6"/>
<Sensor black="1022" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand All @@ -16264,7 +16249,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="8" width="-134" height="-6"/>
<Sensor black="1022" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand All @@ -16284,7 +16268,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="6" width="-132" height="0"/>
<Sensor black="1022" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand All @@ -16304,7 +16287,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="6" width="-132" height="0"/>
<Sensor black="1022" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand All @@ -16324,7 +16306,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="12" width="-120" height="-12"/>
<Sensor black="1020" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand All @@ -16344,7 +16325,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="12" width="-120" height="-12"/>
<Sensor black="1020" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand Down Expand Up @@ -16424,7 +16404,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="12" width="-132" height="-6"/>
<Sensor black="1022" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand All @@ -16444,7 +16423,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="12" width="-132" height="-6"/>
<Sensor black="1022" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand All @@ -16464,7 +16442,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="12" width="-138" height="-6"/>
<Sensor black="1022" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand All @@ -16484,7 +16461,6 @@
<ColorRow y="4">GGRGGB</ColorRow>
<ColorRow y="5">RBGBRG</ColorRow>
</CFA2>
<Crop x="0" y="12" width="-138" height="-6"/>
<Sensor black="1022" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
Expand Down
38 changes: 32 additions & 6 deletions src/librawspeed/decoders/RafDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ RawImage RafDecoder::decodeRawInternal() {
if (raw->hasEntry(TiffTag::FUJI_RAWIMAGEFULLHEIGHT)) {
height = raw->getEntry(TiffTag::FUJI_RAWIMAGEFULLHEIGHT)->getU32();
width = raw->getEntry(TiffTag::FUJI_RAWIMAGEFULLWIDTH)->getU32();
} else if (raw->hasEntry(TiffTag::IMAGEWIDTH)) {
const TiffEntry* e = raw->getEntry(TiffTag::IMAGEWIDTH);
} else if (raw->hasEntry(TiffTag::FUJI_RAWIMAGEFULLSIZE)) {
const TiffEntry* e = raw->getEntry(TiffTag::FUJI_RAWIMAGEFULLSIZE);
height = e->getU16(0);
width = e->getU16(1);
} else
Expand Down Expand Up @@ -206,17 +206,23 @@ void RafDecoder::applyCorrections(const Camera* cam) {
iPoint2D crop_offset(0, 0);

if (applyCrop) {
new_size = cam->cropSize;
crop_offset = cam->cropPos;
if (cam->cropAvailable) {
new_size = cam->cropSize;
crop_offset = cam->cropPos;
} else {
const iRectangle2D vendor_crop = getDefaultCrop();
new_size = vendor_crop.dim;
crop_offset = vendor_crop.pos;
}
bool double_width = hints.contains("double_width_unpacked");
// If crop size is negative, use relative cropping
if (new_size.x <= 0) {
new_size.x =
mRaw->dim.x / (double_width ? 2 : 1) - cam->cropPos.x + new_size.x;
mRaw->dim.x / (double_width ? 2 : 1) - crop_offset.x + new_size.x;
} else
new_size.x /= (double_width ? 2 : 1);
if (new_size.y <= 0)
new_size.y = mRaw->dim.y - cam->cropPos.y + new_size.y;
new_size.y = mRaw->dim.y - crop_offset.y + new_size.y;
}

bool rotate = hints.contains("fuji_rotate");
Expand Down Expand Up @@ -396,4 +402,24 @@ int RafDecoder::isCompressed() const {
return count * 8 / (width * height) < bps;
}

iRectangle2D RafDecoder::getDefaultCrop() {
// Crop tags alias baseline TIFF tags, but are in the Fujifilm proprietary
// directory that can be identified by a different unique tag.
if (const auto* raw = mRootIFD->getIFDWithTag(TiffTag::FUJI_RAFDATA);
raw->hasEntry(TiffTag::FUJI_RAWIMAGECROPTOPLEFT) &&
raw->hasEntry(TiffTag::FUJI_RAWIMAGECROPPEDSIZE)) {
const auto* pos = raw->getEntry(TiffTag::FUJI_RAWIMAGECROPTOPLEFT);
const uint16_t topBorder = pos->getU16(0);
const uint16_t leftBorder = pos->getU16(1);
const auto* dim = raw->getEntry(TiffTag::FUJI_RAWIMAGECROPPEDSIZE);
const uint16_t height = dim->getU16(0);
const uint16_t width = dim->getU16(1);
return {leftBorder, topBorder, width, height};
}
ThrowRDE("Cannot figure out vendor crop. Required entries were not found: "
"%X, %X",
static_cast<unsigned int>(TiffTag::FUJI_RAWIMAGECROPTOPLEFT),
static_cast<unsigned int>(TiffTag::FUJI_RAWIMAGECROPPEDSIZE));
}

} // namespace rawspeed
1 change: 1 addition & 0 deletions src/librawspeed/decoders/RafDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class RafDecoder final : public AbstractTiffDecoder {
void applyCorrections(const Camera* cam);
void decodeMetaDataInternal(const CameraMetaData* meta) override;
void checkSupportInternal(const CameraMetaData* meta) override;
iRectangle2D getDefaultCrop() override;
static bool isRAF(Buffer input);

protected:
Expand Down
4 changes: 3 additions & 1 deletion src/librawspeed/parsers/FiffParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ void FiffParser::parseData() {
uint16_t length = bytes.getU16();
TiffDataType type = TiffDataType::UNDEFINED;

if (tag == TiffTag::IMAGEWIDTH ||
if (tag == TiffTag::FUJI_RAWIMAGEFULLSIZE ||
tag == TiffTag::FUJI_RAWIMAGECROPTOPLEFT ||
tag == TiffTag::FUJI_RAWIMAGECROPPEDSIZE ||
tag == TiffTag::FUJIOLDWB) // also 0x121?
type = TiffDataType::SHORT;

Expand Down
5 changes: 5 additions & 0 deletions src/librawspeed/tiff/TiffTag.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum class TiffTag {
MAKERNOTE_ALT = 0x2e,

IMAGEWIDTH = 0x0100,
FUJI_RAWIMAGEFULLSIZE = 0x0100,
IMAGELENGTH = 0x0101,
BITSPERSAMPLE = 0x0102,
COMPRESSION = 0x0103,
Expand All @@ -50,7 +51,9 @@ enum class TiffTag {
IMAGEDESCRIPTION = 0x010E,
MAKE = 0x010F,
MODEL = 0x0110,
FUJI_RAWIMAGECROPTOPLEFT = 0x0110,
STRIPOFFSETS = 0x0111,
FUJI_RAWIMAGECROPPEDSIZE = 0x0111,
ORIENTATION = 0x0112,
SAMPLESPERPIXEL = 0x0115,
ROWSPERSTRIP = 0x0116,
Expand Down Expand Up @@ -245,6 +248,8 @@ enum class TiffTag {
// THE XMP SPEC DECLARES THAT XMP DATA SHOULD LIVE 0x2BC WHEN
// EMBEDDED IN TIFF IMAGES.
XMP = 0x02BC,
// Fujifilm unique tag within proprietary directory
FUJI_RAFDATA = 0xC000,
// Canon tag for uncompressed RGB preview
CANON_UNCOMPRESSED = 0xC5D9,

Expand Down

0 comments on commit f09c4bd

Please sign in to comment.