Any function to rotate image along axis?

 

Whats wrong with this function?


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Rotate(const int x_cent, const int y_cent,    // Rotation around this point
            const double ang,                      // The rotation angle
            const string _resource,                // File to be rotated
            const string object)                   // The end object need to be updated
  {
   uint In[];   // Array to convert input image the file
   uint Out[];  // Array to receive the file
   int  Width;
   uint hr;

   if(!ResourceReadImage(_resource,In,Width,hr))
     {
      Print("Еrror loading resource: ",_resource);
      return;
     }

   ::ArrayCopy(Out, In);

   if(!ang)
      return;

   const int Height = ArraySize(In) / Width;
   int y320[];

   ::ArrayResize(y320, Height);

   for(int n=0; n<Height; n++)
      y320[n]=n*Width;

   ::ArrayResize(Out, ::ArraySize(In));
   ::ArrayInitialize(Out, 0);

   const double Sin = ::MathSin(-ang);
   const double Cos = ::MathCos(-ang);

   int scn = 0;
   for(int y = 0; y < Height; y++)
     {
      for(int x=0; x < Width; x++)
        {
         const int x2 = x - x_cent;
         const int y2 = y - y_cent;

         const int x1 = (int)(Cos * x2 - Sin * y2) + x_cent;
         const int y1 = (int)(Sin * x2 + Cos * y2) + y_cent;

         Out[scn + x]= ((x1<0) || (x1>=Width) || (y1<0) || (y1>=Height)) ? 0 : In[x1+y320[y1]];
        }
      scn += Width;
     }

   int HeightNew = ArraySize(Out) / Width;

   if(!ResourceCreate("myfileNew", Out, Width, HeightNew,0,0,Width, COLOR_FORMAT_ARGB_NORMALIZE))
     {
      Print("Еrror creating resource: ", _resource);
      return;
     }
   ObjectSetString(0,object, OBJPROP_BMPFILE, "::myfileNew");
  }
//+------------------------------------------------------------------+