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 <limits.h> | 7 #include <limits.h> |
8 | 8 |
9 #include "core/include/fxge/fx_dib.h" | 9 #include "core/include/fxge/fx_dib.h" |
10 #include "core/include/fxge/fx_ge.h" | 10 #include "core/include/fxge/fx_ge.h" |
11 #include "core/src/fxge/dib/dib_int.h" | 11 #include "core/src/fxge/dib/dib_int.h" |
12 | 12 |
13 void CWeightTable::Calc(int dest_len, | 13 void CWeightTable::Calc(int dest_len, |
14 int dest_min, | 14 int dest_min, |
15 int dest_max, | 15 int dest_max, |
16 int src_len, | 16 int src_len, |
17 int src_min, | 17 int src_min, |
18 int src_max, | 18 int src_max, |
19 int flags) { | 19 int flags) { |
20 FX_Free(m_pWeightTables); | 20 FX_Free(m_pWeightTables); |
21 m_pWeightTables = NULL; | 21 m_pWeightTables = NULL; |
22 double scale, base; | 22 double scale, base; |
23 scale = FXSYS_Div((FX_FLOAT)(src_len), (FX_FLOAT)(dest_len)); | 23 scale = (FX_FLOAT)src_len / (FX_FLOAT)dest_len; |
24 if (dest_len < 0) { | 24 if (dest_len < 0) { |
25 base = (FX_FLOAT)(src_len); | 25 base = (FX_FLOAT)(src_len); |
26 } else { | 26 } else { |
27 base = 0; | 27 base = 0; |
28 } | 28 } |
29 int ext_size = flags & FXDIB_BICUBIC_INTERPOL ? 3 : 1; | 29 int ext_size = flags & FXDIB_BICUBIC_INTERPOL ? 3 : 1; |
30 m_ItemSize = | 30 m_ItemSize = |
31 sizeof(int) * 2 + | 31 sizeof(int) * 2 + |
32 (int)(sizeof(int) * (FXSYS_ceil(FXSYS_fabs((FX_FLOAT)scale)) + ext_size)); | 32 (int)(sizeof(int) * (FXSYS_ceil(FXSYS_fabs((FX_FLOAT)scale)) + ext_size)); |
33 m_DestMin = dest_min; | 33 m_DestMin = dest_min; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 if (start_i >= src_max) { | 181 if (start_i >= src_max) { |
182 start_i = src_max - 1; | 182 start_i = src_max - 1; |
183 } | 183 } |
184 pixel_weights.m_SrcStart = start_i; | 184 pixel_weights.m_SrcStart = start_i; |
185 pixel_weights.m_SrcEnd = start_i; | 185 pixel_weights.m_SrcEnd = start_i; |
186 continue; | 186 continue; |
187 } | 187 } |
188 pixel_weights.m_SrcStart = start_i; | 188 pixel_weights.m_SrcStart = start_i; |
189 pixel_weights.m_SrcEnd = end_i; | 189 pixel_weights.m_SrcEnd = end_i; |
190 for (int j = start_i; j <= end_i; j++) { | 190 for (int j = start_i; j <= end_i; j++) { |
191 double dest_start = FXSYS_Div((FX_FLOAT)(j)-base, scale); | 191 double dest_start = ((FX_FLOAT)j - base) / scale; |
192 double dest_end = FXSYS_Div((FX_FLOAT)(j + 1) - base, scale); | 192 double dest_end = ((FX_FLOAT)(j + 1) - base) / scale; |
193 if (dest_start > dest_end) { | 193 if (dest_start > dest_end) { |
194 double temp = dest_start; | 194 double temp = dest_start; |
195 dest_start = dest_end; | 195 dest_start = dest_end; |
196 dest_end = temp; | 196 dest_end = temp; |
197 } | 197 } |
198 double area_start = dest_start > (FX_FLOAT)(dest_pixel) | 198 double area_start = dest_start > (FX_FLOAT)(dest_pixel) |
199 ? dest_start | 199 ? dest_start |
200 : (FX_FLOAT)(dest_pixel); | 200 : (FX_FLOAT)(dest_pixel); |
201 double area_end = dest_end > (FX_FLOAT)(dest_pixel + 1) | 201 double area_end = dest_end > (FX_FLOAT)(dest_pixel + 1) |
202 ? (FX_FLOAT)(dest_pixel + 1) | 202 ? (FX_FLOAT)(dest_pixel + 1) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 m_SrcWidth * m_SrcHeight * 8 / FXSYS_abs(dest_width)) { | 263 m_SrcWidth * m_SrcHeight * 8 / FXSYS_abs(dest_width)) { |
264 flags = FXDIB_INTERPOL; | 264 flags = FXDIB_INTERPOL; |
265 } | 265 } |
266 m_Flags = flags; | 266 m_Flags = flags; |
267 } else { | 267 } else { |
268 m_Flags = FXDIB_NOSMOOTH; | 268 m_Flags = FXDIB_NOSMOOTH; |
269 if (flags & FXDIB_DOWNSAMPLE) { | 269 if (flags & FXDIB_DOWNSAMPLE) { |
270 m_Flags |= FXDIB_DOWNSAMPLE; | 270 m_Flags |= FXDIB_DOWNSAMPLE; |
271 } | 271 } |
272 } | 272 } |
273 double scale_x = FXSYS_Div((FX_FLOAT)(m_SrcWidth), (FX_FLOAT)(m_DestWidth)); | 273 double scale_x = (FX_FLOAT)m_SrcWidth / (FX_FLOAT)m_DestWidth; |
274 double scale_y = FXSYS_Div((FX_FLOAT)(m_SrcHeight), (FX_FLOAT)(m_DestHeight)); | 274 double scale_y = (FX_FLOAT)m_SrcHeight / (FX_FLOAT)m_DestHeight; |
275 double base_x = m_DestWidth > 0 ? 0.0f : (FX_FLOAT)(m_DestWidth); | 275 double base_x = m_DestWidth > 0 ? 0.0f : (FX_FLOAT)(m_DestWidth); |
276 double base_y = m_DestHeight > 0 ? 0.0f : (FX_FLOAT)(m_DestHeight); | 276 double base_y = m_DestHeight > 0 ? 0.0f : (FX_FLOAT)(m_DestHeight); |
277 double src_left = scale_x * ((FX_FLOAT)(clip_rect.left) + base_x); | 277 double src_left = scale_x * ((FX_FLOAT)(clip_rect.left) + base_x); |
278 double src_right = scale_x * ((FX_FLOAT)(clip_rect.right) + base_x); | 278 double src_right = scale_x * ((FX_FLOAT)(clip_rect.right) + base_x); |
279 double src_top = scale_y * ((FX_FLOAT)(clip_rect.top) + base_y); | 279 double src_top = scale_y * ((FX_FLOAT)(clip_rect.top) + base_y); |
280 double src_bottom = scale_y * ((FX_FLOAT)(clip_rect.bottom) + base_y); | 280 double src_bottom = scale_y * ((FX_FLOAT)(clip_rect.bottom) + base_y); |
281 if (src_left > src_right) { | 281 if (src_left > src_right) { |
282 double temp = src_left; | 282 double temp = src_left; |
283 src_left = src_right; | 283 src_left = src_right; |
284 src_right = temp; | 284 src_right = temp; |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 m_bFlipX, m_ClipRect.left, result_width); | 908 m_bFlipX, m_ClipRect.left, result_width); |
909 if (m_pMaskScanline) { | 909 if (m_pMaskScanline) { |
910 m_pSource->m_pAlphaMask->DownSampleScanline( | 910 m_pSource->m_pAlphaMask->DownSampleScanline( |
911 src_y, m_pMaskScanline, 1, m_DestWidth, m_bFlipX, m_ClipRect.left, | 911 src_y, m_pMaskScanline, 1, m_DestWidth, m_bFlipX, m_ClipRect.left, |
912 result_width); | 912 result_width); |
913 } | 913 } |
914 m_pDest->ComposeScanline(dest_y, m_pScanline, m_pMaskScanline); | 914 m_pDest->ComposeScanline(dest_y, m_pScanline, m_pMaskScanline); |
915 } | 915 } |
916 return FALSE; | 916 return FALSE; |
917 } | 917 } |
OLD | NEW |