Skip to content

Commit df1a4e1

Browse files
committed
Use macros for some 3-way blit LL-impls
1 parent c8e6154 commit df1a4e1

File tree

2 files changed

+90
-62
lines changed

2 files changed

+90
-62
lines changed

kos/src/libvideo/gfx/gfx-utils.h

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,79 @@ interpolate_2d(video_color_t c_y0_x0, video_color_t c_y0_x1,
695695
} \
696696
} while (dst_size_y); \
697697
} __WHILE0
698+
#define GFX_NEAREST_STRETCH3(out_x, out_y, \
699+
dst_x, dst_y, dst_size_x, dst_size_y, \
700+
src_x, src_y, src_size_x, src_size_y, \
701+
copy_pixel /*(out_x, out_y, dst_x, dst_y, src_x, src_y)*/, \
702+
out_row_start /*(out_y, dst_y, src_y)*/, \
703+
out_row_end /*(out_y, dst_y, src_y)*/) \
704+
do { \
705+
stretch_fp_t _step_x = STRETCH_FP(src_size_x) / dst_size_x; \
706+
stretch_fp_t _step_y = STRETCH_FP(src_size_y) / dst_size_y; \
707+
/* Start half-a-step ahead, thus rounding by 0.5 pixels */ \
708+
stretch_fp_t _src_pos_y = _step_y >> 1; \
709+
video_coord_t _iter_y = 0; \
710+
do { \
711+
video_coord_t _row_dst_y = dst_y + _iter_y; \
712+
video_coord_t _row_out_y = out_y + _iter_y; \
713+
video_coord_t _row_src_y = src_y + STRETCH_FP_WHOLE(_src_pos_y); \
714+
/* Start half-a-step ahead, thus rounding by 0.5 pixels */ \
715+
stretch_fp_t _src_pos_x = _step_x >> 1; \
716+
video_coord_t _iter_x = 0; \
717+
_src_pos_x += STRETCH_FP(src_x); \
718+
{ \
719+
out_row_start(_row_out_y, _row_dst_y, _row_src_y); \
720+
do { \
721+
video_coord_t row_src_x = STRETCH_FP_WHOLE(_src_pos_x); \
722+
copy_pixel(out_x + _iter_x, _row_out_y, \
723+
dst_x + _iter_x, _row_dst_y, \
724+
row_src_x, _row_src_y); \
725+
_src_pos_x += _step_x; \
726+
} while (++_iter_x < dst_size_x); \
727+
out_row_end(_row_out_y, _row_dst_y, _row_src_y); \
728+
} \
729+
_src_pos_y += _step_y; \
730+
} while (++_iter_y < dst_size_y); \
731+
} __WHILE0
732+
#define GFX_NEAREST_STRETCH3_IMATRIX(out_x, out_y, \
733+
dst_x, dst_y, dst_size_x, dst_size_y, dst_matrix, \
734+
src_x, src_y, src_size_x, src_size_y, src_matrix, \
735+
copy_pixel /*(out_x, out_y, dst_x, dst_y, src_x, src_y)*/, \
736+
out_row_start /*(out_y)*/, \
737+
out_row_end /*(out_y)*/) \
738+
do { \
739+
stretch_fp_t _step_x = STRETCH_FP(src_size_x) / dst_size_x; \
740+
stretch_fp_t _step_y = STRETCH_FP(src_size_y) / dst_size_y; \
741+
/* Start half-a-step ahead, thus rounding by 0.5 pixels */ \
742+
stretch_fp_t _src_pos_y = _step_y >> 1; \
743+
video_coord_t _iter_y = 0; \
744+
do { \
745+
video_coord_t _row_out_y = out_y + _iter_y; \
746+
video_coord_t _row_src_y = STRETCH_FP_WHOLE(_src_pos_y); \
747+
/* Start half-a-step ahead, thus rounding by 0.5 pixels */ \
748+
stretch_fp_t _src_pos_x = _step_x >> 1; \
749+
video_coord_t _base_src_x = src_x + video_imatrix2d_get(&src_matrix, 0, 1) * _row_src_y; \
750+
video_coord_t _base_src_y = src_y + video_imatrix2d_get(&src_matrix, 1, 1) * _row_src_y; \
751+
video_coord_t _used_dst_x = dst_x; \
752+
video_coord_t _used_dst_y = dst_y; \
753+
video_dim_t _iter_x = 0; \
754+
out_row_start(_row_out_y); \
755+
do { \
756+
video_coord_t _row_src_x = STRETCH_FP_WHOLE(_src_pos_x); \
757+
video_coord_t _used_src_x = _base_src_x + video_imatrix2d_get(&src_matrix, 0, 0) * _row_src_x; \
758+
video_coord_t _used_src_y = _base_src_y + video_imatrix2d_get(&src_matrix, 1, 0) * _row_src_x; \
759+
copy_pixel(out_x + _iter_x, _row_out_y, _used_dst_x, _used_dst_y, _used_src_x, _used_src_y); \
760+
_src_pos_x += _step_x; \
761+
_used_dst_x += video_imatrix2d_get(&dst_matrix, 0, 0); \
762+
_used_dst_y += video_imatrix2d_get(&dst_matrix, 1, 0); \
763+
} while (++_iter_x < dst_size_x); \
764+
out_row_end(_row_out_y); \
765+
_src_pos_y += _step_y; \
766+
dst_x += video_imatrix2d_get(&dst_matrix, 0, 1); \
767+
dst_y += video_imatrix2d_get(&dst_matrix, 1, 1); \
768+
} while (++_iter_y < dst_size_y); \
769+
} __WHILE0
770+
698771

