Skip to content

Commit

Permalink
sync back fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWandererProductions committed Oct 15, 2024
1 parent 4dda277 commit c88c7d2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 13 deletions.
10 changes: 5 additions & 5 deletions Imaging/DirectBitmapImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ public void ApplyColorMatrix(float[][] matrix)
// Log color after bias addition
Debug.WriteLine($"After adding bias: R={result[0]}, G={result[1]}, B={result[2]}, A={result[3]}");

// Clamp the values to [0, 255]
result[0] = Math.Clamp(result[0], 0, 255);
result[1] = Math.Clamp(result[1], 0, 255);
result[2] = Math.Clamp(result[2], 0, 255);
result[3] = Math.Clamp(result[3], 0, 255);
// Clamp the values to [0, 255] and round down
result[0] = (int)Math.Ceiling(Math.Clamp(result[0], 0, 255));
result[1] = (int)Math.Ceiling(Math.Clamp(result[1], 0, 255));
result[2] = (int)Math.Ceiling(Math.Clamp(result[2], 0, 255));
result[3] = (int)Math.Ceiling(Math.Clamp(result[3], 0, 255));

// Log clamped values
Debug.WriteLine($"Clamped values: R={result[0]}, G={result[1]}, B={result[2]}, A={result[3]}");
Expand Down
21 changes: 13 additions & 8 deletions Imaging/ImageFilterStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,19 @@ internal static Bitmap Pixelate(Image image, int stepWidth)
for (var y = 0; y < dbm.Height; y += stepWidth)
for (var x = 0; x < dbm.Width; x += stepWidth)
{
// Get the color of the current rectangle
var rectangle = new Rectangle(x, y, stepWidth, stepWidth);
var averageColor = ImageHelper.GetMeanColor(dbm, rectangle);

using var g = Graphics.FromImage(processedImage);
using var brush = new SolidBrush(averageColor);
g.FillRectangle(brush, x, y, stepWidth, stepWidth);
}
// Ensure the rectangle doesn't exceed image boundaries
var rectWidth = Math.Min(stepWidth, dbm.Width - x);
var rectHeight = Math.Min(stepWidth, dbm.Height - y);

// Get the color of the current rectangle
var rectangle = new Rectangle(x, y, rectWidth, rectHeight);
var averageColor = ImageHelper.GetMeanColor(dbm, rectangle);

// Draw the rectangle with the average color
using var g = Graphics.FromImage(processedImage);
using var brush = new SolidBrush(averageColor);
g.FillRectangle(brush, x, y, rectWidth, rectHeight);
}

return processedImage;
}
Expand Down
39 changes: 39 additions & 0 deletions Imaging/LifProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,44 @@ public static Bitmap ConvertToBitmapFromCif(Dictionary<Color, List<int>> cif, in

return bitmap;
}

public static Dictionary<Color, List<int>> CompressCif(Dictionary<Color, List<int>> cif1,
Dictionary<Color, List<int>> cif2, double threshold)
{
if (!AreColorCountsSimilar(GetColorCount(cif1), GetColorCount(cif2), threshold))
{
return cif2; // No compression possible, return the second CIF as is
}

var compressedCif = new Dictionary<Color, List<int>>();

// Store the base CIF data
foreach (var entry in cif1)
{
compressedCif[entry.Key] = new List<int>(entry.Value); // Copy existing pixels
}

// Apply delta logic for similar colors
foreach (var entry in cif2)
{
if (!compressedCif.ContainsKey(entry.Key))
{
compressedCif[entry.Key] = new List<int>();
}
else
{
// Only add new pixels if the color already exists
compressedCif[entry.Key].AddRange(entry.Value);
}
}

return compressedCif;
}

// Helper method to get color counts
private static Dictionary<Color, int> GetColorCount(Dictionary<Color, List<int>> cif)
{
return cif.ToDictionary(entry => entry.Key, entry => entry.Value.Count);
}
}
}

0 comments on commit c88c7d2

Please sign in to comment.