/*
    Robot Interface Remote Client
    (C) 2006 Jason Hunt
    nulluser@gmail.com
    
    file: camera.cpp
*/


#include <windows.h>
#include <stdio.h>

#include "types.h"
#include "window.h"
#include "display.h"
#include "vfwmod.h"
#include "target.h"

unsigned int image_x_size = 0;//320;           // Size of camera image
unsigned int image_y_size = 0;//200;

unsigned char *compressed_image = NULL;  // Buffer for compressed

color_type *image_buffer = NULL;         // Buffer for camera data
BITMAPINFO image_buffer_info;            // Bitmap info for camera

bool camera_active = false;


/* Setup buffer for camera image */
void image_start( void )
{    
    if (image_buffer != NULL) free(image_buffer);    

    image_buffer = (color_type *) malloc(image_x_size * image_y_size * sizeof(color_type));
        
    if (image_buffer == NULL)
    {            
        add_line("Unable to create camera buffer");
        return;
    }        
    
    if (compressed_image != NULL) free(compressed_image);    

    compressed_image = (byte *) malloc(image_x_size * image_y_size * sizeof(color_type) * 2);
        
    if (compressed_image == NULL)
    {            
        add_line("Unable to create compressed camera buffer");
        return;
    }      
    
    char r[300];
    sprintf(r, "Size: %d  x  %d ", image_x_size, image_y_size);
    add_line(r);

    memset(&image_buffer_info.bmiHeader, 0, sizeof(image_buffer_info.bmiHeader));

    // Set the new Bitmap information
    image_buffer_info.bmiHeader.biSize = sizeof(image_buffer_info.bmiHeader);
    image_buffer_info.bmiHeader.biWidth = image_x_size;
    image_buffer_info.bmiHeader.biHeight = image_y_size; 
    image_buffer_info.bmiHeader.biPlanes = 1;
    image_buffer_info.bmiHeader.biBitCount = 32;
    image_buffer_info.bmiHeader.biCompression = BI_RGB;
    image_buffer_info.bmiHeader.biSizeImage = image_x_size * image_y_size * 2;
    image_buffer_info.bmiHeader.biClrUsed = 0;
    image_buffer_info.bmiHeader.biClrImportant = 0;

    // Resize main window to reflact camera_size


    display_resize();
    resize_target_buffers();

/*    if (image_x_size > 0 && image_y_size > 0)
    {

        WINDOWPLACEMENT p;                      // Holds window data

        p.length = sizeof(WINDOWPLACEMENT);     // Setup struct
        GetWindowPlacement(main_win, &p);       // Get window information
        
        display_x = image_x_size + extra_display_width; //+ 12;
        display_y = image_y_size + text_area_height + 34;
        
        p.rcNormalPosition.right = p.rcNormalPosition.left + display_x;
        p.rcNormalPosition.bottom= p.rcNormalPosition.top + display_y;
            
        SetWindowPlacement(main_win, &p);
    
        resize_target_buffers();
    }*/
}
/* End of camera_setup_buffer */



/* Stop camera system */
void image_stop( void )
{
    if (image_buffer)
        free(image_buffer);      
  
    if (compressed_image)
        free(compressed_image);      

}
/* End of stop_camera */







