aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/platform/vivid
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2015-03-09 10:47:48 -0400
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>2015-04-02 19:48:53 -0400
commitc6ff1c1b5ba0cff72f899e3b3ba0343b5a0e0024 (patch)
treebe96eb5cbdcce1c787a7c73e6087a76c52b80eb6 /drivers/media/platform/vivid
parent07386b9ab1d2adcf83543dfee0e835db56ccb3d5 (diff)
[media] vivid-tpg: move the 'extras' drawing to a separate function
This moves the drawing code for the extras (border, square, etc) to a function of its own instead of having this in the main for loop. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers/media/platform/vivid')
-rw-r--r--drivers/media/platform/vivid/vivid-tpg.c216
1 files changed, 104 insertions, 112 deletions
diff --git a/drivers/media/platform/vivid/vivid-tpg.c b/drivers/media/platform/vivid/vivid-tpg.c
index f76ef3e2f498..21c2f4b3242e 100644
--- a/drivers/media/platform/vivid/vivid-tpg.c
+++ b/drivers/media/platform/vivid/vivid-tpg.c
@@ -1594,6 +1594,105 @@ static void tpg_fill_params_extras(const struct tpg_data *tpg,
1594 (params->is_60hz ? V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM); 1594 (params->is_60hz ? V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM);
1595} 1595}
1596 1596
1597static void tpg_fill_plane_extras(const struct tpg_data *tpg,
1598 const struct tpg_draw_params *params,
1599 unsigned p, unsigned h, u8 *vbuf)
1600{
1601 unsigned twopixsize = params->twopixsize;
1602 unsigned img_width = params->img_width;
1603 unsigned frame_line = params->frame_line;
1604 const struct v4l2_rect *sq = &tpg->square;
1605 const struct v4l2_rect *b = &tpg->border;
1606 const struct v4l2_rect *c = &tpg->crop;
1607
1608 if (params->is_tv && !params->is_60hz &&
1609 frame_line == 0 && params->wss_width) {
1610 /*
1611 * Replace the first half of the top line of a 50 Hz frame
1612 * with random data to simulate a WSS signal.
1613 */
1614 u8 *wss = tpg->random_line[p] + params->wss_random_offset;
1615
1616 memcpy(vbuf, wss, params->wss_width);
1617 }
1618
1619 if (tpg->show_border && frame_line >= b->top &&
1620 frame_line < b->top + b->height) {
1621 unsigned bottom = b->top + b->height - 1;
1622 unsigned left = params->left_pillar_width;
1623 unsigned right = params->right_pillar_start;
1624
1625 if (frame_line == b->top || frame_line == b->top + 1 ||
1626 frame_line == bottom || frame_line == bottom - 1) {
1627 memcpy(vbuf + left, tpg->contrast_line[p],
1628 right - left);
1629 } else {
1630 if (b->left >= c->left &&
1631 b->left < c->left + c->width)
1632 memcpy(vbuf + left,
1633 tpg->contrast_line[p], twopixsize);
1634 if (b->left + b->width > c->left &&
1635 b->left + b->width <= c->left + c->width)
1636 memcpy(vbuf + right - twopixsize,
1637 tpg->contrast_line[p], twopixsize);
1638 }
1639 }
1640 if (tpg->qual != TPG_QUAL_NOISE && frame_line >= b->top &&
1641 frame_line < b->top + b->height) {
1642 memcpy(vbuf, tpg->black_line[p], params->left_pillar_width);
1643 memcpy(vbuf + params->right_pillar_start, tpg->black_line[p],
1644 img_width - params->right_pillar_start);
1645 }
1646 if (tpg->show_square && frame_line >= sq->top &&
1647 frame_line < sq->top + sq->height &&
1648 sq->left < c->left + c->width &&
1649 sq->left + sq->width >= c->left) {
1650 unsigned left = sq->left;
1651 unsigned width = sq->width;
1652
1653 if (c->left > left) {
1654 width -= c->left - left;
1655 left = c->left;
1656 }
1657 if (c->left + c->width < left + width)
1658 width -= left + width - c->left - c->width;
1659 left -= c->left;
1660 left = tpg_hscale_div(tpg, p, left);
1661 width = tpg_hscale_div(tpg, p, width);
1662 memcpy(vbuf + left, tpg->contrast_line[p], width);
1663 }
1664 if (tpg->insert_sav) {
1665 unsigned offset = tpg_hdiv(tpg, p, tpg->compose.width / 3);
1666 u8 *p = vbuf + offset;
1667 unsigned vact = 0, hact = 0;
1668
1669 p[0] = 0xff;
1670 p[1] = 0;
1671 p[2] = 0;
1672 p[3] = 0x80 | (params->sav_eav_f << 6) |
1673 (vact << 5) | (hact << 4) |
1674 ((hact ^ vact) << 3) |
1675 ((hact ^ params->sav_eav_f) << 2) |
1676 ((params->sav_eav_f ^ vact) << 1) |
1677 (hact ^ vact ^ params->sav_eav_f);
1678 }
1679 if (tpg->insert_eav) {
1680 unsigned offset = tpg_hdiv(tpg, p, tpg->compose.width * 2 / 3);
1681 u8 *p = vbuf + offset;
1682 unsigned vact = 0, hact = 1;
1683
1684 p[0] = 0xff;
1685 p[1] = 0;
1686 p[2] = 0;
1687 p[3] = 0x80 | (params->sav_eav_f << 6) |
1688 (vact << 5) | (hact << 4) |
1689 ((hact ^ vact) << 3) |
1690 ((hact ^ params->sav_eav_f) << 2) |
1691 ((params->sav_eav_f ^ vact) << 1) |
1692 (hact ^ vact ^ params->sav_eav_f);
1693 }
1694}
1695
1597void tpg_fill_plane_buffer(struct tpg_data *tpg, v4l2_std_id std, unsigned p, u8 *vbuf) 1696void tpg_fill_plane_buffer(struct tpg_data *tpg, v4l2_std_id std, unsigned p, u8 *vbuf)
1598{ 1697{
1599 struct tpg_draw_params params; 1698 struct tpg_draw_params params;
@@ -1608,7 +1707,6 @@ void tpg_fill_plane_buffer(struct tpg_data *tpg, v4l2_std_id std, unsigned p, u8
1608 unsigned line_offset; 1707 unsigned line_offset;
1609 unsigned stride; 1708 unsigned stride;
1610 unsigned factor = V4L2_FIELD_HAS_T_OR_B(tpg->field) ? 2 : 1; 1709 unsigned factor = V4L2_FIELD_HAS_T_OR_B(tpg->field) ? 2 : 1;
1611 u8 *orig_vbuf = vbuf;
1612 1710
1613 /* Coarse scaling with Bresenham */ 1711 /* Coarse scaling with Bresenham */
1614 unsigned int_part = (tpg->crop.height / factor) / tpg->compose.height; 1712 unsigned int_part = (tpg->crop.height / factor) / tpg->compose.height;
@@ -1653,7 +1751,9 @@ void tpg_fill_plane_buffer(struct tpg_data *tpg, v4l2_std_id std, unsigned p, u8
1653 u8 *linestart_top; 1751 u8 *linestart_top;
1654 u8 *linestart_bottom; 1752 u8 *linestart_bottom;
1655 1753
1656 frame_line = tpg_calc_frameline(tpg, src_y, tpg->field); 1754 params.frame_line = tpg_calc_frameline(tpg, src_y, tpg->field);
1755 params.frame_line_next = params.frame_line;
1756 frame_line = params.frame_line;
1657 even = !(frame_line & 1); 1757 even = !(frame_line & 1);
1658 buf_line = tpg_calc_buffer_line(tpg, h, tpg->field); 1758 buf_line = tpg_calc_buffer_line(tpg, h, tpg->field);
1659 src_y += int_part; 1759 src_y += int_part;
@@ -1802,117 +1902,9 @@ void tpg_fill_plane_buffer(struct tpg_data *tpg, v4l2_std_id std, unsigned p, u8
1802 memcpy(vbuf + buf_line * stride, linestart_older, img_width); 1902 memcpy(vbuf + buf_line * stride, linestart_older, img_width);
1803 break; 1903 break;
1804 } 1904 }
1805 }
1806 1905
1807 vbuf = orig_vbuf; 1906 tpg_fill_plane_extras(tpg, &params, p, h,
1808 vbuf += tpg_hdiv(tpg, p, tpg->compose.left); 1907 vbuf + buf_line * params.stride);
1809 src_y = 0;
1810 error = 0;
1811 for (h = 0; h < tpg->compose.height; h++) {
1812 unsigned frame_line = tpg_calc_frameline(tpg, src_y, tpg->field);
1813 unsigned buf_line = tpg_calc_buffer_line(tpg, h, tpg->field);
1814 const struct v4l2_rect *sq = &tpg->square;
1815 const struct v4l2_rect *b = &tpg->border;
1816 const struct v4l2_rect *c = &tpg->crop;
1817
1818 src_y += int_part;
1819 error += fract_part;
1820 if (error >= tpg->compose.height) {
1821 error -= tpg->compose.height;
1822 src_y++;
1823 }
1824
1825 if (vdiv > 1) {
1826 if (h & 1)
1827 continue;
1828 buf_line /= vdiv;
1829 }
1830
1831 if (params.is_tv && !params.is_60hz && frame_line == 0 && params.wss_width) {
1832 /*
1833 * Replace the first half of the top line of a 50 Hz frame
1834 * with random data to simulate a WSS signal.
1835 */
1836 u8 *wss = tpg->random_line[p] + params.wss_random_offset;
1837
1838 memcpy(vbuf + buf_line * stride, wss, params.wss_width);
1839 }
1840
1841 if (tpg->show_border && frame_line >= b->top &&
1842 frame_line < b->top + b->height) {
1843 unsigned bottom = b->top + b->height - 1;
1844 unsigned left = params.left_pillar_width;
1845 unsigned right = params.right_pillar_start;
1846
1847 if (frame_line == b->top || frame_line == b->top + 1 ||
1848 frame_line == bottom || frame_line == bottom - 1) {
1849 memcpy(vbuf + buf_line * stride + left, tpg->contrast_line[p],
1850 right - left);
1851 } else {
1852 if (b->left >= c->left &&
1853 b->left < c->left + c->width)
1854 memcpy(vbuf + buf_line * stride + left,
1855 tpg->contrast_line[p], twopixsize);
1856 if (b->left + b->width > c->left &&
1857 b->left + b->width <= c->left + c->width)
1858 memcpy(vbuf + buf_line * stride + right - twopixsize,
1859 tpg->contrast_line[p], twopixsize);
1860 }
1861 }
1862 if (tpg->qual != TPG_QUAL_NOISE && frame_line >= b->top &&
1863 frame_line < b->top + b->height) {
1864 memcpy(vbuf + buf_line * stride, tpg->black_line[p], params.left_pillar_width);
1865 memcpy(vbuf + buf_line * stride + params.right_pillar_start, tpg->black_line[p],
1866 img_width - params.right_pillar_start);
1867 }
1868 if (tpg->show_square && frame_line >= sq->top &&
1869 frame_line < sq->top + sq->height &&
1870 sq->left < c->left + c->width &&
1871 sq->left + sq->width >= c->left) {
1872 unsigned left = sq->left;
1873 unsigned width = sq->width;
1874
1875 if (c->left > left) {
1876 width -= c->left - left;
1877 left = c->left;
1878 }
1879 if (c->left + c->width < left + width)
1880 width -= left + width - c->left - c->width;
1881 left -= c->left;
1882 left = tpg_hscale_div(tpg, p, left);
1883 width = tpg_hscale_div(tpg, p, width);
1884 memcpy(vbuf + buf_line * stride + left, tpg->contrast_line[p], width);
1885 }
1886 if (tpg->insert_sav) {
1887 unsigned offset = tpg_hdiv(tpg, p, tpg->compose.width / 3);
1888 u8 *p = vbuf + buf_line * stride + offset;
1889 unsigned vact = 0, hact = 0;
1890
1891 p[0] = 0xff;
1892 p[1] = 0;
1893 p[2] = 0;
1894 p[3] = 0x80 | (params.sav_eav_f << 6) |
1895 (vact << 5) | (hact << 4) |
1896 ((hact ^ vact) << 3) |
1897 ((hact ^ params.sav_eav_f) << 2) |
1898 ((params.sav_eav_f ^ vact) << 1) |
1899 (hact ^ vact ^ params.sav_eav_f);
1900 }
1901 if (tpg->insert_eav) {
1902 unsigned offset = tpg_hdiv(tpg, p, tpg->compose.width * 2 / 3);
1903 u8 *p = vbuf + buf_line * stride + offset;
1904 unsigned vact = 0, hact = 1;
1905
1906 p[0] = 0xff;
1907 p[1] = 0;
1908 p[2] = 0;
1909 p[3] = 0x80 | (params.sav_eav_f << 6) |
1910 (vact << 5) | (hact << 4) |
1911 ((hact ^ vact) << 3) |
1912 ((hact ^ params.sav_eav_f) << 2) |
1913 ((params.sav_eav_f ^ vact) << 1) |
1914 (hact ^ vact ^ params.sav_eav_f);
1915 }
1916 } 1908 }
1917} 1909}
1918 1910