]> bicyclesonthemoon.info Git - ott/enhance/commitdiff
Initial state as of 30.06.2019
authorb <rowerynaksiezycu@gmail.com>
Sun, 30 Jun 2019 10:24:13 +0000 (10:24 +0000)
committerb <rowerynaksiezycu@gmail.com>
Sun, 30 Jun 2019 10:24:13 +0000 (10:24 +0000)
enhance.cpp [new file with mode: 0644]

diff --git a/enhance.cpp b/enhance.cpp
new file mode 100644 (file)
index 0000000..bb6b615
--- /dev/null
@@ -0,0 +1,218 @@
+// enhance.cpp
+// The enhancement software - reveal hidden details
+//  9.06.2019
+// 
+// Copyright (C) 2014 - 2019  Balthasar Szczepański
+// 
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+// 
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU Affero General Public License for more details.
+// 
+// You should have received a copy of the GNU Affero General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+// 
+
+// Requires Dev Image Library (libdevil) (http://openil.sourceforge.net/)
+// on Pentium III libdevil must be recompiled with
+// --disable-ssl2 --disable-ssl3
+// (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954)
+
+#define INPIX_MUSTARD 1
+#define OUTPIX_MUSTARD 2
+
+#define ARGUMENT_MUSTARD 4
+
+#define ANIMATED_MUSTARD 6
+#define FAIL 900
+#define OK 0
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <IL/il.h>
+#include <IL/ilu.h>
+
+void mustard(int mustard);
+ILubyte swap1(ILubyte x);
+ILubyte swap2(ILubyte x);
+ILubyte swap4(ILubyte x);
+int main (int argc, const char *argv[]);
+
+ILuint pix;
+ILboolean q=true;
+ILboolean pixOpen=false;
+
+
+ILubyte swap1(ILubyte x)
+{
+       ILubyte y=0;
+       
+       y |= x&0x01;
+       x >>= 1;
+       y <<= 1;
+       y |= x&0x01;
+       x >>= 1;
+       y <<= 1;
+       y |= x&0x01;
+       x >>= 1;
+       y <<= 1;
+       y |= x&0x01;
+       x >>= 1;
+       y <<= 1;
+       y |= x&0x01;
+       x >>= 1;
+       y <<= 1;
+       y |= x&0x01;
+       x >>= 1;
+       y <<= 1;
+       y |= x&0x01;
+       x >>= 1;
+       y <<= 1;
+       y |= x&0x01;
+       
+       return y;
+}
+
+ILubyte swap2(ILubyte x)
+{
+       ILubyte y=0;
+       
+       y |= x&0x03;
+       x >>= 2;
+       y <<= 2;
+       y |= x&0x03;
+       x >>= 2;
+       y <<= 2;
+       y |= x&0x03;
+       x >>= 2;
+       y <<= 2;
+       y |= x&0x03;
+       
+       return y;
+}
+
+ILubyte swap4(ILubyte x)
+{
+       ILubyte y=0;
+       
+       y |= x&0x0f;
+       x >>= 4;
+       y <<= 4;
+       y |= x&0x0f;
+       
+       return y;
+}
+
+int main (int argc, const char *argv[])
+{
+       ILuint inX, inY, inZ, inC;
+       ILubyte *newdata, *pal;
+       unsigned char indexed;
+       
+       if(argc<3)
+               mustard(ARGUMENT_MUSTARD);
+       if (argc>=4)
+       {
+               if (argv[3][0]=='q' || argv[3][0]=='Q')
+                       q=false;
+       }
+       
+       if(q) printf("%s -> %s ",argv[1],argv[2]);
+       
+       ilInit();
+       iluInit();
+       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);
+       indexed=(ilGetInteger(IL_IMAGE_FORMAT)==IL_COLOUR_INDEX)?1:0;
+       
+       if (indexed)
+       {
+               ilConvertPal(IL_PAL_RGB24);
+               inC=ilGetInteger(IL_PALETTE_NUM_COLS);
+               pal=ilGetPalette();
+               
+               for(unsigned long k=0;k<inC;++k)
+               {
+                       pal[k*3  ]=swap4(pal[k*3  ]);
+                       pal[k*3+1]=swap2(pal[k*3+1]);
+                       pal[k*3+2]=swap1(pal[k*3+2]);
+               }
+               printf("e\n");
+       }
+       else
+       {
+               
+               if(!ilConvertImage(IL_RGB,IL_UNSIGNED_BYTE))mustard(INPIX_MUSTARD);
+               
+               inX=ilGetInteger(IL_IMAGE_WIDTH);
+               inY=ilGetInteger(IL_IMAGE_HEIGHT);
+               inZ=ilGetInteger(IL_NUM_IMAGES);
+               if(!inZ)
+                       inZ=1;
+               
+               // printf("%d %d %d\n", inX, inY, inZ);
+               
+               newdata=ilGetData();
+               for(unsigned long k=0;k<inZ;++k)
+               {
+                       for(unsigned long i=0;i<inX;++i)
+                       {
+                               for(unsigned long j=0;j<inY;++j)
+                               {
+                                       newdata[(k*inX*inY+j*inX+i)*3  ]=swap4(newdata[(k*inX*inY+j*inX+i)*3  ]);
+                                       newdata[(k*inX*inY+j*inX+i)*3+1]=swap2(newdata[(k*inX*inY+j*inX+i)*3+1]);
+                                       newdata[(k*inX*inY+j*inX+i)*3+2]=swap1(newdata[(k*inX*inY+j*inX+i)*3+2]);
+                               }
+                       }
+               }
+       }
+       if(!ilSave((inZ>1)?IL_GIF:IL_PNG,argv[2]))mustard(OUTPIX_MUSTARD);
+       // no mustard
+       mustard(0);
+}
+
+void mustard(int mustard)
+{
+       ILenum error;
+       while((error=ilGetError())!=IL_NO_ERROR)
+               printf("%d: %s\n",error,iluErrorString(error));
+       switch(mustard)
+       {
+       case 0:
+               if(q) printf("ENHANCED!\n");
+               break;
+       case ARGUMENT_MUSTARD:
+               if(q)
+                       printf("enhance inPix outPix [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);
+}
+