Cleanup jpeg bitmap creation & loading code
This commit is contained in:
@@ -328,17 +328,26 @@ JPEGReader::~JPEGReader()
|
|||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
void* JPEGReader::CreateBitmap( void* pParam )
|
void* JPEGReader::CreateBitmap( void* _pParam )
|
||||||
{
|
{
|
||||||
Size aSize( ((JPEGCreateBitmapParam*)pParam)->nWidth,
|
JPEGCreateBitmapParam *pParam = (JPEGCreateBitmapParam *) _pParam;
|
||||||
((JPEGCreateBitmapParam*)pParam)->nHeight );
|
|
||||||
sal_Bool bGray = ((JPEGCreateBitmapParam*)pParam)->bGray != 0;
|
if (pParam->nWidth > SAL_MAX_INT32/8 || pParam->nHeight > SAL_MAX_INT32/8)
|
||||||
|
return NULL; // avoid overflows later
|
||||||
|
|
||||||
|
Size aSize( pParam->nWidth, pParam->nHeight );
|
||||||
|
sal_Bool bGray = pParam->bGray != 0;
|
||||||
|
|
||||||
void* pBmpBuf = NULL;
|
void* pBmpBuf = NULL;
|
||||||
|
|
||||||
if( pAcc )
|
if( pAcc )
|
||||||
aBmp.ReleaseAccess( pAcc );
|
aBmp.ReleaseAccess( pAcc );
|
||||||
|
|
||||||
|
sal_uInt64 nSize = aSize.Width();
|
||||||
|
nSize *= aSize.Height();
|
||||||
|
if (nSize > SAL_MAX_INT32 / 24)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if( bGray )
|
if( bGray )
|
||||||
{
|
{
|
||||||
BitmapPalette aGrayPal( 256 );
|
BitmapPalette aGrayPal( 256 );
|
||||||
@@ -359,12 +368,11 @@ void* JPEGReader::CreateBitmap( void* pParam )
|
|||||||
unsigned long nUnit = ((JPEGCreateBitmapParam*)pParam)->density_unit;
|
unsigned long nUnit = ((JPEGCreateBitmapParam*)pParam)->density_unit;
|
||||||
|
|
||||||
if( ( ( 1 == nUnit ) || ( 2 == nUnit ) ) &&
|
if( ( ( 1 == nUnit ) || ( 2 == nUnit ) ) &&
|
||||||
( (JPEGCreateBitmapParam*) pParam )->X_density &&
|
pParam->X_density && pParam->Y_density )
|
||||||
( (JPEGCreateBitmapParam*) pParam )->Y_density )
|
|
||||||
{
|
{
|
||||||
Point aEmptyPoint;
|
Point aEmptyPoint;
|
||||||
Fraction aFractX( 1, ((JPEGCreateBitmapParam*)pParam)->X_density );
|
Fraction aFractX( 1, pParam->X_density );
|
||||||
Fraction aFractY( 1, ((JPEGCreateBitmapParam*)pParam)->Y_density );
|
Fraction aFractY( 1, pParam->Y_density );
|
||||||
MapMode aMapMode( nUnit == 1 ? MAP_INCH : MAP_CM, aEmptyPoint, aFractX, aFractY );
|
MapMode aMapMode( nUnit == 1 ? MAP_INCH : MAP_CM, aEmptyPoint, aFractX, aFractY );
|
||||||
Size aPrefSize = OutputDevice::LogicToLogic( aSize, aMapMode, MAP_100TH_MM );
|
Size aPrefSize = OutputDevice::LogicToLogic( aSize, aMapMode, MAP_100TH_MM );
|
||||||
|
|
||||||
@@ -377,8 +385,6 @@ void* JPEGReader::CreateBitmap( void* pParam )
|
|||||||
|
|
||||||
if( pAcc )
|
if( pAcc )
|
||||||
{
|
{
|
||||||
long nAlignedWidth;
|
|
||||||
|
|
||||||
const sal_uLong nFormat = pAcc->GetScanlineFormat();
|
const sal_uLong nFormat = pAcc->GetScanlineFormat();
|
||||||
|
|
||||||
if(
|
if(
|
||||||
@@ -387,16 +393,15 @@ void* JPEGReader::CreateBitmap( void* pParam )
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
pBmpBuf = pAcc->GetBuffer();
|
pBmpBuf = pAcc->GetBuffer();
|
||||||
nAlignedWidth = pAcc->GetScanlineSize();
|
pParam->nAlignedWidth = pAcc->GetScanlineSize();
|
||||||
((JPEGCreateBitmapParam*)pParam)->bTopDown = pAcc->IsTopDown();
|
pParam->bTopDown = pAcc->IsTopDown();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nAlignedWidth = AlignedWidth4Bytes( aSize.Width() * ( bGray ? 8 : 24 ) );
|
pParam->nAlignedWidth = AlignedWidth4Bytes( aSize.Width() * ( bGray ? 8 : 24 ) );
|
||||||
((JPEGCreateBitmapParam*)pParam)->bTopDown = sal_True;
|
pParam->bTopDown = sal_True;
|
||||||
pBmpBuf = pBuffer = rtl_allocateMemory( nAlignedWidth * aSize.Height() );
|
pBmpBuf = pBuffer = rtl_allocateMemory( pParam->nAlignedWidth * aSize.Height() );
|
||||||
}
|
}
|
||||||
((JPEGCreateBitmapParam*)pParam)->nAlignedWidth = nAlignedWidth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return pBmpBuf;
|
return pBmpBuf;
|
||||||
|
Reference in New Issue
Block a user