Merge pull request #7 from Lymphatus/0.5.0

0.5.0
This commit is contained in:
Matteo Paonessa 2019-12-23 19:11:14 +01:00 committed by GitHub
commit bc971e6023
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 98 additions and 73 deletions

View File

@ -7,8 +7,14 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# The version number.
set(VERSION_MAJOR 0)
set(VERSION_MINOR 4)
set(VERSION_PATCH 4)
set(VERSION_MINOR 5)
set(VERSION_PATCH 0)
if (DEFINED VERBOSE)
set(VERBOSE ${VERBOSE})
else ()
set(VERBOSE 0)
endif ()
configure_file(
"caesium/config.h.in"
@ -22,19 +28,19 @@ if (APPLE)
include_directories(/opt/mozjpeg/include)
include_directories(/usr/local/include)
elseif(WIN32)
elseif (WIN32)
include_directories(C:\\mozjpeg\\include)
include_directories(C:\\zopfli\\src)
else()
else ()
include_directories(/opt/mozjpeg/include)
include_directories(/usr/include/zopflipng)
if(EXISTS /opt/mozjpeg/lib64)
if (EXISTS /opt/mozjpeg/lib64)
link_directories(/opt/mozjpeg/lib64)
else()
else ()
link_directories(/opt/mozjpeg/lib)
endif()
endif()
endif ()
endif ()
link_directories(/usr/local/lib)

View File

@ -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:
```C
bool cs_compress(const char *input,
char *output,
cs_image_pars *options);
const char *output,
cs_image_pars *options,
int* err_n);
```
#### Parameters
**input** - input file path
**output** - output file path
**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
**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
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 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.
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
##### Requirements

View File

@ -1,4 +1,3 @@
#include <stdlib.h>
#include <stdio.h>
#include "error.h"
@ -6,7 +5,7 @@
#include "png.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;
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) {
display_error(ERROR, 104);
*err_n = error_code;
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);
}
*err_n = error_code;
return result;
}

View File

@ -54,7 +54,7 @@ typedef enum error_level
WARNING = 1
} 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();
#ifdef __cplusplus

View File

@ -1,3 +1,5 @@
#define VERSION_MAJOR @VERSION_MAJOR@
#define VERSION_MINOR @VERSION_MINOR@
#define VERSION_PATCH @VERSION_PATCH@
#define VERBOSE @VERBOSE@

View File

@ -1,18 +1,23 @@
#include <stdio.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]");
fprintf(stderr, "%s %d: %s\n",
error_level,
code,
get_error_message(code));
}
}
const char *get_error_message(int code)
{
const char *get_error_message(int code) {
switch (code) {
//Generic errors
case 101:

View File

@ -3,6 +3,8 @@
#include "caesium.h"
extern int error_code;
void display_error(error_level level, int code);
const char *get_error_message(int code);

View File

@ -1,3 +0,0 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 4
#define VERSION_PATCH 1

View File

@ -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)
target_link_libraries(caesiumd LINK_PUBLIC caesium)

View File

@ -1,6 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include "caesium.h"
#include "../caesium/caesium.h"
#include "config.h"
int main(int argc, char *argv[])
@ -16,7 +16,8 @@ int main(int argc, char *argv[])
}
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);
}