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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 FX_DWORD m_SrcSize; | 484 FX_DWORD m_SrcSize; |
485 uint8_t* m_pScanlineBuf; | 485 uint8_t* m_pScanlineBuf; |
486 uint8_t* m_pRefBuf; | 486 uint8_t* m_pRefBuf; |
487 }; | 487 }; |
488 | 488 |
489 CCodec_FaxDecoder::CCodec_FaxDecoder() { | 489 CCodec_FaxDecoder::CCodec_FaxDecoder() { |
490 m_pScanlineBuf = NULL; | 490 m_pScanlineBuf = NULL; |
491 m_pRefBuf = NULL; | 491 m_pRefBuf = NULL; |
492 } | 492 } |
493 CCodec_FaxDecoder::~CCodec_FaxDecoder() { | 493 CCodec_FaxDecoder::~CCodec_FaxDecoder() { |
494 if (m_pScanlineBuf) { | 494 FX_Free(m_pScanlineBuf); |
495 FX_Free(m_pScanlineBuf); | 495 FX_Free(m_pRefBuf); |
496 } | |
497 if (m_pRefBuf) { | |
498 FX_Free(m_pRefBuf); | |
499 } | |
500 } | 496 } |
501 FX_BOOL CCodec_FaxDecoder::Create(const uint8_t* src_buf, | 497 FX_BOOL CCodec_FaxDecoder::Create(const uint8_t* src_buf, |
502 FX_DWORD src_size, | 498 FX_DWORD src_size, |
503 int width, | 499 int width, |
504 int height, | 500 int height, |
505 int K, | 501 int K, |
506 FX_BOOL EndOfLine, | 502 FX_BOOL EndOfLine, |
507 FX_BOOL EncodedByteAlign, | 503 FX_BOOL EncodedByteAlign, |
508 FX_BOOL BlackIs1, | 504 FX_BOOL BlackIs1, |
509 int Columns, | 505 int Columns, |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 m_pSrcBuf = src_buf; | 759 m_pSrcBuf = src_buf; |
764 m_Cols = width; | 760 m_Cols = width; |
765 m_Rows = height; | 761 m_Rows = height; |
766 m_Pitch = pitch; | 762 m_Pitch = pitch; |
767 m_pRefLine = FX_Alloc(uint8_t, m_Pitch); | 763 m_pRefLine = FX_Alloc(uint8_t, m_Pitch); |
768 FXSYS_memset(m_pRefLine, 0xff, m_Pitch); | 764 FXSYS_memset(m_pRefLine, 0xff, m_Pitch); |
769 m_pLineBuf = FX_Alloc2D(uint8_t, m_Pitch, 8); | 765 m_pLineBuf = FX_Alloc2D(uint8_t, m_Pitch, 8); |
770 m_DestBuf.EstimateSize(0, 10240); | 766 m_DestBuf.EstimateSize(0, 10240); |
771 } | 767 } |
772 CCodec_FaxEncoder::~CCodec_FaxEncoder() { | 768 CCodec_FaxEncoder::~CCodec_FaxEncoder() { |
773 if (m_pRefLine) { | 769 FX_Free(m_pRefLine); |
774 FX_Free(m_pRefLine); | 770 FX_Free(m_pLineBuf); |
775 } | |
776 if (m_pLineBuf) { | |
777 FX_Free(m_pLineBuf); | |
778 } | |
779 } | 771 } |
780 void CCodec_FaxEncoder::Encode(uint8_t*& dest_buf, FX_DWORD& dest_size) { | 772 void CCodec_FaxEncoder::Encode(uint8_t*& dest_buf, FX_DWORD& dest_size) { |
781 int dest_bitpos = 0; | 773 int dest_bitpos = 0; |
782 uint8_t last_byte = 0; | 774 uint8_t last_byte = 0; |
783 for (int i = 0; i < m_Rows; i++) { | 775 for (int i = 0; i < m_Rows; i++) { |
784 const uint8_t* scan_line = m_pSrcBuf + i * m_Pitch; | 776 const uint8_t* scan_line = m_pSrcBuf + i * m_Pitch; |
785 FXSYS_memset(m_pLineBuf, 0, m_Pitch * 8); | 777 FXSYS_memset(m_pLineBuf, 0, m_Pitch * 8); |
786 m_pLineBuf[0] = last_byte; | 778 m_pLineBuf[0] = last_byte; |
787 _FaxEncode2DLine(m_pLineBuf, dest_bitpos, scan_line, m_pRefLine, m_Cols); | 779 _FaxEncode2DLine(m_pLineBuf, dest_bitpos, scan_line, m_pRefLine, m_Cols); |
788 m_DestBuf.AppendBlock(m_pLineBuf, dest_bitpos / 8); | 780 m_DestBuf.AppendBlock(m_pLineBuf, dest_bitpos / 8); |
(...skipping 27 matching lines...) Expand all Loading... |
816 FX_BOOL EndOfLine, | 808 FX_BOOL EndOfLine, |
817 FX_BOOL EncodedByteAlign, | 809 FX_BOOL EncodedByteAlign, |
818 FX_BOOL BlackIs1, | 810 FX_BOOL BlackIs1, |
819 int Columns, | 811 int Columns, |
820 int Rows) { | 812 int Rows) { |
821 CCodec_FaxDecoder* pDecoder = new CCodec_FaxDecoder; | 813 CCodec_FaxDecoder* pDecoder = new CCodec_FaxDecoder; |
822 pDecoder->Create(src_buf, src_size, width, height, K, EndOfLine, | 814 pDecoder->Create(src_buf, src_size, width, height, K, EndOfLine, |
823 EncodedByteAlign, BlackIs1, Columns, Rows); | 815 EncodedByteAlign, BlackIs1, Columns, Rows); |
824 return pDecoder; | 816 return pDecoder; |
825 } | 817 } |
OLD | NEW |