/BarcodeGui/ggg.cpp
http://barcodegui.googlecode.com/ · C++ · 312 lines · 241 code · 6 blank · 65 comment · 86 complexity · 54b348beb53c1c1dfd44cbae3ab9afc1 MD5 · raw file
- int decode_fromA(char *str)
- {
- int res = 0;
- if(strcmp(str, "wwwbbwb"))
- res = 0;
- if(strcmp(str, "wwbbwwb"))
- res = 1;
- if(strcmp(str, "wwbwwbb"))
- res = 2;
- if(strcmp(str, "wbbbbwb"))
- res = 3;
- if(strcmp(str, "wbwwwbb"))
- res = 4;
- if(strcmp(str, "wbbwwwb"))
- res = 5;
- if(strcmp(str, "wbwbbbb"))
- res = 6;
- if(strcmp(str, "wbbbwbb"))
- res = 7;
- if(strcmp(str, "wbbwbbb"))
- res = 8;
- if(strcmp(str, "wwwbwbb"))
- res = 9;
- return res;
- }
- int decode_fromB(char *str)
- {
- int res = 0;
- if(strcmp(str, "wbwwbbb"))
- res = 0;
- if(strcmp(str, "wbbwwbb"))
- res = 1;
- if(strcmp(str, "wwbbwbb"))
- res = 2;
- if(strcmp(str, "wbwwwwb"))
- res = 3;
- if(strcmp(str, "wwbbbwb"))
- res = 4;
- if(strcmp(str, "wbbbwwb"))
- res = 5;
- if(strcmp(str, "wwwwbwb"))
- res = 6;
- if(strcmp(str, "wwbwwwb"))
- res = 7;
- if(strcmp(str, "wwwbwwb"))
- res = 8;
- if(strcmp(str, "wwbwbbb"))
- res = 9;
- return res;
- }
- int decode_fromC(char *str)
- {
- int res = 0;
- if(strcmp(str, "bbbwwbw"))
- res = 0;
- if(strcmp(str, "bbwwbbw"))
- res = 1;
- if(strcmp(str, "bbwbbww"))
- res = 2;
- if(strcmp(str, "bwwwwbw"))
- res = 3;
- if(strcmp(str, "bwbbbww"))
- res = 4;
- if(strcmp(str, "bwwbbbw"))
- res = 5;
- if(strcmp(str, "bwbwwww"))
- res = 6;
- if(strcmp(str, "bwwwbww"))
- res = 7;
- if(strcmp(str, "bwwbwww"))
- res = 8;
- if(strcmp(str, "bbbwbww"))
- res = 9;
- return res;
- }
- int decode_getnum(bool *mass, int i, char &style)
- {
- char str[8];
- int nb = 0;
- int nw = 0;
- for(int j = 0; j < 7; i++)
- {
- if(mass[i + j])
- {
- nb++;
- str[j] = 'b';
- }
- else
- {
- str[j] = 'w';
- nw++;
- }
- }
- if(style == 'n')
- {
- if(nb == 3 || nb == 5)
- style = 'A';
- else
- style = 'B';
- }
- if(style == 'A')
- return decode_fromA(str);
- if(style == 'B')
- return decode_fromB(str);
- if(style == 'C')
- return decode_fromC(str);
- }
- int decode_getfirstnum(char *str)
- {
- int res = 0;
- if(strcmp(str, "AAAAAA"))
- res = 0;
- if(strcmp(str, "AABABB"))
- res = 1;
- if(strcmp(str, "AABBAB"))
- res = 2;
- if(strcmp(str, "AABBBA"))
- res = 3;
- if(strcmp(str, "ABAABB"))
- res = 4;
- if(strcmp(str, "ABBAAB"))
- res = 5;
- if(strcmp(str, "ABBBAA"))
- res = 6;
- if(strcmp(str, "ABABAB"))
- res = 7;
- if(strcmp(str, "ABABBA"))
- res = 8;
- if(strcmp(str, "ABBABA"))
- res = 9;
- return res;
- }
- bool decode_checkcontrolnum(int *code, int controlnum)
- {
- int i=0;
- int result=0;
- div_t value;
- while(i<6)
- {
- result+=3*code[i*2+1]+code[i*2];
- i++;
- }
- value=div(result,10);
- return ((10-value.rem) == controlnum);
- }
- void decode(System::Drawing::Bitmap ^bit, int *res)
- {
- int startbarcode_x;
- int startbarcode_y;
- int endofsecondblackline_x;
- int linewidth = 0;
- int lineheigth = 0;
- int linewidth1 = 0;
- int lineheigth1 = 0;
- int bitheight = ;
- int bitwidth = ;
- int numbers[13];
- bool lines[42];
- char codes[7];
- int point_x;
- int point_y;
- int x;
- int y;
- char style;
- Color point_color;
- Color black;
- //1 ? 2
- for(x = 0; x < bitwidth; x++)
- {
- for(y = 0; y < bitheigth; y++)
- {
- if(bit->getPixel(x, y) == black)
- {
- while(lineheigth + y < bitheight && bit->getPixel(x, lineheigth + y) == black)
- {
- lineheigth++;
- }
- while(linewidth + x < bitwidth && bit->getPixel(x + linewidth, y) == black)
- {
- linewidth++;
- }
- x += linewidth;
- while(!(x < bitwidth && bit->getPixel(x + linewidth, y) == black))
- {
- x++;
- }
- while(lineheigth1 + y < bitheight && bit->getPixel(x, lineheigth1 + y) == black)
- {
- lineheigth1++;
- }
- while(linewidth1 + x < bitwidth && bit->getPixel(x + linewidth1, y) == black)
- {
- linewidth1++;
- }
- if(abs(lineheigth - lineheigth1) == 0 && abs(linewidth - linewidth1))
- {
- x += 0.5*linewidth;
- y += lineheigth/2;
- point_x = x;
- point_y = y;
- }
- else
- {
- lineheigth = 0;
- linewidth1 = 0;
- lineheigth = 0;
- linewidth1 = 0;
- x += linewidth1;
- }
- }
- }
- }
- //3
- x = 0;
- for(int i = 0; i < 42; i++)
- {
- lines[i] = (bit->getPixel(point_x + x, point_y) == black);
- x += linewidth;
- }
- for(int i = 0; i < 6; i++)
- {
- style = 'n';
- res[i + 1] = decode_getnum(lines, i*7, style);
- codes[i] = style;
- }
- res[0] = decode_getfirstnum(codes);
- point_x += x;
- point_x += 6*linewidth;
- //5
- x = 0;
- for(int i = 0; i < 42; i++)
- {
- lines[i] = (bit->getPixel(point_x + x, point_y) == black);
- x += linewidth;
- }
- for(int i = 0; i < 6; i++)
- {
- style = 'C';
- res[i + 7] = decode_getnum(lines, i*7, style);
- }
- if(!decode_checkcontrolnum(res, res[12]))
- for(int i = 0; i < 13; i++)
- res[i] = 0;
- //1)????? ?????-???
- //2)?????????? ??????? ?????
- //3)???????????? ????? ?? 2 ?? 7
- //4)???????? 1-? ?????
- //5)???????????? ????? ? 8 ?? 13
- //6)????????? ??????????? ?????
- //7)return
-
- //1)
- //1.1)????? ?????? ???????
- //1.2)????? ????? ? ????????? ?????? ?????
- //1.3)????????? ? ??????? ??????? ??????? ? ???? ?????? ?? ???? ?????
- //1.4)???? ?? ??????? ???????????? ?????? ? ????? ?????? ?????? ???????
- //1.5)????? ????? ? ????????? ?????? ?????
- //1.6)???????? ? ??????? ?????? ?????
- //1.6.1)???? ???????? ??????????, ????????? ?? 2-?? ??????? ???????
- //1.6.1.1)???? ?????? ?? ????? ?????
- //1.6.1.2)????????? ?????? ?????? ??????? ??? ?????? ?????-????
- //1.6.1.3)????????? ????? ?????? ?????? ????? ??? ???????? ??????? ?????? ?????
- //1.6.1.4)????? ??????? ?????? 2, ??????? ????? ?? 1/2 ?????? ?????? ?????? ?????, ????? ????????? ?????????? ?????-????
- //1.6.2)???? ?? ??????????, ?????? ?????? ?? ????? ???
- //1.6.2.1)?????????? ?????
- //1.6.2.2)????????? ?? ????? ?????? ?????? ?????
- //1.6.2.3)goto ????? 1)
-
- //2)
- //2.1) linewidth = (endofsecondblackline_x - startbarcode_x)/3
- //2.2)??????? ?? 3 ?????? ????? ??????, ????? ????????? ? ?????? ??????? ?????? ?????
- //2.3)??????? ?????? ?? ???????? ?????? ?????, ????? ????? ????????? ?????? ?????
-
- //3)
- //3.1) ??????? ? ?????? 42 ???????? ???? (?????? ??? ?????), ?????? ? ????? ??? ???????? ?? ???? ??????? ????? ??????
- //3.2) ?? ??????? ???????????? ?????????? ???????? ???? ? ?????? ?? ?????????(? ??? B)
- //3.3) ??? ?????? ????? ???????? ??????? ? ????????
- //3.3.1) ?????????? ?????? ????????? ?? ??????? ? ?????????? ????????
- //3.3.2) ?????????? ?????
- //3.4) ??????? ?? 0.5 ???????? ?????? ?????, ????? ??????? ? ?????? ???????????? ?????-????????????
- //3.6) ?????? 3 ????? ? ??????????? ?????? ?????
- //3.7) ??????? ?? ?????? ?????? ????(? ?????? ?????? ?????????? ?? 1.5 ???????? ?????? ????? ??????
- //????? ????????? ? ?????? ?????? ?????)
-
- //4)
- //4.1) ??????? ?????? ????? ?? ???????:
- // 0 - ??????
- // 1 - ??BABB
- // 2 - AABBAB
- // 3 - AABBBA
- // 4 - ABAABB
- // 5 - ABBAAB
- // 6 - ABBBAA
- // 7 - ABABAB
- // 8 - ABABBA
- // 9 - ABBABA
-
- //5)
- //5.1) ??????? ? ?????? 42 ???????? ???? (?????? ??? ?????), ?????? ? ????? ??? ???????? ?? ???? ??????? ????? ??????
- //5.2) ?? ??????? ???????????? ?????????? ???????? ???? ? ?????? ?? ?????????(? ??? B)
- //5.3) ??? ?????? ????? ???????? ??????? ? ????????
- //5.3.1) ?????????? ?????
-
- //6)
- //6.1) ????????? ??????????? ?????
- //6.1.1) ???? ??? ??
- //6.1.1.1) ??????? ?????? ???????????? ?????
- //6.1.2) ???? ?????
- //6.1.2.1) ?????? ?????????? ?????
- //???????? ??? ????????
- //??????? ??????.
- }