📄 cips6.c
字号:
/***********************************************
*
* display_menu_for_display_image(
*
************************************************/
display_menu_for_display_image(image_colors,
display_colors,
invert, color_transform,
monitor_type,
show_hist)
char color_transform[], monitor_type[];
int *invert, *image_colors,
*display_colors, *show_hist;
{
char response[80];
int int_response, not_finished, r;
not_finished = 1;
while(not_finished){
printf("\n\nDISPLAY> Enter choice "
"(0 for no change) ");
printf("\nDISPLAY> 1. Invert is %d (1=on 0=off)",
*invert);
printf("\nDISPLAY> 2. Color Transform-- %s",
color_transform);
printf("\nDISPLAY> 3. Input image has %d colors",
*image_colors);
printf("\nDISPLAY> 4. Display will show %d colors",
*display_colors);
printf("\nDISPLAY> 5. Monitor type is %s",
monitor_type);
printf("\nDISPLAY> 6. Histogram is %d",
*show_hist);
printf(" (1=show 0=don't show)");
printf("\nDISPLAY> _\b");
get_integer(&r);
if(r == 0){
not_finished = 0;
}
if(r == 1){
printf("\nDISPLAY> Enter 1 for invert on");
printf(" 0 for invert off");
printf("\nDISPLAY> ___");
get_integer(&int_response);
*invert = int_response;
} /* ends if r == 1 */
if(r == 2){
printf("\nDISPLAY> Enter the new color "
"transform mode ");
printf("\nDISPLAY> (S) Straight mode");
printf(" (H) Histogram Equalization");
printf("\nDISPLAY> _\b");
gets(response);
if((response[0] == 'S') ||
(response[0] == 's'))
strcpy(color_transform,
"Straight mode");
else
strcpy(color_transform,
"Histogram Equalization mode");
} /* ends if r == 2 */
if(r == 3){
printf("\nDISPLAY> Enter the number "
"of colors");
printf(" in the input image");
printf("\nDISPLAY> ___");
get_integer(&int_response);
*image_colors = int_response;
} /* ends if r == 3 */
if(r == 4){
printf(
"\nDISPLAY> Enter the number of colors "
"for the display");
printf("\nDISPLAY> ___");
get_integer(&int_response);
*display_colors = int_response;
} /* ends if r == 4 */
if(r == 5){
printf("\nDISPLAY> Enter the new monitor type");
printf("\nDISPLAY> (E) EGA (V) VGA");
printf(" (C) CGA (M) Monochrome");
printf("\nDISPLAY> _\b");
gets(response);
if((response[0] == 'E') ||
(response[0] == 'e'))
strcpy(monitor_type, "EGA");
if((response[0] == 'V') ||
(response[0] == 'v'))
strcpy(monitor_type, "VGA");
if((response[0] == 'C') ||
(response[0] == 'c'))
strcpy(monitor_type, "CGA");
if((response[0] == 'M') ||
(response[0] == 'm'))
strcpy(monitor_type, "Monochrome");
} /* ends if r == 5 */
if(r == 6){
printf(
"\nDISPLAY> Enter 1 for show histogram "
"0 for don't");
printf("\nDISPLAY> ___");
get_integer(&int_response);
*show_hist = int_response;
} /* ends if r == 6 */
} /* ends while not_finished */
} /* ends display_menu */
/********************************
*
* display_image_portion(...
*
*********************************/
display_image_portion(image, x, y, display_colors,
image_colors, invert)
int invert, display_colors, image_colors;
short image[ROWS][COLS];
unsigned int x, y;
{
unsigned int color, i, j;
if(invert == 1){
for(i=0; i<ROWS; i++)
for(j=0; j<COLS; j++)
image[i][j] = (display_colors-1)
- image[i][j];
} /* ends if invert == 1 */
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
/* MSC 6.0 */
my_setcolor(image[i][j]);
my_setpixel(j+x, i+y);
/*****
my_set_pixel(j+x, i+y, image[i][j]);
******/
} /* ends loop over j */
} /* ends loop over i */
} /* ends display_image_portion */
/**********************************************
*
* map_16_shades_of_gray(...
*
* This function maps 16 shades of gray into
* the first 16 color indices. This allows
* you to display a true "black and white"
* image on a color monitor.
*
*********************************************/
map_16_shades_of_gray(display_mode)
int display_mode;
{
/* all MSC 6.0 statements */
my_setvideomode(display_mode);
my_remappalette(0, 0x000000L);
my_remappalette(1, 0x040404L);
my_remappalette(2, 0x080808L);
my_remappalette(3, 0x0c0c0cL);
my_remappalette(4, 0x101010L);
my_remappalette(5, 0x141414L);
my_remappalette(6, 0x181818L);
my_remappalette(7, 0x1c1c1cL);
my_remappalette(8, 0x202020L);
my_remappalette(9, 0x242424L);
my_remappalette(10, 0x282828L);
my_remappalette(11, 0x2c2c2cL);
my_remappalette(12, 0x303030L);
my_remappalette(13, 0x343434L);
my_remappalette(14, 0x383838L);
my_remappalette(15, 0x3f3f3fL);
}
/*********************************************
*
* transform_the_colors(...
*
* This function transforms the gray shades
* in the image array for display. It can either
* do it in straight mode by multiplying or
* dividing or it can do it with hist
* equalization by calling the function
* perform_histogram_equalization.
*
*************************************************/
transform_the_colors(image, color_transform,
display_colors, image_colors,
histogram, horizontal,
vertical)
char color_transform[];
int display_colors, horizontal,
image_colors, vertical;
short image[ROWS][COLS];
unsigned long histogram[];
{
int color, i, j;
float new_grays, area;
unsigned long x;
if(color_transform[0] == 'S'){
for(i=0; i<ROWS; i++){
for(j=0; j<COLS; j++){
if( (display_colors == 16) &&
(image_colors == 256))
color = image[i][j]/16;
if( (display_colors == 16) &&
(image_colors == 16))
color = image[i][j];
if( (display_colors == 256) &&
(image_colors == 256))
color = image[i][j];
if( (display_colors == 256) &&
(image_colors == 16))
color = image[i][j]*16;
image[i][j] = color;
} /* ends loop over j */
} /* ends loop over i */
} /* ends if transform is straight */
if(color_transform[0] == 'H'){
area = ((long)(vertical)) *
((long)(horizontal));
area = area*10000.0;
new_grays = display_colors;
perform_histogram_equalization(image, histogram,
new_grays, area);
} /* ends if transform is hist equalization */
} /* ends transform_the_colors */
/*************************************************
*
* file d:\cips\djet.c
*
* Functions: This file contains
* end_graphics_mode
* get_graphics_caption
* print_bytes
* print_graphics_image
* print_original_200_row
* select_300_dpi_resolution
* select_full_graphics_mode
* set_horizontal_offset
* set_raster_width
* start_raster_graphics
*
* Purpose:
* These functions print a 200x200 image using
* dithering to an HP DeskJet or compatable
* (Laserjet). This uses an 8x8 matrix which
* gives 64 shades of gray.
*
* External Calls:
* rtiff.c - read_tiff_image
* hist.c - zero_histogram
* calculate_histogram
* perform_histogram_equalization
*
*
* Modifications:
* January 1991 - created
* 25 August 1991 - modified for use in the
* C Image Processing System.
*
ZDDDDD? ZDDDDD?
3 3 3 3 The function print_graphics_image
3 3 3 3 begins with 2 100x100 image arrays
3 3 3 3
3 3 3 3
@DDDDDY @DDDDDY
ZDDDDDDDDDDDDDDD?
3 3 It joins them into
3 3 1 100x200 image array
3 3
3 3
@DDDDDDDDDDDDDDDY
ZDDDDDDDDDDDDDDD?
@DDDDDDDDDDDDDDDY
ZDDDDDDDDDDDDDDD?
@DDDDDDDDDDDDDDDY
. It loops and creates
. 100 200 element image arrays
.
ZDDDDDDDDDDDDDDD?
@DDDDDDDDDDDDDDDY
The function print_original_200_row
receives a 200 element array
ZBDDDDDDDDDDDDDDDDDDDDDDDDDDB?
@ADDDDDDDDDDDDDDDDDDDDDDDDDDAY
This array is transformed into a 8x200
array of characters called 'row'
ZDDDDDDDDD ... ~DDDDDDD?
CDDDDDDDDD ... ~DDDDDDD4
CDDDDDDDDD ... ~DDDDDDD4
CDDDDDDDDD ... ~DDDDDDD4
CDDDDDDDDD ... ~DDDDDDD4
CDDDDDDDDD ... ~DDDDDDD4
CDDDDDDDDD ... ~DDDDDDD4
CDDDDDDDDD ... ~DDDDDDD4
@DDDDDDDDD ... ~DDDDDDDY
Each column of this array is a 1x8 character
array which is an 8-bit x 8-bit array
IMM;
: :
HMM<
Each row of 'row' is passed to the funnction
print_bytes for graphics printing
***************************************************/
#define ESCAPE 27
#define FORMFEED '\014'
short r[200];
/*******************************************
*
* The patterns array holds the rows to the
* 8x8 matrices used for printing
* shades of gray.
*
********************************************/
char patterns[64][8] =
{ {255, 255, 255, 255, 255, 255, 255, 255},
{255, 255, 255, 255, 255, 255, 255, 127},
{255, 255, 255, 255, 255, 255, 255, 63},
{255, 255, 255, 255, 255, 255, 255, 31},
{255, 255, 255, 255, 255, 255, 255, 15},
{255, 255, 255, 255, 255, 255, 255, 7},
{255, 255, 255, 255, 255, 255, 255, 3},
{255, 255, 255, 255, 255, 255, 255, 1},
{255, 255, 255, 255, 255, 255, 255, 0},
{255, 255, 255, 255, 255, 255, 127, 0},
{255, 255, 255, 255, 255, 255, 63, 0},
{255, 255, 255, 255, 255, 255, 31, 0},
{255, 255, 255, 255, 255, 255, 15, 0},
{255, 255, 255, 255, 255, 255, 7, 0},
{255, 255, 255, 255, 255, 255, 3, 0},
{255, 255, 255, 255, 255, 255, 1, 0},
{255, 255, 255, 255, 255, 255, 0, 0},
{255, 255, 255, 255, 255, 127, 0, 0},
{255, 255, 255, 255, 255, 63, 0, 0},
{255, 255, 255, 255, 255, 31, 0, 0},
{255, 255, 255, 255, 255, 15, 0, 0},
{255, 255, 255, 255, 255, 7, 0, 0},
{255, 255, 255, 255, 255, 3, 0, 0},
{255, 255, 255, 255, 255, 1, 0, 0},
{255, 255, 255, 255, 255, 0, 0, 0},
{255, 255, 255, 255, 127, 0, 0, 0},
{255, 255, 255, 255, 63, 0, 0, 0},
{255, 255, 255, 255, 31, 0, 0, 0},
{255, 255, 255, 255, 15, 0, 0, 0},
{255, 255, 255, 255, 7, 0, 0, 0},
{255, 255, 255, 255, 3, 0, 0, 0},
{255, 255, 255, 255, 1, 0, 0, 0},
{255, 255, 255, 255, 0, 0, 0, 0},
{255, 255, 255, 127, 0, 0, 0, 0},
{255, 255, 255, 63, 0, 0, 0, 0},
{255, 255, 255, 31, 0, 0, 0, 0},
{255, 255, 255, 15, 0, 0, 0, 0},
{255, 255, 255, 7, 0, 0, 0, 0},
{255, 255, 255, 3, 0, 0, 0, 0},
{255, 255, 255, 1, 0, 0, 0, 0},
{255, 255, 255, 0, 0, 0, 0, 0},
{255, 255, 127, 0, 0, 0, 0, 0},
{255, 255, 63, 0, 0, 0, 0, 0},
{255, 255, 31, 0, 0, 0, 0, 0},
{255, 255, 15, 0, 0, 0, 0, 0},
{255, 255, 7, 0, 0, 0, 0, 0},
{255, 255, 3, 0, 0, 0, 0, 0},
{255, 255, 1, 0, 0, 0, 0, 0},
{255, 255, 0, 0, 0, 0, 0, 0},
{255, 127, 0, 0, 0, 0, 0, 0},
{255, 63, 0, 0, 0, 0, 0, 0},
{255, 31, 0, 0, 0, 0, 0, 0},
{255, 15, 0, 0, 0, 0, 0, 0},
{255, 7, 0, 0, 0, 0, 0, 0},
{255, 3, 0, 0, 0, 0, 0, 0},
{255, 1, 0, 0, 0, 0, 0, 0},
{255, 0, 0, 0, 0, 0, 0, 0},
{127, 0, 0, 0, 0, 0, 0, 0},
{ 63, 0, 0, 0, 0, 0, 0, 0},
{ 31, 0, 0, 0, 0, 0, 0, 0},
{ 15, 0, 0, 0, 0, 0, 0, 0},
{ 7, 0, 0, 0, 0, 0, 0, 0},
{ 3, 0, 0, 0, 0, 0, 0, 0},
{ 1, 0, 0, 0, 0, 0, 0, 0}};
/************************************************
*
* print_graphics_image(...
*
************************************************/
print_graphics_image(image1, image2, image_name,
il, ie, ll, le, image_colors,
invert, caption, show_hist,
color_transform)
char caption[], image_name[], color_transform[];
int image_colors, invert,
il, ie, ll, le, show_hist;
short image1[ROWS][COLS], image2[ROWS][COLS];
{
char c[80],
page[80];
FILE *printer;
int i,
j;
unsigned long histogram[256], final_hist[256];
printer = fopen("prn", "w");
/**********************************************
*
* Print a few blank lines on the page.
*
***********************************************/
strcpy(page, " \n");
fputs(page, printer);
fputs(page, printer);
/***********************************************
*
* Read in two image arrays.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -