Esempio n. 1
0
// nodeless version of the Phase kernel
vx_status vxPhase(vx_image grad_x, vx_image grad_y, vx_image output)
{
    vx_uint32 x;
    vx_uint32 y;
    vx_df_image format = 0;
    vx_uint8* dst_base = NULL;
    void* src_base_x   = NULL;
    void* src_base_y   = NULL;
    vx_imagepatch_addressing_t src_addr_x;
    vx_imagepatch_addressing_t src_addr_y;
    vx_imagepatch_addressing_t dst_addr;
    vx_rectangle_t rect;
    vx_status status = VX_FAILURE;

    if (grad_x == 0 && grad_y == 0)
        return VX_ERROR_INVALID_PARAMETERS;

    status  = VX_SUCCESS;
    status |= vxQueryImage(grad_x, VX_IMAGE_FORMAT, &format, sizeof(format));
    status |= vxGetValidRegionImage(grad_x, &rect);
    status |= vxAccessImagePatch(grad_x, &rect, 0, &src_addr_x, &src_base_x, VX_READ_ONLY);
    status |= vxAccessImagePatch(grad_y, &rect, 0, &src_addr_y, &src_base_y, VX_READ_ONLY);
    status |= vxAccessImagePatch(output, &rect, 0, &dst_addr, (void **)&dst_base, VX_WRITE_ONLY);

    for (y = 0; y < dst_addr.dim_y; y++)
    {
        for (x = 0; x < dst_addr.dim_x; x++)
        {
            void*     in_x = vxFormatImagePatchAddress2d(src_base_x, x, y, &src_addr_x);
            void*     in_y = vxFormatImagePatchAddress2d(src_base_y, x, y, &src_addr_y);
            vx_uint8* dst  = vxFormatImagePatchAddress2d(dst_base, x, y, &dst_addr);

            /* -M_PI to M_PI */
            double val_x;
            double val_y;

            if (format == VX_DF_IMAGE_F32)
            {
                val_x = (double)(((vx_float32*)in_x)[0]);
                val_y = (double)(((vx_float32*)in_y)[0]);
            }
            else // VX_DF_IMAGE_S16
            {
                val_x = (double)(((vx_int16*)in_x)[0]);
                val_y = (double)(((vx_int16*)in_y)[0]);
            }

            double arct = atan2(val_y,val_x);
            /* 0 - TAU */
            double norm = arct;
            if (arct < 0.0f)
            {
                norm = VX_TAU + arct;
            }

            /* 0.0 - 1.0 */
            norm = norm / VX_TAU;

            /* 0 - 255 */
            *dst = (vx_uint8)((vx_uint32)(norm * 256u + 0.5) & 0xFFu);
            if (val_y != 0 || val_x != 0)
            {
                VX_PRINT(VX_ZONE_INFO, "atan2(%d,%d) = %lf [norm=%lf] dst=%02x\n", val_y, val_x, arct, norm, *dst);
            }
        }
    }

    status |= vxCommitImagePatch(grad_x, NULL, 0, &src_addr_x, src_base_x);
    status |= vxCommitImagePatch(grad_y, NULL, 0, &src_addr_y, src_base_y);
    status |= vxCommitImagePatch(output, &rect, 0, &dst_addr, dst_base);

    return status;
}
Esempio n. 2
0
static vx_status vxChannelCombineKernel(vx_node node, vx_reference *parameters, vx_uint32 num)
{
    vx_status status = VX_FAILURE;
    if (num == 5)
    {
        vx_image inputs[4] = {
            (vx_image)parameters[0],
            (vx_image)parameters[1],
            (vx_image)parameters[2],
            (vx_image)parameters[3],
        };
        vx_image output = (vx_image)parameters[4];
        vx_fourcc format = 0;
        vx_rectangle rect;
        vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format));
        rect = vxGetValidRegionImage(inputs[0]);
        if ((format == FOURCC_RGB) || (format == FOURCC_RGBX))
        {
            /* write all the channels back out in interleaved format */
            vx_imagepatch_addressing_t src_addrs[4];
            vx_imagepatch_addressing_t dst_addr;
            void *base_src_ptrs[4] = {NULL, NULL, NULL, NULL};
            void *base_dst_ptr = NULL;
            uint32_t x, y, p;
            uint32_t numplanes = 3;

            if (format == FOURCC_RGBX)
            {
                numplanes = 4;
            }

            // get the planes
            for (p = 0; p < numplanes; p++)
            {
                vxAccessImagePatch(inputs[p], rect, 0, &src_addrs[p], &base_src_ptrs[p]);
            }
            vxAccessImagePatch(output, rect, 0, &dst_addr, &base_dst_ptr);
            for (y = 0; y < dst_addr.dim_y; y+=dst_addr.step_y)
            {
                for (x = 0; x < dst_addr.dim_x; x+=dst_addr.step_x)
                {
                    uint8_t *planes[4] = {
                        vxFormatImagePatchAddress2d(base_src_ptrs[0], x, y, &src_addrs[0]),
                        vxFormatImagePatchAddress2d(base_src_ptrs[1], x, y, &src_addrs[1]),
                        vxFormatImagePatchAddress2d(base_src_ptrs[2], x, y, &src_addrs[2]),
                        NULL,
                    };
                    uint8_t *dst = vxFormatImagePatchAddress2d(base_dst_ptr, x, y, &dst_addr);
                    dst[0] = planes[0][0];
                    dst[1] = planes[1][0];
                    dst[2] = planes[2][0];
                    if (format == FOURCC_RGBX)
                    {
                        planes[3] = vxFormatImagePatchAddress2d(base_src_ptrs[3], x, y, &src_addrs[3]);
                        dst[3] = planes[3][0];
                    }
                }
            }
            // write the data back
            vxCommitImagePatch(output, rect, 0, &dst_addr, base_dst_ptr);
            // release the planes
            for (p = 0; p < numplanes; p++)
            {
                vxCommitImagePatch(inputs[p], 0, 0, &src_addrs[p], &base_src_ptrs[p]);
            }
        }
        else if (format == FOURCC_YUV4)
        {
            /* write all the channels back out in the planar format */
            vx_imagepatch_addressing_t src_addrs[3];
            vx_imagepatch_addressing_t dst_addrs[3];
            void *base_src_ptrs[3] = {NULL, NULL, NULL};
            void *base_dst_ptrs[3] = {NULL, NULL, NULL};
            uint32_t x, y, p;

            // get the planes
            for (p = 0; p < 3; p++)
            {
                vxAccessImagePatch(inputs[p], rect, 0, &src_addrs[p], &base_src_ptrs[p]);
                vxAccessImagePatch(output, rect, 0, &dst_addrs[p], &base_dst_ptrs[p]);
            }

            for (y = 0; y < dst_addrs[0].dim_y; y+=dst_addrs[0].step_y)
            {
                for (x = 0; x < dst_addrs[0].dim_x; x+=dst_addrs[0].step_x)
                {
                    uint8_t *planes[3] = {
                        vxFormatImagePatchAddress2d(base_src_ptrs[0], x, y, &src_addrs[0]),
                        vxFormatImagePatchAddress2d(base_src_ptrs[1], x, y, &src_addrs[1]),
                        vxFormatImagePatchAddress2d(base_src_ptrs[2], x, y, &src_addrs[2]),
                    };
                    uint8_t *dsts[3] = {
                        vxFormatImagePatchAddress2d(base_dst_ptrs[0], x, y, &dst_addrs[0]),
                        vxFormatImagePatchAddress2d(base_dst_ptrs[0], x, y, &dst_addrs[0]),
                        vxFormatImagePatchAddress2d(base_dst_ptrs[0], x, y, &dst_addrs[0]),
                    };
                    dsts[0][0] = planes[0][0];
                    dsts[1][0] = planes[1][0];
                    dsts[2][0] = planes[2][0];
                }
            }
            // release the planes
            for (p = 0; p < 3; p++)
            {
                // write the data back
                vxCommitImagePatch(output, rect, 0, &dst_addrs[p], base_dst_ptrs[p]);
                // release the input
                vxCommitImagePatch(inputs[p], 0, 0, &src_addrs[p], &base_src_ptrs[p]);
            }
        }
        vxReleaseRectangle(&rect);
        status = VX_SUCCESS;
    }
    else
        status = VX_ERROR_INVALID_PARAMETERS;
    return status;
}