//--------------------------------------------------------------------------- void __fastcall TDIBImage::FlipVertical() { if (m_OpenedPixels == NULL) return; int LineWidth = (((GetWidth()* 24 + 31)/32) * 4); int size = LineWidth*sizeof(unsigned char); unsigned char* buffer = (unsigned char*)malloc(size); if (buffer == NULL) return; for (int i = 0; i < GetHeight()/2; i++) { memcpy(buffer, GetScanline(i),size); memcpy(GetScanline(i),GetScanline(GetHeight()-1-i),size); memcpy(GetScanline(GetHeight()-1-i), buffer, size); } free(buffer); }
void ScannerSub::Error(LPSTR str){ nErrorCount++; fprintf(lpLogFP, "%s(%d):(Scanner)%s \n", GetFileName().c_str(), GetScanline(), str); }
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 nullptr; } CFX_DIBitmap* pTransBitmap = new CFX_DIBitmap; int result_height = dest_clip.Height(), result_width = dest_clip.Width(); if (!pTransBitmap->Create(result_width, result_height, GetFormat())) { delete pTransBitmap; return nullptr; } pTransBitmap->CopyPalette(m_pPalette.get()); int dest_pitch = pTransBitmap->GetPitch(); uint8_t* 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_memset(dest_buf, 0xff, dest_pitch * result_height); for (int row = row_start; row < row_end; row++) { const uint8_t* src_scan = GetScanline(row); int dest_col = (bXFlip ? dest_clip.right - (row - row_start) - 1 : row) - dest_clip.left; uint8_t* 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; uint8_t* dest_scan = dest_buf + dest_col * nBytes; if (bYFlip) { dest_scan += (result_height - 1) * dest_pitch; } if (nBytes == 4) { uint32_t* src_scan = (uint32_t*)GetScanline(row) + col_start; for (int col = col_start; col < col_end; col++) { *(uint32_t*)dest_scan = *src_scan++; dest_scan += dest_step; } } else { const uint8_t* 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) { 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; uint8_t* dest_scan = dest_buf + dest_col; if (bYFlip) { dest_scan += (result_height - 1) * dest_pitch; } const uint8_t* 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; }
long WriteJPEG( void* pJPEGWriter, void* pOStm, long nWidth, long nHeight, long bGreys, long nQualityPercent, void* pCallbackData ) { struct jpeg_compress_struct cinfo; struct my_error_mgr jerr; void* pScanline; long nY; // declare bCompCreated, bRet volatile because of gcc // warning: variable 'bCompCreated' might be clobbered by `longjmp' or `vfork' volatile long bCompCreated = 0; volatile long bRet = 0; if ( setjmp( jerr.setjmp_buffer ) ) goto Exit; cinfo.err = jpeg_std_error( &jerr.pub ); jerr.pub.error_exit = my_error_exit; jerr.pub.output_message = my_output_message; jpeg_create_compress( &cinfo ); bCompCreated = 1; jpeg_svstream_dest( &cinfo, pOStm ); cinfo.image_width = (JDIMENSION) nWidth; cinfo.image_height = (JDIMENSION) nHeight; if ( bGreys ) { cinfo.input_components = 1; cinfo.in_color_space = JCS_GRAYSCALE; } else { cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; } jpeg_set_defaults( &cinfo ); jpeg_set_quality( &cinfo, (int) nQualityPercent, sal_False ); if ( ( nWidth > 128 ) || ( nHeight > 128 ) ) jpeg_simple_progression( &cinfo ); jpeg_start_compress( &cinfo, sal_True ); for( nY = 0; nY < nHeight; nY++ ) { pScanline = GetScanline( pJPEGWriter, nY ); if( pScanline ) jpeg_write_scanlines( &cinfo, (JSAMPARRAY) &pScanline, 1 ); if( JPEGCallback( pCallbackData, nY * 100L / nHeight ) ) goto Exit; } bRet = 1; jpeg_finish_compress(&cinfo); Exit: if ( bCompCreated ) jpeg_destroy_compress( &cinfo ); return bRet; }