-using namespace zxing::qrcode;
-
-void draw_matrix(Image& image, Ref<BitMatrix> matrix) {
- int width = matrix->getWidth();
- int height = matrix->getHeight();
-// image.modifyImage();
-// image.type(TrueColorType);
-
- PixelPacket* pixels = image.getPixels(0, 0, width, height);
-
- PixelPacket* pixel = pixels;
- ColorMono color;
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- color.mono(!matrix->get(x, y));
- *pixel = color;
- pixel++;
- }
- }
- image.syncPixels();
-}
-
-void save_matrix(Ref<BitMatrix> matrix, string filename, float scale = 1.0) {
- Image image(Geometry(matrix->getWidth(), matrix->getHeight()), Color(MaxRGB, MaxRGB, MaxRGB, 0));
- int width = matrix->getWidth();
- int height = matrix->getHeight();
- draw_matrix(image, matrix);
- image.scale(Geometry(width*scale, height*scale));
- image.write(filename);
-}
-
-void save_grid(Ref<BitMatrix> matrix, string filename, Ref<PerspectiveTransform> transform, int dimension) {
- Image image(Geometry(matrix->getWidth(), matrix->getHeight()), Color(MaxRGB, MaxRGB, MaxRGB, 0));
-
- draw_matrix(image, matrix);
-
- image.strokeColor(Color(MaxRGB, 0, 0, MaxRGB / 3));
- image.fillColor(Color(0, 0, 0, MaxRGB));
- image.strokeWidth(1);
-
- for (int i = 0; i <= dimension; i++) {
- valarray<float> tpoints(0.0, 4);
-
- tpoints[0] = 0;
- tpoints[1] = i;
- tpoints[2] = dimension;
- tpoints[3] = i;
- transform->transformPoints(tpoints);
-
- DrawableLine line1(tpoints[0], tpoints[1], tpoints[2], tpoints[3]);
- image.draw(line1);
-
- tpoints[0] = i;
- tpoints[1] = 0;
- tpoints[2] = i;
- tpoints[3] = dimension;
- transform->transformPoints(tpoints);
-
- DrawableLine line2(tpoints[0], tpoints[1], tpoints[2], tpoints[3]);
- image.draw(line2);
- }