ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
neon/luminance.c
Go to the documentation of this file.
4#include <string.h>
5#include <arm_neon.h>
6void simd_luminance_neon(const uint8_t *rgb, uint8_t *out, size_t width) {
7 const rgb_pixel_t *row = (const rgb_pixel_t *)rgb;
8 size_t x = 0;
9 for (; width - x >= 16; x += 16) {
10 // Load 16 RGB pixels (48 bytes)
11 uint8x16x3_t pixels = vld3q_u8((const uint8_t *)(row + x));
12
13 // Calculate luminance for all 16 pixels: (77*R + 150*G + 29*B + 128) >> 8
14 uint16x8_t luma_lo = vmull_u8(vget_low_u8(pixels.val[0]), vdup_n_u8(LUMA_RED)); // R * 77
15 luma_lo = vmlal_u8(luma_lo, vget_low_u8(pixels.val[1]), vdup_n_u8(LUMA_GREEN)); // + G * 150
16 luma_lo = vmlal_u8(luma_lo, vget_low_u8(pixels.val[2]), vdup_n_u8(LUMA_BLUE)); // + B * 29
17 luma_lo = vaddq_u16(luma_lo, vdupq_n_u16(128)); // + 128 (rounding)
18 luma_lo = vshrq_n_u16(luma_lo, 8); // >> 8
19
20 uint16x8_t luma_hi = vmull_u8(vget_high_u8(pixels.val[0]), vdup_n_u8(LUMA_RED));
21 luma_hi = vmlal_u8(luma_hi, vget_high_u8(pixels.val[1]), vdup_n_u8(LUMA_GREEN));
22 luma_hi = vmlal_u8(luma_hi, vget_high_u8(pixels.val[2]), vdup_n_u8(LUMA_BLUE));
23 luma_hi = vaddq_u16(luma_hi, vdupq_n_u16(128));
24 luma_hi = vshrq_n_u16(luma_hi, 8);
25
26 // Convert 16-bit luminance back to 8-bit
27 uint8x16_t luminance = vcombine_u8(vmovn_u16(luma_lo), vmovn_u16(luma_hi));
28
29 vst1q_u8(out + x, luminance);
30 }
31 simd_luminance_scalar((const uint8_t *)(row + x), out + x, width - x);
32}
33int glyph_shape_correlation_neon(const int16_t samples[16], const int16_t mask[16]) {
34 int16x8_t a0 = vld1q_s16(samples), a1 = vld1q_s16(samples + 8);
35 int16x8_t b0 = vld1q_s16(mask), b1 = vld1q_s16(mask + 8);
36 int32x4_t sums = vmull_s16(vget_low_s16(a0), vget_low_s16(b0));
37 sums = vmlal_s16(sums, vget_high_s16(a0), vget_high_s16(b0));
38 sums = vmlal_s16(sums, vget_low_s16(a1), vget_low_s16(b1));
39 sums = vmlal_s16(sums, vget_high_s16(a1), vget_high_s16(b1));
40 int32_t lanes[4];
41 vst1q_s32(lanes, sums);
42 return lanes[0] + lanes[1] + lanes[2] + lanes[3];
43}
void simd_luminance_scalar(const uint8_t *rgb, uint8_t *out, size_t count)
Definition dispatch.c:57
unsigned int width
Definition fft.c:23
unsigned char uint8_t
Definition common.h:60
#define LUMA_BLUE
Luminance blue coefficient (0.114 * 256 = 29).
#define LUMA_GREEN
Luminance green coefficient (0.587 * 256 = 150).
#define LUMA_RED
Luminance red coefficient (0.299 * 256 = 77).
void simd_luminance_neon(const uint8_t *rgb, uint8_t *out, size_t width)
int glyph_shape_correlation_neon(const int16_t samples[16], const int16_t mask[16])
static bool size_t gotel_query_t * out
Definition queries.h:8
🔤 String Manipulation and Shell Escaping Utilities
SIMD-optimized ASCII conversion interface.