macOS版 ART (raw現像ソフト)でjpeg-xlで書き出せない

「ファイル保存エラー」が出る。

対策

  1. HomeBrewでjpeg-xlをインストールし
  2. /Applications/ART.app/Contents/Resources/imageio/bin/cjxlをシンボリックリンクにする
$ brew install jpeg-xl
$ cd /Applications/ART.app/Contents/Resources/imageio/bin
$ mv cjxl cjxl.bak
$ ln -s $(which cjxl) cjxl

なんで動かないのか検証

まず処理をみる

$ /Applications/ART.app/Contents/MacOS/ART-cli -V -Tjxl -c /Users/irk/Desktop/nef/DSC_0014.NEF
Settings directory (user_config_dir) = /Users/irk/.config/ART
Cache directory (cacheBaseDir) = /Users/irk/.cache/ART
Default profile for raw images "Dynamic" found
Default profile for non-raw images "Neutral" found
Loading lensfun database from '/Applications/ART.app/Contents/MacOS/../../Contents/Resources/lensfun'...OK
trying to load extra working spaces from /Applications/ART.app/Contents/MacOS/../../Contents/Resources/iccprofiles/workingspaces.json FAIL
trying to load extra working spaces from /library/ColorSync/Profiles/Displays/workingspaces.json FAIL
Loaded 7 custom loaders
ART, version 1.26.5, command line.
  Processing: /Users/irk/Desktop/nef/DSC_0014.NEF
Loading Nikon D5000 image from /Users/irk/Desktop/nef/DSC_0014.NEF using libraw...
constants exists for "Nikon D5000" in camconst.json
raw dimensions: 4352 x 2868
black levels: R:0 G1:0 B:0 G2:0 (provided by libraw)
white levels: R:4095 G1:4095 B:4095 G2:4095 (provided by libraw)
raw crop: 0 0 4310 2868 (provided by libraw)
color matrix provided by camconst.json
[7309, -1403, -519, -8474, 16008, 2622, -2433, 2826, 8064]
cam_mul:[531.000000 256.000000 278.000000 256.000000], AsShotNeutral:[0.482109 1.000000 0.920863 1.000000]
pre_mul:[1.000000 0.482109 0.523540 0.482109], scale_mul:[16.003662 7.715514 8.378566 7.715514], cblack:[0.000000 0.000000 0.000000 0.000000]
rgb_cam:[ [ 1.826925 -0.006813 0.062587], [-0.654972 1.332168 -0.400578], [-0.171953 -0.325355 1.337991] ]
Raw As Shot White balance: temp 6584.918976, tint 1.110651, multipliers [2.059047 1.874106 2.106991 | 2.008508 1.919054 2.055332]
Load /Users/irk/Desktop/nef/DSC_0014.NEF: 127062 usec
Processing with the normal pipeline
cam_mul:[531.000000 256.000000 278.000000 256.000000], AsShotNeutral:[0.482109 1.000000 0.920863 1.000000]
pre_mul:[1.000000 0.427726 0.437765 0.427726], scale_mul:[16.003662 6.845178 7.005847 6.845178], cblack:[0.000000 0.000000 0.000000 0.000000]
rgb_cam:[ [ 1.826925 -0.006813 0.062587], [-0.654972 1.332168 -0.400578], [-0.171953 -0.325355 1.337991] ]
Raw preprocessing white balance: temp 6584.918976, tint 1.110651, multipliers [2.059047 1.874106 2.106991 | 2.059047 1.874106 2.106992]
Nikon D5000.badpixels not found
Preprocessing: 7253 usec
Demosaicing Bayer data: rcd - 19227 usec
Output profile_: "RTv4_sRGB"
Using "RTv4_sRGB" output profile
saving /Users/irk/Desktop/nef/DSC_0014.jxl with python3 jxl/jxl_io.py --mode write
  exec error: exit status: 256
Error: failure in saving to: /Users/irk/Desktop/nef/DSC_0014.jxl

どうやらpythonスクリプトを実行しているらしい。

他のフォーマットで書き出せるか試してみる。試しにwebpで書き出す。

$ /Applications/ART.app/Contents/MacOS/ART-cli -V -Twebp -c /Users/irk/Desktop/nef/DSC_0014.NEF
Settings directory (user_config_dir) = /Users/irk/.config/ART
Cache directory (cacheBaseDir) = /Users/irk/.cache/ART
Default profile for raw images "Dynamic" found
Default profile for non-raw images "Neutral" found
Loading lensfun database from '/Applications/ART.app/Contents/MacOS/../../Contents/Resources/lensfun'...OK
trying to load extra working spaces from /Applications/ART.app/Contents/MacOS/../../Contents/Resources/iccprofiles/workingspaces.json FAIL
trying to load extra working spaces from /library/ColorSync/Profiles/Displays/workingspaces.json FAIL
Loaded 7 custom loaders
ART, version 1.26.5, command line.
  Processing: /Users/irk/Desktop/nef/DSC_0014.NEF
Loading Nikon D5000 image from /Users/irk/Desktop/nef/DSC_0014.NEF using libraw...
constants exists for "Nikon D5000" in camconst.json
raw dimensions: 4352 x 2868
black levels: R:0 G1:0 B:0 G2:0 (provided by libraw)
white levels: R:4095 G1:4095 B:4095 G2:4095 (provided by libraw)
raw crop: 0 0 4310 2868 (provided by libraw)
color matrix provided by camconst.json
[7309, -1403, -519, -8474, 16008, 2622, -2433, 2826, 8064]
cam_mul:[531.000000 256.000000 278.000000 256.000000], AsShotNeutral:[0.482109 1.000000 0.920863 1.000000]
pre_mul:[1.000000 0.482109 0.523540 0.482109], scale_mul:[16.003662 7.715514 8.378566 7.715514], cblack:[0.000000 0.000000 0.000000 0.000000]
rgb_cam:[ [ 1.826925 -0.006813 0.062587], [-0.654972 1.332168 -0.400578], [-0.171953 -0.325355 1.337991] ]
Raw As Shot White balance: temp 6584.918976, tint 1.110651, multipliers [2.059047 1.874106 2.106991 | 2.008508 1.919054 2.055332]
Load /Users/irk/Desktop/nef/DSC_0014.NEF: 125345 usec
Processing with the normal pipeline
cam_mul:[531.000000 256.000000 278.000000 256.000000], AsShotNeutral:[0.482109 1.000000 0.920863 1.000000]
pre_mul:[1.000000 0.427726 0.437765 0.427726], scale_mul:[16.003662 6.845178 7.005847 6.845178], cblack:[0.000000 0.000000 0.000000 0.000000]
rgb_cam:[ [ 1.826925 -0.006813 0.062587], [-0.654972 1.332168 -0.400578], [-0.171953 -0.325355 1.337991] ]
Raw preprocessing white balance: temp 6584.918976, tint 1.110651, multipliers [2.059047 1.874106 2.106991 | 2.059047 1.874106 2.106992]
Nikon D5000.badpixels not found
Preprocessing: 7620 usec
Demosaicing Bayer data: rcd - 20987 usec
Output profile_: "RTv2_sRGB"
Using "RTv2_sRGB" output profile
saving /Users/irk/Desktop/nef/DSC_0014.webp with python3 webp/webp_io.py -m write

中身を見る

/Applications/ART.app/Contents/Resources/imageio/jxlにあるjxl_io.pyを見ると;

def write(opts):
    fd, name = tempfile.mkstemp(suffix='.ppm')
    os.close(fd)

    data = tifffile.imread(opts.input)
    if not opts.hdr:
        data = numpy.fmax(numpy.fmin(data, 1.0), 0.0)
    data *= 65535.0
    data = data.astype(numpy.dtype(numpy.uint16).newbyteorder('>'))
    with open(name, 'wb') as out:
        out.write(b'P6 ')
        out.write(str(data.shape[1]).encode('utf-8'))
        out.write(b' ')
        out.write(str(data.shape[0]).encode('utf-8'))
        out.write(b' ')
        out.write(b'65535\n')
        out.write(data.tobytes('C'))

    colorspace = [] if not opts.hdr else ['-x', 'color_space=RGB_D65_202_Per_PeQ']
    subprocess.run(['cjxl', '--container=1', name, opts.output] + colorspace,
                   check=True)
    os.unlink(name)
    
    subprocess.run(['exiftool', '-tagsFromFile', opts.input,
                    '-overwrite_original', opts.output], check=True)

        
def main():
    opts = getopts()
    if opts.mode == 'read':
        read(opts)
    else:
        write(opts)

cjxlというバイナリで処理が行われているらしい。

cjxlを実行してみる

たぶんバイナリは近くにあるだろうという目算のもとbinをあさる。

$ cd /Applications/ART.app/Contents/Resources/imageio/bin
$ ./cjxl
dyld[20919]: Library not loaded: /opt/local/lib/libz.1.dylib
  Referenced from: <04AE3EDB-E3A5-36A8-83E0-7821714B5FBC> /Applications/ART.app/Contents/Resources/imageio/bin/cjxl
  Reason: tried: '/opt/local/lib/libz.1.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/local/lib/libz.1.dylib' (no such file), '/opt/local/lib/libz.1.dylib' (no such file)
[1]    20919 abort      ./cjxl

無いダイナミックライブラリを読み込もうとしているらしい。/opt/local/libってなんだろう?

確か、少し前のmacOS用パッケージマネージャは自分用のディレクトリを作らず、unixの慣習に従って/opt/localを使っていた気がする。それの名残りかも?

コメント

タイトルとURLをコピーしました