diff --git a/ComicCompress.csproj b/ComicCompress.csproj index 8d860f2..5eae267 100644 --- a/ComicCompress.csproj +++ b/ComicCompress.csproj @@ -8,20 +8,36 @@ True + + + + + + + + + + + + + + + + - + - + - - + + @@ -30,5 +46,9 @@ + + + + diff --git a/ComicCompress.csproj.user b/ComicCompress.csproj.user index e2ee5ae..be5151e 100644 --- a/ComicCompress.csproj.user +++ b/ComicCompress.csproj.user @@ -4,7 +4,7 @@ ProjectDebugger - DEV_HOME + ComicCompress CBx ProjectDebugger diff --git a/ComicCompress.sln b/ComicCompress.sln index 7b2586c..29882c1 100644 --- a/ComicCompress.sln +++ b/ComicCompress.sln @@ -5,6 +5,10 @@ VisualStudioVersion = 17.5.33530.505 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComicCompress", "ComicCompress.csproj", "{2625C71D-E4EC-4768-BF04-87AAB364916A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "iMGcompress-core", "..\iMGcompress-core\iMGcompress-core.csproj", "{E0CADD9B-0210-441D-9A66-1ABB861553E6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "iMGcompress", "..\iMGcompress\iMGcompress.csproj", "{1253AD50-D3B8-4360-B654-FC4A861D7FEC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +19,14 @@ Global {2625C71D-E4EC-4768-BF04-87AAB364916A}.Debug|Any CPU.Build.0 = Debug|Any CPU {2625C71D-E4EC-4768-BF04-87AAB364916A}.Release|Any CPU.ActiveCfg = Release|Any CPU {2625C71D-E4EC-4768-BF04-87AAB364916A}.Release|Any CPU.Build.0 = Release|Any CPU + {E0CADD9B-0210-441D-9A66-1ABB861553E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E0CADD9B-0210-441D-9A66-1ABB861553E6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E0CADD9B-0210-441D-9A66-1ABB861553E6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E0CADD9B-0210-441D-9A66-1ABB861553E6}.Release|Any CPU.Build.0 = Release|Any CPU + {1253AD50-D3B8-4360-B654-FC4A861D7FEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1253AD50-D3B8-4360-B654-FC4A861D7FEC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1253AD50-D3B8-4360-B654-FC4A861D7FEC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1253AD50-D3B8-4360-B654-FC4A861D7FEC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Compressor.cs b/Compressor.cs index f11f16d..ba3f5d3 100644 --- a/Compressor.cs +++ b/Compressor.cs @@ -14,6 +14,7 @@ using javax.swing.plaf; using SharpCompress.Readers; using SharpCompress.Writers; using SharpCompress.Compressors.Xz; +using iMGcompress_core; //using SixLabors.ImageSharp; //using SixLabors.ImageSharp; //using SixLabors.ImageSharp.Processing; @@ -31,8 +32,8 @@ namespace ComicCompressor { Logger = logger; } - - public void Compress(string filename, string outputFile = null) +#if true + public void Compress(string filename, string outputFile = null, Dictionary file_statistics = null) { Stopwatch sw = Stopwatch.StartNew(); outputFile = Path.ChangeExtension(outputFile ?? filename, "cbz"); @@ -91,12 +92,12 @@ namespace ComicCompressor } } else - (save, num_pages) = ProcessArchive(archive, outputFile, filename); + (save, num_pages) = ProcessArchive(archive, outputFile, filename, file_statistics); 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); } - +#endif private (double, int) ProcessReader(IArchive archive, IReader reader, string outputPath) { var encoder = new SimpleEncoder(); @@ -179,7 +180,7 @@ namespace ComicCompressor { return ((value % (place * 10)) - (value % place)) / place; } - private (double, int) ProcessArchive(IArchive archive, string outputPath, string inputPath) + private (double, int) ProcessArchive(IArchive archive, string outputPath, string inputPath, Dictionary file_statistics = null) { //var fileEntries = archive.Entries.Where(e => !e.IsDirectory); var fileEntries = archive.Entries.Where(e => !e.IsDirectory).OrderBy(e => e.Key); @@ -226,13 +227,13 @@ namespace ComicCompressor save = 100 * (double)output_length / (double)archive.TotalSize; - Program.file_stat fs = null; - Program.File_statistics.TryGetValue(inputPath, out fs); + file_stat fs = null; + 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); + file_statistics.TryAdd(inputPath, fs); } diff --git a/ImageExtractor.cs b/ImageExtractor.cs index 8ce5c8e..5eb9e41 100644 --- a/ImageExtractor.cs +++ b/ImageExtractor.cs @@ -7,6 +7,8 @@ using System.Runtime.ConstrainedExecution; using ikvm.extensions; using Imazen.WebP; +using iMGcompress_core; + using iTextSharp.text.pdf; using iTextSharp.text.pdf.parser; diff --git a/Logger.cs b/Logger.cs index 6a025bb..4ead196 100644 --- a/Logger.cs +++ b/Logger.cs @@ -7,7 +7,7 @@ using Pastel; namespace ComicCompressor { - public class Logger + public class Logger_OFF { public LogLevel LoggingLevel { get; set; } = LogLevel.Warning; public bool Debug = false; diff --git a/Program.cs b/Program.cs index e65235f..3a24ea6 100644 --- a/Program.cs +++ b/Program.cs @@ -22,7 +22,7 @@ using Xabe.FFmpeg; using SharpCompress.Archives; using SharpCompress.Archives.Zip; using SharpCompress.Common; -using itext.pdfimage.Extensions; +//using itext.pdfimage.Extensions; using org.omg.PortableInterceptor; using org.apache.pdfbox.util.@operator; using java.nio; @@ -36,12 +36,15 @@ using System.Reflection; using Microsoft.VisualBasic; using BinaryKits.Zpl.Viewer; +using iMGcompress_core; +using Compressor = iMGcompress_core.Compressor; + namespace ComicCompressor { public class Program { - // string progVersion = "Version 2.0.0 - (04/07/2024)"; + // string progVersion = "Version 2.0.0 - (04/07/2024)"; // Added copy of non image files with same name //string progVersion = "Version 2.0.1 - (12/08/2024)"; @@ -50,8 +53,13 @@ namespace ComicCompressor //string progVersion = "Version 2.0.2 - (27/08/2024)"; // Completed support for ZEBRA PRN files, generate image and base64 for prn and image. Using URI format for base64 files - string progVersion = "Version 2.1.0 - (28/08/2024)"; + //string progVersion = "Version 2.1.0 - (28/08/2024)"; + // Moved functionalities to library iMGcompress-core + //string progVersion = "Version 3.0.0 - (21/11/2024)"; + + // In core changed color of percent save to white + string progVersion = "Version 3.0.1 - (23/01/2025)"; public static int Main(string[] args) => CommandLineApplication.Execute(args); #region INPUT_FLAGS @@ -80,7 +88,6 @@ namespace ComicCompressor [Option("-c|--cpu", Description = "Run in parallel, use given number of CPUs")] public int NumOfCpu { get; } = Environment.ProcessorCount; - [Option("-d|--pdf", Description = "Process pdf only")] public bool DoPdf { get; } = false; @@ -96,18 +103,6 @@ namespace ComicCompressor #region STATISTICS - public class file_stat - { - public string Filename { get; set; } - public file_stat(string filename) { - Filename = filename; - } - public long Uncompressed_file_len { get; set; } - public long Compressed_file_len { get; set; } - - - } - static Dictionary file_statistics = new Dictionary(); public static Dictionary File_statistics { get => file_statistics; set => file_statistics = value; } @@ -141,7 +136,7 @@ namespace ComicCompressor Stopwatch sw = Stopwatch.StartNew(); Logger = new Logger(); - Logger.Debug = true; + Logger.DebugOn = true; Logger.LoggingLevel = LogLevel.Verbose; Logger.Log(progVersion, LogLevel.Verbose, true); @@ -276,7 +271,7 @@ namespace ComicCompressor { long lengthin = new System.IO.FileInfo(filename).Length; long lengthout = new System.IO.FileInfo(outputPath).Length; - Program.file_stat fs = null; + file_stat fs = null; Program.File_statistics.TryGetValue(filename, out fs); if (fs != null) { @@ -293,7 +288,7 @@ namespace ComicCompressor { long lengthin = new System.IO.FileInfo(filename).Length; long lengthout = new System.IO.FileInfo(outputPath_webp).Length; - Program.file_stat fs = null; + file_stat fs = null; Program.File_statistics.TryGetValue(filename, out fs); if (fs != null) { @@ -313,7 +308,7 @@ namespace ComicCompressor long lengthin = new System.IO.FileInfo(filename).Length; long lengthout = new System.IO.FileInfo(outputPath).Length; - Program.file_stat fs = null; + file_stat fs = null; Program.File_statistics.TryGetValue(filename, out fs); if (fs != null) { @@ -399,7 +394,7 @@ namespace ComicCompressor long lengthin = new System.IO.FileInfo(filename).Length; long lengthout = new System.IO.FileInfo(outputPath).Length; - Program.file_stat fs = null; + file_stat fs = null; Program.File_statistics.TryGetValue(filename, out fs); if (fs != null) { @@ -441,7 +436,7 @@ namespace ComicCompressor try { - compressor.Compress(filename, outputPath); + compressor.Compress(filename, outputPath, file_statistics); } catch (Exception e) { diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json index 65d0ded..d08af6d 100644 --- a/Properties/launchSettings.json +++ b/Properties/launchSettings.json @@ -31,6 +31,10 @@ "DEV_HOME": { "commandName": "Project", "commandLineArgs": "-i \"D:\\SynologyDrive\\A\\_PRINT_TEMPLATES_\\DEV_IN\" -o \"D:\\SynologyDrive\\A\\_PRINT_TEMPLATES_\\DEV_OUT\" -r -s -j -a -n" + }, + "ComicCompress CBx": { + "commandName": "Project", + "commandLineArgs": "-i _IMG_ -o _IMG_PDF_ -r -s -d" } } } \ No newline at end of file diff --git a/pdfimages.exe b/pdfimages.exe new file mode 100644 index 0000000..08a87cd Binary files /dev/null and b/pdfimages.exe differ