2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read the Digital Negative Image Format %
20 % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 #include "MagickCore/studio.h"
42 #include "MagickCore/blob.h"
43 #include "MagickCore/blob-private.h"
44 #include "MagickCore/constitute.h"
45 #include "MagickCore/delegate.h"
46 #include "MagickCore/exception.h"
47 #include "MagickCore/exception-private.h"
48 #include "MagickCore/geometry.h"
49 #include "MagickCore/image.h"
50 #include "MagickCore/image-private.h"
51 #include "MagickCore/layer.h"
52 #include "MagickCore/list.h"
53 #include "MagickCore/log.h"
54 #include "MagickCore/magick.h"
55 #include "MagickCore/memory_.h"
56 #include "MagickCore/resource_.h"
57 #include "MagickCore/quantum-private.h"
58 #include "MagickCore/static.h"
59 #include "MagickCore/string_.h"
60 #include "MagickCore/module.h"
61 #include "MagickCore/transform.h"
62 #include "MagickCore/utility.h"
63 #include "MagickCore/xml-tree.h"
64 #include "MagickCore/xml-tree-private.h"
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 % R e a d D N G I m a g e %
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 % ReadDNGImage() reads an binary file in the Digital Negative format and
78 % returns it. It allocates the memory necessary for the new Image structure
79 % and returns a pointer to the new image.
81 % The format of the ReadDNGImage method is:
83 % Image *ReadDNGImage(const ImageInfo *image_info,
84 % ExceptionInfo *exception)
86 % A description of each parameter follows:
88 % o image_info: the image info.
90 % o exception: return any errors or warnings in this structure.
93 static Image *ReadDNGImage(const ImageInfo *image_info,ExceptionInfo *exception)
110 assert(image_info != (const ImageInfo *) NULL);
111 assert(image_info->signature == MagickSignature);
112 if (image_info->debug != MagickFalse)
113 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
114 image_info->filename);
115 assert(exception != (ExceptionInfo *) NULL);
116 assert(exception->signature == MagickSignature);
117 image=AcquireImage(image_info,exception);
118 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
119 if (status == MagickFalse)
121 image=DestroyImageList(image);
122 return((Image *) NULL);
124 (void) CloseBlob(image);
125 (void) DestroyImageList(image);
127 Convert DNG to PPM with delegate.
129 image=AcquireImage(image_info,exception);
130 read_info=CloneImageInfo(image_info);
131 SetImageInfoBlob(read_info,(void *) NULL,0);
132 (void) InvokeDelegate(read_info,image,"dng:decode",(char *) NULL,exception);
133 image=DestroyImage(image);
134 (void) FormatLocaleString(read_info->filename,MaxTextExtent,"%s.png",
136 sans_exception=AcquireExceptionInfo();
137 image=ReadImage(read_info,sans_exception);
138 sans_exception=DestroyExceptionInfo(sans_exception);
139 if (image == (Image *) NULL)
141 (void) FormatLocaleString(read_info->filename,MaxTextExtent,"%s.ppm",
143 image=ReadImage(read_info,exception);
145 (void) RelinquishUniqueFileResource(read_info->filename);
146 if (image != (Image *) NULL)
149 filename[MaxTextExtent],
155 (void) CopyMagickString(image->magick,read_info->magick,MaxTextExtent);
156 (void) FormatLocaleString(filename,MaxTextExtent,"%s.ufraw",
158 sans=AcquireExceptionInfo();
159 xml=FileToString(filename,MaxTextExtent,sans);
160 (void) RelinquishUniqueFileResource(filename);
161 if (xml != (char *) NULL)
169 ufraw=NewXMLTree(xml,sans);
170 if (ufraw != (XMLTreeInfo *) NULL)
174 property[MaxTextExtent];
182 if (image->properties == (void *) NULL)
183 ((Image *) image)->properties=NewSplayTree(
184 CompareSplayTreeString,RelinquishMagickMemory,
185 RelinquishMagickMemory);
186 next=GetXMLTreeChild(ufraw,(const char *) NULL);
187 while (next != (XMLTreeInfo *) NULL)
189 tag=GetXMLTreeTag(next);
190 if (tag == (char *) NULL)
192 (void) FormatLocaleString(property,MaxTextExtent,"dng:%s",tag);
193 content=ConstantString(GetXMLTreeContent(next));
194 StripString(content);
195 if ((LocaleCompare(tag,"log") != 0) &&
196 (LocaleCompare(tag,"InputFilename") != 0) &&
197 (LocaleCompare(tag,"OutputFilename") != 0) &&
198 (LocaleCompare(tag,"OutputType") != 0) &&
199 (strlen(content) != 0))
200 (void) AddValueToSplayTree((SplayTreeInfo *)
201 ((Image *) image)->properties,ConstantString(property),
203 next=GetXMLTreeSibling(next);
205 ufraw=DestroyXMLTree(ufraw);
207 xml=DestroyString(xml);
209 sans=DestroyExceptionInfo(sans);
211 read_info=DestroyImageInfo(read_info);
216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220 % R e g i s t e r D N G I m a g e %
224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 % RegisterDNGImage() adds attributes for the DNG image format to
227 % the list of supported formats. The attributes include the image format
228 % tag, a method to read and/or write the format, whether the format
229 % supports the saving of more than one frame to the same file or blob,
230 % whether the format supports native in-memory I/O, and a brief
231 % description of the format.
233 % The format of the RegisterDNGImage method is:
235 % size_t RegisterDNGImage(void)
238 ModuleExport size_t RegisterDNGImage(void)
243 entry=SetMagickInfo("3FR");
244 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
245 entry->blob_support=MagickFalse;
246 entry->seekable_stream=MagickTrue;
247 entry->format_type=ExplicitFormatType;
248 entry->description=ConstantString("Hasselblad CFV/H3D39II");
249 entry->module=ConstantString("DNG");
250 (void) RegisterMagickInfo(entry);
251 entry=SetMagickInfo("ARW");
252 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
253 entry->blob_support=MagickFalse;
254 entry->seekable_stream=MagickTrue;
255 entry->format_type=ExplicitFormatType;
256 entry->description=ConstantString("Sony Alpha Raw Image Format");
257 entry->module=ConstantString("DNG");
258 (void) RegisterMagickInfo(entry);
259 entry=SetMagickInfo("DNG");
260 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
261 entry->blob_support=MagickFalse;
262 entry->seekable_stream=MagickTrue;
263 entry->format_type=ExplicitFormatType;
264 entry->description=ConstantString("Digital Negative");
265 entry->module=ConstantString("DNG");
266 (void) RegisterMagickInfo(entry);
267 entry=SetMagickInfo("CR2");
268 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
269 entry->blob_support=MagickFalse;
270 entry->seekable_stream=MagickTrue;
271 entry->format_type=ExplicitFormatType;
272 entry->description=ConstantString("Canon Digital Camera Raw Image Format");
273 entry->module=ConstantString("DNG");
274 (void) RegisterMagickInfo(entry);
275 entry=SetMagickInfo("CRW");
276 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
277 entry->blob_support=MagickFalse;
278 entry->seekable_stream=MagickTrue;
279 entry->format_type=ExplicitFormatType;
280 entry->description=ConstantString("Canon Digital Camera Raw Image Format");
281 entry->module=ConstantString("DNG");
282 (void) RegisterMagickInfo(entry);
283 entry=SetMagickInfo("DCR");
284 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
285 entry->blob_support=MagickFalse;
286 entry->seekable_stream=MagickTrue;
287 entry->format_type=ExplicitFormatType;
288 entry->description=ConstantString("Kodak Digital Camera Raw Image File");
289 entry->module=ConstantString("DNG");
290 (void) RegisterMagickInfo(entry);
291 entry=SetMagickInfo("ERF");
292 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
293 entry->blob_support=MagickFalse;
294 entry->seekable_stream=MagickTrue;
295 entry->format_type=ExplicitFormatType;
296 entry->description=ConstantString("Epson RAW Format");
297 entry->module=ConstantString("DNG");
298 (void) RegisterMagickInfo(entry);
299 entry=SetMagickInfo("KDC");
300 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
301 entry->blob_support=MagickFalse;
302 entry->seekable_stream=MagickTrue;
303 entry->format_type=ExplicitFormatType;
304 entry->description=ConstantString("Kodak Digital Camera Raw Image Format");
305 entry->module=ConstantString("DNG");
306 (void) RegisterMagickInfo(entry);
307 entry=SetMagickInfo("K25");
308 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
309 entry->blob_support=MagickFalse;
310 entry->seekable_stream=MagickTrue;
311 entry->format_type=ExplicitFormatType;
312 entry->description=ConstantString("Kodak Digital Camera Raw Image Format");
313 entry->module=ConstantString("DNG");
314 (void) RegisterMagickInfo(entry);
315 entry=SetMagickInfo("MEF");
316 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
317 entry->blob_support=MagickFalse;
318 entry->seekable_stream=MagickTrue;
319 entry->format_type=ExplicitFormatType;
320 entry->description=ConstantString("Mamiya Raw Image File");
321 entry->module=ConstantString("DNG");
322 (void) RegisterMagickInfo(entry);
323 entry=SetMagickInfo("MRW");
324 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
325 entry->blob_support=MagickFalse;
326 entry->seekable_stream=MagickTrue;
327 entry->format_type=ExplicitFormatType;
328 entry->description=ConstantString("Sony (Minolta) Raw Image File");
329 entry->module=ConstantString("DNG");
330 (void) RegisterMagickInfo(entry);
331 entry=SetMagickInfo("NEF");
332 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
333 entry->blob_support=MagickFalse;
334 entry->seekable_stream=MagickTrue;
335 entry->format_type=ExplicitFormatType;
336 entry->description=ConstantString("Nikon Digital SLR Camera Raw Image File");
337 entry->module=ConstantString("DNG");
338 (void) RegisterMagickInfo(entry);
339 entry=SetMagickInfo("NRW");
340 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
341 entry->blob_support=MagickFalse;
342 entry->seekable_stream=MagickTrue;
343 entry->format_type=ExplicitFormatType;
344 entry->description=ConstantString("Nikon Digital SLR Camera Raw Image File");
345 entry->module=ConstantString("DNG");
346 (void) RegisterMagickInfo(entry);
347 entry=SetMagickInfo("ORF");
348 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
349 entry->blob_support=MagickFalse;
350 entry->seekable_stream=MagickTrue;
351 entry->format_type=ExplicitFormatType;
352 entry->description=ConstantString("Olympus Digital Camera Raw Image File");
353 entry->module=ConstantString("DNG");
354 (void) RegisterMagickInfo(entry);
355 entry=SetMagickInfo("PEF");
356 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
357 entry->blob_support=MagickFalse;
358 entry->seekable_stream=MagickTrue;
359 entry->format_type=ExplicitFormatType;
360 entry->description=ConstantString("Pentax Electronic File");
361 entry->module=ConstantString("DNG");
362 (void) RegisterMagickInfo(entry);
363 entry=SetMagickInfo("RAF");
364 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
365 entry->blob_support=MagickFalse;
366 entry->seekable_stream=MagickTrue;
367 entry->format_type=ExplicitFormatType;
368 entry->description=ConstantString("Fuji CCD-RAW Graphic File");
369 entry->module=ConstantString("DNG");
370 (void) RegisterMagickInfo(entry);
371 entry=SetMagickInfo("RW2");
372 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
373 entry->blob_support=MagickFalse;
374 entry->seekable_stream=MagickTrue;
375 entry->format_type=ExplicitFormatType;
376 entry->description=ConstantString("Panasonic Lumix Raw Image");
377 entry->module=ConstantString("DNG");
378 (void) RegisterMagickInfo(entry);
379 entry=SetMagickInfo("SRF");
380 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
381 entry->blob_support=MagickFalse;
382 entry->seekable_stream=MagickTrue;
383 entry->format_type=ExplicitFormatType;
384 entry->description=ConstantString("Sony Raw Format");
385 entry->module=ConstantString("DNG");
386 (void) RegisterMagickInfo(entry);
387 entry=SetMagickInfo("SR2");
388 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
389 entry->blob_support=MagickFalse;
390 entry->seekable_stream=MagickTrue;
391 entry->format_type=ExplicitFormatType;
392 entry->description=ConstantString("Sony Raw Format 2");
393 entry->module=ConstantString("DNG");
394 (void) RegisterMagickInfo(entry);
395 entry=SetMagickInfo("X3F");
396 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
397 entry->blob_support=MagickFalse;
398 entry->seekable_stream=MagickTrue;
399 entry->format_type=ExplicitFormatType;
400 entry->description=ConstantString("Sigma Camera RAW Picture File");
401 entry->module=ConstantString("DNG");
402 (void) RegisterMagickInfo(entry);
403 return(MagickImageCoderSignature);
407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411 % U n r e g i s t e r D N G I m a g e %
415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
417 % UnregisterDNGImage() removes format registrations made by the
418 % BIM module from the list of supported formats.
420 % The format of the UnregisterBIMImage method is:
422 % UnregisterDNGImage(void)
425 ModuleExport void UnregisterDNGImage(void)
427 (void) UnregisterMagickInfo("X3F");
428 (void) UnregisterMagickInfo("SR2");
429 (void) UnregisterMagickInfo("SRF");
430 (void) UnregisterMagickInfo("RW2");
431 (void) UnregisterMagickInfo("RAF");
432 (void) UnregisterMagickInfo("PEF");
433 (void) UnregisterMagickInfo("ORF");
434 (void) UnregisterMagickInfo("NRW");
435 (void) UnregisterMagickInfo("NEF");
436 (void) UnregisterMagickInfo("MRW");
437 (void) UnregisterMagickInfo("MEF");
438 (void) UnregisterMagickInfo("K25");
439 (void) UnregisterMagickInfo("KDC");
440 (void) UnregisterMagickInfo("DCR");
441 (void) UnregisterMagickInfo("CRW");
442 (void) UnregisterMagickInfo("CR2");
443 (void) UnregisterMagickInfo("DNG");
444 (void) UnregisterMagickInfo("ARW");
445 (void) UnregisterMagickInfo("3FR");