Skip to content

Commit

Permalink
Possible NullPointerException
Browse files Browse the repository at this point in the history
The EMFImageLoader is called multiple times without providing a BlendFunction. see freehep#43
This causes a NPE, in case the image is a 32 bit EMF.
I don't know if 0xFF is the correct default value, but at least this fixes the NPE.
  • Loading branch information
daRoof authored Jan 31, 2019
1 parent b36188d commit 2602d24
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,19 @@ protected static BufferedImage handle32Bit_RGB( EMFInputStream emf, int width, i
int off = 0;
int pixel;
int alpha;

int sourceConstantAlpha = 0xFF; // assume default value

// The SourceConstantaAlpha member of BLENDFUNCTION specifies an alpha transparency
// value to be used on the entire source bitmap. The SourceConstantAlpha value is
// combined with any per-pixel alpha values. If SourceConstantAlpha is 0, it is
// assumed that the image is transparent. Set the SourceConstantAlpha value to 255
// (which indicates that the image is opaque) when you only want to use per-pixel
// alpha values.
int sourceConstantAlpha = blendFunction.getSourceConstantAlpha();
if( null != blendFunction ) {
sourceConstantAlpha = blendFunction.getSourceConstantAlpha();
}

if( blendFunction.getAlphaFormat() != EMFConstants.AC_SRC_ALPHA )
if( null != blendFunction && blendFunction.getAlphaFormat() != EMFConstants.AC_SRC_ALPHA )
{
// If the source bitmap has no per-pixel alpha value (that is, AC_SRC_ALPHA is not
// set), the SourceConstantAlpha value determines the blend of the source and
Expand Down

0 comments on commit 2602d24

Please sign in to comment.