Skip to content

Commit

Permalink
Merge pull request #4 from Firstmol/3-sigsegv-fix
Browse files Browse the repository at this point in the history
#3 Sigegv fix
  • Loading branch information
ediweissmann authored May 8, 2020
2 parents a79b0bf + e9222c2 commit 9699326
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/javase/java/com/luciad/imageio/webp/WebPWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,22 @@ private static byte[] encode(WebPEncoderOptions aOptions, RenderedImage aImage)
throw new NullPointerException("Image may not be null");
}

boolean encodeAlpha = hasTranslucency(aImage);
if (encodeAlpha) {
byte[] rgbaData = getRGBA(aImage);
return WebP.encodeRGBA(aOptions, rgbaData, aImage.getWidth(), aImage.getHeight(), aImage.getWidth() * 4);
} else {
byte[] rgbData = getRGB(aImage);
return WebP.encodeRGB(aOptions, rgbData, aImage.getWidth(), aImage.getHeight(), aImage.getWidth() * 3);
ThreadLocal<WebPEncoderOptions> encoderThreadLocal = new ThreadLocal<>();
try {
encoderThreadLocal.set(aOptions);

byte[] pixels;
boolean encodeAlpha = hasTranslucency(aImage);
if (encodeAlpha) {
byte[] rgbaData = getRGBA(aImage);
pixels = WebP.encodeRGBA(aOptions, rgbaData, aImage.getWidth(), aImage.getHeight(), aImage.getWidth() * 4);
} else {
byte[] rgbData = getRGB(aImage);
pixels = WebP.encodeRGB(aOptions, rgbData, aImage.getWidth(), aImage.getHeight(), aImage.getWidth() * 3);
}
return pixels;
} finally {
encoderThreadLocal.remove();
}
}

Expand Down

0 comments on commit 9699326

Please sign in to comment.