This file is indexed.

/usr/include/podofo/base/PdfFiltersPrivate.h is in libpodofo-dev 0.9.4-6.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
/***************************************************************************
 *   Copyright (C) 2007 by Dominik Seichter                                *
 *   domseichter@web.de                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 *                                                                         *
 *   In addition, as a special exception, the copyright holders give       *
 *   permission to link the code of portions of this program with the      *
 *   OpenSSL library under certain conditions as described in each         *
 *   individual source file, and distribute linked combinations            *
 *   including the two.                                                    *
 *   You must obey the GNU General Public License in all respects          *
 *   for all of the code used other than OpenSSL.  If you modify           *
 *   file(s) with this exception, you may extend this exception to your    *
 *   version of the file(s), but you are not obligated to do so.  If you   *
 *   do not wish to do so, delete this exception statement from your       *
 *   version.  If you delete this exception statement from all source      *
 *   files in the program, then also delete it here.                       *
 ***************************************************************************/

#ifndef _PDF_FILTERS_PRIVATE_H_
#define _PDF_FILTERS_PRIVATE_H_

/**
 * \file PdfFiltersPrivate.h
 *
 * Provides implementations of various PDF stream filters.
 *
 * This is an internal header. It should not be included in podofo.h, and
 * should not be included directly by client applications. These filters should
 * only be accessed through the factory interface in PdfFilters.h .
 */

#include "PdfDefines.h"
#include "PdfDefinesPrivate.h"
#include "PdfFilter.h"
#include "PdfRefCountedBuffer.h"

#include <zlib.h>

#ifdef PODOFO_HAVE_JPEG_LIB
extern "C" {
#ifdef _WIN32		// Collision between win and jpeg-headers
#define XMD_H
#undef FAR
#endif
#include "jpeglib.h"
}
#endif // PODOFO_HAVE_JPEG_LIB

#ifdef PODOFO_HAVE_TIFF_LIB
extern "C" {
#include "tiffio.h"
#ifdef _WIN32		// Collision between tiff and jpeg-headers
#define XMD_H
#undef FAR
#endif
}
#endif // PODOFO_HAVE_TIFF_LIB


namespace PoDoFo {

#define PODOFO_FILTER_INTERNAL_BUFFER_SIZE 4096

class PdfPredictorDecoder;
class PdfOutputDevice;

/** The ascii hex filter.
 */
class PdfHexFilter : public PdfFilter {
 public:
    virtual ~PdfHexFilter() { }

    /** Check wether the encoding is implemented for this filter.
     * 
     *  \returns true if the filter is able to encode data
     */
    inline virtual bool CanEncode() const; 

    /** Encode a block of data and write it to the PdfOutputStream
     *  specified by BeginEncodeImpl.
     *
     *  BeginEncodeImpl() has to be called before this function.
     *
     *  \param pBuffer pointer to a buffer with data to encode
     *  \param lLen length of data to encode.
     *
     *  Call EndEncodeImpl() after all data has been encoded
     *
     *
     *  \see BeginEncodeImpl
     *  \see EndEncodeImpl
     */
    virtual void EncodeBlockImpl( const char* pBuffer, pdf_long lLen );

    /** Check wether the decoding is implemented for this filter.
     * 
     *  \returns true if the filter is able to decode data
     */
    inline virtual bool CanDecode() const; 

    /** Real implementation of `BeginDecode()'. NEVER call this method directly.
     *
     *  By default this function does nothing. If your filter needs to do setup for decoding,
     *  you should override this method.
     *
     *  PdfFilter ensures that a valid stream is available when this method is called, and
     *  that EndDecode() was called since the last BeginDecode()/DecodeBlock().
     *
     * \see BeginDecode */
    virtual void BeginDecodeImpl( const PdfDictionary* );

    /** Real implementation of `DecodeBlock()'. NEVER call this method directly.
     *
     *  You must override this method to decode the buffer passed by the caller.
     *
     *  You are not obliged to immediately process any or all of the data in
     *  the passed buffer, but you must ensure that you have processed it and
     *  written it out by the end of EndDecodeImpl(). You must copy the buffer
     *  if you're going to store it, as ownership is not transferred to the
     *  filter and the caller may free the buffer at any time.
     *
     *  PdfFilter ensures that a valid stream is available when this method is
     *  called, ensures that BeginDecode() has been called, and ensures that
     *  EndDecode() has not been called since the last BeginDecode().
     *
     * \see DecodeBlock */
    virtual void DecodeBlockImpl( const char* pBuffer, pdf_long lLen );

