From 4256dbdaec40a21083dfd42fb4f0c686a362ad16 Mon Sep 17 00:00:00 2001 From: Ilya Sheprut Date: Sat, 11 Apr 2026 02:44:30 +0300 Subject: [PATCH] Add a typedef to 32 bit unsigned int as "Color" --- src/CUDA/3d_points_lines.cu | 16 ++-- src/CUDA/background_color.cu | 11 ++- src/CUDA/beaver_grid.cu | 8 +- src/CUDA/beaver_grid_TNF.cu | 8 +- src/CUDA/beaver_grid_TNF_3d.cu | 14 ++-- src/CUDA/color.cuh | 63 ++++++++------- src/CUDA/common_graphics.cuh | 4 +- src/CUDA/conway.cu | 8 +- .../geodesic_raymarch.cu | 14 ++-- .../differential_geometry/numerical_2d.cu | 12 +-- src/CUDA/edge_detect.cuh | 4 +- src/CUDA/mandelbrot.cu | 28 +++---- src/CUDA/mandelbulb.cu | 14 ++-- src/CUDA/manifold.cu | 26 +++--- src/CUDA/pixels_manip.cu | 56 ++++++------- src/CUDA/polynomials/complex_polynomial.cu | 12 +-- src/CUDA/polynomials/root_fractal.cu | 10 +-- src/CUDA/surface.cu | 16 ++-- src/Core/Color.h | 81 ++++++++++--------- src/Core/Convolution.cpp | 10 +-- src/Core/Convolution.h | 8 +- src/Core/Pixels.cpp | 42 +++++----- src/Core/Pixels.h | 48 +++++------ src/DataObjects/Graph.h | 3 +- .../LambdaCalculus/LambdaAbstraction.cpp | 6 +- .../LambdaCalculus/LambdaAbstraction.h | 6 +- .../LambdaCalculus/LambdaApplication.cpp | 6 +- .../LambdaCalculus/LambdaApplication.h | 6 +- .../LambdaCalculus/LambdaExpression.cpp | 6 +- .../LambdaCalculus/LambdaExpression.h | 12 +-- .../LambdaCalculus/LambdaUtils.cpp | 6 +- src/DataObjects/LambdaCalculus/LambdaUtils.h | 4 +- .../LambdaCalculus/LambdaVariable.cpp | 6 +- .../LambdaCalculus/LambdaVariable.h | 6 +- src/Host_Device_Shared/Color.h | 11 +++ .../ThreeDimensionStructs.h | 9 ++- src/IO/VideoWriter.h | 2 +- src/IO/Writer.cpp | 8 +- src/IO/Writer.h | 11 +-- src/Scenes/Common/CoordinateScene.cpp | 12 +-- src/Scenes/Common/CoordinateScene.h | 4 +- src/Scenes/Common/CoordinateSceneWithTrail.h | 4 +- src/Scenes/Common/PauseScene.cpp | 2 +- src/Scenes/Common/ThreeDimensionScene.cpp | 10 +-- src/Scenes/Common/ThreeDimensionScene.h | 4 +- src/Scenes/Connect4/C4GraphScene.cpp | 2 +- src/Scenes/Connect4/C4GraphScene.h | 2 +- src/Scenes/Connect4/C4Scene.cpp | 2 +- src/Scenes/Math/AngularFractalScene.cpp | 2 +- src/Scenes/Math/BarChartScene.cpp | 2 +- src/Scenes/Math/Beavers/BeaverGridScene.cpp | 2 +- .../Math/Beavers/BeaverGridTNF3DScene.cpp | 2 +- .../Math/Beavers/BeaverGridTNFScene.cpp | 2 +- src/Scenes/Math/ComplexPlotScene.cpp | 4 +- src/Scenes/Math/ConwayScene.cpp | 2 +- src/Scenes/Math/GeodesicScene.cpp | 8 +- src/Scenes/Math/GraphScene.cpp | 4 +- src/Scenes/Math/GraphScene.h | 4 +- src/Scenes/Math/KlotskiScene.cpp | 4 +- src/Scenes/Math/KlotskiScene.h | 2 +- src/Scenes/Math/MandelbrotScene.cpp | 8 +- src/Scenes/Math/MandelbulbScene.cpp | 2 +- src/Scenes/Math/ManifoldScene.cpp | 8 +- src/Scenes/Math/ManifoldScene.h | 2 +- src/Scenes/Math/RealFunctionScene.cpp | 2 +- src/Scenes/Math/RealFunctionScene.h | 2 +- src/Scenes/Math/RootFractalScene.cpp | 2 +- src/Scenes/Media/AlphaFilterScene.cpp | 6 +- src/Scenes/Media/AlphaFilterScene.h | 6 +- src/Scenes/Media/StateSliderScene.cpp | 6 +- .../Physics/MovingPendulumGridScene.cpp | 2 +- src/Scenes/Physics/PendulumGridScene.cpp | 4 +- src/Scenes/Physics/PendulumPointsScene.cpp | 2 +- src/Scenes/Physics/PendulumScene.cpp | 4 +- 74 files changed, 386 insertions(+), 371 deletions(-) create mode 100644 src/Host_Device_Shared/Color.h diff --git a/src/CUDA/3d_points_lines.cu b/src/CUDA/3d_points_lines.cu index b8c520b6..d1a66f70 100644 --- a/src/CUDA/3d_points_lines.cu +++ b/src/CUDA/3d_points_lines.cu @@ -10,7 +10,7 @@ #include "common_graphics.cuh" // Contains fill_circle __global__ void render_points_kernel( - unsigned int* pixels, int width, int height, + Color* pixels, int width, int height, float geom_mean_size, float points_opacity, float points_radius_multiplier, Cuda::Point* points, int num_points, Cuda::quat camera_direction, Cuda::vec3 camera_pos, float fov) @@ -31,7 +31,7 @@ __global__ void render_points_kernel( } __global__ void render_lines_kernel( - unsigned int* pixels, int width, int height, + Color* pixels, int width, int height, float geom_mean_size, int thickness, float lines_opacity, Cuda::Line* lines, int num_lines, Cuda::quat camera_direction, Cuda::vec3 camera_pos, float fov) @@ -59,14 +59,14 @@ __global__ void render_lines_kernel( } extern "C" void render_points_on_gpu( - unsigned int* h_pixels, int width, int height, + Color* h_pixels, int width, int height, float geom_mean_size, float points_opacity, float points_radius_multiplier, Cuda::Point* h_points, int num_points, Cuda::quat camera_direction, Cuda::vec3 camera_pos, float fov) { - unsigned int* d_pixels = nullptr; + Color* d_pixels = nullptr; Cuda::Point* d_points = nullptr; - size_t pix_sz = width * height * sizeof(unsigned int); + size_t pix_sz = width * height * sizeof(Color); size_t pt_sz = num_points * sizeof(Cuda::Point); cudaMalloc((void**)&d_pixels, pix_sz); @@ -90,14 +90,14 @@ extern "C" void render_points_on_gpu( } extern "C" void render_lines_on_gpu( - unsigned int* h_pixels, int width, int height, + Color* h_pixels, int width, int height, float geom_mean_size, int thickness, float lines_opacity, Cuda::Line* h_lines, int num_lines, Cuda::quat camera_direction, Cuda::vec3 camera_pos, float fov) { - unsigned int* d_pixels = nullptr; + Color* d_pixels = nullptr; Cuda::Line* d_lines = nullptr; - size_t pix_sz = width * height * sizeof(unsigned int); + size_t pix_sz = width * height * sizeof(Color); size_t ln_sz = num_lines * sizeof(Cuda::Line); cudaMalloc((void**)&d_pixels, pix_sz); diff --git a/src/CUDA/background_color.cu b/src/CUDA/background_color.cu index 5c69b680..a44f2d86 100644 --- a/src/CUDA/background_color.cu +++ b/src/CUDA/background_color.cu @@ -6,9 +6,9 @@ #include "color.cuh" __global__ -void alpha_overlay_kernel(unsigned int* pixels, +void alpha_overlay_kernel(Color* pixels, int width, int height, - int bg) + Color bg) { // 2D coordinates int x = blockIdx.x * blockDim.x + threadIdx.x; @@ -18,15 +18,15 @@ void alpha_overlay_kernel(unsigned int* pixels, int idx = y * width + x; - unsigned int pix = pixels[idx]; + Color pix = pixels[idx]; pixels[idx] = d_color_combine(bg, pix); } extern "C" -void alpha_overlay_cuda(unsigned int* src_host, +void alpha_overlay_cuda(Color* src_host, int width, int height, - unsigned int bg_color) + Color bg_color) { if (!src_host || width <= 0 || height <= 0) return; @@ -54,4 +54,3 @@ void alpha_overlay_cuda(unsigned int* src_host, // Free device memory cudaFree(d_src); } - diff --git a/src/CUDA/beaver_grid.cu b/src/CUDA/beaver_grid.cu index 15bb0570..f8d9b0cb 100644 --- a/src/CUDA/beaver_grid.cu +++ b/src/CUDA/beaver_grid.cu @@ -37,7 +37,7 @@ __device__ void decode_turing_machine_index(int x, int y, int grid_w, int grid_h } } -__global__ void beaver_grid_kernel(int num_states, int num_symbols, unsigned int* pixels, int w, int h, int grid_w, int grid_h, Cuda::vec2 lx_ty, Cuda::vec2 rx_by, int max_steps) { +__global__ void beaver_grid_kernel(int num_states, int num_symbols, Color* pixels, int w, int h, int grid_w, int grid_h, Cuda::vec2 lx_ty, Cuda::vec2 rx_by, int max_steps) { int idx = blockIdx.x * blockDim.x + threadIdx.x; int idy = blockIdx.y * blockDim.y + threadIdx.y; @@ -91,8 +91,8 @@ __global__ void beaver_grid_kernel(int num_states, int num_symbols, unsigned int pixels[pixel_index] = halted ? d_rainbow(atan_steps) : 0xff000000; } -extern "C" void beaver_grid_cuda(int num_states, int num_symbols, unsigned int* pixels, int w, int h, Cuda::vec2 lx_ty, Cuda::vec2 rx_by, int max_steps) { - unsigned int* d_pixels; +extern "C" void beaver_grid_cuda(int num_states, int num_symbols, Color* pixels, int w, int h, Cuda::vec2 lx_ty, Cuda::vec2 rx_by, int max_steps) { + Color* d_pixels; int w_base = (num_states + 1); int h_base = 2 * num_symbols; // given by (2m(n+1))^(mn) @@ -103,7 +103,7 @@ extern "C" void beaver_grid_cuda(int num_states, int num_symbols, unsigned int* grid_w *= w_base; grid_h *= h_base; } - size_t size = w * h * sizeof(unsigned int); + size_t size = w * h * sizeof(Color); cudaMalloc(&d_pixels, size); dim3 blockSize(16, 16); dim3 gridSize((w + blockSize.x - 1) / blockSize.x, (h + blockSize.y - 1) / blockSize.y); diff --git a/src/CUDA/beaver_grid_TNF.cu b/src/CUDA/beaver_grid_TNF.cu index 3716ab12..d1f66cee 100644 --- a/src/CUDA/beaver_grid_TNF.cu +++ b/src/CUDA/beaver_grid_TNF.cu @@ -37,7 +37,7 @@ __device__ void get_child(TuringMachine& tm, int action_index, const Cuda::vec2& tm.num_states += (int)(tm.next_state[action_index] == tm.num_states-1); } -__global__ void beaver_TNF_kernel(unsigned int* pixels, int w, int h, Cuda::vec2 lx_ty, Cuda::vec2 rx_by, bool corners_in_01, float border_thickness, TuringMachine TNF_root, int max_steps) { +__global__ void beaver_TNF_kernel(Color* pixels, int w, int h, Cuda::vec2 lx_ty, Cuda::vec2 rx_by, bool corners_in_01, float border_thickness, TuringMachine TNF_root, int max_steps) { // convert the corners so that instead of storing the screen corners in the CoordinateScene's coordinate system, they store the TNF grid corners in the screen's coordinate system Cuda::vec2 grid_lx_ty = -lx_ty / (rx_by - lx_ty); rx_by = (Cuda::vec2(1,1) - lx_ty) / (rx_by - lx_ty); @@ -134,9 +134,9 @@ __global__ void beaver_TNF_kernel(unsigned int* pixels, int w, int h, Cuda::vec2 pixels[pixel_index] = d_rainbow(atanf(depth*depth / 200.) / 1.57079632679f); } -extern "C" void beaver_grid_TNF_cuda(unsigned int* pixels, int w, int h, Cuda::vec2 lx_ty, Cuda::vec2 rx_by, int max_steps) { - unsigned int* d_pixels; - size_t size = w * h * sizeof(unsigned int); +extern "C" void beaver_grid_TNF_cuda(Color* pixels, int w, int h, Cuda::vec2 lx_ty, Cuda::vec2 rx_by, int max_steps) { + Color* d_pixels; + size_t size = w * h * sizeof(Color); cudaMalloc(&d_pixels, size); dim3 blockSize(16, 16); dim3 gridSize((w + blockSize.x - 1) / blockSize.x, (h + blockSize.y - 1) / blockSize.y); diff --git a/src/CUDA/beaver_grid_TNF_3d.cu b/src/CUDA/beaver_grid_TNF_3d.cu index 4d6e605e..4409a27d 100644 --- a/src/CUDA/beaver_grid_TNF_3d.cu +++ b/src/CUDA/beaver_grid_TNF_3d.cu @@ -266,7 +266,7 @@ __device__ void loop5(Cuda::vec3& raypos, Cuda::vec3 raydir, Cuda::vec4& raycol, -__global__ void beaver_raytrace_kernel(unsigned int* pixels, int w, int h, Cuda::vec3 raypos, Cuda::quat camera, float fov, int max_steps, float shell_border, float core_border, Cuda::vec3 scale, Cuda::vec3 target) { +__global__ void beaver_raytrace_kernel(Color* pixels, int w, int h, Cuda::vec3 raypos, Cuda::quat camera, float fov, int max_steps, float shell_border, float core_border, Cuda::vec3 scale, Cuda::vec3 target) { int idx = blockIdx.x * blockDim.x + threadIdx.x; int idy = blockIdx.y * blockDim.y + threadIdx.y; if (idx >= w || idy >= h) { @@ -318,11 +318,11 @@ __global__ void beaver_raytrace_kernel(unsigned int* pixels, int w, int h, Cuda: t++; } } - pixels[pixel_index] = ((unsigned int)(floor(raycol.x * 255)) << 24) | ((unsigned int)(floor(raycol.y * 255)) << 16) | ((unsigned int)(floor(raycol.z * 255)) << 8) | (unsigned int)(floor(raycol.w * 255)); + pixels[pixel_index] = (static_cast(floor(raycol.x * 255)) << 24) | (static_cast(floor(raycol.y * 255)) << 16) | (static_cast(floor(raycol.z * 255)) << 8) | static_cast(floor(raycol.w * 255)); } extern "C" void beaver_grid_TNF_3D_cuda( - unsigned int* pixels, + Color* pixels, int w, int h, Cuda::vec3 pos, Cuda::quat camera, float fov, Cuda::vec3 target, Cuda::vec3 up, float use_quat_camera, @@ -330,9 +330,9 @@ extern "C" void beaver_grid_TNF_3D_cuda( Cuda::vec3 scale, int max_steps ){ - unsigned int* d_pixels; + Color* d_pixels; - cudaMalloc(&d_pixels, w * h * sizeof(unsigned int)); + cudaMalloc(&d_pixels, w * h * sizeof(Color)); dim3 threads(16, 16); dim3 block((w + threads.x - 1) / threads.x, (h + threads.y - 1) / threads.y); @@ -344,7 +344,7 @@ extern "C" void beaver_grid_TNF_3D_cuda( beaver_raytrace_kernel<<>>(d_pixels, w, h, pos, camera, fov, max_steps, shell_border, core_border, scale, target); - cudaMemcpy(pixels, d_pixels, w * h * sizeof(unsigned int), cudaMemcpyDeviceToHost); + cudaMemcpy(pixels, d_pixels, w * h * sizeof(Color), cudaMemcpyDeviceToHost); cudaFree(d_pixels); -} \ No newline at end of file +} diff --git a/src/CUDA/color.cuh b/src/CUDA/color.cuh index 59e081ce..3434a5e9 100644 --- a/src/CUDA/color.cuh +++ b/src/CUDA/color.cuh @@ -1,32 +1,33 @@ #pragma once #include +#include "../Host_Device_Shared/Color.h" #include "../Host_Device_Shared/helpers.h" -__device__ __forceinline__ int d_argb(int a, int r, int g, int b){return (int(Cuda::clamp(a,0,255))<<24)| - (int(Cuda::clamp(r,0,255))<<16)| - (int(Cuda::clamp(g,0,255))<<8 )| - (int(Cuda::clamp(b,0,255)) );} +__device__ __forceinline__ Color d_argb(int a, int r, int g, int b){return (static_cast(Cuda::clamp(a,0,255))<<24)| + (static_cast(Cuda::clamp(r,0,255))<<16)| + (static_cast(Cuda::clamp(g,0,255))<<8 )| + static_cast(Cuda::clamp(b,0,255)) ;} -__device__ __forceinline__ int d_geta(int color) { +__device__ __forceinline__ int d_geta(Color color) { return (color >> 24) & 0xFF; } -__device__ __forceinline__ int d_getr(int color) { +__device__ __forceinline__ int d_getr(Color color) { return (color >> 16) & 0xFF; } -__device__ __forceinline__ int d_getg(int color) { +__device__ __forceinline__ int d_getg(Color color) { return (color >> 8) & 0xFF; } -__device__ __forceinline__ int d_getb(int color) { +__device__ __forceinline__ int d_getb(Color color) { return color & 0xFF; } -__device__ __forceinline__ int d_rainbow(float x){return d_argb(255, - sin((x+1/3.)*M_PI*2)*128.+128, - sin((x+2/3.)*M_PI*2)*128.+128, - sin((x )*M_PI*2)*128.+128);} +__device__ __forceinline__ Color d_rainbow(float x){return d_argb(255, + sin((x+1/3.)*M_PI*2)*128.+128, + sin((x+2/3.)*M_PI*2)*128.+128, + sin((x )*M_PI*2)*128.+128);} -__device__ __forceinline__ int d_colorlerp(int c1, int c2, float t) { +__device__ __forceinline__ Color d_colorlerp(Color c1, Color c2, float t) { int a1 = (c1 >> 24) & 0xFF; int r1 = (c1 >> 16) & 0xFF; int g1 = (c1 >> 8) & 0xFF; int b1 = c1 & 0xFF; int a2 = (c2 >> 24) & 0xFF; int r2 = (c2 >> 16) & 0xFF; int g2 = (c2 >> 8) & 0xFF; int b2 = c2 & 0xFF; int a = roundf((1 - t) * a1 + t * a2); @@ -36,54 +37,54 @@ __device__ __forceinline__ int d_colorlerp(int c1, int c2, float t) { return (a << 24) | (r << 16) | (g << 8) | b; } -__device__ __forceinline__ int d_color_combine(int base_color, int over_color, float overlay_opacity_multiplier = 1) { +__device__ __forceinline__ Color d_color_combine(Color base_color, Color over_color, float overlay_opacity_multiplier = 1) { float base_opacity = d_geta(base_color) / 255.0f; float over_opacity = d_geta(over_color) / 255.0f * overlay_opacity_multiplier; float final_opacity = 1 - (1 - base_opacity) * (1 - over_opacity); if (final_opacity == 0) return 0x00000000; int final_alpha = roundf(final_opacity * 255.0f); float chroma_weight = over_opacity / final_opacity; - int final_rgb = d_colorlerp(base_color, over_color, chroma_weight) & 0x00ffffff; - return (final_alpha << 24) | (final_rgb); + Color final_rgb = d_colorlerp(base_color, over_color, chroma_weight) & 0x00ffffff; + return (static_cast(final_alpha) << 24) | final_rgb; } -__device__ __forceinline__ void d_set_pixel(int x, int y, int col, unsigned int* pixels, int width, int height) { +__device__ __forceinline__ void d_set_pixel(int x, int y, Color col, Color* pixels, int width, int height) { if (x < 0 || x >= width || y < 0 || y >= height) return; pixels[y * width + x] = col; } -__device__ __forceinline__ void d_overlay_pixel(int x, int y, int col, float opacity, unsigned int* pixels, int width, int height) { +__device__ __forceinline__ void d_overlay_pixel(int x, int y, Color col, float opacity, Color* pixels, int width, int height) { if (x < 0 || x >= width || y < 0 || y >= height) return; opacity = Cuda::clamp(opacity, 0.0f, 1.0f); int idx = y * width + x; - int base = pixels[idx]; - int blended = d_color_combine(base, col, opacity); + Color base = pixels[idx]; + Color blended = d_color_combine(base, col, opacity); pixels[idx] = blended; } -__device__ __forceinline__ void d_naive_add_pixel(int x, int y, int col, float opacity, unsigned int* pixels, int width, int height) { +__device__ __forceinline__ void d_naive_add_pixel(int x, int y, Color col, float opacity, Color* pixels, int width, int height) { if (x < 0 || x >= width || y < 0 || y >= height) return; opacity = Cuda::clamp(opacity, 0.0f, 1.0f); int idx = y * width + x; - int base = pixels[idx]; + Color base = pixels[idx]; // Naively add each channel multiplied by opacity, clamping to 255 int a = d_geta(base) + int(d_geta(col) * opacity); int r = d_getr(base) + int(d_getr(col) * opacity); int g = d_getg(base) + int(d_getg(col) * opacity); int b = d_getb(base) + int(d_getb(col) * opacity); - int blended = d_argb(a, r, g, b); + Color blended = d_argb(a, r, g, b); pixels[idx] = blended; } -__device__ __forceinline__ void d_atomic_overlay_pixel(int x, int y, int col, float opacity, unsigned int* pixels, int width, int height) { +__device__ __forceinline__ void d_atomic_overlay_pixel(int x, int y, Color col, float opacity, Color* pixels, int width, int height) { if (x < 0 || x >= width || y < 0 || y >= height) return; opacity = Cuda::clamp(opacity, 0.0f, 1.0f); int idx = y * width + x; - unsigned int old_pixel = pixels[idx]; - int base = old_pixel; - int blended = d_color_combine(base, col, opacity); - int new_pixel = blended; + Color old_pixel = pixels[idx]; + Color base = old_pixel; + Color blended = d_color_combine(base, col, opacity); + Color new_pixel = blended; atomicCAS(&pixels[idx], old_pixel, new_pixel); } @@ -94,7 +95,7 @@ __device__ __forceinline__ float d_linear_srgb_to_srgb(float x) { return 12.92 * x; } -__device__ __forceinline__ int d_OKLABtoRGB(int alpha, float L, float a, float b) +__device__ __forceinline__ Color d_OKLABtoRGB(int alpha, float L, float a, float b) { float l_ = L + 0.3963377774f * a + 0.2158037573f * b; float m_ = L - 0.1055613458f * a - 0.0638541728f * b; @@ -112,7 +113,7 @@ __device__ __forceinline__ int d_OKLABtoRGB(int alpha, float L, float a, float b ); } -__device__ __forceinline__ int d_complex_to_srgb(const thrust::complex& c, float ab_dilation, float dot_radius) { +__device__ __forceinline__ Color d_complex_to_srgb(const thrust::complex& c, float ab_dilation, float dot_radius) { float mag = abs(c); if(mag < 1e-7) return d_argb(255, 255, 255, 255); // white to dodge division by zero thrust::complex norm = (c * ab_dilation / mag + thrust::complex(1,1)) * .5; @@ -120,7 +121,7 @@ __device__ __forceinline__ int d_complex_to_srgb(const thrust::complex& c return d_OKLABtoRGB(255, 1-.8*am, Cuda::lerp(-.233888, .276216, norm.real()), Cuda::lerp(-.311528, .198570, norm.imag())); } -__device__ __forceinline__ int d_HSVtoRGB(float h, float s, float v, int alpha = 255) { +__device__ __forceinline__ Color d_HSVtoRGB(float h, float s, float v, int alpha = 255) { float r_f, g_f, b_f; if (s == 0.0) { diff --git a/src/CUDA/common_graphics.cuh b/src/CUDA/common_graphics.cuh index bcc37f7b..d1951600 100644 --- a/src/CUDA/common_graphics.cuh +++ b/src/CUDA/common_graphics.cuh @@ -5,7 +5,7 @@ namespace Cuda { // Fill a circle on a pixel buffer -__device__ __forceinline__ void d_fill_circle(float cx, float cy, float r, int col, unsigned int* pixels, int width, int height, float opa=1.0f) { +__device__ __forceinline__ void d_fill_circle(float cx, float cy, float r, Color col, Color* pixels, int width, int height, float opa=1.0f) { // breakout if outside of screen if (cx + r < 0 || cx - r >= width || cy + r < 0 || cy - r >= height) return; @@ -19,7 +19,7 @@ __device__ __forceinline__ void d_fill_circle(float cx, float cy, float r, int c } } -__device__ __forceinline__ void bresenham(int x1, int y1, int x2, int y2, int col, float opacity, int thickness, unsigned int* pixels, int width, int height) { +__device__ __forceinline__ void bresenham(int x1, int y1, int x2, int y2, Color col, float opacity, int thickness, Color* pixels, int width, int height) { int dx = abs(x2 - x1), dy = abs(y2 - y1); if (dx > 10000 || dy > 10000) return; int sx = (x1 < x2) ? 1 : -1; diff --git a/src/CUDA/conway.cu b/src/CUDA/conway.cu index e44ba0a0..2d004fb9 100644 --- a/src/CUDA/conway.cu +++ b/src/CUDA/conway.cu @@ -122,7 +122,7 @@ extern "C" void iterate_conway(Bitboard* d_board, Bitboard* d_board_2, int w_bit cudaDeviceSynchronize(); } -__global__ void conway_draw_kernel(Bitboard* board, Bitboard* board_2, int w_bitboards, int h_bitboards, unsigned int* pixels, int pixels_w, int pixels_h, Cuda::vec2 lx_ty, Cuda::vec2 rx_by, float w_t) +__global__ void conway_draw_kernel(Bitboard* board, Bitboard* board_2, int w_bitboards, int h_bitboards, Color* pixels, int pixels_w, int pixels_h, Cuda::vec2 lx_ty, Cuda::vec2 rx_by, float w_t) { int px = blockDim.x * blockIdx.x + threadIdx.x; int py = blockDim.y * blockIdx.y + threadIdx.y; @@ -221,11 +221,11 @@ __global__ void conway_draw_kernel(Bitboard* board, Bitboard* board_2, int w_bit } } -extern "C" void draw_conway(Bitboard* d_board, Bitboard* d_board_2, int w_bitboards, int h_bitboards, unsigned int* h_pixels, int pixels_w, int pixels_h, Cuda::vec2 lx_ty, Cuda::vec2 rx_by, float transition) +extern "C" void draw_conway(Bitboard* d_board, Bitboard* d_board_2, int w_bitboards, int h_bitboards, Color* h_pixels, int pixels_w, int pixels_h, Cuda::vec2 lx_ty, Cuda::vec2 rx_by, float transition) { - size_t pix_sz = pixels_w * pixels_h * sizeof(unsigned int); + size_t pix_sz = pixels_w * pixels_h * sizeof(Color); - unsigned int* d_pixels; + Color* d_pixels; cudaMalloc((void**)&d_pixels, pix_sz); diff --git a/src/CUDA/differential_geometry/geodesic_raymarch.cu b/src/CUDA/differential_geometry/geodesic_raymarch.cu index 6296a68c..ff48c0df 100644 --- a/src/CUDA/differential_geometry/geodesic_raymarch.cu +++ b/src/CUDA/differential_geometry/geodesic_raymarch.cu @@ -273,7 +273,7 @@ static __device__ bool rk4_step_geodesic(float Y[6], float Y2[6], float dt) { return true; } -static __device__ bool collision_sphere(float Y[6], uint32_t& color, float& dist, float radius, const Cuda::vec3& center) { +static __device__ bool collision_sphere(float Y[6], Color& color, float& dist, float radius, const Cuda::vec3& center) { float dx = Y[0] - center.x; float dy = Y[1] - center.y; float dz = Y[2] - center.z; @@ -287,7 +287,7 @@ static __device__ bool collision_sphere(float Y[6], uint32_t& color, float& dist return false; // no collision } -static __device__ bool collision_cube(float Y[6], uint32_t& color, float& dist) { +static __device__ bool collision_cube(float Y[6], Color& color, float& dist) { const int wall_dist = 4; const int floor_ceiling_dist = 1; if (Y[0] < -wall_dist) { // Left Wall Pattern @@ -348,7 +348,7 @@ static __device__ bool collision_cube(float Y[6], uint32_t& color, float& dist) } // Kernel: trace one ray per pixel, integrate geodesic in parameter-space -__global__ void cuda_surface_raymarch_kernel(uint32_t* d_pixels, int w, int h, +__global__ void cuda_surface_raymarch_kernel(Color* d_pixels, int w, int h, Cuda::quat camera_orientation, Cuda::vec3 camera_position, float fov, float max_dist, @@ -370,7 +370,7 @@ __global__ void cuda_surface_raymarch_kernel(uint32_t* d_pixels, int w, int h, Y[4] = dir_world.y; Y[5] = dir_world.z; - uint32_t out = 0xff00ff00u; + Color out = 0xff00ff00u; float last_dist = 4.0f; float dist_traveled = 0.0f; while (dist_traveled < max_dist) { @@ -420,7 +420,7 @@ __global__ void cuda_surface_raymarch_kernel(uint32_t* d_pixels, int w, int h, } // Host-facing launcher -extern "C" void launch_cuda_surface_raymarch(uint32_t* h_pixels, int w, int h, +extern "C" void launch_cuda_surface_raymarch(Color* h_pixels, int w, int h, int x_size, Cuda::ResolvedStateEquationComponent* x_eq, int y_size, Cuda::ResolvedStateEquationComponent* y_eq, int z_size, Cuda::ResolvedStateEquationComponent* z_eq, @@ -441,8 +441,8 @@ extern "C" void launch_cuda_surface_raymarch(uint32_t* h_pixels, int w, int h, cudaMemcpyToSymbol(d_w_size, &w_size, sizeof(int)); cudaMemcpyToSymbol(special_case_code, &special, sizeof(int)); - uint32_t* d_pixels; - size_t pixel_buffer_size = w * h * sizeof(uint32_t); + Color* d_pixels; + size_t pixel_buffer_size = w * h * sizeof(Color); cudaMalloc(&d_pixels, pixel_buffer_size); dim3 block(16, 16); diff --git a/src/CUDA/differential_geometry/numerical_2d.cu b/src/CUDA/differential_geometry/numerical_2d.cu index b7429840..b6cb79a8 100644 --- a/src/CUDA/differential_geometry/numerical_2d.cu +++ b/src/CUDA/differential_geometry/numerical_2d.cu @@ -177,7 +177,7 @@ static __device__ bool rk4_step_geodesic(float Y[4], float dt) { } __global__ void geodesics_2d_kernel( - uint32_t* pixels, const int w, const int h, + Color* pixels, const int w, const int h, const Cuda::vec2 start_position, const Cuda::vec2 start_velocity, const int num_geodesics, const int num_steps, const float spread_angle, const Cuda::vec3 camera_pos, const Cuda::quat camera_direction, @@ -249,7 +249,7 @@ __global__ void geodesics_2d_kernel( } extern "C" void cuda_render_geodesics_2d( - uint32_t* pixels, const int w, const int h, + Color* pixels, const int w, const int h, const Cuda::ManifoldData& manifold, const Cuda::vec2 start_position, const Cuda::vec2 start_velocity, const int num_geodesics, const int num_steps, const float spread_angle, @@ -257,9 +257,9 @@ extern "C" void cuda_render_geodesics_2d( const float geom_mean_size, const float fov, const float opacity ) { // Allocate and copy pixels to device - uint32_t* d_pixels; - cudaMalloc(&d_pixels, w * h * sizeof(uint32_t)); - cudaMemcpy(d_pixels, pixels, w * h * sizeof(uint32_t), cudaMemcpyHostToDevice); + Color* d_pixels; + cudaMalloc(&d_pixels, w * h * sizeof(Color)); + cudaMemcpy(d_pixels, pixels, w * h * sizeof(Color), cudaMemcpyHostToDevice); Cuda::ManifoldData cp_manifold = deepcopy_manifold(manifold); cudaMemcpyToSymbol(d_manifold, &cp_manifold, sizeof(Cuda::ManifoldData)); @@ -278,7 +278,7 @@ extern "C" void cuda_render_geodesics_2d( cudaDeviceSynchronize(); // Copy pixels back to host - cudaMemcpy(pixels, d_pixels, w * h * sizeof(uint32_t), cudaMemcpyDeviceToHost); + cudaMemcpy(pixels, d_pixels, w * h * sizeof(Color), cudaMemcpyDeviceToHost); // Free device memory cudaFree(d_pixels); diff --git a/src/CUDA/edge_detect.cuh b/src/CUDA/edge_detect.cuh index 06051871..a335c61c 100644 --- a/src/CUDA/edge_detect.cuh +++ b/src/CUDA/edge_detect.cuh @@ -6,7 +6,7 @@ // If the depth difference between a pixel and any of its 4-connected neighbors // is greater than .1, color the pixel with edge_color. __global__ void cuda_edge_detect_kernel( - uint32_t* d_pixels, float* d_depth_buffer, int w, int h, uint32_t edge_color + Color* d_pixels, float* d_depth_buffer, int w, int h, Color edge_color ) { int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; @@ -40,7 +40,7 @@ __global__ void cuda_edge_detect_kernel( } void cuda_edge_detect( - uint32_t* d_pixels, float* d_depth_buffer, int w, int h, uint32_t edge_color + Color* d_pixels, float* d_depth_buffer, int w, int h, Color edge_color ) { dim3 blockSize(16, 16); dim3 gridSize((w + blockSize.x - 1) / blockSize.x, (h + blockSize.y - 1) / blockSize.y); diff --git a/src/CUDA/mandelbrot.cu b/src/CUDA/mandelbrot.cu index 70820b86..f6000ad9 100644 --- a/src/CUDA/mandelbrot.cu +++ b/src/CUDA/mandelbrot.cu @@ -9,11 +9,11 @@ const float bailout_radius = 256; const float bailout_radius_sq = bailout_radius*bailout_radius; // Function to linearly interpolate between two colors -__device__ unsigned int cuda_color_lerp(unsigned int c1, unsigned int c2, float t) { - return ((unsigned int)((1 - t) * ((c1 >> 24) & 0xff) + t * ((c2 >> 24) & 0xff)) << 24) | - ((unsigned int)((1 - t) * ((c1 >> 16) & 0xff) + t * ((c2 >> 16) & 0xff)) << 16) | - ((unsigned int)((1 - t) * ((c1 >> 8 ) & 0xff) + t * ((c2 >> 8 ) & 0xff)) << 8 ) | - ((unsigned int)((1 - t) * ( c1 & 0xff) + t * ( c2 & 0xff)) ) ; +__device__ Color cuda_color_lerp(Color c1, Color c2, float t) { + return (static_cast((1 - t) * ((c1 >> 24) & 0xff) + t * ((c2 >> 24) & 0xff)) << 24) | + (static_cast((1 - t) * ((c1 >> 16) & 0xff) + t * ((c2 >> 16) & 0xff)) << 16) | + (static_cast((1 - t) * ((c1 >> 8 ) & 0xff) + t * ((c2 >> 8 ) & 0xff)) << 8 ) | + static_cast((1 - t) * ( c1 & 0xff) + t * ( c2 & 0xff)); } __device__ cuComplex cuCpow(cuComplex base, cuComplex exponent) { @@ -34,7 +34,7 @@ __device__ cuComplex cuCpow(cuComplex base, cuComplex exponent) { } // Color interpolation function (shared) -__device__ unsigned int get_mandelbrot_color(float iterations, int max_iterations, bool bailed_out, float gradation, float sq_radius, float log_real_part_exp, float phase_shift, unsigned int internal_color) { +__device__ Color get_mandelbrot_color(float iterations, int max_iterations, bool bailed_out, float gradation, float sq_radius, float log_real_part_exp, float phase_shift, Color internal_color) { if(!bailed_out) return internal_color; if(bailed_out && gradation > 0.01){ @@ -43,7 +43,7 @@ __device__ unsigned int get_mandelbrot_color(float iterations, int max_iteration iterations += (1-nu) * gradation; // Do not use gradient for exponential parameterization } - const unsigned int color_palette[] = { + const Color color_palette[] = { 0xffffffff, 0xff000088, 0xff000000, @@ -157,8 +157,8 @@ __global__ void go( int max_iterations, float gradation, float phase_shift, - unsigned int internal_color, - unsigned int* colors + Color internal_color, + Color* colors ) { int pixel_x = blockIdx.x * blockDim.x + threadIdx.x; int pixel_y = blockIdx.y * blockDim.y + threadIdx.y; @@ -196,13 +196,13 @@ extern "C" void mandelbrot_render( int max_iterations, // Pass max_iterations as a parameter float gradation, float phase_shift, - unsigned int internal_color, - unsigned int* colors + Color internal_color, + Color* colors ) { - unsigned int* d_colors; + Color* d_colors; // Allocate memory on the device for the depth buffer - cudaMalloc(&d_colors, width * height * sizeof(unsigned int)); + cudaMalloc(&d_colors, width * height * sizeof(Color)); // Define grid and block dimensions dim3 threadsPerBlock(16, 16); // 2D block of 16x16 threads @@ -218,7 +218,7 @@ extern "C" void mandelbrot_render( ); // Copy results back from device to host - cudaMemcpy(colors, d_colors, width * height * sizeof(unsigned int), cudaMemcpyDeviceToHost); + cudaMemcpy(colors, d_colors, width * height * sizeof(Color), cudaMemcpyDeviceToHost); // Free the device memory cudaFree(d_colors); diff --git a/src/CUDA/mandelbulb.cu b/src/CUDA/mandelbulb.cu index 05756e67..290e2051 100644 --- a/src/CUDA/mandelbulb.cu +++ b/src/CUDA/mandelbulb.cu @@ -6,7 +6,7 @@ const float EPSILON = 2e-4f; -__device__ unsigned int getLighting(const Cuda::vec3& pos, const Cuda::vec3& lightPos, const Cuda::vec3& normal, float shadow, float iters, float max_raymarch_iters){ +__device__ Color getLighting(const Cuda::vec3& pos, const Cuda::vec3& lightPos, const Cuda::vec3& normal, float shadow, float iters, float max_raymarch_iters){ float light = max(dot(normal, normalize(lightPos - pos)), 0.0); light *= max(shadow, 0.1); float glow = min(iters / max_raymarch_iters, 1.0); @@ -70,7 +70,7 @@ __device__ Cuda::vec3 getNormal(const Cuda::vec3& pos, int max_mandelbulb_iters) )); } -__global__ void runRaymarch(const int width, const int height, const Cuda::vec3 pos, const Cuda::quat camera_orientation, float fov, const Cuda::vec3 lightPos, int max_raymarch_iters, int max_mandelbulb_iters, unsigned int* colors){ +__global__ void runRaymarch(const int width, const int height, const Cuda::vec3 pos, const Cuda::quat camera_orientation, float fov, const Cuda::vec3 lightPos, int max_raymarch_iters, int max_mandelbulb_iters, Color* colors){ int pixel_x = blockIdx.x * blockDim.x + threadIdx.x; int pixel_y = blockIdx.y * blockDim.y + threadIdx.y; @@ -84,7 +84,7 @@ __global__ void runRaymarch(const int width, const int height, const Cuda::vec3 const Cuda::vec3 end_pos = rayEnd; float iters = rayEnd.w; - unsigned int color; + Color color; // Determines whether to color pixel if(iters >= 0.0){ @@ -103,12 +103,12 @@ extern "C" void render_raymarch( const Cuda::vec3& pos, const Cuda::quat& camera, float fov, const Cuda::vec3& lightPos, const int max_raymarch_iters, const int max_mandelbulb_iters, - unsigned int* colors + Color* colors ){ - unsigned int* d_colors; + Color* d_colors; // Allocates device memory for color array (image buffer) - cudaMalloc(&d_colors, width * height * sizeof(unsigned int)); + cudaMalloc(&d_colors, width * height * sizeof(Color)); // Defines thread and block sizes for kernel launch dim3 threads(16, 16); @@ -116,7 +116,7 @@ extern "C" void render_raymarch( runRaymarch<<>>(width, height, pos, normalize(camera), fov, lightPos, max_raymarch_iters, max_mandelbulb_iters, d_colors); - cudaMemcpy(colors, d_colors, width * height * sizeof(unsigned int), cudaMemcpyDeviceToHost); + cudaMemcpy(colors, d_colors, width * height * sizeof(Color), cudaMemcpyDeviceToHost); cudaFree(d_colors); } diff --git a/src/CUDA/manifold.cu b/src/CUDA/manifold.cu index 8aefe2ab..f2583446 100644 --- a/src/CUDA/manifold.cu +++ b/src/CUDA/manifold.cu @@ -11,13 +11,13 @@ // Kernel __global__ void render_manifold_kernel( - uint32_t* pixels, const int w, const int h, + Color* pixels, const int w, const int h, const Cuda::ManifoldData d_manifold, const Cuda::vec3 camera_pos, const Cuda::quat camera_direction, const float geom_mean_size, const float fov, float* depth_buffer, const float ab_dilation, const float dot_radius, - const uint32_t* tex_pixels, const int tex_w, const int tex_h + const Color* tex_pixels, const int tex_w, const int tex_h ) { // Determine u, v from thread indices int u_idx = blockIdx.x * blockDim.x + threadIdx.x; @@ -53,7 +53,7 @@ __global__ void render_manifold_kernel( ); if(behind_camera) return; // Don't render points behind camera - uint32_t color = 0; + Color color = 0; if (tex_pixels != nullptr) { // Map u,v into texture coordinates by stretching uv space onto the texture (nearest-neighbor) @@ -99,17 +99,17 @@ __global__ void render_manifold_kernel( // Externed entry point extern "C" void cuda_render_manifold( - uint32_t* pixels, const int w, const int h, + Color* pixels, const int w, const int h, const Cuda::ManifoldData* manifold, const int num_manifolds, const Cuda::vec3 camera_pos, const Cuda::quat camera_direction, const float geom_mean_size, const float fov, const float ab_dilation, const float dot_radius, - const uint32_t* d_tex_pixels, const int tex_w, const int tex_h + const Color* d_tex_pixels, const int tex_w, const int tex_h ) { // Allocate and copy pixels to device - uint32_t* d_pixels; - cudaMalloc(&d_pixels, w * h * sizeof(uint32_t)); - cudaMemcpy(d_pixels, pixels, w * h * sizeof(uint32_t), cudaMemcpyHostToDevice); + Color* d_pixels; + cudaMalloc(&d_pixels, w * h * sizeof(Color)); + cudaMemcpy(d_pixels, pixels, w * h * sizeof(Color), cudaMemcpyHostToDevice); // Allocate zeroized depth buffer on device (initialize to large values from host) float* d_depth_buffer; @@ -141,20 +141,20 @@ extern "C" void cuda_render_manifold( cuda_edge_detect(d_pixels, d_depth_buffer, w, h, 0xff0000ff); // Copy pixels back to host - cudaMemcpy(pixels, d_pixels, w * h * sizeof(uint32_t), cudaMemcpyDeviceToHost); + cudaMemcpy(pixels, d_pixels, w * h * sizeof(Color), cudaMemcpyDeviceToHost); // Free device memory cudaFree(d_pixels); cudaFree(d_depth_buffer); } -extern "C" uint32_t* cuda_copy_texture_to_device(const uint32_t* h_tex_pixels, const int tex_w, const int tex_h) { - size_t tex_size = (size_t)tex_w * (size_t)tex_h * sizeof(uint32_t); - uint32_t* d_tex_pixels; +extern "C" Color* cuda_copy_texture_to_device(const Color* h_tex_pixels, const int tex_w, const int tex_h) { + size_t tex_size = (size_t)tex_w * (size_t)tex_h * sizeof(Color); + Color* d_tex_pixels; cudaMalloc(&d_tex_pixels, tex_size); cudaMemcpy(d_tex_pixels, h_tex_pixels, tex_size, cudaMemcpyHostToDevice); return d_tex_pixels; } -extern "C" void cuda_free_texture(uint32_t* d_tex_pixels) { +extern "C" void cuda_free_texture(Color* d_tex_pixels) { cudaFree(d_tex_pixels); } diff --git a/src/CUDA/pixels_manip.cu b/src/CUDA/pixels_manip.cu index 1ee02dc5..e5959b79 100644 --- a/src/CUDA/pixels_manip.cu +++ b/src/CUDA/pixels_manip.cu @@ -19,8 +19,8 @@ __device__ float bicubic_weight(float t) { }; __global__ void bicubic_scale_kernel( - const unsigned int* in_pixels, const int in_w, const int in_h, - unsigned int* out_pixels, const int out_w, const int out_h, + const Color* in_pixels, const int in_w, const int in_h, + Color* out_pixels, const int out_w, const int out_h, const float x_ratio, const float y_ratio) { int idx = blockDim.x * blockIdx.x + threadIdx.x; @@ -52,7 +52,7 @@ __global__ void bicubic_scale_kernel( xi = Cuda::clamp(xi, 0, in_w - 1); yi = Cuda::clamp(yi, 0, in_h - 1); - unsigned int pixel = in_pixels[yi * in_w + xi]; + Color pixel = in_pixels[yi * in_w + xi]; float weight = bicubic_weight(dx - m) * bicubic_weight(dy - n); pa += weight * d_geta(pixel); @@ -75,12 +75,12 @@ __global__ void bicubic_scale_kernel( out_pixels[y * out_w + x] = d_argb(ia, ir, ig, ib); } -extern "C" int cuda_bicubic_scale(const unsigned int* input_pixels, int input_w, int input_h, unsigned int* output_pixels, int output_w, int output_h) { - unsigned int* d_input = nullptr; - unsigned int* d_output = nullptr; +extern "C" int cuda_bicubic_scale(const Color* input_pixels, int input_w, int input_h, Color* output_pixels, int output_w, int output_h) { + Color* d_input = nullptr; + Color* d_output = nullptr; - size_t in_size = input_w * input_h * sizeof(unsigned int); - size_t out_size = output_w * output_h * sizeof(unsigned int); + size_t in_size = input_w * input_h * sizeof(Color); + size_t out_size = output_w * output_h * sizeof(Color); cudaMalloc((void**)&d_input, in_size); cudaMemcpy(d_input, input_pixels, in_size, cudaMemcpyHostToDevice); @@ -108,8 +108,8 @@ extern "C" int cuda_bicubic_scale(const unsigned int* input_pixels, int input_w, } __global__ void overlay_kernel( - unsigned int* background, const int bw, const int bh, - unsigned int* foreground, const int fw, const int fh, + Color* background, const int bw, const int bh, + Color* foreground, const int fw, const int fh, const int dx, const int dy, const float opacity) { int idx = blockDim.x * blockIdx.x + threadIdx.x; @@ -122,18 +122,18 @@ __global__ void overlay_kernel( } extern "C" void cuda_overlay( - unsigned int* h_background, const int bw, const int bh, - unsigned int* h_foreground, const int fw, const int fh, + Color* h_background, const int bw, const int bh, + Color* h_foreground, const int fw, const int fh, const int dx, const int dy, const float opacity) { if (opacity == 0.0f) return; - unsigned int* d_background = nullptr; - unsigned int* d_foreground = nullptr; + Color* d_background = nullptr; + Color* d_foreground = nullptr; - size_t bg_size = bw * bh * sizeof(unsigned int); - size_t fg_size = fw * fh * sizeof(unsigned int); + size_t bg_size = bw * bh * sizeof(Color); + size_t fg_size = fw * fh * sizeof(Color); cudaMalloc((void**)&d_background, bg_size); cudaMemcpy(d_background, h_background, bg_size, cudaMemcpyHostToDevice); @@ -157,8 +157,8 @@ extern "C" void cuda_overlay( } __global__ void overlay_rotation_kernel( - unsigned int* background, const int bw, const int bh, - unsigned int* foreground, const int fw, const int fh, + Color* background, const int bw, const int bh, + Color* foreground, const int fw, const int fh, const int dx, const int dy, const float opacity, const float angle_rad) { int idx = blockDim.x * blockIdx.x + threadIdx.x; @@ -199,10 +199,10 @@ __global__ void overlay_rotation_kernel( float sx = srcx - x0; float sy = srcy - y0; - unsigned int p00 = foreground[y0 * fw + x0]; - unsigned int p10 = foreground[y0 * fw + x1]; - unsigned int p01 = foreground[y1 * fw + x0]; - unsigned int p11 = foreground[y1 * fw + x1]; + Color p00 = foreground[y0 * fw + x0]; + Color p10 = foreground[y0 * fw + x1]; + Color p01 = foreground[y1 * fw + x0]; + Color p11 = foreground[y1 * fw + x1]; float a00 = static_cast(d_geta(p00)); float r00 = static_cast(d_getr(p00)); @@ -249,8 +249,8 @@ __global__ void overlay_rotation_kernel( } extern "C" void cuda_overlay_with_rotation ( - unsigned int* h_background, const int bw, const int bh, - unsigned int* h_foreground, const int fw, const int fh, + Color* h_background, const int bw, const int bh, + Color* h_foreground, const int fw, const int fh, const int dx, const int dy, const float opacity, const float angle_rad) { @@ -258,11 +258,11 @@ extern "C" void cuda_overlay_with_rotation ( // by the specified angle (in radians) before being overlaid onto the background. if (opacity == 0.0f) return; - unsigned int* d_background = nullptr; - unsigned int* d_foreground = nullptr; + Color* d_background = nullptr; + Color* d_foreground = nullptr; - size_t bg_size = bw * bh * sizeof(unsigned int); - size_t fg_size = fw * fh * sizeof(unsigned int); + size_t bg_size = bw * bh * sizeof(Color); + size_t fg_size = fw * fh * sizeof(Color); cudaMalloc((void**)&d_background, bg_size); cudaMemcpy(d_background, h_background, bg_size, cudaMemcpyHostToDevice); diff --git a/src/CUDA/polynomials/complex_polynomial.cu b/src/CUDA/polynomials/complex_polynomial.cu index 16390f17..22c8a9cf 100644 --- a/src/CUDA/polynomials/complex_polynomial.cu +++ b/src/CUDA/polynomials/complex_polynomial.cu @@ -16,7 +16,7 @@ __device__ thrust::complex evaluate_polynomial_given_coefficients(const t } __global__ void render_kernel( - int* d_pixels, + Color* d_pixels, const thrust::complex* d_coefficients, int degree, Cuda::vec2 wh, @@ -31,13 +31,13 @@ __global__ void render_kernel( const Cuda::vec2 point = pixel_to_point_in_screen(Cuda::vec2(x,y), lx_ty, rx_by, wh); const thrust::complex val = evaluate_polynomial_given_coefficients(d_coefficients, degree, thrust::complex(point.x, point.y)); - const int color = d_complex_to_srgb(val, ab_dilation, dot_radius); + const Color color = d_complex_to_srgb(val, ab_dilation, dot_radius); d_pixels[y * int(wh.x) + x] = color; } extern "C" void color_complex_polynomial( - unsigned int* h_pixels, // to be overwritten with the result + Color* h_pixels, // to be overwritten with the result int w, int h, const float* h_coefficients_real, @@ -49,8 +49,8 @@ extern "C" void color_complex_polynomial( float dot_radius ) { // Allocate device memory for pixels - int* d_pixels; - cudaMalloc(&d_pixels, w * h * sizeof(int)); + Color* d_pixels; + cudaMalloc(&d_pixels, w * h * sizeof(Color)); // Allocate device memory for coefficients thrust::complex* d_coefficients; @@ -80,7 +80,7 @@ extern "C" void color_complex_polynomial( cudaDeviceSynchronize(); // Copy pixels back to host - cudaMemcpy(h_pixels, d_pixels, w * h * sizeof(int), cudaMemcpyDeviceToHost); + cudaMemcpy(h_pixels, d_pixels, w * h * sizeof(Color), cudaMemcpyDeviceToHost); // Free device memory cudaFree(d_pixels); diff --git a/src/CUDA/polynomials/root_fractal.cu b/src/CUDA/polynomials/root_fractal.cu index b891c053..8f9fb750 100644 --- a/src/CUDA/polynomials/root_fractal.cu +++ b/src/CUDA/polynomials/root_fractal.cu @@ -92,7 +92,7 @@ __device__ float sigmoid(float x) { return 3*x*x-2*x*x*x; } -__global__ void finalize_color_kernel(unsigned int* d_pixels, float* d_alpha, float* d_red, float* d_green, float* d_blue, int w, int h, float brightness) { +__global__ void finalize_color_kernel(Color* d_pixels, float* d_alpha, float* d_red, float* d_green, float* d_blue, int w, int h, float brightness) { unsigned int idx = blockIdx.x * blockDim.x + threadIdx.x; unsigned int total = w * h; @@ -117,7 +117,7 @@ __global__ void finalize_color_kernel(unsigned int* d_pixels, float* d_alpha, fl } extern "C" void draw_root_fractal( - unsigned int* pixels, + Color* pixels, int w, int h, std::complex c1, @@ -144,8 +144,8 @@ extern "C" void draw_root_fractal( root_fractal_kernel<<>>(d_alpha, d_red, d_green, d_blue, w, h, dc1, dc2, terms, lx, ty, rx, by, radius, opacity); cudaDeviceSynchronize(); - unsigned int* d_pixels; - cudaMalloc(&d_pixels, w * h * sizeof(unsigned int)); + Color* d_pixels; + cudaMalloc(&d_pixels, w * h * sizeof(Color)); int finalize_threadsPerBlock = 256; int finalize_blocks = (w * h + finalize_threadsPerBlock - 1) / finalize_threadsPerBlock; @@ -157,6 +157,6 @@ extern "C" void draw_root_fractal( cudaFree(d_green); cudaFree(d_blue); - cudaMemcpy(pixels, d_pixels, w * h * sizeof(unsigned int), cudaMemcpyDeviceToHost); + cudaMemcpy(pixels, d_pixels, w * h * sizeof(Color), cudaMemcpyDeviceToHost); cudaFree(d_pixels); } diff --git a/src/CUDA/surface.cu b/src/CUDA/surface.cu index c21b3500..2f52d393 100644 --- a/src/CUDA/surface.cu +++ b/src/CUDA/surface.cu @@ -6,13 +6,13 @@ __global__ void render_surface_kernel( // d_pixels is the array which we will plop a surface on. The surface is bounded by (x1,y1) on the top left and (x2,y2) on the top right. - unsigned int* d_pixels_dev, + Color* d_pixels_dev, int x1, int y1, int plot_w, int plot_h, int pixels_w, - unsigned int* d_surface, + Color* d_surface, int surface_w, int surface_h, float opacity, @@ -61,19 +61,19 @@ __global__ void render_surface_kernel( int surface_x = surface_coords.x * surface_w; int surface_y = surface_coords.y * surface_h; - unsigned int color = d_surface[surface_x + surface_y * surface_w]; + Color color = d_surface[surface_x + surface_y * surface_w]; d_pixels_dev[pixels_index] = d_color_combine(d_pixels_dev[pixels_index], color, opacity); } extern "C" void cuda_render_surface( - vector& pix, + vector& pix, int x1, int y1, int plot_w, int plot_h, int pixels_w, - unsigned int* d_surface, + Color* d_surface, int surface_w, int surface_h, float opacity, @@ -93,12 +93,12 @@ extern "C" void cuda_render_surface( // Allocate memory on the device size_t pixels_size = pix.size() * sizeof(int); - unsigned int* d_pixels_dev; + Color* d_pixels_dev; cudaMalloc(&d_pixels_dev, pixels_size); cudaMemcpy(d_pixels_dev, pix.data(), pixels_size, cudaMemcpyHostToDevice); - size_t surface_size = surface_w * surface_h * sizeof(unsigned int); - unsigned int* d_surface_dev; + size_t surface_size = surface_w * surface_h * sizeof(Color); + Color* d_surface_dev; cudaMalloc(&d_surface_dev, surface_size); // Copy data to device diff --git a/src/Core/Color.h b/src/Core/Color.h index 88ab54e4..cd20c3d8 100644 --- a/src/Core/Color.h +++ b/src/Core/Color.h @@ -1,53 +1,54 @@ #pragma once #include +#include "../Host_Device_Shared/Color.h" #include "../Host_Device_Shared/helpers.h" // Colors are everywhere. For the sake of speed, we do not give them a dedicated class. -// They are ints under the hood, and are always 32-bit, 4-channel ARGB. - -inline int argb(int a, int r, int g, int b){return (a<<24)+ - (r<<16)+ - (g<<8 )+ - (b );} -inline int geta(int col){return (col&0xff000000)>>24;} -inline int getr(int col){return (col&0x00ff0000)>>16;} -inline int getg(int col){return (col&0x0000ff00)>>8 ;} -inline int getb(int col){return (col&0x000000ff) ;} -inline int alpha_multiply(int col, float opacity){return (static_cast(geta(col) * opacity) << 24) | col&0xffffff;} -inline int coldist(int col1, int col2){return abs(geta(col1) - geta(col2)) + - abs(getr(col1) - getr(col2)) + - abs(getg(col1) - getg(col2)) + - abs(getb(col1) - getb(col2));} -inline int rainbow(float x){return argb(255, - sin((x+1/3.)*M_PI*2)*128.+128, - sin((x+2/3.)*M_PI*2)*128.+128, - sin((x )*M_PI*2)*128.+128);} -inline int colorlerp(int col1, int col2, float w){return argb(round(lerp(geta(col1), geta(col2), w)), - round(lerp(getr(col1), getr(col2), w)), - round(lerp(getg(col1), getg(col2), w)), - round(lerp(getb(col1), getb(col2), w)));} -inline string color_to_string(int c){return "(" + to_string(geta(c)) + ", " + to_string(getr(c)) + ", " + to_string(getg(c)) + ", " + to_string(getb(c)) + ")";} -inline void print_argb(int c){cout << color_to_string(c) << endl;} - -inline int color_combine(int base_color, int over_color, float overlay_opacity_multiplier = 1) { +// They are Colors under the hood, and are always 32-bit, 4-channel ARGB. + +inline Color argb(int a, int r, int g, int b){return (static_cast(a) << 24) | + (static_cast(r) << 16) | + (static_cast(g) << 8 ) | + static_cast(b);} +inline int geta(Color col){return (col&0xff000000)>>24;} +inline int getr(Color col){return (col&0x00ff0000)>>16;} +inline int getg(Color col){return (col&0x0000ff00)>>8 ;} +inline int getb(Color col){return (col&0x000000ff) ;} +inline Color alpha_multiply(Color col, float opacity){return (static_cast(geta(col) * opacity) << 24) | (col&0x00ffffff);} +inline int coldist(Color col1, Color col2){return abs(geta(col1) - geta(col2)) + + abs(getr(col1) - getr(col2)) + + abs(getg(col1) - getg(col2)) + + abs(getb(col1) - getb(col2));} +inline Color rainbow(float x){return argb(255, + sin((x+1/3.)*M_PI*2)*128.+128, + sin((x+2/3.)*M_PI*2)*128.+128, + sin((x )*M_PI*2)*128.+128);} +inline Color colorlerp(Color col1, Color col2, float w){return argb(round(lerp(geta(col1), geta(col2), w)), + round(lerp(getr(col1), getr(col2), w)), + round(lerp(getg(col1), getg(col2), w)), + round(lerp(getb(col1), getb(col2), w)));} +inline string color_to_string(Color c){return "(" + to_string(geta(c)) + ", " + to_string(getr(c)) + ", " + to_string(getg(c)) + ", " + to_string(getb(c)) + ")";} +inline void print_argb(Color c){cout << color_to_string(c) << endl;} + +inline Color color_combine(Color base_color, Color over_color, float overlay_opacity_multiplier = 1) { float base_opacity = geta(base_color) / 255.0; float over_opacity = geta(over_color) / 255.0 * overlay_opacity_multiplier; float final_opacity = 1 - (1 - base_opacity) * (1 - over_opacity); if (final_opacity == 0) return 0x00000000; int final_alpha = round(final_opacity * 255.0); - float chroma_weight = over_opacity / final_opacity; - int final_rgb = colorlerp(base_color, over_color, chroma_weight) & 0x00ffffff; - return (final_alpha << 24) | (final_rgb); + const float chroma_weight = over_opacity / final_opacity; + const Color final_rgb = colorlerp(base_color, over_color, chroma_weight) & 0x00ffffff; + return (static_cast(final_alpha) << 24) | final_rgb; } -inline int black_to_blue_to_white(double w){ +inline Color black_to_blue_to_white(double w){ int rainbow_part1 = max(0.,min(1.,w*2-0))*255.; int rainbow_part2 = max(0.,min(1.,w*2-1))*255.; return argb(255, rainbow_part2, rainbow_part2, rainbow_part1); } -inline int RGBtoOKLAB(int rgb) +inline Color RGBtoOKLAB(Color rgb) { int r = getr(rgb); int g = getg(rgb); @@ -75,7 +76,7 @@ inline float linear_srgb_to_srgb(float x) { return 12.92 * x; } -inline int OKLABtoRGB(int alpha, float L, float a, float b) +inline Color OKLABtoRGB(int alpha, float L, float a, float b) { float l_ = L + 0.3963377774f * a + 0.2158037573f * b; float m_ = L - 0.1055613458f * a - 0.0638541728f * b; @@ -94,7 +95,7 @@ inline int OKLABtoRGB(int alpha, float L, float a, float b) } // Convert RGB to YUV -inline int RGBtoYUV(const int rgb) { +inline Color RGBtoYUV(const Color rgb) { int r = getr(rgb); int g = getg(rgb); int b = getb(rgb); @@ -112,7 +113,7 @@ inline int RGBtoYUV(const int rgb) { } // Convert YUV to RGB -inline int YUVtoRGB(const int yuv) { +inline Color YUVtoRGB(const Color yuv) { int y = getr(yuv); int u = getg(yuv)-128; int v = getb(yuv)-128; @@ -131,7 +132,7 @@ inline int YUVtoRGB(const int yuv) { // Convert HSV to RGB // h, s, v are in the range [0, 1] -inline int HSVtoRGB(double h, double s, double v, int alpha = 255) { +inline Color HSVtoRGB(double h, double s, double v, int alpha = 255) { double r_f, g_f, b_f; if (s == 0.0) { @@ -162,7 +163,7 @@ inline int HSVtoRGB(double h, double s, double v, int alpha = 255) { return argb(alpha, r, g, b); } -inline int pendulum_color_old(double angle1, double angle2) { +inline Color pendulum_color_old(double angle1, double angle2) { angle1 += M_PI; double y_f = 127.5 + 64 * sin(angle1 + angle2); double u_f = 127.5 + 128 * sin(angle1)*cos(angle2); @@ -174,7 +175,7 @@ inline int pendulum_color_old(double angle1, double angle2) { return YUVtoRGB(argb(255, y, u, v)); } -inline int pendulum_color(double angle1, double angle2, double p1, double p2) { +inline Color pendulum_color(double angle1, double angle2, double p1, double p2) { float sa1 = sin(angle1) + 0.000001; float sa2 = sin(angle2); float h = atan2(sa2, sa1)/6.283+1; @@ -183,9 +184,9 @@ inline int pendulum_color(double angle1, double angle2, double p1, double p2) { return HSVtoRGB(h, s, v); } -inline string latex_color(unsigned int color, string text) { +inline string latex_color(Color color, string text) { // Mask out the alpha channel - unsigned int rgb = color & 0x00FFFFFF; + Color rgb = color & 0x00FFFFFF; // Convert to a hex string stringstream ss; diff --git a/src/Core/Convolution.cpp b/src/Core/Convolution.cpp index 3fa59670..dc352f48 100644 --- a/src/Core/Convolution.cpp +++ b/src/Core/Convolution.cpp @@ -38,7 +38,7 @@ Pixels convolve_map(const Pixels& p1, const Pixels& p2, int& max_x, int& max_y) return create_alpha_from_intensities(map_2d); } -void flood_fill(Pixels& ret, const Pixels& p, int start_x, int start_y, int color) { +void flood_fill(Pixels& ret, const Pixels& p, int start_x, int start_y, Color color) { stack> stack; stack.push({start_x, start_y}); @@ -116,7 +116,7 @@ Pixels remove_unconnected_components(const Pixels& p) { // Construct the output by copying the input and bitwise AND-ing it for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { - int pixel = p.get_pixel_carelessly(x, y) & output.get_pixel_carelessly(x, y); + Color pixel = p.get_pixel_carelessly(x, y) & output.get_pixel_carelessly(x, y); output.set_pixel_carelessly(x, y, pixel); } } @@ -283,12 +283,12 @@ Pixels colorize_segments(const Pixels& segmented) { Pixels colorized(width, height); // A simple function to generate a deterministic but pseudo-random color based on segment ID - auto segment_id_to_color = [](unsigned int id) -> int { + auto segment_id_to_color = [](unsigned int id) -> Color { // Example: Use a hash-like function to generate color from segment ID unsigned int r = (id * 137 + 113) % 256; unsigned int g = (id * 149 + 157) % 256; unsigned int b = (id * 163 + 173) % 256; - return (r << 16) | (g << 8) | b; + return (static_cast(r) << 16) | (static_cast(g) << 8) | static_cast(b); }; // Iterate over each pixel in the segmented image @@ -301,7 +301,7 @@ Pixels colorize_segments(const Pixels& segmented) { return colorized; } -int count_pixels_with_color(const Pixels& p, const unsigned int color) { +int count_pixels_with_color(const Pixels& p, Color color) { int count = 0; for (int y = 0; y < p.h; ++y) { diff --git a/src/Core/Convolution.h b/src/Core/Convolution.h index 40e544d0..3c1a5a41 100644 --- a/src/Core/Convolution.h +++ b/src/Core/Convolution.h @@ -45,12 +45,12 @@ class TranslatedPixels { return pixels.out_of_range(x - translation_x, y - translation_y); } - inline int get_pixel(int x, int y) const { + inline Color get_pixel(int x, int y) const { if (out_of_range(x, y)) return 0; return pixels.get_pixel_carelessly(x - translation_x, y - translation_y); } - inline void set_pixel(int x, int y, int col) { + inline void set_pixel(int x, int y, Color col) { if (out_of_range(x, y)) return; pixels.set_pixel_carelessly(x - translation_x, y - translation_y, col); } @@ -66,7 +66,7 @@ class TranslatedPixels { Pixels convolve_map(const Pixels& p1, const Pixels& p2, int& max_x, int& max_y); -void flood_fill(Pixels& ret, const Pixels& p, int start_x, int start_y, int color); +void flood_fill(Pixels& ret, const Pixels& p, int start_x, int start_y, Color color); Pixels segment(const Pixels& p, unsigned int& id); @@ -86,7 +86,7 @@ TranslatedPixels induce(const TranslatedPixels& original, const TranslatedPixels Pixels colorize_segments(const Pixels& segmented); -int count_pixels_with_color(const Pixels& p, const unsigned int color); +int count_pixels_with_color(const Pixels& p, Color color); TranslatedPixels erase_low_iou(const TranslatedPixels& intersection, const TranslatedPixels& unified, float threshold); diff --git a/src/Core/Pixels.cpp b/src/Core/Pixels.cpp index c0d17e6b..7da8801e 100644 --- a/src/Core/Pixels.cpp +++ b/src/Core/Pixels.cpp @@ -10,7 +10,7 @@ #include #include "../IO/Writer.h" -extern "C" int cuda_bicubic_scale(const unsigned int* input_pixels, int input_w, int input_h, unsigned int* output_pixels, int output_w, int output_h); +extern "C" int cuda_bicubic_scale(const Color* input_pixels, int input_w, int input_h, Color* output_pixels, int output_w, int output_h); Pixels::Pixels() : w(0), h(0), pixels(0) {} Pixels::Pixels(int width, int height) : w(width), h(height), pixels(width*height) {} @@ -19,21 +19,21 @@ bool Pixels::out_of_range(int x, int y) const { return x < 0 || x >= w || y < 0 || y >= h; } -int Pixels::get_pixel_carelessly(int x, int y) const { +Color Pixels::get_pixel_carelessly(int x, int y) const { return pixels[w*y+x]; } -int Pixels::get_pixel_carefully(int x, int y) const { +Color Pixels::get_pixel_carefully(int x, int y) const { if(out_of_range(x, y)) return TRANSPARENT_BLACK; // 0 return pixels[w*y+x]; } -void Pixels::overlay_pixel(int x, int y, int col, double overlay_opacity_multiplier){ +void Pixels::overlay_pixel(int x, int y, Color col, double overlay_opacity_multiplier){ set_pixel_carefully(x, y, color_combine(get_pixel_carefully(x, y), col, overlay_opacity_multiplier)); } void Pixels::get_pixel_by_channels(int x, int y, int& a, int& r, int& g, int& b) const { - int col = get_pixel_carefully(x,y); + Color col = get_pixel_carefully(x,y); a=geta(col); r=getr(col); g=getg(col); @@ -44,11 +44,11 @@ int Pixels::get_alpha(int x, int y) const { return geta(get_pixel_carefully(x,y)); } -void Pixels::set_pixel_carelessly(int x, int y, int col) { +void Pixels::set_pixel_carelessly(int x, int y, Color col) { pixels[w*y+x] = col; } -void Pixels::set_pixel_carefully(int x, int y, int col) { +void Pixels::set_pixel_carefully(int x, int y, Color col) { if(out_of_range(x, y)) return; pixels[w*y+x] = col; } @@ -128,7 +128,7 @@ void Pixels::crop_by_fractions(float crop_top, float crop_bottom, float crop_lef crop(x, y, cw, ch, cropped); } -int Pixels::get_pixel_bilinear(double x, double y) const { +Color Pixels::get_pixel_bilinear(double x, double y) const { int x0 = static_cast(floor(x)); int x1 = x0 + 1; int y0 = static_cast(floor(y)); @@ -137,10 +137,10 @@ int Pixels::get_pixel_bilinear(double x, double y) const { double dx = x - x0; double dy = y - y0; - int c00 = get_pixel_carefully(x0, y0); - int c10 = get_pixel_carefully(x1, y0); - int c01 = get_pixel_carefully(x0, y1); - int c11 = get_pixel_carefully(x1, y1); + Color c00 = get_pixel_carefully(x0, y0); + Color c10 = get_pixel_carefully(x1, y0); + Color c01 = get_pixel_carefully(x0, y1); + Color c11 = get_pixel_carefully(x1, y1); int a00 = geta(c00), r00 = getr(c00), g00 = getg(c00), b00 = getb(c00); int a10 = geta(c10), r10 = getr(c10), g10 = getg(c10), b10 = getb(c10); @@ -175,7 +175,7 @@ bool Pixels::is_empty() const { return true; // No pixel with non-zero alpha found, Pixels is empty } -void Pixels::add_border(int col, int thickness){ +void Pixels::add_border(Color col, int thickness){ if(thickness > w || thickness > h) throw runtime_error("Border thickness too large."); for(int t = 0; t < thickness; t++){ @@ -208,7 +208,7 @@ void Pixels::overwrite(Pixels p, int dx, int dy){ } } -void Pixels::fill_rect(int x, int y, int rw, int rh, int col){ +void Pixels::fill_rect(int x, int y, int rw, int rh, Color col){ if(x < 0) { rw += x; x = 0; } if(y < 0) { rh += y; y = 0; } if(x + rw > w) rw = w - x; @@ -218,11 +218,11 @@ void Pixels::fill_rect(int x, int y, int rw, int rh, int col){ set_pixel_carelessly(x+dx, y+dy, col); } -void Pixels::fill_circle(double x, double y, double r, int col, double opa){ +void Pixels::fill_circle(double x, double y, double r, Color col, double opa){ fill_ring(x, y, r, 0, col, opa); } -void Pixels::fill_ring(double x, double y, double r_outer, double r_inner, int col, double opa){ +void Pixels::fill_ring(double x, double y, double r_outer, double r_inner, Color col, double opa){ double r_outer_sq = square(r_outer); double r_inner_sq = square(r_inner); for(double dx = -r_outer+1; dx < r_outer; dx++){ @@ -235,7 +235,7 @@ void Pixels::fill_ring(double x, double y, double r_outer, double r_inner, int c } } -void Pixels::fill_ellipse(double x, double y, double rw, double rh, int col, double opa){ +void Pixels::fill_ellipse(double x, double y, double rw, double rh, Color col, double opa){ for(double dx = -rw+1; dx < rw; dx++){ double sdx = square(dx/rw); for(double dy = -rh+1; dy < rh; dy++) @@ -244,7 +244,7 @@ void Pixels::fill_ellipse(double x, double y, double rw, double rh, int col, dou } } -void Pixels::bresenham(int x1, int y1, int x2, int y2, int col, float opacity, int thickness) { +void Pixels::bresenham(int x1, int y1, int x2, int y2, Color col, float opacity, int thickness) { int dx = abs(x2 - x1); int dy = abs(y2 - y1); if(dx > 10000 || dy > 10000){ @@ -291,7 +291,7 @@ void Pixels::bresenham(int x1, int y1, int x2, int y2, int col, float opacity, i } } -void Pixels::rounded_rect(float x, float y, float rw, float rh, float r, int col){ +void Pixels::rounded_rect(float x, float y, float rw, float rh, float r, Color col){ int xplusr = round(x+r); int yplusr = round(y+r); int rwmrt2 = round(rw-r*2); @@ -304,7 +304,7 @@ void Pixels::rounded_rect(float x, float y, float rw, float rh, float r, int col fill_ellipse(i%2==0 ? xplusr : xprwmr, i/2==0 ? yplusr : yprhmr, r, r, col); } -void Pixels::flood_fill(int x, int y, int color) { +void Pixels::flood_fill(int x, int y, Color color) { int targetColor = get_pixel_carefully(x, y); // Check if the target pixel already has the desired color @@ -477,7 +477,7 @@ Pixels create_alpha_from_intensities(const vector>& intensi return result; } -Pixels create_pixels_from_2d_vector(const vector>& colors, int negative_intensity) { +Pixels create_pixels_from_2d_vector(const vector>& colors, int negative_intensity) { int height = colors.size(); int width = (height > 0) ? colors[0].size() : 0; diff --git a/src/Core/Pixels.h b/src/Core/Pixels.h index bfa7a297..158c48ee 100644 --- a/src/Core/Pixels.h +++ b/src/Core/Pixels.h @@ -10,19 +10,19 @@ using namespace std; -inline constexpr int OPAQUE_BLACK = 0xFF000000; -inline constexpr int OPAQUE_WHITE = 0xFFFFFFFF; -inline constexpr int TRANSPARENT_BLACK = 0x00000000; -inline constexpr int TRANSPARENT_WHITE = 0x00FFFFFF; +inline constexpr Color OPAQUE_BLACK = 0xFF000000; +inline constexpr Color OPAQUE_WHITE = 0xFFFFFFFF; +inline constexpr Color TRANSPARENT_BLACK = 0x00000000; +inline constexpr Color TRANSPARENT_WHITE = 0x00FFFFFF; extern "C" void cuda_overlay( - unsigned int* h_background, const int bw, const int bh, - unsigned int* h_foreground, const int fw, const int fh, + Color* h_background, const int bw, const int bh, + Color* h_foreground, const int fw, const int fh, const int dx, const int dy, const float opacity); extern "C" void cuda_overlay_with_rotation( - unsigned int* h_background, const int bw, const int bh, - unsigned int* h_foreground, const int fw, const int fh, + Color* h_background, const int bw, const int bh, + Color* h_foreground, const int fw, const int fh, const int dx, const int dy, const float opacity, const float angle_rad); @@ -30,23 +30,23 @@ class Pixels{ public: int w; int h; - vector pixels; + vector pixels; Pixels(); Pixels(int width, int height); bool out_of_range(int x, int y) const; - int get_pixel_carelessly(int x, int y) const; - int get_pixel_carefully(int x, int y) const; + Color get_pixel_carelessly(int x, int y) const; + Color get_pixel_carefully(int x, int y) const; - void overlay_pixel(int x, int y, int col, double overlay_opacity_multiplier = 1); + void overlay_pixel(int x, int y, Color col, double overlay_opacity_multiplier = 1); void get_pixel_by_channels(int x, int y, int& a, int& r, int& g, int& b) const; int get_alpha(int x, int y) const; - void set_pixel_carelessly(int x, int y, int col); - void set_pixel_carefully(int x, int y, int col); + void set_pixel_carelessly(int x, int y, Color col); + void set_pixel_carefully(int x, int y, Color col); void darken(float factor); @@ -61,29 +61,29 @@ class Pixels{ void crop_by_fractions(float crop_top, float crop_bottom, float crop_left, float crop_right, Pixels &cropped) const; - int get_pixel_bilinear(double x, double y) const; + Color get_pixel_bilinear(double x, double y) const; bool is_empty() const; - void add_border(int col, int thickness = 1); + void add_border(Color col, int thickness = 1); void overlay(Pixels p, int dx, int dy, double overlay_opacity_multiplier = 1); void overwrite(Pixels p, int dx, int dy); - void fill_rect(int x, int y, int rw, int rh, int col); + void fill_rect(int x, int y, int rw, int rh, Color col); - void fill_circle(double x, double y, double r, int col, double opa = 1); + void fill_circle(double x, double y, double r, Color col, double opa = 1); - void fill_ring(double x, double y, double r_outer, double r_inner, int col, double opa = 1); + void fill_ring(double x, double y, double r_outer, double r_inner, Color col, double opa = 1); - void fill_ellipse(double x, double y, double rw, double rh, int col, double opa = 1); + void fill_ellipse(double x, double y, double rw, double rh, Color col, double opa = 1); - void bresenham(int x1, int y1, int x2, int y2, int col, float opacity, int thickness); + void bresenham(int x1, int y1, int x2, int y2, Color col, float opacity, int thickness); - void rounded_rect(float x, float y, float rw, float rh, float r, int col); + void rounded_rect(float x, float y, float rw, float rh, float r, Color col); - void flood_fill(int x, int y, int color); + void flood_fill(int x, int y, Color color); Pixels naive_scale_down(int scale_down_factor) const; @@ -98,5 +98,5 @@ class Pixels{ // Free functions Pixels create_alpha_from_intensities(const vector>& intensities); -Pixels create_pixels_from_2d_vector(const vector>& colors, int negative_intensity); +Pixels create_pixels_from_2d_vector(const vector>& colors, int negative_intensity); Pixels crop_by_alpha(const Pixels& p); diff --git a/src/DataObjects/Graph.h b/src/DataObjects/Graph.h index 41d8dab4..6942ad14 100755 --- a/src/DataObjects/Graph.h +++ b/src/DataObjects/Graph.h @@ -1,6 +1,7 @@ #pragma once #include "../Host_Device_Shared/vec.h" +#include "../Host_Device_Shared/Color.h" #include #include #include @@ -45,7 +46,7 @@ class Node { EdgeSet neighbors; bool draw_point = false; double opacity = 1; - int color = 0xffffffff; + Color color = 0xffffffff; float size = 1; double age = 0; vec4 velocity; diff --git a/src/DataObjects/LambdaCalculus/LambdaAbstraction.cpp b/src/DataObjects/LambdaCalculus/LambdaAbstraction.cpp index 45b72ab8..b40f2055 100644 --- a/src/DataObjects/LambdaCalculus/LambdaAbstraction.cpp +++ b/src/DataObjects/LambdaCalculus/LambdaAbstraction.cpp @@ -10,7 +10,7 @@ using std::runtime_error; using std::max; using std::dynamic_pointer_cast; -LambdaAbstraction::LambdaAbstraction(const char v, shared_ptr b, const int c, weak_ptr p, float x, float y, float w, float h, int u) +LambdaAbstraction::LambdaAbstraction(const char v, shared_ptr b, Color c, weak_ptr p, float x, float y, float w, float h, int u) : LambdaExpression("Abstraction", c, p, x, y, w, h, u), bound_variable(v), body(b) { } unordered_set LambdaAbstraction::all_referenced_variables() const { @@ -57,7 +57,7 @@ void LambdaAbstraction::interpolate_recursive(shared_ptr mark_updated(); } -void LambdaAbstraction::tint_recursive(const int c) { +void LambdaAbstraction::tint_recursive(Color c) { body->tint_recursive(c); set_color(colorlerp(color, c, 0.5)); mark_updated(); @@ -68,7 +68,7 @@ void LambdaAbstraction::flush_uid_recursive() { uid = rand(); } -void LambdaAbstraction::set_color_recursive(const int c) { +void LambdaAbstraction::set_color_recursive(Color c) { body->set_color_recursive(c); set_color(c); mark_updated(); diff --git a/src/DataObjects/LambdaCalculus/LambdaAbstraction.h b/src/DataObjects/LambdaCalculus/LambdaAbstraction.h index ed2c149e..adc80104 100644 --- a/src/DataObjects/LambdaCalculus/LambdaAbstraction.h +++ b/src/DataObjects/LambdaCalculus/LambdaAbstraction.h @@ -15,7 +15,7 @@ class LambdaAbstraction : public LambdaExpression { char bound_variable; shared_ptr body; public: - LambdaAbstraction(const char v, shared_ptr b, const int c, weak_ptr p = shared_ptr(), float x = 0, float y = 0, float w = 0, float h = 0, int u = 0); + LambdaAbstraction(const char v, shared_ptr b, Color c, weak_ptr p = shared_ptr(), float x = 0, float y = 0, float w = 0, float h = 0, int u = 0); unordered_set all_referenced_variables() const override; unordered_set free_variables() const override; @@ -26,9 +26,9 @@ class LambdaAbstraction : public LambdaExpression { float get_width_recursive() const; float get_height_recursive() const; void interpolate_recursive(shared_ptr l2, const float weight); - void tint_recursive(const int c); + void tint_recursive(Color c); void flush_uid_recursive(); - void set_color_recursive(const int c); + void set_color_recursive(Color c); int parenthetical_depth() const override; int num_variable_instantiations() const override; bool is_reducible() const override; diff --git a/src/DataObjects/LambdaCalculus/LambdaApplication.cpp b/src/DataObjects/LambdaCalculus/LambdaApplication.cpp index b61a580e..25e64c2e 100644 --- a/src/DataObjects/LambdaCalculus/LambdaApplication.cpp +++ b/src/DataObjects/LambdaCalculus/LambdaApplication.cpp @@ -18,7 +18,7 @@ using std::max; using std::runtime_error; using std::to_string; -LambdaApplication::LambdaApplication(shared_ptr f, shared_ptr s, const int c, weak_ptr p, float x, float y, float w, float h, int u) +LambdaApplication::LambdaApplication(shared_ptr f, shared_ptr s, Color c, weak_ptr p, float x, float y, float w, float h, int u) : LambdaExpression("Application", c, p, x, y, w, h, u), first(f), second(s) { } unordered_set LambdaApplication::all_referenced_variables() const { @@ -73,7 +73,7 @@ void LambdaApplication::interpolate_recursive(shared_ptr mark_updated(); } -void LambdaApplication::tint_recursive(const int c) { +void LambdaApplication::tint_recursive(Color c) { first->tint_recursive(c); second->tint_recursive(c); set_color(colorlerp(color, c, 0.5)); @@ -86,7 +86,7 @@ void LambdaApplication::flush_uid_recursive() { uid = rand(); } -void LambdaApplication::set_color_recursive(const int c) { +void LambdaApplication::set_color_recursive(Color c) { first->set_color_recursive(c); second->set_color_recursive(c); set_color(c); diff --git a/src/DataObjects/LambdaCalculus/LambdaApplication.h b/src/DataObjects/LambdaCalculus/LambdaApplication.h index f43664e2..a8e7ff0a 100644 --- a/src/DataObjects/LambdaCalculus/LambdaApplication.h +++ b/src/DataObjects/LambdaCalculus/LambdaApplication.h @@ -12,7 +12,7 @@ class LambdaApplication : public LambdaExpression { std::shared_ptr first; std::shared_ptr second; public: - LambdaApplication(std::shared_ptr f, std::shared_ptr s, const int c, std::weak_ptr p = std::shared_ptr(), float x = 0, float y = 0, float w = 0, float h = 0, int u = 0); + LambdaApplication(std::shared_ptr f, std::shared_ptr s, Color c, std::weak_ptr p = std::shared_ptr(), float x = 0, float y = 0, float w = 0, float h = 0, int u = 0); std::unordered_set all_referenced_variables() const override; std::unordered_set free_variables() const override; @@ -29,11 +29,11 @@ class LambdaApplication : public LambdaExpression { void interpolate_recursive(std::shared_ptr l2, const float weight); - void tint_recursive(const int c); + void tint_recursive(Color c); void flush_uid_recursive(); - void set_color_recursive(const int c); + void set_color_recursive(Color c); int parenthetical_depth() const override; diff --git a/src/DataObjects/LambdaCalculus/LambdaExpression.cpp b/src/DataObjects/LambdaCalculus/LambdaExpression.cpp index 3dfb0a3e..0e2e0450 100644 --- a/src/DataObjects/LambdaCalculus/LambdaExpression.cpp +++ b/src/DataObjects/LambdaCalculus/LambdaExpression.cpp @@ -3,7 +3,7 @@ #include "LambdaAbstraction.h" #include "LambdaApplication.h" -LambdaExpression::LambdaExpression(const std::string& t, const int c, std::weak_ptr p, float x, float y, float w, float h, int u) +LambdaExpression::LambdaExpression(const std::string& t, Color c, std::weak_ptr p, float x, float y, float w, float h, int u) : type(t), color(c), parent(p), x(x), y(y), w(w), h(h), uid(u) {} std::unordered_set> LambdaExpression::get_all_legal_reductions() { @@ -45,7 +45,7 @@ void LambdaExpression::set_parent(std::weak_ptr p) { mark_updated(); } -void LambdaExpression::set_color(const int c) { +void LambdaExpression::set_color(Color c) { color = c; mark_updated(); } @@ -54,7 +54,7 @@ std::string LambdaExpression::get_type() const { return type; } -int LambdaExpression::get_color() const { +Color LambdaExpression::get_color() const { return color; } diff --git a/src/DataObjects/LambdaCalculus/LambdaExpression.h b/src/DataObjects/LambdaCalculus/LambdaExpression.h index 3a2a80a4..d6117684 100644 --- a/src/DataObjects/LambdaCalculus/LambdaExpression.h +++ b/src/DataObjects/LambdaCalculus/LambdaExpression.h @@ -10,7 +10,7 @@ class LambdaExpression : public DataObject, public std::enable_shared_from_this { protected: const std::string type; - int color; + Color color; std::weak_ptr parent; float x; float y; @@ -18,7 +18,7 @@ class LambdaExpression : public DataObject, public std::enable_shared_from_this< float h; int uid; public: - LambdaExpression(const std::string& t, const int c, std::weak_ptr p = std::shared_ptr(), float x = 0, float y = 0, float w = 0, float h = 0, int u = 0); + LambdaExpression(const std::string& t, Color c, std::weak_ptr p = std::shared_ptr(), float x = 0, float y = 0, float w = 0, float h = 0, int u = 0); virtual std::shared_ptr clone() const = 0; virtual std::unordered_set free_variables() const = 0; @@ -35,9 +35,9 @@ class LambdaExpression : public DataObject, public std::enable_shared_from_this< virtual float get_width_recursive() const = 0; virtual float get_height_recursive() const = 0; virtual bool is_reducible() const = 0; - virtual void set_color_recursive(const int c) = 0; + virtual void set_color_recursive(Color c) = 0; virtual void flush_uid_recursive() = 0; - virtual void tint_recursive(const int c) = 0; + virtual void tint_recursive(Color c) = 0; virtual void interpolate_recursive(std::shared_ptr l2, const float weight) = 0; virtual void check_children_parents() const = 0; std::unordered_set> get_all_legal_reductions(); @@ -45,9 +45,9 @@ class LambdaExpression : public DataObject, public std::enable_shared_from_this< int count_reductions(); char get_fresh() const; void set_parent(std::weak_ptr p); - void set_color(const int c); + void set_color(Color c); std::string get_type() const; - int get_color() const; + Color get_color() const; std::shared_ptr get_parent() const; int get_type_depth(const std::string& s) const; diff --git a/src/DataObjects/LambdaCalculus/LambdaUtils.cpp b/src/DataObjects/LambdaCalculus/LambdaUtils.cpp index a63295ab..098db6e3 100644 --- a/src/DataObjects/LambdaCalculus/LambdaUtils.cpp +++ b/src/DataObjects/LambdaCalculus/LambdaUtils.cpp @@ -18,7 +18,7 @@ using namespace std; -shared_ptr apply(const shared_ptr f, const shared_ptr s, const int c, weak_ptr p, float x, float y, float w, float h, int u){ +shared_ptr apply(const shared_ptr f, const shared_ptr s, Color c, weak_ptr p, float x, float y, float w, float h, int u){ shared_ptr nf = f->clone(); shared_ptr ns = s->clone(); shared_ptr ret = make_shared(nf, ns, c, p, x, y, w, h, u); @@ -27,7 +27,7 @@ shared_ptr apply(const shared_ptr f, c return ret; } -shared_ptr abstract(const char v, const shared_ptr b, const int c, weak_ptr p, float x, float y, float w, float h, int u){ +shared_ptr abstract(const char v, const shared_ptr b, Color c, weak_ptr p, float x, float y, float w, float h, int u){ shared_ptr nb = b->clone(); shared_ptr ret = make_shared(v, nb, c, p, x, y, w, h, u); nb->set_parent(ret); @@ -104,7 +104,7 @@ Pixels LambdaExpression::draw_lambda_diagram(float scale = 1) { Iterator it(shared_from_this()); while (it.has_next()) { shared_ptr current = it.next(); - int color = current->get_color(); + Color color = current->get_color(); if((i==0)==(geta(color) == 255)) continue; if (current->get_type() == "Variable" && step == 0) { pix.fill_rect((current->x+2) * scale, (current->y+2) * scale, scale, current->h * scale, color); diff --git a/src/DataObjects/LambdaCalculus/LambdaUtils.h b/src/DataObjects/LambdaCalculus/LambdaUtils.h index fa1604ec..d6adc18f 100644 --- a/src/DataObjects/LambdaCalculus/LambdaUtils.h +++ b/src/DataObjects/LambdaCalculus/LambdaUtils.h @@ -17,8 +17,8 @@ using std::weak_ptr; using std::string; using std::pair; -shared_ptr apply(const shared_ptr f, const shared_ptr s, const int c, weak_ptr p = shared_ptr(), float x = 0, float y = 0, float w = 0, float h = 0, int u = 0); -shared_ptr abstract(const char v, const shared_ptr b, const int c, weak_ptr p = shared_ptr(), float x = 0, float y = 0, float w = 0, float h = 0, int u = 0); +shared_ptr apply(const shared_ptr f, const shared_ptr s, Color c, weak_ptr p = shared_ptr(), float x = 0, float y = 0, float w = 0, float h = 0, int u = 0); +shared_ptr abstract(const char v, const shared_ptr b, Color c, weak_ptr p = shared_ptr(), float x = 0, float y = 0, float w = 0, float h = 0, int u = 0); shared_ptr get_interpolated_half(shared_ptr l1, shared_ptr l2, const float weight); pair, shared_ptr> get_interpolated(shared_ptr l1, shared_ptr l2, const float weight); diff --git a/src/DataObjects/LambdaCalculus/LambdaVariable.cpp b/src/DataObjects/LambdaCalculus/LambdaVariable.cpp index 58315246..3e1bfc03 100644 --- a/src/DataObjects/LambdaCalculus/LambdaVariable.cpp +++ b/src/DataObjects/LambdaCalculus/LambdaVariable.cpp @@ -1,7 +1,7 @@ #include "LambdaVariable.h" #include -LambdaVariable::LambdaVariable(const char vn, const int c, std::weak_ptr p, float x, float y, float w, float h, int u) : LambdaExpression("Variable", c, p, x, y, w, h, u), varname(vn) { +LambdaVariable::LambdaVariable(const char vn, Color c, std::weak_ptr p, float x, float y, float w, float h, int u) : LambdaExpression("Variable", c, p, x, y, w, h, u), varname(vn) { if(!std::isalpha(static_cast(vn))){ throw std::runtime_error("Lambda variable was not a letter!"); } @@ -37,7 +37,7 @@ void LambdaVariable::interpolate_recursive(std::shared_ptr p = std::shared_ptr(), float x = 0, float y = 0, float w = 0, float h = 0, int u = 0); + LambdaVariable(const char vn, Color c, std::weak_ptr p = std::shared_ptr(), float x = 0, float y = 0, float w = 0, float h = 0, int u = 0); std::unordered_set all_referenced_variables() const override; std::unordered_set free_variables() const override; std::shared_ptr clone() const override; @@ -22,9 +22,9 @@ class LambdaVariable : public LambdaExpression { float get_width_recursive() const; float get_height_recursive() const; void interpolate_recursive(std::shared_ptr l2, const float weight); - void tint_recursive(const int c); + void tint_recursive(Color c); void flush_uid_recursive(); - void set_color_recursive(const int c); + void set_color_recursive(Color c); int parenthetical_depth() const override; int num_variable_instantiations() const override; std::string get_string() const override; diff --git a/src/Host_Device_Shared/Color.h b/src/Host_Device_Shared/Color.h new file mode 100644 index 00000000..24db059e --- /dev/null +++ b/src/Host_Device_Shared/Color.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +typedef uint32_t Color; + +#if defined(__CUDACC__) || defined(__HIPCC__) +namespace Cuda { +typedef uint32_t Color; +} +#endif diff --git a/src/Host_Device_Shared/ThreeDimensionStructs.h b/src/Host_Device_Shared/ThreeDimensionStructs.h index b7032724..8147d491 100644 --- a/src/Host_Device_Shared/ThreeDimensionStructs.h +++ b/src/Host_Device_Shared/ThreeDimensionStructs.h @@ -1,3 +1,4 @@ +#include "Color.h" #include "vec.h" #include "shared_precompiler_directives.h" @@ -5,19 +6,19 @@ SHARED_FILE_PREFIX struct Point { vec3 center; - int color; + Color color; float opacity; float size; - Point(const vec3& pos, int clr, float op = 1, float sz = 1) + Point(const vec3& pos, Color clr, float op = 1, float sz = 1) : center(pos), color(clr), opacity(op), size(sz) { } }; struct Line { - int color; + Color color; float opacity; vec3 start; vec3 end; - Line(const vec3& s, const vec3& e, int clr, float op = 1) + Line(const vec3& s, const vec3& e, Color clr, float op = 1) : color(clr), opacity(op), start(s), end(e) { } }; diff --git a/src/IO/VideoWriter.h b/src/IO/VideoWriter.h index b3babe83..3ad6b1ea 100644 --- a/src/IO/VideoWriter.h +++ b/src/IO/VideoWriter.h @@ -15,7 +15,7 @@ extern "C" extern "C" void alpha_overlay_cuda(unsigned int* src_host, int width, int height, - unsigned int bg_color); + Color bg_color); class VideoWriter { private: diff --git a/src/IO/Writer.cpp b/src/IO/Writer.cpp index 4e7b0f54..85eba750 100644 --- a/src/IO/Writer.cpp +++ b/src/IO/Writer.cpp @@ -11,7 +11,7 @@ using namespace std; -Writer::Writer(int video_width_pixels, int video_height_pixels, int video_framerate_fps, int audio_samplerate_hz, uint32_t video_background_color) : +Writer::Writer(int video_width_pixels, int video_height_pixels, int video_framerate_fps, int audio_samplerate_hz, Color video_background_color) : video_width_pixels(video_width_pixels), video_height_pixels(video_height_pixels), video_framerate_fps(video_framerate_fps), @@ -44,11 +44,11 @@ int Writer::get_video_width_pixels() const { return video_width_pixels; } int Writer::get_video_height_pixels() const { return video_height_pixels; } int Writer::get_video_framerate_fps() const { return video_framerate_fps; } int Writer::get_audio_samplerate_hz() const { return audio_samplerate_hz; } -uint32_t Writer::get_video_background_color() const { return video_background_color; } +Color Writer::get_video_background_color() const { return video_background_color; } static std::unique_ptr writer; -void init_writer(int video_width_pixels, int video_height_pixels, int video_framerate_fps, int audio_samplerate_hz, uint32_t video_background_color) { +void init_writer(int video_width_pixels, int video_height_pixels, int video_framerate_fps, int audio_samplerate_hz, Color video_background_color) { cout << "Initializing writer... " << flush; if (writer) throw std::runtime_error("Writer already initialized"); @@ -75,7 +75,7 @@ int get_video_framerate_fps() { int get_video_height_pixels() { return get_writer().get_video_height_pixels(); } -uint32_t get_video_background_color() { +Color get_video_background_color() { return get_writer().get_video_background_color(); } int get_samples_per_frame() { diff --git a/src/IO/Writer.h b/src/IO/Writer.h index 99047228..96f47aed 100644 --- a/src/IO/Writer.h +++ b/src/IO/Writer.h @@ -3,6 +3,7 @@ #include #include +#include "../Host_Device_Shared/Color.h" #include "AudioWriter.h" #include "VideoWriter.h" #include "SubtitleWriter.h" @@ -16,23 +17,23 @@ class Writer { SubtitleWriter* subtitle = nullptr; ShtookaWriter* shtooka = nullptr; - Writer(int video_width_pixels, int video_height_pixels, int video_framerate_fps, int audio_samplerate_hz, uint32_t video_background_color); + Writer(int video_width_pixels, int video_height_pixels, int video_framerate_fps, int audio_samplerate_hz, Color video_background_color); ~Writer(); int get_video_width_pixels() const; int get_video_height_pixels() const; int get_video_framerate_fps() const; int get_audio_samplerate_hz() const; - uint32_t get_video_background_color() const; + Color get_video_background_color() const; private: const int video_width_pixels; const int video_height_pixels; const int video_framerate_fps; const int audio_samplerate_hz; - const uint32_t video_background_color = 0x00000000; + const Color video_background_color = 0x00000000; }; -void init_writer(int video_width_pixels, int video_height_pixels, int video_framerate_fps, int audio_samplerate_hz, uint32_t video_background_color); +void init_writer(int video_width_pixels, int video_height_pixels, int video_framerate_fps, int audio_samplerate_hz, Color video_background_color); Writer& get_writer(); int get_video_width_pixels(); @@ -40,5 +41,5 @@ int get_video_height_pixels(); float get_video_aspect_ratio(); int get_video_framerate_fps(); int get_audio_samplerate_hz(); -uint32_t get_video_background_color(); +Color get_video_background_color(); int get_samples_per_frame(); diff --git a/src/Scenes/Common/CoordinateScene.cpp b/src/Scenes/Common/CoordinateScene.cpp index f6aa0548..fb081465 100644 --- a/src/Scenes/Common/CoordinateScene.cpp +++ b/src/Scenes/Common/CoordinateScene.cpp @@ -93,13 +93,13 @@ vec2 CoordinateScene::pixel_to_point(const vec2& pix) { } // This is not used here, but it is used in some classes which inherit from CoordinateScene -void CoordinateScene::draw_trail(const list>& trail, const float trail_opacity) { +void CoordinateScene::draw_trail(const list>& trail, const float trail_opacity) { if(trail.size() == 0) return; if(trail_opacity < 0.01) return; float line_width = get_geom_mean_size()/500.; vec2 last_pixel{0,0}; int i = 0; - for(const pair& p : trail) { + for(const pair& p : trail) { if(i != 0) { const vec2 next_pixel(point_to_pixel(p.first)); pix.bresenham(last_pixel.x, last_pixel.y, next_pixel.x, next_pixel.y, p.second, trail_opacity, line_width); @@ -109,7 +109,7 @@ void CoordinateScene::draw_trail(const list>& trail, const float } } -void CoordinateScene::draw_point(const vec2 point, int point_color, float point_opacity) { +void CoordinateScene::draw_point(const vec2 point, Color point_color, float point_opacity) { const vec2 pixel = point_to_pixel(point); pix.fill_circle(pixel.x, pixel.y, get_geom_mean_size()/100., point_color, point_opacity); } @@ -127,9 +127,9 @@ void CoordinateScene::draw_construction() { double gm = get_geom_mean_size(); double line_thickness = gm/200.; - int point_color = 0xffffffff; - int line_color = 0xff6666ff; - int text_color = 0xffffffff; + Color point_color = 0xffffffff; + Color line_color = 0xff6666ff; + Color text_color = 0xffffffff; float microblock_fraction = 0.5; if(state.contains("microblock_fraction_passthrough")) microblock_fraction = state["microblock_fraction_passthrough"]; diff --git a/src/Scenes/Common/CoordinateScene.h b/src/Scenes/Common/CoordinateScene.h index ebe8b020..6b84280b 100644 --- a/src/Scenes/Common/CoordinateScene.h +++ b/src/Scenes/Common/CoordinateScene.h @@ -23,9 +23,9 @@ class CoordinateScene : public Scene { vec2 pixel_to_point(const vec2& pix); // This is not used here, but it is used in some classes which inherit from CoordinateScene - void draw_trail(const std::list>& trail, const float trail_opacity); + void draw_trail(const std::list>& trail, const float trail_opacity); - void draw_point(const vec2 point, int point_color, float point_opacity); + void draw_point(const vec2 point, Color point_color, float point_opacity); void draw() override; diff --git a/src/Scenes/Common/CoordinateSceneWithTrail.h b/src/Scenes/Common/CoordinateSceneWithTrail.h index f7ba06f0..2a60813f 100644 --- a/src/Scenes/Common/CoordinateSceneWithTrail.h +++ b/src/Scenes/Common/CoordinateSceneWithTrail.h @@ -6,8 +6,8 @@ class CoordinateSceneWithTrail : public CoordinateScene { public: - int trail_color = OPAQUE_WHITE; - list> trail; + Color trail_color = OPAQUE_WHITE; + list> trail; CoordinateSceneWithTrail(const vec2& dimensions = vec2(1, 1)); void draw() override; diff --git a/src/Scenes/Common/PauseScene.cpp b/src/Scenes/Common/PauseScene.cpp index f440ee03..5396d4ab 100644 --- a/src/Scenes/Common/PauseScene.cpp +++ b/src/Scenes/Common/PauseScene.cpp @@ -20,7 +20,7 @@ void PauseScene::draw() { double center_x = w / 2.0; double center_y = h / 2.0; - int color = OPAQUE_WHITE; + Color color = OPAQUE_WHITE; // Draw expanding borders from center of each side outward towards corners // At 0 timer_value nothing drawn, at 1 timer_value the fill_rect reaches the corners diff --git a/src/Scenes/Common/ThreeDimensionScene.cpp b/src/Scenes/Common/ThreeDimensionScene.cpp index d3d542b0..ba38b1c8 100644 --- a/src/Scenes/Common/ThreeDimensionScene.cpp +++ b/src/Scenes/Common/ThreeDimensionScene.cpp @@ -4,25 +4,25 @@ extern "C" { void render_points_on_gpu( - unsigned int* h_pixels, int width, int height, + Color* h_pixels, int width, int height, float geom_mean_size, float points_opacity, float points_radius_multiplier, Point* h_points, int num_points, quat camera_direction, vec3 camera_pos, float fov); void render_lines_on_gpu( - unsigned int* h_pixels, int width, int height, + Color* h_pixels, int width, int height, float geom_mean_size, int thickness, float lines_opacity, Line* h_lines, int num_lines, quat camera_direction, vec3 camera_pos, float fov); void cuda_render_surface( - vector& pix, + vector& pix, int x1, int y1, int plot_w, int plot_h, int pixels_w, - unsigned int* d_surface, + Color* d_surface, int surface_w, int surface_h, float opacity, @@ -52,7 +52,7 @@ Surface::Surface(const vec3& c, const vec3& l, const vec3& u, const string& n) // constructor to make the surface fill the screen. Surface::Surface(const string& n) : Surface(vec3(0, 0, 0), vec3(.5, 0, 0), vec3(0, .5, 0), n) {} -Path::Path(const string& n, int clr, float op) +Path::Path(const string& n, Color clr, float op) : name(n), color(clr), opacity(op) { } ThreeDimensionScene::ThreeDimensionScene(const vec2& dimensions) diff --git a/src/Scenes/Common/ThreeDimensionScene.h b/src/Scenes/Common/ThreeDimensionScene.h index df5aafd9..4acdf640 100644 --- a/src/Scenes/Common/ThreeDimensionScene.h +++ b/src/Scenes/Common/ThreeDimensionScene.h @@ -29,9 +29,9 @@ struct Surface { struct Path { string name; vector points; - int color; + Color color; float opacity; - Path(const string& n, int clr, float op = 1); + Path(const string& n, Color clr, float op = 1); }; class ThreeDimensionScene : public SuperScene { diff --git a/src/Scenes/Connect4/C4GraphScene.cpp b/src/Scenes/Connect4/C4GraphScene.cpp index c528f1e1..5e69ca7e 100644 --- a/src/Scenes/Connect4/C4GraphScene.cpp +++ b/src/Scenes/Connect4/C4GraphScene.cpp @@ -25,6 +25,6 @@ C4GraphScene::C4GraphScene(shared_ptr g, bool surfaces_on, const string& graph->add_to_stack(board); } -int C4GraphScene::get_edge_color(const Node& node, const Node& neighbor){ +Color C4GraphScene::get_edge_color(const Node& node, const Node& neighbor){ return min(node.data->representation.size(), neighbor.data->representation.size())%2==0 ? C4_RED : C4_YELLOW; } diff --git a/src/Scenes/Connect4/C4GraphScene.h b/src/Scenes/Connect4/C4GraphScene.h index 957f0805..4e4fdc38 100644 --- a/src/Scenes/Connect4/C4GraphScene.h +++ b/src/Scenes/Connect4/C4GraphScene.h @@ -13,7 +13,7 @@ class C4GraphScene : public GraphScene { public: C4GraphScene(shared_ptr g, bool surfaces_on, const string& rep, const C4BranchMode mode, const vec2& dimensions = vec2(1, 1)); - int get_edge_color(const Node& node, const Node& neighbor); + Color get_edge_color(const Node& node, const Node& neighbor); private: string root_node_representation; diff --git a/src/Scenes/Connect4/C4Scene.cpp b/src/Scenes/Connect4/C4Scene.cpp index b933525e..0bd0264b 100644 --- a/src/Scenes/Connect4/C4Scene.cpp +++ b/src/Scenes/Connect4/C4Scene.cpp @@ -85,7 +85,7 @@ void C4Scene::highlight_winning_discs(){ double px, py; get_disc_screen_coordinates(x, C4_HEIGHT - 1 - y, px, py); bool is_red = bitboard_at(b.red_bitboard, x, y); - int color = is_red ? C4_RED : C4_YELLOW; + Color color = is_red ? C4_RED : C4_YELLOW; pix.fill_ellipse(px, py, ellipse_width, ellipse_width, color); } } diff --git a/src/Scenes/Math/AngularFractalScene.cpp b/src/Scenes/Math/AngularFractalScene.cpp index 8fe4601e..3c69d1a1 100644 --- a/src/Scenes/Math/AngularFractalScene.cpp +++ b/src/Scenes/Math/AngularFractalScene.cpp @@ -20,7 +20,7 @@ void AngularFractalScene::draw() { } void AngularFractalScene::draw_angular_fractal() { - list> trail; + list> trail; vec2 current_point = vec2(0,0); double current_angle = 0; trail.push_back({current_point, OPAQUE_WHITE}); diff --git a/src/Scenes/Math/BarChartScene.cpp b/src/Scenes/Math/BarChartScene.cpp index c39c3a1c..15768415 100644 --- a/src/Scenes/Math/BarChartScene.cpp +++ b/src/Scenes/Math/BarChartScene.cpp @@ -60,7 +60,7 @@ void BarChartScene::draw() { double bar_x = state["bar" + to_string(i) + ".x"] * pix.w - bar_width / 2; double bar_y = pix.h * .8 - bar_height; int alpha = state["bar" + to_string(i) + ".opacity"] * 255; - int color = alpha << 24 | 0xffffff; + Color color = (static_cast(alpha) << 24) | 0xffffff; pix.fill_rect(bar_x, bar_y, bar_width, bar_height, color); } } diff --git a/src/Scenes/Math/Beavers/BeaverGridScene.cpp b/src/Scenes/Math/Beavers/BeaverGridScene.cpp index 0e4c05ed..48f694cc 100644 --- a/src/Scenes/Math/Beavers/BeaverGridScene.cpp +++ b/src/Scenes/Math/Beavers/BeaverGridScene.cpp @@ -1,6 +1,6 @@ #include "BeaverGridScene.h" -extern "C" void beaver_grid_cuda(int num_states, int num_symbols, unsigned int* pixels, int w, int h, vec2 lx_ty, vec2 rx_by, int max_steps); +extern "C" void beaver_grid_cuda(int num_states, int num_symbols, Color* pixels, int w, int h, vec2 lx_ty, vec2 rx_by, int max_steps); BeaverGridScene::BeaverGridScene(const int num_states, const int num_symbols, const vec2& dimension) : CoordinateScene(dimension) { diff --git a/src/Scenes/Math/Beavers/BeaverGridTNF3DScene.cpp b/src/Scenes/Math/Beavers/BeaverGridTNF3DScene.cpp index 082e6937..52b58c0f 100644 --- a/src/Scenes/Math/Beavers/BeaverGridTNF3DScene.cpp +++ b/src/Scenes/Math/Beavers/BeaverGridTNF3DScene.cpp @@ -1,6 +1,6 @@ #include "BeaverGridTNF3DScene.h" -extern "C" void beaver_grid_TNF_3D_cuda(unsigned int* pixels, int w, int h, vec3 pos, quat camera, float fov, vec3 target, vec3 up, float use_quat_camera, float shell_border, float core_border, vec3 scale, int max_steps); +extern "C" void beaver_grid_TNF_3D_cuda(Color* pixels, int w, int h, vec3 pos, quat camera, float fov, vec3 target, vec3 up, float use_quat_camera, float shell_border, float core_border, vec3 scale, int max_steps); BeaverGridTNF3DScene::BeaverGridTNF3DScene(const vec2& dimension) { manager.set({ diff --git a/src/Scenes/Math/Beavers/BeaverGridTNFScene.cpp b/src/Scenes/Math/Beavers/BeaverGridTNFScene.cpp index e69a766d..4d7bd591 100644 --- a/src/Scenes/Math/Beavers/BeaverGridTNFScene.cpp +++ b/src/Scenes/Math/Beavers/BeaverGridTNFScene.cpp @@ -1,6 +1,6 @@ #include "BeaverGridTNFScene.h" -extern "C" void beaver_grid_TNF_cuda(unsigned int* pixels, int w, int h, vec2 lx_ty, vec2 rx_by, int max_steps); +extern "C" void beaver_grid_TNF_cuda(Color* pixels, int w, int h, vec2 lx_ty, vec2 rx_by, int max_steps); BeaverGridTNFScene::BeaverGridTNFScene(const vec2& dimension) : CoordinateScene(dimension) { diff --git a/src/Scenes/Math/ComplexPlotScene.cpp b/src/Scenes/Math/ComplexPlotScene.cpp index f9774ee2..52aef00f 100644 --- a/src/Scenes/Math/ComplexPlotScene.cpp +++ b/src/Scenes/Math/ComplexPlotScene.cpp @@ -5,7 +5,7 @@ #include extern "C" void color_complex_polynomial( - unsigned int* h_pixels, // to be overwritten with the result + Color* h_pixels, // to be overwritten with the result int w, int h, const float* h_coefficients_real, @@ -348,7 +348,7 @@ void ComplexPlotScene::draw() { const complex sqrt_disc = std::sqrt(discriminant); const complex root = (-b + sqrt_disc * sign_c) / (2.0f*a); const vec2 pixel(point_to_pixel(vec2(root.real(), root.imag()))); - const int color = (sign == 1) ? 0xffff0000 : 0xff00ff00; + const Color color = (sign == 1) ? 0xffff0000 : 0xff00ff00; pix.fill_ring(pixel.x, pixel.y, gm*6, gm*5, color, opa); } } diff --git a/src/Scenes/Math/ConwayScene.cpp b/src/Scenes/Math/ConwayScene.cpp index 079be076..eac4b02c 100644 --- a/src/Scenes/Math/ConwayScene.cpp +++ b/src/Scenes/Math/ConwayScene.cpp @@ -4,7 +4,7 @@ extern "C" void draw_conway( Bitboard* h_board, Bitboard* h_board_2, int w_bitboards, int h_bitboards, - unsigned int* h_pixels, int pixels_w, int pixels_h, + Color* h_pixels, int pixels_w, int pixels_h, vec2 lx_ty, vec2 rx_by, float transition ); diff --git a/src/Scenes/Math/GeodesicScene.cpp b/src/Scenes/Math/GeodesicScene.cpp index 1944b0b9..9f7ae7ed 100644 --- a/src/Scenes/Math/GeodesicScene.cpp +++ b/src/Scenes/Math/GeodesicScene.cpp @@ -10,7 +10,7 @@ ResolvedStateEquation i_eq = { {RESOLVED_CONSTANT, .content = {.constant = 0.0}}, }; extern "C" void launch_cuda_surface_raymarch( - uint32_t* h_pixels, int w, int h, + Color* h_pixels, int w, int h, int x_size, ResolvedStateEquationComponent* x_eq, int y_size, ResolvedStateEquationComponent* y_eq, int z_size, ResolvedStateEquationComponent* z_eq, @@ -21,16 +21,16 @@ extern "C" void launch_cuda_surface_raymarch( ); extern "C" void cuda_render_manifold( - uint32_t* pixels, const int w, const int h, + Color* pixels, const int w, const int h, const ManifoldData* manifolds, const int num_manifolds, const vec3 camera_pos, const quat camera_direction, const float geom_mean_size, const float fov, const float ab_dilation, const float dot_radius, - uint32_t* tex_pixels, const int tex_w, const int tex_h + Color* tex_pixels, const int tex_w, const int tex_h ); extern "C" void cuda_render_geodesics_2d( - uint32_t* pixels, const int w, const int h, + Color* pixels, const int w, const int h, const ManifoldData& manifold, const vec2 start_position, const vec2 start_velocity, const int num_geodesics, const int num_steps, const float spread_angle, diff --git a/src/Scenes/Math/GraphScene.cpp b/src/Scenes/Math/GraphScene.cpp index 73cfe89f..8b0d20fc 100644 --- a/src/Scenes/Math/GraphScene.cpp +++ b/src/Scenes/Math/GraphScene.cpp @@ -58,7 +58,7 @@ void GraphScene::graph_to_3d(){ if(p.first == next_hash) { next_pos = node_pos; next_found = true; } if(node.draw_point) add_point(Point(node_pos, node.color, 1, node.radius())); double so = node.splash_opacity(); - int color = color_scheme[static_cast(abs(p.first)*4)%4]; + Color color = color_scheme[static_cast(abs(p.first)*4)%4]; if(so>0) add_point(Point(node_pos, color, so, node.splash_radius())); for(const Edge& neighbor_edge : node.neighbors){ @@ -89,7 +89,7 @@ void GraphScene::graph_to_3d(){ cout << ">"; } -int GraphScene::get_edge_color(const Node& node, const Node& neighbor){ +Color GraphScene::get_edge_color(const Node& node, const Node& neighbor){ return OPAQUE_WHITE; } diff --git a/src/Scenes/Math/GraphScene.h b/src/Scenes/Math/GraphScene.h index a514adc7..b4efc247 100644 --- a/src/Scenes/Math/GraphScene.h +++ b/src/Scenes/Math/GraphScene.h @@ -13,12 +13,12 @@ class GraphScene : public ThreeDimensionScene { public: double curr_hash; double next_hash; - std::vector color_scheme; + std::vector color_scheme; GraphScene(std::shared_ptr g, bool surfaces_on, const vec2& dimensions = vec2(1, 1)); void graph_to_3d(); - virtual int get_edge_color(const Node& node, const Node& neighbor); + virtual Color get_edge_color(const Node& node, const Node& neighbor); const StateQuery populate_state_query() const override; diff --git a/src/Scenes/Math/KlotskiScene.cpp b/src/Scenes/Math/KlotskiScene.cpp index 98098394..83967698 100644 --- a/src/Scenes/Math/KlotskiScene.cpp +++ b/src/Scenes/Math/KlotskiScene.cpp @@ -1,7 +1,7 @@ #include "KlotskiScene.h" #include "../../Core/Color.h" -int piece_color(int cell){ +Color piece_color(int cell){ return rainbow(cell*.618034); } @@ -124,7 +124,7 @@ void KlotskiScene::draw() { double rect_height = square_size - margin; // Simple pseudo-random color based on the character value. - uint32_t color = piece_color(cell); + Color color = piece_color(cell); if(rainbow_pct<0.999) color = colorlerp(OPAQUE_WHITE, color, rainbow_pct); double triple_micro = microblock_fraction*3; diff --git a/src/Scenes/Math/KlotskiScene.h b/src/Scenes/Math/KlotskiScene.h index e1dc4dc8..7bb04b22 100644 --- a/src/Scenes/Math/KlotskiScene.h +++ b/src/Scenes/Math/KlotskiScene.h @@ -5,7 +5,7 @@ #include #include -int piece_color(int cell); +Color piece_color(int cell); class KlotskiScene : public Scene { private: diff --git a/src/Scenes/Math/MandelbrotScene.cpp b/src/Scenes/Math/MandelbrotScene.cpp index 7893331a..8450796e 100644 --- a/src/Scenes/Math/MandelbrotScene.cpp +++ b/src/Scenes/Math/MandelbrotScene.cpp @@ -13,8 +13,8 @@ extern "C" void mandelbrot_render( int max_iterations, float gradation, float phase_shift, - unsigned int internal_color, - unsigned int* depths + Color internal_color, + Color* depths ); MandelbrotScene::MandelbrotScene(const vec2& dimensions) : CoordinateScene(dimensions) { @@ -67,8 +67,8 @@ void MandelbrotScene::draw() { ); if(state["point_path_length"] > 0) { // TODO convert to use CoordinateSceneWithTrail - int startcol = 0xffff0000; - int pathcol = 0xff880000; + Color startcol = 0xffff0000; + Color pathcol = 0xff880000; complex z(state["point_path_start_r"], state["point_path_start_i"]); vec2 start = point_to_pixel(vec2(state["point_path_start_r"], state["point_path_start_i"])); float r = get_width()/300.; diff --git a/src/Scenes/Math/MandelbulbScene.cpp b/src/Scenes/Math/MandelbulbScene.cpp index 13868753..6dd32f3b 100644 --- a/src/Scenes/Math/MandelbulbScene.cpp +++ b/src/Scenes/Math/MandelbulbScene.cpp @@ -5,7 +5,7 @@ extern "C" void render_raymarch( const vec3& pos, const quat& camera, float fov, const vec3& lightPos, const int max_raymarch_iterations, const int max_mandelbulb_iterations, - unsigned int* colors + Color* colors ); MandelbulbScene::MandelbulbScene(const vec2& dimensions) : Scene(dimensions){ diff --git a/src/Scenes/Math/ManifoldScene.cpp b/src/Scenes/Math/ManifoldScene.cpp index 3bf1226c..293c7efd 100644 --- a/src/Scenes/Math/ManifoldScene.cpp +++ b/src/Scenes/Math/ManifoldScene.cpp @@ -3,15 +3,15 @@ #include "ManifoldScene.h" extern "C" void cuda_render_manifold( - uint32_t* pixels, const int w, const int h, + Color* pixels, const int w, const int h, const ManifoldData* manifolds, const int num_manifolds, const vec3 camera_pos, const quat camera_direction, const float geom_mean_size, const float fov, const float ab_dilation, const float dot_radius, - const uint32_t* tex_pixels, const int tex_w, const int tex_h + const Color* tex_pixels, const int tex_w, const int tex_h ); -extern "C" void cuda_free_texture(uint32_t* d_tex_pixels); -extern "C" uint32_t* cuda_copy_texture_to_device(const uint32_t* h_tex_pixels, const int tex_w, const int tex_h); +extern "C" void cuda_free_texture(Color* d_tex_pixels); +extern "C" Color* cuda_copy_texture_to_device(const Color* h_tex_pixels, const int tex_w, const int tex_h); ManifoldScene::ManifoldScene(const vec2& dimensions) : ThreeDimensionScene(dimensions), d_texture_data(nullptr), texture_w(0), texture_h(0) { manager.set({ diff --git a/src/Scenes/Math/ManifoldScene.h b/src/Scenes/Math/ManifoldScene.h index 239619a0..0102e4b1 100644 --- a/src/Scenes/Math/ManifoldScene.h +++ b/src/Scenes/Math/ManifoldScene.h @@ -9,7 +9,7 @@ class ManifoldScene : public ThreeDimensionScene { private: std::unordered_set manifold_names; - uint32_t* d_texture_data; + Color* d_texture_data; int texture_w; int texture_h; diff --git a/src/Scenes/Math/RealFunctionScene.cpp b/src/Scenes/Math/RealFunctionScene.cpp index 7c78d2f7..6f83099c 100644 --- a/src/Scenes/Math/RealFunctionScene.cpp +++ b/src/Scenes/Math/RealFunctionScene.cpp @@ -56,7 +56,7 @@ void RealFunctionScene::render_functions() { const ResolvedStateEquation& re = resolved_equations[func_idx]; vec2 last_pixel = {-1, -1}; bool first_point = true; - int color = function_colors[func_idx]; + Color color = function_colors[func_idx]; for (float x = left_bound_this; x <= right_bound_this; x += dx) { float val = call_the_function(x, re); vec2 pixel = point_to_pixel({x, val}); diff --git a/src/Scenes/Math/RealFunctionScene.h b/src/Scenes/Math/RealFunctionScene.h index 4f4f924a..970aebda 100644 --- a/src/Scenes/Math/RealFunctionScene.h +++ b/src/Scenes/Math/RealFunctionScene.h @@ -19,5 +19,5 @@ class RealFunctionScene : public CoordinateScene { const StateQuery populate_state_query() const override; private: - std::vector function_colors = {0xFF0088FF, 0xFFFF0088}; + std::vector function_colors = {0xFF0088FF, 0xFFFF0088}; }; diff --git a/src/Scenes/Math/RootFractalScene.cpp b/src/Scenes/Math/RootFractalScene.cpp index d7bd877a..fe0f0777 100644 --- a/src/Scenes/Math/RootFractalScene.cpp +++ b/src/Scenes/Math/RootFractalScene.cpp @@ -1,7 +1,7 @@ #include "RootFractalScene.h" #include -extern "C" void draw_root_fractal(unsigned int* pixels, int w, int h, complex c1, complex c2, float terms, float lx, float ty, float rx, float by, float radius, float opacity, float brightness); +extern "C" void draw_root_fractal(Color* pixels, int w, int h, complex c1, complex c2, float terms, float lx, float ty, float rx, float by, float radius, float opacity, float brightness); RootFractalScene::RootFractalScene(const vec2& dimensions) : CoordinateScene(dimensions) { manager.set({ diff --git a/src/Scenes/Media/AlphaFilterScene.cpp b/src/Scenes/Media/AlphaFilterScene.cpp index 30192589..bbcda99d 100644 --- a/src/Scenes/Media/AlphaFilterScene.cpp +++ b/src/Scenes/Media/AlphaFilterScene.cpp @@ -6,14 +6,14 @@ AlphaFilterScene::AlphaFilterScene( std::shared_ptr sc, - const unsigned int preserve_col, + Color preserve_col, const bool inv, const vec2& dimensions) : SuperScene(dimensions), preserve_col(preserve_col), inversed(inv) { add_subscene_check_dupe("main", sc); } -int coldist(unsigned int col1, unsigned int col2) { +int coldist(Color col1, Color col2) { int a1 = (col1 >> 24) & 0xFF; int r1 = (col1 >> 16) & 0xFF; int g1 = (col1 >> 8) & 0xFF; @@ -38,7 +38,7 @@ void AlphaFilterScene::draw() { for(int x = 0; x < pix.w; x++) { for(int y = 0; y < pix.h; y++) { - unsigned int col = subscene_pix->get_pixel_carelessly(x, y); + Color col = subscene_pix->get_pixel_carelessly(x, y); int dist = coldist(col, preserve_col); if ((dist < 256) ^ inversed) pix.set_pixel_carelessly(x, y, col); } diff --git a/src/Scenes/Media/AlphaFilterScene.h b/src/Scenes/Media/AlphaFilterScene.h index 9bd5968a..622f8eb9 100644 --- a/src/Scenes/Media/AlphaFilterScene.h +++ b/src/Scenes/Media/AlphaFilterScene.h @@ -7,7 +7,7 @@ class AlphaFilterScene : public SuperScene { public: AlphaFilterScene( std::shared_ptr sc, - const unsigned int preserve_col, + Color preserve_col, const bool inv = false, const vec2& dimensions = vec2(1, 1) ); @@ -15,6 +15,6 @@ class AlphaFilterScene : public SuperScene { void draw() override; private: - unsigned int preserve_col; - unsigned int inversed; + Color preserve_col; + bool inversed; }; diff --git a/src/Scenes/Media/StateSliderScene.cpp b/src/Scenes/Media/StateSliderScene.cpp index 92bb7264..47f80857 100644 --- a/src/Scenes/Media/StateSliderScene.cpp +++ b/src/Scenes/Media/StateSliderScene.cpp @@ -60,9 +60,9 @@ void StateSliderScene::draw_slider() { const int w = get_width(); // vv Change away!! vv - const int outer_color = 0xff444444; // Dark gray - const int inner_color = 0xff000000; // Black - const int knob_color = 0xff444444; // Dark gray + const Color outer_color = 0xff444444; // Dark gray + const Color inner_color = 0xff000000; // Black + const Color knob_color = 0xff444444; // Dark gray const double outer_radius = h * .5; const double inner_radius = h * .45; const double knob_radius = h * .4; diff --git a/src/Scenes/Physics/MovingPendulumGridScene.cpp b/src/Scenes/Physics/MovingPendulumGridScene.cpp index 74b513f3..0e60eda0 100644 --- a/src/Scenes/Physics/MovingPendulumGridScene.cpp +++ b/src/Scenes/Physics/MovingPendulumGridScene.cpp @@ -54,7 +54,7 @@ void MovingPendulumGridScene::draw_grid() { int i = x+y*w; int color_mode0 = 0; int color_mode1 = 0; int color_mode2 = 0; int color_mode3 = 0; - int color = 0xffff0000; + Color color = 0xffff0000; double how_chaotic = max(0.,grid.diff_sums[i]/grid.samples*contrast); double use_p1 = grid.pendulum_states[i].p1 * mvg; diff --git a/src/Scenes/Physics/PendulumGridScene.cpp b/src/Scenes/Physics/PendulumGridScene.cpp index 2bc05183..4982bc93 100644 --- a/src/Scenes/Physics/PendulumGridScene.cpp +++ b/src/Scenes/Physics/PendulumGridScene.cpp @@ -80,7 +80,7 @@ void PendulumGridScene::draw_grid() { int i = arr_x+arr_y*grid.w; int color_mode0 = 0; int color_mode1 = 0; int color_mode2 = 0; int color_mode3 = 0; - int color = 0xffff0000; + Color color = 0xffff0000; double how_chaotic = max(0.,grid.diff_sums[i]/grid.samples*contrast); double use_p1 = grid.pendulum_states[i].p1 * mvg; @@ -129,7 +129,7 @@ void PendulumGridScene::draw_pendulum_trail(){ const float trail_start_y = state["trail_start_y"]; const float trail_length = state["trail_length"]; Pendulum p({trail_start_x, trail_start_y, 0, 0}); - list> trail; + list> trail; for(int i = 0; i < trail_length; i++){ p.iterate_physics(1, 0.01); trail.push_back(make_pair(vec2(p.state.theta1, p.state.theta2), 0xffff0000)); diff --git a/src/Scenes/Physics/PendulumPointsScene.cpp b/src/Scenes/Physics/PendulumPointsScene.cpp index d846a492..9a344b8d 100644 --- a/src/Scenes/Physics/PendulumPointsScene.cpp +++ b/src/Scenes/Physics/PendulumPointsScene.cpp @@ -17,7 +17,7 @@ void PendulumPointsScene::render_points() { int i = x + y * grid.w; PendulumState this_ps = grid.pendulum_states[i]; PendulumState start_ps = grid.start_states[i]; - int point_color = pendulum_color(start_ps.theta1, start_ps.theta2, start_ps.p1, start_ps.p2); + Color point_color = pendulum_color(start_ps.theta1, start_ps.theta2, start_ps.p1, start_ps.p2); vec2 curr_point = vec2(this_ps.theta1, this_ps.theta2); vec2 curr_pixel = point_to_pixel(curr_point); pix.fill_circle( diff --git a/src/Scenes/Physics/PendulumScene.cpp b/src/Scenes/Physics/PendulumScene.cpp index bda91b47..bdc6a491 100644 --- a/src/Scenes/Physics/PendulumScene.cpp +++ b/src/Scenes/Physics/PendulumScene.cpp @@ -67,14 +67,14 @@ void PendulumScene::draw() { double in_manual_mode = state["manual_mode"]; std::vector thetas = {lerp(pend.state.theta1, state["theta1_manual"], in_manual_mode), lerp(pend.state.theta2, state["theta2_manual"], in_manual_mode)}; - int color = pendulum_color(thetas[0], thetas[1], pend.state.p1, pend.state.p2); + Color color = pendulum_color(thetas[0], thetas[1], pend.state.p1, pend.state.p2); if(state["path_opacity"] > 0.01) pix.overlay(path_background, 0, 0); double pend_opa = state["pendulum_opacity"]; if(pend_opa > 0.01) { double rainbow = state["rainbow"]; - int pendulum_color = colorlerp(OPAQUE_WHITE, color, rainbow); + Color pendulum_color = colorlerp(OPAQUE_WHITE, color, rainbow); for (int i = 0; i < pendulum_count; i++) { double theta = thetas[i]; double length = h/(pendulum_count * 2 + 1.);