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

//Palette Wizard (v1.1 for Plus Beta Build 2013-10-30 and later) by Sir Ementaler
#pragma require "SEmath.asc"
#include "SEmath.asc"
namespace se{
  interface colorEffect{
    jjPALCOLOR getResult(jjPALCOLOR) const;
  }
  class colorBrighten:colorEffect{
    private float invValue,white;
    colorBrighten(float Value){
      Value=max(-1,min(1,Value));
      invValue=1-abs(Value);
      white=Value>0?Value*255:0;
    }
    jjPALCOLOR getResult(jjPALCOLOR input) const override{
      array<int> comp={input.red,input.green,input.blue};
      for(uint i=0;i<3;i++){
        comp[i]=int(comp[i]*invValue+white);
      }
      return jjPALCOLOR(comp[0],comp[1],comp[2]);
    }
  }
  class colorContrast:colorEffect{
    private float contrast;
    colorContrast(float Contrast){
      contrast=Contrast;
    }
    jjPALCOLOR getResult(jjPALCOLOR input) const override{
      array<int> comp={input.red,input.green,input.blue};
      for(uint i=0;i<3;i++){
        comp[i]=int(max(0,min(255,(comp[i]-128)*contrast+128))); 
      }
      return jjPALCOLOR(comp[0],comp[1],comp[2]);
    }
  }
  class colorDecompositionMax:colorEffect{
    jjPALCOLOR getResult(jjPALCOLOR input) const override{
      jjPALCOLOR output;
      output.red=output.green=output.blue=max(max(input.red,input.green),input.blue);
      return output;
    }
  }
  class colorDecompositionMin:colorEffect{
    jjPALCOLOR getResult(jjPALCOLOR input) const override{
      jjPALCOLOR output;
      output.red=output.green=output.blue=min(min(input.red,input.green),input.blue);
      return output;
    }
  }
  class colorFade:colorEffect{
    private array<int> color;
    private float invAlpha;
    colorFade(jjPALCOLOR Color,float Alpha){
      color.resize(3);
      const float alpha=max(0,min(1,Alpha));
      color[0]=int(Color.red*alpha);
      color[1]=int(Color.green*alpha);
      color[2]=int(Color.blue*alpha);
      invAlpha=1-alpha;
    }
    jjPALCOLOR getResult(jjPALCOLOR input) const override{
      array<int> comp={input.red,input.green,input.blue};
      for(uint i=0;i<3;i++){
        comp[i]=int(comp[i]*invAlpha+color[i]);
      }
      return jjPALCOLOR(comp[0],comp[1],comp[2]);
    }
  }
  class colorGamma:colorEffect{
    private array<int> lookupTable;
    colorGamma(float gamma){
      const float inverseGamma=gamma>0?1/gamma:INF;
      lookupTable.resize(256);
      for(uint i=0;i<256;i++){
        lookupTable[i]=int(255*pow(i/255.f,inverseGamma));
      }
    }
    jjPALCOLOR getResult(jjPALCOLOR input) const override{
      array<int> comp={input.red,input.green,input.blue};
      for(uint i=0;i<3;i++){
        comp[i]=lookupTable[comp[i]]; 
      }
      return jjPALCOLOR(comp[0],comp[1],comp[2]);
    }
  }
  class colorGlow:colorEffect{
    private int hue;
    private int sat;
    private int light;
    colorGlow(jjPALCOLOR color){
      hue=color.getHue();
      sat=color.getSat();
      light=color.getLight();
    }
    jjPALCOLOR getResult(jjPALCOLOR input) const override{
      jjPALCOLOR output;
      output.setHSL(hue,sat,light*max(max(input.red,input.green),input.blue)/255);
      return output;
    }
  }
  class colorGradient:colorEffect{
    private array<int> color;
    colorGradient(jjPALCOLOR light,jjPALCOLOR dark){
      color.resize(6);
      color[0]=light.red;
      color[1]=light.green;
      color[2]=light.blue;
      color[3]=dark.red;
      color[4]=dark.green;
      color[5]=dark.blue;
    }
    jjPALCOLOR getResult(jjPALCOLOR input) const override{
      const float alpha=(input.red*0.3f+input.green*0.59f+input.blue*0.11f)/255;
      array<int> comp(3);
      for(uint i=0;i<3;i++){
        comp[i]=int(color[i+3]*(1-alpha)+color[i]*alpha);
      }
      return jjPALCOLOR(comp[0],comp[1],comp[2]);
    }
  }
  class colorGrayscale:colorEffect{
    jjPALCOLOR getResult(jjPALCOLOR input) const override{
      jjPALCOLOR output;
      output.red=output.green=output.blue=int(input.red*0.3f+input.green*0.59f+input.blue*0.11f);
      return output;
    }
  }
  class colorInput:colorEffect{
    jjPALCOLOR getResult(jjPALCOLOR input) const override{
      return input;
    }
  }
  class colorNegative:colorEffect{
    jjPALCOLOR getResult(jjPALCOLOR input) const override{
      array<int> comp={input.red,input.green,input.blue};
      for(uint i=0;i<3;i++){
        comp[i]=255-comp[i];
      }
      return jjPALCOLOR(comp[0],comp[1],comp[2]);
    }
  }
  class colorReduction:colorEffect{
    private array<uint> size;
    colorReduction(uint8 redBits,uint8 greenBits,uint8 blueBits){
      const array<uint8> bits={redBits,greenBits,blueBits};
      size.resize(3);
      for(uint i=0;i<3;i++){
        size[i]=max(1,256>>bits[i]);
      }
    }
    jjPALCOLOR getResult(jjPALCOLOR input) const override{
      array<int> comp={input.red,input.green,input.blue};
      for(uint i=0;i<3;i++){
        comp[i]=comp[i]/size[i]*255/max(1,255/size[i]);
      }
      return jjPALCOLOR(comp[0],comp[1],comp[2]);
    }
  }
  class colorReplace:colorEffect{
    private jjPALCOLOR color;
    colorReplace(jjPALCOLOR Color){
      color=Color;
    }
    jjPALCOLOR getResult(jjPALCOLOR=jjPALCOLOR()) const override{
      return color;
    }
  }
  class colorSaturate:colorEffect{
    private float value;
    colorSaturate(float Value){
      value=1+max(-1,min(1,Value));
    }
    jjPALCOLOR getResult(jjPALCOLOR input) const override{
      jjPALCOLOR output;
      output.setHSL(input.getHue(),min(255,int(input.getSat()*value)),input.getLight());
      return output;
    }
  }
  class colorSepia:colorEffect{
    jjPALCOLOR getResult(jjPALCOLOR input) const override{
      return jjPALCOLOR(
        min(255,int(input.red*0.393f+input.green*0.769f+input.blue*0.189f)),
        min(255,int(input.red*0.349f+input.green*0.686f+input.blue*0.168f)),
        int(input.red*0.272f+input.green*0.534f+input.blue*0.131f));
    }
  }
  class colorShiftHue:colorEffect{
    private int hue;
    colorShiftHue(int Hue){
      hue=Hue%256;
    }
    jjPALCOLOR getResult(jjPALCOLOR input) const override{
      jjPALCOLOR output;
      output.setHSL(input.getHue()+hue,input.getSat(),input.getLight());
      return output;
    }
  }
  class colorSketch:colorEffect{
    private int threshold;
    colorSketch(int8 Threshold){
      threshold=2*Threshold;
    }
    jjPALCOLOR getResult(jjPALCOLOR input) const override{
      const int light=max(0,min(255,(int(input.red*0.3f+input.green*0.59f+input.blue*0.11f-threshold))*4));
      return jjPALCOLOR(40+light*186/255,40+light*173/255,40+light*131/255);
    }
  }
  class colorSolarize:colorEffect{
    jjPALCOLOR getResult(jjPALCOLOR input) const override{
      array<int> comp={input.red,input.green,input.blue};
      for(uint i=0;i<3;i++){
        if(comp[i]<128){
          comp[i]=255-comp[i];
        }
      }
      return jjPALCOLOR(comp[0],comp[1],comp[2]);
    }
  }
  jjPAL@ palEffect(const jjPAL &in source,const colorEffect@ effect,bool abstract=false){
    if(effect is null) return null;
    jjPAL result;
    for(int i=0;i<256;i++){
      if((i==0||i==15||i==255)&&!abstract){
        result.color[i]=source.color[i];
        continue;
      }
      result.color[i]=effect.getResult(source.color[i]);
    }
    return result;
  }
  jjPAL@ palEffect(const jjPAL &in source,uint8 start,uint8 end,const colorEffect@ effect,const colorEffect@ sectionEffect,bool abstract=false){
    if(effect is null||sectionEffect is null) return null;
    jjPAL result;
    jjPALCOLOR output;
    result.color[0]=source.color[0];
    for(uint i=0;i<256;i++){
      if((i==0||i==15||i==255)&&!abstract){
        result.color[i]=source.color[i];
        continue;
      }
      if(i>=start&&i<=end) output=sectionEffect.getResult(source.color[i]);
      else output=effect.getResult(source.color[i]);
      result.color[i]=output;
    }
    return result;
  }
  jjPAL@ palMix(const jjPAL &in source1,const jjPAL &in source2,float alpha,bool abstract=false){
    jjPAL result=source2;
    uint8 start=abstract?0:1;
    result.copyFrom(start,255-start,start,source1,alpha);
    return result;
  }
  jjPALCOLOR palcolorMix(jjPALCOLOR source1,jjPALCOLOR source2,float alpha){
    array<int> comp={source1.red,source1.green,source1.blue,source2.red,source2.green,source2.blue};
    for(uint i=0;i<3;i++){
      comp[i]=int(comp[i]*alpha+comp[i+3]*(1-alpha));
    }
    return jjPALCOLOR(comp[0],comp[1],comp[2]);
  }
}