たくさんの自由帳
Androidのお話
たくさんの自由帳
投稿日 : | 0 日前
文字数(だいたい) : 4070
どうもこんばんわ。
仕事に遅刻して面目次第もありません。わたしです。
どーやっても間に合わねえよってなった。よってそこそこ大事なのに。がんばった。
ImageMagickを自分でビルドすればUltraHDRにも対応できるらしい。
別件でImageMagick使ってみたくて、自分でビルドするの一回やってみたかったんですよね。
↑でImageMagickも実行できるバイナリを配布していますが、これはUltraHDRに対応していない状態でビルドされていて、
その場合は普通のJPEG画像として扱われてしまう。眩しい情報のゲインマップが消えてしまっている?眩しくない。
ので、今回はUltraHDRに対応させたImageMagickを作りたい。
Complete portable application on Linux ...をダウンロードしてきたけど。
chmod +x magick
./magickで、起動しない。
takusan23@DESKTOP-ULEKIDB:~$ ./magick
dlopen(): error loading libfuse.so.2
AppImages require FUSE to run.
You might still be able to extract the contents of this AppImage
if you run it with the --appimage-extract option.
See https://github.com/AppImage/AppImageKit/wiki/FUSE
for more informationWikiを見ろってことなので見たところ、Ubuntu 24.04以降を使っている場合はsudo apt install libfuse2t64をしないといけないらしい。
suto apt update
sudo apt upgrade
sudo apt install libfuse2t64これで./magick --versionすると情報が出てくるようになるはず。
takusan23@DESKTOP-ULEKIDB:~$ ./magick --version
Version: ImageMagick 7.1.1-45 Q16-HDRI x86_64 3cbce5696:20250308 https://imagemagick.org
Copyright: (C) 1999 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP(4.5)
Delegates (built-in): bzlib djvu fontconfig freetype heic jbig jng jp2 jpeg lcms lqr lzma openexr png raqm tiff webp x xml zlib
Compiler: gcc (9.4)で、Delegates の欄に uhdr があれば UltraHDR 画像もサイズ変更等が出来るわけですが、ありません。自分でビルドする必要があります。
UltraHDRがあるので、自分でビルドすればUltraHDR対応版ImageMagickが作れる!!
ImageMagick | Image Formats
ImageMagick is a powerful open-source software suite for creating, editing, converting, and manipulating images in over 200 formats. Ideal for developers, designers, and researchers.
https://imagemagick.org/script/formats.php
ちなみにUltraHDRの名前をこれ以降uhdrとします。
なんでその名前かはわからん、、UltraHDRのソースコードをビルドした時に出来るライブラリ名がlibuhdr.soだからですかね?
Ubuntuマシンを用意する
WSL2の上のUbuntuですlibultrahdrのビルドImageMagickのビルドImageMagickのビルド、初期状態だとほとんどの画像形式が非対応になっているので、対応させたい画像形式に必要なデリゲートライブラリと呼ばれるものをインストールします。jpegやpngやwebpのサポートに必要なデリゲートライブラリはaptから入れれば良い一方、UltraHDRのライブラリはaptで配布されてないため、自分でビルドする必要があります。
ImageMagick | Image Formats
ImageMagick is a powerful open-source software suite for creating, editing, converting, and manipulating images in over 200 formats. Ideal for developers, designers, and researchers.
https://imagemagick.org/script/formats.php
WSL2で用意しました。sudo apt updateとsudo apt upgradeはやってね(お作法感ある)。
あとbuild-essentialを入れます
sudo apt update
sudo apt upgrade
sudo apt install build-essentiallibultrahdr/docs/building.md at main · google/libultrahdr
Ultra HDR is a true HDR image format, and is backcompatible. libultrahdr is the reference codec for the Ultra HDR format. The codecs that support the format can render the HDR intent of the image...
https://github.com/google/libultrahdr/blob/main/docs/building.md
CMakeとNinjaとかのビルドに使うパッケージを入れます。aptで行けるそう。
sudo apt install cmake pkg-config libjpeg-dev ninja-build次にソースコードを落として、ビルド用のフォルダを作って移動します。
一行ずつ叩けばおk
git clone https://github.com/google/libultrahdr.git
cd libultrahdr
mkdir build_directory
cd build_directory次にこれでビルドの準備をします。
例ではclangを使っているけど、build-essential経由で入るgcc/g++でビルドできると思う!!
cmake -G Ninja -DCMAKE_C_COMPILER=gcc-13 -DCMAKE_CXX_COMPILER=g++-13 -DUHDR_BUILD_TESTS=1 ../-- Found JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (found version "80")
-- Configuring done (1.1s)
CMake Error at CMakeLists.txt:771 (add_library):
The install of the uhdr target requires changing an RPATH from the build
tree, but this is not supported with the Ninja generator unless on an
ELF-based or XCOFF-based platform. The CMAKE_BUILD_WITH_INSTALL_RPATH
variable may be set to avoid this relinking step.
CMake Error at CMakeLists.txt:771 (add_library):
The install of the uhdr target requires changing an RPATH from the build
tree, but this is not supported with the Ninja generator unless on an
ELF-based or XCOFF-based platform. The CMAKE_BUILD_WITH_INSTALL_RPATH
variable may be set to avoid this relinking step.
CMake Error at CMakeLists.txt:643 (add_executable):
The install of the ultrahdr_app target requires changing an RPATH from the
build tree, but this is not supported with the Ninja generator unless on an
ELF-based or XCOFF-based platform. The CMAKE_BUILD_WITH_INSTALL_RPATH
variable may be set to avoid this relinking step.もしこれが出た場合は、一度build_directoryフォルダを消してもう一度作って、cmake -G Ninja ...のコマンドを実行するとよいです。
2回目はなんか直りました(よくわからない)
ninjaコマンドでビルド開始です。
ninja以下のコマンドでinstallできます、aptみたいな感覚。
sudo ninja installこんな感じにバイナリが配置される、らしい。
takusan23@DESKTOP-ULEKIDB:~/libultrahdr/build_directory$ sudo ninja install
[3/8] Performing configure step for 'googletest'
-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: /home/takusan23/libultrahdr/build_directory/googletest/src/googletest-build
[4/8] Performing build step for 'googletest'
ninja: no work to do.
[6/7] Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/lib/pkgconfig/libuhdr.pc
-- Installing: /usr/local/lib/libuhdr.so.1.4.0
-- Installing: /usr/local/lib/libuhdr.so.1
-- Installing: /usr/local/lib/libuhdr.so
-- Installing: /usr/local/include/ultrahdr_api.h
-- Installing: /usr/local/lib/libuhdr.a
-- Installing: /usr/local/bin/ultrahdr_app
-- You may need to add path /usr/local/lib/ to LD_LIBRARY_PATH if binaries are unable to load uhdr library
e.g. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/これでImageMagickがビルドで使うlibuhdr.soが用意できました。次はImageMagickのビルドです。
これも手順が書かれてるのでこれ通りにすればいいはず。
有名なので知見がいっぱい

ImageMagick | Install from Source
ImageMagick is a powerful open-source software suite for creating, editing, converting, and manipulating images in over 200 formats. Ideal for developers, designers, and researchers.
https://imagemagick.org/script/install-source.php

ImageMagick | Advanced Linux Source Installation
ImageMagick is a powerful open-source software suite for creating, editing, converting, and manipulating images in over 200 formats. Ideal for developers, designers, and researchers.
https://imagemagick.org/script/advanced-linux-installation.php
git cloneでゲット。
7.1.1-46の部分はGitHub Releasesページから最新のバージョンに置き換えてください。Releases · ImageMagick/ImageMagick
ImageMagick is a free, open-source software suite for creating, editing, converting, and displaying images. It supports 200+ formats and offers powerful command-line tools and APIs for automation, ...
https://github.com/ImageMagick/ImageMagick/releases
git clone --depth 1 --branch 7.1.1-46 https://github.com/ImageMagick/ImageMagick.git ImageMagick-7.1.1
cd ImageMagick-7.1.1/次は./configureと叩きます。これでビルドに必要なデリゲートライブラリがインストールされているかとかを調べてくれます。
が、が、が今はjpegもpngも何も入れてないので、jpegもpngも no って表示されるんじゃないかなと思います。
(UltraHDRのビルドでlibjpeg-devを入れていればjpegはyesかも)
./configureDelegate library configuration:
BZLIB --with-bzlib=yes no
Autotrace --with-autotrace=no no
DJVU --with-djvu=yes no
DPS --with-dps=no no
FFTW --with-fftw=no no
FLIF --with-flif=no no
FlashPIX --with-fpx=no no
FontConfig --with-fontconfig=yes no
FreeType --with-freetype=yes no
Ghostscript lib --with-gslib=no no
Graphviz --with-gvc=yes no
HEIC --with-heic=yes no
JBIG --with-jbig=yes no
JPEG v1 --with-jpeg=yes yes
JPEG XL --with-jxl=yes no
DMR --with-dmr=yes no
LCMS --with-lcms=yes no
LQR --with-lqr=yes no
LTDL --with-ltdl=no no
LZMA --with-lzma=yes no
Magick++ --with-magick-plus-plus=yes no (failed tests)
OpenEXR --with-openexr=yes no
OpenJP2 --with-openjp2=yes no
PANGO --with-pango=yes no
PERL --with-perl=no no
PNG --with-png=yes no
RAQM --with-raqm=yes no
RAW --with-raw=yes no
RSVG --with-rsvg=no no
TIFF --with-tiff=yes no
UHDR --with-uhdr=no no
WEBP --with-webp=yes no
WMF --with-wmf=no no
X11 --with-x= no
XML --with-xml=yes yes
ZIP --with-zip=yes no
ZLIB --with-zlib=yes no
ZSTD --with-zstd=yes noWebページが対応している画像形式一覧です。説明をよく読むと、自分でビルドする際に必要なライブラリが書いてあります。
ImageMagick | Image Formats
ImageMagick is a powerful open-source software suite for creating, editing, converting, and manipulating images in over 200 formats. Ideal for developers, designers, and researchers.
https://imagemagick.org/script/formats.php
pngとjpegとwebp、あとは調べてるとみんな書いてそうだったのでtiffとfreetypeとzlib。
(zlibはpngで使う)
sudo apt install libpng-dev libjpeg-dev libwebp-dev libtiff-dev libfreetype6-dev zlib1g-devもしくは、sudo apt build-dep imagemagickでImageMagickのビルドに必要なパッケージをある程度まとめてインストールする方法もあります。
が、なんか手元のUbuntu 24.04ではなんか動かなかったので一つずつ入れることにした。。。
これでもう一回./configureを叩くと、pngやwebpのサポートが追加されている(noじゃなくてyes)はずです。
Delegate library configuration:
BZLIB --with-bzlib=yes yes
Autotrace --with-autotrace=no no
DJVU --with-djvu=yes no
DPS --with-dps=no no
FFTW --with-fftw=no no
FLIF --with-flif=no no
FlashPIX --with-fpx=no no
FontConfig --with-fontconfig=yes no
FreeType --with-freetype=yes yes
Ghostscript lib --with-gslib=no no
Graphviz --with-gvc=yes no
HEIC --with-heic=yes no
JBIG --with-jbig=yes yes
JPEG v1 --with-jpeg=yes yes
JPEG XL --with-jxl=yes no
DMR --with-dmr=yes no
LCMS --with-lcms=yes no
LQR --with-lqr=yes no
LTDL --with-ltdl=no no
LZMA --with-lzma=yes yes
Magick++ --with-magick-plus-plus=yes yes
OpenEXR --with-openexr=yes no
OpenJP2 --with-openjp2=yes no
PANGO --with-pango=yes no
PERL --with-perl=no no
PNG --with-png=yes yes
RAQM --with-raqm=yes no
RAW --with-raw=yes no
RSVG --with-rsvg=no no
TIFF --with-tiff=yes yes
UHDR --with-uhdr=no no
WEBP --with-webp=yes yes
WMF --with-wmf=no no
X11 --with-x= no
XML --with-xml=yes yes
ZIP --with-zip=yes no
ZLIB --with-zlib=yes yes
ZSTD --with-zstd=yes yesこれはデフォルトでnoになっているので、./configureに引数を渡すとyesになります。libultrahdrをビルドするだけじゃデフォルトで無効だったぽい?
./configure --with-uhdr=yesこれでUHDRもyesになりました。
UHDR --with-uhdr=yes yes準備はできた、、、!
makeコマンドで出来ます。
make時間がかかるので待ちます。
おわった!!
すでに入っている場合は消してね。
以下のコマンドでインストールされます。
sudo make installで、実行しようとするとエラーになります。
/usr/local/bin/magick: error while loading shared libraries: libMagickCore-7.Q16HDRI.so.10: cannot open shared object file: No such file or directory
ImageMagick | Install from Source
ImageMagick is a powerful open-source software suite for creating, editing, converting, and manipulating images in over 200 formats. Ideal for developers, designers, and researchers.
https://imagemagick.org/script/install-source.php
sudo ldconfig /usr/local/libUltraHDR (uhdr)対応版のImageMagickが完成しました。いえーーーい
takusan23@DESKTOP-ULEKIDB:~/ImageMagick-7.1.1$ sudo ldconfig /usr/local/lib
takusan23@DESKTOP-ULEKIDB:~/ImageMagick-7.1.1$ /usr/local/bin/magick --version
Version: ImageMagick 7.1.1-46 Q16-HDRI x86_64 7ee7ea3c9:20250317 https://imagemagick.org
Copyright: (C) 1999 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP(4.5)
Delegates (built-in): bzlib freetype jbig jng jpeg lzma png tiff uhdr webp xml zlib zstd
Compiler: gcc (13.3)UltraHDR画像を小さくしてみる。UltraHDRも拡張子はjpgなので、多分何もしないとJPEGだと思われてしまう。のでファイル名の前にuhdr:を付けます。
ImageMagick | Command-line Processing
ImageMagick is a powerful open-source software suite for creating, editing, converting, and manipulating images in over 200 formats. Ideal for developers, designers, and researchers.
https://imagemagick.org/script/command-line-processing.php
/usr/local/bin/magick -define uhdr:output-color-transfer=hlg -define uhdr:hdr-color-transfer=hlg uhdr:{入力 UltraHDR 画像のパス} -resize 50% uhdr:{出力 UltraHDR 画像のパス}例です:
/usr/local/bin/magick -define uhdr:output-color-transfer=hlg -define uhdr:hdr-color-transfer=hlg uhdr:original_uhdr.jpg -resize 50% uhdr:half_uhdr.jpgちゃんとUltraHDRのまま小さくなってます。良かった。
おわりです。
次回は AWS Lambda で動かすぞ!