summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatthewsotoudeh <matthewsot@outlook.com>2016-04-12 17:18:39 -0700
committermatthewsotoudeh <matthewsot@outlook.com>2016-04-12 17:18:39 -0700
commit10a97c0a45884c9584eeb1f01a79787826b4cb8d (patch)
tree623eda599c93196e2de374daeeaaf3fa78360625
parentb0cea92dd1fcd0ee325069652f5598b4a783a99c (diff)
fixed an issue with compression
it was acting sketchy around inARow = 16 and the end of a line
-rw-r--r--NImg/NImg/Compressor.cs22
-rw-r--r--NImg/NImg/Program.cs2
-rw-r--r--NImg/NImg/Reconstructor.cs2
3 files changed, 16 insertions, 10 deletions
diff --git a/NImg/NImg/Compressor.cs b/NImg/NImg/Compressor.cs
index de04bb9..078f8aa 100644
--- a/NImg/NImg/Compressor.cs
+++ b/NImg/NImg/Compressor.cs
@@ -83,8 +83,7 @@ namespace NImg
writer.Write(originalImage.Width);
writer.Write(originalImage.Height);
writer.Write(Convert.ToByte(colorIndexBytes));
-
- var reconstructedImage = new Bitmap(originalImage.Width, originalImage.Height);
+
var hits = 0;
var misses = 0;
@@ -120,17 +119,27 @@ namespace NImg
}
var roundedToUse = new int[] { (int)Math.Round(toUse[0]), (int)Math.Round(toUse[1]), (int)Math.Round(toUse[2]) };
- if (good && inARow < 16 && xPixel != originalImage.Width - 1) //TODO: double check this
+ if (good && inARow < 15 && xPixel < originalImage.Width - 1)
+ {
+ inARow++;
+ }
+ else if (good && (inARow == 15 || xPixel == originalImage.Width - 1))
{
+ //NOTE: 11110000 -> inARow = 1, not 0, increase by 1
inARow++;
+ Console.WriteLine(inARow);
+ // "Use AI" bytes start are in the form 1111 + (number of pixels)
+ writer.Write(Convert.ToByte("1111" + Convert.ToString(inARow - 1, 2).PadLeft(4, '0'), 2));
+ inARow = 0;
}
else
{
if (inARow > 0)
{
+ //NOTE: 11110000 -> inARow = 1, not 0, increase by 1
Console.WriteLine(inARow);
// "Use AI" bytes start are in the form 1111 + (number of pixels)
- writer.Write(Convert.ToByte("1111" + Convert.ToString(inARow, 2).PadLeft(8, '0').Substring(4), 2));
+ writer.Write(Convert.ToByte("1111" + Convert.ToString(inARow - 1, 2).PadLeft(8, '0').Substring(4), 2));
inARow = 0;
}
@@ -218,15 +227,10 @@ namespace NImg
input[input.Length - 3] = toUse[0] / 255;
input[input.Length - 2] = toUse[1] / 255;
input[input.Length - 1] = toUse[2] / 255;
-
- var colorToUse = Color.FromArgb((int)Math.Round(toUse[0]), (int)Math.Round(toUse[1]), (int)Math.Round(toUse[2]));
- reconstructedImage.SetPixel(xPixel, yPixel, colorToUse);
}
}
Console.WriteLine("Hits: " + hits + " Misses: " + misses);
Console.WriteLine((double)(((double)hits / (double)(hits + misses)) * 100) + "%");
-
- reconstructedImage.Save("reconstructed.png", System.Drawing.Imaging.ImageFormat.Png);
}
}
}
diff --git a/NImg/NImg/Program.cs b/NImg/NImg/Program.cs
index cd5c9e1..a5c1efe 100644
--- a/NImg/NImg/Program.cs
+++ b/NImg/NImg/Program.cs
@@ -10,6 +10,7 @@ namespace NImg
{
case "compress":
Compressor.Compress(args[1]);
+ //Reconstructor.Reconstruct(args[1].Replace(".png", ".nimg"), true);
break;
case "reconstruct":
if (args.Length >= 3 && args[2] == "demo")
@@ -21,6 +22,7 @@ namespace NImg
Reconstructor.Reconstruct(args[1], false);
break;
}
+ Console.WriteLine("Completed, press Enter to exit.");
Console.ReadLine();
}
}
diff --git a/NImg/NImg/Reconstructor.cs b/NImg/NImg/Reconstructor.cs
index ae136e6..6ef62cf 100644
--- a/NImg/NImg/Reconstructor.cs
+++ b/NImg/NImg/Reconstructor.cs
@@ -78,7 +78,7 @@ namespace NImg
var byteStr = Convert.ToString(reader.ReadByte(), 2).PadLeft(8, '0');
if (byteStr.StartsWith("1111"))
{
- var inARow = Convert.ToInt32(byteStr.Substring(4).PadLeft(8, '0'), 2);
+ var inARow = Convert.ToInt32(byteStr.Substring(4).PadLeft(8, '0'), 2) + 1; // 11110000 -> 1, not 0
for (var i = 0; i < inARow; i++)
{
if (demoMode)
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback