Compute Library
 19.11.1
scale.cl File Reference
#include "helpers.h"
#include "warp_helpers.h"

Go to the source code of this file.

Functions

const float8 transform_nearest (const float2 coord, const float2 scale)
 Transforms four 2D coordinates. More...
 
const float8 transform_bilinear (const float2 coord, const float2 scale)
 Transforms four 2D coordinates. More...
 
__kernel void scale_nearest_neighbour_nchw (__global uchar *in_ptr, uint in_stride_x, uint in_step_x, uint in_stride_y, uint in_step_y, uint in_offset_first_element_in_bytes, __global uchar *out_ptr, uint out_stride_x, uint out_step_x, uint out_stride_y, uint out_step_y, uint out_offset_first_element_in_bytes, const float input_width, const float input_height, const float scale_x, const float scale_y)
 Performs an affine transformation on an image interpolating with the NEAREAST NEIGHBOUR method. More...
 
__kernel void scale_bilinear_nchw (__global uchar *in_ptr, uint in_stride_x, uint in_step_x, uint in_stride_y, uint in_step_y, uint in_offset_first_element_in_bytes, __global uchar *out_ptr, uint out_stride_x, uint out_step_x, uint out_stride_y, uint out_step_y, uint out_offset_first_element_in_bytes, const float input_width, const float input_height, const float scale_x, const float scale_y)
 Performs an affine transformation on an image interpolating with the BILINEAR method. More...
 

Function Documentation

◆ scale_bilinear_nchw()

__kernel void scale_bilinear_nchw ( __global uchar *  in_ptr,
uint  in_stride_x,
uint  in_step_x,
uint  in_stride_y,
uint  in_step_y,
uint  in_offset_first_element_in_bytes,
__global uchar *  out_ptr,
uint  out_stride_x,
uint  out_step_x,
uint  out_stride_y,
uint  out_step_y,
uint  out_offset_first_element_in_bytes,
const float  input_width,
const float  input_height,
const float  scale_x,
const float  scale_y 
)

Performs an affine transformation on an image interpolating with the BILINEAR method.

Note
Sampling policy to used is passed as -DSAMPLING_POLICY_(TYPE) e.g. -DSAMPLING_POLICY_TOP_LEFT
Parameters
[in]in_ptrPointer to the source image. Supported data types: U8, S16.
[in]in_stride_xStride of the source image in X dimension (in bytes)
[in]in_step_xsrc_stride_x * number of elements along X processed per workitem(in bytes)
[in]in_stride_yStride of the source image in Y dimension (in bytes)
[in]in_step_ysrc_stride_y * number of elements along Y processed per workitem(in bytes)
[in]in_offset_first_element_in_bytesThe offset of the first element in the source image
[out]out_ptrPointer to the destination image. Supported data types: U8, S16. (Must be the same as the input)
[in]out_stride_xStride of the destination image in X dimension (in bytes)
[in]out_step_xdst_stride_x * number of elements along X processed per workitem(in bytes)
[in]out_stride_yStride of the destination image in Y dimension (in bytes)
[in]out_step_ydst_stride_y * number of elements along Y processed per workitem(in bytes)
[in]out_offset_first_element_in_bytesThe offset of the first element in the destination image
[in]input_widthInput image width
[in]input_heightInput image height
[in]scale_xThe scale factor along x dimension
[in]scale_yThe scale factor along y dimension

Definition at line 131 of file scale.cl.

