Skip to content

Commit

Permalink
add rotate test (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
KnicKnic authored Sep 22, 2018
1 parent e7372fa commit 9a7b2ae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export CFLAGS="-O3"
export CXXFLAGS="$CFLAGS"
MAKE_FLAGS="-s BINARYEN_TRAP_MODE=clamp -s ALLOW_MEMORY_GROWTH=1"

# export CFLAGS="-O0 -g2"
# export CXXFLAGS="$CFLAGS"
# MAKE_FLAGS="-s BINARYEN_TRAP_MODE=clamp -s ALLOW_MEMORY_GROWTH=1 -s SAFE_HEAP=1 -s ASSERTIONS=1"

export PKG_CONFIG_PATH="/code/libpng:/code/zlib:/code/libjpeg:/code/libtiff:/code/libtiff/libtiff:"
export PNG_LIBS="-L/code/libpng -L/code/libpng/.libs"

Expand Down
Binary file added tests/rotate/FriedrichNietzsche.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 16 additions & 3 deletions tests/rotate/node_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ function ValidateFormat(fileName, formatToMatch)
}
}

function RotateFile(sourceFileName, destinationFileName)
function ConvertImage(sourceFileName, destinationFileName, convertArgs = [])
{
sourceFileNameEmscripten = '/' + sourceFileName;
destinationFileNameEmscripten = '/' + destinationFileName;
sourceFile = fs.readFileSync(sourceFileName);
FS.writeFile(sourceFileNameEmscripten, sourceFile);
command = ["convert", sourceFileNameEmscripten, "-rotate", "90", destinationFileNameEmscripten];
command = ["convert", sourceFileNameEmscripten].concat(convertArgs, [destinationFileNameEmscripten]);
if(destinationFileName.endsWith('.png'))
{
command = ["convert", sourceFileNameEmscripten, "-rotate", "90", "-define", "png:include-chunk=none", destinationFileNameEmscripten];
command = ["convert", sourceFileNameEmscripten].concat(convertArgs, ["-define", "png:include-chunk=none", destinationFileNameEmscripten]);
}
console.log(`attempting to convert ${sourceFileName} to ${destinationFileName}` )
console.log(`running command ${command}`)
Expand All @@ -62,12 +62,19 @@ function RotateFile(sourceFileName, destinationFileName)
{
console.log(`failed to convert ${sourceFileName} to ${destinationFileName}` )
console.log(`exception ${e}` )
return false;
}
console.log(`ran command ${command}`)

console.log(`converted ${sourceFileName} to ${destinationFileName}` )
destinationFileEmscripten = FS.readFile(destinationFileNameEmscripten);
fs.writeFileSync(destinationFileName,destinationFileEmscripten);
return true;
}

function RotateFile(sourceFileName, destinationFileName)
{
return ConvertImage(sourceFileName, destinationFileName, convertArgs = ["-rotate", "90"])
}

function ValidateFilesSame(leftFileName, rightFileName)
Expand Down Expand Up @@ -112,6 +119,12 @@ Module.onRuntimeInitialized = function (){
console.log('\ntesting if gimp is working');
RotateFile('to_rotate.xcf', 'rotated.xcf.png');
ValidateFormat('to_rotate.xcf', 'XCF');

if(!ConvertImage('FriedrichNietzsche.png', 'FriedrichNietzsche-charcoal.png', ["-charcoal", "5"]))
{
console.log("Process IMage threw");
process.exit(1);
}
}

var fs = require('fs');
Expand Down

0 comments on commit 9a7b2ae

Please sign in to comment.