LCOV - code coverage report
Current view: top level - filter/source/graphicfilter/itiff - ccidecom.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 129 286 45.1 %
Date: 2015-06-13 12:38:46 Functions: 7 13 53.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "ccidecom.hxx"
      22             : 
      23             : //=============================== Huffman tables ========================
      24             : 
      25             : //---------------------------- White-Run ------------------------------
      26             : 
      27             : #define CCIWhiteTableSize 105
      28             : 
      29             : const CCIHuffmanTableEntry CCIWhiteTable[CCIWhiteTableSize]={
      30             :     {    0, 0x0035,  8 },
      31             :     {    1, 0x0007,  6 },
      32             :     {    2, 0x0007,  4 },
      33             :     {    3, 0x0008,  4 },
      34             :     {    4, 0x000b,  4 },
      35             :     {    5, 0x000c,  4 },
      36             :     {    6, 0x000e,  4 },
      37             :     {    7, 0x000f,  4 },
      38             :     {    8, 0x0013,  5 },
      39             :     {    9, 0x0014,  5 },
      40             :     {   10, 0x0007,  5 },
      41             :     {   11, 0x0008,  5 },
      42             :     {   12, 0x0008,  6 },
      43             :     {   13, 0x0003,  6 },
      44             :     {   14, 0x0034,  6 },
      45             :     {   15, 0x0035,  6 },
      46             :     {   16, 0x002a,  6 },
      47             :     {   17, 0x002b,  6 },
      48             :     {   18, 0x0027,  7 },
      49             :     {   19, 0x000c,  7 },
      50             :     {   20, 0x0008,  7 },
      51             :     {   21, 0x0017,  7 },
      52             :     {   22, 0x0003,  7 },
      53             :     {   23, 0x0004,  7 },
      54             :     {   24, 0x0028,  7 },
      55             :     {   25, 0x002b,  7 },
      56             :     {   26, 0x0013,  7 },
      57             :     {   27, 0x0024,  7 },
      58             :     {   28, 0x0018,  7 },
      59             :     {   29, 0x0002,  8 },
      60             :     {   30, 0x0003,  8 },
      61             :     {   31, 0x001a,  8 },
      62             :     {   32, 0x001b,  8 },
      63             :     {   33, 0x0012,  8 },
      64             :     {   34, 0x0013,  8 },
      65             :     {   35, 0x0014,  8 },
      66             :     {   36, 0x0015,  8 },
      67             :     {   37, 0x0016,  8 },
      68             :     {   38, 0x0017,  8 },
      69             :     {   39, 0x0028,  8 },
      70             :     {   40, 0x0029,  8 },
      71             :     {   41, 0x002a,  8 },
      72             :     {   42, 0x002b,  8 },
      73             :     {   43, 0x002c,  8 },
      74             :     {   44, 0x002d,  8 },
      75             :     {   45, 0x0004,  8 },
      76             :     {   46, 0x0005,  8 },
      77             :     {   47, 0x000a,  8 },
      78             :     {   48, 0x000b,  8 },
      79             :     {   49, 0x0052,  8 },
      80             :     {   50, 0x0053,  8 },
      81             :     {   51, 0x0054,  8 },
      82             :     {   52, 0x0055,  8 },
      83             :     {   53, 0x0024,  8 },
      84             :     {   54, 0x0025,  8 },
      85             :     {   55, 0x0058,  8 },
      86             :     {   56, 0x0059,  8 },
      87             :     {   57, 0x005a,  8 },
      88             :     {   58, 0x005b,  8 },
      89             :     {   59, 0x004a,  8 },
      90             :     {   60, 0x004b,  8 },
      91             :     {   61, 0x0032,  8 },
      92             :     {   62, 0x0033,  8 },
      93             :     {   63, 0x0034,  8 },
      94             :     {   64, 0x001b,  5 },
      95             :     {  128, 0x0012,  5 },
      96             :     {  192, 0x0017,  6 },
      97             :     {  256, 0x0037,  7 },
      98             :     {  320, 0x0036,  8 },
      99             :     {  384, 0x0037,  8 },
     100             :     {  448, 0x0064,  8 },
     101             :     {  512, 0x0065,  8 },
     102             :     {  576, 0x0068,  8 },
     103             :     {  640, 0x0067,  8 },
     104             :     {  704, 0x00cc,  9 },
     105             :     {  768, 0x00cd,  9 },
     106             :     {  832, 0x00d2,  9 },
     107             :     {  896, 0x00d3,  9 },
     108             :     {  960, 0x00d4,  9 },
     109             :     { 1024, 0x00d5,  9 },
     110             :     { 1088, 0x00d6,  9 },
     111             :     { 1152, 0x00d7,  9 },
     112             :     { 1216, 0x00d8,  9 },
     113             :     { 1280, 0x00d9,  9 },
     114             :     { 1344, 0x00da,  9 },
     115             :     { 1408, 0x00db,  9 },
     116             :     { 1472, 0x0098,  9 },
     117             :     { 1536, 0x0099,  9 },
     118             :     { 1600, 0x009a,  9 },
     119             :     { 1664, 0x0018,  6 },
     120             :     { 1728, 0x009b,  9 },
     121             :     { 1792, 0x0008, 11 },
     122             :     { 1856, 0x000c, 11 },
     123             :     { 1920, 0x000d, 11 },
     124             :     { 1984, 0x0012, 12 },
     125             :     { 2048, 0x0013, 12 },
     126             :     { 2112, 0x0014, 12 },
     127             :     { 2176, 0x0015, 12 },
     128             :     { 2240, 0x0016, 12 },
     129             :     { 2304, 0x0017, 12 },
     130             :     { 2368, 0x001c, 12 },
     131             :     { 2432, 0x001d, 12 },
     132             :     { 2496, 0x001e, 12 },
     133             :     { 2560, 0x001f, 12 },
     134             :     { 9999, 0x0001, 12 }    //  EOL
     135             : };
     136             : 
     137             : //---------------------------- Black-Run ------------------------------
     138             : 
     139             : #define CCIBlackTableSize 105
     140             : 
     141             : const CCIHuffmanTableEntry CCIBlackTable[CCIBlackTableSize]={
     142             :     {    0, 0x0037, 10 },
     143             :     {    1, 0x0002,  3 },
     144             :     {    2, 0x0003,  2 },
     145             :     {    3, 0x0002,  2 },
     146             :     {    4, 0x0003,  3 },
     147             :     {    5, 0x0003,  4 },
     148             :     {    6, 0x0002,  4 },
     149             :     {    7, 0x0003,  5 },
     150             :     {    8, 0x0005,  6 },
     151             :     {    9, 0x0004,  6 },
     152             :     {   10, 0x0004,  7 },
     153             :     {   11, 0x0005,  7 },
     154             :     {   12, 0x0007,  7 },
     155             :     {   13, 0x0004,  8 },
     156             :     {   14, 0x0007,  8 },
     157             :     {   15, 0x0018,  9 },
     158             :     {   16, 0x0017, 10 },
     159             :     {   17, 0x0018, 10 },
     160             :     {   18, 0x0008, 10 },
     161             :     {   19, 0x0067, 11 },
     162             :     {   20, 0x0068, 11 },
     163             :     {   21, 0x006c, 11 },
     164             :     {   22, 0x0037, 11 },
     165             :     {   23, 0x0028, 11 },
     166             :     {   24, 0x0017, 11 },
     167             :     {   25, 0x0018, 11 },
     168             :     {   26, 0x00ca, 12 },
     169             :     {   27, 0x00cb, 12 },
     170             :     {   28, 0x00cc, 12 },
     171             :     {   29, 0x00cd, 12 },
     172             :     {   30, 0x0068, 12 },
     173             :     {   31, 0x0069, 12 },
     174             :     {   32, 0x006a, 12 },
     175             :     {   33, 0x006b, 12 },
     176             :     {   34, 0x00d2, 12 },
     177             :     {   35, 0x00d3, 12 },
     178             :     {   36, 0x00d4, 12 },
     179             :     {   37, 0x00d5, 12 },
     180             :     {   38, 0x00d6, 12 },
     181             :     {   39, 0x00d7, 12 },
     182             :     {   40, 0x006c, 12 },
     183             :     {   41, 0x006d, 12 },
     184             :     {   42, 0x00da, 12 },
     185             :     {   43, 0x00db, 12 },
     186             :     {   44, 0x0054, 12 },
     187             :     {   45, 0x0055, 12 },
     188             :     {   46, 0x0056, 12 },
     189             :     {   47, 0x0057, 12 },
     190             :     {   48, 0x0064, 12 },
     191             :     {   49, 0x0065, 12 },
     192             :     {   50, 0x0052, 12 },
     193             :     {   51, 0x0053, 12 },
     194             :     {   52, 0x0024, 12 },
     195             :     {   53, 0x0037, 12 },
     196             :     {   54, 0x0038, 12 },
     197             :     {   55, 0x0027, 12 },
     198             :     {   56, 0x0028, 12 },
     199             :     {   57, 0x0058, 12 },
     200             :     {   58, 0x0059, 12 },
     201             :     {   59, 0x002b, 12 },
     202             :     {   60, 0x002c, 12 },
     203             :     {   61, 0x005a, 12 },
     204             :     {   62, 0x0066, 12 },
     205             :     {   63, 0x0067, 12 },
     206             :     {   64, 0x000f, 10 },
     207             :     {  128, 0x00c8, 12 },
     208             :     {  192, 0x00c9, 12 },
     209             :     {  256, 0x005b, 12 },
     210             :     {  320, 0x0033, 12 },
     211             :     {  384, 0x0034, 12 },
     212             :     {  448, 0x0035, 12 },
     213             :     {  512, 0x006c, 13 },
     214             :     {  576, 0x006d, 13 },
     215             :     {  640, 0x004a, 13 },
     216             :     {  704, 0x004b, 13 },
     217             :     {  768, 0x004c, 13 },
     218             :     {  832, 0x004d, 13 },
     219             :     {  896, 0x0072, 13 },
     220             :     {  960, 0x0073, 13 },
     221             :     { 1024, 0x0074, 13 },
     222             :     { 1088, 0x0075, 13 },
     223             :     { 1152, 0x0076, 13 },
     224             :     { 1216, 0x0077, 13 },
     225             :     { 1280, 0x0052, 13 },
     226             :     { 1344, 0x0053, 13 },
     227             :     { 1408, 0x0054, 13 },
     228             :     { 1472, 0x0055, 13 },
     229             :     { 1536, 0x005a, 13 },
     230             :     { 1600, 0x005b, 13 },
     231             :     { 1664, 0x0064, 13 },
     232             :     { 1728, 0x0065, 13 },
     233             :     { 1792, 0x0008, 11 },
     234             :     { 1856, 0x000c, 11 },
     235             :     { 1920, 0x000d, 11 },
     236             :     { 1984, 0x0012, 12 },
     237             :     { 2048, 0x0013, 12 },
     238             :     { 2112, 0x0014, 12 },
     239             :     { 2176, 0x0015, 12 },
     240             :     { 2240, 0x0016, 12 },
     241             :     { 2304, 0x0017, 12 },
     242             :     { 2368, 0x001c, 12 },
     243             :     { 2432, 0x001d, 12 },
     244             :     { 2496, 0x001e, 12 },
     245             :     { 2560, 0x001f, 12 },
     246             :     { 9999, 0x0001, 12 }    //  EOL
     247             : };
     248             : 
     249             : 
     250             : //---------------------------- 2D-Mode --------------------------------
     251             : 
     252             : #define CCI2DMODE_UNCOMP   0
     253             : #define CCI2DMODE_PASS     1
     254             : #define CCI2DMODE_HORZ     2
     255             : #define CCI2DMODE_VERT_L3  3
     256             : #define CCI2DMODE_VERT_L2  4
     257             : #define CCI2DMODE_VERT_L1  5
     258             : #define CCI2DMODE_VERT_0   6
     259             : #define CCI2DMODE_VERT_R1  7
     260             : #define CCI2DMODE_VERT_R2  8
     261             : #define CCI2DMODE_VERT_R3  9
     262             : 
     263             : #define CCI2DModeTableSize 10
     264             : 
     265             : const CCIHuffmanTableEntry CCI2DModeTable[CCI2DModeTableSize]={
     266             :     { CCI2DMODE_UNCOMP , 0x000f, 10 },
     267             :     { CCI2DMODE_PASS   , 0x0001,  4 },
     268             :     { CCI2DMODE_HORZ   , 0x0001,  3 },
     269             :     { CCI2DMODE_VERT_L3, 0x0002,  7 },
     270             :     { CCI2DMODE_VERT_L2, 0x0002,  6 },
     271             :     { CCI2DMODE_VERT_L1, 0x0002,  3 },
     272             :     { CCI2DMODE_VERT_0 , 0x0001,  1 },
     273             :     { CCI2DMODE_VERT_R1, 0x0003,  3 },
     274             :     { CCI2DMODE_VERT_R2, 0x0003,  6 },
     275             :     { CCI2DMODE_VERT_R3, 0x0003,  7 }
     276             : };
     277             : 
     278             : 
     279             : //-------------------------- 2D-Uncompressed-Mode ----------------------
     280             : 
     281             : #define CCIUNCOMP_0White_1Black  0
     282             : #define CCIUNCOMP_1White_1Black  1
     283             : #define CCIUNCOMP_2White_1Black  2
     284             : #define CCIUNCOMP_3White_1Black  3
     285             : #define CCIUNCOMP_4White_1Black  4
     286             : #define CCIUNCOMP_5White         5
     287             : #define CCIUNCOMP_0White_End     6
     288             : #define CCIUNCOMP_1White_End     7
     289             : #define CCIUNCOMP_2White_End     8
     290             : #define CCIUNCOMP_3White_End     9
     291             : #define CCIUNCOMP_4White_End    10
     292             : 
     293             : #define CCIUncompTableSize 11
     294             : 
     295             : const CCIHuffmanTableEntry CCIUncompTable[CCIUncompTableSize]={
     296             :     { CCIUNCOMP_0White_1Black, 0x0001,  1 },
     297             :     { CCIUNCOMP_1White_1Black, 0x0001,  2 },
     298             :     { CCIUNCOMP_2White_1Black, 0x0001,  3 },
     299             :     { CCIUNCOMP_3White_1Black, 0x0001,  4 },
     300             :     { CCIUNCOMP_4White_1Black, 0x0001,  5 },
     301             :     { CCIUNCOMP_5White       , 0x0001,  6 },
     302             :     { CCIUNCOMP_0White_End   , 0x0001,  7 },
     303             :     { CCIUNCOMP_1White_End   , 0x0001,  8 },
     304             :     { CCIUNCOMP_2White_End   , 0x0001,  9 },
     305             :     { CCIUNCOMP_3White_End   , 0x0001, 10 },
     306             :     { CCIUNCOMP_4White_End   , 0x0001, 11 }
     307             : };
     308             : 
     309             : 
     310             : //================== backup of the Huffman tables ============================
     311             : // To make sure that the Huffman tables do not contain errors they were entered
     312             : // from two different sources (Phew) and compared.
     313             : // Since an error could creep in to the source code while maintaining it
     314             : // (e.g. an accidental key press in the editor) the tables are listed twice
     315             : // and are compared during runtime. (If the comparison fails CCIDcompressor
     316             : // throws an error) The whole thing may appear insane, but an error within the
     317             : // tables would otherwise be really hard to discover and it's very unlikely that
     318             : // one or more sample files run through all codes.
     319             : 
     320             : const CCIHuffmanTableEntry CCIWhiteTableSave[CCIWhiteTableSize]={
     321             :     {    0, 0x0035,  8 },
     322             :     {    1, 0x0007,  6 },
     323             :     {    2, 0x0007,  4 },
     324             :     {    3, 0x0008,  4 },
     325             :     {    4, 0x000b,  4 },
     326             :     {    5, 0x000c,  4 },
     327             :     {    6, 0x000e,  4 },
     328             :     {    7, 0x000f,  4 },
     329             :     {    8, 0x0013,  5 },
     330             :     {    9, 0x0014,  5 },
     331             :     {   10, 0x0007,  5 },
     332             :     {   11, 0x0008,  5 },
     333             :     {   12, 0x0008,  6 },
     334             :     {   13, 0x0003,  6 },
     335             :     {   14, 0x0034,  6 },
     336             :     {   15, 0x0035,  6 },
     337             :     {   16, 0x002a,  6 },
     338             :     {   17, 0x002b,  6 },
     339             :     {   18, 0x0027,  7 },
     340             :     {   19, 0x000c,  7 },
     341             :     {   20, 0x0008,  7 },
     342             :     {   21, 0x0017,  7 },
     343             :     {   22, 0x0003,  7 },
     344             :     {   23, 0x0004,  7 },
     345             :     {   24, 0x0028,  7 },
     346             :     {   25, 0x002b,  7 },
     347             :     {   26, 0x0013,  7 },
     348             :     {   27, 0x0024,  7 },
     349             :     {   28, 0x0018,  7 },
     350             :     {   29, 0x0002,  8 },
     351             :     {   30, 0x0003,  8 },
     352             :     {   31, 0x001a,  8 },
     353             :     {   32, 0x001b,  8 },
     354             :     {   33, 0x0012,  8 },
     355             :     {   34, 0x0013,  8 },
     356             :     {   35, 0x0014,  8 },
     357             :     {   36, 0x0015,  8 },
     358             :     {   37, 0x0016,  8 },
     359             :     {   38, 0x0017,  8 },
     360             :     {   39, 0x0028,  8 },
     361             :     {   40, 0x0029,  8 },
     362             :     {   41, 0x002a,  8 },
     363             :     {   42, 0x002b,  8 },
     364             :     {   43, 0x002c,  8 },
     365             :     {   44, 0x002d,  8 },
     366             :     {   45, 0x0004,  8 },
     367             :     {   46, 0x0005,  8 },
     368             :     {   47, 0x000a,  8 },
     369             :     {   48, 0x000b,  8 },
     370             :     {   49, 0x0052,  8 },
     371             :     {   50, 0x0053,  8 },
     372             :     {   51, 0x0054,  8 },
     373             :     {   52, 0x0055,  8 },
     374             :     {   53, 0x0024,  8 },
     375             :     {   54, 0x0025,  8 },
     376             :     {   55, 0x0058,  8 },
     377             :     {   56, 0x0059,  8 },
     378             :     {   57, 0x005a,  8 },
     379             :     {   58, 0x005b,  8 },
     380             :     {   59, 0x004a,  8 },
     381             :     {   60, 0x004b,  8 },
     382             :     {   61, 0x0032,  8 },
     383             :     {   62, 0x0033,  8 },
     384             :     {   63, 0x0034,  8 },
     385             :     {   64, 0x001b,  5 },
     386             :     {  128, 0x0012,  5 },
     387             :     {  192, 0x0017,  6 },
     388             :     {  256, 0x0037,  7 },
     389             :     {  320, 0x0036,  8 },
     390             :     {  384, 0x0037,  8 },
     391             :     {  448, 0x0064,  8 },
     392             :     {  512, 0x0065,  8 },
     393             :     {  576, 0x0068,  8 },
     394             :     {  640, 0x0067,  8 },
     395             :     {  704, 0x00cc,  9 },
     396             :     {  768, 0x00cd,  9 },
     397             :     {  832, 0x00d2,  9 },
     398             :     {  896, 0x00d3,  9 },
     399             :     {  960, 0x00d4,  9 },
     400             :     { 1024, 0x00d5,  9 },
     401             :     { 1088, 0x00d6,  9 },
     402             :     { 1152, 0x00d7,  9 },
     403             :     { 1216, 0x00d8,  9 },
     404             :     { 1280, 0x00d9,  9 },
     405             :     { 1344, 0x00da,  9 },
     406             :     { 1408, 0x00db,  9 },
     407             :     { 1472, 0x0098,  9 },
     408             :     { 1536, 0x0099,  9 },
     409             :     { 1600, 0x009a,  9 },
     410             :     { 1664, 0x0018,  6 },
     411             :     { 1728, 0x009b,  9 },
     412             :     { 1792, 0x0008, 11 },
     413             :     { 1856, 0x000c, 11 },
     414             :     { 1920, 0x000d, 11 },
     415             :     { 1984, 0x0012, 12 },
     416             :     { 2048, 0x0013, 12 },
     417             :     { 2112, 0x0014, 12 },
     418             :     { 2176, 0x0015, 12 },
     419             :     { 2240, 0x0016, 12 },
     420             :     { 2304, 0x0017, 12 },
     421             :     { 2368, 0x001c, 12 },
     422             :     { 2432, 0x001d, 12 },
     423             :     { 2496, 0x001e, 12 },
     424             :     { 2560, 0x001f, 12 },
     425             :     { 9999, 0x0001, 12 }    //  EOL
     426             : };
     427             : 
     428             : const CCIHuffmanTableEntry CCIBlackTableSave[CCIBlackTableSize]={
     429             :     {    0, 0x0037, 10 },
     430             :     {    1, 0x0002,  3 },
     431             :     {    2, 0x0003,  2 },
     432             :     {    3, 0x0002,  2 },
     433             :     {    4, 0x0003,  3 },
     434             :     {    5, 0x0003,  4 },
     435             :     {    6, 0x0002,  4 },
     436             :     {    7, 0x0003,  5 },
     437             :     {    8, 0x0005,  6 },
     438             :     {    9, 0x0004,  6 },
     439             :     {   10, 0x0004,  7 },
     440             :     {   11, 0x0005,  7 },
     441             :     {   12, 0x0007,  7 },
     442             :     {   13, 0x0004,  8 },
     443             :     {   14, 0x0007,  8 },
     444             :     {   15, 0x0018,  9 },
     445             :     {   16, 0x0017, 10 },
     446             :     {   17, 0x0018, 10 },
     447             :     {   18, 0x0008, 10 },
     448             :     {   19, 0x0067, 11 },
     449             :     {   20, 0x0068, 11 },
     450             :     {   21, 0x006c, 11 },
     451             :     {   22, 0x0037, 11 },
     452             :     {   23, 0x0028, 11 },
     453             :     {   24, 0x0017, 11 },
     454             :     {   25, 0x0018, 11 },
     455             :     {   26, 0x00ca, 12 },
     456             :     {   27, 0x00cb, 12 },
     457             :     {   28, 0x00cc, 12 },
     458             :     {   29, 0x00cd, 12 },
     459             :     {   30, 0x0068, 12 },
     460             :     {   31, 0x0069, 12 },
     461             :     {   32, 0x006a, 12 },
     462             :     {   33, 0x006b, 12 },
     463             :     {   34, 0x00d2, 12 },
     464             :     {   35, 0x00d3, 12 },
     465             :     {   36, 0x00d4, 12 },
     466             :     {   37, 0x00d5, 12 },
     467             :     {   38, 0x00d6, 12 },
     468             :     {   39, 0x00d7, 12 },
     469             :     {   40, 0x006c, 12 },
     470             :     {   41, 0x006d, 12 },
     471             :     {   42, 0x00da, 12 },
     472             :     {   43, 0x00db, 12 },
     473             :     {   44, 0x0054, 12 },
     474             :     {   45, 0x0055, 12 },
     475             :     {   46, 0x0056, 12 },
     476             :     {   47, 0x0057, 12 },
     477             :     {   48, 0x0064, 12 },
     478             :     {   49, 0x0065, 12 },
     479             :     {   50, 0x0052, 12 },
     480             :     {   51, 0x0053, 12 },
     481             :     {   52, 0x0024, 12 },
     482             :     {   53, 0x0037, 12 },
     483             :     {   54, 0x0038, 12 },
     484             :     {   55, 0x0027, 12 },
     485             :     {   56, 0x0028, 12 },
     486             :     {   57, 0x0058, 12 },
     487             :     {   58, 0x0059, 12 },
     488             :     {   59, 0x002b, 12 },
     489             :     {   60, 0x002c, 12 },
     490             :     {   61, 0x005a, 12 },
     491             :     {   62, 0x0066, 12 },
     492             :     {   63, 0x0067, 12 },
     493             :     {   64, 0x000f, 10 },
     494             :     {  128, 0x00c8, 12 },
     495             :     {  192, 0x00c9, 12 },
     496             :     {  256, 0x005b, 12 },
     497             :     {  320, 0x0033, 12 },
     498             :     {  384, 0x0034, 12 },
     499             :     {  448, 0x0035, 12 },
     500             :     {  512, 0x006c, 13 },
     501             :     {  576, 0x006d, 13 },
     502             :     {  640, 0x004a, 13 },
     503             :     {  704, 0x004b, 13 },
     504             :     {  768, 0x004c, 13 },
     505             :     {  832, 0x004d, 13 },
     506             :     {  896, 0x0072, 13 },
     507             :     {  960, 0x0073, 13 },
     508             :     { 1024, 0x0074, 13 },
     509             :     { 1088, 0x0075, 13 },
     510             :     { 1152, 0x0076, 13 },
     511             :     { 1216, 0x0077, 13 },
     512             :     { 1280, 0x0052, 13 },
     513             :     { 1344, 0x0053, 13 },
     514             :     { 1408, 0x0054, 13 },
     515             :     { 1472, 0x0055, 13 },
     516             :     { 1536, 0x005a, 13 },
     517             :     { 1600, 0x005b, 13 },
     518             :     { 1664, 0x0064, 13 },
     519             :     { 1728, 0x0065, 13 },
     520             :     { 1792, 0x0008, 11 },
     521             :     { 1856, 0x000c, 11 },
     522             :     { 1920, 0x000d, 11 },
     523             :     { 1984, 0x0012, 12 },
     524             :     { 2048, 0x0013, 12 },
     525             :     { 2112, 0x0014, 12 },
     526             :     { 2176, 0x0015, 12 },
     527             :     { 2240, 0x0016, 12 },
     528             :     { 2304, 0x0017, 12 },
     529             :     { 2368, 0x001c, 12 },
     530             :     { 2432, 0x001d, 12 },
     531             :     { 2496, 0x001e, 12 },
     532             :     { 2560, 0x001f, 12 },
     533             :     { 9999, 0x0001, 12 }    //  EOL
     534             : };
     535             : 
     536             : 
     537             : const CCIHuffmanTableEntry CCI2DModeTableSave[CCI2DModeTableSize]={
     538             :     { CCI2DMODE_UNCOMP , 0x000f, 10 },
     539             :     { CCI2DMODE_PASS   , 0x0001,  4 },
     540             :     { CCI2DMODE_HORZ   , 0x0001,  3 },
     541             :     { CCI2DMODE_VERT_L3, 0x0002,  7 },
     542             :     { CCI2DMODE_VERT_L2, 0x0002,  6 },
     543             :     { CCI2DMODE_VERT_L1, 0x0002,  3 },
     544             :     { CCI2DMODE_VERT_0 , 0x0001,  1 },
     545             :     { CCI2DMODE_VERT_R1, 0x0003,  3 },
     546             :     { CCI2DMODE_VERT_R2, 0x0003,  6 },
     547             :     { CCI2DMODE_VERT_R3, 0x0003,  7 }
     548             : };
     549             : 
     550             : 
     551             : const CCIHuffmanTableEntry CCIUncompTableSave[CCIUncompTableSize]={
     552             :     { CCIUNCOMP_0White_1Black, 0x0001,  1 },
     553             :     { CCIUNCOMP_1White_1Black, 0x0001,  2 },
     554             :     { CCIUNCOMP_2White_1Black, 0x0001,  3 },
     555             :     { CCIUNCOMP_3White_1Black, 0x0001,  4 },
     556             :     { CCIUNCOMP_4White_1Black, 0x0001,  5 },
     557             :     { CCIUNCOMP_5White       , 0x0001,  6 },
     558             :     { CCIUNCOMP_0White_End   , 0x0001,  7 },
     559             :     { CCIUNCOMP_1White_End   , 0x0001,  8 },
     560             :     { CCIUNCOMP_2White_End   , 0x0001,  9 },
     561             :     { CCIUNCOMP_3White_End   , 0x0001, 10 },
     562             :     { CCIUNCOMP_4White_End   , 0x0001, 11 }
     563             : };
     564             : 
     565             : 
     566             : 
     567             : 
     568           1 : CCIDecompressor::CCIDecompressor( sal_uLong nOpts, sal_uInt32 nImageWidth ) :
     569             :     bTableBad   ( false ),
     570             :     bStatus     ( false ),
     571             :     pByteSwap   ( NULL ),
     572             :     pIStream    ( NULL ),
     573             :     nEOLCount   ( 0 ),
     574             :     nWidth      ( nImageWidth ),
     575             :     nOptions    ( nOpts ),
     576             :     bFirstEOL   ( false ),
     577             :     nInputBitsBuf( 0 ),
     578             :     nInputBitsBufSize( 0 ),
     579             :     pLastLine   ( NULL ),
     580           1 :     nLastLineSize( 0 )
     581             : {
     582           1 :     if ( nOpts & CCI_OPTION_INVERSEBITORDER )
     583             :     {
     584           1 :         pByteSwap = new sal_uInt8[ 256 ];
     585         257 :         for ( int i = 0; i < 256; i++ )
     586             :         {
     587         256 :             pByteSwap[ i ] = sal::static_int_cast< sal_uInt8 >(
     588         512 :                 ( i << 7 ) | ( ( i & 2 ) << 5 ) | ( ( i & 4 ) << 3 ) | ( ( i & 8 ) << 1 ) |
     589         512 :                 ( ( i & 16 ) >> 1 ) | ( ( i & 32 ) >> 3 ) | ( ( i & 64 ) >> 5 ) | ( ( i & 128 ) >> 7 ));
     590             :         }
     591             :     }
     592             : 
     593           1 :     pWhiteLookUp =new CCILookUpTableEntry[1<<13];
     594           1 :     pBlackLookUp =new CCILookUpTableEntry[1<<13];
     595           1 :     p2DModeLookUp=new CCILookUpTableEntry[1<<10];
     596           1 :     pUncompLookUp=new CCILookUpTableEntry[1<<11];
     597             : 
     598           1 :     MakeLookUp(CCIWhiteTable,CCIWhiteTableSave,pWhiteLookUp,CCIWhiteTableSize,13);
     599           1 :     MakeLookUp(CCIBlackTable,CCIBlackTableSave,pBlackLookUp,CCIBlackTableSize,13);
     600           1 :     MakeLookUp(CCI2DModeTable,CCI2DModeTableSave,p2DModeLookUp,CCI2DModeTableSize,10);
     601           1 :     MakeLookUp(CCIUncompTable,CCIUncompTableSave,pUncompLookUp,CCIUncompTableSize,11);
     602           1 : }
     603             : 
     604             : 
     605           1 : CCIDecompressor::~CCIDecompressor()
     606             : {
     607           1 :     delete[] pByteSwap;
     608           1 :     delete[] pLastLine;
     609           1 :     delete[] pWhiteLookUp;
     610           1 :     delete[] pBlackLookUp;
     611           1 :     delete[] p2DModeLookUp;
     612           1 :     delete[] pUncompLookUp;
     613           1 : }
     614             : 
     615             : 
     616           1 : void CCIDecompressor::StartDecompression( SvStream & rIStream )
     617             : {
     618           1 :     pIStream = &rIStream;
     619           1 :     nInputBitsBufSize = 0;
     620           1 :     bFirstEOL = true;
     621           1 :     bStatus = true;
     622           1 :     nEOLCount = 0;
     623             : 
     624           1 :     if ( bTableBad )
     625           0 :         return;
     626             : }
     627             : 
     628             : 
     629        3248 : bool CCIDecompressor::DecompressScanline( sal_uInt8 * pTarget, sal_uLong nTargetBits, bool bLastLine )
     630             : {
     631             :     sal_uInt16 i;
     632             :     sal_uInt8 * pDst;
     633             :     bool b2D;
     634             : 
     635        3248 :     if ( nEOLCount >= 5 )   // RTC (Return To Controller)
     636           0 :         return true;
     637             : 
     638        3248 :     if ( !bStatus )
     639           0 :         return false;
     640             : 
     641             :     // If EOL-Codes exist, the EOL-Code also appeared in front of the first line.
     642             :     // (and I thought it means 'End of Line'...)
     643             :     // Therefore we read the EOL-Code always at the beginning of each line first:
     644        3248 :     if ( nOptions & CCI_OPTION_EOL )
     645             :     {
     646        3248 :         if ( bFirstEOL )
     647             :         {
     648           1 :             sal_uInt32 nCurPos = pIStream->Tell();
     649           1 :             sal_uInt16 nOldInputBitsBufSize = nInputBitsBufSize;
     650           1 :             sal_uInt32 nOldInputBitsBuf = nInputBitsBuf;
     651           1 :             if ( !ReadEOL( 32 ) )
     652             :             {
     653           0 :                 nInputBitsBufSize = nOldInputBitsBufSize;
     654           0 :                 nInputBitsBuf = nOldInputBitsBuf;
     655           0 :                 pIStream->Seek( nCurPos );
     656           0 :                 nOptions &=~ CCI_OPTION_EOL;                // CCITT Group 3 - Compression Type 2
     657             :             }
     658           1 :             bFirstEOL = false;
     659             :         }
     660             :         else
     661             :         {
     662        3247 :             if ( !ReadEOL( nTargetBits ) )
     663             :             {
     664           0 :                 return bStatus;
     665             :             }
     666             :         }
     667             :     }
     668             : 
     669        3248 :     if ( nEOLCount >= 5 )   // RTC (Return To Controller)
     670           0 :         return true;
     671             : 
     672             :     // should the situation arise, generate a white previous line for 2D:
     673        3248 :     if ( nOptions & CCI_OPTION_2D )
     674             :     {
     675           0 :         if ( pLastLine == NULL || nLastLineSize != ( ( nTargetBits + 7 ) >> 3 ) )
     676             :         {
     677           0 :             if ( pLastLine == NULL )
     678           0 :                 delete[] pLastLine;
     679           0 :             nLastLineSize = ( nTargetBits + 7 ) >> 3;
     680           0 :             pLastLine = new sal_uInt8[ nLastLineSize ];
     681           0 :             pDst = pLastLine;
     682           0 :             for ( i = 0; i < nLastLineSize; i++ ) *( pDst++ ) = 0x00;
     683             :         }
     684             :     }
     685             :     // conditionally align start of line to next byte:
     686        3248 :     if ( nOptions & CCI_OPTION_BYTEALIGNROW )
     687           0 :         nInputBitsBufSize &= 0xfff8;
     688             : 
     689             :     // is it a 2D row?
     690        3248 :     if ( nOptions & CCI_OPTION_2D )
     691             :     {
     692           0 :         if ( nOptions & CCI_OPTION_EOL )
     693           0 :             b2D = Read2DTag();
     694             :         else
     695           0 :             b2D = true;
     696             :     }
     697             :     else
     698        3248 :         b2D = false;
     699             : 
     700             :     // read scanline:
     701        3248 :     if ( b2D )
     702           0 :         Read2DScanlineData( pTarget, (sal_uInt16)nTargetBits );
     703             :     else
     704        3248 :         Read1DScanlineData( pTarget, (sal_uInt16)nTargetBits );
     705             : 
     706             :     // if we're in 2D mode we have to remember the line:
     707        3248 :     if ( nOptions & CCI_OPTION_2D && bStatus )
     708             :     {
     709           0 :         sal_uInt8 *pSrc = pTarget;
     710           0 :         pDst = pLastLine;
     711           0 :         for ( i = 0; i < nLastLineSize; i++ ) *(pDst++)=*(pSrc++);
     712             :     }
     713             : 
     714             :     // #i122984#
     715        3248 :     if( !bStatus && bLastLine )
     716             :     {
     717           0 :         bStatus = true;
     718             :     }
     719             : 
     720        3248 :     if ( pIStream->GetError() )
     721           0 :         bStatus = false;
     722             : 
     723        3248 :     return bStatus;
     724             : }
     725             : 
     726             : 
     727           4 : void CCIDecompressor::MakeLookUp(const CCIHuffmanTableEntry * pHufTab,
     728             :                                  const CCIHuffmanTableEntry * pHufTabSave,
     729             :                                  CCILookUpTableEntry * pLookUp,
     730             :                                  sal_uInt16 nHuffmanTableSize,
     731             :                                  sal_uInt16 nMaxCodeBits)
     732             : {
     733           4 :     sal_uInt16 nLookUpSize = 1 << nMaxCodeBits;
     734           4 :     memset(pLookUp, 0, nLookUpSize * sizeof(CCILookUpTableEntry));
     735             : 
     736           4 :     if (bTableBad)
     737           0 :         return;
     738             : 
     739           4 :     sal_uInt16 nMask = 0xffff >> (16-nMaxCodeBits);
     740             : 
     741         235 :     for (sal_uInt16 i = 0; i < nHuffmanTableSize; ++i)
     742             :     {
     743         462 :         if ( pHufTab[i].nValue!=pHufTabSave[i].nValue ||
     744         462 :              pHufTab[i].nCode!=pHufTabSave[i].nCode ||
     745         462 :              pHufTab[i].nCodeBits!=pHufTabSave[i].nCodeBits ||
     746         462 :              pHufTab[i].nCodeBits==0 ||
     747         231 :              pHufTab[i].nCodeBits>nMaxCodeBits )
     748             :         {
     749           0 :             bTableBad=true;
     750           0 :             return;
     751             :         }
     752         231 :         sal_uInt16 nMinCode = nMask & (pHufTab[i].nCode << (nMaxCodeBits-pHufTab[i].nCodeBits));
     753         231 :         sal_uInt16 nMaxCode = nMinCode | (nMask >> pHufTab[i].nCodeBits);
     754       19611 :         for (sal_uInt16 j=nMinCode; j<=nMaxCode; ++j)
     755             :         {
     756       19380 :             if (pLookUp[j].nCodeBits!=0)
     757             :             {
     758           0 :                 bTableBad=true;
     759           0 :                 return;
     760             :             }
     761       19380 :             pLookUp[j].nValue=pHufTab[i].nValue;
     762       19380 :             pLookUp[j].nCodeBits=pHufTab[i].nCodeBits;
     763             :         }
     764             :     }
     765             : }
     766             : 
     767             : 
     768        3248 : bool CCIDecompressor::ReadEOL( sal_uInt32 /*nMaxFillBits*/ )
     769             : {
     770             :     sal_uInt16  nCode;
     771             :     sal_uInt8   nByte;
     772             : 
     773             :     // if (nOptions&CCI_OPTION_BYTEALIGNEOL) nMaxFillBits=7; else nMaxFillBits=0;
     774             :     // D'oh: Either the option in itiff.cxx is not set correctly (-> error in documentation)
     775             :     // or there exist some nasty export filter who always do align.
     776             :     // In addition files were found in which more than the necessary maximum of 7 filling
     777             :     // bits were found. Therefore we now generally accept up to 32 nonsense bits in front of the EOL-Code:
     778             :     // And I found a file in which up to ??? nonsense bits are written. Furthemore the byte order is switched in it. (SJ)
     779             : 
     780        3248 :     sal_uInt32 nMaxPos = pIStream->Tell();
     781        3248 :     nMaxPos += nWidth >> 3;
     782             : 
     783             :     for ( ;; )
     784             :     {
     785        9307 :         while ( nInputBitsBufSize < 12 )
     786             :         {
     787        2811 :             pIStream->ReadUChar( nByte );
     788        2811 :             if ( pIStream->IsEof() )
     789           0 :                 return false;
     790        2811 :             if ( pIStream->Tell() > nMaxPos )
     791           0 :                 return false;
     792             : 
     793        2811 :             if ( nOptions & CCI_OPTION_INVERSEBITORDER )
     794        2811 :                 nByte = pByteSwap[ nByte ];
     795        2811 :             nInputBitsBuf=(nInputBitsBuf<<8) | (sal_uLong)nByte;
     796        2811 :             nInputBitsBufSize += 8;
     797             :         }
     798        3248 :         nCode = (sal_uInt16)( ( nInputBitsBuf >> ( nInputBitsBufSize - 12 ) ) & 0x0fff );
     799        3248 :         if ( nCode == 0x0001 )
     800             :         {
     801        3248 :             nEOLCount++;
     802        3248 :             nInputBitsBufSize -= 12;
     803        3248 :             break;
     804             :         }
     805             :         else
     806           0 :             nInputBitsBufSize--;
     807             :     }
     808           0 :     return true;
     809             : }
     810             : 
     811             : 
     812           0 : bool CCIDecompressor::Read2DTag()
     813             : {
     814             :     sal_uInt8 nByte;
     815             : 
     816             :     // read abit and return sal_True if it's 0, otherwise return sal_False
     817           0 :     if (nInputBitsBufSize==0) {
     818           0 :         pIStream->ReadUChar( nByte );
     819           0 :         if ( nOptions & CCI_OPTION_INVERSEBITORDER )
     820           0 :             nByte = pByteSwap[ nByte ];
     821           0 :         nInputBitsBuf=(sal_uLong)nByte;
     822           0 :         nInputBitsBufSize=8;
     823             :     }
     824           0 :     nInputBitsBufSize--;
     825           0 :     if ( ((nInputBitsBuf>>nInputBitsBufSize)&0x0001) ) return false;
     826           0 :     else return true;
     827             : }
     828             : 
     829             : 
     830           0 : sal_uInt8 CCIDecompressor::ReadBlackOrWhite()
     831             : {
     832             :     sal_uInt8 nByte;
     833             : 
     834             :     // read a bit and deliver 0x00 if it's 0, otherwise 0xff
     835           0 :     if (nInputBitsBufSize==0) {
     836           0 :         pIStream->ReadUChar( nByte );
     837           0 :         if ( nOptions & CCI_OPTION_INVERSEBITORDER )
     838           0 :             nByte = pByteSwap[ nByte ];
     839           0 :         nInputBitsBuf=(sal_uLong)nByte;
     840           0 :         nInputBitsBufSize=8;
     841             :     }
     842           0 :     nInputBitsBufSize--;
     843           0 :     if ( ((nInputBitsBuf>>nInputBitsBufSize)&0x0001) ) return 0xff;
     844           0 :     else return 0x00;
     845             : }
     846             : 
     847             : 
     848           0 : sal_uInt16 CCIDecompressor::ReadCodeAndDecode(const CCILookUpTableEntry * pLookUp,
     849             :                                           sal_uInt16 nMaxCodeBits)
     850             : {
     851             :     // read a Huffman code and decode it:
     852           0 :     while (nInputBitsBufSize<nMaxCodeBits)
     853             :     {
     854           0 :         sal_uInt8 nByte(0);
     855           0 :         pIStream->ReadUChar( nByte );
     856           0 :         if ( nOptions  & CCI_OPTION_INVERSEBITORDER )
     857           0 :             nByte = pByteSwap[ nByte ];
     858           0 :         nInputBitsBuf=(nInputBitsBuf<<8) | (sal_uLong)nByte;
     859           0 :         nInputBitsBufSize+=8;
     860             :     }
     861           0 :     sal_uInt16 nCode = (sal_uInt16)((nInputBitsBuf>>(nInputBitsBufSize-nMaxCodeBits))
     862           0 :                    &(0xffff>>(16-nMaxCodeBits)));
     863           0 :     sal_uInt16 nCodeBits = pLookUp[nCode].nCodeBits;
     864           0 :     if (nCodeBits==0) bStatus=false;
     865           0 :     nInputBitsBufSize = nInputBitsBufSize - nCodeBits;
     866           0 :     return pLookUp[nCode].nValue;
     867             : }
     868             : 
     869             : 
     870           0 : void CCIDecompressor::FillBits(sal_uInt8 * pTarget, sal_uInt16 nTargetBits,
     871             :                                sal_uInt16 nBitPos, sal_uInt16 nNumBits,
     872             :                                sal_uInt8 nBlackOrWhite)
     873             : {
     874           0 :     if ( nBitPos >= nTargetBits )
     875           0 :         return;
     876           0 :     if ( nBitPos + nNumBits > nTargetBits )
     877           0 :         nNumBits = nTargetBits - nBitPos;
     878             : 
     879           0 :     pTarget+=nBitPos>>3;
     880           0 :     nBitPos&=7;
     881             : 
     882           0 :     if (nBlackOrWhite==0x00) *pTarget &= 0xff << (8-nBitPos);
     883           0 :     else                     *pTarget |= 0xff >> nBitPos;
     884           0 :     if (nNumBits>8-nBitPos) {
     885           0 :         nNumBits-=8-nBitPos;
     886           0 :         while (nNumBits>=8) {
     887           0 :             *(++pTarget)=nBlackOrWhite;
     888           0 :             nNumBits-=8;
     889             :         }
     890           0 :         if (nNumBits>0) *(++pTarget)=nBlackOrWhite;
     891             :     }
     892             : }
     893             : 
     894             : 
     895           0 : sal_uInt16 CCIDecompressor::CountBits(const sal_uInt8 * pData, sal_uInt16 nDataSizeBits,
     896             :                                   sal_uInt16 nBitPos, sal_uInt8 nBlackOrWhite)
     897             : {
     898             :     sal_uInt16 nPos,nLo;
     899             :     sal_uInt8 nData;
     900             : 
     901             :     // here the number of bits belonging together is being counted
     902             :     // which all have the color nBlackOrWhite (0xff oder 0x00)
     903             :     // from the position nBitPos on
     904             : 
     905           0 :     nPos=nBitPos;
     906             :     for (;;) {
     907           0 :         if (nPos>=nDataSizeBits) {
     908           0 :             nPos=nDataSizeBits;
     909           0 :             break;
     910             :         }
     911           0 :         nData=pData[nPos>>3];
     912           0 :         nLo=nPos & 7;
     913           0 :         if ( nLo==0 && nData==nBlackOrWhite) nPos+=8;
     914             :         else {
     915           0 :             if ( ((nData^nBlackOrWhite) & (0x80 >> nLo))!=0) break;
     916           0 :             nPos++;
     917             :         }
     918             :     }
     919           0 :     if (nPos<=nBitPos) return 0;
     920           0 :     else return nPos-nBitPos;
     921             : }
     922             : 
     923             : 
     924        3248 : void CCIDecompressor::Read1DScanlineData(sal_uInt8 * pTarget, sal_uInt16 nTargetBits)
     925             : {
     926             :     sal_uInt16 nCode,nCodeBits,nDataBits,nTgtFreeByteBits;
     927             :     sal_uInt8 nByte;
     928             :     sal_uInt8 nBlackOrWhite; // is 0xff for black or 0x00 for white
     929             :     bool bTerminatingCode;
     930             : 
     931             :     // the first code is always a "white-code":
     932        3248 :     nBlackOrWhite=0x00;
     933             : 
     934             :     // number of bits that aren't written in the byte *pTarget yet:
     935        3248 :     nTgtFreeByteBits=8;
     936             : 
     937             :     // loop through codes from the input stream:
     938      188884 :     do {
     939             : 
     940             :         // fetch next 13 bits into nCodem but dont remove them from
     941             :         // the input buffer:
     942      500513 :         while (nInputBitsBufSize<13) {
     943      122745 :             pIStream->ReadUChar( nByte );
     944      122745 :             if ( nOptions & CCI_OPTION_INVERSEBITORDER )
     945      122745 :                 nByte = pByteSwap[ nByte ];
     946      122745 :             nInputBitsBuf=(nInputBitsBuf<<8) | (sal_uLong)nByte;
     947      122745 :             nInputBitsBufSize+=8;
     948             :         }
     949      188884 :         nCode=(sal_uInt16)((nInputBitsBuf>>(nInputBitsBufSize-13))&0x1fff);
     950             : 
     951             :         // determine the number of DataBits CodeBits:
     952      188884 :         if (nBlackOrWhite) {
     953       81948 :             nCodeBits=pBlackLookUp[nCode].nCodeBits;
     954       81948 :             nDataBits=pBlackLookUp[nCode].nValue;
     955             :         }
     956             :         else {
     957      106936 :             nCodeBits=pWhiteLookUp[nCode].nCodeBits;
     958      106936 :             nDataBits=pWhiteLookUp[nCode].nValue;
     959             :         }
     960             :         // is that an invalid code?
     961      188884 :         if ( nDataBits == 9999 )
     962             :         {
     963           0 :             return;
     964             :         }
     965      188884 :         if ( nCodeBits == 0 )
     966             :         {
     967           0 :             return;             // could be filling bits now
     968             :         }
     969      188884 :         nEOLCount = 0;
     970             :         // too much data?
     971      188884 :         if (nDataBits>nTargetBits) {
     972             :             // Yes, could be a subsequent error cause by an invalid code
     973             :             // Thefore continue anyhow:
     974           0 :             nDataBits=nTargetBits;
     975             :         }
     976             : 
     977             :         // is that a 'Terminating-Code'?
     978      188884 :         if (nDataBits<64) bTerminatingCode=true; else bTerminatingCode=false;
     979             : 
     980             :         // remove the read bits from the input buffer:
     981      188884 :         nInputBitsBufSize = nInputBitsBufSize - nCodeBits;
     982             : 
     983             :         // write the number of data bits into the scanline:
     984      188884 :         if (nDataBits>0) {
     985      188584 :             nTargetBits = nTargetBits - nDataBits;
     986      188584 :             if (nBlackOrWhite==0x00) *pTarget &= 0xff << nTgtFreeByteBits;
     987       81934 :             else                     *pTarget |= 0xff >> (8-nTgtFreeByteBits);
     988      188584 :             if (nDataBits<=nTgtFreeByteBits) {
     989       88845 :                 if (nDataBits==nTgtFreeByteBits) {
     990       18807 :                     pTarget++;
     991       18807 :                     nTgtFreeByteBits=8;
     992             :                 }
     993       70038 :                 else nTgtFreeByteBits = nTgtFreeByteBits - nDataBits;
     994             :             }
     995             :             else {
     996       99739 :                 nDataBits = nDataBits - nTgtFreeByteBits;
     997       99739 :                 pTarget++;
     998       99739 :                 nTgtFreeByteBits=8;
     999     1081316 :                 while (nDataBits>=8) {
    1000      881838 :                     *(pTarget++)=nBlackOrWhite;
    1001      881838 :                     nDataBits-=8;
    1002             :                 }
    1003       99739 :                 if (nDataBits>0) {
    1004       80312 :                     *pTarget=nBlackOrWhite;
    1005       80312 :                     nTgtFreeByteBits = nTgtFreeByteBits - nDataBits;
    1006             :                 }
    1007             :             }
    1008             :         }
    1009             : 
    1010             :         // should the situation arise, switch Black <-> White:
    1011      188884 :         if (bTerminatingCode) nBlackOrWhite = ~nBlackOrWhite;
    1012             : 
    1013        3248 :     } while (nTargetBits>0 || !bTerminatingCode);
    1014             : }
    1015             : 
    1016             : 
    1017             : 
    1018           0 : void CCIDecompressor::Read2DScanlineData(sal_uInt8 * pTarget, sal_uInt16 nTargetBits)
    1019             : {
    1020             :     sal_uInt16 n2DMode,nBitPos,nUncomp,nRun,nRun2,nt;
    1021             :     sal_uInt8 nBlackOrWhite;
    1022             : 
    1023           0 :     nBlackOrWhite=0x00;
    1024           0 :     nBitPos=0;
    1025             : 
    1026           0 :     while (nBitPos<nTargetBits && bStatus) {
    1027             : 
    1028           0 :         n2DMode=ReadCodeAndDecode(p2DModeLookUp,10);
    1029           0 :         if (!bStatus) return;
    1030             : 
    1031           0 :         if (n2DMode==CCI2DMODE_UNCOMP) {
    1032             :             for (;;) {
    1033           0 :                 nUncomp=ReadCodeAndDecode(pUncompLookUp,11);
    1034           0 :                 if ( nUncomp <= CCIUNCOMP_4White_1Black ) {
    1035           0 :                     nRun=nUncomp-CCIUNCOMP_0White_1Black;
    1036           0 :                     FillBits(pTarget,nTargetBits,nBitPos,nRun,0x00);
    1037           0 :                     nBitPos = nBitPos + nRun;
    1038           0 :                     FillBits(pTarget,nTargetBits,nBitPos,1,0xff);
    1039           0 :                     nBitPos++;
    1040             :                 }
    1041           0 :                 else if ( nUncomp == CCIUNCOMP_5White ) {
    1042           0 :                     FillBits(pTarget,nTargetBits,nBitPos,5,0x00);
    1043           0 :                     nBitPos = nBitPos + 5;
    1044             :                 }
    1045             :                 else {
    1046           0 :                     nRun=nUncomp-CCIUNCOMP_0White_End;
    1047           0 :                     FillBits(pTarget,nTargetBits,nBitPos,nRun,0x00);
    1048           0 :                     nBitPos = nBitPos + nRun;
    1049           0 :                     nBlackOrWhite=ReadBlackOrWhite();
    1050           0 :                     break;
    1051             :                 }
    1052             :             }
    1053             :         }
    1054             : 
    1055           0 :         else if (n2DMode==CCI2DMODE_PASS) {
    1056           0 :             if (nBitPos==0 && nBlackOrWhite==0x00 && CountBits(pLastLine,nTargetBits,0,0xff)!=0) nRun=0;
    1057             :             else {
    1058           0 :                 nRun=CountBits(pLastLine,nTargetBits,nBitPos,~nBlackOrWhite);
    1059           0 :                 nRun = nRun + CountBits(pLastLine,nTargetBits,nBitPos+nRun,nBlackOrWhite);
    1060             :             }
    1061           0 :             nRun = nRun + CountBits(pLastLine,nTargetBits,nBitPos+nRun,~nBlackOrWhite);
    1062           0 :             FillBits(pTarget,nTargetBits,nBitPos,nRun,nBlackOrWhite);
    1063           0 :             nBitPos = nBitPos + nRun;
    1064             :         }
    1065             : 
    1066           0 :         else if (n2DMode==CCI2DMODE_HORZ) {
    1067           0 :             if (nBlackOrWhite==0x00) {
    1068           0 :                 nRun=0;
    1069           0 :                 do {
    1070           0 :                     nt=ReadCodeAndDecode(pWhiteLookUp,13);
    1071           0 :                     nRun = nRun + nt;
    1072             :                 } while (nt>=64);
    1073           0 :                 nRun2=0;
    1074           0 :                 do {
    1075           0 :                     nt=ReadCodeAndDecode(pBlackLookUp,13);
    1076           0 :                     nRun2 = nRun2 + nt;
    1077             :                 } while (nt>=64);
    1078             :             }
    1079             :             else {
    1080           0 :                 nRun=0;
    1081           0 :                 do {
    1082           0 :                     nt=ReadCodeAndDecode(pBlackLookUp,13);
    1083           0 :                     nRun = nRun + nt;
    1084             :                 } while (nt>=64);
    1085           0 :                 nRun2=0;
    1086           0 :                 do {
    1087           0 :                     nt=ReadCodeAndDecode(pWhiteLookUp,13);
    1088           0 :                     nRun2 = nRun2 + nt;
    1089             :                 } while (nt>=64);
    1090             :             }
    1091           0 :             FillBits(pTarget,nTargetBits,nBitPos,nRun,nBlackOrWhite);
    1092           0 :             nBitPos = nBitPos + nRun;
    1093           0 :             FillBits(pTarget,nTargetBits,nBitPos,nRun2,~nBlackOrWhite);
    1094           0 :             nBitPos = nBitPos + nRun2;
    1095             :         }
    1096             : 
    1097             :         else { // it's one of the modes CCI2DMODE_VERT_...
    1098           0 :             if (nBitPos==0 && nBlackOrWhite==0x00 && CountBits(pLastLine,nTargetBits,0,0xff)!=0) nRun=0;
    1099             :             else {
    1100           0 :                 nRun=CountBits(pLastLine,nTargetBits,nBitPos,~nBlackOrWhite);
    1101           0 :                 nRun = nRun + CountBits(pLastLine,nTargetBits,nBitPos+nRun,nBlackOrWhite);
    1102             :             }
    1103           0 :             nRun+=n2DMode-CCI2DMODE_VERT_0;
    1104           0 :             FillBits(pTarget,nTargetBits,nBitPos,nRun,nBlackOrWhite);
    1105           0 :             nBitPos = nBitPos + nRun;
    1106           0 :             nBlackOrWhite=~nBlackOrWhite;
    1107             :         }
    1108             :     }
    1109             : }
    1110             : 
    1111             : 
    1112             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11