]> bicyclesonthemoon.info Git - ott/enhance/commitdiff
ENHANCE!
authorb <b@276fc840-c973-4a23-809e-93696693fc29>
Fri, 23 May 2014 21:08:41 +0000 (21:08 +0000)
committerb <b@276fc840-c973-4a23-809e-93696693fc29>
Fri, 23 May 2014 21:08:41 +0000 (21:08 +0000)
git-svn-id: svn://botcastle1b/bluenh@1 276fc840-c973-4a23-809e-93696693fc29

bluenh.cpp [new file with mode: 0644]
makefile [new file with mode: 0644]

diff --git a/bluenh.cpp b/bluenh.cpp
new file mode 100644 (file)
index 0000000..f2c15d4
--- /dev/null
@@ -0,0 +1,151 @@
+    //  //bluenhance
+   //  // ENHANCE the bluepix!
+  //  //  
+ //  //   Requires Dev Image Library,
+//  //  //on Pentium III libdevil must be
+   //  // recompiled with --disable-ssl2 --disable-ssl3
+  //  //
+ //  //   ~~bicyclesonthemoon
+
+#define INPIX_MUSTARD 1
+#define OUTPIX_MUSTARD 2
+
+#define ARGUMENT_MUSTARD 4
+
+#define ANIMATED_MUSTARD 6
+#define FAIL 900
+#define OK 0
+
+#define CR newdata[4*(i+inX*j)+0]
+#define CG newdata[4*(i+inX*j)+1]
+#define CB newdata[4*(i+inX*j)+2]
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <IL/il.h>
+
+void mustard(int mustard);
+ILubyte enhance(ILubyte x, long r, long s, long t);
+ILubyte enhance2(ILubyte x, ILubyte a, ILubyte b, ILubyte c, ILubyte d, ILubyte e, ILubyte f);
+int main (int argc, const char *argv[]);
+
+ILuint pix;
+ILboolean q=true;
+ILboolean pixOpen=false;
+ILuint inX, inY;
+ILubyte *newdata;
+
+ILubyte enhance(ILubyte x, long r, long s, long t)
+{
+       long y=(r*x+t)/s;
+       return (ILubyte)((y>255)?255:((y<0)?0:y));
+}
+
+ILubyte enhance2(ILubyte x, ILubyte a, ILubyte b, ILubyte c, ILubyte d, ILubyte e, ILubyte f)
+{
+       return (ILubyte)((x<=a)?d:((x>=c)?f:((x>b)?(enhance(x,f-e,c-b,e*c-b*f)):((x<b)?(enhance(x,e-d,b-a,d*b-a*e)):e))));
+}
+
+int main (int argc, const char *argv[])
+{
+       ILubyte a,b,c,d,e,f;
+       
+       if(argc<9)
+               mustard(ARGUMENT_MUSTARD);
+       if (argc>=10)
+       {
+               if (argv[9][0]=='q' || argv[9][0]=='Q')
+                       q=false;
+       }
+       
+       sscanf(argv[3],"%hhu",&a);
+       sscanf(argv[4],"%hhu",&b);
+       sscanf(argv[5],"%hhu",&c);
+       sscanf(argv[6],"%hhu",&d);
+       sscanf(argv[7],"%hhu",&e);
+       sscanf(argv[8],"%hhu",&f);
+       
+       ilInit();
+       if(!ilEnable(IL_ORIGIN_SET))mustard(FAIL);
+       if(!ilEnable(IL_FILE_OVERWRITE))mustard(FAIL);
+       ilClearColour(255,255,0,0);
+       ilGenImages(1, &pix);
+       pixOpen=true;
+       ilBindImage(pix);
+       if(!ilLoadImage(argv[1]))mustard(INPIX_MUSTARD);
+       if(!ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE))mustard(INPIX_MUSTARD);
+       
+       inX=ilGetInteger(IL_IMAGE_WIDTH);
+       inY=ilGetInteger(IL_IMAGE_HEIGHT);
+       if(ilGetInteger(IL_NUM_IMAGES)>1)
+               mustard(ANIMATED_MUSTARD);
+       
+       newdata=ilGetData();
+       for(unsigned long i=0;i<inX;++i)
+       {
+               for(unsigned long j=0;j<inY;++j)
+               {
+                       //these things are #define'd
+                       if(CR>=CG)
+                       {
+                               if(CR>=CB)
+                               {
+                                       if(CR>CG)
+                                       {
+                                               CR=enhance2(CR,a,b,c,d,e,f);
+                                               if(CR==CB)
+                                                       CB=enhance2(CB,a,b,c,d,e,f);
+                                       }
+                                       else
+                                       {
+                                               if(CR>CB)
+                                               {
+                                                       CR=enhance2(CR,a,b,c,d,e,f);
+                                                       if(CR==CG)
+                                                               CG=enhance2(CG,a,b,c,d,e,f);
+                                               }
+                                       }
+                               }
+                               else
+                                       CB=enhance2(CB,a,b,c,d,e,f);
+                       }
+                       else
+                       {
+                               if(CG>=CB)
+                               {
+                                       CG=enhance2(CG,a,b,c,d,e,f);
+                                       if(CG==CB)
+                                               CB=enhance2(CB,a,b,c,d,e,f);
+                               }
+                               else
+                                       CB=enhance2(CB,a,b,c,d,e,f);
+                       }
+               }
+       }
+       if(!ilSave(IL_PNG,argv[2]))mustard(OUTPIX_MUSTARD);
+       // no mustard
+       mustard(0);
+}
+
+void mustard(int mustard)
+{
+       switch(mustard)
+       {
+       case 0:
+               if(q) printf("ENHANCED!\n");break;
+       case ARGUMENT_MUSTARD:
+               if(q) printf("bluenhanced inPix outPix a b c d e f [q]\n");break;
+       case INPIX_MUSTARD:
+               if(q) printf("inPIX mustard.\n");break;
+       case OUTPIX_MUSTARD:
+               if(q) printf("outPIX mustard.\n");break;
+       case ANIMATED_MUSTARD:
+               if(q) printf("Animation is mustard.\n");break;
+       default:
+               if (q) printf("Ch*rpin* mustard mustaard!\n");
+       }
+       if(pixOpen)
+               ilDeleteImages(1, &pix);
+       exit(mustard);
+}
+       
diff --git a/makefile b/makefile
new file mode 100644 (file)
index 0000000..cfa52ec
--- /dev/null
+++ b/makefile
@@ -0,0 +1,8 @@
+CC=g++
+CF=-g -Wall
+LF=-lIL
+
+all: bluenh
+
+bluenh: bluenh.cpp makefile
+       $(CC) $(CF) $(LF) -o bluenh bluenh.cpp