Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements for image scanning #29

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2013 klep
Copyright (c) 2020 Scott J. Kleper

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
2 changes: 1 addition & 1 deletion scanline Tests/ScanConfigurationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <XCTest/XCTest.h>

#import "ScanConfiguration.h"
#import "../scanline/ScanConfiguration.h"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be necessary. If I revert it back to #import "ScanConfiguration.h", I'm able to run the tests. Although I also had to remove the app source files from the test target, which they shouldn't have been in. Maybe that was the issue here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. When I revert the change I get 'ScanConfiguration.h' file not found. Removing the source files from CompileSources of the Test target unfortunately does not fix things for me:
image
image

However I'm not very familiar with XCode nor the Swift build system. Any ideas?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to get it to work by doing the following:

  1. Change to #import "ScanConfiguration.h" in ScanConfigurationTests.m
  2. Remove everything except ScanConfigurationTests.m and ScanConfiguration.m from the Compile Sources step
  3. Remove #import "scanline-Swift.h" from ScanConfiguration.m

It's not ideal -- we shouldn't need any of the app source files in the test target -- but I'm not sure what the issue is right now with that.


@interface ScanConfigurationTests : XCTestCase

Expand Down
57 changes: 52 additions & 5 deletions scanline.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
objects = {

/* Begin PBXBuildFile section */
1730C4EF23BA281F00391200 /* NSImageExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1730C4EE23BA281F00391200 /* NSImageExtensions.swift */; };
1730C4F123BA284A00391200 /* Insets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1730C4F023BA284A00391200 /* Insets.swift */; };
1730C4F323BA287200391200 /* ArrayExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1730C4F223BA287200391200 /* ArrayExtensions.swift */; };
1730C4F523BA292900391200 /* ScanConfigurationExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1730C4F423BA292900391200 /* ScanConfigurationExtension.swift */; };
1730C4F723BA2C7800391200 /* IntExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1730C4F623BA2C7800391200 /* IntExtensions.swift */; };
1730C4FB23BA3D5300391200 /* ScannerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1730C4FA23BA3D5300391200 /* ScannerController.swift */; };
1730C4FD23BA3D7500391200 /* ScanlineOutputProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1730C4FC23BA3D7500391200 /* ScanlineOutputProcessor.swift */; };
1730C4FF23BA3DA100391200 /* ScannerControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1730C4FE23BA3DA100391200 /* ScannerControllerDelegate.swift */; };
1730C50023BA3E7000391200 /* ScanConfiguration.h in Sources */ = {isa = PBXBuildFile; fileRef = FCF90C471FD3536700EAF3D1 /* ScanConfiguration.h */; };
1730C51423BB6BBB00391200 /* CGRectExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1730C51323BB6BBB00391200 /* CGRectExtensions.swift */; };
FCD75D391FF2E1D50041D955 /* ScanConfigurationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FCD75D381FF2E1D50041D955 /* ScanConfigurationTests.m */; };
FCD75D451FF2E9300041D955 /* config_test.conf in Resources */ = {isa = PBXBuildFile; fileRef = FCD75D441FF2E9300041D955 /* config_test.conf */; };
FCD75D6A1FF2ED220041D955 /* ScanConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = FCF90C461FD3536700EAF3D1 /* ScanConfiguration.m */; };
Expand Down Expand Up @@ -44,6 +54,15 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
1730C4EE23BA281F00391200 /* NSImageExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSImageExtensions.swift; sourceTree = "<group>"; };
1730C4F023BA284A00391200 /* Insets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Insets.swift; sourceTree = "<group>"; };
1730C4F223BA287200391200 /* ArrayExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrayExtensions.swift; sourceTree = "<group>"; };
1730C4F423BA292900391200 /* ScanConfigurationExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanConfigurationExtension.swift; sourceTree = "<group>"; };
1730C4F623BA2C7800391200 /* IntExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntExtensions.swift; sourceTree = "<group>"; };
1730C4FA23BA3D5300391200 /* ScannerController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScannerController.swift; sourceTree = "<group>"; };
1730C4FC23BA3D7500391200 /* ScanlineOutputProcessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanlineOutputProcessor.swift; sourceTree = "<group>"; };
1730C4FE23BA3DA100391200 /* ScannerControllerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScannerControllerDelegate.swift; sourceTree = "<group>"; };
1730C51323BB6BBB00391200 /* CGRectExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGRectExtensions.swift; sourceTree = "<group>"; };
FCD75D361FF2E1D50041D955 /* Scanline Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Scanline Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
FCD75D381FF2E1D50041D955 /* ScanConfigurationTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ScanConfigurationTests.m; sourceTree = "<group>"; };
FCD75D3A1FF2E1D50041D955 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -76,6 +95,18 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
17E8D42C23C1138400E6D9F8 /* extensions */ = {
isa = PBXGroup;
children = (
1730C4F223BA287200391200 /* ArrayExtensions.swift */,
1730C51323BB6BBB00391200 /* CGRectExtensions.swift */,
1730C4F623BA2C7800391200 /* IntExtensions.swift */,
1730C4EE23BA281F00391200 /* NSImageExtensions.swift */,
1730C4F423BA292900391200 /* ScanConfigurationExtension.swift */,
);
path = extensions;
sourceTree = "<group>";
};
FCD75D371FF2E1D50041D955 /* Scanline Tests */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -114,6 +145,11 @@
FCF90C451FD3536700EAF3D1 /* scanline-Bridging-Header.h */,
FCF90C4B1FD3543D00EAF3D1 /* Logger.swift */,
FCF90C4F1FD39E3300EAF3D1 /* ScannerBrowser.swift */,
1730C4F023BA284A00391200 /* Insets.swift */,
1730C4FA23BA3D5300391200 /* ScannerController.swift */,
1730C4FC23BA3D7500391200 /* ScanlineOutputProcessor.swift */,
1730C4FE23BA3DA100391200 /* ScannerControllerDelegate.swift */,
17E8D42C23C1138400E6D9F8 /* extensions */,
);
path = scanline;
sourceTree = "<group>";
Expand Down Expand Up @@ -168,11 +204,12 @@
TargetAttributes = {
FCD75D351FF2E1D50041D955 = {
CreatedOnToolsVersion = 9.2;
LastSwiftMigration = 1130;
ProvisioningStyle = Automatic;
};
FCF90C3A1FD3534B00EAF3D1 = {
CreatedOnToolsVersion = 9.1;
LastSwiftMigration = 0910;
LastSwiftMigration = 1130;
ProvisioningStyle = Automatic;
};
};
Expand Down Expand Up @@ -224,10 +261,20 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1730C50023BA3E7000391200 /* ScanConfiguration.h in Sources */,
FCF90C3F1FD3534B00EAF3D1 /* main.swift in Sources */,
FCF90C481FD3536700EAF3D1 /* ScanConfiguration.m in Sources */,
1730C4EF23BA281F00391200 /* NSImageExtensions.swift in Sources */,
1730C4FF23BA3DA100391200 /* ScannerControllerDelegate.swift in Sources */,
FCF90C501FD39E3300EAF3D1 /* ScannerBrowser.swift in Sources */,
1730C4F723BA2C7800391200 /* IntExtensions.swift in Sources */,
1730C4F523BA292900391200 /* ScanConfigurationExtension.swift in Sources */,
1730C51423BB6BBB00391200 /* CGRectExtensions.swift in Sources */,
1730C4F123BA284A00391200 /* Insets.swift in Sources */,
1730C4FB23BA3D5300391200 /* ScannerController.swift in Sources */,
FCF90C4A1FD3537400EAF3D1 /* ScanlineAppController.swift in Sources */,
1730C4F323BA287200391200 /* ArrayExtensions.swift in Sources */,
1730C4FD23BA3D7500391200 /* ScanlineOutputProcessor.swift in Sources */,
FCF90C4C1FD3543D00EAF3D1 /* Logger.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -259,7 +306,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "scanline/scanline-Bridging-Header.h";
SWIFT_OBJC_INTERFACE_HEADER_NAME = "scanline-Swift.h";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -279,7 +326,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "scanline/scanline-Bridging-Header.h";
SWIFT_OBJC_INTERFACE_HEADER_NAME = "scanline-Swift.h";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down Expand Up @@ -398,7 +445,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "scanline/scanline-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -410,7 +457,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "scanline/scanline-Bridging-Header.h";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
26 changes: 26 additions & 0 deletions scanline/Insets.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// This code is part of scanline and published under MIT license.
//

import Foundation

/// Describes insets that can be applied to a rectangle.
struct Insets {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this just be UIEdgeInsets?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICS UIEdgeInsets is only part of UIKit, which is not linked against scanline as it is a command line application.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right...


let left: CGFloat
let right: CGFloat
let top: CGFloat
let bottom: CGFloat

init(left: Double, top: Double, right: Double, bottom: Double) {
self.left = CGFloat(left)
self.top = CGFloat(top)
self.right = CGFloat(right)
self.bottom = CGFloat(bottom)
}

init(fromString insets: String) {
let insetValues = insets.split(separator: ":")
self.init(left: Double(insetValues[0])!, top: Double(insetValues[1])!, right: Double(insetValues[2])!, bottom: Double(insetValues[1])!)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to avoid the force unwraps here?

}
}
8 changes: 2 additions & 6 deletions scanline/Logger.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
//
// Logger.swift
// scanline
//
// Created by Scott J. Kleper on 12/2/17.
// Copyright © 2017 Scott J. Kleper. All rights reserved.
// This code is part of scanline and published under MIT license.
//

import Foundation
Expand All @@ -17,7 +13,7 @@ class Logger: NSObject {
}

func verbose(_ message: String) {
guard configuration.config[ScanlineConfigOptionVerbose] != nil else { return }
guard configuration.verbose else { return }
print(message)
}

Expand Down
11 changes: 6 additions & 5 deletions scanline/ScanConfiguration.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
//
// ScanConfiguration.h
// scanline
//
// Created by Scott J. Kleper on 9/26/13.
//
// This code is part of scanline and published under MIT license.
//

#import <Foundation/Foundation.h>
Expand All @@ -27,6 +23,11 @@ static NSString * const ScanlineConfigOptionScanner = @"scanner";
static NSString * const ScanlineConfigOptionResolution = @"resolution";
static NSString * const ScanlineConfigOptionBrowseSecs = @"browsesecs";
static NSString * const ScanlineConfigOptionExactName = @"exactname";
static NSString * const ScanlineConfigOptionArea = @"area";
static NSString * const ScanlineConfigOptionCreationDate = @"creation-date";
static NSString * const ScanlineConfigOptionAutoTrim = @"auto-trim";
static NSString * const ScanlineConfigOptionInsets = @"insets";
static NSString * const ScanlineConfigOptionQuality = @"quality";

@interface ScanConfiguration : NSObject

Expand Down
31 changes: 26 additions & 5 deletions scanline/ScanConfiguration.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
//
// ScanConfiguration.m
// scanline
//
// Created by Scott J. Kleper on 9/26/13.
//
// This code is part of scanline and published under MIT license.
//

#import "ScanConfiguration.h"
Expand Down Expand Up @@ -92,6 +88,31 @@ + (NSDictionary*)configOptions
@"type": @"flag",
@"description": @"When specified, only the scanner with the exact name specified will be used (no fuzzy matching)"
},
ScanlineConfigOptionArea: @{
@"synonyms": @[@"size"],
@"type": @"string",
@"description": @"Specify the size of the area that should be scanned in cm. Forat is <width>x<height>, e.g. 20x20 (Default is the whole flatbed scan area)"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*Format :)

},
ScanlineConfigOptionCreationDate: @{
@"type": @"string",
@"description": @"When specified, the EXIF creation date is set to the given date (Format YYYY:MM:DD)"
},
ScanlineConfigOptionInsets: @{
@"synonyms": @[@"cutoff"],
@"type": @"string",
@"description": @"The number of pixels to cut off from each side (Format Left:Top:Right:Bottom)",
@"default": @"0:0:0:0"
},
ScanlineConfigOptionAutoTrim: @{
@"synonyms": @[@"trim-whitespace"],
@"type": @"flag",
@"description": @"Trims whitespace around the image (useful for photos)"
},
ScanlineConfigOptionQuality: @{
@"type": @"string",
@"description": @"Specifes the quality of the image. Only used when -jpg is enabled. Value must be between 0 (low quality, small file) and 100 (best, big file). (Default is 90)",
@"default": @"90"
},
};
}

Expand Down
Loading