Floyd-Strinberg diffusion

This commit is contained in:
Ben
2019-02-04 16:13:57 +00:00
parent d56102f35a
commit afa83ebd72
10 changed files with 9475 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/output.o",
"args": ["image.jpg"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 KiB

View File

@@ -0,0 +1,114 @@
#include <iostream>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
struct Pixel {
unsigned char r, g, b, a;
};
int index(int x, int y, int w) {
return x+y*w;
}
int main(int argc, char** argv) {
if (argc < 2) {
std::cout << "Incorrect usage, use like ./output.o <imagepath>" << std::endl;
return 0;
}
int w, h, c;
Pixel* image = (Pixel*)stbi_load(*(argv + 1), &w, &h, &c, 4);
if (image == NULL){
std::cout << "Invalid image: " << stbi_failure_reason() << std::endl;
return 0;
}
// Pixel* image = (Pixel*)malloc(sizeof(Pixel) * w * h * 4);
// Pixel* image = (Pixel*)stbi_load(*(argv + 1), &w, &h, &c, 4);
// Pixel* image = new Pixel[w * h * 4];
// for (int y = 0; y < h - 1; y++) {
// for (int x = 1; x < w - 1; x++) {
// image[x + y * w] = {255, 255, 255, 255};
// }
// }
int colComplexity = 3;
for (int y = 1; y < h - 1; y++) {
for (int x = 1; x < w - 1; x++) {
image[x + y * w].r = round(colComplexity * image[x + y * w].r / 255) * (255 / colComplexity);
image[x + y * w].g = round(colComplexity * image[x + y * w].g / 255) * (255 / colComplexity);
image[x + y * w].b = round(colComplexity * image[x + y * w].b / 255) * (255 / colComplexity);
float errorR = image[x + y * w].r - image[x + y * w].r;
float errorG = image[x + y * w].g - image[x + y * w].g;
float errorB = image[x + y * w].b - image[x + y * w].b;
int i = index(x+1, y, w);
image[i].r = (float)image[i].r + errorR * (7.0f / 16.0f);
image[i].g = (float)image[i].g + errorG * (7.0f / 16.0f);
image[i].b = (float)image[i].b + errorB * (7.0f / 16.0f);
i = index(x-1, y+1, w);
image[i].r = (float)image[i].r + errorR * (3.0f / 16.0f);
image[i].g = (float)image[i].g + errorG * (3.0f / 16.0f);
image[i].b = (float)image[i].b + errorB * (3.0f / 16.0f);
i = index(x, y+1, w);
image[i].r = (float)image[i].r + errorR * (5.0f / 16.0f);
image[i].g = (float)image[i].g + errorG * (5.0f / 16.0f);
image[i].b = (float)image[i].b + errorB * (5.0f / 16.0f);
i = index(x+1, y+1, w);
image[i].r = (float)image[i].r + errorR * (1.0f / 16.0f);
image[i].g = (float)image[i].g + errorG * (1.0f / 16.0f);
image[i].b = (float)image[i].b + errorB * (1.0f / 16.0f);
// int i = index(x+1, y, w);
// float r = image[i].r;
// float g = image[i].g;
// float b = image[i].b;
// r = r + errorR * 7/16.0;
// g = g + errorG * 7/16.0;
// b = b + errorB * 7/16.0;
// image[i] = {r, g, b, 255};
// i = index(x-1, y+1, w);
// r = image[i].r;
// g = image[i].g;
// b = image[i].b;
// r = r + errorR * 3/16.0;
// g = g + errorG * 3/16.0;
// b = b + errorB * 3/16.0;
// image[i] = {r, g, b, 255};
// i = index(x, y+1, w);
// r = image[i].r;
// g = image[i].g;
// b = image[i].b;
// r = r + errorR * 5/16.0;
// g = g + errorG * 5/16.0;
// b = b + errorB * 5/16.0;
// image[i] = {r, g, b, 255};
// i = index(x+1, y+1, w);
// r = image[i].r;
// g = image[i].g;
// b = image[i].b;
// r = r + errorR * 1/16.0;
// g = g + errorG * 1/16.0;
// b = b + errorB * 1/16.0;
// image[i] = {r, g, b, 255};
// pixel[x + 1][y ] := pixel[x + 1][y ] + quant_error * 7 / 16
// pixel[x - 1][y + 1] := pixel[x - 1][y + 1] + quant_error * 3 / 16
// pixel[x ][y + 1] := pixel[x ][y + 1] + quant_error * 5 / 16
// pixel[x + 1][y + 1] := pixel[x + 1][y + 1] + quant_error * 1 / 16
}
}
stbi_write_png("output.png", w, h, 4, (unsigned char*)image, 0);
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 461 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

152
C++/todo.txt Normal file
View File

@@ -0,0 +1,152 @@
To do
- [ ] Forward kinematics
- [ ] Inverse kinematics
- [x] Simple pendulum
- [ ] Double pendulum
- [x] Doom fire algorithm
- [ ] Quad tree compression
- [ ] GLSL smallpt
- [ ] CPU smallpt
- [ ] Dithering library
- [ ] All RGB
- [ ] Chip-8 emulator
- [ ] Chip-8 assembler
- [ ] Chip-8 disassembler
- [ ] Normal mapping on images
- [ ] Tesseract
- [ ] Lissajous table
- [ ] Navier-Stokes fluid simulation
- [ ] Floyd-Steinberg dithering
- [ ] Terminal text extension
- [ ] SDL2 audio extension
- [ ] Other error diffusion methods
- [ ] Elementary cellular automata
- [ ] Two-dimensional cellular automata
- [ ] Software rasterizer
- [ ] Fire automata
- [ ] Plasma effect
- [ ] Perlin noise terrain
- [ ] Refracting rays
- [ ] Sierpinski triangle
- [ ] Untextured ray caster
- [ ] Textured ray caster
- [ ] Verlet integration rag doll physics
- [ ] Truetype font rasterizing
- [ ] Quaternion raymarching
- [ ] Newton fractal
- [ ] Complex function visualization
- [ ] Smoothed particle hydrodynamics
- [ ] Porting minecraft4k
- [ ] Physics sandbox (Verlet)
- [ ] Barycentric triangle coordinates
- [ ] Pac-Man simulation
- [ ] Dynamic lighting (line of sight)
- [ ] Tetris simulation
- [ ] Falling text (Matrix simulation)
- [ ] Snake simulation
- [ ] Ball/ball collisions and response
- [ ] The Powder Toy
- [ ] Burning ship fractal
- [ ] NES emulator
- [ ] MNIST neural network
- [ ] Simple XOR neural network
- [ ] Genetic algorithms
- [ ] Ear-clipping triangulation
- [ ] Fireworks particle system
- [ ] Newtonian gravity particle system
- [ ] Load models (SGL)
- [ ] Projection (SGL)
- [ ] Transformation (SGL)
- [ ] Culling (SGL)
- [ ] Clipping (SGL)
- [ ] Lighting (SGL)
- [x] Mandelbrot explorer
- [ ] Black/white dithering
- [ ] 3-bit color dithering
- [ ] N-body simulation
- [ ] Barnes-Hut n-body simulation
- [ ] Cloth simulation (Verlet)
- [ ] Procedural texture generation
- [ ] Hilbert curve
- [ ] Turtle graphics engine
- [ ] OpenGL procedural terrain
- [ ] Julia set explorer
- [ ] OpenGL model viewer
- [ ] GPU acceleration framework
- [ ] Raymarching silhouettes
- [ ] Raymarching Phong illumination
- [ ] Domain repetition and primitive operators (raymarching)
- [ ] OpenCV with OpenGL video processing
- [ ] Ray marched terrain
- [ ] GPU accelerated Mandelbrot explorer
- [ ] GPU accelerated Julia explorer
- [ ] GPU accelerated Burning Ship explorer
- [ ] GPU accelerated Newton explorer
- [ ] Physically correct asteroids
- [ ] Fractal generator (high-precision)
- [ ] Affine transformations (identity)
- [ ] Affine transformations (rotation)
- [ ] Affine transformations (translation)
- [ ] Affine transformations (scalar)
- [ ] Affine transformations (shear)
- [ ] Fractal Brownian motion simulation
- [ ] Phong lighting with normal interpolation
- [ ] Audio processing with stb_vorbis
- [ ] Voronoi diagrams
- [ ] Raymarched die
- [ ] Raymarched pawn
- [ ] Cellular noise terrain
- [ ] Voronoi based terrain generation
- [ ] Naive metaballs
- [ ] Naive Voronoi metaballs
- [ ] Naive blended metaballs
- [ ] Metaballs with marching squares
- [ ] Perlin noise flow field
- [ ] Pressure and heat simulations
- [ ] Marching squares isolines
- [ ] 15 seconds of RAM on Chip-8
- [ ] K-means clustering
- [ ] Additive blending
- [ ] RGB 3D visualization
- [ ] RGB-HSL and vice versa
- [ ] Grapher
- [ ] Flocking (boids)
- [ ] Image quantization (median-cut)
- [ ] Image quantization (k-means)
- [ ] Double-precision GLSL fractals
- [ ] Bézier curve
- [ ] Refraction (optics)
- [ ] Mode 7 racing
- [ ] Spiral raster
- [ ] Plot function
- [ ] Rope simulation (Verlet)
- [ ] Hair simulation (Verlet)
- [ ] Koch snowflake
- [ ] Newtons cradle simulation (Verlet)
- [ ] Anti-aliased line rasterization (Xiaolin Wu)
- [ ] Anti-aliased thick line rasterization (Xiaolin Wu)
- [ ] Spirograph
- [ ] Circle-line intersection
- [ ] Fourier series visualization (square)
- [ ] Fourier series visualization (saw)
- [ ] Discrete Fourier transform
- [ ] Fourier transform based epicycles
- [ ] Fast Fourier transform
- [ ] 2D nearest-neighbor interpolation
- [ ] Bilinear interpolation
- [ ] Bicubic interpolation
- [ ] Edge detection
- [ ] Catmull-Rom splines
- [ ] Sepia filter
- [ ] Various black/white filters
- [ ] Guassian blur
- [ ] Box blur
- [ ] Image convolution using kernels
- [ ] Function approximation using neural networks
- [ ] Checkers/chess game in OpenGL
- [ ] Rubiks cube solver and scrambler
- [ ] Rubiks cube renderer in OpenGL
- [ ] Connect 4 in OpenGL
- [ ] Fast Fourier transform for audio visualization
- [ ] Text editor using Terminal extension

152
C++/todo.txt.save Normal file
View File

@@ -0,0 +1,152 @@
To do
- [ ] Forward kinematics
- [ ] Inverse kinematics
- [x] Simple pendulum
- [ ] Double pendulum
- [x] Doom fire algorithm
- [ ] Quad tree compression
- [ ] GLSL smallpt
- [ ] CPU smallpt
- [ ] Dithering library
- [ ] All RGB
- [ ] Chip-8 emulator
- [ ] Chip-8 assembler
- [ ] Chip-8 disassembler
- [ ] Normal mapping on images
- [ ] Tesseract
- [ ] Lissajous table
- [ ] Navier-Stokes fluid simulation
- [] Floyd-Steinberg dithering
- [ ] Terminal text extension
- [ ] SDL2 audio extension
- [ ] Other error diffusion methods
- [ ] Elementary cellular automata
- [ ] Two-dimensional cellular automata
- [ ] Software rasterizer
- [ ] Fire automata
- [ ] Plasma effect
- [ ] Perlin noise terrain
- [ ] Refracting rays
- [ ] Sierpinski triangle
- [ ] Untextured ray caster
- [ ] Textured ray caster
- [ ] Verlet integration rag doll physics
- [ ] Truetype font rasterizing
- [ ] Quaternion raymarching
- [ ] Newton fractal
- [ ] Complex function visualization
- [ ] Smoothed particle hydrodynamics
- [ ] Porting minecraft4k
- [ ] Physics sandbox (Verlet)
- [ ] Barycentric triangle coordinates
- [ ] Pac-Man simulation
- [ ] Dynamic lighting (line of sight)
- [ ] Tetris simulation
- [ ] Falling text (Matrix simulation)
- [ ] Snake simulation
- [ ] Ball/ball collisions and response
- [ ] The Powder Toy
- [ ] Burning ship fractal
- [ ] NES emulator
- [ ] MNIST neural network
- [ ] Simple XOR neural network
- [ ] Genetic algorithms
- [ ] Ear-clipping triangulation
- [ ] Fireworks particle system
- [ ] Newtonian gravity particle system
- [ ] Load models (SGL)
- [ ] Projection (SGL)
- [ ] Transformation (SGL)
- [ ] Culling (SGL)
- [ ] Clipping (SGL)
- [ ] Lighting (SGL)
- [x] Mandelbrot explorer
- [ ] Black/white dithering
- [ ] 3-bit color dithering
- [ ] N-body simulation
- [ ] Barnes-Hut n-body simulation
- [ ] Cloth simulation (Verlet)
- [ ] Procedural texture generation
- [ ] Hilbert curve
- [ ] Turtle graphics engine
- [ ] OpenGL procedural terrain
- [ ] Julia set explorer
- [ ] OpenGL model viewer
- [ ] GPU acceleration framework
- [ ] Raymarching silhouettes
- [ ] Raymarching Phong illumination
- [ ] Domain repetition and primitive operators (raymarching)
- [ ] OpenCV with OpenGL video processing
- [ ] Ray marched terrain
- [ ] GPU accelerated Mandelbrot explorer
- [ ] GPU accelerated Julia explorer
- [ ] GPU accelerated Burning Ship explorer
- [ ] GPU accelerated Newton explorer
- [ ] Physically correct asteroids
- [ ] Fractal generator (high-precision)
- [ ] Affine transformations (identity)
- [ ] Affine transformations (rotation)
- [ ] Affine transformations (translation)
- [ ] Affine transformations (scalar)
- [ ] Affine transformations (shear)
- [ ] Fractal Brownian motion simulation
- [ ] Phong lighting with normal interpolation
- [ ] Audio processing with stb_vorbis
- [ ] Voronoi diagrams
- [ ] Raymarched die
- [ ] Raymarched pawn
- [ ] Cellular noise terrain
- [ ] Voronoi based terrain generation
- [ ] Naive metaballs
- [ ] Naive Voronoi metaballs
- [ ] Naive blended metaballs
- [ ] Metaballs with marching squares
- [ ] Perlin noise flow field
- [ ] Pressure and heat simulations
- [ ] Marching squares isolines
- [ ] 15 seconds of RAM on Chip-8
- [ ] K-means clustering
- [ ] Additive blending
- [ ] RGB 3D visualization
- [ ] RGB-HSL and vice versa
- [ ] Grapher
- [ ] Flocking (boids)
- [ ] Image quantization (median-cut)
- [ ] Image quantization (k-means)
- [ ] Double-precision GLSL fractals
- [ ] Bézier curve
- [ ] Refraction (optics)
- [ ] Mode 7 racing
- [ ] Spiral raster
- [ ] Plot function
- [ ] Rope simulation (Verlet)
- [ ] Hair simulation (Verlet)
- [ ] Koch snowflake
- [ ] Newtons cradle simulation (Verlet)
- [ ] Anti-aliased line rasterization (Xiaolin Wu)
- [ ] Anti-aliased thick line rasterization (Xiaolin Wu)
- [ ] Spirograph
- [ ] Circle-line intersection
- [ ] Fourier series visualization (square)
- [ ] Fourier series visualization (saw)
- [ ] Discrete Fourier transform
- [ ] Fourier transform based epicycles
- [ ] Fast Fourier transform
- [ ] 2D nearest-neighbor interpolation
- [ ] Bilinear interpolation
- [ ] Bicubic interpolation
- [ ] Edge detection
- [ ] Catmull-Rom splines
- [ ] Sepia filter
- [ ] Various black/white filters
- [ ] Guassian blur
- [ ] Box blur
- [ ] Image convolution using kernels
- [ ] Function approximation using neural networks
- [ ] Checkers/chess game in OpenGL
- [ ] Rubiks cube solver and scrambler
- [ ] Rubiks cube renderer in OpenGL
- [ ] Connect 4 in OpenGL
- [ ] Fast Fourier transform for audio visualization
- [ ] Text editor using Terminal extension