Skip to content

Commit

Permalink
Merge commit '512f3ffe9b4bb86767c2b1176554407c75fe1a5c'
Browse files Browse the repository at this point in the history
* commit '512f3ffe9b4bb86767c2b1176554407c75fe1a5c':
  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: Michael Niedermayer <[email protected]>
  • Loading branch information
michaelni committed May 27, 2014
2 parents e2abc0d + 512f3ff commit 48a6916
Show file tree
Hide file tree
Showing 15 changed files with 284 additions and 171 deletions.
7 changes: 4 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -1806,6 +1806,7 @@ CONFIG_EXTRA="
hpeldsp
huffman
huffyuvdsp
huffyuvencdsp
intrax8
lgplv3
llviddsp
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions libavcodec/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 0 additions & 56 deletions libavcodec/dsputil.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
13 changes: 0 additions & 13 deletions libavcodec/dsputil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions libavcodec/huffyuv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -97,6 +98,7 @@ typedef struct HYuvContext {
unsigned int bitstream_buffer_size;
DSPContext dsp;
HuffYUVDSPContext hdsp;
HuffYUVEncDSPContext hencdsp;
LLVidDSPContext llviddsp;
} HYuvContext;

Expand Down
40 changes: 21 additions & 19 deletions libavcodec/huffyuvenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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);
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand All @@ -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);
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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++;

Expand All @@ -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++;
}
Expand All @@ -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);
}
Expand All @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
84 changes: 84 additions & 0 deletions libavcodec/huffyuvencdsp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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);
}
Loading

0 comments on commit 48a6916

Please sign in to comment.