Hi, I removed the asserts referencing unused variables and it passed all tests. The following patch contains the changes and some improvements to the code as a single diff.
2015-07-12 10:04 GMT-03:00 Pedro Arthur <bygran...@gmail.com>: > I'll check it, I think most of these asserts are from some unused > variables which were replaced by the SwsSlice struct. > > 2015-07-11 23:51 GMT-03:00 Michael Niedermayer <mich...@niedermayer.cc>: > >> On Sat, Jul 11, 2015 at 04:57:22PM -0300, Pedro Arthur wrote: >> > Here is the full patch rebased including all previous changes. >> >> if you build ffmpeg with --assert-level=2 >> >> fails fate >> for example in fate-vsynth1-cinepak >> >> its probably best to always build with --assert-level=2 >> so you wont miss such failures >> >> --- ./tests/ref/vsynth/vsynth1-cinepak 2015-07-11 12:25:01.268257903 >> +0200 >> +++ tests/data/fate/vsynth1-cinepak 2015-07-12 04:11:06.041453781 >> +0200 >> @@ -1,4 +0,0 @@ >> -546c7c1069f9e418aa787f469b693b94 *tests/data/fate/vsynth1-cinepak.mov >> -99465 tests/data/fate/vsynth1-cinepak.mov >> -bee091c200262be3427a233a2812388c >> *tests/data/fate/vsynth1-cinepak.out.rawvideo >> -stddev: 8.46 PSNR: 29.58 MAXDIFF: 105 bytes: 7603200/ 456192 >> >> Assertion lumSrcPtr + vLumFilterSize - 1 < (const int16_t **)lumPixBuf + >> vLumBufSize * 2 failed at libswscale/swscale.c:694 >> >> there are also many other fate tests which fail with --assert-level=2 >> >> also it might make more sense to stash all these commits together >> for submission, >> if you like you could keep them seperate in your branch (could make >> sense for debug/bisect) >> >> but the commits showing the step wise development are rather hard to >> review and would be impossible to push to master git >> commits for master git should not introduce known issues that are >> fixed in later commits and should be split in selfcontained changesets >> >> a single stashed together patch should be fine and easy to generate >> >> thanks >> >> [...] >> >> -- >> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB >> >> Avoid a single point of failure, be that a person or equipment. >> >> _______________________________________________ >> ffmpeg-devel mailing list >> ffmpeg-devel@ffmpeg.org >> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel >> >> >
diff --git a/libswscale/Makefile b/libswscale/Makefile index a60b057..d876e75 100644 --- a/libswscale/Makefile +++ b/libswscale/Makefile @@ -14,6 +14,7 @@ OBJS = hscale_fast_bilinear.o \ swscale_unscaled.o \ utils.o \ yuv2rgb.o \ + slice.o \ OBJS-$(CONFIG_SHARED) += log2_tab.o diff --git a/libswscale/slice.c b/libswscale/slice.c new file mode 100644 index 0000000..bb99ac1 --- /dev/null +++ b/libswscale/slice.c @@ -0,0 +1,558 @@ +#include "swscale_internal.h" + +static void free_lines(SwsSlice *s) +{ + int i; + for (i = 0; i < 4; ++i) + { + int n = s->plane[i].available_lines; + int j; + for (j = 0; j < n; ++j) + { + av_freep(&s->plane[i].line[j]); + if (s->is_ring) + s->plane[i].line[j+n] = NULL; + } + } + s->should_free_lines = 0; +} + +static int alloc_lines(SwsSlice *s, int width) +{ + int i; + s->should_free_lines = 1; + + for (i = 0; i < 4; ++i) + { + int n = s->plane[i].available_lines; + int j; + for (j = 0; j < n; ++j) + { + s->plane[i].line[j] = av_mallocz(width); + if (!s->plane[i].line[j]) + { + free_lines(s); + return AVERROR(ENOMEM); + } + if (s->is_ring) + s->plane[i].line[j+n] = s->plane[i].line[j]; + } + } + return 1; +} + +static int alloc_slice(SwsSlice *s, enum AVPixelFormat fmt, int lumLines, int chrLines, int h_sub_sample, int v_sub_sample, int ring) +{ + int i; + int err = 0; + + int size[4] = { lumLines, + chrLines, + chrLines, + lumLines }; + + //s->width; + s->h_chr_sub_sample = h_sub_sample; + s->v_chr_sub_sample = v_sub_sample; + s->fmt = fmt; + s->is_ring = ring; + s->should_free_lines = 0; + + for (i = 0; i < 4; ++i) + { + int j; + int n = size[i] * ( ring == 0 ? 1 : 2); + s->plane[i].line = av_malloc_array(sizeof(uint8_t*), n); + if (!s->plane[i].line) + { + err = AVERROR(ENOMEM); + break; + } + for (int j = 0; j < n; ++j) + s->plane[i].line[j] = NULL; + + s->plane[i].available_lines = size[i]; + s->plane[i].sliceY = 0; + s->plane[i].sliceH = 0; + } + + if (err) + { + for (--i; i >= 0; --i) + av_freep(&s->plane[i].line); + return err; + } + return 1; +} + +static void free_slice(SwsSlice *s) +{ + int i; + if (s->should_free_lines) + free_lines(s); + for (i = 0; i < 4; ++i) + av_freep(&s->plane[i].line); +} + +int ff_rotate_slice(SwsSlice *s, int lum, int chr) +{ + int i; + if (lum) + { + for (i = 0; i < 4; i+=3) + { + int n = s->plane[i].available_lines; + int l = s->plane[i].sliceH; + + if (l+lum >= n * 2) + { + s->plane[i].sliceY += n; + s->plane[i].sliceH -= n; + } + } + } + if (chr) + { + for (i = 1; i < 3; ++i) + { + int n = s->plane[i].available_lines; + int l = s->plane[i].sliceH; + + if (l+chr >= n * 2) + { + s->plane[i].sliceY += n; + s->plane[i].sliceH -= n; + } + } + } + return 1; +} + +int ff_init_slice_from_src(SwsSlice * s, uint8_t *src[4], int stride[4], int srcW, int lumY, int lumH, int chrY, int chrH) +{ + int i = 0; + + const int start[4] = {lumY, + chrY, + chrY, + lumY}; + + const int end[4] = {lumY +lumH, + chrY + chrH, + chrY + chrH, + lumY + lumH}; + + s->width = srcW; + + for (i = 0; i < 4; ++i) + { + int j; + int lines = end[i]; + lines = s->plane[i].available_lines < lines ? s->plane[i].available_lines : lines; + + if (end[i] > s->plane[i].sliceY+s->plane[i].sliceH) + { + if (start[i] <= s->plane[i].sliceY+1) + s->plane[i].sliceY = FFMIN(start[i], s->plane[i].sliceY); + else + s->plane[i].sliceY = start[i]; + s->plane[i].sliceH = end[i] - s->plane[i].sliceY; + } + else + { + if (end[i] >= s->plane[i].sliceY) + s->plane[i].sliceH = s->plane[i].sliceY + s->plane[i].sliceH - start[i]; + else + s->plane[i].sliceH = end[i] - start[i]; + s->plane[i].sliceY = start[i]; + } + + for (j = start[i]; j < lines; j+= 1) + s->plane[i].line[j] = src[i] + (start[i] + j) * stride[i]; + + } + + return 1; +} + +static int lum_h_scale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) +{ + ScaleInstance *instance = desc->instance; + int srcW = desc->src->width; + int dstW = desc->dst->width; + int xInc = instance->xInc; + + int i; + for (i = 0; i < sliceH; ++i) + { + uint8_t ** src = desc->src->plane[0].line; + uint8_t ** dst = desc->dst->plane[0].line; + int src_pos = sliceY+i - desc->src->plane[0].sliceY; + int dst_pos = sliceY+i - desc->dst->plane[0].sliceY; + + + if (!c->hyscale_fast) { + c->hyScale(c, (int16_t*)dst[dst_pos], dstW, (const uint8_t *)src[src_pos], instance->filter, + instance->filter_pos, instance->filter_size); + } else { // fast bilinear upscale / crap downscale + c->hyscale_fast(c, (int16_t*)dst[dst_pos], dstW, src[src_pos], srcW, xInc); + } + + if (c->lumConvertRange) + c->lumConvertRange((int16_t*)dst[dst_pos], dstW); + + desc->dst->plane[0].sliceH += 1; + + if (desc->alpha) + { + src = desc->src->plane[3].line; + dst = desc->dst->plane[3].line; + + src_pos = sliceY+i - desc->src->plane[3].sliceY; + dst_pos = sliceY+i - desc->dst->plane[3].sliceY; + + desc->dst->plane[3].sliceH += 1; + + if (!c->hyscale_fast) { + c->hyScale(c, (int16_t*)dst[dst_pos], dstW, (const uint8_t *)src[src_pos], instance->filter, + instance->filter_pos, instance->filter_size); + } else { // fast bilinear upscale / crap downscale + c->hyscale_fast(c, (int16_t*)dst[dst_pos], dstW, src[src_pos], srcW, xInc); + } + } + } + + return 1; +} + +static int lum_convert(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) +{ + int srcW = desc->src->width; + ConvertInstance * instance = desc->instance; + uint32_t * pal = instance->pal; + + desc->dst->plane[0].sliceY = sliceY; + desc->dst->plane[0].sliceH = sliceH; + desc->dst->plane[3].sliceY = sliceY; + desc->dst->plane[3].sliceH = sliceH; + + int i; + for (i = 0; i < sliceH; ++i) + { + int sp0 = sliceY+i - desc->src->plane[0].sliceY; + int sp1 = ((sliceY+i) >> desc->src->v_chr_sub_sample) - desc->src->plane[1].sliceY; + const uint8_t * src[4] = { desc->src->plane[0].line[sp0], + desc->src->plane[1].line[sp1], + desc->src->plane[2].line[sp1], + desc->src->plane[3].line[sp0]}; + uint8_t * dst = desc->dst->plane[0].line[i]; + + if (c->lumToYV12) { + c->lumToYV12(dst, src[0], src[1], src[2], srcW, pal); + } else if (c->readLumPlanar) { + c->readLumPlanar(dst, src, srcW, c->input_rgb2yuv_table); + } + + + if (desc->alpha) + { + dst = desc->dst->plane[3].line[i]; + if (c->alpToYV12) { + c->alpToYV12(dst, src[3], src[1], src[2], srcW, pal); + } else if (c->readAlpPlanar) { + c->readAlpPlanar(dst, src, srcW, NULL); + } + } + } + + return 1; +} + +static int init_desc_fmt_convert(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst, uint32_t *pal) +{ + ConvertInstance * li = av_malloc(sizeof(ConvertInstance)); + if (!li) + return AVERROR(ENOMEM); + li->pal = pal; + desc->instance = li; + + desc->alpha = isALPHA(src->fmt) && isALPHA(dst->fmt); + desc->src =src; + desc->dst = dst; + desc->process = &lum_convert; + + return 1; +} + + +static int init_desc_hscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, uint16_t *filter, int * filter_pos, int filter_size, int xInc) +{ + ScaleInstance *li = av_malloc(sizeof(ScaleInstance)); + if (!li) + return AVERROR(ENOMEM); + + li->filter = filter; + li->filter_pos = filter_pos; + li->filter_size = filter_size; + li->xInc = xInc; + + desc->instance = li; + + desc->alpha = isALPHA(src->fmt) && isALPHA(dst->fmt); + desc->src = src; + desc->dst = dst; + + desc->process = &lum_h_scale; + + return 1; +} + +static int chr_h_scale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) +{ + ScaleInstance *instance = desc->instance; + int srcW = FF_CEIL_RSHIFT(desc->src->width, desc->src->h_chr_sub_sample); + int dstW = FF_CEIL_RSHIFT(desc->dst->width, desc->dst->h_chr_sub_sample); + int xInc = instance->xInc; + + uint8_t ** src1 = desc->src->plane[1].line; + uint8_t ** dst1 = desc->dst->plane[1].line; + uint8_t ** src2 = desc->src->plane[2].line; + uint8_t ** dst2 = desc->dst->plane[2].line; + + int src_pos1 = sliceY - desc->src->plane[1].sliceY; + int dst_pos1 = sliceY - desc->dst->plane[1].sliceY; + + int src_pos2 = sliceY - desc->src->plane[2].sliceY; + int dst_pos2 = sliceY - desc->dst->plane[2].sliceY; + + + int i; + for (i = 0; i < sliceH; ++i) + { + if (!c->hcscale_fast) { + c->hcScale(c, (uint16_t*)dst1[dst_pos1+i], dstW, src1[src_pos1+i], instance->filter, instance->filter_pos, instance->filter_size); + c->hcScale(c, (uint16_t*)dst2[dst_pos2+i], dstW, src2[src_pos2+i], instance->filter, instance->filter_pos, instance->filter_size); + } else { // fast bilinear upscale / crap downscale + c->hcscale_fast(c, (uint16_t*)dst1[dst_pos1+i], (uint16_t*)dst2[dst_pos2+i], dstW, src1[src_pos1+i], src2[src_pos2+i], srcW, xInc); + } + + if (c->chrConvertRange) + c->chrConvertRange((uint16_t*)dst1[dst_pos1+i], (uint16_t*)dst2[dst_pos2+i], dstW); + + desc->dst->plane[1].sliceH += 1; + desc->dst->plane[2].sliceH += 1; + } + return 1; +} + +static int chr_convert(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) +{ + int srcW = FF_CEIL_RSHIFT(desc->src->width, desc->src->h_chr_sub_sample); + ConvertInstance * instance = desc->instance; + uint32_t * pal = instance->pal; + + int sp0 = (sliceY - (desc->src->plane[0].sliceY >> desc->src->v_chr_sub_sample)) << desc->src->v_chr_sub_sample; + int sp1 = sliceY - desc->src->plane[1].sliceY; + + desc->dst->plane[1].sliceY = sliceY; + desc->dst->plane[1].sliceH = sliceH; + desc->dst->plane[2].sliceY = sliceY; + desc->dst->plane[2].sliceH = sliceH; + + int i; + for (i = 0; i < sliceH; ++i) + { + const uint8_t * src[4] = { desc->src->plane[0].line[sp0+i], + desc->src->plane[1].line[sp1+i], + desc->src->plane[2].line[sp1+i], + desc->src->plane[3].line[sp0+i]}; + + uint8_t * dst1 = desc->dst->plane[1].line[i]; + uint8_t * dst2 = desc->dst->plane[2].line[i]; + if (c->chrToYV12) { + c->chrToYV12(dst1, dst2, src[0], src[1], src[2], srcW, pal); + } else if (c->readChrPlanar) { + c->readChrPlanar(dst1, dst2, src, srcW, c->input_rgb2yuv_table); + } + } + return 1; +} + +static int init_desc_cfmt_convert(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst, uint32_t *pal) +{ + ConvertInstance * li = av_malloc(sizeof(ConvertInstance)); + if (!li) + return AVERROR(ENOMEM); + li->pal = pal; + desc->instance = li; + + desc->src =src; + desc->dst = dst; + desc->process = &chr_convert; + + return 1; +} + +static int init_desc_chscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, uint16_t *filter, int * filter_pos, int filter_size, int xInc) +{ + ScaleInstance *li = av_malloc(sizeof(ScaleInstance)); + if (!li) + return AVERROR(ENOMEM); + + li->filter = filter; + li->filter_pos = filter_pos; + li->filter_size = filter_size; + li->xInc = xInc; + + desc->instance = li; + + desc->alpha = isALPHA(src->fmt) && isALPHA(dst->fmt); + desc->src = src; + desc->dst = dst; + + desc->process = &chr_h_scale; + + return 1; +} + +static void fill_ones(SwsSlice *s, int n, int is16bit) +{ + int i; + for (i = 0; i < 4; ++i) + { + int j; + int size = s->plane[i].available_lines; + for (int j = 0; j < size; ++j) + { + int k; + int end = is16bit ? n>>1: n; + + if (is16bit) + for (k = 0; k < end; ++k) + ((int32_t*)(s->plane[i].line[j]))[k] = 1<<18; + else + for (k = 0; k < end; ++k) + ((int16_t*)(s->plane[i].line[j]))[k] = 1<<14; + } + } +} + +static int no_chr_scale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH) +{ + desc->dst->plane[1].sliceY = sliceY + sliceH - desc->dst->plane[1].available_lines; + desc->dst->plane[1].sliceH = desc->dst->plane[1].available_lines; + desc->dst->plane[2].sliceY = sliceY + sliceH - desc->dst->plane[2].available_lines; + desc->dst->plane[2].sliceH = desc->dst->plane[2].available_lines; + return 0; +} + +static int init_desc_no_chr(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst) +{ + desc->src = src; + desc->dst = dst; + desc->alpha = 0; + desc->instance = NULL; + desc->process = &no_chr_scale; + return 0; +} + +int ff_init_filters(SwsContext * c) +{ + int i; + int index; + int num_ydesc; + int num_cdesc; + int need_lum_conv = c->lumToYV12 || c->readLumPlanar || c->alpToYV12 || c->readAlpPlanar; + int need_chr_conv = c->chrToYV12 || c->readChrPlanar; + int srcIdx, dstIdx; + int dst_stride = FFALIGN(c->dstW * sizeof(int16_t) + 66, 16); + + uint32_t * pal = usePal(c->srcFormat) ? c->pal_yuv : (uint32_t*)c->input_rgb2yuv_table; + + if (c->dstBpc == 16) + dst_stride <<= 1; + + num_ydesc = need_lum_conv ? 2 : 1; + num_cdesc = need_chr_conv ? 2 : 1; + + c->numSlice = FFMAX(num_ydesc, num_cdesc) + 1; + c->numDesc = num_ydesc + num_cdesc; + c->descIndex[0] = num_ydesc; + c->descIndex[1] = num_ydesc + num_cdesc; + + + + c->desc = av_malloc_array(sizeof(SwsFilterDescriptor), c->numDesc); + c->slice = av_malloc_array(sizeof(SwsSlice), c->numSlice); + + + alloc_slice(&c->slice[0], c->srcFormat, c->srcH, c->chrSrcH, c->chrSrcHSubSample, c->chrSrcVSubSample, 0); + for (i = 1; i < c->numSlice-1; ++i) + { + alloc_slice(&c->slice[i], c->srcFormat, c->vLumFilterSize, c->vChrFilterSize, c->chrSrcHSubSample, c->chrSrcVSubSample, 0); + alloc_lines(&c->slice[i], FFALIGN(c->srcW*2+78, 16)); + } + alloc_slice(&c->slice[i], c->srcFormat, c->vLumFilterSize, c->vChrFilterSize, c->chrDstHSubSample, c->chrDstVSubSample, 1); + alloc_lines(&c->slice[i], dst_stride); + fill_ones(&c->slice[i], dst_stride>>1, c->dstBpc == 16); + + index = 0; + srcIdx = 0; + dstIdx = 1; + + if (need_lum_conv) + { + init_desc_fmt_convert(&c->desc[index], &c->slice[srcIdx], &c->slice[dstIdx], pal); + c->desc[index].alpha = c->alpPixBuf != 0; + ++index; + srcIdx = dstIdx; + } + + + dstIdx = FFMAX(num_ydesc, num_cdesc); + init_desc_hscale(&c->desc[index], &c->slice[index], &c->slice[dstIdx], c->hLumFilter, c->hLumFilterPos, c->hLumFilterSize, c->lumXInc); + c->desc[index].alpha = c->alpPixBuf != 0; + + + ++index; + { + srcIdx = 0; + dstIdx = 1; + if (need_chr_conv) + { + init_desc_cfmt_convert(&c->desc[index], &c->slice[srcIdx], &c->slice[dstIdx], pal); + ++index; + srcIdx = dstIdx; + } + + dstIdx = FFMAX(num_ydesc, num_cdesc); + if (c->needs_hcscale) + init_desc_chscale(&c->desc[index], &c->slice[srcIdx], &c->slice[dstIdx], c->hChrFilter, c->hChrFilterPos, c->hChrFilterSize, c->chrXInc); + else + init_desc_no_chr(&c->desc[index], &c->slice[srcIdx], &c->slice[dstIdx]); + } + + return 1; +} + +int ff_free_filters(SwsContext *c) +{ + int i; + for (i = 0; i < c->numDesc; ++i) + av_freep(&c->desc->instance); + + av_freep(&c->desc); + if (c->slice) + { + int i; + for (i = 0; i < c->numSlice; ++i) + free_slice(&c->slice[i]); + } + return 1; +} + + + + + + diff --git a/libswscale/swscale.c b/libswscale/swscale.c index 1945e1d..9f33af2 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -315,6 +315,8 @@ static av_always_inline void hcscale(SwsContext *c, int16_t *dst1, if (DEBUG_SWSCALE_BUFFERS) \ av_log(c, AV_LOG_DEBUG, __VA_ARGS__) + + static int swscale(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[]) @@ -371,6 +373,16 @@ static int swscale(SwsContext *c, const uint8_t *src[], int lastInChrBuf = c->lastInChrBuf; int perform_gamma = c->is_internal_gamma; + int numDesc = c->numDesc; + int lumStart = 0; + int lumEnd = c->descIndex[0]; + int chrStart = lumEnd; + int chrEnd = c->descIndex[1]; + SwsSlice *src_slice = &c->slice[lumStart]; + SwsSlice *dst_slice = &c->slice[c->numSlice-1]; + SwsFilterDescriptor *desc = c->desc; + int16_t **line_pool[4]; + if (!usePal(c->srcFormat)) { pal = c->input_rgb2yuv_table; @@ -439,6 +451,23 @@ static int swscale(SwsContext *c, const uint8_t *src[], } lastDstY = dstY; +#define NEW_FILTER 1 + + ff_init_slice_from_src(src_slice, (uint8_t**)src, srcStride, c->srcW, + srcSliceY, srcSliceH, + chrSrcSliceY, chrSrcSliceH); + + dst_slice->plane[0].sliceY = lastInLumBuf + 1; + dst_slice->plane[1].sliceY = lastInChrBuf + 1; + dst_slice->plane[2].sliceY = lastInChrBuf + 1; + dst_slice->plane[3].sliceY = lastInLumBuf + 1; + + dst_slice->plane[0].sliceH = + dst_slice->plane[1].sliceH = + dst_slice->plane[2].sliceH = + dst_slice->plane[3].sliceH = 0; + dst_slice->width = dstW; + for (; dstY < dstH; dstY++) { const int chrDstY = dstY >> c->chrDstVSubSample; uint8_t *dest[4] = { @@ -460,12 +489,23 @@ static int swscale(SwsContext *c, const uint8_t *src[], int lastLumSrcY2 = FFMIN(c->srcH, firstLumSrcY2 + vLumFilterSize) - 1; int lastChrSrcY = FFMIN(c->chrSrcH, firstChrSrcY + vChrFilterSize) - 1; int enough_lines; + int i; // handle holes (FAST_BILINEAR & weird filters) - if (firstLumSrcY > lastInLumBuf) + if (firstLumSrcY > lastInLumBuf) { lastInLumBuf = firstLumSrcY - 1; - if (firstChrSrcY > lastInChrBuf) + dst_slice->plane[0].sliceY = lastInLumBuf + 1; + dst_slice->plane[3].sliceY = lastInLumBuf + 1; + dst_slice->plane[0].sliceH = + dst_slice->plane[3].sliceH = 0; + } + if (firstChrSrcY > lastInChrBuf) { lastInChrBuf = firstChrSrcY - 1; + dst_slice->plane[1].sliceY = lastInChrBuf + 1; + dst_slice->plane[2].sliceY = lastInChrBuf + 1; + dst_slice->plane[1].sliceH = + dst_slice->plane[2].sliceH = 0; + } av_assert0(firstLumSrcY >= lastInLumBuf - vLumBufSize + 1); av_assert0(firstChrSrcY >= lastInChrBuf - vChrBufSize + 1); @@ -486,6 +526,20 @@ static int swscale(SwsContext *c, const uint8_t *src[], lastLumSrcY, lastChrSrcY); } +#if NEW_FILTER + ff_rotate_slice(dst_slice, lastLumSrcY - lastInLumBuf, lastChrSrcY - lastInChrBuf); + + for (i = lumStart; i < lumEnd; ++i) + desc[i].process(c, &desc[i], lastInLumBuf + 1, lastLumSrcY - lastInLumBuf); + lumBufIndex += lastLumSrcY - lastInLumBuf; + lastInLumBuf = lastLumSrcY; + + for (i = chrStart; i < chrEnd; ++i) + desc[i].process(c, &desc[i], lastInChrBuf + 1, lastChrSrcY - lastInChrBuf); + chrBufIndex += lastChrSrcY - lastInChrBuf; + lastInChrBuf = lastChrSrcY; + +#else // Do horizontal scaling while (lastInLumBuf < lastLumSrcY) { const uint8_t *src1[4] = { @@ -494,13 +548,14 @@ static int swscale(SwsContext *c, const uint8_t *src[], src[2] + (lastInLumBuf + 1 - srcSliceY) * srcStride[2], src[3] + (lastInLumBuf + 1 - srcSliceY) * srcStride[3], }; + lumBufIndex++; av_assert0(lumBufIndex < 2 * vLumBufSize); av_assert0(lastInLumBuf + 1 - srcSliceY < srcSliceH); av_assert0(lastInLumBuf + 1 - srcSliceY >= 0); - if (perform_gamma) - gamma_convert((uint8_t **)src1, srcW, c->inv_gamma); + //if (perform_gamma) + // gamma_convert((uint8_t **)src1, srcW, c->inv_gamma); hyscale(c, lumPixBuf[lumBufIndex], dstW, src1, srcW, lumXInc, hLumFilter, hLumFilterPos, hLumFilterSize, @@ -520,12 +575,12 @@ static int swscale(SwsContext *c, const uint8_t *src[], src[2] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[2], src[3] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[3], }; + chrBufIndex++; av_assert0(chrBufIndex < 2 * vChrBufSize); av_assert0(lastInChrBuf + 1 - chrSrcSliceY < (chrSrcSliceH)); av_assert0(lastInChrBuf + 1 - chrSrcSliceY >= 0); // FIXME replace parameters through context struct (some at least) - if (c->needs_hcscale) hcscale(c, chrUPixBuf[chrBufIndex], chrVPixBuf[chrBufIndex], chrDstW, src1, chrSrcW, chrXInc, @@ -535,6 +590,7 @@ static int swscale(SwsContext *c, const uint8_t *src[], DEBUG_BUFFERS("\t\tchrBufIndex %d: lastInChrBuf: %d\n", chrBufIndex, lastInChrBuf); } +#endif // wrap buf index around to stay inside the ring buffer if (lumBufIndex >= vLumBufSize) lumBufIndex -= vLumBufSize; @@ -560,11 +616,23 @@ static int swscale(SwsContext *c, const uint8_t *src[], } { + +#if NEW_FILTER + const int16_t **lumSrcPtr = (const int16_t **)(void*) dst_slice->plane[0].line + dst_slice->plane[0].sliceH - vLumFilterSize; + const int16_t **chrUSrcPtr = (const int16_t **)(void*) dst_slice->plane[1].line + dst_slice->plane[1].sliceH - vChrFilterSize; + const int16_t **chrVSrcPtr = (const int16_t **)(void*) dst_slice->plane[2].line + dst_slice->plane[2].sliceH - vChrFilterSize; + const int16_t **alpSrcPtr = (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? + (const int16_t **)(void*) dst_slice->plane[3].line + dst_slice->plane[3].sliceH - vLumFilterSize : NULL; +#else const int16_t **lumSrcPtr = (const int16_t **)(void*) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize; const int16_t **chrUSrcPtr = (const int16_t **)(void*) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize; const int16_t **chrVSrcPtr = (const int16_t **)(void*) chrVPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize; const int16_t **alpSrcPtr = (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **)(void*) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL; +#endif + + + int16_t *vLumFilter = c->vLumFilter; int16_t *vChrFilter = c->vChrFilter; @@ -629,8 +697,10 @@ static int swscale(SwsContext *c, const uint8_t *src[], } } } else if (yuv2packedX) { +#if !NEW_FILTER av_assert1(lumSrcPtr + vLumFilterSize - 1 < (const int16_t **)lumPixBuf + vLumBufSize * 2); av_assert1(chrUSrcPtr + vChrFilterSize - 1 < (const int16_t **)chrUPixBuf + vChrBufSize * 2); +#endif if (c->yuv2packed1 && vLumFilterSize == 1 && vChrFilterSize <= 2) { // unscaled RGB int chrAlpha = vChrFilterSize == 1 ? 0 : vChrFilter[2 * dstY + 1]; @@ -663,8 +733,8 @@ static int swscale(SwsContext *c, const uint8_t *src[], chrUSrcPtr, chrVSrcPtr, vChrFilterSize, alpSrcPtr, dest, dstW, dstY); } - if (perform_gamma) - gamma_convert(dest, dstW, c->gamma); + //if (perform_gamma) + // gamma_convert(dest, dstW, c->gamma); } } if (isPlanar(dstFormat) && isALPHA(dstFormat) && !alpPixBuf) { @@ -763,6 +833,8 @@ SwsFunc ff_getSwsFunc(SwsContext *c) if (ARCH_X86) ff_sws_init_swscale_x86(c); + ff_init_filters(c); + return swscale; } @@ -1151,4 +1223,3 @@ int attribute_align_arg sws_scale(struct SwsContext *c, av_free(rgb0_tmp); return ret; } - diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index 2299aa5..82713fd 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -269,6 +269,9 @@ typedef void (*yuv2anyX_fn)(struct SwsContext *c, const int16_t *lumFilter, const int16_t **alpSrc, uint8_t **dest, int dstW, int y); +struct SwsSlice; +struct SwsFilterDescriptor; + /* This struct should be aligned on at least a 32-byte boundary. */ typedef struct SwsContext { /** @@ -319,6 +322,12 @@ typedef struct SwsContext { uint16_t *gamma; uint16_t *inv_gamma; + int numDesc; + int descIndex[2]; + int numSlice; + struct SwsSlice *slice; + struct SwsFilterDescriptor *desc; + uint32_t pal_yuv[256]; uint32_t pal_rgb[256]; @@ -908,4 +917,55 @@ static inline void fillPlane16(uint8_t *plane, int stride, int width, int height } } +#define MAX_SLICE_PLANES 4 + +typedef struct SwsPlane +{ + int available_lines; + int sliceY; + int sliceH; + uint8_t **line; +} SwsPlane; + +typedef struct SwsSlice +{ + int width; + int h_chr_sub_sample; + int v_chr_sub_sample; + int is_ring; + int should_free_lines; + enum AVPixelFormat fmt; + SwsPlane plane[MAX_SLICE_PLANES]; +} SwsSlice; + +typedef struct SwsFilterDescriptor +{ + SwsSlice * src; + SwsSlice * dst; + + int alpha; + void * instance; + + int (*process)(SwsContext*, struct SwsFilterDescriptor*, int, int); +} SwsFilterDescriptor; + +typedef struct ConvertInstance +{ + uint32_t * pal; +} ConvertInstance; + +typedef struct ScaleInstance +{ + uint16_t * filter; + int * filter_pos; + int filter_size; + int xInc; +} ScaleInstance; + +int ff_init_slice_from_src(SwsSlice * s, uint8_t *src[4], int stride[4], int srcW, int lumY, int lumH, int chrY, int chrH); +int ff_init_slice_from_lp(SwsSlice *s, uint8_t ***linesPool, int dstW, int lumY, int lumH, int chrY, int chrH); +int ff_init_filters(SwsContext *c); +int ff_free_filters(SwsContext *c); +int ff_rotate_slice(SwsSlice *s, int lum, int chr); + #endif /* SWSCALE_SWSCALE_INTERNAL_H */ diff --git a/libswscale/utils.c b/libswscale/utils.c index 16f187a..c1b8159 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -2102,6 +2102,7 @@ void sws_freeContext(SwsContext *c) av_freep(&c->gamma); av_freep(&c->inv_gamma); + ff_free_filters(c); av_free(c); }
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel