summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore6
-rw-r--r--Cargo.toml10
-rw-r--r--Makefile26
-rw-r--r--README.md2
-rwxr-xr-xbenoitbin0 -> 22112 bytes
-rw-r--r--changelog.html20
-rw-r--r--include/benoit.hh26
-rw-r--r--src/benoit/benoit.cc144
-rw-r--r--src/benoit/print.cc13
-rw-r--r--src/benoit/strlen.cc9
-rw-r--r--src/main.cc4
-rw-r--r--src/main.rs20
12 files changed, 248 insertions, 32 deletions
diff --git a/.gitignore b/.gitignore
index af88d47..f316085 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
+*.jpeg
+*.o
+*.png
+*.ppm
*.webp
-/Cargo.lock
-/target
diff --git a/Cargo.toml b/Cargo.toml
deleted file mode 100644
index 4d0df28..0000000
--- a/Cargo.toml
+++ /dev/null
@@ -1,10 +0,0 @@
-[package]
-name = "benoit"
-version = "0.0.0"
-authors = ["Gabriel Jensen <[email protected]>"]
-edition = "2018"
-
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
-[dependencies]
-libwebp = {version = "0.1.2",features = ["0_6"]}
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..9f9627a
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,26 @@
+CXX=clang++
+CXXFLAGS=-Iinclude
+ifneq ($(DEBUG),1)
+CXXFLAGS += -DNDEBUG
+endif
+ifeq ($(LUMA__X),1)
+CXXFLAGS += -DLUMA__X=true
+endif
+CXXFLAGS += -std=c++20 -Wall -Wextra -Wpedantic
+CXXFLAGS += -march=native -mtune=native -O3
+LDFLAGS = -lfmt -lwebp
+HDRS_CXX = \
+ include/benoit.hh
+SRCS_CXX = \
+ src/benoit/benoit.cc \
+ src/benoit/print.cc \
+ src/benoit/strlen.cc \
+ src/main.cc
+SRCS=$(SRCS_CXX)
+OBJS=$(SRCS:.cc=.o)
+benoit: $(OBJS)
+ $(CXX) $(LDFLAGS) -o $@ $(OBJS)
+$(OBJS): $(HDRS_CXX) $(SRCS_CXX)
+.PHONY: clean
+clean:
+ rm benoit $(OBJS)
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..2649560
--- /dev/null
+++ b/README.md
@@ -0,0 +1,2 @@
+# benoit
+---
diff --git a/benoit b/benoit
new file mode 100755
index 0000000..9b1796d
--- /dev/null
+++ b/benoit
Binary files differ
diff --git a/changelog.html b/changelog.html
new file mode 100644
index 0000000..266196b
--- /dev/null
+++ b/changelog.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ </head>
+ <body>
+ <h1>1</h1>
+ <ul>
+ <li>Add changelog.</li>
+ <li>Add README.</li>
+ <li>Move codebase to C++.</li>
+ <li>Copy renderer from MandelbrotSDL.</li>
+ <li>Change default filetype to PPM.</li>
+ </ul>
+ <h1>0</h1>
+ <ul>
+ <li>First.</li>
+ </ul>
+ </body>
+</html>
diff --git a/include/benoit.hh b/include/benoit.hh
new file mode 100644
index 0000000..09907aa
--- /dev/null
+++ b/include/benoit.hh
@@ -0,0 +1,26 @@
+# if !defined(BENOIT__HEADER)
+# define BENOIT__HEADER
+# include <cstddef>
+# include <cstdint>
+# include <vector>
+class benoit {
+public:
+ benoit(int const argc,char const * * argv);
+private:
+ enum class imgfmt_t {
+ jpeg,
+ png,
+ ppm,
+ webp,
+ };
+ 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;
+};
+# endif
diff --git a/src/benoit/benoit.cc b/src/benoit/benoit.cc
new file mode 100644
index 0000000..7fee86d
--- /dev/null
+++ b/src/benoit/benoit.cc
@@ -0,0 +1,144 @@
+# include <benoit.hh>
+# include <cstdint>
+# include <cstdlib>
+# include <fcntl.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;
+ }
+ */
+ /*
+ auto webpconf = ::WebPConfig();
+ webpconf.lossless = 0x1;
+ webpconf.quality = 0x64;
+ webpconf.method = 0x6;
+ webpconf.segments = 0x4;
+ webpconf.sns_strength = 0x4;
+ webpconf.filter_strength = 0x0;
+ webpconf.filter_sharpness = 0x0;
+ webpconf.autofilter = 0x0;
+ webpconf.alpha_compression = 0x1;
+ webpconf.alpha_filtering = 0x2;
+ webpconf.alpha_quality = 0x64;
+ webpconf.pass = 0xA;
+ webpconf.preprocessing = 0x1;
+ webpconf.partitions = 0x3;
+ webpconf.partitions = 0x0;
+ webpconf.use_sharp_yuv = 0x0;
+ auto conferr = ::WebPValidateConfig(&webpconf);
+ auto webpimg = ::WebPPicture();
+ WebPPictureInit(&webpimg);
+ webpimg.use_argb = 0x1;
+ webpimg.resx = 0x1;
+ webpimg.resy = 0x1;
+ WebPPictureAlloc(&webpimg);
+ auto webpmemwrit = WebPMemoryWriter();
+ WebPMemoryWriterInit(&webpmemwrit);
+ webpimg.writer = WebPMemoryWrite;
+ webpimg.custom_ptr = &webpmemwrit;
+ webpimg.argb = {0xFF,0xFF,0x0,0x0};
+ if(WebPEncode(&webpconf,&webpimg) == 0x0) {
+ }
+ else {
+
+ }
+ 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("image.webp",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) {
+ 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;
+ long double i2 = 0.0;
+
+ unsigned int iter;
+ for(iter = 0; iter < this->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 = this->maxiter;
+ break;
+ }
+
+ r2 = r2Temp;
+ i2 = i2Temp;
+ }
+
+ unsigned short int red = 0;
+ unsigned short int green = 0;
+ unsigned short int blue = 0;
+
+ 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);
+ }
+ buf.push_back(red);
+ buf.push_back(green);
+ buf.push_back(blue);
+ }
+ 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);
+}
diff --git a/src/benoit/print.cc b/src/benoit/print.cc
new file mode 100644
index 0000000..441cfd5
--- /dev/null
+++ b/src/benoit/print.cc
@@ -0,0 +1,13 @@
+# include <benoit.hh>
+# include <fcntl.h>
+# include <stdexcept>
+# 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");
+ }
+ if(::close(file) < 0x0) {
+ throw std::runtime_error("Unable to close Stdout\u000A");
+ }
+}
diff --git a/src/benoit/strlen.cc b/src/benoit/strlen.cc
new file mode 100644
index 0000000..c0947ba
--- /dev/null
+++ b/src/benoit/strlen.cc
@@ -0,0 +1,9 @@
+# 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/main.cc b/src/main.cc
new file mode 100644
index 0000000..6c5aaa8
--- /dev/null
+++ b/src/main.cc
@@ -0,0 +1,4 @@
+# include <benoit.hh>
+int main(int const argc,char const * * argv) {
+ ::benoit benoit(argc,argv);
+}
diff --git a/src/main.rs b/src/main.rs
deleted file mode 100644
index 1635188..0000000
--- a/src/main.rs
+++ /dev/null
@@ -1,20 +0,0 @@
-use libwebp::WebPEncodeLosslessRGBA;
-use std::fs::File;
-use std::io::prelude::*;
-fn main() -> std::io::Result<()> {
- let buf: &[u8] = &[
- 255,255,255,255,
- 255,0,0,255,
- 0,255,0,255,
- 0,0,255,255,
- 255,255,255,127,
- ];
- let data = WebPEncodeLosslessRGBA(buf,5,1,8).unwrap();
- let mut file = File::create("image.webp")?;
- let mut pos = 0;
- while pos < data.len() {
- let bytes_written = file.write(&data[pos..])?;
- pos += bytes_written;
- }
- Ok(())
-}