{"id":13642217,"url":"https://github.com/lifthrasiir/j40","last_synced_at":"2025-05-06T23:45:51.834Z","repository":{"id":59291423,"uuid":"536255211","full_name":"lifthrasiir/j40","owner":"lifthrasiir","description":"J40: Independent, self-contained JPEG XL decoder","archived":false,"fork":false,"pushed_at":"2022-12-09T02:18:35.000Z","size":1650,"stargazers_count":229,"open_issues_count":14,"forks_count":3,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-03-31T04:11:25.952Z","etag":null,"topics":["c","decoder","image-compression","jpeg-xl","single-file-library"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lifthrasiir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-13T18:15:39.000Z","updated_at":"2025-03-29T13:01:24.000Z","dependencies_parsed_at":"2023-01-25T11:30:14.531Z","dependency_job_id":null,"html_url":"https://github.com/lifthrasiir/j40","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lifthrasiir%2Fj40","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lifthrasiir%2Fj40/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lifthrasiir%2Fj40/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lifthrasiir%2Fj40/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lifthrasiir","download_url":"https://codeload.github.com/lifthrasiir/j40/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252788404,"owners_count":21804280,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","decoder","image-compression","jpeg-xl","single-file-library"],"created_at":"2024-08-02T01:01:28.665Z","updated_at":"2025-05-06T23:45:51.818Z","avatar_url":"https://github.com/lifthrasiir.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# J40: Independent, self-contained JPEG XL decoder\n\n**J40** (Jay-forty) is a decoder for ISO/IEC 18181 [JPEG XL] image format.\nIt intends to be a fully compatible reimplementation to the reference implementation, [libjxl],\nand also serves as a verification that the specification allows for\nan independent implementation besides from libjxl.\n\nJ40 is a [single-file C99 library with zero dependencies][1file],\nmaking it trivial to insert to your project and dependencies.\nIt is also a public domain software and can be used for absolutely every purpose.\n\n[JPEG XL]: https://en.wikipedia.org/wiki/JPEG_XL\n[libjxl]: https://github.com/libjxl/libjxl/\n[1file]: https://github.com/nothings/single_file_libs\n\n_**As of version 2270 (2022-09), J40 is a highly experimental software.**\nExpect breakage, bug and [incomplete format support](#format-support).\nIn order to discourage accidental uses, you need to define an additional macro for now._\n\n## Quick Start\n\nThe following is a simple but complete converter from JPEG XL to [Portable Arbitrary Map][pam] format,\nand covers all the currently available API functions.\n\n[pam]: http://netpbm.sourceforge.net/doc/pam.html\n\n```c\n#define J40_IMPLEMENTATION // only a SINGLE file should have this\n#include \"j40.h\" // you also need to define a macro for experimental versions; follow the error.\n#include \u003cstdio.h\u003e\n#include \u003cstdarg.h\u003e // for va_*\n\nstatic int oops(const char *fmt, ...) {\n    va_list args;\n    va_start(args, fmt);\n    vfprintf(stderr, fmt, args);\n    va_end(args);\n    return 1;\n}\n\nint main(int argc, char **argv) {\n    if (argc \u003c 3) return oops(\"Usage: %s input.jxl output.pam\\n\", argv[0]);\n\n    FILE *out = fopen(argv[2], \"wb\");\n    if (!out) return oops(\"Error: Cannot open an output file.\\n\");\n\n    j40_image image;\n    j40_from_file(\u0026image, argv[1]); // or: j40_from_memory(\u0026image, buf, bufsize, freefunc);\n    j40_output_format(\u0026image, J40_RGBA, J40_U8X4);\n\n    // JPEG XL supports animation, so `j40_next_frame` calls can be called multiple times\n    if (j40_next_frame(\u0026image)) {\n        j40_frame frame = j40_current_frame(\u0026image);\n        j40_pixels_u8x4 pixels = j40_frame_pixels_u8x4(\u0026frame, J40_RGBA);\n        fprintf(out,\n            \"P7\\n\"\n            \"WIDTH %d\\n\"\n            \"HEIGHT %d\\n\"\n            \"DEPTH 4\\n\"\n            \"MAXVAL 255\\n\"\n            \"TUPLTYPE RGB_ALPHA\\n\"\n            \"ENDHDR\\n\",\n            pixels.width, pixels.height);\n        for (int y = 0; y \u003c height; ++y) {\n            fwrite(j40_row_u8x4(pixels, y), 4, pixels.width, out);\n        }\n    }\n\n    // J40 stops once the first error is encountered; its error can be checked at the very end\n    if (j40_error(\u0026image)) return oops(\"Error: %s\\n\", j40_error_string(\u0026image));\n    if (ferror(out)) return oops(\"Error: Cannot fully write to the output file.\\n\");\n\n    j40_free(\u0026image); // also frees all memory associated to j40_frame etc.\n    fclose(out);\n    return 0;\n}\n```\n\nAlternatively, you can use a `dj40` executable to convert a JPEG XL file into a PNG file,\nwhich can be built as follows:\n\n```console\n# if your system has make:\n$ make\n\n# otherwise, do the equivalent of:\n$ cc -O3 dj40.c -o dj40\n```\n\n## Format Support\n\nAs of version 2270, J40 can decode:\n\n* Any image encoded with [fjxl], or\n* Most images encoded with [cjxl][libjxl] containing...\n    * No animations or previews\n    * No image features (`--dots` and `--patches`), which implies:\n        * Efforts (`-e`) up to 6\n        * For lossy compression, target distance (`-d`) less than 3.0\n    * No progressive encoding (`-p`)\n    * No lossless JPEG transcoding in use (can be disabled with `-j`)\n    * No floating point samples\n\n[fjxl]: https://github.com/libjxl/libjxl/tree/main/experimental/fast_lossless\n\nThere are some known cases where J40 and libjxl can significantly diverge:\n\n* Restoration filters (`--epf`, `--gaborish`) are currently ignored.\n* Crop retangles are currently ignored and can reveal a frame larger than the actual image.\n* ICC profiles are only decoded to the point that the actual image can be decoded.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flifthrasiir%2Fj40","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flifthrasiir%2Fj40","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flifthrasiir%2Fj40/lists"}