2015-04-11 23:52:45 +02:00
2015-04-28 22:47:56 +02:00
import java.util.Base64 ;
2015-04-11 23:52:45 +02:00
public class DepthMapNeedle
{
2015-04-13 22:42:16 +02:00
/ * *
* Interprete the arguments and execute the programm
2015-04-28 22:47:56 +02:00
*
2015-04-13 22:42:16 +02:00
* @param args
* /
2015-04-11 23:52:45 +02:00
public static void main ( String [ ] args )
{
2015-04-28 22:47:56 +02:00
Base64Wrapper wrapper = new Base64Wrapper ( ) {
@Override
public byte [ ] decode ( byte [ ] data )
{
2015-07-17 20:09:06 +02:00
if ( data ! = null )
return Base64 . getDecoder ( ) . decode ( data ) ;
else
return null ;
2015-04-28 22:47:56 +02:00
}
@Override
public byte [ ] encode ( byte [ ] data )
{
2015-07-17 20:09:06 +02:00
if ( data ! = null )
return Base64 . getEncoder ( ) . encode ( data ) ;
else
return null ;
2015-04-28 22:47:56 +02:00
}
} ;
2015-04-13 22:42:16 +02:00
//No arguments given or '-h' as first argument -> show help text
2015-04-28 22:47:56 +02:00
if ( args . length = = 0 | | args [ 0 ] . equals ( " -h " ) ) help ( ) ;
2015-04-13 22:42:16 +02:00
//export depthmap
2015-04-28 22:47:56 +02:00
if ( args . length > = 2 & & args [ 0 ] . equals ( " -d " ) )
2015-04-11 23:52:45 +02:00
{
2015-04-28 22:47:56 +02:00
for ( int i = 1 ; i < args . length ; i + + )
2015-04-11 23:52:45 +02:00
{
2015-04-28 22:47:56 +02:00
JPEG image = new JPEG ( args [ i ] , wrapper ) ;
if ( image . exportDepthMap ( ) )
2015-07-17 20:09:06 +02:00
System . out . println ( " Info: Depthmap extracted for file " + args [ i ] + " . " ) ;
else System . out . println ( " Warning: There is no Depthmap in file " + args [ i ] + " . " ) ;
2015-04-11 23:52:45 +02:00
}
}
2015-04-28 22:47:56 +02:00
2015-04-13 22:42:16 +02:00
//export source image
2015-04-28 22:47:56 +02:00
else if ( args . length > = 2 & & args [ 0 ] . equals ( " -s " ) )
2015-04-11 23:52:45 +02:00
{
2015-04-28 22:47:56 +02:00
for ( int i = 1 ; i < args . length ; i + + )
2015-04-11 23:52:45 +02:00
{
2015-04-28 22:47:56 +02:00
JPEG image = new JPEG ( args [ i ] , wrapper ) ;
if ( image . exportSourceImage ( ) )
2015-07-17 20:09:06 +02:00
System . out . println ( " Info: Unblurred source image extracted for file " + args [ i ] + " . " ) ;
2015-04-28 22:47:56 +02:00
else
2015-07-17 20:09:06 +02:00
System . out . println ( " Warning: There is no unblurred source image in file " + args [ i ] + " . Maybe this photo has not been taken with Google Camera \ 's blur function? " ) ;
2015-04-11 23:52:45 +02:00
}
}
2015-04-28 22:47:56 +02:00
2015-04-13 22:42:16 +02:00
//inject depthmap
2015-04-28 22:47:56 +02:00
else if ( args . length > = 3 & & args [ 0 ] . equals ( " -D " ) )
2015-04-11 23:52:45 +02:00
{
String depthmap = args [ 1 ] ;
2015-04-28 22:47:56 +02:00
for ( int i = 2 ; i < args . length ; i + + )
2015-04-11 23:52:45 +02:00
{
2015-04-28 22:47:56 +02:00
JPEG image = new JPEG ( args [ i ] , wrapper ) ;
if ( image . injectDepthMap ( depthmap ) )
2015-07-17 20:09:06 +02:00
System . out . println ( " Info: Depthmap injected into file " + args [ i ] + " . " ) ;
2015-04-28 22:47:56 +02:00
else
2015-07-17 20:09:06 +02:00
System . out . println ( " Warning: Something went wrong while injecting " + depthmap + " into " + args [ i ] + " . \ nRemember: The first argument has to be a png and the following arguments must be jpgs shot with the blur function. " ) ;
2015-04-28 22:47:56 +02:00
image . save ( ) ;
}
}
//inject source image
else if ( args . length > = 3 & & args [ 0 ] . equals ( " -S " ) )
{
String source = args [ 1 ] ;
for ( int i = 2 ; i < args . length ; i + + )
{
JPEG image = new JPEG ( args [ i ] , wrapper ) ;
if ( image . injectSourceImage ( source ) )
2015-07-17 20:09:06 +02:00
System . out . println ( " Info: Source image injected into file " + args [ i ] + " . " ) ;
2015-04-28 22:47:56 +02:00
else
2015-07-17 20:09:06 +02:00
System . out . println ( " Warning: Something went wrong while injecting " + source + " into " + args [ i ] + " . \ nRemember: The first argument has to be a jpg and the following arguments must be jpgs shot with the blur function. " ) ;
2015-04-11 23:52:45 +02:00
image . save ( ) ;
}
}
}
2015-04-28 22:47:56 +02:00
2015-04-13 22:42:16 +02:00
/ * *
* Show help text
* /
2015-04-11 23:52:45 +02:00
public static void help ( )
{
System . out . println ( " Welcome to DepthMapNeedle! "
2015-04-28 22:47:56 +02:00
+ " \ nDepthMapNeedle is a tool to inject or extract depth information in form of depthmaps from photos shot using Google Cameras Blur function. "
+ " \ n "
+ " \ nAvailable Options: "
+ " \ n'-d <file1>.jpg ... <fileN>.jpg': "
+ " \ n Extract the depthmap from the specified photo(s). The depthmaps will be stored with the suffix \" _d.png \" . "
+ " \ n'-s <file1>.jpg ... <fileN>.jpg': "
+ " \ n Extract the unblurred source image from the photo(s). These files will be stored with the suffix \" _s.jpg \" . "
+ " \ n'-D <depthmap>.png <file1>.jpg ... <fileN>.jpg': "
+ " \ n Inject a png file as Depthmap into the following specified jpg files. "
+ " \ n'-S <unblurred>.jpg <file1>.jpg ... <fileN>.jpg': "
+ " \ n Inject an unblurred source image into the following specified jpg files. "
+ " \ n Note: The unblurred source image is a simple jpg file of the same dimensions as the photos. "
+ " \ n'-h': "
+ " \ n Show this help text. " ) ;
2015-04-11 23:52:45 +02:00
}
}