diff options
Diffstat (limited to 'src/blitter/32bpp_sse2.cpp')
-rw-r--r-- | src/blitter/32bpp_sse2.cpp | 148 |
1 files changed, 60 insertions, 88 deletions
diff --git a/src/blitter/32bpp_sse2.cpp b/src/blitter/32bpp_sse2.cpp index a5d8a1987..ddaa352e2 100644 --- a/src/blitter/32bpp_sse2.cpp +++ b/src/blitter/32bpp_sse2.cpp @@ -30,6 +30,7 @@ IGNORE_UNINITIALIZED_WARNING_START template <BlitterMode mode, Blitter_32bppSSE2::ReadMode read_mode, Blitter_32bppSSE2::BlockType bt_last> inline void Blitter_32bppSSE2::Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom) { + const byte *remap = bp->remap; Colour *dst_line = (Colour *) bp->dst + bp->top * bp->pitch + bp->left; int effective_width = bp->width; @@ -43,6 +44,7 @@ inline void Blitter_32bppSSE2::Draw(const Blitter::BlitterParams *bp, ZoomLevel src_rgba_line += bp->skip_left; src_mv_line += bp->skip_left; } + const MapValue *src_mv = src_mv_line; /* Load these variables into register before loop. */ const __m128i clear_hi = CLEAR_HIGH_BYTE_MASK; @@ -51,99 +53,71 @@ inline void Blitter_32bppSSE2::Draw(const Blitter::BlitterParams *bp, ZoomLevel for (int y = bp->height; y != 0; y--) { Colour *dst = dst_line; const Colour *src = src_rgba_line + META_LENGTH; - const MapValue *src_mv = src_mv_line; + if (mode == BM_COLOUR_REMAP) src_mv = src_mv_line; + + if (read_mode == RM_WITH_MARGIN) { + src += src_rgba_line[0].data; + dst += src_rgba_line[0].data; + if (mode == BM_COLOUR_REMAP) src_mv += src_rgba_line[0].data; + const int width_diff = si->sprite_width - bp->width; + effective_width = bp->width - (int) src_rgba_line[0].data; + const int delta_diff = (int) src_rgba_line[1].data - width_diff; + const int new_width = effective_width - delta_diff; + effective_width = delta_diff > 0 ? new_width : effective_width; + if (effective_width <= 0) goto next_line; + } switch (mode) { - default: { - switch (read_mode) { - case RM_WITH_MARGIN: { - src += src_rgba_line[0].data; - dst += src_rgba_line[0].data; - const int width_diff = si->sprite_width - bp->width; - effective_width = bp->width - (int) src_rgba_line[0].data; - const int delta_diff = (int) src_rgba_line[1].data - width_diff; - const int new_width = effective_width - (delta_diff & ~1); - effective_width = delta_diff > 0 ? new_width : effective_width; - if (effective_width <= 0) break; - /* FALLTHROUGH */ - } - - case RM_WITH_SKIP: { - for (uint x = (uint) effective_width / 2; x > 0; x--) { - __m128i srcABCD = _mm_loadl_epi64((const __m128i*) src); - __m128i dstABCD = _mm_loadl_epi64((__m128i*) dst); - ALPHA_BLEND_2(); - _mm_storel_epi64((__m128i*) dst, srcABCD); - src += 2; - dst += 2; - } - if ((bt_last == BT_NONE && effective_width & 1) || bt_last == BT_ODD) { - __m128i srcABCD = _mm_cvtsi32_si128(src->data); - __m128i dstABCD = _mm_cvtsi32_si128(dst->data); - ALPHA_BLEND_2(); - dst->data = _mm_cvtsi128_si32(srcABCD); - } - break; - } + default: + for (uint x = (uint) effective_width / 2; x > 0; x--) { + __m128i srcABCD = _mm_loadl_epi64((const __m128i*) src); + __m128i dstABCD = _mm_loadl_epi64((__m128i*) dst); + ALPHA_BLEND_2(); + _mm_storel_epi64((__m128i*) dst, srcABCD); + src += 2; + dst += 2; + } - default: NOT_REACHED(); + if ((bt_last == BT_NONE && effective_width & 1) || bt_last == BT_ODD) { + __m128i srcABCD = _mm_cvtsi32_si128(src->data); + __m128i dstABCD = _mm_cvtsi32_si128(dst->data); + ALPHA_BLEND_2(); + dst->data = _mm_cvtsi128_si32(srcABCD); } break; - } - case BM_COLOUR_REMAP: { - switch (read_mode) { - case RM_WITH_MARGIN: { - src += src_rgba_line[0].data; - src_mv += src_rgba_line[0].data; - dst += src_rgba_line[0].data; - const int width_diff = si->sprite_width - bp->width; - effective_width = bp->width - (int) src_rgba_line[0].data; - const int delta_diff = (int) src_rgba_line[1].data - width_diff; - const int new_width = effective_width - delta_diff; - effective_width = delta_diff > 0 ? new_width : effective_width; - if (effective_width <= 0) break; - /* FALLTHROUGH */ - } - case RM_WITH_SKIP: { - const byte *remap = bp->remap; - for (uint x = (uint) effective_width; x != 0; x--) { - /* In case the m-channel is zero, do not remap this pixel in any way. */ - __m128i srcABCD; - if (src_mv->m) { - const uint r = remap[src_mv->m]; - if (r != 0) { - Colour remapped_colour = AdjustBrightness(this->LookupColourInPalette(r), src_mv->v); - if (src->a == 255) { - *dst = remapped_colour; - } else { - remapped_colour.a = src->a; - srcABCD = _mm_cvtsi32_si128(remapped_colour.data); - goto bmcr_alpha_blend_single; - } - } + case BM_COLOUR_REMAP: + for (uint x = (uint) effective_width; x != 0; x--) { + /* In case the m-channel is zero, do not remap this pixel in any way. */ + __m128i srcABCD; + if (src_mv->m) { + const uint r = remap[src_mv->m]; + if (r != 0) { + Colour remapped_colour = AdjustBrightness(this->LookupColourInPalette(r), src_mv->v); + if (src->a == 255) { + *dst = remapped_colour; } else { - srcABCD = _mm_cvtsi32_si128(src->data); - if (src->a < 255) { -bmcr_alpha_blend_single: - __m128i dstABCD = _mm_cvtsi32_si128(dst->data); - ALPHA_BLEND_2(); - } - dst->data = _mm_cvtsi128_si32(srcABCD); + remapped_colour.a = src->a; + srcABCD = _mm_cvtsi32_si128(remapped_colour.data); + goto bmcr_alpha_blend_single; } - src_mv++; - dst++; - src++; } - break; + } else { + srcABCD = _mm_cvtsi32_si128(src->data); + if (src->a < 255) { +bmcr_alpha_blend_single: + __m128i dstABCD = _mm_cvtsi32_si128(dst->data); + ALPHA_BLEND_2(); + } + dst->data = _mm_cvtsi128_si32(srcABCD); } - - default: NOT_REACHED(); + src_mv++; + dst++; + src++; } - src_mv_line += si->sprite_width; break; - } - case BM_TRANSPARENT: { + + case BM_TRANSPARENT: /* Make the current colour a bit more black, so it looks like this image is transparent. */ for (uint x = (uint) bp->width / 2; x > 0; x--) { __m128i srcABCD = _mm_loadl_epi64((const __m128i*) src); @@ -153,6 +127,7 @@ bmcr_alpha_blend_single: src += 2; dst += 2; } + if ((bt_last == BT_NONE && bp->width & 1) || bt_last == BT_ODD) { __m128i srcABCD = _mm_cvtsi32_si128(src->data); __m128i dstABCD = _mm_cvtsi32_si128(dst->data); @@ -160,9 +135,10 @@ bmcr_alpha_blend_single: dst->data = _mm_cvtsi128_si32(dstAB); } break; - } } +next_line: + if (mode == BM_COLOUR_REMAP) src_mv_line += si->sprite_width; src_rgba_line = (const Colour*) ((const byte*) src_rgba_line + si->sprite_line_size); dst_line += bp->pitch; } @@ -180,19 +156,15 @@ void Blitter_32bppSSE2::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomL { switch (mode) { case BM_NORMAL: { - const BlockType bt_last = (BlockType) (bp->width & 1); if (bp->skip_left != 0 || bp->width <= MARGIN_NORMAL_THRESHOLD) { + const BlockType bt_last = (BlockType) (bp->width & 1); switch (bt_last) { case BT_EVEN: Draw<BM_NORMAL, RM_WITH_SKIP, BT_EVEN>(bp, zoom); return; case BT_ODD: Draw<BM_NORMAL, RM_WITH_SKIP, BT_ODD>(bp, zoom); return; default: NOT_REACHED(); } } else { - switch (bt_last) { - case BT_EVEN: Draw<BM_NORMAL, RM_WITH_MARGIN, BT_EVEN>(bp, zoom); return; - case BT_ODD: Draw<BM_NORMAL, RM_WITH_MARGIN, BT_ODD>(bp, zoom); return; - default: NOT_REACHED(); - } + Draw<BM_NORMAL, RM_WITH_MARGIN, BT_NONE>(bp, zoom); return; } break; } |