twiddle: use both src and dst value masks

This commit is contained in:
Zack Buhman 2023-12-23 22:48:04 +08:00
parent 15839ae6ca
commit dc85cad8b0
2 changed files with 15 additions and 11 deletions

View File

@ -59,15 +59,15 @@ uint32_t transform(ta_parameter_writer& parameter,
auto polygon = global_polygon_type_0(texture_address);
polygon.parameter_control_word = para_control::para_type::polygon_or_modifier_volume
| para_control::list_type::opaque
| obj_control::col_type::packed_color
| obj_control::texture;
| para_control::list_type::opaque
| obj_control::col_type::packed_color
| obj_control::texture;
polygon.tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
| tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::fog_control::no_fog
| tsp_instruction_word::texture_u_size::from_int(texture_width)
| tsp_instruction_word::texture_v_size::from_int(texture_height);
| tsp_instruction_word::dst_alpha_instr::zero
| tsp_instruction_word::fog_control::no_fog
| tsp_instruction_word::texture_u_size::from_int(texture_width)
| tsp_instruction_word::texture_v_size::from_int(texture_height);
polygon.texture_control_word = texture_control_word::pixel_format::_8bpp_palette
| texture_control_word::scan_order::twiddled
@ -266,10 +266,11 @@ void main()
auto parameter = ta_parameter_writer(ta_parameter_buf);
/*
transform2(parameter,
font->texture_width, font->texture_height);
*/
/*
transform(parameter,
font->texture_width, font->texture_height,
font->first_char_code,
@ -283,7 +284,6 @@ void main()
glyphs,
cabal, 26,
font->glyph_height * 1);
*/
parameter.append<global_end_of_list>() = global_end_of_list();

View File

@ -183,17 +183,21 @@ void texture3(volatile T * dst, const U * src,
constexpr uint32_t pixels_per_u = u_bits / src_bits_per_pixel;
static_assert(pixels_per_u == 1 || pixels_per_u == 2 || pixels_per_u == 4 || pixels_per_u == 8 || pixels_per_u == 16 || pixels_per_u == 32);
constexpr uint32_t src_val_mask = ((1 << src_bits_per_pixel) - 1);
constexpr uint32_t dst_val_mask = ((1 << dst_bits_per_pixel) - 1);
constexpr uint32_t dst_src_shift = (dst_bits_per_pixel < src_bits_per_pixel) ? (src_bits_per_pixel - dst_bits_per_pixel) : 0;
T dst_val = 0;
for (uint32_t curve_ix = 0; curve_ix <= curve_end_ix; curve_ix++) {
auto [x, y] = from_ix(curve_ix);
const uint32_t src_ix = y * src_stride + (x / pixels_per_u);
const uint32_t src_ix_mod = x & (pixels_per_u - 1);
const U src_val = (src[src_ix] >> (src_bits_per_pixel * src_ix_mod)) & ((1 << src_bits_per_pixel) - 1);
const U src_val = (src[src_ix] >> (src_bits_per_pixel * src_ix_mod)) & src_val_mask;
if constexpr (pixels_per_t == 1) {
dst[curve_ix] = src_val;
} else {
const uint32_t curve_ix_mod = curve_ix & (pixels_per_t - 1);
dst_val |= src_val << (dst_bits_per_pixel * curve_ix_mod);
dst_val |= ((src_val >> dst_src_shift) & dst_val_mask) << (dst_bits_per_pixel * curve_ix_mod);
if (curve_ix_mod == (pixels_per_t - 1)) {
dst[curve_ix / pixels_per_t] = dst_val;