summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile8
-rw-r--r--changelog.md12
-rw-r--r--include/benoit/d/alpha.hh6
-rw-r--r--include/benoit/d/ver.hh2
-rw-r--r--include/benoit/t/pos.hh6
-rw-r--r--include/benoit/t/thrddat.hh1
-rw-r--r--src/benoit/arghandl.cc15
-rw-r--r--src/benoit/d/alpha.cc2
-rw-r--r--src/benoit/d/logdoprint.cc4
-rw-r--r--src/benoit/helpscrn.cc60
-rw-r--r--src/benoit/plotmandelbrot.cc99
-rw-r--r--src/benoit/t/pos/pos.cc4
12 files changed, 120 insertions, 99 deletions
diff --git a/Makefile b/Makefile
index db54b8a..e7e2762 100644
--- a/Makefile
+++ b/Makefile
@@ -5,11 +5,12 @@ CXXFLAGS += -DNDEBUG -g
endif
CXXFLAGS += -std=c++20 -Wall -Wextra -Wpedantic
CXXFLAGS += -march=native -mtune=native -O3
-LDFLAGS = -lfmt -lgmp -lmpfr -lpng -lpthread -lpugixml -lwebp
+LDFLAGS = -lfmt -lgmp -lmpfr -lpng -lpthread -lpugixml -lwebp
HDRS_CXX = \
include/benoit/archstr.hh \
include/benoit/arghandl.hh \
include/benoit/crtcfg.hh \
+ include/benoit/d/alpha.hh \
include/benoit/d/arch.hh \
include/benoit/d/cfg.hh \
include/benoit/d/debug.hh \
@@ -47,6 +48,7 @@ SRCS_CXX = \
src/benoit/archstr.cc \
src/benoit/arghandl.cc \
src/benoit/crtcfg.cc \
+ src/benoit/d/alpha.cc \
src/benoit/d/cfg.cc \
src/benoit/d/dobt.cc \
src/benoit/d/imgfmt.cc \
@@ -74,9 +76,9 @@ SRCS_CXX = \
src/main.cc
OBJS_CXX=$(SRCS_CXX:.cc=.o)
OBJS=$(OBJS_CXX)
-benoit: $(OBJS)
+benoit: Makefile $(OBJS)
$(CXX) $(LDFLAGS) -o $@ $(OBJS)
-$(OBJS_CXX): $(HDRS_CXX) $(SRCS_CXX)
+$(OBJS_CXX): Makefile $(HDRS_CXX)
.PHONY: clean
clean:
rm $(OBJS)
diff --git a/changelog.md b/changelog.md
index da27b30..c6bc39a 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,9 +1,15 @@
+# ↊
+
+* Fix #3.
+* Implement a working, multithreaded renderer forked from MandelbrotSDL.
+* Add more command-line options.
+
# 9
* Remove *\*.ppm* from *.gitignore*.
* Reformat changelog from HTML to Markdown.
* Add an alpha channel to the image data.
-* Use *std::from_chars* instead of *std::stoi* for in argument handler.
+* Use *std::from_chars* instead of *std::stoi* in argument handler.
* Inline the *benoit::wrtimg::iterwrt* lambda expression.
# 8
@@ -53,7 +59,7 @@
* Remove unused variables from Makefile.
* Require the LLP64 data model when compiling.
-* Create working multithrded example.
+* Create working multithreaded example.
* Depend also on libpng.
* Remove JPEG as a supported image format.
@@ -64,7 +70,7 @@
* Create better support for different image formats.
* Remove C-string functions in favour of the ones in &ltcstring&gt.
* Greatly improve debugging.
-* Create foundation for new multithrded multiprecision renderer.
+* Create foundation for new multithreaded multiprecision renderer.
* Remove old renderer.
* Completely remove Rust artifacts.
diff --git a/include/benoit/d/alpha.hh b/include/benoit/d/alpha.hh
new file mode 100644
index 0000000..49f176b
--- /dev/null
+++ b/include/benoit/d/alpha.hh
@@ -0,0 +1,6 @@
+# pragma once
+namespace benoit {
+ namespace d {
+ bool extern alpha;
+ }
+}
diff --git a/include/benoit/d/ver.hh b/include/benoit/d/ver.hh
index ae4b026..95e28b9 100644
--- a/include/benoit/d/ver.hh
+++ b/include/benoit/d/ver.hh
@@ -1,6 +1,6 @@
# pragma once
namespace benoit {
namespace d {
- unsigned long long constexpr ver = 0x9;
+ unsigned long long constexpr ver = 0xA;
}
}
diff --git a/include/benoit/t/pos.hh b/include/benoit/t/pos.hh
index 4725bb6..aa43522 100644
--- a/include/benoit/t/pos.hh
+++ b/include/benoit/t/pos.hh
@@ -5,9 +5,9 @@ namespace benoit {
class pos {
public:
pos(boost::multiprecision::mpfr_float x = 0x0,boost::multiprecision::mpfr_float y = 0x0);
- boost::multiprecision::mpfr_float x = 0x0;
- boost::multiprecision::mpfr_float y = 0x0;
- boost::multiprecision::mpfr_float zoom = 0x0;
+ long double x = 0x0;
+ long double y = 0x0;
+ long double zoom = 0x1;
};
}
}
diff --git a/include/benoit/t/thrddat.hh b/include/benoit/t/thrddat.hh
index 1b691dc..1318c00 100644
--- a/include/benoit/t/thrddat.hh
+++ b/include/benoit/t/thrddat.hh
@@ -7,7 +7,6 @@ namespace benoit {
class thrddat {
public:
pthread_t * thrd = nullptr;
- std::uint8_t * thrdcol = nullptr;
benoit::t::rgba * img = nullptr;
unsigned * id = nullptr;
unsigned long long * imgbegin = nullptr;
diff --git a/src/benoit/arghandl.cc b/src/benoit/arghandl.cc
index 0b0b4cc..d54cde8 100644
--- a/src/benoit/arghandl.cc
+++ b/src/benoit/arghandl.cc
@@ -1,7 +1,9 @@
# include <benoit/archstr.hh>
# include <benoit/arghandl.hh>
+# include <benoit/d/alpha.hh>
# include <benoit/d/dobt.hh>
# include <benoit/d/imgfmt.hh>
+# include <benoit/d/maxiter.hh>
# include <benoit/d/numthrds.hh>
# include <benoit/d/outimg.hh>
# include <benoit/d/resx.hh>
@@ -44,7 +46,15 @@ void benoit::arghandl(int const & argc,char const * * & argv) {
benoit::log(funcname,fmt::format("Found object “{}”.",obj));
std::string val = arg.substr(eqpos + 0x1);
benoit::log(funcname,fmt::format("Found value “{}”.",val));
- if(obj == "force-backtrace"s) {
+ if(obj == "alpha"s) {
+ if(!strtobool.contains(val)) {
+ benoit::print(fmt::format(invalvalforobj,val,obj));
+ }
+ else {
+ benoit::d::alpha = strtobool[val];
+ }
+ }
+ else if(obj == "force-backtrace"s) {
if(!strtobool.contains(val)) {
benoit::print(fmt::format(invalvalforobj,val,obj));
}
@@ -70,6 +80,9 @@ void benoit::arghandl(int const & argc,char const * * & argv) {
benoit::d::resy = 0x10000;
}
}
+ else if(obj == "maximum-iterations"s) {
+ std::from_chars(val.c_str(),(val.c_str() + val.size()),benoit::d::maxiter);
+ }
else if(obj == "output"s) {
benoit::d::outimg = val;
}
diff --git a/src/benoit/d/alpha.cc b/src/benoit/d/alpha.cc
new file mode 100644
index 0000000..65d2dcc
--- /dev/null
+++ b/src/benoit/d/alpha.cc
@@ -0,0 +1,2 @@
+# include <benoit/d/alpha.hh>
+bool benoit::d::alpha = false;
diff --git a/src/benoit/d/logdoprint.cc b/src/benoit/d/logdoprint.cc
index 5b68c6a..71de54b 100644
--- a/src/benoit/d/logdoprint.cc
+++ b/src/benoit/d/logdoprint.cc
@@ -1,7 +1,7 @@
# include <benoit/d/logdoprint.hh>
bool benoit::d::logdoprint =
# if defined(NDEBUG)
- false;
+false;
# else
- true;
+true;
# endif
diff --git a/src/benoit/helpscrn.cc b/src/benoit/helpscrn.cc
index 140f5ef..70dd5c6 100644
--- a/src/benoit/helpscrn.cc
+++ b/src/benoit/helpscrn.cc
@@ -2,6 +2,8 @@
# include <benoit/helpscrn.hh>
# include <benoit/d/arch.hh>
# include <benoit/d/kernel.hh>
+# include <benoit/d/logdoprint.hh>
+# include <benoit/d/printdolog.hh>
# include <benoit/d/ver.hh>
# include <benoit/exit.hh>
# include <benoit/kernelstr.hh>
@@ -20,58 +22,58 @@ using namespace std::literals::string_literals;
std::string time = __TIME__;
std::unordered_map<std::string,std::string> monthmap = {
{
- "Jan",
- "01",
+ "Jan"s,
+ "01"s,
},
{
- "Feb",
- "02",
+ "Feb"s,
+ "02"s,
},
{
- "Mar",
- "03",
+ "Mar"s,
+ "03"s,
},
{
- "Apr",
- "04",
+ "Apr"s,
+ "04"s,
},
{
- "May",
- "05",
+ "May"s,
+ "05"s,
},
{
- "Jun",
- "06",
+ "Jun"s,
+ "06"s,
},
{
- "Jul",
- "07",
+ "Jul"s,
+ "07"s,
},
{
- "Aug",
- "08",
+ "Aug"s,
+ "08"s,
},
{
- "Sep",
- "09",
+ "Sep"s,
+ "09"s,
},
{
- "Oct",
- "10",
+ "Oct"s,
+ "10"s,
},
{
- "Nov",
- "11",
+ "Nov"s,
+ "11"s,
},
{
- "Dec",
- "12",
+ "Dec"s,
+ "12"s,
},
};
std::string year = date.substr(0x7);
std::string month = monthmap[date.substr(0x0,0x3)];
std::string day = date.substr(0x4,0x2);
- cmdate = year + "-"s + month + "-"s + day + "T"s + time;
+ cmdate = fmt::format("{}-{}-{}T{}"s,year,month,day,time);
}
std::string cppver = ""s;
{
@@ -113,17 +115,23 @@ using namespace std::literals::string_literals;
else {
datmod = fmt::format("{} AKA how the fuck did this get compiled?"s,datmod);
}
+ benoit::d::logdoprint = false;
+ benoit::d::printdolog = false;
benoit::print(""s);
benoit::print(fmt::format("benoit {}",benoit::d::ver));
benoit::print("Copyright 2021 Gabriel Jensen"s);
benoit::print(""s);
benoit::print("Arguments:"s);
+ benoit::print("\u0009alpha={false,true}:"s);
+ benoit::print("\u0009\u0009Sets whether or not to use alpha or background colour for rendered image."s);
benoit::print("\u0009force-backtrace={false,true}:"s);
benoit::print("\u0009\u0009Forces the backtrace of the at programme exit."s);
benoit::print("\u0009height={0..65536}:"s);
benoit::print("\u0009\u0009Sets the height for the rendered image."s);
benoit::print("\u0009help, --help:"s);
benoit::print("\u0009\u0009Displays this information screen."s);
+ benoit::print("\u0009maximum-iterations={0..18446744073709551615}:"s);
+ benoit::print("\u0009\u0009Sets the maximum number of iterations allowed."s);
benoit::print("\u0009threads={0..65536}:"s);
benoit::print("\u0009\u0009Sets the number of threads that will be used."s);
benoit::print("\u0009height={0..65536}:"s);
@@ -136,5 +144,7 @@ using namespace std::literals::string_literals;
benoit::print(fmt::format("\u0009Data Model: {}"s,datmod));
benoit::print(fmt::format("\u0009System Kernel: {}"s,benoit::kernelstr(benoit::d::kernel)));
benoit::print(""s);
+ benoit::d::logdoprint = true;
+ benoit::d::printdolog = true;
benoit::exit(EXIT_SUCCESS);
}
diff --git a/src/benoit/plotmandelbrot.cc b/src/benoit/plotmandelbrot.cc
index bbc5f8a..8517c99 100644
--- a/src/benoit/plotmandelbrot.cc
+++ b/src/benoit/plotmandelbrot.cc
@@ -1,3 +1,5 @@
+# include <benoit/d/alpha.hh>
+# include <benoit/d/maxiter.hh>
# include <benoit/d/numthrds.hh>
# include <benoit/d/pos.hh>
# include <benoit/d/resx.hh>
@@ -20,11 +22,38 @@ using namespace std::literals::string_literals;
namespace {
void * plotarea(void * thrddatptr) {
benoit::t::thrddat * thrddat = reinterpret_cast<benoit::t::thrddat *>(thrddatptr);
+ const long double maxR = 0x2p0;
+ const long double minR = -0x2p0;
+ const long double maxI = 0x2p0;
+ const long double minI = -0x2p0;
for(unsigned long long px = *thrddat->imgbegin;(px <= *thrddat->imgend);++px) {
- thrddat->img[px].r = *thrddat->thrdcol;
- thrddat->img[px].g = *thrddat->thrdcol;
- thrddat->img[px].b = *thrddat->thrdcol;
- thrddat->img[px].a = 0xBF;
+ unsigned x = (px % benoit::d::resx);
+ unsigned y = ((px - (px % benoit::d::resy)) / benoit::d::resy);
+ long double r = x * ((maxR + benoit::d::pos.x * benoit::d::pos.zoom) / benoit::d::pos.zoom - (minR + benoit::d::pos.x * benoit::d::pos.zoom) / benoit::d::pos.zoom) / benoit::d::resx + (minR + benoit::d::pos.x * benoit::d::pos.zoom) / benoit::d::pos.zoom;
+ long double i = y * ((maxI + benoit::d::pos.y * benoit::d::pos.zoom) / benoit::d::pos.zoom - (minI + benoit::d::pos.y * benoit::d::pos.zoom) / benoit::d::pos.zoom) / benoit::d::resx + (minI + benoit::d::pos.y * benoit::d::pos.zoom) / benoit::d::pos.zoom;
+ long double r2 = 0x0p0;
+ long double i2 = 0x0p0;
+ unsigned iter;
+ for(iter = 0x0u; iter < benoit::d::maxiter; ++iter) {
+ if(r2 * r2 + i2 * i2 >= 0x4p0) {
+ break;
+ }
+ long double r2Temp = r2 * r2 - i2 * i2 + r;
+ long double i2Temp = 0x2p0 * r2 * i2 + i;
+ if(r2 == r2Temp && i2 == i2Temp) {
+ iter = benoit::d::maxiter;
+ break;
+ }
+ r2 = r2Temp;
+ i2 = i2Temp;
+ }
+ {
+ float tmp = ((float)(iter) / (float)(benoit::d::maxiter));
+ thrddat->img[px].r = static_cast<std::uint8_t>((0x1p0 - tmp) * 0xFFp0);
+ thrddat->img[px].g = static_cast<std::uint8_t>((0x1p0 - tmp) * 0xFFp0);
+ thrddat->img[px].b = static_cast<std::uint8_t>((0x1p0 - tmp) * 0xFFp0);
+ thrddat->img[px].a = static_cast<std::uint8_t>(tmp * 0xFFp0);
+ }
}
pthread_exit(nullptr);
}
@@ -50,77 +79,31 @@ std::vector<std::uint8_t> * benoit::plotmandelbrot() {
--*thrds[thrdid].imgend;
assert(*thrds[thrdid].imgend <= numpx);
remainpx -= (*thrds[thrdid].imgend - *thrds[thrdid].imgbegin + 0x1);
- thrds[thrdid].thrdcol = ::new std::uint8_t((float)(thrdid + 0x1) / (float)(benoit::d::numthrds) * 0xFFp0);
thrds[thrdid].thrd = ::new pthread_t;
- benoit::log(fmt::format("Thread #{} will render a total of {} pixels, starting at position {} and ending at position {}, each with the colour {}, which means there are {} pixels remaining."s,thrdid,(*thrds[thrdid].imgend - *thrds[thrdid].imgbegin + 0x1),*thrds[thrdid].imgbegin,*thrds[thrdid].imgend,*thrds[thrdid].thrdcol,remainpx));
+ benoit::log(fmt::format("Thread #{} will render a total of {} pixels, starting at position {} and ending at position {}, which means there are {} pixels remaining."s,thrdid,(*thrds[thrdid].imgend - *thrds[thrdid].imgbegin + 0x1),*thrds[thrdid].imgbegin,*thrds[thrdid].imgend,remainpx));
::pthread_create(thrds[thrdid].thrd,nullptr,::plotarea,&thrds[thrdid]);
}
for(auto thrd : thrds) {
::pthread_join(*thrd.thrd,nullptr);
- benoit::log(fmt::format("Thread #{}, which coloured it's pixels with {}, has joined."s,*thrd.id,*thrd.thrdcol));
+ benoit::log(fmt::format("Thread #{} has joined."s,*thrd.id));
::delete thrd.id;
::delete thrd.imgbegin;
::delete thrd.imgend;
::delete thrd.thrd;
- ::delete thrd.thrdcol;
}
std::vector<std::uint8_t> * img = ::new std::vector<std::uint8_t>;
for(unsigned long long pos = 0x0ull;(pos < numpx);++pos) {
img->push_back(rgbaimg[pos].r);
img->push_back(rgbaimg[pos].g);
img->push_back(rgbaimg[pos].b);
- img->push_back(rgbaimg[pos].a);
+ if(benoit::d::alpha) {
+ img->push_back(rgbaimg[pos].a);
+ }
+ else {
+ img->push_back(0xFF);
+ }
}
::delete rgbaimg;
benoit::logfuncret(funcname);
return img;
}
-/*
-const double maxR = 2.25;
-const double minR = -2.25;
-const double maxI = 2.25;
-const double minI = -2.25;
-
-for(unsigned int y = 0; y < benoit::d::resy; ++y)
- for(unsigned int x = 0; x < benoit::d::resx; ++x) {
- long double r = x * ((maxR + benoit::real * benoit::d::zoom) / benoit::d::zoom - (minR + benoit::real * benoit::d::zoom) / benoit::d::zoom) / benoit::d::resx + (minR + benoit::real * benoit::d::zoom) / benoit::d::zoom;
- long double i = y * ((maxI + benoit::imag * benoit::d::zoom) / benoit::d::zoom - (minI + benoit::imag * benoit::d::zoom) / benoit::d::zoom) / benoit::d::resx + (minI + benoit::imag * benoit::d::zoom) / benoit::d::zoom;
- long double r2 = 0.0;
- long double i2 = 0.0;
-
- unsigned int iter;
- for(iter = 0; iter < benoit::maxiter; ++iter) {
- if(r2 * r2 + i2 * i2 >= 4.0)
- break;
-
- long double r2Temp = r2 * r2 - i2 * i2 + r;
- long double i2Temp = 2.0 * r2 * i2 + i;
-
- if(r2 == r2Temp && i2 == i2Temp) {
- iter = benoit::maxiter;
- break;
- }
-
- r2 = r2Temp;
- i2 = i2Temp;
- }
-
- std::uint8_t blue = 0x0;
- std::uint8_t green = 0x0;
- std::uint8_t red = 0x0;
-
- if(iter != benoit::maxiter) {
- float tmp = ((float)(iter) / (float)(benoit::maxiter));
- blue = (std::uint8_t)((1.0 - tmp) * 255.0);
- green = (std::uint8_t)((1.0 - tmp) * 255.0);
- red = (std::uint8_t)((1.0 - tmp) * 255.0);
- //double t = (double)(iter) / (double)(benoit::maxiter);
- //red = (int)(8.0 * (1.0 - t) * t * t * t * 255.0);
- //green = (int)(16.0 * (1.0 - t) * (1.0 - t) * t * t * 255.0);
- //blue = (int)(8.0 * (1.0 - t) * (1.0 - t) * (1.0 - t) * t * 255.0);
- }
- buf.push_back(blue);
- buf.push_back(green);
- buf.push_back(red);
- }
-*/
diff --git a/src/benoit/t/pos/pos.cc b/src/benoit/t/pos/pos.cc
index f1237e0..a69f8ec 100644
--- a/src/benoit/t/pos/pos.cc
+++ b/src/benoit/t/pos/pos.cc
@@ -1,6 +1,6 @@
# include <benoit/t/pos.hh>
# include <boost/multiprecision/mpfr.hpp>
benoit::t::pos::pos(boost::multiprecision::mpfr_float x,boost::multiprecision::mpfr_float y) {
- this->x = x;
- this->y = y;
+ //this->x = x;
+ //this->y = y;
}