summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile9
-rwxr-xr-xbenoitbin22112 -> 29736 bytes
-rw-r--r--changelog.html11
-rw-r--r--include/benoit.hh54
-rw-r--r--src/benoit/arghandl.cc16
-rw-r--r--src/benoit/benoit.cc112
-rw-r--r--src/benoit/exit.cc13
-rw-r--r--src/benoit/notiffunc.cc9
-rw-r--r--src/benoit/plotmandelbrot.cc15
-rw-r--r--src/benoit/print.cc23
-rw-r--r--src/benoit/strlen.cc9
-rw-r--r--src/benoit/t/pos/pos.cc6
-rw-r--r--src/benoit/~benoit.cc10
13 files changed, 199 insertions, 88 deletions
diff --git a/Makefile b/Makefile
index 9f9627a..7c2a4a9 100644
--- a/Makefile
+++ b/Makefile
@@ -8,13 +8,18 @@ CXXFLAGS += -DLUMA__X=true
endif
CXXFLAGS += -std=c++20 -Wall -Wextra -Wpedantic
CXXFLAGS += -march=native -mtune=native -O3
-LDFLAGS = -lfmt -lwebp
+LDFLAGS = -lfmt -lgmp -lmpfr -lpthread -lwebp
HDRS_CXX = \
include/benoit.hh
SRCS_CXX = \
+ src/benoit/arghandl.cc \
src/benoit/benoit.cc \
+ src/benoit/~benoit.cc \
+ src/benoit/exit.cc \
+ src/benoit/notiffunc.cc \
+ src/benoit/plotmandelbrot.cc \
src/benoit/print.cc \
- src/benoit/strlen.cc \
+ src/benoit/t/pos/pos.cc \
src/main.cc
SRCS=$(SRCS_CXX)
OBJS=$(SRCS:.cc=.o)
diff --git a/benoit b/benoit
index 9b1796d..6855391 100755
--- a/benoit
+++ b/benoit
Binary files differ
diff --git a/changelog.html b/changelog.html
index 266196b..13579bd 100644
--- a/changelog.html
+++ b/changelog.html
@@ -4,6 +4,17 @@
<meta charset="utf-8">
</head>
<body>
+ <h1>2</h1>
+ <ul>
+ <li>Cleanup code.</li>
+ <li>Create argument handler.</li>
+ <li>Create better support for different image formats.</li>
+ <li>Remove C-string functions in favour of the ones in &ltcstring&gt.</li>
+ <li>Greatly improve debugging.</li>
+ <li>Create foundation for new multithreaded multiprecision renderer.</li>
+ <li>Remove old renderer.</li>
+ <li>Completely remove Rust artifacts.</li>
+ </ul>
<h1>1</h1>
<ul>
<li>Add changelog.</li>
diff --git a/include/benoit.hh b/include/benoit.hh
index 09907aa..da4a2e8 100644
--- a/include/benoit.hh
+++ b/include/benoit.hh
@@ -1,26 +1,50 @@
# if !defined(BENOIT__HEADER)
# define BENOIT__HEADER
+# include <boost/multiprecision/mpfr.hpp>
# include <cstddef>
# include <cstdint>
+# include <string>
# include <vector>
+using namespace std::literals::string_literals;
class benoit {
public:
- benoit(int const argc,char const * * argv);
+ [[noreturn]] benoit(int const argc,char const * * argv) noexcept;
+ [[noreturn]] ~benoit() noexcept;
private:
- enum class imgfmt_t {
- jpeg,
- png,
- ppm,
- webp,
+ class t {
+ public:
+ enum class imgfmt {
+ jpeg,
+ png,
+ ppm,
+ webp,
+ };
+ class pos {
+ public:
+ boost::multiprecision::mpfr_float x = 0x0;
+ boost::multiprecision::mpfr_float y = 0x0;
+ pos(boost::multiprecision::mpfr_float x = 0x0,boost::multiprecision::mpfr_float y = 0x0);
+ };
};
- benoit::imgfmt_t imgfmt = benoit::imgfmt_t::ppm;
- long resx = 0x4000;
- long resy = 0x4000;
- long double imag = 0x0p0;
- long double real = 0x0p0;
- long double zoom = 0x1p0;
- unsigned long long maxiter = 0x100;
- void print(char const * msg);
- std::size_t strlen(char const * str) noexcept;
+ benoit::t::imgfmt imgfmt = benoit::t::imgfmt::ppm;
+ benoit::t::pos pos;
+ bool constexpr static debug =
+# if defined(NDEBUG)
+ false;
+# else
+ true;
+# endif
+ std::string outimg = "image";
+ long resx = 0x2000;
+ long resy = 0x2000;
+ long double zoom = 0x1p0;
+ long long ver = 0x3;
+ unsigned long long maxiter = 0x400;
+ std::vector<std::uint8_t> plotmandelbrot();
+ void arghandl(int const & argc,char const * * & argv);
+ [[noreturn]] void exit(int code,std::string msg = ""s) noexcept;
+ void notiffunc(std::string const callfuncname);
+ void print(char const * msg,bool stderr = false);
+ void print(std::string msg,bool stderr = false);
};
# endif
diff --git a/src/benoit/arghandl.cc b/src/benoit/arghandl.cc
new file mode 100644
index 0000000..059728b
--- /dev/null
+++ b/src/benoit/arghandl.cc
@@ -0,0 +1,16 @@
+# include <benoit.hh>
+# include <fmt/core.h>
+void benoit::arghandl(int const & argc,char const * * & argv) {
+ std::string const funcname = "benoit::arghandl(int const &,char const * * &)"s;
+ this->notiffunc(funcname);
+ if(argc < 0x2) {
+ return;
+ }
+ for(int pos = 0x1;(pos < argc);++pos) {
+ std::string arg = argv[pos];
+ if(arg == "--help") {
+ this->print(fmt::format("benoit {}",this->ver));
+ this->exit(EXIT_SUCCESS);
+ }
+ }
+}
diff --git a/src/benoit/benoit.cc b/src/benoit/benoit.cc
index 7fee86d..7f74282 100644
--- a/src/benoit/benoit.cc
+++ b/src/benoit/benoit.cc
@@ -2,39 +2,51 @@
# include <cstdint>
# include <cstdlib>
# include <fcntl.h>
+# include <fmt/core.h>
# include <string>
# include <unistd.h>
# include <vector>
# include <webp/encode.h>
# include <webp/types.h>
using namespace std::literals::string_literals;
-benoit::benoit(int const argc,char const * * argv) {
- /*
- let mut x0 = 0x0;
- let mut y0 = 0x0;
- let maxiter = 0x100;
- let mut pos = 0x1;
- while pos <= (resx * resy) {
- let mut x = 0x0;
- let mut y = 0x0;
- let mut iter = 0x1;
- while x * x + y * y <= 0x4 && iter <= maxiter {
- let xtmp = x * x - y * y + x0;
- y = 2 * x * y + y0;
- x = xtmp;
- iter += 0x1;
- }
- if iter == maxiter {
- buf.push(0xFF);
- }
- else {
- buf.push(0x0);
- }
- buf.push(0x0);
- buf.push(0xFF);
- pos += 0x1;
+[[noreturn]] benoit::benoit(int const argc,char const * * argv) noexcept {
+ std::string const funcname = "benoit::benoit(int const,char const * *)"s;
+ this->notiffunc(funcname);
+ this->arghandl(argc,argv);
+ switch(this->imgfmt) {
+ case benoit::t::imgfmt::jpeg:
+ this->outimg.append(".jpeg"s);
+ break;
+ case benoit::t::imgfmt::png:
+ this->outimg.append(".png"s);
+ break;
+ case benoit::t::imgfmt::ppm:
+ this->outimg.append(".ppm"s);
+ break;
+ case benoit::t::imgfmt::webp:
+ if((this->resx > 0x1000) || (this->resy > 0x1000)) {
+ this->exit(EXIT_FAILURE,"WebP does not support a resolution of more than 4096"s);
+ }
+ this->outimg.append(".webp"s);
+ break;
}
- */
+ this->exit(EXIT_SUCCESS);
+ std::vector<std::uint8_t> buf = this->plotmandelbrot();
+ int file = ::open(this->outimg.c_str(),O_TRUNC | O_WRONLY);
+ std::string msg = ("P3 "s + std::to_string(this->resx) + " "s +std::to_string(this->resy) + " 255 "s);
+ for(auto val : buf) {
+ msg.append(std::to_string(val));
+ msg.append(" ");
+ }
+ if(::write(file,msg.c_str(),std::strlen(msg.c_str())) < 0x0) {
+ this->print(fmt::format("Unable to write to \"{}\"."s,this->outimg));
+ }
+ if(::close(file) < 0x0) {
+ this->print(fmt::format("Unable to close file \"{]\"."s,this->outimg));
+ }
+ this->exit(EXIT_SUCCESS);
+}
+# if 0x0
/*
auto webpconf = ::WebPConfig();
webpconf.lossless = 0x1;
@@ -76,18 +88,17 @@ benoit::benoit(int const argc,char const * * argv) {
//buf.push_back(0xFF);
//buf.push_back(0x0);
//buf.push_back(0x0);
- //auto file = std::fstream("image.webp",std::fstream::binary | std::fstream::out | std::fstream::trunc);
+ //auto file = std::fstream(this->outimt,std::fstream::binary | std::fstream::out | std::fstream::trunc);
//if(!file.is_open()) {
// ::_exit(EXIT_FAILURE);
//}
- auto buf = std::vector<std::uint8_t>();
const double maxR = 2.25;
const double minR = -2.25;
const double maxI = 2.25;
const double minI = -2.25;
- for(unsigned int x = 0; x < this->resx; ++x)
- for(unsigned int y = 0; y < this->resy; ++y) {
+ for(unsigned int y = 0; y < this->resy; ++y)
+ for(unsigned int x = 0; x < this->resx; ++x) {
long double r = x * ((maxR + this->real * this->zoom) / this->zoom - (minR + this->real * this->zoom) / this->zoom) / this->resx + (minR + this->real * this->zoom) / this->zoom;
long double i = y * ((maxI + this->imag * this->zoom) / this->zoom - (minI + this->imag * this->zoom) / this->zoom) / this->resx + (minI + this->imag * this->zoom) / this->zoom;
long double r2 = 0.0;
@@ -110,35 +121,22 @@ benoit::benoit(int const argc,char const * * argv) {
i2 = i2Temp;
}
- unsigned short int red = 0;
- unsigned short int green = 0;
- unsigned short int blue = 0;
+ std::uint8_t blue = 0x0;
+ std::uint8_t green = 0x0;
+ std::uint8_t red = 0x0;
if(iter != this->maxiter) {
- double t = (double)(iter) / (double)(this->maxiter);
- red = (int)(9.0 * (1.0 - t) * t * t * t * 255.0);
- green = (int)(15.0 * (1.0 - t) * (1.0 - t) * t * t * 255.0);
- blue = (int)(8.5 * (1.0 - t) * (1.0 - t) * (1.0 - t) * t * 255.0);
+ float tmp = ((float)(iter) / (float)(this->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)(this->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(red);
- buf.push_back(green);
buf.push_back(blue);
+ buf.push_back(green);
+ buf.push_back(red);
}
- auto file = ::open("image.webp",O_WRONLY);
- //std::uint8_t * data;
- //auto outimglen = WebPEncodeLosslessRGB(buf.data(),this->resx,this->resy,0x8,&data);
- //file.write(reinterpret_cast<char *>(data),outimglen);
- std::string msg = ("P3 "s + std::to_string(this->resx) + " "s +std::to_string(this->resy) + " 255 "s);
- for(auto val : buf) {
- msg.append(std::to_string(val));
- msg.append(" ");
- }
- if(::write(file,msg.c_str(),this->strlen(msg.c_str())) < 0x0) {
- this->print("Unable to write to \"image.webp\".");
- }
- if(::close(file) < 0x0) {
- this->print("Unable to close file \"image.webp\".");
- }
- //file.close();
- ::_exit(EXIT_SUCCESS);
-}
+# endif
diff --git a/src/benoit/exit.cc b/src/benoit/exit.cc
new file mode 100644
index 0000000..e408b9c
--- /dev/null
+++ b/src/benoit/exit.cc
@@ -0,0 +1,13 @@
+# include <benoit.hh>
+# include <fmt/core.h>
+# include <string>
+# include <unistd.h>
+using namespace std::literals::string_literals;
+[[noreturn]] void benoit::exit(int code,std::string msg) noexcept {
+ std::string const funcname = "benoit::exit(int,std::string)"s;
+ this->notiffunc(funcname);
+ if(msg != ""s) {
+ this->print(fmt::format("Exited with error code {}: {}",code,msg),true);
+ }
+ ::_exit(code);
+}
diff --git a/src/benoit/notiffunc.cc b/src/benoit/notiffunc.cc
new file mode 100644
index 0000000..bb2152c
--- /dev/null
+++ b/src/benoit/notiffunc.cc
@@ -0,0 +1,9 @@
+# include <benoit.hh>
+# include <fmt/core.h>
+# include <string>
+void benoit::notiffunc(std::string const callfuncname) {
+ std::string const funcname = "benoit::notiffunc(std:.string constexpr)"s;
+ if constexpr(benoit::debug) {
+ this->print(fmt::format("Function \"{}\" has been called."s,callfuncname));
+ }
+}
diff --git a/src/benoit/plotmandelbrot.cc b/src/benoit/plotmandelbrot.cc
new file mode 100644
index 0000000..a4bf074
--- /dev/null
+++ b/src/benoit/plotmandelbrot.cc
@@ -0,0 +1,15 @@
+# include <benoit.hh>
+# include <boost/multiprecision/mpfr.hpp>
+# include <cstdint>
+# include <vector>
+/*
+namespace {
+ void static * plotarea();
+}
+*/
+std::vector<std::uint8_t> benoit::plotmandelbrot() {
+ std::string const funcname = "benoit::plotmandelbrot()"s;
+ this->notiffunc(funcname);
+ std::vector<std::uint8_t> img;
+ return img;
+}
diff --git a/src/benoit/print.cc b/src/benoit/print.cc
index 441cfd5..7f7901c 100644
--- a/src/benoit/print.cc
+++ b/src/benoit/print.cc
@@ -1,13 +1,26 @@
# include <benoit.hh>
# include <fcntl.h>
# include <stdexcept>
+# include <string>
# include <unistd.h>
-void benoit::print(char const * msg) {
- auto file = ::open("/dev/stdout",O_WRONLY);
- if(::write(file,msg,this->strlen(msg)) < 0x0) {
- throw std::runtime_error("Unable to write to Stdout.\u000A");
+void benoit::print(char const * msg,bool stderr) {
+ std::string const funcname = "benoit::print(char const *)"s;
+ this->print(std::string(msg),stderr);
+}
+void benoit::print(std::string msg,bool stderr) {
+ std::string const funcname = "benoit::print(std::string)"s;
+ int file = 0x0;
+ if(stderr) {
+ ::open("/dev/stderr",O_WRONLY);
+ }
+ else {
+ ::open("/dev/stdout",O_WRONLY);
+ }
+ msg.append("\u000A");
+ if(::write(file,msg.c_str(),msg.size()) < 0x0) {
+ throw std::runtime_error("Unable to write to Stdout.");
}
if(::close(file) < 0x0) {
- throw std::runtime_error("Unable to close Stdout\u000A");
+ throw std::runtime_error("Unable to close Stdout");
}
}
diff --git a/src/benoit/strlen.cc b/src/benoit/strlen.cc
deleted file mode 100644
index c0947ba..0000000
--- a/src/benoit/strlen.cc
+++ /dev/null
@@ -1,9 +0,0 @@
-# include <benoit.hh>
-# include <cstddef>
-std::size_t benoit::strlen(char const * str) noexcept {
- std::size_t len = 0x0;
- while(str[len] != '\0') {
- ++len;
- }
- return len;
-}
diff --git a/src/benoit/t/pos/pos.cc b/src/benoit/t/pos/pos.cc
new file mode 100644
index 0000000..43941b2
--- /dev/null
+++ b/src/benoit/t/pos/pos.cc
@@ -0,0 +1,6 @@
+# include <benoit.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;
+}
diff --git a/src/benoit/~benoit.cc b/src/benoit/~benoit.cc
new file mode 100644
index 0000000..b16b42d
--- /dev/null
+++ b/src/benoit/~benoit.cc
@@ -0,0 +1,10 @@
+# include <benoit.hh>
+# include <cstdlib>
+# include <string>
+# include <unistd.h>
+using namespace std::literals::string_literals;
+[[noreturn]] benoit::~benoit() noexcept {
+ std::string const funcname = "benoit::~benoit()"s;
+ this->notiffunc(funcname);
+ this->exit(EXIT_SUCCESS);
+}