Added missing function as for #10

This commit is contained in:
Matteo Paonessa 2016-09-20 15:37:10 +02:00
parent c4ce35e1ce
commit 1d37307b9e
4 changed files with 49 additions and 18 deletions

2
.gitignore vendored
View File

@ -18,3 +18,5 @@ Thumbs.db
# Files that might appear on external disks
.Spotlight-V100
.Trashes
.clang-format

View File

@ -15,7 +15,7 @@ void trigger_error(int code, bool is_critical, ...) {
va_list args;
va_start(args, is_critical);
fprintf(stderr, "%s %d: ",
fprintf(stderr, "%s - %d: ",
parse_error_level(is_critical),
code);

View File

@ -9,6 +9,7 @@
#include "jpeg.h"
#include "utils.h"
#include "error.h"
//TODO Error handling
@ -231,3 +232,35 @@ unsigned char* cclt_jpeg_decompress(char* fileName, cclt_jpeg_parameters* pars)
return temp;
}
void jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo) {
jpeg_saved_marker_ptr marker;
/* In the current implementation, we don't actually need to examine the
* option flag here; we just copy everything that got saved.
* But to avoid confusion, we do not output JFIF and Adobe APP14 markers
* if the encoder library already wrote one.
*/
for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
if (dstinfo->write_JFIF_header &&
marker->marker == JPEG_APP0 &&
marker->data_length >= 5 &&
GETJOCTET(marker->data[0]) == 0x4A &&
GETJOCTET(marker->data[1]) == 0x46 &&
GETJOCTET(marker->data[2]) == 0x49 &&
GETJOCTET(marker->data[3]) == 0x46 &&
GETJOCTET(marker->data[4]) == 0)
continue; /* reject duplicate JFIF */
if (dstinfo->write_Adobe_marker &&
marker->marker == JPEG_APP0+14 &&
marker->data_length >= 5 &&
GETJOCTET(marker->data[0]) == 0x41 &&
GETJOCTET(marker->data[1]) == 0x64 &&
GETJOCTET(marker->data[2]) == 0x6F &&
GETJOCTET(marker->data[3]) == 0x62 &&
GETJOCTET(marker->data[4]) == 0x65)
continue; /* reject duplicate Adobe */
jpeg_write_marker(dstinfo, marker->marker,
marker->data, marker->data_length);
}
}

View File

@ -24,34 +24,30 @@
-S keep folder structure
*/
// TODO If the output is INSIDE the folder we are passing as input, ignore it or
// we're gonna go in a infinite loop
// TODO Trigger a warning if you are overwriting files
//TODO If the output is INSIDE the folder we are passing as input, ignore it or we're gonna go in a infinite loop
//TODO Trigger a warning if you are overwriting files
int main (int argc, char *argv[]) {
int main(int argc, char *argv[]) {
errno = 0;
off_t i_t_size = 0, o_t_size = 0;
//Parse arguments
// Parse arguments
cclt_parameters pars = parse_arguments(argc, argv);
//Start a timer
// Start a timer
clock_t start = clock(), diff;
//We need the file list right here
// We need the file list right here
cclt_start(&pars, &i_t_size, &o_t_size);
diff = clock() - start;
long msec = diff * 1000 / CLOCKS_PER_SEC;
fprintf(stdout, "-------------------------------\nCompression completed in %lum%lus%lums\n%s -> %s [%.2f%% | %s]\n",
msec / 1000 / 60,
msec / 1000 % 60,
msec % 1000,
get_human_size((long) i_t_size),
get_human_size((long) o_t_size),
((float) o_t_size - i_t_size) * 100 / i_t_size,
get_human_size(((long) o_t_size - i_t_size)));
fprintf(stdout, "-------------------------------\nCompression completed in "
"%lum%lus%lums\n%s -> %s [%.2f%% | %s]\n",
msec / 1000 / 60, msec / 1000 % 60, msec % 1000,
get_human_size((long)i_t_size), get_human_size((long)o_t_size),
((float)o_t_size - i_t_size) * 100 / i_t_size,
get_human_size(((long)o_t_size - i_t_size)));
return 0;
}