summaryrefslogtreecommitdiff
path: root/graphics.c
diff options
context:
space:
mode:
Diffstat (limited to 'graphics.c')
-rwxr-xr-xgraphics.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/graphics.c b/graphics.c
index 90aade1..a075268 100755
--- a/graphics.c
+++ b/graphics.c
@@ -73,7 +73,7 @@ vec4_f32 vec4_f32_lerp (vec4_f32 a, vec4_f32 b, f32 t);
typedef struct {
i64 width;
i64 height;
- i64 line_size;
+ i64 stride;
vec4_f32 *pixels;
} Pixel_Buffer;
@@ -214,11 +214,11 @@ static f64 gamma_re_(f64 x) {
}
static void put_pixel_color_(Brush brush, i64 x, i64 y) {
- brush.buffer.pixels[y * brush.buffer.line_size + x] = brush.color;
+ brush.buffer.pixels[y * brush.buffer.stride + x] = brush.color;
}
static void put_pixel_alpha_(Brush brush, i64 x, i64 y) {
- i64 n = y * brush.buffer.line_size + x;
+ i64 n = y * brush.buffer.stride + x;
vec4_f32 dst = brush.buffer.pixels[n];
f64 a = brush.color.w;
@@ -232,7 +232,7 @@ static void put_pixel_alpha_(Brush brush, i64 x, i64 y) {
}
static void put_pixel_xor_(Brush brush, i64 x, i64 y) {
- i64 n = y * brush.buffer.line_size + x;
+ i64 n = y * brush.buffer.stride + x;
vec3_f32 c = rgb_f32_from_u32(
rgb_u32_from_f32(vec3_from_vec4_f32(brush.buffer.pixels[n]))
@@ -350,10 +350,10 @@ void draw_pixels_(Brush brush, f64 x, f64 y, f64 width, f64 height, Pixel_Buffer
i64 n = 0;
for (i64 jj = src_j0; jj < src_j1; ++jj)
for (i64 ii = src_i0; ii < src_i1; ++ii) {
- brush.color.x += gamma_re_(src.pixels[jj * src.line_size + ii].x);
- brush.color.y += gamma_re_(src.pixels[jj * src.line_size + ii].y);
- brush.color.z += gamma_re_(src.pixels[jj * src.line_size + ii].z);
- brush.color.w += gamma_re_(src.pixels[jj * src.line_size + ii].w);
+ brush.color.x += gamma_re_(src.pixels[jj * src.stride + ii].x);
+ brush.color.y += gamma_re_(src.pixels[jj * src.stride + ii].y);
+ brush.color.z += gamma_re_(src.pixels[jj * src.stride + ii].z);
+ brush.color.w += gamma_re_(src.pixels[jj * src.stride + ii].w);
++n;
}
if (n == 0)
@@ -373,7 +373,7 @@ void draw_pixels_(Brush brush, f64 x, f64 y, f64 width, f64 height, Pixel_Buffer
for (i64 i = i0; i <= i1; ++i) {
i64 src_i = (i64) floor(((i - x0) * src.width) * w_inv + .5);
if (src_i < 0 || src_i >= src.width) continue;
- brush.color = src.pixels[src_j * src.line_size + src_i];
+ brush.color = src.pixels[src_j * src.stride + src_i];
put_pixel_(brush, i, j);
}
}
@@ -890,8 +890,8 @@ static Brush brush_defaults_(Brush b) {
if (b.buffer.pixels == NULL)
b.buffer = frame_pixels();
- if (b.buffer.line_size == 0)
- b.buffer.line_size = b.buffer.width;
+ if (b.buffer.stride == 0)
+ b.buffer.stride = b.buffer.width;
return b;
}
@@ -1204,10 +1204,10 @@ b8 line_contains(f64 x0, f64 y0, f64 x1, f64 y1, f64 width, f64 px, f64 py) {
Pixel_Buffer frame_pixels(void) {
return (Pixel_Buffer) {
- .width = g_platform.frame_width,
- .height = g_platform.frame_height,
- .line_size = g_platform.frame_width,
- .pixels = g_platform.pixels,
+ .width = g_platform.frame_width,
+ .height = g_platform.frame_height,
+ .stride = g_platform.frame_width,
+ .pixels = g_platform.pixels,
};
}
@@ -1223,29 +1223,29 @@ Pixel_Buffer sketch_pixels(i64 width, i64 height) {
}
return (Pixel_Buffer) {
- .width = width,
- .height = height,
- .line_size = width,
- .pixels = g_platform.sketch,
+ .width = width,
+ .height = height,
+ .stride = width,
+ .pixels = g_platform.sketch,
};
}
Pixel_Buffer subimage(Pixel_Buffer image, i64 x, i64 y, i64 width, i64 height) {
if (x < 0 || y < 0 || width <= 0 || height <= 0 || x + width > image.width || y + height > image.height || image.pixels == NULL)
return (Pixel_Buffer) {
- .width = 0,
- .height = 0,
- .line_size = 0,
+ .width = 0,
+ .height = 0,
+ .stride = 0,
// Set pixels pointer to prevent default initialization.
.pixels = g_platform.sketch,
};
return (Pixel_Buffer) {
- .width = width,
- .height = height,
- .line_size = image.line_size,
- .pixels = image.pixels + (y * image.line_size + x),
+ .width = width,
+ .height = height,
+ .stride = image.stride,
+ .pixels = image.pixels + (y * image.stride + x),
};
}
@@ -1259,7 +1259,7 @@ void put_pixel(Brush brush, i64 x, i64 y) {
}
void draw_pixels(Brush brush, f64 x, f64 y, f64 width, f64 height, Pixel_Buffer src) {
- if (width < EPSILON || height < EPSILON || src.width <= 0 || src.height <= 0 || src.line_size <= 0 || src.pixels == NULL)
+ if (width < EPSILON || height < EPSILON || src.width <= 0 || src.height <= 0 || src.stride <= 0 || src.pixels == NULL)
return;
draw_pixels_(brush_defaults_(brush), x, y, width, height, src);
@@ -1611,10 +1611,10 @@ TEST("colors") {
Brush brush = {
.buffer = {
- .width = 1280,
- .height = 720,
- .line_size = 1280,
- .pixels = g_platform.pixels,
+ .width = 1280,
+ .height = 720,
+ .stride = 1280,
+ .pixels = g_platform.pixels,
},
.position = { 0.f, 0.f, },
.scale = { 1.f, 1.f, },