Skip to content

Commit

Permalink
Changed "auto crop" option to "crop to input" (CLI+GUI)
Browse files Browse the repository at this point in the history
Auto crop was only too happy to cut away even some of the border texts.
  • Loading branch information
galfar committed Sep 3, 2021
1 parent 5dcd024 commit b5e2bfc
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 81 deletions.
7 changes: 4 additions & 3 deletions CmdLineOptions.pas
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface
);

TOperationalFlag = (
ofAutoCrop,
ofCropToInput,
ofDetectOnly
);
TOperationalFlags = set of TOperationalFlag;
Expand Down Expand Up @@ -289,7 +289,7 @@ function TCmdLineOptions.ParseCommnadLine: Boolean;
else if Param = '-g' then
begin
if Pos('c', ValLower) > 0 then
Include(FOperationalFlags, ofAutoCrop);
Include(FOperationalFlags, ofCropToInput);
if Pos('d', ValLower) > 0 then
Include(FOperationalFlags, ofDetectOnly);
end
Expand Down Expand Up @@ -418,7 +418,8 @@ function TCmdLineOptions.OptionsToString: string;
' content rect = ' + Format('%d,%d,%d,%d', [ContentRect.Left, ContentRect.Top, ContentRect.Right, ContentRect.Bottom]) + sLineBreak +
' output format = ' + Iff(ForcedOutputFormat = ifUnknown, 'default', Imaging.GetFormatName(ForcedOutputFormat)) + sLineBreak +
' skip angle = ' + FloatToStr(SkipAngle) + sLineBreak +
' oper flags = ' + Iff(ofAutoCrop in FOperationalFlags, 'auto-crop ', '') + Iff(ofDetectOnly in FOperationalFlags, 'detect-only ', '') + sLineBreak +
' oper flags = ' + Iff(ofCropToInput in FOperationalFlags, 'crop-to-input ', '')
+ Iff(ofDetectOnly in FOperationalFlags, 'detect-only ', '') + sLineBreak +
' show info = ' + Iff(ShowParams, 'params ', '') + Iff(ShowStats, 'stats ', '') + Iff(ShowTimings, 'timings ', '') + sLineBreak +
' output compression = jpeg:' + CompJpegStr + ' tiff:' + CompTiffStr + sLineBreak;
end;
Expand Down
102 changes: 50 additions & 52 deletions Gui/mainform.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ object FormMain: TFormMain
object PageIn: TPage
object PanelFiles: TPanel
Left = 0
Height = 386
Height = 368
Top = 0
Width = 514
Align = alClient
BevelOuter = bvNone
ClientHeight = 386
ClientHeight = 368
ClientWidth = 514
TabOrder = 0
object MemoFiles: TMemo
Left = 0
Height = 290
Top = 42
Height = 266
Top = 48
Width = 514
Align = alClient
BorderSpacing.Bottom = 54
Expand All @@ -50,10 +50,10 @@ object FormMain: TFormMain
WordWrap = False
end
object BtnAbout: TButton
Left = 472
Height = 20
Left = 490
Height = 33
Top = 0
Width = 42
Width = 24
Action = ActShowAbout
Anchors = [akTop, akRight]
AutoSize = True
Expand All @@ -71,19 +71,18 @@ object FormMain: TFormMain
object BtnAddFiles: TBitBtn
Left = 0
Height = 31
Top = 348
Top = 330
Width = 120
Action = ActAddFiles
Anchors = [akLeft, akBottom]
Default = True
Font.Height = -16
ParentFont = False
TabOrder = 3
end
object BtnClear: TBitBtn
Left = 392
Height = 31
Top = 352
Top = 334
Width = 120
Action = ActClearFiles
Anchors = [akRight, akBottom]
Expand All @@ -93,7 +92,7 @@ object FormMain: TFormMain
end
object Label1: TLabel
Left = 0
Height = 28
Height = 34
Top = 4
Width = 514
Align = alTop
Expand All @@ -109,26 +108,26 @@ object FormMain: TFormMain
end
object PanelOptions: TPanel
Left = 0
Height = 188
Top = 392
Height = 198
Top = 374
Width = 514
Align = alBottom
AutoSize = True
BorderSpacing.Top = 6
BorderSpacing.Bottom = 14
BevelOuter = bvNone
ClientHeight = 188
ClientHeight = 198
ClientWidth = 514
TabOrder = 1
object Panel1: TPanel
Left = 0
Height = 144
Top = 36
Height = 148
Top = 42
Width = 514
Align = alClient
BorderSpacing.Bottom = 8
BevelOuter = bvNone
ClientHeight = 144
ClientHeight = 148
ClientWidth = 514
TabOrder = 0
object ColorBtnBackground: TColorButton
Expand All @@ -137,9 +136,9 @@ object FormMain: TFormMain
AnchorSideTop.Control = LabBackColor
AnchorSideTop.Side = asrCenter
AnchorSideBottom.Side = asrCenter
Left = 130
Left = 134
Height = 28
Top = 116
Top = 117
Width = 64
BorderSpacing.Left = 12
BorderWidth = 2
Expand All @@ -151,26 +150,26 @@ object FormMain: TFormMain
AnchorSideTop.Control = CheckDefaultOutputFileOptions
AnchorSideTop.Side = asrBottom
Left = 8
Height = 16
Top = 42
Width = 85
Height = 19
Top = 45
Width = 89
BorderSpacing.Top = 12
Caption = 'Output folder:'
ParentColor = False
end
object LabBackColor: TLabel
Left = 8
Height = 16
Height = 19
Top = 122
Width = 110
Width = 114
Caption = 'Background color:'
ParentColor = False
end
object CheckDefaultOutputFileOptions: TCheckBox
Left = 8
Height = 18
Height = 21
Top = 12
Width = 194
Width = 212
Caption = 'Use default output file options'
Checked = True
State = cbChecked
Expand All @@ -180,9 +179,9 @@ object FormMain: TFormMain
AnchorSideTop.Control = LabOptOutputFolder
AnchorSideTop.Side = asrBottom
Left = 8
Height = 16
Top = 76
Width = 68
Height = 19
Top = 82
Width = 72
BorderSpacing.Top = 18
Caption = 'File format:'
ParentColor = False
Expand All @@ -192,25 +191,24 @@ object FormMain: TFormMain
AnchorSideTop.Control = LabOptFileFormat
AnchorSideTop.Side = asrCenter
AnchorSideBottom.Side = asrCenter
Left = 105
Height = 20
Left = 109
Height = 35
Top = 74
Width = 256
ItemHeight = 26
ItemHeight = 0
Style = csDropDownList
TabOrder = 3
Text = '0'
end
object EdDirOutput: TEdit
AnchorSideLeft.Control = LabOptOutputFolder
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = LabOptOutputFolder
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = BtnBrowseOutputDir
Left = 105
Height = 22
Left = 109
Height = 31
Top = 39
Width = 311
Width = 319
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 12
BorderSpacing.Right = 4
Expand All @@ -223,39 +221,39 @@ object FormMain: TFormMain
AnchorSideRight.Control = Panel1
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Side = asrCenter
Left = 422
Height = 20
Top = 40
Width = 84
Left = 434
Height = 33
Top = 38
Width = 72
Action = ActBrowseOutputDir
Anchors = [akTop, akRight]
AutoSize = True
BorderSpacing.Left = 6
BorderSpacing.Right = 8
TabOrder = 2
end
object CheckAutoCrop: TCheckBox
object CheckCropToInput: TCheckBox
AnchorSideLeft.Control = ColorBtnBackground
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = LabBackColor
AnchorSideTop.Side = asrCenter
Left = 254
Height = 18
Left = 258
Height = 21
Top = 121
Width = 78
Width = 108
BorderSpacing.Left = 60
Caption = 'Auto crop'
Caption = 'Crop To Input'
TabOrder = 4
end
object BtnAdvOptions: TBitBtn
AnchorSideTop.Control = LabBackColor
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = BtnBrowseOutputDir
AnchorSideRight.Side = asrBottom
Left = 415
Height = 28
Top = 116
Width = 91
Left = 420
Height = 33
Top = 115
Width = 86
Action = ActShowAdvOptions
Anchors = [akTop, akRight]
AutoSize = True
Expand All @@ -264,7 +262,7 @@ object FormMain: TFormMain
end
object Label2: TLabel
Left = 0
Height = 28
Height = 34
Top = 4
Width = 514
Align = alTop
Expand All @@ -280,8 +278,8 @@ object FormMain: TFormMain
end
object BtnDeskew: TBitBtn
Left = 0
Height = 51
Top = 594
Height = 59
Top = 586
Width = 514
Action = ActDeskew
Align = alBottom
Expand Down
6 changes: 3 additions & 3 deletions Gui/mainform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ TFormMain = class(TForm)
BtnBrowseOutputDir: TButton;
BtnAbout: TButton;
BtnFinish: TBitBtn;
CheckAutoCrop: TCheckBox;
CheckCropToInput: TCheckBox;
CheckDefaultOutputFileOptions: TCheckBox;
ColorBtnBackground: TColorButton;
ComboFileFormat: TComboBox;
Expand Down Expand Up @@ -160,7 +160,7 @@ procedure TFormMain.ApplyOptions(AOptions: TOptions);
EdDirOutput.SelStart := Length(EdDirOutput.Text);
ComboFileFormat.ItemIndex := Integer(AOptions.OutputFileFormat);
ColorBtnBackground.ButtonColor := RGBToColor(GetRedValue(AOptions.BackgroundColor), GetGreenValue(AOptions.BackgroundColor), GetBlueValue(AOptions.BackgroundColor));
CheckAutoCrop.Checked := AOptions.AutoCrop;
CheckCropToInput.Checked := AOptions.CropToInput;
end;

