FX_BOOL CPDF_ImageRenderer::StartBitmapAlpha() { if (m_pDIBSource->IsOpaqueImage()) { CFX_PathData path; path.AppendRect(0, 0, 1, 1); path.Transform(&m_ImageMatrix); FX_DWORD fill_color = ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha); m_pRenderStatus->m_pDevice->DrawPath(&path, NULL, NULL, fill_color, 0, FXFILL_WINDING); } else { const CFX_DIBSource* pAlphaMask = m_pDIBSource->IsAlphaMask() ? m_pDIBSource : m_pDIBSource->GetAlphaMask(); if (FXSYS_fabs(m_ImageMatrix.b) >= 0.5f || FXSYS_fabs(m_ImageMatrix.c) >= 0.5f) { int left, top; nonstd::unique_ptr<CFX_DIBitmap> pTransformed( pAlphaMask->TransformTo(&m_ImageMatrix, left, top)); if (!pTransformed) return TRUE; m_pRenderStatus->m_pDevice->SetBitMask( pTransformed.get(), left, top, ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha)); } else { CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect(); FX_RECT image_rect = image_rect_f.GetOutterRect(); int dest_width = m_ImageMatrix.a > 0 ? image_rect.Width() : -image_rect.Width(); int dest_height = m_ImageMatrix.d > 0 ? -image_rect.Height() : image_rect.Height(); int left = dest_width > 0 ? image_rect.left : image_rect.right; int top = dest_height > 0 ? image_rect.top : image_rect.bottom; m_pRenderStatus->m_pDevice->StretchBitMask( pAlphaMask, left, top, dest_width, dest_height, ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha)); } if (m_pDIBSource != pAlphaMask) { delete pAlphaMask; } } return FALSE; }
FX_BOOL CFX_ImageTransformer::Continue(IFX_Pause* pPause) { if (m_Status == 1) { if (m_Stretcher->Continue(pPause)) return TRUE; if (m_Storer.GetBitmap()) { std::unique_ptr<CFX_DIBitmap> swapped( m_Storer.GetBitmap()->SwapXY(m_pMatrix->c > 0, m_pMatrix->b < 0)); m_Storer.Replace(std::move(swapped)); } return FALSE; } if (m_Status == 2) return m_Stretcher->Continue(pPause); if (m_Status != 3) return FALSE; if (m_Stretcher->Continue(pPause)) return TRUE; int stretch_width = m_StretchClip.Width(); int stretch_height = m_StretchClip.Height(); if (!m_Storer.GetBitmap()) return FALSE; const uint8_t* stretch_buf = m_Storer.GetBitmap()->GetBuffer(); const uint8_t* stretch_buf_mask = nullptr; if (m_Storer.GetBitmap()->m_pAlphaMask) stretch_buf_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetBuffer(); int stretch_pitch = m_Storer.GetBitmap()->GetPitch(); std::unique_ptr<CFX_DIBitmap> pTransformed(new CFX_DIBitmap); FXDIB_Format transformF = GetTransformedFormat(m_Stretcher->source()); if (!pTransformed->Create(m_result.Width(), m_result.Height(), transformF)) return FALSE; pTransformed->Clear(0); if (pTransformed->m_pAlphaMask) pTransformed->m_pAlphaMask->Clear(0); CFX_Matrix result2stretch(1.0f, 0.0f, 0.0f, 1.0f, (FX_FLOAT)(m_result.left), (FX_FLOAT)(m_result.top)); result2stretch.Concat(m_dest2stretch); result2stretch.TranslateI(-m_StretchClip.left, -m_StretchClip.top); if (!stretch_buf_mask && pTransformed->m_pAlphaMask) { pTransformed->m_pAlphaMask->Clear(0xff000000); } else if (pTransformed->m_pAlphaMask) { int stretch_pitch_mask = m_Storer.GetBitmap()->m_pAlphaMask->GetPitch(); if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); for (int row = 0; row < m_result.Height(); row++) { uint8_t* dest_pos_mask = (uint8_t*)pTransformed->m_pAlphaMask->GetScanline(row); for (int col = 0; col < m_result.Width(); col++) { int src_col_l, src_row_l, res_x, res_y; result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, res_y); if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && src_row_l <= stretch_height) { if (src_col_l == stretch_width) { src_col_l--; } if (src_row_l == stretch_height) { src_row_l--; } int src_col_r = src_col_l + 1; int src_row_r = src_row_l + 1; if (src_col_r == stretch_width) { src_col_r--; } if (src_row_r == stretch_height) { src_row_r--; } int row_offset_l = src_row_l * stretch_pitch_mask; int row_offset_r = src_row_r * stretch_pitch_mask; *dest_pos_mask = bilinear_interpol(stretch_buf_mask, row_offset_l, row_offset_r, src_col_l, src_col_r, res_x, res_y, 1, 0); } dest_pos_mask++; } } } else if (m_Flags & FXDIB_BICUBIC_INTERPOL) { CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); for (int row = 0; row < m_result.Height(); row++) { uint8_t* dest_pos_mask = (uint8_t*)pTransformed->m_pAlphaMask->GetScanline(row); for (int col = 0; col < m_result.Width(); col++) { int src_col_l, src_row_l, res_x, res_y; result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, res_y); if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && src_row_l <= stretch_height) { int pos_pixel[8]; int u_w[4], v_w[4]; if (src_col_l == stretch_width) { src_col_l--; } if (src_row_l == stretch_height) { src_row_l--; } bicubic_get_pos_weight(pos_pixel, u_w, v_w, src_col_l, src_row_l, res_x, res_y, stretch_width, stretch_height); *dest_pos_mask = bicubic_interpol(stretch_buf_mask, stretch_pitch_mask, pos_pixel, u_w, v_w, res_x, res_y, 1, 0); } dest_pos_mask++; } } } else { CPDF_FixedMatrix result2stretch_fix(result2stretch, 8); for (int row = 0; row < m_result.Height(); row++) { uint8_t* dest_pos_mask = (uint8_t*)pTransformed->m_pAlphaMask->GetScanline(row); for (int col = 0; col < m_result.Width(); col++) { int src_col, src_row; result2stretch_fix.Transform(col, row, src_col, src_row); if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 && src_row <= stretch_height) { if (src_col == stretch_width) { src_col--; } if (src_row == stretch_height) { src_row--; } *dest_pos_mask = stretch_buf_mask[src_row * stretch_pitch_mask + src_col]; } dest_pos_mask++; } } } } if (m_Storer.GetBitmap()->IsAlphaMask()) { if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); for (int row = 0; row < m_result.Height(); row++) { uint8_t* dest_scan = (uint8_t*)pTransformed->GetScanline(row); for (int col = 0; col < m_result.Width(); col++) { int src_col_l, src_row_l, res_x, res_y; result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, res_y); if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && src_row_l <= stretch_height) { if (src_col_l == stretch_width) { src_col_l--; } if (src_row_l == stretch_height) { src_row_l--; } int src_col_r = src_col_l + 1; int src_row_r = src_row_l + 1; if (src_col_r == stretch_width) { src_col_r--; } if (src_row_r == stretch_height) { src_row_r--; } int row_offset_l = src_row_l * stretch_pitch; int row_offset_r = src_row_r * stretch_pitch; *dest_scan = bilinear_interpol(stretch_buf, row_offset_l, row_offset_r, src_col_l, src_col_r, res_x, res_y, 1, 0); } dest_scan++; } } } else if (m_Flags & FXDIB_BICUBIC_INTERPOL) { CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); for (int row = 0; row < m_result.Height(); row++) { uint8_t* dest_scan = (uint8_t*)pTransformed->GetScanline(row); for (int col = 0; col < m_result.Width(); col++) { int src_col_l, src_row_l, res_x, res_y; result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, res_y); if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && src_row_l <= stretch_height) { int pos_pixel[8]; int u_w[4], v_w[4]; if (src_col_l == stretch_width) { src_col_l--; } if (src_row_l == stretch_height) { src_row_l--; } bicubic_get_pos_weight(pos_pixel, u_w, v_w, src_col_l, src_row_l, res_x, res_y, stretch_width, stretch_height); *dest_scan = bicubic_interpol(stretch_buf, stretch_pitch, pos_pixel, u_w, v_w, res_x, res_y, 1, 0); } dest_scan++; } } } else { CPDF_FixedMatrix result2stretch_fix(result2stretch, 8); for (int row = 0; row < m_result.Height(); row++) { uint8_t* dest_scan = (uint8_t*)pTransformed->GetScanline(row); for (int col = 0; col < m_result.Width(); col++) { int src_col, src_row; result2stretch_fix.Transform(col, row, src_col, src_row); if (src_col >= 0 && src_col <= stretch_width && src_row >= 0 && src_row <= stretch_height) { if (src_col == stretch_width) { src_col--; } if (src_row == stretch_height) { src_row--; } const uint8_t* src_pixel = stretch_buf + stretch_pitch * src_row + src_col; *dest_scan = *src_pixel; } dest_scan++; } } } } else { int Bpp = m_Storer.GetBitmap()->GetBPP() / 8; if (Bpp == 1) { uint32_t argb[256]; FX_ARGB* pPal = m_Storer.GetBitmap()->GetPalette(); if (pPal) { for (int i = 0; i < 256; i++) { argb[i] = pPal[i]; } } else { if (m_Storer.GetBitmap()->IsCmykImage()) { for (int i = 0; i < 256; i++) { argb[i] = 255 - i; } } else { for (int i = 0; i < 256; i++) { argb[i] = 0xff000000 | (i * 0x010101); } } } int destBpp = pTransformed->GetBPP() / 8; if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); for (int row = 0; row < m_result.Height(); row++) { uint8_t* dest_pos = (uint8_t*)pTransformed->GetScanline(row); for (int col = 0; col < m_result.Width(); col++) { int src_col_l, src_row_l, res_x, res_y; result2stretch_fix.Transform(col, row, src_col_l, src_row_l, res_x, res_y); if (src_col_l >= 0 && src_col_l <= stretch_width && src_row_l >= 0 && src_row_l <= stretch_height) { if (src_col_l == stretch_width) { src_col_l--; } if (src_row_l == stretch_height) { src_row_l--; } int src_col_r = src_col_l + 1; int src_row_r = src_row_l + 1; if (src_col_r == stretch_width) { src_col_r--; } if (src_row_r == stretch_height) { src_row_r--; } int row_offset_l = src_row_l * stretch_pitch; int row_offset_r = src_row_r * stretch_pitch; uint32_t r_bgra_cmyk = argb[bilinear_interpol( stretch_buf, row_offset_l, row_offset_r, src_col_l, src_col_r, res_x, res_y, 1, 0)]; if (transformF == FXDIB_Rgba) { dest_pos[0] = (uint8_t)(r_bgra_cmyk >> 24); dest_pos[1] = (uint8_t)(r_bgra_cmyk >> 16); dest_pos[2] = (uint8_t)(r_bgra_cmyk >> 8); } else { *(uint32_t*)dest_pos = r_bgra_cmyk; } } dest_pos += destBpp; } }