source: thomson/tools/gfx2mo5/libraw2mo5.c@ 15d3e8a

main
Last change on this file since 15d3e8a was 15d3e8a, checked in by Adrien Destugues <pulkomandy@…>, 8 years ago

gfx2mo5: can now convert bitmap16 files.

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

  • Property mode set to 100644
File size: 2.9 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 static const int width = 320;
22
23 tmpBuffer = (unsigned char*)calloc(0x4000,1);
24 if (tmpBuffer == NULL)
25 {
26 printf("Allocation tmpBuffer raté\n");
27 exit(4);
28 }
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}
96
97
98unsigned char *raw2bm16(unsigned char *input, int height)
99{
100 unsigned char *tmpBuffer;
101 int x,y;
102 int p1 = 0;
103 int p2 = 0x2000;
104 static const int width = 160;
105
106 tmpBuffer = (unsigned char*)calloc(0x4000,1);
107 if (tmpBuffer == NULL)
108 {
109 printf("Allocation tmpBuffer raté\n");
110 exit(4);
111 }
112
113 for (y = 0; y < height; y++)
114 for (x = 0; x < width; x+=4) {
115 int pix;
116
117 for(pix = 0; pix < 4; pix++) {
118 int nc = input[y*width+x+pix];
119 if (nc > 15) printf("Color over limit!\n");
120
121 switch(pix) {
122 case 0:
123 tmpBuffer[p1] = nc << 4;
124 break;
125 case 1:
126 tmpBuffer[p1++] |= nc;
127 break;
128 case 2:
129 tmpBuffer[p2] = nc << 4;
130 break;
131 case 3:
132 tmpBuffer[p2++] |= nc;
133 break;
134 }
135 }
136 }
137
138 return tmpBuffer;
139}
Note: See TracBrowser for help on using the repository browser.