/****************************************************************************** TITLE : Character Reading Routine Description : This subroutine is used to retrieve the handwritten data from the given character data file. Each 96 bytes or characters represents a handwritten character. These 96 bytes of character data are read in to a byte INPUT array. The data is then unpacked and placed in the FRMDCH two-dimensional array of framed character information. OUTPUT : FRMDCH A 32x24 array of integers containing bit framed character information. A 1 bit is considered to be a part of the character data. SYNOPSIS : The input is stored in a 96-byte array. The data is arranged so that there are 32 rows each of 24 pixels(B/W). Each 3 bytes of the input translates to 24 black/white data, as shown: Byte 1: 7 6 5 4 3 2 1 0 Byte 2: 7 6 5 4 3 2 1 0 Byte 3: 7 6 5 4 3 2 1 0 Byte 4: 7 6 5 4 3 2 1 0 Byte 5: 7 6 5 4 3 2 1 0 Byte 6: 7 6 5 4 3 2 1 0 . . . . . . . . . Byte30: 7 6 5 4 3 2 1 0 Byte31: 7 6 5 4 3 2 1 0 Byte32: 7 6 5 4 3 2 1 0 As can be seen, the left most (most significant) bit of these values is the left most pixel of the image. In this subroutine retrieval of each bit value, representing a pixel of the image, is done using bit operations available in C. Finally, the 96 byte input vector is converted to an 32x24 array of 1's and 0's. ******************************************************************************/ #include #include #include /* TEST PROGRAM: (Input file :zero) */ void main(void) { char Filein[100]; void Rdchar(char *); printf("Enter the input character file name (*.chr): "); scanf("%s",Filein); Rdchar(Filein); } void Rdchar(char *filein) { unsigned int FRMDCH[32][24]; unsigned char CHRA, CHRB; char fileout[100]; FILE *fin, *fout; unsigned char INPUT[3]; int i, j, k; // unsigned int IBYTE; // float ixx; int flag; unsigned int x, y, m, n; int M, N, p, q; unsigned char **RowImg; int **ImgMatx; printf("Enter output file name (*.txt): "); scanf("%s", fileout); printf("Enter the number of Rows and Columns (Max Rows = 25; Max Columns = 20): "); scanf("%d %d", &M, &N); fin = fopen(filein, "rb"); fout = fopen(fileout, "w"); RowImg = (unsigned char**)calloc(32, sizeof(unsigned char*)); for (i = 0;i<32;i++) RowImg[i] = (unsigned char*)calloc(24*N, sizeof(unsigned char)); ImgMatx = (int**)calloc(32*M, sizeof(int*)); for (i = 0; i < 32*M; i++) ImgMatx[i] = (int*)calloc(20*N, sizeof(int)); flag=1; while (!feof(fin)) { for (i=0;i>1; x= CHRA; y= CHRB; if (x==y) FRMDCH[n][m*8+k]=0; else FRMDCH[n][m*8+k]=1; CHRB = CHRB<<1; CHRA=CHRB; } } } for (p = 0;p<32;p++) for(q = 0;q<24;q++) RowImg[p][24*j+q] = FRMDCH[p][q]; } if (feof(fin)) break; for (p=0;p<32;p++) { for (q=0;q<24*N;q++) fprintf(fout,"%d",RowImg[p][q]); fprintf(fout,"\n"); } } if (feof(fin)) break; } fclose(fin); fclose(fout); // Sample code to read the character data into a matrix /* fin = fopen(fileout, "r"); while (!feof(fin)) { for (i = 0; i < 32*M; i++) for (j = 0; j < 20*N; j++) { fscanf(fin, "%c", &ImgMatx[i][j]); } } fclose(fin); fout = fopen("temp.txt", "w"); for (i = 0; i < 32*M; i++) for (j = 0; j < 20*N; j++) fprintf(fout, "%d", ImgMatx[i][j]); fclose(fout); */ }