ticket #5522: interlaced frame required horizontal-temporal inverse transform. though the output is not satisfactory yet. --- libavcodec/cfhd.c | 102 ++++++++++++++++++++++++++++++++++++++++++++---------- libavcodec/cfhd.h | 3 +- 2 files changed, 85 insertions(+), 20 deletions(-)
diff --git a/libavcodec/cfhd.c b/libavcodec/cfhd.c index a064cd1599..b17c7c1dc5 100644 --- a/libavcodec/cfhd.c +++ b/libavcodec/cfhd.c @@ -50,8 +50,11 @@ enum CFHDParam { ChannelWidth = 104, ChannelHeight = 105, PrescaleShift = 109, + Progressive = 68, }; + + static av_cold int cfhd_init(AVCodecContext *avctx) { CFHDContext *s = avctx->priv_data; @@ -83,6 +86,7 @@ static void init_frame_defaults(CFHDContext *s) s->wavelet_depth = 3; s->pshift = 1; s->codebook = 0; + s->progressive = 0; init_plane_defaults(s); } @@ -137,6 +141,28 @@ static inline void filter(int16_t *output, ptrdiff_t out_stride, } } +static inline void interlaced_vertical_filter(int16_t *output, int16_t *low, int16_t *high, + int width, int linesize, int plane) +{ + int i; + int16_t even, odd; + for (i = 0; i < width; i++) { + + + even = (*low - *high)/2; + odd = (*low + *high)/2; + + if (even > 1023) even = 1023; + if (even < 0) even = 0; + if (odd > 1023) odd = 1023; + if (odd < 0) odd = 0; + + output[i] = even; + output[i + linesize] = odd; + low++; + high++; + } +} static void horiz_filter(int16_t *output, int16_t *low, int16_t *high, int width) { @@ -277,6 +303,9 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame, uint16_t data = bytestream2_get_be16(&gb); if (abs_tag8 >= 0x60 && abs_tag8 <= 0x6f) { av_log(avctx, AV_LOG_DEBUG, "large len %x\n", ((tagu & 0xff) << 16) | data); + } else if (tag == Progressive) { + av_log(avctx, AV_LOG_DEBUG, "Progressive?%"PRIu16"\n", data); + s->progressive = data; } else if (tag == ImageWidth) { av_log(avctx, AV_LOG_DEBUG, "Width %"PRIu16"\n", data); s->coded_width = data; @@ -766,36 +795,71 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame, } av_log(avctx, AV_LOG_DEBUG, "Level 3 plane %i %i %i %i\n", plane, lowpass_height, lowpass_width, highpass_stride); - + if (s->progressive) { + 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++; + } + + 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++; + } + + 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 * 2; i++) { + horiz_filter_clip(dst, low, high, lowpass_width, s->bpc); + low += lowpass_width; + high += lowpass_width; + dst += pic->linesize[act_plane] / 2; + } + } + else { + + av_log(avctx, AV_LOG_DEBUG, "interlaced frame ? %d", pic->interlaced_frame); + pic->interlaced_frame = 1; low = s->plane[plane].subband[0]; - high = s->plane[plane].subband[8]; + high = s->plane[plane].subband[7]; 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++; + for (i = 0; i < lowpass_height; i++) { + horiz_filter(output, low, high, lowpass_width); + low += lowpass_width; + high += lowpass_width; + output += lowpass_width * 2; } - low = s->plane[plane].subband[7]; + low = s->plane[plane].subband[8]; 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++; + for (i = 0; i < lowpass_height; i++) { + horiz_filter(output, low, high, lowpass_width); + low += lowpass_width; + high += lowpass_width; + output += lowpass_width * 2; } - dst = (int16_t *)pic->data[act_plane]; + 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 * 2; i++) { - horiz_filter_clip(dst, low, high, lowpass_width, s->bpc); - low += lowpass_width; - high += lowpass_width; - dst += pic->linesize[act_plane] / 2; + 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; + dst += pic->linesize[act_plane]; } + } } diff --git a/libavcodec/cfhd.h b/libavcodec/cfhd.h index 2573e750a6..f9e1c60c3b 100644 --- a/libavcodec/cfhd.h +++ b/libavcodec/cfhd.h @@ -83,7 +83,8 @@ typedef struct CFHDContext { int coded_height; int cropped_height; enum AVPixelFormat coded_format; - + int progressive; + int a_width; int a_height; int a_format; _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel