0

I am trying to create a linear DNG file based on JPG using Lossy JPEG (34892) compression (which was introduced in DNG 1.4.0.0). After running the method below I got an error "Error: File format is invalid (JPEG dimensions do not match tile)" from dng_validate.exe.

It would be nice if someone can resolve it by adjusting my code. Also, I will be happy for a tutorial link. Using of image tools (magick, dcraw, exiftool) also could be a solution.

public static void LinearRawDng()
        {
            string file = "eva.jpg";
            using (Tiff tif = Tiff.Open("eva-linear.dng", "w"))
            {
                Image img = Image.FromFile(file);
                byte[] raster;
                using (MemoryStream ms = new MemoryStream())
                {
                    img.Save(ms, ImageFormat.Jpeg);
                    raster = ms.ToArray();
                }

                tif.SetField(TiffTag.MAKE, "Fitler");
                tif.SetField(TiffTag.UNIQUECAMERAMODEL, "Fitler");
                tif.SetField(TiffTag.DNGVERSION, "\x1\x4\x0\x0");
                tif.SetField(TiffTag.DNGBACKWARDVERSION, "\x1\x4\x0\x0");

                tif.SetField(TiffTag.SUBFILETYPE, 0);
                tif.SetField(TiffTag.PHOTOMETRIC, 34892);
                tif.SetField(TiffTag.COMPRESSION, 34892);
                tif.SetField(TiffTag.SAMPLESPERPIXEL, 1);
                tif.SetField(TiffTag.BITSPERSAMPLE, 8);
                tif.SetField(TiffTag.ORIENTATION, Orientation.TOPLEFT);
                tif.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
                tif.SetField(TiffTag.IMAGEWIDTH, img.Width);
                tif.SetField(TiffTag.IMAGELENGTH, img.Height);


                var result = tif.WriteRawStrip(0, raster, raster.Length);               
                tif.Close();
                Console.WriteLine("Finished");
            }
        }
dimonser
  • 675
  • 6
  • 12

0 Answers0