⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xccxct.c

📁 JPEG2000实现的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
		}
		else if(retval==NULL)
			local_error("Empty component collection specification"
				" (parse_collection)");
		do{
			retval = strtok(NULL,tokens);
			if(retval!=NULL){
				collection_strings[i].length = strlen(retval)+1;
				collection_strings[i].string = 
					(char *)local_malloc(COMPONENT_COLLECTION_MEM_KEY,
						collection_strings[i].length*sizeof(char));
				strcpy(collection_strings[i].string,retval);
				i++;
			}
		}while(retval!=NULL);

		/* Allocate array of structures to hold the index arrays */
		comp_collects = (Group *)
			local_malloc(COMPONENT_COLLECTION_MEM_KEY,sizeof(Group));
		comp_collects->no_collections = no_comp_collects;
		comp_collects->collections = 
				(CompData *)local_malloc(COMPONENT_COLLECTION_MEM_KEY,
					no_comp_collects*sizeof(CompData));

		/* Parse the component collections in the string */
		for(i=0;i<no_comp_collects;i++){
			(comp_collects->collections[i]).no_components =
				get_collection(&((comp_collects->collections[i]).indices),
					collection_strings[i].string);
		}
	}

	/* Free up memory */
	local_free((void *) temp_collect);
	for(i=0;i<no_comp_collects;i++)
		local_free((void *) collection_strings[i].string);
	local_free((void *) collection_strings);

    return(comp_collects);
}

/*****************************************************************************
 * EXTERN                        read_cc_file                                *
 *****************************************************************************/
