Pillow/src/libImaging/EpsEncode.c

84 lines
1.6 KiB
C
Raw Normal View History

/*
2010-07-31 06:52:47 +04:00
* The Python Imaging Library.
* $Id$
*
* encoder for EPS hex data
*
* history:
2020-05-01 15:08:57 +03:00
* 96-04-19 fl created
* 96-06-27 fl don't drop last block of encoded data
2010-07-31 06:52:47 +04:00
*
* notes:
2020-05-01 15:08:57 +03:00
* FIXME: rename to HexEncode.c ??
2010-07-31 06:52:47 +04:00
*
* Copyright (c) Fredrik Lundh 1996.
* Copyright (c) Secret Labs AB 1997.
*
* See the README file for information on usage and redistribution.
*/
#include "Imaging.h"
int
ImagingEpsEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
{
enum { HEXBYTE=1, NEWLINE };
const char *hex = "0123456789abcdef";
UINT8* ptr = buf;
UINT8* in, i;
if (!state->state) {
2020-05-01 15:08:57 +03:00
state->state = HEXBYTE;
state->xsize *= im->pixelsize; /* Hack! */
2010-07-31 06:52:47 +04:00
}
in = (UINT8*) im->image[state->y];
for (;;) {
2020-05-01 15:08:57 +03:00
if (state->state == NEWLINE) {
2020-05-10 12:56:36 +03:00
if (bytes < 1) {
2020-05-01 15:08:57 +03:00
break;
2020-05-10 12:56:36 +03:00
}
2020-05-01 15:08:57 +03:00
*ptr++ = '\n';
bytes--;
state->state = HEXBYTE;
}
2020-05-10 12:56:36 +03:00
if (bytes < 2) {
2020-05-01 15:08:57 +03:00
break;
2020-05-10 12:56:36 +03:00
}
2020-05-01 15:08:57 +03:00
i = in[state->x++];
*ptr++ = hex[(i>>4)&15];
*ptr++ = hex[i&15];
bytes -= 2;
/* Skip junk bytes */
2020-05-10 12:56:36 +03:00
if (im->bands == 3 && (state->x & 3) == 3) {
2020-05-01 15:08:57 +03:00
state->x++;
2020-05-10 12:56:36 +03:00
}
2020-05-01 15:08:57 +03:00
if (++state->count >= 79/2) {
state->state = NEWLINE;
state->count = 0;
}
if (state->x >= state->xsize) {
state->x = 0;
if (++state->y >= state->ysize) {
state->errcode = IMAGING_CODEC_END;
break;
}
in = (UINT8*) im->image[state->y];
}
2010-07-31 06:52:47 +04:00
}
return ptr - buf;
2010-07-31 06:52:47 +04:00
}