{"record":{"id":"56a6b0888c9fffcd","repo":"DrKLO/Telegram","slug":"s-can-t-set-sample-factors","errorCode":null,"errorMessage":"%s: can't set sample factors\n","messagePattern":"(.+?): can't set sample factors\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/mozjpeg/cjpeg.c","lineNumber":636,"sourceCode":"        fprintf(stderr, \"%s: can't set quality ratings\\n\", progname);\n        usage();\n      }\n\n    if (qtablefile != NULL)     /* process -qtables if it was present */\n      if (! read_quant_tables(cinfo, qtablefile, force_baseline)) {\n        fprintf(stderr, \"%s: can't read qtable file\\n\", progname);\n        usage();\n      }\n\n    if (qslotsarg != NULL)      /* process -qslots if it was present */\n      if (!set_quant_slots(cinfo, qslotsarg))\n        usage();\n\n    /* set_quality_ratings sets default subsampling, so the explicit\n       subsampling must be set after it */\n    if (samplearg != NULL)      /* process -sample if it was present */\n      if (! set_sample_factors(cinfo, samplearg)) {\n        fprintf(stderr, \"%s: can't set sample factors\\n\", progname);\n        usage();\n      }\n\n#ifdef C_PROGRESSIVE_SUPPORTED\n    if (simple_progressive)     /* process -progressive; -scans can override */\n      jpeg_simple_progression(cinfo);\n#endif\n\n#ifdef C_MULTISCAN_FILES_SUPPORTED\n    if (scansarg != NULL)       /* process -scans if it was present */\n      if (!read_scan_script(cinfo, scansarg))\n        usage();\n#endif\n  }\n\n  return argn;                  /* return index of next arg (file name) */\n}\n","sourceCodeStart":618,"sourceCodeEnd":654,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/cjpeg.c#L618-L654","documentation":"cjpeg calls set_sample_factors() to parse -sample (format HxV[,HxV,...] per component). It returns FALSE if sscanf fails to read H x V, if the separator is not 'x'/'X' between H and V or not ',' between pairs, or if H or V is outside 1..4. The wrapper prints this message and calls usage().","triggerScenarios":"Passing -sample with malformed syntax: -sample 2 (missing xV), -sample 2-2 (wrong separator), -sample 4x2x2 (extra), or a factor of 5 or 0, e.g. -sample 5x1.","commonSituations":"Confusing the HxV notation with NxN or WxH conventions used elsewhere; typos; values from an encoder GUI that uses a different representation; exceeding the libjpeg 1..4 sampling-factor limit.","solutions":["Use the exact format HxV per component separated by commas, each factor 1..4, e.g. -sample 2x2 or -sample 2x2,1x1,1x1.","Validate the input matches ^[1-4]x[1-4](,[1-4]x[1-4])*$ before passing.","Remember fewer entries than components are backfilled with 1x1."],"exampleFix":"# before\ncjpeg -sample 2-2 input.ppm > out.jpg\n# after\ncjpeg -sample 2x2 input.ppm > out.jpg","handlingStrategy":"validation","validationCode":"#!/bin/sh\n# Validate -sample: HxV[,HxV,...] each in 1..4\nSAMPLE='2x2'\nprintf '%s' \"$SAMPLE\" | grep -Eq '^[1-4]x[1-4](,[1-4]x[1-4])*$' || { echo 'bad -sample' >&2; exit 1; }\ncjpeg -sample \"$SAMPLE\" in.ppm > out.jpg","typeGuard":"// n/a: string-format validation in the caller.","tryCatchPattern":"if ! cjpeg -sample \"$SAMPLE\" in.ppm > out.jpg 2>/tmp/e; then\n  grep -q \"can't set sample factors\\|sampling factors must be\" /tmp/e && { echo 'fix -sample (HxV, 1..4)'; exit 1; }\nfi","preventionTips":["Restrict -sample input with the documented regex before invoking cjpeg.","Document the 1..4 factor limit prominently for users configuring subsampling.","Test the wrapper with edge values (1x1, 4x4, 2x2,1x1,1x1)."],"tags":["mozjpeg","cjpeg","cli-argument","sample-factor","subsampling"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}