Pillow/src/libImaging/PcdDecode.c

75 lines
1.7 KiB
C
Raw Normal View History

2010-07-31 06:52:47 +04:00
/*
* The Python Imaging Library.
* $Id$
*
* decoder for uncompressed PCD image data.
*
* history:
2020-05-01 15:08:57 +03:00
* 96-05-10 fl Created
* 96-05-18 fl New tables
* 97-01-25 fl Use PhotoYCC unpacker
2010-07-31 06:52:47 +04:00
*
* notes:
2020-05-01 15:08:57 +03:00
* This driver supports uncompressed PCD modes only
* (resolutions up to 768x512).
2010-07-31 06:52:47 +04:00
*
* Copyright (c) Fredrik Lundh 1996-97.
* Copyright (c) Secret Labs AB 1997.
*
* See the README file for information on usage and redistribution.
*/
#include "Imaging.h"
int
2021-01-03 06:17:51 +03:00
ImagingPcdDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) {
2010-07-31 06:52:47 +04:00
int x;
int chunk;
2021-01-03 06:17:51 +03:00
UINT8 *out;
UINT8 *ptr;
2010-07-31 06:52:47 +04:00
ptr = buf;
chunk = 3 * state->xsize;
for (;;) {
2020-05-01 15:08:57 +03:00
/* We need data for two full lines before we can do anything */
2020-05-10 12:56:36 +03:00
if (bytes < chunk) {
2020-05-01 15:08:57 +03:00
return ptr - buf;
2020-05-10 12:56:36 +03:00
}
2020-05-01 15:08:57 +03:00
/* Unpack first line */
out = state->buffer;
for (x = 0; x < state->xsize; x++) {
out[0] = ptr[x];
2021-01-03 06:17:51 +03:00
out[1] = ptr[(x + 4 * state->xsize) / 2];
out[2] = ptr[(x + 5 * state->xsize) / 2];
2020-05-01 15:08:57 +03:00
out += 3;
}
2021-01-03 06:17:51 +03:00
state->shuffle((UINT8 *)im->image[state->y], state->buffer, state->xsize);
2020-05-01 15:08:57 +03:00
2020-05-10 12:56:36 +03:00
if (++state->y >= state->ysize) {
2020-05-01 15:08:57 +03:00
return -1; /* This can hardly happen */
2020-05-10 12:56:36 +03:00
}
2020-05-01 15:08:57 +03:00
/* Unpack second line */
out = state->buffer;
for (x = 0; x < state->xsize; x++) {
2021-01-03 06:17:51 +03:00
out[0] = ptr[x + state->xsize];
out[1] = ptr[(x + 4 * state->xsize) / 2];
out[2] = ptr[(x + 5 * state->xsize) / 2];
2020-05-01 15:08:57 +03:00
out += 3;
}
2021-01-03 06:17:51 +03:00
state->shuffle((UINT8 *)im->image[state->y], state->buffer, state->xsize);
2020-05-01 15:08:57 +03:00
2020-05-10 12:56:36 +03:00
if (++state->y >= state->ysize) {
2020-05-01 15:08:57 +03:00
return -1;
2020-05-10 12:56:36 +03:00
}
2020-05-01 15:08:57 +03:00
ptr += chunk;
bytes -= chunk;
2010-07-31 06:52:47 +04:00
}
}