⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imgconvert.c

📁 现在关于h.264的源码很多
💻 C
📖 第 1 页 / 共 5 页
字号:
        case PIX_FMT_YUV422:        case PIX_FMT_UYVY422:        case PIX_FMT_RGB565:        case PIX_FMT_RGB555:            bits = 16;            break;        case PIX_FMT_UYVY411:            bits = 12;            break;        default:            bits = pf->depth * pf->nb_channels;            break;        }        break;    case FF_PIXEL_PLANAR:        if (pf->x_chroma_shift == 0 && pf->y_chroma_shift == 0) {            bits = pf->depth * pf->nb_channels;        } else {            bits = pf->depth + ((2 * pf->depth) >>                                (pf->x_chroma_shift + pf->y_chroma_shift));        }        break;    case FF_PIXEL_PALETTE:        bits = 8;        break;    default:        bits = -1;        break;    }    return bits;}static int avcodec_find_best_pix_fmt1(int pix_fmt_mask,                                      int src_pix_fmt,                                      int has_alpha,                                      int loss_mask){    int dist, i, loss, min_dist, dst_pix_fmt;    /* find exact color match with smallest size */    dst_pix_fmt = -1;    min_dist = 0x7fffffff;    for(i = 0;i < PIX_FMT_NB; i++) {        if (pix_fmt_mask & (1 << i)) {            loss = avcodec_get_pix_fmt_loss(i, src_pix_fmt, has_alpha) & loss_mask;            if (loss == 0) {                dist = avg_bits_per_pixel(i);                if (dist < min_dist) {                    min_dist = dist;                    dst_pix_fmt = i;                }            }        }    }    return dst_pix_fmt;}/** * find best pixel format to convert to. Return -1 if none found */int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt,                              int has_alpha, int *loss_ptr){    int dst_pix_fmt, loss_mask, i;    static const int loss_mask_order[] = {        ~0, /* no loss first */        ~FF_LOSS_ALPHA,        ~FF_LOSS_RESOLUTION,        ~(FF_LOSS_COLORSPACE | FF_LOSS_RESOLUTION),        ~FF_LOSS_COLORQUANT,        ~FF_LOSS_DEPTH,        0,    };    /* try with successive loss */    i = 0;    for(;;) {        loss_mask = loss_mask_order[i++];        dst_pix_fmt = avcodec_find_best_pix_fmt1(pix_fmt_mask, src_pix_fmt,                                                 has_alpha, loss_mask);        if (dst_pix_fmt >= 0)            goto found;        if (loss_mask == 0)            break;    }    return -1; found:    if (loss_ptr)        *loss_ptr = avcodec_get_pix_fmt_loss(dst_pix_fmt, src_pix_fmt, has_alpha);    return dst_pix_fmt;}void ff_img_copy_plane(uint8_t *dst, int dst_wrap,                           const uint8_t *src, int src_wrap,                           int width, int height){    if((!dst) || (!src))        return;    for(;height > 0; height--) {        memcpy(dst, src, width);        dst += dst_wrap;        src += src_wrap;    }}/** * Copy image 'src' to 'dst'. */void img_copy(AVPicture *dst, const AVPicture *src,              int pix_fmt, int width, int height){    int bwidth, bits, i;    PixFmtInfo *pf = &pix_fmt_info[pix_fmt];    pf = &pix_fmt_info[pix_fmt];    switch(pf->pixel_type) {    case FF_PIXEL_PACKED:        switch(pix_fmt) {        case PIX_FMT_YUV422:        case PIX_FMT_UYVY422:        case PIX_FMT_RGB565:        case PIX_FMT_RGB555:            bits = 16;            break;        case PIX_FMT_UYVY411:            bits = 12;            break;        default:            bits = pf->depth * pf->nb_channels;            break;        }        bwidth = (width * bits + 7) >> 3;        ff_img_copy_plane(dst->data[0], dst->linesize[0],                       src->data[0], src->linesize[0],                       bwidth, height);        break;    case FF_PIXEL_PLANAR:        for(i = 0; i < pf->nb_channels; i++) {            int w, h;            w = width;            h = height;            if (i == 1 || i == 2) {                w >>= pf->x_chroma_shift;                h >>= pf->y_chroma_shift;            }            bwidth = (w * pf->depth + 7) >> 3;            ff_img_copy_plane(dst->data[i], dst->linesize[i],                           src->data[i], src->linesize[i],                           bwidth, h);        }        break;    case FF_PIXEL_PALETTE:        ff_img_copy_plane(dst->data[0], dst->linesize[0],                       src->data[0], src->linesize[0],                       width, height);        /* copy the palette */        ff_img_copy_plane(dst->data[1], dst->linesize[1],                       src->data[1], src->linesize[1],                       4, 256);        break;    }}/* XXX: totally non optimized */static void yuv422_to_yuv420p(AVPicture *dst, const AVPicture *src,                              int width, int height){    const uint8_t *p, *p1;    uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;    int w;    p1 = src->data[0];    lum1 = dst->data[0];    cb1 = dst->data[1];    cr1 = dst->data[2];    for(;height >= 1; height -= 2) {        p = p1;        lum = lum1;        cb = cb1;        cr = cr1;        for(w = width; w >= 2; w -= 2) {            lum[0] = p[0];            cb[0] = p[1];            lum[1] = p[2];            cr[0] = p[3];            p += 4;            lum += 2;            cb++;            cr++;        }        if (w) {            lum[0] = p[0];            cb[0] = p[1];            cr[0] = p[3];            cb++;            cr++;        }        p1 += src->linesize[0];        lum1 += dst->linesize[0];        if (height>1) {            p = p1;            lum = lum1;            for(w = width; w >= 2; w -= 2) {                lum[0] = p[0];                lum[1] = p[2];                p += 4;                lum += 2;            }            if (w) {                lum[0] = p[0];            }            p1 += src->linesize[0];            lum1 += dst->linesize[0];        }        cb1 += dst->linesize[1];        cr1 += dst->linesize[2];    }}static void uyvy422_to_yuv420p(AVPicture *dst, const AVPicture *src,                              int width, int height){    const uint8_t *p, *p1;    uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;    int w;    p1 = src->data[0];    lum1 = dst->data[0];    cb1 = dst->data[1];    cr1 = dst->data[2];    for(;height >= 1; height -= 2) {        p = p1;        lum = lum1;        cb = cb1;        cr = cr1;        for(w = width; w >= 2; w -= 2) {            lum[0] = p[1];            cb[0] = p[0];            lum[1] = p[3];            cr[0] = p[2];            p += 4;            lum += 2;            cb++;            cr++;        }        if (w) {            lum[0] = p[1];            cb[0] = p[0];            cr[0] = p[2];            cb++;            cr++;        }        p1 += src->linesize[0];        lum1 += dst->linesize[0];        if (height>1) {            p = p1;            lum = lum1;            for(w = width; w >= 2; w -= 2) {                lum[0] = p[1];                lum[1] = p[3];                p += 4;                lum += 2;            }            if (w) {                lum[0] = p[1];            }            p1 += src->linesize[0];            lum1 += dst->linesize[0];        }        cb1 += dst->linesize[1];        cr1 += dst->linesize[2];    }}static void uyvy422_to_yuv422p(AVPicture *dst, const AVPicture *src,                              int width, int height){    const uint8_t *p, *p1;    uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;    int w;    p1 = src->data[0];    lum1 = dst->data[0];    cb1 = dst->data[1];    cr1 = dst->data[2];    for(;height > 0; height--) {        p = p1;        lum = lum1;        cb = cb1;        cr = cr1;        for(w = width; w >= 2; w -= 2) {            lum[0] = p[1];            cb[0] = p[0];            lum[1] = p[3];            cr[0] = p[2];            p += 4;            lum += 2;            cb++;            cr++;        }        p1 += src->linesize[0];        lum1 += dst->linesize[0];        cb1 += dst->linesize[1];        cr1 += dst->linesize[2];    }}static void yuv422_to_yuv422p(AVPicture *dst, const AVPicture *src,                              int width, int height){    const uint8_t *p, *p1;    uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;    int w;    p1 = src->data[0];    lum1 = dst->data[0];    cb1 = dst->data[1];    cr1 = dst->data[2];    for(;height > 0; height--) {        p = p1;        lum = lum1;        cb = cb1;        cr = cr1;        for(w = width; w >= 2; w -= 2) {            lum[0] = p[0];            cb[0] = p[1];            lum[1] = p[2];            cr[0] = p[3];            p += 4;            lum += 2;            cb++;            cr++;        }        p1 += src->linesize[0];        lum1 += dst->linesize[0];        cb1 += dst->linesize[1];        cr1 += dst->linesize[2];    }}static void yuv422p_to_yuv422(AVPicture *dst, const AVPicture *src,                              int width, int height){    uint8_t *p, *p1;    const uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;    int w;    p1 = dst->data[0];    lum1 = src->data[0];    cb1 = src->data[1];    cr1 = src->data[2];    for(;height > 0; height--) {        p = p1;        lum = lum1;        cb = cb1;        cr = cr1;        for(w = width; w >= 2; w -= 2) {            p[0] = lum[0];            p[1] = cb[0];            p[2] = lum[1];            p[3] = cr[0];            p += 4;            lum += 2;            cb++;            cr++;        }        p1 += dst->linesize[0];        lum1 += src->linesize[0];        cb1 += src->linesize[1];        cr1 += src->linesize[2];    }}static void yuv422p_to_uyvy422(AVPicture *dst, const AVPicture *src,                              int width, int height){    uint8_t *p, *p1;    const uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;    int w;    p1 = dst->data[0];    lum1 = src->data[0];    cb1 = src->data[1];    cr1 = src->data[2];    for(;height > 0; height--) {        p = p1;        lum = lum1;        cb = cb1;        cr = cr1;        for(w = width; w >= 2; w -= 2) {            p[1] = lum[0];            p[0] = cb[0];            p[3] = lum[1];            p[2] = cr[0];            p += 4;            lum += 2;            cb++;            cr++;        }        p1 += dst->linesize[0];        lum1 += src->linesize[0];        cb1 += src->linesize[1];        cr1 += src->linesize[2];    }}static void uyvy411_to_yuv411p(AVPicture *dst, const AVPicture *src,                              int width, int height){    const uint8_t *p, *p1;    uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;    int w;    p1 = src->data[0];    lum1 = dst->data[0];    cb1 = dst->data[1];    cr1 = dst->data[2];    for(;height > 0; height--) {        p = p1;        lum = lum1;        cb = cb1;        cr = cr1;        for(w = width; w >= 4; w -= 4) {            cb[0] = p[0];            lum[0] = p[1];            lum[1] = p[2];            cr[0] = p[3];            lum[2] = p[4];            lum[3] = p[5];            p += 6;            lum += 4;            cb++;            cr++;        }        p1 += src->linesize[0];        lum1 += dst->linesize[0];        cb1 += dst->linesize[1];        cr1 += dst->linesize[2];    }}static void yuv420p_to_yuv422(AVPicture *dst, const AVPicture *src,                              int width, int height){    int w, h;    uint8_t *line1, *line2, *linesrc = dst->data[0];    uint8_t *lum1, *lum2, *lumsrc = src->data[0];    uint8_t *cb1, *cb2 = src->data[1];    uint8_t *cr1, *cr2 = src->data[2];    for(h = height / 2; h--;) {        line1 = linesrc;        line2 = linesrc + dst->linesize[0];        lum1 = lumsrc;        lum2 = lumsrc + src->linesize[0];        cb1 = cb2;        cr1 = cr2;        for(w = width / 2; w--;) {                *line1++ = *lum1++; *line2++ = *lum2++;                *line1++ =          *line2++ = *cb1++;                *line1++ = *lum1++; *line2++ = *lum2++;                *line1++ =          *line2++ = *cr1++;        }        linesrc += dst->linesize[0] * 2;        lumsrc += src->linesize[0] * 2;        cb2 += src->linesize[1];        cr2 += src->linesize[2];    }}static void yuv420p_to_uyvy422(AVPicture *dst, const AVPicture *src,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -