Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: core/src/fxge/dib/fx_dib_transform.cpp

Issue 1252613002: FX_BOOL considered harmful. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Manual edits. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxge/dib/fx_dib_main.cpp ('k') | core/src/fxge/ge/fx_ge_device.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/fxge/fx_dib.h" 7 #include "../../../include/fxge/fx_dib.h"
8 #include "dib_int.h" 8 #include "dib_int.h"
9 int SDP_Table[513] = { 9 int SDP_Table[513] = {
10 256, 256, 256, 256, 256, 256, 256, 256, 256, 255, 255, 255, 255, 255, 255, 2 54, 254, 254, 254, 10 256, 256, 256, 256, 256, 256, 256, 256, 256, 255, 255, 255, 255, 255, 255, 2 54, 254, 254, 254,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 if (res_x < 0 && res_x > -base) { 47 if (res_x < 0 && res_x > -base) {
48 res_x = base + res_x; 48 res_x = base + res_x;
49 } 49 }
50 if (res_y < 0 && res_x > -base) { 50 if (res_y < 0 && res_x > -base) {
51 res_y = base + res_y; 51 res_y = base + res_y;
52 } 52 }
53 x1 /= base; 53 x1 /= base;
54 y1 /= base; 54 y1 /= base;
55 } 55 }
56 }; 56 };
57 CFX_DIBitmap* CFX_DIBSource::SwapXY(FX_BOOL bXFlip, FX_BOOL bYFlip, const FX_REC T* pDestClip) const 57 CFX_DIBitmap* CFX_DIBSource::SwapXY(bool bXFlip, bool bYFlip, const FX_RECT* pDe stClip) const
58 { 58 {
59 FX_RECT dest_clip(0, 0, m_Height, m_Width); 59 FX_RECT dest_clip(0, 0, m_Height, m_Width);
60 if (pDestClip) { 60 if (pDestClip) {
61 dest_clip.Intersect(*pDestClip); 61 dest_clip.Intersect(*pDestClip);
62 } 62 }
63 if (dest_clip.IsEmpty()) { 63 if (dest_clip.IsEmpty()) {
64 return NULL; 64 return NULL;
65 } 65 }
66 CFX_DIBitmap* pTransBitmap = new CFX_DIBitmap; 66 CFX_DIBitmap* pTransBitmap = new CFX_DIBitmap;
67 int result_height = dest_clip.Height(), result_width = dest_clip.Width(); 67 int result_height = dest_clip.Height(), result_width = dest_clip.Width();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 const uint8_t* src_scan = m_pAlphaMask->GetScanline(row) + col_start ; 141 const uint8_t* src_scan = m_pAlphaMask->GetScanline(row) + col_start ;
142 for (int col = col_start; col < col_end; col ++) { 142 for (int col = col_start; col < col_end; col ++) {
143 *dest_scan = *src_scan++; 143 *dest_scan = *src_scan++;
144 dest_scan += dest_step; 144 dest_scan += dest_step;
145 } 145 }
146 } 146 }
147 } 147 }
148 return pTransBitmap; 148 return pTransBitmap;
149 } 149 }
150 #define FIX16_005 0.05f 150 #define FIX16_005 0.05f
151 FX_RECT _FXDIB_SwapClipBox(FX_RECT& clip, int width, int height, FX_BOOL bFlipX, FX_BOOL bFlipY) 151 FX_RECT _FXDIB_SwapClipBox(FX_RECT& clip, int width, int height, bool bFlipX, bo ol bFlipY)
152 { 152 {
153 FX_RECT rect; 153 FX_RECT rect;
154 if (bFlipY) { 154 if (bFlipY) {
155 rect.left = height - clip.top; 155 rect.left = height - clip.top;
156 rect.right = height - clip.bottom; 156 rect.right = height - clip.bottom;
157 } else { 157 } else {
158 rect.left = clip.top; 158 rect.left = clip.top;
159 rect.right = clip.bottom; 159 rect.right = clip.bottom;
160 } 160 }
161 if (bFlipX) { 161 if (bFlipX) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 return storer.Detach(); 199 return storer.Detach();
200 } 200 }
201 CFX_ImageTransformer::CFX_ImageTransformer() 201 CFX_ImageTransformer::CFX_ImageTransformer()
202 { 202 {
203 m_Status = 0; 203 m_Status = 0;
204 m_pMatrix = NULL; 204 m_pMatrix = NULL;
205 } 205 }
206 CFX_ImageTransformer::~CFX_ImageTransformer() 206 CFX_ImageTransformer::~CFX_ImageTransformer()
207 { 207 {
208 } 208 }
209 FX_BOOL CFX_ImageTransformer::Start(const CFX_DIBSource* pSrc, const CFX_AffineM atrix* pDestMatrix, int flags, const FX_RECT* pDestClip) 209 bool CFX_ImageTransformer::Start(const CFX_DIBSource* pSrc, const CFX_AffineMatr ix* pDestMatrix, int flags, const FX_RECT* pDestClip)
210 { 210 {
211 m_pMatrix = (CFX_AffineMatrix*)pDestMatrix; 211 m_pMatrix = (CFX_AffineMatrix*)pDestMatrix;
212 CFX_FloatRect unit_rect = pDestMatrix->GetUnitRect(); 212 CFX_FloatRect unit_rect = pDestMatrix->GetUnitRect();
213 FX_RECT result_rect = unit_rect.GetClosestRect(); 213 FX_RECT result_rect = unit_rect.GetClosestRect();
214 FX_RECT result_clip = result_rect; 214 FX_RECT result_clip = result_rect;
215 if (pDestClip) { 215 if (pDestClip) {
216 result_clip.Intersect(*pDestClip); 216 result_clip.Intersect(*pDestClip);
217 } 217 }
218 if (result_clip.IsEmpty()) { 218 if (result_clip.IsEmpty()) {
219 return FALSE; 219 return false;
220 } 220 }
221 m_ResultLeft = result_clip.left; 221 m_ResultLeft = result_clip.left;
222 m_ResultTop = result_clip.top; 222 m_ResultTop = result_clip.top;
223 m_ResultWidth = result_clip.Width(); 223 m_ResultWidth = result_clip.Width();
224 m_ResultHeight = result_clip.Height(); 224 m_ResultHeight = result_clip.Height();
225 m_Flags = flags; 225 m_Flags = flags;
226 if (FXSYS_fabs(pDestMatrix->a) < FXSYS_fabs(pDestMatrix->b) / 20 && 226 if (FXSYS_fabs(pDestMatrix->a) < FXSYS_fabs(pDestMatrix->b) / 20 &&
227 FXSYS_fabs(pDestMatrix->d) < FXSYS_fabs(pDestMatrix->c) / 20 && 227 FXSYS_fabs(pDestMatrix->d) < FXSYS_fabs(pDestMatrix->c) / 20 &&
228 FXSYS_fabs(pDestMatrix->a) < 0.5f && FXSYS_fabs(pDestMatrix->d) < 0. 5f) { 228 FXSYS_fabs(pDestMatrix->a) < 0.5f && FXSYS_fabs(pDestMatrix->d) < 0. 5f) {
229 int dest_width = result_rect.Width(); 229 int dest_width = result_rect.Width();
230 int dest_height = result_rect.Height(); 230 int dest_height = result_rect.Height();
231 result_clip.Offset(-result_rect.left, -result_rect.top); 231 result_clip.Offset(-result_rect.left, -result_rect.top);
232 result_clip = _FXDIB_SwapClipBox(result_clip, dest_width, dest_height, p DestMatrix->c > 0, pDestMatrix->b < 0); 232 result_clip = _FXDIB_SwapClipBox(result_clip, dest_width, dest_height, p DestMatrix->c > 0, pDestMatrix->b < 0);
233 m_Stretcher.Start(&m_Storer, pSrc, dest_height, dest_width, result_clip, flags); 233 m_Stretcher.Start(&m_Storer, pSrc, dest_height, dest_width, result_clip, flags);
234 m_Status = 1; 234 m_Status = 1;
235 return TRUE; 235 return true;
236 } 236 }
237 if (FXSYS_fabs(pDestMatrix->b) < FIX16_005 && FXSYS_fabs(pDestMatrix->c) < F IX16_005) { 237 if (FXSYS_fabs(pDestMatrix->b) < FIX16_005 && FXSYS_fabs(pDestMatrix->c) < F IX16_005) {
238 int dest_width = pDestMatrix->a > 0 ? (int)FXSYS_ceil(pDestMatrix->a) : (int)FXSYS_floor(pDestMatrix->a); 238 int dest_width = pDestMatrix->a > 0 ? (int)FXSYS_ceil(pDestMatrix->a) : (int)FXSYS_floor(pDestMatrix->a);
239 int dest_height = pDestMatrix->d > 0 ? (int) - FXSYS_ceil(pDestMatrix->d ) : (int) - FXSYS_floor(pDestMatrix->d); 239 int dest_height = pDestMatrix->d > 0 ? (int) - FXSYS_ceil(pDestMatrix->d ) : (int) - FXSYS_floor(pDestMatrix->d);
240 result_clip.Offset(-result_rect.left, -result_rect.top); 240 result_clip.Offset(-result_rect.left, -result_rect.top);
241 m_Stretcher.Start(&m_Storer, pSrc, dest_width, dest_height, result_clip, flags); 241 m_Stretcher.Start(&m_Storer, pSrc, dest_width, dest_height, result_clip, flags);
242 m_Status = 2; 242 m_Status = 2;
243 return TRUE; 243 return true;
244 } 244 }
245 int stretch_width = (int)FXSYS_ceil(FXSYS_sqrt2(pDestMatrix->a, pDestMatrix- >b)); 245 int stretch_width = (int)FXSYS_ceil(FXSYS_sqrt2(pDestMatrix->a, pDestMatrix- >b));
246 int stretch_height = (int)FXSYS_ceil(FXSYS_sqrt2(pDestMatrix->c, pDestMatrix ->d)); 246 int stretch_height = (int)FXSYS_ceil(FXSYS_sqrt2(pDestMatrix->c, pDestMatrix ->d));
247 CFX_AffineMatrix stretch2dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, (FX_FLOAT)(stre tch_height)); 247 CFX_AffineMatrix stretch2dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, (FX_FLOAT)(stre tch_height));
248 stretch2dest.Concat(pDestMatrix->a / stretch_width, pDestMatrix->b / stretch _width, 248 stretch2dest.Concat(pDestMatrix->a / stretch_width, pDestMatrix->b / stretch _width,
249 pDestMatrix->c / stretch_height, pDestMatrix->d / stretc h_height, pDestMatrix->e, pDestMatrix->f); 249 pDestMatrix->c / stretch_height, pDestMatrix->d / stretc h_height, pDestMatrix->e, pDestMatrix->f);
250 m_dest2stretch.SetReverse(stretch2dest); 250 m_dest2stretch.SetReverse(stretch2dest);
251 CFX_FloatRect clip_rect_f(result_clip); 251 CFX_FloatRect clip_rect_f(result_clip);
252 clip_rect_f.Transform(&m_dest2stretch); 252 clip_rect_f.Transform(&m_dest2stretch);
253 m_StretchClip = clip_rect_f.GetOutterRect(); 253 m_StretchClip = clip_rect_f.GetOutterRect();
254 m_StretchClip.Intersect(0, 0, stretch_width, stretch_height); 254 m_StretchClip.Intersect(0, 0, stretch_width, stretch_height);
255 m_Stretcher.Start(&m_Storer, pSrc, stretch_width, stretch_height, m_StretchC lip, flags); 255 m_Stretcher.Start(&m_Storer, pSrc, stretch_width, stretch_height, m_StretchC lip, flags);
256 m_Status = 3; 256 m_Status = 3;
257 return TRUE; 257 return true;
258 } 258 }
259 uint8_t _bilinear_interpol(const uint8_t* buf, int row_offset_l, int row_offset_ r, 259 uint8_t _bilinear_interpol(const uint8_t* buf, int row_offset_l, int row_offset_ r,
260 int src_col_l, int src_col_r, int res_x, int res_y, 260 int src_col_l, int src_col_r, int res_x, int res_y,
261 int bpp, int c_offset) 261 int bpp, int c_offset)
262 { 262 {
263 int i_resx = 255 - res_x; 263 int i_resx = 255 - res_x;
264 int col_bpp_l = src_col_l * bpp; 264 int col_bpp_l = src_col_l * bpp;
265 int col_bpp_r = src_col_r * bpp; 265 int col_bpp_r = src_col_r * bpp;
266 const uint8_t* buf_u = buf + row_offset_l + c_offset; 266 const uint8_t* buf_u = buf + row_offset_l + c_offset;
267 const uint8_t* buf_d = buf + row_offset_r + c_offset; 267 const uint8_t* buf_d = buf + row_offset_r + c_offset;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 format = FXDIB_8bppMask; 328 format = FXDIB_8bppMask;
329 } else if (format >= 1025) { 329 } else if (format >= 1025) {
330 format = FXDIB_Cmyka; 330 format = FXDIB_Cmyka;
331 } else if (format <= 32 || format == FXDIB_Argb) { 331 } else if (format <= 32 || format == FXDIB_Argb) {
332 format = FXDIB_Argb; 332 format = FXDIB_Argb;
333 } else { 333 } else {
334 format = FXDIB_Rgba; 334 format = FXDIB_Rgba;
335 } 335 }
336 return format; 336 return format;
337 } 337 }
338 FX_BOOL CFX_ImageTransformer::Continue(IFX_Pause* pPause) 338 bool CFX_ImageTransformer::Continue(IFX_Pause* pPause)
339 { 339 {
340 if (m_Status == 1) { 340 if (m_Status == 1) {
341 if (m_Stretcher.Continue(pPause)) { 341 if (m_Stretcher.Continue(pPause)) {
342 return TRUE; 342 return true;
343 } 343 }
344 if (m_Storer.GetBitmap()) { 344 if (m_Storer.GetBitmap()) {
345 m_Storer.Replace(m_Storer.GetBitmap()->SwapXY(m_pMatrix->c > 0, m_pM atrix->b < 0)); 345 m_Storer.Replace(m_Storer.GetBitmap()->SwapXY(m_pMatrix->c > 0, m_pM atrix->b < 0));
346 } 346 }
347 return FALSE; 347 return false;
348 } else if (m_Status == 2) { 348 } else if (m_Status == 2) {
349 return m_Stretcher.Continue(pPause); 349 return m_Stretcher.Continue(pPause);
350 } else if (m_Status != 3) { 350 } else if (m_Status != 3) {
351 return FALSE; 351 return false;
352 } 352 }
353 if (m_Stretcher.Continue(pPause)) { 353 if (m_Stretcher.Continue(pPause)) {
354 return TRUE; 354 return true;
355 } 355 }
356 int stretch_width = m_StretchClip.Width(); 356 int stretch_width = m_StretchClip.Width();
357 int stretch_height = m_StretchClip.Height(); 357 int stretch_height = m_StretchClip.Height();
358 if (m_Storer.GetBitmap() == NULL) { 358 if (m_Storer.GetBitmap() == NULL) {
359 return FALSE; 359 return false;
360 } 360 }
361 const uint8_t* stretch_buf = m_Storer.GetBitmap()->GetBuffer(); 361 const uint8_t* stretch_buf = m_Storer.GetBitmap()->GetBuffer();
362 const uint8_t* stretch_buf_mask = NULL; 362 const uint8_t* stretch_buf_mask = NULL;
363 if (m_Storer.GetBitmap()->m_pAlphaMask) { 363 if (m_Storer.GetBitmap()->m_pAlphaMask) {
364 stretch_buf_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetBuffer(); 364 stretch_buf_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetBuffer();
365 } 365 }
366 int stretch_pitch = m_Storer.GetBitmap()->GetPitch(); 366 int stretch_pitch = m_Storer.GetBitmap()->GetPitch();
367 CFX_DIBitmap* pTransformed = new CFX_DIBitmap; 367 CFX_DIBitmap* pTransformed = new CFX_DIBitmap;
368 FXDIB_Format transformF = _GetTransformedFormat(m_Stretcher.m_pSource); 368 FXDIB_Format transformF = _GetTransformedFormat(m_Stretcher.m_pSource);
369 if (!pTransformed->Create(m_ResultWidth, m_ResultHeight, transformF)) { 369 if (!pTransformed->Create(m_ResultWidth, m_ResultHeight, transformF)) {
370 delete pTransformed; 370 delete pTransformed;
371 return FALSE; 371 return false;
372 } 372 }
373 pTransformed->Clear(0); 373 pTransformed->Clear(0);
374 if (pTransformed->m_pAlphaMask) { 374 if (pTransformed->m_pAlphaMask) {
375 pTransformed->m_pAlphaMask->Clear(0); 375 pTransformed->m_pAlphaMask->Clear(0);
376 } 376 }
377 CFX_AffineMatrix result2stretch(1.0f, 0.0f, 0.0f, 1.0f, (FX_FLOAT)(m_ResultL eft), (FX_FLOAT)(m_ResultTop)); 377 CFX_AffineMatrix result2stretch(1.0f, 0.0f, 0.0f, 1.0f, (FX_FLOAT)(m_ResultL eft), (FX_FLOAT)(m_ResultTop));
378 result2stretch.Concat(m_dest2stretch); 378 result2stretch.Concat(m_dest2stretch);
379 result2stretch.TranslateI(-m_StretchClip.left, -m_StretchClip.top); 379 result2stretch.TranslateI(-m_StretchClip.left, -m_StretchClip.top);
380 if (stretch_buf_mask == NULL && pTransformed->m_pAlphaMask) { 380 if (stretch_buf_mask == NULL && pTransformed->m_pAlphaMask) {
381 pTransformed->m_pAlphaMask->Clear(0xff000000); 381 pTransformed->m_pAlphaMask->Clear(0xff000000);
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 dest_pos[2] = (uint8_t)(r_bgra_cmyk >> 8); 632 dest_pos[2] = (uint8_t)(r_bgra_cmyk >> 8);
633 } else { 633 } else {
634 *(FX_DWORD*)dest_pos = r_bgra_cmyk; 634 *(FX_DWORD*)dest_pos = r_bgra_cmyk;
635 } 635 }
636 } 636 }
637 dest_pos += destBpp; 637 dest_pos += destBpp;
638 } 638 }
639 } 639 }
640 } 640 }
641 } else { 641 } else {
642 FX_BOOL bHasAlpha = m_Storer.GetBitmap()->HasAlpha(); 642 bool bHasAlpha = m_Storer.GetBitmap()->HasAlpha();
643 int destBpp = pTransformed->GetBPP() / 8; 643 int destBpp = pTransformed->GetBPP() / 8;
644 if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTER POL)) { 644 if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTER POL)) {
645 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); 645 CFX_BilinearMatrix result2stretch_fix(result2stretch, 8);
646 for (int row = 0; row < m_ResultHeight; row ++) { 646 for (int row = 0; row < m_ResultHeight; row ++) {
647 uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row) ; 647 uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row) ;
648 for (int col = 0; col < m_ResultWidth; col ++) { 648 for (int col = 0; col < m_ResultWidth; col ++) {
649 int src_col_l, src_row_l, res_x, res_y, r_pos_k_r = 0; 649 int src_col_l, src_row_l, res_x, res_y, r_pos_k_r = 0;
650 result2stretch_fix.Transform(col, row, src_col_l, src_ro w_l, res_x, res_y); 650 result2stretch_fix.Transform(col, row, src_col_l, src_ro w_l, res_x, res_y);
651 if (src_col_l >= 0 && src_col_l <= stretch_width && src_ row_l >= 0 && src_row_l <= stretch_height) { 651 if (src_col_l >= 0 && src_col_l <= stretch_width && src_ row_l >= 0 && src_row_l <= stretch_height) {
652 if (src_col_l == stretch_width) { 652 if (src_col_l == stretch_width) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 } 777 }
778 } 778 }
779 } 779 }
780 dest_pos += destBpp; 780 dest_pos += destBpp;
781 } 781 }
782 } 782 }
783 } 783 }
784 } 784 }
785 } 785 }
786 m_Storer.Replace(pTransformed); 786 m_Storer.Replace(pTransformed);
787 return FALSE; 787 return false;
788 } 788 }
OLDNEW
« no previous file with comments | « core/src/fxge/dib/fx_dib_main.cpp ('k') | core/src/fxge/ge/fx_ge_device.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698