diff options
author | shumkovnd <shumkovnd@yandex-team.com> | 2023-11-10 14:39:34 +0300 |
---|---|---|
committer | shumkovnd <shumkovnd@yandex-team.com> | 2023-11-10 16:42:24 +0300 |
commit | 77eb2d3fdcec5c978c64e025ced2764c57c00285 (patch) | |
tree | c51edb0748ca8d4a08d7c7323312c27ba1a8b79a /contrib/python/Pillow/py2/libImaging/HexDecode.c | |
parent | dd6d20cadb65582270ac23f4b3b14ae189704b9d (diff) | |
download | ydb-77eb2d3fdcec5c978c64e025ced2764c57c00285.tar.gz |
KIKIMR-19287: add task_stats_drawing script
Diffstat (limited to 'contrib/python/Pillow/py2/libImaging/HexDecode.c')
-rw-r--r-- | contrib/python/Pillow/py2/libImaging/HexDecode.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/contrib/python/Pillow/py2/libImaging/HexDecode.c b/contrib/python/Pillow/py2/libImaging/HexDecode.c new file mode 100644 index 0000000000..8bd9bf67fa --- /dev/null +++ b/contrib/python/Pillow/py2/libImaging/HexDecode.c @@ -0,0 +1,67 @@ +/* + * The Python Imaging Library. + * $Id$ + * + * decoder for hex encoded image data + * + * history: + * 96-05-16 fl Created + * + * Copyright (c) Fredrik Lundh 1996. + * Copyright (c) Secret Labs AB 1997. + * + * See the README file for information on usage and redistribution. + */ + + +#include "Imaging.h" + +#define HEX(v) ((v >= '0' && v <= '9') ? v - '0' :\ + (v >= 'a' && v <= 'f') ? v - 'a' + 10 :\ + (v >= 'A' && v <= 'F') ? v - 'A' + 10 : -1) + +int +ImagingHexDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t bytes) +{ + UINT8* ptr; + int a, b; + + ptr = buf; + + for (;;) { + + if (bytes < 2) + return ptr - buf; + + a = HEX(ptr[0]); + b = HEX(ptr[1]); + + if (a < 0 || b < 0) { + + ptr++; + bytes--; + + } else { + + ptr += 2; + bytes -= 2; + + state->buffer[state->x] = (a<<4) + b; + + if (++state->x >= state->bytes) { + + /* Got a full line, unpack it */ + state->shuffle((UINT8*) im->image[state->y], state->buffer, + state->xsize); + + state->x = 0; + + if (++state->y >= state->ysize) { + /* End of file (errcode = 0) */ + return -1; + } + } + + } + } +} |