Here is my qtable generator:
Code: Select all
/*
Written in 2014 by Jukka Ripatti
To the extent possible under law, the author have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
See http://creativecommons.org/publicdomain/zero/1.0/
*/
#include <stdio.h>
#include <math.h>
/*
f(0) == 0 f(1) == 1
f'(0) == 0 f'(1) == 0
f''(0) == 0 f''(1) == 0
f'''(0) == 0 f'''(1) == 0
*/
double f(double x) {
return 16 * pow(x, 9) - 72 * pow(x, 8) + 108 * pow(x, 7) - 42 * pow(x, 6) - 36 * pow(x, 5) + 27 * pow(x, 4);
// return .5 * (1. - sin(.5 * M_PI * cos(M_PI * x)));
}
int main(int argc, char **argv) {
double quality;
double min, max;
if(argc != 2) { fprintf(stderr, "Usage: %s <0...100> > qtable.txt\n", argv[0]); return 1; }
if(sscanf(argv[1], "%lf", &quality) != 1) { fprintf(stderr, "Usage: %s <0...100> > qtable.txt\n", argv[0]); return 1; }
if(!(quality <= 100. && quality >= -100.)) { fprintf(stderr, "Usage: %s <0...100> > qtable.txt\n", argv[0]); return 1; }
printf("# %1.3f\n", quality);
printf("# cjpeg -optimize -dct float -qtables this_file.txt -qslots 0 -sample 2x2 -outfile outputfile.jpg inputfile\n\n");
quality = sqrt(1. - (quality / 100.));
min = exp2(quality * 6);
max = exp2(quality * 10.65); // This value may need fine-tuning.
int i, j;
for(j = 0; j < 8; j++) {
for(i = 0; i < 8; i++) {
double value;
value = (f(i / 7.) + f(j / 7.)) / 2.;
value = value * (max - min) + min;
if(value > 255.) value = 255.;
printf(" %3.0f", value);
}
printf("\n");
}
return 0;
}
It creates tables that are intended to be used as such without the -quality setting in cjpeg. It works fine with settings between 75 and 100.
For example a table which is created with setting 75:
Code: Select all
# 75.000
# cjpeg -optimize -dct float -qtables this_file.txt -qslots 0 -sample 2x2 -outfile outputfile.jpg inputfile
8 8 10 13 19 22 24 24
8 8 10 14 19 23 24 24
10 10 11 15 20 24 26 26
13 14 15 19 24 28 29 30
19 19 20 24 29 33 34 35
22 23 24 28 33 37 38 38
24 24 26 29 34 38 40 40
24 24 26 30 35 38 40 40
Setting 90:
Code: Select all
# 90.000
# cjpeg -optimize -dct float -qtables this_file.txt -qslots 0 -sample 2x2 -outfile outputfile.jpg inputfile
4 4 4 5 6 7 7 7
4 4 4 5 6 7 7 7
4 4 4 5 6 7 7 7
5 5 5 6 7 8 8 8
6 6 6 7 8 9 9 9
7 7 7 8 9 10 10 10
7 7 7 8 9 10 10 10
7 7 7 8 9 10 10 10