PcdDecode.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. {
  25. int x;
  26. int chunk;
  27. UINT8* out;
  28. UINT8* ptr;
  29. ptr = buf;
  30. chunk = 3 * state->xsize;
  31. for (;;) {
  32. /* We need data for two full lines before we can do anything */
  33. if (bytes < chunk)
  34. return ptr - buf;
  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],
  44. state->buffer, state->xsize);
  45. if (++state->y >= state->ysize)
  46. return -1; /* This can hardly happen */
  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],
  56. state->buffer, state->xsize);
  57. if (++state->y >= state->ysize)
  58. return -1;
  59. ptr += chunk;
  60. bytes -= chunk;
  61. }
  62. }