138 {
140  Image out = CONVERT_TO_IMAGE_STRUCT(out);
141  const float2 r = (float2)(scale_x, scale_y);
142  const float8 tc = transform_bilinear(get_current_coords(), r);
143  vstore4(bilinear_interpolate_with_border(&in, tc, input_width, input_height, BORDER_SIZE), 0, (__global DATA_TYPE *)out.ptr);
144 }
#define CONVERT_TO_IMAGE_STRUCT(name)
Definition: helpers.h:311
#define DATA_TYPE
const DATA_TYPE4 bilinear_interpolate_with_border(const Image *in, const float8 coords, const float width, const float height, const float border_size)
Computes the bilinear interpolation for each set of coordinates in the vector coords and returns the ...
Definition: warp_helpers.h:95
#define CONVERT_TO_IMAGE_STRUCT_NO_STEP(name)
Definition: helpers.h:314
const float8 transform_bilinear(const float2 coord, const float2 scale)
Transforms four 2D coordinates.
Definition: scale.cl:58
Structure to hold Image information.
Definition: helpers.h:349
__global uchar * ptr
Pointer to the starting postion of the buffer.
Definition: helpers.h:351
const float2 get_current_coords()
Returns the current thread coordinates.
Definition: warp_helpers.h:68

References bilinear_interpolate_with_border(), CONVERT_TO_IMAGE_STRUCT, CONVERT_TO_IMAGE_STRUCT_NO_STEP, DATA_TYPE, get_current_coords(), Image::ptr, and transform_bilinear().

◆ scale_nearest_neighbour_nchw()

__kernel void scale_nearest_neighbour_nchw ( __global uchar *  in_ptr,
uint  in_stride_x,
uint  in_step_x,
uint  in_stride_y,
uint  in_step_y,
uint  in_offset_first_element_in_bytes,
__global uchar *  out_ptr,
uint  out_stride_x,
uint  out_step_x,
uint  out_stride_y,
uint  out_step_y,
uint  out_offset_first_element_in_bytes,
const float  input_width,
const float  input_height,
const float  scale_x,
const float  scale_y 
)

Performs an affine transformation on an image interpolating with the NEAREAST NEIGHBOUR method.

Input and output are single channel U8 or S16.

Note
Sampling policy to used is passed as -DSAMPLING_POLICY_(TYPE) e.g. -DSAMPLING_POLICY_TOP_LEFT
Parameters
[in]in_ptrPointer to the source image. Supported data types: U8, S16.
[in]in_stride_xStride of the source image in X dimension (in bytes)
[in]in_step_xsrc_stride_x * number of elements along X processed per workitem(in bytes)
[in]in_stride_yStride of the source image in Y dimension (in bytes)
[in]in_step_ysrc_stride_y * number of elements along Y processed per workitem(in bytes)
[in]in_offset_first_element_in_bytesThe offset of the first element in the source image
[out]out_ptrPointer to the destination image. Supported data types: U8, S16. (Must be the same as the input)
[in]out_stride_xStride of the destination image in X dimension (in bytes)
[in]out_step_xdst_stride_x * number of elements along X processed per workitem(in bytes)
[in]out_stride_yStride of the destination image in Y dimension (in bytes)
[in]out_step_ydst_stride_y * number of elements along Y processed per workitem(in bytes)
[in]out_offset_first_element_in_bytesThe offset of the first element in the destination image
[in]input_widthInput image width
[in]input_heightInput image height
[in]scale_xThe scale factor along x dimension
[in]scale_yThe scale factor along y dimension

Definition at line 95 of file scale.cl.

102 {
104  Image out = CONVERT_TO_IMAGE_STRUCT(out);
105  const float2 r = (float2)(scale_x, scale_y);
106  const float8 tc = clamp_to_border_with_size(transform_nearest(get_current_coords(), r), input_width, input_height, BORDER_SIZE);
107  vstore4(read_texels4(&in, convert_int8(tc)), 0, (__global DATA_TYPE *)out.ptr);
108 }
#define CONVERT_TO_IMAGE_STRUCT(name)
Definition: helpers.h:311
#define DATA_TYPE
#define CONVERT_TO_IMAGE_STRUCT_NO_STEP(name)
Definition: helpers.h:314
const float8 transform_nearest(const float2 coord, const float2 scale)
Transforms four 2D coordinates.
Definition: scale.cl:34
Structure to hold Image information.
Definition: helpers.h:349
__global uchar * ptr
Pointer to the starting postion of the buffer.
Definition: helpers.h:351
const DATA_TYPE4 read_texels4(const Image *in, const int8 coords)
Reads four texels from the input image.
Definition: warp_helpers.h:59
const float8 clamp_to_border_with_size(float8 coords, const float width, const float height, const float border_size)
Clamps the given coordinates to the borders according to the border size.
Definition: warp_helpers.h:34
const float2 get_current_coords()
Returns the current thread coordinates.
Definition: warp_helpers.h:68

