forked from leuat/TRSE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
214 lines (176 loc) · 5.55 KB
/
main.cpp
File metadata and controls
214 lines (176 loc) · 5.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
* Turbo Rascal Syntax error, “;” expected but “BEGIN” (TRSE, Turbo Rascal SE)
* 8 bit software development IDE for the Commodore 64
* Copyright (C) 2018 Nicolaas Ervik Groeneboom (nicolaas.groeneboom@gmail.com)
*
*
* 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 (LICENSE.txt).
* If not, see <https://www.gnu.org/licenses/>.
*/
#include "mainwindow.h"
#include <QApplication>
#include <QStyleFactory>
#include <QSettings>
void ConvertPerlin(QString input, QString out, float div) {
QImage img;
img.load(input);
QByteArray a;
int xw = img.width()/div;
int xh = img.height()/div;
a.resize(xw*xh);
// qDebug() << "Converting file: " << xw;
for (int x=0;x<xw;x++)
for (int y=0;y<xh;y++) {
a[x + y*xw]=QColor(img.pixel(x*div, y*div)).red();
// if (rand()%100>98)
// qDebug() << a[x + y*xw];
}
QFile f(out);
f.open(QFile::WriteOnly);
f.write(a);
f.close();
}
void SineTable(QString fn) {
QFile f(fn);
f.open(QFile::WriteOnly);
QByteArray b;
for (int i=0;i<256;i++)
b.append(sin((i/256.0)*3.14159265*2)*127+128);
f.write(b);
f.close();
}
void SineTablei(QString fn) {
QFile f(fn);
f.open(QFile::WriteOnly);
QByteArray b;
for (int i=0;i<256;i++) {
b.append(sin((i/256.0)*3.14159265*2)*127+128);
}
f.write(b);
f.close();
}
void RandTable(QString fn) {
QFile f(fn);
f.open(QFile::WriteOnly);
QByteArray b;
for (int i=0;i<256;i++)
b.append(rand()%0xFF);
f.write(b);
f.close();
}
void TanTable(QString fn) {
QFile f(fn);
f.open(QFile::WriteOnly);
QByteArray b;
float ss = 0.8;
float PI = 3.14159265;
float div = 1.0f;
for (int i=0;i<256;i++) {
// b.append(1+tan((i/256.0)*3.14159265/2 + 3.14159)*127+128);
// b.append(1+tan((i/256.0)*PI/2.83)*127+128);
float v = tan( ((i/256.0)*PI*ss+PI/2.0 + (PI/2.0*(1-ss)/1) ) )*0.4;
if (v>div) v=div;
if (v<-div) v=-div;
v=v/div;
// qDebug() << i<< " : " << v;
b.append((v+1)*127+128);
}
// for (int i=0;i<256;i++)
// qDebug() << QString::number(i) << " : " << QString::number(b[i]);
f.write(b);
f.close();
}
void ColumnTab()
{
int k=0xFF;
QByteArray columntab;
columntab.resize(256);
for (int i=0;i<256;i++) {
if (i==0xff-0x80) k=0x70;
if (i==0xff-0x40) k=0x60;
if (i==0xff-0x20) k=0x50;
if (i==0xff-0x10) k=0x40;
if (i==0xff-0x08) k=0x30;
if (i==0xff-0x04) k=0x20;
if (i==0xff-0x02) k=0x10;
if (i==0xff-0x01) k=0x00;
columntab[i]=k/16;
}
QFile f("columntab.bin");
f.open(QFile::WriteOnly);
f.write(columntab);
f.close();
}
void fixCurrentDir(QString execFile) {
QStringList al = execFile.split(QDir::separator());
al.removeLast();
QString dir = QDir::separator();
for (QString s : al)
dir +=s+QDir::separator();
QDir::setCurrent(dir);
}
void CircleAndAtan(QString f1, QString f2, int w, int h) {
QByteArray b1,b2;
for (int j=0;j<h;j++)
for (int i=0;i<w;i++) {
float y = (j-h/2)/(float)h;
float x = (i-w/2)/(float)w;
float s = sqrt(x*x+y*y);
b1.append((char)(s*15.0));
float s2 = atan2(x,y);
b2.append((char)(s2*15.0));
}
Util::SaveByteArray(b1,f1);
Util::SaveByteArray(b2,f2);
}
void TestSSIM() {
LImageQImage ia, ib;
ia.LoadQImage("/home/leuat/Pictures/jupiter1.jpg");
ib.LoadQImage("/home/leuat/Pictures/jupiter1.jpg");
qDebug() <<" Self : " <<ia.CalcSSIM(&ib);
ib.LoadQImage("/home/leuat/Pictures/jupiter2.jpg");
qDebug() <<" jup 2 : " <<ia.CalcSSIM(&ib);
ib.LoadQImage("/home/leuat/Pictures/skullsanta.jpeg");
qDebug() <<" santa : " <<ia.CalcSSIM(&ib);
ib.LoadQImage("/home/leuat/Pictures/avail.png");
qDebug() <<" avail : " <<ia.CalcSSIM(&ib);
}
//https://www.c64-wiki.com/wiki/Commodore_Plus/4
int main(int argc, char *argv[])
{
// ConvertAllObjs();
// qDebug() << Util::BinopString("#$C");
// ConvertPerlin("perlin512.jpg","perlin64.bin",8);
// ColumnTab();
// RandTable("rnd256.bin");
// CircleAndAtan("/home/leuat/Dropbox/TRSE/gameboytest/data/circle.bin","/home/leuat/Dropbox/TRSE/gameboytest/data/atan.bin",16,16);
/* Tool::PathTool("/home/leuat/Pictures/pathtest/pathtest",
"/home/leuat/Dropbox/TRSE/SummerOfSquid/data/path",320,8);*/
// TestSSIM();
// exit(1);
//CreatePerlin("/home/leuat/Dropbox/TRSE/ECM/data/perlin80.dat",80,50,6,1,1,127);
QApplication a(argc, argv);
a.setOrganizationDomain("lemonspawn.com");
a.setApplicationName("TRSE");
QString oldCurDir = QDir::currentPath();
fixCurrentDir(QString(argv[0]));
a.setStyle(QStyleFactory::create("Fusion"));
MainWindow w;
for (int i=0; i<argc;i++)
w.m_commandParams+=QString(argv[i]);
w.show();
w.AfterStart(oldCurDir);
w.RestoreSettings();
return a.exec();
}