Skip to content

Commit

Permalink
Keep v0.4.4 compatible with current state of RawTherapee
Browse files Browse the repository at this point in the history
- Subtract blacks from the output image to keep it compatible with the current state of RawTherapee. This won't work with every camera.
  • Loading branch information
jcelaya committed Jun 9, 2014
1 parent 9261b6a commit 925140a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 40 deletions.
41 changes: 6 additions & 35 deletions DngFloatWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,9 @@ enum {
void DngFloatWriter::write(Array2D<float> && rawPixels, const RawParameters & p, const string & filename) {
params = &p;
rawData = std::move(rawPixels);
width = rawData.getWidth();
height = rawData.getHeight();

// FIXME: This is temporal, until I fix RawTherapee
width = params->width;
height = params->height;
rawData.displace(-(int)params->leftMargin, -(int)params->topMargin);
// FIXME: END

renderPreviews();

Expand Down Expand Up @@ -235,38 +230,14 @@ void DngFloatWriter::createRawIFD() {

// Areas
uint32_t aa[4];
aa[0] = params->topMargin;
aa[1] = params->leftMargin;
// FIXME: This is temporal, until I fix RawTherapee
aa[0] = aa[1] = 0;
// FIXME: END
aa[2] = aa[0] + params->height;
aa[3] = aa[1] + params->width;
aa[2] = params->height;
aa[3] = params->width;
rawIFD.addEntry(ACTIVEAREA, IFD::LONG, 4, aa);
uint32_t ma[16];
int nma = 0;
if (aa[0] > 0) {
ma[nma] = 0; ma[nma + 1] = 0; ma[nma + 2] = aa[0]; ma[nma + 3] = width; nma += 4;
}
if (aa[1] > 0) {
ma[nma] = aa[0]; ma[nma + 1] = 0; ma[nma + 2] = aa[2]; ma[nma + 3] = aa[1]; nma += 4;
}
if (aa[2] < height) {
ma[nma] = aa[2]; ma[nma + 1] = 0; ma[nma + 2] = height; ma[nma + 3] = width; nma += 4;
}
if (aa[3] < width) {
ma[nma] = aa[0]; ma[nma + 1] = aa[3]; ma[nma + 2] = aa[2]; ma[nma + 3] = width; nma += 4;
}
if (nma > 0) {
rawIFD.addEntry(MASKEDAREAS, IFD::LONG, nma, ma);
} else {
// If there are no masked areas, black levels must be encoded, but not both.
uint16_t brep[2] = { 2, 2 };
rawIFD.addEntry(BLACKLEVELREP, IFD::SHORT, 2, brep);
uint16_t cblack[] = { params->blackAt(0, 0), params->blackAt(1, 0),
params->blackAt(0, 1), params->blackAt(1, 1) };
rawIFD.addEntry(BLACKLEVEL, IFD::SHORT, 4, cblack);
}
uint16_t brep[2] = { 2, 2 };
rawIFD.addEntry(BLACKLEVELREP, IFD::SHORT, 2, brep);
uint16_t cblack[] = { 0, 0, 0, 0 };
rawIFD.addEntry(BLACKLEVEL, IFD::SHORT, 4, cblack);
uint32_t crop[2];
crop[0] = 0;
crop[1] = 0;
Expand Down
2 changes: 1 addition & 1 deletion ImageIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ QImage ImageIO::renderPreview(const Array2D<float> & rawData, const RawParameter
for (size_t y = 0; y < params.rawHeight; ++y) {
for (size_t x = 0; x < params.rawWidth; ++x) {
size_t pos = y*params.rawWidth + x;
int v = (rawData[pos] - params.blackAt(x ^ oddx, y ^ oddy)) * scale;
int v = rawData[pos] * scale;
if (v < 0) v = 0;
else if (v > 65535) v = 65535;
d.rawdata.raw_image[pos] = v;
Expand Down
6 changes: 2 additions & 4 deletions ImageStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,10 @@ Array2D<float> ImageStack::compose(const RawParameters & params) const {
}
}
dst.displace(params.leftMargin, params.topMargin);
// Scale to params.max and recover the black levels
size_t oddx = params.leftMargin & 1, oddy = params.topMargin + 1;
// Scale to params.max
for (size_t y = 0; y < params.rawHeight; ++y) {
for (size_t x = 0; x < params.rawWidth; ++x) {
dst(x, y) *= (params.max - params.maxBlack) / max;
dst(x, y) += params.blackAt(x ^ oddx, y ^ oddy);
dst(x, y) *= params.max / max;
}
}

Expand Down

0 comments on commit 925140a

Please sign in to comment.