OSDN Git Service

i made that messy complex palette experiment noisy as fuck again
[proj16/16.git] / src / lib / 16_vlpal.c
1 /* Project 16 Source Code~\r
2  * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
3  *\r
4  * This file is part of Project 16.\r
5  *\r
6  * Project 16 is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation; either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * Project 16 is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
19  * Fifth Floor, Boston, MA 02110-1301 USA.\r
20  *\r
21  */\r
22 \r
23 #include "src/lib/16_vlpal.h"\r
24 \r
25 //color checker~\r
26 //i want to make another vesion that checks the palette when the palette is being appened~\r
27 void modexchkcolor(imgtestpal_t *bmp, word *q, word *a, word *aa, word *z, word *i/*, word *offset*/)\r
28 {\r
29                 byte *pal;\r
30                 word zz=0;\r
31                 pal = modexNewPal();\r
32                 modexPalSave(pal);\r
33 #ifdef BEVERBOSEPALCHECK\r
34                 printf("q: %02d\n", (*q));//\r
35 \r
36                 printf("chkcolor start~\n");\r
37                 printf("1                                  (*z): %d\n", (*z)/3);\r
38                 printf("1                                  (*i): %d\n", (*i)/3);\r
39                 printf("1 offset of color in palette    (*q): %d\n", (*q)/3);//\r
40                 printf("wwwwwwwwwwwwwwww\n");\r
41 #endif\r
42                 //check palette for dups\r
43                 for(; (*z)<PAL_SIZE; (*z)+=3)\r
44                 {\r
45 #ifdef BEVERBOSEPALCHECK\r
46                         printf("\n              z: %d\n", (*z));//\r
47                         printf("                  q: %d\n", (*q));//\r
48                         printf("                  z+q: %d\n\n", ((*z)+(*q)));//\r
49 #endif\r
50                         //if((*z)%3==0)\r
51                         //{\r
52 //----                    if(pal[(*z)]==pal[(*z)+3] && pal[(*z)+1]==pal[(*z)+4] && pal[(*z)+2]==pal[(*z)+5])\r
53                                 if((*z)==(*i))\r
54                                 {\r
55 #ifdef BEVERBOSEPALCHECK\r
56                                           printf("\n%d  [%02d][%02d][%02d]\n", (*z), pal[(*z)], pal[(*z)+1], pal[(*z)+2]);//\r
57                                           printf("%d      [%02d][%02d][%02d]\n\n", (*z)+3, pal[(*z)+3], pal[(*z)+4], pal[(*z)+5]);//\r
58 #endif\r
59 //0000                            (*z)-=3;\r
60                                         break;\r
61                                 }\r
62                                 else for(zz=0; zz<(*q); zz+=3)\r
63                                 {\r
64 #ifdef BEVERBOSEPALCHECK\r
65                                         printf("zz: %02d\n", zz/3);//\r
66 #endif\r
67                                         if(zz%3==0)\r
68                                         {\r
69                                                 if(pal[((*z)+(*q))]==pal[((*z)+(*q))+3] && pal[((*z)+(*q))+1]==pal[((*z)+(*q))+4] && pal[((*z)+(*q))+2]==pal[((*z)+(*q))+5])    //break if duplicate colors found in palette because it have reached the end of the current data of the palette\r
70                                                 {\r
71 //                                                        (*z)-=3;\r
72 //                                                        (*i)-=3;\r
73 #ifdef BEVERBOSEPALCHECK\r
74                                                           printf("\nzq1:%d[%02d][%02d][%02d]\n", (zz+*q), pal[(zz+*q)], pal[(zz+*q)+1], pal[(zz+*q)+2]);//\r
75                                                           printf("zq2:%d[%02d][%02d][%02d]\n\n", (zz+*q)+3, pal[(zz+*q)+3], pal[(zz+*q)+4], pal[(zz+*q)+5]);//\r
76 #endif\r
77                                                         break;\r
78                                                 }\r
79                                                 else if(pal[zz]==pal[((*z)+(*q))] && pal[zz+1]==pal[((*z)+(*q))+1] && pal[zz+2]==pal[((*z)+(*q))+2])\r
80                                                 {\r
81 #ifdef BEVERBOSEPALCHECK\r
82                                                           printf("\n\nwwwwwwwwwwwwwwww\n");//\r
83                                                           printf("      zq: %d  [%02d][%02d][%02d] value that is needing to be changed~\n", ((*z)+(*q))/3, pal[((*z)+(*q))], pal[((*z)+(*q))+1], pal[((*z)+(*q))+2]);//\r
84                                                           printf("      zz: %d  [%02d][%02d][%02d] value that the previous value is going to change to~\n", (zz)/3, pal[zz], pal[zz+1], pal[zz+2]);//\r
85                                                           //printf("      zv: %d  [%02d][%02d][%02d] wwww\n", (zz-z+q)/3, pal[(zz-z+q)], pal[(zz-z+q)+1], pal[(zz-z+q)+2]);//\r
86                                                           printf("      z : %d  [%02d][%02d][%02d] offset value~\n", (*z)/3, pal[(*z)], pal[(*z)+1], pal[(*z)+2]);//\r
87 #endif\r
88 //++++                                            (*i)--;\r
89 //                                                        (*z)--;\r
90                                                         //expand dong here\r
91 /*\r
92 planned features that i plan to implement~\r
93 image that has values on the pallete list!\r
94 wwww\r
95 no... wait.... no wwww\r
96 */\r
97                                                         //for(zzii=0; zzii<3; zzii++)\r
98                                                         //{\r
99 #ifdef BEVERBOSEPALCHECK\r
100                                                                 printf("z+q: %d\n\n", ((*z)+(*q)));\r
101 #endif\r
102                                                                 a[(((*z)+(*q)))]=zz;\r
103                                                         //}\r
104                                                         (*aa)=(((*z)+(*q)));\r
105 #ifdef BEVERBOSEPALCHECK\r
106                                                         printf("!!                                        a[%02d]: %d\n", (((*z)+(*q))/3), zz/3);\r
107                                                           printf("\n              aa: %d\n\n", (*aa));//\r
108                                                           printf("      a[%02d]=(%02d) offset array i think the palette should be updated again~\n", ((*z)+(*q))/3, a[((*z)+(*q))/3]);//\r
109                                                           printf("wwwwwwwwwwwwwwww\n\n");//\r
110 #endif\r
111                                                 }\r
112                                                 /*else\r
113                                                 {\r
114                                                         printf("================\n");\r
115                                                         printf("zq: %d  [%02d][%02d][%02d]\n", ((*z)+(*q))/3, pal[((*z)+(*q))], pal[((*z)+(*q))+1], pal[((*z)+(*q))+2]);\r
116                                                         printf("zz: %d  [%02d][%02d][%02d]\n", (zz)/3, pal[zz], pal[zz+1], pal[zz+2]);\r
117                                                         printf("z : %d  [%02d][%02d][%02d]\n", (*z)/3, pal[(*z)], pal[(*z)+1], pal[(*z)+2]);\r
118                                                         printf("================\n");\r
119                                                 }*/\r
120 #ifdef BEVERBOSEPALCHECK\r
121                                                 printf("[%d]", (zz+*q));//\r
122 #endif\r
123                                         }\r
124                                 }\r
125                 }\r
126 #ifdef BEVERBOSEPALCHECK\r
127                 printf("wwwwwwwwwwwwwwww\n");\r
128                 printf("2                                  (*z): %d\n", (*z)/3);\r
129                 printf("2                                  (*i): %d\n", (*i)/3);\r
130                 printf("2 offset of color in palette    (*q): %d\n", (*q)/3);//\r
131                 printf("chkcolor end~\n");\r
132 #endif\r
133                 //free(pal);\r
134 }\r
135 \r
136 void\r
137 VL_palette(imgtestpal_t *bmp, byte *p, word *i, word qp, word aqoffset)\r
138 {\r
139         //byte *p = bmp->palette;\r
140         word w=0;\r
141         word q=0;\r
142         word qq=0;\r
143         static word a[PAL_SIZE];        //palette array of change values!\r
144         word z=0, aq=0, aa=0, pp=0;\r
145 \r
146         //modexWaitBorder();\r
147         vga_wait_for_vsync();\r
148         if((*i)==0)\r
149         {\r
150                 memset(a, -1, sizeof(a));\r
151                 outp(PAL_WRITE_REG, 0);  /* start at the beginning of palette */\r
152         }\r
153         else if(qp==0)\r
154         {\r
155                 q=(*i);\r
156         }\r
157         else\r
158         {\r
159                 q=(*i);\r
160                 qq=(*i)/3;\r
161 #ifdef BEVERBOSEPALCHECK\r
162                 printf("q: %02d\n", (q));//\r
163                 printf("qq: %02d\n", (qq));//\r
164                 printf("          (*i)-q=%02d\n", (*i)-q);//\r
165 #endif\r
166                 outp(PAL_WRITE_REG, qq);  /* start at the beginning of palette */\r
167         }\r
168         if((*i)<PAL_SIZE && w==0)\r
169         {\r
170                 for(; (*i)<PAL_SIZE; (*i)++)\r
171                 {\r
172                         //if(i%3==0 && (p[i+5]==p[i+4] && p[i+4]==p[i+3] && p[i+3]==p[i+2] && p[i+2]==p[i+1] && p[i+1]==p[i] && p[i+5]==p[i]))\r
173 //____            if((qp>0)&&((*i)-q)%3==0 && (p[((*i)-q)]==p[((*i)-q)+3] && p[((*i)-q)+1]==p[((*i)-q)+4] && p[((*i)-q)+2]==p[((*i)-q)+5])) outp(PAL_DATA_REG, p[(*i)-q]); else\r
174                         if(((((*i)-q)%3==0)) && (p[((*i)-q)]==p[((*i)-q)+3] && p[((*i)-q)+1]==p[((*i)-q)+4] && p[((*i)-q)+2]==p[((*i)-q)+5]))\r
175                         {\r
176                                 w++;\r
177                                 break;\r
178                         }\r
179                         else if(qp>0 && (*i)>=(qp) && (*i)<((qp)+3))\r
180                         {\r
181 #ifdef BEVERBOSEPALCHECK\r
182                                 printf("qp=%d\n", qp);//\r
183                                 printf("                  (*i)=%d a[%d]=%d\n", (*i), qp, a[qp]);//\r
184                                 printf("                %d's color=%d\n", (*i), (a[qp])-(bmp->offset*3)+qp);//\r
185 #endif\r
186                                 outp(PAL_DATA_REG, p[((a[qp])-(bmp->offset*3)+qp)]);// fix this shit!\r
187                                 if((*i)+1==(qp)+3){ w++; /*(*i)++;*/ break; }\r
188                         }\r
189                         else\r
190                         {\r
191                                 if(bmp->offset==0 && (*i)<3 && q==0) outp(PAL_DATA_REG, 0);\r
192                                 else\r
193                                 if(qp==0) outp(PAL_DATA_REG, p[(*i)-q]);\r
194                                 else\r
195                                 { outp(PAL_DATA_REG, p[((*i)-(bmp->offset*3)+qp)]);\r
196 #ifdef BEVERBOSEPALCHECK\r
197                                 printf("p[]=%d  qp=%d   p[]-qp=%d\n", ((*i)-(bmp->offset*3)), qp, ((*i)-(bmp->offset*3))+qp);\r
198 #endif\r
199                                 }\r
200                         }\r
201                 }\r
202 #ifdef BEVERBOSEPALCHECK\r
203                 if(qp>0) printf("qp=%d\n", qp);//\r
204                 if(qp>0) printf("                                                (*i)=%d\n", (*i)/3);//\r
205                 printf("                                                  (*i)=%d\n", (*i)/3);\r
206 #endif\r
207         }\r
208 \r
209 #ifdef BEVERBOSEPALCHECK\r
210         printf("\nqqqqqqqq\n\n");\r
211 #endif\r
212 \r
213         //palette checker~\r
214         if(q>0 && qp==0)\r
215         {\r
216                 long lq;\r
217                 long bufSize = (bmp->width * bmp->height);\r
218                 pp = q;\r
219 #ifdef BEVERBOSEPALCHECK\r
220                 printf("1(*i)=%02d\n", (*i)/3);//\r
221                 printf("1z=%02d\n", z/3);//\r
222 #endif\r
223                 modexchkcolor(bmp, &q, &a, &aa, &z, i);\r
224 #ifdef BEVERBOSEPALCHECK\r
225                 printf("2(*i)=%02d\n", (*i)/3);\r
226                 printf("2z=%02d\n", z/3);\r
227 #endif\r
228                 aq=0;\r
229 aqpee:\r
230                 while(aq<=aa)\r
231                 {\r
232 #ifdef BEVERBOSEPALCHECK\r
233                         printf("a[%02d]=(%d)\n", aq, a[aq]);//\r
234 #endif\r
235                         if(a[aq]==-1) aq++;\r
236                         else { aqoffset++; break; }\r
237                 }\r
238 //update the image data here!\r
239         for(lq=0; lq<bufSize; lq++)\r
240         {\r
241                                 /*\r
242                                                                         note to self\r
243                                                                         use a[qp] instead of bmp->offset for this spot!\r
244                                                                         NO! wwww\r
245                                 */\r
246 \r
247                                 /*\r
248                                 Facking bloody point the values of the changed palette to correct values.... major confusion! wwww\r
249                                 */\r
250 \r
251                 //(offset/bmp->offset)*bmp->offset\r
252 \r
253 #ifdef BEVERBOSEPALCHECK\r
254                 //printf("%02d ",bmp->data[lq]+bmp->offset);//\r
255                 //if(lq > 0 && lq%bmp->width==0) printf("\n");//\r
256                 //printf("%02d_", bmp->data[lq]+bmp->offset);//\r
257 #endif\r
258                 /*if(bmp->data[lq]+bmp->offset==aq)\r
259                 {\r
260 #ifdef BEVERBOSEPALCHECK\r
261                         printf("%02d", bmp->data[lq]);//\r
262                         printf("\n%02d\n", bmp->offset);//\r
263                         printf("aq=%02d ", aq);\r
264                         printf("a[aq]=%02d        ", a[aq]);\r
265                         printf("a[aq]+aqpp=%02d ", a[aq]+aqpp);\r
266                         printf("a[aq]-aqpp=%02d\n", a[aq]-aqpp);\r
267 #endif\r
268                         //bmp->data[lq]=((bmp->data[lq]+bmp->offset)-a[aq]);\r
269 //++++            bmp->data[lq]=a[aq]-aqpp;\r
270 #ifdef BEVERBOSEPALCHECK\r
271                           printf("_%d ", bmp->data[lq]);//\r
272                         if(lq > 0 && lq%bmp->width==0) printf("\n");//\r
273 #endif\r
274                 }\r
275                 else if(bmp->data[lq]+bmp->offset < ((*i)/3)-aqpp)\r
276                 {\r
277                         if(bmp->data[lq]+bmp->offset >= aq)\r
278                         {\r
279                                 bmp->data[lq]=(bmp->data[lq]+bmp->offset)-aqpp;//-((z-(*i))/3);\r
280 #ifdef BEVERBOSEPALCHECK\r
281                                 printf("_%d ", bmp->data[lq]+bmp->offset)-aqpp-((z-(*i))/3);//\r
282 #endif\r
283                         }\r
284                         else bmp->data[lq]+=(bmp->offset-aqpp);\r
285                 }*/\r
286 #ifdef BEVERBOSEPALCHECK\r
287                 //printf("%02d`", bmp->data[lq]);//\r
288                 //if(lq > 0 && lq%bmp->width==0) printf("\n");//\r
289 #endif\r
290         }\r
291 \r
292 #ifdef BEVERBOSEPALCHECK\r
293 printf("                  aq=%02d\n", aq);//\r
294 printf("                  aa=%02d\n", aa);//\r
295 #endif\r
296         //update the palette~\r
297         VL_palette(bmp, p, &pp, aq, aqoffset);\r
298         (*i)=pp;\r
299 \r
300         if(aq<aa){ pp=q; aq++; goto aqpee; }\r
301         }\r
302 }\r