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/* 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 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*/ 88static 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 == 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)) 110 { 111 read_info=DestroyImageInfo(read_info); 112 ThrowFileException(exception,BlobError,"UnableToOpenBlob", 113 image_info->filename); 114 return((Image *) NULL); 115 } 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) 121 { 122 (void) ThrowMagickException(exception,GetMagickModule(),CoderError, 123 "NoDataReturned","`%s'",image_info->filename); 124 return((Image *) NULL); 125 } 126 return(GetFirstImageInList(image)); 127} 128 129/* 130%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 131% % 132% % 133% % 134% R e g i s t e r F D I m a g e % 135% % 136% % 137% % 138%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 139% 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. 146% 147% The format of the RegisterFDImage method is: 148% 149% size_t RegisterFDImage(void) 150% 151*/ 152ModuleExport size_t RegisterFDImage(void) 153{ 154 MagickInfo 155 *entry; 156 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); 162} 163 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*/ 183ModuleExport void UnregisterFDImage(void) 184{ 185 (void) UnregisterMagickInfo("FD"); 186} 187