#include <iostream>
#include <strings.h>
#include <stdlib.h>
#include <stdio.h>
#define WIDTH 10000
#define HEIGHT 10000
///DONE:
/// Mas o menos crea la imagen.
/// Cuando se pasa de 1000 ambos, ocurre una falla.
/// del tipo Violacion de Segmento.
///Error oculto solucionado: No consideraba las iniciales BM (2 bytes) al tamaño
///del archivo, muy importantes.
///TO-DO:
/// -Fill the image with interesting data.
/// -El programa lo unico que debe hacer es soportar colorear de azul,
/// un cuadro de 1000, pixeles.
/// -Hay un problema con lo que significa el manejo del formato, en si mismo
/// -No puedo exceder los 1000px, debe ser algo relacionado con el padding.
/// -Si grabó tal cual se le asignaron los valores a la matriz,
/// por tanto el error es de interpretacion. La escritura está bien.
/// aprender como manejar los bytes y dibujar un cuadrado, o algo así.
/// -Si soportó el array de bmp_pixeles, pero grabó basura
/// -Sin embargo, el formato quedó intacto.
using namespace std;
char bmp_sign[2] = {'B', 'M'}; /// = "BM";
struct bmp_format{
unsigned int filesize; /// = filesize
unsigned short reserved_a; /// = 0;
unsigned short reserved_b; /// = 0;
unsigned int start_of_data_image; /// = 54
unsigned int bitmap_header_size;
unsigned int width;
unsigned int height;
unsigned short number_of_planes;
unsigned short bits_per_pixel;// = 1;
unsigned int compression; /// = 0;
unsigned int size_of_image; /// = 0;
unsigned int horizontal_resolution; /// = 0
unsigned int vertical_resolution; /// = 0;
unsigned int size_of_color_palette;
unsigned int counter_of_interesting_colors;
};
struct bmp_pixel{
unsigned char red;
unsigned char green;
unsigned char blue;
};
int main()
{
FILE *bmp_file;
FILE *debug_image;
FILE *debug_binary;
printf("Abriendo archivos bmp y debug respectivos\n");
bmp_file = fopen("C:\\output.bmp", "w+b");
//debug_image = fopen("C:\\image_in_bin.hex", "w+b");
//debug_binary = fopen("C:\\memory_in_bin.hex", "w+b");
bmp_format bmp_format;
memset(&bmp_format, 0, sizeof(bmp_format));
printf("Estableciendo bmp format a NULL para mantenerlo limpio\n");
unsigned int number_of_data_bytes;
///Initializing data
///TO-DO: Design a better method to adjust values than
///hard-code it.
bmp_format.start_of_data_image = 54;
bmp_format.bitmap_header_size = 40;
bmp_format.width = WIDTH;
bmp_format.height = HEIGHT;
bmp_format.number_of_planes = 1;
bmp_format.bits_per_pixel = 24;
bmp_format.compression = 0;
bmp_format.size_of_image = number_of_data_bytes;
bmp_format.horizontal_resolution = 0;
bmp_format.vertical_resolution = 0;
bmp_format.size_of_color_palette = 0;
bmp_format.counter_of_interesting_colors = 0;
///TODO: This value must have a formule:
/// -bmp_header + ([width * height] * 3 bytes of rgb)
///TODO: Use it over hardcoded values.
number_of_data_bytes = (WIDTH * HEIGHT) * 3;
bmp_format.filesize = 2 + sizeof(bmp_format) + number_of_data_bytes;
printf("Ya fueron rellenados todos los campos de bmp format!!\n");
fwrite((char *) &bmp_sign, 2, 1, bmp_file);
fwrite((char *) &bmp_format, sizeof(bmp_format), 1, bmp_file);
printf("Grabando bmp format + la señal de BM\n");
/*struct bmp_pixel pixeles[WIDTH][HEIGHT];
*/
char pixeles[WIDTH * HEIGHT * 3];
for(int i = 0; i < number_of_data_bytes; i++){
pixeles[i] = 0x50;
}
/*
///Clear pixeles and zero it to avoid filter my
///system data on memory swap.
memset(pixeles, 0, sizeof(pixeles));
for(int e = 0; e < WIDTH; e = e + 5){
for(int i = 0; i < HEIGHT; i++){
pixeles[i][e].blue = 0xDE;
pixeles[i][e].red = 0xAD;
pixeles[i][e].green = 0xff;
}
}*/
///fwrite((char *) pixeles, number_of_data_bytes, 1, debug_image);
///fwrite((char *) pixeles, number_of_data_bytes, 1, debug_binary);
///fwrite((char *) pixeles, (WIDTH * HEIGHT * 3), 1, bmp_file);
fclose(bmp_file);
cout << "Dibujador de BMP. En progreso y con futuro." << endl;
return 0;
}