Quantcast
Channel: Adobe Community : Popular Discussions - DNG SDK
Viewing all articles
Browse latest Browse all 4036

What do I need to create DNG from scratch?

$
0
0

Hello everybody,

 

Is it possible to create DNG from RGB data? I need to implement export of images into DNG format in my application. All I have is image width, height and array of floating-point RGB data.

 

I'm experimenting with DNG SDK for two days, playing with dng_negative parmeters. I've figured out that I can't use ttFloat type of image — it's not supported, BuildStage2Image thorws an exception. Okay, I've converted source data into uint16 and stored it as ttShort dng_image. But my best result was DNG file with very weird colors.

 

So what do I need to store my data into DNG? What color matrix and calibration illuminant should I use? What dng_negative parameters could be leaved with default values? Doxygen documentation is very unclear. All examples I've found over network (on this forum, in sources of digiKam project, etc) is about converting some raw image into DNG. I don't need to convert image file, I need to build DNG from scratch.

 

This is my source, if it can help to undestand what am I doing:

dng_host dngHost;
dngHost.SetSaveLinearDNG(false);

dng_rect imageRect(img.height(), img.width());

AutoPtr<dng_image> dngImage(new dng_simple_image(imageRect, 3, ttShort, dngHost.Allocator()));

// Convert source floating-point image into uint16
QVector<uint16> shortData(img.width() * img.height() * 3);
float *srcData = img.data();
uint16 *dstData = shortData.data();

for (int i = 0; i < img.width() * img.height() * 3; ++i) {    *(dstData++) = static_cast<uint16>(qMin(*(srcData++), 1.0f) * 65535.0f);
}

dng_pixel_buffer buffer;
buffer.fArea = imageRect;
buffer.fPlane = 0;
buffer.fPlanes = 3;
buffer.fRowStep = 3 * img.width();
buffer.fColStep = 3;
buffer.fPlaneStep = 1;
buffer.fPixelType = ttShort;
buffer.fPixelSize = TagTypeSize(ttShort);
buffer.fData = shortData.data();
dngImage->Put(buffer);

AutoPtr<dng_negative> dngNegative(dngHost.Make_dng_negative());

dngNegative->SetDefaultScale(dng_urational(1, 1), dng_urational(1, 1));
dngNegative->SetDefaultCropOrigin(0, 0);
dngNegative->SetDefaultCropSize(img.width(), img.height());
dngNegative->SetActiveArea(imageRect);
dngNegative->SetModelName("Dummy");
dngNegative->SetLocalName("Dummy");
dngNegative->SetOriginalRawFileName(fi.fileName().toUtf8().constData());
dngNegative->SetColorChannels(3);
dngNegative->SetColorKeys(colorKeyRed, colorKeyGreen, colorKeyBlue);
dngNegative->SetWhiteLevel((0x01 << 16) - 1);
dngNegative->SetBlackLevel(0);
dngNegative->SetBaselineExposure(0.0);
dngNegative->SetNoiseReductionApplied(dng_urational(0, 1));
dngNegative->SetBaselineNoise(1.0);
dngNegative->SetBaselineSharpness(1.0);
dngNegative->SetBaseOrientation(dng_orientation::Normal());
dngNegative->SetLinearResponseLimit(1.0);

AutoPtr<dng_camera_profile> prof(new dng_camera_profile);
prof->SetName("dummy");
dng_matrix_3by3 camXYZ(1.0f, 1.0f, 1.0f);
prof->SetColorMatrix1(static_cast<dng_matrix>(camXYZ));
prof->SetCalibrationIlluminant1(lsD65);
prof->SetWasReadFromDNG(true);
dngNegative->AddProfile(prof);

dngNegative->SetStage1Image(dngImage);
dngNegative->BuildStage2Image(dngHost);
dngNegative->BuildStage3Image(dngHost);
dngNegative->SynchronizeMetadata();
dngNegative->RebuildIPTC(true, false);

dng_image_preview thumbnail;
dng_render render(dngHost, *dngNegative);
render.SetFinalSpace(dng_space_sRGB::Get());
render.SetFinalPixelType(ttByte);
render.SetMaximumSize(256);
thumbnail.fImage.Reset(render.Render());

dng_image_writer writer;
dng_file_stream stream(QFile::encodeName(filename).constData(), true);
writer.WriteDNG(dngHost, stream, *dngNegative.Get(), thumbnail, ccUncompressed);

Viewing all articles
Browse latest Browse all 4036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>