    /** Real implementation of `EndDecode()'. NEVER call this method directly.
     *
     * By the time this method returns, all filtered data must be written to the stream
     * and the filter must be in a state where BeginDecode() can be safely called.
     *
     *  PdfFilter ensures that a valid stream is available when this method is
     *  called, and ensures that BeginDecodeImpl() has been called.
     *
     * \see EndDecode */
    virtual void EndDecodeImpl();

    /** GetType of this filter.
     *  \returns the GetType of this filter
     */
    inline virtual EPdfFilter GetType() const;

 private:
    char m_cDecodedByte;
    bool m_bLow;
};

// -----------------------------------------------------
// 
// -----------------------------------------------------
bool PdfHexFilter::CanEncode() const
{
    return true;
}

// -----------------------------------------------------
// 
// -----------------------------------------------------
bool PdfHexFilter::CanDecode() const
{
    return true;
}

// -----------------------------------------------------
// 
// -----------------------------------------------------
EPdfFilter PdfHexFilter::GetType() const
{
    return ePdfFilter_ASCIIHexDecode;
}

/** The Ascii85 filter.
 */
class PdfAscii85Filter : public PdfFilter {
 public:
    virtual ~PdfAscii85Filter() { }

    /** Check wether the encoding is implemented for this filter.
     * 
     *  \returns true if the filter is able to encode data
     */
    inline virtual bool CanEncode() const; 

    /** Begin encoding data using this filter. Called by PdfFilter::BeginEncode.
     *
     *  \see EncodeBlockImpl
     *  \see EndEncodeImpl
     *  \see PdfFilter::BeginEncode
     */
    virtual void BeginEncodeImpl();

    /** Encode a block of data and write it to the PdfOutputStream
     *  specified by BeginEncodeImpl.
     *
     *  BeginEncodeImpl() has to be called before this function.
     *
     *  \param pBuffer pointer to a buffer with data to encode
     *  \param lLen length of data to encode.
     *
     *  Call EndEncodeImpl() after all data has been encoded
     *
     *
     *  \see BeginEncodeImpl
     *  \see EndEncodeImpl
     */
    virtual void EncodeBlockImpl( const char* pBuffer, pdf_long lLen );

    /**
     *  Finish encoding of data.
     *
     *  \see BeginEncodeImpl
     *  \see EncodeBlockImpl
     */
    virtual void EndEncodeImpl();

    /** Check wether the decoding is implemented for this filter.
     * 
     *  \returns true if the filter is able to decode data
     */
    inline virtual bool CanDecode() const; 

    /** Real implementation of `BeginDecode()'. NEVER call this method directly.
     *
     *  By default this function does nothing. If your filter needs to do setup for decoding,
     *  you should override this method.
     *
     *  PdfFilter ensures that a valid stream is available when this method is called, and
     *  that EndDecode() was called since the last BeginDecode()/DecodeBlock().
     *
     * \see BeginDecode */
    virtual void BeginDecodeImpl( const PdfDictionary* );

    /** Real implementation of `DecodeBlock()'. NEVER call this method directly.
     *
     *  You must override this method to decode the buffer passed by the caller.
     *
     *  You are not obliged to immediately process any or all of the data in
     *  the passed buffer, but you must ensure that you have processed it and
     *  written it out by the end of EndDecodeImpl(). You must copy the buffer
     *  if you're going to store it, as ownership is not transferred to the
     *  filter and the caller may free the buffer at any time.
     *
     *  PdfFilter ensures that a valid stream is available when this method is
     *  called, ensures that BeginDecode() has been called, and ensures that
     *  EndDecode() has not been called since the last BeginDecode().
     *
     * \see DecodeBlock */
    virtual void DecodeBlockImpl( const char* pBuffer, pdf_long lLen );

