libpngを使用してPNGファイルを読み取り、フィルターpng_set_rgb_to_gray_fixedを使用してRGB値をグレースケールに変換したいと思います。元の画像はチャネルあたり8ビット、つまりピクセルあたり3バイトです。出力は1ピクセルあたり8ビットになると思います。ただし、png_get_rowbytesは、行サイズが3*widthであることを示しています。私が間違っているのは何ですか?
これが私のコードです(簡潔にするためにエラーチェックコードを削除しました):
FILE *fp = fopen(filename,"rb");
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
png_infop info_ptr = png_create_info_struct(png_ptr);
png_infop end_info = png_create_info_struct(png_ptr);
png_init_io(png_ptr, fp);
png_uint_32 width,height;
int color_depth,color_type, interlace_type, compression_type, filter_method;
png_read_info(png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height,
&color_depth, &color_type, &interlace_type,
&compression_type, &filter_method);
assert(color_type == PNG_COLOR_TYPE_RGB);
png_set_rgb_to_gray_fixed(png_ptr, 3,-1,-1);
int rowbytes = png_get_rowbytes(png_ptr, info_ptr);
assert(rowbytes == width ); // FAILS: rowbytes == 3*width