DrKLO/Telegram · error

%s: sorry, arithmetic coding not supported

Error message

%s: sorry, arithmetic coding not supported

What it means

cjpeg (mozjpeg's JPEG compressor) was built without arithmetic-coding support (C_ARITH_CODING_SUPPORTED undefined). The -arithmetic switch is therefore unavailable; cjpeg prints this message to stderr and exits with EXIT_FAILURE. Arithmetic coding is an optional libjpeg feature, off by default in many mozjpeg builds.

Source

Thrown at TMessagesProj/jni/mozjpeg/cjpeg.c:310

    if (*arg != '-') {
      /* Not a switch, must be a file name argument */
      if (argn <= last_file_arg_seen) {
        outfilename = NULL;     /* -outfile applies to just one input file */
        continue;               /* ignore this name if previously processed */
      }
      break;                    /* else done parsing switches */
    }
    arg++;                      /* advance past switch marker character */

    if (keymatch(arg, "arithmetic", 1)) {
      /* Use arithmetic coding. */
#ifdef C_ARITH_CODING_SUPPORTED
      cinfo->arith_code = TRUE;
      
      /* No table optimization required for AC */
      cinfo->optimize_coding = FALSE;
#else
      fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
              progname);
      exit(EXIT_FAILURE);
#endif

    } else if (keymatch(arg, "baseline", 1)) {
      /* Force baseline-compatible output (8-bit quantizer values). */
      force_baseline = TRUE;
      /* Disable multiple scans */
      simple_progressive = FALSE;
      cinfo->num_scans = 0;
      cinfo->scan_info = NULL;

    } else if (keymatch(arg, "dct", 2)) {
      /* Select DCT algorithm. */
      if (++argn >= argc) {      /* advance to next argument */
        fprintf(stderr, "%s: missing argument for dct\n", progname);
        usage();
      }

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Drop -arithmetic (the default Huffman coding will be used).
  2. Rebuild mozjpeg with arithmetic coding enabled (-DWITH_ARITH_DEC=ON / -DWITH_ARITH_ENC=ON or define C_ARITH_CODING_SUPPORTED) if arithmetic coding is required.

Example fix

# before
cjpeg -arithmetic -quality 80 in.ppm > out.jpg

# after - use default Huffman coding
cjpeg -quality 80 in.ppm > out.jpg
Defensive patterns

Strategy: fallback

Validate before calling

# Probe whether this cjpeg build supports arithmetic coding before using -arithmetic.
if cjpeg -h 2>&1 | grep -q arithmetic; then
  ARITH=-arithmetic
else
  ARITH=   # fall back to default Huffman coding
fi
cjpeg $ARITH -quality 80 in.ppm > out.jpg

Prevention

When it happens

Trigger: Invoking `cjpeg -arithmetic ...` against a mozjpeg/libjpeg build compiled without C_ARITH_CODING_SUPPORTED.

Common situations: Default mozjpeg package builds often disable arithmetic coding; scripts ported from an IJG libjpeg that had it enabled; CI using a minimal mozjpeg.

Related errors


AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14). Data as JSON: /api/errors/06fe15998bf34878. Report an issue: GitHub.