    /** Real implementation of `EndDecode()'. NEVER call this method directly.
     *
     * By the time this method returns, all filtered data must be written to the stream
     * and the filter must be in a state where BeginDecode() can be safely called.
     *
     *  PdfFilter ensures that a valid stream is available when this method is
     *  called, and ensures that BeginDecodeImpl() has been called.
     *
     * \see EndDecode */
    virtual void EndDecodeImpl();

    /** GetType of this filter.
     *  \returns the GetType of this filter
     */
    inline virtual EPdfFilter GetType() const;

 private:
    void EncodeTuple ( unsigned long tuple, int bytes );
    void WidePut( unsigned long tuple, int bytes ) const;

 private:
    int           m_count;
    unsigned long m_tuple;
};

// -----------------------------------------------------
// 
// -----------------------------------------------------
bool PdfAscii85Filter::CanEncode() const
{
    return true;
}

// -----------------------------------------------------
// 
// -----------------------------------------------------
bool PdfAscii85Filter::CanDecode() const
{
    return true;
}

// -----------------------------------------------------
// 
// -----------------------------------------------------
EPdfFilter PdfAscii85Filter::GetType() const
{
    return ePdfFilter_ASCII85Decode;
}

/** The flate filter.
 */
class PdfFlateFilter : public PdfFilter {
 public:
    PdfFlateFilter();
    virtual ~PdfFlateFilter();

    /** Check wether the encoding is implemented for this filter.
     * 
     *  \returns true if the filter is able to encode data
     */
    inline virtual bool CanEncode() const; 

    /** Begin encoding data using this filter. Called by PdfFilter::BeginEncode.
     *
     *  \see EncodeBlockImpl
     *  \see EndEncodeImpl
     *  \see PdfFilter::BeginEncode
     */
    virtual void BeginEncodeImpl();

    /** Encode a block of data and write it to the PdfOutputStream
     *  specified by BeginEncodeImpl.
     *
     *  BeginEncodeImpl() has to be called before this function.
     *
     *  \param pBuffer pointer to a buffer with data to encode
     *  \param lLen length of data to encode.
     *
     *  Call EndEncodeImpl() after all data has been encoded
     *
     *
     *  \see BeginEncodeImpl
     *  \see EndEncodeImpl
     */
    virtual void EncodeBlockImpl( const char* pBuffer, pdf_long lLen );

    /**
     *  Finish encoding of data.
     *
     *  \see BeginEncodeImpl
     *  \see EncodeBlockImpl
     */
    virtual void EndEncodeImpl();

    /** Check wether the decoding is implemented for this filter.
     * 
     *  \returns true if the filter is able to decode data
     */
    inline virtual bool CanDecode() const; 

    /** Real implementation of `BeginDecode()'. NEVER call this method directly.
     *
     *  By default this function does nothing. If your filter needs to do setup for decoding,
     *  you should override this method.
     *
     *  PdfFilter ensures that a valid stream is available when this method is called, and
     *  that EndDecode() was called since the last BeginDecode()/DecodeBlock().
     *
     *  \param pDecodeParms additional parameters for decoding data
     *
     * \see BeginDecode 
     */
    virtual void BeginDecodeImpl( const PdfDictionary* pDecodeParms );

    /** Real implementation of `DecodeBlock()'. NEVER call this method directly.
     *
     *  You must override this method to decode the buffer passed by the caller.
     *
     *  You are not obliged to immediately process any or all of the data in
     *  the passed buffer, but you must ensure that you have processed it and
     *  written it out by the end of EndDecodeImpl(). You must copy the buffer
     *  if you're going to store it, as ownership is not transferred to the
     *  filter and the caller may free the buffer at any time.
     *
     *  PdfFilter ensures that a valid stream is available when this method is
     *  called, ensures that BeginDecode() has been called, and ensures that
     *  EndDecode() has not been called since the last BeginDecode().
     *
     * \see DecodeBlock */
    virtual void DecodeBlockImpl( const char* pBuffer, pdf_long lLen );

    /** Real implementation of `EndDecode()'. NEVER call this method directly.
     *
     * By the time this method returns, all filtered data must be written to the stream
     * and the filter must be in a state where BeginDecode() can be safely called.
     *
     *  PdfFilter ensures that a valid stream is available when this method is
     *  called, and ensures that BeginDecodeImpl() has been called.
     *
     * \see EndDecode */
    virtual void EndDecodeImpl();

