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+ }
0 commit comments