libcaesium/caesium/caesium.c

68 lines
1.6 KiB
C
Raw Normal View History

2016-11-04 11:00:04 +01:00
#include <stdlib.h>
#include <stdio.h>
#include "error.h"
#include "utils.h"
2016-11-13 14:43:54 +01:00
#include "png.h"
#include "jpeg.h"
2016-11-04 11:00:04 +01:00
2017-06-03 13:00:00 +02:00
bool cs_compress(const char *input_path, const char *output_path, cs_image_pars *options)
2016-11-04 11:00:04 +01:00
{
FILE *pInputFile;
2016-11-13 14:43:54 +01:00
image_type type;
2016-11-04 11:00:04 +01:00
bool result = false;
2016-12-23 09:10:21 +01:00
if ((pInputFile = fopen(input_path, "rb")) == NULL) {
2017-02-21 23:15:31 +01:00
display_error(ERROR, 104);
2016-11-04 11:00:04 +01:00
return result;
}
type = detect_image_type(pInputFile);
fclose(pInputFile);
if (type == UNKN) {
2017-02-21 23:15:31 +01:00
display_error(WARNING, 103);
2017-02-25 10:17:33 +01:00
} else if (type == CS_JPEG) {
2016-11-13 14:43:54 +01:00
if (options->jpeg.quality != 0) {
2017-06-03 12:22:23 +02:00
result = cs_jpeg_compress(output_path, cs_jpeg_decompress(input_path, &options->jpeg), &options->jpeg);
2016-11-16 09:41:46 +01:00
//The output is now the new input for optimization
2017-06-03 12:22:23 +02:00
if (result) {
result = cs_jpeg_optimize(output_path, output_path, &options->jpeg, input_path);
}
2016-12-23 09:10:21 +01:00
} else {
2017-06-03 12:22:23 +02:00
result = cs_jpeg_optimize(input_path, output_path, &options->jpeg, input_path);
2016-11-13 14:43:54 +01:00
}
2017-02-25 10:17:33 +01:00
} else if (type == CS_PNG) {
2016-12-23 09:10:21 +01:00
result = cs_png_optimize(input_path, output_path, &options->png);
2016-11-04 11:00:04 +01:00
}
return result;
2017-02-21 12:54:52 +01:00
}
void initialize_jpeg_parameters(cs_image_pars *options)
{
options->jpeg.quality = 0;
options->jpeg.exif_copy = false;
options->jpeg.dct_method = 2048;
}
void initialize_png_parameters(cs_image_pars *par)
{
2017-11-15 10:35:34 +01:00
par->png.iterations = 2;
2017-12-10 20:41:48 +01:00
par->png.iterations_large = 1;
par->png.block_split_strategy = 0;
2017-02-21 12:54:52 +01:00
par->png.lossy_8 = true;
par->png.transparent = true;
2017-12-10 20:41:48 +01:00
par->png.auto_filter_strategy = true;
2017-02-21 12:54:52 +01:00
}
cs_image_pars initialize_parameters()
{
cs_image_pars options;
initialize_jpeg_parameters(&options);
initialize_png_parameters(&options);
return options;
2016-11-04 11:00:04 +01:00
}