ildecompress.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: ildecompress.c /main/3 1995/10/23 15:46:32 rswiston $ */
  24. /**---------------------------------------------------------------------
  25. ***
  26. *** (c)Copyright 1991 Hewlett-Packard Co.
  27. ***
  28. *** RESTRICTED RIGHTS LEGEND
  29. *** Use, duplication, or disclosure by the U.S. Government is subject to
  30. *** restrictions as set forth in sub-paragraph (c)(1)(ii) of the Rights in
  31. *** Technical Data and Computer Software clause in DFARS 252.227-7013.
  32. *** Hewlett-Packard Company
  33. *** 3000 Hanover Street
  34. *** Palo Alto, CA 94304 U.S.A.
  35. *** Rights for non-DOD U.S. Government Departments and Agencies are as set
  36. *** forth in FAR 52.227-19(c)(1,2).
  37. ***
  38. ***-------------------------------------------------------------------*/
  39. #include "ilint.h"
  40. #include "ilpipelem.h"
  41. #include "ildecomp.h"
  42. #include "ilcodec.h"
  43. #include "ilerrors.h"
  44. /* =================================================================================
  45. -------------------- ilDecompress() --------------------
  46. Add a filter to "pipe" (guaranteed to be a pipe in IL_PIPE_FORMING state)
  47. which decompresses the compressed pipe image.
  48. ================================================================================= */
  49. IL_PRIVATE void _ilDecompress (
  50. ilPipe pipe
  51. )
  52. {
  53. unsigned int state;
  54. ilPipeInfo info;
  55. ilImageDes imdes;
  56. ilImageFormat imformat;
  57. /* Get ptr to pipe info and check state. We should NOT FORCE decompression */
  58. state = ilGetPipeInfo(pipe, FALSE, &info, &imdes, &imformat);
  59. /* Verify status of the pipe */
  60. if (state != IL_PIPE_FORMING) {
  61. if (!pipe->context->error) {
  62. ilDeclarePipeInvalid(pipe, IL_ERROR_PIPE_STATE);
  63. return;
  64. }
  65. }
  66. /* Call the appropriate decompression function */
  67. switch (imdes.compression) {
  68. /* Image is already decompressed! Continue, this is NOT an error! */
  69. case IL_UNCOMPRESSED:
  70. break;
  71. case IL_G3:
  72. if (!_ilDecompG3 (pipe, &info, &imdes))
  73. return;
  74. break;
  75. case IL_G4: /* Currently supported CCITT Group4 decompression format */
  76. if (!_ilDecompG4 (pipe, &info, &imdes))
  77. return;
  78. break;
  79. case IL_LZW: /* Currently supported LZW format */
  80. if (!_ilDecompLZW (pipe, &info, &imdes, &imformat))
  81. return;
  82. break;
  83. case IL_PACKBITS:
  84. if (!_ilDecompPackbits (pipe, &info, &imdes, &imformat))
  85. return;
  86. break;
  87. case IL_JPEG: /* Currently supported JPEG format */
  88. if (!_ilDecompJPEG (pipe, &info, &imdes))
  89. return;
  90. break;
  91. default: /* imdes.compression is not valid */
  92. ilDeclarePipeInvalid (pipe, IL_ERROR_COMPRESSION);
  93. return;
  94. } /* end switch */
  95. pipe->context->error = IL_OK;
  96. }