Merge pull request #5 from Lymphatus/windows

Windows
This commit is contained in:
Matteo Paonessa 2016-01-22 10:37:34 +01:00
commit 9c21b24d1b
9 changed files with 46 additions and 55 deletions

3
.gitignore vendored
View File

@ -4,4 +4,5 @@ tmp/*
build/* build/*
autom4te.cache autom4te.cache
aclocal.m4 aclocal.m4
configure configure
configure

View File

@ -1,5 +1,5 @@
## Caesium Command Line Tools ## Caesium Command Line Tools
##### CCLT - v0.9.1-beta (build 20151012) - Copyright © Matteo Paonessa, 2015. All Rights Reserved. ##### CCLT - v0.9.1-beta (build 20160121) - Copyright © Matteo Paonessa, 2016. All Rights Reserved.
---------- ----------
@ -11,7 +11,7 @@
---------- ----------
###### TESTED PLATFORMS ###### TESTED PLATFORMS
* MacOSX El Capitan (v. 10.11) * Mac OS X El Capitan (v10.11.1)
* Arch Linux * Arch Linux
* Ubuntu 14.04.2 * Ubuntu 14.04.2
@ -23,30 +23,26 @@ See INSTALL for more details.
---------- ----------
###### USAGE EXAMPLES ###### USAGE EXAMPLES
Losslessly compress ```image1.jpg```, located in the ```home``` directory, into a folder called ```output```
``` ```
$ caesiumclt -l -o ~/output/ ~/image.jpg $ caesiumclt -l -o ~/output/ ~/image.jpg
``` ```
Losslessly compress ```image1.jpg```, located in the ```home``` directory, into a folder called ```output```
Compress ```image1.jpg```, located in the ```home``` directory, into a folder called ```output``` with lossy compression and quality set to 80
``` ```
$ caesiumclt -q 80 -o ~/output/ ~/image.jpg $ caesiumclt -q 80 -o ~/output/ ~/image.jpg
``` ```
Compress ```image1.jpg```, located in the ```home``` directory, into a folder called ```output``` with lossy compression and quality set to 80
Losslessly compress ```image1.jpg```, located in the ```home``` directory, into a folder called ```output``` and keeps EXIF metadata
``` ```
$ caesiumclt -l -e -o ~/output/ ~/image.jpg $ caesiumclt -l -e -o ~/output/ ~/image.jpg
``` ```
Losslessly compress ```image1.jpg```, located in the ```home``` directory, into a folder called ```output``` and keeps EXIF metadata
Losslessly compress ```Pictures``` folder and subfolders, located in the ```home``` directory, into a folder called ```output```
``` ```
$ caesiumclt -l -R -o ~/output/ ~/Pictures $ caesiumclt -l -R -o ~/output/ ~/Pictures
``` ```
Losslessly compress ```Pictures``` folder and subfolders, located in the ```home``` directory, into a folder called ```output```
```
$ caesiumclt -q 80 -s 50% -o ~/output/ ~/image1.jpg
```
Compress with quality 80 and resize at 50% ```image1.jpg```, located in the ```home``` directory, into a folder called ```output```
---------- ----------

20
configure vendored
View File

@ -1,6 +1,6 @@
#! /bin/sh #! /bin/sh
# Guess values for system-dependent variables and create Makefiles. # Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for caesiumclt 1.9.9. # Generated by GNU Autoconf 2.69 for caesiumclt 0.9.1-beta.
# #
# Report bugs to <caesium@saerasoft.com>. # Report bugs to <caesium@saerasoft.com>.
# #
@ -580,8 +580,8 @@ MAKEFLAGS=
# Identity of this package. # Identity of this package.
PACKAGE_NAME='caesiumclt' PACKAGE_NAME='caesiumclt'
PACKAGE_TARNAME='caesiumclt' PACKAGE_TARNAME='caesiumclt'
PACKAGE_VERSION='1.9.9' PACKAGE_VERSION='0.9.1-beta'
PACKAGE_STRING='caesiumclt 1.9.9' PACKAGE_STRING='caesiumclt 0.9.1-beta'
PACKAGE_BUGREPORT='caesium@saerasoft.com' PACKAGE_BUGREPORT='caesium@saerasoft.com'
PACKAGE_URL='' PACKAGE_URL=''
@ -1267,7 +1267,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing. # Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh. # This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF cat <<_ACEOF
\`configure' configures caesiumclt 1.9.9 to adapt to many kinds of systems. \`configure' configures caesiumclt 0.9.1-beta to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]... Usage: $0 [OPTION]... [VAR=VALUE]...
@ -1333,7 +1333,7 @@ fi
if test -n "$ac_init_help"; then if test -n "$ac_init_help"; then
case $ac_init_help in case $ac_init_help in
short | recursive ) echo "Configuration of caesiumclt 1.9.9:";; short | recursive ) echo "Configuration of caesiumclt 0.9.1-beta:";;
esac esac
cat <<\_ACEOF cat <<\_ACEOF
@ -1429,7 +1429,7 @@ fi
test -n "$ac_init_help" && exit $ac_status test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then if $ac_init_version; then
cat <<\_ACEOF cat <<\_ACEOF
caesiumclt configure 1.9.9 caesiumclt configure 0.9.1-beta
generated by GNU Autoconf 2.69 generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc. Copyright (C) 2012 Free Software Foundation, Inc.
@ -1852,7 +1852,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake. running configure, to aid debugging if configure makes a mistake.
It was created by caesiumclt $as_me 1.9.9, which was It was created by caesiumclt $as_me 0.9.1-beta, which was
generated by GNU Autoconf 2.69. Invocation command line was generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@ $ $0 $@
@ -2716,7 +2716,7 @@ fi
# Define the identity of the package. # Define the identity of the package.
PACKAGE='caesiumclt' PACKAGE='caesiumclt'
VERSION='1.9.9' VERSION='0.9.1-beta'
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
@ -5130,7 +5130,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their # report actual input values of CONFIG_FILES etc. instead of their
# values after options handling. # values after options handling.
ac_log=" ac_log="
This file was extended by caesiumclt $as_me 1.9.9, which was This file was extended by caesiumclt $as_me 0.9.1-beta, which was
generated by GNU Autoconf 2.69. Invocation command line was generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES CONFIG_FILES = $CONFIG_FILES
@ -5187,7 +5187,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\ ac_cs_version="\\
caesiumclt config.status 1.9.9 caesiumclt config.status 0.9.1-beta
configured by $0, generated by GNU Autoconf 2.69, configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\" with options \\"\$ac_cs_config\\"

View File

@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script. # Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69]) AC_PREREQ([2.69])
AC_INIT([caesiumclt], [1.9.9], [caesium@saerasoft.com]) AC_INIT([caesiumclt], [0.9.1-beta], [caesium@saerasoft.com])
AC_CONFIG_SRCDIR([src/]) AC_CONFIG_SRCDIR([src/])
AC_CONFIG_AUX_DIR(tools) AC_CONFIG_AUX_DIR(tools)
AM_INIT_AUTOMAKE(-Wall -Werror foreign) AM_INIT_AUTOMAKE(-Wall -Werror foreign)
@ -22,10 +22,10 @@ AC_ARG_WITH(libjpeg, [ --libjpeg=DIR libjpeg is installed in ],
fi fi
if test -d "${jpeginfo_cv_libjpeg}/lib"; then if test -d "${jpeginfo_cv_libjpeg}/lib"; then
LDFLAGS="-L${jpeginfo_cv_libjpeg}/lib $LDFLAGS" LDFLAGS="-L${jpeginfo_cv_libjpeg}/lib $LDFLAGS"
CPPFLAGS="$CPPFLAGS -I${jpeginfo_cv_libjpeg}/include" CPPFLAGS="$CPPFLAGS -I${jpeginfo_cv_libjpeg}/include"
else else
LDFLAGS="-L${jpeginfo_cv_libjpeg} $LDFLAGS" LDFLAGS="-L${jpeginfo_cv_libjpeg} $LDFLAGS"
CPPFLAGS="$CPPFLAGS -I${jpeginfo_cv_libjpeg}" CPPFLAGS="$CPPFLAGS -I${jpeginfo_cv_libjpeg}"
fi]) fi])
# Checks for libraries. # Checks for libraries.

View File

@ -5,8 +5,8 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <turbojpeg.h> #include <turbojpeg.h>
#include <getopt.h>
#include <ctype.h> #include <ctype.h>
#include <getopt.h>
#include "utils.h" #include "utils.h"
#include "jpeg.h" #include "jpeg.h"
@ -88,9 +88,10 @@ cclt_compress_parameters parse_arguments(int argc, char* argv[]) {
} }
} else { } else {
int i = 0; int i = 0;
if (isDirectory(argv[optind])) { if (is_directory(argv[optind])) {
//TODO Works but I'd like to pass the list and return the number of files instead //TODO Works but I'd like to pass the list and return the number of files instead
parameters.input_files = scan_folder(argv[optind], &parameters.input_files_count, parameters.recursive); parameters.input_files_count = scan_folder(parameters.input_files, argv[optind], parameters.recursive);
//parameters.input_files = scan_folder(argv[optind], &parameters.input_files_count, parameters.recursive);
return parameters; return parameters;
} }
parameters.input_files = (char**) malloc ((argc - optind) * sizeof (char*)); parameters.input_files = (char**) malloc ((argc - optind) * sizeof (char*));

View File

@ -167,7 +167,6 @@ void cclt_jpeg_compress(char* output_file, unsigned char* image_buffer, cclt_com
output_buffer = NULL; output_buffer = NULL;
tjCompressHandle = tjInitCompress(); tjCompressHandle = tjInitCompress();
//TODO Scale must be a power of 2. Can we resolve it?
//TODO Error checks //TODO Error checks
tjCompress2(tjCompressHandle, tjCompress2(tjCompressHandle,
image_buffer, image_buffer,

View File

@ -45,9 +45,13 @@ void cclt_start(char** input_files, int n, char* output_folder, cclt_compress_pa
off_t i_size, o_size; off_t i_size, o_size;
int status; //Pointer for stat() call int status; //Pointer for stat() call
char* output_filename = (char*) malloc ((strlen(output_folder) + 1) * sizeof(char)); char* output_filename = (char*) malloc ((strlen(output_folder) + 1) * sizeof(char));
//CRITICAL SEGFUCKINGFAULT
//TODO input_files[i] è NULL when we pass a folder with -R
char* i_tmp = (char*) malloc (strlen(input_files[i]) * sizeof(char)); char* i_tmp = (char*) malloc (strlen(input_files[i]) * sizeof(char));
strcpy(i_tmp, input_files[i]); strcpy(i_tmp, input_files[i]);
strcpy(output_filename, output_folder); strcpy(output_filename, output_folder);
@ -61,9 +65,6 @@ void cclt_start(char** input_files, int n, char* output_folder, cclt_compress_pa
output_filename = realloc(output_filename, (strlen(output_filename) + strlen(basename(i_tmp))) * sizeof(char)); output_filename = realloc(output_filename, (strlen(output_filename) + strlen(basename(i_tmp))) * sizeof(char));
output_filename = strcat(output_filename, basename(i_tmp)); output_filename = strcat(output_filename, basename(i_tmp));
//TODO OVERALL progress update?
//print_progress(i + 1, pars.input_files_count, "Progress: ");
//Get input stats //Get input stats
status = stat(input_files[i], &st_buf); status = stat(input_files[i], &st_buf);
if (status != 0) { if (status != 0) {
@ -73,7 +74,7 @@ void cclt_start(char** input_files, int n, char* output_folder, cclt_compress_pa
//Check if we ran into a folder //Check if we ran into a folder
//TODO Check symlinks too //TODO Check symlinks too
if (isDirectory(input_files[i])) { if (is_directory(input_files[i])) {
//Folder found, but we don't need it here //Folder found, but we don't need it here
printf("Folder found\n"); printf("Folder found\n");
i++; i++;
@ -161,6 +162,9 @@ int main (int argc, char *argv[]) {
clock_t start = clock(), diff; clock_t start = clock(), diff;
//We need the file list right here //We need the file list right here
cclt_start(pars.input_files, pars.input_files_count, pars.output_folder, &pars, &i_t_size, &o_t_size); cclt_start(pars.input_files, pars.input_files_count, pars.output_folder, &pars, &i_t_size, &o_t_size);
/*for (int i = 0; i < pars.input_files_count; i++) {
printf("FILE %d: %s\n", i, pars.input_files[i]);
}*/
diff = clock() - start; diff = clock() - start;
fprintf(stdout, "-------------------------------\nCompression completed in %lum%lus\n%s -> %s [%.2f%% | %s]\n", fprintf(stdout, "-------------------------------\nCompression completed in %lum%lus\n%s -> %s [%.2f%% | %s]\n",
@ -171,5 +175,5 @@ int main (int argc, char *argv[]) {
((float) o_t_size - i_t_size) * 100 / i_t_size, ((float) o_t_size - i_t_size) * 100 / i_t_size,
get_human_size(((long) o_t_size - i_t_size))); get_human_size(((long) o_t_size - i_t_size)));
exit(0); return 0;
} }

