istereo2

diff libs/imago2/ftype_module.c @ 2:81d35769f546

added the tunnel effect source
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 19 Sep 2015 05:51:51 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/imago2/ftype_module.c	Sat Sep 19 05:51:51 2015 +0300
     1.3 @@ -0,0 +1,118 @@
     1.4 +/*
     1.5 +libimago - a multi-format image file input/output library.
     1.6 +Copyright (C) 2010 John Tsiombikas <nuclear@member.fsf.org>
     1.7 +
     1.8 +This program is free software: you can redistribute it and/or modify
     1.9 +it under the terms of the GNU Lesser General Public License as published
    1.10 +by the Free Software Foundation, either version 3 of the License, or
    1.11 +(at your option) any later version.
    1.12 +
    1.13 +This program is distributed in the hope that it will be useful,
    1.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.16 +GNU Lesser General Public License for more details.
    1.17 +
    1.18 +You should have received a copy of the GNU Lesser General Public License
    1.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1.20 +*/
    1.21 +
    1.22 +#include <stdlib.h>
    1.23 +#include <string.h>
    1.24 +#include "ftype_module.h"
    1.25 +
    1.26 +static struct list_node {
    1.27 +	struct ftype_module *module;
    1.28 +	struct list_node *next;
    1.29 +} *modules;
    1.30 +
    1.31 +/* defined in modules.c which is generated by configure */
    1.32 +void img_modules_init();
    1.33 +
    1.34 +static int done_init;
    1.35 +
    1.36 +int img_register_module(struct ftype_module *mod)
    1.37 +{
    1.38 +	struct list_node *node;
    1.39 +
    1.40 +	if(!(node = malloc(sizeof *node))) {
    1.41 +		return -1;
    1.42 +	}
    1.43 +
    1.44 +	node->module = mod;
    1.45 +	node->next = modules;
    1.46 +	modules = node;
    1.47 +	return 0;
    1.48 +}
    1.49 +
    1.50 +struct ftype_module *img_find_format_module(struct img_io *io)
    1.51 +{
    1.52 +	struct list_node *node;
    1.53 +
    1.54 +	if(!done_init) {
    1.55 +		img_modules_init();
    1.56 +		done_init = 1;
    1.57 +	}
    1.58 +
    1.59 +	node = modules;
    1.60 +	while(node) {
    1.61 +		if(node->module->check(io) != -1) {
    1.62 +			return node->module;
    1.63 +		}
    1.64 +		node = node->next;
    1.65 +	}
    1.66 +	return 0;
    1.67 +}
    1.68 +
    1.69 +struct ftype_module *img_guess_format(const char *fname)
    1.70 +{
    1.71 +	struct list_node *node;
    1.72 +	char *suffix;
    1.73 +	int suffix_len;
    1.74 +
    1.75 +	if(!done_init) {
    1.76 +		img_modules_init();
    1.77 +		done_init = 1;
    1.78 +	}
    1.79 +
    1.80 +	if(!(suffix = strrchr(fname, '.'))) {
    1.81 +		return 0;	/* no suffix, can't guess ... */
    1.82 +	}
    1.83 +	suffix_len = strlen(suffix);
    1.84 +
    1.85 +	node = modules;
    1.86 +	while(node) {
    1.87 +		char *suflist = node->module->suffix;
    1.88 +		char *start, *end;
    1.89 +
    1.90 +		while(*suflist) {
    1.91 +			if(!(start = strstr(suflist, suffix))) {
    1.92 +				break;
    1.93 +			}
    1.94 +			end = start + suffix_len;
    1.95 +
    1.96 +			if(*end == ':' || *end == 0) {
    1.97 +				return node->module;	/* found it */
    1.98 +			}
    1.99 +			suflist = end;
   1.100 +		}
   1.101 +
   1.102 +		node = node->next;
   1.103 +	}
   1.104 +	return 0;
   1.105 +}
   1.106 +
   1.107 +struct ftype_module *img_get_module(int idx)
   1.108 +{
   1.109 +	struct list_node *node;
   1.110 +
   1.111 +	if(!done_init) {
   1.112 +		img_modules_init();
   1.113 +		done_init = 1;
   1.114 +	}
   1.115 +
   1.116 +	node = modules;
   1.117 +	while(node && idx--) {
   1.118 +		node = node->next;
   1.119 +	}
   1.120 +	return node->module;
   1.121 +}