PNG を表す byteArray がありますが、これを webP に変換したいと考えています。次のコードがあります。コードで com.sksamuel.scrimage.Image を使用し、システム ライブラリ webp_jni をロードします。
val image = Image(content) //content of PNG of type Array[Byte]
extension match {
case "webp" => Ok(
libwebp.WebPEncodeRGB(
image.write,
image.width,
image.height,
image.width * 3,
80F)
).as("image/webp")
case _ => Ok(image.write).as("image/png")
}
png 画像をリクエストするとすべて正常に動作しますが、webP 画像をリクエストすると、次のようになります。
# SIGSEGV (0xb) at pc=0x00007fc008287377, pid=14883, tid=140461610465024
#
# JRE version: Java(TM) SE Runtime Environment (8.0_05-b13) (build 1.8.0_05-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.5-b02 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libwebp.so.5+0x33377] WebPPictureAlloc+0x407
ストライド入力 image.width に他の値を試してみました。image.width は 4 の倍数に丸められ、image.width は 3 の倍数に丸められました。この場合、クラッシュしませんが、画像は非常にノイズが多く、オリジナル。