Merge pull request #2 from Lymphatus/tiff

Reverted experimental TIFF support
This commit is contained in:
Matteo Paonessa 2017-03-18 11:52:18 -07:00 committed by GitHub
commit d61b709702
10 changed files with 54 additions and 26 deletions

View File

@ -8,7 +8,7 @@ compiler:
- clang - clang
before_install: before_install:
- sudo apt-get install libtool autoconf git nasm - sudo apt-get install libtool autoconf git nasm pkg-config cmake libtiff-dev
- chmod +x install.sh - chmod +x install.sh
- ./install.sh - ./install.sh

View File

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

View File

@ -1,7 +1,7 @@
set(CMAKE_C_FLAGS "--std=gnu99 -fPIC ${CMAKE_C_FLAGS}") set(CMAKE_C_FLAGS "--std=gnu99 -fPIC ${CMAKE_C_FLAGS}")
find_library(zoflipng zopflipng /usr/local/lib) 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) 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 SHARED caesium.c error.c utils.c png.c lodepng.c jpeg.c)
@ -9,13 +9,24 @@ add_library(caesium_static STATIC caesium.c error.c utils.c png.c lodepng.c jpeg
set_target_properties(caesium_static PROPERTIES OUTPUT_NAME caesium) 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 # Make sure the compiler can find include files for our Caesium library
# when other libraries or executables link to Caesium # when other libraries or executables link to Caesium
target_include_directories(caesium PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(caesium PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
install(FILES caesium.h DESTINATION include) # OSX installs in local
install(TARGETS caesium caesium_static if (APPLE)
LIBRARY DESTINATION lib install(FILES caesium.h DESTINATION /usr/local/include)
ARCHIVE DESTINATION lib) install(TARGETS LIBRARY DESTINATION /usr/local/lib)
install(TARGETS ARCHIVE DESTINATION /usr/local/lib)
elseif (UNIX)
install(FILES caesium.h DESTINATION /usr/include)
install(TARGETS LIBRARY DESTINATION /usr/lib)
install(TARGETS ARCHIVE DESTINATION /usr/lib)
else ()
install(FILES caesium.h DESTINATION include)
install(TARGETS caesium caesium_static
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif ()

View File

@ -23,7 +23,7 @@ bool cs_compress(const char *input_path, const char *output_path, cs_image_pars
if (type == UNKN) { if (type == UNKN) {
display_error(WARNING, 103); display_error(WARNING, 103);
} else if (type == JPEG) { } else if (type == CS_JPEG) {
if (options->jpeg.quality != 0) { if (options->jpeg.quality != 0) {
cs_jpeg_compress(output_path, cs_jpeg_decompress(input_path, &options->jpeg), &options->jpeg); cs_jpeg_compress(output_path, cs_jpeg_decompress(input_path, &options->jpeg), &options->jpeg);
//The output is now the new input for optimization //The output is now the new input for optimization
@ -31,7 +31,7 @@ bool cs_compress(const char *input_path, const char *output_path, cs_image_pars
} else { } else {
result = cs_jpeg_optimize(input_path, output_path, options->jpeg.exif_copy, input_path); 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); result = cs_png_optimize(input_path, output_path, &options->png);
} }

View File

@ -40,8 +40,8 @@ typedef struct cs_image_pars
typedef enum image_type typedef enum image_type
{ {
JPEG, CS_JPEG,
PNG, CS_PNG,
UNKN, UNKN,
} image_type; } 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@

View File

@ -18,9 +18,9 @@ image_type detect_image_type(FILE *pFile)
} }
if (buffer[0] == 0xFF && buffer[1] == 0xD8) { if (buffer[0] == 0xFF && buffer[1] == 0xD8) {
return JPEG; return CS_JPEG;
} else if (buffer[0] == 0x89 && buffer[1] == 0x50) { } else if (buffer[0] == 0x89 && buffer[1] == 0x50) {
return PNG; return CS_PNG;
} }
return UNKN; return UNKN;

View File

@ -1,5 +1,3 @@
add_executable(caesiumd main.c) add_executable(caesiumd main.c)
target_link_libraries(caesiumd LINK_PUBLIC caesium) target_link_libraries(caesiumd LINK_PUBLIC caesium)
install(TARGETS caesiumd DESTINATION bin)

View File

@ -1,14 +1,22 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include "caesium.h" #include "caesium.h"
#include "config.h"
int main(int argc, char *argv[]) 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) { if (argc != 3) {
fprintf(stderr, "Wrong arguments.\nExiting.\n"); fprintf(stderr, "Wrong arguments.\nExiting.\n");
return -1; exit(EXIT_FAILURE);
} }
cs_image_pars options = initialize_parameters(); cs_image_pars options = initialize_parameters();
cs_compress(argv[1], argv[2], &options); 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 git clone https://github.com/mozilla/mozjpeg
cd mozjpeg/ cd mozjpeg/
autoreconf -fiv autoreconf -fiv
autoreconf -fiv autoreconf -fiv #It's not a typo, trust me
mkdir build && cd build mkdir build && cd build
../configure ../configure
make && sudo make install make && sudo make install