OBS image-source插件
+ -

image-source

2024-12-23 0 0

image-source插件通过image_source_load函数来初始化。

  • gs_image_file3_init
  • gs_image_file_init_internal

对于非GIF图片:

    image->texture_data = gs_create_texture_file_data2(file, alpha_mode, &image->format, &image->cx, &image->cy);

gs_create_texture_file_data2通过FFMPEG来编解码;

uint8_t *gs_create_texture_file_data2(const char *file,
                      enum gs_image_alpha_mode alpha_mode,
                      enum gs_color_format *format,
                      uint32_t *cx_out, uint32_t *cy_out)
{
    struct ffmpeg_image image;
    uint8_t *data = NULL;

    if (ffmpeg_image_init(&image, file)) 
    {
        data = ffmpeg_image_decode(&image, alpha_mode);
        if (data) 
        {
            *format = convert_format(image.format);
            *cx_out = (uint32_t)image.cx;
            *cy_out = (uint32_t)image.cy;
        }

        ffmpeg_image_free(&image);
    }

    return data;
}

在ffmpeg_image_decode中,对于解析到的YUV图像,通过ffmpeg_image_reformat_frame转换成BGRA.

enum AVPixelFormat format = AV_PIX_FMT_BGRA;
info->format = AV_PIX_FMT_YUVJ420P;

//创建转换器
struct SwsContext *sws_ctx = sws_getContext(
                info->cx, info->cy, info->format,
                info->cx, info->cy, format, SWS_POINT,
                 NULL, NULL, NULL);

//申请目标空间
        uint8_t *pointers[4];
        int linesizes[4];
        ret = av_image_alloc(pointers, linesizes, info->cx, info->cy,format, 32);

//目标转换
        ret = sws_scale(sws_ctx,
        (const uint8_t *const *)frame->data,frame->linesize, 
        0, 
        info->cy, pointers,    linesizes);

//释放转换器
        sws_freeContext(sws_ctx);

//内存数据复制
        const size_t linesize = (size_t)info->cx * 4;
        data = bmalloc(info->cy * linesize);
        const uint8_t *src = pointers[0];
        uint8_t *dst = data;
        for (size_t y = 0; y < (size_t)info->cy; y++) 
        {
            memcpy(dst, src, linesize);
            dst += linesize;
            src += linesizes[0];
        }

        av_freep(pointers);

叁考资料:https://blog.csdn.net/m0_51386664/article/details/139355139

最后根据RGB的格式和源始数据创建2D纹理。

    case GS_RGBA:
        return DXGI_FORMAT_R8G8B8A8_TYPELESS;
    case GS_BGRX:
        return DXGI_FORMAT_B8G8R8X8_TYPELESS;
    case GS_BGRA:
        return DXGI_FORMAT_B8G8R8A8_TYPELESS;

0 篇笔记 写笔记

作者信息
我爱内核
Windows驱动开发,网站开发
好好学习,天天向上。
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!