#include "d:\cips\cips.h" #define EIGHT '\010' #define ESCAPE 27 #define SIXTYFOUR 64 #define ONEHUNDRED 100 #define FORMFEED '\014' short image1[ROWS][COLS]; short image2[ROWS][COLS]; short r[200]; 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}}; main() { char caption[80], c[80], d[80], image_name[80], page[80], type[80]; FILE *printer; int i, invert, j, channel, il, ie, ll, le; unsigned long histogram[256], final_hist[256]; printer = fopen("prn", "w"); /************************************************ * * Print the page number and a few blank lines. * *************************************************/ select_proportional_font(printer); printf("\n\nEnter page number ---\b\b\b"); gets(page); strcpy(image_name, " "); my_fwriteln(printer, image_name); my_fwriteln(printer, image_name); my_fwriteln(printer, image_name); my_fwriteln(printer, image_name); my_fwriteln(printer, image_name); my_fwrite(printer, image_name); my_fwrite(printer, image_name); sprintf(image_name, " %s", page); my_fwriteln(printer, image_name); strcpy(image_name, " "); my_fwriteln(printer, image_name); my_fwriteln(printer, image_name); my_fwriteln(printer, image_name); my_fwriteln(printer, image_name); my_fwriteln(printer, image_name); /*************************************************** * * Get the following information: * . image name * . image parameters * . size of image * . type of image * ***************************************************/ strcpy(image_name, "d:/pix/philips.tif"); get_image_name(image_name); channel = 1; il = 1; ie = 1; ll = 100; le = 100; invert = 1; get_parameters(&il, &ie, &ll, &le); printf("\nEnter invert (1=on 0=off) -\b"); get_integer(&invert); printf("\n\nEnter the caption for the figure\n->"); gets(caption); printf("\n\nPrint a) 100x200 b) 200x200\n->"); gets(d); printf("\n\nPrint a) original image b) result image\n->"); gets(type); /***************************************************** * * Read in two image arrays and calculate histogram. * ******************************************************/ printf("\nReading image"); read_tiff_image(image_name, image1, il, ie, ll, le); ie = ie + 100; le = le + 100; printf("\nReading image"); read_tiff_image(image_name, image2, il, ie, ll, le); if(invert == 1){ for(i=0; i max) max = hist[i]; printf("\n\n\nmax is %d", max); if(max > 200){ for(i=0; i<64; i++){ hist[i] = hist[i]*200/max; printf("\nhist[i] = %d", hist[i]); } } /******************************** * * Second print it * *********************************/ for(i=0; i<64; i++){ printf("\n\t\thist row %d hist[i]=%d", i, hist[i]); /* print the line 8 times */ for(k=0; k<8; k++){ 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); /* this prints 200 bytes so print 200 */ putc(ESCAPE, printer); putc('*', printer); putc('b', printer); putc('2', printer); putc('0', printer); putc('0', printer); putc('W', printer); if(hist[i] >= 200) hist[i] = 200; limit = 200 - hist[i]; if(hist[i] == 0) putc(c, printer); for(j=0; j 63) value = 63; if(value < 0) value = 0; if(value < 32) value = 32 + (32-value) - 1; else if(value > 32) value = 32 - (value-32) - 1; for(j=0; j<8; j++){ row[j][i] = patterns[value][j]; } } 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 print_original_100_row */ print_result_100_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(short_row[i] == 41) value = 63; if(short_row[i] == 69) value = 20; if(short_row[i] == 97) value = 40; /***printf(" v=%d ", value);**/ for(j=0; j<8; j++){ row[j][i] = patterns[value][j]; } } for(i=0; i<8; i++){ for(j=0; j<200; j++){ c[j] = row[i][j]; /*printf(" c[%d]=%x ", j, c[j]);*/ } printf("\ncalling print bytes i=%d j=%d", i, j); set_horizontal_offset(printer); print_bytes(printer, c); } } /* ends print_result_100_row */ perform_histogram_equalization(image, histogram) short image[ROWS][COLS]; unsigned long histogram[]; { int area, i, j, k; unsigned long sum, sum_of_h[256]; double constant; sum = 0; for(i=0; i<256; i++){ sum = sum + histogram[i]; sum_of_h[i] = sum; } /* constant = new # of gray levels div by area */ constant = 64.0/20000.0; for(i=0; i