Skip to content

Commit

Permalink
Let user keep color of images
Browse files Browse the repository at this point in the history
  • Loading branch information
yonixw committed Jan 4, 2021
1 parent 2af915a commit 91f9254
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
8 changes: 5 additions & 3 deletions MangaPrinter.Core/TemplateBuilders/DuplexTemplates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class DuplexTemplates
private string _programVersion = "???";
public DuplexTemplates(string versionString)
{
_programVersion = string.Format("\n\nyonixw/MangaPrinter@Github\n{0}", versionString);
_programVersion = string.Format("\n\n[MangaPrinter {0}]\n\n", versionString );
}

private Dictionary<SingleSideType, String> _sideTextConsts = new Dictionary<SingleSideType, string>()
Expand All @@ -43,7 +43,7 @@ public string sideTextConsts(SingleSideType type)
public static Font fontSide = new Font(new FontFamily("Arial"), 5, FontStyle.Bold); // size will be changed
public static Font fontPageText = new Font(new FontFamily("Arial"), 5);

public Bitmap BuildFace(PrintFace face, int spW, int spH, int padding)
public Bitmap BuildFace(PrintFace face, int spW, int spH, int padding, bool colors)
{
Bitmap result = null;
if (face.Left == face.Right) // double
Expand Down Expand Up @@ -73,7 +73,9 @@ public Bitmap BuildFace(PrintFace face, int spW, int spH, int padding)
result = TemplateSingle(face, spW, spH, padding);
}

return GraphicsUtils.MakeGrayscale3(result);
if (result != null && !colors) result = GraphicsUtils.MakeGrayscale3(result);
// TODO: dispose bitmaps?
return result;
}

