Example #1
0
	int main(int32_t argc, char_t *argv[])
	{
		errFlag = eReturnOK;
		char_t name1[80], name2[80], name3[80], type[80];
   		int32_t      count, i, j;
   		uint32_t     length, width;

       /*********************************************
       *
       *   Interpret the command line parameters.
       *
       **********************************************/
        
	if(argc < 5)
	{	
    		printf(
    		"\n\nNot enough parameters:"
     		"\n"
     		"\n usage: mainover in-file1 in-file2 out-file "
     		"type"
     		"\n"
     		"\n recall type: nonzero zero greater less"
     		" average"
     		"\n the input images must be the same size"
     		"\n"
     		"\n");
    		errFlag = eNotSuffArg;
   	}

	if(errFlag == eReturnOK)
	{
		strcpy(name1,  argv[ARGV_ARGUMENT1]);
   		strcpy(name2, argv[ARGV_ARGUMENT2]);
   		strcpy(name3, argv[ARGV_ARGUMENT3]);
   		strcpy(type,  argv[ARGV_ARGUMENT4]);

	   	if(does_not_exist(name1))
		{
	    		printf("\nERROR input file %s does not exist", name1);
	    		errFlag = eNotInputFile1;
		}
		
		if(errFlag == eReturnOK)
		{
		   	if(does_not_exist(name2))
			{
		    		printf("\nERROR input file %s does not exist", name2);
		    		errFlag = eNotInputFile2;
		   	}

		       /*********************************************
		       *
		       *   Read the input image headers.
		       *   Ensure the input image are the same size.
		       *   Allocate the image arrays and read
		       *   the image data.
		       *
		       **********************************************/
			if(errFlag == eReturnOK)
			{
			   	if(are_not_same_size(name1, name2))
				{
			      		printf("\n Images %s and %s are not the same size", name1, name2);
			      		errFlag = eNotSameSize;
			   	}  /* ends if sizes not the same */

				if(errFlag == eReturnOK)
				{

				   	get_image_size(name1, &length, &width);
				   	the_image = allocate_image_array(length, width);
				   	out_image = allocate_image_array(length, width);
				   	create_image_file(name1, name3);
				   	read_image_array(name1, the_image);
				   	read_image_array(name2, out_image);

				       /*********************************************
				       *
				       *   Apply the desired overlay function.
				       *
				       **********************************************/

				      	/* non-zero */
				   	if(strncmp("non", type, 3) == 0)
					{
				      		non_zero_overlay(the_image, out_image, length, width);
				   	}  /* ends non_zero operation */

				      	/* zero */
				   	if(strcmp("zero", type) == 0)
					{
				      		zero_overlay(the_image, out_image, length, width);
				   	}  /* ends zero operation */

				      	/* greater */
				   	if(strncmp("gre", type, 3) == 0)
					{
				      		greater_overlay(the_image, out_image, length, width);
				   	}  /* ends greater operation */

				      	/* less */
				   	if(strncmp("les", type, 3) == 0)
					{
				      		less_overlay(the_image, out_image, length, width);
				   	}  /* ends less operation */

				      	/* average */
				   	if(strncmp("ave", type, 3) == 0)
					{
				      		average_overlay(the_image, out_image, length, width);
				   	}  /* ends average operation */

				   	write_image_array(name3, out_image);
				   	free_image_array(out_image, length);
				   	free_image_array(the_image, length);

					}}}}
	return errFlag;
	}  /* ends main  */
Example #2
0
int main(uint16_t argc, char_t *argv[])
{

   char_t     name1[80], name2[80], name3[80];
   uint32_t     bits_per_pixel, length, width;
   sint16_t    **image1, **image2;
   uint16_t    max;
	 errFlag = eReturnOK;

       /******************************************
       *
       *  Interpret the command line parameters.
       *
       *******************************************/

if(image1 == NULL) {
	errFlag = eImage1Null;
}

if(image2 == NULL) {
	errFlag = eImage2Null;
}

   if(argc != 5){
    printf(
     "\n"
     "\n usage: mainas in1-file in2-file "
     "out_file add-subtract"
     "\n"
     "\n   recall add-subtract a=add s=subtract\n");
    errFlag = eNotStuffArg;
   }

if(errFlag == eReturnOK) {

   strcpy(name1, argv[1]);
   strcpy(name2, argv[2]);
   strcpy(name3, argv[3]);

   if(does_not_exist(name1)){
    printf("\nERROR input file %s does not exist",
             name1);
    errFlag = eNotExistName1;
   }

if(errFlag == eReturnOK) {

   if(does_not_exist(name2)){
    printf("\nERROR input file %s does not exist",
             name2);
    errFlag = eNotExistName2;
   }

if(errFlag == eReturnOK) {

       /******************************************
       *
       *  Ensure the two input images have the 
       *  same sizes.
       *
       *******************************************/

   if(are_not_same_size(name1, name2)){
      printf(
      "\nERROR Image files %s and %s are not same size", 
      name1, name2);
      errFlag = eNotSameSize;
   }

if(errFlag == eReturnOK) {

       /******************************************
       *
       *  Allocate the two image arrays
       *
       *******************************************/

   get_image_size(name1, &length, &width);
   get_bitsperpixel(name1, &bits_per_pixel);
   image1 = allocate_image_array(length, width);
   image2 = allocate_image_array(length, width);
   
       /******************************************
       *
       *  Create the output file and read the
       *  two input images.
       *
       *******************************************/

   create_image_file(name1, name3);
   read_image_array(name1, image1);
   read_image_array(name2, image2);

       /********************************************
       *
       *   Add or subtract the input images and 
       *   write the result to the output image.
       *
       ********************************************/

   if(argv[4][0] == 'a' || argv[4][0] == 'A'){
      if(bits_per_pixel == 4)
         max = 16;
      else
         max = 255;
      add_image_array(image1, image2,
         length, width, max);
   }  /* ends if add */

   if(argv[4][0] == 's' || argv[4][0] == 'S')
      subtract_image_array(image1, image2,
         length, width);

   write_image_array(name3, image2);

   free_image_array(image1, length);
   free_image_array(image2, length);

}//eNotSameSize
}//eNotExistName
}//eNotExistName1
}/*eNotStuffArg*/
		return errFlag;
}  /* ends main  */