source: thomson/tools/gfx2mo5/libraw2mo5.c@ 068b1fa

main
Last change on this file since 068b1fa was 068b1fa, checked in by Adrien Destugues <pulkomandy@…>, 10 years ago

gfx2mo5: make TO mode a run-time option

  • Use getopt for parsing option.
  • The "MO5 gate array fixup" is now option -f
  • The "TO modeis now option -t

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

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/* GFX2mo5 - libraw2mo5.c
2 * CloudStrife - 20080921
3 * PulkoMandy - 20101221, 20130213
4 * Diffusé sous licence libre CeCILL v2
5 * Voir LICENCE
6 */
7
8#include <stdbool.h>
9#include <stdint.h>
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13
14unsigned char *raw2mo5(unsigned char *input, int height, int fixup, bool to)
15{
16 unsigned char *tmpBuffer;
17 int x,y;
18 int previous = 0;
19 bool lfo = false;
20 uint8_t val;
21
22 tmpBuffer = (unsigned char*)calloc(0x4000,1);
23 if (tmpBuffer == NULL)
24 {
25 printf("Allocation tmpBuffer raté\n");
26 exit(4);
27 }
28 #define width 320
29
30 for (y = 0; y < height; y++)
31 for (x = 0; x < 320; x+=8) {
32 int fore = 255;
33 int back = 255;
34 int pix;
35 bool oldlfo = lfo;
36
37 for(pix = 0; pix < 8; pix++) {
38 int nc = input[y*width+x+pix];
39 if (nc > 15) printf("Color over limit!\n");
40 if (back == nc) {
41 // Pixel is in backcolor, set FORME to 0
42 lfo = false;
43 } else if (fore == nc) {
44 // Pixel is in forecolor, set FORME to 1
45 tmpBuffer[(y*320+x)/8] |= 0x80>>pix;
46 lfo = true;
47 } else if (back==255) {
48 // Pixel is in unknown color, back is free : allocate backcolor
49 back = nc;
50 lfo = false;
51 } else if (fore == 255) {
52 // Pixel is unknown color, back is allocated : allocate front and set FORME
53 fore = nc;
54 tmpBuffer[(y*320+x)/8] |= 0x80>>pix;
55 lfo = true;
56 } else {
57 printf("Color clash at %d %d : %d %d %d\n",x+pix,y,fore, back,
58 input[y*width+x+pix]);
59 }
60 }
61
62 if (fore == 255) fore = fixup;
63 if (fore != 255) {
64 previous &= 0xF;
65 previous |= fore << 4;
66 }
67 if (back != 255) {
68 previous &= 0xF0;
69 previous |= back;
70 }
71
72 // Make sure the last pixel of this GPL and the first of the next GPL
73 // are both FORME or both FOND, else we get an ugly glitch on the
74 // EFGJ033 Gate Array MO5!
75 val = tmpBuffer[(y*320+x)/8];
76 if(fixup > 0 && ((oldlfo == !(val & 0x80) && val != 0) || val == 0xFF))
77 {
78 previous = 7 | (previous << 4);
79 tmpBuffer[(y*320+x)/8] ^= 0xFF;
80
81 lfo = !lfo;
82 }
83
84 // TO8 mode
85 if(to)
86 {
87 previous = (previous & 0x7) | ((previous & 0xF0) >> 1) | ((previous & 0x8) << 4);
88 previous ^= 0xC0;
89 }
90
91 tmpBuffer[0x2000+(y*320+x)/8] = previous;
92 }
93
94 return tmpBuffer;
95}
Note: See TracBrowser for help on using the repository browser.