-
Notifications
You must be signed in to change notification settings - Fork 0
/
Source.cpp
163 lines (140 loc) · 3.72 KB
/
Source.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include<cv.h>
#include<highgui.h>
#include"cxcore.h"
#define LCD_COLS 144
#define LCD_ROWS 168
#define LCD_BYTES_inLine 18
#define BINARY_THR 210
uchar arr[LCD_ROWS][LCD_BYTES_inLine]; //[168][18]
char eraseFileFlag= 0;
char fileNameString[10];
using namespace cv;
void makeArray(char *imgPtr)
{
int i,j,k;
uchar byteVal ;
uchar val;
for (i=0; i<LCD_ROWS; i++)
{
for(j=0; j<LCD_BYTES_inLine; j++)
{
byteVal = 0x00;
for (k=0;k<8;k++)
{
val = (uchar)*((i*LCD_BYTES_inLine*24)+imgPtr+(j*24)+(k*3));
val = (val > BINARY_THR) ? 1 : 0;
byteVal |= val << (7-k);
}
arr[i][j] = byteVal;
}
}
}
void MakeHeader(char *imgPtr,int Size)
{
FILE *fp;
int i;
uchar* arrPtr;
arrPtr = &arr[0][0] ;
makeArray(imgPtr);
if ((fp = fopen(fileNameString,"w")) == NULL)
printf("error openig file");
fprintf(fp,"\n/* AUTHOR : SANDEEP RAVI */\n");
fprintf(fp,"unsigned char ImageData[] = {\n");
fprintf(fp," 0x%x" ,*arrPtr);
for(i=2;i<(LCD_ROWS*LCD_BYTES_inLine);i++)
{
fprintf(fp,",0x%x" ,*(arrPtr+i));
if (!(i%18))
fprintf(fp,"\n");
}
fprintf(fp,"};\n");
fclose(fp);
}
void MakeSequenceHeader(char *imgPtr,int Size,int seqNo)
{
FILE *fp;
int i;
uchar* arrPtr;
arrPtr = &arr[0][0] ;
makeArray(imgPtr);
if (eraseFileFlag == 0)
{
if ((fp = fopen(fileNameString,"w")) == NULL) // to erase the contents of the file
printf("error openig file");
fclose(fp);
eraseFileFlag = 1;
}
if ((fp = fopen(fileNameString,"a")) == NULL)
printf("error openig file");
fprintf(fp,"\n/* AUTHOR : SANDEEP RAVI */\n");
fprintf(fp,"\n const unsigned char A%d[] = {\n",seqNo);
fprintf(fp," 0x%x" ,*arrPtr);
for(i=2;i<(LCD_ROWS*LCD_BYTES_inLine);i++)
{
fprintf(fp,",0x%x" ,*(arrPtr+i));
if (!(i%18))
fprintf(fp,"\n");
}
fprintf(fp,"};\n");
fclose(fp);
}
void main()
{
char choice;
char str[50],tempStr[20];
char str1[10];
char GenString[20];
int filename,noOfFiles;
int i,j;
char locationBackup[100]= "D:\\DispImages\\";
char location[100];
IplImage* newImage;
Mat A,B;
printf("************* WELCOME **************\n");
printf("Please Select your choice \n 1 -> Single image conversion \n 2 -> Image Sequence Conversion \n");
printf("Please Enter your Choice : ");
scanf("%c",&choice);
switch(choice)
{
case '1':
printf("\nPlease Enter filename with extension\n");
scanf("%s",&str);
printf("\nPlease enter name of the .h file :");
scanf("%s",&fileNameString);
strcat(location,str);
newImage = cvLoadImage(location,1);
if (!newImage)
printf("Error Opening Image");
cvNamedWindow("Main Image",1);
cvShowImage("Main Image",newImage);
MakeHeader(newImage->imageData,newImage->imageSize);
printf("Image Size is: %d", newImage->imageSize);
cvWaitKey(0);
cvDestroyWindow("Main Image");
cvReleaseImage(&newImage);
break;
case '2':
printf("\nPlease Enter the First .png filename without extension: ");
scanf("%s",&str1);
printf("\nEnter number of images: ");
scanf("%d",&noOfFiles);
printf("\nPlease enter name of the .h file :");
scanf("%s",&fileNameString);
filename = atoi(str1);
for(i=0;i<noOfFiles;i++)
{
sprintf(GenString,"Animate\\%d.png",filename+i);
strcpy(location,locationBackup);
strcat(location,GenString);
newImage = cvLoadImage(location,1);
if (!newImage)
printf("Error Opening Image %d",filename+i);
cvNamedWindow("Main Image",1);
cvShowImage("Main Image",newImage);
MakeSequenceHeader(newImage->imageData,newImage->imageSize,i);
cvDestroyWindow("Main Image");
cvReleaseImage(&newImage);
}
break;
}
}