OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include <emmintrin.h> | 8 #include <emmintrin.h> |
9 #include "SkBitmapProcState_opts_SSE2.h" | 9 #include "SkBitmapProcState_opts_SSE2.h" |
10 #include "SkBlitRow_opts_SSE2.h" | 10 #include "SkBlitRow_opts_SSE2.h" |
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 while (((size_t)dst & 0x0F) != 0) { | 866 while (((size_t)dst & 0x0F) != 0) { |
867 SkPMColor c = *src++; | 867 SkPMColor c = *src++; |
868 SkPMColorAssert(c); | 868 SkPMColorAssert(c); |
869 | 869 |
870 *dst++ = SkPixel32ToPixel16_ToU16(c); | 870 *dst++ = SkPixel32ToPixel16_ToU16(c); |
871 count--; | 871 count--; |
872 } | 872 } |
873 | 873 |
874 const __m128i* s = reinterpret_cast<const __m128i*>(src); | 874 const __m128i* s = reinterpret_cast<const __m128i*>(src); |
875 __m128i* d = reinterpret_cast<__m128i*>(dst); | 875 __m128i* d = reinterpret_cast<__m128i*>(dst); |
876 __m128i r16_mask = _mm_set1_epi32(SK_R16_MASK); | |
877 __m128i g16_mask = _mm_set1_epi32(SK_G16_MASK); | |
878 __m128i b16_mask = _mm_set1_epi32(SK_B16_MASK); | |
879 | 876 |
880 while (count >= 8) { | 877 while (count >= 8) { |
881 // Load 8 pixels of src. | 878 // Load 8 pixels of src. |
882 __m128i src_pixel1 = _mm_loadu_si128(s++); | 879 __m128i src_pixel1 = _mm_loadu_si128(s++); |
883 __m128i src_pixel2 = _mm_loadu_si128(s++); | 880 __m128i src_pixel2 = _mm_loadu_si128(s++); |
884 | 881 |
885 // Calculate result r. | 882 __m128i d_pixel = SkPixel32ToPixel16_ToU16_SSE2(src_pixel1, src_pixe
l2); |
886 __m128i r1 = _mm_srli_epi32(src_pixel1, | |
887 SK_R32_SHIFT + (8 - SK_R16_BITS)); | |
888 r1 = _mm_and_si128(r1, r16_mask); | |
889 __m128i r2 = _mm_srli_epi32(src_pixel2, | |
890 SK_R32_SHIFT + (8 - SK_R16_BITS)); | |
891 r2 = _mm_and_si128(r2, r16_mask); | |
892 __m128i r = _mm_packs_epi32(r1, r2); | |
893 | |
894 // Calculate result g. | |
895 __m128i g1 = _mm_srli_epi32(src_pixel1, | |
896 SK_G32_SHIFT + (8 - SK_G16_BITS)); | |
897 g1 = _mm_and_si128(g1, g16_mask); | |
898 __m128i g2 = _mm_srli_epi32(src_pixel2, | |
899 SK_G32_SHIFT + (8 - SK_G16_BITS)); | |
900 g2 = _mm_and_si128(g2, g16_mask); | |
901 __m128i g = _mm_packs_epi32(g1, g2); | |
902 | |
903 // Calculate result b. | |
904 __m128i b1 = _mm_srli_epi32(src_pixel1, | |
905 SK_B32_SHIFT + (8 - SK_B16_BITS)); | |
906 b1 = _mm_and_si128(b1, b16_mask); | |
907 __m128i b2 = _mm_srli_epi32(src_pixel2, | |
908 SK_B32_SHIFT + (8 - SK_B16_BITS)); | |
909 b2 = _mm_and_si128(b2, b16_mask); | |
910 __m128i b = _mm_packs_epi32(b1, b2); | |
911 | |
912 // Store 8 16-bit colors in dst. | |
913 __m128i d_pixel = SkPackRGB16_SSE2(r, g, b); | |
914 _mm_store_si128(d++, d_pixel); | 883 _mm_store_si128(d++, d_pixel); |
915 count -= 8; | 884 count -= 8; |
916 } | 885 } |
917 src = reinterpret_cast<const SkPMColor*>(s); | 886 src = reinterpret_cast<const SkPMColor*>(s); |
918 dst = reinterpret_cast<uint16_t*>(d); | 887 dst = reinterpret_cast<uint16_t*>(d); |
919 } | 888 } |
920 | 889 |
921 if (count > 0) { | 890 if (count > 0) { |
922 do { | 891 do { |
923 SkPMColor c = *src++; | 892 SkPMColor c = *src++; |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1351 uint32_t dst_expanded = SkExpand_rgb_16(*dst); | 1320 uint32_t dst_expanded = SkExpand_rgb_16(*dst); |
1352 dst_expanded = dst_expanded * (SkAlpha255To256(255 - a) >> 3); | 1321 dst_expanded = dst_expanded * (SkAlpha255To256(255 - a) >> 3); |
1353 // now src and dst expanded are in g:11 r:10 x:1 b:10 | 1322 // now src and dst expanded are in g:11 r:10 x:1 b:10 |
1354 *dst = SkCompact_rgb_16((src_expanded + dst_expanded) >> 5); | 1323 *dst = SkCompact_rgb_16((src_expanded + dst_expanded) >> 5); |
1355 } | 1324 } |
1356 dst += 1; | 1325 dst += 1; |
1357 DITHER_INC_X(x); | 1326 DITHER_INC_X(x); |
1358 } while (--count != 0); | 1327 } while (--count != 0); |
1359 } | 1328 } |
1360 } | 1329 } |
OLD | NEW |