source: thomson/tools/gfx2mo5/libraw2mo5.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.3 KB
Line 
1/* GFX2mo5 - libraw2mo5.c
2 * CloudStrife - 20080921
3 * PulkoMandy - 20101221
4 * Diffusé sous licence libre CeCILL v2
5 * Voire LICENCE
6 */
7
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11
12unsigned char *raw2mo5(unsigned char *input)
13{
14 unsigned char *tmpBuffer;
15 int x,y;
16
17 tmpBuffer = (unsigned char*)calloc(0x4000,1);
18 if (tmpBuffer == NULL)
19 {
20 printf("Allocation tmpBuffer raté\n");
21 exit(4);
22 }
23 #define width 320
24
25 for (y = 0; y < 200; y++)
26 for (x = 0; x < 320; x+=8) {
27 int fore = 255;
28 int back = 255;
29 int pix;
30 for(pix = 0; pix < 8; pix++) {
31 int nc = input[y*width+x+pix];
32 if (nc > 15) printf("Color over limit!\n");
33 if (back == nc) {
34 // Pixel is in backcolor, set FORME to 0
35 } else if (fore == nc) {
36 // Pixel is in forecolor, set FORME to 1
37 tmpBuffer[(y*320+x)/8] |= 0x80>>pix;
38 } else if (back==255) {
39 // Pixel is in unknown color, back is free : allocate backcolor
40 back = nc;
41 } else if (fore == 255) {
42 // Pixel is unknown color, back is allocated : allocate front and set FORME
43 fore = nc;
44 tmpBuffer[(y*320+x)/8] |= 0x80>>pix;
45 } else {
46 printf("Color clash at %d %d : %d %d %d\n",x+pix,y,fore, back,
47 input[y*width+x+pix]);
48 }
49 }
50 if (fore == 255) fore = 0;
51 if (back == 255) back = 0;
52
53 tmpBuffer[0x2000+(y*320+x)/8] = (fore << 4) | back;
54 }
55
56 return tmpBuffer;
57}
Note: See TracBrowser for help on using the repository browser.