Downloads containing SEpalwiz-1.1.asc

Downloads
Name Author Game Mode Rating
TSF with JJ2+ Only: Devan's Revenge (Intro)Featured Download sAlAmAnDeR Single player 9.6 Download file
TSF with JJ2+ Only: Chaos V1.1Featured Download sAlAmAnDeR Mutator 8.5 Download file

File preview

  1. //Palette Wizard (v1.1 for Plus Beta Build 2013-10-30 and later) by Sir Ementaler
  2. #pragma require "SEmath.asc"
  3. #include "SEmath.asc"
  4. namespace se{
  5.   interface colorEffect{
  6.     jjPALCOLOR getResult(jjPALCOLOR) const;
  7.   }
  8.   class colorBrighten:colorEffect{
  9.     private float invValue,white;
  10.     colorBrighten(float Value){
  11.       Value=max(-1,min(1,Value));
  12.       invValue=1-abs(Value);
  13.       white=Value>0?Value*255:0;
  14.     }
  15.     jjPALCOLOR getResult(jjPALCOLOR input) const override{
  16.       array<int> comp={input.red,input.green,input.blue};
  17.       for(uint i=0;i<3;i++){
  18.         comp[i]=int(comp[i]*invValue+white);
  19.       }
  20.       return jjPALCOLOR(comp[0],comp[1],comp[2]);
  21.     }
  22.   }
  23.   class colorContrast:colorEffect{
  24.     private float contrast;
  25.     colorContrast(float Contrast){
  26.       contrast=Contrast;
  27.     }
  28.     jjPALCOLOR getResult(jjPALCOLOR input) const override{
  29.       array<int> comp={input.red,input.green,input.blue};
  30.       for(uint i=0;i<3;i++){
  31.         comp[i]=int(max(0,min(255,(comp[i]-128)*contrast+128)));
  32.       }
  33.       return jjPALCOLOR(comp[0],comp[1],comp[2]);
  34.     }
  35.   }
  36.   class colorDecompositionMax:colorEffect{
  37.     jjPALCOLOR getResult(jjPALCOLOR input) const override{
  38.       jjPALCOLOR output;
  39.       output.red=output.green=output.blue=max(max(input.red,input.green),input.blue);
  40.       return output;
  41.     }
  42.   }
  43.   class colorDecompositionMin:colorEffect{
  44.     jjPALCOLOR getResult(jjPALCOLOR input) const override{
  45.       jjPALCOLOR output;
  46.       output.red=output.green=output.blue=min(min(input.red,input.green),input.blue);
  47.       return output;
  48.     }
  49.   }
  50.   class colorFade:colorEffect{
  51.     private array<int> color;
  52.     private float invAlpha;
  53.     colorFade(jjPALCOLOR Color,float Alpha){
  54.       color.resize(3);
  55.       const float alpha=max(0,min(1,Alpha));
  56.       color[0]=int(Color.red*alpha);
  57.       color[1]=int(Color.green*alpha);
  58.       color[2]=int(Color.blue*alpha);
  59.       invAlpha=1-alpha;
  60.     }
  61.     jjPALCOLOR getResult(jjPALCOLOR input) const override{
  62.       array<int> comp={input.red,input.green,input.blue};
  63.       for(uint i=0;i<3;i++){
  64.         comp[i]=int(comp[i]*invAlpha+color[i]);
  65.       }
  66.       return jjPALCOLOR(comp[0],comp[1],comp[2]);
  67.     }
  68.   }
  69.   class colorGamma:colorEffect{
  70.     private array<int> lookupTable;
  71.     colorGamma(float gamma){
  72.       const float inverseGamma=gamma>0?1/gamma:INF;
  73.       lookupTable.resize(256);
  74.       for(uint i=0;i<256;i++){
  75.         lookupTable[i]=int(255*pow(i/255.f,inverseGamma));
  76.       }
  77.     }
  78.     jjPALCOLOR getResult(jjPALCOLOR input) const override{
  79.       array<int> comp={input.red,input.green,input.blue};
  80.       for(uint i=0;i<3;i++){
  81.         comp[i]=lookupTable[comp[i]];
  82.       }
  83.       return jjPALCOLOR(comp[0],comp[1],comp[2]);
  84.     }
  85.   }
  86.   class colorGlow:colorEffect{
  87.     private int hue;
  88.     private int sat;
  89.     private int light;
  90.     colorGlow(jjPALCOLOR color){
  91.       hue=color.getHue();
  92.       sat=color.getSat();
  93.       light=color.getLight();
  94.     }
  95.     jjPALCOLOR getResult(jjPALCOLOR input) const override{
  96.       jjPALCOLOR output;
  97.       output.setHSL(hue,sat,light*max(max(input.red,input.green),input.blue)/255);
  98.       return output;
  99.     }
  100.   }
  101.   class colorGradient:colorEffect{
  102.     private array<int> color;
  103.     colorGradient(jjPALCOLOR light,jjPALCOLOR dark){
  104.       color.resize(6);
  105.       color[0]=light.red;
  106.       color[1]=light.green;
  107.       color[2]=light.blue;
  108.       color[3]=dark.red;
  109.       color[4]=dark.green;
  110.       color[5]=dark.blue;
  111.     }
  112.     jjPALCOLOR getResult(jjPALCOLOR input) const override{
  113.       const float alpha=(input.red*0.3f+input.green*0.59f+input.blue*0.11f)/255;
  114.       array<int> comp(3);
  115.       for(uint i=0;i<3;i++){
  116.         comp[i]=int(color[i+3]*(1-alpha)+color[i]*alpha);
  117.       }
  118.       return jjPALCOLOR(comp[0],comp[1],comp[2]);
  119.     }
  120.   }
  121.   class colorGrayscale:colorEffect{
  122.     jjPALCOLOR getResult(jjPALCOLOR input) const override{
  123.       jjPALCOLOR output;
  124.       output.red=output.green=output.blue=int(input.red*0.3f+input.green*0.59f+input.blue*0.11f);
  125.       return output;
  126.     }
  127.   }
  128.   class colorInput:colorEffect{
  129.     jjPALCOLOR getResult(jjPALCOLOR input) const override{
  130.       return input;
  131.     }
  132.   }
  133.   class colorNegative:colorEffect{
  134.     jjPALCOLOR getResult(jjPALCOLOR input) const override{
  135.       array<int> comp={input.red,input.green,input.blue};
  136.       for(uint i=0;i<3;i++){
  137.         comp[i]=255-comp[i];
  138.       }
  139.       return jjPALCOLOR(comp[0],comp[1],comp[2]);
  140.     }
  141.   }
  142.   class colorReduction:colorEffect{
  143.     private array<uint> size;
  144.     colorReduction(uint8 redBits,uint8 greenBits,uint8 blueBits){
  145.       const array<uint8> bits={redBits,greenBits,blueBits};
  146.       size.resize(3);
  147.       for(uint i=0;i<3;i++){
  148.         size[i]=max(1,256>>bits[i]);
  149.       }
  150.     }
  151.     jjPALCOLOR getResult(jjPALCOLOR input) const override{
  152.       array<int> comp={input.red,input.green,input.blue};
  153.       for(uint i=0;i<3;i++){
  154.         comp[i]=comp[i]/size[i]*255/max(1,255/size[i]);
  155.       }
  156.       return jjPALCOLOR(comp[0],comp[1],comp[2]);
  157.     }
  158.   }
  159.   class colorReplace:colorEffect{
  160.     private jjPALCOLOR color;
  161.     colorReplace(jjPALCOLOR Color){
  162.       color=Color;
  163.     }
  164.     jjPALCOLOR getResult(jjPALCOLOR=jjPALCOLOR()) const override{
  165.       return color;
  166.     }
  167.   }
  168.   class colorSaturate:colorEffect{
  169.     private float value;
  170.     colorSaturate(float Value){
  171.       value=1+max(-1,min(1,Value));
  172.     }
  173.     jjPALCOLOR getResult(jjPALCOLOR input) const override{
  174.       jjPALCOLOR output;
  175.       output.setHSL(input.getHue(),min(255,int(input.getSat()*value)),input.getLight());
  176.       return output;
  177.     }
  178.   }
  179.   class colorSepia:colorEffect{
  180.     jjPALCOLOR getResult(jjPALCOLOR input) const override{
  181.       return jjPALCOLOR(
  182.         min(255,int(input.red*0.393f+input.green*0.769f+input.blue*0.189f)),
  183.         min(255,int(input.red*0.349f+input.green*0.686f+input.blue*0.168f)),
  184.         int(input.red*0.272f+input.green*0.534f+input.blue*0.131f));
  185.     }
  186.   }
  187.   class colorShiftHue:colorEffect{
  188.     private int hue;
  189.     colorShiftHue(int Hue){
  190.       hue=Hue%256;
  191.     }
  192.     jjPALCOLOR getResult(jjPALCOLOR input) const override{
  193.       jjPALCOLOR output;
  194.       output.setHSL(input.getHue()+hue,input.getSat(),input.getLight());
  195.       return output;
  196.     }
  197.   }
  198.   class colorSketch:colorEffect{
  199.     private int threshold;
  200.     colorSketch(int8 Threshold){
  201.       threshold=2*Threshold;
  202.     }
  203.     jjPALCOLOR getResult(jjPALCOLOR input) const override{
  204.       const int light=max(0,min(255,(int(input.red*0.3f+input.green*0.59f+input.blue*0.11f-threshold))*4));
  205.       return jjPALCOLOR(40+light*186/255,40+light*173/255,40+light*131/255);
  206.     }
  207.   }
  208.   class colorSolarize:colorEffect{
  209.     jjPALCOLOR getResult(jjPALCOLOR input) const override{
  210.       array<int> comp={input.red,input.green,input.blue};
  211.       for(uint i=0;i<3;i++){
  212.         if(comp[i]<128){
  213.           comp[i]=255-comp[i];
  214.         }
  215.       }
  216.       return jjPALCOLOR(comp[0],comp[1],comp[2]);
  217.     }
  218.   }
  219.   jjPAL@ palEffect(const jjPAL &in source,const colorEffect@ effect,bool abstract=false){
  220.     if(effect is null) return null;
  221.     jjPAL result;
  222.     for(int i=0;i<256;i++){
  223.       if((i==0||i==15||i==255)&&!abstract){
  224.         result.color[i]=source.color[i];
  225.         continue;
  226.       }
  227.       result.color[i]=effect.getResult(source.color[i]);
  228.     }
  229.     return result;
  230.   }
  231.   jjPAL@ palEffect(const jjPAL &in source,uint8 start,uint8 end,const colorEffect@ effect,const colorEffect@ sectionEffect,bool abstract=false){
  232.     if(effect is null||sectionEffect is null) return null;
  233.     jjPAL result;
  234.     jjPALCOLOR output;
  235.     result.color[0]=source.color[0];
  236.     for(uint i=0;i<256;i++){
  237.       if((i==0||i==15||i==255)&&!abstract){
  238.         result.color[i]=source.color[i];
  239.         continue;
  240.       }
  241.       if(i>=start&&i<=end) output=sectionEffect.getResult(source.color[i]);
  242.       else output=effect.getResult(source.color[i]);
  243.       result.color[i]=output;
  244.     }
  245.     return result;
  246.   }
  247.   jjPAL@ palMix(const jjPAL &in source1,const jjPAL &in source2,float alpha,bool abstract=false){
  248.     jjPAL result=source2;
  249.     uint8 start=abstract?0:1;
  250.     result.copyFrom(start,255-start,start,source1,alpha);
  251.     return result;
  252.   }
  253.   jjPALCOLOR palcolorMix(jjPALCOLOR source1,jjPALCOLOR source2,float alpha){
  254.     array<int> comp={source1.red,source1.green,source1.blue,source2.red,source2.green,source2.blue};
  255.     for(uint i=0;i<3;i++){
  256.       comp[i]=int(comp[i]*alpha+comp[i+3]*(1-alpha));
  257.     }
  258.     return jjPALCOLOR(comp[0],comp[1],comp[2]);
  259.   }
  260. }