https://github.com/lifthrasiir/j40 Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code + Explore + All features + Documentation + GitHub Skills + Changelog * Solutions + By Size + Enterprise + Teams + Compare all + By Solution + CI/CD & Automation + DevOps + DevSecOps + Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles + Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} lifthrasiir / j40 Public * Notifications * Fork 0 * Star 129 J40: Independent, self-contained JPEG XL decoder License View license 129 stars 0 forks Star Notifications * Code * Issues 4 * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights lifthrasiir/j40 This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 1 branch 1 tag Code * Clone HTTPS GitHub CLI [https://github.com/l] Use Git or checkout with SVN using the web URL. [gh repo clone lifthr] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @lifthrasiir lifthrasiir Fix a bug where j40_free doesn't work when there was an error. ... 59d8618 Sep 17, 2022 Fix a bug where j40_free doesn't work when there was an error. Also ignore cannot_retry for now, as it is still unclear how should a signal to retry reading be given. 59d8618 Git stats * 37 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github Make sure that any future contribution is in the public domain. Sep 13, 2022 extra Bundle stb_image_write dependency. Sep 13, 2022 .gitignore Add more entries to .gitignore, importing from github/gitignore. Sep 13, 2022 LICENSE.txt Add README and LICENSE. Sep 13, 2022 Makefile Add a minimal Makefile. Sep 13, 2022 README.md Add README and LICENSE. Sep 13, 2022 dj40.c Bundle stb_image_write dependency. Sep 13, 2022 j40.h Fix a bug where j40_free doesn't work when there was an error. Sep 17, 2022 View code J40: Independent, self-contained JPEG XL decoder Quick Start Format Support README.md J40: Independent, self-contained JPEG XL decoder J40 (Jay-forty) is a decoder for ISO/IEC 18181 JPEG XL image format. It intends to be a fully compatible reimplementation to the reference implementation, libjxl, and also serves as a verification that the specification allows for an independent implementation besides from libjxl. J40 is a single-file C99 library with zero dependencies, making it trivial to insert to your project and dependencies. It is also a public domain software and can be used for absolutely every purpose. As of version 2270 (2022-09), J40 is a highly experimental software. Expect breakage, bug and incomplete format support. In order to discourage accidental uses, you need to define an additional macro for now. Quick Start The following is a simple but complete converter from JPEG XL to Portable Arbitrary Map format, and covers all the currently available API functions. #define J40_IMPLEMENTATION // only a SINGLE file should have this #include "j40.h" // you also need to define a macro for experimental versions; follow the error. #include #include // for va_* static int oops(const char *fmt, ...) { va_list args; va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); return 1; } int main(int argc, char **argv) { if (argc < 3) return oops("Usage: %s input.jxl output.pam\n", argv[0]); FILE *out = fopen(argv[2], "wb"); if (!out) return oops("Error: Cannot open an output file.\n"); j40_image image; j40_from_file(&image, argv[1]); // or: j40_from_memory(&image, buf, bufsize, freefunc); j40_output_format(&image, J40_RGBA, J40_U8X4); // JPEG XL supports animation, so `j40_next_frame` calls can be called multiple times if (j40_next_frame(&image)) { j40_frame frame = j40_current_frame(&image); j40_pixels_u8x4 pixels = j40_frame_pixels_u8x4(&frame, J40_RGBA); fprintf(out, "P7\n" "WIDTH %d\n" "HEIGHT %d\n" "DEPTH 4\n" "MAXVAL 255\n" "TUPLTYPE RGB_ALPHA\n" "ENDHDR\n", pixels.width, pixels.height); for (int y = 0; y < height; ++y) { fwrite(j40_row_u8x4(pixels, y), 4, pixels.width, out); } } // J40 stops once the first error is encountered; its error can be checked at the very end if (j40_error(&image)) return oops("Error: %s\n", j40_error_string(&image)); if (ferror(out)) return oops("Error: Cannot fully write to the output file.\n"); j40_free(&image); // also frees all memory associated to j40_frame etc. fclose(out); return 0; } Alternatively, you can use a dj40 executable to convert a JPEG XL file into a PNG file, which can be built as follows: # if your system has make: $ make # otherwise, do the equivalent of: $ cc -O3 dj40.c -o dj40 Format Support As of version 2270, J40 can decode: * Any image encoded with fjxl, or * Most images encoded with cjxl containing... + No animations or previews + No image features (--dots and --patches), which implies: o Efforts (-e) up to 6 o For lossy compression, target distance (-d) less than 3.0 + No progressive encoding (-p) + No lossless JPEG transcoding in use (can be disabled with -j) + No floating point samples There are some known cases where J40 and libjxl can significantly diverge: * Restoration filters (--epf, --gaborish) are currently ignored. * Crop retangles are currently ignored and can reveal a frame larger than the actual image. * ICC profiles are only decoded to the point that the actual image can be decoded. About J40: Independent, self-contained JPEG XL decoder Topics c decoder image-compression jpeg-xl Resources Readme License View license Stars 129 stars Watchers 4 watching Forks 0 forks Releases 1 2270: Initial release Latest Sep 13, 2022 Languages * C 99.9% * Makefile 0.1% Footer (c) 2022 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.