Debian Codegraph @

core/libs/dngwriter/extra/dng_sdk/dng_validate.cpp

raw
1 /*****************************************************************************/
2 // Copyright 2006-2019 Adobe Systems Incorporated
3 // All Rights Reserved.
4 //
5 // NOTICE: Adobe permits you to use, modify, and distribute this file in
6 // accordance with the terms of the Adobe license agreement accompanying it.
7 /*****************************************************************************/
8
9 // Process exit codes
10 // ------------------
11 //
12 // As usual, 0 indicates success.
13 //
14 // If an exception occurs, the exit code will be equal to:
15 //
16 // DNG SDK error code - 100000 + 100
17 //
18 // For example, the error dng_error_memory, which has a DNG SDK error code of
19 // 100005, is returned as an exit code of 105.
20 //
21 // This convention accounts for the fact that the shell truncates process exit
22 // codes to 8 bits and that the exit code 1 is used by ASAN to signal that a
23 // memory error occurred (so mapping the first DNG SDK error code to an exit
24 // code of 1 would not be a good idea).
25
26 /*****************************************************************************/
27
28 #include "dng_color_space.h"
29 #include "dng_date_time.h"
30 #include "dng_exceptions.h"
31 #include "dng_file_stream.h"
32 #include "dng_globals.h"
33 #include "dng_host.h"
34 #include "dng_ifd.h"
35 #include "dng_image_writer.h"
36 #include "dng_info.h"
37 #include "dng_linearization_info.h"
38 #include "dng_mosaic_info.h"
39 #include "dng_negative.h"
40 #include "dng_preview.h"
41 #include "dng_render.h"
42 #include "dng_tag_codes.h"
43 #include "dng_tag_types.h"
44 #include "dng_tag_values.h"
45
46 #if qDNGUseXMP
47 #include "dng_xmp.h"
48 #include "dng_xmp_sdk.h"
49 #endif
50
51 /*****************************************************************************/
52
53 #if qDNGValidateTarget
54
55 /*****************************************************************************/
56
57 #define kDNGValidateVersion "1.7.1"
58
59 /*****************************************************************************/
60
61 static bool gFourColorBayer = false;
62
63 static int32 gMosaicPlane = -1;
64
65 static bool gIgnoreEnhanced = false;
66
67 static uint32 gPreferredSize = 0;
68 static uint32 gMinimumSize = 0;
69 static uint32 gMaximumSize = 0;
70
71 static uint32 gProxyDNGSize = 0;
72
73 static bool gLossyMosaicJXL = false;
74 static bool gLosslessJXL = false;
75
76 static const dng_color_space *gFinalSpace = &dng_space_sRGB::Get ();
77
78 static uint32 gFinalPixelType = ttByte;
79
80 static dng_string gDumpStage1;
81 static dng_string gDumpStage2;
82 static dng_string gDumpStage3;
83 static dng_string gDumpTransparency;
84 static dng_string gDumpDepthMap;
85 static dng_string gDumpTIF;
86 static dng_string gDumpDNG;
87
88 static dng_string gCameraProfileName;
89
90 /*****************************************************************************/
91
92 static dng_error_code dng_validate (const char *filename)
93 {
94
95 printf ("Validating \"%s\"...\n", filename);
96
97 try
98 {
99
100 dng_file_stream stream (filename);
101
102 dng_host host;
103
104 host.SetPreferredSize (gPreferredSize);
105 host.SetMinimumSize (gMinimumSize );
106 host.SetMaximumSize (gMaximumSize );
107
108 host.ValidateSizes ();
109
110 if (host.MinimumSize ())
111 {
112
113 host.SetForPreview (true);
114
115 gDumpDNG.Clear ();
116
117 }
118
119 if (gDumpDNG.NotEmpty ())
120 {
121
122 host.SetSaveDNGVersion (dngVersion_SaveDefault);
123
124 host.SetSaveLinearDNG (false);
125
126 host.SetKeepOriginalFile (false);
127
128 host.SetLossyMosaicJXL (gLossyMosaicJXL);
129 host.SetLosslessJXL (gLosslessJXL );
130
131 }
132
133 host.SetIgnoreEnhanced (gIgnoreEnhanced);
134
135 // Read into the negative.
136
137 AutoPtr<dng_negative> negative;
138
139 {
140
141 dng_info info;
142
143 info.Parse (host, stream);
144
145 info.PostParse (host);
146
147 if (!info.IsValidDNG ())
148 {
149 return dng_error_bad_format;
150 }
151
152 negative.Reset (host.Make_dng_negative ());
153
154 negative->Parse (host, stream, info);
155
156 negative->PostParse (host, stream, info);
157
158 if (info.fEnhancedIndex != -1 && !host.IgnoreEnhanced ())
159 {
160
161 dng_timer timer ("Read enhanced image time");
162
163 negative->ReadEnhancedImage (host, stream, info);
164
165 }
166
167 else
168 {
169
170 dng_timer timer ("Raw image read time");
171
172 negative->ReadStage1Image (host, stream, info);
173
174 }
175
176 if (info.fMaskIndex != -1)
177 {
178
179 dng_timer timer ("Transparency mask read time");
180
181 negative->ReadTransparencyMask (host, stream, info);
182
183 }
184
185 if (info.fDepthIndex != -1)
186 {
187
188 dng_timer timer ("Depth map read time");
189
190 negative->ReadDepthMap (host, stream, info);
191
192 }
193
194 const bool hasSemanticMasks = !info.fSemanticMaskIndices.empty ();
195
196 if (hasSemanticMasks)
197 {
198
199 dng_timer timer ("DNG semantic mask read time");
200
201 negative->ReadSemanticMasks (host,
202 stream,
203 info);
204
205 }
206
207 negative->ValidateRawImageDigest (host);
208
209 }
210
211 // Option to write stage 1 image.
212
213 if (gDumpStage1.NotEmpty ())
214 {
215
216 if (negative->Stage1Image ())
217 {
218
219 dng_file_stream stream2 (gDumpStage1.Get (), true);
220
221 const dng_image &stage1 = *negative->Stage1Image ();
222
223 dng_image_writer writer;
224
225 writer.WriteTIFF (host,
226 stream2,
227 stage1,
228 stage1.Planes () >= 3 ? piRGB
229 : piBlackIsZero);
230
231 }
232
233 gDumpStage1.Clear ();
234
235 }
236
237 // Metadata.
238
239 negative->SynchronizeMetadata ();
240
241 // Build stage 2 image.
242
243 if (negative->Stage1Image ())
244 {
245
246 dng_timer timer ("Linearization time");
247
248 negative->BuildStage2Image (host);
249
250 }
251
252 if (gDumpStage2.NotEmpty ())
253 {
254
255 dng_file_stream stream2 (gDumpStage2.Get (), true);
256
257 if (negative->Stage2Image ())
258 {
259
260 const dng_image &stage2 = *negative->Stage2Image ();
261
262 dng_image_writer writer;
263
264 writer.WriteTIFF (host,
265 stream2,
266 stage2,
267 stage2.Planes () >= 3 ? piRGB
268 : piBlackIsZero);
269
270 }
271
272 gDumpStage2.Clear ();
273
274 }
275
276 // Four color Bayer option.
277
278 if (gFourColorBayer)
279 {
280 negative->SetFourColorBayer ();
281 }
282
283 // Build stage 3 image.
284
285 if (negative->Stage2Image ())
286 {
287
288 dng_timer timer ("Interpolate time");
289
290 negative->BuildStage3Image (host,
291 gMosaicPlane);
292
293 }
294
295 else
296 {
297
298 negative->ResizeTransparencyToMatchStage3 (host);
299
300 negative->ResizeDepthToMatchStage3 (host);
301
302 }
303
304 // Resize semantic masks to match stage 3.
305
306 negative->ResizeSemanticMasksToMatchStage3 (host);
307
308 // Convert to proxy, if requested.
309
310 if (gProxyDNGSize)
311 {
312
313 dng_timer timer ("ConvertToProxy time");
314
315 dng_image_writer writer;
316
317 negative->ConvertToProxy (host,
318 writer,
319 gProxyDNGSize);
320
321 }
322
323 else if (host.LossyMosaicJXL ())
324 {
325
326 dng_timer timer ("Lossy JXL compress mosaic time");
327
328 dng_image_writer writer;
329
330 negative->LossyCompressMosaicJXL (host,
331 writer);
332
333 }
334
335 if (host.LosslessJXL ())
336 {
337
338 dng_timer timer ("Lossless JXL compress time");
339
340 dng_image_writer writer;
341
342 negative->LosslessCompressJXL (host,
343 writer);
344
345 }
346
347 // Flatten transparency, if required.
348
349 if (negative->NeedFlattenTransparency (host))
350 {
351
352 dng_timer timer ("FlattenTransparency time");
353
354 negative->FlattenTransparency (host);
355
356 }
357
358 if (gDumpStage3.NotEmpty ())
359 {
360
361 dng_file_stream stream2 (gDumpStage3.Get (), true);
362
363 const dng_image &stage3 = *negative->Stage3Image ();
364
365 dng_image_writer writer;
366
367 writer.WriteTIFF (host,
368 stream2,
369 stage3,
370 stage3.Planes () >= 3 ? piRGB
371 : piBlackIsZero);
372
373 gDumpStage3.Clear ();
374
375 }
376
377 if (gDumpTransparency.NotEmpty ())
378 {
379
380 if (negative->TransparencyMask ())
381 {
382
383 dng_file_stream stream2 (gDumpTransparency.Get (), true);
384
385 const dng_image &transparencyMask = *negative->TransparencyMask ();
386
387 dng_image_writer writer;
388
389 writer.WriteTIFF (host,
390 stream2,
391 transparencyMask,
392 piBlackIsZero);
393
394 }
395
396 gDumpTransparency.Clear ();
397
398 }
399
400 if (gDumpDepthMap.NotEmpty ())
401 {
402
403 if (negative->HasDepthMap ())
404 {
405
406 dng_file_stream stream2 (gDumpDepthMap.Get (), true);
407
408 const dng_image &depthMap = *negative->DepthMap ();
409
410 dng_image_writer writer;
411
412 writer.WriteTIFF (host,
413 stream2,
414 depthMap,
415 piBlackIsZero);
416
417 }
418
419 gDumpDepthMap.Clear ();
420
421 }
422
423 // Output DNG file if requested.
424
425 if (gDumpDNG.NotEmpty ())
426 {
427
428 // Build the preview list.
429
430 dng_preview_list previewList;
431
432 dng_date_time_info dateTimeInfo;
433
434 CurrentDateTimeAndZone (dateTimeInfo);
435
436 for (uint32 previewIndex = 0; previewIndex < 2; previewIndex++)
437 {
438
439 // Skip preview if writing a compresssed main image to save space
440 // in this example code.
441
442 if (negative->RawLossyCompressedImage () != NULL && previewIndex > 0)
443 {
444 break;
445 }
446
447 // Report timing.
448
449 dng_timer timer (previewIndex == 0 ? "Build thumbnail time"
450 : "Build preview time");
451
452 // Render a preview sized image.
453
454 AutoPtr<dng_image> previewImage;
455
456 {
457
458 dng_render render (host, *negative);
459
460 render.SetFinalSpace (negative->IsMonochrome () ? dng_space_GrayGamma22::Get ()
461 : dng_space_sRGB ::Get ());
462
463 render.SetFinalPixelType (ttByte);
464
465 render.SetMaximumSize (previewIndex == 0 ? 256 : 1024);
466
467 previewImage.Reset (render.Render ());
468
469 }
470
471 // Don't write the preview if it is same size as thumbnail.
472
473 if (previewIndex > 0 &&
474 Max_uint32 (previewImage->Bounds ().W (),
475 previewImage->Bounds ().H ()) <= 256)
476 {
477 break;
478 }
479
480 // If we have compressed JPEG data, create a compressed thumbnail. Otherwise
481 // save a uncompressed thumbnail.
482
483 bool useCompressedPreview = (negative->RawLossyCompressedImage () != NULL) ||
484 (previewIndex > 0);
485
486 AutoPtr<dng_preview> preview (useCompressedPreview ?
487 (dng_preview *) new dng_jpeg_preview :
488 (dng_preview *) new dng_image_preview);
489
490 // Setup up preview info.
491
492 preview->fInfo.fApplicationName .Set ("dng_validate");
493 preview->fInfo.fApplicationVersion.Set (kDNGValidateVersion);
494
495 preview->fInfo.fSettingsName.Set ("Default");
496
497 preview->fInfo.fColorSpace = previewImage->Planes () == 1 ?
498 previewColorSpace_GrayGamma22 :
499 previewColorSpace_sRGB;
500
501 preview->fInfo.fDateTime = dateTimeInfo.Encode_ISO_8601 ();
502
503 if (!useCompressedPreview)
504 {
505
506 dng_image_preview *imagePreview = dynamic_cast<dng_image_preview *> (preview.Get ());
507
508 imagePreview->SetImage (host,
509 previewImage.Release ());
510
511 }
512
513 else
514 {
515
516 dng_jpeg_preview *jpegPreview = dynamic_cast<dng_jpeg_preview *> (preview.Get ());
517
518 int32 quality = (previewIndex == 0 ? 8 : 5);
519
520 dng_image_writer writer;
521
522 writer.EncodeJPEGPreview (host,
523 *previewImage,
524 *jpegPreview,
525 quality);
526
527 }
528
529 previewList.Append (preview);
530
531 }
532
533 // Write DNG file.
534
535 dng_file_stream stream2 (gDumpDNG.Get (), true);
536
537 {
538
539 dng_timer timer ("Write DNG time");
540
541 dng_image_writer writer;
542
543 writer.WriteDNG (host,
544 stream2,
545 *negative.Get (),
546 &previewList,
547 dngVersion_SaveDefault,
548 false);
549
550 }
551
552 gDumpDNG.Clear ();
553
554 }
555
556 // Output TIF file if requested.
557
558 if (gDumpTIF.NotEmpty ())
559 {
560
561 // Render final image.
562
563 dng_render render (host, *negative);
564
565 render.SetFinalSpace (*gFinalSpace );
566 render.SetFinalPixelType (gFinalPixelType);
567
568 if (gCameraProfileName.NotEmpty ())
569 {
570
571 dng_camera_profile_id profileID (gCameraProfileName);
572
573 render.SetCameraProfileID (profileID);
574
575 }
576
577 if (host.MinimumSize ())
578 {
579
580 dng_point stage3Size = negative->Stage3Image ()->Size ();
581
582 render.SetMaximumSize (Max_uint32 (stage3Size.v,
583 stage3Size.h));
584
585 }
586
587 AutoPtr<dng_image> finalImage;
588
589 {
590
591 dng_timer timer ("Render time");
592
593 finalImage.Reset (render.Render ());
594
595 }
596
597 finalImage->Rotate (negative->Orientation ());
598
599 // Now that Camera Raw supports non-raw formats, we should
600 // not keep any Camera Raw settings in the XMP around when
601 // writing rendered files.
602
603 #if qDNGUseXMP
604
605 if (negative->GetXMP ())
606 {
607
608 negative->GetXMP ()->RemoveProperties (XMP_NS_CRS);
609 negative->GetXMP ()->RemoveProperties (XMP_NS_CRSS);
610 negative->GetXMP ()->RemoveProperties (XMP_NS_CRD);
611 negative->GetXMP ()->RemoveProperties (XMP_NS_CRLCP);
612
613 }
614
615 #endif
616
617 // Write TIF file.
618
619 dng_file_stream stream2 (gDumpTIF.Get (), true);
620
621 {
622
623 const dng_camera_profile *profilePtr = nullptr;
624
625 dng_camera_profile profile;
626
627 if (!negative->IsMonochrome ())
628 {
629
630 const auto &profileID = render.CameraProfileID ();
631
632 if (negative->GetProfileByID (profileID, profile))
633 profilePtr = &profile;
634
635 }
636
637 dng_timer timer ("Write TIFF time");
638
639 dng_image_writer writer;
640
641 writer.WriteTIFF (host,
642 stream2,
643 *finalImage.Get (),
644 finalImage->Planes () >= 3 ? piRGB
645 : piBlackIsZero,
646 ccUncompressed,
647 &negative->Metadata (),
648 &render.FinalSpace (profilePtr));
649
650 }
651
652 gDumpTIF.Clear ();
653
654 }
655
656 }
657
658 catch (const dng_exception &except)
659 {
660
661 return except.ErrorCode ();
662
663 }
664
665 catch (...)
666 {
667
668 return dng_error_unknown;
669
670 }
671
672 printf ("Validation complete\n");
673
674 return dng_error_none;
675
676 }
677
678 /*****************************************************************************/
679
680 int main (int argc, char *argv [])
681 {
682
683 try
684 {
685
686 if (argc == 1)
687 {
688
689 fprintf (stderr,
690 "\n"
691 "dng_validate, version " kDNGValidateVersion " "
692 #if qDNG64Bit
693 "(64-bit)"
694 #else
695 "(32-bit)"
696 #endif
697 "\n"
698 "Copyright 2005-2023 Adobe Systems, Inc.\n"
699 "\n"
700 "Usage: %s [options] file1 file2 ...\n"
701 "\n"
702 "Valid options:\n"
703 "-v Verbose mode\n"
704 "-d <num> Dump line limit (implies -v)\n"
705 "-b4 Use four-color Bayer interpolation\n"
706 "-s <num> Use this sample of multi-sample CFAs\n"
707 "-ignoreEnhanced Ignore the enhanced image IFD\n"
708 "-size <num> Preferred preview image size\n"
709 "-min <num> Minimum preview image size\n"
710 "-max <num> Maximum preview image size\n"
711 "-proxy <num> Target size for proxy DNG\n"
712 "-lossyMosaicJXL Writes DNG with lossy mosaic JXL\n"
713 "-losslessJXL Writes DNG with lossless JXL\n"
714 "-cs1 Color space: \"sRGB\" (default)\n"
715 "-cs2 Color space: \"Adobe RGB\"\n"
716 "-cs3 Color space: \"ProPhoto RGB\"\n"
717 "-cs4 Color space: \"ColorMatch RGB\"\n"
718 "-cs5 Color space: \"Gray Gamma 1.8\"\n"
719 "-cs6 Color space: \"Gray Gamma 2.2\"\n"
720 "-csP3 Color space: \"Display P3\"\n"
721 "-cs2020 Color space: \"Rec. 2020 / BT.2100\"\n"
722 "-16 16-bits/channel output\n"
723 "-32 32-bits/channel floating-point output\n"
724 "-profile <name> Name of camera profile to use for rendering\n"
725 "-1 <file> Write stage 1 image to \"<file>.tif\"\n"
726 "-2 <file> Write stage 2 image to \"<file>.tif\"\n"
727 "-3 <file> Write stage 3 image to \"<file>.tif\"\n"
728 "-transparency <file> Write transparency mask to \"<file>.tif\"\n"
729 "-depthMap <file> Write depth map to \"<file>.tif\"\n"
730 "-tif <file> Write TIF image to \"<file>.tif\"\n"
731 "-dng <file> Write DNG image to \"<file>.dng\"\n"
732 "\n",
733 argv [0]);
734
735 return 1;
736
737 }
738
739 int index;
740
741 for (index = 1; index < argc && argv [index] [0] == '-'; index++)
742 {
743
744 dng_string option;
745
746 option.Set (&argv [index] [1]);
747
748 if (option.Matches ("v", true))
749 {
750 gVerbose = true;
751 }
752
753 else if (option.Matches ("d", true))
754 {
755
756 gVerbose = true;
757
758 gDumpLineLimit = 0;
759
760 if (index + 1 < argc)
761 {
762 gDumpLineLimit = atoi (argv [++index]);
763 }
764
765 if (!gDumpLineLimit)
766 {
767 fprintf (stderr, "*** Invalid number after -d\n");
768 return 1;
769 }
770
771 }
772
773 else if (option.Matches ("s", true))
774 {
775
776 if (index + 1 < argc)
777 {
778 gMosaicPlane = atoi (argv [++index]);
779 }
780
781 else
782 {
783 fprintf (stderr, "*** Missing number after -s\n");
784 return 1;
785 }
786
787 }
788
789 else if (option.Matches ("b4", true))
790 {
791 gFourColorBayer = true;
792 }
793
794 else if (option.Matches ("ignoreEnhanced", true))
795 {
796 gIgnoreEnhanced = true;
797 }
798
799 else if (option.Matches ("size", true))
800 {
801
802 if (index + 1 < argc)
803 {
804 gPreferredSize = (uint32) atoi (argv [++index]);
805 }
806
807 else
808 {
809 fprintf (stderr, "*** Missing number after -size\n");
810 return 1;
811 }
812
813 }
814
815 else if (option.Matches ("min", true))
816 {
817
818 if (index + 1 < argc)
819 {
820 gMinimumSize = (uint32) atoi (argv [++index]);
821 }
822
823 else
824 {
825 fprintf (stderr, "*** Missing number after -min\n");
826 return 1;
827 }
828
829 }
830
831 else if (option.Matches ("max", true))
832 {
833
834 if (index + 1 < argc)
835 {
836 gMaximumSize = (uint32) atoi (argv [++index]);
837 }
838
839 else
840 {
841 fprintf (stderr, "*** Missing number after -max\n");
842 return 1;
843 }
844
845 }
846
847 else if (option.Matches ("proxy", true))
848 {
849
850 if (index + 1 < argc)
851 {
852 gProxyDNGSize = (uint32) atoi (argv [++index]);
853 }
854
855 else
856 {
857 fprintf (stderr, "*** Missing number after -proxy\n");
858 return 1;
859 }
860
861 }
862
863 else if (option.Matches ("lossyMosaicJXL", true))
864 {
865
866 gLossyMosaicJXL = true;
867
868 }
869
870 else if (option.Matches ("losslessJXL", true))
871 {
872
873 gLosslessJXL = true;
874
875 }
876
877 else if (option.Matches ("cs1", true))
878 {
879
880 gFinalSpace = &dng_space_sRGB::Get ();
881
882 }
883
884 else if (option.Matches ("cs2", true))
885 {
886
887 gFinalSpace = &dng_space_AdobeRGB::Get ();
888
889 }
890
891 else if (option.Matches ("cs3", true))
892 {
893
894 gFinalSpace = &dng_space_ProPhoto::Get ();
895
896 }
897
898 else if (option.Matches ("cs4", true))
899 {
900
901 gFinalSpace = &dng_space_ColorMatch::Get ();
902
903 }
904
905 else if (option.Matches ("cs5", true))
906 {
907
908 gFinalSpace = &dng_space_GrayGamma18::Get ();
909
910 }
911
912 else if (option.Matches ("cs6", true))
913 {
914
915 gFinalSpace = &dng_space_GrayGamma22::Get ();
916
917 }
918
919 else if (option.Matches ("csP3", true))
920 {
921
922 gFinalSpace = &dng_space_DisplayP3::Get ();
923
924 }
925
926 else if (option.Matches ("cs2020", true))
927 {
928
929 gFinalSpace = &dng_space_Rec2020::Get ();
930
931 }
932
933 else if (option.Matches ("16"))
934 {
935
936 gFinalPixelType = ttShort;
937
938 }
939
940 else if (option.Matches ("32"))
941 {
942
943 gFinalPixelType = ttFloat;
944
945 }
946
947 else if (option.Matches ("1"))
948 {
949
950 gDumpStage1.Clear ();
951
952 if (index + 1 < argc)
953 {
954 gDumpStage1.Set (argv [++index]);
955 }
956
957 if (gDumpStage1.IsEmpty () || gDumpStage1.StartsWith ("-"))
958 {
959 fprintf (stderr, "*** Missing file name after -1\n");
960 return 1;
961 }
962
963 if (!gDumpStage1.EndsWith (".tif"))
964 {
965 gDumpStage1.Append (".tif");
966 }
967
968 }
969
970 else if (option.Matches ("2"))
971 {
972
973 gDumpStage2.Clear ();
974
975 if (index + 1 < argc)
976 {
977 gDumpStage2.Set (argv [++index]);
978 }
979
980 if (gDumpStage2.IsEmpty () || gDumpStage2.StartsWith ("-"))
981 {
982 fprintf (stderr, "*** Missing file name after -2\n");
983 return 1;
984 }
985
986 if (!gDumpStage2.EndsWith (".tif"))
987 {
988 gDumpStage2.Append (".tif");
989 }
990
991 }
992
993 else if (option.Matches ("3"))
994 {
995
996 gDumpStage3.Clear ();
997
998 if (index + 1 < argc)
999 {
1000 gDumpStage3.Set (argv [++index]);
1001 }
1002
1003 if (gDumpStage3.IsEmpty () || gDumpStage3.StartsWith ("-"))
1004 {
1005 fprintf (stderr, "*** Missing file name after -3\n");
1006 return 1;
1007 }
1008
1009 if (!gDumpStage3.EndsWith (".tif"))
1010 {
1011 gDumpStage3.Append (".tif");
1012 }
1013
1014 }
1015
1016 else if (option.Matches ("profile"))
1017 {
1018
1019 gCameraProfileName.Clear ();
1020
1021 if (index + 1 < argc)
1022 {
1023 gCameraProfileName.Set (argv [++index]);
1024 }
1025
1026 if (gCameraProfileName.IsEmpty () || gCameraProfileName.StartsWith ("-"))
1027 {
1028 fprintf (stderr, "*** Missing profile name after -profile\n");
1029 return 1;
1030 }
1031
1032 }
1033
1034 else if (option.Matches ("transparency"))
1035 {
1036
1037 gDumpTransparency.Clear ();
1038
1039 if (index + 1 < argc)
1040 {
1041 gDumpTransparency.Set (argv [++index]);
1042 }
1043
1044 if (gDumpTransparency.IsEmpty () || gDumpTransparency.StartsWith ("-"))
1045 {
1046 fprintf (stderr, "*** Missing file name after -transparency\n");
1047 return 1;
1048 }
1049
1050 if (!gDumpTransparency.EndsWith (".tif"))
1051 {
1052 gDumpTransparency.Append (".tif");
1053 }
1054
1055 }
1056
1057 else if (option.Matches ("depthMap"))
1058 {
1059
1060 gDumpDepthMap.Clear ();
1061
1062 if (index + 1 < argc)
1063 {
1064 gDumpDepthMap.Set (argv [++index]);
1065 }
1066
1067 if (gDumpDepthMap.IsEmpty () || gDumpDepthMap.StartsWith ("-"))
1068 {
1069 fprintf (stderr, "*** Missing file name after -depthMap\n");
1070 return 1;
1071 }
1072
1073 if (!gDumpDepthMap.EndsWith (".tif"))
1074 {
1075 gDumpDepthMap.Append (".tif");
1076 }
1077
1078 }
1079
1080 else if (option.Matches ("tif", true))
1081 {
1082
1083 gDumpTIF.Clear ();
1084
1085 if (index + 1 < argc)
1086 {
1087 gDumpTIF.Set (argv [++index]);
1088 }
1089
1090 if (gDumpTIF.IsEmpty () || gDumpTIF.StartsWith ("-"))
1091 {
1092 fprintf (stderr, "*** Missing file name after -tif\n");
1093 return 1;
1094 }
1095
1096 if (!gDumpTIF.EndsWith (".tif"))
1097 {
1098 gDumpTIF.Append (".tif");
1099 }
1100
1101 }
1102
1103 else if (option.Matches ("dng", true))
1104 {
1105
1106 gDumpDNG.Clear ();
1107
1108 if (index + 1 < argc)
1109 {
1110 gDumpDNG.Set (argv [++index]);
1111 }
1112
1113 if (gDumpDNG.IsEmpty () || gDumpDNG.StartsWith ("-"))
1114 {
1115 fprintf (stderr, "*** Missing file name after -dng\n");
1116 return 1;
1117 }
1118
1119 if (!gDumpDNG.EndsWith (".dng"))
1120 {
1121 gDumpDNG.Append (".dng");
1122 }
1123
1124 }
1125
1126 else
1127 {
1128 fprintf (stderr, "*** Unknown option \"-%s\"\n", option.Get ());
1129 return 1;
1130 }
1131
1132 }
1133
1134 if (index == argc)
1135 {
1136 fprintf (stderr, "*** No file specified\n");
1137 return 1;
1138 }
1139
1140 #if qDNGUseXMP
1141 dng_xmp_sdk::InitializeSDK ();
1142 #endif
1143
1144 int result = 0;
1145
1146 while (index < argc)
1147 {
1148
1149 dng_error_code error_code = dng_validate (argv [index++]);
1150
1151 if (error_code != dng_error_none)
1152 {
1153
1154 result = error_code - dng_error_unknown + 100;
1155
1156 }
1157
1158 }
1159
1160 #if qDNGUseXMP
1161 dng_xmp_sdk::TerminateSDK ();
1162 #endif
1163
1164 return result;
1165
1166 }
1167
1168 catch (...)
1169 {
1170
1171 }
1172
1173 fprintf (stderr, "*** Exception thrown in main routine\n");
1174
1175 return 1;
1176
1177 }
1178
1179 /*****************************************************************************/
1180
1181 #endif
1182
1183 /*****************************************************************************/