void CFX_BinaryBuf::AppendFill(FX_BYTE byte, FX_STRSIZE count) { ExpandBuf(count); if (!m_pBuffer) { return; } FXSYS_memset8(m_pBuffer + m_DataSize, byte, count); m_DataSize += count; }
int FPDFAPI_FlateOutput(void* context, unsigned char* dest_buf, unsigned int dest_size) { ((z_stream*)context)->next_out = dest_buf; ((z_stream*)context)->avail_out = dest_size; unsigned int pre_pos = (unsigned int)FPDFAPI_FlateGetTotalOut(context); int ret = inflate((z_stream*)context, Z_SYNC_FLUSH); unsigned int post_pos = (unsigned int)FPDFAPI_FlateGetTotalOut(context); unsigned int written = post_pos - pre_pos; if (written < dest_size) { FXSYS_memset8(dest_buf + written, '\0', dest_size - written); } return ret; }
FX_LPBYTE CCodec_RLScanlineDecoder::v_GetNextLine() { if (m_SrcOffset == 0) { GetNextOperator(); } else { if (m_bEOD) { return NULL; } } FXSYS_memset32(m_pScanline, 0, m_Pitch); FX_DWORD col_pos = 0; FX_BOOL eol = FALSE; while (m_SrcOffset < m_SrcSize && !eol) { if (m_Operator < 128) { FX_DWORD copy_len = m_Operator + 1; if (col_pos + copy_len >= m_dwLineBytes) { copy_len = m_dwLineBytes - col_pos; eol = TRUE; } if (copy_len >= m_SrcSize - m_SrcOffset) { copy_len = m_SrcSize - m_SrcOffset; m_bEOD = TRUE; } FXSYS_memcpy32(m_pScanline + col_pos, m_pSrcBuf + m_SrcOffset, copy_len); col_pos += copy_len; UpdateOperator((FX_BYTE)copy_len); } else if (m_Operator > 128) { int fill = 0; if (m_SrcOffset - 1 < m_SrcSize - 1) { fill = m_pSrcBuf[m_SrcOffset]; } FX_DWORD duplicate_len = 257 - m_Operator; if (col_pos + duplicate_len >= m_dwLineBytes) { duplicate_len = m_dwLineBytes - col_pos; eol = TRUE; } FXSYS_memset8(m_pScanline + col_pos, fill, duplicate_len); col_pos += duplicate_len; UpdateOperator((FX_BYTE)duplicate_len); } else { m_bEOD = TRUE; break; } } return m_pScanline; }
CFX_DIBitmap* CFX_DIBSource::SwapXY(FX_BOOL bXFlip, FX_BOOL bYFlip, const FX_RECT* pDestClip) const { FX_RECT dest_clip(0, 0, m_Height, m_Width); if (pDestClip) { dest_clip.Intersect(*pDestClip); } if (dest_clip.IsEmpty()) { return NULL; } CFX_DIBitmap* pTransBitmap = FX_NEW CFX_DIBitmap; if (!pTransBitmap) { return NULL; } int result_height = dest_clip.Height(), result_width = dest_clip.Width(); if (!pTransBitmap->Create(result_width, result_height, GetFormat())) { delete pTransBitmap; return NULL; } pTransBitmap->CopyPalette(m_pPalette); int src_pitch = m_Pitch; int dest_pitch = pTransBitmap->GetPitch(); FX_LPBYTE dest_buf = pTransBitmap->GetBuffer(); int row_start = bXFlip ? m_Height - dest_clip.right : dest_clip.left; int row_end = bXFlip ? m_Height - dest_clip.left : dest_clip.right; int col_start = bYFlip ? m_Width - dest_clip.bottom : dest_clip.top; int col_end = bYFlip ? m_Width - dest_clip.top : dest_clip.bottom; if (GetBPP() == 1) { FXSYS_memset8(dest_buf, 0xff, dest_pitch * result_height); for (int row = row_start; row < row_end; row ++) { FX_LPCBYTE src_scan = GetScanline(row); int dest_col = (bXFlip ? dest_clip.right - (row - row_start) - 1 : row) - dest_clip.left; FX_LPBYTE dest_scan = dest_buf; if (bYFlip) { dest_scan += (result_height - 1) * dest_pitch; } int dest_step = bYFlip ? -dest_pitch : dest_pitch; for (int col = col_start; col < col_end; col ++) { if (!(src_scan[col / 8] & (1 << (7 - col % 8)))) { dest_scan[dest_col / 8] &= ~(1 << (7 - dest_col % 8)); } dest_scan += dest_step; } } } else { int nBytes = GetBPP() / 8; int dest_step = bYFlip ? -dest_pitch : dest_pitch; if (nBytes == 3) { dest_step -= 2; } for (int row = row_start; row < row_end; row ++) { int dest_col = (bXFlip ? dest_clip.right - (row - row_start) - 1 : row) - dest_clip.left; FX_LPBYTE dest_scan = dest_buf + dest_col * nBytes; if (bYFlip) { dest_scan += (result_height - 1) * dest_pitch; } if (nBytes == 4) { FX_DWORD* src_scan = (FX_DWORD*)GetScanline(row) + col_start; for (int col = col_start; col < col_end; col ++) { *(FX_DWORD*)dest_scan = *src_scan++; dest_scan += dest_step; } } else { FX_LPCBYTE src_scan = GetScanline(row) + col_start * nBytes; if (nBytes == 1) for (int col = col_start; col < col_end; col ++) { *dest_scan = *src_scan++; dest_scan += dest_step; } else for (int col = col_start; col < col_end; col ++) { *dest_scan++ = *src_scan++; *dest_scan++ = *src_scan++; *dest_scan = *src_scan++; dest_scan += dest_step; } } } } if (m_pAlphaMask) { src_pitch = m_pAlphaMask->m_Pitch; dest_pitch = pTransBitmap->m_pAlphaMask->GetPitch(); dest_buf = pTransBitmap->m_pAlphaMask->GetBuffer(); int dest_step = bYFlip ? -dest_pitch : dest_pitch; for (int row = row_start; row < row_end; row ++) { int dest_col = (bXFlip ? dest_clip.right - (row - row_start) - 1 : row) - dest_clip.left; FX_LPBYTE dest_scan = dest_buf + dest_col; if (bYFlip) { dest_scan += (result_height - 1) * dest_pitch; } FX_LPCBYTE src_scan = m_pAlphaMask->GetScanline(row) + col_start; for (int col = col_start; col < col_end; col ++) { *dest_scan = *src_scan++; dest_scan += dest_step; } } } return pTransBitmap; }
CStretchEngine::CStretchEngine(IFX_ScanlineComposer* pDestBitmap, FXDIB_Format dest_format, int dest_width, int dest_height, const FX_RECT& clip_rect, const CFX_DIBSource* pSrcBitmap, int flags) { m_State = 0; m_DestFormat = dest_format; m_DestBpp = dest_format & 0xff; m_SrcBpp = pSrcBitmap->GetFormat() & 0xff; m_bHasAlpha = pSrcBitmap->GetFormat() & 0x200; m_pSrcPalette = pSrcBitmap->GetPalette(); m_pDestBitmap = pDestBitmap; m_DestWidth = dest_width; m_DestHeight = dest_height; m_pInterBuf = NULL; m_pExtraAlphaBuf = NULL; m_pDestMaskScanline = NULL; m_DestClip = clip_rect; FX_DWORD size = clip_rect.Width(); if (size && m_DestBpp > (int)(INT_MAX / size)) { return; } size *= m_DestBpp; if (size > INT_MAX - 31) { return; } size += 31; size = size / 32 * 4; m_pDestScanline = FX_AllocNL(FX_BYTE, size); if (m_pDestScanline == NULL) { return; } if (dest_format == FXDIB_Rgb32) { FXSYS_memset8(m_pDestScanline, 255, size); } m_InterPitch = (m_DestClip.Width() * m_DestBpp + 31) / 32 * 4; m_ExtraMaskPitch = (m_DestClip.Width() * 8 + 31) / 32 * 4; m_pInterBuf = NULL; m_pSource = pSrcBitmap; m_SrcWidth = pSrcBitmap->GetWidth(); m_SrcHeight = pSrcBitmap->GetHeight(); m_SrcPitch = (m_SrcWidth * m_SrcBpp + 31) / 32 * 4; if ((flags & FXDIB_NOSMOOTH) == 0) { FX_BOOL bInterpol = flags & FXDIB_INTERPOL || flags & FXDIB_BICUBIC_INTERPOL; if (!bInterpol && FXSYS_abs(dest_width) != 0 && FXSYS_abs(dest_height) < m_SrcWidth * m_SrcHeight * 8 / FXSYS_abs(dest_width)) { flags = FXDIB_INTERPOL; } m_Flags = flags; } else { m_Flags = FXDIB_NOSMOOTH; if (flags & FXDIB_DOWNSAMPLE) { m_Flags |= FXDIB_DOWNSAMPLE; } } double scale_x = FXSYS_Div((FX_FLOAT)(m_SrcWidth), (FX_FLOAT)(m_DestWidth)); double scale_y = FXSYS_Div((FX_FLOAT)(m_SrcHeight), (FX_FLOAT)(m_DestHeight)); double base_x = m_DestWidth > 0 ? 0.0f : (FX_FLOAT)(m_DestWidth); double base_y = m_DestHeight > 0 ? 0.0f : (FX_FLOAT)(m_DestHeight); double src_left = FXSYS_Mul(scale_x, (FX_FLOAT)(clip_rect.left) + base_x); double src_right = FXSYS_Mul(scale_x, (FX_FLOAT)(clip_rect.right) + base_x); double src_top = FXSYS_Mul(scale_y, (FX_FLOAT)(clip_rect.top) + base_y); double src_bottom = FXSYS_Mul(scale_y, (FX_FLOAT)(clip_rect.bottom) + base_y); if (src_left > src_right) { double temp = src_left; src_left = src_right; src_right = temp; } if (src_top > src_bottom) { double temp = src_top; src_top = src_bottom; src_bottom = temp; } m_SrcClip.left = (int)FXSYS_floor((FX_FLOAT)src_left); m_SrcClip.right = (int)FXSYS_ceil((FX_FLOAT)src_right); m_SrcClip.top = (int)FXSYS_floor((FX_FLOAT)src_top); m_SrcClip.bottom = (int)FXSYS_ceil((FX_FLOAT)src_bottom); FX_RECT src_rect(0, 0, m_SrcWidth, m_SrcHeight); m_SrcClip.Intersect(src_rect); if (m_SrcBpp == 1) { if (m_DestBpp == 8) { m_TransMethod = 1; } else { m_TransMethod = 2; } } else if (m_SrcBpp == 8) { if (m_DestBpp == 8) { if (!m_bHasAlpha) { m_TransMethod = 3; } else { m_TransMethod = 4; } } else { if (!m_bHasAlpha) { m_TransMethod = 5; } else { m_TransMethod = 6; } } } else { if (!m_bHasAlpha) { m_TransMethod = 7; } else { m_TransMethod = 8; } } }