Initial support

This commit is contained in:
Matteo Paonessa 2017-02-25 10:17:33 +01:00
parent f3011b4a49
commit b54d117c86
10 changed files with 84 additions and 16 deletions

View File

@ -5,6 +5,18 @@ project(libcaesium)
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# The version number.
set(VERSION_MAJOR 0)
set(VERSION_MINOR 2)
set(VERSION_PATCH 0)
configure_file(
"caesium/config.h.in"
"${PROJECT_BINARY_DIR}/config.h"
)
include_directories("${PROJECT_BINARY_DIR}")
set(MOZJPEG_INCLUDE /opt/mozjpeg/include)
set(MOZJPEG_LIB32 /opt/mozjpeg/lib)
set(MOZJPEG_LIB64 /opt/mozjpeg/lib64)

View File

@ -1,15 +1,15 @@
set(CMAKE_C_FLAGS "--std=gnu99 -fPIC ${CMAKE_C_FLAGS}")
find_library(zoflipng zopflipng /usr/local/lib)
find_library(jpeg jpeg /opt/mozjpeg/lib)
find_library(jpeg /opt/mozjpeg/lib)
find_library(turbojpeg turbojpeg /opt/mozjpeg/lib)
add_library(caesium SHARED caesium.c error.c utils.c png.c lodepng.c jpeg.c)
add_library(caesium_static STATIC caesium.c error.c utils.c png.c lodepng.c jpeg.c)
add_library(caesium SHARED caesium.c error.c utils.c png.c lodepng.c jpeg.c tiff.c)
add_library(caesium_static STATIC caesium.c error.c utils.c png.c lodepng.c jpeg.c tiff.c)
set_target_properties(caesium_static PROPERTIES OUTPUT_NAME caesium)
target_link_libraries(caesium zopflipng jpeg turbojpeg)
target_link_libraries(caesium zopflipng jpeg turbojpeg tiff)
# Make sure the compiler can find include files for our Caesium library
# when other libraries or executables link to Caesium

View File

@ -5,6 +5,7 @@
#include "utils.h"
#include "png.h"
#include "jpeg.h"
#include "tiff.h"
bool cs_compress(const char *input_path, const char *output_path, cs_image_pars *options)
{
@ -23,7 +24,7 @@ bool cs_compress(const char *input_path, const char *output_path, cs_image_pars
if (type == UNKN) {
display_error(WARNING, 103);
} else if (type == JPEG) {
} else if (type == CS_JPEG) {
if (options->jpeg.quality != 0) {
cs_jpeg_compress(output_path, cs_jpeg_decompress(input_path, &options->jpeg), &options->jpeg);
//The output is now the new input for optimization
@ -31,8 +32,10 @@ bool cs_compress(const char *input_path, const char *output_path, cs_image_pars
} else {
result = cs_jpeg_optimize(input_path, output_path, options->jpeg.exif_copy, input_path);
}
} else if (type == PNG) {
} else if (type == CS_PNG) {
result = cs_png_optimize(input_path, output_path, &options->png);
} else if (type == CS_TIFF) {
result = cs_tiff_optimize(input_path, output_path, &options->tiff);
}
return result;
@ -55,12 +58,18 @@ void initialize_png_parameters(cs_image_pars *par)
par->png.auto_filter_strategy = 1;
}
void initialize_tiff_parameters(cs_image_pars *par)
{
par->tiff.compression = 0;
}
cs_image_pars initialize_parameters()
{
cs_image_pars options;
initialize_jpeg_parameters(&options);
initialize_png_parameters(&options);
initialize_tiff_parameters(&options);
return options;
}

View File

@ -32,16 +32,23 @@ typedef struct cs_png_pars
int auto_filter_strategy;
} cs_png_pars;
typedef struct cs_tiff_pars
{
int compression;
} cs_tiff_pars;
typedef struct cs_image_pars
{
cs_jpeg_pars jpeg;
cs_png_pars png;
cs_tiff_pars tiff;
} cs_image_pars;
typedef enum image_type
{
JPEG,
PNG,
CS_JPEG,
CS_PNG,
CS_TIFF,
UNKN,
} image_type;

3
caesium/config.h.in Normal file
View File

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

15
caesium/tiff.c Normal file
View File

@ -0,0 +1,15 @@
#include "tiff.h"
bool cs_tiff_optimize(const char *input, const char *output, cs_tiff_pars* options)
{
TIFF* in;
TIFF* out;
in = TIFFOpen(input, "rb");
TIFFClose(in);
TIFFClose(out);
return true;
}

11
caesium/tiff.h Normal file
View File

@ -0,0 +1,11 @@
#include <stdbool.h>
#ifndef LIBCAESIUM_TIFF_H
#define LIBCAESIUM_TIFF_H
#include <tiffio.h>
#include "caesium.h"
bool cs_tiff_optimize(const char *input, const char *output, cs_tiff_pars* options);
#endif //LIBCAESIUM_TIFF_H

View File

@ -6,21 +6,24 @@
image_type detect_image_type(FILE *pFile)
{
unsigned char buffer[2];
unsigned char buffer[4];
if (pFile == NULL) {
display_error(WARNING, 101);
return UNKN;
}
if (fread(buffer, 1, 2, pFile) < 2) {
if (fread(buffer, 1, 4, pFile) < 4) {
return UNKN;
}
if (buffer[0] == 0xFF && buffer[1] == 0xD8) {
return JPEG;
if (buffer[0] == 0xFF && buffer[1] == 0xFF) {
return CS_JPEG;
} else if (buffer[0] == 0x89 && buffer[1] == 0x50) {
return PNG;
return CS_PNG;
} else if ((buffer[0] == 0x49 && buffer[1] == 0x49 && buffer[2] == 0x2A && buffer[3] == 0x00)
|| (buffer[0] == 0x4D && buffer[1] == 0x4D && buffer[2] == 0x00 && buffer[3] == 0x2A)) {
return CS_TIFF;
}
return UNKN;

View File

@ -1,14 +1,22 @@
#include <stdio.h>
#include <stdlib.h>
#include "caesium.h"
#include "config.h"
int main(int argc, char *argv[])
{
fprintf(stdout, "libcaesium demo application v%d.%d.%d\n\n",
VERSION_MAJOR,
VERSION_MINOR,
VERSION_PATCH);
if (argc != 3) {
fprintf(stderr, "Wrong arguments.\nExiting.\n");
return -1;
exit(EXIT_FAILURE);
}
cs_image_pars options = initialize_parameters();
cs_compress(argv[1], argv[2], &options);
return 0;
exit(EXIT_SUCCESS);
}

View File

@ -4,7 +4,7 @@
git clone https://github.com/mozilla/mozjpeg
cd mozjpeg/
autoreconf -fiv
autoreconf -fiv
autoreconf -fiv #It's not a typo, trust me
mkdir build && cd build
../configure
make && sudo make install