699772

700773
/* Dummy callback for "dst_row_start" and "dst_row_end" */

kos/src/libvideo/gfx/swgfx/ll_blit3.c.inl

Lines changed: 17 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ libvideo_swblitter3__blit_imatrix__generic__bypixel(struct video_blitter3 const
112112
src_x, src_y, size_x, size_y, src_matrix,
113113
BLIT_PIXEL, GFX_ROW_NOOP, GFX_ROW_NOOP);
114114
}
115-
#undef BLIT_PIXEL
116-
117115

118116
PRIVATE ATTR_IN(1) void CC
119117
libvideo_swblitter3__stretch__generic_n__bypixel(struct video_blitter3 const *__restrict self,
@@ -122,35 +120,14 @@ libvideo_swblitter3__stretch__generic_n__bypixel(struct video_blitter3 const *__
122120
video_dim_t dst_size_x, video_dim_t dst_size_y,
123121
video_coord_t src_x, video_coord_t src_y,
124122
video_dim_t src_size_x, video_dim_t src_size_y) {
125-
video_dim_t y;
126123
struct video_gfx const *out = self->vbt3_wrdst;
127124
struct video_gfx const *dst = self->vbt3_rddst;
128125
struct video_gfx const *src = self->vbt3_src;
129126
blt3_blend_t blend = video_swblitter3_getcdrv(self)->bsw3_blend;
130-
stretch_fp_t step_x, step_y, src_pos_y;
131-
step_x = STRETCH_FP(src_size_x) / dst_size_x;
132-
step_y = STRETCH_FP(src_size_y) / dst_size_y;
133-
src_pos_y = step_y >> 1; /* Start half-a-step ahead, thus rounding by 0.5 pixels */
134-
y = 0;
135-
do {
136-
video_coord_t row_dst_y = dst_y + y;
137-
video_coord_t row_out_y = out_y + y;
138-
video_coord_t row_src_y = src_y + STRETCH_FP_WHOLE(src_pos_y);
139-
stretch_fp_t src_pos_x = step_x >> 1; /* Start half-a-step ahead, thus rounding by 0.5 pixels */
140-
video_dim_t x = 0;
141-
src_pos_x += STRETCH_FP(src_x);
142-
do {
143-
video_coord_t row_src_x = STRETCH_FP_WHOLE(src_pos_x);
144-
video_color_t sc = LL_getcolor(src, row_src_x, row_src_y);
145-
video_color_t dc = LL_getcolor(dst, dst_x + x, row_dst_y);
146-
video_color_t oc = (*blend)(self, dc, sc);
147-
LL_putcolor(out, out_x + x, row_out_y, oc);
148-
src_pos_x += step_x;
149-
++x;
150-
} while (x < dst_size_x);
151-
++y;
152-
src_pos_y += step_y;
153-
} while (y < dst_size_y);
127+
GFX_NEAREST_STRETCH3(out_x, out_y,
128+
dst_x, dst_y, dst_size_x, dst_size_y,
129+
src_x, src_y, src_size_x, src_size_y,
130+
BLIT_PIXEL, GFX_ROW_NOOP, GFX_ROW_NOOP);
154131
}
155132

156133
PRIVATE ATTR_IN(1) void CC
@@ -162,47 +139,16 @@ libvideo_swblitter3__stretch_imatrix__generic_n__bypixel(struct video_blitter3 c
162139
video_coord_t src_x, video_coord_t src_y,
163140
video_dim_t src_size_x, video_dim_t src_size_y,
164141
video_imatrix2d_t src_matrix) {
165-
video_dim_t y;
166142
struct video_gfx const *out = self->vbt3_wrdst;
167143
struct video_gfx const *dst = self->vbt3_rddst;
168144
struct video_gfx const *src = self->vbt3_src;
169145
blt3_blend_t blend = video_swblitter3_getcdrv(self)->bsw3_blend;
170-
stretch_fp_t step_x, step_y, src_pos_y;
171146
gfx_assert_imatrix2d(&dst_matrix);
172147
gfx_assert_imatrix2d(&src_matrix);
173-
174-
step_x = STRETCH_FP(src_size_x) / dst_size_x;
175-
step_y = STRETCH_FP(src_size_y) / dst_size_y;
176-
src_pos_y = step_y >> 1; /* Start half-a-step ahead, thus rounding by 0.5 pixels */
177-
y = 0;
178-
do {
179-
video_coord_t row_out_y = out_y + y;
180-
video_coord_t row_dst_y = dst_y + y;
181-
video_coord_t row_src_y = STRETCH_FP_WHOLE(src_pos_y);
182-
stretch_fp_t src_pos_x = step_x >> 1; /* Start half-a-step ahead, thus rounding by 0.5 pixels */
183-
video_offset_t delta_src_x = src_x + video_imatrix2d_get(&src_matrix, 0, 1) * row_src_y;
184-
video_offset_t delta_src_y = src_y + video_imatrix2d_get(&src_matrix, 1, 1) * row_src_y;
185-
video_offset_t delta_dst_x = dst_x + video_imatrix2d_get(&dst_matrix, 0, 1) * row_dst_y;
186-
video_offset_t delta_dst_y = dst_y + video_imatrix2d_get(&dst_matrix, 1, 1) * row_dst_y;
187-
video_dim_t x = 0;
188-
do {
189-
video_coord_t row_src_x = STRETCH_FP_WHOLE(src_pos_x);
190-
video_coord_t used_src_x = delta_src_x + video_imatrix2d_get(&src_matrix, 0, 0) * row_src_x;
191-
video_coord_t used_src_y = delta_src_y + video_imatrix2d_get(&src_matrix, 1, 0) * row_src_x;
192-
video_coord_t used_dst_x = delta_dst_x + video_imatrix2d_get(&dst_matrix, 0, 0) * x;
193-
video_coord_t used_dst_y = delta_dst_y + video_imatrix2d_get(&dst_matrix, 1, 0) * x;
194-
video_coord_t used_out_x = out_x + x;
195-
video_coord_t used_out_y = row_out_y;
196-
video_color_t sc = LL_getcolor(src, used_src_x, used_src_y);
197-
video_color_t dc = LL_getcolor(dst, used_dst_x, used_dst_y);
198-
video_color_t oc = (*blend)(self, dc, sc);
199-
LL_putcolor(out, used_out_x, used_out_y, oc);
200-
src_pos_x += step_x;
201-
++x;
202-
} while (x < dst_size_x);
203-
++y;
204-
src_pos_y += step_y;
205-
} while (y < dst_size_y);
148+
GFX_NEAREST_STRETCH3_IMATRIX(out_x, out_y,
149+
dst_x, dst_y, dst_size_x, dst_size_y, dst_matrix,
150+
src_x, src_y, src_size_x, src_size_y, src_matrix,
151+
BLIT_PIXEL, GFX_ROW_NOOP, GFX_ROW_NOOP);
206152
}
207153

208154

@@ -234,6 +180,7 @@ libvideo_swblitter3__stretch_imatrix__generic_l__bypixel(struct video_blitter3 c
234180
dst_x, dst_y, dst_size_x, dst_size_y, dst_matrix,
235181
src_x, src_y, src_size_x, src_size_y, src_matrix);
236182
}
183+
#undef BLIT_PIXEL
237184

238185

239186

@@ -506,6 +453,14 @@ libvideo_swblitter3__blit_imatrix__blend1(struct video_blitter3 const *__restric
506453
gfx_assert_imatrix2d(&dst_matrix);
507454
gfx_assert_imatrix2d(&src_matrix);
508455

456+
/* Fast-pass for known matrices */
457+
if (src_matrix == VIDEO_IMATRIX2D_INIT(1, 0, 0, 1) &&
458+
dst_matrix == VIDEO_IMATRIX2D_INIT(1, 0, 0, 1)) {
459+
libvideo_swblitter3__blit__blend1(self, out_x, out_y, dst_x, dst_y,
460+
src_x, src_y, size_x, size_y);
461+
return;
462+
}
463+
509464
TRACE_START("swblitter3__blit_imatrix__blend1("
510465
"out: {%" PRIuCRD "x%" PRIuCRD "}, "
511466
"dst: {%" PRIuCRD "x%" PRIuCRD ", matrix: {{%d,%d},{%d,%d}}}, "

0 commit comments

Comments
 (0)