Switch to imlib_load/save_image_with_errno_return()

This commit is contained in:
Kim Woelders 2022-03-18 19:38:12 +01:00
parent 4229e1d1b6
commit 4bf622173c
7 changed files with 57 additions and 53 deletions

View File

@ -22,7 +22,7 @@ main(int argc, char **argv)
{
char *dot, *colon, *n, *oldn;
Imlib_Image im;
Imlib_Load_Error lerr;
int err;
/* I'm just plain being lazy here.. get our basename. */
for (oldn = n = argv[0]; n; oldn = n)
@ -30,12 +30,12 @@ main(int argc, char **argv)
if (argc < 3 || !strcmp(argv[1], "-h"))
usage(-1);
im = imlib_load_image_with_error_return(argv[1], &lerr);
im = imlib_load_image_with_errno_return(argv[1], &err);
if (!im)
{
fprintf(stderr, PROG_NAME ": Error %d loading image: %s\n",
lerr, argv[1]);
return lerr;
fprintf(stderr, PROG_NAME ": Error %d:'%s' loading image: '%s'\n",
err, imlib_strerror(err), argv[1]);
return 1;
}
/* we only care what format the export format is. */
@ -74,21 +74,12 @@ main(int argc, char **argv)
else
imlib_image_set_format("jpg");
imlib_save_image_with_error_return(argv[2], &lerr);
switch (lerr)
{
case IMLIB_LOAD_ERROR_NONE:
break;
case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT:
fprintf(stderr, "No saver for format: %s\n", imlib_image_format());
/* FALLTHROUGH */
default:
fprintf(stderr, "%s: Error %d saving image: %s\n",
PROG_NAME, lerr, argv[2]);
break;
}
imlib_save_image_with_errno_return(argv[2], &err);
if (err)
fprintf(stderr, PROG_NAME ": Error %d:'%s' saving image: '%s'\n",
err, imlib_strerror(err), argv[2]);
return lerr;
return err;
}
static void

View File

@ -31,7 +31,7 @@ main(int argc, char **argv)
unsigned int wo, ho;
unsigned int depth;
Window rr;
Imlib_Load_Error err;
int err;
verbose = 0;
get_alpha = 1;
@ -132,9 +132,10 @@ main(int argc, char **argv)
}
imlib_context_set_image(im);
imlib_save_image_with_error_return(file, &err);
if (err != IMLIB_LOAD_ERROR_NONE)
fprintf(stderr, "Failed to save image to '%s' (error %d)\n", file, err);
imlib_save_image_with_errno_return(file, &err);
if (err)
fprintf(stderr, "Failed to save image to '%s' (error %d:'%s')\n",
file, err, imlib_strerror(err));
return 0;
}

View File

@ -92,7 +92,7 @@ main(int argc, char **argv)
{
int opt;
Imlib_Image im;
Imlib_Load_Error lerr;
int err;
unsigned int t0;
char nbuf[4096];
int frame;
@ -177,10 +177,10 @@ main(int argc, char **argv)
for (cnt = 0; cnt < load_cnt; cnt++)
{
lerr = 0;
err = 0;
if (check_progress)
im = imlib_load_image_with_error_return(argv[0], &lerr);
im = imlib_load_image_with_errno_return(argv[0], &err);
else if (load_fd)
im = image_load_fd(argv[0]);
else if (load_now)
@ -198,8 +198,8 @@ main(int argc, char **argv)
if (!im)
{
fprintf(fout, "*** Error %d loading image: %s\n",
lerr, argv[0]);
fprintf(fout, "*** Error %d:'%s' loading image: '%s'\n",
err, imlib_strerror(err), argv[0]);
if (break_on_error & 2)
goto quit;
goto next;

View File

@ -3,6 +3,7 @@
#include "config.h"
#include <Imlib2.h>
#include <errno.h>
#include <fcntl.h>
#include "test.h"
@ -90,9 +91,9 @@ test_load(void)
// Load files of all types
snprintf(fileo, sizeof(fileo), "%s/%s.%s", IMG_SRC, "icon-64", pfxs[i]);
D("Load '%s'\n", fileo);
im = imlib_load_image_with_error_return(fileo, &lerr);
im = imlib_load_image_with_errno_return(fileo, &err);
EXPECT_TRUE(im);
EXPECT_EQ(lerr, 0);
EXPECT_EQ(err, 0);
if (!im || lerr)
D("Error %d im=%p loading '%s'\n", lerr, im, fileo);
if (im)
@ -112,11 +113,11 @@ test_load(void)
unlink(fileo);
symlink(filei, fileo);
D("Load incorrect suffix '%s'\n", fileo);
im = imlib_load_image_with_error_return(fileo, &lerr);
im = imlib_load_image_with_errno_return(fileo, &err);
EXPECT_TRUE(im);
EXPECT_EQ(lerr, 0);
if (!im || lerr)
D("Error %d im=%p loading '%s'\n", lerr, im, fileo);
EXPECT_EQ(err, 0);
if (!im || err)
D("Error %d im=%p loading '%s'\n", err, im, fileo);
if (im)
image_free(im);
}
@ -128,8 +129,13 @@ test_load(void)
fp = fopen(fileo, "wb");
fclose(fp);
D("Load empty '%s'\n", fileo);
im = imlib_load_image_with_errno_return(fileo, &err);
D(" err = %d\n", err);
EXPECT_FALSE(im);
EXPECT_EQ(err, IMLIB_ERR_BAD_IMAGE);
im = imlib_load_image_with_error_return(fileo, &lerr);
D(" err = %d\n", lerr);
EXPECT_FALSE(im);
EXPECT_EQ(lerr, IMLIB_LOAD_ERROR_IMAGE_READ);
// Non-existing files of all types
@ -137,7 +143,13 @@ test_load(void)
unlink(fileo);
symlink("non-existing", fileo);
D("Load non-existing '%s'\n", fileo);
im = imlib_load_image_with_errno_return(fileo, &err);
D(" err = %d\n", err);
EXPECT_FALSE(im);
EXPECT_EQ(err, ENOENT);
im = imlib_load_image_with_error_return(fileo, &lerr);
D(" err = %d\n", lerr);
EXPECT_FALSE(im);
EXPECT_EQ(lerr, IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST);
// Load via fd

View File

@ -54,7 +54,7 @@ test_rotate(int no, int aa)
int wo, ho;
unsigned int i, ic, crc;
Imlib_Image imi, imo;
Imlib_Load_Error lerr;
int err;
unsigned char *data;
ptd = &td[no];
@ -92,10 +92,10 @@ test_rotate(int no, int aa)
IMG_GEN, ptd->file, wo, ho, i, "png");
imlib_image_set_format("png");
D("Save '%s'\n", fileo);
imlib_save_image_with_error_return(fileo, &lerr);
EXPECT_EQ(lerr, 0);
if (lerr)
D("Error %d saving '%s'\n", lerr, fileo);
imlib_save_image_with_errno_return(fileo, &err);
EXPECT_EQ(err, 0);
if (err)
D("Error %d saving '%s'\n", err, fileo);
data = (unsigned char *)imlib_image_get_data_for_reading_only();
crc = crc32(0, data, wo * ho * sizeof(DATA32));

View File

@ -45,7 +45,7 @@ test_save(const char *file, int prog)
char filei[256];
char fileo[256];
unsigned int i;
int w, h;
int w, h, err;
Imlib_Image im, im1, im2, im3;
Imlib_Load_Error lerr;
@ -85,10 +85,10 @@ test_save(const char *file, int prog)
snprintf(fileo, sizeof(fileo), "%s/save-%s-%dx%d.%s",
IMG_GEN, file, w, h, pfxs[i]);
D("Save '%s'\n", fileo);
imlib_save_image_with_error_return(fileo, &lerr);
EXPECT_EQ(lerr, 0);
if (lerr)
D("Error %d saving '%s'\n", lerr, fileo);
imlib_save_image_with_errno_return(fileo, &err);
EXPECT_EQ(err, 0);
if (err)
D("Error %d saving '%s'\n", err, fileo);
imlib_context_set_image(im1);
imlib_image_set_format(pfxs[i]);
@ -109,10 +109,10 @@ test_save(const char *file, int prog)
snprintf(fileo, sizeof(fileo), "%s/save-%s-%dx%d.%s",
IMG_GEN, file, w, h, pfxs[i]);
D("Save '%s'\n", fileo);
imlib_save_image_with_error_return(fileo, &lerr);
EXPECT_EQ(lerr, 0);
if (lerr)
D("Error %d saving '%s'\n", lerr, fileo);
imlib_save_image_with_errno_return(fileo, &err);
EXPECT_EQ(err, 0);
if (err)
D("Error %d saving '%s'\n", err, fileo);
imlib_context_set_image(im3);
imlib_image_set_format(pfxs[i]);

View File

@ -33,7 +33,7 @@ test_scale(int no)
int w, h;
unsigned int i, crc;
Imlib_Image imi, imo;
Imlib_Load_Error lerr;
int err;
unsigned char *data;
#ifdef DO_MMX_ASM
@ -77,10 +77,10 @@ test_scale(int no)
IMG_GEN, ptd->file, w, h, "png");
imlib_image_set_format("png");
D("Save '%s'\n", fileo);
imlib_save_image_with_error_return(fileo, &lerr);
EXPECT_EQ(lerr, 0);
if (lerr)
D("Error %d saving '%s'\n", lerr, fileo);
imlib_save_image_with_errno_return(fileo, &err);
EXPECT_EQ(err, 0);
if (err)
D("Error %d saving '%s'\n", err, fileo);
imlib_context_set_image(imo);
imlib_free_image_and_decache();