static void envelope_peak16(WaveformContext *s, AVFrame *out, int plane, int component)

{

    const int dst_linesize = out->linesize[component] / 2;

    const int bg = s->bg_color[component] * (s->size / 256);

    const int limit = s->size - 1;

    const int is_chroma = (component == 1 || component == 2);

    const int shift_w = (is_chroma ? s->desc->log2_chroma_w : 0);

    const int shift_h = (is_chroma ? s->desc->log2_chroma_h : 0);

    const int dst_h = FF_CEIL_RSHIFT(out->height, shift_h);

    const int dst_w = FF_CEIL_RSHIFT(out->width, shift_w);

    const int start = s->estart[plane];

    const int end = s->eend[plane];

    int *emax = s->emax[plane][component];

    int *emin = s->emin[plane][component];

    uint16_t *dst;

    int x, y;



    if (s->mode) {

        for (x = 0; x < dst_w; x++) {

            for (y = start; y < end && y < emin[x]; y++) {

                dst = (uint16_t *)out->data[component] + y * dst_linesize + x;

                if (dst[0] != bg) {

                    emin[x] = y;

                    break;

                }

            }

            for (y = end - 1; y >= start && y >= emax[x]; y--) {

                dst = (uint16_t *)out->data[component] + y * dst_linesize + x;

                if (dst[0] != bg) {

                    emax[x] = y;

                    break;

                }

            }

        }



        if (s->envelope == 3)

            envelope_instant16(s, out, plane, component);



        for (x = 0; x < dst_w; x++) {

            dst = (uint16_t *)out->data[component] + emin[x] * dst_linesize + x;

            dst[0] = limit;

            dst = (uint16_t *)out->data[component] + emax[x] * dst_linesize + x;

            dst[0] = limit;

        }

    } else {

        for (y = 0; y < dst_h; y++) {

            dst = (uint16_t *)out->data[component] + y * dst_linesize;

            for (x = start; x < end && x < emin[y]; x++) {

                if (dst[x] != bg) {

                    emin[y] = x;

                    break;

                }

            }

            for (x = end - 1; x >= start && x >= emax[y]; x--) {

                if (dst[x] != bg) {

                    emax[y] = x;

                    break;

                }

            }

        }



        if (s->envelope == 3)

            envelope_instant16(s, out, plane, component);



        for (y = 0; y < dst_h; y++) {

            dst = (uint16_t *)out->data[component] + y * dst_linesize + emin[y];

            dst[0] = limit;

            dst = (uint16_t *)out->data[component] + y * dst_linesize + emax[y];

            dst[0] = limit;

        }

    }

}

static void envelope_peak16(WaveformContext *s, AVFrame *out, int plane, int component)

{

    const int dst_linesize = out->linesize[component] / 2;

    const int bg = s->bg_color[component] * (s->size / 256);

    const int limit = s->size - 1;

    const int is_chroma = (component == 1 || component == 2);

    const int shift_w = (is_chroma ? s->desc->log2_chroma_w : 0);

    const int shift_h = (is_chroma ? s->desc->log2_chroma_h : 0);

    const int dst_h = FF_CEIL_RSHIFT(out->height, shift_h);

    const int dst_w = FF_CEIL_RSHIFT(out->width, shift_w);

    const int start = s->estart[plane];

    const int end = s->eend[plane];

    int *emax = s->emax[plane][component];

    int *emin = s->emin[plane][component];

    uint16_t *dst;

    int x, y;



    if (s->mode) {

        for (x = 0; x < dst_w; x++) {

            for (y = start; y < end && y < emin[x]; y++) {

                dst = (uint16_t *)out->data[component] + y * dst_linesize + x;

                if (dst[0] != bg) {

                    emin[x] = y;

                    break;

                }

            }

            for (y = end - 1; y >= start && y >= emax[x]; y--) {

                dst = (uint16_t *)out->data[component] + y * dst_linesize + x;

                if (dst[0] != bg) {

                    emax[x] = y;

                    break;

                }

            }

        }



        if (s->envelope == 3)

            envelope_instant16(s, out, plane, component);



        for (x = 0; x < dst_w; x++) {

            dst = (uint16_t *)out->data[component] + emin[x] * dst_linesize + x;

            dst[0] = limit;

            dst = (uint16_t *)out->data[component] + emax[x] * dst_linesize + x;

            dst[0] = limit;

        }

    } else {

        for (y = 0; y < dst_h; y++) {

            dst = (uint16_t *)out->data[component] + y * dst_linesize;

            for (x = start; x < end && x < emin[y]; x++) {

                if (dst[x] != bg) {

                    emin[y] = x;

                    break;

                }

            }

            for (x = end - 1; x >= start && x >= emax[y]; x--) {

                if (dst[x] != bg) {

                    emax[y] = x;

                    break;

                }

            }

        }



        if (s->envelope == 3)

            envelope_instant16(s, out, plane, component);



        for (y = 0; y < dst_h; y++) {

            dst = (uint16_t *)out->data[component] + y * dst_linesize + emin[y];

            dst[0] = limit;

            dst = (uint16_t *)out->data[component] + y * dst_linesize + emax[y];

            dst[0] = limit;

        }

    }

}

static void FUNC_0(WaveformContext *VAR_0, AVFrame *VAR_1, int VAR_2, int VAR_3)

{

    const int VAR_4 = VAR_1->linesize[VAR_3] / 2;

    const int VAR_5 = VAR_0->bg_color[VAR_3] * (VAR_0->size / 256);

    const int VAR_6 = VAR_0->size - 1;

    const int VAR_7 = (VAR_3 == 1 || VAR_3 == 2);

    const int VAR_8 = (VAR_7 ? VAR_0->desc->log2_chroma_w : 0);

    const int VAR_9 = (VAR_7 ? VAR_0->desc->log2_chroma_h : 0);

    const int VAR_10 = FF_CEIL_RSHIFT(VAR_1->height, VAR_9);

    const int VAR_11 = FF_CEIL_RSHIFT(VAR_1->width, VAR_8);

    const int VAR_12 = VAR_0->estart[VAR_2];

    const int VAR_13 = VAR_0->eend[VAR_2];

    int *VAR_14 = VAR_0->VAR_14[VAR_2][VAR_3];

    int *VAR_15 = VAR_0->VAR_15[VAR_2][VAR_3];

    uint16_t *dst;

    int VAR_16, VAR_17;



    if (VAR_0->mode) {

        for (VAR_16 = 0; VAR_16 < VAR_11; VAR_16++) {

            for (VAR_17 = VAR_12; VAR_17 < VAR_13 && VAR_17 < VAR_15[VAR_16]; VAR_17++) {

                dst = (uint16_t *)VAR_1->data[VAR_3] + VAR_17 * VAR_4 + VAR_16;

                if (dst[0] != VAR_5) {

                    VAR_15[VAR_16] = VAR_17;

                    break;

                }

            }

            for (VAR_17 = VAR_13 - 1; VAR_17 >= VAR_12 && VAR_17 >= VAR_14[VAR_16]; VAR_17--) {

                dst = (uint16_t *)VAR_1->data[VAR_3] + VAR_17 * VAR_4 + VAR_16;

                if (dst[0] != VAR_5) {

                    VAR_14[VAR_16] = VAR_17;

                    break;

                }

            }

        }



        if (VAR_0->envelope == 3)

            envelope_instant16(VAR_0, VAR_1, VAR_2, VAR_3);



        for (VAR_16 = 0; VAR_16 < VAR_11; VAR_16++) {

            dst = (uint16_t *)VAR_1->data[VAR_3] + VAR_15[VAR_16] * VAR_4 + VAR_16;

            dst[0] = VAR_6;

            dst = (uint16_t *)VAR_1->data[VAR_3] + VAR_14[VAR_16] * VAR_4 + VAR_16;

            dst[0] = VAR_6;

        }

    } else {

        for (VAR_17 = 0; VAR_17 < VAR_10; VAR_17++) {

            dst = (uint16_t *)VAR_1->data[VAR_3] + VAR_17 * VAR_4;

            for (VAR_16 = VAR_12; VAR_16 < VAR_13 && VAR_16 < VAR_15[VAR_17]; VAR_16++) {

                if (dst[VAR_16] != VAR_5) {

                    VAR_15[VAR_17] = VAR_16;

                    break;

                }

            }

            for (VAR_16 = VAR_13 - 1; VAR_16 >= VAR_12 && VAR_16 >= VAR_14[VAR_17]; VAR_16--) {

                if (dst[VAR_16] != VAR_5) {

                    VAR_14[VAR_17] = VAR_16;

                    break;

                }

            }

        }



        if (VAR_0->envelope == 3)

            envelope_instant16(VAR_0, VAR_1, VAR_2, VAR_3);



        for (VAR_17 = 0; VAR_17 < VAR_10; VAR_17++) {

            dst = (uint16_t *)VAR_1->data[VAR_3] + VAR_17 * VAR_4 + VAR_15[VAR_17];

            dst[0] = VAR_6;

            dst = (uint16_t *)VAR_1->data[VAR_3] + VAR_17 * VAR_4 + VAR_14[VAR_17];

            dst[0] = VAR_6;

        }

    }

}

