This commit also restricts w to 4, 8, or 16. Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz: before after draw_edges_8_1724_4_c: 46796.5 7141.7 ( 6.55x) draw_edges_8_1724_8_c: 43584.5 7216.5 ( 6.04x) draw_edges_8_1724_16_c: 47007.2 10080.5 ( 4.66x) draw_edges_128_407_4_c: 11199.0 4185.0 ( 2.68x) draw_edges_128_407_8_c: 10660.2 4418.0 ( 2.41x) draw_edges_128_407_16_c: 11800.2 4634.5 ( 2.55x) draw_edges_1080_31_4_c: 1356.5 634.7 ( 2.14x) draw_edges_1080_31_8_c: 1972.0 1430.2 ( 1.38x) draw_edges_1080_31_16_c: 4621.0 4009.7 ( 1.15x) draw_edges_1920_4_4_c: 834.5 795.2 ( 1.05x) draw_edges_1920_4_4_negstride_c: 821.7 802.0 ( 1.02x) draw_edges_1920_4_8_c: 2782.2 2650.7 ( 1.05x) draw_edges_1920_4_8_negstride_c: 2724.7 2670.0 ( 1.02x) draw_edges_1920_4_16_c: 6437.5 6327.7 ( 1.02x) draw_edges_1920_4_16_negstride_c: 6395.2 6349.5 ( 1.01x) A55: before after draw_edges_8_1724_4_c: 52540.4 19739.2 ( 2.66x) draw_edges_8_1724_8_c: 45386.9 19847.4 ( 2.29x) draw_edges_8_1724_16_c: 51995.4 23284.7 ( 2.23x) draw_edges_128_407_4_c: 13401.1 6988.2 ( 1.92x) draw_edges_128_407_8_c: 12218.4 7527.9 ( 1.62x) draw_edges_128_407_16_c: 13695.9 8207.2 ( 1.67x) draw_edges_1080_31_4_c: 3702.9 3110.4 ( 1.19x) draw_edges_1080_31_8_c: 6015.6 5643.2 ( 1.07x) draw_edges_1080_31_16_c: 12281.9 11901.4 ( 1.03x) draw_edges_1920_4_4_c: 3957.9 3970.2 ( 1.00x) draw_edges_1920_4_4_negstride_c: 3964.1 3825.2 ( 1.04x) draw_edges_1920_4_8_c: 7757.9 7676.4 ( 1.01x) draw_edges_1920_4_8_negstride_c: 7923.6 7812.4 ( 1.01x) draw_edges_1920_4_16_c: 14791.6 15143.9 ( 0.98x) draw_edges_1920_4_16_negstride_c: 14788.6 15163.4 ( 0.98x) A76: before after draw_edges_8_1724_4_c: 39786.0 4968.5 ( 8.01x) draw_edges_8_1724_8_c: 32971.5 5069.5 ( 6.50x) draw_edges_8_1724_16_c: 40056.0 6017.2 ( 6.66x) draw_edges_128_407_4_c: 9517.2 1210.5 ( 7.86x) draw_edges_128_407_8_c: 8035.7 1346.2 ( 5.97x) draw_edges_128_407_16_c: 9946.5 1648.2 ( 6.03x) draw_edges_1080_31_4_c: 1308.0 660.7 ( 1.98x) draw_edges_1080_31_8_c: 1785.5 1270.7 ( 1.41x) draw_edges_1080_31_16_c: 3266.7 2591.5 ( 1.26x) draw_edges_1920_4_4_c: 1151.0 1090.7 ( 1.06x) draw_edges_1920_4_4_negstride_c: 1153.7 1096.5 ( 1.05x) draw_edges_1920_4_8_c: 2220.7 2186.5 ( 1.02x) draw_edges_1920_4_8_negstride_c: 2218.5 2193.5 ( 1.01x) draw_edges_1920_4_16_c: 4324.2 4230.0 ( 1.02x) draw_edges_1920_4_16_negstride_c: 4310.7 4233.0 ( 1.02x)
274 lines
7.6 KiB
C
274 lines
7.6 KiB
C
/*
|
|
* This file is part of FFmpeg.
|
|
*
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
#include <assert.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
|
|
#include "config.h"
|
|
#include "libavutil/avassert.h"
|
|
#include "libavutil/attributes.h"
|
|
#include "libavutil/imgutils.h"
|
|
#include "avcodec.h"
|
|
#include "me_cmp.h"
|
|
#include "mpegvideoencdsp.h"
|
|
|
|
static int try_8x8basis_c(const int16_t rem[64], const int16_t weight[64],
|
|
const int16_t basis[64], int scale)
|
|
{
|
|
int i;
|
|
unsigned int sum = 0;
|
|
|
|
for (i = 0; i < 8 * 8; i++) {
|
|
int b = rem[i] + ((basis[i] * scale +
|
|
(1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >>
|
|
(BASIS_SHIFT - RECON_SHIFT));
|
|
int w = weight[i];
|
|
b >>= RECON_SHIFT;
|
|
av_assert2(-512 < b && b < 512);
|
|
|
|
sum += (w * b) * (w * b) >> 4;
|
|
}
|
|
return sum >> 2;
|
|
}
|
|
|
|
static void add_8x8basis_c(int16_t rem[64], const int16_t basis[64], int scale)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < 8 * 8; i++)
|
|
rem[i] += (basis[i] * scale +
|
|
(1 << (BASIS_SHIFT - RECON_SHIFT - 1))) >>
|
|
(BASIS_SHIFT - RECON_SHIFT);
|
|
}
|
|
|
|
static int pix_sum_c(const uint8_t *pix, int line_size)
|
|
{
|
|
int s = 0, i, j;
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
for (j = 0; j < 16; j += 8) {
|
|
s += pix[0];
|
|
s += pix[1];
|
|
s += pix[2];
|
|
s += pix[3];
|
|
s += pix[4];
|
|
s += pix[5];
|
|
s += pix[6];
|
|
s += pix[7];
|
|
pix += 8;
|
|
}
|
|
pix += line_size - 16;
|
|
}
|
|
return s;
|
|
}
|
|
|
|
static int pix_norm1_c(const uint8_t *pix, int line_size)
|
|
{
|
|
int s = 0, i, j;
|
|
const uint32_t *sq = ff_square_tab + 256;
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
for (j = 0; j < 16; j += 8) {
|
|
#if HAVE_FAST_64BIT
|
|
register uint64_t x = *(uint64_t *) pix;
|
|
s += sq[x & 0xff];
|
|
s += sq[(x >> 8) & 0xff];
|
|
s += sq[(x >> 16) & 0xff];
|
|
s += sq[(x >> 24) & 0xff];
|
|
s += sq[(x >> 32) & 0xff];
|
|
s += sq[(x >> 40) & 0xff];
|
|
s += sq[(x >> 48) & 0xff];
|
|
s += sq[(x >> 56) & 0xff];
|
|
#else
|
|
register uint32_t x = *(uint32_t *) pix;
|
|
s += sq[x & 0xff];
|
|
s += sq[(x >> 8) & 0xff];
|
|
s += sq[(x >> 16) & 0xff];
|
|
s += sq[(x >> 24) & 0xff];
|
|
x = *(uint32_t *) (pix + 4);
|
|
s += sq[x & 0xff];
|
|
s += sq[(x >> 8) & 0xff];
|
|
s += sq[(x >> 16) & 0xff];
|
|
s += sq[(x >> 24) & 0xff];
|
|
#endif
|
|
pix += 8;
|
|
}
|
|
pix += line_size - 16;
|
|
}
|
|
return s;
|
|
}
|
|
|
|
static av_always_inline void draw_edges_lr(uint8_t *ptr, int wrap, int width, int height, int w)
|
|
{
|
|
for (int i = 0; i < height; i++) {
|
|
memset(ptr - w, ptr[0], w);
|
|
memset(ptr + width, ptr[width - 1], w);
|
|
ptr += wrap;
|
|
}
|
|
}
|
|
|
|
/* draw the edges of width 'w' of an image of size width, height */
|
|
// FIXME: Check that this is OK for MPEG-4 interlaced.
|
|
static void draw_edges_8_c(uint8_t *buf, int wrap, int width, int height,
|
|
int w, int h, int sides)
|
|
{
|
|
uint8_t *last_line;
|
|
int i;
|
|
|
|
/* left and right */
|
|
if (w == 16) {
|
|
draw_edges_lr(buf, wrap, width, height, 16);
|
|
} else if (w == 8) {
|
|
draw_edges_lr(buf, wrap, width, height, 8);
|
|
} else {
|
|
av_assert1(w == 4);
|
|
draw_edges_lr(buf, wrap, width, height, 4);
|
|
}
|
|
|
|
/* top and bottom + corners */
|
|
buf -= w;
|
|
last_line = buf + (height - 1) * wrap;
|
|
if (sides & EDGE_TOP)
|
|
for (i = 0; i < h; i++)
|
|
// top
|
|
memcpy(buf - (i + 1) * wrap, buf, width + w + w);
|
|
if (sides & EDGE_BOTTOM)
|
|
for (i = 0; i < h; i++)
|
|
// bottom
|
|
memcpy(last_line + (i + 1) * wrap, last_line, width + w + w);
|
|
}
|
|
|
|
/* 2x2 -> 1x1 */
|
|
static void shrink22(uint8_t *dst, int dst_wrap,
|
|
const uint8_t *src, int src_wrap,
|
|
int width, int height)
|
|
{
|
|
int w;
|
|
const uint8_t *s1, *s2;
|
|
uint8_t *d;
|
|
|
|
for (; height > 0; height--) {
|
|
s1 = src;
|
|
s2 = s1 + src_wrap;
|
|
d = dst;
|
|
for (w = width; w >= 4; w -= 4) {
|
|
d[0] = (s1[0] + s1[1] + s2[0] + s2[1] + 2) >> 2;
|
|
d[1] = (s1[2] + s1[3] + s2[2] + s2[3] + 2) >> 2;
|
|
d[2] = (s1[4] + s1[5] + s2[4] + s2[5] + 2) >> 2;
|
|
d[3] = (s1[6] + s1[7] + s2[6] + s2[7] + 2) >> 2;
|
|
s1 += 8;
|
|
s2 += 8;
|
|
d += 4;
|
|
}
|
|
for (; w > 0; w--) {
|
|
d[0] = (s1[0] + s1[1] + s2[0] + s2[1] + 2) >> 2;
|
|
s1 += 2;
|
|
s2 += 2;
|
|
d++;
|
|
}
|
|
src += 2 * src_wrap;
|
|
dst += dst_wrap;
|
|
}
|
|
}
|
|
|
|
/* 4x4 -> 1x1 */
|
|
static void shrink44(uint8_t *dst, int dst_wrap,
|
|
const uint8_t *src, int src_wrap,
|
|
int width, int height)
|
|
{
|
|
int w;
|
|
const uint8_t *s1, *s2, *s3, *s4;
|
|
uint8_t *d;
|
|
|
|
for (; height > 0; height--) {
|
|
s1 = src;
|
|
s2 = s1 + src_wrap;
|
|
s3 = s2 + src_wrap;
|
|
s4 = s3 + src_wrap;
|
|
d = dst;
|
|
for (w = width; w > 0; w--) {
|
|
d[0] = (s1[0] + s1[1] + s1[2] + s1[3] +
|
|
s2[0] + s2[1] + s2[2] + s2[3] +
|
|
s3[0] + s3[1] + s3[2] + s3[3] +
|
|
s4[0] + s4[1] + s4[2] + s4[3] + 8) >> 4;
|
|
s1 += 4;
|
|
s2 += 4;
|
|
s3 += 4;
|
|
s4 += 4;
|
|
d++;
|
|
}
|
|
src += 4 * src_wrap;
|
|
dst += dst_wrap;
|
|
}
|
|
}
|
|
|
|
/* 8x8 -> 1x1 */
|
|
static void shrink88(uint8_t *dst, int dst_wrap,
|
|
const uint8_t *src, int src_wrap,
|
|
int width, int height)
|
|
{
|
|
int w, i;
|
|
|
|
for (; height > 0; height--) {
|
|
for(w = width;w > 0; w--) {
|
|
int tmp = 0;
|
|
for (i = 0; i < 8; i++) {
|
|
tmp += src[0] + src[1] + src[2] + src[3] +
|
|
src[4] + src[5] + src[6] + src[7];
|
|
src += src_wrap;
|
|
}
|
|
*(dst++) = (tmp + 32) >> 6;
|
|
src += 8 - 8 * src_wrap;
|
|
}
|
|
src += 8 * src_wrap - 8 * width;
|
|
dst += dst_wrap - width;
|
|
}
|
|
}
|
|
|
|
av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c,
|
|
AVCodecContext *avctx)
|
|
{
|
|
c->try_8x8basis = try_8x8basis_c;
|
|
c->add_8x8basis = add_8x8basis_c;
|
|
|
|
c->shrink[0] = av_image_copy_plane;
|
|
c->shrink[1] = shrink22;
|
|
c->shrink[2] = shrink44;
|
|
c->shrink[3] = shrink88;
|
|
|
|
c->pix_sum = pix_sum_c;
|
|
c->pix_norm1 = pix_norm1_c;
|
|
|
|
c->draw_edges = draw_edges_8_c;
|
|
|
|
#if ARCH_AARCH64
|
|
ff_mpegvideoencdsp_init_aarch64(c, avctx);
|
|
#elif ARCH_ARM
|
|
ff_mpegvideoencdsp_init_arm(c, avctx);
|
|
#elif ARCH_PPC
|
|
ff_mpegvideoencdsp_init_ppc(c, avctx);
|
|
#elif ARCH_RISCV
|
|
ff_mpegvideoencdsp_init_riscv(c, avctx);
|
|
#elif ARCH_X86
|
|
ff_mpegvideoencdsp_init_x86(c, avctx);
|
|
#elif ARCH_MIPS
|
|
ff_mpegvideoencdsp_init_mips(c, avctx);
|
|
#endif
|
|
}
|