&^%$#@! 10 Tue Apr 04 06:28:45 1995 This is the clean version that works. !@#$%^& /*********************************************** * * file pstereo.c * * Functions: This file contains * main * zero_line * initialize_pattern * lengthen_pattern * no_change * shorten_pattern * get_random_values * random_substitution * read_image_line * write_image_line * test_print_line * * Purpose: * This file contains a program that will * make pixel based random dot stereograms. * * External Calls: * tiff.c - read_tiff_header * rtiff.c - read_tiff_image * wtiff.c - does_not_exist * round_off_image_size * create_allocate_tiff_file * write_array_into_tiff_image * * Modifications: * 18 March 1995 - created * *************************************************/ /***** ALGORITHM NOTES width is the width of the input and output lines pattern_width is the initial width of the pattern current_width is the current width of the pattern (this changes as elements are inserted into and deleted from the pattern). pattern[] must be wider than width and narrower than ? so I will try it at width=width depth_line[] will be width wide processed_pattern will be width wide index points to the current place in the pattern we are working on pp_index points to the current place in the processed pattern, Cannot use the depth_line counter j for this because you will skip over places in the processed pattern. *********/ #include "cips.h" #define KONSTANT 2 #define PATTERN_START 0 #define PATTERN_END 255 #define ASCII_SIZE 256 #define TEST_NO_CHANGE #undef DEBUG_MODE #define COMMAND_LINE_MODE short the_image[ROWS][COLS]; void zero_line(); void initialize_pattern(); void lengthen_pattern(); void no_change(); void shorten_pattern(); void get_random_values(); void random_substitution(); void read_image_line(); void write_image_line(); void test_print_line(); main(argc, argv) char *argv[]; int argc; { char depth_file_name[MAX_NAME_LENGTH], s_file_name[MAX_NAME_LENGTH], pp_file_name[MAX_NAME_LENGTH], response[MAX_NAME_LENGTH]; FILE *depth_file, *processed_pattern_file, *stereo_file; int current_width, *depth_line, i, j, index, last_pixel, length, location, max_width, *pattern, pattern_width, pp_index, *processed_pattern, this_pixel, width; struct tiff_header_struct image_header; int line = 0; #ifdef COMMAND_LINE_MODE if(argc != 5){ printf( "\nusage: pstereo pattern-width " "\n depth-file-name " "stereo-file-name " "\n processed-pattern-file-name" "\n"); exit(1); } strcpy(depth_file_name, argv[2]); strcpy(s_file_name, argv[3]); strcpy(pp_file_name, argv[4]); if(does_not_exist(depth_file_name)){ printf("\nThe depth file %s does not exist", depth_file_name); exit(1); } read_tiff_header(depth_file_name, &image_header); round_off_image_size(&image_header, &length, &width); image_header.image_length = length*ROWS; image_header.image_width = width*COLS; create_allocate_tiff_file(pp_file_name, &image_header, the_image); create_allocate_tiff_file(s_file_name, &image_header, the_image); width = width*COLS; pattern_width = atoi(argv[1]); pattern = malloc(KONSTANT*width*sizeof(int)); depth_line = malloc(KONSTANT*width*sizeof(int)); processed_pattern = malloc(KONSTANT*width*sizeof(int)); #endif /* ifdef COMMAND_LINE_MODE */ #ifdef DEBUG_MODE strcpy(depth_file_name, "d:/src/dfile.tif"); strcpy(s_file_name, "d:/src/sfile.tif"); strcpy(pp_file_name, "d:/src/ppfile.tif"); if(does_not_exist(depth_file_name)){ printf("\nThe depth file %s does not exist", depth_file_name); exit(1); } read_tiff_header(depth_file_name, &image_header); round_off_image_size(&image_header, &length, &width); image_header.image_length = length*ROWS; image_header.image_width = width*COLS; create_allocate_tiff_file(pp_file_name, &image_header, the_image); create_allocate_tiff_file(s_file_name, &image_header, the_image); width = width*COLS; pattern_width = 15; pattern = malloc(KONSTANT*width*sizeof(int)); depth_line = malloc(KONSTANT*width*sizeof(int)); processed_pattern = malloc(KONSTANT*width*sizeof(int)); #endif /* ifdef COMMAND_LINE_MODE */ /*********************************************** * * This is the major loop of the program. * It reads one line at a time from the * depth file, processes that one line, * and writes the resulting pattern to the * processed pattern file. * ***********************************************/ printf("\npstereo>> %d rows", length*ROWS); for(i=0; i last_pixel) shorten_pattern( (this_pixel-last_pixel), pattern, &index, ¤t_width, width); if(this_pixel < last_pixel) lengthen_pattern( (last_pixel-this_pixel), pattern, &index, ¤t_width, &width, &max_width); /**************************************** * * Perform the no_change in every * pass. Do it after you have done * the shorten and lenghten pattern. * ****************************************/ no_change(pattern, processed_pattern, pp_index, current_width, &index); pp_index++; if(index >= current_width) index = 0; last_pixel = depth_line[j]; } /* ends loop over j */ write_image_line(the_image, pp_file_name, i+1, processed_pattern, width); random_substitution(processed_pattern, width); write_image_line(the_image, s_file_name, i+1, processed_pattern, width); } /* ends the major loop */ free(pattern); free(depth_line); free(processed_pattern); return(111); } /* ends main */ /*********************************************** * * shorten_pattern(... * * This funtion shortens the pattern by * deleting an element from it. For example, * if the input pattern is abcdefg, * the output pattern could be abcfg. * ***********************************************/ void shorten_pattern(size, pattern, index, current_width, width) int *pattern; int size, *index, *current_width, width; { int *temp_pattern; int i, new_index, new_width; temp_pattern = malloc(KONSTANT*width*sizeof(int)); for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *index = 0; free(temp_pattern); } /* ends shorten_pattern */ /*********************************************** * * initialize_pattern(... * * This function creates an initial pattern * that is as wide as the pattern_width * parameter. * ***********************************************/ void initialize_pattern(pattern, current_width, max_width, pattern_width, index) int pattern[]; int *current_width, *max_width, *index, pattern_width; { int i; for(i=0; i= current_width) *index = 0; } /* ends no_change */ /*********************************************** * * zero_line(... * * This function fills an int array with * zeros. * ***********************************************/ void zero_line(array, length) int *array; int length; { int i; for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *index = 0; *max_width = *max_width + size; free(temp_pattern); } /* ends lengthen_pattern */ /*********************************************** * * random_substitution(... * * This function takes the processed_pattern * array and substitutes random values for each * value in the array. * * Fill the substitution_values array with * random characters that are all printable * (PATTERN_START to PATTERN_END). * ***********************************************/ void random_substitution(processed_pattern, width) int *processed_pattern; int width; { int substitution_values[GRAY_LEVELS+1]; int i, place; get_random_values(substitution_values); for(i=0; i<(KONSTANT*width); i++){ place = processed_pattern[i]; processed_pattern[i] = substitution_values[place]; } /* ends loop over i */ } /* ends random_substitution */ /*********************************************** * * get_random_values(... * * This function fills array with random values. * The limit on the random values are from * PATTERN_START to PATTERN_END. * ***********************************************/ void get_random_values(array) int array[]; { int i, number; #ifdef NEVER these lines worked ok, they used all the printable characters from 0 through small z for(i=0; i 57 && number < 65) number = number + 7; array[i] = number; } /* ends loop over i */ #endif #ifdef NEVER /* Let's try something different, only use the characters A-Z A-Z are 65-90 */ for(i=0; i width) le = width; } /* ends else */ } /* ends while still_reading */ } /* ends read_image_line */ /*********************************************** * * write_image_line(... * * This function writes a line of pixels to * a TIFF image file. * ***********************************************/ void write_image_line(the_image, file_name, line_number, array, width) char file_name[]; short the_image[ROWS][COLS]; int *array, line_number, width; { int i, il, ie, ll, le, pixels_to_write, writing_counter, still_writing; il = line_number; ll = il + 1; ie = 1; le = ie + COLS; if(width < COLS) le = ie + (width - 1); pixels_to_write = width; writing_counter = 0; still_writing = 1; while(still_writing){ for(i=0; i<(le-ie); i++) the_image[0][i] = array[i + (writing_counter*COLS)]; writing_counter++; write_array_into_tiff_image(file_name, the_image, il, ie, ll, le); pixels_to_write = pixels_to_write - (le-ie); if(pixels_to_write <= 1) still_writing = 0; else{ ie = ie + COLS; le = ie + COLS; if(le > width) le = width; } /* ends else */ } /* ends while still_writing */ } /* ends write_image_line */ !@#$%^& &^%$#@! 9 Tue Apr 04 05:45:37 1995 This has the debug statement out. Now I will remove the redundant pattern_index and index. I will delete pattern_index. !@#$%^& /*********************************************** * * file pstereo.c * * Functions: This file contains * main * zero_line * initialize_pattern * lengthen_pattern * no_change * shorten_pattern * get_random_values * random_substitution * read_image_line * write_image_line * test_print_line * * Purpose: * This file contains a program that will * make character based stereograms. * * External Calls: * tiff.c - read_tiff_header * rtiff.c - read_tiff_image * wtiff.c - does_not_exist * round_off_image_size * create_allocate_tiff_file * write_array_into_tiff_image * * Modifications: * 18 March 1995 - created * *************************************************/ /***** ALGORITHM NOTES width is the width of the input and output lines pattern_width is the initial width of the pattern current_width is the current width of the pattern (this changes as elements are inserted into and deleted from the pattern). pattern[] must be wider than width and narrower than ? so I will try it at width=width depth_line[] will be width wide processed_pattern will be width wide pattern_index usually points to the end of the pattern index points to the current place in the pattern we are working on pp_index points to the current place in the processed pattern, Cannot use the depth_line counter j for this because you will skip over places in the processed pattern. *********/ #include "cips.h" #define KONSTANT 2 #define PATTERN_START 0 #define PATTERN_END 255 #define ASCII_SIZE 256 #define TEST_NO_CHANGE #undef DEBUG_MODE #define COMMAND_LINE_MODE short the_image[ROWS][COLS]; void zero_line(); void initialize_pattern(); void lengthen_pattern(); void no_change(); void shorten_pattern(); void get_random_values(); void random_substitution(); void read_image_line(); void write_image_line(); void test_print_line(); main(argc, argv) char *argv[]; int argc; { char depth_file_name[MAX_NAME_LENGTH], s_file_name[MAX_NAME_LENGTH], pp_file_name[MAX_NAME_LENGTH], response[MAX_NAME_LENGTH]; FILE *depth_file, *processed_pattern_file, *stereo_file; int current_width, *depth_line, i, j, index, last_pixel, length, location, max_width, *pattern, pattern_index, pattern_width, pp_index, *processed_pattern, this_pixel, width; struct tiff_header_struct image_header; int line = 0; #ifdef COMMAND_LINE_MODE if(argc != 5){ printf( "\nusage: pstereo pattern-width " "\n depth-file-name " "stereo-file-name " "\n processed-pattern-file-name" "\n"); exit(1); } strcpy(depth_file_name, argv[2]); strcpy(s_file_name, argv[3]); strcpy(pp_file_name, argv[4]); if(does_not_exist(depth_file_name)){ printf("\nThe depth file %s does not exist", depth_file_name); exit(1); } read_tiff_header(depth_file_name, &image_header); round_off_image_size(&image_header, &length, &width); image_header.image_length = length*ROWS; image_header.image_width = width*COLS; create_allocate_tiff_file(pp_file_name, &image_header, the_image); create_allocate_tiff_file(s_file_name, &image_header, the_image); width = width*COLS; pattern_width = atoi(argv[1]); pattern = malloc(KONSTANT*width*sizeof(int)); depth_line = malloc(KONSTANT*width*sizeof(int)); processed_pattern = malloc(KONSTANT*width*sizeof(int)); #endif /* ifdef COMMAND_LINE_MODE */ #ifdef DEBUG_MODE strcpy(depth_file_name, "d:/src/dfile.tif"); strcpy(s_file_name, "d:/src/sfile.tif"); strcpy(pp_file_name, "d:/src/ppfile.tif"); if(does_not_exist(depth_file_name)){ printf("\nThe depth file %s does not exist", depth_file_name); exit(1); } read_tiff_header(depth_file_name, &image_header); round_off_image_size(&image_header, &length, &width); image_header.image_length = length*ROWS; image_header.image_width = width*COLS; create_allocate_tiff_file(pp_file_name, &image_header, the_image); create_allocate_tiff_file(s_file_name, &image_header, the_image); width = width*COLS; pattern_width = 15; pattern = malloc(KONSTANT*width*sizeof(int)); depth_line = malloc(KONSTANT*width*sizeof(int)); processed_pattern = malloc(KONSTANT*width*sizeof(int)); #endif /* ifdef COMMAND_LINE_MODE */ #ifdef DEBUG_MODE #endif /* ifdef DEBUG_MODE */ /*********************************************** * * This is the major loop of the program. * It reads one line at a time from the * depth file, processes that one line, * and writes the resulting pattern to the * processed pattern file. * ***********************************************/ printf("\npstereo>> %d rows", length*ROWS); for(i=0; i last_pixel) shorten_pattern( (this_pixel-last_pixel), pattern, &index, ¤t_width, &pattern_index, width); if(this_pixel < last_pixel) lengthen_pattern( (last_pixel-this_pixel), pattern, &index, ¤t_width, &pattern_index, &width, &max_width); /**************************************** * * Perform the no_change in every * pass. Do it after you have done * the shorten and lenghten pattern. * ****************************************/ no_change(pattern, processed_pattern, pp_index, &pattern_index, current_width, &index); pp_index++; if(pattern_index >= current_width) pattern_index = 0; last_pixel = depth_line[j]; } /* ends loop over j */ write_image_line(the_image, pp_file_name, i+1, processed_pattern, width); random_substitution(processed_pattern, width); write_image_line(the_image, s_file_name, i+1, processed_pattern, width); } /* ends the major loop */ free(pattern); free(depth_line); free(processed_pattern); return(111); } /* ends main */ /*********************************************** * * shorten_pattern(... * * This funtion shortens the pattern by * deleting an element from it. For example, * if the input pattern is abcdefg, * the output pattern could be abcfg. * ***********************************************/ void shorten_pattern(size, pattern, index, current_width, pattern_index, width) int *pattern; int size, *index, *current_width, *pattern_index, width; { int *temp_pattern; int i, new_index, new_width; temp_pattern = malloc(KONSTANT*width*sizeof(int)); for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *pattern_index = 0; *index = *pattern_index; free(temp_pattern); } /* ends shorten_pattern */ /*********************************************** * * initialize_pattern(... * * This function creates an initial pattern * that is as wide as the pattern_width * parameter. * ***********************************************/ void initialize_pattern(pattern_index, pattern, current_width, max_width, pattern_width, index) int pattern[]; int *pattern_index, *current_width, *max_width, *index, pattern_width; { int i; for(i=0; i= current_width) *pattern_index = 0; *index = *index + 1; if(*index >= current_width) *index = 0; } /* ends no_change */ /*********************************************** * * zero_line(... * * This function fills an int array with * zeros. * ***********************************************/ void zero_line(array, length) int *array; int length; { int i; for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *pattern_index = 0; *index = *pattern_index; *max_width = *max_width + size; free(temp_pattern); } /* ends lengthen_pattern */ /*********************************************** * * random_substitution(... * * This function takes the processed_pattern * array and substitutes random values for each * value in the array. * * Fill the substitution_values array with * random characters that are all printable * (PATTERN_START to PATTERN_END). * ***********************************************/ void random_substitution(processed_pattern, width) int *processed_pattern; int width; { int substitution_values[GRAY_LEVELS+1]; int i, place; get_random_values(substitution_values); for(i=0; i<(KONSTANT*width); i++){ place = processed_pattern[i]; processed_pattern[i] = substitution_values[place]; } /* ends loop over i */ } /* ends random_substitution */ /*********************************************** * * get_random_values(... * * This function fills array with random values. * The limit on the random values are from * PATTERN_START to PATTERN_END. * ***********************************************/ void get_random_values(array) int array[]; { int i, number; #ifdef NEVER these lines worked ok, they used all the printable characters from 0 through small z for(i=0; i 57 && number < 65) number = number + 7; array[i] = number; } /* ends loop over i */ #endif #ifdef NEVER /* Let's try something different, only use the characters A-Z A-Z are 65-90 */ for(i=0; i width) le = width; } /* ends else */ } /* ends while still_reading */ } /* ends read_image_line */ /*********************************************** * * write_image_line(... * ***********************************************/ void write_image_line(the_image, file_name, line_number, array, width) char file_name[]; short the_image[ROWS][COLS]; int *array, line_number, width; { int i, il, ie, ll, le, pixels_to_write, writing_counter, still_writing; il = line_number; ll = il + 1; ie = 1; le = ie + COLS; if(width < COLS) le = ie + (width - 1); pixels_to_write = width; writing_counter = 0; still_writing = 1; while(still_writing){ for(i=0; i<(le-ie); i++) the_image[0][i] = array[i + (writing_counter*COLS)]; writing_counter++; write_array_into_tiff_image(file_name, the_image, il, ie, ll, le); pixels_to_write = pixels_to_write - (le-ie); if(pixels_to_write <= 1) still_writing = 0; else{ ie = ie + COLS; le = ie + COLS; if(le > width) le = width; } /* ends else */ } /* ends while still_writing */ } /* ends write_image_line */ !@#$%^& &^%$#@! 8 Sun Mar 26 11:48:35 1995 This has lots of debug printf statements BUT IT WORKS RIGHT! It has the correction to set index equal to pattern_index. Corrects an error in the text book. !@#$%^& /*********************************************** * * file pstereo.c * * Functions: This file contains * main * zero_line * initialize_pattern * lengthen_pattern * no_change * shorten_pattern * get_random_values * random_substitution * read_image_line * write_image_line * test_print_line * * Purpose: * This file contains a program that will * make character based stereograms. * * External Calls: * tiff.c - read_tiff_header * ritff.c - read_tiff_image * wtiff.c - does_not_exist * round_off_image_size * create_allocate_tiff_file * write_array_into_tiff_image * * Modifications: * 18 March 1995 - created * *************************************************/ /***** ALGORITHM NOTES width is the width of the input and output lines pattern_width is the initial width of the pattern current_width is the current width of the pattern (this changes as elements are inserted into and deleted from the pattern). pattern[] must be wider than width and narrower than ? so I will try it at width=width depth_line[] will be width wide processed_pattern will be width wide pattern_index usually points to the end of the pattern index points to the current place in the pattern we are working on pp_index points to the current place in the processed pattern, Cannot use the depth_line counter j for this because you will skip over places in the processed pattern. *********/ #include "cips.h" #define KONSTANT 2 #define PATTERN_START 0 #define PATTERN_END 255 #define ASCII_SIZE 256 #define TEST_NO_CHANGE #undef DEBUG_MODE #define COMMAND_LINE_MODE short the_image[ROWS][COLS]; void zero_line(); void initialize_pattern(); void lengthen_pattern(); void no_change(); void shorten_pattern(); void get_random_values(); void random_substitution(); void read_image_line(); void write_image_line(); void test_print_line(); main(argc, argv) char *argv[]; int argc; { char depth_file_name[MAX_NAME_LENGTH], s_file_name[MAX_NAME_LENGTH], pp_file_name[MAX_NAME_LENGTH], response[MAX_NAME_LENGTH]; FILE *depth_file, *processed_pattern_file, *stereo_file; int current_width, *depth_line, i, j, index, last_pixel, length, location, max_width, *pattern, pattern_index, pattern_width, pp_index, *processed_pattern, this_pixel, width; struct tiff_header_struct image_header; int line = 0; #ifdef COMMAND_LINE_MODE if(argc != 5){ printf( "\nusage: pstereo pattern-width " "\n depth-file-name " "stereo-file-name " "\n processed-pattern-file-name" "\n"); exit(1); } strcpy(depth_file_name, argv[2]); strcpy(s_file_name, argv[3]); strcpy(pp_file_name, argv[4]); if(does_not_exist(depth_file_name)){ printf("\nThe depth file %s does not exist", depth_file_name); exit(1); } read_tiff_header(depth_file_name, &image_header); round_off_image_size(&image_header, &length, &width); image_header.image_length = length*ROWS; image_header.image_width = width*COLS; create_allocate_tiff_file(pp_file_name, &image_header, the_image); create_allocate_tiff_file(s_file_name, &image_header, the_image); width = width*COLS; pattern_width = atoi(argv[1]); pattern = malloc(KONSTANT*width*sizeof(int)); depth_line = malloc(KONSTANT*width*sizeof(int)); processed_pattern = malloc(KONSTANT*width*sizeof(int)); #endif /* ifdef COMMAND_LINE_MODE */ #ifdef DEBUG_MODE strcpy(depth_file_name, "d:/src/dfile.tif"); strcpy(s_file_name, "d:/src/sfile.tif"); strcpy(pp_file_name, "d:/src/ppfile.tif"); if(does_not_exist(depth_file_name)){ printf("\nThe depth file %s does not exist", depth_file_name); exit(1); } read_tiff_header(depth_file_name, &image_header); round_off_image_size(&image_header, &length, &width); image_header.image_length = length*ROWS; image_header.image_width = width*COLS; create_allocate_tiff_file(pp_file_name, &image_header, the_image); create_allocate_tiff_file(s_file_name, &image_header, the_image); width = width*COLS; pattern_width = 15; pattern = malloc(KONSTANT*width*sizeof(int)); depth_line = malloc(KONSTANT*width*sizeof(int)); processed_pattern = malloc(KONSTANT*width*sizeof(int)); #endif /* ifdef COMMAND_LINE_MODE */ #ifdef DEBUG_MODE #endif /* ifdef DEBUG_MODE */ /*********************************************** * * This is the major loop of the program. * It reads one line at a time from the * depth file, processes that one line, * and writes the resulting pattern to the * processed pattern file. * ***********************************************/ printf("\npstereo>> %d rows", length*ROWS); for(i=0; i last_pixel) shorten_pattern( (this_pixel-last_pixel), pattern, &index, ¤t_width, &pattern_index, width); if(this_pixel < last_pixel) lengthen_pattern( (last_pixel-this_pixel), pattern, &index, ¤t_width, &pattern_index, &width, &max_width); /**************************************** * * Perform the no_change in every * pass. Do it after you have done * the shorten and lenghten pattern. * ****************************************/ no_change(pattern, processed_pattern, pp_index, &pattern_index, current_width, &index); pp_index++; if(pattern_index >= current_width) pattern_index = 0; last_pixel = depth_line[j]; } /* ends loop over j */ write_image_line(the_image, pp_file_name, i+1, processed_pattern, width); random_substitution(processed_pattern, width); write_image_line(the_image, s_file_name, i+1, processed_pattern, width); } /* ends the major loop */ free(pattern); free(depth_line); free(processed_pattern); return(111); } /* ends main */ /*********************************************** * * shorten_pattern(... * * This funtion shortens the pattern by * deleting an element from it. For example, * if the input pattern is abcdefg, * the output pattern could be abcfg. * ***********************************************/ void shorten_pattern(size, pattern, index, current_width, pattern_index, width) int *pattern; int size, *index, *current_width, *pattern_index, width; { int *temp_pattern; int i, new_index, new_width; char testr[80]; printf("\nSHORTEN> enter Test (t) or Not (n)"); gets(testr); if(testr[0] == 't' || testr[0] == 'T'){ printf("\n|pndx=%d|ndx=%d|wid=%d|", *pattern_index, *index, *current_width); for(i=0; i<*current_width; i++) printf("-%3d", pattern[i]); } /* ends if testr */ temp_pattern = malloc(KONSTANT*width*sizeof(int)); for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *pattern_index = 0; *index = *pattern_index; free(temp_pattern); if(testr[0] == 't' || testr[0] == 'T'){ printf("\n|pndx=%d|ndx=%d|wid=%d|", *pattern_index, *index, *current_width); for(i=0; i<*current_width; i++) printf("-%3d", pattern[i]); } /* ends if testr */ } /* ends shorten_pattern */ /*********************************************** * * initialize_pattern(... * * This function creates an initial pattern * that is as wide as the pattern_width * parameter. * ***********************************************/ void initialize_pattern(pattern_index, pattern, current_width, max_width, pattern_width, index) int pattern[]; int *pattern_index, *current_width, *max_width, *index, pattern_width; { int i; for(i=0; i= current_width) *pattern_index = 0; *index = *index + 1; if(*index >= current_width) *index = 0; } /* ends no_change */ /*********************************************** * * zero_line(... * * This function fills an int array with * zeros. * ***********************************************/ void zero_line(array, length) int *array; int length; { int i; for(i=0; i enter Test (t) or Not (n)"); gets(testr); if(testr[0] == 't' || testr[0] == 'T'){ printf("\n|pndx=%d|ndx=%d|wid=%d|", *pattern_index, *index, *current_width); for(i=0; i<*current_width; i++) printf("-%3d", pattern[i]); } /* ends if testr */ temp_pattern = malloc(KONSTANT*(*width)*sizeof(int)); for(i=0; i<(*width); i++) temp_pattern[i] = pattern[i]; zero_line(pattern, KONSTANT*(*width)); for(count=0, new_index=0; count= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *pattern_index = 0; *index = *pattern_index; *max_width = *max_width + size; free(temp_pattern); if(testr[0] == 't' || testr[0] == 'T'){ printf("\n|pndx=%d|ndx=%d|wid=%d|", *pattern_index, *index, *current_width); for(i=0; i<*current_width; i++) printf("-%3d", pattern[i]); printf("\nPress Enter to continue"); gets(testr); } /* ends if testr */ } /* ends lengthen_pattern */ /*********************************************** * * random_substitution(... * * This function takes the processed_pattern * array and substitutes random values for each * value in the array. * * Fill the substitution_values array with * random characters that are all printable * (PATTERN_START to PATTERN_END). * ***********************************************/ void random_substitution(processed_pattern, width) int *processed_pattern; int width; { int substitution_values[GRAY_LEVELS+1]; int i, place; get_random_values(substitution_values); for(i=0; i<(KONSTANT*width); i++){ place = processed_pattern[i]; processed_pattern[i] = substitution_values[place]; } /* ends loop over i */ } /* ends random_substitution */ /*********************************************** * * get_random_values(... * * This function fills array with random values. * The limit on the random values are from * PATTERN_START to PATTERN_END. * ***********************************************/ void get_random_values(array) int array[]; { int i, number; #ifdef NEVER these lines worked ok, they used all the printable characters from 0 through small z for(i=0; i 57 && number < 65) number = number + 7; array[i] = number; } /* ends loop over i */ #endif #ifdef NEVER /* Let's try something different, only use the characters A-Z A-Z are 65-90 */ for(i=0; i width) le = width; } /* ends else */ } /* ends while still_reading */ } /* ends read_image_line */ /*********************************************** * * write_image_line(... * ***********************************************/ void write_image_line(the_image, file_name, line_number, array, width) char file_name[]; short the_image[ROWS][COLS]; int *array, line_number, width; { int i, il, ie, ll, le, pixels_to_write, writing_counter, still_writing; il = line_number; ll = il + 1; ie = 1; le = ie + COLS; if(width < COLS) le = ie + (width - 1); pixels_to_write = width; writing_counter = 0; still_writing = 1; while(still_writing){ for(i=0; i<(le-ie); i++) the_image[0][i] = array[i + (writing_counter*COLS)]; writing_counter++; write_array_into_tiff_image(file_name, the_image, il, ie, ll, le); pixels_to_write = pixels_to_write - (le-ie); if(pixels_to_write <= 1) still_writing = 0; else{ ie = ie + COLS; le = ie + COLS; if(le > width) le = width; } /* ends else */ } /* ends while still_writing */ } /* ends write_image_line */ !@#$%^& &^%$#@! 7 Mon Mar 20 06:24:58 1995 The read_image_line and write_image_line work. !@#$%^& /*********************************************** * * file pstereo.c * * Functions: This file contains * main * zero_line * initialize_pattern * lengthen_pattern * no_change * shorten_pattern * get_random_values * random_substitution * read_image_line * write_image_line * test_print_line * * Purpose: * This file contains a program that will * make character based stereograms. * * External Calls: * tiff.c - read_tiff_header * ritff.c - read_tiff_image * wtiff.c - does_not_exist * round_off_image_size * create_allocate_tiff_file * write_array_into_tiff_image * * Modifications: * 18 March 1995 - created * *************************************************/ /***** ALGORITHM NOTES width is the width of the input and output lines pattern_width is the initial width of the pattern current_width is the current width of the pattern (this changes as elements are inserted into and deleted from the pattern). pattern[] must be wider than width and narrower than ? so I will try it at width=width depth_line[] will be width wide processed_pattern will be width wide pattern_index usually points to the end of the pattern index points to the current place in the pattern we are working on pp_index points to the current place in the processed pattern, Cannot use the depth_line counter j for this because you will skip over places in the processed pattern. *********/ #include "cips.h" #define KONSTANT 2 #define PATTERN_START 0 #define PATTERN_END 255 #define ASCII_SIZE 256 #define TEST_NO_CHANGE #undef DEBUG_MODE #define COMMAND_LINE_MODE short the_image[ROWS][COLS]; void zero_line(); void initialize_pattern(); void lengthen_pattern(); void no_change(); void shorten_pattern(); void get_random_values(); void random_substitution(); void read_image_line(); void write_image_line(); void test_print_line(); main(argc, argv) char *argv[]; int argc; { char depth_file_name[MAX_NAME_LENGTH], s_file_name[MAX_NAME_LENGTH], pp_file_name[MAX_NAME_LENGTH], response[MAX_NAME_LENGTH]; FILE *depth_file, *processed_pattern_file, *stereo_file; int current_width, *depth_line, i, j, index, last_pixel, length, location, max_width, *pattern, pattern_index, pattern_width, pp_index, *processed_pattern, this_pixel, width; struct tiff_header_struct image_header; int line = 0; #ifdef COMMAND_LINE_MODE if(argc != 5){ printf( "\nusage: pstereo pattern-width " "\n depth-file-name " "stereo-file-name " "\n processed-pattern-file-name" "\n"); exit(1); } strcpy(depth_file_name, argv[2]); strcpy(s_file_name, argv[3]); strcpy(pp_file_name, argv[4]); if(does_not_exist(depth_file_name)){ printf("\nThe depth file %s does not exist", depth_file_name); exit(1); } read_tiff_header(depth_file_name, &image_header); round_off_image_size(&image_header, &length, &width); image_header.image_length = length*ROWS; image_header.image_width = width*COLS; create_allocate_tiff_file(pp_file_name, &image_header, the_image); create_allocate_tiff_file(s_file_name, &image_header, the_image); width = width*COLS; pattern_width = atoi(argv[1]); pattern = malloc(KONSTANT*width*sizeof(int)); depth_line = malloc(KONSTANT*width*sizeof(int)); processed_pattern = malloc(KONSTANT*width*sizeof(int)); #endif /* ifdef COMMAND_LINE_MODE */ #ifdef DEBUG_MODE strcpy(depth_file_name, "d:/src/dfile.tif"); strcpy(s_file_name, "d:/src/sfile.tif"); strcpy(pp_file_name, "d:/src/ppfile.tif"); if(does_not_exist(depth_file_name)){ printf("\nThe depth file %s does not exist", depth_file_name); exit(1); } read_tiff_header(depth_file_name, &image_header); round_off_image_size(&image_header, &length, &width); image_header.image_length = length*ROWS; image_header.image_width = width*COLS; create_allocate_tiff_file(pp_file_name, &image_header, the_image); create_allocate_tiff_file(s_file_name, &image_header, the_image); width = width*COLS; pattern_width = 10; pattern = malloc(KONSTANT*width*sizeof(int)); depth_line = malloc(KONSTANT*width*sizeof(int)); processed_pattern = malloc(KONSTANT*width*sizeof(int)); #endif /* ifdef COMMAND_LINE_MODE */ #ifdef DEBUG_MODE #endif /* ifdef DEBUG_MODE */ /*********************************************** * * This is the major loop of the program. * It reads one line at a time from the * depth file, processes that one line, * and writes the resulting pattern to the * processed pattern file. * ***********************************************/ for(i=0; i last_pixel) shorten_pattern( (this_pixel-last_pixel), pattern, &index, ¤t_width, &pattern_index, width); if(this_pixel < last_pixel) lengthen_pattern( (last_pixel-this_pixel), pattern, &index, ¤t_width, &pattern_index, &width, &max_width); /**************************************** * * Perform the no_change in every * pass. Do it after you have done * the shorten and lenghten pattern. * ****************************************/ no_change(pattern, processed_pattern, pp_index, &pattern_index, current_width, &index); pp_index++; if(pattern_index >= current_width) pattern_index = 0; last_pixel = depth_line[j]; } /* ends loop over j */ write_image_line(the_image, pp_file_name, i+1, processed_pattern, width); random_substitution(processed_pattern, width); write_image_line(the_image, s_file_name, i+1, processed_pattern, width); } /* ends the major loop */ free(pattern); free(depth_line); free(processed_pattern); return(111); } /* ends main */ /*********************************************** * * shorten_pattern(... * * This funtion shortens the pattern by * deleting an element from it. For example, * if the input pattern is abcdefg, * the output pattern could be abcfg. * ***********************************************/ void shorten_pattern(size, pattern, index, current_width, pattern_index, width) int *pattern; int size, *index, *current_width, *pattern_index, width; { int *temp_pattern; int i, new_index, new_width; temp_pattern = malloc(KONSTANT*width*sizeof(int)); for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *pattern_index = 0; free(temp_pattern); } /* ends shorten_pattern */ /*********************************************** * * initialize_pattern(... * * This function creates an initial pattern * that is as wide as the pattern_width * parameter. * ***********************************************/ void initialize_pattern(pattern_index, pattern, current_width, max_width, pattern_width, index) int pattern[]; int *pattern_index, *current_width, *max_width, *index, pattern_width; { int i; for(i=0; i= current_width) *pattern_index = 0; *index = *index + 1; if(*index >= current_width) *index = 0; } /* ends no_change */ /*********************************************** * * zero_line(... * * This function fills an int array with * zeros. * ***********************************************/ void zero_line(array, length) int *array; int length; { int i; for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *pattern_index = 0; *max_width = *max_width + size; free(temp_pattern); } /* ends lengthen_pattern */ /*********************************************** * * random_substitution(... * * This function takes the processed_pattern * array and substitutes random values for each * value in the array. * * Fill the substitution_values array with * random characters that are all printable * (PATTERN_START to PATTERN_END). * ***********************************************/ void random_substitution(processed_pattern, width) int *processed_pattern; int width; { int substitution_values[GRAY_LEVELS+1]; int i, place; get_random_values(substitution_values); for(i=0; i<(KONSTANT*width); i++){ place = processed_pattern[i]; processed_pattern[i] = substitution_values[place]; } /* ends loop over i */ } /* ends random_substitution */ /*********************************************** * * get_random_values(... * * This function fills array with random values. * The limit on the random values are from * PATTERN_START to PATTERN_END. * ***********************************************/ void get_random_values(array) int array[]; { int i, number; #ifdef NEVER these lines worked ok, they used all the printable characters from 0 through small z for(i=0; i 57 && number < 65) number = number + 7; array[i] = number; } /* ends loop over i */ #endif /* Let's try something different, only use the characters A-Z A-Z are 65-90 */ for(i=0; i width) le = width; } /* ends else */ } /* ends while still_reading */ } /* ends read_image_line */ /*********************************************** * * write_image_line(... * ***********************************************/ void write_image_line(the_image, file_name, line_number, array, width) char file_name[]; short the_image[ROWS][COLS]; int *array, line_number, width; { int i, il, ie, ll, le, pixels_to_write, writing_counter, still_writing; il = line_number; ll = il + 1; ie = 1; le = ie + COLS; if(width < COLS) le = ie + (width - 1); pixels_to_write = width; writing_counter = 0; still_writing = 1; while(still_writing){ for(i=0; i<(le-ie); i++) the_image[0][i] = array[i + (writing_counter*COLS)]; writing_counter++; write_array_into_tiff_image(file_name, the_image, il, ie, ll, le); pixels_to_write = pixels_to_write - (le-ie); if(pixels_to_write <= 1) still_writing = 0; else{ ie = ie + COLS; le = ie + COLS; if(le > width) le = width; } /* ends else */ } /* ends while still_writing */ } /* ends write_image_line */ !@#$%^& &^%$#@! 6 Sun Mar 19 10:56:58 1995 Coded write_image_line. No testing yet. !@#$%^& /*********************************************** * * file pstereo.c * * Functions: This file contains * main * zero_line * initialize_pattern * lengthen_pattern * no_change * shorten_pattern * get_random_values * random_substitution * read_image_line * write_image_line * test_print_line * * Purpose: * This file contains a program that will * make character based stereograms. * * External Calls: * tiff.c - read_tiff_header * ritff.c - read_tiff_image * wtiff.c - does_not_exist * round_off_image_size * create_allocate_tiff_file * write_array_into_tiff_image * * Modifications: * 18 March 1995 - created * *************************************************/ /***** ALGORITHM NOTES width is the width of the input and output lines pattern_width is the initial width of the pattern current_width is the current width of the pattern (this changes as elements are inserted into and deleted from the pattern). pattern[] must be wider than width and narrower than ? so I will try it at width=width depth_line[] will be width wide processed_pattern will be width wide pattern_index usually points to the end of the pattern index points to the current place in the pattern we are working on pp_index points to the current place in the processed pattern, Cannot use the depth_line counter j for this because you will skip over places in the processed pattern. *********/ #include "cips.h" #define KONSTANT 2 #define PATTERN_START 0 #define PATTERN_END 255 #define ASCII_SIZE 256 #define TEST_NO_CHANGE #define DEBUG_MODE #undef COMMAND_LINE_MODE short the_image[ROWS][COLS]; void zero_line(); void initialize_pattern(); void lengthen_pattern(); void no_change(); void shorten_pattern(); void get_random_values(); void random_substitution(); void read_image_line(); void write_image_line(); void test_print_line(); main(argc, argv) char *argv[]; int argc; { char depth_file_name[MAX_NAME_LENGTH], s_file_name[MAX_NAME_LENGTH], pp_file_name[MAX_NAME_LENGTH], response[MAX_NAME_LENGTH]; FILE *depth_file, *processed_pattern_file, *stereo_file; int current_width, *depth_line, i, j, index, last_pixel, length, location, max_width, *pattern, pattern_index, pattern_width, pp_index, *processed_pattern, this_pixel, width; struct tiff_header_struct image_header; int line = 0; #ifdef COMMAND_LINE_MODE if(argc != 5){ printf( "\nusage: pstereo pattern-width " "\n depth-file-name " "stereo-file-name " "\n processed-pattern-file-name" "\n"); exit(1); } strcpy(depth_file_name, argv[2]); strcpy(s_file_name, argv[3]); strcpy(pp_file_name, argv[4]); if(does_not_exist(depth_file_name)){ printf("\nThe depth file %s does not exist", depth_file_name); exit(1); } read_tiff_header(depth_file_name, &image_header); round_off_image_size(&image_header, &length, &width); image_header.image_length = length*ROWS; image_header.image_width = width*COLS; create_allocate_tiff_file(pp_file_name, &image_header, the_image); create_allocate_tiff_file(s_file_name, &image_header, the_image); width = width*COLS; pattern_width = atoi(argv[1]); pattern = malloc(KONSTANT*width*sizeof(int)); depth_line = malloc(KONSTANT*width*sizeof(int)); processed_pattern = malloc(KONSTANT*width*sizeof(int)); #endif /* ifdef COMMAND_LINE_MODE */ #ifdef DEBUG_MODE strcpy(depth_file_name, "d:/src/dfile.tif"); strcpy(s_file_name, "d:/src/sfile.tif"); strcpy(pp_file_name, "d:/src/ppfile.tif"); if(does_not_exist(depth_file_name)){ printf("\nThe depth file %s does not exist", depth_file_name); exit(1); } read_tiff_header(depth_file_name, &image_header); round_off_image_size(&image_header, &length, &width); image_header.image_length = length*ROWS; image_header.image_width = width*COLS; create_allocate_tiff_file(pp_file_name, &image_header, the_image); create_allocate_tiff_file(s_file_name, &image_header, the_image); width = width*COLS; pattern_width = 10; pattern = malloc(KONSTANT*width*sizeof(int)); depth_line = malloc(KONSTANT*width*sizeof(int)); processed_pattern = malloc(KONSTANT*width*sizeof(int)); #endif /* ifdef COMMAND_LINE_MODE */ #ifdef DEBUG_MODE #endif /* ifdef DEBUG_MODE */ /*********************************************** * * This is the major loop of the program. * It reads one line at a time from the * depth file, processes that one line, * and writes the resulting pattern to the * processed pattern file. * ***********************************************/ for(i=0; i last_pixel) shorten_pattern( (this_pixel-last_pixel), pattern, &index, ¤t_width, &pattern_index, width); if(this_pixel < last_pixel) lengthen_pattern( (last_pixel-this_pixel), pattern, &index, ¤t_width, &pattern_index, &width, &max_width); /**************************************** * * Perform the no_change in every * pass. Do it after you have done * the shorten and lenghten pattern. * ****************************************/ no_change(pattern, processed_pattern, pp_index, &pattern_index, current_width, &index); pp_index++; if(pattern_index >= current_width) pattern_index = 0; last_pixel = depth_line[j]; } /* ends loop over j */ write_image_line(the_image, pp_file_name, i+1, processed_pattern, width); random_substitution(processed_pattern, width); write_image_line(the_image, s_file_name, i+1, processed_pattern, width); } /* ends the major loop */ free(pattern); free(depth_line); free(processed_pattern); return(111); } /* ends main */ /*********************************************** * * shorten_pattern(... * * This funtion shortens the pattern by * deleting an element from it. For example, * if the input pattern is abcdefg, * the output pattern could be abcfg. * ***********************************************/ void shorten_pattern(size, pattern, index, current_width, pattern_index, width) int *pattern; int size, *index, *current_width, *pattern_index, width; { int *temp_pattern; int i, new_index, new_width; temp_pattern = malloc(KONSTANT*width*sizeof(int)); for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *pattern_index = 0; free(temp_pattern); } /* ends shorten_pattern */ /*********************************************** * * initialize_pattern(... * * This function creates an initial pattern * that is as wide as the pattern_width * parameter. * ***********************************************/ void initialize_pattern(pattern_index, pattern, current_width, max_width, pattern_width, index) int pattern[]; int *pattern_index, *current_width, *max_width, *index, pattern_width; { int i; for(i=0; i= current_width) *pattern_index = 0; *index = *index + 1; if(*index >= current_width) *index = 0; } /* ends no_change */ /*********************************************** * * zero_line(... * * This function fills an int array with * zeros. * ***********************************************/ void zero_line(array, length) int *array; int length; { int i; for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *pattern_index = 0; *max_width = *max_width + size; free(temp_pattern); } /* ends lengthen_pattern */ /*********************************************** * * random_substitution(... * * This function takes the processed_pattern * array and substitutes random values for each * value in the array. * * Fill the substitution_values array with * random characters that are all printable * (PATTERN_START to PATTERN_END). * ***********************************************/ void random_substitution(processed_pattern, width) int *processed_pattern; int width; { int substitution_values[GRAY_LEVELS+1]; int i, place; get_random_values(substitution_values); for(i=0; i<(KONSTANT*width); i++){ place = processed_pattern[i]; processed_pattern[i] = substitution_values[place]; } /* ends loop over i */ } /* ends random_substitution */ /*********************************************** * * get_random_values(... * * This function fills array with random values. * The limit on the random values are from * PATTERN_START to PATTERN_END. * ***********************************************/ void get_random_values(array) int array[]; { int i, number; #ifdef NEVER these lines worked ok, they used all the printable characters from 0 through small z for(i=0; i 57 && number < 65) number = number + 7; array[i] = number; } /* ends loop over i */ #endif /* Let's try something different, only use the characters A-Z A-Z are 65-90 */ for(i=0; i width) le = width; } /* ends else */ } /* ends while still_reading */ } /* ends read_image_line */ /*********************************************** * * write_image_line(... * ***********************************************/ void write_image_line(the_image, file_name, line_number, array, width) char file_name[]; short the_image[ROWS][COLS]; int *array, line_number, width; { int i, il, ie, ll, le, pixels_to_write, writing_counter, still_writing; il = line_number; ll = il + 1; ie = 1; le = ie + COLS; if(width < COLS) le = ie + (width - 1); pixels_to_write = width; writing_counter = 0; still_writing = 1; while(still_writing){ for(i=0; i<(le-ie); i++) the_image[0][i] = array[i + (writing_counter*COLS)]; write_array_into_tiff_image(file_name, the_image, il, ie, ll, le); pixels_to_write = pixels_to_write - (le-ie); if(pixels_to_write <= 1) still_writing = 0; else{ ie = ie + COLS; le = ie + COLS; if(le > width) le = width; } /* ends else */ } /* ends while still_writing */ } /* ends write_image_line */ !@#$%^& &^%$#@! 5 Sun Mar 19 10:33:56 1995 Finished testing read_image_line. OK I think. !@#$%^& /*********************************************** * * file pstereo.c * * Functions: This file contains * main * zero_line * initialize_pattern * lengthen_pattern * no_change * shorten_pattern * get_random_values * random_substitution * read_image_line * write_image_line * test_print_line * * Purpose: * This file contains a program that will * make character based stereograms. * * External Calls: * tiff.c - read_tiff_header * ritff.c - read_tiff_image * wtiff.c - does_not_exist * round_off_image_size * create_allocate_tiff_file * * Modifications: * 18 March 1995 - created * *************************************************/ /***** ALGORITHM NOTES width is the width of the input and output lines pattern_width is the initial width of the pattern current_width is the current width of the pattern (this changes as elements are inserted into and deleted from the pattern). pattern[] must be wider than width and narrower than ? so I will try it at width=width depth_line[] will be width wide processed_pattern will be width wide pattern_index usually points to the end of the pattern index points to the current place in the pattern we are working on pp_index points to the current place in the processed pattern, Cannot use the depth_line counter j for this because you will skip over places in the processed pattern. *********/ #include "cips.h" #define KONSTANT 2 #define PATTERN_START 0 #define PATTERN_END 255 #define ASCII_SIZE 256 #define TEST_NO_CHANGE #define DEBUG_MODE #undef COMMAND_LINE_MODE short the_image[ROWS][COLS]; void zero_line(); void initialize_pattern(); void lengthen_pattern(); void no_change(); void shorten_pattern(); void get_random_values(); void random_substitution(); void read_image_line(); void write_image_line(); void test_print_line(); main(argc, argv) char *argv[]; int argc; { char depth_file_name[MAX_NAME_LENGTH], s_file_name[MAX_NAME_LENGTH], pp_file_name[MAX_NAME_LENGTH], response[MAX_NAME_LENGTH]; FILE *depth_file, *processed_pattern_file, *stereo_file; int current_width, *depth_line, i, j, index, last_pixel, length, location, max_width, *pattern, pattern_index, pattern_width, pp_index, *processed_pattern, this_pixel, width; struct tiff_header_struct image_header; int line = 0; #ifdef COMMAND_LINE_MODE if(argc != 5){ printf( "\nusage: pstereo pattern-width " "\n depth-file-name " "stereo-file-name " "\n processed-pattern-file-name" "\n"); exit(1); } strcpy(depth_file_name, argv[2]); strcpy(s_file_name, argv[3]); strcpy(pp_file_name, argv[4]); if(does_not_exist(depth_file_name)){ printf("\nThe depth file %s does not exist", depth_file_name); exit(1); } read_tiff_header(depth_file_name, &image_header); round_off_image_size(&image_header, &length, &width); image_header.image_length = length*ROWS; image_header.image_width = width*COLS; create_allocate_tiff_file(pp_file_name, &image_header, the_image); create_allocate_tiff_file(s_file_name, &image_header, the_image); width = width*COLS; pattern_width = atoi(argv[1]); pattern = malloc(KONSTANT*width*sizeof(int)); depth_line = malloc(KONSTANT*width*sizeof(int)); processed_pattern = malloc(KONSTANT*width*sizeof(int)); #endif /* ifdef COMMAND_LINE_MODE */ #ifdef DEBUG_MODE strcpy(depth_file_name, "d:/src/dfile.tif"); strcpy(s_file_name, "d:/src/sfile.tif"); strcpy(pp_file_name, "d:/src/ppfile.tif"); if(does_not_exist(depth_file_name)){ printf("\nThe depth file %s does not exist", depth_file_name); exit(1); } read_tiff_header(depth_file_name, &image_header); round_off_image_size(&image_header, &length, &width); image_header.image_length = length*ROWS; image_header.image_width = width*COLS; create_allocate_tiff_file(pp_file_name, &image_header, the_image); create_allocate_tiff_file(s_file_name, &image_header, the_image); width = width*COLS; pattern_width = 10; pattern = malloc(KONSTANT*width*sizeof(int)); depth_line = malloc(KONSTANT*width*sizeof(int)); processed_pattern = malloc(KONSTANT*width*sizeof(int)); #endif /* ifdef COMMAND_LINE_MODE */ #ifdef DEBUG_MODE #endif /* ifdef DEBUG_MODE */ /*********************************************** * * This is the major loop of the program. * It reads one line at a time from the * depth file, processes that one line, * and writes the resulting pattern to the * processed pattern file. * ***********************************************/ for(i=0; i last_pixel) shorten_pattern( (this_pixel-last_pixel), pattern, &index, ¤t_width, &pattern_index, width); if(this_pixel < last_pixel) lengthen_pattern( (last_pixel-this_pixel), pattern, &index, ¤t_width, &pattern_index, &width, &max_width); /**************************************** * * Perform the no_change in every * pass. Do it after you have done * the shorten and lenghten pattern. * ****************************************/ no_change(pattern, processed_pattern, pp_index, &pattern_index, current_width, &index); pp_index++; if(pattern_index >= current_width) pattern_index = 0; last_pixel = depth_line[j]; } /* ends loop over j */ write_image_line(the_image, pp_file_name, i+1, processed_pattern, width); random_substitution(processed_pattern, width); write_image_line(the_image, s_file_name, i+1, processed_pattern, width); } /* ends the major loop */ free(pattern); free(depth_line); free(processed_pattern); return(111); } /* ends main */ /*********************************************** * * shorten_pattern(... * * This funtion shortens the pattern by * deleting an element from it. For example, * if the input pattern is abcdefg, * the output pattern could be abcfg. * ***********************************************/ void shorten_pattern(size, pattern, index, current_width, pattern_index, width) int *pattern; int size, *index, *current_width, *pattern_index, width; { int *temp_pattern; int i, new_index, new_width; temp_pattern = malloc(KONSTANT*width*sizeof(int)); for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *pattern_index = 0; free(temp_pattern); } /* ends shorten_pattern */ /*********************************************** * * initialize_pattern(... * * This function creates an initial pattern * that is as wide as the pattern_width * parameter. * ***********************************************/ void initialize_pattern(pattern_index, pattern, current_width, max_width, pattern_width, index) int pattern[]; int *pattern_index, *current_width, *max_width, *index, pattern_width; { int i; for(i=0; i= current_width) *pattern_index = 0; *index = *index + 1; if(*index >= current_width) *index = 0; } /* ends no_change */ /*********************************************** * * zero_line(... * * This function fills an int array with * zeros. * ***********************************************/ void zero_line(array, length) int *array; int length; { int i; for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *pattern_index = 0; *max_width = *max_width + size; free(temp_pattern); } /* ends lengthen_pattern */ /*********************************************** * * random_substitution(... * * This function takes the processed_pattern * array and substitutes random values for each * value in the array. * * Fill the substitution_values array with * random characters that are all printable * (PATTERN_START to PATTERN_END). * ***********************************************/ void random_substitution(processed_pattern, width) int *processed_pattern; int width; { int substitution_values[GRAY_LEVELS+1]; int i, place; get_random_values(substitution_values); for(i=0; i<(KONSTANT*width); i++){ place = processed_pattern[i]; processed_pattern[i] = substitution_values[place]; } /* ends loop over i */ } /* ends random_substitution */ /*********************************************** * * get_random_values(... * * This function fills array with random values. * The limit on the random values are from * PATTERN_START to PATTERN_END. * ***********************************************/ void get_random_values(array) int array[]; { int i, number; #ifdef NEVER these lines worked ok, they used all the printable characters from 0 through small z for(i=0; i 57 && number < 65) number = number + 7; array[i] = number; } /* ends loop over i */ #endif /* Let's try something different, only use the characters A-Z A-Z are 65-90 */ for(i=0; i width) le = width; } /* ends else */ } /* ends while still_reading */ } /* ends read_image_line */ /*********************************************** * * write_image_line(... * ***********************************************/ void write_image_line(the_image, file_name, line_number, array, width) char file_name[]; short the_image[ROWS][COLS]; int *array, line_number, width; { } /* ends write_image_line */ !@#$%^& &^%$#@! 4 Sun Mar 19 09:47:18 1995 Finished coding read_image_line, starting to test. !@#$%^& /*********************************************** * * file pstereo.c * * Functions: This file contains * main * zero_line * initialize_pattern * lengthen_pattern * no_change * shorten_pattern * get_random_values * random_substitution * read_image_line * write_image_line * test_print_line * * Purpose: * This file contains a program that will * make character based stereograms. * * External Calls: * tiff.c - read_tiff_header * ritff.c - read_tiff_image * wtiff.c - does_not_exist * round_off_image_size * create_allocate_tiff_file * * Modifications: * 18 March 1995 - created * *************************************************/ /***** ALGORITHM NOTES width is the width of the input and output lines pattern_width is the initial width of the pattern current_width is the current width of the pattern (this changes as elements are inserted into and deleted from the pattern). pattern[] must be wider than width and narrower than ? so I will try it at width=width depth_line[] will be width wide processed_pattern will be width wide pattern_index usually points to the end of the pattern index points to the current place in the pattern we are working on pp_index points to the current place in the processed pattern, Cannot use the depth_line counter j for this because you will skip over places in the processed pattern. *********/ #include "cips.h" #define KONSTANT 2 #define PATTERN_START 0 #define PATTERN_END 255 #define ASCII_SIZE 256 #define TEST_NO_CHANGE #undef DEBUG_MODE #define COMMAND_LINE_MODE short the_image[ROWS][COLS]; void zero_line(); void initialize_pattern(); void lengthen_pattern(); void no_change(); void shorten_pattern(); void get_random_values(); void random_substitution(); void read_image_line(); void write_image_line(); void test_print_line(); main(argc, argv) char *argv[]; int argc; { char depth_file_name[MAX_NAME_LENGTH], s_file_name[MAX_NAME_LENGTH], pp_file_name[MAX_NAME_LENGTH], response[MAX_NAME_LENGTH]; FILE *depth_file, *processed_pattern_file, *stereo_file; int current_width, *depth_line, i, j, index, last_pixel, length, location, max_width, *pattern, pattern_index, pattern_width, pp_index, *processed_pattern, this_pixel, width; struct tiff_header_struct image_header; int line = 0; #ifdef COMMAND_LINE_MODE if(argc != 5){ printf( "\nusage: pstereo pattern-width " "\n depth-file-name " "stereo-file-name " "\n processed-pattern-file-name" "\n"); exit(1); } strcpy(depth_file_name, argv[2]); strcpy(s_file_name, argv[3]); strcpy(pp_file_name, argv[4]); if(does_not_exist(depth_file_name)){ printf("\nThe depth file %s does not exist", depth_file_name); exit(1); } read_tiff_header(depth_file_name, &image_header); round_off_image_size(&image_header, &length, &width); image_header.image_length = length*ROWS; image_header.image_width = width*COLS; create_allocate_tiff_file(pp_file_name, &image_header, the_image); create_allocate_tiff_file(s_file_name, &image_header, the_image); width = width*COLS; pattern_width = atoi(argv[1]); pattern = malloc(KONSTANT*width*sizeof(int)); depth_line = malloc(KONSTANT*width*sizeof(int)); processed_pattern = malloc(KONSTANT*width*sizeof(int)); #endif /* ifdef COMMAND_LINE_MODE */ #ifdef DEBUG_MODE strcpy(depth_file_name, "d:\src\dfile.tif"); strcpy(s_file_name, "d:\src\sfile.tif"); strcpy(pp_file_name, "d:\src\ppfile.tif"); if(does_not_exist(depth_file_name)){ printf("\nThe depth file %s does not exist", depth_file_name); exit(1); } read_tiff_header(depth_file_name, &image_header); round_off_image_size(&image_header, &length, &width); image_header.image_length = length*ROWS; image_header.image_width = width*COLS; create_allocate_tiff_file(pp_file_name, &image_header, the_image); create_allocate_tiff_file(s_file_name, &image_header, the_image); width = width*COLS; pattern_width = 10; pattern = malloc(KONSTANT*width*sizeof(int)); depth_line = malloc(KONSTANT*width*sizeof(int)); processed_pattern = malloc(KONSTANT*width*sizeof(int)); #endif /* ifdef COMMAND_LINE_MODE */ #ifdef DEBUG_MODE #endif /* ifdef DEBUG_MODE */ /*********************************************** * * This is the major loop of the program. * It reads one line at a time from the * depth file, processes that one line, * and writes the resulting pattern to the * processed pattern file. * ***********************************************/ for(i=0; i last_pixel) shorten_pattern( (this_pixel-last_pixel), pattern, &index, ¤t_width, &pattern_index, width); if(this_pixel < last_pixel) lengthen_pattern( (last_pixel-this_pixel), pattern, &index, ¤t_width, &pattern_index, &width, &max_width); /**************************************** * * Perform the no_change in every * pass. Do it after you have done * the shorten and lenghten pattern. * ****************************************/ no_change(pattern, processed_pattern, pp_index, &pattern_index, current_width, &index); pp_index++; if(pattern_index >= current_width) pattern_index = 0; last_pixel = depth_line[j]; } /* ends loop over j */ write_image_line(the_image, pp_file_name, i+1, processed_pattern, width); random_substitution(processed_pattern, width); write_image_line(the_image, s_file_name, i+1, processed_pattern, width); } /* ends the major loop */ free(pattern); free(depth_line); free(processed_pattern); return(111); } /* ends main */ /*********************************************** * * shorten_pattern(... * * This funtion shortens the pattern by * deleting an element from it. For example, * if the input pattern is abcdefg, * the output pattern could be abcfg. * ***********************************************/ void shorten_pattern(size, pattern, index, current_width, pattern_index, width) int *pattern; int size, *index, *current_width, *pattern_index, width; { int *temp_pattern; int i, new_index, new_width; temp_pattern = malloc(KONSTANT*width*sizeof(int)); for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *pattern_index = 0; free(temp_pattern); } /* ends shorten_pattern */ /*********************************************** * * initialize_pattern(... * * This function creates an initial pattern * that is as wide as the pattern_width * parameter. * ***********************************************/ void initialize_pattern(pattern_index, pattern, current_width, max_width, pattern_width, index) int pattern[]; int *pattern_index, *current_width, *max_width, *index, pattern_width; { int i; for(i=0; i= current_width) *pattern_index = 0; *index = *index + 1; if(*index >= current_width) *index = 0; } /* ends no_change */ /*********************************************** * * zero_line(... * * This function fills an int array with * zeros. * ***********************************************/ void zero_line(array, length) int array[]; int length; { int i; for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *pattern_index = 0; *max_width = *max_width + size; free(temp_pattern); } /* ends lengthen_pattern */ /*********************************************** * * random_substitution(... * * This function takes the processed_pattern * array and substitutes random values for each * value in the array. * * Fill the substitution_values array with * random characters that are all printable * (PATTERN_START to PATTERN_END). * ***********************************************/ void random_substitution(processed_pattern, width) int *processed_pattern; int width; { int substitution_values[GRAY_LEVELS+1]; int i, place; get_random_values(substitution_values); for(i=0; i<(KONSTANT*width); i++){ place = processed_pattern[i]; processed_pattern[i] = substitution_values[place]; } /* ends loop over i */ } /* ends random_substitution */ /*********************************************** * * get_random_values(... * * This function fills array with random values. * The limit on the random values are from * PATTERN_START to PATTERN_END. * ***********************************************/ void get_random_values(array) int array[]; { int i, number; #ifdef NEVER these lines worked ok, they used all the printable characters from 0 through small z for(i=0; i 57 && number < 65) number = number + 7; array[i] = number; } /* ends loop over i */ #endif /* Let's try something different, only use the characters A-Z A-Z are 65-90 */ for(i=0; i last_pixel) shorten_pattern( (this_pixel-last_pixel), pattern, &index, ¤t_width, &pattern_index, width); if(this_pixel < last_pixel) lengthen_pattern( (last_pixel-this_pixel), pattern, &index, ¤t_width, &pattern_index, &width, &max_width); /**************************************** * * Perform the no_change in every * pass. Do it after you have done * the shorten and lenghten pattern. * ****************************************/ no_change(pattern, processed_pattern, pp_index, &pattern_index, current_width, &index); pp_index++; if(pattern_index >= current_width) pattern_index = 0; last_pixel = depth_line[j]; } /* ends loop over j */ write_image_line(the_image, pp_file_name, processed_pattern, width); random_substitution(processed_pattern, width); write_image_line(the_image, s_file_name, processed_pattern, width); } /* ends the major loop */ free(pattern); free(depth_line); free(processed_pattern); return(111); } /* ends main */ /*********************************************** * * shorten_pattern(... * * This funtion shortens the pattern by * deleting an element from it. For example, * if the input pattern is abcdefg, * the output pattern could be abcfg. * ***********************************************/ void shorten_pattern(size, pattern, index, current_width, pattern_index, width) int *pattern; int size, *index, *current_width, *pattern_index, width; { int *temp_pattern; int i, new_index, new_width; temp_pattern = malloc(KONSTANT*width*sizeof(int)); for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *pattern_index = 0; free(temp_pattern); } /* ends shorten_pattern */ /*********************************************** * * initialize_pattern(... * * This function creates an initial pattern * that is as wide as the pattern_width * parameter. * ***********************************************/ void initialize_pattern(pattern_index, pattern, current_width, max_width, pattern_width, index) int pattern[]; int *pattern_index, *current_width, *max_width, *index, pattern_width; { int i; for(i=0; i= current_width) *pattern_index = 0; *index = *index + 1; if(*index >= current_width) *index = 0; } /* ends no_change */ /*********************************************** * * zero_line(... * * This function fills an int array with * zeros. * ***********************************************/ void zero_line(array, length) int array[]; int length; { int i; for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *pattern_index = 0; *max_width = *max_width + size; free(temp_pattern); } /* ends lengthen_pattern */ /*********************************************** * * random_substitution(... * * This function takes the processed_pattern * array and substitutes random values for each * value in the array. * * Fill the substitution_values array with * random characters that are all printable * (PATTERN_START to PATTERN_END). * ***********************************************/ void random_substitution(processed_pattern, width) int *processed_pattern; int width; { int substitution_values[GRAY_LEVELS+1]; int i, place; get_random_values(substitution_values); for(i=0; i<(KONSTANT*width); i++){ place = processed_pattern[i]; processed_pattern[i] = substitution_values[place]; } /* ends loop over i */ } /* ends random_substitution */ /*********************************************** * * get_random_values(... * * This function fills array with random values. * The limit on the random values are from * PATTERN_START to PATTERN_END. * ***********************************************/ void get_random_values(array) int array[]; { int i, number; #ifdef NEVER these lines worked ok, they used all the printable characters from 0 through small z for(i=0; i 57 && number < 65) number = number + 7; array[i] = number; } /* ends loop over i */ #endif /* Let's try something different, only use the characters A-Z A-Z are 65-90 */ for(i=0; i last_character) shorten_pattern( (this_character-last_character), pattern, &index, ¤t_width, &pattern_index, width); if(this_character < last_character) lengthen_pattern( (last_character-this_character), pattern, &index, ¤t_width, &pattern_index, &width, &max_width); /**************************************** * * Perform the no_change in every * pass. Do it after you have done * the shorten and lenghten pattern. * ****************************************/ no_change(pattern, processed_pattern, pp_index, &pattern_index, current_width, &index); pp_index++; if(pattern_index >= current_width) pattern_index = 0; last_character = depth_line[j]; } /* ends loop over j */ pdest = strchr(processed_pattern, '\0'); location = pdest - processed_pattern; processed_pattern[location] = '\n'; fputs(processed_pattern, processed_pattern_file); random_substitution(processed_pattern, width); fputs(processed_pattern, stereo_file); } /* ends the major loop */ fclose(depth_file); fclose(processed_pattern_file); fclose(stereo_file); free(pattern); free(depth_line); free(processed_pattern); return(111); } /* ends main */ /*********************************************** * * shorten_pattern(... * * This funtion shortens the pattern by * deleting an element from it. For example, * if the input pattern is abcdefg, * the output pattern could be abcfg. * ***********************************************/ void shorten_pattern(size, pattern, index, current_width, pattern_index, width) char *pattern; int size, *index, *current_width, *pattern_index, width; { char *temp_pattern; int i, new_index, new_width; temp_pattern = malloc(KONSTANT*width); for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *pattern_index = 0; free(temp_pattern); } /* ends shorten_pattern */ /*********************************************** * * initialize_pattern(... * * This function creates an initial pattern * that is as wide as the pattern_width * parameter. * ***********************************************/ void initialize_pattern(pattern_index, pattern, current_width, max_width, pattern_width, index) char pattern[]; int *pattern_index, *current_width, *max_width, *index, pattern_width; { int i; for(i=0; i= current_width) *pattern_index = 0; *index = *index + 1; if(*index >= current_width) *index = 0; } /* ends no_change */ /*********************************************** * * fill_line(... * * This function fills a character line * with NULL characters. * ***********************************************/ void fill_line(line, length) char *line; int length; { int i; for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *pattern_index = 0; *max_width = *max_width + size; free(temp_pattern); } /* ends lengthen_pattern */ /*********************************************** * * random_substitution(... * * This function takes the processed_pattern * array and substitutes random values for each * value in the array. * * Fill the substitution_values array with * random characters that are all printable * (PATTERN_START to PATTERN_END). * ***********************************************/ void random_substitution(processed_pattern, width) char *processed_pattern; int width; { char substitution_values[ASCII_SIZE]; int i, place; get_random_values(substitution_values); for(i=0; i<(KONSTANT*width); i++){ if(processed_pattern[i] != '\n' && processed_pattern[i] != '\0'){ place = processed_pattern[i]; processed_pattern[i] = substitution_values[place]; } /* ends if */ } /* ends loop over i */ } /* ends random_substitution */ /*********************************************** * * get_random_values(... * * This function fills array with random values. * The limit on the random values are from * PATTERN_START to PATTERN_END. * ***********************************************/ void get_random_values(array) char array[]; { int i, number; #ifdef NEVER these lines worked ok, they used all the printable characters from 0 through small z for(i=0; i 57 && number < 65) number = number + 7; array[i] = number; } /* ends loop over i */ #endif /* Let's try something different, only use the characters A-Z A-Z are 65-90 */ for(i=0; i last_character) shorten_pattern( (this_character-last_character), pattern, &index, ¤t_width, &pattern_index, width); if(this_character < last_character) lengthen_pattern( (last_character-this_character), pattern, &index, ¤t_width, &pattern_index, &width, &max_width); /**************************************** * * Perform the no_change in every * pass. Do it after you have done * the shorten and lenghten pattern. * ****************************************/ no_change(pattern, processed_pattern, pp_index, &pattern_index, current_width, &index); pp_index++; if(pattern_index >= current_width) pattern_index = 0; last_character = depth_line[j]; } /* ends loop over j */ pdest = strchr(processed_pattern, '\0'); location = pdest - processed_pattern; processed_pattern[location] = '\n'; fputs(processed_pattern, processed_pattern_file); random_substitution(processed_pattern, width); fputs(processed_pattern, stereo_file); } /* ends the major loop */ fclose(depth_file); fclose(processed_pattern_file); fclose(stereo_file); free(pattern); free(depth_line); free(processed_pattern); return(111); } /* ends main */ /*********************************************** * * shorten_pattern(... * * This funtion shortens the pattern by * deleting an element from it. For example, * if the input pattern is abcdefg, * the output pattern could be abcfg. * ***********************************************/ void shorten_pattern(size, pattern, index, current_width, pattern_index, width) char *pattern; int size, *index, *current_width, *pattern_index, width; { char *temp_pattern; int i, new_index, new_width; temp_pattern = malloc(KONSTANT*width); for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *pattern_index = 0; free(temp_pattern); } /* ends shorten_pattern */ /*********************************************** * * initialize_pattern(... * * This function creates an initial pattern * that is as wide as the pattern_width * parameter. * ***********************************************/ void initialize_pattern(pattern_index, pattern, current_width, max_width, pattern_width, index) char pattern[]; int *pattern_index, *current_width, *max_width, *index, pattern_width; { int i; for(i=0; i= current_width) *pattern_index = 0; *index = *index + 1; if(*index >= current_width) *index = 0; } /* ends no_change */ /*********************************************** * * fill_line(... * * This function fills a character line * with NULL characters. * ***********************************************/ void fill_line(line, length) char *line; int length; { int i; for(i=0; i= *current_width) *index = 0; } /* ends loop over new_index */ *current_width = new_width; *pattern_index = 0; *max_width = *max_width + size; free(temp_pattern); } /* ends lengthen_pattern */ /*********************************************** * * random_substitution(... * * This function takes the processed_pattern * array and substitutes random values for each * value in the array. * * Fill the substitution_values array with * random characters that are all printable * (PATTERN_START to PATTERN_END). * ***********************************************/ void random_substitution(processed_pattern, width) char *processed_pattern; int width; { char substitution_values[ASCII_SIZE]; int i, place; get_random_values(substitution_values); for(i=0; i<(KONSTANT*width); i++){ if(processed_pattern[i] != '\n' && processed_pattern[i] != '\0'){ place = processed_pattern[i]; processed_pattern[i] = substitution_values[place]; } /* ends if */ } /* ends loop over i */ } /* ends random_substitution */ /*********************************************** * * get_random_values(... * * This function fills array with random values. * The limit on the random values are from * PATTERN_START to PATTERN_END. * ***********************************************/ void get_random_values(array) char array[]; { int i, number; #ifdef NEVER these lines worked ok, they used all the printable characters from 0 through small z for(i=0; i 57 && number < 65) number = number + 7; array[i] = number; } /* ends loop over i */ #endif /* Let's try something different, only use the characters A-Z A-Z are 65-90 */ for(i=0; i