pnlset2bin.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  1. #include <stdbool.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include "pnlset2bin.h"
  7. #define CustomerLOGO 1
  8. #define PanelSet_Header "PanelSet_Ascii_Version"
  9. #if 0
  10. static long filelength(FILE * pFile)
  11. {
  12. long ret;
  13. long oldpos;
  14. oldpos = ftell(pFile);
  15. fseek(pFile, 0, SEEK_END);
  16. ret = ftell(pFile);
  17. fseek(pFile, oldpos, SEEK_SET);
  18. return ret;
  19. }
  20. #endif
  21. uint StrToHexNumber(char* szText, uint* pNumber, uint nMax)
  22. {
  23. uint i,nValue= 0;
  24. i= 0;
  25. while( i<nMax )
  26. {
  27. if( szText[i] >='0' && szText[i]<= '9' )
  28. nValue= (nValue<<4) | (szText[i]-'0');
  29. else if( szText[i] >='a' && szText[i]<= 'f' )
  30. nValue= (nValue<<4) | (szText[i]-'a'+10);
  31. else if( szText[i] >='A' && szText[i]<= 'F' )
  32. nValue= (nValue<<4) | (szText[i]-'A'+10);
  33. else break;
  34. i++;
  35. }
  36. *pNumber= nValue;
  37. return i;
  38. }
  39. uint StrToDecimalNumber(char* szText, uint* pNumber, uint nMax)
  40. {
  41. uint i,nValue= 0;
  42. i= 0;
  43. while( i<nMax )
  44. {
  45. if( szText[i] >='0' && szText[i]<= '9' )
  46. nValue= (nValue*10) + (szText[i]-'0');
  47. else break;
  48. i++;
  49. }
  50. *pNumber= nValue;
  51. return i;
  52. }
  53. bool GetBit(const unsigned char pByte[], uint nBitIndex)
  54. {
  55. uint nQuot,nRem;
  56. nQuot= nBitIndex >> 3;
  57. nRem= nBitIndex & 0x7;
  58. return (pByte[nQuot] >> nRem) & 0x01;
  59. }
  60. uint GetBitData(const unsigned char pByte[], uint nBitIndex, uint nBitWidth)
  61. {
  62. uint i,nBit,nValue= 0;
  63. for(i=0; i<nBitWidth; i++)
  64. {
  65. nBit= GetBit(pByte, nBitIndex+i);
  66. nValue= (nBit<<i) | nValue;
  67. }
  68. return nValue;
  69. }
  70. void SetBit(unsigned char pByte[], uint nBitIndex, bool bValue)
  71. {
  72. uint nQuot,nRem;
  73. unsigned char nMask;
  74. nQuot= nBitIndex >> 3;
  75. nRem= nBitIndex & 0x7;
  76. nMask= (1 << nRem) & 0xff;
  77. if( bValue )
  78. {
  79. pByte[nQuot]|= nMask;
  80. }
  81. else
  82. {
  83. nMask= ~nMask;
  84. pByte[nQuot]&= nMask;
  85. }
  86. }
  87. void SetBitData(unsigned char pByte[], uint nBitIndex, uint nBitWidth, uint nData)
  88. {
  89. uint i;
  90. for(i=0; i<nBitWidth; i++)
  91. SetBit(pByte, nBitIndex+i, (nData>>i)&0x1);
  92. }
  93. void PrintUsage(void)
  94. {
  95. fprintf(stderr, "\n");
  96. fprintf(stderr, "pnlset2bin v0.01\n");
  97. fprintf(stderr, "Usage: pnlset2bin inputINIfile outputBINfile\n");
  98. fprintf(stderr, "Example: pnlset2bin panelset.ini panelset.bin\n");
  99. fprintf(stderr, "\n");
  100. }
  101. int cmN_getFileOneLineDataAscii(FILE *fpIn,char *pData, int maxLen)
  102. { //return is get len not add null
  103. int i;
  104. char line[maxLen];
  105. while(fgets(line, maxLen, fpIn)){
  106. if(strncmp(line, PanelSet_Header, strlen(PanelSet_Header)) == 0)
  107. break;
  108. }
  109. for(i=0; i<maxLen;i++)
  110. {
  111. if( i>= maxLen) //end size
  112. {
  113. return i; // not add null
  114. }
  115. if(line[i] == 0x0A )//line end ** OK
  116. {
  117. pData[i] = 0x00;
  118. return i;
  119. }
  120. if((isascii(line[i]))&&(!iscntrl(line[i])))
  121. {
  122. pData[i] = line[i];
  123. }
  124. else
  125. {
  126. pData[i] = 0x20;
  127. }
  128. }
  129. return 0; // fail
  130. }
  131. int cmN_getLineAsciiData_PanelSetVer2(char *pInData, char *pOutData, int Len)
  132. { //return is get len and add null
  133. int i, num, start;
  134. int headLen;
  135. headLen = (int)strlen(PANELSET_VERSION2_NAME_HEADER);
  136. if (!strncmp(PANELSET_VERSION2_NAME_HEADER,pInData, headLen))
  137. {
  138. num = 0;
  139. start = 0;
  140. for(i=headLen; i<Len;i++)
  141. {
  142. if(pInData[i] != 0x20)
  143. {
  144. start = i;
  145. break;
  146. }
  147. }
  148. if( (start == 0)||(i==Len) ) // empty give 0x20
  149. {
  150. pOutData[0] = 0x20;
  151. return 1;
  152. }
  153. for(i=start; i<Len;i++)
  154. {
  155. if((isascii(pInData[i]))&&(!iscntrl(pInData[i])))
  156. {
  157. pOutData[num] = pInData[i];
  158. }
  159. else
  160. {
  161. pOutData[num] = 0x20;
  162. }
  163. num ++;
  164. if(num >=PANELSET_VERSION2_NAME_MAX_LEN)
  165. {
  166. break;
  167. }
  168. }
  169. //move 0x20 at last
  170. for(i=(num - 1); i>= 0;i--)
  171. {
  172. if(pOutData[i] != 0x20)
  173. {
  174. if(i == 0)
  175. {
  176. return 1;//fix all is empty
  177. }
  178. else
  179. {
  180. return (i+1);
  181. }
  182. }
  183. }
  184. }
  185. else
  186. {
  187. return 0; // fail
  188. }
  189. return 0; // fail
  190. }
  191. #if 0
  192. DWORD ini2bin(char* pInFile, char *pOutFile)
  193. {
  194. FILE *InFile,*OutFile;
  195. DWORD isFill = TRUE, isAdd = TRUE; //for many VIP merge //add MMIO
  196. int i, len, tmp, mmioflag=0, optionflag=0;
  197. DWORD tempDW = 0;
  198. BRVIP_FLASH BrvipFlash;
  199. char ptr[0x100];
  200. unsigned int data,data1,data2,data3;
  201. unsigned long ULData[2000],ULSize;
  202. char pExist[PB_MAX_END];//for check only
  203. memset(pExist, 0, sizeof(char));
  204. InFile = fopen(pInFile,"r");
  205. if (InFile == NULL)
  206. {
  207. fprintf(stderr, "Can't open ini file\n");
  208. return FALSE;
  209. }
  210. if(isAdd == TRUE)
  211. {
  212. OutFile = fopen(pOutFile,"ab");
  213. }
  214. else
  215. {
  216. OutFile = fopen(pOutFile,"wb");
  217. }
  218. if (OutFile == NULL)
  219. {
  220. fclose(InFile);
  221. fprintf(stderr, "Can't open will write file\n");
  222. return FALSE;
  223. }
  224. int mergeToSize;//should "PANELSET SIZE" 2K, but boo t Rom give 8K So, Some where will add
  225. mergeToSize = PANELSET_SIZE; //--2k //; 0x2000=8k;//should "PANELSET SIZE" 2K, but boo t Rom give 8K So, Some where will add
  226. //---------- for isAdd fill to 8K
  227. if( (isFill == TRUE)&&(isAdd) )
  228. {
  229. DWORD fileLen, fillLen;
  230. fileLen = filelength(OutFile);
  231. if(fileLen % PANELSET_SIZE) //---by each size #1
  232. {
  233. if( PANELSET_SIZE > 0 )
  234. {
  235. int range = mergeToSize;// should "PANELSET SIZE" 2K, but boo t Rom give 8K So, Some where will add
  236. fillLen = range -(fileLen & (range-1));
  237. }
  238. else
  239. {
  240. fillLen = 0;
  241. }
  242. fseek( OutFile, 0, SEEK_END);
  243. for(i=0; i< fillLen ;i++)
  244. {
  245. fputc(0xFF,OutFile);
  246. }
  247. }
  248. //fclose(OutFile);
  249. }
  250. //----------
  251. //?? does need to init "BrvipFlash
  252. memset(&BrvipFlash, 0, sizeof(BRVIP_FLASH));//not init value is diff linux 0 windows CC
  253. //Reserve01 and Reserve02
  254. //----- ver =>
  255. tmp = 100;
  256. i = cmN_getFileOneLineDataAscii(InFile,ptr, tmp);
  257. len = cmN_getLineAsciiData_PanelSetVer2(ptr, ptr+tmp, i);
  258. memset(ptr, 0, PANELSET_VERSION2_NAME_MAX_LEN);
  259. memcpy(ptr , ptr+tmp, len);
  260. if(len == 0)
  261. {
  262. fclose(InFile);
  263. fclose(OutFile);
  264. fprintf(stderr, "Error ! \n First line must be PanelSet_Ascii_Version\n");
  265. return FALSE;
  266. }
  267. for(i=0; i< PANELSET_VERSION2_NAME_MAX_LEN;i++)
  268. {
  269. BrvipFlash.ScalerRegister.VersionOfAscii_20[i] = ptr[i];
  270. }
  271. //----- ver <=
  272. //start fill //source from Ics 172.18.252.142\sis1259\brvip\work\utility\utility.c+flash.h
  273. while (fscanf(InFile,"%s",ptr) != EOF) {
  274. if (!strcmp("[MMIO0]",ptr)) fgetpos(InFile, (fpos_t*)&mmioflag);
  275. if (0 != mmioflag && !optionflag)
  276. {
  277. if (0 == strstr(ptr, "OffsetLast0x14=")) continue;
  278. else
  279. {
  280. optionflag = 1;
  281. sscanf(ptr, "OffsetLast0x14=%d", (int*)&tempDW);
  282. }
  283. }
  284. if (EOF == fscanf(InFile," %x\n",&data)) break;
  285. if (!strcmp("PanelHorizontalEnd",ptr)) {
  286. BrvipFlash.PanelParameter.PanelHorizontalEnd = data;
  287. pExist[PB_PanelHorizontalEnd] = 1;
  288. } else if (!strcmp("PanelVerticalEnd",ptr)) {
  289. BrvipFlash.PanelParameter.PanelVerticalEnd = data;
  290. pExist[PB_PanelVerticalEnd] = 1;
  291. } else if (!strcmp("PanelHorizontalSyncStart",ptr)) {
  292. BrvipFlash.PanelParameter.PanelHorizontalSyncStart = (unsigned char)data;
  293. pExist[PB_PanelHorizontalSyncStart] = 1;
  294. } else if (!strcmp("PanelHorizontalSyncEnd",ptr)) {
  295. BrvipFlash.PanelParameter.PanelHorizontalSyncEnd = (unsigned char)data;
  296. pExist[PB_PanelHorizontalSyncEnd] = 1;
  297. } else if (!strcmp("PanelVerticalSyncStart",ptr)) {
  298. BrvipFlash.PanelParameter.PanelVerticalSyncStart = (unsigned char)data;
  299. pExist[PB_PanelVerticalSyncStart] = 1;
  300. } else if (!strcmp("PanelVerticalSyncEnd",ptr)) {
  301. BrvipFlash.PanelParameter.PanelVerticalSyncEnd = (unsigned char)data;
  302. pExist[PB_PanelVerticalSyncEnd] = 1;
  303. } else if (!strcmp("PanelVerticalMaxEnd",ptr)) {
  304. BrvipFlash.PanelParameter.PanelVerticalMaxEnd = (unsigned short)data;
  305. pExist[PB_PanelVerticalMaxEnd] = 1;
  306. } else if (!strcmp("PanelHorizontalDisplayStart",ptr)) {
  307. BrvipFlash.PanelParameter.PanelHorizontalDisplayStart = data;
  308. pExist[PB_PanelHorizontalDisplayStart] = 1;
  309. } else if (!strcmp("PanelVerticalDisplayStart",ptr)) {
  310. BrvipFlash.PanelParameter.PanelVerticalDisplayStart = data;
  311. pExist[PB_PanelVerticalDisplayStart] = 1;
  312. } else if (!strcmp("PanelHorizontalDisplayEnd",ptr)) {
  313. BrvipFlash.PanelParameter.PanelHorizontalDisplayEnd = data;
  314. pExist[PB_PanelHorizontalDisplayEnd] = 1;
  315. } else if (!strcmp("PanelVerticalDisplayEnd",ptr)) {
  316. BrvipFlash.PanelParameter.PanelVerticalDisplayEnd = data;
  317. pExist[PB_PanelVerticalDisplayEnd] = 1;
  318. } else if (!strcmp("PanelBlueOverScan",ptr)) {
  319. BrvipFlash.PanelParameter.PanelBlueOverScan = (unsigned char)data;
  320. pExist[PB_PanelBlueOverScan] = 1;
  321. } else if (!strcmp("PanelGreenOverScan",ptr)) {
  322. BrvipFlash.PanelParameter.PanelGreenOverScan = (unsigned char)data;
  323. pExist[PB_PanelGreenOverScan] = 1;
  324. } else if (!strcmp("PanelRedOverScan",ptr)) {
  325. BrvipFlash.PanelParameter.PanelRedOverScan = (unsigned char)data;
  326. pExist[PB_PanelRedOverScan] = 1;
  327. } else if (!strcmp("DpyHorizontalDisplayStart",ptr)) {
  328. BrvipFlash.DisplayPosition.DpyHorizontalDisplayStart = data;
  329. pExist[PB_DpyHorizontalDisplayStart] = 1;
  330. } else if (!strcmp("DpyVerticalDisplayStart",ptr)) {
  331. BrvipFlash.DisplayPosition.DpyVerticalDisplayStart = data;
  332. pExist[PB_DpyVerticalDisplayStart] = 1;
  333. } else if (!strcmp("DpyHorizontalDisplayEnd",ptr)) {
  334. BrvipFlash.DisplayPosition.DpyHorizontalDisplayEnd = data;
  335. pExist[PB_DpyHorizontalDisplayEnd] = 1;
  336. } else if (!strcmp("DpyVerticalDisplayEnd",ptr)) {
  337. BrvipFlash.DisplayPosition.DpyVerticalDisplayEnd = data;
  338. pExist[PB_DpyVerticalDisplayEnd] = 1;
  339. } else if (!strcmp("DpyOffset",ptr)) {
  340. BrvipFlash.DisplayPosition.DpyOffset = (unsigned char)data;
  341. pExist[PB_DpyOffset] = 1;
  342. } else if (!strcmp("DpySize",ptr)) {
  343. BrvipFlash.DisplayPosition.DpySize = (unsigned char)data;
  344. pExist[PB_DpySize] = 1;
  345. } else if (!strcmp("DpyLine",ptr)) {
  346. BrvipFlash.DisplayPosition.DpyLine = data;
  347. pExist[PB_DpyLine] = 1;
  348. } else if (!strcmp("Version",ptr)) {
  349. BrvipFlash.Version = data;
  350. pExist[PB_Version] = 1;
  351. } else if (!strcmp("DeviceID",ptr)) {
  352. BrvipFlash.DeviceID = (unsigned short)data;
  353. pExist[PB_DeviceID] = 1;
  354. } else if (!strcmp("VendorID",ptr)) {
  355. BrvipFlash.VendorID = (unsigned short)data;
  356. pExist[PB_VendorID] = 1;
  357. } else if (!strcmp("Dpy00",ptr)) {
  358. BrvipFlash.Dpy00 = data;
  359. pExist[PB_Dpy00] = 1;
  360. } else if (!strcmp("Dpy20",ptr)) {
  361. BrvipFlash.Dpy20 = data;
  362. pExist[PB_Dpy20] = 1;
  363. } else if (!strcmp("Before_MMIOAddress",ptr)) {
  364. BrvipFlash.Before_MMIOAddress = data;
  365. pExist[PB_Before_MMIOAddress] = 1;
  366. } else if (!strcmp("VIPAddress",ptr)) {
  367. BrvipFlash.VIPAddress = data;
  368. pExist[PB_VIPAddress] = 1;
  369. } else if (!strcmp("After_MMIOAddress",ptr)) {
  370. BrvipFlash.After_MMIOAddress = data;
  371. pExist[PB_After_MMIOAddress] = 1;
  372. } else if (!strcmp("SlrReset",ptr)) {;
  373. BrvipFlash.ScalerRegister.SlrReset = data;
  374. pExist[PB_SlrReset] = 1;
  375. } else if (!strcmp("SlrConfig",ptr)) {
  376. BrvipFlash.ScalerRegister.SlrConfig = data;
  377. pExist[PB_SlrConfig] = 1;
  378. } else if (!strcmp("SlrHorizontalFactor",ptr)) {
  379. BrvipFlash.ScalerRegister.SlrHorizontalFactor = data;
  380. pExist[PB_SlrHorizontalFactor] = 1;
  381. } else if (!strcmp("SlrVerticalFactor",ptr)) {
  382. BrvipFlash.ScalerRegister.SlrVerticalFactor = data;
  383. pExist[PB_SlrVerticalFactor] = 1;
  384. } else if (!strcmp("SlrVerticalDown",ptr)) {
  385. BrvipFlash.ScalerRegister.SlrVerticalDown = data;
  386. pExist[PB_SlrVerticalDown] = 1;
  387. }
  388. /* else if (!strcmp("SlrLeft",ptr)) {
  389. BrvipFlash.ScalerRegister.SlrLeft = data;
  390. pExist[PB_SlrLeft] = 1;
  391. } else if (!strcmp("SlrRight",ptr)) {
  392. BrvipFlash.ScalerRegister.SlrRight = data;
  393. pExist[PB_SlrRight] = 1;
  394. } else if (!strcmp("SlrLeft0",ptr)) {
  395. BrvipFlash.ScalerRegister.SlrLeft0 = data;
  396. pExist[PB_SlrLeft0] = 1;
  397. } else if (!strcmp("SlrRight0",ptr)) {
  398. BrvipFlash.ScalerRegister.SlrRight0 = data;
  399. pExist[PB_SlrRight0] = 1;
  400. } else if (!strcmp("SlrHorizontalFactor0",ptr)) {
  401. BrvipFlash.ScalerRegister.SlrHorizontalFactor0 = data;
  402. pExist[PB_SlrHorizontalFactor0] = 1;
  403. } */
  404. else if (!strcmp("SlrLine",ptr)) {
  405. BrvipFlash.ScalerRegister.SlrLine = data;
  406. pExist[PB_SlrLine] = 1;
  407. } else if (!strcmp("SlrInc",ptr)) {
  408. BrvipFlash.ScalerRegister.SlrInc = data;
  409. pExist[PB_SlrInc] = 1;
  410. } else if (!strcmp("Gpio_15",ptr)) {
  411. BrvipFlash.Gpio_15 = data;
  412. pExist[PB_Gpio_15] = 1;
  413. } else if (!strcmp("Gpio_16",ptr)) {
  414. BrvipFlash.Gpio_16 = data;
  415. pExist[PB_Gpio_16] = 1;
  416. }
  417. else if (!strcmp("PanelBackLight_GPIOPin",ptr)) {
  418. BrvipFlash.PanelBackLight_GPIOPin = (unsigned char)data;
  419. pExist[PB_PanelBackLight_GPIOPin] = 1;
  420. }
  421. else if (!strcmp("PanelPower_GPIOPin",ptr)) {
  422. BrvipFlash.PanelPower_GPIOPin = (unsigned char)data;
  423. pExist[PB_PanelPower_GPIOPin] = 1;
  424. }
  425. else if (!strcmp("PanelBackLight_ActiveValue",ptr)) {
  426. BrvipFlash.PanelBackLight_ActiveValue = (unsigned char)data;
  427. pExist[PB_PanelBackLight_ActiveValue] = 1;
  428. }
  429. else if (!strcmp("PanelPower_ActiveValue",ptr)) {
  430. BrvipFlash.PanelPower_ActiveValue = (unsigned char)data;
  431. pExist[PB_PanelPower_ActiveValue] = 1;
  432. }
  433. else if (!strcmp("LCDBackLightOrder",ptr)) {
  434. BrvipFlash.LCDBackLightOrder = (DWORD)data;
  435. pExist[PB_LCDBackLightOrder] = 1;
  436. }
  437. else if (!strcmp("LCDBackLight_OtherFrq",ptr)) {
  438. BrvipFlash.LCDBackLight_OtherFrq = (DWORD)data;
  439. pExist[PB_LCDBackLight_OtherFrq] = 1;
  440. }
  441. else if (!strcmp("LCDBackLightMap_00",ptr)) {
  442. BrvipFlash.LCDBackLightMap_00 = (DWORD)data;
  443. pExist[PB_LCDBackLightMap_00] = 1;
  444. }
  445. else if (!strcmp("LCDBackLightMap_01",ptr)) {
  446. BrvipFlash.LCDBackLightMap_01 = (DWORD)data;
  447. pExist[PB_LCDBackLightMap_01] = 1;
  448. }
  449. else if (!strcmp("LCDBackLightMap_02",ptr)) {
  450. BrvipFlash.LCDBackLightMap_02 = (DWORD)data;
  451. pExist[PB_LCDBackLightMap_02] = 1;
  452. }
  453. else if (!strcmp("LCDBackLightMap_03",ptr)) {
  454. BrvipFlash.LCDBackLightMap_03 = (DWORD)data;
  455. pExist[PB_LCDBackLightMap_03] = 1;
  456. }
  457. else if (!strcmp("LCDBackLightMap_04",ptr)) {
  458. BrvipFlash.LCDBackLightMap_04 = (DWORD)data;
  459. pExist[PB_LCDBackLightMap_04] = 1;
  460. }
  461. else if (!strcmp("LCDBackLightMap_05",ptr)) {
  462. BrvipFlash.LCDBackLightMap_05 = (DWORD)data;
  463. pExist[PB_LCDBackLightMap_05] = 1;
  464. }
  465. else if (!strcmp("LCDBackLightMap_06",ptr)) {
  466. BrvipFlash.LCDBackLightMap_06 = (DWORD)data;
  467. pExist[PB_LCDBackLightMap_06] = 1;
  468. }
  469. else if (!strcmp("LCDBackLightMap_07",ptr)) {
  470. BrvipFlash.LCDBackLightMap_07 = (DWORD)data;
  471. pExist[PB_LCDBackLightMap_07] = 1;
  472. }
  473. else if (!strcmp("LCDBackLightMap_08",ptr)) {
  474. BrvipFlash.LCDBackLightMap_08 = (DWORD)data;
  475. pExist[PB_LCDBackLightMap_08] = 1;
  476. }
  477. else if (!strcmp("LCDBackLightMap_09",ptr)) {
  478. BrvipFlash.LCDBackLightMap_09 = (DWORD)data;
  479. pExist[PB_LCDBackLightMap_09] = 1;
  480. }
  481. else if (!strcmp("LCDBackLightMap_10",ptr)) {
  482. BrvipFlash.LCDBackLightMap_10 = (DWORD)data;
  483. pExist[PB_LCDBackLightMap_10] = 1;
  484. }
  485. else if (!strcmp("LCDBackLightMap_11",ptr)) {
  486. BrvipFlash.LCDBackLightMap_11 = (DWORD)data;
  487. pExist[PB_LCDBackLightMap_11] = 1;
  488. }
  489. else if (!strcmp("LCDBackLightMap_12",ptr)) {
  490. BrvipFlash.LCDBackLightMap_12 = (DWORD)data;
  491. pExist[PB_LCDBackLightMap_12] = 1;
  492. }
  493. else if (!strcmp("LCDBackLightMap_13",ptr)) {
  494. BrvipFlash.LCDBackLightMap_13 = (DWORD)data;
  495. pExist[PB_LCDBackLightMap_13] = 1;
  496. }
  497. else if (!strcmp("LCDBackLightMap_14",ptr)) {
  498. BrvipFlash.LCDBackLightMap_14 = (DWORD)data;
  499. pExist[PB_LCDBackLightMap_14] = 1;
  500. }
  501. else if (!strcmp("LogoType",ptr)) {
  502. BrvipFlash.LogoType = (DWORD)data;
  503. pExist[PB_LogoType] = 1;
  504. }
  505. else if (!strcmp("LogoSize",ptr)) {
  506. BrvipFlash.LogoSize = (DWORD)data;
  507. pExist[PB_LogoSize] = 1;
  508. }
  509. else if (!strcmp("PanelBackLight_OffdelayTime",ptr)) {
  510. BrvipFlash.PanelBackLight_OffdelayTime = (DWORD)data;
  511. pExist[PB_PanelBackLight_OffdelayTime] = 1;
  512. }
  513. else if (!strcmp("PanelBackPower_OffdelayTime",ptr)) {
  514. BrvipFlash.PanelBackPower_OffdelayTime = (DWORD)data;
  515. pExist[PB_PanelBackPower_OffdelayTime] = 1;
  516. }
  517. }
  518. fseek(InFile, mmioflag, SEEK_SET);
  519. //BrvipFlash.Before_MMIOAddress = 0xbc0b0000+sizeof(BRVIP_FLASH); 07/03/02008 David.
  520. BrvipFlash.Before_MMIOAddress = BR_ADDR_VIP+sizeof(BRVIP_FLASH);
  521. BrvipFlash.After_MMIOAddress = BrvipFlash.Before_MMIOAddress;
  522. ULSize = 0;
  523. //fwrite(&BrvipFlash,sizeof(BRVIP_FLASH),1,OutFile);
  524. while (fscanf(InFile,"\n%x %x %x %x",&data,&data1,&data2,&data3) != EOF)
  525. {
  526. if ((data == 0xffffffff)||(data == 0x00000000))
  527. {
  528. break;
  529. }
  530. //fwrite(&data,4,1,OutFile);
  531. //fwrite(&data1,4,1,OutFile);
  532. //fwrite(&data2,4,1,OutFile);
  533. //fwrite(&data3,4,1,OutFile);
  534. //BrvipFlash.After_MMIOAddress += 0x10;
  535. ULData[ULSize] = data;
  536. ULData[ULSize+1] = data1;
  537. ULData[ULSize+2] = data2;
  538. ULData[ULSize+3] = data3;
  539. ULSize += 4;
  540. }
  541. data=0xffffffff;
  542. //fwrite(&data,4,1,OutFile);
  543. //fwrite(&data,4,1,OutFile);
  544. //fwrite(&data,4,1,OutFile);
  545. //fwrite(&data,4,1,OutFile);
  546. //BrvipFlash.After_MMIOAddress += 0x10;
  547. ULData[ULSize] = data;
  548. ULData[ULSize+1] = data;
  549. ULData[ULSize+2] = data;
  550. ULData[ULSize+3] = data;
  551. ULSize += 4;
  552. BrvipFlash.After_MMIOAddress += (ULSize*4);
  553. printf("Before_MMIOAddress %x\n",(unsigned int)BrvipFlash.Before_MMIOAddress);
  554. printf("ULSize %x\n",(unsigned int)ULSize);
  555. printf("After_MMIOAddress %x\n",(unsigned int)BrvipFlash.After_MMIOAddress);
  556. fwrite(&BrvipFlash,sizeof(BRVIP_FLASH),1,OutFile);
  557. fwrite(ULData,4*ULSize,1,OutFile);
  558. while (fscanf(InFile,"\n%x %x %x %x",&data,&data1,&data2,&data3) != EOF)
  559. {
  560. if ((data == 0xffffffff)||(data == 0x00000000))
  561. {
  562. break;
  563. }
  564. fwrite(&data,4,1,OutFile);
  565. fwrite(&data1,4,1,OutFile);
  566. fwrite(&data2,4,1,OutFile);
  567. fwrite(&data3,4,1,OutFile);
  568. }
  569. data=0xffffffff;
  570. fwrite(&data,4,1,OutFile);
  571. fwrite(&data,4,1,OutFile);
  572. fwrite(&data,4,1,OutFile);
  573. fwrite(&data,4,1,OutFile);
  574. #ifdef SET_338_VIP
  575. while (fscanf(InFile,"\n%x %x %x %x",&data,&data1,&data2,&data3) != EOF)
  576. {
  577. if ((data == 0xffffffff)||(data == 0x00000000))
  578. {
  579. break;
  580. }
  581. fwrite(&data,4,1,OutFile);
  582. fwrite(&data1,4,1,OutFile);
  583. fwrite(&data2,4,1,OutFile);
  584. fwrite(&data3,4,1,OutFile);
  585. }
  586. data=0xffffffff;
  587. fwrite(&data,4,1,OutFile);
  588. fwrite(&data,4,1,OutFile);
  589. fwrite(&data,4,1,OutFile);
  590. fwrite(&data,4,1,OutFile);
  591. #endif //SET_338_VIP
  592. fclose(InFile);
  593. //--------- Option
  594. if (optionflag)
  595. {
  596. if(PANELSET_SIZE != PANELSET_NOW_USE_FIX_SIZE)
  597. {
  598. fprintf(stderr, "Error! \nPanelSet Size change !\n Driver must update for this");
  599. fclose(OutFile);
  600. return FALSE;
  601. }
  602. DWORD fileLen, fillLen;
  603. fgetpos(OutFile,(fpos_t*)&fileLen);
  604. fileLen = fileLen % mergeToSize;
  605. if(fileLen >= (PANELSET_OPTION_D_OFFSET)) //0x7ec
  606. {
  607. fprintf(stderr, "Error! \nPanelSet Size change ! Over ox 7 e c\n Tool must update");
  608. fclose(OutFile);
  609. return FALSE;
  610. }
  611. fillLen = (PANELSET_OPTION_D_OFFSET - fileLen);
  612. if(PANELSET_OPTION_D_OFFSET < fileLen) //avoid
  613. {
  614. fillLen = 0;
  615. fprintf(stderr, "Error! \nPanelSet Error size \n Tool must update");
  616. }
  617. // OutFile = fopen(pOutFile,"ab");
  618. for(i=0; i< fillLen ;i++)
  619. {
  620. fputc(0xFF,OutFile);
  621. }
  622. fwrite(&tempDW,4,1,OutFile);
  623. }
  624. //---------
  625. fclose(OutFile);
  626. if(isFill == TRUE)
  627. {
  628. OutFile = fopen(pOutFile,"ab");
  629. if (OutFile == NULL)
  630. {
  631. fprintf(stderr, "Can't open will write2 file\n");
  632. return FALSE;
  633. }
  634. DWORD fileLen, fillLen;
  635. fileLen = filelength(OutFile);
  636. if(fileLen % PANELSET_SIZE) //---by each size #2
  637. {
  638. #ifdef FILL_MEM_BY_INI
  639. if( PANELSET_SIZE > 0 )
  640. {
  641. int range;
  642. if(isAdd)
  643. {
  644. range = mergeToSize;// should "PANELSET SIZE" 2K, but boo t Rom give 8K So, Some where will add
  645. }
  646. else
  647. {
  648. range = PANELSET_SIZE;// general case
  649. }
  650. fillLen = range -(fileLen & (range-1));
  651. }
  652. else
  653. fillLen = 0;
  654. #else
  655. fillLen = 0x1000 -(fileLen & 0x0fff);
  656. #endif //FILL_MEM_BY_INI
  657. fseek( OutFile, 0, SEEK_END);
  658. for(i=0; i< fillLen ;i++)
  659. {
  660. fputc(0xFF,OutFile);
  661. }
  662. }
  663. fclose(OutFile);
  664. }
  665. //check lost only
  666. for(i=0; i<PB_MAX_END ;i++)
  667. {
  668. if(pExist[i]!=1)
  669. {
  670. fprintf(stderr, "Error \n\n It must have lost data at No %d\n", i);
  671. return FALSE;
  672. }
  673. }
  674. return TRUE;
  675. }
  676. #endif
  677. #if 1
  678. char* fgetLine( char *s, int size, FILE *fpIn );
  679. /* return writed size, */
  680. int write_i2c_data_to_bin(FILE *fp, int fileoffset, char* output_mem, int mem_offset){
  681. // int i, length;
  682. char *line_buff, *outbuff, *ch_p;
  683. int tmp_data, outbuff_idx = 0,exit = 0;
  684. line_buff = malloc(256);
  685. if (line_buff == NULL)
  686. return -1;
  687. outbuff = malloc(1024);
  688. if (outbuff == NULL) {
  689. free(line_buff);
  690. return -1;
  691. }
  692. printf("i2c[%x]: \n", mem_offset );
  693. if (fseek(fp, fileoffset, SEEK_SET) < 0) {
  694. free(line_buff);
  695. free(outbuff);
  696. return -1;
  697. }
  698. //fgetLine(line_buff, 256, InFile);//bypasss [I2C]\n
  699. while(1){
  700. if(exit)
  701. break;
  702. if(fgetLine(line_buff, 256, fp) != (char *)NULL){
  703. //printf("i2c[%x]: %s\n", mem_offset,line_buff );
  704. ch_p = strtok (line_buff,", ");
  705. #if 0
  706. if(!strcmp("00",ch_p)){
  707. exit =1;
  708. }
  709. #endif
  710. while ((ch_p != NULL) && (exit == 0))
  711. {
  712. if(sscanf(ch_p, "%x", &tmp_data) <=0){
  713. exit =1;
  714. break;
  715. }
  716. //printf ("%x ",tmp_data);
  717. outbuff[outbuff_idx++] = (char)tmp_data;
  718. ch_p = strtok (NULL, ", ");
  719. }
  720. //printf ("\n");
  721. }
  722. }
  723. if(mem_offset + outbuff_idx > PANELSET_SIZE) {
  724. free(line_buff);
  725. free(outbuff);
  726. return -1;
  727. }
  728. memcpy(output_mem+mem_offset, outbuff, outbuff_idx);
  729. free(line_buff);
  730. free(outbuff);
  731. return outbuff_idx;
  732. }
  733. #endif
  734. /*
  735. return writed size if success
  736. else -1
  737. */
  738. int ini2binmem(char* pInFile, char *pOutData, int nBufSize)
  739. {
  740. FILE *InFile;
  741. int i, len, tmp, mmioflag=0; //, optionflag=0;
  742. int i2c0_fileoffset = 0, i2c1_fileoffset = 0;
  743. int writeOffset = 0;
  744. // DWORD tempDW = 0;
  745. BRVIP_FLASH BrvipFlash;
  746. char ptr[0x100];
  747. unsigned int data,data1,data2,data3;
  748. unsigned long ULData[2000],ULSize;
  749. char pExist[PB_MAX_END];//for check only
  750. memset(pExist, 0, sizeof(char));
  751. memset(pOutData, 0xFF, nBufSize);
  752. if (nBufSize < PANELSET_SIZE)
  753. {
  754. fprintf(stderr, "Out buffer is too small\n");
  755. return -1;
  756. }
  757. InFile = fopen(pInFile,"r");
  758. if (InFile == NULL)
  759. {
  760. fprintf(stderr, "Can't open ini file\n");
  761. return -1;
  762. }
  763. /*
  764. int mergeToSize;//should "PANELSET SIZE" 2K, but boo t Rom give 8K So, Some where will add
  765. mergeToSize = PANELSET_SIZE; //--2k //; 0x2000=8k;//should "PANELSET SIZE" 2K, but boo t Rom give 8K So, Some where will add
  766. */
  767. //?? does need to init "BrvipFlash
  768. memset(&BrvipFlash, 0, sizeof(BRVIP_FLASH));//not init value is diff linux 0 windows CC
  769. //Reserve01 and Reserve02
  770. //----- ver =>
  771. tmp = 100;
  772. i = cmN_getFileOneLineDataAscii(InFile,ptr, tmp);
  773. len = cmN_getLineAsciiData_PanelSetVer2(ptr, ptr+tmp, i);
  774. memset(ptr, 0, PANELSET_VERSION2_NAME_MAX_LEN);
  775. memcpy(ptr , ptr+tmp, len);
  776. if(len == 0)
  777. {
  778. fclose(InFile);
  779. fprintf(stderr, "Error ! \n First line must be PanelSet_Ascii_Version\n");
  780. return -1;
  781. }
  782. for(i=0; i< PANELSET_VERSION2_NAME_MAX_LEN;i++)
  783. {
  784. BrvipFlash.ScalerRegister.VersionOfAscii_20[i] = ptr[i];
  785. }
  786. //----- ver <=
  787. //start fill //source from Ics 172.18.252.142\sis1259\brvip\work\utility\utility.c+flash.h
  788. while (fscanf(InFile,"%s",ptr) != EOF) {
  789. if (!strcmp("[MMIO0]",ptr)) fgetpos(InFile, (fpos_t*)&mmioflag);
  790. if (!strcmp("[I2C0]",ptr)) fgetpos(InFile, (fpos_t*)&i2c0_fileoffset);
  791. if (!strcmp("[I2C1]",ptr)) fgetpos(InFile, (fpos_t*)&i2c1_fileoffset);
  792. #if 0 //gaia, 2013.05.02 ya! i don't know what is this..
  793. if (0 != mmioflag && !optionflag)
  794. {
  795. if (0 == strstr(ptr, "OffsetLast0x14=")) continue;
  796. else
  797. {
  798. optionflag = 1;
  799. sscanf(ptr, "OffsetLast0x14=%d", (int*)&tempDW);
  800. }
  801. }
  802. #endif
  803. if (EOF == fscanf(InFile," %x\n",&data)) break;
  804. if (!strcmp("PanelHorizontalEnd",ptr)) {
  805. BrvipFlash.PanelParameter.PanelHorizontalEnd = data;
  806. pExist[PB_PanelHorizontalEnd] = 1;
  807. } else if (!strcmp("PanelVerticalEnd",ptr)) {
  808. BrvipFlash.PanelParameter.PanelVerticalEnd = data;
  809. pExist[PB_PanelVerticalEnd] = 1;
  810. } else if (!strcmp("PanelHorizontalSyncStart",ptr)) {
  811. BrvipFlash.PanelParameter.PanelHorizontalSyncStart = (unsigned char)data;
  812. pExist[PB_PanelHorizontalSyncStart] = 1;
  813. } else if (!strcmp("PanelHorizontalSyncEnd",ptr)) {
  814. BrvipFlash.PanelParameter.PanelHorizontalSyncEnd = (unsigned char)data;
  815. pExist[PB_PanelHorizontalSyncEnd] = 1;
  816. } else if (!strcmp("PanelVerticalSyncStart",ptr)) {
  817. BrvipFlash.PanelParameter.PanelVerticalSyncStart = (unsigned char)data;
  818. pExist[PB_PanelVerticalSyncStart] = 1;
  819. } else if (!strcmp("PanelVerticalSyncEnd",ptr)) {
  820. BrvipFlash.PanelParameter.PanelVerticalSyncEnd = (unsigned char)data;
  821. pExist[PB_PanelVerticalSyncEnd] = 1;
  822. } else if (!strcmp("PanelVerticalMaxEnd",ptr)) {
  823. BrvipFlash.PanelParameter.PanelVerticalMaxEnd = (unsigned short)data;
  824. pExist[PB_PanelVerticalMaxEnd] = 1;
  825. } else if (!strcmp("PanelHorizontalDisplayStart",ptr)) {
  826. BrvipFlash.PanelParameter.PanelHorizontalDisplayStart = data;
  827. pExist[PB_PanelHorizontalDisplayStart] = 1;
  828. } else if (!strcmp("PanelVerticalDisplayStart",ptr)) {
  829. BrvipFlash.PanelParameter.PanelVerticalDisplayStart = data;
  830. pExist[PB_PanelVerticalDisplayStart] = 1;
  831. } else if (!strcmp("PanelHorizontalDisplayEnd",ptr)) {
  832. BrvipFlash.PanelParameter.PanelHorizontalDisplayEnd = data;
  833. pExist[PB_PanelHorizontalDisplayEnd] = 1;
  834. } else if (!strcmp("PanelVerticalDisplayEnd",ptr)) {
  835. BrvipFlash.PanelParameter.PanelVerticalDisplayEnd = data;
  836. pExist[PB_PanelVerticalDisplayEnd] = 1;
  837. } else if (!strcmp("PanelBlueOverScan",ptr)) {
  838. BrvipFlash.PanelParameter.PanelBlueOverScan = (unsigned char)data;
  839. pExist[PB_PanelBlueOverScan] = 1;
  840. } else if (!strcmp("PanelGreenOverScan",ptr)) {
  841. BrvipFlash.PanelParameter.PanelGreenOverScan = (unsigned char)data;
  842. pExist[PB_PanelGreenOverScan] = 1;
  843. } else if (!strcmp("PanelRedOverScan",ptr)) {
  844. BrvipFlash.PanelParameter.PanelRedOverScan = (unsigned char)data;
  845. pExist[PB_PanelRedOverScan] = 1;
  846. } else if (!strcmp("DpyHorizontalDisplayStart",ptr)) {
  847. BrvipFlash.DisplayPosition.DpyHorizontalDisplayStart = data;
  848. pExist[PB_DpyHorizontalDisplayStart] = 1;
  849. } else if (!strcmp("DpyVerticalDisplayStart",ptr)) {
  850. BrvipFlash.DisplayPosition.DpyVerticalDisplayStart = data;
  851. pExist[PB_DpyVerticalDisplayStart] = 1;
  852. } else if (!strcmp("DpyHorizontalDisplayEnd",ptr)) {
  853. BrvipFlash.DisplayPosition.DpyHorizontalDisplayEnd = data;
  854. pExist[PB_DpyHorizontalDisplayEnd] = 1;
  855. } else if (!strcmp("DpyVerticalDisplayEnd",ptr)) {
  856. BrvipFlash.DisplayPosition.DpyVerticalDisplayEnd = data;
  857. pExist[PB_DpyVerticalDisplayEnd] = 1;
  858. } else if (!strcmp("DpyOffset",ptr)) {
  859. BrvipFlash.DisplayPosition.DpyOffset = (unsigned short)data;
  860. pExist[PB_DpyOffset] = 1;
  861. } else if (!strcmp("DpySize",ptr)) {
  862. BrvipFlash.DisplayPosition.DpySize = (unsigned short)data;
  863. pExist[PB_DpySize] = 1;
  864. } else if (!strcmp("DpyLine",ptr)) {
  865. BrvipFlash.DisplayPosition.DpyLine = data;
  866. pExist[PB_DpyLine] = 1;
  867. } else if (!strcmp("Version",ptr)) {
  868. BrvipFlash.Version = data;
  869. pExist[PB_Version] = 1;
  870. } else if (!strcmp("DeviceID",ptr)) {
  871. BrvipFlash.DeviceID = (unsigned short)data;
  872. pExist[PB_DeviceID] = 1;
  873. } else if (!strcmp("VendorID",ptr)) {
  874. BrvipFlash.VendorID = (unsigned short)data;
  875. pExist[PB_VendorID] = 1;
  876. } else if (!strcmp("Dpy00",ptr)) {
  877. BrvipFlash.Dpy00 = data;
  878. pExist[PB_Dpy00] = 1;
  879. } else if (!strcmp("Dpy20",ptr)) {
  880. BrvipFlash.Dpy20 = data;
  881. pExist[PB_Dpy20] = 1;
  882. } else if (!strcmp("Before_MMIOAddress",ptr)) {
  883. BrvipFlash.Before_MMIOAddress = data;
  884. pExist[PB_Before_MMIOAddress] = 1;
  885. } else if (!strcmp("VIPAddress",ptr)) {
  886. BrvipFlash.VIPAddress = data;
  887. pExist[PB_VIPAddress] = 1;
  888. } else if (!strcmp("After_MMIOAddress",ptr)) {
  889. BrvipFlash.After_MMIOAddress = data;
  890. pExist[PB_After_MMIOAddress] = 1;
  891. } else if (!strcmp("SlrReset",ptr)) {;
  892. BrvipFlash.ScalerRegister.SlrReset = data;
  893. pExist[PB_SlrReset] = 1;
  894. } else if (!strcmp("SlrConfig",ptr)) {
  895. BrvipFlash.ScalerRegister.SlrConfig = data;
  896. pExist[PB_SlrConfig] = 1;
  897. } else if (!strcmp("SlrHorizontalFactor",ptr)) {
  898. BrvipFlash.ScalerRegister.SlrHorizontalFactor = data;
  899. pExist[PB_SlrHorizontalFactor] = 1;
  900. } else if (!strcmp("SlrVerticalFactor",ptr)) {
  901. BrvipFlash.ScalerRegister.SlrVerticalFactor = data;
  902. pExist[PB_SlrVerticalFactor] = 1;
  903. } else if (!strcmp("SlrVerticalDown",ptr)) {
  904. BrvipFlash.ScalerRegister.SlrVerticalDown = data;
  905. pExist[PB_SlrVerticalDown] = 1;
  906. }
  907. /* else if (!strcmp("SlrLeft",ptr)) {
  908. BrvipFlash.ScalerRegister.SlrLeft = data;
  909. pExist[PB_SlrLeft] = 1;
  910. } else if (!strcmp("SlrRight",ptr)) {
  911. BrvipFlash.ScalerRegister.SlrRight = data;
  912. pExist[PB_SlrRight] = 1;
  913. } else if (!strcmp("SlrLeft0",ptr)) {
  914. BrvipFlash.ScalerRegister.SlrLeft0 = data;
  915. pExist[PB_SlrLeft0] = 1;
  916. } else if (!strcmp("SlrRight0",ptr)) {
  917. BrvipFlash.ScalerRegister.SlrRight0 = data;
  918. pExist[PB_SlrRight0] = 1;
  919. } else if (!strcmp("SlrHorizontalFactor0",ptr)) {
  920. BrvipFlash.ScalerRegister.SlrHorizontalFactor0 = data;
  921. pExist[PB_SlrHorizontalFactor0] = 1;
  922. } */
  923. else if (!strcmp("SlrLine",ptr)) {
  924. BrvipFlash.ScalerRegister.SlrLine = data;
  925. pExist[PB_SlrLine] = 1;
  926. } else if (!strcmp("SlrInc",ptr)) {
  927. BrvipFlash.ScalerRegister.SlrInc = data;
  928. pExist[PB_SlrInc] = 1;
  929. }
  930. #if 0
  931. else if (!strcmp("Gpio_15",ptr)) {
  932. BrvipFlash.Gpio_15 = data;
  933. pExist[PB_Gpio_15] = 1;
  934. } else if (!strcmp("Gpio_16",ptr)) {
  935. BrvipFlash.Gpio_16 = data;
  936. pExist[PB_Gpio_16] = 1;
  937. }
  938. #else
  939. else if (!strcmp("PanelBackLight_GPIOmode",ptr)) {
  940. BrvipFlash.PanelBackLight_GPIOPin = (unsigned char)data;
  941. //pExist[PB_PanelBackLight_GPIOmode] = 1;
  942. }
  943. else if (!strcmp("PanelPower_GPIOmode",ptr)) {
  944. BrvipFlash.PanelPower_GPIOPin = (unsigned char)data;
  945. //pExist[PB_PanelPower_GPIOmode] = 1;
  946. }
  947. #endif
  948. else if (!strcmp("PanelBackLight_GPIOPin",ptr)) {
  949. BrvipFlash.PanelBackLight_GPIOPin = (unsigned char)data;
  950. pExist[PB_PanelBackLight_GPIOPin] = 1;
  951. }
  952. else if (!strcmp("PanelPower_GPIOPin",ptr)) {
  953. BrvipFlash.PanelPower_GPIOPin = (unsigned char)data;
  954. pExist[PB_PanelPower_GPIOPin] = 1;
  955. }
  956. else if (!strcmp("PanelBackLight_ActiveValue",ptr)) {
  957. BrvipFlash.PanelBackLight_ActiveValue = (unsigned char)data;
  958. pExist[PB_PanelBackLight_ActiveValue] = 1;
  959. }
  960. else if (!strcmp("PanelPower_ActiveValue",ptr)) {
  961. BrvipFlash.PanelPower_ActiveValue = (unsigned char)data;
  962. pExist[PB_PanelPower_ActiveValue] = 1;
  963. }
  964. else if (!strcmp("LCDBackLightOrder",ptr)) {
  965. BrvipFlash.LCDBackLightOrder = (DWORD)data;
  966. pExist[PB_LCDBackLightOrder] = 1;
  967. }
  968. else if (!strcmp("LCDBackLight_OtherFrq",ptr)) {
  969. BrvipFlash.LCDBackLight_OtherFrq = (DWORD)data;
  970. pExist[PB_LCDBackLight_OtherFrq] = 1;
  971. }
  972. else if (!strcmp("LCDBackLightMap_00",ptr)) {
  973. BrvipFlash.LCDBackLightMap_00 = (DWORD)data;
  974. pExist[PB_LCDBackLightMap_00] = 1;
  975. }
  976. else if (!strcmp("LCDBackLightMap_01",ptr)) {
  977. BrvipFlash.LCDBackLightMap_01 = (DWORD)data;
  978. pExist[PB_LCDBackLightMap_01] = 1;
  979. }
  980. else if (!strcmp("LCDBackLightMap_02",ptr)) {
  981. BrvipFlash.LCDBackLightMap_02 = (DWORD)data;
  982. pExist[PB_LCDBackLightMap_02] = 1;
  983. }
  984. else if (!strcmp("LCDBackLightMap_03",ptr)) {
  985. BrvipFlash.LCDBackLightMap_03 = (DWORD)data;
  986. pExist[PB_LCDBackLightMap_03] = 1;
  987. }
  988. else if (!strcmp("LCDBackLightMap_04",ptr)) {
  989. BrvipFlash.LCDBackLightMap_04 = (DWORD)data;
  990. pExist[PB_LCDBackLightMap_04] = 1;
  991. }
  992. else if (!strcmp("LCDBackLightMap_05",ptr)) {
  993. BrvipFlash.LCDBackLightMap_05 = (DWORD)data;
  994. pExist[PB_LCDBackLightMap_05] = 1;
  995. }
  996. else if (!strcmp("LCDBackLightMap_06",ptr)) {
  997. BrvipFlash.LCDBackLightMap_06 = (DWORD)data;
  998. pExist[PB_LCDBackLightMap_06] = 1;
  999. }
  1000. else if (!strcmp("LCDBackLightMap_07",ptr)) {
  1001. BrvipFlash.LCDBackLightMap_07 = (DWORD)data;
  1002. pExist[PB_LCDBackLightMap_07] = 1;
  1003. }
  1004. else if (!strcmp("LCDBackLightMap_08",ptr)) {
  1005. BrvipFlash.LCDBackLightMap_08 = (DWORD)data;
  1006. pExist[PB_LCDBackLightMap_08] = 1;
  1007. }
  1008. else if (!strcmp("LCDBackLightMap_09",ptr)) {
  1009. BrvipFlash.LCDBackLightMap_09 = (DWORD)data;
  1010. pExist[PB_LCDBackLightMap_09] = 1;
  1011. }
  1012. else if (!strcmp("LCDBackLightMap_10",ptr)) {
  1013. BrvipFlash.LCDBackLightMap_10 = (DWORD)data;
  1014. pExist[PB_LCDBackLightMap_10] = 1;
  1015. }
  1016. else if (!strcmp("LCDBackLightMap_11",ptr)) {
  1017. BrvipFlash.LCDBackLightMap_11 = (DWORD)data;
  1018. pExist[PB_LCDBackLightMap_11] = 1;
  1019. }
  1020. else if (!strcmp("LCDBackLightMap_12",ptr)) {
  1021. BrvipFlash.LCDBackLightMap_12 = (DWORD)data;
  1022. pExist[PB_LCDBackLightMap_12] = 1;
  1023. }
  1024. else if (!strcmp("LCDBackLightMap_13",ptr)) {
  1025. BrvipFlash.LCDBackLightMap_13 = (DWORD)data;
  1026. pExist[PB_LCDBackLightMap_13] = 1;
  1027. }
  1028. else if (!strcmp("LCDBackLightMap_14",ptr)) {
  1029. BrvipFlash.LCDBackLightMap_14 = (DWORD)data;
  1030. pExist[PB_LCDBackLightMap_14] = 1;
  1031. }
  1032. else if (!strcmp("LogoType",ptr)) {
  1033. BrvipFlash.LogoType = (DWORD)data;
  1034. pExist[PB_LogoType] = 1;
  1035. }
  1036. else if (!strcmp("LogoSize",ptr)) {
  1037. BrvipFlash.LogoSize = (DWORD)data;
  1038. pExist[PB_LogoSize] = 1;
  1039. }
  1040. else if (!strcmp("PanelBackLight_OffdelayTime",ptr)) {
  1041. BrvipFlash.PanelBackLight_OffdelayTime = (DWORD)data;
  1042. pExist[PB_PanelBackLight_OffdelayTime] = 1;
  1043. }
  1044. else if (!strcmp("PanelBackPower_OffdelayTime",ptr)) {
  1045. BrvipFlash.PanelBackPower_OffdelayTime = (DWORD)data;
  1046. pExist[PB_PanelBackPower_OffdelayTime] = 1;
  1047. }
  1048. }
  1049. fseek(InFile, mmioflag, SEEK_SET);
  1050. //BrvipFlash.Before_MMIOAddress = 0xbc0b0000+sizeof(BRVIP_FLASH); 07/03/02008 David.
  1051. BrvipFlash.Before_MMIOAddress = BR_ADDR_VIP+sizeof(BRVIP_FLASH);
  1052. BrvipFlash.After_MMIOAddress = BrvipFlash.Before_MMIOAddress;
  1053. ULSize = 0;
  1054. //fwrite(&BrvipFlash,sizeof(BRVIP_FLASH),1,OutFile);
  1055. while (fscanf(InFile,"\n%x %x %x %x",&data,&data1,&data2,&data3) != EOF)
  1056. {
  1057. if ((data == 0xffffffff)||(data == 0x00000000))
  1058. {
  1059. break;
  1060. }
  1061. //fwrite(&data,4,1,OutFile);
  1062. //fwrite(&data1,4,1,OutFile);
  1063. //fwrite(&data2,4,1,OutFile);
  1064. //fwrite(&data3,4,1,OutFile);
  1065. //BrvipFlash.After_MMIOAddress += 0x10;
  1066. ULData[ULSize] = data;
  1067. ULData[ULSize+1] = data1;
  1068. ULData[ULSize+2] = data2;
  1069. ULData[ULSize+3] = data3;
  1070. ULSize += 4;
  1071. }
  1072. data=0xffffffff;
  1073. //fwrite(&data,4,1,OutFile);
  1074. //fwrite(&data,4,1,OutFile);
  1075. //fwrite(&data,4,1,OutFile);
  1076. //fwrite(&data,4,1,OutFile);
  1077. //BrvipFlash.After_MMIOAddress += 0x10;
  1078. ULData[ULSize] = data;
  1079. ULData[ULSize+1] = data;
  1080. ULData[ULSize+2] = data;
  1081. ULData[ULSize+3] = data;
  1082. ULSize += 4;
  1083. BrvipFlash.After_MMIOAddress += (ULSize*4);
  1084. printf("Before_MMIOAddress %x\n",(unsigned int)BrvipFlash.Before_MMIOAddress);
  1085. printf("ULSize %x",(unsigned int)ULSize);
  1086. printf("After_MMIOAddress %x\n",(unsigned int)BrvipFlash.After_MMIOAddress);
  1087. //memcpy(pOutData+writeOffset, &BrvipFlash, sizeof(BRVIP_FLASH)); //write it later
  1088. writeOffset += sizeof(BRVIP_FLASH);
  1089. memcpy(pOutData+writeOffset, ULData, 4*ULSize);
  1090. writeOffset += 4*ULSize;
  1091. while (fscanf(InFile,"\n%x %x %x %x",&data,&data1,&data2,&data3) != EOF)
  1092. {
  1093. if ((data == 0xffffffff)||(data == 0x00000000))
  1094. {
  1095. break;
  1096. }
  1097. memcpy(pOutData+writeOffset, &data, 4);
  1098. writeOffset += 4;
  1099. memcpy(pOutData+writeOffset, &data1, 4);
  1100. writeOffset += 4;
  1101. memcpy(pOutData+writeOffset, &data2, 4);
  1102. writeOffset += 4;
  1103. memcpy(pOutData+writeOffset, &data3, 4);
  1104. writeOffset += 4;
  1105. }
  1106. data=0xffffffff;
  1107. memcpy(pOutData+writeOffset, &data, 4);
  1108. writeOffset += 4;
  1109. memcpy(pOutData+writeOffset, &data, 4);
  1110. writeOffset += 4;
  1111. memcpy(pOutData+writeOffset, &data, 4);
  1112. writeOffset += 4;
  1113. memcpy(pOutData+writeOffset, &data, 4);
  1114. writeOffset += 4;
  1115. #ifdef SET_338_VIP
  1116. while (fscanf(InFile,"\n%x %x %x %x",&data,&data1,&data2,&data3) != EOF)
  1117. {
  1118. if ((data == 0xffffffff)||(data == 0x00000000))
  1119. {
  1120. break;
  1121. }
  1122. memcpy(pOutData+writeOffset, &data, 4);
  1123. writeOffset += 4;
  1124. memcpy(pOutData+writeOffset, &data1, 4);
  1125. writeOffset += 4;
  1126. memcpy(pOutData+writeOffset, &data2, 4);
  1127. writeOffset += 4;
  1128. memcpy(pOutData+writeOffset, &data3, 4);
  1129. writeOffset += 4;
  1130. }
  1131. data=0xffffffff;
  1132. memcpy(pOutData+writeOffset, &data, 4);
  1133. writeOffset += 4;
  1134. memcpy(pOutData+writeOffset, &data, 4);
  1135. writeOffset += 4;
  1136. memcpy(pOutData+writeOffset, &data, 4);
  1137. writeOffset += 4;
  1138. memcpy(pOutData+writeOffset, &data, 4);
  1139. writeOffset += 4;
  1140. #endif //SET_338_VIP
  1141. #if 1
  1142. if(i2c0_fileoffset){
  1143. int tmp_write_size = write_i2c_data_to_bin(InFile, i2c0_fileoffset, pOutData, writeOffset);
  1144. if(tmp_write_size > 0){
  1145. BrvipFlash.I2C0_IndexAddress = (short)writeOffset;
  1146. writeOffset += tmp_write_size;
  1147. }
  1148. }
  1149. if(i2c1_fileoffset){
  1150. int tmp_write_size = write_i2c_data_to_bin(InFile, i2c1_fileoffset, pOutData, writeOffset);
  1151. if(tmp_write_size > 0){
  1152. BrvipFlash.I2C1_IndexAddress = (short)writeOffset;
  1153. writeOffset += tmp_write_size;
  1154. }
  1155. }
  1156. #endif
  1157. fclose(InFile);
  1158. /* store brvip after save all struct data */
  1159. memcpy(pOutData, &BrvipFlash, sizeof(BRVIP_FLASH));
  1160. #if 0 //gaia, 2013.05.02 ya! i don't know what is this..
  1161. //--------- Option
  1162. if (optionflag)
  1163. {
  1164. if(PANELSET_SIZE != PANELSET_NOW_USE_FIX_SIZE)
  1165. {
  1166. fprintf(stderr, "Error! \nPanelSet Size change !\n Driver must update for this");
  1167. return -1;
  1168. }
  1169. DWORD fileLen;
  1170. fileLen = writeOffset % mergeToSize;
  1171. if(fileLen >= (PANELSET_OPTION_D_OFFSET)) //0x7ec
  1172. {
  1173. fprintf(stderr, "Error! \nPanelSet Size change ! Over ox 7 e c\n Tool must update");
  1174. return -1;
  1175. }
  1176. writeOffset = PANELSET_OPTION_D_OFFSET;
  1177. memcpy(pOutData+writeOffset, &tempDW,4);
  1178. }
  1179. //---------
  1180. //check lost only
  1181. for(i=0; i<PB_MAX_END ;i++)
  1182. {
  1183. if(pExist[i]!=1)
  1184. {
  1185. fprintf(stderr, "Error \n\n It must have lost data at No %d\n", i);
  1186. return -1;
  1187. }
  1188. }
  1189. #endif
  1190. return writeOffset;
  1191. }
  1192. int BMP2Bin(char *szFileIn, char *szFileOut)
  1193. {
  1194. unsigned char BMPFILEHEADER[14],BMPINFOSIZE[4],WIDTH[4],HEIGHT[4];
  1195. FILE *fin,*fout;
  1196. int numread,i,dataoffset;//fseekresult;
  1197. int width,height;//,size;
  1198. int outwidth,align_offset;
  1199. int icolor;
  1200. //int line_offset;
  1201. int line_length_pad;
  1202. unsigned char *READLINE, *ZERO;
  1203. unsigned char MYWORD[2];
  1204. int fin_index,fout_index;
  1205. #ifdef CustomerLOGO
  1206. unsigned char buf[8]={0x00};
  1207. #endif
  1208. READLINE = malloc(12288);
  1209. if (READLINE == NULL)
  1210. return 0;
  1211. ZERO = malloc(12288);
  1212. if (ZERO == NULL)
  1213. {
  1214. free(READLINE);
  1215. return 0;
  1216. }
  1217. fout_index=0;
  1218. for(i=0;i<12288;i++)
  1219. {
  1220. ZERO[i]=0;
  1221. if((i%3)==0) ZERO[i]=0xff;
  1222. }
  1223. //line_offset=0;
  1224. fin=fopen(szFileIn,"rb");
  1225. fout=fopen(szFileOut,"wb");
  1226. //foutARGB=fopen(argv[3],"w+");
  1227. if (fin == NULL || fout == NULL)
  1228. {
  1229. if (fin) fclose(fin);
  1230. if (fout) fclose(fout);
  1231. free(READLINE);
  1232. free(ZERO);
  1233. fprintf(stderr, "Open file fail!!");
  1234. return 0;
  1235. }
  1236. fseek( fin, 0, SEEK_SET);//fseekresult=fseek( fin, 0, SEEK_SET);
  1237. numread = fread( BMPFILEHEADER, sizeof( char ), 14, fin );
  1238. if(numread!=14)
  1239. {
  1240. fprintf(stderr, "Error:read file header error!!\n");
  1241. fclose(fout);
  1242. fclose(fin);
  1243. free(READLINE);
  1244. free(ZERO);
  1245. return 0;
  1246. }
  1247. if((BMPFILEHEADER[0]!=0x42)||(BMPFILEHEADER[1]!=0x4d))
  1248. {
  1249. fprintf(stderr, "Error:Not BMP File!!");
  1250. fclose(fout);
  1251. fclose(fin);
  1252. free(READLINE);
  1253. free(ZERO);
  1254. return 0;
  1255. }
  1256. //<=============================Process Header======================>
  1257. //< Just capture what we need..... >
  1258. //< DataOffSet: >
  1259. //< Width: >
  1260. //< Height: >
  1261. //<=================================================================>
  1262. //for(i=0;i<14;i++)
  1263. // printf("0x%02x ",(char)BMPFILEHEADER[i]);
  1264. //printf("\n");
  1265. dataoffset=(((BMPFILEHEADER[13]<<8)+BMPFILEHEADER[12])<<16)+(BMPFILEHEADER[11]<<8)+BMPFILEHEADER[10];
  1266. //printf("dataoffset=%d\n",dataoffset);
  1267. fseek( fin, 14, SEEK_SET);//fseekresult=fseek( fin, 14, SEEK_SET);
  1268. numread =fread( BMPINFOSIZE, sizeof( char ), 4, fin );
  1269. if(numread!=4)
  1270. {
  1271. fprintf(stderr, "Error:read BMP Info Header error!!");
  1272. fclose(fout);
  1273. fclose(fin);
  1274. free(READLINE);
  1275. free(ZERO);
  1276. return 0;
  1277. }
  1278. #if 0 //fgets( BMPINFOSIZE, 4, fin );
  1279. size=(((BMPINFOSIZE[3]<<8)+BMPINFOSIZE[2])<<16)+(BMPINFOSIZE[1]<<8)+BMPINFOSIZE[0];
  1280. #endif
  1281. fseek( fin, 18, SEEK_SET);//fseekresult=fseek( fin, 18, SEEK_SET);
  1282. numread=fread( WIDTH, sizeof( char ), 4, fin );
  1283. if(numread!=4)
  1284. {
  1285. fprintf(stderr, "Error:read BMP Info Header error!!");
  1286. fclose(fout);
  1287. fclose(fin);
  1288. free(READLINE);
  1289. free(ZERO);
  1290. return 0;
  1291. }
  1292. width=(((WIDTH[3]<<8)+WIDTH[2])<<16)+(WIDTH[1]<<8)+WIDTH[0];
  1293. fseek( fin, 22, SEEK_SET);//fseekresult=fseek( fin, 22, SEEK_SET);
  1294. numread=fread( HEIGHT, sizeof( char ), 4, fin );
  1295. if(numread!=4)
  1296. {
  1297. fprintf(stderr, "Error:read BMP Info Header error!!");
  1298. fclose(fout);
  1299. fclose(fin);
  1300. free(READLINE);
  1301. free(ZERO);
  1302. return 0;
  1303. }
  1304. height=(((HEIGHT[3]<<8)+HEIGHT[2])<<16)+(HEIGHT[1]<<8)+HEIGHT[0];
  1305. printf("Input BMP width=%d,height=%d\n",width,height);
  1306. fseek( fin, 28, SEEK_SET);//fseekresult=fseek( fin, 28, SEEK_SET);
  1307. numread=fread( MYWORD, sizeof( char ), 2, fin );
  1308. if(numread!=2)
  1309. {
  1310. fprintf(stderr, "Error:read BMP Info Header error!!");
  1311. fclose(fout);
  1312. fclose(fin);
  1313. free(READLINE);
  1314. free(ZERO);
  1315. return 0;
  1316. }
  1317. icolor=(MYWORD[1]<<8)+MYWORD[0];
  1318. printf("icolor=%d\n",icolor);
  1319. //<======================== Read Data ================================>
  1320. //< (GBR)(GBR)(GBR)...................................................>
  1321. //< (RBG)(RBG)........................................................>
  1322. //<===================================================================>
  1323. outwidth=(((width*3)+255)/256)*256;
  1324. //outwidth=line_offset*256;
  1325. if((width*3)%4)
  1326. line_length_pad=(4-((width*3)%4));
  1327. else
  1328. line_length_pad=0;
  1329. printf("line_length_pad=%d\n",line_length_pad);
  1330. fin_index=dataoffset+(height-1)*width*3+(height-1)*line_length_pad;
  1331. align_offset=outwidth-width*3-line_length_pad;
  1332. printf("align_offset=%d,outwidth=%d\n",align_offset,outwidth);
  1333. // for(i=height-1;i>0;i--)
  1334. for(i=0;i<height;i++)
  1335. {
  1336. //printf("line %d\n",i);
  1337. //printf("offset(fin_index):0x%x\n",fin_index);
  1338. fseek( fin, fin_index, SEEK_SET);//fseekresult=fseek( fin, fin_index, SEEK_SET);
  1339. numread=fread( READLINE, sizeof( char ),(line_length_pad+(width*3)) , fin );
  1340. if(numread!=line_length_pad+(width*3))
  1341. {
  1342. //printf("fseekresult=%d numread should be %d,but is %d\n",fseekresult,line_length_pad+(width*3),numread);
  1343. fseek( fin, fin_index, SEEK_SET);//fseekresult=fseek( fin, fin_index, SEEK_SET);
  1344. numread=fread( READLINE, sizeof( char ),( line_length_pad+(width*3)), fin );
  1345. if(numread!=line_length_pad+(width*3))
  1346. {
  1347. if ( ferror( fin ) )
  1348. printf( "rs:file Read error\n" );
  1349. else
  1350. printf("rs:not ferror\n");
  1351. if ( feof( fin ) )
  1352. printf( "rs:file end\n" );
  1353. else
  1354. printf("rs:not feof\n");
  1355. fprintf(stderr, "Error:read RGB row data failed!");
  1356. printf("numread should be %d,but is %d\n",line_length_pad+(width*3),numread);
  1357. fclose(fout);
  1358. fclose(fin);
  1359. free(READLINE);
  1360. free(ZERO);
  1361. return 0;
  1362. }
  1363. }
  1364. {
  1365. int j;
  1366. unsigned char G,B,R;
  1367. //======Transfer GBR to RBG============
  1368. for(j=0;j<width;j++)
  1369. {
  1370. //printf("j=%d,SRC(%02x,%02x,%02x)",j,READLINE[j*3],READLINE[j*3+1],READLINE[j*3+2]);
  1371. int p;
  1372. B=READLINE[j*3];
  1373. G=READLINE[j*3+1];
  1374. R=READLINE[j*3+2];
  1375. READLINE[j*3]=R;
  1376. READLINE[j*3+1]=B;
  1377. READLINE[j*3+2]=G;
  1378. //printf("j=%d,DES(%02x,%02x,%02x)\n",j,READLINE[j*3],READLINE[j*3+1],READLINE[j*3+2]);
  1379. if(j==width-1)
  1380. {
  1381. for(p=0;p<line_length_pad;p++)
  1382. {
  1383. READLINE[j*3+3+p]=0;
  1384. }
  1385. }
  1386. }
  1387. }
  1388. fseek( fout, fout_index, SEEK_SET);//fseekresult=fseek( fout, fout_index, SEEK_SET);
  1389. fwrite(READLINE, sizeof( char ), line_length_pad+width*3, fout);
  1390. fout_index+=line_length_pad+width*3;
  1391. fseek( fout, fout_index, SEEK_SET);//fseekresult=fseek( fout, fout_index, SEEK_SET);
  1392. fwrite(ZERO, sizeof( char ), align_offset, fout);
  1393. //printf("write 0x%3x bytes",align_offset+width*3);
  1394. fout_index+=align_offset;
  1395. fin_index-=line_length_pad+width*3;
  1396. //printf("fout_index: 0x%3x ,fin_index:%d=0x%08x\n",fout_index,fin_index,fin_index);
  1397. }
  1398. #ifdef CustomerLOGO
  1399. fseek( fout, 0, SEEK_SET);//fseekresult=fseek( fout, fout_index, SEEK_SET);
  1400. fwrite(WIDTH, sizeof( char ), 4, fout);
  1401. fwrite(HEIGHT, sizeof( char ), 4, fout);
  1402. fwrite(buf, sizeof( char ), 8, fout);
  1403. #endif
  1404. fclose(fout);
  1405. fclose(fin);
  1406. free(READLINE);
  1407. free(ZERO);
  1408. return 1;
  1409. }