2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Read the Digital Negative Image Format %
20 % Copyright 1999-2011 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 "magick/studio.h"
42 #include "magick/blob.h"
43 #include "magick/blob-private.h"
44 #include "magick/constitute.h"
45 #include "magick/delegate.h"
46 #include "magick/exception.h"
47 #include "magick/exception-private.h"
48 #include "magick/geometry.h"
49 #include "magick/image.h"
50 #include "magick/image-private.h"
51 #include "magick/layer.h"
52 #include "magick/list.h"
53 #include "magick/log.h"
54 #include "magick/magick.h"
55 #include "magick/memory_.h"
56 #include "magick/resource_.h"
57 #include "magick/quantum-private.h"
58 #include "magick/static.h"
59 #include "magick/string_.h"
60 #include "magick/module.h"
61 #include "magick/transform.h"
62 #include "magick/utility.h"
63 #include "magick/xml-tree.h"
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 % R e a d D N G I m a g e %
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 % ReadDNGImage() reads an binary file in the Digital Negative format and
77 % returns it. It allocates the memory necessary for the new Image structure
78 % and returns a pointer to the new image.
80 % The format of the ReadDNGImage method is:
82 % Image *ReadDNGImage(const ImageInfo *image_info,
83 % ExceptionInfo *exception)
85 % A description of each parameter follows:
87 % o image_info: the image info.
89 % o exception: return any errors or warnings in this structure.
92 static Image *ReadDNGImage(const ImageInfo *image_info,ExceptionInfo *exception)
109 assert(image_info != (const ImageInfo *) NULL);
110 assert(image_info->signature == MagickSignature);
111 if (image_info->debug != MagickFalse)
112 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
113 image_info->filename);
114 assert(exception != (ExceptionInfo *) NULL);
115 assert(exception->signature == MagickSignature);
116 image=AcquireImage(image_info);
117 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
118 if (status == MagickFalse)
120 image=DestroyImageList(image);
121 return((Image *) NULL);
123 (void) CloseBlob(image);
124 (void) DestroyImageList(image);
126 Convert DNG to PPM with delegate.
128 image=AcquireImage(image_info);
129 read_info=CloneImageInfo(image_info);
130 SetImageInfoBlob(read_info,(void *) NULL,0);
131 (void) InvokeDelegate(read_info,image,"dng:decode",(char *) NULL,exception);
132 image=DestroyImage(image);
133 (void) FormatLocaleString(read_info->filename,MaxTextExtent,"%s.png",
135 sans_exception=AcquireExceptionInfo();
136 image=ReadImage(read_info,sans_exception);
137 sans_exception=DestroyExceptionInfo(sans_exception);
138 if (image == (Image *) NULL)
140 (void) FormatLocaleString(read_info->filename,MaxTextExtent,"%s.ppm",
142 image=ReadImage(read_info,exception);
144 (void) RelinquishUniqueFileResource(read_info->filename);
145 if (image != (Image *) NULL)
148 filename[MaxTextExtent],
154 (void) CopyMagickString(image->magick,read_info->magick,MaxTextExtent);
155 (void) FormatLocaleString(filename,MaxTextExtent,"%s.ufraw",
157 sans=AcquireExceptionInfo();
158 xml=FileToString(filename,MaxTextExtent,sans);
159 (void) RelinquishUniqueFileResource(filename);
160 if (xml != (char *) NULL)
168 ufraw=NewXMLTree(xml,sans);
169 if (ufraw != (XMLTreeInfo *) NULL)
173 property[MaxTextExtent];
181 if (image->properties == (void *) NULL)
182 ((Image *) image)->properties=NewSplayTree(
183 CompareSplayTreeString,RelinquishMagickMemory,
184 RelinquishMagickMemory);
185 next=GetXMLTreeChild(ufraw,(const char *) NULL);
186 while (next != (XMLTreeInfo *) NULL)
188 tag=GetXMLTreeTag(next);
189 if (tag == (char *) NULL)
191 (void) FormatLocaleString(property,MaxTextExtent,"dng:%s",tag);
192 content=ConstantString(GetXMLTreeContent(next));
193 StripString(content);
194 if ((LocaleCompare(tag,"log") != 0) &&
195 (LocaleCompare(tag,"InputFilename") != 0) &&
196 (LocaleCompare(tag,"OutputFilename") != 0) &&
197 (LocaleCompare(tag,"OutputType") != 0) &&
198 (strlen(content) != 0))
199 (void) AddValueToSplayTree((SplayTreeInfo *)
200 ((Image *) image)->properties,ConstantString(property),
202 next=GetXMLTreeSibling(next);
204 ufraw=DestroyXMLTree(ufraw);
206 xml=DestroyString(xml);
208 sans=DestroyExceptionInfo(sans);
210 read_info=DestroyImageInfo(read_info);
215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
219 % R e g i s t e r D N G I m a g e %
223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225 % RegisterDNGImage() adds attributes for the DNG image format to
226 % the list of supported formats. The attributes include the image format
227 % tag, a method to read and/or write the format, whether the format
228 % supports the saving of more than one frame to the same file or blob,
229 % whether the format supports native in-memory I/O, and a brief
230 % description of the format.
232 % The format of the RegisterDNGImage method is:
234 % size_t RegisterDNGImage(void)
237 ModuleExport size_t RegisterDNGImage(void)
242 entry=SetMagickInfo("3FR");
243 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
244 entry->blob_support=MagickFalse;
245 entry->seekable_stream=MagickTrue;
246 entry->format_type=ExplicitFormatType;
247 entry->description=ConstantString("Hasselblad CFV/H3D39II");
248 entry->module=ConstantString("DNG");
249 (void) RegisterMagickInfo(entry);
250 entry=SetMagickInfo("ARW");
251 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
252 entry->blob_support=MagickFalse;
253 entry->seekable_stream=MagickTrue;
254 entry->format_type=ExplicitFormatType;
255 entry->description=ConstantString("Sony Alpha Raw Image Format");
256 entry->module=ConstantString("DNG");
257 (void) RegisterMagickInfo(entry);
258 entry=SetMagickInfo("DNG");
259 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
260 entry->blob_support=MagickFalse;
261 entry->seekable_stream=MagickTrue;
262 entry->format_type=ExplicitFormatType;
263 entry->description=ConstantString("Digital Negative");
264 entry->module=ConstantString("DNG");
265 (void) RegisterMagickInfo(entry);
266 entry=SetMagickInfo("CR2");
267 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
268 entry->blob_support=MagickFalse;
269 entry->seekable_stream=MagickTrue;
270 entry->format_type=ExplicitFormatType;
271 entry->description=ConstantString("Canon Digital Camera Raw Image Format");
272 entry->module=ConstantString("DNG");
273 (void) RegisterMagickInfo(entry);
274 entry=SetMagickInfo("CRW");
275 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
276 entry->blob_support=MagickFalse;
277 entry->seekable_stream=MagickTrue;
278 entry->format_type=ExplicitFormatType;
279 entry->description=ConstantString("Canon Digital Camera Raw Image Format");
280 entry->module=ConstantString("DNG");
281 (void) RegisterMagickInfo(entry);
282 entry=SetMagickInfo("DCR");
283 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
284 entry->blob_support=MagickFalse;
285 entry->seekable_stream=MagickTrue;
286 entry->format_type=ExplicitFormatType;
287 entry->description=ConstantString("Kodak Digital Camera Raw Image File");
288 entry->module=ConstantString("DNG");
289 (void) RegisterMagickInfo(entry);
290 entry=SetMagickInfo("ERF");
291 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
292 entry->blob_support=MagickFalse;
293 entry->seekable_stream=MagickTrue;
294 entry->format_type=ExplicitFormatType;
295 entry->description=ConstantString("Epson RAW Format");
296 entry->module=ConstantString("DNG");
297 (void) RegisterMagickInfo(entry);
298 entry=SetMagickInfo("KDC");
299 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
300 entry->blob_support=MagickFalse;
301 entry->seekable_stream=MagickTrue;
302 entry->format_type=ExplicitFormatType;
303 entry->description=ConstantString("Kodak Digital Camera Raw Image Format");
304 entry->module=ConstantString("DNG");
305 (void) RegisterMagickInfo(entry);
306 entry=SetMagickInfo("K25");
307 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
308 entry->blob_support=MagickFalse;
309 entry->seekable_stream=MagickTrue;
310 entry->format_type=ExplicitFormatType;
311 entry->description=ConstantString("Kodak Digital Camera Raw Image Format");
312 entry->module=ConstantString("DNG");
313 (void) RegisterMagickInfo(entry);
314 entry=SetMagickInfo("MRW");
315 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
316 entry->blob_support=MagickFalse;
317 entry->seekable_stream=MagickTrue;
318 entry->format_type=ExplicitFormatType;
319 entry->description=ConstantString("Sony (Minolta) Raw Image File");
320 entry->module=ConstantString("DNG");
321 (void) RegisterMagickInfo(entry);
322 entry=SetMagickInfo("NEF");
323 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
324 entry->blob_support=MagickFalse;
325 entry->seekable_stream=MagickTrue;
326 entry->format_type=ExplicitFormatType;
327 entry->description=ConstantString("Nikon Digital SLR Camera Raw Image File");
328 entry->module=ConstantString("DNG");
329 (void) RegisterMagickInfo(entry);
330 entry=SetMagickInfo("ORF");
331 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
332 entry->blob_support=MagickFalse;
333 entry->seekable_stream=MagickTrue;
334 entry->format_type=ExplicitFormatType;
335 entry->description=ConstantString("Olympus Digital Camera Raw Image File");
336 entry->module=ConstantString("DNG");
337 (void) RegisterMagickInfo(entry);
338 entry=SetMagickInfo("PEF");
339 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
340 entry->blob_support=MagickFalse;
341 entry->seekable_stream=MagickTrue;
342 entry->format_type=ExplicitFormatType;
343 entry->description=ConstantString("Pentax Electronic File");
344 entry->module=ConstantString("DNG");
345 (void) RegisterMagickInfo(entry);
346 entry=SetMagickInfo("RAF");
347 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
348 entry->blob_support=MagickFalse;
349 entry->seekable_stream=MagickTrue;
350 entry->format_type=ExplicitFormatType;
351 entry->description=ConstantString("Fuji CCD-RAW Graphic File");
352 entry->module=ConstantString("DNG");
353 (void) RegisterMagickInfo(entry);
354 entry=SetMagickInfo("SRF");
355 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
356 entry->blob_support=MagickFalse;
357 entry->seekable_stream=MagickTrue;
358 entry->format_type=ExplicitFormatType;
359 entry->description=ConstantString("Sony Raw Format");
360 entry->module=ConstantString("DNG");
361 (void) RegisterMagickInfo(entry);
362 entry=SetMagickInfo("SR2");
363 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
364 entry->blob_support=MagickFalse;
365 entry->seekable_stream=MagickTrue;
366 entry->format_type=ExplicitFormatType;
367 entry->description=ConstantString("Sony Raw Format 2");
368 entry->module=ConstantString("DNG");
369 (void) RegisterMagickInfo(entry);
370 entry=SetMagickInfo("X3F");
371 entry->decoder=(DecodeImageHandler *) ReadDNGImage;
372 entry->blob_support=MagickFalse;
373 entry->seekable_stream=MagickTrue;
374 entry->format_type=ExplicitFormatType;
375 entry->description=ConstantString("Sigma Camera RAW Picture File");
376 entry->module=ConstantString("DNG");
377 (void) RegisterMagickInfo(entry);
378 return(MagickImageCoderSignature);
382 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
386 % U n r e g i s t e r D N G I m a g e %
390 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
392 % UnregisterDNGImage() removes format registrations made by the
393 % BIM module from the list of supported formats.
395 % The format of the UnregisterBIMImage method is:
397 % UnregisterDNGImage(void)
400 ModuleExport void UnregisterDNGImage(void)
402 (void) UnregisterMagickInfo("X3F");
403 (void) UnregisterMagickInfo("SR2");
404 (void) UnregisterMagickInfo("SRF");
405 (void) UnregisterMagickInfo("RAF");
406 (void) UnregisterMagickInfo("PEF");
407 (void) UnregisterMagickInfo("ORF");
408 (void) UnregisterMagickInfo("NEF");
409 (void) UnregisterMagickInfo("MRW");
410 (void) UnregisterMagickInfo("K25");
411 (void) UnregisterMagickInfo("KDC");
412 (void) UnregisterMagickInfo("DCR");
413 (void) UnregisterMagickInfo("CRW");
414 (void) UnregisterMagickInfo("CR2");
415 (void) UnregisterMagickInfo("DNG");
416 (void) UnregisterMagickInfo("ARW");
417 (void) UnregisterMagickInfo("3FR");