/*************************************************************************** * Func: pattern * * * * Desc: halftones a gray-scale image via patterning and writes a pbm file * * * * Params: ptr - pointer to image in memory * * filename _ name of file to write image to * * rows - number of rows in the image * * cols - number of columns in the image * * * * Returns: nothing * ***************************************************************************/ void pattern(image_ptr image, char *filename, int rows, int cols) { FILE *fp; /* file pointer for output file */ unsigned long index; /* index to input image */ int row_size; /* size of row in bytes */ unsigned long i, j; /* index variable */ unsigned char *line1; /* first image output line */ unsigned char *line2; /* second image output line */ unsigned char *line3; /* third image output line */ unsigned char *line4; /* fourth image output line */ int even; /* LUT index of even pixel of pixel pair being processed */ int odd; /* LUT index of odd pixel of pixel pair being processed */ int last; /* LUT index for last pixel in an odd scanline */ /* The following declares the patterns. There are two declarations because in some cases, such as graphics displayed on a CRT, black = 0. In other cases, such as printing, black = 1. You will need to determine which declarations to comment out */ /* black bit = 0 */ unsigned char first_row[17] = { 0xf, 0x7, 0x7, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; unsigned char second_row[17] = {0xf, 0xf, 0xf, 0xf, 0xf, 0x7, 0x7, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x1, 0x1, 0x0, 0x0}; unsigned char third_row[17] = {0xf, 0xf, 0xd, 0xd, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x4, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0}; unsigned char fourth_row[17] = {0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xd, 0xd, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x4, 0x4, 0x0}; /* black bit = 1 */ /* unsigned char first_row[17] = { 0x0, 0x8, 0x8, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xe, 0xe, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf}; unsigned char second_row[17] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x8, 0x8, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xe, 0xe, 0xf, 0xf}; unsigned char third_row[17] = { 0x0, 0x0, 0x2, 0x2, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xb, 0xb, 0xf, 0xf, 0xf, 0xf, 0xf}; unsigned char fourth_row[17] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x2, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xb, 0xb, 0xf}; */ /* open new output file */ if((fp=fopen(filename, "wb")) == NULL) { printf("Unable to open %s for output\n",filename); exit(1); } /* print out the portable bitmap header */ fprintf(fp, "P4\n%d %d\n", cols*4, rows*4); row_size = (cols + 1) / 2; /* alocate memory for line buffers */ line1 = (unsigned char *) malloc(row_size); line2 = (unsigned char *) malloc(row_size); line3 = (unsigned char *) malloc(row_size); line4 = (unsigned char *) malloc(row_size); for(i=0; i