harvard-lts / kakadu-vips

Kakadu JP2 reader and writer for libvips
Apache License 2.0
3 stars 0 forks source link

add htj2k option #9

Closed jcupitt closed 5 months ago

jcupitt commented 5 months ago

to enable high-throughput j2k

see https://github.com/harvard-lts/kakadu-vips/issues/6

jcupitt commented 5 months ago

Test with eg.:

$ time vips kakadusave k2.jpg x.jp2 --options Creversible=yes

real    0m0.091s
user    0m0.462s
sys 0m0.020s
$ time vips kakadusave k2.jpg x.jph --options Creversible=yes

real    0m0.080s
user    0m0.090s
sys 0m0.037s
$ ls -l x.jp2 x.jph
-rw-r--r-- 1 john john 2447603 Mar  5 18:29 x.jp2
-rw-r--r-- 1 john john 2681043 Mar  5 18:29 x.jph

You can see there's a dramatic drop in user time, and the file size is slightly larger.

The option is enabled automatically for filenames with a .jph suffix, or you can set the htj2k option if there's no filename available.

data = image.kakadusave_buffer(htj2k=True)
scossu commented 5 months ago

pyvips is still not detecting the extension:

>>> from pyvips import Image
>>> img = Image.new_from_file("x.jph")
>>> img.get("vips-loader")
'jp2kload'
>>> with open("x.jph", "rb") as fh:
...     img = Image.new_from_buffer(fh.read(), options="")
... 
>>> img.get("vips-loader")
'jp2kload_buffer'

Shouldn't the loader be kakaduload and kakaduload_buffer respectively?

jcupitt commented 5 months ago

The kakadu loader and saver don't take over libvips jpeg2000 handling, you have to invoke them explicitly with kakaduload and kakadusave.

scossu commented 5 months ago

OK, got it. My impression was that they would (as OPJ does, or doesn't it either?)

In either case it's not a big deal, I'll just add a fallback option.

scossu commented 5 months ago

Could you please look into the merge conflicts? I think I could resolve them but I'd rather rely on your judgment.

jcupitt commented 5 months ago

We could make them take over all jpeg2000 handling, but that should probably be another PR.

scossu commented 5 months ago

That would be ideal, thanks.

jcupitt commented 5 months ago

OK, I made https://github.com/harvard-lts/kakadu-vips/issues/10