procedure TFormMain.GatherOptions(AOptions: TOptions);
Expand All @@ -182,7 +182,7 @@ procedure TFormMain.GatherOptions(AOptions: TOptions);
AOptions.OutputFileFormat := TFileFormat(PtrUInt(ComboFileFormat.Items.Objects[ComboFileFormat.ItemIndex]));
LazColor := ColorBtnBackground.ButtonColor;
AOptions.BackgroundColor := Color32(255, Red(LazColor), Green(LazColor), Blue(LazColor)).Color;
AOptions.AutoCrop := CheckAutoCrop.Checked;
AOptions.CropToInput := CheckCropToInput.Checked;
end;

procedure TFormMain.RunnerFinished(Sender: TObject; Reason: TFinishReason);
Expand Down
10 changes: 5 additions & 5 deletions Gui/options.pas
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TOptions = class
OutputFolder: string;
OutputFileFormat: TFileFormat;
BackgroundColor: TColor32;
AutoCrop: Boolean;
CropToInput: Boolean;

// Advanced options
ResamplingFilter: TResamplingFilter;
Expand Down Expand Up @@ -228,7 +228,7 @@ procedure TOptions.ToCmdLineParameters(AParams: TStrings; AFileIndex: Integer);

if BackgroundColor <> $FF000000 then
AParams.AddStrings(['-b', IntToHex(BackgroundColor, 8)]);
if AutoCrop then
if CropToInput then
AParams.AddStrings(['-g', 'c']);

