]> granicus.if.org Git - imagemagick/blob - coders/fd.c
(no commit message)
[imagemagick] / coders / fd.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
6 %                               FFFFF  DDDD                                   %
7 %                               F      D   D                                  %
8 %                               FFF    D   D                                  %
9 %                               F      D   D                                  %
10 %                               F      DDDD                                   %
11 %                                                                             %
12 %                                                                             %
13 %                  Retrieve An Image Via a File Descriptor.                   %
14 %                                                                             %
15 %                              Software Design                                %
16 %                                John Cristy                                  %
17 %                              Bill Radcliffe                                 %
18 %                                March 2000                                   %
19 %                                                                             %
20 %                                                                             %
21 %  Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization      %
22 %  dedicated to making software imaging solutions freely available.           %
23 %                                                                             %
24 %  You may not use this file except in compliance with the License.  You may  %
25 %  obtain a copy of the License at                                            %
26 %                                                                             %
27 %    http://www.imagemagick.org/script/license.php                            %
28 %                                                                             %
29 %  Unless required by applicable law or agreed to in writing, software        %
30 %  distributed under the License is distributed on an "AS IS" BASIS,          %
31 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
32 %  See the License for the specific language governing permissions and        %
33 %  limitations under the License.                                             %
34 %                                                                             %
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 %
37 %
38 */
39 \f
40 /*
41   Include declarations.
42 */
43 #include "MagickCore/studio.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/constitute.h"
47 #include "MagickCore/exception.h"
48 #include "MagickCore/exception-private.h"
49 #include "MagickCore/image.h"
50 #include "MagickCore/image-private.h"
51 #include "MagickCore/list.h"
52 #include "MagickCore/magick.h"
53 #include "MagickCore/memory_.h"
54 #include "MagickCore/module.h"
55 #include "MagickCore/quantum-private.h"
56 #include "MagickCore/static.h"
57 #include "MagickCore/resource_.h"
58 #include "MagickCore/string_.h"
59 #include "MagickCore/string-private.h"
60 #include "MagickCore/utility.h"
61 \f
62 /*
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 %                                                                             %
65 %                                                                             %
66 %                                                                             %
67 %   R e a d F D I m a g e                                                     %
68 %                                                                             %
69 %                                                                             %
70 %                                                                             %
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 %
73 %  ReadFDImage retrieves an image via a file descriptor, decodes the image,
74 %  and returns it.  It allocates the memory necessary for the new Image
75 %  structure and returns a pointer to the new image.
76 %
77 %  The format of the ReadFDImage method is:
78 %
79 %      Image *ReadFDImage(const ImageInfo *image_info,ExceptionInfo *exception)
80 %
81 %  A description of each parameter follows:
82 %
83 %    o image_info: the image info.
84 %
85 %    o exception: return any errors or warnings in this structure.
86 %
87 */
88 static Image *ReadFDImage(const ImageInfo *image_info,ExceptionInfo *exception)
89 {
90   Image
91     *image;
92
93   ImageInfo
94     *read_info;
95
96   /*
97     Open image file.
98   */
99   assert(image_info != (const ImageInfo *) NULL);
100   assert(image_info->signature == MagickSignature);
101   if (image_info->debug != MagickFalse)
102     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
103       image_info->filename);
104   assert(exception != (ExceptionInfo *) NULL);
105   assert(exception->signature == MagickSignature);
106   read_info=CloneImageInfo(image_info);
107   read_info->file=fdopen(StringToLong(image_info->filename),"rb");
108   if (read_info->file ==  (FILE *) NULL)
109     {
110       ThrowFileException(exception,BlobError,"UnableToOpenBlob",
111         image_info->filename);
112       return((Image *) NULL);
113     }
114   *read_info->magick='\0';
115   image=ReadImage(read_info,exception);
116   (void) fclose(read_info->file);
117   read_info=DestroyImageInfo(read_info);
118   if (image == (Image *) NULL)
119     {
120       (void) ThrowMagickException(exception,GetMagickModule(),CoderError,
121         "NoDataReturned","`%s'",image_info->filename);
122       return((Image *) NULL);
123     }
124   return(GetFirstImageInList(image));
125 }
126 \f
127 /*
128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129 %                                                                             %
130 %                                                                             %
131 %                                                                             %
132 %   R e g i s t e r F D I m a g e                                             %
133 %                                                                             %
134 %                                                                             %
135 %                                                                             %
136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137 %
138 %  RegisterFDImage() adds attributes for the FD image format to
139 %  the list of supported formats.  The attributes include the image format
140 %  tag, a method to read and/or write the format, whether the format
141 %  supports the saving of more than one frame to the same file or blob,
142 %  whether the format supports native in-memory I/O, and a brief
143 %  description of the format.
144 %
145 %  The format of the RegisterFDImage method is:
146 %
147 %      size_t RegisterFDImage(void)
148 %
149 */
150 ModuleExport size_t RegisterFDImage(void)
151 {
152   MagickInfo
153     *entry;
154
155   entry=SetMagickInfo("FD");
156   entry->decoder=(DecodeImageHandler *) ReadFDImage;
157   entry->description=ConstantString("Read image from a file descriptor");
158   entry->module=ConstantString("FD");
159   entry->stealth=MagickTrue;
160   (void) RegisterMagickInfo(entry);
161   return(MagickImageCoderSignature);
162 }
163 \f
164 /*
165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166 %                                                                             %
167 %                                                                             %
168 %                                                                             %
169 %   U n r e g i s t e r F D I m a g e                                         %
170 %                                                                             %
171 %                                                                             %
172 %                                                                             %
173 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174 %
175 %  UnregisterFDImage() removes format registrations made by the FD module from
176 %  the list of supported formats.
177 %
178 %  The format of the UnregisterFDImage method is:
179 %
180 %      UnregisterFDImage(void)
181 %
182 */
183 ModuleExport void UnregisterFDImage(void)
184 {
185   (void) UnregisterMagickInfo("FD");
186 }