OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. | 2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 1663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1674 #endif | 1674 #endif |
1675 | 1675 |
1676 for (y = 0; y < height; ++y) { | 1676 for (y = 0; y < height; ++y) { |
1677 ARGBShadeRow(src_argb, dst_argb, width, value); | 1677 ARGBShadeRow(src_argb, dst_argb, width, value); |
1678 src_argb += src_stride_argb; | 1678 src_argb += src_stride_argb; |
1679 dst_argb += dst_stride_argb; | 1679 dst_argb += dst_stride_argb; |
1680 } | 1680 } |
1681 return 0; | 1681 return 0; |
1682 } | 1682 } |
1683 | 1683 |
1684 // Interpolate 2 ARGB images by specified amount (0 to 255). | 1684 // Interpolate 2 images by specified amount (0 to 255). |
1685 LIBYUV_API | 1685 static |
1686 int ARGBInterpolate(const uint8* src_argb0, int src_stride_argb0, | 1686 int InterpolateBpp(const uint8* src_argb0, int src_stride_argb0, |
1687 const uint8* src_argb1, int src_stride_argb1, | 1687 const uint8* src_argb1, int src_stride_argb1, |
1688 uint8* dst_argb, int dst_stride_argb, | 1688 uint8* dst_argb, int dst_stride_argb, |
1689 int width, int height, int interpolation) { | 1689 int width, int height, int interpolation, int bpp) { |
1690 int y; | 1690 int y; |
1691 void (*InterpolateRow)(uint8* dst_ptr, const uint8* src_ptr, | 1691 void (*InterpolateRow)(uint8* dst_ptr, const uint8* src_ptr, |
1692 ptrdiff_t src_stride, int dst_width, | 1692 ptrdiff_t src_stride, int dst_width, |
1693 int source_y_fraction) = InterpolateRow_C; | 1693 int source_y_fraction) = InterpolateRow_C; |
1694 if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0) { | 1694 if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0) { |
1695 return -1; | 1695 return -1; |
1696 } | 1696 } |
1697 // Negative height means invert the image. | 1697 // Negative height means invert the image. |
1698 if (height < 0) { | 1698 if (height < 0) { |
1699 height = -height; | 1699 height = -height; |
1700 dst_argb = dst_argb + (height - 1) * dst_stride_argb; | 1700 dst_argb = dst_argb + (height - 1) * dst_stride_argb; |
1701 dst_stride_argb = -dst_stride_argb; | 1701 dst_stride_argb = -dst_stride_argb; |
1702 } | 1702 } |
1703 // Coalesce rows. | 1703 // Coalesce rows. |
1704 if (src_stride_argb0 == width * 4 && | 1704 if (src_stride_argb0 == width * bpp && |
1705 src_stride_argb1 == width * 4 && | 1705 src_stride_argb1 == width * bpp && |
1706 dst_stride_argb == width * 4) { | 1706 dst_stride_argb == width * bpp) { |
1707 width *= height; | 1707 width *= height; |
1708 height = 1; | 1708 height = 1; |
1709 src_stride_argb0 = src_stride_argb1 = dst_stride_argb = 0; | 1709 src_stride_argb0 = src_stride_argb1 = dst_stride_argb = 0; |
1710 } | 1710 } |
1711 #if defined(HAS_INTERPOLATEROW_SSE2) | 1711 #if defined(HAS_INTERPOLATEROW_SSE2) |
1712 if (TestCpuFlag(kCpuHasSSE2)) { | 1712 if (TestCpuFlag(kCpuHasSSE2)) { |
1713 InterpolateRow = InterpolateRow_Any_SSE2; | 1713 InterpolateRow = InterpolateRow_Any_SSE2; |
1714 if (IS_ALIGNED(width, 4)) { | 1714 if (IS_ALIGNED(width * bpp, 16)) { |
1715 InterpolateRow = InterpolateRow_SSE2; | 1715 InterpolateRow = InterpolateRow_SSE2; |
1716 } | 1716 } |
1717 } | 1717 } |
1718 #endif | 1718 #endif |
1719 #if defined(HAS_INTERPOLATEROW_SSSE3) | 1719 #if defined(HAS_INTERPOLATEROW_SSSE3) |
1720 if (TestCpuFlag(kCpuHasSSSE3)) { | 1720 if (TestCpuFlag(kCpuHasSSSE3)) { |
1721 InterpolateRow = InterpolateRow_Any_SSSE3; | 1721 InterpolateRow = InterpolateRow_Any_SSSE3; |
1722 if (IS_ALIGNED(width, 4)) { | 1722 if (IS_ALIGNED(width * bpp, 16)) { |
1723 InterpolateRow = InterpolateRow_SSSE3; | 1723 InterpolateRow = InterpolateRow_SSSE3; |
1724 } | 1724 } |
1725 } | 1725 } |
1726 #endif | 1726 #endif |
1727 #if defined(HAS_INTERPOLATEROW_AVX2) | 1727 #if defined(HAS_INTERPOLATEROW_AVX2) |
1728 if (TestCpuFlag(kCpuHasAVX2)) { | 1728 if (TestCpuFlag(kCpuHasAVX2)) { |
1729 InterpolateRow = InterpolateRow_Any_AVX2; | 1729 InterpolateRow = InterpolateRow_Any_AVX2; |
1730 if (IS_ALIGNED(width, 8)) { | 1730 if (IS_ALIGNED(width * bpp, 32)) { |
1731 InterpolateRow = InterpolateRow_AVX2; | 1731 InterpolateRow = InterpolateRow_AVX2; |
1732 } | 1732 } |
1733 } | 1733 } |
1734 #endif | 1734 #endif |
1735 #if defined(HAS_INTERPOLATEROW_NEON) | 1735 #if defined(HAS_INTERPOLATEROW_NEON) |
1736 if (TestCpuFlag(kCpuHasNEON)) { | 1736 if (TestCpuFlag(kCpuHasNEON)) { |
1737 InterpolateRow = InterpolateRow_Any_NEON; | 1737 InterpolateRow = InterpolateRow_Any_NEON; |
1738 if (IS_ALIGNED(width, 4)) { | 1738 if (IS_ALIGNED(width * bpp, 16)) { |
1739 InterpolateRow = InterpolateRow_NEON; | 1739 InterpolateRow = InterpolateRow_NEON; |
1740 } | 1740 } |
1741 } | 1741 } |
1742 #endif | 1742 #endif |
1743 #if defined(HAS_INTERPOLATEROW_MIPS_DSPR2) | 1743 #if defined(HAS_INTERPOLATEROW_MIPS_DSPR2) |
1744 if (TestCpuFlag(kCpuHasMIPS_DSPR2) && | 1744 if (TestCpuFlag(kCpuHasMIPS_DSPR2) && |
1745 IS_ALIGNED(src_argb0, 4) && IS_ALIGNED(src_stride_argb0, 4) && | 1745 IS_ALIGNED(src_argb0, 4) && IS_ALIGNED(src_stride_argb0, 4) && |
1746 IS_ALIGNED(src_argb1, 4) && IS_ALIGNED(src_stride_argb1, 4) && | 1746 IS_ALIGNED(src_argb1, 4) && IS_ALIGNED(src_stride_argb1, 4) && |
1747 IS_ALIGNED(dst_argb, 4) && IS_ALIGNED(dst_stride_argb, 4)) { | 1747 IS_ALIGNED(dst_argb, 4) && IS_ALIGNED(dst_stride_argb, 4) && |
| 1748 IS_ALIGNED(width * bpp, 4)) { |
1748 InterpolateRow = InterpolateRow_MIPS_DSPR2; | 1749 InterpolateRow = InterpolateRow_MIPS_DSPR2; |
1749 } | 1750 } |
1750 #endif | 1751 #endif |
1751 | 1752 |
1752 for (y = 0; y < height; ++y) { | 1753 for (y = 0; y < height; ++y) { |
1753 InterpolateRow(dst_argb, src_argb0, src_argb1 - src_argb0, | 1754 InterpolateRow(dst_argb, src_argb0, src_argb1 - src_argb0, |
1754 width * 4, interpolation); | 1755 width * bpp, interpolation); |
1755 src_argb0 += src_stride_argb0; | 1756 src_argb0 += src_stride_argb0; |
1756 src_argb1 += src_stride_argb1; | 1757 src_argb1 += src_stride_argb1; |
1757 dst_argb += dst_stride_argb; | 1758 dst_argb += dst_stride_argb; |
1758 } | 1759 } |
1759 return 0; | 1760 return 0; |
1760 } | 1761 } |
1761 | 1762 |
| 1763 // Interpolate 2 ARGB images by specified amount (0 to 255). |
| 1764 LIBYUV_API |
| 1765 int ARGBInterpolate(const uint8* src_argb0, int src_stride_argb0, |
| 1766 const uint8* src_argb1, int src_stride_argb1, |
| 1767 uint8* dst_argb, int dst_stride_argb, |
| 1768 int width, int height, int interpolation) { |
| 1769 return InterpolateBpp(src_argb0, src_stride_argb0, |
| 1770 src_argb1, src_stride_argb1, |
| 1771 dst_argb, dst_stride_argb, |
| 1772 width, height, interpolation, 4); |
| 1773 } |
| 1774 |
| 1775 // Interpolate 2 planes by specified amount (0 to 255). |
| 1776 LIBYUV_API |
| 1777 int InterpolatePlane(const uint8* src0, int src_stride0, |
| 1778 const uint8* src1, int src_stride1, |
| 1779 uint8* dst, int dst_stride, |
| 1780 int width, int height, int interpolation) { |
| 1781 return InterpolateBpp(src0, src_stride0, |
| 1782 src1, src_stride1, |
| 1783 dst, dst_stride, |
| 1784 width, height, interpolation, 1); |
| 1785 } |
| 1786 |
| 1787 |
| 1788 // Interpolate 2 YUV images by specified amount (0 to 255). |
| 1789 LIBYUV_API |
| 1790 int I420Interpolate(const uint8* src0_y, int src0_stride_y, |
| 1791 const uint8* src0_u, int src0_stride_u, |
| 1792 const uint8* src0_v, int src0_stride_v, |
| 1793 const uint8* src1_y, int src1_stride_y, |
| 1794 const uint8* src1_u, int src1_stride_u, |
| 1795 const uint8* src1_v, int src1_stride_v, |
| 1796 uint8* dst_y, int dst_stride_y, |
| 1797 uint8* dst_u, int dst_stride_u, |
| 1798 uint8* dst_v, int dst_stride_v, |
| 1799 int width, int height, int interpolation) { |
| 1800 int halfwidth = (width + 1) >> 1; |
| 1801 int halfheight = (height + 1) >> 1; |
| 1802 if (!src0_y || !src0_u || !src0_v || |
| 1803 !src1_y || !src1_u || !src1_v || |
| 1804 !dst_y || !dst_u || !dst_v || |
| 1805 width <= 0 || height == 0) { |
| 1806 return -1; |
| 1807 } |
| 1808 InterpolateBpp(src0_y, src0_stride_y, |
| 1809 src1_y, src1_stride_y, |
| 1810 dst_y, dst_stride_y, |
| 1811 width, height, interpolation, 1); |
| 1812 InterpolateBpp(src0_u, src0_stride_u, |
| 1813 src1_u, src1_stride_u, |
| 1814 dst_u, dst_stride_u, |
| 1815 halfwidth, halfheight, interpolation, 1); |
| 1816 InterpolateBpp(src0_v, src0_stride_v, |
| 1817 src1_v, src1_stride_v, |
| 1818 dst_v, dst_stride_v, |
| 1819 halfwidth, halfheight, interpolation, 1); |
| 1820 return 0; |
| 1821 } |
| 1822 |
1762 // Shuffle ARGB channel order. e.g. BGRA to ARGB. | 1823 // Shuffle ARGB channel order. e.g. BGRA to ARGB. |
1763 LIBYUV_API | 1824 LIBYUV_API |
1764 int ARGBShuffle(const uint8* src_bgra, int src_stride_bgra, | 1825 int ARGBShuffle(const uint8* src_bgra, int src_stride_bgra, |
1765 uint8* dst_argb, int dst_stride_argb, | 1826 uint8* dst_argb, int dst_stride_argb, |
1766 const uint8* shuffler, int width, int height) { | 1827 const uint8* shuffler, int width, int height) { |
1767 int y; | 1828 int y; |
1768 void (*ARGBShuffleRow)(const uint8* src_bgra, uint8* dst_argb, | 1829 void (*ARGBShuffleRow)(const uint8* src_bgra, uint8* dst_argb, |
1769 const uint8* shuffler, int width) = ARGBShuffleRow_C; | 1830 const uint8* shuffler, int width) = ARGBShuffleRow_C; |
1770 if (!src_bgra || !dst_argb || | 1831 if (!src_bgra || !dst_argb || |
1771 width <= 0 || height == 0) { | 1832 width <= 0 || height == 0) { |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2415 } | 2476 } |
2416 free_aligned_buffer_64(rows); | 2477 free_aligned_buffer_64(rows); |
2417 } | 2478 } |
2418 return 0; | 2479 return 0; |
2419 } | 2480 } |
2420 | 2481 |
2421 #ifdef __cplusplus | 2482 #ifdef __cplusplus |
2422 } // extern "C" | 2483 } // extern "C" |
2423 } // namespace libyuv | 2484 } // namespace libyuv |
2424 #endif | 2485 #endif |
OLD | NEW |