Skip to content

Commit de7ae03

Browse files
committed
C89_BUILD fixes
1 parent 2908041 commit de7ae03

2 files changed

Lines changed: 105 additions & 57 deletions

File tree

gfx/video_filters/dedither.c

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "softfilter.h"
22
#include <stdlib.h>
33
#include <string.h>
4+
#include <retro_inline.h>
45

56
#ifdef RARCH_INTERNAL
67
#define softfilter_get_implementation dedither_get_implementation
@@ -41,45 +42,57 @@ static void *dedither_generic_create(const struct softfilter_config *config,
4142
unsigned max_width, unsigned max_height,
4243
unsigned threads, softfilter_simd_mask_t simd, void *userdata) {
4344
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
44-
if (!filt) return NULL;
45+
if (!filt)
46+
return NULL;
4547
filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data));
4648
filt->threads = 1;
4749
filt->in_fmt = in_fmt;
4850
return filt;
4951
}
5052

51-
static void dedither_generic_destroy(void *data) {
53+
static void dedither_generic_destroy(void *data)
54+
{
5255
struct filter_data *filt = (struct filter_data*)data;
53-
if (filt) { free(filt->workers); free(filt); }
56+
if (filt)
57+
{
58+
free(filt->workers);
59+
free(filt);
60+
}
5461
}
5562

56-
static void dedither_generic_output(void *data, unsigned *out_width, unsigned *out_height,
57-
unsigned width, unsigned height) {
58-
*out_width = width; *out_height = height;
63+
static void dedither_generic_output(void *data, unsigned *out_width, unsigned *out_height, unsigned width, unsigned height)
64+
{
65+
*out_width = width;
66+
*out_height = height;
5967
}
6068

6169
/* Color comparison with threshold */
62-
static inline int pix_equal(uint32_t c1, uint32_t c2, int threshold) {
70+
static INLINE int pix_equal(uint32_t c1, uint32_t c2, int threshold)
71+
{
6372
int r = abs((int)((c1 >> 16) & 0xFF) - (int)((c2 >> 16) & 0xFF));
6473
int g = abs((int)((c1 >> 8) & 0xFF) - (int)((c2 >> 8) & 0xFF));
6574
int b = abs((int)(c1 & 0xFF) - (int)(c2 & 0xFF));
6675
return (r + g + b) < threshold;
6776
}
6877

6978
/* XRGB8888 Kernel - 2D Dither Detection (6x6) */
70-
static void dedither_work_cb_xrgb8888(void *data, void *thread_data) {
79+
static void dedither_work_cb_xrgb8888(void *data, void *thread_data)
80+
{
81+
uint32_t y, x;
7182
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)thread_data;
7283
const uint32_t *in = (const uint32_t*)thr->in_data;
7384
uint32_t *out = (uint32_t*)thr->out_data;
7485
uint32_t in_stride = (uint32_t)(thr->in_pitch >> 2);
7586
uint32_t out_stride = (uint32_t)(thr->out_pitch >> 2);
7687
const int threshold = 40;
7788

78-
for (uint32_t y = 0; y < thr->height; ++y) {
79-
for (uint32_t x = 0; x < thr->width; ++x) {
89+
for (y = 0; y < thr->height; ++y)
90+
{
91+
for (x = 0; x < thr->width; ++x)
92+
{
8093
/* Check safety bounds for 6-pixel horizontal and vertical patterns */
81-
if (x >= 2 && x < thr->width - 3 && y >= 2 && y < thr->height - 3) {
82-
94+
if (x >= 2 && x < thr->width - 3 && y >= 2 && y < thr->height - 3)
95+
{
8396
const uint32_t *line = in + y * in_stride;
8497

8598
/* Horizontal samples (Row y) */
@@ -104,7 +117,8 @@ static void dedither_work_cb_xrgb8888(void *data, void *thread_data) {
104117
pix_equal(v2, v4, threshold) && pix_equal(v4, v6, threshold) &&
105118
!pix_equal(h3, v4, threshold));
106119

107-
if (h_dit || v_dit) {
120+
if (h_dit || v_dit)
121+
{
108122
uint32_t avg;
109123
if (h_dit)
110124
avg = (((h2 & 0xFEFEFEFE) >> 1) + ((h4 & 0xFEFEFEFE) >> 1));
@@ -113,27 +127,32 @@ static void dedither_work_cb_xrgb8888(void *data, void *thread_data) {
113127

114128
/* Apply soft blend (1:2:1 weighting) */
115129
out[y * out_stride + x] = (((avg & 0xFEFEFEFE) >> 1) + ((h3 & 0xFEFEFEFE) >> 1));
116-
} else {
117-
out[y * out_stride + x] = h3; /* Keep original sharp pixel */
118130
}
119-
} else {
120-
out[y * out_stride + x] = in[y * in_stride + x];
131+
else
132+
out[y * out_stride + x] = h3; /* Keep original sharp pixel */
121133
}
134+
else
135+
out[y * out_stride + x] = in[y * in_stride + x];
122136
}
123137
}
124138
}
125139

126140
/* RGB565 Kernel - 2D Dither Detection (6x6) */
127-
static void dedither_work_cb_rgb565(void *data, void *thread_data) {
141+
static void dedither_work_cb_rgb565(void *data, void *thread_data)
142+
{
143+
uint32_t x, y;
128144
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)thread_data;
129145
const uint16_t *in = (const uint16_t*)thr->in_data;
130146
uint16_t *out = (uint16_t*)thr->out_data;
131147
uint16_t in_stride = (uint16_t)(thr->in_pitch >> 1);
132148
uint16_t out_stride = (uint16_t)(thr->out_pitch >> 1);
133149

134-
for (uint32_t y = 0; y < thr->height; ++y) {
135-
for (uint32_t x = 0; x < thr->width; ++x) {
136-
if (x >= 2 && x < thr->width - 3 && y >= 2 && y < thr->height - 3) {
150+
for (y = 0; y < thr->height; ++y)
151+
{
152+
for (x = 0; x < thr->width; ++x)
153+
{
154+
if (x >= 2 && x < thr->width - 3 && y >= 2 && y < thr->height - 3)
155+
{
137156
const uint16_t *line = in + y * in_stride;
138157
uint16_t h1 = line[x - 2]; uint16_t h2 = line[x - 1];
139158
uint16_t h3 = line[x]; uint16_t h4 = line[x + 1];
@@ -146,22 +165,30 @@ static void dedither_work_cb_rgb565(void *data, void *thread_data) {
146165
int h_dit = (h1 == h3 && h3 == h5 && h2 == h4 && h4 == h6 && h3 != h4);
147166
int v_dit = (v1 == h3 && h3 == v5 && v2 == v4 && v4 == v6 && h3 != v2);
148167

149-
if (h_dit || v_dit) {
168+
if (h_dit || v_dit)
169+
{
150170
uint16_t avg_s = (h_dit) ? (((h2 & 0xF7DE) >> 1) + ((h4 & 0xF7DE) >> 1)) : (((v2 & 0xF7DE) >> 1) + ((v4 & 0xF7DE) >> 1));
151171
out[y * out_stride + x] = (((avg_s & 0xF7DE) >> 1) + ((h3 & 0xF7DE) >> 1));
152-
} else out[y * out_stride + x] = h3;
153-
} else out[y * out_stride + x] = in[y * in_stride + x];
172+
}
173+
else
174+
out[y * out_stride + x] = h3;
175+
}
176+
else
177+
out[y * out_stride + x] = in[y * in_stride + x];
154178
}
155179
}
156180
}
157181

158-
static void dedither_generic_packets(void *data, struct softfilter_work_packet *packets,
159-
void *output, size_t output_stride, const void *input, unsigned width, unsigned height, size_t input_stride) {
182+
static void dedither_generic_packets(void *data,
183+
struct softfilter_work_packet *packets,
184+
void *output, size_t output_stride, const void *input,
185+
unsigned width, unsigned height, size_t input_stride)
186+
{
160187
struct filter_data *filt = (struct filter_data*)data;
161-
struct softfilter_thread_data *thr = &filt->workers[0];
162-
thr->out_data = output; thr->in_data = input;
188+
struct softfilter_thread_data *thr = &filt->workers[0];
189+
thr->out_data = output; thr->in_data = input;
163190
thr->out_pitch = output_stride; thr->in_pitch = input_stride;
164-
thr->width = width; thr->height = height;
191+
thr->width = width; thr->height = height;
165192

166193
if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
167194
packets[0].work = dedither_work_cb_xrgb8888;
@@ -177,6 +204,7 @@ static const struct softfilter_implementation dedither_generic = {
177204
SOFTFILTER_API_VERSION, "Master De-Dither 2D (6x6)", "dedither",
178205
};
179206

180-
const struct softfilter_implementation *softfilter_get_implementation(softfilter_simd_mask_t simd) {
181-
(void)simd; return &dedither_generic;
182-
}
207+
const struct softfilter_implementation *softfilter_get_implementation(softfilter_simd_mask_t simd)
208+
{
209+
return &dedither_generic;
210+
}

gfx/video_filters/pixel_art_aa.c

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,30 @@ static void paa_query_output_size(void *data, unsigned *out_width, unsigned *out
5959
*out_height = height << 1;
6060
}
6161

62-
/* Helper για μίξη RGB565 */
63-
static inline uint16_t mix_565(uint16_t c1, uint16_t c2) {
62+
/* Helper RGB565 */
63+
static INLINE uint16_t mix_565(uint16_t c1, uint16_t c2) {
6464
return (((c1 & 0xF7DE) >> 1) + ((c2 & 0xF7DE) >> 1));
6565
}
6666

67-
/* Helper για μίξη XRGB8888 */
68-
static inline uint32_t mix_8888(uint32_t c1, uint32_t c2) {
67+
/* Helper XRGB8888 */
68+
static INLINE uint32_t mix_8888(uint32_t c1, uint32_t c2) {
6969
return (((c1 & 0xFEFEFEFE) >> 1) + ((c2 & 0xFEFEFEFE) >> 1));
7070
}
7171

7272
/* Logic for XRGB8888 */
73-
static void paa_work_cb_xrgb8888(void *data, void *thread_data) {
73+
static void paa_work_cb_xrgb8888(void *data, void *thread_data)
74+
{
75+
uint32_t x, y;
7476
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)thread_data;
75-
const uint32_t *in = (const uint32_t*)thr->in_data;
76-
uint32_t *out = (uint32_t*)thr->out_data;
77-
uint32_t in_stride = (uint32_t)(thr->in_pitch >> 2);
77+
const uint32_t *in = (const uint32_t*)thr->in_data;
78+
uint32_t *out = (uint32_t*)thr->out_data;
79+
uint32_t in_stride = (uint32_t)(thr->in_pitch >> 2);
7880
uint32_t out_stride = (uint32_t)(thr->out_pitch >> 2);
7981

80-
for (uint32_t y = 0; y < thr->height; y++) {
81-
for (uint32_t x = 0; x < thr->width; x++) {
82+
for (y = 0; y < thr->height; y++)
83+
{
84+
for (x = 0; x < thr->width; x++)
85+
{
8286
uint32_t p = in[y * in_stride + x];
8387
uint32_t *out_ptr = out + (y * 2 * out_stride) + (x * 2);
8488
uint32_t n = (y > 0) ? in[(y-1)*in_stride + x] : p;
@@ -89,24 +93,32 @@ static void paa_work_cb_xrgb8888(void *data, void *thread_data) {
8993
out_ptr[0] = p; out_ptr[1] = p;
9094
out_ptr[out_stride] = p; out_ptr[out_stride + 1] = p;
9195

92-
if (n != p && w != p && n == w) out_ptr[0] = mix_8888(p, n);
93-
if (n != p && e != p && n == e) out_ptr[1] = mix_8888(p, n);
94-
if (s != p && w != p && s == w) out_ptr[out_stride] = mix_8888(p, s);
95-
if (s != p && e != p && s == e) out_ptr[out_stride + 1] = mix_8888(p, s);
96+
if (n != p && w != p && n == w)
97+
out_ptr[0] = mix_8888(p, n);
98+
if (n != p && e != p && n == e)
99+
out_ptr[1] = mix_8888(p, n);
100+
if (s != p && w != p && s == w)
101+
out_ptr[out_stride] = mix_8888(p, s);
102+
if (s != p && e != p && s == e)
103+
out_ptr[out_stride + 1] = mix_8888(p, s);
96104
}
97105
}
98106
}
99107

100108
/* Logic for RGB565 */
101-
static void paa_work_cb_rgb565(void *data, void *thread_data) {
109+
static void paa_work_cb_rgb565(void *data, void *thread_data)
110+
{
111+
uint32_t x, y;
102112
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)thread_data;
103113
const uint16_t *in = (const uint16_t*)thr->in_data;
104114
uint16_t *out = (uint16_t*)thr->out_data;
105115
uint16_t in_stride = (uint16_t)(thr->in_pitch >> 1);
106116
uint16_t out_stride = (uint16_t)(thr->out_pitch >> 1);
107117

108-
for (uint32_t y = 0; y < thr->height; y++) {
109-
for (uint32_t x = 0; x < thr->width; x++) {
118+
for (y = 0; y < thr->height; y++)
119+
{
120+
for (x = 0; x < thr->width; x++)
121+
{
110122
uint16_t p = in[y * in_stride + x];
111123
uint16_t *out_ptr = out + (y * 2 * out_stride) + (x * 2);
112124
uint16_t n = (y > 0) ? in[(y-1)*in_stride + x] : p;
@@ -117,16 +129,24 @@ static void paa_work_cb_rgb565(void *data, void *thread_data) {
117129
out_ptr[0] = p; out_ptr[1] = p;
118130
out_ptr[out_stride] = p; out_ptr[out_stride + 1] = p;
119131

120-
if (n != p && w != p && n == w) out_ptr[0] = mix_565(p, n);
121-
if (n != p && e != p && n == e) out_ptr[1] = mix_565(p, n);
122-
if (s != p && w != p && s == w) out_ptr[out_stride] = mix_565(p, s);
123-
if (s != p && e != p && s == e) out_ptr[out_stride + 1] = mix_565(p, s);
132+
if (n != p && w != p && n == w)
133+
out_ptr[0] = mix_565(p, n);
134+
if (n != p && e != p && n == e)
135+
out_ptr[1] = mix_565(p, n);
136+
if (s != p && w != p && s == w)
137+
out_ptr[out_stride] = mix_565(p, s);
138+
if (s != p && e != p && s == e)
139+
out_ptr[out_stride + 1] = mix_565(p, s);
124140
}
125141
}
126142
}
127143

128-
static void paa_get_work_packets(void *data, struct softfilter_work_packet *packets,
129-
void *output, size_t output_stride, const void *input, unsigned width, unsigned height, size_t input_stride) {
144+
static void paa_get_work_packets(void *data,
145+
struct softfilter_work_packet *packets,
146+
void *output, size_t output_stride,
147+
const void *input, unsigned width, unsigned height,
148+
size_t input_stride)
149+
{
130150
struct filter_data *filt = (struct filter_data*)data;
131151
struct softfilter_thread_data *thr = &filt->workers[0];
132152
thr->out_data = output; thr->in_data = input;
@@ -148,5 +168,5 @@ static const struct softfilter_implementation paa_impl = {
148168
};
149169

150170
const struct softfilter_implementation *softfilter_get_implementation(softfilter_simd_mask_t simd) {
151-
(void)simd; return &paa_impl;
152-
}
171+
return &paa_impl;
172+
}

0 commit comments

Comments
 (0)