Moved parameter init to the library
This commit is contained in:
parent
7842f551ab
commit
e24647f55d
12
README.md
12
README.md
|
@ -8,7 +8,7 @@ Binaries not available yet. Please refer to the compilation section below.
|
||||||
|
|
||||||
## Basic usage
|
## Basic usage
|
||||||
|
|
||||||
Libcaesium exposes one single function, auto-detecting the input file type:
|
Libcaesium exposes one single function to compress, auto-detecting the input file type:
|
||||||
```C
|
```C
|
||||||
bool cs_compress(const char *input,
|
bool cs_compress(const char *input,
|
||||||
const char *output,
|
const char *output,
|
||||||
|
@ -24,6 +24,8 @@ bool cs_compress(const char *input,
|
||||||
|
|
||||||
## Compression options
|
## Compression options
|
||||||
Libcaesium supports a few compression parameters for each JPEG and PNG.
|
Libcaesium supports a few compression parameters for each JPEG and PNG.
|
||||||
|
You need to initialize the default values before compressing by calling `initialize_parameters()`.
|
||||||
|
|
||||||
They are defined into a top level struct containing each supported file parameters, as follows:
|
They are defined into a top level struct containing each supported file parameters, as follows:
|
||||||
```C
|
```C
|
||||||
typedef struct cs_image_pars
|
typedef struct cs_image_pars
|
||||||
|
@ -39,14 +41,6 @@ typedef struct cs_jpeg_pars
|
||||||
int quality;
|
int quality;
|
||||||
bool exif_copy;
|
bool exif_copy;
|
||||||
int dct_method;
|
int dct_method;
|
||||||
/*
|
|
||||||
* Parameters you have no reason to set as they will be
|
|
||||||
* overwritten during the process
|
|
||||||
*/
|
|
||||||
int color_space;
|
|
||||||
enum TJSAMP subsample;
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
} cs_jpeg_pars;
|
} cs_jpeg_pars;
|
||||||
```
|
```
|
||||||
The first 3 parameters matters, in term of compression, while the others will be set by the compressor/decompressor
|
The first 3 parameters matters, in term of compression, while the others will be set by the compressor/decompressor
|
||||||
|
|
|
@ -36,4 +36,31 @@ bool cs_compress(const char *input_path, const char *output_path, cs_image_pars
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
par->png.iterations = 10;
|
||||||
|
par->png.iterations_large = 5;
|
||||||
|
par->png.block_split_strategy = 4;
|
||||||
|
par->png.lossy_8 = true;
|
||||||
|
par->png.transparent = true;
|
||||||
|
par->png.auto_filter_strategy = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cs_image_pars initialize_parameters()
|
||||||
|
{
|
||||||
|
cs_image_pars options;
|
||||||
|
|
||||||
|
initialize_jpeg_parameters(&options);
|
||||||
|
initialize_png_parameters(&options);
|
||||||
|
|
||||||
|
return options;
|
||||||
}
|
}
|
|
@ -52,6 +52,7 @@ typedef enum error_level
|
||||||
} error_level;
|
} error_level;
|
||||||
|
|
||||||
bool cs_compress(const char *input_path, const char *output_path, cs_image_pars *options);
|
bool cs_compress(const char *input_path, const char *output_path, cs_image_pars *options);
|
||||||
|
cs_image_pars initialize_parameters();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
add_executable(caesiumd main.c helper.c)
|
add_executable(caesiumd main.c)
|
||||||
|
|
||||||
target_link_libraries(caesiumd LINK_PUBLIC caesium)
|
target_link_libraries(caesiumd LINK_PUBLIC caesium)
|
||||||
|
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
#include <stdbool.h>
|
|
||||||
#include <turbojpeg.h>
|
|
||||||
|
|
||||||
#include "helper.h"
|
|
||||||
|
|
||||||
void initialize_jpeg_parameters(cs_image_pars *options)
|
|
||||||
{
|
|
||||||
options->jpeg.quality = 0;
|
|
||||||
options->jpeg.exif_copy = false;
|
|
||||||
options->jpeg.dct_method = TJFLAG_FASTDCT;
|
|
||||||
options->jpeg.width = 0;
|
|
||||||
options->jpeg.height = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void initialize_png_parameters(cs_image_pars *par)
|
|
||||||
{
|
|
||||||
par->png.iterations = 10;
|
|
||||||
par->png.iterations_large = 5;
|
|
||||||
par->png.block_split_strategy = 4;
|
|
||||||
par->png.lossy_8 = true;
|
|
||||||
par->png.transparent = true;
|
|
||||||
par->png.auto_filter_strategy = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
cs_image_pars initialize_parameters()
|
|
||||||
{
|
|
||||||
cs_image_pars options;
|
|
||||||
|
|
||||||
initialize_jpeg_parameters(&options);
|
|
||||||
initialize_png_parameters(&options);
|
|
||||||
|
|
||||||
return options;
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
#ifndef LIBCAESIUM_HELPER_H
|
|
||||||
#define LIBCAESIUM_HELPER_H
|
|
||||||
|
|
||||||
#include "caesium.h"
|
|
||||||
|
|
||||||
void initialize_jpeg_parameters(cs_image_pars *options);
|
|
||||||
|
|
||||||
void initialize_png_parameters(cs_image_pars *options);
|
|
||||||
|
|
||||||
cs_image_pars initialize_parameters();
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "caesium.h"
|
#include "caesium.h"
|
||||||
#include "helper.h"
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue