From 804083681e077becd98adb3d86f58c68025e3074 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 22 Jul 2005 04:37:27 +0000 Subject: Interpret patterns where the first byte of the mask is '*' as unanchored. 2005-07-22 Matthias Clasen * gdk-pixbuf-io.c (format_check): Interpret patterns where the first byte of the mask is '*' as unanchored. (#311011) (gdk_pixbuf_new_from_file): Use the first 256 bytes for sniffing the file format. --- gdk-pixbuf/ChangeLog | 7 ++++++ gdk-pixbuf/gdk-pixbuf-io.c | 60 ++++++++++++++++++++++++++++------------------ 2 files changed, 44 insertions(+), 23 deletions(-) (limited to 'gdk-pixbuf') diff --git a/gdk-pixbuf/ChangeLog b/gdk-pixbuf/ChangeLog index a58d80bf9..c79228407 100644 --- a/gdk-pixbuf/ChangeLog +++ b/gdk-pixbuf/ChangeLog @@ -1,3 +1,10 @@ +2005-07-22 Matthias Clasen + + * gdk-pixbuf-io.c (format_check): Interpret patterns where + the first byte of the mask is '*' as unanchored. (#311011) + (gdk_pixbuf_new_from_file): Use the first 256 bytes for + sniffing the file format. + 2005-07-15 Matthias Clasen * === Released 2.7.3 === diff --git a/gdk-pixbuf/gdk-pixbuf-io.c b/gdk-pixbuf/gdk-pixbuf-io.c index dc0408d2f..a8faa782f 100644 --- a/gdk-pixbuf/gdk-pixbuf-io.c +++ b/gdk-pixbuf/gdk-pixbuf-io.c @@ -48,32 +48,46 @@ static gint format_check (GdkPixbufModule *module, guchar *buffer, int size) { - int j; + int i, j; gchar m; GdkPixbufModulePattern *pattern; + gboolean unanchored; + guchar *prefix, *mask; for (pattern = module->info->signature; pattern->prefix; pattern++) { - for (j = 0; j < size && pattern->prefix[j] != 0; j++) { - m = pattern->mask ? pattern->mask[j] : ' '; - if (m == ' ') { - if (buffer[j] != pattern->prefix[j]) - break; - } - else if (m == '!') { - if (buffer[j] == pattern->prefix[j]) - break; - } - else if (m == 'z') { - if (buffer[j] != 0) - break; - } - else if (m == 'n') { - if (buffer[j] == 0) - break; - } - } - if (pattern->prefix[j] == 0) - return pattern->relevance; + if (pattern->mask && pattern->mask[0] == '*') { + prefix = pattern->prefix + 1; + mask = pattern->mask + 1; + unanchored = TRUE; + } + else { + prefix = pattern->prefix; + mask = pattern->mask; + unanchored = FALSE; + } + for (i = 0; unanchored && i < size; i++) { + for (j = 0; i + j < size && prefix[j] != 0; j++) { + m = mask ? mask[j] : ' '; + if (m == ' ') { + if (buffer[i + j] != prefix[j]) + break; + } + else if (m == '!') { + if (buffer[i + j] == prefix[j]) + break; + } + else if (m == 'z') { + if (buffer[i + j] != 0) + break; + } + else if (m == 'n') { + if (buffer[i + j] == 0) + break; + } + } + if (prefix[j] == 0) + return pattern->relevance; + } } return 0; } @@ -821,7 +835,7 @@ gdk_pixbuf_new_from_file (const char *filename, GdkPixbuf *pixbuf; int size; FILE *f; - guchar buffer [128]; + guchar buffer[256]; GdkPixbufModule *image_module; gchar *display_name; -- cgit v1.2.1