    /** GetType of this filter.
     *  \returns the GetType of this filter
     */
    inline virtual EPdfFilter GetType() const;

 private:
    void EncodeBlockInternal( const char* pBuffer, pdf_long lLen, int nMode );

 private:
    unsigned char        m_buffer[PODOFO_FILTER_INTERNAL_BUFFER_SIZE];

    z_stream             m_stream;
    PdfPredictorDecoder* m_pPredictor;
};

// -----------------------------------------------------
// 
// -----------------------------------------------------
bool PdfFlateFilter::CanEncode() const
{
    return true;
}

// -----------------------------------------------------
// 
// -----------------------------------------------------
bool PdfFlateFilter::CanDecode() const
{
    return true;
}

// -----------------------------------------------------
// 
// -----------------------------------------------------
EPdfFilter PdfFlateFilter::GetType() const
{
    return ePdfFilter_FlateDecode;
}


/** The RLE filter.
 */
class PdfRLEFilter : public PdfFilter {
 public:
    virtual ~PdfRLEFilter() {}

    /** Check wether the encoding is implemented for this filter.
     * 
     *  \returns true if the filter is able to encode data
     */
    inline virtual bool CanEncode() const; 

    virtual void BeginEncodeImpl();

    /** Encode a block of data and write it to the PdfOutputStream
     *  specified by BeginEncodeImpl.
     *
     *  BeginEncodeImpl() has to be called before this function.
     *
     *  \param pBuffer pointer to a buffer with data to encode
     *  \param lLen length of data to encode.
     *
     *  Call EndEncodeImpl() after all data has been encoded
     *
     *
     *  \see BeginEncodeImpl
     *  \see EndEncodeImpl
     */
    virtual void EncodeBlockImpl( const char* pBuffer, pdf_long lLen );

    /**
     *  Finish encoding of data.
     *
     *  \see BeginEncodeImpl
     *  \see EncodeBlockImpl
     */
    virtual void EndEncodeImpl();

    /** Check wether the decoding is implemented for this filter.
     * 
     *  \returns true if the filter is able to decode data
     */
    inline virtual bool CanDecode() const; 

    /** Real implementation of `BeginDecode()'. NEVER call this method directly.
     *
     *  By default this function does nothing. If your filter needs to do setup for decoding,
     *  you should override this method.
     *
     *  PdfFilter ensures that a valid stream is available when this method is called, and
     *  that EndDecode() was called since the last BeginDecode()/DecodeBlock().
     *
     * \see BeginDecode */
    virtual void BeginDecodeImpl( const PdfDictionary* );

    /** Real implementation of `DecodeBlock()'. NEVER call this method directly.
     *
     *  You must override this method to decode the buffer passed by the caller.
     *
     *  You are not obliged to immediately process any or all of the data in
     *  the passed buffer, but you must ensure that you have processed it and
     *  written it out by the end of EndDecodeImpl(). You must copy the buffer
     *  if you're going to store it, as ownership is not transferred to the
     *  filter and the caller may free the buffer at any time.
     *
     *  PdfFilter ensures that a valid stream is available when this method is
     *  called, ensures that BeginDecode() has been called, and ensures that
     *  EndDecode() has not been called since the last BeginDecode().
     *
     * \see DecodeBlock */
    virtual void DecodeBlockImpl( const char* pBuffer, pdf_long lLen );

    /** GetType of this filter.
     *  \returns the GetType of this filter
     */
    inline virtual EPdfFilter GetType() const;

 private:
    int m_nCodeLen;
};

// -----------------------------------------------------
// 
// -----------------------------------------------------
bool PdfRLEFilter::CanEncode() const
{
    return false;
}

// -----------------------------------------------------
// 
// -----------------------------------------------------
bool PdfRLEFilter::CanDecode() const
{
    return true;
}

// -----------------------------------------------------
// 
// -----------------------------------------------------
EPdfFilter PdfRLEFilter::GetType() const
{
    return ePdfFilter_RunLengthDecode;
}

/** The LZW filter.
 */
class PdfLZWFilter : public PdfFilter {
    struct TLzwItem {
        std::vector<unsigned char> value;
    };
    
