Commit 48a69163 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit '512f3ffe'

* commit '512f3ffe':
  dsputil: Split off HuffYUV encoding bits into their own context

Conflicts:
	configure
	libavcodec/dsputil.c
	libavcodec/dsputil.h
	libavcodec/huffyuv.h
	libavcodec/huffyuvenc.c
	libavcodec/pngenc.c
	libavcodec/x86/dsputilenc_mmx.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents e2abc0d5 512f3ffe
......@@ -1806,6 +1806,7 @@ CONFIG_EXTRA="
hpeldsp
huffman
huffyuvdsp
huffyuvencdsp
intrax8
lgplv3
llviddsp
......@@ -2061,7 +2062,7 @@ h264_decoder_select="cabac golomb h264chroma h264dsp h264pred h264qpel videodsp"
h264_decoder_suggest="error_resilience"
hevc_decoder_select="cabac dsputil golomb videodsp"
huffyuv_decoder_select="dsputil huffyuvdsp llviddsp"
huffyuv_encoder_select="dsputil huffman llviddsp"
huffyuv_encoder_select="dsputil huffman huffyuvencdsp llviddsp"
iac_decoder_select="imc_decoder"
imc_decoder_select="dsputil fft mdct sinewin"
indeo3_decoder_select="hpeldsp"
......@@ -2113,7 +2114,7 @@ nuv_decoder_select="dsputil lzo"
on2avc_decoder_select="mdct"
opus_decoder_deps="swresample"
png_decoder_select="zlib"
png_encoder_select="dsputil zlib"
png_encoder_select="huffyuvencdsp zlib"
prores_decoder_select="dsputil"
prores_encoder_select="dsputil"
qcelp_decoder_select="lsp"
......@@ -2151,7 +2152,7 @@ truespeech_decoder_select="dsputil"
tscc_decoder_select="zlib"
twinvq_decoder_select="mdct lsp sinewin"
utvideo_decoder_select="dsputil"
utvideo_encoder_select="dsputil huffman"
utvideo_encoder_select="dsputil huffman huffyuvencdsp"
vble_decoder_select="huffyuvdsp"
vc1_decoder_select="error_resilience h263_decoder h264chroma h264qpel intrax8"
vc1image_decoder_select="vc1_decoder"
......
......@@ -55,6 +55,7 @@ OBJS-$(CONFIG_H264QPEL) += h264qpel.o
OBJS-$(CONFIG_HPELDSP) += hpeldsp.o
OBJS-$(CONFIG_HUFFMAN) += huffman.o
OBJS-$(CONFIG_HUFFYUVDSP) += huffyuvdsp.o
OBJS-$(CONFIG_HUFFYUVENCDSP) += huffyuvencdsp.o
OBJS-$(CONFIG_INTRAX8) += intrax8.o intrax8dsp.o
OBJS-$(CONFIG_LIBXVID) += libxvid_rc.o
OBJS-$(CONFIG_LLVIDDSP) += lossless_videodsp.o
......
......@@ -55,10 +55,6 @@ uint32_t ff_square_tab[512] = { 0, };
#include "dsputil_template.c"
#include "dsputilenc_template.c"
// 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
#define pb_7f (~0UL / 255 * 0x7f)
#define pb_80 (~0UL / 255 * 0x80)
const uint8_t ff_alternate_horizontal_scan[64] = {
0, 1, 2, 3, 8, 9, 16, 17,
10, 11, 4, 5, 6, 7, 15, 14,
......@@ -1780,55 +1776,6 @@ void ff_set_cmp(DSPContext *c, me_cmp_func *cmp, int type)
}
}
static void diff_bytes_c(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w)
{
long i;
#if !HAVE_FAST_UNALIGNED
if ((long) src2 & (sizeof(long) - 1)) {
for (i = 0; i + 7 < w; i += 8) {
dst[i + 0] = src1[i + 0] - src2[i + 0];
dst[i + 1] = src1[i + 1] - src2[i + 1];
dst[i + 2] = src1[i + 2] - src2[i + 2];
dst[i + 3] = src1[i + 3] - src2[i + 3];
dst[i + 4] = src1[i + 4] - src2[i + 4];
dst[i + 5] = src1[i + 5] - src2[i + 5];
dst[i + 6] = src1[i + 6] - src2[i + 6];
dst[i + 7] = src1[i + 7] - src2[i + 7];
}
} else
#endif
for (i = 0; i <= w - (int) sizeof(long); i += sizeof(long)) {
long a = *(long *) (src1 + i);
long b = *(long *) (src2 + i);
*(long *) (dst + i) = ((a | pb_80) - (b & pb_7f)) ^
((a ^ b ^ pb_80) & pb_80);
}
for (; i < w; i++)
dst[i + 0] = src1[i + 0] - src2[i + 0];
}
static void sub_hfyu_median_prediction_c(uint8_t *dst, const uint8_t *src1,
const uint8_t *src2, int w,
int *left, int *left_top)
{
int i;
uint8_t l, lt;
l = *left;
lt = *left_top;
for (i = 0; i < w; i++) {
const int pred = mid_pred(l, src1[i], (l + src1[i] - lt) & 0xFF);
lt = src1[i];
l = src2[i];
dst[i] = l - pred;
}
*left = l;
*left_top = lt;
}
#define BUTTERFLY2(o1, o2, i1, i2) \
o1 = (i1) + (i2); \
o2 = (i1) - (i2);
......@@ -2681,9 +2628,6 @@ av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
c->ssd_int8_vs_int16 = ssd_int8_vs_int16_c;
c->diff_bytes = diff_bytes_c;
c->sub_hfyu_median_prediction = sub_hfyu_median_prediction_c;
c->bswap_buf = bswap_buf;
c->bswap16_buf = bswap16_buf;
......
......@@ -187,19 +187,6 @@ typedef struct DSPContext {
me_cmp_func pix_abs[2][4];
/* HuffYUV specific */
void (*diff_bytes)(uint8_t *dst /* align 16 */,
const uint8_t *src1 /* align 16 */,
const uint8_t *src2 /* align 1 */,
int w);
/**
* Subtract HuffYUV's variant of median prediction.
* Note, this might read from src1[-1], src2[-1].
*/
void (*sub_hfyu_median_prediction)(uint8_t *dst, const uint8_t *src1,
const uint8_t *src2, int w,
int *left, int *left_top);
void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w);
void (*bswap16_buf)(uint16_t *dst, const uint16_t *src, int len);
......
......@@ -35,6 +35,7 @@
#include "dsputil.h"
#include "get_bits.h"
#include "huffyuvdsp.h"
#include "huffyuvencdsp.h"
#include "put_bits.h"
#include "lossless_videodsp.h"
......@@ -97,6 +98,7 @@ typedef struct HYuvContext {
unsigned int bitstream_buffer_size;
DSPContext dsp;
HuffYUVDSPContext hdsp;
HuffYUVEncDSPContext hencdsp;
LLVidDSPContext llviddsp;
} HYuvContext;
......
......@@ -31,6 +31,7 @@
#include "avcodec.h"
#include "huffyuv.h"
#include "huffman.h"
#include "huffyuvencdsp.h"
#include "internal.h"
#include "put_bits.h"
#include "libavutil/pixdesc.h"
......@@ -39,7 +40,7 @@ static inline void diff_bytes(HYuvContext *s, uint8_t *dst,
const uint8_t *src0, const uint8_t *src1, int w)
{
if (s->bps <= 8) {
s->dsp.diff_bytes(dst, src0, src1, w);
s->hencdsp.diff_bytes(dst, src0, src1, w);
} else {
s->llviddsp.diff_int16((uint16_t *)dst, (const uint16_t *)src0, (const uint16_t *)src1, s->n - 1, w);
}
......@@ -63,7 +64,7 @@ static inline int sub_left_prediction(HYuvContext *s, uint8_t *dst,
dst[i] = temp - left;
left = temp;
}
s->dsp.diff_bytes(dst + 16, src + 16, src + 15, w - 16);
s->hencdsp.diff_bytes(dst + 16, src + 16, src + 15, w - 16);
return src[w-1];
}
} else {
......@@ -115,7 +116,7 @@ static inline void sub_left_prediction_bgr32(HYuvContext *s, uint8_t *dst,
a = at;
}
s->dsp.diff_bytes(dst + 16, src + 16, src + 12, w * 4 - 16);
s->hencdsp.diff_bytes(dst + 16, src + 16, src + 12, w * 4 - 16);
*red = src[(w - 1) * 4 + R];
*green = src[(w - 1) * 4 + G];
......@@ -144,7 +145,7 @@ static inline void sub_left_prediction_rgb24(HYuvContext *s, uint8_t *dst,
b = bt;
}
s->dsp.diff_bytes(dst + 48, src + 48, src + 48 - 3, w * 3 - 48);
s->hencdsp.diff_bytes(dst + 48, src + 48, src + 48 - 3, w * 3 - 48);
*red = src[(w - 1) * 3 + 0];
*green = src[(w - 1) * 3 + 1];
......@@ -154,7 +155,7 @@ static inline void sub_left_prediction_rgb24(HYuvContext *s, uint8_t *dst,
static void sub_median_prediction(HYuvContext *s, uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top)
{
if (s->bps <= 8) {
s->dsp.sub_hfyu_median_prediction(dst, src1, src2, w , left, left_top);
s->hencdsp.sub_hfyu_median_pred(dst, src1, src2, w , left, left_top);
} else {
s->llviddsp.sub_hfyu_median_prediction_int16((uint16_t *)dst, (const uint16_t *)src1, (const uint16_t *)src2, s->n - 1, w , left, left_top);
}
......@@ -215,6 +216,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
ff_huffyuv_common_init(avctx);
ff_huffyuvencdsp_init(&s->hencdsp);
avctx->extradata = av_mallocz(3*MAX_N + 4);
if (!avctx->extradata)
......@@ -754,9 +756,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
lefttopy = p->data[0][3];
lefttopu = p->data[1][1];
lefttopv = p->data[2][1];
s->dsp.sub_hfyu_median_prediction(s->temp[0], p->data[0]+4, p->data[0] + fake_ystride + 4, width - 4 , &lefty, &lefttopy);
s->dsp.sub_hfyu_median_prediction(s->temp[1], p->data[1]+2, p->data[1] + fake_ustride + 2, width2 - 2, &leftu, &lefttopu);
s->dsp.sub_hfyu_median_prediction(s->temp[2], p->data[2]+2, p->data[2] + fake_vstride + 2, width2 - 2, &leftv, &lefttopv);
s->hencdsp.sub_hfyu_median_pred(s->temp[0], p->data[0] + 4, p->data[0] + fake_ystride + 4, width - 4, &lefty, &lefttopy);
s->hencdsp.sub_hfyu_median_pred(s->temp[1], p->data[1] + 2, p->data[1] + fake_ustride + 2, width2 - 2, &leftu, &lefttopu);
s->hencdsp.sub_hfyu_median_pred(s->temp[2], p->data[2] + 2, p->data[2] + fake_vstride + 2, width2 - 2, &leftv, &lefttopv);
encode_422_bitstream(s, 0, width - 4);
y++; cy++;
......@@ -766,7 +768,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
if (s->bitstream_bpp == 12) {
while (2 * cy > y) {
ydst = p->data[0] + p->linesize[0] * y;
s->dsp.sub_hfyu_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy);
s->hencdsp.sub_hfyu_median_pred(s->temp[0], ydst - fake_ystride, ydst, width, &lefty, &lefttopy);
encode_gray_bitstream(s, width);
y++;
}
......@@ -776,9 +778,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
udst = p->data[1] + p->linesize[1] * cy;
vdst = p->data[2] + p->linesize[2] * cy;
s->dsp.sub_hfyu_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy);
s->dsp.sub_hfyu_median_prediction(s->temp[1], udst - fake_ustride, udst, width2, &leftu, &lefttopu);
s->dsp.sub_hfyu_median_prediction(s->temp[2], vdst - fake_vstride, vdst, width2, &leftv, &lefttopv);
s->hencdsp.sub_hfyu_median_pred(s->temp[0], ydst - fake_ystride, ydst, width, &lefty, &lefttopy);
s->hencdsp.sub_hfyu_median_pred(s->temp[1], udst - fake_ustride, udst, width2, &leftu, &lefttopu);
s->hencdsp.sub_hfyu_median_pred(s->temp[2], vdst - fake_vstride, vdst, width2, &leftv, &lefttopv);
encode_422_bitstream(s, 0, width);
}
......@@ -791,7 +793,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
ydst = p->data[0] + p->linesize[0] * y;
if (s->predictor == PLANE && s->interlaced < y) {
s->dsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
s->hencdsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
lefty = sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
} else {
......@@ -807,9 +809,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
vdst = p->data[2] + p->linesize[2] * cy;
if (s->predictor == PLANE && s->interlaced < cy) {
s->dsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
s->dsp.diff_bytes(s->temp[2], udst, udst - fake_ustride, width2);
s->dsp.diff_bytes(s->temp[2] + width2, vdst, vdst - fake_vstride, width2);
s->hencdsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
s->hencdsp.diff_bytes(s->temp[2], udst, udst - fake_ustride, width2);
s->hencdsp.diff_bytes(s->temp[2] + width2, vdst, vdst - fake_vstride, width2);
lefty = sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
leftu = sub_left_prediction(s, s->temp[1], s->temp[2], width2, leftu);
......@@ -842,7 +844,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
for (y = 1; y < s->height; y++) {
uint8_t *dst = data + y*stride;
if (s->predictor == PLANE && s->interlaced < y) {
s->dsp.diff_bytes(s->temp[1], dst, dst - fake_stride, width * 4);
s->hencdsp.diff_bytes(s->temp[1], dst, dst - fake_stride, width * 4);
sub_left_prediction_bgr32(s, s->temp[0], s->temp[1], width,
&leftr, &leftg, &leftb, &lefta);
} else {
......@@ -870,8 +872,8 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
for (y = 1; y < s->height; y++) {
uint8_t *dst = data + y * stride;
if (s->predictor == PLANE && s->interlaced < y) {
s->dsp.diff_bytes(s->temp[1], dst, dst - fake_stride,
width * 3);
s->hencdsp.diff_bytes(s->temp[1], dst, dst - fake_stride,
width * 3);
sub_left_prediction_rgb24(s, s->temp[0], s->temp[1], width,
&leftr, &leftg, &leftb);
} else {
......
/*
* 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 "config.h"
#include "libavutil/attributes.h"
#include "huffyuvencdsp.h"
#include "mathops.h"
// 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
#define pb_7f (~0UL / 255 * 0x7f)
#define pb_80 (~0UL / 255 * 0x80)
static void diff_bytes_c(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w)
{
long i;
#if !HAVE_FAST_UNALIGNED
if ((long) src2 & (sizeof(long) - 1)) {
for (i = 0; i + 7 < w; i += 8) {
dst[i + 0] = src1[i + 0] - src2[i + 0];
dst[i + 1] = src1[i + 1] - src2[i + 1];
dst[i + 2] = src1[i + 2] - src2[i + 2];
dst[i + 3] = src1[i + 3] - src2[i + 3];
dst[i + 4] = src1[i + 4] - src2[i + 4];
dst[i + 5] = src1[i + 5] - src2[i + 5];
dst[i + 6] = src1[i + 6] - src2[i + 6];
dst[i + 7] = src1[i + 7] - src2[i + 7];
}
} else
#endif
for (i = 0; i <= w - (int) sizeof(long); i += sizeof(long)) {
long a = *(long *) (src1 + i);
long b = *(long *) (src2 + i);
*(long *) (dst + i) = ((a | pb_80) - (b & pb_7f)) ^
((a ^ b ^ pb_80) & pb_80);
}
for (; i < w; i++)
dst[i + 0] = src1[i + 0] - src2[i + 0];
}
static void sub_hfyu_median_pred_c(uint8_t *dst, const uint8_t *src1,
const uint8_t *src2, int w,
int *left, int *left_top)
{
int i;
uint8_t l, lt;
l = *left;
lt = *left_top;
for (i = 0; i < w; i++) {
const int pred = mid_pred(l, src1[i], (l + src1[i] - lt) & 0xFF);
lt = src1[i];
l = src2[i];
dst[i] = l - pred;
}
*left = l;
*left_top = lt;
}
av_cold void ff_huffyuvencdsp_init(HuffYUVEncDSPContext *c)
{
c->diff_bytes = diff_bytes_c;
c->sub_hfyu_median_pred = sub_hfyu_median_pred_c;
if (ARCH_X86)
ff_huffyuvencdsp_init_x86(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
*/
#ifndef AVCODEC_HUFFYUVENCDSP_H
#define AVCODEC_HUFFYUVENCDSP_H
#include <stdint.h>
typedef struct HuffYUVEncDSPContext {
void (*diff_bytes)(uint8_t *dst /* align 16 */,
const uint8_t *src1 /* align 16 */,
const uint8_t *src2 /* align 1 */,
int w);
/**
* Subtract HuffYUV's variant of median prediction.
* Note, this might read from src1[-1], src2[-1].
*/
void (*sub_hfyu_median_pred)(uint8_t *dst, const uint8_t *src1,
const uint8_t *src2, int w,
int *left, int *left_top);
} HuffYUVEncDSPContext;
void ff_huffyuvencdsp_init(HuffYUVEncDSPContext *c);
void ff_huffyuvencdsp_init_x86(HuffYUVEncDSPContext *c);
#endif /* AVCODEC_HUFFYUVENCDSP_H */
......@@ -22,7 +22,7 @@
#include "avcodec.h"
#include "internal.h"
#include "bytestream.h"
#include "dsputil.h"
#include "huffyuvencdsp.h"
#include "png.h"
#include "libavutil/avassert.h"
......@@ -34,7 +34,7 @@
typedef struct PNGEncContext {
AVClass *class;
DSPContext dsp;
HuffYUVEncDSPContext hdsp;
uint8_t *bytestream;
uint8_t *bytestream_start;
......@@ -115,7 +115,7 @@ static void sub_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top,
}
}
static void sub_left_prediction(DSPContext *dsp, uint8_t *dst, const uint8_t *src, int bpp, int size)
static void sub_left_prediction(PNGEncContext *c, uint8_t *dst, const uint8_t *src, int bpp, int size)
{
const uint8_t *src1 = src + bpp;
const uint8_t *src2 = src;
......@@ -128,10 +128,10 @@ static void sub_left_prediction(DSPContext *dsp, uint8_t *dst, const uint8_t *sr
for (x = 0; x < unaligned_w; x++)
*dst++ = *src1++ - *src2++;
size -= unaligned_w;
dsp->diff_bytes(dst, src1, src2, size);
c->hdsp.diff_bytes(dst, src1, src2, size);
}
static void png_filter_row(DSPContext *dsp, uint8_t *dst, int filter_type,
static void png_filter_row(PNGEncContext *c, uint8_t *dst, int filter_type,
uint8_t *src, uint8_t *top, int size, int bpp)
{
int i;
......@@ -141,10 +141,10 @@ static void png_filter_row(DSPContext *dsp, uint8_t *dst, int filter_type,
memcpy(dst, src, size);
break;
case PNG_FILTER_VALUE_SUB:
sub_left_prediction(dsp, dst, src, bpp, size);
sub_left_prediction(c, dst, src, bpp, size);
break;
case PNG_FILTER_VALUE_UP:
dsp->diff_bytes(dst, src, top, size);
c->hdsp.diff_bytes(dst, src, top, size);
break;
case PNG_FILTER_VALUE_AVG:
for (i = 0; i < bpp; i++)
......@@ -172,7 +172,7 @@ static uint8_t *png_choose_filter(PNGEncContext *s, uint8_t *dst,
int cost, bcost = INT_MAX;
uint8_t *buf1 = dst, *buf2 = dst + size + 16;
for (pred = 0; pred < 5; pred++) {
png_filter_row(&s->dsp, buf1 + 1, pred, src, top, size, bpp);
png_filter_row(s, buf1 + 1, pred, src, top, size, bpp);
buf1[0] = pred;
cost = 0;
for (i = 0; i <= size; i++)
......@@ -184,7 +184,7 @@ static uint8_t *png_choose_filter(PNGEncContext *s, uint8_t *dst,
}
return buf2;
} else {
png_filter_row(&s->dsp, dst + 1, pred, src, top, size, bpp);
png_filter_row(s, dst + 1, pred, src, top, size, bpp);
dst[0] = pred;
return dst;
}
......@@ -479,7 +479,7 @@ static av_cold int png_enc_init(AVCodecContext *avctx)
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
avctx->coded_frame->key_frame = 1;
ff_dsputil_init(&s->dsp, avctx);
ff_huffyuvencdsp_init(&s->hdsp);
s->filter_type = av_clip(avctx->prediction_method,
PNG_FILTER_VALUE_NONE,
......
......@@ -30,6 +30,7 @@
#include "libavutil/common.h"
#include "avcodec.h"
#include "dsputil.h"
#include "huffyuvencdsp.h"
enum {
PRED_NONE = 0,
......@@ -66,6 +67,7 @@ extern const int ff_ut_rgb_order[4];
typedef struct UtvideoContext {
AVCodecContext *avctx;
DSPContext dsp;
HuffYUVEncDSPContext hdsp;
uint32_t frame_info_size, flags, frame_info;
int planes;
......
......@@ -31,6 +31,7 @@
#include "bytestream.h"
#include "put_bits.h"
#include "dsputil.h"
#include "huffyuvencdsp.h"
#include "mathops.h"
#include "utvideo.h"
#include "huffman.h"
......@@ -109,6 +110,7 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx)
}
ff_dsputil_init(&c->dsp, avctx);
ff_huffyuvencdsp_init(&c->hdsp);
/* Check the prediction method, and error out if unsupported */
if (avctx->prediction_method < 0 || avctx->prediction_method > 4) {
......@@ -312,7 +314,7 @@ static void median_predict(UtvideoContext *c, uint8_t *src, uint8_t *dst, int st
/* Rest of the coded part uses median prediction */
for (j = 1; j < height; j++) {
c->dsp.sub_hfyu_median_prediction(dst, src - stride, src, width, &A, &B);
c->hdsp.sub_hfyu_median_pred(dst, src - stride, src, width, &A, &B);
dst += width;
src += stride;
}
......
......@@ -19,6 +19,7 @@ OBJS-$(CONFIG_HEVC_DECODER) += x86/hevcdsp_init.o
OBJS-$(CONFIG_HPELDSP) += x86/hpeldsp_init.o
OBJS-$(CONFIG_LLVIDDSP) += x86/lossless_videodsp_init.o
OBJS-$(CONFIG_HUFFYUVDSP) += x86/huffyuvdsp_init.o
OBJS-$(CONFIG_HUFFYUVENCDSP) += x86/huffyuvencdsp_mmx.o
OBJS-$(CONFIG_LPC) += x86/lpc.o
OBJS-$(CONFIG_MPEGAUDIODSP) += x86/mpegaudiodsp.o
OBJS-$(CONFIG_MPEGVIDEO) += x86/mpegvideo.o
......
......@@ -29,7 +29,6 @@
#include "libavcodec/dct.h"
#include "libavcodec/dsputil.h"
#include "libavcodec/mpegvideo.h"
#include "libavcodec/mathops.h"
#include "dsputil_x86.h"
void ff_get_pixels_mmx(int16_t *block, const uint8_t *pixels, int line_size);
......@@ -700,70 +699,6 @@ static int vsad16_mmxext(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
}
#undef SUM
static void diff_bytes_mmx(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w)
{
x86_reg i = 0;
if (w >= 16)
__asm__ volatile (
"1: \n\t"
"movq (%2, %0), %%mm0 \n\t"
"movq (%1, %0), %%mm1 \n\t"
"psubb %%mm0, %%mm1 \n\t"
"movq %%mm1, (%3, %0) \n\t"
"movq 8(%2, %0), %%mm0 \n\t"
"movq 8(%1, %0), %%mm1 \n\t"
"psubb %%mm0, %%mm1 \n\t"
"movq %%mm1, 8(%3, %0) \n\t"
"add $16, %0 \n\t"
"cmp %4, %0 \n\t"
" jb 1b \n\t"
: "+r" (i)
: "r" (src1), "r" (src2), "r" (dst), "r" ((x86_reg) w - 15));
for (; i < w; i++)
dst[i + 0] = src1[i + 0] - src2[i + 0];
}
static void sub_hfyu_median_prediction_mmxext(uint8_t *dst, const uint8_t *src1,
const uint8_t *src2, int w,
int *left, int *left_top)
{
x86_reg i = 0;
uint8_t l, lt;
__asm__ volatile (
"movq (%1, %0), %%mm0 \n\t" // LT
"psllq $8, %%mm0 \n\t"
"1: \n\t"
"movq (%1, %0), %%mm1 \n\t" // T
"movq -1(%2, %0), %%mm2 \n\t" // L
"movq (%2, %0), %%mm3 \n\t" // X
"movq %%mm2, %%mm4 \n\t" // L
"psubb %%mm0, %%mm2 \n\t"
"paddb %%mm1, %%mm2 \n\t" // L + T - LT
"movq %%mm4, %%mm5 \n\t" // L
"pmaxub %%mm1, %%mm4 \n\t" // max(T, L)
"pminub %%mm5, %%mm1 \n\t" // min(T, L)
"pminub %%mm2, %%mm4 \n\t"
"pmaxub %%mm1, %%mm4 \n\t"
"psubb %%mm4, %%mm3 \n\t" // dst - pred
"movq %%mm3, (%3, %0) \n\t"
"add $8, %0 \n\t"
"movq -1(%1, %0), %%mm0 \n\t" // LT
"cmp %4, %0 \n\t"
" jb 1b \n\t"
: "+r" (i)
: "r" (src1), "r" (src2), "r" (dst), "r" ((x86_reg) w));
l = *left;
lt = *left_top;
dst[0] = src2[0] - mid_pred(l, src1[0], (l + src1[0] - lt) & 0xFF);
*left_top = src1[w - 1];
*left = src2[w - 1];
}
static int ssd_int8_vs_int16_mmx(const int8_t *pix1, const int16_t *pix2,
int size)
......@@ -905,7 +840,6 @@ av_cold void ff_dsputilenc_init_mmx(DSPContext *c, AVCodecContext *avctx,
(dct_algo == FF_DCT_AUTO || dct_algo == FF_DCT_MMX))
c->fdct = ff_fdct_mmx;
c->diff_bytes = diff_bytes_mmx;
c->sse[0] = sse16_mmx;
c->sse[1] = sse8_mmx;
c->vsad[4] = vsad_intra16_mmx;
......@@ -938,8 +872,6 @@ av_cold void ff_dsputilenc_init_mmx(DSPContext *c, AVCodecContext *avctx,
if (!(avctx->flags & CODEC_FLAG_BITEXACT)) {
c->vsad[0] = vsad16_mmxext;
}
c->sub_hfyu_median_prediction = sub_hfyu_median_prediction_mmxext;
}
if (INLINE_SSE2(cpu_flags)) {
......
......@@ -42,7 +42,7 @@ av_cold void ff_huffyuvdsp_init_x86(HuffYUVDSPContext *c)
int cpu_flags = av_get_cpu_flags();
#if HAVE_7REGS && HAVE_INLINE_ASM
if (cpu_flags & AV_CPU_FLAG_CMOV)
if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_CMOV)
c->add_hfyu_median_pred = ff_add_hfyu_median_pred_cmov;
#endif
......
/*
* SIMD-optimized HuffYUV encoding functions
* Copyright (c) 2000, 2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
* MMX optimization by Nick Kurshev <nickols_k@mail.ru>
*
* 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 "libavutil/attributes.h"
#include "libavutil/cpu.h"
#include "libavutil/x86/asm.h"
#include "libavutil/x86/cpu.h"
#include "libavcodec/huffyuvencdsp.h"
#include "libavcodec/mathops.h"
#if HAVE_INLINE_ASM
static void diff_bytes_mmx(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w)
{
x86_reg i = 0;
if (w >= 16)
__asm__ volatile (
"1: \n\t"
"movq (%2, %0), %%mm0 \n\t"
"movq (%1, %0), %%mm1 \n\t"
"psubb %%mm0, %%mm1 \n\t"
"movq %%mm1, (%3, %0) \n\t"
"movq 8(%2, %0), %%mm0 \n\t"
"movq 8(%1, %0), %%mm1 \n\t"
"psubb %%mm0, %%mm1 \n\t"
"movq %%mm1, 8(%3, %0) \n\t"
"add $16, %0 \n\t"
"cmp %4, %0 \n\t"
" jb 1b \n\t"
: "+r" (i)
: "r" (src1), "r" (src2), "r" (dst), "r" ((x86_reg) w - 15));
for (; i < w; i++)
dst[i + 0] = src1[i + 0] - src2[i + 0];
}
static void sub_hfyu_median_pred_mmxext(uint8_t *dst, const uint8_t *src1,
const uint8_t *src2, int w,
int *left, int *left_top)
{
x86_reg i = 0;
uint8_t l, lt;
__asm__ volatile (
"movq (%1, %0), %%mm0 \n\t" // LT
"psllq $8, %%mm0 \n\t"
"1: \n\t"
"movq (%1, %0), %%mm1 \n\t" // T
"movq -1(%2, %0), %%mm2 \n\t" // L
"movq (%2, %0), %%mm3 \n\t" // X
"movq %%mm2, %%mm4 \n\t" // L
"psubb %%mm0, %%mm2 \n\t"
"paddb %%mm1, %%mm2 \n\t" // L + T - LT
"movq %%mm4, %%mm5 \n\t" // L
"pmaxub %%mm1, %%mm4 \n\t" // max(T, L)
"pminub %%mm5, %%mm1 \n\t" // min(T, L)
"pminub %%mm2, %%mm4 \n\t"
"pmaxub %%mm1, %%mm4 \n\t"
"psubb %%mm4, %%mm3 \n\t" // dst - pred
"movq %%mm3, (%3, %0) \n\t"
"add $8, %0 \n\t"
"movq -1(%1, %0), %%mm0 \n\t" // LT
"cmp %4, %0 \n\t"
" jb 1b \n\t"
: "+r" (i)
: "r" (src1), "r" (src2), "r" (dst), "r" ((x86_reg) w));
l = *left;
lt = *left_top;
dst[0] = src2[0] - mid_pred(l, src1[0], (l + src1[0] - lt) & 0xFF);
*left_top = src1[w - 1];
*left = src2[w - 1];
}
#endif /* HAVE_INLINE_ASM */
av_cold void ff_huffyuvencdsp_init_x86(HuffYUVEncDSPContext *c)
{
#if HAVE_INLINE_ASM
int cpu_flags = av_get_cpu_flags();
if (INLINE_MMX(cpu_flags)) {
c->diff_bytes = diff_bytes_mmx;
}
if (INLINE_MMXEXT(cpu_flags)) {
c->sub_hfyu_median_pred = sub_hfyu_median_pred_mmxext;
}
#endif /* HAVE_INLINE_ASM */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment