OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "../../../include/fpdfapi/fpdf_parser.h" | 7 #include "../../../include/fpdfapi/fpdf_parser.h" |
8 #include "../../../include/fxcodec/fx_codec.h" | 8 #include "../../../include/fxcodec/fx_codec.h" |
9 #include "../../../include/fxcodec/fx_codec_flate.h" | 9 #include "../../../include/fxcodec/fx_codec_flate.h" |
10 #include "../../../include/fpdfapi/fpdf_module.h" | 10 #include "../../../include/fpdfapi/fpdf_module.h" |
11 #include "filters_int.h" | 11 #include "filters_int.h" |
12 | 12 |
13 extern "C" { | 13 extern "C" { |
14 | 14 |
15 static void* my_alloc_func(void* opaque, unsigned int items, unsigned int size) | 15 static void* my_alloc_func(void* opaque, unsigned int items, unsigned int size) |
16 { | 16 { |
17 return FX_Alloc2D(uint8_t, items, size); | 17 return FX_Alloc2D(uint8_t, items, size); |
18 } | 18 } |
19 static void my_free_func(void* opaque, void* address) | 19 static void my_free_func(void* opaque, void* address) |
20 { | 20 { |
21 FX_Free(address); | 21 FX_Free(address); |
22 } | 22 } |
23 | 23 |
24 } // extern "C" | 24 } // extern "C" |
25 | 25 |
26 CFX_DataFilter::CFX_DataFilter() | 26 CFX_DataFilter::CFX_DataFilter() |
27 { | 27 { |
28 m_bEOF = FALSE; | 28 m_bEOF = false; |
29 m_pDestFilter = NULL; | 29 m_pDestFilter = NULL; |
30 m_SrcPos = 0; | 30 m_SrcPos = 0; |
31 } | 31 } |
32 CFX_DataFilter::~CFX_DataFilter() | 32 CFX_DataFilter::~CFX_DataFilter() |
33 { | 33 { |
34 delete m_pDestFilter; | 34 delete m_pDestFilter; |
35 } | 35 } |
36 void CFX_DataFilter::SetDestFilter(CFX_DataFilter* pFilter) | 36 void CFX_DataFilter::SetDestFilter(CFX_DataFilter* pFilter) |
37 { | 37 { |
38 if (m_pDestFilter) { | 38 if (m_pDestFilter) { |
(...skipping 22 matching lines...) Expand all Loading... |
61 if (m_pDestFilter) { | 61 if (m_pDestFilter) { |
62 CFX_BinaryBuf temp_buf; | 62 CFX_BinaryBuf temp_buf; |
63 v_FilterFinish(temp_buf); | 63 v_FilterFinish(temp_buf); |
64 if (temp_buf.GetSize()) { | 64 if (temp_buf.GetSize()) { |
65 m_pDestFilter->FilterIn(temp_buf.GetBuffer(), temp_buf.GetSize(), de
st_buf); | 65 m_pDestFilter->FilterIn(temp_buf.GetBuffer(), temp_buf.GetSize(), de
st_buf); |
66 } | 66 } |
67 m_pDestFilter->FilterFinish(dest_buf); | 67 m_pDestFilter->FilterFinish(dest_buf); |
68 } else { | 68 } else { |
69 v_FilterFinish(dest_buf); | 69 v_FilterFinish(dest_buf); |
70 } | 70 } |
71 m_bEOF = TRUE; | 71 m_bEOF = true; |
72 } | 72 } |
73 void CFX_DataFilter::ReportEOF(FX_DWORD left_input) | 73 void CFX_DataFilter::ReportEOF(FX_DWORD left_input) |
74 { | 74 { |
75 if (m_bEOF) { | 75 if (m_bEOF) { |
76 return; | 76 return; |
77 } | 77 } |
78 m_bEOF = TRUE; | 78 m_bEOF = true; |
79 m_SrcPos -= left_input; | 79 m_SrcPos -= left_input; |
80 } | 80 } |
81 CFX_DataFilter* FPDF_CreateFilter(const CFX_ByteStringC& name, const CPDF_Dictio
nary* pParam, int width, int height) | 81 CFX_DataFilter* FPDF_CreateFilter(const CFX_ByteStringC& name, const CPDF_Dictio
nary* pParam, int width, int height) |
82 { | 82 { |
83 FX_DWORD id = name.GetID(); | 83 FX_DWORD id = name.GetID(); |
84 switch (id) { | 84 switch (id) { |
85 case FXBSTR_ID('F', 'l', 'a', 't'): | 85 case FXBSTR_ID('F', 'l', 'a', 't'): |
86 case FXBSTR_ID('F', 'l', 0, 0): | 86 case FXBSTR_ID('F', 'l', 0, 0): |
87 case FXBSTR_ID('L', 'Z', 'W', 'D'): | 87 case FXBSTR_ID('L', 'Z', 'W', 'D'): |
88 case FXBSTR_ID('L', 'Z', 'W', 0): { | 88 case FXBSTR_ID('L', 'Z', 'W', 0): { |
(...skipping 17 matching lines...) Expand all Loading... |
106 } | 106 } |
107 return new CPDF_Ascii85Filter; | 107 return new CPDF_Ascii85Filter; |
108 case FXBSTR_ID('A', 'H', 'x', 0): | 108 case FXBSTR_ID('A', 'H', 'x', 0): |
109 return new CPDF_AsciiHexFilter; | 109 return new CPDF_AsciiHexFilter; |
110 case FXBSTR_ID('A', '8', '5', 0): | 110 case FXBSTR_ID('A', '8', '5', 0): |
111 return new CPDF_Ascii85Filter; | 111 return new CPDF_Ascii85Filter; |
112 case FXBSTR_ID('R', 'u', 'n', 'L'): | 112 case FXBSTR_ID('R', 'u', 'n', 'L'): |
113 return new CPDF_RunLenFilter; | 113 return new CPDF_RunLenFilter; |
114 case FXBSTR_ID('C', 'C', 'I', 'T'): { | 114 case FXBSTR_ID('C', 'C', 'I', 'T'): { |
115 int Encoding = 0; | 115 int Encoding = 0; |
116 int bEndOfLine = FALSE; | 116 int bEndOfLine = false; |
117 int bByteAlign = FALSE; | 117 int bByteAlign = false; |
118 int bBlack = FALSE; | 118 int bBlack = false; |
119 int nRows = 0; | 119 int nRows = 0; |
120 int nColumns = 1728; | 120 int nColumns = 1728; |
121 if (pParam) { | 121 if (pParam) { |
122 Encoding = pParam->GetInteger(FX_BSTRC("K")); | 122 Encoding = pParam->GetInteger(FX_BSTRC("K")); |
123 bEndOfLine = pParam->GetInteger(FX_BSTRC("EndOfLine")); | 123 bEndOfLine = pParam->GetInteger(FX_BSTRC("EndOfLine")); |
124 bByteAlign = pParam->GetInteger(FX_BSTRC("EncodedByteAlign")
); | 124 bByteAlign = pParam->GetInteger(FX_BSTRC("EncodedByteAlign")
); |
125 bBlack = pParam->GetInteger(FX_BSTRC("BlackIs1")); | 125 bBlack = pParam->GetInteger(FX_BSTRC("BlackIs1")); |
126 nColumns = pParam->GetInteger(FX_BSTRC("Columns"), 1728); | 126 nColumns = pParam->GetInteger(FX_BSTRC("Columns"), 1728); |
127 nRows = pParam->GetInteger(FX_BSTRC("Rows")); | 127 nRows = pParam->GetInteger(FX_BSTRC("Rows")); |
128 } | 128 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 171 } |
172 } | 172 } |
173 } else { | 173 } else { |
174 if (pParams && pParams->GetType() != PDFOBJ_DICTIONARY) { | 174 if (pParams && pParams->GetType() != PDFOBJ_DICTIONARY) { |
175 pParams = NULL; | 175 pParams = NULL; |
176 } | 176 } |
177 pFirstFilter = FPDF_CreateFilter(pDecoder->GetString(), (CPDF_Dictionary
*)pParams, width, height); | 177 pFirstFilter = FPDF_CreateFilter(pDecoder->GetString(), (CPDF_Dictionary
*)pParams, width, height); |
178 } | 178 } |
179 return pFirstFilter; | 179 return pFirstFilter; |
180 } | 180 } |
181 CPDF_StreamFilter* CPDF_Stream::GetStreamFilter(FX_BOOL bRaw) const | 181 CPDF_StreamFilter* CPDF_Stream::GetStreamFilter(bool bRaw) const |
182 { | 182 { |
183 CFX_DataFilter* pFirstFilter = NULL; | 183 CFX_DataFilter* pFirstFilter = NULL; |
184 if (m_pCryptoHandler) { | 184 if (m_pCryptoHandler) { |
185 pFirstFilter = new CPDF_DecryptFilter(m_pCryptoHandler, m_ObjNum, m_GenN
um); | 185 pFirstFilter = new CPDF_DecryptFilter(m_pCryptoHandler, m_ObjNum, m_GenN
um); |
186 } | 186 } |
187 if (!bRaw) { | 187 if (!bRaw) { |
188 CFX_DataFilter* pFilter = _FPDF_CreateFilterFromDict(m_pDict); | 188 CFX_DataFilter* pFilter = _FPDF_CreateFilterFromDict(m_pDict); |
189 if (pFilter) { | 189 if (pFilter) { |
190 if (pFirstFilter == NULL) { | 190 if (pFirstFilter == NULL) { |
191 pFirstFilter = pFilter; | 191 pFirstFilter = pFilter; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 } | 287 } |
288 void CPDF_DecryptFilter::v_FilterIn(const uint8_t* src_buf, FX_DWORD src_size, C
FX_BinaryBuf& dest_buf) | 288 void CPDF_DecryptFilter::v_FilterIn(const uint8_t* src_buf, FX_DWORD src_size, C
FX_BinaryBuf& dest_buf) |
289 { | 289 { |
290 if (m_pContext == NULL) { | 290 if (m_pContext == NULL) { |
291 m_pContext = m_pCryptoHandler->DecryptStart(m_ObjNum, m_GenNum); | 291 m_pContext = m_pCryptoHandler->DecryptStart(m_ObjNum, m_GenNum); |
292 } | 292 } |
293 m_pCryptoHandler->DecryptStream(m_pContext, src_buf, src_size, dest_buf); | 293 m_pCryptoHandler->DecryptStream(m_pContext, src_buf, src_size, dest_buf); |
294 } | 294 } |
295 void CPDF_DecryptFilter::v_FilterFinish(CFX_BinaryBuf& dest_buf) | 295 void CPDF_DecryptFilter::v_FilterFinish(CFX_BinaryBuf& dest_buf) |
296 { | 296 { |
297 m_bEOF = TRUE; | 297 m_bEOF = true; |
298 if (m_pContext == NULL) { | 298 if (m_pContext == NULL) { |
299 return; | 299 return; |
300 } | 300 } |
301 m_pCryptoHandler->DecryptFinish(m_pContext, dest_buf); | 301 m_pCryptoHandler->DecryptFinish(m_pContext, dest_buf); |
302 m_pContext = NULL; | 302 m_pContext = NULL; |
303 } | 303 } |
304 CPDF_FlateFilter::CPDF_FlateFilter() | 304 CPDF_FlateFilter::CPDF_FlateFilter() |
305 { | 305 { |
306 m_pContext = NULL; | 306 m_pContext = NULL; |
307 } | 307 } |
(...skipping 15 matching lines...) Expand all Loading... |
323 dest_buf.AppendBlock(m_DestBuffer, out_size); | 323 dest_buf.AppendBlock(m_DestBuffer, out_size); |
324 if (ret == Z_BUF_ERROR) { | 324 if (ret == Z_BUF_ERROR) { |
325 break; | 325 break; |
326 } | 326 } |
327 if (ret != Z_OK) { | 327 if (ret != Z_OK) { |
328 ReportEOF(FPDFAPI_FlateGetAvailIn(m_pContext)); | 328 ReportEOF(FPDFAPI_FlateGetAvailIn(m_pContext)); |
329 break; | 329 break; |
330 } | 330 } |
331 } | 331 } |
332 } | 332 } |
333 CPDF_LzwFilter::CPDF_LzwFilter(FX_BOOL bEarlyChange) | 333 CPDF_LzwFilter::CPDF_LzwFilter(bool bEarlyChange) |
334 { | 334 { |
335 m_bEarlyChange = bEarlyChange ? 1 : 0; | 335 m_bEarlyChange = bEarlyChange ? 1 : 0; |
336 m_CodeLen = 9; | 336 m_CodeLen = 9; |
337 m_nCodes = 0; | 337 m_nCodes = 0; |
338 m_nLeftBits = 0; | 338 m_nLeftBits = 0; |
339 m_LeftBits = 0; | 339 m_LeftBits = 0; |
340 m_OldCode = (FX_DWORD) - 1; | 340 m_OldCode = (FX_DWORD) - 1; |
341 } | 341 } |
342 void CPDF_LzwFilter::v_FilterIn(const uint8_t* src_buf, FX_DWORD src_size, CFX_B
inaryBuf& dest_buf) | 342 void CPDF_LzwFilter::v_FilterIn(const uint8_t* src_buf, FX_DWORD src_size, CFX_B
inaryBuf& dest_buf) |
343 { | 343 { |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 FXSYS_memset(dest_buf.GetBuffer() + dest_buf.GetSize() - m_C
ount, byte, m_Count); | 690 FXSYS_memset(dest_buf.GetBuffer() + dest_buf.GetSize() - m_C
ount, byte, m_Count); |
691 m_State = 0; | 691 m_State = 0; |
692 break; | 692 break; |
693 } | 693 } |
694 } | 694 } |
695 } | 695 } |
696 } | 696 } |
697 CPDF_JpegFilter::CPDF_JpegFilter() | 697 CPDF_JpegFilter::CPDF_JpegFilter() |
698 { | 698 { |
699 m_pContext = NULL; | 699 m_pContext = NULL; |
700 m_bGotHeader = FALSE; | 700 m_bGotHeader = false; |
701 m_pScanline = NULL; | 701 m_pScanline = NULL; |
702 m_iLine = 0; | 702 m_iLine = 0; |
703 } | 703 } |
704 CPDF_JpegFilter::~CPDF_JpegFilter() | 704 CPDF_JpegFilter::~CPDF_JpegFilter() |
705 { | 705 { |
706 if (m_pScanline) { | 706 if (m_pScanline) { |
707 FX_Free(m_pScanline); | 707 FX_Free(m_pScanline); |
708 } | 708 } |
709 if (m_pContext) { | 709 if (m_pContext) { |
710 CPDF_ModuleMgr::Get()->GetJpegModule()->Finish(m_pContext); | 710 CPDF_ModuleMgr::Get()->GetJpegModule()->Finish(m_pContext); |
(...skipping 24 matching lines...) Expand all Loading... |
735 int left_size = CPDF_ModuleMgr::Get()->GetJpegModule()->GetAvailInput(m_
pContext); | 735 int left_size = CPDF_ModuleMgr::Get()->GetJpegModule()->GetAvailInput(m_
pContext); |
736 if (ret == 1) { | 736 if (ret == 1) { |
737 ReportEOF(left_size); | 737 ReportEOF(left_size); |
738 return; | 738 return; |
739 } | 739 } |
740 if (ret == 2) { | 740 if (ret == 2) { |
741 m_InputBuf.AppendBlock(jpeg_src_buf + jpeg_src_size - left_size, lef
t_size); | 741 m_InputBuf.AppendBlock(jpeg_src_buf + jpeg_src_size - left_size, lef
t_size); |
742 return; | 742 return; |
743 } | 743 } |
744 CPDF_ModuleMgr::Get()->GetJpegModule()->StartScanline(m_pContext, 1); | 744 CPDF_ModuleMgr::Get()->GetJpegModule()->StartScanline(m_pContext, 1); |
745 m_bGotHeader = TRUE; | 745 m_bGotHeader = true; |
746 m_Pitch = m_Width * m_nComps; | 746 m_Pitch = m_Width * m_nComps; |
747 } | 747 } |
748 if (m_pScanline == NULL) { | 748 if (m_pScanline == NULL) { |
749 m_pScanline = FX_Alloc(uint8_t, m_Pitch + 4); | 749 m_pScanline = FX_Alloc(uint8_t, m_Pitch + 4); |
750 } | 750 } |
751 while (1) { | 751 while (1) { |
752 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->ReadScanline(m_pContext, m_
pScanline)) { | 752 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->ReadScanline(m_pContext, m_
pScanline)) { |
753 int left_size = CPDF_ModuleMgr::Get()->GetJpegModule()->GetAvailInpu
t(m_pContext); | 753 int left_size = CPDF_ModuleMgr::Get()->GetJpegModule()->GetAvailInpu
t(m_pContext); |
754 m_InputBuf.AppendBlock(jpeg_src_buf + jpeg_src_size - left_size, lef
t_size); | 754 m_InputBuf.AppendBlock(jpeg_src_buf + jpeg_src_size - left_size, lef
t_size); |
755 break; | 755 break; |
756 } | 756 } |
757 dest_buf.AppendBlock(m_pScanline, m_Pitch); | 757 dest_buf.AppendBlock(m_pScanline, m_Pitch); |
758 m_iLine ++; | 758 m_iLine ++; |
759 if (m_iLine == m_Height) { | 759 if (m_iLine == m_Height) { |
760 ReportEOF(CPDF_ModuleMgr::Get()->GetJpegModule()->GetAvailInput(m_pC
ontext)); | 760 ReportEOF(CPDF_ModuleMgr::Get()->GetJpegModule()->GetAvailInput(m_pC
ontext)); |
761 return; | 761 return; |
762 } | 762 } |
763 } | 763 } |
764 } | 764 } |
765 CPDF_FaxFilter::CPDF_FaxFilter() | 765 CPDF_FaxFilter::CPDF_FaxFilter() |
766 { | 766 { |
767 m_Encoding = 0; | 767 m_Encoding = 0; |
768 m_bEndOfLine = FALSE; | 768 m_bEndOfLine = false; |
769 m_bByteAlign = FALSE; | 769 m_bByteAlign = false; |
770 m_bBlack = FALSE; | 770 m_bBlack = false; |
771 m_nRows = 0; | 771 m_nRows = 0; |
772 m_nColumns = 0; | 772 m_nColumns = 0; |
773 m_Pitch = 0; | 773 m_Pitch = 0; |
774 m_pScanlineBuf = NULL; | 774 m_pScanlineBuf = NULL; |
775 m_pRefBuf = NULL; | 775 m_pRefBuf = NULL; |
776 m_iRow = 0; | 776 m_iRow = 0; |
777 m_InputBitPos = 0; | 777 m_InputBitPos = 0; |
778 } | 778 } |
779 CPDF_FaxFilter::~CPDF_FaxFilter() | 779 CPDF_FaxFilter::~CPDF_FaxFilter() |
780 { | 780 { |
781 if (m_pScanlineBuf) { | 781 if (m_pScanlineBuf) { |
782 FX_Free(m_pScanlineBuf); | 782 FX_Free(m_pScanlineBuf); |
783 } | 783 } |
784 if (m_pRefBuf) { | 784 if (m_pRefBuf) { |
785 FX_Free(m_pRefBuf); | 785 FX_Free(m_pRefBuf); |
786 } | 786 } |
787 } | 787 } |
788 FX_BOOL CPDF_FaxFilter::Initialize(int Encoding, int bEndOfLine, int bByteAlign,
int bBlack, int nRows, int nColumns) | 788 bool CPDF_FaxFilter::Initialize(int Encoding, int bEndOfLine, int bByteAlign, in
t bBlack, int nRows, int nColumns) |
789 { | 789 { |
790 m_Encoding = Encoding; | 790 m_Encoding = Encoding; |
791 m_bEndOfLine = bEndOfLine; | 791 m_bEndOfLine = bEndOfLine; |
792 m_bByteAlign = bByteAlign; | 792 m_bByteAlign = bByteAlign; |
793 m_bBlack = bBlack; | 793 m_bBlack = bBlack; |
794 m_nRows = nRows; | 794 m_nRows = nRows; |
795 m_nColumns = nColumns; | 795 m_nColumns = nColumns; |
796 m_Pitch = (m_nColumns + 7) / 8; | 796 m_Pitch = (m_nColumns + 7) / 8; |
797 m_pScanlineBuf = FX_Alloc(uint8_t, m_Pitch); | 797 m_pScanlineBuf = FX_Alloc(uint8_t, m_Pitch); |
798 m_pRefBuf = FX_Alloc(uint8_t, m_Pitch); | 798 m_pRefBuf = FX_Alloc(uint8_t, m_Pitch); |
799 FXSYS_memset(m_pScanlineBuf, 0xff, m_Pitch); | 799 FXSYS_memset(m_pScanlineBuf, 0xff, m_Pitch); |
800 FXSYS_memset(m_pRefBuf, 0xff, m_Pitch); | 800 FXSYS_memset(m_pRefBuf, 0xff, m_Pitch); |
801 m_iRow = 0; | 801 m_iRow = 0; |
802 m_InputBitPos = 0; | 802 m_InputBitPos = 0; |
803 return TRUE; | 803 return true; |
804 } | 804 } |
805 void CPDF_FaxFilter::v_FilterIn(const uint8_t* src_buf, FX_DWORD src_size, CFX_B
inaryBuf& dest_buf) | 805 void CPDF_FaxFilter::v_FilterIn(const uint8_t* src_buf, FX_DWORD src_size, CFX_B
inaryBuf& dest_buf) |
806 { | 806 { |
807 const uint8_t* fax_src_buf; | 807 const uint8_t* fax_src_buf; |
808 FX_DWORD fax_src_size; | 808 FX_DWORD fax_src_size; |
809 CFX_BinaryBuf temp_buf; | 809 CFX_BinaryBuf temp_buf; |
810 int bitpos; | 810 int bitpos; |
811 if (m_InputBuf.GetSize()) { | 811 if (m_InputBuf.GetSize()) { |
812 temp_buf.EstimateSize(m_InputBuf.GetSize() + src_size); | 812 temp_buf.EstimateSize(m_InputBuf.GetSize() + src_size); |
813 temp_buf.AppendBlock(m_InputBuf.GetBuffer(), m_InputBuf.GetSize()); | 813 temp_buf.AppendBlock(m_InputBuf.GetBuffer(), m_InputBuf.GetSize()); |
814 m_InputBuf.Clear(); | 814 m_InputBuf.Clear(); |
815 temp_buf.AppendBlock(src_buf, src_size); | 815 temp_buf.AppendBlock(src_buf, src_size); |
816 fax_src_buf = temp_buf.GetBuffer(); | 816 fax_src_buf = temp_buf.GetBuffer(); |
817 fax_src_size = temp_buf.GetSize(); | 817 fax_src_size = temp_buf.GetSize(); |
818 bitpos = m_InputBitPos; | 818 bitpos = m_InputBitPos; |
819 } else { | 819 } else { |
820 fax_src_buf = src_buf; | 820 fax_src_buf = src_buf; |
821 fax_src_size = src_size; | 821 fax_src_size = src_size; |
822 bitpos = 0; | 822 bitpos = 0; |
823 } | 823 } |
824 ProcessData(fax_src_buf, fax_src_size, bitpos, FALSE, dest_buf); | 824 ProcessData(fax_src_buf, fax_src_size, bitpos, false, dest_buf); |
825 int left_bits = fax_src_size * 8 - bitpos; | 825 int left_bits = fax_src_size * 8 - bitpos; |
826 m_InputBuf.AppendBlock(fax_src_buf + bitpos / 8, (left_bits + 7) / 8); | 826 m_InputBuf.AppendBlock(fax_src_buf + bitpos / 8, (left_bits + 7) / 8); |
827 m_InputBitPos = bitpos % 8; | 827 m_InputBitPos = bitpos % 8; |
828 } | 828 } |
829 void CPDF_FaxFilter::v_FilterFinish(CFX_BinaryBuf& dest_buf) | 829 void CPDF_FaxFilter::v_FilterFinish(CFX_BinaryBuf& dest_buf) |
830 { | 830 { |
831 ProcessData(m_InputBuf.GetBuffer(), m_InputBuf.GetSize(), m_InputBitPos, TRU
E, dest_buf); | 831 ProcessData(m_InputBuf.GetBuffer(), m_InputBuf.GetSize(), m_InputBitPos, tru
e, dest_buf); |
832 } | 832 } |
833 FX_BOOL _FaxSkipEOL(const uint8_t* src_buf, int bitsize, int& bitpos); | 833 bool _FaxSkipEOL(const uint8_t* src_buf, int bitsize, int& bitpos); |
834 FX_BOOL _FaxG4GetRow(const uint8_t* src_buf, int bitsize, int& bitpos, uint8_t*
dest_buf, const uint8_t* ref_buf, int columns); | 834 bool _FaxG4GetRow(const uint8_t* src_buf, int bitsize, int& bitpos, uint8_t* des
t_buf, const uint8_t* ref_buf, int columns); |
835 FX_BOOL _FaxGet1DLine(const uint8_t* src_buf, int bitsize, int& bitpos, uint8_t*
dest_buf, int columns); | 835 bool _FaxGet1DLine(const uint8_t* src_buf, int bitsize, int& bitpos, uint8_t* de
st_buf, int columns); |
836 void CPDF_FaxFilter::ProcessData(const uint8_t* src_buf, FX_DWORD src_size, int&
bitpos, FX_BOOL bFinish, | 836 void CPDF_FaxFilter::ProcessData(const uint8_t* src_buf, FX_DWORD src_size, int&
bitpos, bool bFinish, |
837 CFX_BinaryBuf& dest_buf) | 837 CFX_BinaryBuf& dest_buf) |
838 { | 838 { |
839 int bitsize = src_size * 8; | 839 int bitsize = src_size * 8; |
840 while (1) { | 840 while (1) { |
841 if ((bitsize < bitpos + 256) && !bFinish) { | 841 if ((bitsize < bitpos + 256) && !bFinish) { |
842 return; | 842 return; |
843 } | 843 } |
844 int start_bitpos = bitpos; | 844 int start_bitpos = bitpos; |
845 FXSYS_memset(m_pScanlineBuf, 0xff, m_Pitch); | 845 FXSYS_memset(m_pScanlineBuf, 0xff, m_Pitch); |
846 if (!ReadLine(src_buf, bitsize, bitpos)) { | 846 if (!ReadLine(src_buf, bitsize, bitpos)) { |
847 bitpos = start_bitpos; | 847 bitpos = start_bitpos; |
848 return; | 848 return; |
849 } | 849 } |
850 if (m_Encoding) { | 850 if (m_Encoding) { |
851 FXSYS_memcpy(m_pRefBuf, m_pScanlineBuf, m_Pitch); | 851 FXSYS_memcpy(m_pRefBuf, m_pScanlineBuf, m_Pitch); |
852 } | 852 } |
853 if (m_bBlack) { | 853 if (m_bBlack) { |
854 for (int i = 0; i < m_Pitch; i ++) { | 854 for (int i = 0; i < m_Pitch; i ++) { |
855 m_pScanlineBuf[i] = ~m_pScanlineBuf[i]; | 855 m_pScanlineBuf[i] = ~m_pScanlineBuf[i]; |
856 } | 856 } |
857 } | 857 } |
858 dest_buf.AppendBlock(m_pScanlineBuf, m_Pitch); | 858 dest_buf.AppendBlock(m_pScanlineBuf, m_Pitch); |
859 m_iRow ++; | 859 m_iRow ++; |
860 if (m_iRow == m_nRows) { | 860 if (m_iRow == m_nRows) { |
861 ReportEOF(src_size - (bitpos + 7) / 8); | 861 ReportEOF(src_size - (bitpos + 7) / 8); |
862 return; | 862 return; |
863 } | 863 } |
864 } | 864 } |
865 } | 865 } |
866 FX_BOOL CPDF_FaxFilter::ReadLine(const uint8_t* src_buf, int bitsize, int& bitpo
s) | 866 bool CPDF_FaxFilter::ReadLine(const uint8_t* src_buf, int bitsize, int& bitpos) |
867 { | 867 { |
868 if (!_FaxSkipEOL(src_buf, bitsize, bitpos)) { | 868 if (!_FaxSkipEOL(src_buf, bitsize, bitpos)) { |
869 return FALSE; | 869 return false; |
870 } | 870 } |
871 FX_BOOL ret; | 871 bool ret; |
872 if (m_Encoding < 0) { | 872 if (m_Encoding < 0) { |
873 ret = _FaxG4GetRow(src_buf, bitsize, bitpos, m_pScanlineBuf, m_pRefBuf,
m_nColumns); | 873 ret = _FaxG4GetRow(src_buf, bitsize, bitpos, m_pScanlineBuf, m_pRefBuf,
m_nColumns); |
874 } else if (m_Encoding == 0) { | 874 } else if (m_Encoding == 0) { |
875 ret = _FaxGet1DLine(src_buf, bitsize, bitpos, m_pScanlineBuf, m_nColumns
); | 875 ret = _FaxGet1DLine(src_buf, bitsize, bitpos, m_pScanlineBuf, m_nColumns
); |
876 } else { | 876 } else { |
877 if (bitpos == bitsize) { | 877 if (bitpos == bitsize) { |
878 return FALSE; | 878 return false; |
879 } | 879 } |
880 FX_BOOL bNext1D = src_buf[bitpos / 8] & (1 << (7 - bitpos % 8)); | 880 bool bNext1D = src_buf[bitpos / 8] & (1 << (7 - bitpos % 8)); |
881 bitpos ++; | 881 bitpos ++; |
882 if (bNext1D) { | 882 if (bNext1D) { |
883 ret = _FaxGet1DLine(src_buf, bitsize, bitpos, m_pScanlineBuf, m_nCol
umns); | 883 ret = _FaxGet1DLine(src_buf, bitsize, bitpos, m_pScanlineBuf, m_nCol
umns); |
884 } else { | 884 } else { |
885 ret = _FaxG4GetRow(src_buf, bitsize, bitpos, m_pScanlineBuf, m_pRefB
uf, m_nColumns); | 885 ret = _FaxG4GetRow(src_buf, bitsize, bitpos, m_pScanlineBuf, m_pRefB
uf, m_nColumns); |
886 } | 886 } |
887 } | 887 } |
888 if (!ret) { | 888 if (!ret) { |
889 return FALSE; | 889 return false; |
890 } | 890 } |
891 if (m_bEndOfLine) | 891 if (m_bEndOfLine) |
892 if (!_FaxSkipEOL(src_buf, bitsize, bitpos)) { | 892 if (!_FaxSkipEOL(src_buf, bitsize, bitpos)) { |
893 return FALSE; | 893 return false; |
894 } | 894 } |
895 if (m_bByteAlign) { | 895 if (m_bByteAlign) { |
896 bitpos = (bitpos + 7) / 8 * 8; | 896 bitpos = (bitpos + 7) / 8 * 8; |
897 } | 897 } |
898 return TRUE; | 898 return true; |
899 } | 899 } |
OLD | NEW |