Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Canary] Transcoding Support + More Image Format Support (JPEGXL) #3250

Open
wants to merge 49 commits into
base: canary
Choose a base branch
from

Conversation

maxpiva
Copy link

@maxpiva maxpiva commented Oct 4, 2024

Canary testers, I need your help! This is a massive PR that swaps out the Image system in Kavita and brings Transcoding support. This is built from the nightly. Please give it a serious stress test and report back on the nightly thread.

Added

  • Added: Added support for JPEG-XL, JPEG 200, and HEIF image formats
  • Added: Kavita now has transcoding support. This means Kavita will respect Accept Headers and if the target browser/device doesn't support the image, Kavita will convert it on the fly. From testing this is not noticeable and without quality drop.

Changed

  • Changed: Kavita should no longer require SSE4.2 CPU Instructions and should be able to run on older hardware.
  • Changed: Due to the massive overhaul to the image manipulation library, smart cropping (mainly visible on oddly-shaped cover images) was changed from NetVips to SmartCrop.js C# library. Minor differences from testing.

Developer

  • Swapped out NetVips with ImageMagick (Magick.NET)
  • Updated Flurl.Http with a new configuration
  • Removed NetVips and SixLabors.ImageSharp

maxpiva and others added 30 commits August 15, 2024 08:25
Fixed test and benchmark DI.
Point docker-build to another hub
Edit dockerfile and include jxl package.
1. Supported Image Formats came in the accept flag from the browser.
2. If jxl (or future formats, ie browser not supported AVIF, HEIF, etc) are not supported, Kavita will convert it to a suitable display format via conversion providers.
3. if it supported it will return the image as is, no conversion needed.
4. Thumbnails are always converted.
1. Supported Image Formats came in the accept flag from the browser.
2. If jxl (or future formats, ie browser not supported AVIF, HEIF, etc) are not supported, Kavita will convert it to a suitable display format via conversion providers.
3. if it supported it will return the image as is, no conversion needed.
4. Thumbnails are always converted.
Fix GetCoverImage, trying to create a temporary image in current directory, and rename the parameter field name, that generates a wrong asumption.
Optimize Cover Creation
Removing ImageConvertors (No Longer Needed)
Refactored mime types and extensions constants
Enable back docker build/push
@majora2007
Copy link
Member

@maxpiva So what was the consensus of the NetVips stuff? Wondering if I can slot this in the canary (since the Koreader one needs some more work).

@maxpiva
Copy link
Author

maxpiva commented Oct 29, 2024

@majora2007 IDK. Asked the guy how to make it possible, but have no answer, is he/she in the discord channel?

Ref:
#3141 (comment)

if we make it work at OS level. I could code also the netvips implementation, and we can choose at build time which one to use.

@majora2007
Copy link
Member

@majora2007 IDK. Asked the guy how to make it possible, but have no answer, is he/she in the discord channel?

Ref: #3141 (comment)

if we make it work at OS level. I could code also the netvips implementation, and we can choose at build time which one to use.

That is the maintainer of NetVips actually. They aren't in the discord. I'm not sure if it can be possible as well have native Linux builds as well. Let's move forward with canary testing for now.

@majora2007
Copy link
Member

Okay the time is near. Once you get the merge conflicts out of the way, I'm good to deploy this to our canary branch and start extended testing with our dedicated testers.

@maxpiva
Copy link
Author

maxpiva commented Dec 10, 2024

Sorry Reopen the PR by mistake

@maxpiva maxpiva closed this Dec 10, 2024
Q8 is a lot faster new DefineConstants Q8, Q16 and Q16HDRI can be passed to build if you want any variation, default is Q8.
Q16 and Q16HDRI is desirable when the ouput screens are >8 bit, and the initial format support more than 8Bits. IE: AVIF, HEIF or JPGXL.
@majora2007 majora2007 reopened this Dec 10, 2024
@maxpiva
Copy link
Author

maxpiva commented Dec 11, 2024 via email

@majora2007
Copy link
Member

Sounds good. Once you are ready, give me a ping and I can get this deployed onto canary for our testers before I log off for the holiday season.

Fix merge bugs.
Added/Updated nugets, to remove transient security vulnarabilities from other nugets.
@maxpiva
Copy link
Author

maxpiva commented Dec 11, 2024

@majora2007 @DieselTech

Merge from Develop.
Added ImageMagick Q8, Q16 and Q16HDRI support.

The original implementation was using Q16HDRI which is 4 times memory heavier and slower than the other implementations.
Now we are using Q8 which is the lighter one.

Q8 - 8 Bit per channel per pixel processing on bytes. Similar to NetVips chain.
Q16 - 16 Bit per channel per pixel processing on ushorts. 16 Bit color precision.
Q16HDRI - 16 Bit per channel per pixel processing on floats. 16 Bit color precision, more mantissa and precision.

Right now, the .NET Proxy Library, Magick.Net does not support Side by Side, you must choose one implementation or the other at build time, so, currently the user, cannot choose the ImageMagick Implementation to use, without us, using a custom Magick.Net that native load the correct library, depending on ours choice.

Nevertheless, there is 3 new Define Constants, one can use to tailor Kavita in the future.

you can add to dotnet build :

/p:DefineConstants="Q8"
or
/p:DefineConstants="Q16"
or
/p:DefineConstants="Q16HDRI"

