2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Retrieve An Image Via a File Descriptor. %
21 % Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization %
22 % dedicated to making software imaging solutions freely available. %
24 % You may not use this file except in compliance with the License. You may %
25 % obtain a copy of the License at %
27 % https://www.imagemagick.org/script/license.php %
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. %
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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"
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 % R e a d F D I m a g e %
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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.
77 % The format of the ReadFDImage method is:
79 % Image *ReadFDImage(const ImageInfo *image_info,ExceptionInfo *exception)
81 % A description of each parameter follows:
83 % o image_info: the image info.
85 % o exception: return any errors or warnings in this structure.
88 static Image *ReadFDImage(const ImageInfo *image_info,ExceptionInfo *exception)
99 assert(image_info != (const ImageInfo *) NULL);
100 assert(image_info->signature == MagickCoreSignature);
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 == MagickCoreSignature);
106 read_info=CloneImageInfo(image_info);
107 read_info->file=fdopen(StringToLong(image_info->filename),"rb");
108 if ((read_info->file == (FILE *) NULL) ||
109 (IsGeometry(image_info->filename) == MagickFalse))
111 read_info=DestroyImageInfo(read_info);
112 ThrowFileException(exception,BlobError,"UnableToOpenBlob",
113 image_info->filename);
114 return((Image *) NULL);
116 *read_info->magick='\0';
117 image=ReadImage(read_info,exception);
118 (void) fclose(read_info->file);
119 read_info=DestroyImageInfo(read_info);
120 if (image == (Image *) NULL)
122 (void) ThrowMagickException(exception,GetMagickModule(),CoderError,
123 "NoDataReturned","`%s'",image_info->filename);
124 return((Image *) NULL);
126 return(GetFirstImageInList(image));
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 % R e g i s t e r F D I m a g e %
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 % RegisterFDImage() adds attributes for the FD image format to
141 % the list of supported formats. The attributes include the image format
142 % tag, a method to read and/or write the format, whether the format
143 % supports the saving of more than one frame to the same file or blob,
144 % whether the format supports native in-memory I/O, and a brief
145 % description of the format.
147 % The format of the RegisterFDImage method is:
149 % size_t RegisterFDImage(void)
152 ModuleExport size_t RegisterFDImage(void)
157 entry=AcquireMagickInfo("FD","FD","Read image from a file descriptor");
158 entry->decoder=(DecodeImageHandler *) ReadFDImage;
159 entry->flags|=CoderStealthFlag;
160 (void) RegisterMagickInfo(entry);
161 return(MagickImageCoderSignature);
165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169 % U n r e g i s t e r F D I m a g e %
173 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175 % UnregisterFDImage() removes format registrations made by the FD module from
176 % the list of supported formats.
178 % The format of the UnregisterFDImage method is:
180 % UnregisterFDImage(void)
183 ModuleExport void UnregisterFDImage(void)
185 (void) UnregisterMagickInfo("FD");