diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/benoit/crtcfg.cc | 30 | ||||
-rw-r--r-- | src/benoit/d/cfg.cc | 2 | ||||
-rw-r--r-- | src/benoit/err/clsfil.cc | 8 | ||||
-rw-r--r-- | src/benoit/err/wrttofil.cc | 8 | ||||
-rw-r--r-- | src/benoit/helpscrn.cc | 4 | ||||
-rw-r--r-- | src/benoit/loadcfg.cc | 35 | ||||
-rw-r--r-- | src/benoit/main.cc | 1 | ||||
-rw-r--r-- | src/benoit/plotmandelbrot.cc | 106 | ||||
-rw-r--r-- | src/benoit/print.cc | 12 | ||||
-rw-r--r-- | src/benoit/t/pos/pos.cc | 7 | ||||
-rw-r--r-- | src/benoit/wrtimg.cc | 18 |
11 files changed, 168 insertions, 63 deletions
diff --git a/src/benoit/crtcfg.cc b/src/benoit/crtcfg.cc index 202016c..6784467 100644 --- a/src/benoit/crtcfg.cc +++ b/src/benoit/crtcfg.cc @@ -1,10 +1,40 @@ # include <benoit/crtcfg.hh> +# include <benoit/d/cfg.hh> +# include <benoit/err/clsfil.hh> +# include <benoit/err/wrttofil.hh> # include <benoit/logfunc.hh> # include <benoit/logfuncret.hh> +# include <benoit/print.hh> +# include <cstdint> +# include <fcntl.h> +# include <fmt/core.h> # include <string> +# include <unistd.h> using namespace std::literals::string_literals; void benoit::crtcfg() { std::string const funcname = "benoit::crtcfg()"s; benoit::logfunc(funcname); + std::string cfgstr = ""s; + cfgstr.append("{\u000A"s); + cfgstr.append("\u0009\u0022benoit\u0022:[\u000A"s); + cfgstr.append("\u0009\u0009{\u000A"s); + cfgstr.append("\u0009\u0009\u0009\u0022x\u0022:\u00221÷1\u0022,\u000A"s); + cfgstr.append("\u0009\u0009\u0009\u0022y\u0022:\u00221÷1\u0022,\u000A"s); + cfgstr.append("\u0009\u0009\u0009\u0022zoom\u0022:\u00220÷1\u0022\u000A"s); + cfgstr.append("\u0009\u0009}\u000A"s); + cfgstr.append("\u0009]\u000A"s); + cfgstr.append("}\u000A"s); + std::uint8_t * dat = reinterpret_cast<std::uint8_t *>(const_cast<char *>(cfgstr.c_str())); + int fil = ::open(benoit::d::cfg.c_str(),(O_CREAT | O_TRUNC | O_WRONLY),0x1B4); + for(unsigned long long pos = 0x0;(pos < cfgstr.size());++pos) { + ::ssize_t byteswrtn = ::write(fil,&dat[pos],0x1); + if(byteswrtn < 0x0) { + benoit::err::wrttofil(benoit::d::cfg); + return; + } + } + if(::close(fil) < 0x0) { + benoit::err::clsfil(benoit::d::cfg); + } benoit::logfuncret(funcname); } diff --git a/src/benoit/d/cfg.cc b/src/benoit/d/cfg.cc index 7b9cf99..0f8e82c 100644 --- a/src/benoit/d/cfg.cc +++ b/src/benoit/d/cfg.cc @@ -1,4 +1,4 @@ # include <benoit/d/cfg.hh> # include <string> using namespace std::literals::string_literals; -std::string benoit::d::cfg = "benoit.xml"s; +std::string benoit::d::cfg = "benoit.json"s; diff --git a/src/benoit/err/clsfil.cc b/src/benoit/err/clsfil.cc new file mode 100644 index 0000000..548ce7a --- /dev/null +++ b/src/benoit/err/clsfil.cc @@ -0,0 +1,8 @@ +# include <benoit/err/clsfil.hh> +# include <benoit/print.hh> +# include <fmt/core.h> +# include <string> +using namespace std::literals::string_literals; +void benoit::err::clsfil(std::string const fil) noexcept { + benoit::print(fmt::format("Unable to close file “{}”."s,fil),true); +} diff --git a/src/benoit/err/wrttofil.cc b/src/benoit/err/wrttofil.cc new file mode 100644 index 0000000..eb756f9 --- /dev/null +++ b/src/benoit/err/wrttofil.cc @@ -0,0 +1,8 @@ +# include <benoit/err/wrttofil.hh> +# include <benoit/print.hh> +# include <fmt/core.h> +# include <string> +using namespace std::literals::string_literals; +void benoit::err::wrttofil(std::string const fil) noexcept { + benoit::print(fmt::format("Unable to write to “{}”."s,fil),true); +} diff --git a/src/benoit/helpscrn.cc b/src/benoit/helpscrn.cc index 70dd5c6..02ef215 100644 --- a/src/benoit/helpscrn.cc +++ b/src/benoit/helpscrn.cc @@ -115,11 +115,13 @@ using namespace std::literals::string_literals; else { datmod = fmt::format("{} AKA how the fuck did this get compiled?"s,datmod); } + bool logdoprint = benoit::d::logdoprint; 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("All rigths reserved."s); benoit::print(""s); benoit::print("Arguments:"s); benoit::print("\u0009alpha={false,true}:"s); @@ -144,7 +146,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::logdoprint = logdoprint; benoit::d::printdolog = true; benoit::exit(EXIT_SUCCESS); } diff --git a/src/benoit/loadcfg.cc b/src/benoit/loadcfg.cc index 937d5a8..b1be003 100644 --- a/src/benoit/loadcfg.cc +++ b/src/benoit/loadcfg.cc @@ -1,15 +1,48 @@ # include <benoit/crtcfg.hh> # include <benoit/d/cfg.hh> +# include <benoit/d/pos.hh> # include <benoit/loadcfg.hh> +# include <benoit/log.hh> +# include <benoit/logfunc.hh> +# include <benoit/logfuncret.hh> +# include <benoit/print.hh> +# include <fcntl.h> +# include <fmt/core.h> # include <iostream> -# include <pugixml.hpp> # include <string> +# include <sys/stat.h> # include <unistd.h> +# include <iostream> using namespace std::literals::string_literals; void benoit::loadcfg() { std::string const funcname = "benoit::loadcfg()"s; + benoit::logfunc(funcname); if(::access(benoit::d::cfg.c_str(),R_OK) < 0x0) { benoit::crtcfg(); return; } + int filsiz = 0x0; + { + struct ::stat st; + ::stat(benoit::d::cfg.c_str(),&st); + filsiz = static_cast<int>(st.st_size); + } + benoit::log(fmt::format("The size of “{}” is {}."s,benoit::d::cfg,filsiz)); + if(filsiz == 0x0) { + benoit::crtcfg(); + return; + } + std::string cfgstr = ""s; + { + int fil = ::open(benoit::d::cfg.c_str(),O_RDONLY); + char * cfgcstr = ::new char[filsiz]; + for(int pos = 0x0;(pos < filsiz);++pos) { + if(::read(fil,&cfgcstr[pos],0x1) < 0x0) { + } + } + cfgstr = std::string(cfgcstr); + delete[] cfgcstr; + ::close(fil); + } + benoit::logfuncret(funcname); } diff --git a/src/benoit/main.cc b/src/benoit/main.cc index 267f7f1..fbddfa2 100644 --- a/src/benoit/main.cc +++ b/src/benoit/main.cc @@ -20,7 +20,6 @@ static_assert(((sizeof(short) >= 0x2) && (sizeof(int) >= 0x4) && (sizeof(long) > using namespace std::literals::string_literals; [[noreturn]] void benoit::main(int const argc,char const * * argv) noexcept { std::string const funcname = "benoit::main(int const,char const * *)"s; - benoit::log(fmt::format("{}"s,argv[0x0])); benoit::logfunc(funcname); benoit::d::numthrds = std::thread::hardware_concurrency(); benoit::log(fmt::format("{} availabe threads have been detected."s,benoit::d::numthrds)); diff --git a/src/benoit/plotmandelbrot.cc b/src/benoit/plotmandelbrot.cc index 8517c99..6d3b993 100644 --- a/src/benoit/plotmandelbrot.cc +++ b/src/benoit/plotmandelbrot.cc @@ -11,8 +11,7 @@ # include <benoit/print.hh> # include <benoit/t/thrddat.hh> # include <benoit/t/rgba.hh> -# include <boost/multiprecision/mpfr.hpp> -# include <cassert> +# include <cmath> # include <cstdint> # include <fmt/core.h> # include <pthread.h> @@ -22,37 +21,54 @@ 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) { 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) { + ::__float128 r = x * ((0x2p0 + benoit::d::pos.x * benoit::d::pos.zoom) / benoit::d::pos.zoom - (-0x2p0 + benoit::d::pos.x * benoit::d::pos.zoom) / benoit::d::pos.zoom) / benoit::d::resx + (-0x2p0 + benoit::d::pos.x * benoit::d::pos.zoom) / benoit::d::pos.zoom; + ::__float128 i = y * ((0x2p0 + benoit::d::pos.y * benoit::d::pos.zoom) / benoit::d::pos.zoom - (-0x2p0 + benoit::d::pos.y * benoit::d::pos.zoom) / benoit::d::pos.zoom) / benoit::d::resx + (-0x2p0 + benoit::d::pos.y * benoit::d::pos.zoom) / benoit::d::pos.zoom; + ::__float128 r1 = 0x0p0; + ::__float128 i1 = 0x0p0; + unsigned long long iter = 0x0ull; + for(;(iter < benoit::d::maxiter);++iter) { + if((r1 * r1 + i1 * i1) >= 0x4p0) { break; } - long double r2Temp = r2 * r2 - i2 * i2 + r; - long double i2Temp = 0x2p0 * r2 * i2 + i; - if(r2 == r2Temp && i2 == i2Temp) { + ::__float128 r1tmp = (r1 * r1 - i1 * i1 + r); + ::__float128 i1tmp = (0x2p0 * r1 * i1 + i); + if((r1 == r1tmp) && (i1 == i1tmp)) { iter = benoit::d::maxiter; break; } - r2 = r2Temp; - i2 = i2Temp; + r1 = r1tmp; + i1 = i1tmp; } - { - 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); + if(iter != benoit::d::maxiter) { + float fac = (static_cast<float>(iter) / 0x40p0); + fac = (fac - std::floor(fac)); + if(fac <= (0x1p0 / 0x4p0)) { + thrddat->img[px].r = static_cast<std::uint8_t>(fac * 0xFFp0 * 0x4p0); + thrddat->img[px].g = static_cast<std::uint8_t>(0x0p0); + thrddat->img[px].b = static_cast<std::uint8_t>(0x0p0); + } + else if(fac <= (0x1p0 / 0x2p0)) { + thrddat->img[px].r = static_cast<std::uint8_t>(0xFFp0); + thrddat->img[px].g = static_cast<std::uint8_t>(fac * 0xFFp0 * 0x4p0); + thrddat->img[px].b = static_cast<std::uint8_t>(0x0p0); + } + else if(fac <= (0x3p0 / 0x4p0)) { + thrddat->img[px].r = static_cast<std::uint8_t>(0xFFp0); + thrddat->img[px].g = static_cast<std::uint8_t>(0xFFp0); + thrddat->img[px].b = static_cast<std::uint8_t>(fac * 0xFFp0 * 0x4p0); + } + else { + fac = (0x1p0 - fac); + thrddat->img[px].r = static_cast<std::uint8_t>(fac * 0xFFp0 * 0x4p0); + thrddat->img[px].g = static_cast<std::uint8_t>(fac * 0xFFp0 * 0x4p0); + thrddat->img[px].b = static_cast<std::uint8_t>(fac * 0xFFp0 * 0x4p0); + } + } + else { + thrddat->img[px].a = 0x0u; } } pthread_exit(nullptr); @@ -67,28 +83,40 @@ std::vector<std::uint8_t> * benoit::plotmandelbrot() { benoit::t::rgba * rgbaimg = ::new benoit::t::rgba[numpx]; std::vector<benoit::t::thrddat> thrds(benoit::d::numthrds); for(unsigned thrdid = 0x0;(thrdid < benoit::d::numthrds);++thrdid) { - thrds[thrdid].id = ::new unsigned(thrdid); - thrds[thrdid].img = rgbaimg; - thrds[thrdid].imgbegin = ::new unsigned long long(numpx / benoit::d::numthrds * thrdid); - if((thrdid + 0x1) == benoit::d::numthrds) { - thrds[thrdid].imgend = ::new unsigned long long(*thrds[thrdid].imgbegin + remainpx); + benoit::log(fmt::format("Allocating data for thread #{}."s,thrdid)); + thrds[thrdid].id = ::new unsigned(thrdid); + thrds[thrdid].img = rgbaimg; + thrds[thrdid].isrun = ::new bool(false); + thrds[thrdid].thrd = ::new pthread_t; + } + for(unsigned thrdid = 0x0,y = 0x0u;(y < benoit::d::resy);++thrdid,++y) { + if(remainpx == 0x0) { + break; } - else { - thrds[thrdid].imgend = ::new unsigned long long(*thrds[thrdid].imgbegin + numpx / benoit::d::numthrds); + if(thrdid == benoit::d::numthrds) { + thrdid = 0x0; } - --*thrds[thrdid].imgend; - assert(*thrds[thrdid].imgend <= numpx); - remainpx -= (*thrds[thrdid].imgend - *thrds[thrdid].imgbegin + 0x1); - thrds[thrdid].thrd = ::new pthread_t; - 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)); + if(*thrds[thrdid].isrun) { + pthread_join(*thrds[thrdid].thrd,nullptr); + delete thrds[thrdid].isrun; + thrds[thrdid].isrun = ::new bool(false); + } + thrds[thrdid].imgbegin = ::new unsigned long long(y * benoit::d::resx); + thrds[thrdid].imgend = ::new unsigned long long(*thrds[thrdid].imgbegin + benoit::d::resx - 0x1); ::pthread_create(thrds[thrdid].thrd,nullptr,::plotarea,&thrds[thrdid]); + delete thrds[thrdid].isrun; + thrds[thrdid].isrun = ::new bool(true); } for(auto thrd : thrds) { - ::pthread_join(*thrd.thrd,nullptr); - benoit::log(fmt::format("Thread #{} has joined."s,*thrd.id)); + benoit::log(fmt::format("Destroying thread #{}'s data."s,*thrd.id)); + if(*thrd.isrun) { + ::pthread_join(*thrd.thrd,nullptr); + } + thrd.img = nullptr; ::delete thrd.id; ::delete thrd.imgbegin; ::delete thrd.imgend; + ::delete thrd.isrun; ::delete thrd.thrd; } std::vector<std::uint8_t> * img = ::new std::vector<std::uint8_t>; @@ -103,7 +131,7 @@ std::vector<std::uint8_t> * benoit::plotmandelbrot() { img->push_back(0xFF); } } - ::delete rgbaimg; + ::delete[] rgbaimg; benoit::logfuncret(funcname); return img; } diff --git a/src/benoit/print.cc b/src/benoit/print.cc index e1488bd..6d9d953 100644 --- a/src/benoit/print.cc +++ b/src/benoit/print.cc @@ -6,22 +6,18 @@ # include <string> # include <unistd.h> using namespace std::literals::string_literals; -void benoit::print(char const * msg,bool stderr) { - std::string const funcname = "benoit::print(char const *,bool)"s; - benoit::print(std::string(msg),stderr); -} void benoit::print(std::string msg,bool stderr) { std::string const funcname = "benoit::print(std::string,bool)"s; if(benoit::d::printdolog) { benoit::d::thelog.insert(benoit::d::thelog.begin(),msg); } msg.append("\u000A"s); - int file = 0x0; + int fil = 0x0; if(stderr) { - file = 0x1; + fil = 0x1; } - if(::write(file,msg.c_str(),msg.size()) < 0x0) { + if(::write(fil,msg.c_str(),msg.size()) < 0x0) { throw std::runtime_error("Unable to write to Stdout."); } - fsync(file); + fsync(fil); } diff --git a/src/benoit/t/pos/pos.cc b/src/benoit/t/pos/pos.cc index a69f8ec..50fa2df 100644 --- a/src/benoit/t/pos/pos.cc +++ b/src/benoit/t/pos/pos.cc @@ -1,6 +1,5 @@ # 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; +benoit::t::pos::pos(__float128 x,__float128 y) { + this->x = x; + this->y = y; } diff --git a/src/benoit/wrtimg.cc b/src/benoit/wrtimg.cc index 0f10257..1053a9e 100644 --- a/src/benoit/wrtimg.cc +++ b/src/benoit/wrtimg.cc @@ -2,6 +2,8 @@ # include <benoit/d/outimg.hh> # include <benoit/d/resx.hh> # include <benoit/d/resy.hh> +# include <benoit/err/clsfil.hh> +# include <benoit/err/wrttofil.hh> # include <benoit/logfunc.hh> # include <benoit/logfuncret.hh> # include <benoit/print.hh> @@ -23,7 +25,7 @@ void benoit::wrtimg(std::vector<std::uint8_t> * img) { std::string const funcname = "benoit::wrtimg(std::vector<std::uint8_t> *)"s; benoit::logfunc(funcname); std::uint8_t * dat; - unsigned long long datsiz; + unsigned long long datsiz = 0x0; switch(benoit::d::imgfmt) { case benoit::t::imgfmt::png: break; @@ -31,18 +33,18 @@ void benoit::wrtimg(std::vector<std::uint8_t> * img) { datsiz = WebPEncodeLosslessRGBA(img->data(),benoit::d::resx,benoit::d::resy,(benoit::d::resx * 0x4),&dat); break; } - int file = ::open(benoit::d::outimg.c_str(),(O_CREAT | O_TRUNC | O_WRONLY),0x1B4); + int fil = ::open(benoit::d::outimg.c_str(),(O_CREAT | O_TRUNC | O_WRONLY),0x1B4); for(unsigned long long pos = 0x0;(pos < datsiz);++pos) { - ::ssize_t byteswrtn = ::write(file,&dat[pos],0x1); + ::ssize_t byteswrtn = ::write(fil,&dat[pos],0x1); if(byteswrtn < 0x0) { - benoit::print(fmt::format("Unable to write to “{}”."s,benoit::d::outimg)); + benoit::err::wrttofil(benoit::d::outimg); return; } } delete dat; delete img; - if(::close(file) < 0x0) { - benoit::print(fmt::format("Unable to close file “{}”."s,benoit::d::outimg)); + if(::close(fil) < 0x0) { + benoit::err::clsfil(benoit::d::outimg); } benoit::logfuncret(funcname); } @@ -86,8 +88,8 @@ auto buf = std::vector<std::uint8_t>(); buf.push_back(0xFF); buf.push_back(0x0); buf.push_back(0x0); -auto file = std::fstream(benoit::outimt,std::fstream::binary | std::fstream::out | std::fstream::trunc); -if(!file.is_open()) { +auto fil = std::fstream(benoit::outimt,std::fstream::binary | std::fstream::out | std::fstream::trunc); +if(!fil.is_open()) { ::_exit(EXIT_FAILURE); } */ |