| 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 "core/fxcodec/codec/codec_int.h" | 7 #include "core/fxcodec/codec/codec_int.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 bool ret = true; | 838 bool ret = true; |
| 839 if (predictor_type == 2) { | 839 if (predictor_type == 2) { |
| 840 ret = PNG_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, Columns); | 840 ret = PNG_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, Columns); |
| 841 } else if (predictor_type == 1) { | 841 } else if (predictor_type == 1) { |
| 842 ret = | 842 ret = |
| 843 TIFF_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, Columns); | 843 TIFF_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, Columns); |
| 844 } | 844 } |
| 845 return ret ? offset : FX_INVALID_OFFSET; | 845 return ret ? offset : FX_INVALID_OFFSET; |
| 846 } | 846 } |
| 847 | 847 |
| 848 // static |
| 848 bool CCodec_FlateModule::Encode(const uint8_t* src_buf, | 849 bool CCodec_FlateModule::Encode(const uint8_t* src_buf, |
| 849 uint32_t src_size, | 850 uint32_t src_size, |
| 850 uint8_t** dest_buf, | 851 uint8_t** dest_buf, |
| 851 uint32_t* dest_size) { | 852 uint32_t* dest_size) { |
| 852 *dest_size = src_size + src_size / 1000 + 12; | 853 *dest_size = src_size + src_size / 1000 + 12; |
| 853 *dest_buf = FX_Alloc(uint8_t, *dest_size); | 854 *dest_buf = FX_Alloc(uint8_t, *dest_size); |
| 854 unsigned long temp_size = *dest_size; | 855 unsigned long temp_size = *dest_size; |
| 855 if (!FPDFAPI_FlateCompress(*dest_buf, &temp_size, src_buf, src_size)) | 856 if (!FPDFAPI_FlateCompress(*dest_buf, &temp_size, src_buf, src_size)) |
| 856 return false; | 857 return false; |
| 857 | 858 |
| 858 *dest_size = (uint32_t)temp_size; | 859 *dest_size = (uint32_t)temp_size; |
| 859 return true; | 860 return true; |
| 860 } | 861 } |
| 861 | 862 |
| 863 // static |
| 862 bool CCodec_FlateModule::PngEncode(const uint8_t* src_buf, | 864 bool CCodec_FlateModule::PngEncode(const uint8_t* src_buf, |
| 863 uint32_t src_size, | 865 uint32_t src_size, |
| 864 uint8_t** dest_buf, | 866 uint8_t** dest_buf, |
| 865 uint32_t* dest_size) { | 867 uint32_t* dest_size) { |
| 866 uint8_t* pSrcBuf = FX_Alloc(uint8_t, src_size); | 868 uint8_t* pSrcBuf = FX_Alloc(uint8_t, src_size); |
| 867 FXSYS_memcpy(pSrcBuf, src_buf, src_size); | 869 FXSYS_memcpy(pSrcBuf, src_buf, src_size); |
| 868 PNG_PredictorEncode(&pSrcBuf, &src_size); | 870 PNG_PredictorEncode(&pSrcBuf, &src_size); |
| 869 bool ret = Encode(pSrcBuf, src_size, dest_buf, dest_size); | 871 bool ret = Encode(pSrcBuf, src_size, dest_buf, dest_size); |
| 870 FX_Free(pSrcBuf); | 872 FX_Free(pSrcBuf); |
| 871 return ret; | 873 return ret; |
| 872 } | 874 } |
| OLD | NEW |