imlib2_load: Add crc32 printout

For comparing results before/after loader changes.
This commit is contained in:
Kim Woelders 2024-03-21 06:43:27 +01:00
parent 1bc95a8631
commit f8a4510438
2 changed files with 27 additions and 2 deletions

View File

@ -23,7 +23,7 @@ imlib2_conv_SOURCES = imlib2_conv.c $(SRCS_UTIL)
imlib2_conv_LDADD = $(top_builddir)/src/lib/libImlib2.la
imlib2_load_SOURCES = imlib2_load.c $(SRCS_UTIL)
imlib2_load_LDADD = $(top_builddir)/src/lib/libImlib2.la $(CLOCK_LIBS)
imlib2_load_LDADD = $(top_builddir)/src/lib/libImlib2.la -lz $(CLOCK_LIBS)
imlib2_show_SOURCES = imlib2_show.c $(SRCS_X11)
imlib2_show_LDADD = $(top_builddir)/src/lib/libImlib2.la -lX11 -lm

View File

@ -11,6 +11,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <zlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
@ -34,6 +35,7 @@ static FILE *fout;
"Usage:\n" \
" imlib2_load [OPTIONS] FILE...\n" \
"OPTIONS:\n" \
" -C : Print CRC32 of image data\n" \
" -c : Enable image caching\n" \
" -e : Break on error\n" \
" -f : Load with imlib_load_image_fd()\n" \
@ -51,6 +53,21 @@ usage(void)
printf(HELP);
}
static unsigned int
image_get_crc32(Imlib_Image im)
{
const unsigned char *data;
unsigned int crc, w, h;
imlib_context_set_image(im);
w = imlib_image_get_width();
h = imlib_image_get_height();
data = (const unsigned char *)imlib_image_get_data_for_reading_only();
crc = crc32(0, data, w * h * sizeof(uint32_t));
return crc;
}
static Imlib_Image *
image_load_fd(const char *file, int *perr)
{
@ -144,6 +161,7 @@ main(int argc, char **argv)
int load_cnt, cnt;
int load_mode;
bool opt_cache;
bool show_crc;
fout = stdout;
verbose = 0;
@ -153,11 +171,15 @@ main(int argc, char **argv)
load_cnt = 1;
load_mode = LOAD_DEFER;
opt_cache = false;
show_crc = false;
while ((opt = getopt(argc, argv, "cefijmn:pvx")) != -1)
while ((opt = getopt(argc, argv, "Ccefijmn:pvx")) != -1)
{
switch (opt)
{
case 'C':
show_crc = true;
break;
case 'c':
opt_cache = true;
break;
@ -278,6 +300,9 @@ main(int argc, char **argv)
}
}
if (cnt == 0 && show_crc)
printf("%08x %s\n", image_get_crc32(im), argv[0]);
if (opt_cache)
imlib_free_image();
else