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