栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 软件开发 > 游戏开发 > Unity3D

【OpenVX】vx

Unity3D 更新时间:发布时间: 百科书网 趣学号
1. 官方定义

OpenVX 图像类型 vx_imagee中用vx_imagepatch_addressing_t结构表示数据的内存布局。以下是官方对vx_imagepatch_addressing_t结构的定义与成员解释。英文不好,直接附上原文。

typedef struct _vx_imagepatch_addressing_t {
    vx_uint32    dim_x;
    vx_uint32    dim_y;
    vx_int32     stride_x;
    vx_int32     stride_y;
    vx_uint32    scale_x;
    vx_uint32    scale_y;
    vx_uint32    step_x;
    vx_uint16    step_y;
    vx_uint16    stride_x_bits;
} vx_imagepatch_addressing_t;
  • dim_x, dim_y
    The dimensions of the image in logical pixel units in the x & y direction.
  • stride_x, stride_y
    The physical byte distance from a logical pixel to the next logically adjacent pixel in the positive x or y direction.
  • scale_x, scale_y
    The relationship of scaling from the primary plane (typically the zero indexed plane) to this plane. An integer down-scaling factor of f shall be set to a value equal to scale = unity / f and an integer up-scaling factor of f shall be set to a value of scale = unity × f. unity is defined as VX_SCALE_UNITY.
  • step_x, step_y
    The step is the number of logical pixel units to skip to arrive at the next physically unique pixel. For example, on a plane that is half-scaled in a dimension, the step in that dimension is 2 to indicate that every other pixel in that dimension is an alias. This is useful in situations where iteration over unique pixels is required, such as in serializing or de-serializing the image patch information.
  • stride_x_bits
    The physical bit distance from a logical pixel to the next logically adjacent pixel in the positive x-direction. This field is only used when the stride in the x-direction is not an integer number of bytes (e.g. for VX_DF_IMAGE_U1 images).