Is nothing is included Kavita will be built with Q8.
That will build Kavita with that implementation, code, interop code is already tested on all implementations.

Q16 will make sense, if the user has a screen capable of more than 8 Bits per pixel, and the source has more than 8 Bit per pixel also, IE: HEIF, AVIF, JPEGXL. Some Dithering bastards, could chime in, that is also good for 8-bit sources on 10-bit screens. ;)

In Regard NetVips, Supporting the new formats requires new tooling, docker needs to install netvips native, and I was unable to make it work on normal windows, since the native nuget dosn't support the extended formats, we need to make it download it and installing manually without breaking in the Windows Build stage, or do a .bat/.powershell.

As you see I abstracted all the image processes into interfaces, so swapping engines (ImageMagick x NetVips) is possible, since Kavita is now totally abstracted of the Image Processing libraries we use, and NetVips implementation should be easy to do, since we need to refactor only the existing NetVips actions into the interfaces.

The problem is the tooling to make NetVips viable again.

So far so good on my server.

@majora2007 majora2007 changed the title Transcoding Support + More Image Format Support (JPEGXL) [Canary] Transcoding Support + More Image Format Support (JPEGXL) Dec 11, 2024
@majora2007 majora2007 changed the base branch from develop to canary December 11, 2024 13:03
@majora2007
Copy link
Member

I'm sorry @maxpiva, I created canary off the latest develop this morning and I guess there are some conflicts. Once you get them done, just dm me so I can merge and start the activities for the dedicated testers.

@maxpiva
Copy link
Author

maxpiva commented Dec 11, 2024

Let me merge from Canary into this branch. Previously I merged and resolved from develop.

@maxpiva
Copy link
Author

maxpiva commented Dec 11, 2024

@majora2007
Merged with Canary. Runned backend tests and benchmarks. Seems fine.

FYI: Canary has differences in the frontend against develop (I just taked canary), also some version differences on Canary Kavita.Commons.csproj (not important).
Currently with Canary Fronted wont build. DO you want me to rollback frontend changes to develop?

`
Start 'Building UI'
Removing old wwwroot
Installing web dependencies

up to date, audited 725 packages in 2s

114 packages are looking for funding
run npm fund for details

5 vulnerabilities (1 low, 1 moderate, 3 high)

To address all issues, run:
npm audit fix

Run npm audit for details.
Building UI

kavita-webui@0.7.12.1 prod
npm run cache-locale-prime && ng build --configuration production && npm run minify-langs && npm run cache-locale

kavita-webui@0.7.12.1 cache-locale-prime
node hash-localization-prime.js

Application bundle generation failed. [1.663 seconds]

X [ERROR] Angular compilation initialization failed. [plugin angular-compiler]

Error: The Angular Compiler requires TypeScript >=5.4.0 and <5.6.0 but 5.7.2 was found instead.
at checkVersion (file:///C:/Sources/Repos/Kavita/UI/Web/node_modules/@angular/compiler-cli/bundles/chunk-Y3H6JOVH.js:1161:11)
at verifySupportedTypeScriptVersion (file:///C:/Sources/Repos/Kavita/UI/Web/node_modules/@angular/compiler-cli/bundles/chunk-Y3H6JOVH.js:1165:3)
at new NgtscProgram (file:///C:/Sources/Repos/Kavita/UI/Web/node_modules/@angular/compiler-cli/bundles/chunk-Y3H6JOVH.js:4347:7)
at C:\Sources\Repos\Kavita\UI\Web\node_modules@angular\build\src\tools\angular\compilation\aot-compilation.js:53:88
at profileSync (C:\Sources\Repos\Kavita\UI\Web\node_modules@angular\build\src\tools\esbuild\profiling.js:68:16)
at AotCompilation.initialize (C:\Sources\Repos\Kavita\UI\Web\node_modules@angular\build\src\tools\angular\compilation\aot-compilation.js:53:60)
at async initialize (C:\Sources\Repos\Kavita\UI\Web\node_modules@angular\build\src\tools\angular\compilation\parallel-worker.js:36:50)
at async C:\Sources\Repos\Kavita\UI\Web\node_modules@angular\build\node_modules\piscina\dist\worker.js:146:26
`

@majora2007 majora2007 deleted the branch Kareadita:canary December 11, 2024 21:16
@majora2007 majora2007 closed this Dec 11, 2024
@majora2007 majora2007 reopened this Dec 11, 2024
@majora2007
Copy link
Member

Okay bare with me. I have no idea how canary got out of sync with develop as I deleted it this morning then recreated it off develop.

I recreated it off of develop. It looks like there might be a few changes that need to be fixed up from your PR (or cherrypick from before the "canary" merge and remerge). Sorry about all the trouble.

@xrishox
Copy link

xrishox commented Dec 25, 2024

wow this sounds great, i can't wait to test this out! when transcoding from jxl to a supported format, what format does it choose. at first blush it would seem like there would be no reason to not just convert to png since it's lossless, but on second thought that could be really problematic if people are on mobile and bandwidth restricted. on the other hand though encoding a lossy format to another lossy format could start to introduce artifacts. i wonder how you guys chose to address this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted A feature request that is accepted
Projects
Development

Successfully merging this pull request may close these issues.

5 participants