/*
- * "$Id: filter.c 5196 2006-02-27 21:23:00Z mike $"
+ * "$Id: filter.c 5493 2006-05-05 16:33:57Z mike $"
*
* File type conversion routines for the Common UNIX Printing System (CUPS).
*
*/
static int compare_filters(mime_filter_t *, mime_filter_t *);
+static int compare_srcs(mime_filter_t *, mime_filter_t *);
static cups_array_t *find_filters(mime_t *mime, mime_type_t *src,
mime_type_t *dst, int *cost,
_mime_typelist_t *visited);
if (!mime || !src || !dst)
return (NULL);
+ /*
+ * (Re)build the source lookup array as needed...
+ */
+
+ if (!mime->srcs)
+ {
+ mime_filter_t *current; /* Current filter */
+
+
+ mime->srcs = cupsArrayNew((cups_array_func_t)compare_srcs, NULL);
+
+ for (current = mimeFirstFilter(mime);
+ current;
+ current = mimeNextFilter(mime))
+ cupsArrayAdd(mime->srcs, current);
+ }
+
/*
* Find the filters...
*/
}
+/*
+ * 'compare_srcs()' - Compare two srcs...
+ */
+
+static int /* O - Comparison result */
+compare_srcs(mime_filter_t *f0, /* I - First filter */
+ mime_filter_t *f1) /* I - Second filter */
+{
+ int i; /* Result of comparison */
+
+
+ if ((i = strcmp(f0->src->super, f1->src->super)) == 0)
+ i = strcmp(f0->src->type, f1->src->type);
+
+ return (i);
+}
+
+
/*
* 'find_filters()' - Find the filters to convert from one type to another.
*/
mincost; /* Current minimum */
cups_array_t *temp, /* Temporary filter */
*mintemp; /* Current minimum */
- mime_filter_t *current; /* Current filter */
+ mime_filter_t *current, /* Current filter */
+ srckey; /* Source type key */
_mime_typelist_t listnode, /* New list node */
*listptr; /* Pointer in list */
mincost = current->cost;
+ if (!cost)
+ return (mintemp);
+
DEBUG_puts(" Found direct filter:");
DEBUG_printf((" %s (cost=%d)\n", current->filter, mincost));
}
* OK, now look for filters from the source type to any other type...
*/
- for (current = (mime_filter_t *)cupsArrayFirst(mime->filters);
- current;
- current = (mime_filter_t *)cupsArrayNext(mime->filters))
- if (current->src == src)
- {
- /*
- * See if we have already tried the destination type as a source
- * type (this avoids extra filter looping...)
- */
+ srckey.src = src;
- for (listptr = list; listptr; listptr = listptr->next)
- if (current->dst == listptr->src)
- break;
+ for (current = (mime_filter_t *)cupsArrayFind(mime->srcs, &srckey);
+ current && current->src == src;
+ current = (mime_filter_t *)cupsArrayNext(mime->srcs))
+ {
+ /*
+ * See if we have already tried the destination type as a source
+ * type (this avoids extra filter looping...)
+ */
- if (listptr)
- continue;
+ mime_type_t *current_dst; /* Current destination type */
- /*
- * See if we have any filters that can convert from the destination type
- * of this filter to the final type...
- */
- listnode.src = current->src;
+ for (listptr = list, current_dst = current->dst;
+ listptr;
+ listptr = listptr->next)
+ if (current_dst == listptr->src)
+ break;
+
+ if (listptr)
+ continue;
- cupsArraySave(mime->filters);
- temp = find_filters(mime, current->dst, dst, &tempcost, &listnode);
- cupsArrayRestore(mime->filters);
+ /*
+ * See if we have any filters that can convert from the destination type
+ * of this filter to the final type...
+ */
+
+ listnode.src = current->src;
- if (!temp)
- continue;
+ cupsArraySave(mime->srcs);
+ temp = find_filters(mime, current->dst, dst, &tempcost, &listnode);
+ cupsArrayRestore(mime->srcs);
+
+ if (!temp)
+ continue;
+
+ if (!cost)
+ return (temp);
+
+ /*
+ * Found a match; see if this one is less costly than the last (if
+ * any...)
+ */
+
+ if (tempcost < mincost)
+ {
+ cupsArrayDelete(mintemp);
/*
- * Found a match; see if this one is less costly than the last (if
- * any...)
+ * Hey, we got a match! Add the current filter to the beginning of the
+ * filter list...
*/
- if (tempcost < mincost)
- {
- cupsArrayDelete(mintemp);
-
- /*
- * Hey, we got a match! Add the current filter to the beginning of the
- * filter list...
- */
-
- mintemp = temp;
- mincost = tempcost + current->cost;
- cupsArrayInsert(mintemp, current);
- }
- else
- cupsArrayDelete(temp);
+ mintemp = temp;
+ mincost = tempcost + current->cost;
+ cupsArrayInsert(mintemp, current);
}
+ else
+ cupsArrayDelete(temp);
+ }
if (mintemp)
{
/*
- * End of "$Id: filter.c 5196 2006-02-27 21:23:00Z mike $".
+ * End of "$Id: filter.c 5493 2006-05-05 16:33:57Z mike $".
*/