2. 辅助函数
  • 获取图像类型的字符串显示
    std::string get_string_vx_df_image_e(vx_df_image_e format)
    {
        switch (format)
        {
        case VX_DF_IMAGE_VIRT:
            return std::string("VX_DF_IMAGE_VIRT");
        case VX_DF_IMAGE_RGB:
            return std::string("VX_DF_IMAGE_RGB");
        case VX_DF_IMAGE_RGBX:
            return std::string("VX_DF_IMAGE_RGBX");
        case VX_DF_IMAGE_NV12:
            return std::string("VX_DF_IMAGE_NV12");
        case VX_DF_IMAGE_NV21:
            return std::string("VX_DF_IMAGE_NV21");
        case VX_DF_IMAGE_UYVY:
            return std::string("VX_DF_IMAGE_UYVY");
        case VX_DF_IMAGE_YUYV:
            return std::string("VX_DF_IMAGE_YUYV");
        case VX_DF_IMAGE_IYUV:
            return std::string("VX_DF_IMAGE_IYUV");
        case VX_DF_IMAGE_U8:
            return std::string("VX_DF_IMAGE_U8");
        case VX_DF_IMAGE_U16:
            return std::string("VX_DF_IMAGE_U16");
        case VX_DF_IMAGE_S16:
            return std::string("VX_DF_IMAGE_S16");
        case VX_DF_IMAGE_U32:
            return std::string("VX_DF_IMAGE_U32");
        case VX_DF_IMAGE_S32:
            return std::string("VX_DF_IMAGE_S32");
        }
    
        return std::string("");
    }
    
  • 显示vx_imagepatch_addressing_t成员值
    void show_vx_image_patch_addressing_t(vx_image image) {
    vx_df_image_e format;
    vxQueryImage(image, VX_IMAGE_FORMAT, &format, sizeof(vx_df_image));
    std::cout << "format        : " << get_string_vx_df_image_e(format) << std::endl;
    vx_size planes;
    vxQueryImage(image, VX_IMAGE_PLANES, &planes, sizeof(vx_size));
    
    vx_rectangle_t patch;
    vxGetValidRegionImage(image, &patch);
    
    for (size_t i = 0; i < planes; i++) {
        vx_imagepatch_addressing_t addr = VX_IMAGEPATCH_ADDR_INIT;
    
        vx_map_id map_id;
        unsigned char *ptr;
        vxMapImagePatch(image, &patch, i, &map_id, &addr, (void **) &ptr,
                        VX_READ_ONLY, VX_MEMORY_TYPE_HOST,VX_NOGAP_X);
        std::cout << "tplane        : " << i << std::endl;
        std::cout << "taddr.dim_x   : " << addr.dim_x << std::endl;
        std::cout << "taddr.dim_y   : " << addr.dim_y << std::endl;
        std::cout << "taddr.stride_x: " << addr.stride_x << std::endl;
        std::cout << "taddr.stride_y: " << addr.stride_y << std::endl;
        std::cout << "taddr.scale_x : " << addr.scale_x << std::endl;
        std::cout << "taddr.scale_y : " << addr.scale_y << std::endl;
        std::cout << "taddr.step_x  : " << addr.step_x << std::endl;
        std::cout << "taddr.step_y  : " << addr.step_y << std::endl;
        std::cout << std::endl;
        vxUnmapImagePatch(image, map_id);
    }
    
  • 测试程序
    void TEST_image_patch_addr_for_all_types(vx_context context) {
    for (auto &df_image : df_images) {
        std::cout << "===================================================" << std::endl;
        vx_image image = vxCreateImage(context, 640, 480, df_image);
        show_vx_image_patch_addressing_t(image);
    }
    
3. 测试程序
  • 相同尺寸不同图像类型

    int main()
    {
        vx_context context = vxCreateContext();
        TEST_image_stride_y(context, 100, 100, VX_DF_IMAGE_U8);
        TEST_image_stride_y(context, 100, 100, VX_DF_IMAGE_RGB);
        TEST_image_stride_y(context, 100, 100, VX_DF_IMAGE_NV12);
    
        vxReleaseContext(&context);
        return EXIT_SUCCESS;
    }
    

    ===================================================
    format :
    ===================================================
    format : VX_DF_IMAGE_RGB
    plane : 0
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 3
    addr.stride_y: 1920
    addr.scale_x : 1024
    addr.scale_y : 1024
    addr.step_x : 1
    addr.step_y : 1

    ===================================================
    format : VX_DF_IMAGE_RGBX
    plane : 0
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 4
    addr.stride_y: 2560
    addr.scale_x : 1024
    addr.scale_y : 1024
    addr.step_x : 1
    addr.step_y : 1

    ===================================================
    format : VX_DF_IMAGE_NV12
    plane : 0
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 1
    addr.stride_y: 640
    addr.scale_x : 1024
    addr.scale_y : 1024
    addr.step_x : 1
    addr.step_y : 1

    plane : 1
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 2
    addr.stride_y: 640
    addr.scale_x : 512
    addr.scale_y : 512
    addr.step_x : 2
    addr.step_y : 2

    ===================================================
    format : VX_DF_IMAGE_NV21
    plane : 0
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 1
    addr.stride_y: 640
    addr.scale_x : 1024
    addr.scale_y : 1024
    addr.step_x : 1
    addr.step_y : 1

    plane : 1
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 2
    addr.stride_y: 640
    addr.scale_x : 512
    addr.scale_y : 512
    addr.step_x : 2
    addr.step_y : 2

    ===================================================
    format : VX_DF_IMAGE_UYVY
    plane : 0
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 2
    addr.stride_y: 1280
    addr.scale_x : 1024
    addr.scale_y : 1024
    addr.step_x : 1
    addr.step_y : 1

    ===================================================
    format : VX_DF_IMAGE_YUYV
    plane : 0
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 2
    addr.stride_y: 1280
    addr.scale_x : 1024
    addr.scale_y : 1024
    addr.step_x : 1
    addr.step_y : 1

    ===================================================
    format : VX_DF_IMAGE_IYUV
    plane : 0
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 1
    addr.stride_y: 640
    addr.scale_x : 1024
    addr.scale_y : 1024
    addr.step_x : 1
    addr.step_y : 1

    plane : 1
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 1
    addr.stride_y: 320
    addr.scale_x : 512
    addr.scale_y : 512
    addr.step_x : 2
    addr.step_y : 2

    plane : 2
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 1
    addr.stride_y: 320
    addr.scale_x : 512
    addr.scale_y : 512
    addr.step_x : 2
    addr.step_y : 2

    ===================================================
    format : VX_DF_IMAGE_YUV4
    plane : 0
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 1
    addr.stride_y: 640
    addr.scale_x : 1024
    addr.scale_y : 1024
    addr.step_x : 1
    addr.step_y : 1

    plane : 1
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 1
    addr.stride_y: 640
    addr.scale_x : 1024
    addr.scale_y : 1024
    addr.step_x : 1
    addr.step_y : 1

    plane : 2
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 1
    addr.stride_y: 640
    addr.scale_x : 1024
    addr.scale_y : 1024
    addr.step_x : 1
    addr.step_y : 1

    ===================================================
    format : VX_DF_IMAGE_U8
    plane : 0
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 1
    addr.stride_y: 640
    addr.scale_x : 1024
    addr.scale_y : 1024
    addr.step_x : 1
    addr.step_y : 1

    ===================================================
    format : VX_DF_IMAGE_U16
    plane : 0
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 2
    addr.stride_y: 1280
    addr.scale_x : 1024
    addr.scale_y : 1024
    addr.step_x : 1
    addr.step_y : 1

    ===================================================
    format : VX_DF_IMAGE_S16
    plane : 0
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 2
    addr.stride_y: 1280
    addr.scale_x : 1024
    addr.scale_y : 1024
    addr.step_x : 1
    addr.step_y : 1

    ===================================================
    format : VX_DF_IMAGE_U32
    plane : 0
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 4
    addr.stride_y: 2560
    addr.scale_x : 1024
    addr.scale_y : 1024
    addr.step_x : 1
    addr.step_y : 1

    ===================================================
    format : VX_DF_IMAGE_S32
    plane : 0
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 4
    addr.stride_y: 2560
    addr.scale_x : 1024
    addr.scale_y : 1024
    addr.step_x : 1
    addr.step_y : 1

    ===================================================
    format : VX_DF_IMAGE_U1
    plane : 0
    addr.dim_x : 640
    addr.dim_y : 480
    addr.stride_x: 0
    addr.stride_y: 80
    addr.scale_x : 1024
    addr.scale_y : 1024
    addr.step_x : 1
    addr.step_y : 1

转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/1069176.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号