Skip to content

Commit 5b1ea02

Browse files
committed
Plugins (infinite): Streamline method _inf_compute_surface
- Save write to add_src - Save adding 0 for absent neighbors - Use "foo[index]" rather than "*(foo + index)" for reability - Simplify interpol->weight byte unpacking Ideas by Chong Kai Xiong (@kaixiong) (cherry picked from commit b7fc821)
1 parent 063b609 commit 5b1ea02

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

  • libvisual-plugins/plugins/actor/infinite

libvisual-plugins/plugins/actor/infinite/display.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,25 +164,26 @@ static void _inf_compute_surface(InfinitePrivate *priv, t_interpol* vector_field
164164
interpol = &vector_field[add_dest];
165165
const uint16_t y = interpol->coord & 0xffff;
166166
const uint16_t x = interpol->coord >> 16;
167-
add_src = y * priv->plugwidth + x;
168-
ptr_pix = priv->surface1 + add_src;;
167+
(void)add_src;
168+
ptr_pix = priv->surface1 + y * priv->plugwidth + x;
169169

170170
const uint8_t *ptr_pix_end = priv->surface1 + (priv->plugwidth * priv->plugheight);
171171

172-
const uint8_t neighbor_right = (ptr_pix + 1 >= ptr_pix_end)
173-
? 0
174-
: *(ptr_pix + 1);
175-
const uint8_t neighbor_below = (ptr_pix + priv->plugwidth >= ptr_pix_end)
176-
? 0
177-
: *(ptr_pix + priv->plugwidth);
178-
const uint8_t neighbor_right_below = (ptr_pix + priv->plugwidth + 1 >= ptr_pix_end)
179-
? 0
180-
: *(ptr_pix + priv->plugwidth + 1);
181-
182-
color= (*(ptr_pix) * (interpol->weight >> 24)
183-
+neighbor_right * ((interpol->weight & 0xFFFFFF) >> 16)
184-
+neighbor_below * ((interpol->weight & 0xFFFF) >> 8)
185-
+neighbor_right_below * (interpol->weight & 0xFF)) >> 8;
172+
color = ptr_pix[0] * (interpol->weight >> 24);
173+
174+
// right neigbor
175+
if (ptr_pix + 1 < ptr_pix_end)
176+
color += ptr_pix[1] * ((interpol->weight >> 16) & 0xFF);
177+
178+
// bottom neigbor
179+
if (ptr_pix + priv->plugwidth < ptr_pix_end)
180+
color += ptr_pix[priv->plugwidth] * ((interpol->weight >> 8) & 0xFF);
181+
182+
// bottom right neigbor
183+
if (ptr_pix + priv->plugwidth + 1 < ptr_pix_end)
184+
color += ptr_pix[priv->plugwidth + 1] * (interpol->weight & 0xFF);
185+
186+
color >>= 8;
186187
/*
187188
color= (*(ptr_pix) // * (interpol->weight >> 24)
188189
+*(ptr_pix + 1) // * ((interpol->weight & 0xFFFFFF) >> 16)

0 commit comments

Comments
 (0)