/*******
 * picture-splice.c
 *
 * Example program takes two pictures, using the Scribbler 2 
 *  and shows a picture composed of pieces of the two pictures
 *
 * Author: April O'Neill
 * Created: 4 August 2011
 *
 * Revised:  30 May 2015 by Henry Walker
 *           row/column references changed to reflect 2D matrix notation
 *
 *******/

#include <stdio.h>
#include "MyroC.h"


int
main()
{
  int i, j, width, height, midwidth, midheight;
  Picture  pic1,  pic2,  spliced;
  char connection_name [40] = "B4:D8:A9:00:09:58";  // Fluke 2 0958
  //char connection_name [40] = "B4:D8:A9:00:09:1B";  // Fluke 2 091B
  rConnect (connection_name);
  //rConnect ("/dev/rfcomm0");

  pic1 = rTakePicture();
  height = pic1.height;
  midheight = height / 2;
  width = pic1.width;
  midwidth = width / 2;

  rTurnLeft (1, 1);
  pic2 = rTakePicture();
  spliced = rTakePicture();
  rDisplayPicture (&pic1, 5, "pic1");
  rDisplayPicture (&pic2, 5, "pic2");

  for (i = 0; i < height ; i++)
    {
      for (j = 0; j < width; j++)
        {
          if ( ( (i < midheight) && (j < midwidth))
               || ( (i > midheight) && (j > midwidth)) )
          spliced.pix_array[i][j]=pic1.pix_array[i][j];           
else
            spliced.pix_array[i][j]=pic2.pix_array[i][j]; 

        }
    }

  rDisplayPicture (&spliced,10,"spliced");
  rDisconnect();
  return 0;
}
