Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating affine for test. #311

Open
wants to merge 2 commits into
base: affine
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 45 additions & 18 deletions pyclesperanto_prototype/_tier8/affine_transform_2d_x.cl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


#ifndef SAMPLER_FILTER
#define SAMPLER_FILTER CLK_FILTER_LINEAR
#define SAMPLER_FILTER CLK_FILTER_NEAREST
#endif

#ifndef SAMPLER_ADDRESS
Expand All @@ -53,43 +53,70 @@ __kernel void affine_transform_2d(
uint i = get_global_id(0);
uint j = get_global_id(1);

uint Nx = GET_IMAGE_WIDTH(output);
uint Ny = GET_IMAGE_HEIGHT(output);
uint Nx = GET_IMAGE_WIDTH(input)-1;
uint Ny = GET_IMAGE_HEIGHT(input)-1;

float x = i+0.5f;
float y = j+0.5f;
float x = i;
float y = j;

float y2 = (mat[3]*x+mat[4]*y+mat[5]);
float x2 = (mat[0]*x+mat[1]*y+mat[2]);

int2 coord_norm = (int2)(x2,y2);

// float2 frac_coord = (float2)(x2-floor(x2),y2-floor(y2));
float2 frac_coord = (float2)(x2/Nx,y2/Ny);
float2 frac_coord = (float2)(x2-coord_norm.x,y2-coord_norm.y);

float pix = 0;
if (x2 >= 0 && y2 >= 0 &&
x2 < GET_IMAGE_WIDTH(input) && y2 < GET_IMAGE_HEIGHT(input)
) {

// Get the corrdinates and color of the four surrounding pixels
int2 top_left_coord = coord_norm;
int2 top_right_coord = coord_norm + (int2)(1, 0);
int2 bottom_left_coord = coord_norm + (int2)(0, 1);
int2 bottom_right_coord = coord_norm + (int2)(1, 1);


// float2 top_left_coord = (float2)(coord_norm.x,coord_norm.y);
// float2 top_right_coord = (float2)((coord_norm.x+1),(coord_norm.y));
// float2 bottom_left_coord = (float2)((coord_norm.x),(coord_norm.y+1));
// float2 bottom_right_coord = (float2)((coord_norm.x+1),(coord_norm.y+1));

float2 top_left_coord = (float2)(coord_norm.x,coord_norm.y);
float2 top_right_coord =
(float2)((coord_norm.x+1) > Nx?(coord_norm.x-1):(coord_norm.x+1),(coord_norm.y));
float2 bottom_left_coord =
(float2)((coord_norm.x),(coord_norm.y+1)>Ny?(coord_norm.y-1):(coord_norm.y+1));
float2 bottom_right_coord =
(float2)((coord_norm.x+1)>Nx?(coord_norm.x-1):(coord_norm.x+1),(coord_norm.y+1)>Ny?(coord_norm.y-1):(coord_norm.y+1));

float top_left_color = (float) (READ_input_IMAGE(input, sampler, POS_input_INSTANCE(top_left_coord.x, top_left_coord.y, 0, 0)).x);
float top_right_color = (float) (READ_input_IMAGE(input, sampler, POS_input_INSTANCE(top_right_coord.x, top_right_coord.y, 0, 0)).x);
float bottom_left_color = (float) (READ_input_IMAGE(input, sampler, POS_input_INSTANCE(bottom_left_coord.x, bottom_left_coord.y, 0, 0)).x);
float bottom_right_color = (float) (READ_input_IMAGE(input, sampler, POS_input_INSTANCE(bottom_right_coord.x, bottom_right_coord.y, 0, 0)).x);

printf("coordinates: (%f,%f),%f (%f,%f),%f (%f,%f),%f (%f,%f),%f",
top_left_coord.x, top_left_coord.y, top_left_color,
top_right_coord.x, top_right_coord.y, top_right_color,
bottom_left_coord.x, bottom_left_coord.y,bottom_left_color,
bottom_right_coord.x, bottom_right_coord.y, bottom_right_color);

// if(top_left_color == top_right_color){
// top_right_coord = (float2)((coord_norm.x-1),(coord_norm.y));
// top_right_color = (float) (READ_input_IMAGE(input, sampler, POS_input_INSTANCE(top_right_coord.x, top_right_coord.y, 0, 0)).x);
// }
// if(top_left_color == bottom_left_color){
// bottom_left_coord = (float2)((coord_norm.x),(coord_norm.y-1));
// bottom_left_color = (float) (READ_input_IMAGE(input, sampler, POS_input_INSTANCE(bottom_left_coord.x, bottom_left_coord.y, 0, 0)).x);
// }
// if(top_left_color == bottom_right_color){
// bottom_right_coord = (float2)((coord_norm.x-1),(coord_norm.y-1));
// bottom_right_color = (float) (READ_input_IMAGE(input, sampler, POS_input_INSTANCE(bottom_right_coord.x, bottom_right_coord.y, 0, 0)).x);
// }

pix = (float) mix(mix(top_left_color, top_right_color, frac_coord.x), mix(bottom_left_color, bottom_right_color, frac_coord.x), frac_coord.y);
// pix = (float) (1 - frac_coord.y) * ((1 - frac_coord.x) * top_left_color + frac_coord.x * top_right_color) + frac_coord.y * ((1 - frac_coord.x) * bottom_left_color + frac_coord.x * bottom_right_color);
// pix = (float)(READ_input_IMAGE(input, sampler, POS_input_INSTANCE(x2, y2, 0, 0)).x);

// pix = frac_coord.x * frac_coord.y * top_left_color +
// (1-frac_coord.x) * frac_coord.y * top_right_color +
// frac_coord.x * (1-frac_coord.y) * bottom_right_color +
// (1-frac_coord.x) * (1-frac_coord.y) * bottom_left_color;
}

int2 pos = (int2){i, j};

WRITE_output_IMAGE(output, POS_output_INSTANCE(i, j, 0, 0), CONVERT_output_PIXEL_TYPE(pix));

}
}
Loading