@ -20,7 +20,6 @@
# include <array>
# include <random>
# include <dlfcn.h>
# include <gtest/gtest.h>
# include "../common/DepthPhotoProcessor.h"
@ -36,19 +35,6 @@ static const size_t kTestBufferNV12Size ((((kTestBufferWidth) * (kTestBufferHeig
static const size_t kTestBufferDepthSize ( kTestBufferWidth * kTestBufferHeight ) ;
static const size_t kSeed = 1234 ;
void linkToDepthPhotoLibrary ( void * * libHandle /*out*/ ,
process_depth_photo_frame * processFrameFunc /*out*/ ) {
ASSERT_NE ( libHandle , nullptr ) ;
ASSERT_NE ( processFrameFunc , nullptr ) ;
* libHandle = dlopen ( kDepthPhotoLibrary , RTLD_NOW | RTLD_LOCAL ) ;
if ( * libHandle ! = nullptr ) {
* processFrameFunc = reinterpret_cast < camera3 : : process_depth_photo_frame > (
dlsym ( * libHandle , kDepthPhotoProcessFunction ) ) ;
ASSERT_NE ( * processFrameFunc , nullptr ) ;
}
}
void generateColorJpegBuffer ( int jpegQuality , ExifOrientation orientationValue , bool includeExif ,
bool switchDimensions , std : : vector < uint8_t > * colorJpegBuffer /*out*/ ) {
ASSERT_NE ( colorJpegBuffer , nullptr ) ;
@ -91,26 +77,9 @@ void generateDepth16Buffer(std::array<uint16_t, kTestBufferDepthSize> *depth16Bu
}
}
TEST ( DepthProcessorTest , LinkToLibray ) {
void * libHandle ;
process_depth_photo_frame processFunc ;
linkToDepthPhotoLibrary ( & libHandle , & processFunc ) ;
if ( libHandle ! = nullptr ) {
dlclose ( libHandle ) ;
}
}
TEST ( DepthProcessorTest , BadInput ) {
void * libHandle ;
int jpegQuality = 95 ;
process_depth_photo_frame processFunc ;
linkToDepthPhotoLibrary ( & libHandle , & processFunc ) ;
if ( libHandle = = nullptr ) {
// Depth library no present, nothing more to test.
return ;
}
DepthPhotoInputFrame inputFrame ;
// Worst case both depth and confidence maps have the same size as the main color image.
inputFrame . mMaxJpegSize = inputFrame . mMainJpegSize * 3 ;
@ -128,37 +97,27 @@ TEST(DepthProcessorTest, BadInput) {
inputFrame . mMainJpegWidth = kTestBufferWidth ;
inputFrame . mMainJpegHeight = kTestBufferHeight ;
inputFrame . mJpegQuality = jpegQuality ;
ASSERT_NE ( process Func ( inputFrame , depthPhotoBuffer . size ( ) , depthPhotoBuffer . data ( ) ,
ASSERT_NE ( process DepthPhotoFrame ( inputFrame , depthPhotoBuffer . size ( ) , depthPhotoBuffer . data ( ) ,
& actualDepthPhotoSize ) , 0 ) ;
inputFrame . mMainJpegBuffer = reinterpret_cast < const char * > ( colorJpegBuffer . data ( ) ) ;
inputFrame . mMainJpegSize = colorJpegBuffer . size ( ) ;
ASSERT_NE ( process Func ( inputFrame , depthPhotoBuffer . size ( ) , depthPhotoBuffer . data ( ) ,
ASSERT_NE ( process DepthPhotoFrame ( inputFrame , depthPhotoBuffer . size ( ) , depthPhotoBuffer . data ( ) ,
& actualDepthPhotoSize ) , 0 ) ;
inputFrame . mDepthMapBuffer = depth16Buffer . data ( ) ;
inputFrame . mDepthMapWidth = inputFrame . mDepthMapStride = kTestBufferWidth ;
inputFrame . mDepthMapHeight = kTestBufferHeight ;
ASSERT_NE ( process Func ( inputFrame , depthPhotoBuffer . size ( ) , nullptr ,
ASSERT_NE ( process DepthPhotoFrame ( inputFrame , depthPhotoBuffer . size ( ) , nullptr ,
& actualDepthPhotoSize ) , 0 ) ;
ASSERT_NE ( processFunc ( inputFrame , depthPhotoBuffer . size ( ) , depthPhotoBuffer . data ( ) , nullptr ) ,
0 ) ;
dlclose ( libHandle ) ;
ASSERT_NE ( processDepthPhotoFrame ( inputFrame , depthPhotoBuffer . size ( ) , depthPhotoBuffer . data ( ) ,
nullptr ) , 0 ) ;
}
TEST ( DepthProcessorTest , BasicDepthPhotoValidation ) {
void * libHandle ;
int jpegQuality = 95 ;
process_depth_photo_frame processFunc ;
linkToDepthPhotoLibrary ( & libHandle , & processFunc ) ;
if ( libHandle = = nullptr ) {
// Depth library no present, nothing more to test.
return ;
}
std : : vector < uint8_t > colorJpegBuffer ;
generateColorJpegBuffer ( jpegQuality , ExifOrientation : : ORIENTATION_UNDEFINED ,
/*includeExif*/ false , /*switchDimensions*/ false , & colorJpegBuffer ) ;
@ -180,7 +139,7 @@ TEST(DepthProcessorTest, BasicDepthPhotoValidation) {
std : : vector < uint8_t > depthPhotoBuffer ( inputFrame . mMaxJpegSize ) ;
size_t actualDepthPhotoSize = 0 ;
ASSERT_EQ ( process Func ( inputFrame , depthPhotoBuffer . size ( ) , depthPhotoBuffer . data ( ) ,
ASSERT_EQ ( process DepthPhotoFrame ( inputFrame , depthPhotoBuffer . size ( ) , depthPhotoBuffer . data ( ) ,
& actualDepthPhotoSize ) , 0 ) ;
ASSERT_TRUE ( ( actualDepthPhotoSize > 0 ) & & ( depthPhotoBuffer . size ( ) > = actualDepthPhotoSize ) ) ;
@ -196,21 +155,11 @@ TEST(DepthProcessorTest, BasicDepthPhotoValidation) {
ASSERT_EQ ( NV12Compressor : : findJpegSize ( depthPhotoBuffer . data ( ) + mainJpegSize ,
actualDepthPhotoSize - mainJpegSize , & depthMapSize ) , OK ) ;
ASSERT_TRUE ( ( depthMapSize > 0 ) & & ( depthMapSize < ( actualDepthPhotoSize - mainJpegSize ) ) ) ;
dlclose ( libHandle ) ;
}
TEST ( DepthProcessorTest , TestDepthPhotoExifOrientation ) {
void * libHandle ;
int jpegQuality = 95 ;
process_depth_photo_frame processFunc ;
linkToDepthPhotoLibrary ( & libHandle , & processFunc ) ;
if ( libHandle = = nullptr ) {
// Depth library no present, nothing more to test.
return ;
}
ExifOrientation exifOrientations [ ] = { ExifOrientation : : ORIENTATION_UNDEFINED ,
ExifOrientation : : ORIENTATION_0_DEGREES , ExifOrientation : : ORIENTATION_90_DEGREES ,
ExifOrientation : : ORIENTATION_180_DEGREES , ExifOrientation : : ORIENTATION_270_DEGREES } ;
@ -242,8 +191,8 @@ TEST(DepthProcessorTest, TestDepthPhotoExifOrientation) {
std : : vector < uint8_t > depthPhotoBuffer ( inputFrame . mMaxJpegSize ) ;
size_t actualDepthPhotoSize = 0 ;
ASSERT_EQ ( process Func ( inputFrame , depthPhotoBuffer . size ( ) , depthPhotoBuffer . data ( ) ,
& actualDepthPhotoSize ) , 0 ) ;
ASSERT_EQ ( process DepthPhotoFrame ( inputFrame , depthPhotoBuffer . size ( ) ,
depthPhotoBuffer . data ( ) , & actualDepthPhotoSize ) , 0 ) ;
ASSERT_TRUE ( ( actualDepthPhotoSize > 0 ) & &
( depthPhotoBuffer . size ( ) > = actualDepthPhotoSize ) ) ;
@ -281,21 +230,11 @@ TEST(DepthProcessorTest, TestDepthPhotoExifOrientation) {
ASSERT_EQ ( confidenceJpegExifOrientation , exifOrientation ) ;
}
}
dlclose ( libHandle ) ;
}
TEST ( DepthProcessorTest , TestDephtPhotoPhysicalRotation ) {
void * libHandle ;
int jpegQuality = 95 ;
process_depth_photo_frame processFunc ;
linkToDepthPhotoLibrary ( & libHandle , & processFunc ) ;
if ( libHandle = = nullptr ) {
// Depth library no present, nothing more to test.
return ;
}
// In case of physical rotation, the EXIF orientation must always be 0.
auto exifOrientation = ExifOrientation : : ORIENTATION_0_DEGREES ;
DepthPhotoOrientation depthOrientations [ ] = {
@ -339,8 +278,8 @@ TEST(DepthProcessorTest, TestDephtPhotoPhysicalRotation) {
std : : vector < uint8_t > depthPhotoBuffer ( inputFrame . mMaxJpegSize ) ;
size_t actualDepthPhotoSize = 0 ;
ASSERT_EQ ( process Func ( inputFrame , depthPhotoBuffer . size ( ) , depthPhotoBuffer . data ( ) ,
& actualDepthPhotoSize ) , 0 ) ;
ASSERT_EQ ( process DepthPhotoFrame ( inputFrame , depthPhotoBuffer . size ( ) ,
depthPhotoBuffer . data ( ) , & actualDepthPhotoSize ) , 0 ) ;
ASSERT_TRUE ( ( actualDepthPhotoSize > 0 ) & &
( depthPhotoBuffer . size ( ) > = actualDepthPhotoSize ) ) ;
@ -377,6 +316,4 @@ TEST(DepthProcessorTest, TestDephtPhotoPhysicalRotation) {
ASSERT_EQ ( confidenceMapWidth , expectedWidth ) ;
ASSERT_EQ ( confidenceMapHeight , expectedHeight ) ;
}
dlclose ( libHandle ) ;
}