1/*
2 * make_pattern.cpp
3 * Copyright 2000 Y.Takagi All Rights Reserved.
4 */
5
6#include <iostream>
7#include <iomanip>
8
9using namespace std;
10
11#define MAX_HORTZ	4
12#define MAX_VERT	4
13#define MAX_ELEMENT	(MAX_HORTZ * MAX_VERT)
14
15#include "original_dither_pattern.h"
16
17void create_index_table(const unsigned char *p1, unsigned char *p2)
18{
19	for (int i = 0 ; i < MAX_ELEMENT ; i++) {
20		p2[*p1] = i;
21		p1++;
22	}
23}
24
25inline int index2horz(int index)
26{
27	return index % MAX_HORTZ;
28}
29
30inline int index2vert(int index)
31{
32	return index / MAX_HORTZ;
33}
34
35void create_pattern16x16(const unsigned char *pattern4x4, unsigned char *pattern16x16)
36{
37	unsigned char value2index[MAX_ELEMENT];
38	create_index_table(pattern4x4, value2index);
39
40	for (int i = 0 ; i < MAX_ELEMENT ; i++) {
41		int index = value2index[i];
42		int h = index2horz(index);
43		int v = index2vert(index);
44		for (int j = 0 ; j < MAX_ELEMENT ; j++) {
45			int index2 = value2index[j];
46			int h2 = index2horz(index2) * 4 + h;
47			int v2 = index2vert(index2) * 4 + v;
48			pattern16x16[h2 + v2 * MAX_ELEMENT] = j + i * MAX_ELEMENT;
49		}
50	}
51}
52
53void print_pattern(ostream &os, const char *name, const unsigned char *pattern)
54{
55	os << "const unsigned char " << name << "[] = {" << '\n' << '\t';
56	for (int i = 0 ; i < 256 ; i++) {
57		os << setw(3) << (int)pattern[i];
58		if (i == MAX_ELEMENT * MAX_ELEMENT - 1) {
59			os << '\n';
60		} else {
61			os << ',';
62			if (i % MAX_ELEMENT == MAX_ELEMENT - 1) {
63				os << '\n' << '\t';
64			}
65		}
66	}
67	os << "};" << '\n';
68}
69
70int main()
71{
72	unsigned char pattern16x16_type1[MAX_ELEMENT * MAX_ELEMENT];
73	create_pattern16x16(pattern4x4_type1, pattern16x16_type1);
74	print_pattern(cout, "pattern16x16_type1", pattern16x16_type1);
75
76	cout << endl;
77
78	unsigned char pattern16x16_type2[MAX_ELEMENT * MAX_ELEMENT];
79	create_pattern16x16(pattern4x4_type2, pattern16x16_type2);
80	print_pattern(cout, "pattern16x16_type2", pattern16x16_type2);
81
82	cout << endl;
83
84	unsigned char pattern16x16_type3[MAX_ELEMENT * MAX_ELEMENT];
85	create_pattern16x16(pattern4x4_type3, pattern16x16_type3);
86	print_pattern(cout, "pattern16x16_type3", pattern16x16_type3);
87
88	cout << endl;
89	return 0;
90}
91