awips2/pythonPackages/pil/libImaging/PcdDecode.c
root 06a8b51d6d Initial revision of AWIPS2 11.9.0-7p5
Former-commit-id: 64fa9254b946eae7e61bbc3f513b7c3696c4f54f
2012-01-06 08:55:05 -06:00

78 lines
1.6 KiB
C

/*
* The Python Imaging Library.
* $Id: PcdDecode.c 2134 2004-10-06 08:55:20Z fredrik $
*
* decoder for uncompressed PCD image data.
*
* history:
* 96-05-10 fl Created
* 96-05-18 fl New tables
* 97-01-25 fl Use PhotoYCC unpacker
*
* notes:
* This driver supports uncompressed PCD modes only
* (resolutions up to 768x512).
*
* 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
ImagingPcdDecode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
{
int x;
int chunk;
UINT8* out;
UINT8* ptr;
ptr = buf;
chunk = 3 * state->xsize;
for (;;) {
/* We need data for two full lines before we can do anything */
if (bytes < chunk)
return ptr - buf;
/* Unpack first line */
out = state->buffer;
for (x = 0; x < state->xsize; x++) {
out[0] = ptr[x];
out[1] = ptr[(x+4*state->xsize)/2];
out[2] = ptr[(x+5*state->xsize)/2];
out += 4;
}
state->shuffle((UINT8*) im->image[state->y],
state->buffer, state->xsize);
if (++state->y >= state->ysize)
return -1; /* This can hardly happen */
/* Unpack second line */
out = state->buffer;
for (x = 0; x < state->xsize; x++) {
out[0] = ptr[x+state->xsize];
out[1] = ptr[(x+4*state->xsize)/2];
out[2] = ptr[(x+5*state->xsize)/2];
out += 4;
}
state->shuffle((UINT8*) im->image[state->y],
state->buffer, state->xsize);
if (++state->y >= state->ysize)
return -1;
ptr += chunk;
bytes -= chunk;
}
}