// Advanced options
Expand Down Expand Up @@ -259,7 +259,7 @@ procedure TOptions.Reset;
OutputFolder := '';
OutputFileFormat := ffSameAsInput;
BackgroundColor := DefaultBackgroundColor;
AutoCrop := False;
CropToInput := False;

ResamplingFilter := rfDefaultLinear;
MaxAngle := DefaultMaxAngle;
Expand All @@ -282,7 +282,7 @@ procedure TOptions.SaveToIni(Ini: TIniFile);
Ini.WriteString(IniSectionOptions, 'OutputFolder', OutputFolder);
Ini.WriteString(IniSectionOptions, 'OutputFileFormat', TEnumUtils<TFileFormat>.EnumToStr(OutputFileFormat));
Ini.WriteString(IniSectionOptions, 'BackgroundColor', ColorToString(BackgroundColor));
Ini.WriteNiceBool(IniSectionOptions, 'AutoCrop', AutoCrop);
Ini.WriteNiceBool(IniSectionOptions, 'CropToInput', CropToInput);

Ini.WriteString(IniSectionAdvanced, 'ResamplingFilter', TEnumUtils<TResamplingFilter>.EnumToStr(ResamplingFilter));
Ini.WriteFloat(IniSectionAdvanced, 'MaxAngle', MaxAngle);
Expand All @@ -305,7 +305,7 @@ procedure TOptions.LoadFromIni(Ini: TIniFile);
OutputFolder := Ini.ReadString(IniSectionOptions, 'OutputFolder', '');
OutputFileFormat := TEnumUtils<TFileFormat>.StrToEnum(Ini.ReadString(IniSectionOptions, 'OutputFileFormat', ''));
BackgroundColor := StringToColorDef(Ini.ReadString(IniSectionOptions, 'BackgroundColor', ''), DefaultBackgroundColor);
AutoCrop := Ini.ReadNiceBool(IniSectionOptions, 'AutoCrop', False);
CropToInput := Ini.ReadNiceBool(IniSectionOptions, 'CropToInput', False);

ResamplingFilter := TEnumUtils<TResamplingFilter>.StrToEnum(Ini.ReadString(IniSectionAdvanced, 'ResamplingFilter', ''));
MaxAngle := Ini.ReadFloat(IniSectionAdvanced, 'MaxAngle', DefaultMaxAngle);
Expand Down
Loading

0 comments on commit b5e2bfc

Please sign in to comment.