ilcompress.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 librararies 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: ilcompress.c /main/3 1995/10/23 15:42:52 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 "ilcompress.h"
  42. #include "ilcodec.h"
  43. #include "ilerrors.h"
  44. /* --------------------------- ilCompress ----------------------------------- */
  45. /* Public function; see spec.
  46. Forces pipe data to be compressed with the given "compression", in constant
  47. strips. If "dstStripHeight" is zero (0), then any stripHeight is allowable,
  48. but if compression is done, it is done with the default strip height.
  49. */
  50. ilBool ilCompress (
  51. ilPipe pipe,
  52. unsigned int compression,
  53. ilPtr pCompData,
  54. long dstStripHeight,
  55. unsigned long mustBeZero
  56. )
  57. {
  58. unsigned int state;
  59. ilPipeInfo info;
  60. ilImageDes des;
  61. ilImageFormat format;
  62. ilSrcElementData srcData;
  63. ilBool correct;
  64. if (ilGetPipeInfo (pipe, FALSE, &info, &des, &format) != IL_PIPE_FORMING)
  65. if (!pipe->context->error)
  66. return ilDeclarePipeInvalid (pipe, IL_ERROR_PIPE_STATE);
  67. if (mustBeZero != 0)
  68. return ilDeclarePipeInvalid(pipe, IL_ERROR_PAR_NOT_ZERO);
  69. /* Force requested strip height to image height if greater. */
  70. if (dstStripHeight > info.height)
  71. dstStripHeight = info.height;
  72. /* Check current pipe image and force decompression if wrong compression, or
  73. inconstant strip height, or not requested (non-zero) strip height.
  74. */
  75. if ((des.compression != compression)
  76. || (dstStripHeight && (info.stripHeight != dstStripHeight))
  77. || !info.constantStrip)
  78. ilGetPipeInfo (pipe, TRUE, &info, &des, &format); /* decompress */
  79. /* Specify the input (and therefore the output) strip height: if dstStripHeight
  80. is zero, take default, otherwise requested, always constant strips.
  81. */
  82. if (dstStripHeight <= 0)
  83. dstStripHeight = ilRecommendedStripHeight (&des, &format, info.width, info.height);
  84. srcData.consumerImage = (ilObject)NULL;
  85. srcData.minBufferHeight = 0;
  86. srcData.stripHeight = dstStripHeight;
  87. srcData.constantStrip = TRUE;
  88. /* Pipe image is now correct compression or is uncompressed. For compression
  89. types which have no variants, exit if already requested compression; for
  90. types with variant, call compression-specific code to check variant.
  91. */
  92. switch (compression) {
  93. case IL_UNCOMPRESSED: /* image now uncompressed; skip */
  94. break;
  95. case IL_G3: /* check G3 variants */
  96. return _ilCompressG3 (pipe, &info, &des, &format, &srcData, pCompData);
  97. break;
  98. case IL_JPEG: /* check JPEG variants */
  99. return _ilCompressJPEG (pipe, &info, &des, &format, &srcData, pCompData);
  100. break;
  101. case IL_G4: /* check G4 variants */
  102. return _ilCompressG4 (pipe, &info, &des, &format, &srcData, pCompData);
  103. break;
  104. case IL_LZW:
  105. if (des.compression != IL_LZW)
  106. return _ilCompressLZW (pipe, &info, &des, &format, &srcData);
  107. break;
  108. case IL_PACKBITS:
  109. if (des.compression != IL_PACKBITS)
  110. return _ilCompressPackbits (pipe, &info, &des, &format, &srcData);
  111. break;
  112. default:
  113. return ilDeclarePipeInvalid (pipe, IL_ERROR_COMPRESSION);
  114. }
  115. /* No (re)compression needed; exit with success */
  116. pipe->context->error = IL_OK;
  117. return TRUE;
  118. }