PageRenderTime 54ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/BarcodeGui/ggg.cpp

http://barcodegui.googlecode.com/
C++ | 312 lines | 241 code | 6 blank | 65 comment | 80 complexity | 54b348beb53c1c1dfd44cbae3ab9afc1 MD5 | raw file
  1. int decode_fromA(char *str)
  2. {
  3. int res = 0;
  4. if(strcmp(str, "wwwbbwb"))
  5. res = 0;
  6. if(strcmp(str, "wwbbwwb"))
  7. res = 1;
  8. if(strcmp(str, "wwbwwbb"))
  9. res = 2;
  10. if(strcmp(str, "wbbbbwb"))
  11. res = 3;
  12. if(strcmp(str, "wbwwwbb"))
  13. res = 4;
  14. if(strcmp(str, "wbbwwwb"))
  15. res = 5;
  16. if(strcmp(str, "wbwbbbb"))
  17. res = 6;
  18. if(strcmp(str, "wbbbwbb"))
  19. res = 7;
  20. if(strcmp(str, "wbbwbbb"))
  21. res = 8;
  22. if(strcmp(str, "wwwbwbb"))
  23. res = 9;
  24. return res;
  25. }
  26. int decode_fromB(char *str)
  27. {
  28. int res = 0;
  29. if(strcmp(str, "wbwwbbb"))
  30. res = 0;
  31. if(strcmp(str, "wbbwwbb"))
  32. res = 1;
  33. if(strcmp(str, "wwbbwbb"))
  34. res = 2;
  35. if(strcmp(str, "wbwwwwb"))
  36. res = 3;
  37. if(strcmp(str, "wwbbbwb"))
  38. res = 4;
  39. if(strcmp(str, "wbbbwwb"))
  40. res = 5;
  41. if(strcmp(str, "wwwwbwb"))
  42. res = 6;
  43. if(strcmp(str, "wwbwwwb"))
  44. res = 7;
  45. if(strcmp(str, "wwwbwwb"))
  46. res = 8;
  47. if(strcmp(str, "wwbwbbb"))
  48. res = 9;
  49. return res;
  50. }
  51. int decode_fromC(char *str)
  52. {
  53. int res = 0;
  54. if(strcmp(str, "bbbwwbw"))
  55. res = 0;
  56. if(strcmp(str, "bbwwbbw"))
  57. res = 1;
  58. if(strcmp(str, "bbwbbww"))
  59. res = 2;
  60. if(strcmp(str, "bwwwwbw"))
  61. res = 3;
  62. if(strcmp(str, "bwbbbww"))
  63. res = 4;
  64. if(strcmp(str, "bwwbbbw"))
  65. res = 5;
  66. if(strcmp(str, "bwbwwww"))
  67. res = 6;
  68. if(strcmp(str, "bwwwbww"))
  69. res = 7;
  70. if(strcmp(str, "bwwbwww"))
  71. res = 8;
  72. if(strcmp(str, "bbbwbww"))
  73. res = 9;
  74. return res;
  75. }
  76. int decode_getnum(bool *mass, int i, char &style)
  77. {
  78. char str[8];
  79. int nb = 0;
  80. int nw = 0;
  81. for(int j = 0; j < 7; i++)
  82. {
  83. if(mass[i + j])
  84. {
  85. nb++;
  86. str[j] = 'b';
  87. }
  88. else
  89. {
  90. str[j] = 'w';
  91. nw++;
  92. }
  93. }
  94. if(style == 'n')
  95. {
  96. if(nb == 3 || nb == 5)
  97. style = 'A';
  98. else
  99. style = 'B';
  100. }
  101. if(style == 'A')
  102. return decode_fromA(str);
  103. if(style == 'B')
  104. return decode_fromB(str);
  105. if(style == 'C')
  106. return decode_fromC(str);
  107. }
  108. int decode_getfirstnum(char *str)
  109. {
  110. int res = 0;
  111. if(strcmp(str, "AAAAAA"))
  112. res = 0;
  113. if(strcmp(str, "AABABB"))
  114. res = 1;
  115. if(strcmp(str, "AABBAB"))
  116. res = 2;
  117. if(strcmp(str, "AABBBA"))
  118. res = 3;
  119. if(strcmp(str, "ABAABB"))
  120. res = 4;
  121. if(strcmp(str, "ABBAAB"))
  122. res = 5;
  123. if(strcmp(str, "ABBBAA"))
  124. res = 6;
  125. if(strcmp(str, "ABABAB"))
  126. res = 7;
  127. if(strcmp(str, "ABABBA"))
  128. res = 8;
  129. if(strcmp(str, "ABBABA"))
  130. res = 9;
  131. return res;
  132. }
  133. bool decode_checkcontrolnum(int *code, int controlnum)
  134. {
  135. int i=0;
  136. int result=0;
  137. div_t value;
  138. while(i<6)
  139. {
  140. result+=3*code[i*2+1]+code[i*2];
  141. i++;
  142. }
  143. value=div(result,10);
  144. return ((10-value.rem) == controlnum);
  145. }
  146. void decode(System::Drawing::Bitmap ^bit, int *res)
  147. {
  148. int startbarcode_x;
  149. int startbarcode_y;
  150. int endofsecondblackline_x;
  151. int linewidth = 0;
  152. int lineheigth = 0;
  153. int linewidth1 = 0;
  154. int lineheigth1 = 0;
  155. int bitheight = ;
  156. int bitwidth = ;
  157. int numbers[13];
  158. bool lines[42];
  159. char codes[7];
  160. int point_x;
  161. int point_y;
  162. int x;
  163. int y;
  164. char style;
  165. Color point_color;
  166. Color black;
  167. //1 ? 2
  168. for(x = 0; x < bitwidth; x++)
  169. {
  170. for(y = 0; y < bitheigth; y++)
  171. {
  172. if(bit->getPixel(x, y) == black)
  173. {
  174. while(lineheigth + y < bitheight && bit->getPixel(x, lineheigth + y) == black)
  175. {
  176. lineheigth++;
  177. }
  178. while(linewidth + x < bitwidth && bit->getPixel(x + linewidth, y) == black)
  179. {
  180. linewidth++;
  181. }
  182. x += linewidth;
  183. while(!(x < bitwidth && bit->getPixel(x + linewidth, y) == black))
  184. {
  185. x++;
  186. }
  187. while(lineheigth1 + y < bitheight && bit->getPixel(x, lineheigth1 + y) == black)
  188. {
  189. lineheigth1++;
  190. }
  191. while(linewidth1 + x < bitwidth && bit->getPixel(x + linewidth1, y) == black)
  192. {
  193. linewidth1++;
  194. }
  195. if(abs(lineheigth - lineheigth1) == 0 && abs(linewidth - linewidth1))
  196. {
  197. x += 0.5*linewidth;
  198. y += lineheigth/2;
  199. point_x = x;
  200. point_y = y;
  201. }
  202. else
  203. {
  204. lineheigth = 0;
  205. linewidth1 = 0;
  206. lineheigth = 0;
  207. linewidth1 = 0;
  208. x += linewidth1;
  209. }
  210. }
  211. }
  212. }
  213. //3
  214. x = 0;
  215. for(int i = 0; i < 42; i++)
  216. {
  217. lines[i] = (bit->getPixel(point_x + x, point_y) == black);
  218. x += linewidth;
  219. }
  220. for(int i = 0; i < 6; i++)
  221. {
  222. style = 'n';
  223. res[i + 1] = decode_getnum(lines, i*7, style);
  224. codes[i] = style;
  225. }
  226. res[0] = decode_getfirstnum(codes);
  227. point_x += x;
  228. point_x += 6*linewidth;
  229. //5
  230. x = 0;
  231. for(int i = 0; i < 42; i++)
  232. {
  233. lines[i] = (bit->getPixel(point_x + x, point_y) == black);
  234. x += linewidth;
  235. }
  236. for(int i = 0; i < 6; i++)
  237. {
  238. style = 'C';
  239. res[i + 7] = decode_getnum(lines, i*7, style);
  240. }
  241. if(!decode_checkcontrolnum(res, res[12]))
  242. for(int i = 0; i < 13; i++)
  243. res[i] = 0;
  244. //1)????? ?????-???
  245. //2)?????????? ??????? ?????
  246. //3)???????????? ????? ?? 2 ?? 7
  247. //4)???????? 1-? ?????
  248. //5)???????????? ????? ? 8 ?? 13
  249. //6)????????? ??????????? ?????
  250. //7)return
  251. //1)
  252. //1.1)????? ?????? ???????
  253. //1.2)????? ????? ? ????????? ?????? ?????
  254. //1.3)????????? ? ??????? ??????? ??????? ? ???? ?????? ?? ???? ?????
  255. //1.4)???? ?? ??????? ???????????? ?????? ? ????? ?????? ?????? ???????
  256. //1.5)????? ????? ? ????????? ?????? ?????
  257. //1.6)???????? ? ??????? ?????? ?????
  258. //1.6.1)???? ???????? ??????????, ????????? ?? 2-?? ??????? ???????
  259. //1.6.1.1)???? ?????? ?? ????? ?????
  260. //1.6.1.2)????????? ?????? ?????? ??????? ??? ?????? ?????-????
  261. //1.6.1.3)????????? ????? ?????? ?????? ????? ??? ???????? ??????? ?????? ?????
  262. //1.6.1.4)????? ??????? ?????? 2, ??????? ????? ?? 1/2 ?????? ?????? ?????? ?????, ????? ????????? ?????????? ?????-????
  263. //1.6.2)???? ?? ??????????, ?????? ?????? ?? ????? ???
  264. //1.6.2.1)?????????? ?????
  265. //1.6.2.2)????????? ?? ????? ?????? ?????? ?????
  266. //1.6.2.3)goto ????? 1)
  267. //2)
  268. //2.1) linewidth = (endofsecondblackline_x - startbarcode_x)/3
  269. //2.2)??????? ?? 3 ?????? ????? ??????, ????? ????????? ? ?????? ??????? ?????? ?????
  270. //2.3)??????? ?????? ?? ???????? ?????? ?????, ????? ????? ????????? ?????? ?????
  271. //3)
  272. //3.1) ??????? ? ?????? 42 ???????? ???? (?????? ??? ?????), ?????? ? ????? ??? ???????? ?? ???? ??????? ????? ??????
  273. //3.2) ?? ??????? ???????????? ?????????? ???????? ???? ? ?????? ?? ?????????(? ??? B)
  274. //3.3) ??? ?????? ????? ???????? ??????? ? ????????
  275. //3.3.1) ?????????? ?????? ????????? ?? ??????? ? ?????????? ????????
  276. //3.3.2) ?????????? ?????
  277. //3.4) ??????? ?? 0.5 ???????? ?????? ?????, ????? ??????? ? ?????? ???????????? ?????-????????????
  278. //3.6) ?????? 3 ????? ? ??????????? ?????? ?????
  279. //3.7) ??????? ?? ?????? ?????? ????(? ?????? ?????? ?????????? ?? 1.5 ???????? ?????? ????? ??????
  280. //????? ????????? ? ?????? ?????? ?????)
  281. //4)
  282. //4.1) ??????? ?????? ????? ?? ???????:
  283. // 0 - ??????
  284. // 1 - ??BABB
  285. // 2 - AABBAB
  286. // 3 - AABBBA
  287. // 4 - ABAABB
  288. // 5 - ABBAAB
  289. // 6 - ABBBAA
  290. // 7 - ABABAB
  291. // 8 - ABABBA
  292. // 9 - ABBABA
  293. //5)
  294. //5.1) ??????? ? ?????? 42 ???????? ???? (?????? ??? ?????), ?????? ? ????? ??? ???????? ?? ???? ??????? ????? ??????
  295. //5.2) ?? ??????? ???????????? ?????????? ???????? ???? ? ?????? ?? ?????????(? ??? B)
  296. //5.3) ??? ?????? ????? ???????? ??????? ? ????????
  297. //5.3.1) ?????????? ?????
  298. //6)
  299. //6.1) ????????? ??????????? ?????
  300. //6.1.1) ???? ??? ??
  301. //6.1.1.1) ??????? ?????? ???????????? ?????
  302. //6.1.2) ???? ?????
  303. //6.1.2.1) ?????? ?????????? ?????
  304. //???????? ??? ????????
  305. //??????? ??????.
  306. }