PcdDecode.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * The Python Imaging Library.
  3. * $Id$
  4. *
  5. * decoder for uncompressed PCD image data.
  6. *
  7. * history:
  8. * 96-05-10 fl Created
  9. * 96-05-18 fl New tables
  10. * 97-01-25 fl Use PhotoYCC unpacker
  11. *
  12. * notes:
  13. * This driver supports uncompressed PCD modes only
  14. * (resolutions up to 768x512).
  15. *
  16. * Copyright (c) Fredrik Lundh 1996-97.
  17. * Copyright (c) Secret Labs AB 1997.
  18. *
  19. * See the README file for information on usage and redistribution.
  20. */
  21. #include "Imaging.h"
  22. int
  23. ImagingPcdDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) {
  24. int x;
  25. int chunk;
  26. UINT8 *out;
  27. UINT8 *ptr;
  28. ptr = buf;
  29. chunk = 3 * state->xsize;
  30. for (;;) {
  31. /* We need data for two full lines before we can do anything */
  32. if (bytes < chunk) {
  33. return ptr - buf;
  34. }
  35. /* Unpack first line */
  36. out = state->buffer;
  37. for (x = 0; x < state->xsize; x++) {
  38. out[0] = ptr[x];
  39. out[1] = ptr[(x + 4 * state->xsize) / 2];
  40. out[2] = ptr[(x + 5 * state->xsize) / 2];
  41. out += 3;
  42. }
  43. state->shuffle((UINT8 *)im->image[state->y], state->buffer, state->xsize);
  44. if (++state->y >= state->ysize) {
  45. return -1; /* This can hardly happen */
  46. }
  47. /* Unpack second line */
  48. out = state->buffer;
  49. for (x = 0; x < state->xsize; x++) {
  50. out[0] = ptr[x + state->xsize];
  51. out[1] = ptr[(x + 4 * state->xsize) / 2];
  52. out[2] = ptr[(x + 5 * state->xsize) / 2];
  53. out += 3;
  54. }
  55. state->shuffle((UINT8 *)im->image[state->y], state->buffer, state->xsize);
  56. if (++state->y >= state->ysize) {
  57. return -1;
  58. }
  59. ptr += chunk;
  60. bytes -= chunk;
  61. }
  62. }