blob: 2f49c520e46d7f17ac39185e62b66eac9b139f6e [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% DDDD N N GGGG %
7% D D NN N GS %
8% D D N N N G GG %
9% D D N NN G G %
10% DDDD N N GGGG %
11% %
12% %
13% Read the Digital Negative Image Format %
14% %
15% Software Design %
cristyde984cd2013-12-01 14:49:27 +000016% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000017% July 1999 %
18% %
19% %
cristyfe676ee2013-11-18 13:03:38 +000020% Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
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. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37*/
38/*
39 Include declarations.
40*/
cristy4c08aed2011-07-01 19:47:50 +000041#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"
cristy433d1182011-09-04 13:38:52 +000064#include "MagickCore/xml-tree-private.h"
cristy3ed852e2009-09-05 21:47:34 +000065
66/*
67%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68% %
69% %
70% %
71% R e a d D N G I m a g e %
72% %
73% %
74% %
75%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76%
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.
80%
81% The format of the ReadDNGImage method is:
82%
83% Image *ReadDNGImage(const ImageInfo *image_info,
84% ExceptionInfo *exception)
85%
86% A description of each parameter follows:
87%
88% o image_info: the image info.
89%
90% o exception: return any errors or warnings in this structure.
91%
92*/
93static Image *ReadDNGImage(const ImageInfo *image_info,ExceptionInfo *exception)
94{
95 ExceptionInfo
96 *sans_exception;
97
98 Image
99 *image;
100
101 ImageInfo
102 *read_info;
103
104 MagickBooleanType
105 status;
106
107 /*
108 Open image file.
109 */
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);
cristy9950d572011-10-01 18:22:35 +0000117 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000118 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
119 if (status == MagickFalse)
120 {
121 image=DestroyImageList(image);
122 return((Image *) NULL);
123 }
124 (void) CloseBlob(image);
125 (void) DestroyImageList(image);
126 /*
127 Convert DNG to PPM with delegate.
128 */
cristy9950d572011-10-01 18:22:35 +0000129 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000130 read_info=CloneImageInfo(image_info);
cristy98f91ec2011-02-03 01:15:48 +0000131 SetImageInfoBlob(read_info,(void *) NULL,0);
cristy3ed852e2009-09-05 21:47:34 +0000132 (void) InvokeDelegate(read_info,image,"dng:decode",(char *) NULL,exception);
133 image=DestroyImage(image);
cristyb51dff52011-05-19 16:55:47 +0000134 (void) FormatLocaleString(read_info->filename,MaxTextExtent,"%s.png",
cristy3ed852e2009-09-05 21:47:34 +0000135 read_info->unique);
136 sans_exception=AcquireExceptionInfo();
137 image=ReadImage(read_info,sans_exception);
138 sans_exception=DestroyExceptionInfo(sans_exception);
139 if (image == (Image *) NULL)
140 {
cristyb51dff52011-05-19 16:55:47 +0000141 (void) FormatLocaleString(read_info->filename,MaxTextExtent,"%s.ppm",
cristy3ed852e2009-09-05 21:47:34 +0000142 read_info->unique);
143 image=ReadImage(read_info,exception);
144 }
145 (void) RelinquishUniqueFileResource(read_info->filename);
146 if (image != (Image *) NULL)
147 {
148 char
149 filename[MaxTextExtent],
150 *xml;
151
152 ExceptionInfo
153 *sans;
154
155 (void) CopyMagickString(image->magick,read_info->magick,MaxTextExtent);
cristyb51dff52011-05-19 16:55:47 +0000156 (void) FormatLocaleString(filename,MaxTextExtent,"%s.ufraw",
cristy3ed852e2009-09-05 21:47:34 +0000157 read_info->unique);
158 sans=AcquireExceptionInfo();
159 xml=FileToString(filename,MaxTextExtent,sans);
160 (void) RelinquishUniqueFileResource(filename);
161 if (xml != (char *) NULL)
162 {
163 XMLTreeInfo
cristyddbc41b2011-04-24 14:27:48 +0000164 *ufraw;
cristy3ed852e2009-09-05 21:47:34 +0000165
166 /*
167 Inject
168 */
169 ufraw=NewXMLTree(xml,sans);
170 if (ufraw != (XMLTreeInfo *) NULL)
171 {
172 char
173 *content,
174 property[MaxTextExtent];
175
176 const char
177 *tag;
178
179 XMLTreeInfo
180 *next;
181
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)
188 {
189 tag=GetXMLTreeTag(next);
190 if (tag == (char *) NULL)
191 tag="unknown";
cristyb51dff52011-05-19 16:55:47 +0000192 (void) FormatLocaleString(property,MaxTextExtent,"dng:%s",tag);
cristy3ed852e2009-09-05 21:47:34 +0000193 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),
202 content);
203 next=GetXMLTreeSibling(next);
204 }
205 ufraw=DestroyXMLTree(ufraw);
206 }
207 xml=DestroyString(xml);
208 }
209 sans=DestroyExceptionInfo(sans);
210 }
211 read_info=DestroyImageInfo(read_info);
212 return(image);
213}
214
215/*
216%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217% %
218% %
219% %
220% R e g i s t e r D N G I m a g e %
221% %
222% %
223% %
224%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225%
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.
232%
233% The format of the RegisterDNGImage method is:
234%
cristybb503372010-05-27 20:51:26 +0000235% size_t RegisterDNGImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000236%
237*/
cristybb503372010-05-27 20:51:26 +0000238ModuleExport size_t RegisterDNGImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000239{
240 MagickInfo
241 *entry;
242
cristy94c8fe42009-10-06 01:57:36 +0000243 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);
cristy3ed852e2009-09-05 21:47:34 +0000251 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);
cristy1be98ec2012-01-30 16:51:12 +0000315 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);
cristy3ed852e2009-09-05 21:47:34 +0000323 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);
cristycb8f0ae2012-03-02 12:26:21 +0000339 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);
cristy3ed852e2009-09-05 21:47:34 +0000347 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);
cristy98aceb82012-10-20 21:24:00 +0000371 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);
cristy3ed852e2009-09-05 21:47:34 +0000379 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);
404}
405
406/*
407%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
408% %
409% %
410% %
411% U n r e g i s t e r D N G I m a g e %
412% %
413% %
414% %
415%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
416%
417% UnregisterDNGImage() removes format registrations made by the
418% BIM module from the list of supported formats.
419%
420% The format of the UnregisterBIMImage method is:
421%
422% UnregisterDNGImage(void)
423%
424*/
425ModuleExport void UnregisterDNGImage(void)
426{
427 (void) UnregisterMagickInfo("X3F");
428 (void) UnregisterMagickInfo("SR2");
429 (void) UnregisterMagickInfo("SRF");
cristy98aceb82012-10-20 21:24:00 +0000430 (void) UnregisterMagickInfo("RW2");
cristy3ed852e2009-09-05 21:47:34 +0000431 (void) UnregisterMagickInfo("RAF");
432 (void) UnregisterMagickInfo("PEF");
433 (void) UnregisterMagickInfo("ORF");
cristycb8f0ae2012-03-02 12:26:21 +0000434 (void) UnregisterMagickInfo("NRW");
cristy3ed852e2009-09-05 21:47:34 +0000435 (void) UnregisterMagickInfo("NEF");
436 (void) UnregisterMagickInfo("MRW");
cristy800c7c42012-01-30 16:51:59 +0000437 (void) UnregisterMagickInfo("MEF");
cristy3ed852e2009-09-05 21:47:34 +0000438 (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");
cristy94c8fe42009-10-06 01:57:36 +0000445 (void) UnregisterMagickInfo("3FR");
cristy3ed852e2009-09-05 21:47:34 +0000446}