Skip to content

Commit

Permalink
raw2dng: Add option to generate thumbnails and preview
Browse files Browse the repository at this point in the history
This is sometimes required by some raw processors.
Darktable for tiffs is now supported

Signed-off-by: Yan Burman <yanburman@users.noreply.github.com>
  • Loading branch information
yanburman committed Dec 18, 2016
1 parent 1a610b0 commit c5b090c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
46 changes: 44 additions & 2 deletions src/DNGConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <dng_host.h>
#include <dng_file_stream.h>
#include <dng_render.h>
#include <dng_preview.h>
#include <dng_xmp_sdk.h>
#include <dng_xmp.h>
#include <dng_globals.h>
Expand Down Expand Up @@ -717,6 +718,45 @@ dng_error_code DNGConverter::ConvertToDNG(const std::string &m_szInputFile, cons
// Update IPTC
oNegative->RebuildIPTC(true);

dng_preview_list *oPreviewList = NULL;
dng_jpeg_preview *oJpegPreview = NULL;

if (m_oConfig.m_bGenPreview) {
#ifdef TIME_PROFILE
oProfiler.reset();
oProfiler.run();
#endif

dng_render oNegRender(oDNGHost, *oNegative.Get());

oJpegPreview = new dng_jpeg_preview();
oJpegPreview->fInfo.fColorSpace = previewColorSpace_sRGB;

oNegRender.SetMaximumSize(1024);
AutoPtr<dng_image> negImage(oNegRender.Render());
dng_image_writer oJpegWriter;
oJpegWriter.EncodeJPEGPreview(oDNGHost, *negImage.Get(), *oJpegPreview, 4);
AutoPtr<dng_preview> oPreview(dynamic_cast<dng_preview *>(oJpegPreview));

dng_image_preview *oThumbnailPreview = new dng_image_preview();
oThumbnailPreview->fInfo.fColorSpace = previewColorSpace_sRGB;

oNegRender.SetMaximumSize(256);
oThumbnailPreview->fImage.Reset(oNegRender.Render());
AutoPtr<dng_preview> oThumbnail(dynamic_cast<dng_preview *>(oThumbnailPreview));

oPreviewList = new dng_preview_list();
oPreviewList->Append(oPreview);
oPreviewList->Append(oThumbnail);

#ifdef TIME_PROFILE
oProfiler.stop();
printf("Generate thumbnails and preview time: %lu usec\n", oProfiler.elapsed_usec());
#endif
}

AutoPtr<dng_preview_list> oPreviews(oPreviewList);

AutoPtr<dng_image_writer> oWriter(new dng_image_writer());

if (m_oConfig.m_bDng) {
Expand All @@ -728,7 +768,7 @@ dng_error_code DNGConverter::ConvertToDNG(const std::string &m_szInputFile, cons
oProfiler.run();
#endif
// Write DNG file to disk
oWriter->WriteDNG(oDNGHost, oDNGStream, *oNegative.Get());
oWriter->WriteDNG(oDNGHost, oDNGStream, *oNegative.Get(), oPreviews.Get());
#ifdef TIME_PROFILE
oProfiler.stop();
printf("dng_image_writer::WriteDNG() time: %lu usec\n", oProfiler.elapsed_usec());
Expand Down Expand Up @@ -769,7 +809,9 @@ dng_error_code DNGConverter::ConvertToDNG(const std::string &m_szInputFile, cons
piRGB,
ccUncompressed,
oNegative.Get(),
&oRender.FinalSpace());
&oRender.FinalSpace(),
NULL,
oJpegPreview);
#ifdef TIME_PROFILE
oProfiler.stop();
printf("dng_image_writer::WriteTIFF() time: %lu usec\n", oProfiler.elapsed_usec());
Expand Down
5 changes: 4 additions & 1 deletion src/DNGConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#include <dng_orientation.h>

struct Config {
Config() : m_bTiff(false), m_bDng(false), m_bLensCorrections(false), m_bNoCalibration(false), m_iThreads(2)
Config()
: m_bTiff(false), m_bDng(false), m_bLensCorrections(false), m_bNoCalibration(false), m_iThreads(2),
m_bGenPreview(false)
{
}

Expand All @@ -22,6 +24,7 @@ struct Config {
bool m_bLensCorrections;
bool m_bNoCalibration;
int m_iThreads;
bool m_bGenPreview;
std::string m_szPathPrefixOutput;
};

Expand Down
3 changes: 3 additions & 0 deletions src/sjcam_raw2dng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ static void usage(const char *prog, Config &conf)
#endif
"\t-p, --threads <NUM> Number of threads to run. Default: %d (0 or -1 for number of CPUS in the system)\n"
"\t-c, --no-color Do not apply color calibration (for color calibration)\n"
"\t-m, --thumb Add JPEG thumbnails (disabled by default to save disk space and conversion time)\n"
"\t-o, --output <DIR> Output dir (must exist)\n"
"\t-t, --tiff Write TIFF image to \"<file>.tiff\" (false by default)\n"
"\t-d, --dng Write DNG image to \"<file>.dng\" (used by default if no output is supplied)\n",
Expand Down Expand Up @@ -143,6 +144,8 @@ int main(int argc, char *argv[])
#endif
} else if (option.Matches("c", true) || option.Matches("-no-color", true)) {
conf.m_bNoCalibration = true;
} else if (option.Matches("m", true) || option.Matches("-thumb", true)) {
conf.m_bGenPreview = true;
} else if (option.Matches("o", true) || option.Matches("-output", true)) {
if (index + 1 < argc) {
conf.m_szPathPrefixOutput = argv[++index];
Expand Down

0 comments on commit c5b090c

Please sign in to comment.