]> granicus.if.org Git - imagemagick/blob - coders/dng.c
Fixed api call to Ghostscript.
[imagemagick] / coders / dng.c
1 /*
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                                %
16 %                                   Cristy                                    %
17 %                                 July 1999                                   %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization      %
21 %  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 */
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"
65 \f
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 */
93 static 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);
117   image=AcquireImage(image_info,exception);
118   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   */
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",
135     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     {
141       (void) FormatLocaleString(read_info->filename,MaxTextExtent,"%s.ppm",
142         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);
156       (void) FormatLocaleString(filename,MaxTextExtent,"%s.ufraw",
157         read_info->unique);
158       sans=AcquireExceptionInfo();
159       xml=FileToString(filename,MaxTextExtent,sans);
160       (void) RelinquishUniqueFileResource(filename);
161       if (xml != (char *) NULL)
162         {
163           XMLTreeInfo
164             *ufraw;
165
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";
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),
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 \f
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 %
235 %      size_t RegisterDNGImage(void)
236 %
237 */
238 ModuleExport size_t RegisterDNGImage(void)
239 {
240   MagickInfo
241     *entry;
242
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("RMF");
372   entry->decoder=(DecodeImageHandler *) ReadDNGImage;
373   entry->blob_support=MagickFalse;
374   entry->seekable_stream=MagickTrue;
375   entry->format_type=ExplicitFormatType;
376   entry->description=ConstantString("Raw Media Format");
377   entry->module=ConstantString("DNG");
378   (void) RegisterMagickInfo(entry);
379   entry=SetMagickInfo("RW2");
380   entry->decoder=(DecodeImageHandler *) ReadDNGImage;
381   entry->blob_support=MagickFalse;
382   entry->seekable_stream=MagickTrue;
383   entry->format_type=ExplicitFormatType;
384   entry->description=ConstantString("Panasonic Lumix Raw Image");
385   entry->module=ConstantString("DNG");
386   (void) RegisterMagickInfo(entry);
387   entry=SetMagickInfo("SRF");
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");
393   entry->module=ConstantString("DNG");
394   (void) RegisterMagickInfo(entry);
395   entry=SetMagickInfo("SR2");
396   entry->decoder=(DecodeImageHandler *) ReadDNGImage;
397   entry->blob_support=MagickFalse;
398   entry->seekable_stream=MagickTrue;
399   entry->format_type=ExplicitFormatType;
400   entry->description=ConstantString("Sony Raw Format 2");
401   entry->module=ConstantString("DNG");
402   (void) RegisterMagickInfo(entry);
403   entry=SetMagickInfo("X3F");
404   entry->decoder=(DecodeImageHandler *) ReadDNGImage;
405   entry->blob_support=MagickFalse;
406   entry->seekable_stream=MagickTrue;
407   entry->format_type=ExplicitFormatType;
408   entry->description=ConstantString("Sigma Camera RAW Picture File");
409   entry->module=ConstantString("DNG");
410   (void) RegisterMagickInfo(entry);
411   return(MagickImageCoderSignature);
412 }
413 \f
414 /*
415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
416 %                                                                             %
417 %                                                                             %
418 %                                                                             %
419 %   U n r e g i s t e r D N G I m a g e                                       %
420 %                                                                             %
421 %                                                                             %
422 %                                                                             %
423 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
424 %
425 %  UnregisterDNGImage() removes format registrations made by the
426 %  BIM module from the list of supported formats.
427 %
428 %  The format of the UnregisterBIMImage method is:
429 %
430 %      UnregisterDNGImage(void)
431 %
432 */
433 ModuleExport void UnregisterDNGImage(void)
434 {
435   (void) UnregisterMagickInfo("X3F");
436   (void) UnregisterMagickInfo("SR2");
437   (void) UnregisterMagickInfo("SRF");
438   (void) UnregisterMagickInfo("RW2");
439   (void) UnregisterMagickInfo("RMF");
440   (void) UnregisterMagickInfo("RAF");
441   (void) UnregisterMagickInfo("PEF");
442   (void) UnregisterMagickInfo("ORF");
443   (void) UnregisterMagickInfo("NRW");
444   (void) UnregisterMagickInfo("NEF");
445   (void) UnregisterMagickInfo("MRW");
446   (void) UnregisterMagickInfo("MEF");
447   (void) UnregisterMagickInfo("K25");
448   (void) UnregisterMagickInfo("KDC");
449   (void) UnregisterMagickInfo("DCR");
450   (void) UnregisterMagickInfo("CRW");
451   (void) UnregisterMagickInfo("CR2");
452   (void) UnregisterMagickInfo("DNG");
453   (void) UnregisterMagickInfo("ARW");
454   (void) UnregisterMagickInfo("3FR");
455 }