📄 cips6.c
字号:
fputc(ESCAPE, printer);
fputc('*', printer);
fputc('t', printer);
fputc('3', printer);
fputc('0', printer);
fputc('0', printer);
fputc('R', printer);
}
/************************************************
*
* print_bytes(...
*
************************************************/
print_bytes(printer, buffer)
FILE *printer;
char buffer[];
{
int i;
fputc(ESCAPE, printer);
fputc('*', printer);
fputc('b', printer);
fputc('2', printer);
fputc('0', printer);
fputc('0', printer);
fputc('W', printer);
for(i=0; i<200; i++){
fputc(buffer[i], printer);
}
} /* ends print_bytes */
/**************************************************
*
* print_original_200_row(...
*
***************************************************/
print_original_200_row(printer, short_row)
FILE *printer;
short short_row[200];
{
char row[8][200];
char c[200], response[80];
int i, j, k;
short value;
for(i=0; i<200; i++){
value = short_row[i];
if(value > 63) value = 63;
if(value < 0) value = 0;
for(j=0; j<8; j++)
row[j][i] = patterns[value][j];
} /* ends loop over i */
for(i=0; i<8; i++){
for(j=0; j<200; j++)
c[j] = row[i][j];
set_horizontal_offset(printer);
print_bytes(printer, c);
} /* ends loop over i */
} /* ends print_original_200_row */
/***********************************
*
* print_hist_image(...
*
************************************/
print_hist_image(printer, hist)
FILE *printer;
unsigned long hist[];
{
char c, d;
int i, j, k;
unsigned long limit, max;
d = 0;
c = 255;
/********************************
*
* First scale the histogram
*
*********************************/
max = 0;
for(i=0; i<256; i++)
if(hist[i] > max) max = hist[i];
if(max > 200){
for(i=0; i<256; i++){
hist[i] = (hist[i]*200)/max;
}
}
/********************************
*
* Second print it
*
* Print a space between the image
* and the histogram.
*
*********************************/
for(i=0; i<20; i++){
end_graphics_mode(printer);
select_300_dpi_resolution(printer);
set_raster_width(printer);
start_raster_graphics(printer);
select_full_graphics_mode(printer);
set_horizontal_offset(printer);
fputc(ESCAPE, printer);
fputc('*', printer);
fputc('b', printer);
fputc('2', printer);
fputc('0', printer);
fputc('0', printer);
fputc('W', printer);
for(j=0; j<200; j++)
fputc(d, printer);
}
printf("\n\nHIST> Now printing the histogram");
for(i=0; i<256; i++){
printf("\n\tHIST> Histogram[%d]=%ld",
i, hist[i]);
/* print the line 2 times */
for(k=0; k<2; k++){
end_graphics_mode(printer);
select_300_dpi_resolution(printer);
set_raster_width(printer);
start_raster_graphics(printer);
select_full_graphics_mode(printer);
/***************************
*
* Print grid marks every
* 50 pixels. Do this by
* setting a shorter margin
* then printing 2 marks then
* the data.
*
****************************/
if( (i == 0) ||
(i == 50) ||
(i == 100) ||
(i == 150) ||
(i == 200) ||
(i == 255)){
set_shorter_horizontal_offset(printer);
fputc(ESCAPE, printer);
fputc('*', printer);
fputc('b', printer);
fputc('2', printer);
fputc('0', printer);
fputc('2', printer);
fputc('W', printer);
fputc(c, printer);
fputc(c, printer);
if(hist[i] >= 200)
hist[i] = 200;
limit = 200 - hist[i];
if(hist[i] == 0)
fputc(c, printer);
for(j=0; j<hist[i]; j++)
fputc(c, printer);
for(j=0; j<limit; j++)
fputc(d, printer);
} /* ends print grid marks */
/***************************
*
* If you do not print
* grid marks, set the normal
* margin and then print the
* data.
*
****************************/
else{
set_horizontal_offset(printer);
/* this prints 200 bytes so print 200 */
fputc(ESCAPE, printer);
fputc('*', printer);
fputc('b', printer);
fputc('2', printer);
fputc('0', printer);
fputc('0', printer);
fputc('W', printer);
if(hist[i] >= 200)
hist[i] = 200;
limit = 200 - hist[i];
if(hist[i] == 0)
fputc(c, printer);
for(j=0; j<hist[i]; j++)
fputc(c, printer);
for(j=0; j<limit; j++)
fputc(d, printer);
} /* ends else no grid marks */
} /* ends loop over k */
} /* ends loop over i */
} /* ends print_hist_image */
/***********************************************
*
* file d:\cips\scale.c
*
* Functions: This file contains
* zoom_image_array
* shrink_image_array
* interpolate_pixel
* average_pixel
* median_pixel
* get_scaling_options
* blank_image_array
*
* Purpose:
* These functions implement image array
* zooming (enlarging) and shrinking.
*
* External Calls:
* wtiff.c - round_off_image_size
* create_file_if_needed
* write_array_into_tiff_image
* tiff.c - read_tiff_header
* rtiff.c - read_tiff_image
* numcvrt.c - get_integer
* filter.c - median_of
*
* Modifications:
* 8 April 1992 - created
*
*************************************************/
/*******************************************
*
* zoom_image_array(...
*
* This function zooms in on an input
* image array. It zooms by enlarging
* an input image array and writing the
* resulting image arrays to an output
* image file. It can zoom or enlarge by
* a factor of 2 or 4.
*
* You can zoom or enlarge an image array
* by using either the replication or
* interpolation methods.
*
*******************************************/
zoom_image_array(in_name, out_name, the_image, out_image,
il, ie, ll, le, scale, method)
char in_name[], out_name[], method[];
int il, ie, ll, le, scale;
short the_image[ROWS][COLS],
out_image[ROWS][COLS];
{
int A, B, a, b, count, factor,
i, j, length, width;
struct tiff_header_struct image_header;
/******************************************
*
* Check the scale factor. If it is not
* a valid factor (2 or 4), then set
* it to 2.
*
******************************************/
factor = scale;
if(factor != 2 &&
factor != 4) factor = 2;
create_file_if_needed(in_name, out_name, out_image);
/*******************************************
*
* Let me try to explain the nested loops
* shown below.
*
* We will enlarge the_image by the factor.
* Therefore, we want to divide the_image
* into parts of size ROWS/factor by
* COLS/factor. We will loop through
* the_image parts ROWS/factor and COLS/factor
* using the loops over i and j.
*
* We divided the_image into parts so we must
* include all of these parts. That is why we
* do the loops over A and B. There are
* factor*factor parts.
*
* Finally, we do the loops over a and b.
* We must replicate every element in the_image
* factor*factor times and put these into
* out_image. The a and b loops perform this
* task.
*
* The equations inside the []'s for
* the_image and out_image are also confusing.
* If you work them out, you'll see that we
* are bouncing through the image arrays
* and fitting the pixels into the right
* places.
*
* The final proof is that this works.
*
* One final note: the factor should divide
* evenly into ROWS. For example, ROWS=100
* so using a factor of 8 is not good.
* 100/8 = 12.5 and this leave you with
* an empty strip along the right and
* bottom edges of the out_image.
*
*******************************************/
/*****************************************
*
* Replication method
*
******************************************/
if(method[0] == 'r' || method[0] == 'R'){
read_tiff_image(in_name, the_image,
il, ie, ll, le);
count = 1;
for(A=0; A<factor; A++){
for(B=0; B<factor; B++){
for(i=0; i<ROWS/factor; i++){
for(j=0; j<COLS/factor; j++){
for(a=0; a<factor; a++){
for(b=0; b<factor; b++){
out_image[factor*i+a][factor*j+b] =
the_image[i+A*ROWS/factor][j+B*COLS/factor];
} /* ends loop over b */
} /* ends loop over a */
} /* ends loop over j */
} /* ends loop over i */
printf("\nzooming replication %3d of %3d",
count++, factor*factor);
write_array_into_tiff_image(out_name, out_image,
1+A*ROWS, 1+B*COLS, 101+A*ROWS, 101+B*COLS);
} /* ends loop over B */
} /* ends loop over A */
} /* ends replication method */
/***************************
*
* Interpolation method
*
****************************/
if(method[0] == 'i' || method[0] == 'I'){
read_tiff_image(in_name, the_image,
il, ie, ll, le);
count = 1;
for(A=0; A<factor; A++){
for(B=0; B<factor; B++){
for(i=0; i<ROWS/factor; i++){
for(j=0; j<COLS/factor; j++){
for(a=0; a<factor; a++){
for(b=0; b<factor; b++){
out_image[factor*i+a][factor*j+b] =
interpolate_pixel(the_image, A, B,
i, j, a, b, factor);
} /* ends loop over b */
} /* ends loop over a */
} /* ends loop over j */
} /* ends loop over i */
printf("\nzooming interpolation %3d of %3d",
count++, factor*factor);
write_array_into_tiff_image(out_name, out_image,
1+A*ROWS, 1+B*COLS,
101+A*ROWS, 101+B*COLS);
} /* ends loop over B */
} /* ends loop over A */
} /* ends interpolation method */
} /* ends zoom_image_array */
/***********************************************
*
* interpolate_pixel(...
*
* This function interpolates between pixel
* values and returns the interlopated value.
*
***********************************************/
interpolate_pixel(the_image, A, B, i, j, a, b, factor)
int A, B, a, b, factor, i, j;
short the_image[ROWS][COLS];
{
int num, x = 0, y = 0;
short diff, result;
if(a > 0) y = 1;
if(b > 0) x = 1;
diff =
the_image[y+i+A*ROWS/factor][x+j+B*COLS/factor] -
the_image[i+A*ROWS/factor][j+B*COLS/factor];
/******************************************
*
* If you are at the edge of the input image
* array, then you cannot interpolate to the
* next point because there is no next point.
* Therefore, set the diff to 0.
*
*******************************************/
if((y+i+A*ROWS/factor) >= ROWS) diff = 0;
if((x+j+B*COLS/factor) >= COLS) diff = 0;
num = a+b;
if(num > factor) num = factor;
result = the_image[i+A*ROWS/factor][j+B*COLS/factor] +
num*diff/factor;
return(result);
} /* ends interpolate_pixel */
/*******************************************
*
* shrin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -