{render,config}: allow specifying wallpaper anchor position

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Iee73e9d149e85d2c00eaba4be25d42bd6a6a6964
This commit is contained in:
raf 2026-04-13 14:25:47 +03:00
commit a82b986ac6
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
4 changed files with 189 additions and 29 deletions

View file

@ -41,8 +41,9 @@ static void get_gl_filter_params(chroma_filter_quality_t quality,
}
}
// Calculate texture coordinates based on scaling mode
// Calculate texture coordinates based on scaling mode and anchor position
static void calculate_texture_coords(chroma_scale_mode_t scale_mode,
chroma_anchor_t anchor,
int image_width, int image_height,
int output_width, int output_height,
float tex_coords[8]) {
@ -142,6 +143,72 @@ static void calculate_texture_coords(chroma_scale_mode_t scale_mode,
break;
}
// Apply anchor-based offset by shifting the visible crop region
// For fill: shift which part of image is shown
// For fit/center: shift where the image is positioned
//
// Positive shift reveals left/bottom portion
// Negative shift reveals right/top portion
float u_shift = 0.0f;
float v_shift = 0.0f;
switch (anchor) {
case CHROMA_ANCHOR_CENTER:
u_shift = 0.0f;
v_shift = 0.0f;
break;
case CHROMA_ANCHOR_TOP:
u_shift = 0.0f;
v_shift = -0.5f; // shift up to show top of image
break;
case CHROMA_ANCHOR_BOTTOM:
u_shift = 0.0f;
v_shift = 0.5f; // shift down to show bottom of image
break;
case CHROMA_ANCHOR_LEFT:
u_shift = -0.5f; // shift left to show left of image
v_shift = 0.0f;
break;
case CHROMA_ANCHOR_RIGHT:
u_shift = 0.5f; // shift right to show right of image
v_shift = 0.0f;
break;
case CHROMA_ANCHOR_TOP_LEFT:
u_shift = -0.5f;
v_shift = -0.5f;
break;
case CHROMA_ANCHOR_TOP_RIGHT:
u_shift = 0.5f;
v_shift = -0.5f;
break;
case CHROMA_ANCHOR_BOTTOM_LEFT:
u_shift = -0.5f;
v_shift = 0.5f;
break;
case CHROMA_ANCHOR_BOTTOM_RIGHT:
u_shift = 0.5f;
v_shift = 0.5f;
break;
}
// Calculate the shift amount based on crop/border space available
float u_crop = 1.0f - (u2 - u1);
float v_crop = 1.0f - (v2 - v1);
u1 += u_shift * u_crop;
u2 += u_shift * u_crop;
v1 += v_shift * v_crop;
v2 += v_shift * v_crop;
// Clamp to valid range [0, 1]
if (u1 < 0.0f)
u1 = 0.0f;
if (u2 > 1.0f)
u2 = 1.0f;
if (v1 < 0.0f)
v1 = 0.0f;
if (v2 > 1.0f)
v2 = 1.0f;
// Set texture coordinates for quad (bottom-left, bottom-right, top-right,
// top-left)
tex_coords[0] = u1;
@ -688,11 +755,11 @@ int chroma_render_wallpaper(chroma_state_t *state, chroma_output_t *output) {
// Update VBO only if needed. E.g, image changed, scale mode changed, or first
// render
if (output->vbo_dirty) {
// Calculate texture coordinates based on scaling mode
// Calculate texture coordinates based on scaling mode and anchor
float tex_coords[8];
calculate_texture_coords(output->scale_mode, output->image->width,
output->image->height, output->width,
output->height, tex_coords);
calculate_texture_coords(output->scale_mode, output->anchor,
output->image->width, output->image->height,
output->width, output->height, tex_coords);
// Create dynamic vertex data with calculated texture coordinates
float dynamic_vertices[] = {