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 | 9 |
10 namespace { | 10 namespace { |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 bitpos++; | 274 bitpos++; |
275 int next_off = ins_off + ins * 3; | 275 int next_off = ins_off + ins * 3; |
276 for (; ins_off < next_off; ins_off += 3) { | 276 for (; ins_off < next_off; ins_off += 3) { |
277 if (ins_array[ins_off] == code) { | 277 if (ins_array[ins_off] == code) { |
278 return ins_array[ins_off + 1] + ins_array[ins_off + 2] * 256; | 278 return ins_array[ins_off + 1] + ins_array[ins_off + 2] * 256; |
279 } | 279 } |
280 } | 280 } |
281 } | 281 } |
282 } | 282 } |
283 | 283 |
284 #ifndef PDF_ENABLE_XFA | |
Tom Sepez
2015/10/29 23:10:29
note: made identical to master.
| |
284 FX_BOOL FaxG4GetRow(const uint8_t* src_buf, | 285 FX_BOOL FaxG4GetRow(const uint8_t* src_buf, |
285 int bitsize, | 286 int bitsize, |
286 int& bitpos, | 287 int& bitpos, |
287 uint8_t* dest_buf, | 288 uint8_t* dest_buf, |
288 const uint8_t* ref_buf, | 289 const uint8_t* ref_buf, |
289 int columns) { | 290 int columns) { |
290 int a0 = -1; | 291 int a0 = -1; |
291 bool a0color = true; | 292 bool a0color = true; |
292 while (1) { | 293 while (1) { |
293 if (bitpos >= bitsize) { | 294 if (bitpos >= bitsize) { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 } | 460 } |
460 startpos += run_len; | 461 startpos += run_len; |
461 if (startpos >= columns) { | 462 if (startpos >= columns) { |
462 break; | 463 break; |
463 } | 464 } |
464 color = !color; | 465 color = !color; |
465 } | 466 } |
466 return TRUE; | 467 return TRUE; |
467 } | 468 } |
468 | 469 |
470 #endif | |
469 const uint8_t BlackRunTerminator[128] = { | 471 const uint8_t BlackRunTerminator[128] = { |
470 0x37, 10, 0x02, 3, 0x03, 2, 0x02, 2, 0x03, 3, 0x03, 4, 0x02, 4, | 472 0x37, 10, 0x02, 3, 0x03, 2, 0x02, 2, 0x03, 3, 0x03, 4, 0x02, 4, |
471 0x03, 5, 0x05, 6, 0x04, 6, 0x04, 7, 0x05, 7, 0x07, 7, 0x04, 8, | 473 0x03, 5, 0x05, 6, 0x04, 6, 0x04, 7, 0x05, 7, 0x07, 7, 0x04, 8, |
472 0x07, 8, 0x18, 9, 0x17, 10, 0x18, 10, 0x08, 10, 0x67, 11, 0x68, 11, | 474 0x07, 8, 0x18, 9, 0x17, 10, 0x18, 10, 0x08, 10, 0x67, 11, 0x68, 11, |
473 0x6c, 11, 0x37, 11, 0x28, 11, 0x17, 11, 0x18, 11, 0xca, 12, 0xcb, 12, | 475 0x6c, 11, 0x37, 11, 0x28, 11, 0x17, 11, 0x18, 11, 0xca, 12, 0xcb, 12, |
474 0xcc, 12, 0xcd, 12, 0x68, 12, 0x69, 12, 0x6a, 12, 0x6b, 12, 0xd2, 12, | 476 0xcc, 12, 0xcd, 12, 0x68, 12, 0x69, 12, 0x6a, 12, 0x6b, 12, 0xd2, 12, |
475 0xd3, 12, 0xd4, 12, 0xd5, 12, 0xd6, 12, 0xd7, 12, 0x6c, 12, 0x6d, 12, | 477 0xd3, 12, 0xd4, 12, 0xd5, 12, 0xd6, 12, 0xd7, 12, 0x6c, 12, 0x6d, 12, |
476 0xda, 12, 0xdb, 12, 0x54, 12, 0x55, 12, 0x56, 12, 0x57, 12, 0x64, 12, | 478 0xda, 12, 0xdb, 12, 0x54, 12, 0x55, 12, 0x56, 12, 0x57, 12, 0x64, 12, |
477 0x65, 12, 0x52, 12, 0x53, 12, 0x24, 12, 0x37, 12, 0x38, 12, 0x27, 12, | 479 0x65, 12, 0x52, 12, 0x53, 12, 0x24, 12, 0x37, 12, 0x38, 12, 0x27, 12, |
478 0x28, 12, 0x58, 12, 0x59, 12, 0x2b, 12, 0x2c, 12, 0x5a, 12, 0x66, 12, | 480 0x28, 12, 0x58, 12, 0x59, 12, 0x2b, 12, 0x2c, 12, 0x5a, 12, 0x66, 12, |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
723 return m_pScanlineBuf; | 725 return m_pScanlineBuf; |
724 } | 726 } |
725 FX_DWORD CCodec_FaxDecoder::GetSrcOffset() { | 727 FX_DWORD CCodec_FaxDecoder::GetSrcOffset() { |
726 FX_DWORD ret = (bitpos + 7) / 8; | 728 FX_DWORD ret = (bitpos + 7) / 8; |
727 if (ret > m_SrcSize) { | 729 if (ret > m_SrcSize) { |
728 ret = m_SrcSize; | 730 ret = m_SrcSize; |
729 } | 731 } |
730 return ret; | 732 return ret; |
731 } | 733 } |
732 | 734 |
735 #ifdef PDF_ENABLE_XFA | |
736 FX_BOOL FaxSkipEOL(const uint8_t* src_buf, int bitsize, int& bitpos) { | |
737 int startbit = bitpos; | |
738 while (bitpos < bitsize) { | |
739 int bit = NEXTBIT; | |
740 if (bit) { | |
741 if (bitpos - startbit <= 11) { | |
742 bitpos = startbit; | |
743 } | |
744 return TRUE; | |
745 } | |
746 } | |
747 return FALSE; | |
748 } | |
749 | |
750 FX_BOOL FaxGet1DLine(const uint8_t* src_buf, | |
751 int bitsize, | |
752 int& bitpos, | |
753 uint8_t* dest_buf, | |
754 int columns) { | |
755 bool color = true; | |
756 int startpos = 0; | |
757 while (1) { | |
758 if (bitpos >= bitsize) { | |
759 return FALSE; | |
760 } | |
761 int run_len = 0; | |
762 while (1) { | |
763 int run = FaxGetRun(color ? FaxWhiteRunIns : FaxBlackRunIns, src_buf, | |
764 bitpos, bitsize); | |
765 if (run < 0) { | |
766 while (bitpos < bitsize) { | |
767 int bit = NEXTBIT; | |
768 if (bit) { | |
769 return TRUE; | |
770 } | |
771 } | |
772 return FALSE; | |
773 } | |
774 run_len += run; | |
775 if (run < 64) { | |
776 break; | |
777 } | |
778 } | |
779 if (!color) { | |
780 FaxFillBits(dest_buf, columns, startpos, startpos + run_len); | |
781 } | |
782 startpos += run_len; | |
783 if (startpos >= columns) { | |
784 break; | |
785 } | |
786 color = !color; | |
787 } | |
788 return TRUE; | |
789 } | |
790 | |
791 FX_BOOL FaxG4GetRow(const uint8_t* src_buf, | |
792 int bitsize, | |
793 int& bitpos, | |
794 uint8_t* dest_buf, | |
795 const uint8_t* ref_buf, | |
796 int columns) { | |
797 int a0 = -1; | |
798 bool a0color = true; | |
799 while (1) { | |
800 if (bitpos >= bitsize) { | |
801 return FALSE; | |
802 } | |
803 int a1, a2, b1, b2; | |
804 FaxG4FindB1B2(ref_buf, columns, a0, a0color, b1, b2); | |
805 FX_BOOL bit = NEXTBIT; | |
806 int v_delta = 0; | |
807 if (bit) { | |
808 } else { | |
809 if (bitpos >= bitsize) { | |
810 return FALSE; | |
811 } | |
812 FX_BOOL bit1 = NEXTBIT; | |
813 if (bitpos >= bitsize) { | |
814 return FALSE; | |
815 } | |
816 FX_BOOL bit2 = NEXTBIT; | |
817 if (bit1 && bit2) { | |
818 v_delta = 1; | |
819 } else if (bit1) { | |
820 v_delta = -1; | |
821 } else if (bit2) { | |
822 int run_len1 = 0; | |
823 while (1) { | |
824 int run = FaxGetRun(a0color ? FaxWhiteRunIns : FaxBlackRunIns, | |
825 src_buf, bitpos, bitsize); | |
826 run_len1 += run; | |
827 if (run < 64) { | |
828 break; | |
829 } | |
830 } | |
831 if (a0 < 0) { | |
832 run_len1++; | |
833 } | |
834 a1 = a0 + run_len1; | |
835 if (!a0color) { | |
836 FaxFillBits(dest_buf, columns, a0, a1); | |
837 } | |
838 int run_len2 = 0; | |
839 while (1) { | |
840 int run = FaxGetRun(a0color ? FaxBlackRunIns : FaxWhiteRunIns, | |
841 src_buf, bitpos, bitsize); | |
842 run_len2 += run; | |
843 if (run < 64) { | |
844 break; | |
845 } | |
846 } | |
847 a2 = a1 + run_len2; | |
848 if (a0color) { | |
849 FaxFillBits(dest_buf, columns, a1, a2); | |
850 } | |
851 a0 = a2; | |
852 if (a0 < columns) { | |
853 continue; | |
854 } | |
855 return TRUE; | |
856 } else { | |
857 if (bitpos >= bitsize) { | |
858 return FALSE; | |
859 } | |
860 bit = NEXTBIT; | |
861 if (bit) { | |
862 if (!a0color) { | |
863 FaxFillBits(dest_buf, columns, a0, b2); | |
864 } | |
865 if (b2 >= columns) { | |
866 return TRUE; | |
867 } | |
868 a0 = b2; | |
869 continue; | |
870 } else { | |
871 if (bitpos >= bitsize) { | |
872 return FALSE; | |
873 } | |
874 FX_BOOL bit1 = NEXTBIT; | |
875 if (bitpos >= bitsize) { | |
876 return FALSE; | |
877 } | |
878 FX_BOOL bit2 = NEXTBIT; | |
879 if (bit1 && bit2) { | |
880 v_delta = 2; | |
881 } else if (bit1) { | |
882 v_delta = -2; | |
883 } else if (bit2) { | |
884 if (bitpos >= bitsize) { | |
885 return FALSE; | |
886 } | |
887 bit = NEXTBIT; | |
888 if (bit) { | |
889 v_delta = 3; | |
890 } else { | |
891 v_delta = -3; | |
892 } | |
893 } else { | |
894 if (bitpos >= bitsize) { | |
895 return FALSE; | |
896 } | |
897 bit = NEXTBIT; | |
898 if (bit) { | |
899 bitpos += 3; | |
900 continue; | |
901 } else { | |
902 bitpos += 5; | |
903 return TRUE; | |
904 } | |
905 } | |
906 } | |
907 } | |
908 } | |
909 a1 = b1 + v_delta; | |
910 if (!a0color) { | |
911 FaxFillBits(dest_buf, columns, a0, a1); | |
912 } | |
913 if (a1 >= columns) { | |
914 return TRUE; | |
915 } | |
916 a0 = a1; | |
917 a0color = !a0color; | |
918 } | |
919 } | |
920 | |
921 #endif | |
733 void FaxG4Decode(const uint8_t* src_buf, | 922 void FaxG4Decode(const uint8_t* src_buf, |
734 FX_DWORD src_size, | 923 FX_DWORD src_size, |
735 int* pbitpos, | 924 int* pbitpos, |
736 uint8_t* dest_buf, | 925 uint8_t* dest_buf, |
737 int width, | 926 int width, |
738 int height, | 927 int height, |
739 int pitch) { | 928 int pitch) { |
740 if (pitch == 0) { | 929 if (pitch == 0) { |
741 pitch = (width + 7) / 8; | 930 pitch = (width + 7) / 8; |
742 } | 931 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
821 FX_BOOL EndOfLine, | 1010 FX_BOOL EndOfLine, |
822 FX_BOOL EncodedByteAlign, | 1011 FX_BOOL EncodedByteAlign, |
823 FX_BOOL BlackIs1, | 1012 FX_BOOL BlackIs1, |
824 int Columns, | 1013 int Columns, |
825 int Rows) { | 1014 int Rows) { |
826 CCodec_FaxDecoder* pDecoder = new CCodec_FaxDecoder; | 1015 CCodec_FaxDecoder* pDecoder = new CCodec_FaxDecoder; |
827 pDecoder->Create(src_buf, src_size, width, height, K, EndOfLine, | 1016 pDecoder->Create(src_buf, src_size, width, height, K, EndOfLine, |
828 EncodedByteAlign, BlackIs1, Columns, Rows); | 1017 EncodedByteAlign, BlackIs1, Columns, Rows); |
829 return pDecoder; | 1018 return pDecoder; |
830 } | 1019 } |
OLD | NEW |