Advertisement
NightFox

MSX Screen 2 BMP converter

Jun 20th, 2015
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 21.18 KB | None | 0 0
  1. /*
  2. -------------------------------------------------------------------------------
  3.     MSX Image to VRAM converter
  4.     Genera desde una imagen las tablas de PATTERN, COLOR & NAME
  5.     para usarlas en el modo SCREEN 2.
  6.     (c)2015 by Cesar Rincon "NightFox"
  7.     http://www.nightfoxandco.com
  8.     Version 0.1 Alpha
  9. -------------------------------------------------------------------------------
  10. */
  11.  
  12.  
  13.  
  14. /*
  15. -------------------------------------------------------------------------------
  16.     Includes
  17. -------------------------------------------------------------------------------
  18. */
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23.  
  24.  
  25.  
  26. /*
  27. -------------------------------------------------------------------------------
  28.     Definicion de tipos
  29. -------------------------------------------------------------------------------
  30. */
  31.  
  32. typedef signed char s8;
  33. typedef unsigned char u8;
  34. typedef signed short s16;
  35. typedef unsigned short u16;
  36. typedef signed int s32;
  37. typedef unsigned int u32;
  38.  
  39.  
  40.  
  41. /*
  42. -------------------------------------------------------------------------------
  43.     Variables globales
  44. -------------------------------------------------------------------------------
  45. */
  46.  
  47. typedef struct {
  48.     u32 width;              // Ancho de la imagen
  49.     u32 height;             // Alto de la imagen
  50.     u8* data;             // Datos de la imagen
  51.     u8* raw[3];           // Tiles en bruto
  52.     u8* patterns[3];      // Buffer para los patterns
  53.     u8* colors[3];        // Buffer para los colores
  54.     u8* names[3];         // Buffer para los nombres (mapa)
  55.     u32 tiles[3];           // Tiles en cada "banco" (3)
  56.     u32 map_pos[3];         // Posicion en el mapa
  57. } img_info;
  58. img_info img;               // Guarda la imagen cargada y su informacion
  59.  
  60.  
  61. void CleanBuffers(void) {
  62.  
  63.     free(img.data);
  64.     img.data = NULL;
  65.  
  66.     int n = 0;
  67.     for (n = 0; n < 3; n ++) {
  68.         free(img.raw[n]);
  69.         img.raw[n] = NULL;
  70.         free(img.patterns[n]);
  71.         img.patterns[n] = NULL;
  72.         free(img.colors[n]);
  73.         img.colors[n] = NULL;
  74.         free(img.names[n]);
  75.         img.names[n] = NULL;
  76.     }
  77.  
  78. }
  79.  
  80.  
  81. /*
  82. -------------------------------------------------------------------------------
  83.     Carga el archivo BIPMAP y conviertelo a RAW
  84. -------------------------------------------------------------------------------
  85. */
  86.  
  87. // Funcion NF_LoadBMP();
  88. s32 LoadBitmap(const char* file) {
  89.  
  90.     // Buffers locales
  91.     u8* buffer;     // Buffer temporal
  92.     buffer = NULL;
  93.     u8* palette;        // Paleta (requerida por algun modo)
  94.     palette = NULL;
  95.  
  96.     // Magic ID
  97.     char magic_id[4];
  98.     memset(magic_id, 0, 4);
  99.  
  100.     // Define la estructura para almacenar la cabecera del BMP
  101.     typedef struct {
  102.         u32 bmp_size;       // Tamaño en bytes del BMP
  103.         u16 res_a;          // Reservado
  104.         u16 res_b;          // Reservado
  105.         u32 offset;         // Offset donde empiezan los datos
  106.         u32 header_size;    // Tamaño de la cabecera (40 bytes)
  107.         u32 bmp_width;      // Ancho de la imagen en pixeles
  108.         u32 bmp_height;     // Altura de la imagen en pixeles
  109.         u16 color_planes;   // Numero de planos de color
  110.         u16 bpp;            // Numero de bits por pixel
  111.         u32 compression;    // Compresion usada
  112.         u32 raw_size;       // Tamaño de los datos en RAW despues de la cabecera
  113.         u32 dpi_hor;        // Puntos por pulgada (horizontal)
  114.         u32 dpi_ver;        // Puntos por pulgada (vertical)
  115.         u32 pal_colors;     // Numero de colores en la paleta
  116.         u32 imp_colors;     // Colores importantes
  117.     } bmp_header_info;
  118.     bmp_header_info bmp_header;
  119.  
  120.     // Pon todos los bytes de la estructura a 0
  121.     memset(&bmp_header, 0, sizeof(bmp_header));
  122.  
  123.     // Declara los punteros a los ficheros
  124.     FILE* file_id;
  125.  
  126.     // Carga el archivo .BMP
  127.     file_id = fopen(file, "rb");
  128.  
  129.     if (file_id) {  // Si el archivo existe...
  130.         // Posicionate en el byte 0
  131.         fseek(file_id, 0, SEEK_SET);
  132.         // Lee el Magic String del archivo BMP (2 primeros Bytes, "BM") / (0x00 - 0x01)
  133.         fread(magic_id, 1, 2, file_id);
  134.         // Si es un archivo BMP... (Magic string == "BM")
  135.         if (strcmp(magic_id, "BM") == 0) {
  136.             // Posicionate en el byte 2
  137.             fseek(file_id, 2, SEEK_SET);
  138.             // Lee la cabecera del archivo BMP (0x02 - 0x36)
  139.             fread((void*)&bmp_header, 1, sizeof(bmp_header), file_id);
  140.             /////////////////////////////////////////////////////////////
  141.             // Es un archivo BMP valido, cargalo en un buffer temporal //
  142.             /////////////////////////////////////////////////////////////
  143.             // Crea un buffer temporal
  144.             buffer = (u8*) calloc (bmp_header.raw_size, sizeof(u8));
  145.             if (buffer == NULL) {
  146.                 printf("No se ha podido crear el buffer temporal para la imagen.\nError critico.\n");
  147.                 free(buffer);
  148.                 buffer = NULL;
  149.                 free(palette);
  150.                 palette = NULL;
  151.                 return -1;
  152.             }
  153.             // Si se ha creado con exito, carga el archivo al buffer
  154.             fseek(file_id, bmp_header.offset, SEEK_SET);
  155.             fread(buffer, 1, bmp_header.raw_size, file_id);
  156.         } else {
  157.             // No es un archivo BMP valido
  158.             printf("El archivo %s no es un BMP valido.\nError critico.\n", file);
  159.             free(buffer);
  160.             buffer = NULL;
  161.             free(palette);
  162.             palette = NULL;
  163.             return -1;
  164.         }
  165.     } else {
  166.         // El archivo no existe
  167.         printf("El archivo %s no existe.\nError critico.\n", file);
  168.         free(buffer);
  169.         buffer = NULL;
  170.         free(palette);
  171.         palette = NULL;
  172.         return -1;
  173.     }
  174.     // Cierra el archivo
  175.     fclose(file_id);
  176.  
  177.     // Variables que se usaran a partir de aqui
  178.     u32 x = 0;          // Coordemada X
  179.     u32 y = 0;          // Coordenada Y
  180.     u32 idx = 0;        // Indice en el buffer temporal
  181.     u32 offset = 0;     // Indice en el buffer de destino
  182.     u16 colors = 0;     // En 8 bits, numero de colores
  183.     u32 size = 0;       // Tamaño del buffer (en bytes)
  184.  
  185.     // Guarda el tamaño de la imagen
  186.     img.width = bmp_header.bmp_width;
  187.     img.height = bmp_header.bmp_height;
  188.     if ((img.width != 256) || (img.height != 192)) {
  189.         printf("Tamaño ilegal de archivo.\nSe requiere una imagen de 256x192 pixeles.\n");
  190.         free(buffer);
  191.         buffer = NULL;
  192.         free(palette);
  193.         palette = NULL;
  194.         return -1;
  195.     }
  196.     // Habilita el buffer de destino (u8 de alto x ancho del tamaño de imagen)
  197.     size = (bmp_header.bmp_width * bmp_header.bmp_height);
  198.     img.data = (u8*) calloc (size, sizeof(u8));
  199.     if (img.data == NULL) {
  200.         printf("No se ha podido crear el buffer de datos para la imagen.\nError critico.\n");
  201.         free(buffer);
  202.         buffer = NULL;
  203.         free(palette);
  204.         palette = NULL;
  205.         return -1;
  206.     }
  207.  
  208.     // Segun los BITS por Pixel (8, 16, 24)
  209.     switch (bmp_header.bpp) {
  210.  
  211.         case 8:     // 8 bits por pixel
  212.             // Calcula el tamaño de la paleta
  213.             colors = ((bmp_header.offset - 0x36) >> 2);
  214.             palette = (u8*) calloc ((colors << 2), sizeof(u8));
  215.             if (palette == NULL) {
  216.                 printf("No se ha podido crear el buffer para la paleta.\nError critico.\n");
  217.                 free(buffer);
  218.                 buffer = NULL;
  219.                 free(palette);
  220.                 palette = NULL;
  221.                 return -1;
  222.             }
  223.             // Abre de nuevo el archivo y carga la paleta
  224.             file_id = fopen(file, "rb");
  225.             if (!file_id) {
  226.                 printf("El archivo %s no existe.\nError critico.\n", file);
  227.                 free(buffer);
  228.                 buffer = NULL;
  229.                 free(palette);
  230.                 palette = NULL;;
  231.                 return -1;
  232.             }
  233.             fseek(file_id, 0x36, SEEK_SET);
  234.             fread(palette, 1, (colors << 2), file_id);
  235.             fclose(file_id);
  236.             // Convierte el archivo a RAW de 8 bits
  237.             for (y = 0; y < bmp_header.bmp_height; y ++) {
  238.                 for (x = 0; x < bmp_header.bmp_width; x ++) {
  239.                     // Calcula los offsets
  240.                     offset = ((((bmp_header.bmp_height - 1) - y) * bmp_header.bmp_width) + x);
  241.                     // Guarda el pixel del buffer en img_data
  242.                     img.data[offset] = buffer[idx];
  243.                     // Siguiente pixel
  244.                     idx ++;
  245.                 }
  246.                 // Ajusta la alineacion a 4 bytes al final de linea
  247.                 while ((idx % 4) != 0) idx ++;
  248.             }
  249.             // Elimina la paleta de la RAM
  250.             free(palette);
  251.             palette = NULL;
  252.             break;
  253.  
  254.         default:
  255.             printf("La imagen no esta indexada.\nError critico.\n");
  256.             free(buffer);
  257.             buffer = NULL;
  258.             free(palette);
  259.             palette = NULL;
  260.             return -1;
  261.             break;
  262.  
  263.     }
  264.  
  265.  
  266.     // Libera el buffer temporal
  267.     free(buffer);
  268.     buffer = NULL;
  269.  
  270.  
  271.     // Devuelve el puntero al buffer de datos
  272.     return 0;
  273.  
  274. }
  275.  
  276.  
  277.  
  278. /*
  279. -------------------------------------------------------------------------------
  280.     Analiza los datos y genera el archivo tileset
  281. -------------------------------------------------------------------------------
  282. */
  283.  
  284. s32 GenerateTileset(const char* filename) {
  285.  
  286.     // Buffers temporales para los tiles
  287.     u8* tile_pattern = (u8*) calloc(64, sizeof(u8));
  288.     u8* test_pattern = (u8*) calloc(64, sizeof(u8));
  289.     // Verifica si se han creado todos los buffers
  290.     if (
  291.         (tile_pattern == NULL)
  292.         ||
  293.         (test_pattern == NULL)
  294.         ) {
  295.         printf("Error creando los buffers internos.\nError critico.\n");
  296.         free(tile_pattern);
  297.         tile_pattern = NULL;
  298.         free(test_pattern);
  299.         test_pattern = NULL;
  300.         return -1;
  301.     }
  302.  
  303.     // Crea los buffers para las tablas de pattern y color
  304.     // (Asume que todos los tiles son unicos)
  305.     u32 n = 0;
  306.     for (n = 0; n < 3; n ++) {
  307.         img.raw[n] = (u8*) calloc(16384, sizeof(u8));           // Tiles diferentes de 8x8 x 256
  308.         img.patterns[n] = (u8*) calloc(2048, sizeof(u8));      // 8 bytes por tile (8 filas de 8 pixeles)
  309.         img.colors[n] = (u8*) calloc(2048, sizeof(u8));        // Cada fila de pixeles tiene dos colores de 4 bits
  310.         img.names[n] = (u8*) calloc(256, sizeof(u8));          // Tabla de nombres de cada banco (mapa)
  311.         if ((img.raw[n] == NULL) || (img.patterns[n] == NULL) || (img.colors[n] == NULL || img.names[n] == NULL)) {
  312.             printf("Error creando los buffers internos.\nError critico.\n");
  313.             free(tile_pattern);
  314.             tile_pattern = NULL;
  315.             free(test_pattern);
  316.             test_pattern = NULL;
  317.             return -1;
  318.         }
  319.     }
  320.  
  321.     // Analisis del RAW
  322.     u32 main_offset = 0;
  323.     u32 local_offset = 0;
  324.     u32 b = 0;
  325.     s32 match = 0;
  326.     s32 exist = -1;
  327.  
  328.     // Analiza el archivo en pasos de 8x8 pixeles
  329.     printf("Generando banco de tiles:\n\n");
  330.     u32 pos_y = 0, pos_x = 0, temp_y = 0, temp_x = 0, t = 0;
  331.  
  332.     for (pos_y = 0; pos_y < img.height; pos_y += 8) {
  333.  
  334.         // Calcula el banco
  335.         b = (int)(pos_y / 64);
  336.  
  337.         for (pos_x = 0; pos_x < img.width; pos_x += 8) {
  338.  
  339.             // Copia los datos al tile
  340.             for (temp_y = 0; temp_y < 8; temp_y ++) {
  341.                 for (temp_x = 0; temp_x < 8; temp_x ++) {
  342.                     local_offset = (temp_y << 3) + temp_x;
  343.                     main_offset = ((pos_y + temp_y) * img.width) + (pos_x + temp_x);
  344.                     tile_pattern[local_offset] = img.data[main_offset];
  345.                 }
  346.             }
  347.  
  348.  
  349.  
  350.             // Borra la asignacion de tile existente
  351.             exist = -1;
  352.  
  353.             // Ahora verifica si ya hay algun tile registrado
  354.             if (img.tiles[b] > 0) {
  355.                 // Verifica si el tile es nuevo o ya existe
  356.                 for (n = 0; n < img.tiles[b]; n ++) {
  357.                     // Flag de repeticion
  358.                     match = 0;
  359.                     // Compara la info con la almacenada en el buffer de tiles
  360.                     for (t = 0; t < 64; t ++) {
  361.                         local_offset = (n * 64) + t;
  362.                         // Si los pixeles son iguales...
  363.                         if (tile_pattern[t] == img.raw[b][local_offset]) {
  364.                             match ++;
  365.                         }
  366.                         // Si todos los pixeles eran iguales, indicalo
  367.                         if (match == 64) {
  368.                             exist = n;
  369.                             n = img.tiles[b];       // Sal
  370.                         }
  371.                     }
  372.                 }
  373.  
  374.                 // Si el tile ya existe...
  375.                 if (exist != -1) {
  376.                     // Indicador
  377.                     img.names[b][img.map_pos[b]] = exist;
  378.                     // Indicador
  379.                     printf(".");
  380.                     img.map_pos[b] ++;
  381.                 } else {    // SI no existe, agregalo a los buffers
  382.                     // Indicador
  383.                     //printf("B:%01d.P%03d.M%03d", b, img.tiles[b], img.map_pos[b]);
  384.                     // Actualiza los buffers
  385.                     memcpy(img.raw[b] + (img.tiles[b] * 64), tile_pattern, 64);                   // Copia la informacion del tile
  386.                     img.names[b][img.map_pos[b]] = img.tiles[b];                // Indica al mapa que tile es
  387.                     // Indicador
  388.                     printf("%01d", b);
  389.                     // Actualiza los contadores
  390.                     img.map_pos[b] ++;
  391.                     img.tiles[b] ++;
  392.                 }
  393.  
  394.             } else {
  395.  
  396.                 // Si el el primero, registralo
  397.                 memcpy(img.raw[b], tile_pattern, 64);           // Copia la informacion del tile
  398.                 img.names[b][img.map_pos[b]] = img.tiles[b];    // Indica al mapa que tile es
  399.                 // Indicador
  400.                 printf("%01d", b);
  401.                 // Actualiza los contadores
  402.                 img.map_pos[b] ++;
  403.                 img.tiles[b] ++;
  404.  
  405.             }
  406.  
  407.         }
  408.     }
  409.  
  410.     // Resumen
  411.     printf("\n\nBanco de tiles creado con exito.\n\n");
  412.     printf("Banco 1: %03d tiles.\n", img.tiles[0]);
  413.     printf("Banco 2: %03d tiles.\n", img.tiles[1]);
  414.     printf("Banco 3: %03d tiles.\n\n", img.tiles[2]);
  415.  
  416.  
  417.     // Fase 2, genera las tablas de pattern y color para cada banco
  418.     u32 l = 0;
  419.     u32 i = 0;
  420.     u8 bg_color = 0;
  421.     u8 pixel_color = 0;
  422.     u32 encode = 0;
  423.     u32 tbl = 0;
  424.     printf("Codificando los tiles a filas de patterns...\n\n");
  425.     for (b = 0; b < 3; b ++) {
  426.         tbl = 0;
  427.         // Analiza los tiles de ese banco
  428.         for (n = 0; n < img.tiles[b]; n ++) {
  429.             // Paso 1, analiza cada linea y calcula su valor en binario
  430.             printf("B: %01d   T: %03d   LINES: ", b, n);
  431.             for (l = 0; l < 8; l ++) {          // Linea del tile
  432.                 // Guarda el primer color de la fila
  433.                 local_offset = (n * 64) + (l * 8);
  434.                 bg_color = img.raw[b][local_offset];
  435.                 pixel_color = bg_color;
  436.                 encode = 0;
  437.                 for (i = 0; i < 8; i ++) {      // Pixel
  438.                     local_offset = (n * 64) + (l * 8) + i;  // Calcula el offset del pixel en el buffer
  439.                     if (bg_color != img.raw[b][local_offset]) {
  440.                         // Si el color no es el de fondo, codifica el bit
  441.                         encode |= (1 << (7 - i));
  442.                         pixel_color = img.raw[b][local_offset];
  443.                     }
  444.                 }
  445.                 // Guarda la fila
  446.                 img.patterns[b][tbl] = encode;
  447.                 img.colors[b][tbl] = ((((pixel_color + 1) << 4) & 0xf0)| ((bg_color + 1) & 0x0f));
  448.                 printf("$%02x ", img.patterns[b][tbl]);
  449.                 tbl ++;
  450.             }
  451.             printf("\n");
  452.         }
  453.  
  454.     }
  455.  
  456.     printf("\n\n");
  457.  
  458.     // Fase 3, genera el archivo codificado
  459.     char fnam[256];
  460.     char output[256];
  461.     char txt[32];
  462.     sprintf(fnam, "%s.asm", filename);
  463.     FILE* file = fopen(fnam, "wb");
  464.  
  465.     // Si se puede crear el archivo...
  466.     if (file != NULL) {
  467.  
  468.         // Cabecera del archivo
  469.         sprintf(output, "; Imagen convertida para MSX SCREEN 2\n");
  470.         fwrite(output, strlen(output), 1, file);
  471.         sprintf(output, "; Archivo de origen: %s\n", filename);
  472.         fwrite(output, strlen(output), 1, file);
  473.         sprintf(output, "; Tamaño: %03dx%03d pixeles\n", img.width, img.height);
  474.         fwrite(output, strlen(output), 1, file);
  475.         sprintf(output, "; Informacion:\n");
  476.         fwrite(output, strlen(output), 1, file);
  477.         for (b = 0; b < 3; b ++) {
  478.             sprintf(output, "; Banco %01d: %03d patterns (%d bytes) [$%04x bytes]\n", b, img.tiles[b], (img.tiles[b] * 8), (img.tiles[b] * 8));
  479.             fwrite(output, strlen(output), 1, file);
  480.         }
  481.         sprintf(output, "\n\n\n");
  482.         fwrite(output, strlen(output), 1, file);
  483.  
  484.         // Genera los patterns
  485.         printf("Grabando datos CHR ");
  486.         for (b = 0; b < 3; b ++) {
  487.             tbl = 0;
  488.             // Genera la etiqueta
  489.             sprintf(output, "_CHR_%01d:\n", b);
  490.             fwrite(output, strlen(output), 1, file);
  491.             for (n = 0; n < img.tiles[b]; n ++) {
  492.                 // Tiles
  493.                 sprintf(output, "db ");
  494.                 // Lineas
  495.                 for (l = 0; l < 8; l ++) {      // Linea
  496.                     if (l != 7) {
  497.                         sprintf(txt, "$%02x, ", img.patterns[b][tbl]);
  498.                     } else {
  499.                         sprintf(txt, "$%02x\n", img.patterns[b][tbl]);
  500.                     }
  501.                     strcat(output, txt);
  502.                     tbl ++;
  503.                 }
  504.                 // Guarda la info
  505.                 printf(".");
  506.                 fwrite(output, strlen(output), 1, file);
  507.             }
  508.             // Genera un espacio entre bancos
  509.             sprintf(output, "\n\n");
  510.             fwrite(output, strlen(output), 1, file);
  511.         }
  512.         printf(" ok\n\n");
  513.  
  514.  
  515.         // Genera los colores
  516.         printf("Grabando datos CLR ");
  517.         for (b = 0; b < 3; b ++) {
  518.             tbl = 0;
  519.             // Genera la etiqueta
  520.             sprintf(output, "_CLR_%01d:\n", b);
  521.             fwrite(output, strlen(output), 1, file);
  522.             for (n = 0; n < img.tiles[b]; n ++) {
  523.                 // Tiles
  524.                 sprintf(output, "db ");
  525.                 // Lineas
  526.                 for (l = 0; l < 8; l ++) {      // Linea
  527.                     if (l != 7) {
  528.                         sprintf(txt, "$%02x, ", img.colors[b][tbl]);
  529.                     } else {
  530.                         sprintf(txt, "$%02x\n", img.colors[b][tbl]);
  531.                     }
  532.                     strcat(output, txt);
  533.                     tbl ++;
  534.                 }
  535.                 // Guarda la info
  536.                 printf(".");
  537.                 fwrite(output, strlen(output), 1, file);
  538.             }
  539.             // Genera un espacio entre bancos
  540.             sprintf(output, "\n\n");
  541.             fwrite(output, strlen(output), 1, file);
  542.         }
  543.         printf(" ok\n\n");
  544.  
  545.  
  546.  
  547.         // Genera la tabla de nombres
  548.         printf("Grabando datos NAME ");
  549.         for (b = 0; b < 3; b ++) {
  550.             // Genera la etiqueta
  551.             sprintf(output, "_NAM_%01d:\n", b);
  552.             fwrite(output, strlen(output), 1, file);
  553.             l = 0; i = 0;
  554.             sprintf(output, "db ");
  555.             for (n = 0; n < img.map_pos[b]; n ++) {
  556.                 // Lineas
  557.                 if (i != 31) {
  558.                     sprintf(txt, "$%02x, ", img.names[b][n]);
  559.                 } else {
  560.                     sprintf(txt, "$%02x\n", img.names[b][n]);
  561.                 }
  562.                 strcat(output, txt);
  563.                 // Ajuste de indice
  564.                 i ++;
  565.                 if (i > 31) {
  566.                     i = 0;
  567.                     // Guarda la info de la linea
  568.                     printf(".");
  569.                     fwrite(output, strlen(output), 1, file);
  570.                     sprintf(output, "db ");
  571.                 }
  572.             }
  573.             // Genera un espacio entre bancos
  574.             sprintf(output, "\n\n");
  575.             fwrite(output, strlen(output), 1, file);
  576.         }
  577.  
  578.     } else {
  579.  
  580.         printf("No se puede generar el archivo.\n");
  581.         free(tile_pattern);
  582.         tile_pattern = NULL;
  583.         free(test_pattern);
  584.         test_pattern = NULL;
  585.         return -1;
  586.  
  587.     }
  588.  
  589.     // Cierra el archivo
  590.     fclose(file);
  591.  
  592.     printf(" ok\n\n");
  593.  
  594.     return 0;
  595.  
  596. }
  597.  
  598.  
  599.  
  600. /*
  601. -------------------------------------------------------------------------------
  602.     Archivo MAIN
  603. -------------------------------------------------------------------------------
  604. */
  605.  
  606. int main(int argc, char *argv[]) {
  607.  
  608.     printf("\n\nConversor de imagenes BMP a formato MSX.\nVersion 0.1 alpha.\n(c)2015 por Cesar Rincon.\n\n\n");
  609.  
  610.     // Inicializa las estructuras
  611.     memset(&img, 0, sizeof(img));
  612.  
  613.     // Analiza el numero de argumentos
  614.     if (argc != 2) {
  615.         printf("Uso: %s archivo.bmp\n", argv[0]);
  616.         CleanBuffers();
  617.         return -1;
  618.     }
  619.  
  620.     // Carga el archivo BITMAP
  621.     if (LoadBitmap(argv[1]) == -1) {
  622.         printf("Error al procesar el archivo BITMAP.\n");
  623.         CleanBuffers();
  624.         return -1;
  625.     }
  626.  
  627.     // Guarda un archivo de prueba
  628.     //FILE* file = fopen("bindata.raw", "wb");
  629.     //fwrite(img.data, (img.width * img.height), 1, file);
  630.     //fclose(file);
  631.     printf("\nProcesando archivo BITMAP...\n\nNombre: %s\nTamaño: %dx%d pixeles.\n\n", argv[1], img.width, img.height);
  632.  
  633.     if (GenerateTileset(argv[1]) == -1) {
  634.         printf("Error al procesar los datos.\n");
  635.         CleanBuffers();
  636.         return -1;
  637.     }
  638.  
  639.     // Sal del programa
  640.     printf("Archivo ASM generado con exito.\n");
  641.     CleanBuffers();
  642.     return 0;
  643.  
  644. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement