// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
// Generates Bayer's dither matrices, of various sizes.
//
// Example matrices:
// 2x2:
// 0 2
// 3 1
//
// 4x4:
// 0 8 2 10
// 12 4 14 6
// 3 11 1 9
// 15 7 13 5
//
// Method:
// - Start with 2x2 matrix, M0
// 0 2
// 3 1
// - Make matrices, each twice the size of the previous one.
// The i-th matrix, Mi, is
// A B
// C D
// where A,B,C,D are sub-matrices half the size (the size of M(i-1)),
// A = 4*M(i-1)
// D = 4*M(i-1)+1
// B = 4*M(i-1)+2
// C = 4*M(i-1)+3
//
// Author: Alejo Hausner (ahausner@truehaus.net) 2008.
#ifdef WIN32
#include
#endif
#include
#include
#include
#include
#include "Image.h"
using namespace std;
FILE *dbgfp = fopen("debug.dat","w");
int **doubleUp(int **Mk1, int k) {
int w = (int)pow(2.0, (double)(k+1));
int **Mk = new int*[w];
for (int i=0; i