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/include/fxcodec/fx_codec.h" | 7 #include "core/include/fxcodec/fx_codec.h" |
8 #include "core/include/fxge/fx_dib.h" | 8 #include "core/include/fxge/fx_dib.h" |
9 #include "core/src/fxcodec/codec/fx_codec_progress.h" | 9 #include "core/src/fxcodec/codec/fx_codec_progress.h" |
10 void CFXCODEC_WeightTable::Calc(int dest_len, | 10 void CFXCODEC_WeightTable::Calc(int dest_len, |
11 int dest_min, | 11 int dest_min, |
12 int dest_max, | 12 int dest_max, |
13 int src_len, | 13 int src_len, |
14 int src_min, | 14 int src_min, |
15 int src_max, | 15 int src_max, |
16 FX_BOOL bInterpol) { | 16 FX_BOOL bInterpol) { |
17 if (m_pWeightTables) { | 17 if (m_pWeightTables) { |
18 FX_Free(m_pWeightTables); | 18 FX_Free(m_pWeightTables); |
19 } | 19 } |
20 double scale, base; | 20 double scale, base; |
21 scale = FXSYS_Div((FX_FLOAT)(src_len), (FX_FLOAT)(dest_len)); | 21 scale = (FX_FLOAT)src_len / (FX_FLOAT)dest_len; |
22 if (dest_len < 0) { | 22 if (dest_len < 0) { |
23 base = (FX_FLOAT)(src_len); | 23 base = (FX_FLOAT)(src_len); |
24 } else { | 24 } else { |
25 base = 0.0f; | 25 base = 0.0f; |
26 } | 26 } |
27 m_ItemSize = | 27 m_ItemSize = |
28 (int)(sizeof(int) * 2 + | 28 (int)(sizeof(int) * 2 + |
29 sizeof(int) * (FXSYS_ceil(FXSYS_fabs((FX_FLOAT)scale)) + 1)); | 29 sizeof(int) * (FXSYS_ceil(FXSYS_fabs((FX_FLOAT)scale)) + 1)); |
30 m_DestMin = dest_min; | 30 m_DestMin = dest_min; |
31 m_pWeightTables = FX_Alloc(uint8_t, (dest_max - dest_min) * m_ItemSize + 4); | 31 m_pWeightTables = FX_Alloc(uint8_t, (dest_max - dest_min) * m_ItemSize + 4); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 end_i = src_max - 1; | 81 end_i = src_max - 1; |
82 } | 82 } |
83 if (start_i > end_i) { | 83 if (start_i > end_i) { |
84 pixel_weights.m_SrcStart = start_i; | 84 pixel_weights.m_SrcStart = start_i; |
85 pixel_weights.m_SrcEnd = start_i; | 85 pixel_weights.m_SrcEnd = start_i; |
86 continue; | 86 continue; |
87 } | 87 } |
88 pixel_weights.m_SrcStart = start_i; | 88 pixel_weights.m_SrcStart = start_i; |
89 pixel_weights.m_SrcEnd = end_i; | 89 pixel_weights.m_SrcEnd = end_i; |
90 for (int j = start_i; j <= end_i; j++) { | 90 for (int j = start_i; j <= end_i; j++) { |
91 double dest_start = FXSYS_Div((FX_FLOAT)(j)-base, scale); | 91 double dest_start = ((FX_FLOAT)j - base) / scale; |
92 double dest_end = FXSYS_Div((FX_FLOAT)(j + 1) - base, scale); | 92 double dest_end = ((FX_FLOAT)(j + 1) - base) / scale; |
93 if (dest_start > dest_end) { | 93 if (dest_start > dest_end) { |
94 double temp = dest_start; | 94 double temp = dest_start; |
95 dest_start = dest_end; | 95 dest_start = dest_end; |
96 dest_end = temp; | 96 dest_end = temp; |
97 } | 97 } |
98 double area_start = dest_start > (FX_FLOAT)(dest_pixel) | 98 double area_start = dest_start > (FX_FLOAT)(dest_pixel) |
99 ? dest_start | 99 ? dest_start |
100 : (FX_FLOAT)(dest_pixel); | 100 : (FX_FLOAT)(dest_pixel); |
101 double area_end = dest_end > (FX_FLOAT)(dest_pixel + 1) | 101 double area_end = dest_end > (FX_FLOAT)(dest_pixel + 1) |
102 ? (FX_FLOAT)(dest_pixel + 1) | 102 ? (FX_FLOAT)(dest_pixel + 1) |
(...skipping 2183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2286 } | 2286 } |
2287 } break; | 2287 } break; |
2288 default: | 2288 default: |
2289 break; | 2289 break; |
2290 } | 2290 } |
2291 return FXCODEC_STATUS_ERROR; | 2291 return FXCODEC_STATUS_ERROR; |
2292 } | 2292 } |
2293 ICodec_ProgressiveDecoder* CCodec_ModuleMgr::CreateProgressiveDecoder() { | 2293 ICodec_ProgressiveDecoder* CCodec_ModuleMgr::CreateProgressiveDecoder() { |
2294 return new CCodec_ProgressiveDecoder(this); | 2294 return new CCodec_ProgressiveDecoder(this); |
2295 } | 2295 } |
OLD | NEW |