summaryrefslogtreecommitdiff
path: root/effects_software.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'effects_software.cpp')
-rw-r--r--effects_software.cpp143
1 files changed, 143 insertions, 0 deletions
diff --git a/effects_software.cpp b/effects_software.cpp
index 27023e6..71023e0 100644
--- a/effects_software.cpp
+++ b/effects_software.cpp
@@ -47,3 +47,146 @@ Effect_Software_DrawColor(int Width, int Height, int BytesPerPixel, void *Effect
}
}
}
+static void
+CurvesSolver(real32 *LUT, v2 Point_P1, v2 Point_P2, v2 m1, v2 m2, int i)
+{
+
+ real32 Precision = ((real32)1 / 256) * 0.1;
+ real32 Point_Span = Point_P2.x - Point_P1.x;
+ v2 Cache[256];
+
+ if (i == 0) {
+ // Don't know how to fix this, so I'm just gonna linear interpolate
+ // until I try quadratic solving.
+ real32 Count_Start = (Point_P1.x * 256);
+ real32 Count_End = (Point_P2.x * 256);
+ real32 Count_Total = Count_End - Count_Start;
+ real32 Width = Point_P2.x - Point_P1.x;
+ real32 Height = Point_P2.y - Point_P1.y;
+ real32 Count = Count_Start;
+ real32 t = 1;
+ while (Count < Count_End) {
+ LUT[(uint32)Count] = Normalize(Point_P1.y + (Height*((Count-Count_Start)/(Count_End - (Count_End - 256)))/Width));
+ Count++;
+ }
+ } else {
+ real32 Count_Start = (Point_P1.x * 256);
+ real32 Count_End = (Point_P2.x * 256);
+ real32 Count_Total = Count_End - Count_Start;
+ real32 Count = Count_Start;
+ real32 t = 0;
+ while (Count < Count_End) {
+
+ real32 c = 2*t*t*t - 3*t*t;
+ real32 c0 = c + 1;
+ real32 c1 = t*t*t - 2*t*t + t;
+ real32 c2 = -c;
+ real32 c3 = t*t*t - t*t;
+
+ v2 Point = (c0 * Point_P1) + (c1 * m1) + (c2 * Point_P2) + (c3 * m2);
+
+ real32 TargetX = Count / 256;
+
+ // Only record the value if it's within a certain precision.
+
+ if (Point.x <= TargetX - Precision ||
+ Point.x >= TargetX + Precision) {
+ t = t * TargetX / Point.x;
+ } else {
+ if (Point.y > 1.0f) {
+ LUT[(uint32)Count] = 1.0f;
+ } else if (Point.y < 0.0f)
+ LUT[(uint32)Count] = 0.0f;
+ else {
+ LUT[(uint32)Count] = Point.y;
+ }
+ t += (Point_Span / Count_Total);
+ Count++;
+ }
+ }
+ }
+}
+
+/*
+static void
+Effect_Curves(file_source *Source, void *BitmapAddress, uint16 ShaderProgram, uint8 *FileEffectAddress)
+{
+ uint32 ChannelIndex = *(uint32 *)(real32 *)FileEffectAddress;
+ FileEffectAddress += sizeof(real32);
+ real32 NumberOfPoints_Main = *(real32 *)FileEffectAddress;
+ FileEffectAddress += sizeof(real32);
+ v4 NumberOfPoints_Col = *(v4 *)FileEffectAddress;
+ FileEffectAddress += sizeof(v4);
+
+ real32 LUT[5][256] = {};
+
+ for (int a = 0; a < 5; a++) {
+
+ int Num = (a == 0) ? NumberOfPoints_Main : NumberOfPoints_Col.E[a-1];
+ v2 *CurvePoint = (v2 *)(FileEffectAddress + (a * (sizeof(v2) * 10)));
+
+ for (int i = 0; i < Num; i++) {
+ v2 Point_P1 = CurvePoint[i];
+ v2 Point_P2 = CurvePoint[i + 1];
+ v2 Point_P0 = (i != 0) ? CurvePoint[i - 1] : V2(0, 0);
+ v2 Point_P3 = (i != (Num - 2)) ? CurvePoint[i + 2] : V2(1, 1);
+
+ v2 m1 = (Point_P2 - Point_P0) / (2 * Tau);
+ v2 m2 = (Point_P3 - Point_P1) / (2 * Tau);
+
+ CurvesSolver(LUT[a], Point_P1, Point_P2, m1, m2, i);
+ }
+
+ if (CurvePoint[0].x > 0.0f) {
+ real32 Count_Start = 0;
+ real32 Count_End = (CurvePoint[0].x * 255);
+ real32 Count = Count_Start;
+ while (Count < Count_End) {
+ LUT[a][(uint32)Count] = LUT[a][(uint32)Count_End];
+ Count++;
+ }
+ }
+
+ if (CurvePoint[Num-1].x < 1.0f) {
+ real32 Count_Start = (CurvePoint[Num-1].x * 255) - 0.5;
+ real32 Count_End = 255;
+ real32 Count = Count_Start;
+ while (Count < Count_End) {
+ LUT[a][(uint32)Count] = LUT[a][(uint32)Count_Start];
+ Count++;
+ }
+ }
+
+ for (int i = 0; i < Num; i++) {
+ if (CurvePoint[i].y == 1.0f)
+ LUT[a][255] = 1.0f;
+ }
+ }
+
+
+ uint64 Size = Source->Width*Source->Height;
+ int i = 0;
+ Assert(BytesPerPixel == 4);
+ while (i < Size) {
+ uint32 *Pixel = (uint32 *)BitmapAddress + i;
+ v4 t = Uint32ToCol8(*Pixel);
+
+ real32 R_Lookup = LUT[1][(uint32)(t.r)];
+ real32 G_Lookup = LUT[2][(uint32)(t.g)];
+ real32 B_Lookup = LUT[3][(uint32)(t.b)];
+ real32 A_Lookup = LUT[4][(uint32)(t.a)];
+
+ real32 R_Lookup_All = LUT[0][(uint32)(R_Lookup*255)];
+ real32 G_Lookup_All = LUT[0][(uint32)(G_Lookup*255)];
+ real32 B_Lookup_All = LUT[0][(uint32)(B_Lookup*255)];
+
+ uint32 Result = (((uint32)((A_Lookup * 255.0f) + 0.5) << 24) |
+ ((uint32)((B_Lookup_All * 255.0f) + 0.5) << 16) |
+ ((uint32)((G_Lookup_All * 255.0f) + 0.5) << 8) |
+ ((uint32)((R_Lookup_All * 255.0f) + 0.5) << 0));
+
+ *Pixel = Result;
+ i++;
+ }
+}
+*/