root / ImageMagick / trunk / coders / dng.c

Revision 11742, 15.4 kB (checked in by cristy, 4 weeks ago)
Line 
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%                                John Cristy                                  %
17%                                 July 1999                                   %
18%                                                                             %
19%                                                                             %
20%  Copyright 1999-2008 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 "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"
64
65/*
66%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67%                                                                             %
68%                                                                             %
69%                                                                             %
70%   R e a d D N G I m a g e                                                   %
71%                                                                             %
72%                                                                             %
73%                                                                             %
74%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75%
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.
79%
80%  The format of the ReadDNGImage method is:
81%
82%      Image *ReadDNGImage(const ImageInfo *image_info,
83%        ExceptionInfo *exception)
84%
85%  A description of each parameter follows:
86%
87%    o image_info: the image info.
88%
89%    o exception: return any errors or warnings in this structure.
90%
91*/
92static Image *ReadDNGImage(const ImageInfo *image_info,ExceptionInfo *exception)
93{
94  Image
95    *image;
96
97  ImageInfo
98    *read_info;
99
100  MagickBooleanType
101    status;
102
103  /*
104    Open image file.
105  */
106  assert(image_info != (const ImageInfo *) NULL);
107  assert(image_info->signature == MagickSignature);
108  if (image_info->debug != MagickFalse)
109    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
110      image_info->filename);
111  assert(exception != (ExceptionInfo *) NULL);
112  assert(exception->signature == MagickSignature);
113  image=AcquireImage(image_info);
114  status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
115  if (status == MagickFalse)
116    {
117      image=DestroyImageList(image);
118      return((Image *) NULL);
119    }
120  (void) CloseBlob(image);
121  (void) DestroyImageList(image);
122  /*
123    Convert DNG to PPM with delegate.
124  */
125  image=AcquireImage(image_info);
126  read_info=CloneImageInfo(image_info);
127  (void) InvokeDelegate(read_info,image,"dng:decode",(char *) NULL,exception);
128  image=DestroyImage(image);
129  (void) FormatMagickString(read_info->filename,MaxTextExtent,"%s.pnm",
130    read_info->unique);
131  image=ReadImage(read_info,exception);
132  (void) RelinquishUniqueFileResource(read_info->filename);
133  if (image != (Image *) NULL)
134    {
135      char
136        filename[MaxTextExtent],
137        *xml;
138
139      ExceptionInfo
140        *sans;
141
142      (void) CopyMagickString(image->magick,read_info->magick,MaxTextExtent);
143      (void) FormatMagickString(filename,MaxTextExtent,"%s.ufraw",
144        read_info->unique);
145      sans=AcquireExceptionInfo();
146      xml=FileToString(filename,MaxTextExtent,sans);
147      (void) RelinquishUniqueFileResource(filename);
148      if (xml != (char *) NULL)
149        {
150          XMLTreeInfo
151           *ufraw;
152
153          /*
154            Inject
155          */
156          ufraw=NewXMLTree(xml,sans);
157          if (ufraw != (XMLTreeInfo *) NULL)
158            {
159              char
160                *content,
161                property[MaxTextExtent];
162
163              const char
164                *tag;
165
166              XMLTreeInfo
167                *next;
168
169              if (image->properties == (void *) NULL)
170                ((Image *) image)->properties=NewSplayTree(
171                  CompareSplayTreeString,RelinquishMagickMemory,
172                  RelinquishMagickMemory);
173              next=GetXMLTreeChild(ufraw,(const char *) NULL);
174              while (next != (XMLTreeInfo *) NULL)
175              {
176                tag=GetXMLTreeTag(next);
177                if (tag == (char *) NULL)
178                  tag="unknown";
179                (void) FormatMagickString(property,MaxTextExtent,"dng:%s",tag);
180                content=ConstantString(GetXMLTreeContent(next));
181                StripString(content);
182                if ((LocaleCompare(tag,"log") != 0) &&
183                    (LocaleCompare(tag,"InputFilename") != 0) &&
184                    (LocaleCompare(tag,"OutputFilename") != 0) &&
185                    (LocaleCompare(tag,"OutputType") != 0) &&
186                    (strlen(content) != 0))
187                  (void) AddValueToSplayTree((SplayTreeInfo *)
188                    ((Image *) image)->properties,ConstantString(property),
189                    content);
190                next=GetXMLTreeSibling(next);
191              }
192              ufraw=DestroyXMLTree(ufraw);
193            }
194          xml=DestroyString(xml);
195        }
196      sans=DestroyExceptionInfo(sans);
197    }
198  read_info=DestroyImageInfo(read_info);
199  return(image);
200}
201
202/*
203%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204%                                                                             %
205%                                                                             %
206%                                                                             %
207%   R e g i s t e r D N G I m a g e                                           %
208%                                                                             %
209%                                                                             %
210%                                                                             %
211%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212%
213%  RegisterDNGImage() adds attributes for the DNG image format to
214%  the list of supported formats.  The attributes include the image format
215%  tag, a method to read and/or write the format, whether the format
216%  supports the saving of more than one frame to the same file or blob,
217%  whether the format supports native in-memory I/O, and a brief
218%  description of the format.
219%
220%  The format of the RegisterDNGImage method is:
221%
222%      unsigned long RegisterDNGImage(void)
223%
224*/
225ModuleExport unsigned long RegisterDNGImage(void)
226{
227  MagickInfo
228    *entry;
229
230  entry=SetMagickInfo("ARW");
231  entry->decoder=(DecodeImageHandler *) ReadDNGImage;
232  entry->blob_support=MagickFalse;
233  entry->format_type=ExplicitFormatType;
234  entry->description=ConstantString("Sony Alpha Raw Image Format");
235  entry->module=ConstantString("DNG");
236  (void) RegisterMagickInfo(entry);
237  entry=SetMagickInfo("DNG");
238  entry->decoder=(DecodeImageHandler *) ReadDNGImage;
239  entry->blob_support=MagickFalse;
240  entry->format_type=ExplicitFormatType;
241  entry->description=ConstantString("Digital Negative");
242  entry->module=ConstantString("DNG");
243  (void) RegisterMagickInfo(entry);
244  entry=SetMagickInfo("CR2");
245  entry->decoder=(DecodeImageHandler *) ReadDNGImage;
246  entry->blob_support=MagickFalse;
247  entry->format_type=ExplicitFormatType;
248  entry->description=ConstantString("Canon Digital Camera Raw Image Format");
249  entry->module=ConstantString("DNG");
250  (void) RegisterMagickInfo(entry);
251  entry=SetMagickInfo("CRW");
252  entry->decoder=(DecodeImageHandler *) ReadDNGImage;
253  entry->blob_support=MagickFalse;
254  entry->format_type=ExplicitFormatType;
255  entry->description=ConstantString("Canon Digital Camera Raw Image Format");
256  entry->module=ConstantString("DNG");
257  (void) RegisterMagickInfo(entry);
258  entry=SetMagickInfo("DCR");
259  entry->decoder=(DecodeImageHandler *) ReadDNGImage;
260  entry->blob_support=MagickFalse;
261  entry->format_type=ExplicitFormatType;
262  entry->description=ConstantString("Kodak Digital Camera Raw Image File");
263  entry->module=ConstantString("DNG");
264  (void) RegisterMagickInfo(entry);
265  entry=SetMagickInfo("ERF");
266  entry->decoder=(DecodeImageHandler *) ReadDNGImage;
267  entry->blob_support=MagickFalse;
268  entry->format_type=ExplicitFormatType;
269  entry->description=ConstantString("Epson RAW Format");
270  entry->module=ConstantString("DNG");
271  (void) RegisterMagickInfo(entry);
272  entry=SetMagickInfo("KDC");
273  entry->decoder=(DecodeImageHandler *) ReadDNGImage;
274  entry->blob_support=MagickFalse;
275  entry->format_type=ExplicitFormatType;
276  entry->description=ConstantString("Kodak Digital Camera Raw Image Format");
277  entry->module=ConstantString("DNG");
278  (void) RegisterMagickInfo(entry);
279  entry=SetMagickInfo("K25");
280  entry->decoder=(DecodeImageHandler *) ReadDNGImage;
281  entry->blob_support=MagickFalse;
282  entry->format_type=ExplicitFormatType;
283  entry->description=ConstantString("Kodak Digital Camera Raw Image Format");
284  entry->module=ConstantString("DNG");
285  (void) RegisterMagickInfo(entry);
286  entry=SetMagickInfo("MRW");
287  entry->decoder=(DecodeImageHandler *) ReadDNGImage;
288  entry->blob_support=MagickFalse;
289  entry->format_type=ExplicitFormatType;
290  entry->description=ConstantString("Sony (Minolta) Raw Image File");
291  entry->module=ConstantString("DNG");
292  (void) RegisterMagickInfo(entry);
293  entry=SetMagickInfo("NEF");
294  entry->decoder=(DecodeImageHandler *) ReadDNGImage;
295  entry->blob_support=MagickFalse;
296  entry->format_type=ExplicitFormatType;
297  entry->description=ConstantString("Nikon Digital SLR Camera Raw Image File");
298  entry->module=ConstantString("DNG");
299  (void) RegisterMagickInfo(entry);
300  entry=SetMagickInfo("ORF");
301  entry->decoder=(DecodeImageHandler *) ReadDNGImage;
302  entry->blob_support=MagickFalse;
303  entry->format_type=ExplicitFormatType;
304  entry->description=ConstantString("Olympus Digital Camera Raw Image File");
305  entry->module=ConstantString("DNG");
306  (void) RegisterMagickInfo(entry);
307  entry=SetMagickInfo("PEF");
308  entry->decoder=(DecodeImageHandler *) ReadDNGImage;
309  entry->blob_support=MagickFalse;
310  entry->format_type=ExplicitFormatType;
311  entry->description=ConstantString("Pentax Electronic File");
312  entry->module=ConstantString("DNG");
313  (void) RegisterMagickInfo(entry);
314  entry=SetMagickInfo("RAF");
315  entry->decoder=(DecodeImageHandler *) ReadDNGImage;
316  entry->blob_support=MagickFalse;
317  entry->format_type=ExplicitFormatType;
318  entry->description=ConstantString("Fuji CCD-RAW Graphic File");
319  entry->module=ConstantString("DNG");
320  (void) RegisterMagickInfo(entry);
321  entry=SetMagickInfo("SRF");
322  entry->decoder=(DecodeImageHandler *) ReadDNGImage;
323  entry->blob_support=MagickFalse;
324  entry->format_type=ExplicitFormatType;
325  entry->description=ConstantString("Sony Raw Format");
326  entry->module=ConstantString("DNG");
327  (void) RegisterMagickInfo(entry);
328  entry=SetMagickInfo("SR2");
329  entry->decoder=(DecodeImageHandler *) ReadDNGImage;
330  entry->blob_support=MagickFalse;
331  entry->format_type=ExplicitFormatType;
332  entry->description=ConstantString("Sony Raw Format 2");
333  entry->module=ConstantString("DNG");
334  (void) RegisterMagickInfo(entry);
335  entry=SetMagickInfo("X3F");
336  entry->decoder=(DecodeImageHandler *) ReadDNGImage;
337  entry->blob_support=MagickFalse;
338  entry->format_type=ExplicitFormatType;
339  entry->description=ConstantString("Sigma Camera RAW Picture File");
340  entry->module=ConstantString("DNG");
341  (void) RegisterMagickInfo(entry);
342  return(MagickImageCoderSignature);
343}
344
345/*
346%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
347%                                                                             %
348%                                                                             %
349%                                                                             %
350%   U n r e g i s t e r D N G I m a g e                                       %
351%                                                                             %
352%                                                                             %
353%                                                                             %
354%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
355%
356%  UnregisterDNGImage() removes format registrations made by the
357%  BIM module from the list of supported formats.
358%
359%  The format of the UnregisterBIMImage method is:
360%
361%      UnregisterDNGImage(void)
362%
363*/
364ModuleExport void UnregisterDNGImage(void)
365{
366  (void) UnregisterMagickInfo("X3F");
367  (void) UnregisterMagickInfo("SR2");
368  (void) UnregisterMagickInfo("SRF");
369  (void) UnregisterMagickInfo("RAF");
370  (void) UnregisterMagickInfo("PEF");
371  (void) UnregisterMagickInfo("ORF");
372  (void) UnregisterMagickInfo("NEF");
373  (void) UnregisterMagickInfo("MRW");
374  (void) UnregisterMagickInfo("K25");
375  (void) UnregisterMagickInfo("KDC");
376  (void) UnregisterMagickInfo("DCR");
377  (void) UnregisterMagickInfo("CRW");
378  (void) UnregisterMagickInfo("CR2");
379  (void) UnregisterMagickInfo("DNG");
380  (void) UnregisterMagickInfo("ARW");
381}
Note: See TracBrowser for help on using the browser.