Page 1 of 1

Convert BPG from PNG

Posted: 2018-11-07T18:24:32-07:00
by dem123456789
I am a new user of ImageMagick. I download and install the newest version ImageMagick-7.0.8-14-Q16-x64-dll on Windows. I try to convert a png file to bpg file.
The png file is 199KB but the converted bpg file is 255KB. No matter what quality I set, the size is huge and PSNR is Inf(seems lossless).
The command I use is
convert mountain.png -quality 10 test.bpg
I do use imdisplay to show the test.bpg. It looks OK and I measure the PSNR which is Inf.
Where I do this wrong? I think BPG is lossy compression and should perform like JPEG right?

Re: Convert BPG from PNG

Posted: 2018-11-07T20:23:11-07:00
by fmw42
I am on a Mac and tried your command with the lena.png image, but am getting error messages with both IM 6.9.10.14 and 7.0.8.14. I am not sure if BPG is limited to Windows or not. The page at https://imagemagick.org/script/formats.php says nothing about OS limitations nor delegates. See this page about quality for BPG

No matter what quality I assign (10 or 92), it comes back with:

Code: Select all

magick lena.png -quality 92 lena.bpg
magick: delegate failed `'bpgenc' -b 12 -o '%o' '%i'' @ error/delegate.c/InvokeDelegate/1860.

Code: Select all

magick lena.png -quality 10 lena.bpg
magick: delegate failed `'bpgenc' -b 12 -o '%o' '%i'' @ error/delegate.c/InvokeDelegate/1860.

Looks like I would need to install the libbpg delegate.

Re: Convert BPG from PNG

Posted: 2018-11-07T20:54:28-07:00
by fmw42
OK, I installed libbpg. The lena.png image has file size of Filesize: 118327B

I ran the command

Code: Select all

magick -verbose lena.png -quality 10 lena.bpg
And the bpg file has file size 322131B. So the result is about 3 time the size of the original.

The verbose information shows the same bpg command no matter what -quality value

Code: Select all

bpgenc' -b 12 -o '/tmp/magick-26410khRDz3mnZsMF' '/tmp/magick-26410rNEMHSIvxtDw
It does not seem to be using the -q qp argument as shown at https://bellard.org/bpg/lena.html

bpgenc
BPG Image Encoder version 0.9.8
usage: bpgenc [options] infile.[jpg|png]

Main options:
-h show the full help (including the advanced options)
-o outfile set output filename (default = out.bpg)
-q qp set quantizer parameter (smaller gives better quality,
range: 0-51, default = 29)
-f cfmt set the preferred chroma format (420, 422, 444,
default=420)
-c color_space set the preferred color space (ycbcr, rgb, ycgco,
ycbcr_bt709, ycbcr_bt2020, default=ycbcr)
-b bit_depth set the bit depth (8 to 12, default =8)
-lossless enable lossless mode
-e encoder select the HEVC encoder (jctvc, default = jctvc)
-m level select the compression level (1=fast, 9=slow, default =8)

Animation options:
-a generate animations from a sequence of images. Use %d or
%Nd (N = number of digits) in the filename to specify the
image index, starting from 0 or 1.
-fps N set the frame rate (default = 25)
-loop N set the number of times the animation is played. 0 means
infinite (default = 0)
-delayfile file text file containing one number per image giving the
display delay per image in centiseconds.


Since smaller -q gives better quality, then the largest value should give the most compression and least quality. So when I do

Code: Select all

magick lena.png -quality 51 lena.bmp
The file size is still 322131B

Sorry, I know little about bpg. But this looks like a bug in ImageMagick in not passing the -quality argument to libbpg.

Re: Convert BPG from PNG

Posted: 2018-11-07T22:37:56-07:00
by dem123456789
So what I should do now? Report issue at GitHub and use native or other BPG converter?

Re: Convert BPG from PNG

Posted: 2018-11-07T22:46:03-07:00
by fmw42
dem123456789 wrote: 2018-11-07T22:37:56-07:00 So what I should do now? Report issue at GitHub and use native or other BPG converter?
Yes, report the bug at GitHub or here on the Bug's forum.

I looked into the delegates.xml file for the bpg entry, which follows. But it is only the decode entry.

Code: Select all

  <delegate decode="bpg" command="&quot;bpgdec&quot; -b 16 -o &quot;%o.png&quot; &quot;%i&quot;; /bin/mv &quot;%o.png&quot; &quot;%o&quot;"/>
See delegates.xml at https://imagemagick.org/script/resources.php

Re: Convert BPG from PNG

Posted: 2018-11-08T16:16:04-07:00
by fmw42
I tried adding this line to the delegates.xml file, since there was only a decode and not an encode entry for bpg:

Code: Select all

 <delegate encode="bpg" command="&quot;bpgenc&quot; -b 8 -q 50 -o &quot;%o.png&quot; &quot;%i&quot;; /bin/mv &quot;%o.png&quot; &quot;%o&quot;"/>
I tried both -q 50 and -q 10, but still get the same file size as when this entry was not included.

Re: Convert BPG from PNG

Posted: 2018-11-08T18:16:16-07:00
by dem123456789
I open an issue here https://github.com/ImageMagick/ImageMagick/issues/1378
I guess I need to use other implementations for now.

Re: Convert BPG from PNG

Posted: 2018-11-08T18:45:13-07:00
by fmw42
You can just use the bpgenc command itself directly without Imagemagick. I tried it and it does work. Use "bpgenc" at the terminal to get the help information.

Re: Convert BPG from PNG

Posted: 2018-11-08T20:09:54-07:00
by dem123456789
Got it Thank you.