Second commit
This commit is contained in:
parent
97627a804d
commit
aa1b4419a7
70
compress.c
70
compress.c
|
@ -7,58 +7,58 @@
|
||||||
|
|
||||||
void cclt_compress(char* output_file, unsigned char* image_buffer)
|
void cclt_compress(char* output_file, unsigned char* image_buffer)
|
||||||
{
|
{
|
||||||
struct jpeg_compress_struct cinfo;
|
struct jpeg_compress_struct cinfo;
|
||||||
|
|
||||||
struct jpeg_error_mgr jerr;
|
struct jpeg_error_mgr jerr;
|
||||||
FILE * outfile;
|
FILE * outfile;
|
||||||
JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
|
JSAMPROW row_pointer[1];
|
||||||
int row_stride; /* physical row width in image buffer */
|
int row_stride;
|
||||||
|
|
||||||
if ((outfile = fopen(output_file, "wb")) == NULL) {
|
if ((outfile = fopen(output_file, "wb")) == NULL) {
|
||||||
fprintf(stderr, "can't open %s\n", output_file);
|
fprintf(stderr, "can't open %s\n", output_file);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
cinfo.err = jpeg_std_error(&jerr);
|
cinfo.err = jpeg_std_error(&jerr);
|
||||||
|
|
||||||
jpeg_create_compress(&cinfo);
|
jpeg_create_compress(&cinfo);
|
||||||
jpeg_stdio_dest(&cinfo, outfile);
|
jpeg_stdio_dest(&cinfo, outfile);
|
||||||
|
|
||||||
cinfo.image_width = 80;
|
cinfo.image_width = 80;
|
||||||
cinfo.image_height = 80;
|
cinfo.image_height = 80;
|
||||||
cinfo.input_components = 3;
|
cinfo.input_components = 3;
|
||||||
cinfo.in_color_space = JCS_RGB;
|
cinfo.in_color_space = JCS_RGB;
|
||||||
|
|
||||||
jpeg_set_defaults(&cinfo);
|
jpeg_set_defaults(&cinfo);
|
||||||
|
|
||||||
cinfo.dct_method = JDCT_FLOAT;
|
cinfo.dct_method = JDCT_FLOAT;
|
||||||
cinfo.optimize_coding = TRUE;
|
cinfo.optimize_coding = TRUE;
|
||||||
cinfo.smoothing_factor = 50;
|
cinfo.smoothing_factor = 50;
|
||||||
jpeg_set_quality(&cinfo, 80, TRUE );
|
jpeg_set_quality(&cinfo, 80, TRUE );
|
||||||
jpeg_set_colorspace(&cinfo, JCS_RGB);
|
jpeg_set_colorspace(&cinfo, JCS_RGB);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
jpeg_start_compress(&cinfo, TRUE);
|
|
||||||
|
jpeg_start_compress(&cinfo, TRUE);
|
||||||
|
|
||||||
//TODO cambia
|
//TODO cambia
|
||||||
row_stride = 80 * 3;//image_width * 3;
|
row_stride = 80 * 3;//image_width * 3;
|
||||||
|
|
||||||
|
|
||||||
while (cinfo.next_scanline < cinfo.image_height) {
|
while (cinfo.next_scanline < cinfo.image_height) {
|
||||||
|
|
||||||
printf("%d%\r", cinfo.next_scanline * 100 / cinfo.image_height);
|
|
||||||
|
|
||||||
row_pointer[0] = &image_buffer[cinfo.next_scanline * row_stride];
|
printf("%d%\r", cinfo.next_scanline * 100 / cinfo.image_height);
|
||||||
(void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
|
|
||||||
}
|
row_pointer[0] = &image_buffer[cinfo.next_scanline * row_stride];
|
||||||
printf("%d%\n", cinfo.next_scanline * 100 / cinfo.image_height);
|
(void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
|
||||||
|
}
|
||||||
|
printf("%d%\n", cinfo.next_scanline * 100 / cinfo.image_height);
|
||||||
|
|
||||||
|
|
||||||
jpeg_finish_compress(&cinfo);
|
jpeg_finish_compress(&cinfo);
|
||||||
fclose(outfile);
|
fclose(outfile);
|
||||||
|
|
||||||
|
|
||||||
jpeg_destroy_compress(&cinfo);
|
jpeg_destroy_compress(&cinfo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
28
main.c
28
main.c
|
@ -15,10 +15,10 @@
|
||||||
-o output file
|
-o output file
|
||||||
-v version
|
-v version
|
||||||
-l lossless
|
-l lossless
|
||||||
-s
|
-s scale
|
||||||
-h help
|
-h help
|
||||||
-R recursive
|
-R recursive
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
cclt_compress_parameters parse_arguments(int argc, char* argv[]) {
|
cclt_compress_parameters parse_arguments(int argc, char* argv[]) {
|
||||||
|
@ -36,16 +36,16 @@ cclt_compress_parameters parse_arguments(int argc, char* argv[]) {
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
if (optopt == 'q' || optopt == 'e' || optopt == 'o' || optopt == 's') {
|
if (optopt == 'q' || optopt == 'e' || optopt == 'o' || optopt == 's') {
|
||||||
//fprintf (stderr, "Option -%c requires an argument.\n", optopt);
|
//fprintf (stderr, "Option -%c requires an argument.\n", optopt);
|
||||||
//Arguments without values
|
//Arguments without values
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
else if (isprint(optopt)) {
|
else if (isprint(optopt)) {
|
||||||
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
|
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
|
fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
qvalue = optarg;
|
qvalue = optarg;
|
||||||
|
@ -54,15 +54,15 @@ cclt_compress_parameters parse_arguments(int argc, char* argv[]) {
|
||||||
evalue = optarg;
|
evalue = optarg;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char *argv[]) {
|
int main (int argc, char *argv[]) {
|
||||||
|
|
||||||
cclt_compress_parameters parameters;
|
cclt_compress_parameters parameters;
|
||||||
|
|
||||||
//Check if there's at least one argument
|
//Check if there's at least one argument
|
||||||
|
@ -70,7 +70,7 @@ int main (int argc, char *argv[]) {
|
||||||
printf("CCLT requires at least one argument. Aborting.\n");
|
printf("CCLT requires at least one argument. Aborting.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
parameters = parse_arguments(argc, argv);
|
parameters = parse_arguments(argc, argv);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue