ildecompg4.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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: ildecompg4.h /main/3 1995/10/23 15:45:43 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. /* ====================================================================================
  40. -------------------- Macros --------------------
  41. ==================================================================================== */
  42. #define READ32_LSB(address) \
  43. (* ((unsigned char *)(address)) + \
  44. (*(((unsigned char *)(address))+1)<< 8) + \
  45. (*(((unsigned char *)(address))+2)<<16) + \
  46. (*(((unsigned char *)(address))+3)<<24))
  47. #define READ32_MSB(address) \
  48. (ilBitReverseTable[* ((unsigned char *)(address))] + \
  49. (ilBitReverseTable[*(((unsigned char *)(address))+1)] << 8) + \
  50. (ilBitReverseTable[*(((unsigned char *)(address))+2)]<<16) + \
  51. (ilBitReverseTable[*(((unsigned char *)(address))+3)]<<24) )
  52. #define GET_VALUE_LSB(value,base, offset, mask) { \
  53. if (offset > pPriv->maxSrcPos) return IL_ERROR_COMPRESSED_DATA; \
  54. value = (READ32_LSB((base) + ((offset) >> 3)) >> ((offset) & 7) & (mask)); \
  55. }
  56. #define GET_VALUE_MSB(value,base, offset, mask) { \
  57. if (offset > pPriv->maxSrcPos) return IL_ERROR_COMPRESSED_DATA; \
  58. value = (READ32_MSB((base) + ((offset) >> 3)) >> ((offset) & 7) & (mask)); \
  59. }
  60. /* ====================================================================================
  61. -------------------- Code table constants --------------------
  62. ==================================================================================== */
  63. #define G4K_BlackTableSize 8192
  64. #define G4K_WhiteTableSize 4096
  65. #define G4K_DecodeTableSize 4096
  66. #define G4K_MinSrcLen 14 /* Defines the maximum codeword size in bits */
  67. #define G4M_WhiteRun 0x0FFF
  68. #define G4M_BlackRun 0x1FFF
  69. #define G4M_Codeword 0x0FFF
  70. /* ====================================================================================
  71. -------------------- Decoding mode constants --------------------
  72. ==================================================================================== */
  73. #define G4K_ModeNewScan 1
  74. #define G4K_ModeCodeword 2
  75. #define G4K_ModeFirstRun 3
  76. #define G4K_ModeSecondRun 4
  77. /*
  78. These constants define the usage of the change lists. If the change list
  79. index is even, a white run is described. If a black run is being defined,
  80. the changelist index will be odd.
  81. */
  82. #define G4K_WhiteRun 1
  83. #define G4K_BlackRun 0
  84. /* Code type constants */
  85. #define G4K_CodetypeTerminator 2
  86. #define G4K_CodetypeEol -1
  87. #define G4K_CodetypeMakeup 1
  88. /* Code value constants */
  89. #define G4K_CodevaluePass 4
  90. #define G4K_CodevalueHoriz 5
  91. #define G4K_CodevalueV0 0
  92. #define G4K_CodevalueVR1 1
  93. #define G4K_CodevalueVL1 -1
  94. #define G4K_CodevalueVR2 2
  95. #define G4K_CodevalueVL2 -2
  96. #define G4K_CodevalueVR3 3
  97. #define G4K_CodevalueVL3 -3
  98. /* ====================================================================================
  99. -------------------- Status code definitions --------------------
  100. ==================================================================================== */
  101. #define G4K_StsEol -1
  102. #define G4K_StsDcdErr -2
  103. #define G4K_StsSrcExh -3
  104. #define G4K_StsDstFul -4
  105. #define G4K_AlgorithmAbort 62
  106. /* define to find out the value of the bit (1 or 0) in the image line */
  107. #define PIXEL(buf,ix) ((((buf)[(ix)>>3]) >> (7-((ix)&7))) & 1)
  108. /* define to find out the value of the bit (1 or 0) in the image line */
  109. #define PIXEL_LSB(buf,ix) ((ilBitReverseTable[((buf)[(ix)>>3])] >> (7-((ix)&7))) & 1)
  110. /* ========================================================================
  111. Decompression private data structure definition
  112. ======================================================================== */
  113. typedef struct {
  114. int width; /* width of the image */
  115. long compFlags; /* flags denoting G4 comp. options */
  116. ilBool white; /* value of the white pixel 0 or 1 */
  117. ilPtr ImageP; /* ptr. to the Source Image begin */
  118. int srcpos; /* bit position is Src image start */
  119. ilBool Is_Lsb_First; /* true if LSB is desired */
  120. ilPtr gpRefLine; /* ptr.to refrence line for 2d coding */
  121. long nDstLineBytes; /* no.of bytes in the Image */
  122. long maxSrcPos; /* size of the src Image in bits */
  123. } ilDecompG3G4PrivRec, *ilDecompG3G4PrivPtr;
  124. /* ====================================================================================
  125. -------------------- Huffman decode table structure definition --------------------
  126. ==================================================================================== */
  127. typedef struct {
  128. short value;
  129. unsigned char length;
  130. char type;
  131. } ilDecompG4HuffTableRec, *ilDecompG4HuffTablePtr;
  132. typedef const ilDecompG4HuffTableRec* ilDecompG4HuffTablePtrConst;
  133. IL_EXTERN const ilDecompG4HuffTableRec ilArFax1DDecodeWhite[G4K_WhiteTableSize];
  134. IL_EXTERN const ilDecompG4HuffTableRec ilArFax1DDecodeBlack[G4K_BlackTableSize];
  135. IL_EXTERN const ilDecompG4HuffTableRec ilArFax2DDecodeTable[G4K_DecodeTableSize];
  136. IL_EXTERN ilError _ilDecompG4Line(
  137. ilDecompG3G4PrivPtr pPriv,
  138. ilPtr pRefLine,
  139. ilPtr dstImageP
  140. );