| 130 | } |
| 131 | |
| 132 | BitMatrix Inflate(BitMatrix&& input, int width, int height, int quietZone) |
| 133 | { |
| 134 | const int codeWidth = input.width(); |
| 135 | const int codeHeight = input.height(); |
| 136 | const int outputWidth = std::max(width, codeWidth + 2 * quietZone); |
| 137 | const int outputHeight = std::max(height, codeHeight + 2 * quietZone); |
| 138 | |
| 139 | if (input.width() == outputWidth && input.height() == outputHeight) |
| 140 | return std::move(input); |
| 141 | |
| 142 | const int scale = std::min((outputWidth - 2*quietZone) / codeWidth, (outputHeight - 2*quietZone) / codeHeight); |
| 143 | // Padding includes both the quiet zone and the extra white pixels to |
| 144 | // accommodate the requested dimensions. |
| 145 | const int leftPadding = (outputWidth - (codeWidth * scale)) / 2; |
| 146 | const int topPadding = (outputHeight - (codeHeight * scale)) / 2; |
| 147 | |
| 148 | BitMatrix result(outputWidth, outputHeight); |
| 149 | |
| 150 | for (int inputY = 0, outputY = topPadding; inputY < input.height(); ++inputY, outputY += scale) { |
| 151 | for (int inputX = 0, outputX = leftPadding; inputX < input.width(); ++inputX, outputX += scale) { |
| 152 | if (input.get(inputX, inputY)) |
| 153 | result.setRegion(outputX, outputY, scale, scale); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | return result; |
| 158 | } |
| 159 | |
| 160 | BitMatrix Deflate(const BitMatrix& input, int width, int height, float top, float left, float subSampling) |
| 161 | { |