From 3f07aa32d07062e4eec2a0a43ed37d26952cfde9 Mon Sep 17 00:00:00 2001 From: cristy Date: Sat, 18 Jan 2014 01:16:33 +0000 Subject: [PATCH] --- coders/json.c | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 coders/json.c diff --git a/coders/json.c b/coders/json.c new file mode 100644 index 000000000..78edb353f --- /dev/null +++ b/coders/json.c @@ -0,0 +1,219 @@ +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% JJJJJ SSSSS OOO N N % +% J SS O O NN N % +% J SSS O O N N N % +% J J SS O O N NN % +% JJJ SSSSS OOO N N % +% % +% % +% Write Info About the Image in JSON Format. % +% % +% Software Design % +% Cristy % +% January 2014 % +% % +% % +% Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization % +% dedicated to making software imaging solutions freely available. % +% % +% You may not use this file except in compliance with the License. You may % +% obtain a copy of the License at % +% % +% http://www.imagemagick.org/script/license.php % +% % +% Unless required by applicable law or agreed to in writing, software % +% distributed under the License is distributed on an "AS IS" BASIS, % +% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % +% See the License for the specific language governing permissions and % +% limitations under the License. % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% +*/ + +/* + Include declarations. +*/ +#include "MagickCore/studio.h" +#include "MagickCore/artifact.h" +#include "MagickCore/blob.h" +#include "MagickCore/blob-private.h" +#include "MagickCore/colorspace.h" +#include "MagickCore/exception.h" +#include "MagickCore/exception-private.h" +#include "MagickCore/identify.h" +#include "MagickCore/image.h" +#include "MagickCore/image-private.h" +#include "MagickCore/list.h" +#include "MagickCore/magick.h" +#include "MagickCore/memory_.h" +#include "MagickCore/monitor.h" +#include "MagickCore/monitor-private.h" +#include "MagickCore/option.h" +#include "MagickCore/property.h" +#include "MagickCore/quantum-private.h" +#include "MagickCore/static.h" +#include "MagickCore/string_.h" +#include "MagickCore/module.h" +#include "MagickCore/utility.h" + +/* + Forward declarations. +*/ +static MagickBooleanType + WriteJSONImage(const ImageInfo *,Image *,ExceptionInfo *); + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% R e g i s t e r J S O N I m a g e % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% RegisterJSONImage() adds attributes for the JSON image format to +% the list of supported formats. The attributes include the image format +% tag, a method to read and/or write the format, whether the format +% supports the saving of more than one frame to the same file or blob, +% whether the format supports native in-memory I/O, and a brief +% description of the format. +% +% The format of the RegisterJSONImage method is: +% +% size_t RegisterJSONImage(void) +% +*/ +ModuleExport size_t RegisterJSONImage(void) +{ + MagickInfo + *entry; + + entry=SetMagickInfo("JSON"); + entry->encoder=(EncodeImageHandler *) WriteJSONImage; + entry->blob_support=MagickFalse; + entry->description=ConstantString("The image format and characteristics"); + entry->module=ConstantString("JSON"); + (void) RegisterMagickInfo(entry); + return(MagickImageCoderSignature); +} + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% U n r e g i s t e r J S O N I m a g e % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% UnregisterJSONImage() removes format registrations made by the +% JSON module from the list of supported formats. +% +% The format of the UnregisterJSONImage method is: +% +% UnregisterJSONImage(void) +% +*/ +ModuleExport void UnregisterJSONImage(void) +{ + (void) UnregisterMagickInfo("JSON"); +} + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% W r i t e J S O N I m a g e % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% WriteJSONImage writes the image attributes in the JSON format. +% +% The format of the WriteJSONImage method is: +% +% MagickBooleanType WriteJSONImage(const ImageInfo *image_info, +% Image *image,ExceptionInfo *exception) +% +% A description of each parameter follows. +% +% o image_info: the image info. +% +% o image: The image. +% +% o exception: return any errors or warnings in this structure. +% +*/ +static MagickBooleanType WriteJSONImage(const ImageInfo *image_info, + Image *image,ExceptionInfo *exception) +{ + const char + *format; + + MagickBooleanType + status; + + MagickOffsetType + scene; + + /* + Open output image file. + */ + assert(image_info != (const ImageInfo *) NULL); + assert(image_info->signature == MagickSignature); + assert(image != (Image *) NULL); + assert(image->signature == MagickSignature); + if (image->debug != MagickFalse) + (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); + status=OpenBlob(image_info,image,WriteBlobMode,exception); + if (status == MagickFalse) + return(status); + scene=0; + do + { + format=GetImageOption(image_info,"format"); + if (format == (char *) NULL) + { + (void) CopyMagickString(image->filename,image->magick_filename, + MaxTextExtent); + image->magick_columns=image->columns; + image->magick_rows=image->rows; + (void) IdentifyImage(image,GetBlobFileHandle(image), + image_info->verbose,exception); + } + else + { + char + *text; + + text=InterpretImageProperties((ImageInfo *) image_info,image,format, + exception); + if (text != (char *) NULL) + { + (void) WriteBlobString(image,text); + text=DestroyString(text); + } + } + if (GetNextImageInList(image) == (Image *) NULL) + break; + image=SyncNextImageInList(image); + status=SetImageProgress(image,SaveImagesTag,scene++, + GetImageListLength(image)); + if (status == MagickFalse) + break; + } while (image_info->adjoin != MagickFalse); + (void) CloseBlob(image); + return(MagickTrue); +} -- 2.40.0