}
}
-static inline void filter(int16_t *output, ptrdiff_t out_stride,
- int16_t *low, ptrdiff_t low_stride,
- int16_t *high, ptrdiff_t high_stride,
- int len, int clip)
-{
- int16_t tmp;
- int i;
-
- tmp = (11*low[0*low_stride] - 4*low[1*low_stride] + low[2*low_stride] + 4) >> 3;
- output[(2*0+0)*out_stride] = (tmp + high[0*high_stride]) >> 1;
- if (clip)
- output[(2*0+0)*out_stride] = av_clip_uintp2_c(output[(2*0+0)*out_stride], clip);
-
- tmp = ( 5*low[0*low_stride] + 4*low[1*low_stride] - low[2*low_stride] + 4) >> 3;
- output[(2*0+1)*out_stride] = (tmp - high[0*high_stride]) >> 1;
- if (clip)
- output[(2*0+1)*out_stride] = av_clip_uintp2_c(output[(2*0+1)*out_stride], clip);
-
- for (i = 1; i < len - 1; i++) {
- tmp = (low[(i-1)*low_stride] - low[(i+1)*low_stride] + 4) >> 3;
- output[(2*i+0)*out_stride] = (tmp + low[i*low_stride] + high[i*high_stride]) >> 1;
- if (clip)
- output[(2*i+0)*out_stride] = av_clip_uintp2_c(output[(2*i+0)*out_stride], clip);
-
- tmp = (low[(i+1)*low_stride] - low[(i-1)*low_stride] + 4) >> 3;
- output[(2*i+1)*out_stride] = (tmp + low[i*low_stride] - high[i*high_stride]) >> 1;
- if (clip)
- output[(2*i+1)*out_stride] = av_clip_uintp2_c(output[(2*i+1)*out_stride], clip);
- }
-
- tmp = ( 5*low[i*low_stride] + 4*low[(i-1)*low_stride] - low[(i-2)*low_stride] + 4) >> 3;
- output[(2*i+0)*out_stride] = (tmp + high[i*high_stride]) >> 1;
- if (clip)
- output[(2*i+0)*out_stride] = av_clip_uintp2_c(output[(2*i+0)*out_stride], clip);
-
- tmp = (11*low[i*low_stride] - 4*low[(i-1)*low_stride] + low[(i-2)*low_stride] + 4) >> 3;
- output[(2*i+1)*out_stride] = (tmp - high[i*high_stride]) >> 1;
- if (clip)
- output[(2*i+1)*out_stride] = av_clip_uintp2_c(output[(2*i+1)*out_stride], clip);
-}
-
static inline void interlaced_vertical_filter(int16_t *output, int16_t *low, int16_t *high,
int width, int linesize, int plane)
{
}
}
-static inline void inverse_temporal_filter(int16_t *output, int16_t *low, int16_t *high,
- int width)
+static inline void inverse_temporal_filter(int16_t *low, int16_t *high, int width)
{
for (int i = 0; i < width; i++) {
int even = (low[i] - high[i]) / 2;
}
}
-static void horiz_filter(int16_t *output, int16_t *low, int16_t *high,
- int width)
-{
- filter(output, 1, low, 1, high, 1, width, 0);
-}
-
-static void horiz_filter_clip(int16_t *output, int16_t *low, int16_t *high,
- int width, int clip)
-{
- filter(output, 1, low, 1, high, 1, width, clip);
-}
-
-static void horiz_filter_clip_bayer(int16_t *output, int16_t *low, int16_t *high,
- int width, int clip)
-{
- filter(output, 2, low, 1, high, 1, width, clip);
-}
-
-static void vert_filter(int16_t *output, ptrdiff_t out_stride,
- int16_t *low, ptrdiff_t low_stride,
- int16_t *high, ptrdiff_t high_stride, int len)
-{
- filter(output, out_stride, low, low_stride, high, high_stride, len, 0);
-}
-
static void free_buffers(CFHDContext *s)
{
int i, j;
return ret;
avctx->pix_fmt = s->coded_format;
+ ff_cfhddsp_init(&s->dsp, s->bpc, avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16);
+
if ((ret = av_pix_fmt_get_chroma_sub_sample(s->coded_format,
&chroma_x_shift,
&chroma_y_shift)) < 0)
int w8, h8, w4, h4, w2, h2;
int width = (i || bayer) ? s->coded_width >> chroma_x_shift : s->coded_width;
int height = (i || bayer) ? s->coded_height >> chroma_y_shift : s->coded_height;
- ptrdiff_t stride = FFALIGN(width / 8, 8) * 8;
+ ptrdiff_t stride = (FFALIGN(width / 8, 8) + 64) * 8;
if (chroma_y_shift && !bayer)
height = FFALIGN(height / 8, 2) * 8;
s->plane[i].height = height;
s->plane[i].stride = stride;
- w8 = FFALIGN(s->plane[i].width / 8, 8);
+ w8 = FFALIGN(s->plane[i].width / 8, 8) + 64;
h8 = FFALIGN(height, 8) / 8;
w4 = w8 * 2;
h4 = h8 * 2;
AVPacket *avpkt)
{
CFHDContext *s = avctx->priv_data;
+ CFHDDSPContext *dsp = &s->dsp;
GetByteContext gb;
ThreadFrame frame = { .f = data };
AVFrame *pic = data;
}
if (lowpass_height > lowpass_a_height || lowpass_width > lowpass_a_width ||
- lowpass_a_width * lowpass_a_height * sizeof(int16_t) > bytestream2_get_bytes_left(&gb)) {
+ lowpass_width * lowpass_height * sizeof(int16_t) > bytestream2_get_bytes_left(&gb)) {
av_log(avctx, AV_LOG_ERROR, "Too many lowpass coefficients\n");
ret = AVERROR(EINVAL);
goto end;
finish:
if (s->subband_num_actual != 255)
s->codebook = 0;
-
- /* Copy last line of coefficients if odd height */
- if (highpass_height & 1) {
- memcpy(&coeff_data[highpass_height * highpass_stride],
- &coeff_data[(highpass_height - 1) * highpass_stride],
- highpass_stride * sizeof(*coeff_data));
- }
}
}
for (plane = 0; plane < s->planes && !ret; plane++) {
/* level 1 */
int lowpass_height = s->plane[plane].band[0][0].height;
+ int output_stride = s->plane[plane].band[0][0].a_width;
int lowpass_width = s->plane[plane].band[0][0].width;
int highpass_stride = s->plane[plane].band[0][1].stride;
int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
low = s->plane[plane].subband[0];
high = s->plane[plane].subband[2];
output = s->plane[plane].l_h[0];
- for (i = 0; i < lowpass_width; i++) {
- vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
- low++;
- high++;
- output++;
- }
+ dsp->vert_filter(output, output_stride, low, lowpass_width, high, highpass_stride, lowpass_width, lowpass_height);
low = s->plane[plane].subband[1];
high = s->plane[plane].subband[3];
output = s->plane[plane].l_h[1];
- for (i = 0; i < lowpass_width; i++) {
- // note the stride of "low" is highpass_stride
- vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
- low++;
- high++;
- output++;
- }
+ dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
low = s->plane[plane].l_h[0];
high = s->plane[plane].l_h[1];
output = s->plane[plane].subband[0];
- for (i = 0; i < lowpass_height * 2; i++) {
- horiz_filter(output, low, high, lowpass_width);
- low += lowpass_width;
- high += lowpass_width;
- output += lowpass_width * 2;
- }
+ dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
if (s->bpc == 12) {
output = s->plane[plane].subband[0];
for (i = 0; i < lowpass_height * 2; i++) {
for (j = 0; j < lowpass_width * 2; j++)
output[j] *= 4;
- output += lowpass_width * 2;
+ output += output_stride * 2;
}
}
/* level 2 */
lowpass_height = s->plane[plane].band[1][1].height;
+ output_stride = s->plane[plane].band[1][1].a_width;
lowpass_width = s->plane[plane].band[1][1].width;
highpass_stride = s->plane[plane].band[1][1].stride;
low = s->plane[plane].subband[0];
high = s->plane[plane].subband[5];
output = s->plane[plane].l_h[3];
- for (i = 0; i < lowpass_width; i++) {
- vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
- low++;
- high++;
- output++;
- }
+ dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
low = s->plane[plane].subband[4];
high = s->plane[plane].subband[6];
output = s->plane[plane].l_h[4];
- for (i = 0; i < lowpass_width; i++) {
- vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
- low++;
- high++;
- output++;
- }
+ dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
low = s->plane[plane].l_h[3];
high = s->plane[plane].l_h[4];
output = s->plane[plane].subband[0];
- for (i = 0; i < lowpass_height * 2; i++) {
- horiz_filter(output, low, high, lowpass_width);
- low += lowpass_width;
- high += lowpass_width;
- output += lowpass_width * 2;
- }
+ dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
output = s->plane[plane].subband[0];
for (i = 0; i < lowpass_height * 2; i++) {
for (j = 0; j < lowpass_width * 2; j++)
output[j] *= 4;
- output += lowpass_width * 2;
+ output += output_stride * 2;
}
/* level 3 */
lowpass_height = s->plane[plane].band[2][1].height;
+ output_stride = s->plane[plane].band[2][1].a_width;
lowpass_width = s->plane[plane].band[2][1].width;
highpass_stride = s->plane[plane].band[2][1].stride;
low = s->plane[plane].subband[0];
high = s->plane[plane].subband[8];
output = s->plane[plane].l_h[6];
- for (i = 0; i < lowpass_width; i++) {
- vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
- low++;
- high++;
- output++;
- }
+ dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
low = s->plane[plane].subband[7];
high = s->plane[plane].subband[9];
output = s->plane[plane].l_h[7];
- for (i = 0; i < lowpass_width; i++) {
- vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
- low++;
- high++;
- output++;
- }
+ dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
dst = (int16_t *)pic->data[act_plane];
if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16) {
}
for (i = 0; i < lowpass_height * 2; i++) {
- if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16)
- horiz_filter_clip_bayer(dst, low, high, lowpass_width, s->bpc);
- else
- horiz_filter_clip(dst, low, high, lowpass_width, s->bpc);
+ dsp->horiz_filter_clip(dst, low, high, lowpass_width, s->bpc);
if (avctx->pix_fmt == AV_PIX_FMT_GBRAP12 && act_plane == 3)
process_alpha(dst, lowpass_width * 2);
- low += lowpass_width;
- high += lowpass_width;
+ low += output_stride;
+ high += output_stride;
dst += dst_linesize;
}
} else {
low = s->plane[plane].subband[0];
high = s->plane[plane].subband[7];
output = s->plane[plane].l_h[6];
- for (i = 0; i < lowpass_height; i++) {
- horiz_filter(output, low, high, lowpass_width);
- low += lowpass_width;
- high += lowpass_width;
- output += lowpass_width * 2;
- }
+ dsp->horiz_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
low = s->plane[plane].subband[8];
high = s->plane[plane].subband[9];
output = s->plane[plane].l_h[7];
- for (i = 0; i < lowpass_height; i++) {
- horiz_filter(output, low, high, lowpass_width);
- low += lowpass_width;
- high += lowpass_width;
- output += lowpass_width * 2;
- }
+ dsp->horiz_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
dst = (int16_t *)pic->data[act_plane];
low = s->plane[plane].l_h[6];
high = s->plane[plane].l_h[7];
for (i = 0; i < lowpass_height; i++) {
interlaced_vertical_filter(dst, low, high, lowpass_width * 2, pic->linesize[act_plane]/2, act_plane);
- low += lowpass_width * 2;
- high += lowpass_width * 2;
+ low += output_stride * 2;
+ high += output_stride * 2;
dst += pic->linesize[act_plane];
}
}
} else if (s->transform_type == 2 && (avctx->internal->is_copy || s->frame_index == 1 || s->sample_type != 1)) {
for (plane = 0; plane < s->planes && !ret; plane++) {
int lowpass_height = s->plane[plane].band[0][0].height;
+ int output_stride = s->plane[plane].band[0][0].a_width;
int lowpass_width = s->plane[plane].band[0][0].width;
int highpass_stride = s->plane[plane].band[0][1].stride;
int act_plane = plane == 1 ? 2 : plane == 2 ? 1 : plane;
low = s->plane[plane].subband[0];
high = s->plane[plane].subband[2];
output = s->plane[plane].l_h[0];
- for (i = 0; i < lowpass_width; i++) {
- vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
- low++;
- high++;
- output++;
- }
+ dsp->vert_filter(output, output_stride, low, lowpass_width, high, highpass_stride, lowpass_width, lowpass_height);
low = s->plane[plane].subband[1];
high = s->plane[plane].subband[3];
output = s->plane[plane].l_h[1];
- for (i = 0; i < lowpass_width; i++) {
- vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
- low++;
- high++;
- output++;
- }
+ dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
low = s->plane[plane].l_h[0];
high = s->plane[plane].l_h[1];
output = s->plane[plane].l_h[7];
- for (i = 0; i < lowpass_height * 2; i++) {
- horiz_filter(output, low, high, lowpass_width);
- low += lowpass_width;
- high += lowpass_width;
- output += lowpass_width * 2;
- }
+ dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
if (s->bpc == 12) {
output = s->plane[plane].l_h[7];
for (i = 0; i < lowpass_height * 2; i++) {
for (j = 0; j < lowpass_width * 2; j++)
output[j] *= 4;
- output += lowpass_width * 2;
+ output += output_stride * 2;
}
}
lowpass_height = s->plane[plane].band[1][1].height;
+ output_stride = s->plane[plane].band[1][1].a_width;
lowpass_width = s->plane[plane].band[1][1].width;
highpass_stride = s->plane[plane].band[1][1].stride;
low = s->plane[plane].l_h[7];
high = s->plane[plane].subband[5];
output = s->plane[plane].l_h[3];
- for (i = 0; i < lowpass_width; i++) {
- vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
- low++;
- high++;
- output++;
- }
+ dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
low = s->plane[plane].subband[4];
high = s->plane[plane].subband[6];
output = s->plane[plane].l_h[4];
- for (i = 0; i < lowpass_width; i++) {
- vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
- low++;
- high++;
- output++;
- }
+ dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
low = s->plane[plane].l_h[3];
high = s->plane[plane].l_h[4];
output = s->plane[plane].l_h[7];
- for (i = 0; i < lowpass_height * 2; i++) {
- horiz_filter(output, low, high, lowpass_width);
- low += lowpass_width;
- high += lowpass_width;
- output += lowpass_width * 2;
- }
+ dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
output = s->plane[plane].l_h[7];
for (i = 0; i < lowpass_height * 2; i++) {
for (j = 0; j < lowpass_width * 2; j++)
output[j] *= 4;
- output += lowpass_width * 2;
+ output += output_stride * 2;
}
low = s->plane[plane].subband[7];
high = s->plane[plane].subband[9];
output = s->plane[plane].l_h[3];
- for (i = 0; i < lowpass_width; i++) {
- vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
- low++;
- high++;
- output++;
- }
+ dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
low = s->plane[plane].subband[8];
high = s->plane[plane].subband[10];
output = s->plane[plane].l_h[4];
- for (i = 0; i < lowpass_width; i++) {
- vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
- low++;
- high++;
- output++;
- }
+ dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
low = s->plane[plane].l_h[3];
high = s->plane[plane].l_h[4];
output = s->plane[plane].l_h[9];
- for (i = 0; i < lowpass_height * 2; i++) {
- horiz_filter(output, low, high, lowpass_width);
- low += lowpass_width;
- high += lowpass_width;
- output += lowpass_width * 2;
- }
+ dsp->horiz_filter(output, output_stride, low, output_stride, high, output_stride, lowpass_width, lowpass_height * 2);
lowpass_height = s->plane[plane].band[4][1].height;
+ output_stride = s->plane[plane].band[4][1].a_width;
lowpass_width = s->plane[plane].band[4][1].width;
highpass_stride = s->plane[plane].band[4][1].stride;
av_log(avctx, AV_LOG_DEBUG, "temporal level %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride);
high = s->plane[plane].l_h[9];
output = s->plane[plane].l_h[7];
for (i = 0; i < lowpass_height; i++) {
- inverse_temporal_filter(output, low, high, lowpass_width);
- low += lowpass_width;
- high += lowpass_width;
+ inverse_temporal_filter(low, high, lowpass_width);
+ low += output_stride;
+ high += output_stride;
}
if (s->progressive) {
low = s->plane[plane].l_h[7];
high = s->plane[plane].subband[15];
output = s->plane[plane].l_h[6];
- for (i = 0; i < lowpass_width; i++) {
- vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
- low++;
- high++;
- output++;
- }
+ dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
low = s->plane[plane].subband[14];
high = s->plane[plane].subband[16];
output = s->plane[plane].l_h[7];
- for (i = 0; i < lowpass_width; i++) {
- vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
- low++;
- high++;
- output++;
- }
+ dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
low = s->plane[plane].l_h[9];
high = s->plane[plane].subband[12];
output = s->plane[plane].l_h[8];
- for (i = 0; i < lowpass_width; i++) {
- vert_filter(output, lowpass_width, low, lowpass_width, high, highpass_stride, lowpass_height);
- low++;
- high++;
- output++;
- }
+ dsp->vert_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
low = s->plane[plane].subband[11];
high = s->plane[plane].subband[13];
output = s->plane[plane].l_h[9];
- for (i = 0; i < lowpass_width; i++) {
- vert_filter(output, lowpass_width, low, highpass_stride, high, highpass_stride, lowpass_height);
- low++;
- high++;
- output++;
- }
+ dsp->vert_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
if (s->sample_type == 1)
continue;
low = s->plane[plane].l_h[6];
high = s->plane[plane].l_h[7];
for (i = 0; i < lowpass_height * 2; i++) {
- if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16)
- horiz_filter_clip_bayer(dst, low, high, lowpass_width, s->bpc);
- else
- horiz_filter_clip(dst, low, high, lowpass_width, s->bpc);
- low += lowpass_width;
- high += lowpass_width;
+ dsp->horiz_filter_clip(dst, low, high, lowpass_width, s->bpc);
+ low += output_stride;
+ high += output_stride;
dst += dst_linesize;
}
} else {
low = s->plane[plane].l_h[7];
high = s->plane[plane].subband[14];
output = s->plane[plane].l_h[6];
- for (i = 0; i < lowpass_height; i++) {
- horiz_filter(output, low, high, lowpass_width);
- low += lowpass_width;
- high += lowpass_width;
- output += lowpass_width * 2;
- }
+ dsp->horiz_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
low = s->plane[plane].subband[15];
high = s->plane[plane].subband[16];
output = s->plane[plane].l_h[7];
- for (i = 0; i < lowpass_height; i++) {
- horiz_filter(output, low, high, lowpass_width);
- low += lowpass_width;
- high += lowpass_width;
- output += lowpass_width * 2;
- }
+ dsp->horiz_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
low = s->plane[plane].l_h[9];
high = s->plane[plane].subband[11];
output = s->plane[plane].l_h[8];
- for (i = 0; i < lowpass_height; i++) {
- horiz_filter(output, low, high, lowpass_width);
- low += lowpass_width;
- high += lowpass_width;
- output += lowpass_width * 2;
- }
+ dsp->horiz_filter(output, output_stride, low, output_stride, high, highpass_stride, lowpass_width, lowpass_height);
low = s->plane[plane].subband[12];
high = s->plane[plane].subband[13];
output = s->plane[plane].l_h[9];
- for (i = 0; i < lowpass_height; i++) {
- horiz_filter(output, low, high, lowpass_width);
- low += lowpass_width;
- high += lowpass_width;
- output += lowpass_width * 2;
- }
+ dsp->horiz_filter(output, output_stride, low, highpass_stride, high, highpass_stride, lowpass_width, lowpass_height);
if (s->sample_type == 1)
continue;
high = s->plane[plane].l_h[7];
for (i = 0; i < lowpass_height; i++) {
interlaced_vertical_filter(dst, low, high, lowpass_width * 2, pic->linesize[act_plane]/2, act_plane);
- low += lowpass_width * 2;
- high += lowpass_width * 2;
+ low += output_stride * 2;
+ high += output_stride * 2;
dst += pic->linesize[act_plane];
}
}
if (s->transform_type == 2 && s->sample_type == 1) {
int16_t *low, *high, *dst;
- int lowpass_height, lowpass_width, highpass_stride;
+ int output_stride, lowpass_height, lowpass_width, highpass_stride;
ptrdiff_t dst_linesize;
for (plane = 0; plane < s->planes; plane++) {
}
lowpass_height = s->plane[plane].band[4][1].height;
+ output_stride = s->plane[plane].band[4][1].a_width;
lowpass_width = s->plane[plane].band[4][1].width;
highpass_stride = s->plane[plane].band[4][1].stride;
}
for (i = 0; i < lowpass_height * 2; i++) {
- if (avctx->pix_fmt == AV_PIX_FMT_BAYER_RGGB16)
- horiz_filter_clip_bayer(dst, low, high, lowpass_width, s->bpc);
- else
- horiz_filter_clip(dst, low, high, lowpass_width, s->bpc);
- low += lowpass_width;
- high += lowpass_width;
+ dsp->horiz_filter_clip(dst, low, high, lowpass_width, s->bpc);
+ low += output_stride;
+ high += output_stride;
dst += dst_linesize;
}
} else {
high = s->plane[plane].l_h[9];
for (i = 0; i < lowpass_height; i++) {
interlaced_vertical_filter(dst, low, high, lowpass_width * 2, pic->linesize[act_plane]/2, act_plane);
- low += lowpass_width * 2;
- high += lowpass_width * 2;
+ low += output_stride * 2;
+ high += output_stride * 2;
dst += pic->linesize[act_plane];
}
}
--- /dev/null
+;******************************************************************************
+;* x86-optimized functions for the CFHD decoder
+;* Copyright (c) 2020 Paul B Mahol
+;*
+;* 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/x86/x86util.asm"
+
+SECTION_RODATA
+
+factor_p1_n1: dw 1, -1, 1, -1, 1, -1, 1, -1,
+factor_n1_p1: dw -1, 1, -1, 1, -1, 1, -1, 1,
+factor_p11_n4: dw 11, -4, 11, -4, 11, -4, 11, -4,
+factor_p5_p4: dw 5, 4, 5, 4, 5, 4, 5, 4,
+pd_4: times 4 dd 4
+pw_1: times 8 dw 1
+pw_0: times 8 dw 0
+pw_1023: times 8 dw 1023
+pw_4095: times 8 dw 4095
+
+SECTION .text
+
+%macro CFHD_HORIZ_FILTER 1
+%if %1 == 1023
+cglobal cfhd_horiz_filter_clip10, 5, 6, 8 + 4 * ARCH_X86_64, output, low, high, width, bpc
+ DEFINE_ARGS output, low, high, width, x, temp
+ shl widthd, 1
+%define ostrideq widthq
+%define lwidthq widthq
+%define hwidthq widthq
+%elif %1 == 4095
+cglobal cfhd_horiz_filter_clip12, 5, 6, 8 + 4 * ARCH_X86_64, output, low, high, width, bpc
+ DEFINE_ARGS output, low, high, width, x, temp
+ shl widthd, 1
+%define ostrideq widthq
+%define lwidthq widthq
+%define hwidthq widthq
+%else
+%if ARCH_X86_64
+cglobal cfhd_horiz_filter, 11, 11, 12, output, ostride, low, lwidth, high, hwidth, width, height
+DEFINE_ARGS output, ostride, low, lwidth, high, hwidth, width, height, x, y, temp
+ shl ostrided, 1
+ shl lwidthd, 1
+ shl hwidthd, 1
+ shl widthd, 1
+
+ mov yq, heightq
+ neg yq
+%else
+cglobal cfhd_horiz_filter, 7, 7, 8, output, x, low, y, high, temp, width, height
+ shl xd, 1
+ shl yd, 1
+ shl tempd, 1
+ shl widthd, 1
+
+ mov xmp, xq
+ mov ymp, yq
+ mov tempmp, tempq
+
+ mov yd, r7m
+ neg yq
+
+%define ostrideq xm
+%define lwidthq ym
+%define hwidthq tempm
+%endif
+%endif
+
+%if ARCH_X86_64
+ mova m8, [factor_p1_n1]
+ mova m9, [factor_n1_p1]
+ mova m10, [pw_1]
+ mova m11, [pd_4]
+%endif
+
+%if %1 == 0
+.looph:
+%endif
+ movsx xq, word [lowq]
+ imul xq, 11
+
+ movsx tempq, word [lowq + 2]
+ imul tempq, -4
+ add tempq, xq
+
+ movsx xq, word [lowq + 4]
+ add tempq, xq
+ add tempq, 4
+ sar tempq, 3
+
+ movsx xq, word [highq]
+ add tempq, xq
+ sar tempq, 1
+
+%if %1
+ movd xm0, tempd
+ CLIPW m0, [pw_0], [pw_%1]
+ pextrw tempd, xm0, 0
+%endif
+ mov word [outputq], tempw
+
+ movsx xq, word [lowq]
+ imul xq, 5
+
+ movsx tempq, word [lowq + 2]
+ imul tempq, 4
+ add tempq, xq
+
+ movsx xq, word [lowq + 4]
+ sub tempq, xq
+ add tempq, 4
+ sar tempq, 3
+
+ movsx xq, word [highq]
+ sub tempq, xq
+ sar tempq, 1
+
+%if %1
+ movd xm0, tempd
+ CLIPW m0, [pw_0], [pw_%1]
+ pextrw tempd, xm0, 0
+%endif
+ mov word [outputq + 2], tempw
+
+ mov xq, 0
+
+.loop:
+ movu m4, [lowq + xq]
+ movu m1, [lowq + xq + 4]
+
+ mova m5, m4
+ punpcklwd m4, m1
+ punpckhwd m5, m1
+
+ mova m6, m4
+ mova m7, m5
+
+%if ARCH_X86_64
+ pmaddwd m4, m8
+ pmaddwd m5, m8
+ pmaddwd m6, m9
+ pmaddwd m7, m9
+
+ paddd m4, m11
+ paddd m5, m11
+ paddd m6, m11
+ paddd m7, m11
+%else
+ pmaddwd m4, [factor_p1_n1]
+ pmaddwd m5, [factor_p1_n1]
+ pmaddwd m6, [factor_n1_p1]
+ pmaddwd m7, [factor_n1_p1]
+
+ paddd m4, [pd_4]
+ paddd m5, [pd_4]
+ paddd m6, [pd_4]
+ paddd m7, [pd_4]
+%endif
+
+ psrad m4, 3
+ psrad m5, 3
+ psrad m6, 3
+ psrad m7, 3
+
+ movu m2, [lowq + xq + 2]
+ movu m3, [highq + xq + 2]
+
+ mova m0, m2
+ punpcklwd m2, m3
+ punpckhwd m0, m3
+
+ mova m1, m2
+ mova m3, m0
+
+%if ARCH_X86_64
+ pmaddwd m2, m10
+ pmaddwd m0, m10
+ pmaddwd m1, m8
+ pmaddwd m3, m8
+%else
+ pmaddwd m2, [pw_1]
+ pmaddwd m0, [pw_1]
+ pmaddwd m1, [factor_p1_n1]
+ pmaddwd m3, [factor_p1_n1]
+%endif
+
+ paddd m2, m4
+ paddd m0, m5
+ paddd m1, m6
+ paddd m3, m7
+
+ psrad m2, 1
+ psrad m0, 1
+ psrad m1, 1
+ psrad m3, 1
+
+ packssdw m2, m0
+ packssdw m1, m3
+
+ mova m0, m2
+ punpcklwd m2, m1
+ punpckhwd m0, m1
+
+%if %1
+ CLIPW m2, [pw_0], [pw_%1]
+ CLIPW m0, [pw_0], [pw_%1]
+%endif
+
+ movu [outputq + xq * 2 + 4], m2
+ movu [outputq + xq * 2 + mmsize + 4], m0
+
+ add xq, mmsize
+ cmp xq, widthq
+ jl .loop
+
+ add lowq, widthq
+ add highq, widthq
+ add outputq, widthq
+ add outputq, widthq
+
+ movsx xq, word [lowq - 2]
+ imul xq, 5
+
+ movsx tempq, word [lowq - 4]
+ imul tempq, 4
+ add tempq, xq
+
+ movsx xq, word [lowq - 6]
+ sub tempq, xq
+ add tempq, 4
+ sar tempq, 3
+
+ movsx xq, word [highq - 2]
+ add tempq, xq
+ sar tempq, 1
+
+%if %1
+ movd xm0, tempd
+ CLIPW m0, [pw_0], [pw_%1]
+ pextrw tempd, xm0, 0
+%endif
+ mov word [outputq - 4], tempw
+
+ movsx xq, word [lowq - 2]
+ imul xq, 11
+
+ movsx tempq, word [lowq - 4]
+ imul tempq, -4
+ add tempq, xq
+
+ movsx xq, word [lowq - 6]
+ add tempq, xq
+ add tempq, 4
+ sar tempq, 3
+
+ movsx xq, word [highq - 2]
+ sub tempq, xq
+ sar tempq, 1
+
+%if %1
+ movd xm0, tempd
+ CLIPW m0, [pw_0], [pw_%1]
+ pextrw tempd, xm0, 0
+%endif
+ mov word [outputq - 2], tempw
+
+%if %1 == 0
+ sub lowq, widthq
+ sub highq, widthq
+ sub outputq, widthq
+ sub outputq, widthq
+
+ add lowq, lwidthq
+ add highq, hwidthq
+ add outputq, ostrideq
+ add outputq, ostrideq
+ add yq, 1
+ jl .looph
+%endif
+
+ RET
+%endmacro
+
+INIT_XMM sse2
+CFHD_HORIZ_FILTER 0
+
+INIT_XMM sse2
+CFHD_HORIZ_FILTER 1023
+
+INIT_XMM sse2
+CFHD_HORIZ_FILTER 4095
+
+INIT_XMM sse2
+%if ARCH_X86_64
+cglobal cfhd_vert_filter, 11, 11, 14, output, ostride, low, lwidth, high, hwidth, width, height
+DEFINE_ARGS output, ostride, low, lwidth, high, hwidth, width, height, x, y, pos
+ shl ostrided, 1
+ shl lwidthd, 1
+ shl hwidthd, 1
+ shl widthd, 1
+
+ dec heightq
+
+ mova m8, [factor_p1_n1]
+ mova m9, [factor_n1_p1]
+ mova m10, [pw_1]
+ mova m11, [pd_4]
+ mova m12, [factor_p11_n4]
+ mova m13, [factor_p5_p4]
+%else
+cglobal cfhd_vert_filter, 7, 7, 8, output, x, low, y, high, pos, width, height
+ shl xd, 1
+ shl yd, 1
+ shl posd, 1
+ shl widthd, 1
+
+ mov xmp, xq
+ mov ymp, yq
+ mov posmp, posq
+
+ mov xq, r7m
+ dec xq
+ mov widthmp, xq
+
+%define ostrideq xm
+%define lwidthq ym
+%define hwidthq posm
+%define heightq widthm
+
+%endif
+
+ xor xq, xq
+.loopw:
+ xor yq, yq
+
+ mov posq, xq
+ movu m0, [lowq + posq]
+ add posq, lwidthq
+ movu m1, [lowq + posq]
+ mova m2, m0
+ punpcklwd m0, m1
+ punpckhwd m2, m1
+
+%if ARCH_X86_64
+ pmaddwd m0, m12
+ pmaddwd m2, m12
+%else
+ pmaddwd m0, [factor_p11_n4]
+ pmaddwd m2, [factor_p11_n4]
+%endif
+
+ pxor m4, m4
+ add posq, lwidthq
+ movu m1, [lowq + posq]
+ mova m3, m4
+ punpcklwd m4, m1
+ punpckhwd m3, m1
+
+ psrad m4, 16
+ psrad m3, 16
+
+ paddd m0, m4
+ paddd m2, m3
+
+ paddd m0, [pd_4]
+ paddd m2, [pd_4]
+
+ psrad m0, 3
+ psrad m2, 3
+
+ mov posq, xq
+ pxor m4, m4
+ movu m1, [highq + posq]
+ mova m3, m4
+ punpcklwd m4, m1
+ punpckhwd m3, m1
+
+ psrad m4, 16
+ psrad m3, 16
+
+ paddd m0, m4
+ paddd m2, m3
+
+ psrad m0, 1
+ psrad m2, 1
+
+ packssdw m0, m2
+
+ movu [outputq + posq], m0
+
+ movu m0, [lowq + posq]
+ add posq, lwidthq
+ movu m1, [lowq + posq]
+ mova m2, m0
+ punpcklwd m0, m1
+ punpckhwd m2, m1
+
+%ifdef ARCH_X86_64
+ pmaddwd m0, m13
+ pmaddwd m2, m13
+%else
+ pmaddwd m0, [factor_p5_p4]
+ pmaddwd m2, [factor_p5_p4]
+%endif
+
+ pxor m4, m4
+ add posq, lwidthq
+ movu m1, [lowq + posq]
+ mova m3, m4
+ punpcklwd m4, m1
+ punpckhwd m3, m1
+
+ psrad m4, 16
+ psrad m3, 16
+
+ psubd m0, m4
+ psubd m2, m3
+
+ paddd m0, [pd_4]
+ paddd m2, [pd_4]
+
+ psrad m0, 3
+ psrad m2, 3
+
+ mov posq, xq
+ pxor m4, m4
+ movu m1, [highq + posq]
+ mova m3, m4
+ punpcklwd m4, m1
+ punpckhwd m3, m1
+
+ psrad m4, 16
+ psrad m3, 16
+
+ psubd m0, m4
+ psubd m2, m3
+
+ psrad m0, 1
+ psrad m2, 1
+
+ packssdw m0, m2
+
+ add posq, ostrideq
+ movu [outputq + posq], m0
+
+ add yq, 1
+.looph:
+ mov posq, lwidthq
+ imul posq, yq
+ sub posq, lwidthq
+ add posq, xq
+
+ movu m4, [lowq + posq]
+
+ add posq, lwidthq
+ add posq, lwidthq
+ movu m1, [lowq + posq]
+
+ mova m5, m4
+ punpcklwd m4, m1
+ punpckhwd m5, m1
+
+ mova m6, m4
+ mova m7, m5
+
+%ifdef ARCH_X86_64
+ pmaddwd m4, m8
+ pmaddwd m5, m8
+ pmaddwd m6, m9
+ pmaddwd m7, m9
+
+ paddd m4, m11
+ paddd m5, m11
+ paddd m6, m11
+ paddd m7, m11
+%else
+ pmaddwd m4, [factor_p1_n1]
+ pmaddwd m5, [factor_p1_n1]
+ pmaddwd m6, [factor_n1_p1]
+ pmaddwd m7, [factor_n1_p1]
+
+ paddd m4, [pd_4]
+ paddd m5, [pd_4]
+ paddd m6, [pd_4]
+ paddd m7, [pd_4]
+%endif
+
+ psrad m4, 3
+ psrad m5, 3
+ psrad m6, 3
+ psrad m7, 3
+
+ sub posq, lwidthq
+ movu m0, [lowq + posq]
+
+ mov posq, hwidthq
+ imul posq, yq
+ add posq, xq
+ movu m1, [highq + posq]
+
+ mova m2, m0
+ punpcklwd m0, m1
+ punpckhwd m2, m1
+
+ mova m1, m0
+ mova m3, m2
+
+%ifdef ARCH_X86_64
+ pmaddwd m0, m10
+ pmaddwd m2, m10
+ pmaddwd m1, m8
+ pmaddwd m3, m8
+%else
+ pmaddwd m0, [pw_1]
+ pmaddwd m2, [pw_1]
+ pmaddwd m1, [factor_p1_n1]
+ pmaddwd m3, [factor_p1_n1]
+%endif
+
+ paddd m0, m4
+ paddd m2, m5
+ paddd m1, m6
+ paddd m3, m7
+
+ psrad m0, 1
+ psrad m2, 1
+ psrad m1, 1
+ psrad m3, 1
+
+ packssdw m0, m2
+ packssdw m1, m3
+
+ mov posq, ostrideq
+ imul posq, 2
+ imul posq, yq
+ add posq, xq
+
+ movu [outputq + posq], m0
+ add posq, ostrideq
+ movu [outputq + posq], m1
+
+ add yq, 1
+ cmp yq, heightq
+ jl .looph
+
+ mov posq, lwidthq
+ imul posq, yq
+ add posq, xq
+ movu m0, [lowq + posq]
+ sub posq, lwidthq
+ movu m1, [lowq + posq]
+ mova m2, m0
+ punpcklwd m0, m1
+ punpckhwd m2, m1
+
+%ifdef ARCH_X86_64
+ pmaddwd m0, m13
+ pmaddwd m2, m13
+%else
+ pmaddwd m0, [factor_p5_p4]
+ pmaddwd m2, [factor_p5_p4]
+%endif
+
+ pxor m4, m4
+ sub posq, lwidthq
+ movu m1, [lowq + posq]
+ mova m3, m4
+ punpcklwd m4, m1
+ punpckhwd m3, m1
+
+ psrad m4, 16
+ psrad m3, 16
+
+ psubd m0, m4
+ psubd m2, m3
+
+%ifdef ARCH_X86_64
+ paddd m0, m11
+ paddd m2, m11
+%else
+ paddd m0, [pd_4]
+ paddd m2, [pd_4]
+%endif
+
+ psrad m0, 3
+ psrad m2, 3
+
+ mov posq, hwidthq
+ imul posq, yq
+ add posq, xq
+ pxor m4, m4
+ movu m1, [highq + posq]
+ mova m3, m4
+ punpcklwd m4, m1
+ punpckhwd m3, m1
+
+ psrad m4, 16
+ psrad m3, 16
+
+ paddd m0, m4
+ paddd m2, m3
+
+ psrad m0, 1
+ psrad m2, 1
+
+ packssdw m0, m2
+
+ mov posq, ostrideq
+ imul posq, 2
+ imul posq, yq
+ add posq, xq
+ movu [outputq + posq], m0
+
+ mov posq, lwidthq
+ imul posq, yq
+ add posq, xq
+ movu m0, [lowq + posq]
+ sub posq, lwidthq
+ movu m1, [lowq + posq]
+ mova m2, m0
+ punpcklwd m0, m1
+ punpckhwd m2, m1
+
+%ifdef ARCH_X86_64
+ pmaddwd m0, m12
+ pmaddwd m2, m12
+%else
+ pmaddwd m0, [factor_p11_n4]
+ pmaddwd m2, [factor_p11_n4]
+%endif
+
+ pxor m4, m4
+ sub posq, lwidthq
+ movu m1, [lowq + posq]
+ mova m3, m4
+ punpcklwd m4, m1
+ punpckhwd m3, m1
+
+ psrad m4, 16
+ psrad m3, 16
+
+ paddd m0, m4
+ paddd m2, m3
+
+%ifdef ARCH_X86_64
+ paddd m0, m11
+ paddd m2, m11
+%else
+ paddd m0, [pd_4]
+ paddd m2, [pd_4]
+%endif
+
+ psrad m0, 3
+ psrad m2, 3
+
+ mov posq, hwidthq
+ imul posq, yq
+ add posq, xq
+ pxor m4, m4
+ movu m1, [highq + posq]
+ mova m3, m4
+ punpcklwd m4, m1
+ punpckhwd m3, m1
+
+ psrad m4, 16
+ psrad m3, 16
+
+ psubd m0, m4
+ psubd m2, m3
+
+ psrad m0, 1
+ psrad m2, 1
+
+ packssdw m0, m2
+
+ mov posq, ostrideq
+ imul posq, 2
+ imul posq, yq
+ add posq, ostrideq
+ add posq, xq
+ movu [outputq + posq], m0
+
+ add xq, mmsize
+ cmp xq, widthq
+ jl .loopw
+ RET