SHARE
TWEET

Untitled

a guest Apr 18th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. __kernel void pixelArtUpscale(__global const int* inputImage, __global int* outputImage, const int sourceWidth){
  2.  
  3.     int lx = get_local_id(0) + 1;
  4.     int ly = get_local_id(1) + 1;
  5.  
  6.     int gx = get_global_id(0);
  7.     int gy = get_global_id(1);
  8.  
  9.     __local unsigned int localBuffer[32 + 2][32 + 2];
  10.  
  11.     const size_t rowcol = (get_global_id(1) * get_global_size(0) + get_global_id(0));
  12.     localBuffer[lx][ly] = inputImage[rowcol];
  13.  
  14.     // load pixel left and right when at the edge
  15.     if (lx == 1){
  16.         if (rowcol % get_global_size(0) == 0){
  17.             localBuffer[lx - 1][ly] = inputImage[rowcol];
  18.         } else{
  19.             localBuffer[lx - 1][ly] = inputImage[rowcol - 1];
  20.         }
  21.     }
  22.     else if (lx == get_local_size(0)){
  23.         if (rowcol % get_global_size(0) == get_global_size(0) - 1){
  24.             localBuffer[lx + 1][ly] = inputImage[rowcol];
  25.         } else{
  26.             localBuffer[lx + 1][ly] = inputImage[rowcol + 1];
  27.         }
  28.     }
  29.  
  30.     // load pixel top and bottom when at the edge
  31.     if (ly == 1){
  32.         if (rowcol >= get_global_size(0)) {
  33.             localBuffer[lx][ly - 1] = inputImage[rowcol - get_global_size(0)];
  34.         } else {
  35.             localBuffer[lx][ly - 1] = inputImage[rowcol];
  36.         }
  37.     }
  38.     else if (ly == get_local_size(1)){
  39.         if (rowcol < get_global_size(0)*get_global_size(1) - get_global_size(0)){
  40.             localBuffer[lx][ly + 1] = inputImage[rowcol + get_global_size(0)];
  41.         } else {
  42.             localBuffer[lx][ly + 1] = inputImage[rowcol];
  43.         }
  44.     }
  45.  
  46.     // load 4 corner pixel
  47.     const size_t Localrowcol = (get_local_id(1) * get_local_size(0) + get_local_id(0));
  48.     if (Localrowcol == 0) {
  49.         localBuffer[lx - 1][ly - 1] = inputImage[rowcol];
  50.     }
  51.     if (Localrowcol == get_local_size(0) - 1) {
  52.         localBuffer[lx + 1][ly - 1] = inputImage[rowcol];
  53.     }
  54.     if (Localrowcol == get_local_size(0)*get_local_size(1) - get_local_size(0)){
  55.         localBuffer[lx - 1][ly + 1] = inputImage[rowcol];
  56.     }
  57.     if (Localrowcol == get_local_size(0)*get_local_size(1) - 1){
  58.         localBuffer[lx + 1][ly + 1] = inputImage[rowcol];
  59.     }
  60.  
  61.     // wait on all to be filled
  62.     barrier(CLK_LOCAL_MEM_FENCE);
  63.  
  64.  
  65.     int A = localBuffer[lx - 1][ly - 1];
  66.     int B = localBuffer[lx][ly - 1];
  67.     int C = localBuffer[lx + 1][ly - 1];
  68.     int D = localBuffer[lx - 1][ly - 1];
  69.     int E = localBuffer[lx][ly];
  70.     int F = localBuffer[lx + 1][ly];
  71.     int G = localBuffer[lx - 1][ly + 1];
  72.     int H = localBuffer[lx][ly + 1];
  73.     int I = localBuffer[lx + 1][ly + 1];
  74.  
  75.     //Eagle impleentation
  76.     int E00 = E;
  77.     int E10 = E;
  78.     int E01 = E;
  79.     int E11 = E;
  80.  
  81.     if(D == A && A == B) E00 = A;
  82.     if(B == C && C == F) E01 = C;
  83.     if(D == G && G == H) E10 = G;
  84.     if(F == I && I == H) E11 = I;
  85.  
  86.  
  87.     outputImage[2 * gy * (2 * get_global_size(0)) + 2 * gx] = E00;
  88.     outputImage[ 2* gy * (2 * get_global_size(0)) + 2 * gx + 1] = E01;
  89.     outputImage[(2 * gy + 1) * (2 * get_global_size(0)) + 2 * gx] = E10;
  90.     outputImage[(2 * gy + 1) * (2 * get_global_size(0)) + 2 * gx + 1] = E11;
  91.  
  92. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top