Skip to content

Commit

Permalink
US38: Small improvement saving the DNG file
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelaya committed May 17, 2014
1 parent 56c3278 commit 2a6facd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 7 additions & 4 deletions DngFloatWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ void DngFloatWriter::write(const string & filename) {
file.seekp(dataOffset);

progress.advance(75, "Writing output");
Timer t("Write output");
writePreviews();
writeRawData();
measureTime("Write raw", [&] () { writeRawData(); });
file.seekp(0);
TiffHeader().write(file);
mainIFD.write(file, false);
Expand Down Expand Up @@ -490,8 +491,8 @@ void DngFloatWriter::writeRawData() {
size_t tileCount = tilesAcross * tilesDown;
uint32_t tileOffsets[tileCount];
uint32_t tileBytes[tileCount];
uLongf dstLen = tileWidth * tileLength * 4;
int bytesps = bps >> 3;
uLongf dstLen = tileWidth * tileLength * bytesps;

// #pragma omp parallel
{
Expand All @@ -502,9 +503,11 @@ void DngFloatWriter::writeRawData() {
for (size_t y = 0; y < height; y += tileLength) {
for (size_t x = 0; x < width; x += tileWidth) {
size_t t = (y / tileLength) * tilesAcross + (x / tileWidth);
fill_n(uBuffer, dstLen, 0);
size_t thisTileLength = y + tileLength > height ? height - y : tileLength;
size_t thisTileWidth = x + tileWidth > width ? width - x : tileWidth;
if (thisTileLength != tileLength || thisTileWidth != tileWidth) {
fill_n(uBuffer, dstLen, 0);
}
for (size_t row = 0; row < thisTileLength; ++row) {
Bytef * dst = uBuffer + row*tileWidth*bytesps;
Bytef * src = (Bytef *)&rawData[(y+row)*width + x];
Expand All @@ -516,7 +519,7 @@ void DngFloatWriter::writeRawData() {
tileBytes[t] = conpressedLength;
if (err != Z_OK) {
std::cerr << "DNG Deflate: Failed compressing tile " << t << ", with error " << err << std::endl;
} else { // Floating point data
} else {
// #pragma omp critical
{
tileOffsets[t] = file.tellp();
Expand Down
8 changes: 5 additions & 3 deletions Log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,17 @@ inline std::ostream & operator<<(std::ostream & os, const QString & s) {
class Timer {
public:
Timer(const char * n) : name(n) {
start = std::clock();
clock_gettime(CLOCK_MONOTONIC_COARSE, &start);
}
~Timer() {
double t = (std::clock() - start) / (double) CLOCKS_PER_SEC;
timespec end;
clock_gettime(CLOCK_MONOTONIC_COARSE, &end);
double t = end.tv_sec - start.tv_sec + (end.tv_nsec - start.tv_nsec)/1000000000.0;
Log::msg(Log::DEBUG, name, ": ", t, " seconds");
}

private:
std::clock_t start;
timespec start;
const char * name;
};

Expand Down

0 comments on commit 2a6facd

Please sign in to comment.