Convert BPG from PNG

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
dem123456789
Posts: 12
Joined: 2018-11-07T18:19:39-07:00
Authentication code: 1152

Convert BPG from PNG

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert BPG from PNG

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert BPG from PNG

Post 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.
dem123456789
Posts: 12
Joined: 2018-11-07T18:19:39-07:00
Authentication code: 1152

Re: Convert BPG from PNG

Post by dem123456789 »

So what I should do now? Report issue at GitHub and use native or other BPG converter?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert BPG from PNG

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert BPG from PNG

Post 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.
dem123456789
Posts: 12
Joined: 2018-11-07T18:19:39-07:00
Authentication code: 1152

Re: Convert BPG from PNG

Post by dem123456789 »

I open an issue here https://github.com/ImageMagick/ImageMagick/issues/1378
I guess I need to use other implementations for now.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert BPG from PNG

Post 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.
dem123456789
Posts: 12
Joined: 2018-11-07T18:19:39-07:00
Authentication code: 1152

Re: Convert BPG from PNG

Post by dem123456789 »

Got it Thank you.
Post Reply