static void FUNC_0(WaveformContext *VAR_0, AVFrame *VAR_1, int VAR_2, int VAR_3)
{ const int VAR_4 = VAR_1->linesize[VAR_3] / 2; const int VAR_5 = VAR_0->bg_color[VAR_3] * (VAR_0->size / 256); const int VAR_6 = VAR_0->size - 1; const int VAR_7 = (VAR_3 == 1 || VAR_3 == 2); const int VAR_8 = (VAR_7 ? VAR_0->desc->log2_chroma_w : 0); const int VAR_9 = (VAR_7 ? VAR_0->desc->log2_chroma_h : 0); const int VAR_10 = FF_CEIL_RSHIFT(VAR_1->height, VAR_9); const int VAR_11 = FF_CEIL_RSHIFT(VAR_1->width, VAR_8); const int VAR_12 = VAR_0->estart[VAR_2]; const int VAR_13 = VAR_0->eend[VAR_2]; int *VAR_14 = VAR_0->VAR_14[VAR_2][VAR_3]; int *VAR_15 = VAR_0->VAR_15[VAR_2][VAR_3]; uint16_t *dst; int VAR_16, VAR_17; if (VAR_0->mode) { for (VAR_16 = 0; VAR_16 < VAR_11; VAR_16++) { for (VAR_17 = VAR_12; VAR_17 < VAR_13 && VAR_17 < VAR_15[VAR_16]; VAR_17++) { dst = (uint16_t *)VAR_1->data[VAR_3] + VAR_17 * VAR_4 + VAR_16; if (dst[0] != VAR_5) { VAR_15[VAR_16] = VAR_17; break; } } for (VAR_17 = VAR_13 - 1; VAR_17 >= VAR_12 && VAR_17 >= VAR_14[VAR_16]; VAR_17--) { dst = (uint16_t *)VAR_1->data[VAR_3] + VAR_17 * VAR_4 + VAR_16; if (dst[0] != VAR_5) { VAR_14[VAR_16] = VAR_17; break; } } } if (VAR_0->envelope == 3)
envelope_instant16(VAR_0, VAR_1, VAR_2, VAR_3); for (VAR_16 = 0; VAR_16 < VAR_11; VAR_16++) { dst = (uint16_t *)VAR_1->data[VAR_3] + VAR_15[VAR_16] * VAR_4 + VAR_16; dst[0] = VAR_6; dst = (uint16_t *)VAR_1->data[VAR_3] + VAR_14[VAR_16] * VAR_4 + VAR_16; dst[0] = VAR_6; } } else { for (VAR_17 = 0; VAR_17 < VAR_10; VAR_17++) { dst = (uint16_t *)VAR_1->data[VAR_3] + VAR_17 * VAR_4; for (VAR_16 = VAR_12; VAR_16 < VAR_13 && VAR_16 < VAR_15[VAR_17]; VAR_16++) { if (dst[VAR_16] != VAR_5) { VAR_15[VAR_17] = VAR_16; break; } } for (VAR_16 = VAR_13 - 1; VAR_16 >= VAR_12 && VAR_16 >= VAR_14[VAR_17]; VAR_16--) { if (dst[VAR_16] != VAR_5) { VAR_14[VAR_17] = VAR_16; break; } } } if (VAR_0->envelope == 3)
envelope_instant16(VAR_0, VAR_1, VAR_2, VAR_3); for (VAR_17 = 0; VAR_17 < VAR_10; VAR_17++) { dst = (uint16_t *)VAR_1->data[VAR_3] + VAR_17 * VAR_4 + VAR_15[VAR_17]; dst[0] = VAR_6; dst = (uint16_t *)VAR_1->data[VAR_3] + VAR_17 * VAR_4 + VAR_14[VAR_17]; dst[0] = VAR_6; } } }