From 2a6facd255c726eeac561d358fd53e37f27a9b84 Mon Sep 17 00:00:00 2001 From: Javier Celaya Date: Sat, 17 May 2014 18:30:54 +0100 Subject: [PATCH] US38: Small improvement saving the DNG file --- DngFloatWriter.cpp | 11 +++++++---- Log.hpp | 8 +++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/DngFloatWriter.cpp b/DngFloatWriter.cpp index f19996a..38dd2e9 100644 --- a/DngFloatWriter.cpp +++ b/DngFloatWriter.cpp @@ -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); @@ -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 { @@ -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]; @@ -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(); diff --git a/Log.hpp b/Log.hpp index b62c0a1..48b00e9 100644 --- a/Log.hpp +++ b/Log.hpp @@ -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; };