View File

@ -51,7 +51,6 @@ void print_help() {
"\t-e\tkeeps EXIF info during compression\n" "\t-e\tkeeps EXIF info during compression\n"
"\t-o\tcompress to custom folder\n" "\t-o\tcompress to custom folder\n"
"\t-l\tuse lossless optimization\n" "\t-l\tuse lossless optimization\n"
"\t-s\tscale to value, expressed as percentage (e.g. 20%%) [Only 1/2^n allowed]\n"
"\t-R\tif input is a folder, scan subfolders too\n" "\t-R\tif input is a folder, scan subfolders too\n"
//TODO Remove this warning //TODO Remove this warning
"\t-S\tkeep the folder structure [Not active yet]\n" "\t-S\tkeep the folder structure [Not active yet]\n"
@ -60,14 +59,6 @@ void print_help() {
exit(0); exit(0);
} }
void print_progress(int current, int max, char* message) {
fprintf(stdout, "\e[?25l");
fprintf(stdout, "\r%s[%d%%]", message, current * 100 / max);
if (current == max) {
fprintf(stdout, "\e[?25h\n");
}
}
//TODO Recheck //TODO Recheck
int mkpath(const char *pathname, mode_t mode) { int mkpath(const char *pathname, mode_t mode) {
@ -76,7 +67,7 @@ int mkpath(const char *pathname, mode_t mode) {
/* make a parent directory path */ /* make a parent directory path */
strncpy(parent, pathname, sizeof(parent)); strncpy(parent, pathname, sizeof(parent));
parent[sizeof(parent) - 1] = '\0'; parent[sizeof(parent) - 1] = '\0';
for(p = parent + strlen(parent); *p != '/' && p != parent; p--); for (p = parent + strlen(parent); *p != '/' && p != parent; p--);
*p = '\0'; *p = '\0';
/* try make parent directory */ /* try make parent directory */
if(p != parent && mkpath(parent, mode) != 0) { if(p != parent && mkpath(parent, mode) != 0) {
@ -93,19 +84,18 @@ int mkpath(const char *pathname, mode_t mode) {
return -1; return -1;
} }
char** scan_folder(char* basedir, int* n, int recur) { int scan_folder(char** fileList, char* basedir, int recur) {
//TODO CRITIAL Pass list as 1st parameter
DIR *dir; DIR *dir;
struct dirent *ent; struct dirent *ent;
char* entpath = NULL; char* entpath = NULL;
struct stat s; struct stat s;
int indexes = 0; int indexes = 0;
int i = 0; int i = 0;
char** fileList = NULL;
char absolute_path[PATH_MAX]; char absolute_path[PATH_MAX];
char* ptr = realpath(basedir, absolute_path); char* ptr = realpath(basedir, absolute_path);
dir = opendir(ptr); dir = opendir(ptr);
if (dir != NULL) { if (dir != NULL) {
@ -130,7 +120,7 @@ char** scan_folder(char* basedir, int* n, int recur) {
if (S_ISDIR(s.st_mode)) { if (S_ISDIR(s.st_mode)) {
// Directory, walk it if recursive is set // Directory, walk it if recursive is set
if (recur != 0) { if (recur != 0) {
fileList = scan_folder(entpath, n, recur); scan_folder(fileList, entpath, recur);
} }
} else { } else {
//File, add to the list //File, add to the list
@ -142,6 +132,7 @@ char** scan_folder(char* basedir, int* n, int recur) {
fileList[i] = (char*) malloc(strlen(entpath) * sizeof(char)); fileList[i] = (char*) malloc(strlen(entpath) * sizeof(char));
//Copy the file path in the array //Copy the file path in the array
fileList[i] = strcpy(fileList[i], entpath); fileList[i] = strcpy(fileList[i], entpath);
printf("%s\n", fileList[i]);
i++; i++;
} }
} }
@ -151,8 +142,8 @@ char** scan_folder(char* basedir, int* n, int recur) {
exit(-19); exit(-19);
} }
free(entpath); free(entpath);
*n = i;
return fileList; return i;
} }
enum image_type detect_image_type(char* path) { enum image_type detect_image_type(char* path) {
@ -187,7 +178,7 @@ enum image_type detect_image_type(char* path) {
} }
} }
int isDirectory(const char *file_path) { int is_directory(const char *file_path) {
struct stat s; struct stat s;
stat(file_path, &s); stat(file_path, &s);
return S_ISDIR(s.st_mode); return S_ISDIR(s.st_mode);

View File

@ -6,7 +6,7 @@
#include <sys/types.h> #include <sys/types.h>
#define APP_VERSION "0.9.1-beta" #define APP_VERSION "0.9.1-beta"
#define BUILD 20150921 #define BUILD 20160116
typedef struct cclt_compress_parameters { typedef struct cclt_compress_parameters {
int quality; int quality;
@ -32,11 +32,10 @@ enum image_type {
int string_to_int(char* in_string); int string_to_int(char* in_string);
void print_help(); void print_help();
void print_progress(int current, int max, char* message);
int mkpath(const char *pathname, mode_t mode); int mkpath(const char *pathname, mode_t mode);
enum image_type detect_image_type(char* path); enum image_type detect_image_type(char* path);
int isDirectory(const char *file_path); int is_directory(const char *file_path);
char** scan_folder(char* basedir, int* n, int recur); int scan_folder(char** fileList, char* basedir, int recur);
char* get_human_size(long size); char* get_human_size(long size);
#endif #endif