/* Reads an .fcc or .icc file to determine the decorrelation and dependency */
/* transformation component collections. The format of the file should look */
/* something like the following: */
/* */
/*               DECORREL */
/*               [input collection 1][output collection 1][OM1,TM1] */
/*               [input collection 2][output collection 2][OM2,TM2] */
/*                                        . */
/*                                        . */
/*                                        . */
/*               DEPEND */
/*               [input collection 1][output collection 1][OM1,TM1] */
/*               [input collection 2][output collection 2][OM2,TM2] */
/*                                        . */
/*                                        . */
/*                                        . */
/* */
/*               Note that comments are permitted using the C++ */
/*               comment style ('/*'). */
/* */
/* If no decorrelation or dependency transform is desired, the DECORREL and */
/* DEPEND keywords must still be present but no component collection */
/* information follows. Also, the DECORREL section must be first in the file. */
collection *read_cc_file(char *filename)
{
	char suffix[5],buffer[BUF_LEN];
	char *retval;
	uint length,OK,no_collect_groups,i,j,temp;
	int hit_eof;
	Group *collections_list = NULL;
	Group *the_collection,*temp_ptr;
	collection *big_kahuna;
	FILE *fp;

	/* Check for suffix '.fcc' or '.icc'. If it's not present, */
	/* throw an error. Note we do not care about case. If the */
	/* case is wrong and we are on an operating system that */
	/* cares, then the file will fail to open. */
	length = strlen(filename);
	strncpy(suffix,filename+length-4,5);
	convert_to_lower(suffix);
	if(strcmp(suffix,".fcc") != 0){
		if(strcmp(suffix,".icc") != 0)
			OK = 0;
		else
			OK = 1;
	}
	else
		OK = 1;
	if(!OK){
		local_error("Invalid component collection filename: %s (read_cc_file)."
			"\nFile name must end in '.fcc' or '.icc'",filename);
	}

	fp = fopen(filename,"rt");
	if(fp == NULL){
		local_error("Unable to open file: %s (read_cc_file)",filename);
	}

	/* The first non-comment line in an xcc file must be 'DECORREL'. */
	/* So we loop here until we find it or we hit the EOF. */
	OK = 0;
	do{
		retval = fgets2(buffer,BUF_LEN,fp);
		if(retval == NULL){
			hit_eof = feof(fp);
			break;
		}
		length = strip_comment(buffer);
		if(length != 0 ){
			if(strcmp(buffer,"DECORREL") == 0){
				OK = 1;
				break;
			}
			else{
				local_error("Non-comment line precedes DECORREL in file: %s"
					" (read_cc_file)",filename);
			}
		}
	}while(!OK);

	/* Handle the error conditions */
	if(!OK && hit_eof){
		local_error("Keyword DECORREL not found in file: %s (read_cc_file)",
			filename);
	}
	else if(!OK && hit_eof == 0){
		local_error("File read error: %s (read_cc_file)",filename);
	}

	/* We found the 'DECORREL' line, so now we process the decorrelation */
	/* component collections. We stop when we see 'DEPEND' or hit the EOF. */
	OK = 0;
	no_collect_groups = 0;
	do{
		retval = fgets2(buffer,BUF_LEN,fp);
		if(retval == NULL){
			hit_eof = feof(fp);
			break;
		}
		length = strip_comment(buffer);
		if(strcmp(buffer,"DEPEND") == 0){	/* Break on finding 'DEPEND' */
			OK = 1;
			break;
		}
		else if(length != 0 ){	/* Here we process a component collection */
			if(collections_list == NULL){
				/* This is the first collection found so */
				/* it's top of the list. */
				the_collection = collections_list = parse_collection(buffer);
				the_collection->next = NULL;
			}
			else{
				/* If we have already started the list... */
				the_collection->next = parse_collection(buffer);
				the_collection = the_collection->next;
				the_collection->next = NULL;
			}

			/* We should read three collections for each segment */
			if(the_collection->no_collections != 3){
				local_error("Improperly formed component collection "
					"in file: %s (read_cc_file).",filename);
			}
			else
				no_collect_groups++;
		}
	}while(!OK);

	/* Handle the error conditions */
	if(!OK && hit_eof){
		local_error("Keyword DEPEND not found in file: %s (read_cc_file)",
			filename);
	}
	else if(!OK && hit_eof == 0){
		local_error("File read error: %s (read_cc_file)",filename);
	}

	/* We read in the decorrelation component collections. Now we convert */
	/* this linked list into array form using the collection and segment */
	/* structures. We first allocate the collection structure, then the */
	/* segment structure array. */
	big_kahuna = (collection *)local_malloc(COMPONENT_COLLECTION_MEM_KEY,
		sizeof(collection));
	big_kahuna->n_comp_segments = no_collect_groups;

	if(no_collect_groups != 0){
		big_kahuna->comp_segment =
			(segment *)local_malloc(COMPONENT_COLLECTION_MEM_KEY,
				no_collect_groups*sizeof(segment));
		/* Now run the linked list and extract the data */
		i = 0;
		the_collection = temp_ptr = collections_list;
		do{
			/* This block handles the input component collection */
			big_kahuna->comp_segment[i].n_input_components = temp =
				the_collection->collections[0].no_components;
			/* Allocate storage for component indices */
			big_kahuna->comp_segment[i].input_components =
				(int *)local_malloc(COMPONENT_COLLECTION_MEM_KEY,
					temp*sizeof(int));
			for(j=0;j<temp;j++){
				big_kahuna->comp_segment[i].input_components[j] =
					the_collection->collections[0].indices[j];
			}

			/* This block handles the output component collection */
			big_kahuna->comp_segment[i].n_output_components = temp =
				the_collection->collections[1].no_components;
			/* Allocate storage for component indices */
			big_kahuna->comp_segment[i].output_components =
				(int *)local_malloc(COMPONENT_COLLECTION_MEM_KEY,
					temp*sizeof(int));
			for(j=0;j<temp;j++){
				big_kahuna->comp_segment[i].output_components[j] =
					the_collection->collections[1].indices[j];
			}

			/* This block handles the transform & offset matrix specification */
			if(the_collection->collections[2].no_components!=2){
				local_error("Improper decorrelation matrix specification in "
					"file: %s (read_cc_file).",filename);
			}
			big_kahuna->comp_segment[i].off_vector =
				the_collection->collections[2].indices[0];
			big_kahuna->comp_segment[i].xfm_matrix =
				the_collection->collections[2].indices[1];

			the_collection = the_collection->next;

            /* Free the arrays of component indices for each collection */
			for(j=0;j<temp_ptr->no_collections;j++)
				local_free((void *) temp_ptr->collections[j].indices);
			/* Free the structure pointing to the collections */
			local_free((void *)temp_ptr);

            temp_ptr = the_collection;
			i++;
		}while(the_collection != NULL);
	}
	else
		big_kahuna->comp_segment = NULL;

	/* We previously found the 'DEPEND' line, so now we process the */
	/* dependency component collections. We stop when we hit the EOF. */
	no_collect_groups = 0;
	collections_list = NULL;
	for(;;){
		retval = fgets2(buffer,BUF_LEN,fp);
		if(retval == NULL){
			hit_eof = feof(fp);
			break;
		}
		length = strip_comment(buffer);
		if(length != 0 ){	/* Here we process a component collection */
			if(collections_list == NULL){
				/* This is the first collection found so */
				/* it's top of the list. */
				the_collection = collections_list = parse_collection(buffer);
				the_collection->next = NULL;
			}
			else{
				/* If we have already started the list... */
				the_collection->next = parse_collection(buffer);
				the_collection = the_collection->next;
				the_collection->next = NULL;
			}

			/* We should read three collections for each segment */
			if(the_collection->no_collections != 3){
				local_error("Improperly formed component collection in file:"
					" %s (read_cc_file).",filename);
			}
			else
				no_collect_groups++;
		}
	}

	/* Handle the error conditions */
	if(hit_eof == 0){
		local_error("File read error: %s (read_cc_file)",filename);
	}

	/* We read in the dependency component collections. Now we convert */
	/* this linked list into array form using the collection and segment */
	/* structures. */
	big_kahuna->n_intermed_segments = no_collect_groups;
	if(no_collect_groups != 0){
		big_kahuna->intermed_segment =
			(segment *)local_malloc(COMPONENT_COLLECTION_MEM_KEY,
				no_collect_groups*sizeof(segment));
		/* Now run the linked list and extract the data */
		i = 0;
		the_collection = temp_ptr = collections_list;
		do{
			/* This block handles the input component collection */
			big_kahuna->intermed_segment[i].n_input_components = temp =
				the_collection->collections[0].no_components;
			/* Allocate storage for component indices */
			big_kahuna->intermed_segment[i].input_components =
				(int *)local_malloc(COMPONENT_COLLECTION_MEM_KEY,
					temp*sizeof(int));
			for(j=0;j<temp;j++){
				big_kahuna->intermed_segment[i].input_components[j] =
					the_collection->collections[0].indices[j];
			}

			/* This block handles the output component collection */
			big_kahuna->intermed_segment[i].n_output_components = temp =
				the_collection->collections[1].no_components;
			/* Allocate storage for component indices */
			big_kahuna->intermed_segment[i].output_components =
				(int *)local_malloc(COMPONENT_COLLECTION_MEM_KEY,
					temp*sizeof(int));
			for(j=0;j<temp;j++){
				big_kahuna->intermed_segment[i].output_components[j] =
					the_collection->collections[1].indices[j];
			}

			/* This block handles the transform & offset matrix specification */
			if(the_collection->collections[2].no_components!=2){
				local_error("Improper dependency matrix specification in file:"
					" %s (read_cc_file).",filename);
			}
			big_kahuna->intermed_segment[i].off_vector =
				the_collection->collections[2].indices[0];
			big_kahuna->intermed_segment[i].xfm_matrix =
				the_collection->collections[2].indices[1];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -