LoginSignup
6
1

More than 5 years have passed since last update.

libpng を使ったアプリが実行時に `libpng warning: Interlace handling should be turned on when using png_read_image` を吐いてくれる時の正しい対処法

Posted at

概要

libpng を使ったアプリの実行中に以下のの警告表示が発生する場合の正しい対処方法をメモ。

warning

libpng warning: Interlace handling should be turned on when using png_read_image

原因

インターレースが有効なPNGを読み込む際に、png_set_interlace_handling しないまま png_read_image を呼んでしまっている。

対処方法

png_get_IHDR などで読み込むPNGの width や height などと併せて interlace の定数値も読めるので、 interlace の定数値が PNG_INTERLACE_NONE でなければ png_set_interlace_handling を呼んでから png_read_image するよう修正する。

...

// 本件で欲しい情報
int interlace_type = PNG_INTERLACE_NONE;

// 情報が要らないところは nullptr を渡す仕様
png_get_IHDR
( png.get()
, nullptr // info
, &width
, &height
, &bits_per_element
, &color_type
, &interlace_type
, nullptr // compression_type
, nullptr //filter_type
);

...

// 本件に必要な修正
if ( interlace_type != PNG_INTERLACE_NONE )
  png_set_interlace_handling( png.get() );

...

// read
png_read_image( png.get(), rows.data() );
png_read_end( png.get(), nullptr );

...

参考

6
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1