void TranslationView::Resize()
{
    Size parentSize = ParentView->GetSize();
    Layout.SetSize(parentSize);

    State.EnsureSize(parentSize);

    Size bufferingDeviceContextSize = DeviceContextBuffer->GetSize();
    bufferingDeviceContextSize = Size(
        max(parentSize.GetWidth(), bufferingDeviceContextSize.GetWidth()),
        max(parentSize.GetHeight(), bufferingDeviceContextSize.GetHeight()));
    DeviceContextBuffer->Resize(bufferingDeviceContextSize);

    ApplyViewState(true);

    Renderer* renderer = RenderingContext->GetRenderer();

    if(GetModel()->GetTranslateResult().IsEmptyResult())
    {
        renderer->DrawRect(Rect(0, headerHeight, State.GetSize().GetWidth(), State.GetSize().GetHeight() - headerHeight), LightGrayBrush);
    }

    RenderSeparator(renderer, max(State.GetContentSize().GetWidth(), State.GetSize().GetWidth()));

    renderer->Render(DeviceContextBuffer);
    RenderingContext->ReleaseRenderer(renderer);

    Draw();
}
Size TranslationView::RenderContent(Renderer* renderer, TranslationViewModel* model)
{
    headerComponent->Render();

    Size contentSize;
    if (model->GetTranslateResult().IsEmptyResult())
    {
        translateResultComponent->MakeHidden();

        Size backgroundSize = Size(
            max(ParentView->GetSize().GetWidth(), headerComponent->GetBoundingRect().GetWidth()),
            ParentView->GetSize().GetHeight() - headerHeight);
        renderer->DrawRect(Rect(Point(0, headerHeight), backgroundSize), BackgroundBrush);

        contentSize = headerComponent->GetBoundingRect().GetSize();
    }
    else
    {
        translateResultComponent->MakeVisible();
        translateResultComponent->Render();

        contentSize = Size(
            max(headerComponent->GetBoundingRect().GetWidth(), translateResultComponent->GetBoundingRect().GetWidth()),
            headerComponent->GetBoundingRect().GetHeight() + translateResultComponent->GetBoundingRect().GetHeight());
    }

    RenderSeparator(renderer, max(GetSize().GetWidth(), contentSize.GetWidth()));

    return contentSize;
}
void loadImage(sf::Image* Imageptr, sf::Sprite* Spriteptr, Size sizeOfImage, int** imageDataRed,int** imageDataBlue,int** imageDataGreen)
{
	int imageWidth  = sizeOfImage.GetWidth();
	int imageHeight = sizeOfImage.GetHeight();
	
	
                sf::Uint8* Img1 = (sf::Uint8*) calloc(imageWidth*imageHeight*4, sizeof(sf::Uint8));
                
               
                for(int i = 0 ; i < imageHeight ; i++)
                 {
                 for(int j = 0 ; j < imageWidth ; j++)
                        {
                        
                        
                         if(imageDataRed[i][j] > 0)
                         Img1[i*imageWidth*4 + j*4 ] = imageDataRed[i][j];
                         
                         if(imageDataBlue[i][j] > 0)
                         Img1[i*imageWidth*4 + j*4 +1] = imageDataBlue[i][j];
                         
                         if(imageDataGreen[i][j] > 0)
                         Img1[i*imageWidth*4 + j*4 +2] = imageDataGreen[i][j];
                         
                         if(imageDataRed[i][j] > 255)
                         Img1[i*imageWidth*4 + j*4 ] = 255;
                         
                         if(imageDataBlue[i][j] > 255)
                         Img1[i*imageWidth*4 + j*4 +1] = 255;
                         
                         if(imageDataGreen[i][j] > 255)
                         Img1[i*imageWidth*4 + j*4 +2] = 255;
			  
                         Img1[i*imageWidth*4 + j*4 +3] = 255;
                         
                         }
                 } 
	Imageptr->LoadFromPixels(imageWidth,imageHeight,Img1);        
        Spriteptr->SetImage(*Imageptr);	
        free(Img1);
        
                
}
int main(int argc ,char** argv)
{
    // Create the main rendering window
        
        /*
        const double PI = atan(1.0f) * 4.0f;
        const int maxValue = 100; 
        double sincArray1[maxValue];
        int upScale = 2;
        int downScale = 1;
        
        
           
        CalculateSincValues( sincArray1, upScale,  maxValue);
        /*for(int i = 0 ; i < maxValue ; i++)
        {
                printf("sincArray[%d] = [%f] \n ",i,sincArray1[i]);
         }
          */      
        
	
	
	
	
	LargeImage Limg;
	
	        
   	
        Limg.LoadFromImage(argv[1]);
        Limg.WriteLargeImage(argv[2]);
        printf("Image Converted and written! \n");
        fflush(stdout);
        
        
       
        //Size sizeimg = Limg.GetLargeImageSize();
        //int numbOfLayers = Limg.GetNumbOfLayers();
        //Size numbOfBlocks = Limg.GetNumbOfBlocks(1);
        //int noOfBlocks = numbOfBlocks.GetWidth();
        //CompressedBlock*** layer = Limg.GetLayer();
       //printf("the width of the LargeImage = [%d] \n",sizeimg.GetWidth());
        //Size sizeCoarseImg = Limg.GetCoarseImageSize();
        
        
        RenderImage Rimg(Limg);
        
        
        
        
        
        
        
        
        
        Size windowSize = Rimg.GetWindowSize();
        int windowWidth  = windowSize.GetWidth(); 
        int windowHeight = windowSize.GetHeight();
        
         sf::RenderWindow App(sf::VideoMode(windowWidth,windowHeight, 32), "SFML Graphics");
         const sf::Input& Input = App.GetInput();

        int** windowImageRed = Rimg.GetChildImageRed();
        int** windowImageBlue = Rimg.GetChildImageBlue();
        int** windowImageGreen = Rimg.GetChildImageGreen(); 
        
       /* 
       char** writeImgRed = (char**) calloc (windowHeight, sizeof(char*));
       char** writeImgBlue = (char**) calloc (windowHeight, sizeof(char*));
       char** writeImgGreen = (char**) calloc (windowHeight, sizeof(char*));
       for(int i = 0 ; i < windowHeight ; i++)
       {
       		writeImgRed[i] = (char*) calloc (windowWidth, sizeof(char));
       		writeImgBlue[i] = (char*) calloc (windowWidth, sizeof(char));
       		writeImgGreen[i] = (char*) calloc (windowWidth, sizeof(char));
       }
       
       for(int i = 0 ; i < windowHeight ; i++)
       {
       		for(int j = 0 ; j < windowWidth ; j++)
       		{	if(windowImageRed[i][j] > 255 )
       			writeImgRed[i][j] = 255;
       			if(windowImageRed[i][j] > 0)
       			writeImgRed[i][j] = (char) windowImageRed[i][j];
       			
       			if(windowImageBlue[i][j] > 255 )
       			writeImgBlue[i][j] = 255;
       			if(windowImageBlue[i][j] > 0)
       			writeImgBlue[i][j] = (char) windowImageBlue[i][j];
       			
       			if(windowImageGreen[i][j] > 255 )
       			writeImgGreen[i][j] = 255;
       			if(windowImageGreen[i][j] > 0)
       			writeImgGreen[i][j] = (char) windowImageGreen[i][j];
       		}
       }
       */ 
        sf::Uint8* Img = (sf::Uint8*) calloc(windowWidth*windowHeight*4, sizeof(sf::Uint8));
        
        for(int i = 0 ; i < windowHeight ; i++)
                {
                 for(int j = 0 ; j < windowWidth ; j++)
                        {
                         if(windowImageRed[i][j] > 0)
                         Img[i*(windowWidth)*4 + j*4 ] = windowImageRed[i][j];
                        
                         if(windowImageBlue[i][j] > 0)
                         Img[i*(windowWidth)*4 + j*4 + 1 ] = windowImageBlue[i][j];
                        
                         if(windowImageGreen[i][j] > 0)
                         Img[i*(windowWidth)*4 + j*4 + 2] = windowImageGreen[i][j];
                         
                         if(windowImageRed[i][j] >255)
                         Img[i*(windowWidth)*4 + j*4 ] = 255;
                         
                         if(windowImageBlue[i][j] >255)
                         Img[i*(windowWidth)*4 + j*4 + 1] = 255;
                         
                         
                         if(windowImageGreen[i][j] >255)
                         Img[i*(windowWidth)*4 + j*4 + 2] = 255;
                         
                         
                        
                         Img[i*(windowWidth)*4 + j*4 +3] = 255;
                         
                         }
                 } 
          
        //write_png_file(argv[2], windowSize,(char**) writeImg );   
          
    // Load the sprite image from a file
    sf::Image Image;
    sf::Image* Imageptr = &Image;
    Image.LoadFromPixels(windowWidth,windowHeight,Img);
     //   return EXIT_FAILURE;

    // Create the sprite
    sf::Sprite Sprite(Image);
    sf::Sprite* Spriteptr = &Sprite;
    free(Img);

    // Change its properties
    //Sprite.SetColor(sf::Color(0, 255, 255, 128));
    //Sprite.SetPosition(200.f, 100.f);
    //Sprite.SetScale(2.f, 2.f);

    // Start game loop
    double zoom = 1;
    int pixelX = 0;
    int pixelY = 0; 
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Get elapsed time
        float ElapsedTime = App.GetFrameTime();
        

        if (Event.Key.Code == sf::Key::F1)
	{
	    sf::Image Screen = App.Capture();
	    Screen.SaveToFile("screenshot.png");
	}
	 if (App.GetInput().IsKeyDown(sf::Key::Z))
	 {
	 	zoom = zoom + ElapsedTime;
	 	//if(zoom > 2) zoom = 2;
	 	if(zoom < 1) zoom = 1;
	        Rimg.updateZoomLevel( zoom);
	        printf(" zoom = [%f] \n", zoom);
	        fflush(stdout);
	 	
	 }
	 if (App.GetInput().IsKeyDown(sf::Key::X))
	 {
	 	zoom = zoom - ElapsedTime;
	 	//if(zoom > 2) zoom = 2;
	 	if(zoom < 1) zoom = 1;
	        Rimg.updateZoomLevel( zoom);
	        printf(" zoom = [%f] \n", zoom);
	        fflush(stdout);
	 	
	 }
	 
	 if (App.GetInput().IsKeyDown(sf::Key::Right))
	 {
	 	pixelX = pixelX + 100*ElapsedTime;
	 	
	        Rimg.updatePivotPixel(pixelX, pixelY);
	        printf(" pivotPixel = [%d][%d] \n", pixelX , pixelY);
	        fflush(stdout);
	        //callbackJ( windowSize, &Rimg, Imageptr, Spriteptr);	
	 	
	 }
	 
	 if (App.GetInput().IsKeyDown(sf::Key::Down))
	 {
	 	pixelY = pixelY + 100*ElapsedTime;
	 	
	        Rimg.updatePivotPixel(pixelX, pixelY);
	        printf(" pivotPixel = [%d][%d] \n", pixelX , pixelY);
	        fflush(stdout);
	 	//callbackJ( windowSize, &Rimg, Imageptr, Spriteptr);	
	 }
        
        if (App.GetInput().IsKeyDown(sf::Key::Left))
	 {
	 	pixelX = pixelX - 10*ElapsedTime;
	 	if(pixelX < 0) pixelX = 0;
	        Rimg.updatePivotPixel(pixelX, pixelY);
	        printf(" pivotPixel = [%d][%d] \n", pixelX , pixelY);
	        fflush(stdout);
	 	//callbackJ( windowSize, &Rimg, Imageptr, Spriteptr);	
	 }
        
        if (App.GetInput().IsKeyDown(sf::Key::Up))
	 {
	 	pixelY = pixelY - 10*ElapsedTime;
	 	if(pixelY < 0) pixelY = 0;
	        Rimg.updatePivotPixel(pixelX, pixelY);
	        printf(" pivotPixel = [%d][%d] \n", pixelX , pixelY);
	        fflush(stdout);
	 	//callbackJ( windowSize, &Rimg, Imageptr, Spriteptr);	
	 }
        
        
         unsigned int MouseX          = Input.GetMouseX();
	 unsigned int MouseY          = Input.GetMouseY();

        
        
        if (App.GetInput().IsKeyDown(sf::Key::J))    callbackJ( windowSize, &Rimg, Imageptr, Spriteptr);
        if (App.GetInput().IsKeyDown(sf::Key::L))
	 {
	 	zoom = 2;
	 	//if(zoom > 2) zoom = 2;
	 	if(zoom < 1) zoom = 1;
	        Rimg.updateZoomLevel( zoom);
	        printf(" zoom = [%f] \n", zoom);
	        fflush(stdout);
	 	
	 } 
	 
	if (App.GetInput().IsKeyDown(sf::Key::K))	
	{
	
	 printf(" MouseX = [%d]:MouseY =[%d] \n",MouseX,MouseY);
	 fflush(stdout);
	 }       

        // Clear screen
        App.Clear();

        // Display sprite in our window
        App.Draw(Sprite);

        // Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}