diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/benoit/benoit.cc | 26 | ||||
-rw-r--r-- | src/benoit/plotmandelbrot.cc | 22 |
2 files changed, 30 insertions, 18 deletions
diff --git a/src/benoit/benoit.cc b/src/benoit/benoit.cc index 7f74282..a97e35c 100644 --- a/src/benoit/benoit.cc +++ b/src/benoit/benoit.cc @@ -1,4 +1,5 @@ # include <benoit.hh> +# include <cstddef> # include <cstdint> # include <cstdlib> # include <fcntl.h> @@ -14,9 +15,6 @@ using namespace std::literals::string_literals; 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; @@ -30,8 +28,8 @@ using namespace std::literals::string_literals; this->outimg.append(".webp"s); break; } - this->exit(EXIT_SUCCESS); std::vector<std::uint8_t> buf = this->plotmandelbrot(); + this->exit(EXIT_SUCCESS); 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) { @@ -46,7 +44,6 @@ using namespace std::literals::string_literals; } this->exit(EXIT_SUCCESS); } -# if 0x0 /* auto webpconf = ::WebPConfig(); webpconf.lossless = 0x1; @@ -83,15 +80,14 @@ using namespace std::literals::string_literals; } WebPPictureFree(&webpimg); - */ - //auto buf = std::vector<std::uint8_t>(); - //buf.push_back(0xFF); - //buf.push_back(0x0); - //buf.push_back(0x0); - //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>(); + buf.push_back(0xFF); + buf.push_back(0x0); + buf.push_back(0x0); + auto file = std::fstream(this->outimt,std::fstream::binary | std::fstream::out | std::fstream::trunc); + if(!file.is_open()) { + ::_exit(EXIT_FAILURE); + } const double maxR = 2.25; const double minR = -2.25; const double maxI = 2.25; @@ -139,4 +135,4 @@ using namespace std::literals::string_literals; buf.push_back(green); buf.push_back(red); } -# endif +*/ diff --git a/src/benoit/plotmandelbrot.cc b/src/benoit/plotmandelbrot.cc index a4bf074..2a594cd 100644 --- a/src/benoit/plotmandelbrot.cc +++ b/src/benoit/plotmandelbrot.cc @@ -1,15 +1,31 @@ # include <benoit.hh> # include <boost/multiprecision/mpfr.hpp> # include <cstdint> +# include <fmt/core.h> +# include <iostream> +# include <pthread.h> +# include <string> # include <vector> -/* +using namespace std::literals::string_literals; namespace { - void static * plotarea(); + void * plotarea(void * rowsptr) { + unsigned short rows = *(unsigned short *)(rowsptr); + std::cout << fmt::format("Hello there from thread!\u000AI will calculate {} rows.\u000A"s,rows); + return nullptr; + } } -*/ std::vector<std::uint8_t> benoit::plotmandelbrot() { std::string const funcname = "benoit::plotmandelbrot()"s; this->notiffunc(funcname); std::vector<std::uint8_t> img; + std::vector<::pthread_t> threads; + for(unsigned short thread = 0x0;(thread < this->numthreads);++thread) { + threads.emplace_back(); + unsigned short rowspthread = (this->resy / this->numthreads); + ::pthread_create(&threads[thread],nullptr,::plotarea,&rowspthread); + } + for(auto thread : threads) { + ::pthread_join(thread,nullptr); + } return img; } |