source: thomson/tools/gfx2mo5/raw2mo5.c@ 99bc67a

main
Last change on this file since 99bc67a was 99bc67a, checked in by Adrien Destugues <pulkomandy@…>, 12 years ago

Add PNG to MO5 converter.

git-svn-id: svn://localhost/thomson@20 85ae3b6b-dc8f-4344-a89d-598714f2e4e5

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/* GFX2mo5 - raw2mo5.c
2 * CloudStrife - 20080921
3 * Diffusé sous licence libre CeCILL v2
4 * Voire LICENCE
5 */
6
7#include <stdio.h>
8#include <stdlib.h>
9#include "libraw2mo5.h"
10
11int main(int argc, char **argv)
12{
13 FILE *inFile, *outFile;
14 unsigned char *inBuffer, *outBuffer;
15 unsigned long inSize;
16
17 unsigned short width;
18 unsigned short height;
19 unsigned char mode;
20
21 if((argc != 6) && (argc != 7))
22 {
23 printf("Utilisation : %s input_filename output_filename width height mode [registre9]\n",argv[0]);
24 printf("Exemple : Convertir une image en 176 sur 224 en mode 0 :\n");
25 printf("%s image.raw image.scr 176 224 0\n",argv[0]);
26 printf("Exemple : Convertir une image en 256 sur 128 en mode 1 avec R9 = 3 :\n");
27 printf("%s image.raw image.scr 256 128 1 3\n",argv[0]);
28 exit(0);
29 }
30
31 inFile = fopen(argv[1],"rb");
32
33 sscanf(argv[3],"%hud",&width);
34 sscanf(argv[4],"%hud",&height);
35 sscanf(argv[5],"%hhud",&mode);
36 if(mode > 3) printf("mode doit être compris entre 0 et 3");
37 mode = mode & 3;
38
39 if (inFile == NULL)
40 {
41 printf("Fichier Inexistant\n");
42 exit(1);
43 }
44
45 fseek(inFile, 0, SEEK_END);
46 inSize = ftell(inFile);
47 rewind(inFile);
48
49 if (inSize != (unsigned long)(width*height))
50 {
51 printf("Attention ! Mauvaise taille du fichier d'entré\n");
52 }
53
54 inBuffer = (unsigned char*)malloc(inSize);
55 if (inBuffer == NULL)
56 {
57 printf("Allocation inBuffer raté\n");
58 exit(3);
59 }
60
61 fread(inBuffer, 1, inSize, inFile);
62 fclose(inFile);
63
64 outBuffer = raw2mo5(inBuffer);
65
66 outFile = fopen(argv[2], "wb");
67 fwrite(outBuffer, 1, 0x4000, outFile);
68 fclose(outFile);
69
70 free(inBuffer);
71 inBuffer = NULL;
72
73 free(outBuffer);
74 outBuffer = NULL;
75
76 return 0;
77}
Note: See TracBrowser for help on using the repository browser.