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 "../../fx_zlib.h" | 7 #include "../../fx_zlib.h" |
8 #include "../../../include/fxcodec/fx_codec.h" | 8 #include "../../../include/fxcodec/fx_codec.h" |
9 #include "codec_int.h" | 9 #include "codec_int.h" |
10 extern "C" | 10 extern "C" |
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 guess_buf[guess_size] = '\0'; | 844 guess_buf[guess_size] = '\0'; |
845 } | 845 } |
846 dest_buf = guess_buf; | 846 dest_buf = guess_buf; |
847 } | 847 } |
848 FPDFAPI_FlateEnd(context); | 848 FPDFAPI_FlateEnd(context); |
849 context = NULL; | 849 context = NULL; |
850 } | 850 } |
851 ICodec_ScanlineDecoder* CCodec_FlateModule::CreateDecoder(FX_LPCBYTE src_buf, FX
_DWORD src_size, int width, int height, | 851 ICodec_ScanlineDecoder* CCodec_FlateModule::CreateDecoder(FX_LPCBYTE src_buf, FX
_DWORD src_size, int width, int height, |
852 int nComps, int bpc, int predictor, int Colors, int BitsPerComponent, in
t Columns) | 852 int nComps, int bpc, int predictor, int Colors, int BitsPerComponent, in
t Columns) |
853 { | 853 { |
854 CCodec_FlateScanlineDecoder* pDecoder = FX_NEW CCodec_FlateScanlineDecoder; | 854 CCodec_FlateScanlineDecoder* pDecoder = new CCodec_FlateScanlineDecoder; |
855 if (pDecoder == NULL) { | |
856 return NULL; | |
857 } | |
858 pDecoder->Create(src_buf, src_size, width, height, nComps, bpc, predictor, C
olors, BitsPerComponent, Columns); | 855 pDecoder->Create(src_buf, src_size, width, height, nComps, bpc, predictor, C
olors, BitsPerComponent, Columns); |
859 return pDecoder; | 856 return pDecoder; |
860 } | 857 } |
861 FX_DWORD CCodec_FlateModule::FlateOrLZWDecode(FX_BOOL bLZW, const FX_BYTE* src_b
uf, FX_DWORD src_size, FX_BOOL bEarlyChange, | 858 FX_DWORD CCodec_FlateModule::FlateOrLZWDecode(FX_BOOL bLZW, const FX_BYTE* src_b
uf, FX_DWORD src_size, FX_BOOL bEarlyChange, |
862 int predictor, int Colors, int BitsPerComponent, int Columns, | 859 int predictor, int Colors, int BitsPerComponent, int Columns, |
863 FX_DWORD estimated_size, FX_LPBYTE& dest_buf, FX_DWORD& dest_size) | 860 FX_DWORD estimated_size, FX_LPBYTE& dest_buf, FX_DWORD& dest_size) |
864 { | 861 { |
865 CLZWDecoder* pDecoder = NULL; | 862 CLZWDecoder* pDecoder = NULL; |
866 dest_buf = NULL; | 863 dest_buf = NULL; |
867 FX_DWORD offset = 0; | 864 FX_DWORD offset = 0; |
868 int predictor_type = 0; | 865 int predictor_type = 0; |
869 if (predictor) { | 866 if (predictor) { |
870 if (predictor >= 10) { | 867 if (predictor >= 10) { |
871 predictor_type = 2; | 868 predictor_type = 2; |
872 } else if (predictor == 2) { | 869 } else if (predictor == 2) { |
873 predictor_type = 1; | 870 predictor_type = 1; |
874 } | 871 } |
875 } | 872 } |
876 if (bLZW) { | 873 if (bLZW) { |
877 pDecoder = FX_NEW CLZWDecoder; | 874 pDecoder = new CLZWDecoder; |
878 if (pDecoder == NULL) { | |
879 return -1; | |
880 } | |
881 dest_size = (FX_DWORD) - 1; | 875 dest_size = (FX_DWORD) - 1; |
882 offset = src_size; | 876 offset = src_size; |
883 int err = pDecoder->Decode(NULL, dest_size, src_buf, offset, bEarlyChang
e); | 877 int err = pDecoder->Decode(NULL, dest_size, src_buf, offset, bEarlyChang
e); |
884 delete pDecoder; | 878 delete pDecoder; |
885 if (err || dest_size == 0 || dest_size + 1 < dest_size) { | 879 if (err || dest_size == 0 || dest_size + 1 < dest_size) { |
886 return (FX_DWORD) - 1; | 880 return (FX_DWORD) - 1; |
887 } | 881 } |
888 pDecoder = FX_NEW CLZWDecoder; | 882 pDecoder = new CLZWDecoder; |
889 if (pDecoder == NULL) { | |
890 return -1; | |
891 } | |
892 dest_buf = FX_Alloc( FX_BYTE, dest_size + 1); | 883 dest_buf = FX_Alloc( FX_BYTE, dest_size + 1); |
893 if (dest_buf == NULL) { | 884 if (dest_buf == NULL) { |
894 return -1; | 885 return -1; |
895 } | 886 } |
896 dest_buf[dest_size] = '\0'; | 887 dest_buf[dest_size] = '\0'; |
897 pDecoder->Decode(dest_buf, dest_size, src_buf, offset, bEarlyChange); | 888 pDecoder->Decode(dest_buf, dest_size, src_buf, offset, bEarlyChange); |
898 delete pDecoder; | 889 delete pDecoder; |
899 } else { | 890 } else { |
900 FlateUncompress(src_buf, src_size, estimated_size, dest_buf, dest_size,
offset); | 891 FlateUncompress(src_buf, src_size, estimated_size, dest_buf, dest_size,
offset); |
901 } | 892 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 dest_size = src_size + src_size / 1000 + 12; | 928 dest_size = src_size + src_size / 1000 + 12; |
938 dest_buf = FX_Alloc( FX_BYTE, dest_size); | 929 dest_buf = FX_Alloc( FX_BYTE, dest_size); |
939 if (dest_buf == NULL) { | 930 if (dest_buf == NULL) { |
940 return FALSE; | 931 return FALSE; |
941 } | 932 } |
942 unsigned long temp_size = dest_size; | 933 unsigned long temp_size = dest_size; |
943 FPDFAPI_FlateCompress(dest_buf, &temp_size, src_buf, src_size); | 934 FPDFAPI_FlateCompress(dest_buf, &temp_size, src_buf, src_size); |
944 dest_size = (FX_DWORD)temp_size; | 935 dest_size = (FX_DWORD)temp_size; |
945 return TRUE; | 936 return TRUE; |
946 } | 937 } |
OLD | NEW |