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/fxcodec/fx_codec.h" | 7 #include "../../../include/fxcodec/fx_codec.h" |
8 #include "codec_int.h" | 8 #include "codec_int.h" |
9 const uint8_t OneLeadPos[256] = { | 9 const uint8_t OneLeadPos[256] = { |
10 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, | 10 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 const uint8_t* m_pSrcBuf; | 478 const uint8_t* m_pSrcBuf; |
479 FX_DWORD m_SrcSize; | 479 FX_DWORD m_SrcSize; |
480 uint8_t* m_pScanlineBuf; | 480 uint8_t* m_pScanlineBuf; |
481 uint8_t* m_pRefBuf; | 481 uint8_t* m_pRefBuf; |
482 }; | 482 }; |
483 CCodec_FaxDecoder::CCodec_FaxDecoder() { | 483 CCodec_FaxDecoder::CCodec_FaxDecoder() { |
484 m_pScanlineBuf = NULL; | 484 m_pScanlineBuf = NULL; |
485 m_pRefBuf = NULL; | 485 m_pRefBuf = NULL; |
486 } | 486 } |
487 CCodec_FaxDecoder::~CCodec_FaxDecoder() { | 487 CCodec_FaxDecoder::~CCodec_FaxDecoder() { |
488 if (m_pScanlineBuf) { | |
489 FX_Free(m_pScanlineBuf); | 488 FX_Free(m_pScanlineBuf); |
490 } | |
491 if (m_pRefBuf) { | |
492 FX_Free(m_pRefBuf); | 489 FX_Free(m_pRefBuf); |
493 } | |
494 } | 490 } |
495 FX_BOOL CCodec_FaxDecoder::Create(const uint8_t* src_buf, | 491 FX_BOOL CCodec_FaxDecoder::Create(const uint8_t* src_buf, |
496 FX_DWORD src_size, | 492 FX_DWORD src_size, |
497 int width, | 493 int width, |
498 int height, | 494 int height, |
499 int K, | 495 int K, |
500 FX_BOOL EndOfLine, | 496 FX_BOOL EndOfLine, |
501 FX_BOOL EncodedByteAlign, | 497 FX_BOOL EncodedByteAlign, |
502 FX_BOOL BlackIs1, | 498 FX_BOOL BlackIs1, |
503 int Columns, | 499 int Columns, |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 m_pSrcBuf = src_buf; | 753 m_pSrcBuf = src_buf; |
758 m_Cols = width; | 754 m_Cols = width; |
759 m_Rows = height; | 755 m_Rows = height; |
760 m_Pitch = pitch; | 756 m_Pitch = pitch; |
761 m_pRefLine = FX_Alloc(uint8_t, m_Pitch); | 757 m_pRefLine = FX_Alloc(uint8_t, m_Pitch); |
762 FXSYS_memset(m_pRefLine, 0xff, m_Pitch); | 758 FXSYS_memset(m_pRefLine, 0xff, m_Pitch); |
763 m_pLineBuf = FX_Alloc2D(uint8_t, m_Pitch, 8); | 759 m_pLineBuf = FX_Alloc2D(uint8_t, m_Pitch, 8); |
764 m_DestBuf.EstimateSize(0, 10240); | 760 m_DestBuf.EstimateSize(0, 10240); |
765 } | 761 } |
766 CCodec_FaxEncoder::~CCodec_FaxEncoder() { | 762 CCodec_FaxEncoder::~CCodec_FaxEncoder() { |
767 if (m_pRefLine) { | |
768 FX_Free(m_pRefLine); | 763 FX_Free(m_pRefLine); |
769 } | |
770 if (m_pLineBuf) { | |
771 FX_Free(m_pLineBuf); | 764 FX_Free(m_pLineBuf); |
772 } | |
773 } | 765 } |
774 void CCodec_FaxEncoder::Encode(uint8_t*& dest_buf, FX_DWORD& dest_size) { | 766 void CCodec_FaxEncoder::Encode(uint8_t*& dest_buf, FX_DWORD& dest_size) { |
775 int dest_bitpos = 0; | 767 int dest_bitpos = 0; |
776 uint8_t last_byte = 0; | 768 uint8_t last_byte = 0; |
777 for (int i = 0; i < m_Rows; i++) { | 769 for (int i = 0; i < m_Rows; i++) { |
778 const uint8_t* scan_line = m_pSrcBuf + i * m_Pitch; | 770 const uint8_t* scan_line = m_pSrcBuf + i * m_Pitch; |
779 FXSYS_memset(m_pLineBuf, 0, m_Pitch * 8); | 771 FXSYS_memset(m_pLineBuf, 0, m_Pitch * 8); |
780 m_pLineBuf[0] = last_byte; | 772 m_pLineBuf[0] = last_byte; |
781 _FaxEncode2DLine(m_pLineBuf, dest_bitpos, scan_line, m_pRefLine, m_Cols); | 773 _FaxEncode2DLine(m_pLineBuf, dest_bitpos, scan_line, m_pRefLine, m_Cols); |
782 m_DestBuf.AppendBlock(m_pLineBuf, dest_bitpos / 8); | 774 m_DestBuf.AppendBlock(m_pLineBuf, dest_bitpos / 8); |
(...skipping 27 matching lines...) Expand all Loading... |
810 FX_BOOL EndOfLine, | 802 FX_BOOL EndOfLine, |
811 FX_BOOL EncodedByteAlign, | 803 FX_BOOL EncodedByteAlign, |
812 FX_BOOL BlackIs1, | 804 FX_BOOL BlackIs1, |
813 int Columns, | 805 int Columns, |
814 int Rows) { | 806 int Rows) { |
815 CCodec_FaxDecoder* pDecoder = new CCodec_FaxDecoder; | 807 CCodec_FaxDecoder* pDecoder = new CCodec_FaxDecoder; |
816 pDecoder->Create(src_buf, src_size, width, height, K, EndOfLine, | 808 pDecoder->Create(src_buf, src_size, width, height, K, EndOfLine, |
817 EncodedByteAlign, BlackIs1, Columns, Rows); | 809 EncodedByteAlign, BlackIs1, Columns, Rows); |
818 return pDecoder; | 810 return pDecoder; |
819 } | 811 } |
OLD | NEW |