{"id":16115630,"url":"https://github.com/kornelski/mozjpeg-sys","last_synced_at":"2025-04-06T17:11:58.872Z","repository":{"id":26335668,"uuid":"29784373","full_name":"kornelski/mozjpeg-sys","owner":"kornelski","description":"Rust bindings for mozjpeg","archived":false,"fork":false,"pushed_at":"2024-08-02T22:28:16.000Z","size":170,"stargazers_count":33,"open_issues_count":10,"forks_count":17,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-10-10T20:19:13.828Z","etag":null,"topics":["ffi-wrapper","jpeg","libjpeg","mozjpeg","rust"],"latest_commit_sha":null,"homepage":"https://lib.rs/crates/mozjpeg-sys","language":"Rust","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/kornelski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-01-24T17:13:53.000Z","updated_at":"2024-08-03T06:50:19.000Z","dependencies_parsed_at":"2023-02-18T13:45:52.247Z","dependency_job_id":"2619b17b-feb3-46d9-951b-f4993028f13c","html_url":"https://github.com/kornelski/mozjpeg-sys","commit_stats":{"total_commits":126,"total_committers":9,"mean_commits":14.0,"dds":0.08730158730158732,"last_synced_commit":"68f6e3644122a0c3c3e6b01652abb7914448e2ee"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kornelski%2Fmozjpeg-sys","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kornelski%2Fmozjpeg-sys/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kornelski%2Fmozjpeg-sys/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kornelski%2Fmozjpeg-sys/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kornelski","download_url":"https://codeload.github.com/kornelski/mozjpeg-sys/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247517915,"owners_count":20951719,"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":["ffi-wrapper","jpeg","libjpeg","mozjpeg","rust"],"created_at":"2024-10-09T20:19:21.957Z","updated_at":"2025-04-06T17:11:58.850Z","avatar_url":"https://github.com/kornelski.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Low-level [MozJPEG](https://github.com/mozilla/mozjpeg) bindings for [Rust](https://www.rust-lang.org/)\n\nThis crate exposes the raw libjpeg API, so [the libjpeg usage manual](https://github.com/mozilla/mozjpeg/blob/master/libjpeg.txt) applies. You'll most likely want to use it via [a higher-level API instead](https://lib.rs/crates/mozjpeg) :)\n\nMany fields in structs are marked as private by default, but if you need to access them, make a pull request marking them `pub`.\n\n## Requirements\n\n* build-essentials (gcc, etc.)\n* [nasm](https://www.nasm.us/) for Intel CPUs, `gas` for ARM. Note: Apple's Xcode ships an incredibly outdated version of nasm that won't work.\n\nThis crate supports x86, x86-64 and ARM64.\n\n## Usage\n\nIn Rust/Cargo, add \"[mozjpeg-sys][crate]\" as a dependency in `Cargo.toml`.\n\n[crate]: https://lib.rs/crates/mozjpeg-sys\n\nIn case you need the `jpeglib.h` header for C code built with Cargo, the required include path**s** (use [`env::split_paths()`][1]) are set for Cargo [build scripts][2] in the `DEP_JPEG_INCLUDE` env var.\n\n[1]: https://doc.rust-lang.org/std/env/fn.split_paths.html\n[2]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts\n\nFor non-Rust projects you can build the library using [Cargo](https://rustup.rs/):\n\n```sh\ncargo build --release\n```\n\nIt creates `target/release/libmozjpeg_sys.a` and `target/release/libmozjpeg_sys.{dll,so,dylib}`, which can be linked with C and other languages.\n\nBy default `nasm_simd` feature is enabled, and this crate will try to compile SIMD support. Additionally, you can set `TARGET_CPU` environmental variable (equivalent to `-march=$TARGET_CPU`) to optimize all of C code for a specific CPU model.\n\n### [Example](examples/reencode.rs)\n\n```rust\nlet mut err: jpeg_error_mgr = mem::zeroed();\nlet mut cinfo: jpeg_decompress_struct = mem::zeroed();\ncinfo.common.err = jpeg_std_error(\u0026mut err);\njpeg_create_decompress(\u0026mut cinfo);\n\nlet file_name = CString::new(file_name.as_bytes()).unwrap();\nlet mode = CString::new(\"rb\").unwrap();\nlet fh = libc::fopen(file_name.as_ptr(), mode.as_ptr());\njpeg_stdio_src(\u0026mut cinfo, fh);\njpeg_read_header(\u0026mut cinfo, true as boolean);\n\n// Available only after `jpeg_read_header()`\nlet width = cinfo.image_width;\nlet height = cinfo.image_height;\n\n// Output settings be set before calling `jpeg_start_decompress()`\ncinfo.out_color_space = J_COLOR_SPACE::JCS_RGB;\njpeg_start_decompress(\u0026mut cinfo);\nlet row_stride = cinfo.image_width as usize * cinfo.output_components as usize;\nlet buffer_size = row_stride * cinfo.image_height as usize;\nlet mut buffer = vec![0u8; buffer_size];\n\nwhile cinfo.output_scanline \u003c cinfo.output_height {\n    let offset = cinfo.output_scanline as usize * row_stride;\n    let mut jsamparray = [buffer[offset..].as_mut_ptr()];\n    jpeg_read_scanlines(\u0026mut cinfo, jsamparray.as_mut_ptr(), 1);\n}\n\njpeg_finish_decompress(\u0026mut cinfo);\njpeg_destroy_decompress(\u0026mut cinfo);\nlibc::fclose(fh);\n```\n\nWriting:\n\n```rust\nlet quality = 98;\nlet file_name = CString::new(\"example_result.jpg\").unwrap();\nlet mode = CString::new(\"wb\").unwrap();\nlet fh = libc::fopen(file_name.as_ptr(), mode.as_ptr());\n\nlet mut err = mem::zeroed();\nlet mut cinfo: jpeg_compress_struct = mem::zeroed();\ncinfo.common.err = jpeg_std_error(\u0026mut err);\njpeg_create_compress(\u0026mut cinfo);\njpeg_stdio_dest(\u0026mut cinfo, fh);\n\ncinfo.image_width = width;\ncinfo.image_height = height;\ncinfo.in_color_space = J_COLOR_SPACE::JCS_RGB;\ncinfo.input_components = 3;\njpeg_set_defaults(\u0026mut cinfo);\n\nlet row_stride = cinfo.image_width as usize * cinfo.input_components as usize;\ncinfo.dct_method = J_DCT_METHOD::JDCT_ISLOW;\njpeg_set_quality(\u0026mut cinfo, quality, true as boolean);\n\njpeg_start_compress(\u0026mut cinfo, true as boolean);\n\nwhile cinfo.next_scanline \u003c cinfo.image_height {\n    let offset = cinfo.next_scanline as usize * row_stride;\n    let jsamparray = [buffer[offset..].as_ptr()];\n    jpeg_write_scanlines(\u0026mut cinfo, jsamparray.as_ptr(), 1);\n}\n\njpeg_finish_compress(\u0026mut cinfo);\njpeg_destroy_compress(\u0026mut cinfo);\nlibc::fclose(fh);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkornelski%2Fmozjpeg-sys","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkornelski%2Fmozjpeg-sys","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkornelski%2Fmozjpeg-sys/lists"}