blob: a9a7d3ecd16cf19946cf6cff64851e43076aff75 [file] [log] [blame]
/*
* Copyright (c) 2012-2014 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and/or associated documentation files (the
* "Materials"), to deal in the Materials without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Materials, and to
* permit persons to whom the Materials are furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
/*!
* \file
* \brief The Image Scale Kernel
* \author Erik Rainey <erik.rainey@gmail.com>
*/
#include <VX/vx.h>
#include <VX/vx_helper.h>
#include <vxcl_kernel_module.h>
#include <stdio.h>
#include <math.h>
static vx_status VX_CALLBACK vxScaleImageInputValidator(vx_node node, vx_uint32 index)
{
vx_status status = VX_ERROR_INVALID_PARAMETERS;
if (index == 0)
{
vx_image input = 0;
vx_parameter param = vxGetParameterByIndex(node, index);
vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &input, sizeof(input));
if (input)
{
vx_df_image format = 0;
vxQueryImage(input, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format));
if (format == VX_DF_IMAGE_U8)
{
status = VX_SUCCESS;
}
vxReleaseImage(&input);
}
vxReleaseParameter(&param);
}
else if (index == 2)
{
vx_parameter param = vxGetParameterByIndex(node, index);
if (param)
{
vx_scalar scalar = 0;
vxQueryParameter(param, VX_PARAMETER_ATTRIBUTE_REF, &scalar, sizeof(scalar));
if (scalar)
{
vx_enum stype = 0;
vxQueryScalar(scalar, VX_SCALAR_ATTRIBUTE_TYPE, &stype, sizeof(stype));
if (stype == VX_TYPE_ENUM)
{
vx_enum interp = 0;
vxReadScalarValue(scalar, &interp);
if ((interp == VX_INTERPOLATION_TYPE_NEAREST_NEIGHBOR) ||
(interp == VX_INTERPOLATION_TYPE_BILINEAR) ||
(interp == VX_INTERPOLATION_TYPE_AREA))
{
status = VX_SUCCESS;
}
else
{
status = VX_ERROR_INVALID_VALUE;
}
}
else
{
status = VX_ERROR_INVALID_TYPE;
}
vxReleaseScalar(&scalar);
}
vxReleaseParameter(&param);
}
}
return status;
}
static vx_status VX_CALLBACK vxScaleImageOutputValidator(vx_node node, vx_uint32 index, vx_meta_format ptr)
{
vx_status status = VX_ERROR_INVALID_PARAMETERS;
if (index == 1)
{
vx_parameter src_param = vxGetParameterByIndex(node, 0);
vx_parameter dst_param = vxGetParameterByIndex(node, index);
if (src_param && dst_param)
{
vx_image src = 0;
vx_image dst = 0;
vxQueryParameter(src_param, VX_PARAMETER_ATTRIBUTE_REF, &src, sizeof(src));
vxQueryParameter(dst_param, VX_PARAMETER_ATTRIBUTE_REF, &dst, sizeof(dst));
if ((src) && (dst))
{
vx_uint32 w1 = 0, h1 = 0, w2 = 0, h2 = 0;
vx_df_image f1 = VX_DF_IMAGE_VIRT, f2 = VX_DF_IMAGE_VIRT;
vxQueryImage(src, VX_IMAGE_ATTRIBUTE_WIDTH, &w1, sizeof(w1));
vxQueryImage(src, VX_IMAGE_ATTRIBUTE_HEIGHT, &h1, sizeof(h1));
vxQueryImage(dst, VX_IMAGE_ATTRIBUTE_WIDTH, &w2, sizeof(w2));
vxQueryImage(dst, VX_IMAGE_ATTRIBUTE_HEIGHT, &h2, sizeof(h2));
vxQueryImage(src, VX_IMAGE_ATTRIBUTE_FORMAT, &f1, sizeof(f1));
vxQueryImage(dst, VX_IMAGE_ATTRIBUTE_FORMAT, &f2, sizeof(f2));
/* output can not be virtual */
if ((w2 != 0) && (h2 != 0) && (f2 != VX_DF_IMAGE_VIRT) && (f1 == f2))
{
/* fill in the meta data with the attributes so that the checker will pass */
vxSetMetaFormatAttribute(ptr, VX_IMAGE_ATTRIBUTE_FORMAT, &f2, sizeof(f2));
vxSetMetaFormatAttribute(ptr, VX_IMAGE_ATTRIBUTE_WIDTH, &w2, sizeof(w2));
vxSetMetaFormatAttribute(ptr, VX_IMAGE_ATTRIBUTE_HEIGHT, &h2, sizeof(h2));
status = VX_SUCCESS;
}
vxReleaseImage(&src);
vxReleaseImage(&dst);
}
vxReleaseParameter(&src_param);
vxReleaseParameter(&dst_param);
}
}
return status;
}
static vx_param_description_t scale_kernel_params[] = {
{VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED},
{VX_OUTPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED},
{VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_OPTIONAL},
};
vx_cl_kernel_description_t scale_image_clkernel = {
{
VX_KERNEL_SCALE_IMAGE,
"com.samsung.opencl.scale_image",
NULL,
scale_kernel_params, dimof(scale_kernel_params),
vxScaleImageInputValidator,
vxScaleImageOutputValidator,
NULL,
NULL,
},
"/system/usr/vxcl/vx_scaler.cl",
"vx_scaler",
INIT_PROGRAMS,
INIT_KERNELS,
INIT_NUMKERNELS,
INIT_RETURNS,
NULL,
};