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 % Cristy % 17 % Bill Radcliffe % 18 % March 2000 % 19 % % 20 % % 21 % Copyright 1999-2016 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 40 /* 42 Include declarations. 43 */ 44 #include "MagickCore/studio.h" 45 #include "MagickCore/blob.h" 46 #include "MagickCore/blob-private.h" 47 #include "MagickCore/constitute.h" 48 #include "MagickCore/exception.h" 49 #include "MagickCore/exception-private.h" 50 #include "MagickCore/image.h" 51 #include "MagickCore/image-private.h" 52 #include "MagickCore/list.h" 53 #include "MagickCore/magick.h" 54 #include "MagickCore/memory_.h" 55 #include "MagickCore/module.h" 56 #include "MagickCore/quantum-private.h" 57 #include "MagickCore/static.h" 58 #include "MagickCore/resource_.h" 59 #include "MagickCore/string_.h" 60 #include "MagickCore/string-private.h" 61 #include "MagickCore/utility.h" 62 63 /* 65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 66 % % 67 % % 68 % % 69 % R e a d F D I m a g e % 70 % % 71 % % 72 % % 73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 74 % 75 % ReadFDImage retrieves an image via a file descriptor, decodes the image, 76 % and returns it. It allocates the memory necessary for the new Image 77 % structure and returns a pointer to the new image. 78 % 79 % The format of the ReadFDImage method is: 80 % 81 % Image *ReadFDImage(const ImageInfo *image_info,ExceptionInfo *exception) 82 % 83 % A description of each parameter follows: 84 % 85 % o image_info: the image info. 86 % 87 % o exception: return any errors or warnings in this structure. 88 % 89 */ 90 static Image *ReadFDImage(const ImageInfo *image_info,ExceptionInfo *exception) 91 { 92 Image 93 *image; 94 95 ImageInfo 96 *read_info; 97 98 /* 99 Open image file. 100 */ 101 assert(image_info != (const ImageInfo *) NULL); 102 assert(image_info->signature == MagickCoreSignature); 103 if (image_info->debug != MagickFalse) 104 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", 105 image_info->filename); 106 assert(exception != (ExceptionInfo *) NULL); 107 assert(exception->signature == MagickCoreSignature); 108 read_info=CloneImageInfo(image_info); 109 read_info->file=fdopen(StringToLong(image_info->filename),"rb"); 110 if ((read_info->file == (FILE *) NULL) || 111 (IsGeometry(image_info->filename) == MagickFalse)) 112 { 113 read_info=DestroyImageInfo(read_info); 114 ThrowFileException(exception,BlobError,"UnableToOpenBlob", 115 image_info->filename); 116 return((Image *) NULL); 117 } 118 *read_info->magick='\0'; 119 image=ReadImage(read_info,exception); 120 (void) fclose(read_info->file); 121 read_info=DestroyImageInfo(read_info); 122 if (image == (Image *) NULL) 123 { 124 (void) ThrowMagickException(exception,GetMagickModule(),CoderError, 125 "NoDataReturned","`%s'",image_info->filename); 126 return((Image *) NULL); 127 } 128 return(GetFirstImageInList(image)); 129 } 130 131 /* 133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 134 % % 135 % % 136 % % 137 % R e g i s t e r F D I m a g e % 138 % % 139 % % 140 % % 141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 142 % 143 % RegisterFDImage() adds attributes for the FD image format to 144 % the list of supported formats. The attributes include the image format 145 % tag, a method to read and/or write the format, whether the format 146 % supports the saving of more than one frame to the same file or blob, 147 % whether the format supports native in-memory I/O, and a brief 148 % description of the format. 149 % 150 % The format of the RegisterFDImage method is: 151 % 152 % size_t RegisterFDImage(void) 153 % 154 */ 155 ModuleExport size_t RegisterFDImage(void) 156 { 157 MagickInfo 158 *entry; 159 160 entry=AcquireMagickInfo("FD","FD","Read image from a file descriptor"); 161 entry->decoder=(DecodeImageHandler *) ReadFDImage; 162 entry->flags|=CoderStealthFlag; 163 (void) RegisterMagickInfo(entry); 164 return(MagickImageCoderSignature); 165 } 166 167 /* 169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 170 % % 171 % % 172 % % 173 % U n r e g i s t e r F D I m a g e % 174 % % 175 % % 176 % % 177 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 178 % 179 % UnregisterFDImage() removes format registrations made by the FD module from 180 % the list of supported formats. 181 % 182 % The format of the UnregisterFDImage method is: 183 % 184 % UnregisterFDImage(void) 185 % 186 */ 187 ModuleExport void UnregisterFDImage(void) 188 { 189 (void) UnregisterMagickInfo("FD"); 190 } 191