| 54 | } |
| 55 | |
| 56 | BitMatrix ParseBitMatrix(const std::string& str, char one, bool expectSpace) |
| 57 | { |
| 58 | auto lineLength = str.find('\n'); |
| 59 | if (lineLength == std::string::npos) |
| 60 | return {}; |
| 61 | |
| 62 | int strStride = expectSpace ? 2 : 1; |
| 63 | int height = narrow_cast<int>(str.length() / (lineLength + 1)); |
| 64 | int width = narrow_cast<int>(lineLength / strStride); |
| 65 | BitMatrix mat(width, height); |
| 66 | for (int y = 0; y < height; ++y) { |
| 67 | size_t offset = y * (lineLength + 1); |
| 68 | for (int x = 0; x < width; ++x, offset += strStride) { |
| 69 | if (str[offset] == one) |
| 70 | mat.set(x, y); |
| 71 | } |
| 72 | } |
| 73 | return mat; |
| 74 | } |
| 75 | |
| 76 | void SaveAsPBM(const BitMatrix& matrix, const std::string filename, int quietZone) |
| 77 | { |