]> Skullheadx's Git Forge - qrcodescanner.git/commitdiff
unmask encoding region of the symbol
authorSkullheadx <admonty1@gmail.com>
Wed, 20 Nov 2024 17:20:24 +0000 (12:20 -0500)
committerSkullheadx <admonty1@gmail.com>
Wed, 20 Nov 2024 17:20:24 +0000 (12:20 -0500)
camera.cpp
output.pbm
qrgenerator.cpp

index 7ce54fd0aebe040971772ac20de5043077b8ca84..e87d8ea29f8689fd884b16ce22914f493ef031c4 100644 (file)
@@ -10,16 +10,25 @@ unsigned int distance(std::vector<bool> &v1, const std::vector<bool> &v2);
 void read_words_from_file(char const *filename, std::vector<std::vector<bool>> &symbol);
 
 std::vector<bool> get_format_info(std::vector<std::vector<bool>> &symbol);
+void decode_mask(std::vector<std::vector<bool>> &symbol, std::size_t mask_pattern);
 
 int main(){
        std::vector<std::vector<bool>> symbol(21, std::vector<bool>(21,0));
 
        read_words_from_file("output.pbm", symbol);
-       print(symbol);
+       //print(symbol);
        
        std::vector<bool> format_info = get_format_info(symbol);
 
-       print(format_info);
+       std::cout << "Format Info: "; print(format_info); std::cout << std::endl;
+       std::bitset<3> mask_pattern{};  
+       mask_pattern[0] = format_info[2];
+       mask_pattern[1] = format_info[3];
+       mask_pattern[2] = format_info[4];
+       decode_mask(symbol, mask_pattern.to_ulong());
+       
+       print(symbol);
+
        
        return 0;
 }
@@ -107,7 +116,7 @@ std::vector<bool> get_format_info(std::vector<std::vector<bool>> &symbol){
                {1,1,1,1,0,1,0,1,1,0,0,1,0,0,0},
                {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
        };
-       
+       //print(format_info);   
        std::vector<bool> mask = {1,0,1,0,1,0,0,0,0,0,1,0,0,1,0};
        vec_xor(format_info, mask);
 
@@ -134,6 +143,55 @@ std::vector<bool> get_format_info(std::vector<std::vector<bool>> &symbol){
        return format_info;
 }
 
+void decode_mask(std::vector<std::vector<bool>> &symbol, std::size_t mask_pattern){
+       std::vector<std::vector<bool>> data_mask(21, std::vector<bool> (21, 0));
+       for (std::size_t i{}; i < 21; ++i){
+               for (std::size_t j{}; j < 21; ++j){
+                       if ((i < 9 && j < 9) || (i > 12 && j < 9) || (i < 9 && j > 12) || i == 6 || j == 6){
+                               continue;
+                       }
+                       // 000
+                       if (mask_pattern == 0 && (i+j)%2 == 0){
+                               data_mask[i][j] = 1;
+                       }
+                       // 001
+                       else if (mask_pattern == 1 && i % 2 == 0){
+                               data_mask[i][j] = 1;
+                       }
+                       // 010
+                       else if (mask_pattern == 2 && j % 3 == 0){
+                               data_mask[i][j] = 1;
+                       }
+                       // 011
+                       else if (mask_pattern == 3 && (i+j)%3 == 0){
+                               data_mask[i][j] = 1;
+                       }
+                       // 100
+                       else if (mask_pattern == 4 && (i / 2 + j / 3) % 2 == 0){
+                               data_mask[i][j] = 1;
+                       }
+                       // 101
+                       else if (mask_pattern == 5 && (i * j) % 2 + (i * j) % 3 == 0){
+                               data_mask[i][j] = 1;
+                       }       
+                       // 110
+                       else if (mask_pattern == 6 && ((i * j) % 2 + (i * j) % 3 ) % 2 == 0){
+                               data_mask[i][j] = 1;
+                       }       
+                       // 111
+                       else if (mask_pattern == 7 && (((i + j) % 2 + (i * j) % 3 ) % 2 == 0)){
+                               data_mask[i][j] = 1;
+                       }       
+               }
+       }        
+       
+       for (std::size_t i{0}; i < 21; ++i){
+               for (std::size_t j{0}; j < 21; ++j){
+                       symbol[i][j] = symbol[i][j] ^ data_mask[i][j];
+               }
+       }
+}
+
 void read_words_from_file(char const *filename, std::vector<std::vector<bool>> &symbol) {
        std::ifstream file{ filename };
        if (!file.is_open()) {
index 363237fe0e0358480fca14503966b87747413374..dbea2aa7a9a1027f716766fb515b59ee4fea00b0 100644 (file)
@@ -1,23 +1,23 @@
 P1
 21 21
-1 1 1 1 1 1 1 0 1 0 0 0 0 0 1 1 1 1 1 1 1 
-1 0 0 0 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 0 1 
-1 0 1 1 1 0 1 0 0 0 0 0 1 0 1 0 1 1 1 0 1 
-1 0 1 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0 0 0 0 0 0 0 0 0 0 0 0 
+1 0 1 0 1 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 
+1 1 1 0 1 1 0 1 0 1 1 1 1 1 0 1 1 0 0 1 0 
+0 1 0 0 0 1 1 0 0 0 1 0 1 1 0 1 1 0 0 1 1 
+1 1 1 0 1 1 0 1 0 1 1 0 1 1 1 1 0 1 1 1 0 
+0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 
+0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 1 
+1 1 1 1 1 1 1 0 0 1 0 0 0 1 0 1 1 1 1 1 1 
+1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 1 1 1 
+1 0 1 1 1 0 1 0 1 1 0 1 1 0 0 0 1 0 0 0 0 
+1 0 1 1 1 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 
+1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 1 0 0 1 1 0 
+1 0 0 0 0 0 1 0 0 1 1 1 1 0 1 0 0 1 0 0 0 
+1 1 1 1 1 1 1 0 1 0 0 0 1 0 1 1 1 1 1 1 1 
index 442ad614c196dcf4957e05abc391ac5811f21b6e..49ef0d90c7e5bd081b05315d571d00deedc028e0 100644 (file)
@@ -28,7 +28,7 @@ int main() {
        int k;
        //std::cout << id_generator(69) << std::endl;
        std::string input_data{"6969696969"};
-       const unsigned int input_length = 8;
+       const unsigned int input_length = 10;
        std::vector<bool> input_data_vector{};
        for (unsigned int i{0}; i < input_length; i+=3){
 /* 8 - 6 = 2