commit
bc971e6023
|
@ -7,8 +7,14 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||||
|
|
||||||
# The version number.
|
# The version number.
|
||||||
set(VERSION_MAJOR 0)
|
set(VERSION_MAJOR 0)
|
||||||
set(VERSION_MINOR 4)
|
set(VERSION_MINOR 5)
|
||||||
set(VERSION_PATCH 4)
|
set(VERSION_PATCH 0)
|
||||||
|
|
||||||
|
if (DEFINED VERBOSE)
|
||||||
|
set(VERBOSE ${VERBOSE})
|
||||||
|
else ()
|
||||||
|
set(VERBOSE 0)
|
||||||
|
endif ()
|
||||||
|
|
||||||
configure_file(
|
configure_file(
|
||||||
"caesium/config.h.in"
|
"caesium/config.h.in"
|
||||||
|
@ -22,19 +28,19 @@ if (APPLE)
|
||||||
|
|
||||||
include_directories(/opt/mozjpeg/include)
|
include_directories(/opt/mozjpeg/include)
|
||||||
include_directories(/usr/local/include)
|
include_directories(/usr/local/include)
|
||||||
elseif(WIN32)
|
elseif (WIN32)
|
||||||
include_directories(C:\\mozjpeg\\include)
|
include_directories(C:\\mozjpeg\\include)
|
||||||
include_directories(C:\\zopfli\\src)
|
include_directories(C:\\zopfli\\src)
|
||||||
else()
|
else ()
|
||||||
include_directories(/opt/mozjpeg/include)
|
include_directories(/opt/mozjpeg/include)
|
||||||
include_directories(/usr/include/zopflipng)
|
include_directories(/usr/include/zopflipng)
|
||||||
|
|
||||||
if(EXISTS /opt/mozjpeg/lib64)
|
if (EXISTS /opt/mozjpeg/lib64)
|
||||||
link_directories(/opt/mozjpeg/lib64)
|
link_directories(/opt/mozjpeg/lib64)
|
||||||
else()
|
else ()
|
||||||
link_directories(/opt/mozjpeg/lib)
|
link_directories(/opt/mozjpeg/lib)
|
||||||
endif()
|
endif ()
|
||||||
endif()
|
endif ()
|
||||||
|
|
||||||
link_directories(/usr/local/lib)
|
link_directories(/usr/local/lib)
|
||||||
|
|
||||||
|
|
10
README.md
10
README.md
|
@ -11,16 +11,19 @@ Binaries not available yet. Please refer to the compilation section below.
|
||||||
Libcaesium exposes one single function to compress, 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,
|
||||||
char *output,
|
const char *output,
|
||||||
cs_image_pars *options);
|
cs_image_pars *options,
|
||||||
|
int* err_n);
|
||||||
```
|
```
|
||||||
#### Parameters
|
#### Parameters
|
||||||
**input** - input file path
|
**input** - input file path
|
||||||
**output** - output file path
|
**output** - output file path
|
||||||
**options** - pointer to the options struct, containing compression parameters (see below)
|
**options** - pointer to the options struct, containing compression parameters (see below)
|
||||||
|
**err_n** - pointer to an integer that will contain the error code if something went wrong during compression
|
||||||
|
|
||||||
#### Return value
|
#### Return value
|
||||||
**true** if the compression has successfully ended, or **false** if any error occurs.
|
**true** if the compression has successfully ended, or **false** if any error occurs. If any error occurred, the **err_n**
|
||||||
|
variable will contain the error code. See `error.h` for further info.
|
||||||
|
|
||||||
## 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.
|
||||||
|
@ -78,6 +81,7 @@ Those are the zopflipng compression parameters, except for the last one.
|
||||||
Libcaesium uses cmake to build and install the library. Before compiling, be sure to have all the requisites.
|
Libcaesium uses cmake to build and install the library. Before compiling, be sure to have all the requisites.
|
||||||
Libcaesium requires [mozjpeg](https://github.com/mozilla/mozjpeg) and [zopfli](https://github.com/google/zopfli) installed as shared/static libraries.
|
Libcaesium requires [mozjpeg](https://github.com/mozilla/mozjpeg) and [zopfli](https://github.com/google/zopfli) installed as shared/static libraries.
|
||||||
Please refer to their own documentation for detailed instructions.
|
Please refer to their own documentation for detailed instructions.
|
||||||
|
You can also enable the verbose output, which will print on stderr if anything goes wrong, by using the `-DVERBOSE=1` flag during compilation.
|
||||||
|
|
||||||
### OS X/Linux
|
### OS X/Linux
|
||||||
##### Requirements
|
##### Requirements
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
@ -6,7 +5,7 @@
|
||||||
#include "png.h"
|
#include "png.h"
|
||||||
#include "jpeg.h"
|
#include "jpeg.h"
|
||||||
|
|
||||||
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, int* err_n)
|
||||||
{
|
{
|
||||||
FILE *pInputFile;
|
FILE *pInputFile;
|
||||||
image_type type;
|
image_type type;
|
||||||
|
@ -15,6 +14,7 @@ bool cs_compress(const char *input_path, const char *output_path, cs_image_pars
|
||||||
|
|
||||||
if ((pInputFile = fopen(input_path, "rb")) == NULL) {
|
if ((pInputFile = fopen(input_path, "rb")) == NULL) {
|
||||||
display_error(ERROR, 104);
|
display_error(ERROR, 104);
|
||||||
|
*err_n = error_code;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,8 @@ bool cs_compress(const char *input_path, const char *output_path, cs_image_pars
|
||||||
result = cs_png_optimize(input_path, output_path, &options->png);
|
result = cs_png_optimize(input_path, output_path, &options->png);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*err_n = error_code;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ typedef enum error_level
|
||||||
WARNING = 1
|
WARNING = 1
|
||||||
} 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, int* err_n);
|
||||||
cs_image_pars initialize_parameters();
|
cs_image_pars initialize_parameters();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
#define VERSION_MAJOR @VERSION_MAJOR@
|
#define VERSION_MAJOR @VERSION_MAJOR@
|
||||||
#define VERSION_MINOR @VERSION_MINOR@
|
#define VERSION_MINOR @VERSION_MINOR@
|
||||||
#define VERSION_PATCH @VERSION_PATCH@
|
#define VERSION_PATCH @VERSION_PATCH@
|
||||||
|
|
||||||
|
#define VERBOSE @VERBOSE@
|
|
@ -1,18 +1,23 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
void display_error(error_level level, int code)
|
int error_code = 0;
|
||||||
{
|
|
||||||
|
void display_error(error_level level, int code) {
|
||||||
|
error_code = code;
|
||||||
|
if (VERBOSE) {
|
||||||
char *error_level = ((level) ? "[WARNING]" : "[ERROR]");
|
char *error_level = ((level) ? "[WARNING]" : "[ERROR]");
|
||||||
|
|
||||||
fprintf(stderr, "%s %d: %s\n",
|
fprintf(stderr, "%s %d: %s\n",
|
||||||
error_level,
|
error_level,
|
||||||
code,
|
code,
|
||||||
get_error_message(code));
|
get_error_message(code));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *get_error_message(int code)
|
const char *get_error_message(int code) {
|
||||||
{
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
//Generic errors
|
//Generic errors
|
||||||
case 101:
|
case 101:
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include "caesium.h"
|
#include "caesium.h"
|
||||||
|
|
||||||
|
extern int error_code;
|
||||||
|
|
||||||
void display_error(error_level level, int code);
|
void display_error(error_level level, int code);
|
||||||
|
|
||||||
const char *get_error_message(int code);
|
const char *get_error_message(int code);
|
||||||
|
|
3
config.h
3
config.h
|
@ -1,3 +0,0 @@
|
||||||
#define VERSION_MAJOR 0
|
|
||||||
#define VERSION_MINOR 4
|
|
||||||
#define VERSION_PATCH 1
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
if (NOT WIN32)
|
||||||
|
set(CMAKE_C_FLAGS "--std=gnu99 -fPIC -Wno-nullability-completeness ${CMAKE_C_FLAGS}")
|
||||||
|
else ()
|
||||||
|
set(CMAKE_C_FLAGS "--std=gnu99 ${CMAKE_C_FLAGS}")
|
||||||
|
endif ()
|
||||||
|
|
||||||
add_executable(caesiumd main.c)
|
add_executable(caesiumd main.c)
|
||||||
|
|
||||||
target_link_libraries(caesiumd LINK_PUBLIC caesium)
|
target_link_libraries(caesiumd LINK_PUBLIC caesium)
|
|
@ -1,6 +1,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "caesium.h"
|
#include "../caesium/caesium.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
@ -16,7 +16,8 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_image_pars options = initialize_parameters();
|
cs_image_pars options = initialize_parameters();
|
||||||
bool result = cs_compress(argv[1], argv[2], &options);
|
int error_code = 0;
|
||||||
|
cs_compress(argv[1], argv[2], &options, &error_code);
|
||||||
|
|
||||||
exit(!result);
|
exit(error_code);
|
||||||
}
|
}
|
Loading…
Reference in New Issue