Minor tweaks
This commit is contained in:
parent
bf2953de2b
commit
967d0bdda4
11
README.md
11
README.md
|
@ -1,16 +1,19 @@
|
|||
## Caesium Command Line Tools
|
||||
##### CCLT - v 1.9.9 BETA (build 20150724) - Copyright © Matteo Paonessa, 2015. All Rights Reserved.
|
||||
##### CCLT - v 1.9.9 BETA (build 20150728) - Copyright © Matteo Paonessa, 2015. All Rights Reserved.
|
||||
|
||||
----------
|
||||
|
||||
###### REQUIREMENTS
|
||||
* [libjpeg-turbo](http://libjpeg-turbo.org/)
|
||||
* [libpng](http://libpng.org/)
|
||||
* [zlib](http://www.zlib.net/)
|
||||
|
||||
----------
|
||||
|
||||
###### TESTED PLATFORMS
|
||||
* MacOSX Yosemite (v. 10.10.3)
|
||||
* Linux (Arch Linux)
|
||||
* MacOSX Yosemite (v. 10.10.4)
|
||||
* Arch Linux
|
||||
* Ubuntu 14.04.2
|
||||
|
||||
----------
|
||||
|
||||
|
@ -21,7 +24,6 @@ See INSTALL for more details.
|
|||
|
||||
###### TODO
|
||||
* Recursive folder support
|
||||
* PNG and GIF lossless optimization
|
||||
|
||||
----------
|
||||
|
||||
|
@ -35,3 +37,4 @@ Note that CCLT started along with Caesium 2.0.0 so it uses its versioning system
|
|||
* Caesium website - [http://saerasoft.com/caesium](http://saerasoft.com/caesium)
|
||||
* CCLT Git Repository - [https://github.com/Lymphatus/CaesiumCLT](https://github.com/Lymphatus/CaesiumCLT)
|
||||
* Author website - SaeraSoft - [http://saerasoft.com](http://saerasoft.com)
|
||||
* Twitter - [Matteo Paonessa](https://twitter.com/MatteoPaonessa)
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "utils.h"
|
||||
#include "jpeg.h"
|
||||
#include "png.h"
|
||||
|
||||
|
||||
cclt_compress_parameters initialize_compression_parameters() {
|
||||
|
@ -44,6 +45,7 @@ cclt_compress_parameters parse_arguments(int argc, char* argv[]) {
|
|||
exit(0);
|
||||
break;
|
||||
case '?':
|
||||
//TODO if -o not specified or empty, use current. Useful?
|
||||
if (optopt == 'q' || optopt == 'o' || optopt == 's') {
|
||||
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
|
||||
//Arguments without values
|
||||
|
@ -101,11 +103,14 @@ cclt_compress_parameters parse_arguments(int argc, char* argv[]) {
|
|||
|
||||
void cclt_compress_routine(char* input, char* output, cclt_compress_parameters* pars) {
|
||||
enum image_type type = detect_image_type(input);
|
||||
if (type == JPEG) {
|
||||
if (type == JPEG && pars->lossless == 0) {
|
||||
cclt_compress(output, cclt_decompress(input, pars), pars);
|
||||
cclt_optimize(output, output, pars->exif_copy, input);
|
||||
} else if (type == JPEG && pars->lossless != 0) {
|
||||
cclt_optimize(input, output, pars->exif_copy, input);
|
||||
} else if (type == PNG) {
|
||||
printf("PNG detected. Not implemented yet.\n");
|
||||
read_png_file(input);
|
||||
write_png_file(output);
|
||||
} else if (type == GIF) {
|
||||
printf("GIF detected. Not implemented yet.\n");
|
||||
} else {
|
||||
|
|
|
@ -165,6 +165,7 @@ void cclt_compress(char* output_file, unsigned char* image_buffer, cclt_compress
|
|||
output_buffer = NULL;
|
||||
tjCompressHandle = tjInitCompress();
|
||||
|
||||
//TODO Scale must be a power of 2. Can we resolve it?
|
||||
status = tjCompress2(tjCompressHandle,
|
||||
image_buffer,
|
||||
pars->width,
|
||||
|
@ -210,6 +211,7 @@ unsigned char* cclt_decompress(char* fileName, cclt_compress_parameters* pars) {
|
|||
|
||||
pars->width = ceil(fileWidth * ((double) pars->scaling_factor / 100));
|
||||
pars->height = ceil(fileHeight * ((double) pars->scaling_factor / 100));
|
||||
|
||||
pars->subsample = jpegSubsamp;
|
||||
|
||||
if (pars->subsample == TJSAMP_GRAY) {
|
||||
|
|
14
src/main.c
14
src/main.c
|
@ -31,7 +31,7 @@
|
|||
void cclt_start(char** input_files, int n, char* output_folder, cclt_compress_parameters* pars, off_t* i_t_size, off_t* o_t_size) {
|
||||
|
||||
struct stat st_buf;
|
||||
int i = 0, lossless = pars->lossless, exif = pars->exif_copy, recursive = pars->recursive;
|
||||
int i = 0, recursive = pars->recursive;
|
||||
|
||||
if (mkpath(output_folder, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1) {
|
||||
if (errno != EEXIST) {
|
||||
|
@ -105,11 +105,11 @@ void cclt_start(char** input_files, int n, char* output_folder, cclt_compress_pa
|
|||
//TODO Do we want a more verbose output?
|
||||
fprintf(stdout, "Compressing: %s -> %s\n", input_files[i], output_filename);
|
||||
|
||||
if (lossless != 0) {
|
||||
cclt_optimize(input_files[i], output_filename, exif, input_files[i]);
|
||||
} else {
|
||||
//if (lossless != 0) {
|
||||
// cclt_optimize(input_files[i], output_filename, exif, input_files[i]);
|
||||
//} else {
|
||||
cclt_compress_routine(input_files[i], output_filename, pars);
|
||||
}
|
||||
//}
|
||||
|
||||
//Get output stats
|
||||
status = stat(output_filename, &st_buf);
|
||||
|
@ -195,8 +195,8 @@ int main (int argc, char *argv[]) {
|
|||
|
||||
cclt_start(pars.input_files, pars.input_files_count, pars.output_folder, &pars, &i_t_size, &o_t_size);
|
||||
|
||||
fprintf(stdout, "-------------------------------\nCompression completed.\n%ld bytes -> %ld bytes [%.2f%%]\n",
|
||||
(long) i_t_size, (long) o_t_size, ((float) o_t_size - i_t_size) * 100 / i_t_size);
|
||||
fprintf(stdout, "-------------------------------\nCompression completed.\n%ld bytes -> %ld bytes [%.2f%% | %ld bytes]\n",
|
||||
(long) i_t_size, (long) o_t_size, ((float) o_t_size - i_t_size) * 100 / i_t_size, (long) (o_t_size - i_t_size));
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
|
21
src/png.c
21
src/png.c
|
@ -14,12 +14,12 @@
|
|||
|
||||
#include "png.h"
|
||||
|
||||
int width, height;
|
||||
png_byte color_type;
|
||||
png_byte bit_depth;
|
||||
png_bytep *row_pointers;
|
||||
int width, height;
|
||||
png_byte color_type;
|
||||
png_byte bit_depth;
|
||||
png_bytep *row_pointers;
|
||||
|
||||
void read_png_file (char *filename) {
|
||||
void read_png_file (char *filename) {
|
||||
FILE *fp = fopen(filename, "rb");
|
||||
|
||||
png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
|
@ -57,12 +57,12 @@ void read_png_file (char *filename) {
|
|||
|
||||
// These color_type don't have an alpha channel then fill it with 0xff.
|
||||
if(color_type == PNG_COLOR_TYPE_RGB ||
|
||||
color_type == PNG_COLOR_TYPE_GRAY ||
|
||||
color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
color_type == PNG_COLOR_TYPE_GRAY ||
|
||||
color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
png_set_filler(png, 0xFF, PNG_FILLER_AFTER);
|
||||
|
||||
if(color_type == PNG_COLOR_TYPE_GRAY ||
|
||||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
png_set_gray_to_rgb(png);
|
||||
|
||||
png_read_update_info(png, info);
|
||||
|
@ -92,6 +92,9 @@ void write_png_file (char *filename) {
|
|||
|
||||
png_init_io(png, fp);
|
||||
|
||||
//zlib compression here
|
||||
png_set_compression_level(png, 9);
|
||||
|
||||
// Output is 8bit depth, RGBA format.
|
||||
png_set_IHDR(
|
||||
png,
|
||||
|
@ -102,7 +105,7 @@ void write_png_file (char *filename) {
|
|||
PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_DEFAULT,
|
||||
PNG_FILTER_TYPE_DEFAULT
|
||||
);
|
||||
);
|
||||
png_write_info(png, info);
|
||||
|
||||
// To remove the alpha channel for PNG_COLOR_TYPE_RGB format,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <sys/types.h>
|
||||
|
||||
#define APP_VERSION "1.9.9 BETA"
|
||||
#define BUILD 20150723
|
||||
#define BUILD 20150728
|
||||
|
||||
typedef struct cclt_compress_parameters {
|
||||
int quality;
|
||||
|
|
Loading…
Reference in New Issue