parent
861a38137e
commit
6439cdcbd3
|
@ -1,5 +1,5 @@
|
||||||
## Caesium Command Line Tools
|
## Caesium Command Line Tools
|
||||||
##### CCLT - v0.9.1-beta (build 20160423) - Copyright © Matteo Paonessa, 2016. All Rights Reserved.
|
##### CCLT - v0.9.1-beta (build 20160808) - Copyright © Matteo Paonessa, 2016. All Rights Reserved.
|
||||||
|
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ Check the [Commits](https://github.com/Lymphatus/CaesiumCLT/commits/master) for
|
||||||
----------
|
----------
|
||||||
|
|
||||||
###### RESOURCES
|
###### RESOURCES
|
||||||
* CaesiumCLT website - [http://saerasoft.com/caesium](http://saerasoft.com/caesium/clt)
|
* CaesiumCLT website - [http://saerasoft.com/caesium/clt](http://saerasoft.com/caesium/clt)
|
||||||
* Caesium website - [http://saerasoft.com/caesium](http://saerasoft.com/caesium)
|
* Caesium website - [http://saerasoft.com/caesium](http://saerasoft.com/caesium)
|
||||||
* CaesiumCLT Git Repository - [https://github.com/Lymphatus/CaesiumCLT](https://github.com/Lymphatus/CaesiumCLT)
|
* CaesiumCLT Git Repository - [https://github.com/Lymphatus/CaesiumCLT](https://github.com/Lymphatus/CaesiumCLT)
|
||||||
* Author website - SaeraSoft - [http://saerasoft.com](http://saerasoft.com)
|
* Author website - SaeraSoft - [http://saerasoft.com](http://saerasoft.com)
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "jpeg.h"
|
#include "jpeg.h"
|
||||||
|
@ -22,16 +23,16 @@ void initialize_jpeg_parameters(cclt_parameters* par) {
|
||||||
par->jpeg.height = 0;
|
par->jpeg.height = 0;
|
||||||
par->jpeg.color_space = TJCS_RGB;
|
par->jpeg.color_space = TJCS_RGB;
|
||||||
par->jpeg.dct_method = TJFLAG_FASTDCT;
|
par->jpeg.dct_method = TJFLAG_FASTDCT;
|
||||||
par->jpeg.exif_copy = 0;
|
par->jpeg.exif_copy = false;
|
||||||
par->jpeg.lossless = 0;
|
par->jpeg.lossless = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize_png_parameters(cclt_parameters* par) {
|
void initialize_png_parameters(cclt_parameters* par) {
|
||||||
par->png.iterations = 15;
|
par->png.iterations = 10;
|
||||||
par->png.iterations_large = 5;
|
par->png.iterations_large = 5;
|
||||||
par->png.block_split_strategy = 4;
|
par->png.block_split_strategy = 4;
|
||||||
par->png.lossy_8 = 1;
|
par->png.lossy_8 = true;
|
||||||
par->png.transparent = 1;
|
par->png.transparent = true;
|
||||||
par->png.auto_filter_strategy = 1;
|
par->png.auto_filter_strategy = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,19 +46,19 @@ cclt_parameters initialize_compression_parameters() {
|
||||||
par.input_files_count = 0;
|
par.input_files_count = 0;
|
||||||
par.recursive = 0;
|
par.recursive = 0;
|
||||||
par.input_files = NULL;
|
par.input_files = NULL;
|
||||||
par.structure = 0;
|
par.structure = false;
|
||||||
|
|
||||||
return par;
|
return par;
|
||||||
}
|
}
|
||||||
|
|
||||||
void validate_parameters(cclt_parameters* pars) {
|
void validate_parameters(cclt_parameters* pars) {
|
||||||
//Either -l or -q must be set but not together
|
//Either -l or -q must be set but not together
|
||||||
if (!((pars->jpeg.lossless == 1) ^ (pars->jpeg.quality > 0))) {
|
if (!((pars->jpeg.lossless) ^ (pars->jpeg.quality > 0))) {
|
||||||
//Both or none are set
|
//Both or none are set
|
||||||
if (pars->jpeg.lossless == 1 && pars->jpeg.quality > 0) {
|
if (pars->jpeg.lossless && pars->jpeg.quality > 0) {
|
||||||
fprintf(stderr, "[ERROR] -l option can't be used with -q. Either use one or the other.\n");
|
fprintf(stderr, "[ERROR] -l option can't be used with -q. Either use one or the other.\n");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
} else if (pars->jpeg.lossless == 0 && pars->jpeg.quality <= 0) {
|
} else if (!pars->jpeg.lossless && pars->jpeg.quality <= 0) {
|
||||||
fprintf(stderr, "[ERROR] Either -l or -q must be set.\n");
|
fprintf(stderr, "[ERROR] Either -l or -q must be set.\n");
|
||||||
exit(-2);
|
exit(-2);
|
||||||
}
|
}
|
||||||
|
@ -93,7 +94,7 @@ cclt_parameters parse_arguments(int argc, char* argv[]) {
|
||||||
if ((c = getopt (argc, argv, "q:velo:s:hR")) != -1) {
|
if ((c = getopt (argc, argv, "q:velo:s:hR")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'v':
|
case 'v':
|
||||||
printf("%s (Build: %d)\n", APP_VERSION, BUILD);
|
printf("%s-%d\n", APP_VERSION, BUILD);
|
||||||
exit(0);
|
exit(0);
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
|
@ -116,10 +117,10 @@ cclt_parameters parse_arguments(int argc, char* argv[]) {
|
||||||
parameters.jpeg.quality = string_to_int(optarg);
|
parameters.jpeg.quality = string_to_int(optarg);
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
parameters.jpeg.exif_copy = 1;
|
parameters.jpeg.exif_copy = true;
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
parameters.jpeg.lossless = 1;
|
parameters.jpeg.lossless = true;
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
parameters.output_folder = optarg;
|
parameters.output_folder = optarg;
|
||||||
|
@ -128,10 +129,10 @@ cclt_parameters parse_arguments(int argc, char* argv[]) {
|
||||||
print_help();
|
print_help();
|
||||||
break;
|
break;
|
||||||
case 'R':
|
case 'R':
|
||||||
parameters.recursive = 1;
|
parameters.recursive = true;
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
parameters.structure = 1;
|
parameters.structure = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
abort();
|
abort();
|
||||||
|
@ -171,6 +172,7 @@ int cclt_compress_routine(char* input, char* output, cclt_parameters* pars) {
|
||||||
//Detect which image type are we compressing
|
//Detect which image type are we compressing
|
||||||
enum image_type type = detect_image_type(input);
|
enum image_type type = detect_image_type(input);
|
||||||
char* exif_orig = (char*) malloc(strlen(input) * sizeof(char));
|
char* exif_orig = (char*) malloc(strlen(input) * sizeof(char));
|
||||||
|
strcpy(exif_orig, input);
|
||||||
|
|
||||||
if (type == JPEG) {
|
if (type == JPEG) {
|
||||||
//Lossy processing just uses the compression method before optimizing
|
//Lossy processing just uses the compression method before optimizing
|
||||||
|
@ -180,7 +182,6 @@ int cclt_compress_routine(char* input, char* output, cclt_parameters* pars) {
|
||||||
//If we are using lossy compression, the input file is the output of
|
//If we are using lossy compression, the input file is the output of
|
||||||
//the previous function
|
//the previous function
|
||||||
//Exif must be copied from the original thou
|
//Exif must be copied from the original thou
|
||||||
strcpy(exif_orig, input);
|
|
||||||
input = output;
|
input = output;
|
||||||
}
|
}
|
||||||
//Optimize
|
//Optimize
|
||||||
|
|
|
@ -26,7 +26,7 @@ struct jpeg_decompress_struct cclt_get_markers(char* input) {
|
||||||
//Check for errors
|
//Check for errors
|
||||||
//TODO Use UNIX error messages
|
//TODO Use UNIX error messages
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
printf("[ERROR] Failed to open file \"%s\".\n", input);
|
printf("[ERROR] Failed to open file (markers) \"%s\".\n", input);
|
||||||
exit(-13);
|
exit(-13);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ int cclt_jpeg_optimize(char* input_file, char* output_file, int exif_flag, char*
|
||||||
//Check for errors
|
//Check for errors
|
||||||
//TODO Use UNIX error messages
|
//TODO Use UNIX error messages
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
printf("[ERROR] Failed to open file \"%s\".\n", input_file);
|
printf("[ERROR] Failed to open file (input) \"%s\".\n", input_file);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ int cclt_jpeg_optimize(char* input_file, char* output_file, int exif_flag, char*
|
||||||
jpeg_stdio_src(&srcinfo, fp);
|
jpeg_stdio_src(&srcinfo, fp);
|
||||||
|
|
||||||
//Save EXIF info
|
//Save EXIF info
|
||||||
if (exif_flag == 1) {
|
if (exif_flag) {
|
||||||
for (int m = 0; m < 16; m++) {
|
for (int m = 0; m < 16; m++) {
|
||||||
jpeg_save_markers(&srcinfo, JPEG_APP0 + m, 0xFFFF);
|
jpeg_save_markers(&srcinfo, JPEG_APP0 + m, 0xFFFF);
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ int cclt_jpeg_optimize(char* input_file, char* output_file, int exif_flag, char*
|
||||||
//Check for errors
|
//Check for errors
|
||||||
//TODO Use UNIX error messages
|
//TODO Use UNIX error messages
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
printf("[ERROR] Failed to open file \"%s\".\n", output_file);
|
printf("[ERROR] Failed to open file (output) \"%s\".\n", output_file);
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
src/utils.h
17
src/utils.h
|
@ -4,9 +4,10 @@
|
||||||
#include <jpeglib.h>
|
#include <jpeglib.h>
|
||||||
#include <turbojpeg.h>
|
#include <turbojpeg.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define APP_VERSION "0.9.1-beta"
|
#define APP_VERSION "0.9.1"
|
||||||
#define BUILD 20160421
|
#define BUILD 20160808
|
||||||
|
|
||||||
typedef struct cclt_jpeg_parameters {
|
typedef struct cclt_jpeg_parameters {
|
||||||
int quality;
|
int quality;
|
||||||
|
@ -14,8 +15,8 @@ typedef struct cclt_jpeg_parameters {
|
||||||
int height;
|
int height;
|
||||||
int color_space;
|
int color_space;
|
||||||
int dct_method;
|
int dct_method;
|
||||||
int exif_copy;
|
bool exif_copy;
|
||||||
int lossless;
|
bool lossless;
|
||||||
enum TJSAMP subsample;
|
enum TJSAMP subsample;
|
||||||
} cclt_jpeg_parameters;
|
} cclt_jpeg_parameters;
|
||||||
|
|
||||||
|
@ -23,8 +24,8 @@ typedef struct cclt_png_parameters {
|
||||||
int iterations;
|
int iterations;
|
||||||
int iterations_large;
|
int iterations_large;
|
||||||
int block_split_strategy;
|
int block_split_strategy;
|
||||||
int lossy_8;
|
bool lossy_8;
|
||||||
int transparent;
|
bool transparent;
|
||||||
int auto_filter_strategy;
|
int auto_filter_strategy;
|
||||||
} cclt_png_parameters;
|
} cclt_png_parameters;
|
||||||
|
|
||||||
|
@ -35,8 +36,8 @@ typedef struct cclt_parameters {
|
||||||
char* output_folder;
|
char* output_folder;
|
||||||
char** input_files;
|
char** input_files;
|
||||||
int input_files_count;
|
int input_files_count;
|
||||||
int recursive;
|
bool recursive;
|
||||||
int structure;
|
bool structure;
|
||||||
} cclt_parameters;
|
} cclt_parameters;
|
||||||
|
|
||||||
enum image_type {
|
enum image_type {
|
||||||
|
|
Loading…
Reference in New Issue