private Bitmap TemplateDouble(PrintFace face, int spW, int spH, int padding)
Expand Down
4 changes: 3 additions & 1 deletion MangaPrinter.WpfGUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,10 @@
<Menu DockPanel.Dock="Top" Padding="5px" FontSize="9.75pt">
<MenuItem Header="(2) (Re)Bind All!" Style="{StaticResource MenuItemBtnStyle}" Foreground="Black" Click="MenuItem_Click"/>
<MenuItem Header="(3) Export PDF!" Style="{StaticResource MenuItemBtnStyle}" Foreground="Black" Name="mnuExport" Click="MnuExport_Click" />
<CheckBox Name="cbExportMinimal" IsChecked="False">Let me convert to pdf</CheckBox>
<CheckBox Name="cbExportMinimal" IsChecked="False">Export to images</CheckBox>
<Hyperlink Name="lblHelpExportMinimal" Click="LblHelpExportMinimal_Click">( ? )</Hyperlink>
<CheckBox Name="cbKeepColors" IsChecked="False">Keep colors</CheckBox>
<Hyperlink Name="lblKeepColorsHelp" Click="lblKeepColorsHelp_Click">( ? )</Hyperlink>
</Menu>
<Grid >
<Grid.ColumnDefinitions>
Expand Down
30 changes: 22 additions & 8 deletions MangaPrinter.WpfGUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
{
lstFileChapters.ItemsSource = mangaChapters;
lstFileChaptersBinding.ItemsSource = mangaChapters;
rtbInfo.AppendText(" " + Properties.Resources.GitInfo.Split(';')[0]);
rtbInfo.AppendText(" " + Properties.Resources.GitInfo.Replace("\"", "").Split(';')[0]);

// Load Settings:
var Config = MangaPrinter.WpfGUI.Properties.Settings.Default;
Expand Down Expand Up @@ -448,10 +448,11 @@ private void LstPrintPages_SelectionChanged(object sender, SelectionChangedEvent
FileInfo tempImage = new FileInfo("_tmp_.png");
private void MnuPrvwFront_Click(object sender, RoutedEventArgs e)
{

ListBoxAction<SelectablePrintPage>(lstPrintPages, (p) =>
{
var b = (new DuplexTemplates(Properties.Resources.GitInfo.Split(' ')[0])).BuildFace(p.Front,
int.Parse(txtPrintWidth.Text), int.Parse(txtPrintHeight.Text), int.Parse(txtPrintPadding.Text));
var b = (new DuplexTemplates(Properties.Resources.GitInfo.Replace("\"", "").Split(' ')[0])).BuildFace(p.Front,
int.Parse(txtPrintWidth.Text), int.Parse(txtPrintHeight.Text), int.Parse(txtPrintPadding.Text), cbKeepColors.IsChecked ?? false);

if (tempImage.Exists)
tempImage.Delete();
Expand All @@ -470,8 +471,8 @@ private void MnuPrvwBack_Click(object sender, RoutedEventArgs e)
{
ListBoxAction<SelectablePrintPage>(lstPrintPages, (p) =>
{
var b = (new DuplexTemplates(Properties.Resources.GitInfo.Split(' ')[0])).BuildFace(p.Back,
int.Parse(txtPrintWidth.Text), int.Parse(txtPrintHeight.Text), int.Parse(txtPrintPadding.Text));
var b = (new DuplexTemplates(Properties.Resources.GitInfo.Replace("\"", "").Split(' ')[0])).BuildFace(p.Back,
int.Parse(txtPrintWidth.Text), int.Parse(txtPrintHeight.Text), int.Parse(txtPrintPadding.Text), cbKeepColors.IsChecked ?? false);

if (tempImage.Exists)
tempImage.Delete();
Expand Down Expand Up @@ -502,6 +503,18 @@ private void LblHelpExportMinimal_Click(object sender, RoutedEventArgs e)
}

SaveFileDialog dlgSave = new SaveFileDialog();

private void lblKeepColorsHelp_Click(object sender, RoutedEventArgs e)
{
string helpMessage =
"Normally, we convert all pages to grayscale. This option lets you keep the color. \n\n" +
"* Colorful PDFs are usually bigger (x3+). \n" +
"* Colorful PDFs even sometimes cannot be printed by some industrial printers (maybe due to temp memory size). \n\n" +
"So, It is not recommended to relay on the printer to convert to grayscale.";

MessageBox.Show(helpMessage, "Help", MessageBoxButton.OK, MessageBoxImage.Information);
}

private void MnuExport_Click(object sender, RoutedEventArgs e)
{
dlgSave.Title = "Export book as PDF";
Expand All @@ -515,6 +528,7 @@ private void MnuExport_Click(object sender, RoutedEventArgs e)
int pad = int.Parse(txtPrintPadding.Text);
int pagesCount = allPrintPages.Count;
bool convertPdf = !(cbExportMinimal.IsChecked??false);
bool keepColors = cbKeepColors.IsChecked ?? false;
List<string> filesToDelete = new List<string>();

DateTime timeTemp;
Expand All @@ -526,15 +540,15 @@ private void MnuExport_Click(object sender, RoutedEventArgs e)
Exception ex = winWorking.waitForTask<Exception>(this, (updateFunc) =>
{

DuplexTemplates dt = new DuplexTemplates(Properties.Resources.GitInfo.Split(' ')[0]);
DuplexTemplates dt = new DuplexTemplates(Properties.Resources.GitInfo.Replace("\"","").Split(' ')[0]);
foreach (SelectablePrintPage page in allPrintPages)
{

try
{
updateFunc("[1/3] Export page " + page.PageNumber, (int)(100.0f * saveCounter / 2 / pagesCount));

var b = dt.BuildFace(page.Front, pW, pH, pad);
var b = dt.BuildFace(page.Front, pW, pH, pad, keepColors);
var bName = System.IO.Path.Combine(
fi.Directory.FullName,
"_temp_" + String.Format("{0:000000000}", saveCounter++) + ".jpg"
Expand All @@ -543,7 +557,7 @@ private void MnuExport_Click(object sender, RoutedEventArgs e)
filesToDelete.Add(bName);
b.Dispose();

b = dt.BuildFace(page.Back, pW, pH, pad);
b = dt.BuildFace(page.Back, pW, pH, pad, keepColors);
bName = System.IO.Path.Combine(
fi.Directory.FullName,
"_temp_" + String.Format("{0:000000000}", saveCounter++) + ".jpg"
Expand Down

0 comments on commit 91f9254

Please sign in to comment.