Skip to content

Commit 98d3f9f

Browse files
committed
Added memswap function protototype
1 parent cb9cb07 commit 98d3f9f

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

include/lsp-plug.in/r3d/base/backend.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ namespace lsp
5252
static status_t init(backend_t *handle);
5353
static void destroy(backend_t *handle);
5454

55+
static void memswap(void *a, void *b, size_t bytes);
56+
static void swap_rows(void *buf, size_t rows, size_t bytes_per_row);
57+
5558
static status_t locate(backend_t *handle, ssize_t left, ssize_t top, ssize_t width, ssize_t height);
5659
static status_t set_matrix(backend_t *handle, matrix_type_t type, const mat4_t *m);
5760
static status_t get_matrix(backend_t *handle, matrix_type_t type, mat4_t *m);

src/main/base_backend.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,54 @@ namespace lsp
159159
R[15] = A[3] * B[12] + A[7] * B[13] + A[11] * B[14] + A[15] * B[15];
160160
}
161161

162+
void base_backend_t::memswap(void *a, void *b, size_t bytes)
163+
{
164+
uint32_t *xa = reinterpret_cast<uint32_t *>(a);
165+
uint32_t *xb = reinterpret_cast<uint32_t *>(b);
166+
for (; bytes >= 16 ; bytes -= 16, xa += 4, xb += 4)
167+
{
168+
uint32_t t0 = xa[0];
169+
uint32_t t1 = xa[1];
170+
uint32_t t2 = xa[2];
171+
uint32_t t3 = xa[3];
172+
173+
xa[0] = xb[0];
174+
xa[1] = xb[1];
175+
xa[2] = xb[2];
176+
xa[3] = xb[3];
177+
178+
xb[0] = t0;
179+
xb[1] = t1;
180+
xb[2] = t2;
181+
xb[3] = t3;
182+
}
183+
184+
for (; bytes >= 4 ; bytes -= 4, xa += 1, xb += 1)
185+
{
186+
uint32_t t0 = xa[0];
187+
xa[0] = xb[0];
188+
xb[0] = t0;
189+
}
190+
191+
uint8_t *ya = reinterpret_cast<uint8_t *>(xa);
192+
uint8_t *yb = reinterpret_cast<uint8_t *>(xb);
193+
194+
for (size_t i=0; i<bytes; ++i)
195+
{
196+
uint8_t t0 = ya[i];
197+
ya[i] = yb[i];
198+
yb[i] = t0;
199+
}
200+
}
201+
202+
void base_backend_t::swap_rows(void *buf, size_t rows, size_t bytes_per_row)
203+
{
204+
uint8_t *a = static_cast<uint8_t *>(buf);
205+
uint8_t *b = &a[(rows - 1) * bytes_per_row];
206+
for ( ; a < b ; a += bytes_per_row, b -= bytes_per_row)
207+
memswap(a, b, bytes_per_row);
208+
}
209+
162210
status_t base_backend_t::set_bg_color(backend_t *handle, const color_t *color)
163211
{
164212
if (color == NULL)

0 commit comments

Comments
 (0)