Karoshi MSX Community
22 de Julio de 2017, 05:11:35 am *
Bienvenido(a), Visitante. Por favor, ingresa o regístrate.

Ingresar con nombre de usuario, contraseña y duración de la sesión
Noticias:
 
   Inicio   Ayuda Buscar Calendario Ingresar Registrarse  
Páginas: [1]
  Imprimir  
Autor Tema: Quick'n'Dirty GIMP BMP -> MSX (sc5, sc6)  (Leído 3589 veces)
0 Usuarios y 1 Visitante están viendo este tema.
pitpan
Karoshi Forum's Guru
*******
Mensajes: 1812


Ver Perfil
« : 12 de Octubre de 2010, 01:33:01 pm »

Please read this first:

- This tiny program does not implement full BMP format
- It will only work in BMP files saved by GIMP program with 16 colours and no RLE compression
- The resulting PAL and PAT files are the palette and pattern raw data in MSX format, but they have no heading
- Compile using GCC: gcc bmp2msx.c -obmp2msx
- Probably it will work also in Windows/Mac with GIMP files, but it hasn't been tested
- This code is pure crap, I know it, so don't bother to comment it aloud Wink

Código:
// BMP -> raw SCREEN 5/6 converter (palette and pattern files)
// Eduardo Robsy Petrus, 2010
// v.0.1
// Use with GIMP BMP files with 16 colours and no RLE compression
// Make sure that the image has even pixel width

#include<stdio.h>

FILE *input,*output;
int i,j,x,y,k;
unsigned char buffer[1024*128];

int main(int argc, char *argv[])

{

// Print tool name
 printf("BMP2MSX v.0.1 - converts GIMP 16-colour BMP to MSX Screen 5/6\n");

// Check if there is a filename parameter
 if (argc!=2)
 {
// If not, print brief instructions
  printf("Usage: bmp2msx [file.bmp]\n");
  return 0;
 }

// Try to open the file
 if ((input=fopen(argv[1],"r"))==NULL)
 {
  printf("Cannot open %s\n",argv[1]);
  return 1;
 }

// Read all file to buffer
 for (i=0;!feof(input);buffer[i++]=fgetc(input));
 i--;
 fclose(input);

// Create palette file
 output=fopen("output.pal","w");
 for (i=0;i<16;i++)
 {
  j=((buffer[0x35+i*4+3]/32)*16)+(buffer[0x35+i*4+1]/32);
  fputc(j,output);
  j=buffer[0x35+i*4+2]/32;
  fputc(j,output);
 }
 fclose(output);

// Create pattern file
 output=fopen("output.pat","w");
 x=(buffer[0x12]+buffer[0x13]*256)/2;
 y=buffer[0x16]+buffer[0x17]*256;
 printf("%i x %i pixels\n",x,y);

 for (j=y-1;j>=0;j--)
 for (i=0;i<x;i++)
 {
  k=buffer[buffer[2]+j*x+i];
  fputc(k,output);
 }
 fclose(output);

 return;

}

A very easy process to convert images:

- Open/Edit the image in GIMP
- Convert to indexed image (image > mode > indexed), set 16 as maximum colours and enable dithering if you need it
- Save as BMP file with no RLE compression
- Use the provided command-line tool to convert it easily
- Generate the required code to render the image back in MSX!
« Última modificación: 13 de Octubre de 2010, 10:54:38 am por pitpan » En línea
Páginas: [1]
  Imprimir  
 
Ir a:  

Impulsado por MySQL Impulsado por PHP Powered by SMF 1.1.21 | SMF © 2013, Simple Machines XHTML 1.0 válido! CSS válido!