MozJPEG improves JPEG compression efficiency achieving higher visual quality and smaller file sizes at the same time

Overview

Mozilla JPEG Encoder Project Build Status

MozJPEG improves JPEG compression efficiency achieving higher visual quality and smaller file sizes at the same time. It is compatible with the JPEG standard, and the vast majority of the world's deployed JPEG decoders.

MozJPEG is a patch for libjpeg-turbo. Please send pull requests to libjpeg-turbo if the changes aren't specific to newly-added MozJPEG-only compression code. This project aims to keep differences with libjpeg-turbo minimal, so whenever possible, improvements and bug fixes should go there first.

MozJPEG is compatible with the libjpeg API and ABI. It is intended to be a drop-in replacement for libjpeg. MozJPEG is a strict superset of libjpeg-turbo's functionality. All MozJPEG's improvements can be disabled at run time, and in that case it behaves exactly like libjpeg-turbo.

MozJPEG is meant to be used as a library in graphics programs and image processing tools. We include a demo cjpeg command-line tool, but it's not intended for serious use. We encourage authors of graphics programs to use libjpeg's C API and link with MozJPEG library instead.

Features

  • Progressive encoding with "jpegrescan" optimization. It can be applied to any JPEG file (with jpegtran) to losslessly reduce file size.
  • Trellis quantization. When converting other formats to JPEG it maximizes quality/filesize ratio.
  • Comes with new quantization table presets, e.g. tuned for high-resolution displays.
  • Fully compatible with all web browsers.
  • Can be seamlessly integrated into any program that uses the industry-standard libjpeg API. There's no need to write any MozJPEG-specific integration code.

Releases

Compiling

See BUILDING. MozJPEG is built exactly the same way as libjpeg-turbo, so if you need additional help please consult libjpeg-turbo documentation.

Comments
  • Remove or rename JBOOLEAN_USE_MOZ_DEFAULTS

    Remove or rename JBOOLEAN_USE_MOZ_DEFAULTS

    It's poorly named. Not very useful. Not orthogonal with other options.

    "moz defaults" doesn't really mean anything (the real functionality is related to enabling more expensive encoding features, but you can't guess that from the name of the parameter). Now that moz defaults are in fact the default, this option became a way to switch to default settings of libjpeg 6b, so a better name would be JBOOLEAN_USE_LIBJPEG6B_DEFAULTS.

    libjpeg 6b default settings are a bit outdated now, so I wouldn't even encourage use of them by having such option. If somebody needs exact legacy defaults for compatibility, it's unlikely they'd take effort to use mozjpeg and then disable mozjpeg's features. If somebody needs them for specific purpose, e.g. single-pass encoding, there should be more specific settings to enable that.

    Overall I think it would be better to have a set of clearer, more specific options and not include a vague concept of "moz defaults" as part of the API.

    opened by kornelski 25
  • Optimize quantization tables

    Optimize quantization tables

    Currently the encoder switches between "JPEG default" and flat quantization tables based on the metric it is tuning for. There ought to be better tables, including tables tuned for each individual image.

    enhancement 
    opened by fbossen 20
  • Segfaults when compiled with LLVM/clang

    Segfaults when compiled with LLVM/clang

    Hi,

    we have noticed that mozjpeg compiled with clang-3.8.0 causes many segfaults i.e. firefox, dolphin. https://issues.openmandriva.org/show_bug.cgi?id=1560 https://issues.openmandriva.org/show_bug.cgi?id=1559

    Sources for uour mozjpeg package can be found here https://github.com/OpenMandrivaAssociation/mozjpeg

    bug 
    opened by tpgxyz 19
  • PNG support disabled in Windows binaries?

    PNG support disabled in Windows binaries?

    The Windows binaries generated from the 3.0 release source by following the instructions in BUILDING.txt does not appear to have PNG support enabled.

    When a PNG file is passed as input to cjpeg.exe, the following error message is displayed: Unrecognized input file format --- perhaps you need -targa

    I have manually compiled libpng and modified INCLUDE and LIBPATH, but that did not enable PNG support.

    I have also tried manually editing jconfig.h to set PNG_SUPPORTED macro, but this approach did not work either.

    bug 
    opened by hoon 16
  • Using trellis quantization without other options is tricky

    Using trellis quantization without other options is tricky

    Background: I'm trying to compress images at a specific DSSIM quality, and for that I need to try a few different JPEG quality levels, as quickly as possible.

    I wanted to enable trellis quantization (because it visibly affects the output), but disable all other slow optimizations, since I don't look at the file size when only measuring quality.

    However, using just trellis is tricky and I didn't find documentation for it.

    I've tried:

    jpeg_set_defaults(&cinfo);
    jpeg_c_set_bool_param(&cinfo, JBOOLEAN_OPTIMIZE_SCANS, FALSE);
    cinfo.optimize_coding = FALSE;
    

    but there appears to be non-obvious coupling between trellis and progressive scan optimization:

    Invalid progressive parameters at scan script entry 4

    An alternative approach doesn't work either:

    jpeg_c_set_bool_param(&cinfo, JBOOLEAN_USE_MOZ_DEFAULTS, FALSE); 
    jpeg_set_defaults(&cinfo);
    jpeg_c_set_bool_param(&cinfo, JBOOLEAN_TRELLIS_QUANT, TRUE);
    

    Bogus buffer control mode

    I think the current settings are too low-level and don't hide implementation details of the library. I shouldn't be required to know that one setting depends on some other, seemingly unrelated settings. Flipping a single option on or off should do just that — not crash the library.

    So if I just execute jpeg_c_set_bool_param(&cinfo, JBOOLEAN_TRELLIS_QUANT, TRUE) I expect that to automatically enable everything that trellis depends on behind the scenes, and not crash.

    enhancement 
    opened by kornelski 14
  • Complete quoting for parameters of some CMake commands

    Complete quoting for parameters of some CMake commands

    Some parameters (like "${CMAKE_SOURCE_DIR}" and "${CMAKE_CURRENT_BINARY_DIR}") are passed to CMake commands in your build scripts without enclosing them by quotation marks. I see that these places will result in build difficulties if the contents of the used variables will contain special characters like spaces.

    I would recommend to apply advices from a Wiki article.

    opened by elfring 13
  • Deringing via overshoot clipping

    Deringing via overshoot clipping

    This improves compression of black-on-white text and line art with sharp edges as mentioned in #7

    The trick is essentially based on making white areas even whiter, so that ringing artefacts mostly remain above the maximum level of white, and are hidden by clipping done in the decoder (all JPEG decoders must perform clipping, because even standard encoding accidentally creates overshoot values).

    I've described it in more detail: https://pornel.net/deringing/

    This implementation works for black-on-white details (positive overshoot) only, and doesn't attempt to do anything for white-on-black details (negative overshoot). This is because sRGB gamma makes ringing artefacts much more visible on white background than on black background.

    This JPEG has the same file size as well-optimized PNG source. Notice how area around black lines is cleaner on white background than on color background: test-80-smbc2-catf

    enhancement 
    opened by kornelski 12
  • `mozjpeg` compared with `jpegoptim`

    `mozjpeg` compared with `jpegoptim`

    I am using mozjpeg for a few months (and I like it !). Recently, I compared with jpegoptim on simple images (typically one object on white background). I successfully target the same low size, achieving good quality (like low quality in https://imageoptim/online).

    For non-specialists, is there general simple rules to help choose between mozjpeg and jpegoptim ?

    opened by zeroheure 11
  • how to resize in windows?

    how to resize in windows?

    Please write in usage.txt how to perform resize 50% in.jpg out.jpg

    don`t work:

    jpegtran.exe -scale 1/2 in.jpg -outfile out.jpg
    djpeg.exe -scale 1/2 in.jpg > out.jpg
    
    opened by higimo 11
  • bad encoding of black letters on white background

    bad encoding of black letters on white background

    Original comment containing links to test images: https://news.ycombinator.com/item?id=8807536

    Problem spotted: https://news.ycombinator.com/item?id=8807554

    Images: http://i.imgur.com/DTxTcLp.jpg http://i.imgur.com/jVESWGS.jpg

    opened by bdaehlie 11
  • Adjust quantization tables for high-resolution displays

    Adjust quantization tables for high-resolution displays

    There is a trick used when compressing images for high-DPI ("Retina") displays: because details are less visible in higher resolution (or when resampled on lower-resolution displays), the image can tolerate higher level of compression.

    http://filamentgroup.com/lab/compressive-images.html http://gogrowstrategies.com/compressive-images/

    Unfortunately in libjpeg the quantization tables are derived from default tables by proportionally scaling all coefficients.

    The problem with that is that very low quality settings cause DC to be quantized too heavily, virtually guaranteeing that the image will look blocky and posterized. Giving bits to ACs can't help if the DC is awful.

    My suggestion is:

    • Tweak the algorithm in jpeg_add_quant_table to quantize DC and the first few ACs less when the quality is very low.
    • Add a switch to cjpeg for optimization for high-dpi displays. It'd adjust quality scale (lower the quality), quantization tables (protect DC from getting too blocky) and perhaps adjust the lambda for trellis.

    The implementation I've done https://github.com/pornel/mozjpeg/commit/615652b81a8e93c50d5ec72a0f1a29e5af71ee1e just increases DC and the first few ACs. It does work, but maybe an even more elegant approach would be to devise quantization tables optimized for low and high qualities and crate final quantization table from interpolation between these tables.

    enhancement 
    opened by kornelski 11
  • It seems as if an older version of jpegtran produced smaller lossles jpg files

    It seems as if an older version of jpegtran produced smaller lossles jpg files

    I have created a program that loops through a given folder and runs jpegtran on every jpg file it finds. If I get an output file and it is smaller than the input jpg, then it overwrites the input file. Below are the arguments that I use for which I expect lossless reduction

    -optimize -progressive -copy none -outfile "F:\pictures\optimised.tmp" "F:\pictures\Image00.jpg"

    I ran it on files that had been optimised by that older version, actually only one file which came out larger than the input jpg. Very unexpected, I thought it would be same size. I haven’t tested if this true for the other files as well. I know for sure that I ran the older version for rhe files in this particular folder.

    Therefore, I wonder if I’m doing something wrong or if it’s normal to sometimes get optimised pictures that are larger. After all it could be so if jpegtran repairs the file if it doesn’t have a marker that it should in which case I should accept the output file as better albeit larger. If jpegtran repairs files then I think the return value should indicate success and repaiired.

    Btw I have noticed that some jpg files lack the marker that indicates height and width which van be opened anyway. Is ther any open source programs that takes can fix this and similar problems?

    opened by FredWahl 2
  • -sample 1x1 and default quality

    -sample 1x1 and default quality

    The docs say default quality is 75.

    When using stock cjpeg, both these commands result in identical output:

    cjpeg -sample 1x1
    cjpeg -sample 1x1 -q 75
    

    However, with mozjpeg these two commands result in very different output. What exactly is going on here?

    opened by ccxvii 1
  • Windows Binary Upload to Release failed for 4.1.1 (missing privileges)

    Windows Binary Upload to Release failed for 4.1.1 (missing privileges)

    https://ci.appveyor.com/project/kornel/mozjpeg-4ekrx/builds/44465987

    Creating "v4.1.1" release for repository "mozilla/mozjpeg" tag "v4.1.1" commit "a2d2907ff023227e80c1e4efa809812410275a12"...Error creating GitHub release: Error reading repository 'mozilla/mozjpeg' releases: 401 - Unauthorized

    opened by swiffer 1
  • Need help for jpeg

    Need help for jpeg

    Hi, I repaired some jpeg encrypted jpeg by ransomware ( encrypted 150kb of header ) but when i move the good header to corrupt jpeg, how can i fix the color of this jpeg: DSC_0019

    opened by cuuhodrc 8
Releases(v4.1.1)
  • v4.1.1(Aug 15, 2022)

  • v4.0.0(Nov 13, 2020)

    Rebased MozJPEG changes on libjpeg-turbo v2, which includes lots of bug fixes and performance improvements.

    Because libjpeg-turbo has switched to cmake, MozJPEG has too. MozJPEG can now be built using either cmake or Cargo.

    Source code(tar.gz)
    Source code(zip)
  • v4.0.1-rc(Sep 1, 2020)

  • v3.3.1(Mar 17, 2018)

  • v3.2(May 1, 2017)

    • Updated to libjpeg-turbo 1.5.0.
    • Fixed interaction of JINT_DC_SCAN_OPT_MODE and JBOOLEAN_OPTIMIZE_SCANS (#249)
    • #define JPEG_C_PARAM_SUPPORTED 1 for easier interoperability with stock libjpeg
    • Minor bugfixes in yuvjpeg/jpegyuv test helper tools.
    • the cjpeg demo tool guesses default -sample setting from -quality
    Source code(tar.gz)
    Source code(zip)
    mozjpeg-3.2-release-source.tar.gz(1.55 MB)
  • v3.2-pre(Feb 13, 2017)

  • v3.1(May 19, 2015)

    • Improved effectiveness of DC trellis in high-quality images
    • Fixed DC overflow caused by overshoot deringing feature
    • Fixed reading of 16-bit PNG images
    • Fixed memory leaks in jpegyuv and jpegtran utilities
    • Added cjpeg -quant-baseline option to reduce size of quantization tables
    • Merged patches up to libjpeg-turbo r1482
    Source code(tar.gz)
    Source code(zip)
    mozjpeg-3.1-release-source.tar.gz(1.47 MB)
  • v3.0(Dec 30, 2014)

    NOTE: This release includes significant changes to the mozjpeg ABI in order to return to ABI compatibility with libjpeg-turbo. See the file ‘README-mozilla.txt’ for more information.

    • mozjpeg is now backward ABI-compatible with libjpeg-turbo. See ‘README-mozilla.txt’ for more information.
    • DC trellis quantization (compression improvement)
    • Merge successive DQT (FFDB) and DHT (FFC4) markers in a single marker (compression improvement)
    • Deringing for black-on-white text
    • Option to select quantization tables
    • New cjpeg flag ‘-version’ to obtain version
    • PNG input support for cjpeg
    • Various other improvements from syncing with latest libjpeg-turbo code
    Source code(tar.gz)
    Source code(zip)
    mozjpeg-3.0-release-source.tar.gz(1.45 MB)
  • v2.1(Jul 31, 2014)

    • The ‘-baseline’ option for cjpeg has been re-defined to produce baseline mode JPEGs. This makes it possible to produce baseline JPEGs with cjpeg while also using trellis quantization and other improvements. Previously the ‘-baseline’ flag simply specified that baseline quantization tables be used, and the only way to produce a baseline mode JPEG was to use the ‘-revert’ option.
    • Fix for using trellis quantization in non-progressive mode
    • Build fixes for various platforms
    • More helpful error messages from cjpeg
    • Various other minor fixes
    Source code(tar.gz)
    Source code(zip)
  • v2.0.1(Jul 15, 2014)

  • v2.0(Jul 15, 2014)

    • We’ve implemented trellis quantization to reduce file sizes for both baseline and progressive images.
    • The cjpeg utility now supports JPEG input in order to simplify re-compression workflows.
    • We’ve added options to specifically tune for PSNR, PSNR-HVS-M, SSIM, and MS-SSIM metrics.
    • We now generate a single DC scan by default in order to be compatible with decoders that can’t handle arbitrary DC scans.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Mar 28, 2014)

  • v1.0(Mar 5, 2014)

    mozjpeg v1.0 is a fork of libjpeg-turbo with 'jpgcrush' functionality built in.

    The 'jpgcrush' feature finds the progressive coding configuration which uses the fewest bits. This most frequently reduces file size by 2-10%, but those are not hard limits. Significantly greater reductions have been observed.

    Library configuration defaults are the same as for libjpeg-turbo, in order to make transitions as painless as possible. There are new configuration options for new features, but they are not enabled by default.

    The 'cjpeg' program defaults are not the same as for the equivalent program in libjpeg-turbo. The 'cjpeg' defaults for mozjpeg are set to aggressively optimize for smaller file sizes.

    Source code(tar.gz)
    Source code(zip)
Owner
Mozilla
This technology could fall into the right hands.
Mozilla
High Quality DeNoise 3D is an AviSynth port of the MPlayer filter of the same name

High Quality DeNoise 3D is an AviSynth port of the MPlayer filter of the same name. It performs a 3-way low-pass filter, which can completely remove high-frequency noise while minimizing blending artifacts.

null 13 Oct 3, 2022
PoC that fixes two GTA Online bugs and drastically improves load times for CPU-bound systems

Project status Officially fixed by R* 2021-03-16 :) PoC that fixes two GTA Online bugs and drastically improves load times for CPU-bound systems All a

null 2.8k Jan 5, 2023
A Gen implementation in C. With memory efficiency, portability and speed in mind

A Gen implementation in C. With memory efficiency, portability and speed in mind

Gen Programming Language 3 Jul 31, 2022
A version of Tetris with randomly generated polyominoes of varying sizes

Multris A version of Tetris with randomly generated polyominoes of varying sizes ----- CONTROLS ----- LEFT / RIGHT ARROW - Move. Hold to move quicker.

null 17 Nov 5, 2022
SMOL-V: like Vulkan/Khronos SPIR-V, but smaller.

SMOL-V: like Vulkan/Khronos SPIR-V, but smaller. Overview SMOL-V encodes Vulkan/Khronos SPIR-V format programs into a form that is smoller, and is mor

Aras Pranckevičius 271 Dec 19, 2022
This project helps a person park their car in their garage in the same place every time.

garage-parking-sensor Description This project is developed to help a person park their car in their garage in the same place every time. Normally peo

Calvin Pereira 1 Aug 18, 2022
RRxIO - Robust Radar Visual/Thermal Inertial Odometry: Robust and accurate state estimation even in challenging visual conditions.

RRxIO - Robust Radar Visual/Thermal Inertial Odometry RRxIO offers robust and accurate state estimation even in challenging visual conditions. RRxIO c

Christopher Doer 63 Dec 20, 2022
Visual Leak Detector for Visual C++ 2008-2015

Visual Leak Detector Introduction Visual C++ provides built-in memory leak detection, but its capabilities are minimal at best. This memory leak detec

Arkady Shapkin 908 Jan 8, 2023
Second life for famous JPEGView - fast and tiny viewer/editor for JPEG, BMP, PNG, WEBP, TGA, GIF and TIFF images with a minimalist GUI and base image processing.

JPEGView-Image-Viewer-and-Editor Updated Dec 07 2021. Version 1.1.1.0 has been released. Download link1, link2 added. Second life for famous JPEGView

Ann Hatt 40 Dec 27, 2022
Quick fix to iphone usb tethering with ios14 or higher for Linux kernel lower than 5.10.4

Quick fix to Linux Iphone USB tethering with IOS 14 or higher (Tested with ubuntu 18.04, kernel 5.4.0-65, if you fail in the build, please download yo

null 24 Sep 18, 2022
Allows to join RDF of previous expansions on a higher character level

mod-rdf-expansion Allows to join RDF of previous expansions on a higher character level. Up to character level 58, you can join the "Random Classic Du

AzerothCore 4 Dec 25, 2022
Rangeless - c++ LINQ -like library of higher-order functions for data manipulation

rangeless::fn range-free LINQ-like library of higher-order functions for manipulation of containers and lazy input-sequences. Documentation What it's

null 184 Dec 27, 2022
JS/WASM build of libjxl (JPEG-XL)

libjxl-js JS/WASM build of libjxl (JPEG-XL) Try It Out! Try it in your browser here Building This project uses git submodules to pull in libjxl. If de

Chris Hafey 12 Nov 28, 2022
Single header lib for JPEG encoding. Public domain. C99. stb style.

tiny_jpeg.h A header-only public domain implementation of Baseline JPEG compression. Features: stb-style header only library. Does not do dynamic allo

Sergio Gonzalez 212 Dec 14, 2022
StarkScript - or the Stark programming language - is a compiled C-based programming language that aims to offer the same usability as that of JavaScript's and TypeScript's

StarkScript StarkScript - or the Stark programming language - is a compiled C-based programming language that aims to offer the same usability as that

EnderCommunity 5 May 10, 2022
This repo contains BOTH c++ and BP examples to acheive the same logic, but in each frameworks specific ways

ApparatusCppMoveRandomly Hey there! This repo contains BOTH c++ and BP examples to acheive the same logic, but in each frameworks specific ways. I int

null 2 Jan 24, 2022
Node.js Workers, except on the same thread

synchronous-worker – Run Node.js APIs synchronously Usage Example const w = new SynchronousWorker();

Anna Henningsen 72 Nov 25, 2022
Flutter app that syncs clipboards between devices in the same local network.

clipboard_sync A flutter app that syncs clipboards between devices in the same LAN using Interprocess communication (Sockets). What it does ? group of

Pushpavel 5 Oct 29, 2021
It creates a random word by mixing two English common words into a single one, each one with the first character in capital letter. It also allow you to scroll down infinitely without repeating the same word twice.

startup_namer A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if

Samuel Cobas 2 Feb 3, 2022