New error enumeration

This commit is contained in:
Matteo Paonessa 2017-02-21 23:15:31 +01:00
parent e24647f55d
commit f3011b4a49
5 changed files with 23 additions and 23 deletions

View File

@ -13,7 +13,7 @@ bool cs_compress(const char *input_path, const char *output_path, cs_image_pars
bool result = false;
if ((pInputFile = fopen(input_path, "rb")) == NULL) {
display_error(ERROR, 4);
display_error(ERROR, 104);
return result;
}
@ -22,7 +22,7 @@ bool cs_compress(const char *input_path, const char *output_path, cs_image_pars
fclose(pInputFile);
if (type == UNKN) {
display_error(WARNING, 3);
display_error(WARNING, 103);
} else if (type == JPEG) {
if (options->jpeg.quality != 0) {
cs_jpeg_compress(output_path, cs_jpeg_decompress(input_path, &options->jpeg), &options->jpeg);

View File

@ -4,7 +4,7 @@
void display_error(error_level level, int code)
{
char *error_level = ((level) ? "WARNING" : "ERROR");
char *error_level = ((level) ? "[WARNING]" : "[ERROR]");
fprintf(stderr, "%s %d: %s\n",
error_level,
code,
@ -15,31 +15,31 @@ const char *get_error_message(int code)
{
switch (code) {
//Generic errors
case 1:
case 101:
return "NULL file pointer while checking type.";
case 3:
case 103:
return "File type not supported.";
case 4:
case 104:
return "Could not open input file.";
//JPEG related errors
case 100:
case 200:
return "Failed to open JPEG file while trying to get markers";
case 101:
case 201:
return "Failed to open input JPEG file while optimizing";
case 102:
case 202:
return "Failed to open output JPEG file while optimizing";
case 103:
case 203:
return "Failed to open JPEG file while compressing";
case 104:
case 204:
return "Failed to open JPEG file while decompressing";
//PNG related errors
case 200:
case 300:
return "Failed to load PNG file.";
case 201:
case 301:
return "Error while optimizing PNG.";
case 203:
case 303:
return "Error while writing output PNG file.";
default:

View File

@ -17,7 +17,7 @@ struct jpeg_decompress_struct cs_get_markers(const char *input)
//Check for errors
if ((fp = fopen(input, "r")) == NULL) {
display_error(ERROR, 100);
display_error(ERROR, 200);
}
//Create the IO instance for the input file
@ -59,7 +59,7 @@ bool cs_jpeg_optimize(const char *input_file, const char *output_file, bool exif
//Check for errors
if ((fp = fopen(input_file, "r")) == NULL) {
display_error(ERROR, 101);
display_error(ERROR, 201);
}
//Create the IO instance for the input file
@ -90,7 +90,7 @@ bool cs_jpeg_optimize(const char *input_file, const char *output_file, bool exif
//Check for errors
if ((fp = fopen(output_file, "wb")) == NULL) {
display_error(ERROR, 102);
display_error(ERROR, 202);
}
//CRITICAL - This is the optimization step
@ -138,7 +138,7 @@ void cs_jpeg_compress(const char *output_file, unsigned char *image_buffer, cs_j
//Check for errors
if ((fp = fopen(output_file, "wb")) == NULL) {
display_error(ERROR, 103);
display_error(ERROR, 203);
}
output_buffer = NULL;
@ -175,7 +175,7 @@ unsigned char *cs_jpeg_decompress(const char *fileName, cs_jpeg_pars *options)
int fileWidth = 0, fileHeight = 0, jpegSubsamp = 0, colorSpace = 0;
if ((fp = fopen(fileName, "rb")) == NULL) {
display_error(ERROR, 104);
display_error(ERROR, 204);
}
fseek(fp, 0, SEEK_END);
sourceJpegBufferSize = ftell(fp);

View File

@ -32,7 +32,7 @@ bool cs_png_optimize(const char *input, const char *output, cs_png_pars *options
png_options.auto_filter_strategy = options->auto_filter_strategy;
if (lodepng_load_file(&orig_buffer, &orig_buffer_size, input) != 0) {
display_error(ERROR, 200);
display_error(ERROR, 300);
goto cleanup;
}
@ -42,12 +42,12 @@ bool cs_png_optimize(const char *input, const char *output, cs_png_pars *options
0,
&resultpng,
&resultpng_size) != 0) {
display_error(ERROR, 201);
display_error(ERROR, 301);
goto cleanup;
}
if (lodepng_save_file(resultpng, resultpng_size, output) != 0) {
display_error(ERROR, 202);
display_error(ERROR, 302);
goto cleanup;
}

View File

@ -9,7 +9,7 @@ image_type detect_image_type(FILE *pFile)
unsigned char buffer[2];
if (pFile == NULL) {
display_error(ERROR, 1);
display_error(WARNING, 101);
return UNKN;
}