Moved functionalities to library iMGcompress-core
This commit is contained in:
2025-01-23 12:53:22 +01:00
parent 87b7ef4fdf
commit 5152a87ffa
9 changed files with 70 additions and 36 deletions
+24 -4
View File
@@ -8,20 +8,36 @@
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Remove="itext_pdfimage\**" />
<EmbeddedResource Remove="itext_pdfimage\**" />
<None Remove="itext_pdfimage\**" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Compressor.cs" />
<Compile Remove="FileParser.cs" />
<Compile Remove="ImageExtractor.cs" />
<Compile Remove="ImageExtractor7.cs" />
<Compile Remove="Logger.cs" />
<Compile Remove="PixelMap.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BinaryKits.Zpl.Viewer" Version="1.2.1" />
<PackageReference Include="GroupDocs.Parser" Version="23.8.0" />
<PackageReference Include="Imazen.WebP" Version="10.0.1" />
<PackageReference Include="itext7" Version="8.0.1" />
<PackageReference Include="iTextSharp" Version="5.5.13.3" />
<PackageReference Include="iTextSharp" Version="5.5.13.4" />
<PackageReference Include="LibHeifSharp" Version="3.2.0" />
<PackageReference Include="Magick.NET-Q8-x64" Version="13.6.0" />
<PackageReference Include="Magick.NET.SystemDrawing" Version="7.2.2" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.1.1" />
<PackageReference Include="Pastel" Version="5.1.0" />
<PackageReference Include="Pastel" Version="6.0.0" />
<PackageReference Include="Pdfbox" Version="1.1.1" />
<PackageReference Include="sharpcompress" Version="0.37.2" />
<PackageReference Include="System.Drawing.Common" Version="8.0.0" />
<PackageReference Include="sharpcompress" Version="0.38.0" />
<PackageReference Include="System.Drawing.Common" Version="9.0.0" />
<PackageReference Include="Xabe.FFmpeg" Version="5.2.6" />
<PackageReference Include="Xabe.FFmpeg.Downloader" Version="5.2.6" />
</ItemGroup>
@@ -30,5 +46,9 @@
<Content CopyToOutputDirectory="PreserveNewest" Include="libwebp.dll" Link="libwebp.dll" Pack="true" PackagePath="libwebp.dll" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\iMGcompress-core\iMGcompress-core.csproj" />
</ItemGroup>
</Project>
+1 -1
View File
@@ -4,7 +4,7 @@
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup>
<ActiveDebugProfile>DEV_HOME</ActiveDebugProfile>
<ActiveDebugProfile>ComicCompress CBx</ActiveDebugProfile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
+12
View File
@@ -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
+9 -8
View File
@@ -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<string, file_stat> 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<string, file_stat> 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);
}
+2
View File
@@ -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;
+1 -1
View File
@@ -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;
+16 -21
View File
@@ -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,6 +36,9 @@ using System.Reflection;
using Microsoft.VisualBasic;
using BinaryKits.Zpl.Viewer;
using iMGcompress_core;
using Compressor = iMGcompress_core.Compressor;
namespace ComicCompressor
{
public class Program
@@ -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<Program>(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 <string, file_stat> file_statistics = new Dictionary<string, file_stat>();
public static Dictionary<string, file_stat> 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)
{
+4
View File
@@ -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"
}
}
}
BIN
View File
Binary file not shown.