--- /dev/null
+/*
+ Copyright 1999-2019 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
+
+ https://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.
+*/
+#ifndef MAGICK_BYTE_BUFFER_PRIVATE_H
+#define MAGICK_BYTE_BUFFER_PRIVATE_H
+
+typedef struct _ByteBuffer
+{
+ Image
+ *image;
+
+ ssize_t
+ offset,
+ count;
+
+ unsigned char
+ data[8192];
+} ByteBuffer;
+
+static int ReadByteBuffer(ByteBuffer *buffer)
+{
+ if ((buffer->offset == buffer->count) && (buffer->offset > 0))
+ {
+ if (buffer->count != (ssize_t) sizeof(buffer->data))
+ return(EOF);
+ buffer->offset=0;
+ }
+ if (buffer->offset == 0)
+ {
+ buffer->count=ReadBlob(buffer->image,sizeof(buffer->data),buffer->data);
+ if (buffer->count < 1)
+ return(EOF);
+ }
+ return(buffer->data[buffer->offset++]);
+}
+
+static char *GetByteBufferDatum(ByteBuffer *buffer)
+{
+ ssize_t
+ i;
+
+ 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);
+ buffer->count+=i;
+ buffer->offset=1;
+ return((char *) buffer->data+1);
+}
+
+static inline void CheckRemainingByteBuffer(ByteBuffer *buffer,size_t length)
+{
+ if ((buffer->offset+length) > (ssize_t) sizeof(buffer->data))
+ (void) GetByteBufferDatum(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)
+{
+ const char
+ *q;
+
+ CheckRemainingByteBuffer(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
#include "MagickCore/transform.h"
#include "MagickCore/utility.h"
#include "MagickCore/module.h"
+#include "byte-buffer-private.h"
\f
/*
Define declarations.
StringInfo
*profile;
} PDFInfo;
-
-typedef struct _PDFBuffer
-{
- Image
- *image;
-
- ssize_t
- offset,
- count;
-
- unsigned char
- data[8192];
-} PDFBuffer;
\f
/*
Forward declarations.
return(MagickFalse);
}
-static inline int ReadPDFByte(PDFBuffer *buffer)
-{
- if ((buffer->offset == buffer->count) && (buffer->offset > 0))
- {
- if (buffer->count != (ssize_t) sizeof(buffer->data))
- return(EOF);
- buffer->offset=0;
- }
- if (buffer->offset == 0)
- {
- buffer->count=ReadBlob(buffer->image,sizeof(buffer->data),buffer->data);
- if (buffer->count < 1)
- return(EOF);
- }
- return(buffer->data[buffer->offset++]);
-}
-
-static char *MovePDFBuffer(PDFBuffer *buffer)
-{
- ssize_t
- i;
-
- 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);
- buffer->count+=i;
- buffer->offset=1;
- return((char *) buffer->data+1);
-}
-
-static inline void CheckRemainingPDFBuffer(PDFBuffer *buffer,size_t length)
-{
- if ((buffer->offset+length) > (ssize_t) sizeof(buffer->data))
- (void) MovePDFBuffer(buffer);
-}
-
-static inline void SkipPDFBytes(PDFBuffer *buffer,size_t length)
-{
- CheckRemainingPDFBuffer(buffer,length);
- if ((buffer->offset+length) < buffer->count)
- buffer->offset+=length;
-}
-
-static inline MagickBooleanType ComparePDFBuffer(const char *p,
- PDFBuffer *buffer,const size_t length)
-{
- const char
- *q;
-
- CheckRemainingPDFBuffer(buffer,length);
- q=(const char *) buffer->data+buffer->offset;
- if (LocaleNCompare(p,q,length) != 0)
- return(MagickFalse);
- return(MagickTrue);
-}
-
-static void ReadPDFXMPProfile(PDFInfo *pdf_info,PDFBuffer *buffer)
+static void ReadPDFXMPProfile(PDFInfo *pdf_info,ByteBuffer *buffer)
{
#define BeginXMPPacket "?xpacket begin="
#define EndXMPPacket "<?xpacket end="
if (pdf_info->profile != (StringInfo *) NULL)
return;
- if (ComparePDFBuffer(BeginXMPPacket,buffer,strlen(BeginXMPPacket)) == MagickFalse)
+ if (CompareByteBuffer(BeginXMPPacket,buffer,strlen(BeginXMPPacket)) == MagickFalse)
return;
length=8192;
pdf_info->profile=AcquireStringInfo(length);
p=(char *) GetStringInfoDatum(pdf_info->profile);
*p++='<';
count=1;
- for (c=ReadPDFByte(buffer); c != EOF; c=ReadPDFByte(buffer))
+ for (c=ReadByteBuffer(buffer); c != EOF; c=ReadByteBuffer(buffer))
{
if (count == (ssize_t) length)
{
count++;
*p++=(char) c;
if (found_end == MagickFalse)
- found_end=ComparePDFBuffer(EndXMPPacket,buffer,strlen(EndXMPPacket));
+ found_end=CompareByteBuffer(EndXMPPacket,buffer,strlen(EndXMPPacket));
else
{
if (c == (int) '>')
int
c;
- PDFBuffer
+ ByteBuffer
buffer;
register char
spotcolor=0;
(void) memset(&buffer,0,sizeof(buffer));
buffer.image=image;
- for (c=ReadPDFByte(&buffer); c != EOF; c=ReadPDFByte(&buffer))
+ for (c=ReadByteBuffer(&buffer); c != EOF; c=ReadByteBuffer(&buffer))
{
switch(c)
{
if (*version == '\0')
{
i=0;
- for (c=ReadPDFByte(&buffer); c != EOF; c=ReadPDFByte(&buffer))
+ for (c=ReadByteBuffer(&buffer); c != EOF; c=ReadByteBuffer(&buffer))
{
if ((c == '\r') || (c == '\n') || ((i+1) == MagickPathExtent))
break;
default:
continue;
}
- if (ComparePDFBuffer(PDFRotate,&buffer,strlen(PDFRotate)) != MagickFalse)
+ if (CompareByteBuffer(PDFRotate,&buffer,strlen(PDFRotate)) != MagickFalse)
{
- p=MovePDFBuffer(&buffer);
+ p=GetByteBufferDatum(&buffer);
(void) sscanf(p,PDFRotate" %lf",&pdf_info->angle);
}
if (pdf_info->cmyk == MagickFalse)
{
- if ((ComparePDFBuffer(DefaultCMYK,&buffer,strlen(DefaultCMYK)) != MagickFalse) ||
- (ComparePDFBuffer(DeviceCMYK,&buffer,strlen(DeviceCMYK)) != MagickFalse) ||
- (ComparePDFBuffer(CMYKProcessColor,&buffer,strlen(CMYKProcessColor)) != MagickFalse))
+ if ((CompareByteBuffer(DefaultCMYK,&buffer,strlen(DefaultCMYK)) != MagickFalse) ||
+ (CompareByteBuffer(DeviceCMYK,&buffer,strlen(DeviceCMYK)) != MagickFalse) ||
+ (CompareByteBuffer(CMYKProcessColor,&buffer,strlen(CMYKProcessColor)) != MagickFalse))
{
pdf_info->cmyk=MagickTrue;
continue;
}
}
- if (ComparePDFBuffer(SpotColor,&buffer,strlen(SpotColor)) != MagickFalse)
+ if (CompareByteBuffer(SpotColor,&buffer,strlen(SpotColor)) != MagickFalse)
{
char
name[MagickPathExtent],
(void) FormatLocaleString(property,MagickPathExtent,
"pdf:SpotColor-%.20g",(double) spotcolor++);
i=0;
- SkipPDFBytes(&buffer,strlen(SpotColor)+1);
- for (c=ReadPDFByte(&buffer); c != EOF; c=ReadPDFByte(&buffer))
+ SkipByteBuffer(&buffer,strlen(SpotColor)+1);
+ for (c=ReadByteBuffer(&buffer); c != EOF; c=ReadByteBuffer(&buffer))
{
if ((isspace(c) != 0) || (c == '/') || ((i+1) == MagickPathExtent))
break;
count=0;
if (pdf_info->cropbox != MagickFalse)
{
- if (ComparePDFBuffer(CropBox,&buffer,strlen(CropBox)) != MagickFalse)
+ if (CompareByteBuffer(CropBox,&buffer,strlen(CropBox)) != MagickFalse)
{
/*
Note region defined by crop box.
*/
- p=MovePDFBuffer(&buffer);
+ p=GetByteBufferDatum(&buffer);
count=(ssize_t) sscanf(p,"CropBox [%lf %lf %lf %lf",&bounds.x1,
&bounds.y1,&bounds.x2,&bounds.y2);
if (count != 4)
else
if (pdf_info->trimbox != MagickFalse)
{
- if (ComparePDFBuffer(TrimBox,&buffer,strlen(TrimBox)) != MagickFalse)
+ if (CompareByteBuffer(TrimBox,&buffer,strlen(TrimBox)) != MagickFalse)
{
/*
Note region defined by trim box.
*/
- p=MovePDFBuffer(&buffer);
+ p=GetByteBufferDatum(&buffer);
count=(ssize_t) sscanf(p,"TrimBox [%lf %lf %lf %lf",&bounds.x1,
&bounds.y1,&bounds.x2,&bounds.y2);
if (count != 4)
}
}
else
- if (ComparePDFBuffer(MediaBox,&buffer,strlen(MediaBox)) != MagickFalse)
+ if (CompareByteBuffer(MediaBox,&buffer,strlen(MediaBox)) != MagickFalse)
{
/*
Note region defined by media box.
*/
- p=MovePDFBuffer(&buffer);
+ p=GetByteBufferDatum(&buffer);
count=(ssize_t) sscanf(p,"MediaBox [%lf %lf %lf %lf",&bounds.x1,
&bounds.y1,&bounds.x2,&bounds.y2);
if (count != 4)