Added Compression statistics report in every run

QqAdded support for reading PPM PixelMap image files.
This commit is contained in:
Marco Giuntoni
2024-04-20 13:14:52 +02:00
parent 5473d2170f
commit 4353c4ce98
5 changed files with 794 additions and 22 deletions
+30 -6
View File
@@ -88,7 +88,7 @@ namespace ComicCompressor
}
}
else
(save, num_pages) = ProcessArchive(archive, outputFile);
(save, num_pages) = ProcessArchive(archive, outputFile, filename);
if (num_pages == 0) num_pages = 1;
long elapsed = sw.ElapsedMilliseconds;
Logger.Log($"\r\nFinished({save.ToString("0.##")}%) [{elapsed}][{elapsed/num_pages}]: " + filename, LogLevel.Verbose, col: Color.Green);
@@ -124,6 +124,7 @@ namespace ComicCompressor
if (!entry_key_lower.EndsWith(".jpg") &&
!entry_key_lower.EndsWith(".png") &&
!entry_key_lower.EndsWith(".bmp") &&
!entry_key_lower.EndsWith(".ppm") &&
!entry_key_lower.EndsWith(".gif") &&
!entry_key_lower.EndsWith(".jpeg"))
{
@@ -149,7 +150,6 @@ namespace ComicCompressor
}
ProcessReaderEntry(reader, entryStream, imageStreams, output, encoder);
}
}
}
@@ -175,7 +175,7 @@ namespace ComicCompressor
{
return ((value % (place * 10)) - (value % place)) / place;
}
private (double, int) ProcessArchive(IArchive archive, string outputPath)
private (double, int) ProcessArchive(IArchive archive, string outputPath, string inputPath)
{
//var fileEntries = archive.Entries.Where(e => !e.IsDirectory);
var fileEntries = archive.Entries.Where(e => !e.IsDirectory).OrderBy(e => e.Key);
@@ -222,6 +222,17 @@ namespace ComicCompressor
save = 100 * (double)output_length / (double)archive.TotalSize;
Program.file_stat fs = null;
Program.File_statistics.TryGetValue(inputPath,out fs);
if(fs != null)
{
fs.Uncompressed_file_len = archive.TotalSize;
fs.Compressed_file_len = output_length;
Program.File_statistics.TryAdd(inputPath, fs);
}
return (save, nop);
}
@@ -244,11 +255,13 @@ namespace ComicCompressor
{
return (false,true);
}
string entry_key_lower = entry.Key.ToLower();
bool isPPM = entry_key_lower.EndsWith(".ppm");
if (!entry_key_lower.EndsWith(".jpg") &&
!entry_key_lower.EndsWith(".png") &&
!entry_key_lower.EndsWith(".bmp") &&
!entry_key_lower.EndsWith(".ppm") &&
!entry_key_lower.EndsWith(".gif") &&
!entry_key_lower.EndsWith(".jpeg"))
{
@@ -260,7 +273,7 @@ namespace ComicCompressor
return (false, true);
}
if (cover)
if (cover && !isPPM)
{
var ms = new MemoryStream();
imageStreams.Add(ms);
@@ -276,7 +289,18 @@ namespace ComicCompressor
stream.CopyTo(raw_ms);
try
{
bits = new Bitmap(raw_ms);
if(isPPM)
{
Logger.Log("P", LogLevel.Verbose, false, col: Color.PaleGreen);
PixelMap ppm = new PixelMap(raw_ms);
//bits = ppm.Bitmap;
bits = ppm.BitMap;
Logger.Log("\b", LogLevel.Verbose, false, col: Color.PaleGreen);
}
else
{
bits = new Bitmap(raw_ms);
}
}
catch (Exception e)
{