    typedef std::vector<TLzwItem>     TLzwTable;
    typedef TLzwTable::iterator       TILzwTable;
    typedef TLzwTable::const_iterator TCILzwTable;

 public:
    PdfLZWFilter();

    virtual ~PdfLZWFilter();

    /** Check wether the encoding is implemented for this filter.
     * 
     *  \returns true if the filter is able to encode data
     */
    inline virtual bool CanEncode() const; 

    /** Begin encoding data using this filter. Called by PdfFilter::BeginEncode.
     *
     *  \see EncodeBlockImpl
     *  \see EndEncodeImpl
     *  \see PdfFilter::BeginEncode
     */
    virtual void BeginEncodeImpl();

    /** Encode a block of data and write it to the PdfOutputStream
     *  specified by BeginEncodeImpl.
     *
     *  BeginEncodeImpl() has to be called before this function.
     *
     *  \param pBuffer pointer to a buffer with data to encode
     *  \param lLen length of data to encode.
     *
     *  Call EndEncodeImpl() after all data has been encoded
     *
     *
     *  \see BeginEncodeImpl
     *  \see EndEncodeImpl
     */
    virtual void EncodeBlockImpl( const char* pBuffer, pdf_long lLen );

    /**
     *  Finish encoding of data.
     *
     *  \see BeginEncodeImpl
     *  \see EncodeBlockImpl
     */
    virtual void EndEncodeImpl();

    /** Check wether the decoding is implemented for this filter.
     * 
     *  \returns true if the filter is able to decode data
     */
    inline virtual bool CanDecode() const; 

    /** Real implementation of `BeginDecode()'. NEVER call this method directly.
     *
     *  By default this function does nothing. If your filter needs to do setup for decoding,
     *  you should override this method.
     *
     *  PdfFilter ensures that a valid stream is available when this method is called, and
     *  that EndDecode() was called since the last BeginDecode()/DecodeBlock().
     *
     * \see BeginDecode */
    virtual void BeginDecodeImpl( const PdfDictionary* );

    /** Real implementation of `DecodeBlock()'. NEVER call this method directly.
     *
     *  You must override this method to decode the buffer passed by the caller.
     *
     *  You are not obliged to immediately process any or all of the data in
     *  the passed buffer, but you must ensure that you have processed it and
     *  written it out by the end of EndDecodeImpl(). You must copy the buffer
     *  if you're going to store it, as ownership is not transferred to the
     *  filter and the caller may free the buffer at any time.
     *
     *  PdfFilter ensures that a valid stream is available when this method is
     *  called, ensures that BeginDecode() has been called, and ensures that
     *  EndDecode() has not been called since the last BeginDecode().
     *
     * \see DecodeBlock */
    virtual void DecodeBlockImpl( const char* pBuffer, pdf_long lLen );

    /** Real implementation of `EndDecode()'. NEVER call this method directly.
     *
     * By the time this method returns, all filtered data must be written to the stream
     * and the filter must be in a state where BeginDecode() can be safely called.
     *
     *  PdfFilter ensures that a valid stream is available when this method is
     *  called, and ensures that BeginDecodeImpl() has been called.
     *
     * \see EndDecode */
    virtual void EndDecodeImpl();

    /** GetType of this filter.
     *  \returns the GetType of this filter
     */
    inline virtual EPdfFilter GetType() const;

 private:
    /** Initialize an lzw table.
     */
    void InitTable();

 private:
    static const unsigned short s_masks[4];
    static const unsigned short s_clear;
    static const unsigned short s_eod;

    TLzwTable     m_table;

    unsigned int  m_mask;
    unsigned int  m_code_len;
    unsigned char m_character;

    bool          m_bFirst;

    PdfPredictorDecoder* m_pPredictor;
};

// -----------------------------------------------------
// 
// -----------------------------------------------------
bool PdfLZWFilter::CanEncode() const
{
    return false;
}

// -----------------------------------------------------
// 
// -----------------------------------------------------
bool PdfLZWFilter::CanDecode() const
{
    return true;
}

// -----------------------------------------------------
// 
// -----------------------------------------------------
EPdfFilter PdfLZWFilter::GetType() const
{
    return ePdfFilter_LZWDecode;
}


#ifdef PODOFO_HAVE_JPEG_LIB

void PODOFO_API jpeg_memory_src (j_decompress_ptr cinfo, const JOCTET * buffer, size_t bufsize);

extern "C" {
void JPegErrorExit(j_common_ptr cinfo);

void JPegErrorOutput(j_common_ptr, int);
};

/** The DCT filter can decoded JPEG compressed data.
 *  
 *  This filter requires JPEG lib to be available
 */
class PdfDCTFilter : public PdfFilter {
 public:
    PdfDCTFilter();

