aboutsummaryrefslogtreecommitdiff
path: root/tools/gfx2crtc/raw2crtc.c
blob: c8738dceeb603e71bdc4838a9bc57a03c976e832 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* GFX2CRTC - raw2crtc.c 
 * CloudStrife - 20080921
 * Diffusé sous licence libre CeCILL v2
 * Voire LICENCE
 */

#include <stdio.h>
#include <stdlib.h>
#include "libraw2crtc.h"

int main(int argc, char **argv)
{
  FILE *inFile, *outFile;
  unsigned char *inBuffer, *outBuffer;
  unsigned long inSize;
  unsigned long outSize;

  unsigned char r1, r6, r9;
  unsigned short width;
  unsigned short height;
  unsigned char mode;

  if((argc != 6) && (argc != 7))
  {
    printf("Utilisation : %s input_filename output_filename width height mode [registre9]\n",argv[0]);
    printf("Exemple : Convertir une image en 176 sur 224 en mode 0 :\n");
    printf("%s image.raw image.scr 176 224 0\n",argv[0]);
    printf("Exemple : Convertir une image en 256 sur 128 en mode 1 avec R9 = 3 :\n");
    printf("%s image.raw image.scr 256 128 1 3\n",argv[0]);
    exit(0);
  }

  inFile = fopen(argv[1],"rb");

  sscanf(argv[3],"%hud",&width);
  sscanf(argv[4],"%hud",&height);
  sscanf(argv[5],"%hhud",&mode);
  if(mode > 3) printf("mode doit �tre compris entre 0 et 3");
  mode = mode & 3;
  if(argc == 7) 
  {sscanf(argv[6],"%hhud",&r9);}
  else
  {r9 = 7;}

  if (inFile == NULL)
  {
    printf("Fichier Inexistant\n");
    exit(1);
  }

  fseek(inFile, 0, SEEK_END);
  inSize = ftell(inFile);
  rewind(inFile);

  if (inSize != (unsigned long)(width*height))
  {
    printf("Attention ! Mauvaise taille du fichier d'entr�\n");
  }

  inBuffer = (unsigned char*)malloc(inSize);
  if (inBuffer == NULL)
  {
    printf("Allocation inBuffer rat�\n");
    exit(3);
  }

  fread(inBuffer, 1, inSize, inFile);
  fclose(inFile);

  outBuffer = raw2crtc(inBuffer, width, height, mode, r9, &outSize, &r1, 0, 0, &r6);

  printf("Taille de l'�cran de sortie : %lu\n",outSize);
  printf("Mode = %d  Largeur = %d  Hauteur = %d  R1 = %d  R9 = %d R6 = %d\n",mode,width,height,r1,r9,r6);

  outFile = fopen(argv[2], "wb");
  fwrite(outBuffer, 1, outSize, outFile);
  fclose(outFile);

  free(inBuffer);
  inBuffer = NULL;

  free(outBuffer);
  outBuffer = NULL;

  return 0;
}