【OpenVX】vx_imagepatch_addressing_t

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhy29563

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值