    virtual ~PdfDCTFilter();

    /** Check wether the encoding is implemented for this filter.
     * 
     *  \returns true if the filter is able to encode data
     */
    inline virtual bool CanEncode() const; 

    /** Begin encoding data using this filter. Called by PdfFilter::BeginEncode.
     *
     *  \see EncodeBlockImpl
     *  \see EndEncodeImpl
     *  \see PdfFilter::BeginEncode
     */
    virtual void BeginEncodeImpl();

    /** Encode a block of data and write it to the PdfOutputStream
     *  specified by BeginEncodeImpl.
     *
     *  BeginEncodeImpl() has to be called before this function.
     *
     *  \param pBuffer pointer to a buffer with data to encode
     *  \param lLen length of data to encode.
     *
     *  Call EndEncodeImpl() after all data has been encoded
     *
     *
     *  \see BeginEncodeImpl
     *  \see EndEncodeImpl
     */
    virtual void EncodeBlockImpl( const char* pBuffer, pdf_long lLen );

    /**
     *  Finish encoding of data.
     *
     *  \see BeginEncodeImpl
     *  \see EncodeBlockImpl
     */
    virtual void EndEncodeImpl();

    /** Check wether the decoding is implemented for this filter.
     * 
     *  \returns true if the filter is able to decode data
     */
    inline virtual bool CanDecode() const; 

    /** Real implementation of `BeginDecode()'. NEVER call this method directly.
     *
     *  By default this function does nothing. If your filter needs to do setup for decoding,
     *  you should override this method.
     *
     *  PdfFilter ensures that a valid stream is available when this method is called, and
     *  that EndDecode() was called since the last BeginDecode()/DecodeBlock().
     *
     * \see BeginDecode */
    virtual void BeginDecodeImpl( const PdfDictionary* );

    /** Real implementation of `DecodeBlock()'. NEVER call this method directly.
     *
     *  You must override this method to decode the buffer passed by the caller.
     *
     *  You are not obliged to immediately process any or all of the data in
     *  the passed buffer, but you must ensure that you have processed it and
     *  written it out by the end of EndDecodeImpl(). You must copy the buffer
     *  if you're going to store it, as ownership is not transferred to the
     *  filter and the caller may free the buffer at any time.
     *
     *  PdfFilter ensures that a valid stream is available when this method is
     *  called, ensures that BeginDecode() has been called, and ensures that
     *  EndDecode() has not been called since the last BeginDecode().
     *
     * \see DecodeBlock */
    virtual void DecodeBlockImpl( const char* pBuffer, pdf_long lLen );

    /** Real implementation of `EndDecode()'. NEVER call this method directly.
     *
     * By the time this method returns, all filtered data must be written to the stream
     * and the filter must be in a state where BeginDecode() can be safely called.
     *
     *  PdfFilter ensures that a valid stream is available when this method is
     *  called, and ensures that BeginDecodeImpl() has been called.
     *
     * \see EndDecode */
    virtual void EndDecodeImpl();

    /** GetType of this filter.
     *  \returns the GetType of this filter
     */
    inline virtual EPdfFilter GetType() const;

 private:
    struct jpeg_decompress_struct m_cinfo;
    struct jpeg_error_mgr         m_jerr;

    PdfRefCountedBuffer           m_buffer;
    PdfOutputDevice*              m_pDevice;
};

// -----------------------------------------------------
// 
// -----------------------------------------------------
bool PdfDCTFilter::CanEncode() const
{
    return false;
}

// -----------------------------------------------------
// 
// -----------------------------------------------------
bool PdfDCTFilter::CanDecode() const
{
    return true;
}

// -----------------------------------------------------
// 
// -----------------------------------------------------
EPdfFilter PdfDCTFilter::GetType() const
{
    return ePdfFilter_DCTDecode;
}
#endif // PODOFO_HAVE_JPEG_LIB

#ifdef PODOFO_HAVE_TIFF_LIB

/** The CCITT filter can decoded CCITTFaxDecode compressed data.
 *  
 *  This filter requires TIFFlib to be available
 */
class PdfCCITTFilter : public PdfFilter {
 public:
    PdfCCITTFilter();

    virtual ~PdfCCITTFilter();

    /** Check wether the encoding is implemented for this filter.
     * 
     *  \returns true if the filter is able to encode data
     */
    inline virtual bool CanEncode() const; 

    /** Begin encoding data using this filter. Called by PdfFilter::BeginEncode.
     *
     *  \see EncodeBlockImpl
     *  \see EndEncodeImpl
     *  \see PdfFilter::BeginEncode
     */
    virtual void BeginEncodeImpl();

    /** Encode a block of data and write it to the PdfOutputStream
     *  specified by BeginEncodeImpl.
     *
     *  BeginEncodeImpl() has to be called before this function.
     *
     *  \param pBuffer pointer to a buffer with data to encode
     *  \param lLen length of data to encode.
     *
     *  Call EndEncodeImpl() after all data has been encoded
     *
     *
     *  \see BeginEncodeImpl
     *  \see EndEncodeImpl
     */
    virtual void EncodeBlockImpl( const char* pBuffer, pdf_long lLen );

    /**
     *  Finish encoding of data.
     *
     *  \see BeginEncodeImpl
     *  \see EncodeBlockImpl
     */
    virtual void EndEncodeImpl();

    /** Check wether the decoding is implemented for this filter.
     * 
     *  \returns true if the filter is able to decode data
     */
    inline virtual bool CanDecode() const; 

    /** Real implementation of `BeginDecode()'. NEVER call this method directly.
     *
     *  By default this function does nothing. If your filter needs to do setup for decoding,
     *  you should override this method.
     *
     *  PdfFilter ensures that a valid stream is available when this method is called, and
     *  that EndDecode() was called since the last BeginDecode()/DecodeBlock().
     *
     * \see BeginDecode */
    virtual void BeginDecodeImpl( const PdfDictionary* );

    /** Real implementation of `DecodeBlock()'. NEVER call this method directly.
     *
     *  You must override this method to decode the buffer passed by the caller.
     *
     *  You are not obliged to immediately process any or all of the data in
     *  the passed buffer, but you must ensure that you have processed it and
     *  written it out by the end of EndDecodeImpl(). You must copy the buffer
     *  if you're going to store it, as ownership is not transferred to the
     *  filter and the caller may free the buffer at any time.
     *
     *  PdfFilter ensures that a valid stream is available when this method is
     *  called, ensures that BeginDecode() has been called, and ensures that
     *  EndDecode() has not been called since the last BeginDecode().
     *
     * \see DecodeBlock */
    virtual void DecodeBlockImpl( const char* pBuffer, pdf_long lLen );

    /** Real implementation of `EndDecode()'. NEVER call this method directly.
     *
     * By the time this method returns, all filtered data must be written to the stream
     * and the filter must be in a state where BeginDecode() can be safely called.
     *
     *  PdfFilter ensures that a valid stream is available when this method is
     *  called, and ensures that BeginDecodeImpl() has been called.
     *
     * \see EndDecode */
    virtual void EndDecodeImpl();

    /** GetType of this filter.
     *  \returns the GetType of this filter
     */
    inline virtual EPdfFilter GetType() const;

 private:
    TIFF* m_tiff;
};

// -----------------------------------------------------
// 
// -----------------------------------------------------
bool PdfCCITTFilter::CanEncode() const
{
    return false;
}

// -----------------------------------------------------
// 
// -----------------------------------------------------
bool PdfCCITTFilter::CanDecode() const
{
    return true;
}

// -----------------------------------------------------
// 
// -----------------------------------------------------
EPdfFilter PdfCCITTFilter::GetType() const
{
    return ePdfFilter_CCITTFaxDecode;
}
#endif // PODOFO_HAVE_TIFF_LIB

};


#endif /* _PDF_FILTERS_PRIVATE_H_ */