📄 pstereo.c
字号:
int i;
for(i=0; i<pattern_width; i++)
pattern[i] = i+PATTERN_START;
*index = 0;
*current_width = pattern_width;
*max_width = pattern_width;
} /* ends initialize_pattern */
/***********************************************
*
* no_change(...
*
* This function processes the pattern
* and does not make any changes to it.
*
***********************************************/
void no_change(pattern, processed_pattern, pp_index,
current_width, index)
short *pattern, *processed_pattern;
int pp_index, current_width, *index;
{
processed_pattern[pp_index] =
pattern[*index];
*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)
short *array;
int length;
{
int i;
for(i=0; i<length; i++)
array[i] = 0;
} /* ends zero_line */
/***********************************************
*
* lengthen_pattern(...
*
* This funtion lengthens the pattern by
* inserting an element(s) into it. For example,
* if the input pattern is abcdefg,
* the output pattern could be abcdefgh.
*
***********************************************/
void lengthen_pattern(size, pattern, index,
current_width, width, max_width)
short *pattern;
int size, *index, *current_width,
*width, *max_width;
{
int *temp_pattern;
int count, i, new_index, new_width;
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<size;
count++, new_index++){
pattern[new_index] =
count + *max_width + PATTERN_START;
} /* ends loop over count */
new_width = *current_width + size;
for( ; new_index < new_width; new_index++){
pattern[new_index] = temp_pattern[*index];
*index = *index + 1;
if(*index >= *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)
short *processed_pattern;
int width;
{
int substitution_values[GRAY_LEVELS+1];
int i, place;
get_random_values(substitution_values);
for(i=0; i<(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<ASCII_SIZE; i++){
number = rand();
number = number % (PATTERN_END - PATTERN_START);
number = number + PATTERN_START;
array[i] = number;
} /* ends loop over i */
#endif
#ifdef NEVER
/* Let's try something different, only use the
characters 0-9 and A-Z
0-9 are 48-57 decimal A-Z are 65-90 */
for(i=0; i<ASCII_SIZE; i++){
number = rand();
number = number % 36;
number = number + PATTERN_START;
if(number > 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<GRAY_LEVELS+1; i++){
number = rand();
number = number % GRAY_LEVELS+1;
array[i] = number;
} /* ends loop over i */
#endif
/* Let's try something different, only use the
1's and 0's */
for(i=0; i<GRAY_LEVELS+1; i++){
number = rand();
number = number % 2;
if(number == 1) number = PATTERN_END;
array[i] = number;
} /* ends loop over i */
} /* ends get_random_values */
/***********************************************
*
* test_print_line(...
*
* This is a debug function that prints
* an array of integers.
*
***********************************************/
void test_print_line(line, width)
short *line;
int width;
{
int i;
for(i=0; i<width; i++)
printf("-%3d", line[i]);
printf("\n");
} /* ends test_print_line */
#ifdef NEVER
/***********************************************
*
* read_image_line(...
*
* This function reads a line of pixels from
* a TIFF image file.
*
***********************************************/
void read_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_read,
reading_counter,
still_reading;
il = line_number;
ll = il + 1;
ie = 1;
le = ie + COLS;
if(width < COLS)
le = ie + (width - 1);
pixels_to_read = width;
reading_counter = 0;
still_reading = 1;
while(still_reading){
read_tiff_image(file_name, the_image,
il, ie, ll, le);
for(i=0; i<(le-ie); i++)
array[i + (reading_counter*COLS)] =
the_image[0][i];
reading_counter++;
pixels_to_read = pixels_to_read - (le-ie);
if(pixels_to_read <= 1)
still_reading = 0;
else{
ie = ie + COLS;
le = ie + COLS;
if(le > 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 */
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -