From 804083681e077becd98adb3d86f58c68025e3074 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 22 Jul 2005 04:37:27 +0000 Subject: [PATCH] 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. --- docs/reference/ChangeLog | 5 ++ .../gdk-pixbuf/tmpl/module_interface.sgml | 15 +++-- gdk-pixbuf/ChangeLog | 7 +++ gdk-pixbuf/gdk-pixbuf-io.c | 60 ++++++++++++------- 4 files changed, 59 insertions(+), 28 deletions(-) diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index a423a0e2af..0fc148de12 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,8 @@ +2005-07-22 Matthias Clasen + + * gdk-pixbuf/tmpl/module_interface.sgml: Document unanchored + patterns. + 2005-07-21 Federico Mena Quintero * gtk/tmpl/gtkfilechooserdialog.sgml (dialog): Expand the Save diff --git a/docs/reference/gdk-pixbuf/tmpl/module_interface.sgml b/docs/reference/gdk-pixbuf/tmpl/module_interface.sgml index ac12c39e38..e06b0d3250 100644 --- a/docs/reference/gdk-pixbuf/tmpl/module_interface.sgml +++ b/docs/reference/gdk-pixbuf/tmpl/module_interface.sgml @@ -204,14 +204,19 @@ operations. The signature of a module is a set of prefixes. Prefixes are encoded as -pairs of ordinary strings, where the second string, if not %NULL, must be -of the same length as the first one and may contain ' ', '!', 'x', 'z', -and 'n' to indicate bytes that must be matched, not matched, -"don't-care"-bytes, zeros and non-zeros. +pairs of ordinary strings, where the second string, called the mask, if +not %NULL, must be of the same length as the first one and may contain +' ', '!', 'x', 'z', and 'n' to indicate bytes that must be matched, +not matched, "don't-care"-bytes, zeros and non-zeros. Each prefix has an associated integer that describes the relevance of the prefix, with 0 meaning a mismatch and 100 a "perfect match". - + +Starting with &gdk-pixbuf; 2.8, the first byte of the mask may be '*', +indicating an unanchored pattern that matches not only at the beginning, +but also in the middle. Versions prior to 2.8 will interpret the '*' +like an 'x'. + The signature of a module is stored as an array of #GdkPixbufModulePatterns. The array is terminated by a pattern diff --git a/gdk-pixbuf/ChangeLog b/gdk-pixbuf/ChangeLog index a58d80bf91..c792284076 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 dc0408d2f7..a8faa782f9 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;