Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d53b06e
commit 05ffa0d
Showing
11 changed files
with
175 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.DS_Store | ||
xcuserdata | ||
node_modules | ||
tests/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
task 'test', () -> | ||
require('./tests/tests').main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2012+ redact-by-example contributors | ||
|
||
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 the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Suppose that a pixel has the color (R, G, B) if and only if it's been redacted. | ||
|
||
Suppose you want the same redactions that were applied to EXAMPLE to be applied to SRC, with the resulting image saved at DEST. | ||
|
||
redact-by-example EXAMPLE SRC DEST R G B | ||
|
||
Note: R, G, B `\in` {0, ..., 255} | ||
|
||
Note: DEST is always written as a PNG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,68 @@ | ||
#import <Foundation/Foundation.h> | ||
#import <AppKit/AppKit.h> | ||
|
||
|
||
typedef struct _RGB { | ||
unsigned char r, g, b; | ||
} RGB; | ||
|
||
|
||
void fatal_error(NSString *msg) { | ||
NSLog(@"%@", msg); | ||
exit(1); | ||
} | ||
|
||
NSBitmapImageRep* loadImageRep(const char *path) { | ||
NSString *pathString = [NSString stringWithCString:path encoding:NSUTF8StringEncoding]; | ||
NSImage *img = [[NSImage alloc] initWithContentsOfFile:pathString]; | ||
NSBitmapImageRep *rep = [NSBitmapImageRep imageRepWithData:[img TIFFRepresentation]]; | ||
if ([rep samplesPerPixel] != 3) { | ||
fatal_error(@"only RGB supported so far"); | ||
} | ||
if ([rep bitsPerPixel] != 24) { | ||
fatal_error(@"only 24-bit pixels supported so far"); | ||
} | ||
return rep; | ||
} | ||
|
||
|
||
int main(int argc, const char * argv[]) { | ||
@autoreleasepool { | ||
NSLog(@"Hello, World!"); | ||
if (argc != (1 + 3 + 3)) { | ||
fatal_error(@"invalid args"); | ||
} | ||
NSBitmapImageRep *exampleRep = loadImageRep(argv[1]); | ||
NSBitmapImageRep *targetRep = loadImageRep(argv[2]); | ||
NSString *destPath = [NSString stringWithCString:argv[3] encoding:NSUTF8StringEncoding]; | ||
RGB redactionPixel; | ||
redactionPixel.r = atoi(argv[4]); | ||
redactionPixel.g = atoi(argv[5]); | ||
redactionPixel.b = atoi(argv[6]); | ||
|
||
long w = (long)[exampleRep pixelsWide]; | ||
long h = (long)[exampleRep pixelsHigh]; | ||
long i; | ||
if ((w != [exampleRep pixelsWide]) || (h != [exampleRep pixelsHigh])) { | ||
fatal_error(@"Dimensions don't match."); | ||
} | ||
|
||
RGB *examplePixels = (RGB *)[exampleRep bitmapData]; | ||
RGB *targetPixels = (RGB *)[targetRep bitmapData]; | ||
RGB pixel; | ||
for (long y = 0; y < h; y++) { | ||
for (long x = 0; x < w; x++) { | ||
i = (y * w) + x; | ||
pixel = examplePixels[i]; | ||
if ( | ||
(pixel.r == redactionPixel.r) && | ||
(pixel.g == redactionPixel.g) && | ||
(pixel.b == redactionPixel.b)) { | ||
targetPixels[i] = redactionPixel; | ||
} | ||
} | ||
} | ||
|
||
NSData *png = [targetRep representationUsingType:NSPNGFileType properties:nil]; | ||
[png writeToFile:destPath atomically:YES]; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"uiautomation-runner": "0.0.4", | ||
"mkdirp": "~0.3.3", | ||
"png-guts": ">=0.0.3", | ||
"async": "~0.1.22" | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
fs = require 'fs' | ||
assert = require 'assert' | ||
{exec} = require 'child_process' | ||
{spawn_with_output} = require 'uiautomation-runner' | ||
PNG_GUTS = require('png-guts').BIN_PATH | ||
async = require 'async' | ||
mkdirp = require 'mkdirp' | ||
|
||
|
||
SETTINGS = { | ||
xcode_project: "#{__dirname}/../redact-by-example.xcodeproj" | ||
xcode_scheme: 'redact-by-example' | ||
xcode_sdk: 'macosx10.7' | ||
xcode_configuration: 'Release' | ||
build_dir: "#{__dirname}/build" | ||
} | ||
|
||
|
||
main = () -> | ||
async.series [ | ||
((c) -> mkdirp SETTINGS.build_dir, c) | ||
xcodebuild | ||
run_tests | ||
], (e) -> | ||
throw e if e | ||
console.log 'OK' | ||
|
||
|
||
xcodebuild = (c) -> | ||
spawn_with_output "xcodebuild", [ | ||
'-project', SETTINGS.xcode_project, | ||
'-scheme', SETTINGS.xcode_scheme, | ||
'-sdk', SETTINGS.xcode_sdk, | ||
'-configuration', SETTINGS.xcode_configuration, | ||
'build', | ||
('CONFIGURATION_BUILD_DIR=' + SETTINGS.build_dir) | ||
], {noisy:true}, c | ||
|
||
|
||
run_tests = (c) -> | ||
bin = "#{SETTINGS.build_dir}/redact-by-example" | ||
example = "#{__dirname}/redacted.png" | ||
src = "#{__dirname}/subject.png" | ||
dest = "#{__dirname}/build/result.png" | ||
dest_stripped = "#{__dirname}/build/result-stripped.png" | ||
exec "'#{bin}' #{example} #{src} #{dest} 0 0 255", (e, out, err) -> | ||
return c e if e | ||
exec "cat '#{dest}' | '#{PNG_GUTS}' --strip-ancillary > '#{dest_stripped}'", (e, out, err) -> | ||
return c e if e | ||
exec "compare -metric RMSE '#{dest_stripped}' '#{__dirname}/result-expected.png' /dev/null", (e, out, err) -> | ||
return c e if e | ||
assert.equal err, "0 (0)\n" | ||
c null | ||
|
||
|
||
module.exports = {main} | ||
if not module.parent | ||
main() |