From: Cristy Date: Sat, 13 Jul 2019 13:06:57 +0000 (-0400) Subject: Move ByteBuffer into the Magick namespace X-Git-Tag: 7.0.8-54~49 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b13bbd7aa0a98de07bc4ac2afb8f108f152a41db;p=imagemagick Move ByteBuffer into the Magick namespace --- diff --git a/coders/Makefile.am b/coders/Makefile.am index 05cf1bdb1..0a72efa5e 100644 --- a/coders/Makefile.am +++ b/coders/Makefile.am @@ -232,7 +232,7 @@ CODERS_NOINST_HDRS = \ coders/bgr.h \ coders/bmp.h \ coders/braille.h \ - coders/byte-buffer-private.h \ + coders/bytebuffer-private.h \ coders/cals.h \ coders/caption.h \ coders/cin.h \ diff --git a/coders/byte-buffer-private.h b/coders/bytebuffer-private.h similarity index 73% rename from coders/byte-buffer-private.h rename to coders/bytebuffer-private.h index 919c546d3..db516d99e 100644 --- a/coders/byte-buffer-private.h +++ b/coders/bytebuffer-private.h @@ -16,7 +16,7 @@ #ifndef MAGICK_BYTE_BUFFER_PRIVATE_H #define MAGICK_BYTE_BUFFER_PRIVATE_H -typedef struct _ByteBuffer +typedef struct _MagickByteBuffer { Image *image; @@ -27,9 +27,9 @@ typedef struct _ByteBuffer unsigned char data[8192]; -} ByteBuffer; +} MagickByteBuffer; -static int ReadByteBuffer(ByteBuffer *buffer) +static inline int ReadMagickByteBuffer(MagickByteBuffer *buffer) { if ((buffer->offset == buffer->count) && (buffer->offset > 0)) { @@ -46,12 +46,12 @@ static int ReadByteBuffer(ByteBuffer *buffer) return(buffer->data[buffer->offset++]); } -static char *GetByteBufferDatum(ByteBuffer *buffer) +static inline char *GetMagickByteBufferDatum(MagickByteBuffer *buffer) { ssize_t i; - i=1; /* Skip first to avoid reload of buffer; */ + i=1; /* Skip first to avoid reload of buffer */ while (buffer->offset < buffer->count) buffer->data[i++]=buffer->data[buffer->offset++]; buffer->count=ReadBlob(buffer->image,sizeof(buffer->data)-i,buffer->data+i); @@ -60,30 +60,32 @@ static char *GetByteBufferDatum(ByteBuffer *buffer) return((char *) buffer->data+1); } -static inline void CheckRemainingByteBuffer(ByteBuffer *buffer,size_t length) +static void CheckMagickByteBuffer(MagickByteBuffer *buffer, + const size_t length) { if ((buffer->offset+length) > (ssize_t) sizeof(buffer->data)) - (void) GetByteBufferDatum(buffer); + (void) GetMagickByteBufferDatum(buffer); } -static inline void SkipByteBuffer(ByteBuffer *buffer,size_t length) -{ - CheckRemainingByteBuffer(buffer,length); - if ((buffer->offset+length) < buffer->count) - buffer->offset+=length; -} - -static MagickBooleanType CompareByteBuffer(const char *p,ByteBuffer *buffer, - const size_t length) +static MagickBooleanType CompareMagickByteBuffer(MagickByteBuffer *buffer, + const char *p,const size_t length) { const char *q; - CheckRemainingByteBuffer(buffer,length); + CheckMagickByteBuffer(buffer,length); q=(const char *) buffer->data+buffer->offset; if (LocaleNCompare(p,q,length) != 0) return(MagickFalse); return(MagickTrue); } -#endif \ No newline at end of file +static inline void SkipMagickByteBuffer(MagickByteBuffer *buffer, + const size_t length) +{ + CheckMagickByteBuffer(buffer,length); + if ((buffer->offset+length) < buffer->count) + buffer->offset+=length; +} + +#endif diff --git a/coders/ghostscript-private.h b/coders/ghostscript-private.h index 390522059..022cb7448 100644 --- a/coders/ghostscript-private.h +++ b/coders/ghostscript-private.h @@ -204,7 +204,8 @@ static MagickBooleanType IsGhostscriptRendered(const char *path) return(MagickFalse); } -static void ReadGhostScriptXMPProfile(ByteBuffer *buffer,StringInfo **profile) +static void ReadGhostScriptXMPProfile(MagickByteBuffer *buffer, + StringInfo **profile) { #define BeginXMPPacket "?xpacket begin=" #define EndXMPPacket "') @@ -255,4 +259,4 @@ static void ReadGhostScriptXMPProfile(ByteBuffer *buffer,StringInfo **profile) SetStringInfoLength(*profile,(size_t) count); } -#endif \ No newline at end of file +#endif diff --git a/coders/pdf.c b/coders/pdf.c index d881197f5..a5854bcd4 100644 --- a/coders/pdf.c +++ b/coders/pdf.c @@ -81,7 +81,7 @@ #include "MagickCore/transform.h" #include "MagickCore/utility.h" #include "MagickCore/module.h" -#include "byte-buffer-private.h" +#include "bytebuffer-private.h" #include "ghostscript-private.h" /* @@ -199,7 +199,7 @@ static void ReadPDFInfo(const ImageInfo *image_info,Image *image, int c; - ByteBuffer + MagickByteBuffer buffer; register char @@ -227,7 +227,7 @@ static void ReadPDFInfo(const ImageInfo *image_info,Image *image, spotcolor=0; (void) memset(&buffer,0,sizeof(buffer)); buffer.image=image; - for (c=ReadByteBuffer(&buffer); c != EOF; c=ReadByteBuffer(&buffer)) + for (c=ReadMagickByteBuffer(&buffer); c != EOF; c=ReadMagickByteBuffer(&buffer)) { switch(c) { @@ -236,7 +236,7 @@ static void ReadPDFInfo(const ImageInfo *image_info,Image *image, if (*version == '\0') { i=0; - for (c=ReadByteBuffer(&buffer); c != EOF; c=ReadByteBuffer(&buffer)) + for (c=ReadMagickByteBuffer(&buffer); c != EOF; c=ReadMagickByteBuffer(&buffer)) { if ((c == '\r') || (c == '\n') || ((i+1) == MagickPathExtent)) break; @@ -256,22 +256,22 @@ static void ReadPDFInfo(const ImageInfo *image_info,Image *image, default: continue; } - if (CompareByteBuffer(PDFRotate,&buffer,strlen(PDFRotate)) != MagickFalse) + if (CompareMagickByteBuffer(&buffer,PDFRotate,strlen(PDFRotate)) != MagickFalse) { - p=GetByteBufferDatum(&buffer); + p=GetMagickByteBufferDatum(&buffer); (void) sscanf(p,PDFRotate" %lf",&pdf_info->angle); } if (pdf_info->cmyk == MagickFalse) { - if ((CompareByteBuffer(DefaultCMYK,&buffer,strlen(DefaultCMYK)) != MagickFalse) || - (CompareByteBuffer(DeviceCMYK,&buffer,strlen(DeviceCMYK)) != MagickFalse) || - (CompareByteBuffer(CMYKProcessColor,&buffer,strlen(CMYKProcessColor)) != MagickFalse)) + if ((CompareMagickByteBuffer(&buffer,DefaultCMYK,strlen(DefaultCMYK)) != MagickFalse) || + (CompareMagickByteBuffer(&buffer,DeviceCMYK,strlen(DeviceCMYK)) != MagickFalse) || + (CompareMagickByteBuffer(&buffer,CMYKProcessColor,strlen(CMYKProcessColor)) != MagickFalse)) { pdf_info->cmyk=MagickTrue; continue; } } - if (CompareByteBuffer(SpotColor,&buffer,strlen(SpotColor)) != MagickFalse) + if (CompareMagickByteBuffer(&buffer,SpotColor,strlen(SpotColor)) != MagickFalse) { char name[MagickPathExtent], @@ -284,8 +284,8 @@ static void ReadPDFInfo(const ImageInfo *image_info,Image *image, (void) FormatLocaleString(property,MagickPathExtent, "pdf:SpotColor-%.20g",(double) spotcolor++); i=0; - SkipByteBuffer(&buffer,strlen(SpotColor)+1); - for (c=ReadByteBuffer(&buffer); c != EOF; c=ReadByteBuffer(&buffer)) + SkipMagickByteBuffer(&buffer,strlen(SpotColor)+1); + for (c=ReadMagickByteBuffer(&buffer); c != EOF; c=ReadMagickByteBuffer(&buffer)) { if ((isspace(c) != 0) || (c == '/') || ((i+1) == MagickPathExtent)) break; @@ -304,12 +304,12 @@ static void ReadPDFInfo(const ImageInfo *image_info,Image *image, count=0; if (pdf_info->cropbox != MagickFalse) { - if (CompareByteBuffer(CropBox,&buffer,strlen(CropBox)) != MagickFalse) + if (CompareMagickByteBuffer(&buffer,CropBox,strlen(CropBox)) != MagickFalse) { /* Note region defined by crop box. */ - p=GetByteBufferDatum(&buffer); + p=GetMagickByteBufferDatum(&buffer); count=(ssize_t) sscanf(p,"CropBox [%lf %lf %lf %lf",&bounds.x1, &bounds.y1,&bounds.x2,&bounds.y2); if (count != 4) @@ -320,12 +320,12 @@ static void ReadPDFInfo(const ImageInfo *image_info,Image *image, else if (pdf_info->trimbox != MagickFalse) { - if (CompareByteBuffer(TrimBox,&buffer,strlen(TrimBox)) != MagickFalse) + if (CompareMagickByteBuffer(&buffer,TrimBox,strlen(TrimBox)) != MagickFalse) { /* Note region defined by trim box. */ - p=GetByteBufferDatum(&buffer); + p=GetMagickByteBufferDatum(&buffer); count=(ssize_t) sscanf(p,"TrimBox [%lf %lf %lf %lf",&bounds.x1, &bounds.y1,&bounds.x2,&bounds.y2); if (count != 4) @@ -334,12 +334,12 @@ static void ReadPDFInfo(const ImageInfo *image_info,Image *image, } } else - if (CompareByteBuffer(MediaBox,&buffer,strlen(MediaBox)) != MagickFalse) + if (CompareMagickByteBuffer(&buffer,MediaBox,strlen(MediaBox)) != MagickFalse) { /* Note region defined by media box. */ - p=GetByteBufferDatum(&buffer); + p=GetMagickByteBufferDatum(&buffer); count=(ssize_t) sscanf(p,"MediaBox [%lf %lf %lf %lf",&bounds.x1, &bounds.y1,&bounds.x2,&bounds.y2); if (count != 4) diff --git a/coders/ps.c b/coders/ps.c index 04c72a6d5..c8753632e 100644 --- a/coders/ps.c +++ b/coders/ps.c @@ -77,7 +77,7 @@ #include "MagickCore/token.h" #include "MagickCore/transform.h" #include "MagickCore/utility.h" -#include "byte-buffer-private.h" +#include "bytebuffer-private.h" #include "ghostscript-private.h" /* @@ -171,7 +171,7 @@ static MagickBooleanType IsPS(const unsigned char *magick,const size_t length) % */ -static inline int ProfileInteger(ByteBuffer *buffer,short int *hex_digits) +static inline int ProfileInteger(MagickByteBuffer *buffer,short int *hex_digits) { int c, @@ -185,7 +185,7 @@ static inline int ProfileInteger(ByteBuffer *buffer,short int *hex_digits) value=0; for (i=0; i < 2; ) { - c=ReadByteBuffer(buffer); + c=ReadMagickByteBuffer(buffer); if ((c == EOF) || ((c == '%') && (l == '%'))) { value=(-1); @@ -221,7 +221,7 @@ static void ReadPSInfo(const ImageInfo *image_info,Image *image, #define ICCProfile "BeginICCProfile:" #define PhotoshopProfile "BeginPhotoshop:" - ByteBuffer + MagickByteBuffer buffer; int @@ -289,7 +289,7 @@ static void ReadPSInfo(const ImageInfo *image_info,Image *image, skip=MagickFalse; (void) memset(&buffer,0,sizeof(buffer)); buffer.image=image; - for (c=ReadByteBuffer(&buffer); c != EOF; c=ReadByteBuffer(&buffer)) + for (c=ReadMagickByteBuffer(&buffer); c != EOF; c=ReadMagickByteBuffer(&buffer)) { switch(c) { @@ -313,42 +313,42 @@ static void ReadPSInfo(const ImageInfo *image_info,Image *image, /* Skip %%BeginDocument thru %%EndDocument. */ - if (CompareByteBuffer(BeginDocument,&buffer,strlen(BeginDocument)) != MagickFalse) + if (CompareMagickByteBuffer(&buffer,BeginDocument,strlen(BeginDocument)) != MagickFalse) skip=MagickTrue; - if (CompareByteBuffer(EndDocument,&buffer,strlen(EndDocument)) != MagickFalse) + if (CompareMagickByteBuffer(&buffer,EndDocument,strlen(EndDocument)) != MagickFalse) skip=MagickFalse; if (skip != MagickFalse) continue; - if (CompareByteBuffer(PostscriptLevel,&buffer,strlen(PostscriptLevel)) != MagickFalse) + if (CompareMagickByteBuffer(&buffer,PostscriptLevel,strlen(PostscriptLevel)) != MagickFalse) { - p=GetByteBufferDatum(&buffer)+4; + p=GetMagickByteBufferDatum(&buffer)+4; (void) SetImageProperty(image,"ps:Level",p,exception); } - if (CompareByteBuffer(ImageData,&buffer,strlen(ImageData)) != MagickFalse) + if (CompareMagickByteBuffer(&buffer,ImageData,strlen(ImageData)) != MagickFalse) { - p=GetByteBufferDatum(&buffer); + p=GetMagickByteBufferDatum(&buffer); (void) sscanf(p,ImageData " %lu %lu",&ps_info->columns,&ps_info->rows); } /* Is this a CMYK document? */ length=strlen(DocumentProcessColors); - if (CompareByteBuffer(DocumentProcessColors,&buffer,length) != MagickFalse) + if (CompareMagickByteBuffer(&buffer,DocumentProcessColors,length) != MagickFalse) { - p=GetByteBufferDatum(&buffer); + p=GetMagickByteBufferDatum(&buffer); if ((GlobExpression(p,"*Cyan*",MagickTrue) != MagickFalse) || (GlobExpression(p,"*Magenta*",MagickTrue) != MagickFalse) || (GlobExpression(p,"*Yellow*",MagickTrue) != MagickFalse)) ps_info->cmyk=MagickTrue; } - if (CompareByteBuffer(CMYKCustomColor,&buffer,strlen(CMYKCustomColor)) != MagickFalse) + if (CompareMagickByteBuffer(&buffer,CMYKCustomColor,strlen(CMYKCustomColor)) != MagickFalse) ps_info->cmyk=MagickTrue; - if (CompareByteBuffer(CMYKProcessColor,&buffer,strlen(CMYKProcessColor)) != MagickFalse) + if (CompareMagickByteBuffer(&buffer,CMYKProcessColor,strlen(CMYKProcessColor)) != MagickFalse) ps_info->cmyk=MagickTrue; length=strlen(DocumentCustomColors); - if ((CompareByteBuffer(DocumentCustomColors,&buffer,length) != MagickFalse) || - (CompareByteBuffer(CMYKCustomColor,&buffer,strlen(CMYKCustomColor)) != MagickFalse) || - (CompareByteBuffer(SpotColor,&buffer,strlen(SpotColor)) != MagickFalse)) + if ((CompareMagickByteBuffer(&buffer,DocumentCustomColors,length) != MagickFalse) || + (CompareMagickByteBuffer(&buffer,CMYKCustomColor,strlen(CMYKCustomColor)) != MagickFalse) || + (CompareMagickByteBuffer(&buffer,SpotColor,strlen(SpotColor)) != MagickFalse)) { char name[MagickPathExtent], @@ -361,7 +361,7 @@ static void ReadPSInfo(const ImageInfo *image_info,Image *image, (void) FormatLocaleString(property,MagickPathExtent, "pdf:SpotColor-%.20g",(double) spotcolor++); i=0; - for (c=ReadByteBuffer(&buffer); c != EOF; c=ReadByteBuffer(&buffer)) + for (c=ReadMagickByteBuffer(&buffer); c != EOF; c=ReadMagickByteBuffer(&buffer)) { if ((isspace(c) != 0) || ((i+1) == MagickPathExtent)) break; @@ -378,7 +378,7 @@ static void ReadPSInfo(const ImageInfo *image_info,Image *image, continue; } if ((ps_info->icc_profile == (StringInfo *) NULL) && - (CompareByteBuffer(ICCProfile,&buffer,strlen(ICCProfile)) != MagickFalse)) + (CompareMagickByteBuffer(&buffer,ICCProfile,strlen(ICCProfile)) != MagickFalse)) { unsigned char *datum; @@ -401,7 +401,7 @@ static void ReadPSInfo(const ImageInfo *image_info,Image *image, continue; } if ((ps_info->photoshop_profile == (StringInfo *) NULL) && - (CompareByteBuffer(PhotoshopProfile,&buffer,strlen(PhotoshopProfile)) != MagickFalse)) + (CompareMagickByteBuffer(&buffer,PhotoshopProfile,strlen(PhotoshopProfile)) != MagickFalse)) { unsigned char *q; @@ -409,7 +409,7 @@ static void ReadPSInfo(const ImageInfo *image_info,Image *image, /* Read Photoshop profile. */ - p=GetByteBufferDatum(&buffer); + p=GetMagickByteBufferDatum(&buffer); count=(ssize_t) sscanf(p,PhotoshopProfile " %lu",&extent); if (count != 1) continue; @@ -434,37 +434,37 @@ static void ReadPSInfo(const ImageInfo *image_info,Image *image, */ count=0; i=0; - if (CompareByteBuffer(BoundingBox,&buffer,strlen(BoundingBox)) != MagickFalse) + if (CompareMagickByteBuffer(&buffer,BoundingBox,strlen(BoundingBox)) != MagickFalse) { - p=GetByteBufferDatum(&buffer); + p=GetMagickByteBufferDatum(&buffer); count=(ssize_t) sscanf(p,BoundingBox " %lf %lf %lf %lf", &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2); i=2; } - if (CompareByteBuffer(DocumentMedia,&buffer,strlen(DocumentMedia)) != MagickFalse) + if (CompareMagickByteBuffer(&buffer,DocumentMedia,strlen(DocumentMedia)) != MagickFalse) { - p=GetByteBufferDatum(&buffer); + p=GetMagickByteBufferDatum(&buffer); count=(ssize_t) sscanf(p,DocumentMedia " %lf %lf %lf %lf", &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2); i=1; } - if (CompareByteBuffer(HiResBoundingBox,&buffer,strlen(HiResBoundingBox)) != MagickFalse) + if (CompareMagickByteBuffer(&buffer,HiResBoundingBox,strlen(HiResBoundingBox)) != MagickFalse) { - p=GetByteBufferDatum(&buffer); + p=GetMagickByteBufferDatum(&buffer); count=(ssize_t) sscanf(p,HiResBoundingBox " %lf %lf %lf %lf", &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2); i=3; } - if (CompareByteBuffer(PageBoundingBox,&buffer,strlen(PageBoundingBox)) != MagickFalse) + if (CompareMagickByteBuffer(&buffer,PageBoundingBox,strlen(PageBoundingBox)) != MagickFalse) { - p=GetByteBufferDatum(&buffer); + p=GetMagickByteBufferDatum(&buffer); count=(ssize_t) sscanf(p,PageBoundingBox " %lf %lf %lf %lf", &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2); i=1; } - if (CompareByteBuffer(PageMedia,&buffer,strlen(PageMedia)) == 0) + if (CompareMagickByteBuffer(&buffer,PageMedia,strlen(PageMedia)) == 0) { - p=GetByteBufferDatum(&buffer); + p=GetMagickByteBufferDatum(&buffer); count=(ssize_t) sscanf(p,PageMedia " %lf %lf %lf %lf", &bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2); i=1; @@ -673,6 +673,7 @@ static Image *ReadPSImage(const ImageInfo *image_info,ExceptionInfo *exception) count=write(file,translate_geometry,(unsigned int) strlen(translate_geometry)); } + (void) count; file=close(file)-1; /* Render Postscript with the Ghostscript delegate.