References clamp_to_border_with_size(), CONVERT_TO_IMAGE_STRUCT, CONVERT_TO_IMAGE_STRUCT_NO_STEP, DATA_TYPE, get_current_coords(), Image::ptr, read_texels4(), and transform_nearest().

◆ transform_bilinear()

const float8 transform_bilinear ( const float2  coord,
const float2  scale 
)
inline

Transforms four 2D coordinates.

This is used to map the output coordinates to the input coordinates.

Parameters
[in]coord2D coordinates to transform.
[in]scaleinput/output scale ratio
Returns
a float8 containing 4 2D transformed values in the input image.

Definition at line 58 of file scale.cl.

59 {
60  const float4 in_x_coords = (float4)(coord.s0, 1 + coord.s0, 2 + coord.s0, 3 + coord.s0);
61 #ifdef SAMPLING_POLICY_TOP_LEFT
62  const float4 new_x = in_x_coords * (float4)(scale.s0);
63  const float4 new_y = (float4)(coord.s1 * scale.s1);
64  return (float8)(new_x.s0, new_y.s0, new_x.s1, new_y.s1, new_x.s2, new_y.s2, new_x.s3, new_y.s3);
65 #elif SAMPLING_POLICY_CENTER
66  const float4 new_x = (in_x_coords + ((float4)(0.5f))) * (float4)(scale.s0) - (float4)(0.5f);
67  const float4 new_y = (float4)((coord.s1 + 0.5f) * scale.s1 - 0.5f);
68  return (float8)(new_x.s0, new_y.s0, new_x.s1, new_y.s1, new_x.s2, new_y.s2, new_x.s3, new_y.s3);
69 #else /* SAMPLING_POLICY */
70 #error("Unsupported sampling policy");
71 #endif /* SAMPLING_POLICY */
72 }

References arm_compute::test::validation::scale.

Referenced by scale_bilinear_nchw().

◆ transform_nearest()

const float8 transform_nearest ( const float2  coord,
const float2  scale 
)
inline

Transforms four 2D coordinates.

This is used to map the output coordinates to the input coordinates.

Parameters
[in]coord2D coordinates to transform.
[in]scaleinput/output scale ratio
Returns
a float8 containing 4 2D transformed values in the input image.

Definition at line 34 of file scale.cl.

35 {
36 #ifdef SAMPLING_POLICY_TOP_LEFT
37  const float4 in_x_coords = (float4)(coord.s0, 1 + coord.s0, 2 + coord.s0, 3 + coord.s0);
38  const float4 new_x = in_x_coords * (float4)(scale.s0);
39  const float4 new_y = (float4)(coord.s1 * scale.s1);
40  return (float8)(new_x.s0, new_y.s0, new_x.s1, new_y.s1, new_x.s2, new_y.s2, new_x.s3, new_y.s3);
41 #elif SAMPLING_POLICY_CENTER
42  const float4 in_x_coords = (float4)(coord.s0, 1 + coord.s0, 2 + coord.s0, 3 + coord.s0);
43  const float4 new_x = (in_x_coords + ((float4)(0.5f))) * (float4)(scale.s0);
44  const float4 new_y = (float4)((coord.s1 + 0.5f) * scale.s1);
45  return (float8)(new_x.s0, new_y.s0, new_x.s1, new_y.s1, new_x.s2, new_y.s2, new_x.s3, new_y.s3);
46 #else /* SAMPLING_POLICY */
47 #error("Unsupported sampling policy");
48 #endif /* SAMPLING_POLICY */
49 }

References arm_compute::test::validation::scale.

Referenced by scale_nearest_neighbour_nchw().