]> bicyclesonthemoon.info Git - ott/enhance/blob - npb.cpp
Fading enhancement actually works now!
[ott/enhance] / npb.cpp
1     //  //It's NewpixbOTTification Time!
2    //  // Take a picture and add a newpixbot to it!
3   //  //  
4  //  //   Requires Dev Image Library,
5 //  //  //on Pentium III libdevil must be
6    //  // recompiled with --disable-ssl2 --disable-ssl3
7   //  //
8  //  //   ~~bicyclesonthemoon
9
10 #define INPIX_MUSTARD 1
11 #define OUTPIX_MUSTARD 2
12 #define NPBPIX_MUSTARD 3
13 #define ARGUMENT_MUSTARD 4
14 #define SEAISH_MUSTARD 5
15 #define ANIMATED_MUSTARD 6
16 #define FAIL 900
17 #define OK 0
18
19 #define NPBPIX0 "npb0.png"
20 #define X0  411
21 #define X01  21
22 #define X02  96
23 #define Y0  404
24 #define Y01 214
25 #define Y02  68
26
27 #define NPBPIX1 "npb1.png"
28 #define X1  411
29 #define X11  22
30 #define X12 133
31 #define Y1  404
32 #define Y11 241
33 #define Y12  94
34
35 #define NPBPIX2 "npb2.png"
36 #define X2  411
37 #define X21 213
38 #define Y2  404
39 #define Y21 234
40
41 #include <stdlib.h>
42 #include <stdio.h>
43 #include <IL/il.h>
44
45 void mustard(int mustard);
46 void loadnpb(const char *path);
47 void npbottify0(const char *path);
48 void npbottify1(const char *path);
49 void npbottify2(const char *path);
50 int main (int argc, const char *argv[]);
51
52 ILuint inPix, outPix, npbPix;
53 ILboolean q=true;
54 ILboolean inH=false;
55 ILboolean outH=false;
56 ILboolean npbH=false;
57 ILuint inX, inY, outX, outY;
58 ILubyte *newdata;
59
60 int main (int argc, const char *argv[])
61 {
62         if(argc<3)
63                 mustard(ARGUMENT_MUSTARD);
64         if (argc>=4)
65         {
66                 if (argv[3][0]=='q' || argv[3][0]=='Q')
67                         q=false;
68         }
69         
70         ilInit();
71         if(!ilEnable(IL_ORIGIN_SET))mustard(FAIL);
72         if(!ilEnable(IL_FILE_OVERWRITE))mustard(FAIL);
73         ilClearColour(255,255,0,0);
74         ilGenImages(1, &inPix);
75         inH=true;
76         ilBindImage(inPix);
77         if(!ilLoadImage(argv[1]))mustard(INPIX_MUSTARD);
78         if(!ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE))mustard(INPIX_MUSTARD);
79         //if(!ilConvertPal(IL_PAL_RGBA32))mustard(FAIL);
80         
81         inX=ilGetInteger(IL_IMAGE_WIDTH);
82         inY=ilGetInteger(IL_IMAGE_HEIGHT);
83         if(ilGetInteger(IL_NUM_IMAGES)>1)
84                 mustard(ANIMATED_MUSTARD);
85         
86         if(inX<=X02&&inY<=Y02)
87                 npbottify0(argv[2]);
88         else if(inX<=X12&&inY<=Y12)
89                 npbottify1(argv[2]);
90         else
91                 npbottify2(argv[2]);    
92         //ok
93         mustard(0);
94 }
95
96 void loadnpb(const char *path)
97 {
98         ilGenImages(1, &npbPix);
99         npbH=true;
100         ilBindImage(npbPix);
101         if(!ilLoadImage(path))mustard(NPBPIX_MUSTARD);
102         if(!ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE))mustard(NPBPIX_MUSTARD);
103 }
104
105 void npbottify0(const char *path)
106 {
107         //newdata= new ILubyte[X0*Y0*4];
108         ilGenImages(1, &outPix);
109         outH=true;
110         loadnpb(NPBPIX0);
111         ilBindImage(outPix);
112         if(!ilCopyImage(npbPix))mustard(FAIL);
113         //if(!ilTexImage(X0,Y0,1,4,IL_RGBA,IL_UNSIGNED_BYTE,NULL))mustard(OUTPIX_MUSTARD);
114         //if(!ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE))mustard(OUTPIX_MUSTARD);
115         newdata=ilGetData();
116         for(unsigned long i=0;i<X0;++i)
117         {
118                 for(unsigned long j=0;j<Y0;++j)
119                 {
120                         if((i>=X01+(X02-inX)/2)&&
121                            (i< X01+(X02-inX)/2+inX)&&
122                            (j>=Y01+(Y02-inY)/2)&&
123                            (j< Y01+(Y02-inY)/2+inY))
124                         {
125                                 newdata[4*(i+X0*j)+0]=0xFF;
126                                 newdata[4*(i+X0*j)+1]=0xFF;
127                                 newdata[4*(i+X0*j)+2]=0xFF;
128                                 newdata[4*(i+X0*j)+3]=0xFF;
129                         }
130                         else if((i>=X01)&&(i<X01+X02)&&
131                                 (j>=Y01)&&(j<Y01+Y02))
132                         {
133                                 newdata[4*(i+X0*j)+0]=0xFF;//looks better white
134                                 newdata[4*(i+X0*j)+1]=0xFF;
135                                 newdata[4*(i+X0*j)+2]=0xFF;
136                                 newdata[4*(i+X0*j)+3]=0xFF;
137                         }
138                         else
139                         {
140                                 //newdata[4*(i+X0*j)+0]=0xFF;
141                                 //newdata[4*(i+X0*j)+1]=0xFF;
142                                 //newdata[4*(i+X0*j)+2]=0xFF;
143                                 //newdata[4*(i+X0*j)+3]=0x00;
144                         }
145                 }
146         }
147         //if(!ilSetData(newdata))mustard(OUTPIX_MUSTARD);
148         
149         //printf("%d\n",iCurImage);
150         if(!ilOverlayImage(inPix,X01+(X02-inX)/2,Y0-inY-(Y01+(Y02-inY)/2),0))mustard(FAIL);
151         if(!ilOverlayImage(npbPix,0,0,0))mustard(FAIL);
152         if(!ilSave(IL_PNG,path))mustard(OUTPIX_MUSTARD);
153 }
154
155 void npbottify1(const char *path)
156 {
157         //newdata= new ILubyte[X0*Y0*4];
158         ilGenImages(1, &outPix);
159         outH=true;
160         loadnpb(NPBPIX1);
161         ilBindImage(outPix);
162         if(!ilCopyImage(npbPix))mustard(FAIL);
163         //if(!ilTexImage(X1,Y1,1,4,IL_RGBA,IL_UNSIGNED_BYTE,NULL))mustard(OUTPIX_MUSTARD);
164         //if(!ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE))mustard(OUTPIX_MUSTARD);
165         newdata=ilGetData();
166         for(unsigned long i=0;i<X1;++i)
167         {
168                 for(unsigned long j=0;j<Y1;++j)
169                 {
170                         if((i>=X11+(X12-inX)/2)&&
171                            (i< X11+(X12-inX)/2+inX)&&
172                            (j>=Y11+(Y12-inY)/2)&&
173                            (j< Y11+(Y12-inY)/2+inY))
174                         {
175                                 newdata[4*(i+X1*j)+0]=0xFF;
176                                 newdata[4*(i+X1*j)+1]=0xFF;
177                                 newdata[4*(i+X1*j)+2]=0xFF;
178                                 newdata[4*(i+X1*j)+3]=0xFF;
179                         }
180                         else if((i>=X11)&&(i<X11+X12)&&
181                                 (j>=Y11)&&(j<Y11+Y12))
182                         {
183                                 newdata[4*(i+X1*j)+0]=0x00;
184                                 newdata[4*(i+X1*j)+1]=0x00;
185                                 newdata[4*(i+X1*j)+2]=0x00;
186                                 newdata[4*(i+X1*j)+3]=0xFF;
187                         }
188                         else
189                         {
190                                 //
191                         }
192                 }
193         }
194         //if(!ilSetData(newdata))mustard(OUTPIX_MUSTARD);
195         
196         //printf("%d\n",iCurImage);
197         if(!ilOverlayImage(inPix,X11+(X12-inX)/2,Y1-inY-(Y11+(Y12-inY)/2),0))mustard(FAIL);
198         //(!ilOverlayImage(npbPix,0,0,0))mustard(FAIL);
199         if(!ilSave(IL_PNG,path))mustard(OUTPIX_MUSTARD);
200 }
201
202 void npbottify2(const char *path)
203 {
204         unsigned long i,j;
205         outX=(X21+inX+2>X2)?(X21+inX+2):X2;
206         outY=(Y21+inY+2>Y2)?(Y21+inY+2):Y2;
207         ilGenImages(1, &outPix);
208         outH=true;
209         loadnpb(NPBPIX2);
210         newdata=ilGetData();
211         ilBindImage(outPix);
212         if(!ilTexImage(outX,outY,1,4,IL_RGBA,IL_UNSIGNED_BYTE,NULL))mustard(OUTPIX_MUSTARD);
213         if(!ilClearImage())mustard(FAIL);
214         ilSetPixels(outX-X2,0,0,X2,Y2,1,IL_RGBA,IL_UNSIGNED_BYTE,newdata);
215         newdata=ilGetData();
216         for(i=outX-X21-inX-2;i<outX-X21+2;++i)
217         {
218                 //printf("i=%lu\n",i);
219                 for(j=Y21-2;j<Y21+inY+2;++j)
220                 {
221                         //printf("i=%lu j=%lu\n",i,j);
222                         if((i==outX-X21-inX-2)||(i==outX-X21-inX-1)||
223                            (i==outX-X21    +1)||(i==outX-X21      )||
224                            (j==     Y21    -2)||(j==     Y21    -1)||
225                            (j==     Y21+inY+1)||(j==     Y21+inY  ))
226                         {
227                                 newdata[4*(i+outX*j)+0]=0x00;
228                                 newdata[4*(i+outX*j)+1]=0x00;
229                                 newdata[4*(i+outX*j)+2]=0x00;
230                                 newdata[4*(i+outX*j)+3]=0xFF;   
231                         }
232                         else
233                         {
234                                 newdata[4*(i+outX*j)+0]=0xFF;
235                                 newdata[4*(i+outX*j)+1]=0xFF;
236                                 newdata[4*(i+outX*j)+2]=0xFF;
237                                 newdata[4*(i+outX*j)+3]=0xFF;
238                         }
239                 }
240         }
241         
242         if(!ilOverlayImage(inPix,outX-X21-inX,outY-Y21-inY,0))mustard(FAIL);
243         
244         i=outX-X21-inX-2;
245         j=Y21-2;
246         newdata[4*(i+outX*j)+0]=0x00;
247         newdata[4*(i+outX*j)+1]=0x00;
248         newdata[4*(i+outX*j)+2]=0x00;
249         newdata[4*(i+outX*j)+3]=0x00;   
250         j=Y21+inY+1;
251         newdata[4*(i+outX*j)+0]=0x00;
252         newdata[4*(i+outX*j)+1]=0x00;
253         newdata[4*(i+outX*j)+2]=0x00;
254         newdata[4*(i+outX*j)+3]=0x00;   
255         i=outX-X21+1;
256         newdata[4*(i+outX*j)+0]=0x00;
257         newdata[4*(i+outX*j)+1]=0x00;
258         newdata[4*(i+outX*j)+2]=0x00;
259         newdata[4*(i+outX*j)+3]=0x00;   
260         j=Y21-2;
261         newdata[4*(i+outX*j)+0]=0x00;
262         newdata[4*(i+outX*j)+1]=0x00;
263         newdata[4*(i+outX*j)+2]=0x00;
264         newdata[4*(i+outX*j)+3]=0x00;   
265         
266         i=outX-X21-inX;
267         j=Y21;
268         newdata[4*(i+outX*j)+0]=0x00;
269         newdata[4*(i+outX*j)+1]=0x00;
270         newdata[4*(i+outX*j)+2]=0x00;
271         newdata[4*(i+outX*j)+3]=0xFF;   
272         j=Y21+inY-1;
273         newdata[4*(i+outX*j)+0]=0x00;
274         newdata[4*(i+outX*j)+1]=0x00;
275         newdata[4*(i+outX*j)+2]=0x00;
276         newdata[4*(i+outX*j)+3]=0xFF;   
277         i=outX-X21-1;
278         newdata[4*(i+outX*j)+0]=0x00;
279         newdata[4*(i+outX*j)+1]=0x00;
280         newdata[4*(i+outX*j)+2]=0x00;
281         newdata[4*(i+outX*j)+3]=0xFF;   
282         j=Y21;
283         newdata[4*(i+outX*j)+0]=0x00;
284         newdata[4*(i+outX*j)+1]=0x00;
285         newdata[4*(i+outX*j)+2]=0x00;
286         newdata[4*(i+outX*j)+3]=0xFF;
287         
288         if(!ilSave(IL_PNG,path))mustard(OUTPIX_MUSTARD);
289
290         
291 }
292
293 void mustard(int mustard)
294 {
295         switch(mustard)
296         {
297         case 0:
298                 if(q) printf("NewpixbOTTified!\n");break;
299         case ARGUMENT_MUSTARD:
300                 if(q) printf("npb inPix outPix [q]\n");break;
301         case INPIX_MUSTARD:
302                 if(q) printf("inPIX mustard.\n");break;
303         case OUTPIX_MUSTARD:
304                 if(q) printf("outPIX mustard.\n");break;
305         case NPBPIX_MUSTARD:
306                 if(q) printf("npbPIX mustard.\n");break;
307         case SEAISH_MUSTARD:
308                 if(q) printf("Seaishness is mustard.\n");break;
309         case ANIMATED_MUSTARD:
310                 if(q) printf("Animation is mustard.\n");break;
311         default:
312                 if (q) printf("Ch*rpin* mustard mustaard!\n");
313         }
314         if(inH)
315                 ilDeleteImages(1, &inPix);
316         if(outH)
317         {
318                 ilDeleteImages(1, &outPix);
319                 //delete[] newdata;
320         }
321         if(npbH)
322                 ilDeleteImages(1, &npbPix);
323         exit(mustard);
324 }
325