Assorted whitespace cleanup and typo fixes.
[haiku.git] / src / libs / print / libprint / tools / make_pattern.cpp
blob2f34669bd9db5c58a465dae40e13bd682b805903
1 /*
2 * make_pattern.cpp
3 * Copyright 2000 Y.Takagi All Rights Reserved.
4 */
6 #include <iostream>
7 #include <iomanip>
9 using namespace std;
11 #define MAX_HORTZ 4
12 #define MAX_VERT 4
13 #define MAX_ELEMENT (MAX_HORTZ * MAX_VERT)
15 #include "original_dither_pattern.h"
17 void create_index_table(const unsigned char *p1, unsigned char *p2)
19 for (int i = 0 ; i < MAX_ELEMENT ; i++) {
20 p2[*p1] = i;
21 p1++;
25 inline int index2horz(int index)
27 return index % MAX_HORTZ;
30 inline int index2vert(int index)
32 return index / MAX_HORTZ;
35 void create_pattern16x16(const unsigned char *pattern4x4, unsigned char *pattern16x16)
37 unsigned char value2index[MAX_ELEMENT];
38 create_index_table(pattern4x4, value2index);
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;
53 void print_pattern(ostream &os, const char *name, const unsigned char *pattern)
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';
67 os << "};" << '\n';
70 int main()
72 unsigned char pattern16x16_type1[MAX_ELEMENT * MAX_ELEMENT];
73 create_pattern16x16(pattern4x4_type1, pattern16x16_type1);
74 print_pattern(cout, "pattern16x16_type1", pattern16x16_type1);
76 cout << endl;
78 unsigned char pattern16x16_type2[MAX_ELEMENT * MAX_ELEMENT];
79 create_pattern16x16(pattern4x4_type2, pattern16x16_type2);
80 print_pattern(cout, "pattern16x16_type2", pattern16x16_type2);
82 cout << endl;
84 unsigned char pattern16x16_type3[MAX_ELEMENT * MAX_ELEMENT];
85 create_pattern16x16(pattern4x4_type3, pattern16x16_type3);
86 print_pattern(cout, "pattern16x16_type3", pattern16x16_type3);
88 cout << endl;
89 return 0;