diff --git a/examples/app.cmake b/examples/app.cmake index 6e95cef0..f748dbf1 100644 --- a/examples/app.cmake +++ b/examples/app.cmake @@ -76,8 +76,7 @@ IF(${CURRENT_OS} STREQUAL "linux") gpupixel GL glfw) - SET(GPUPIXEL_LIBS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libgpupixel.so) - ) + SET(GPUPIXEL_LIBS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libgpupixel.so) set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-Wl,-rpath,./") ELSEIF(${CURRENT_OS} STREQUAL "windows") TARGET_LINK_LIBRARIES(${PROJECT_NAME} diff --git a/examples/desktop/app.cc b/examples/desktop/app.cc index 9cd54ef3..d3cf1556 100644 --- a/examples/desktop/app.cc +++ b/examples/desktop/app.cc @@ -5,11 +5,7 @@ #include "gpupixel.h" using namespace gpupixel; - std::shared_ptr beauty_face_filter_; -std::shared_ptr face_reshape_filter_; -std::shared_ptr lipstick_filter_; -std::shared_ptr blusher_filter_; std::shared_ptr gpuSourceImage; std::shared_ptr output_; std::shared_ptr target_view; @@ -22,181 +18,114 @@ float lipstickValue = 0; float blusherValue = 0; void framebuffer_size_callback(GLFWwindow* window, int width, int height); -void processInput(GLFWwindow *window); +void processInput(GLFWwindow* window); - void error_callback( int error, const char *msg ) { - std::string s; - s = " [" + std::to_string(error) + "] " + msg + '\n'; - std::cerr << s << std::endl; +void error_callback(int error, const char* msg) { + std::string s; + s = " [" + std::to_string(error) + "] " + msg + '\n'; + std::cerr << s << std::endl; } -int main() -{ - glfwInit(); - GLFWwindow* window = GPUPixelContext::getInstance()->GetGLContext(); - - if (window == NULL) - { - std::cout << "Failed to create GLFW window" << std::endl; - glfwTerminate(); - return -1; - } +int main() { + glfwInit(); + GLFWwindow* window = GPUPixelContext::getInstance()->GetGLContext(); - gladLoadGL(); - glfwMakeContextCurrent(window); - - glfwShowWindow(window); - glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); - - // create filter - // ---- - lipstick_filter_ = LipstickFilter::create(); - blusher_filter_ = BlusherFilter::create(); - face_reshape_filter_ = FaceReshapeFilter::create(); - - // filter pipline - // ---- - gpuSourceImage = SourceImage::create("demo.png"); - target_view = std::make_shared(); - - gpuSourceImage->RegLandmarkCallback([=](std::vector landmarks) { - lipstick_filter_->SetFaceLandmarks(landmarks); - blusher_filter_->SetFaceLandmarks(landmarks); - face_reshape_filter_->SetFaceLandmarks(landmarks); - }); - - beauty_face_filter_ = BeautyFaceFilter::create(); - - - // gpuSourceImage->addTarget(beauty_face_filter_) - // ->addTarget(target_view); - - gpuSourceImage->addTarget(lipstick_filter_) - ->addTarget(blusher_filter_) - ->addTarget(face_reshape_filter_) - ->addTarget(beauty_face_filter_) - ->addTarget(target_view); - - // - target_view->onSizeChanged(1280, 720); - - // render loop - // ----------- - while (!glfwWindowShouldClose(window)) - { - // input - // ----- - processInput(window); - - // - // ----- - gpuSourceImage->Render(); - - // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.) - // ------------------------------------------------------------------------------- - glfwSwapBuffers(window); - glfwPollEvents(); - } - - - // glfw: terminate, clearing all previously allocated GLFW resources. - // ------------------------------------------------------------------ + if (window == NULL) { + std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); - return 0; -} - -// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly -// --------------------------------------------------------------------------------------------------------- -void processInput(GLFWwindow *window) -{ - if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) - glfwSetWindowShouldClose(window, true); - - if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) { - beautyValue++; - if(beautyValue > 10.0) beautyValue = 10.0; - beauty_face_filter_->setBlurAlpha(beautyValue/10); - } - - if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) { - beautyValue--; - if(beautyValue < 0.0) beautyValue = 0.0; - beauty_face_filter_->setBlurAlpha(beautyValue/10); - } - - - if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) { - whithValue++; - if(whithValue > 10.0) whithValue = 10.0; - beauty_face_filter_->setWhite(whithValue/20); - } - - if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS) { - whithValue--; - if(whithValue < 0.0) whithValue = 0.0; - beauty_face_filter_->setWhite(whithValue/20); - } + return -1; + } - if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) { - thinFaceValue++; - if(thinFaceValue > 10.0) thinFaceValue = 10.0; - face_reshape_filter_->setFaceSlimLevel(thinFaceValue/200); - } - - if (glfwGetKey(window, GLFW_KEY_C) == GLFW_PRESS) { - thinFaceValue--; - if(thinFaceValue < 0.0) thinFaceValue = 0.0; - face_reshape_filter_->setFaceSlimLevel(thinFaceValue/200); - } + gladLoadGL(); + glfwMakeContextCurrent(window); - if (glfwGetKey(window, GLFW_KEY_F) == GLFW_PRESS) { - bigeyeValue++; - if(bigeyeValue > 10.0) bigeyeValue = 10.0; - face_reshape_filter_->setEyeZoomLevel(bigeyeValue/100); - } - - if (glfwGetKey(window, GLFW_KEY_V) == GLFW_PRESS) { - bigeyeValue--; - if(bigeyeValue < 0.0) bigeyeValue = 0.0; - face_reshape_filter_->setEyeZoomLevel(bigeyeValue/100); - } - - if (glfwGetKey(window, GLFW_KEY_G) == GLFW_PRESS) { - lipstickValue++; - if(lipstickValue > 10.0) lipstickValue = 10.0; + glfwShowWindow(window); + glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); + + // ---- + // filter pipline + // ---- + gpuSourceImage = SourceImage::create("demo.png"); + target_view = std::make_shared(); + + beauty_face_filter_ = BeautyFaceFilter::create(); + + gpuSourceImage->addTarget(beauty_face_filter_); + beauty_face_filter_->addTarget(target_view); + + // + target_view->onSizeChanged(1280, 720); + + // render loop + // ----------- + while (!glfwWindowShouldClose(window)) { + // input + // ----- + processInput(window); + + // + // ----- + gpuSourceImage->Render(); + + // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved + // etc.) + // ------------------------------------------------------------------------------- + glfwSwapBuffers(window); + glfwPollEvents(); + } + + // glfw: terminate, clearing all previously allocated GLFW resources. + // ------------------------------------------------------------------ + glfwTerminate(); + return 0; +} - lipstick_filter_->setBlendLevel(lipstickValue/10); +// process all input: query GLFW whether relevant keys are pressed/released this +// frame and react accordingly +// --------------------------------------------------------------------------------------------------------- +void processInput(GLFWwindow* window) { + if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) { + glfwSetWindowShouldClose(window, true); + } + + if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) { + beautyValue++; + if (beautyValue > 10.0) { + beautyValue = 10.0; } + beauty_face_filter_->setBlurAlpha(beautyValue / 10); + } - if (glfwGetKey(window, GLFW_KEY_B) == GLFW_PRESS) { - lipstickValue--; - if(lipstickValue < 0.0) lipstickValue = 0.0; - - lipstick_filter_->setBlendLevel(lipstickValue/10); + if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) { + beautyValue--; + if (beautyValue < 0.0) { + beautyValue = 0.0; } + beauty_face_filter_->setBlurAlpha(beautyValue / 10); + } - if (glfwGetKey(window, GLFW_KEY_H) == GLFW_PRESS) { - blusherValue++; - if(blusherValue > 10.0) blusherValue = 10.0; - - blusher_filter_->setBlendLevel(blusherValue/10); + if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) { + whithValue++; + if (whithValue > 10.0) { + whithValue = 10.0; } + beauty_face_filter_->setWhite(whithValue / 20); + } - if (glfwGetKey(window, GLFW_KEY_N) == GLFW_PRESS) { - blusherValue--; - if(blusherValue < 0.0) blusherValue = 0.0; - - blusher_filter_->setBlendLevel(blusherValue/10); + if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS) { + whithValue--; + if (whithValue < 0.0) { + whithValue = 0.0; } - + beauty_face_filter_->setWhite(whithValue / 20); + } } -// glfw: whenever the window size changed (by OS or user resize) this callback function executes +// glfw: whenever the window size changed (by OS or user resize) this callback +// function executes // --------------------------------------------------------------------------------------------- -void framebuffer_size_callback(GLFWwindow* window, int width, int height) -{ - // make sure the viewport matches the new window dimensions; note that width and - // height will be significantly larger than specified on retina displays. - glViewport(0, 0, width, height); - +void framebuffer_size_callback(GLFWwindow* window, int width, int height) { + // make sure the viewport matches the new window dimensions; note that width + // and height will be significantly larger than specified on retina displays. + glViewport(0, 0, width, height); } diff --git a/examples/ios/GPUPixelApp.xcodeproj/project.pbxproj b/examples/ios/GPUPixelApp.xcodeproj/project.pbxproj index 6cec69f0..a7379397 100644 --- a/examples/ios/GPUPixelApp.xcodeproj/project.pbxproj +++ b/examples/ios/GPUPixelApp.xcodeproj/project.pbxproj @@ -9,12 +9,6 @@ /* Begin PBXBuildFile section */ 840CD3D42B88448900EEF7B0 /* gpupixel.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 840CD3D32B88448900EEF7B0 /* gpupixel.framework */; }; 840CD3D52B88448900EEF7B0 /* gpupixel.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 840CD3D32B88448900EEF7B0 /* gpupixel.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 840FD5CF2B82455100781FA6 /* vnn_kit_ios.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 840FD5CC2B82455100781FA6 /* vnn_kit_ios.framework */; }; - 840FD5D02B82455100781FA6 /* vnn_kit_ios.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 840FD5CC2B82455100781FA6 /* vnn_kit_ios.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 840FD5D12B82455100781FA6 /* vnn_face_ios.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 840FD5CD2B82455100781FA6 /* vnn_face_ios.framework */; }; - 840FD5D22B82455100781FA6 /* vnn_face_ios.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 840FD5CD2B82455100781FA6 /* vnn_face_ios.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 840FD5D32B82455100781FA6 /* vnn_core_ios.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 840FD5CE2B82455100781FA6 /* vnn_core_ios.framework */; }; - 840FD5D42B82455100781FA6 /* vnn_core_ios.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 840FD5CE2B82455100781FA6 /* vnn_core_ios.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 8417C43A267F5AF10074DDEF /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8417C437267F5AF10074DDEF /* AVFoundation.framework */; }; 8417C43C267F5B470074DDEF /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8417C43B267F5B470074DDEF /* CoreMedia.framework */; }; 84307E91261F2CD9003EAC98 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 84307E90261F2CD9003EAC98 /* AppDelegate.m */; }; @@ -38,9 +32,6 @@ dstSubfolderSpec = 10; files = ( 840CD3D52B88448900EEF7B0 /* gpupixel.framework in Embed Frameworks */, - 840FD5D02B82455100781FA6 /* vnn_kit_ios.framework in Embed Frameworks */, - 840FD5D42B82455100781FA6 /* vnn_core_ios.framework in Embed Frameworks */, - 840FD5D22B82455100781FA6 /* vnn_face_ios.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -83,11 +74,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 840FD5CF2B82455100781FA6 /* vnn_kit_ios.framework in Frameworks */, - 840FD5D32B82455100781FA6 /* vnn_core_ios.framework in Frameworks */, 840CD3D42B88448900EEF7B0 /* gpupixel.framework in Frameworks */, 8417C43C267F5B470074DDEF /* CoreMedia.framework in Frameworks */, - 840FD5D12B82455100781FA6 /* vnn_face_ios.framework in Frameworks */, 8417C43A267F5AF10074DDEF /* AVFoundation.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/examples/ios/GPUPixelApp/ImageFilterController.mm b/examples/ios/GPUPixelApp/ImageFilterController.mm index 1a65edfa..62f48ea4 100644 --- a/examples/ios/GPUPixelApp/ImageFilterController.mm +++ b/examples/ios/GPUPixelApp/ImageFilterController.mm @@ -17,9 +17,6 @@ @interface ImageFilterController () { GPUPixelView *gpuPixelView; std::shared_ptr beauty_face_filter_; - std::shared_ptr face_reshape_filter_; - std::shared_ptr lipstick_filter_; - std::shared_ptr blusher_filter_; std::shared_ptr gpuSourceImage; CADisplayLink *_displayLink; } @@ -56,7 +53,7 @@ - (void)viewDidLoad { } -(void)initUI { - NSArray *array = [NSArray arrayWithObjects:@"Smooth", @"White", @"ThinFace", @"BigEye", @"Lipstick", @"Blusher", nil]; + NSArray *array = [NSArray arrayWithObjects:@"Smooth", @"White", nil]; self.segment = [[UISegmentedControl alloc]initWithItems:array]; self.segment.frame = CGRectMake(10, self.view.frame.size.height - 70, @@ -106,31 +103,17 @@ -(void) initVideoFilter { gpupixel::GPUPixelContext::getInstance()->runSync([&] { gpuPixelView = [[GPUPixelView alloc] initWithFrame:self.view.frame]; [self.view addSubview:gpuPixelView]; - - - lipstick_filter_ = LipstickFilter::create(); - blusher_filter_ = BlusherFilter::create(); - beauty_face_filter_ = BeautyFaceFilter::create(); - face_reshape_filter_ = FaceReshapeFilter::create(); - + NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"sample_face" ofType:@"png"]; gpuSourceImage = SourceImage::create([imagePath UTF8String]); - gpuSourceImage->RegLandmarkCallback([=](std::vector landmarks) { - lipstick_filter_->SetFaceLandmarks(landmarks); - blusher_filter_->SetFaceLandmarks(landmarks); - face_reshape_filter_->SetFaceLandmarks(landmarks); - }); - + // filter pipline - gpuSourceImage->addTarget(lipstick_filter_) - ->addTarget(blusher_filter_) - ->addTarget(face_reshape_filter_) - ->addTarget(beauty_face_filter_) - ->addTarget(gpuPixelView); + gpuSourceImage->addTarget(beauty_face_filter_); + beauty_face_filter_->addTarget(gpuPixelView); [gpuPixelView setBackgroundColor:[UIColor grayColor]]; [gpuPixelView setFillMode:(gpupixel::TargetView::PreserveAspectRatioAndFill)]; @@ -180,30 +163,7 @@ - (void)setWhithValue:(CGFloat)value{ _whithValue = value; beauty_face_filter_->setWhite(value/20); } -- (void)setSaturationValue:(CGFloat)value{ - _saturationValue = value; -} - -- (void)setThinFaceValue:(CGFloat)value{ - _thinFaceValue = value; - face_reshape_filter_->setFaceSlimLevel(value/100); -} - -- (void)setEyeValue:(CGFloat)value{ - _eyeValue = value; - face_reshape_filter_->setEyeZoomLevel(value/50); -} - -- (void)setLipstickValue:(CGFloat)value{ - _lipstickValue = value; - lipstick_filter_->setBlendLevel(value/10); -} - -- (void)setBlusherValue:(CGFloat)value{ - _blusherValue = value; - blusher_filter_->setBlendLevel(value/10); -} - + - (void)displayLinkDidFire:(CADisplayLink *)displayLink { // must call function gpuSourceImage->Render(); @@ -220,10 +180,6 @@ -(void)onFilterSwitchChange:(UISegmentedControl *)sender{ } else { beauty_face_filter_->setBlurAlpha(0); beauty_face_filter_->setWhite(0); - face_reshape_filter_->setFaceSlimLevel(0); - face_reshape_filter_->setEyeZoomLevel(0); - lipstick_filter_->setBlendLevel(0); - blusher_filter_->setBlendLevel(0); } } diff --git a/examples/ios/GPUPixelApp/VideoFilterController.mm b/examples/ios/GPUPixelApp/VideoFilterController.mm index 8e7ce03b..2fc0db30 100644 --- a/examples/ios/GPUPixelApp/VideoFilterController.mm +++ b/examples/ios/GPUPixelApp/VideoFilterController.mm @@ -17,9 +17,6 @@ @interface VideoFilterController () { GPUPixelView *gpuPixelView; std::shared_ptr beauty_face_filter_; std::shared_ptr targetRawOutput_; - std::shared_ptr face_reshape_filter_; - std::shared_ptr lipstick_filter_; - std::shared_ptr blusher_filter_; } // @@ -57,7 +54,7 @@ - (void)viewDidLoad { } -(void)initUI { - NSArray *array = [NSArray arrayWithObjects:@"磨皮",@"美白",@"瘦脸",@"大眼", @"口红", @"腮红", nil]; + NSArray *array = [NSArray arrayWithObjects:@"磨皮",@"美白", nil]; //初始化UISegmentedControl self.segment = [[UISegmentedControl alloc]initWithItems:array]; //设置frame @@ -140,27 +137,13 @@ -(void) initVideoFilter { gpuPixelView = [[GPUPixelView alloc] initWithFrame:self.view.frame]; [self.view addSubview:gpuPixelView]; - - lipstick_filter_ = LipstickFilter::create(); - blusher_filter_ = BlusherFilter::create(); - - gpuPixelRawInput->RegLandmarkCallback([=](std::vector landmarks) { - lipstick_filter_->SetFaceLandmarks(landmarks); - blusher_filter_->SetFaceLandmarks(landmarks); - face_reshape_filter_->SetFaceLandmarks(landmarks); - }); - // create filter targetRawOutput_ = TargetRawDataOutput::create(); beauty_face_filter_ = BeautyFaceFilter::create(); - face_reshape_filter_ = FaceReshapeFilter::create(); - + // filter pipline - gpuPixelRawInput->addTarget(lipstick_filter_) - ->addTarget(blusher_filter_) - ->addTarget(face_reshape_filter_) - ->addTarget(beauty_face_filter_) - ->addTarget(gpuPixelView); + gpuPixelRawInput->addTarget(beauty_face_filter_); + beauty_face_filter_->addTarget(gpuPixelView); [gpuPixelView setBackgroundColor:[UIColor grayColor]]; [gpuPixelView setFillMode:(gpupixel::TargetView::PreserveAspectRatioAndFill)]; @@ -176,29 +159,6 @@ - (void)setWhithValue:(CGFloat)value{ _whithValue = value; beauty_face_filter_->setWhite(value/20); } -- (void)setSaturationValue:(CGFloat)value{ - _saturationValue = value; -} - -- (void)setThinFaceValue:(CGFloat)value{ - _thinFaceValue = value; - face_reshape_filter_->setFaceSlimLevel(value/100); -} - -- (void)setEyeValue:(CGFloat)value{ - _eyeValue = value; - face_reshape_filter_->setEyeZoomLevel(value/50); -} - -- (void)setLipstickValue:(CGFloat)value{ - _lipstickValue = value; - lipstick_filter_->setBlendLevel(value/10); -} - -- (void)setBlusherValue:(CGFloat)value{ - _blusherValue = value; - blusher_filter_->setBlendLevel(value/10); -} // camera frame callback - (void)videoCaptureOutputDataCallback:(CMSampleBufferRef)sampleBuffer { @@ -239,10 +199,6 @@ -(void)onFilterSwitchChange:(UISegmentedControl *)sender{ } else { beauty_face_filter_->setBlurAlpha(0); beauty_face_filter_->setWhite(0); - face_reshape_filter_->setFaceSlimLevel(0); - face_reshape_filter_->setEyeZoomLevel(0); - lipstick_filter_->setBlendLevel(0); - blusher_filter_->setBlendLevel(0); } } diff --git a/examples/mac/GPUPixelMacApp.xcodeproj/project.pbxproj b/examples/mac/GPUPixelMacApp.xcodeproj/project.pbxproj index 15da91af..2de55a05 100644 --- a/examples/mac/GPUPixelMacApp.xcodeproj/project.pbxproj +++ b/examples/mac/GPUPixelMacApp.xcodeproj/project.pbxproj @@ -9,12 +9,6 @@ /* Begin PBXBuildFile section */ 840CD3D12B8843CD00EEF7B0 /* gpupixel.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 840CD3CF2B88431900EEF7B0 /* gpupixel.framework */; }; 840CD3D22B8843CD00EEF7B0 /* gpupixel.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 840CD3CF2B88431900EEF7B0 /* gpupixel.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 840FD5BD2B7E523D00781FA6 /* vnn_face_osx.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 840FD5BA2B7E523D00781FA6 /* vnn_face_osx.framework */; }; - 840FD5BE2B7E523D00781FA6 /* vnn_face_osx.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 840FD5BA2B7E523D00781FA6 /* vnn_face_osx.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 840FD5BF2B7E523D00781FA6 /* vnn_core_osx.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 840FD5BB2B7E523D00781FA6 /* vnn_core_osx.framework */; }; - 840FD5C02B7E523D00781FA6 /* vnn_core_osx.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 840FD5BB2B7E523D00781FA6 /* vnn_core_osx.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 840FD5C12B7E523D00781FA6 /* vnn_kit_osx.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 840FD5BC2B7E523D00781FA6 /* vnn_kit_osx.framework */; }; - 840FD5C22B7E523D00781FA6 /* vnn_kit_osx.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 840FD5BC2B7E523D00781FA6 /* vnn_kit_osx.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 84AE136B26FCBCAA00E215AE /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84AE136A26FCBCAA00E215AE /* AVFoundation.framework */; }; 84AE137526FCBCDA00E215AE /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84AE137426FCBCDA00E215AE /* CoreMedia.framework */; }; 84AE137A26FCBCFA00E215AE /* VideoCameraManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84AE137926FCBCFA00E215AE /* VideoCameraManager.mm */; }; @@ -33,9 +27,6 @@ dstSubfolderSpec = 10; files = ( 840CD3D22B8843CD00EEF7B0 /* gpupixel.framework in Embed Frameworks */, - 840FD5C02B7E523D00781FA6 /* vnn_core_osx.framework in Embed Frameworks */, - 840FD5BE2B7E523D00781FA6 /* vnn_face_osx.framework in Embed Frameworks */, - 840FD5C22B7E523D00781FA6 /* vnn_kit_osx.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -70,10 +61,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 840FD5C12B7E523D00781FA6 /* vnn_kit_osx.framework in Frameworks */, 840CD3D12B8843CD00EEF7B0 /* gpupixel.framework in Frameworks */, - 840FD5BD2B7E523D00781FA6 /* vnn_face_osx.framework in Frameworks */, - 840FD5BF2B7E523D00781FA6 /* vnn_core_osx.framework in Frameworks */, 84AE137526FCBCDA00E215AE /* CoreMedia.framework in Frameworks */, 84AE136B26FCBCAA00E215AE /* AVFoundation.framework in Frameworks */, ); diff --git a/examples/mac/GPUPixelMacApp/ViewController.mm b/examples/mac/GPUPixelMacApp/ViewController.mm index 6d179109..18ac44e2 100644 --- a/examples/mac/GPUPixelMacApp/ViewController.mm +++ b/examples/mac/GPUPixelMacApp/ViewController.mm @@ -15,9 +15,6 @@ @interface ViewController() { GPUPixelView *gpuPixelView; std::shared_ptr beauty_face_filter_; std::shared_ptr targetRawOutput_; - std::shared_ptr face_reshape_filter_; - std::shared_ptr lipstick_filter_; - std::shared_ptr blusher_filter_; } @property (weak) IBOutlet NSSlider *levelSlider; @@ -96,28 +93,12 @@ -(void) initVideoFilter { gpuPixelView = [[GPUPixelView alloc] initWithFrame: self.view.frame]; [self.view addSubview:gpuPixelView positioned:NSWindowBelow relativeTo:nil]; - // create filter - - lipstick_filter_ = LipstickFilter::create(); - blusher_filter_ = BlusherFilter::create(); - face_reshape_filter_ = FaceReshapeFilter::create(); - - gpuPixelRawInput->RegLandmarkCallback([=](std::vector landmarks) { - lipstick_filter_->SetFaceLandmarks(landmarks); - blusher_filter_->SetFaceLandmarks(landmarks); - face_reshape_filter_->SetFaceLandmarks(landmarks); - }); - // create filter targetRawOutput_ = TargetRawDataOutput::create(); beauty_face_filter_ = BeautyFaceFilter::create(); - - - gpuPixelRawInput->addTarget(lipstick_filter_) - ->addTarget(blusher_filter_) - ->addTarget(face_reshape_filter_) - ->addTarget(beauty_face_filter_) - ->addTarget(gpuPixelView); + + gpuPixelRawInput->addTarget(beauty_face_filter_); + beauty_face_filter_->addTarget(gpuPixelView); [gpuPixelView setFillMode:(gpupixel::TargetView::PreserveAspectRatioAndFill)]; @@ -133,31 +114,7 @@ - (void)setWhithValue:(CGFloat)value{ _whithValue = value; beauty_face_filter_->setWhite(value/20); } -- (void)setSaturationValue:(CGFloat)value{ - _saturationValue = value; -} - -- (void)setThinFaceValue:(CGFloat)value{ - _thinFaceValue = value; - face_reshape_filter_->setFaceSlimLevel(value/100); -} - -- (void)setEyeValue:(CGFloat)value{ - _eyeValue = value; - face_reshape_filter_->setEyeZoomLevel(value/50); -} - -- (void)setLipstickValue:(CGFloat)value{ - _lipstickValue = value; - lipstick_filter_->setBlendLevel(value/10); -} - -- (void)setBlusherValue:(CGFloat)value{ - _blusherValue = value; - blusher_filter_->setBlendLevel(value/10); -} - - (void)willOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer { CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); CVPixelBufferLockBaseAddress(imageBuffer, 0); diff --git a/src/android/java/gpupixel/src/main/java/com/pixpark/gpupixel/GPUPixel.java b/src/android/java/gpupixel/src/main/java/com/pixpark/gpupixel/GPUPixel.java index c111b787..c921cdd7 100755 --- a/src/android/java/gpupixel/src/main/java/com/pixpark/gpupixel/GPUPixel.java +++ b/src/android/java/gpupixel/src/main/java/com/pixpark/gpupixel/GPUPixel.java @@ -9,8 +9,8 @@ import android.content.Context; import android.graphics.Bitmap; -import android.opengl.GLSurfaceView; import android.graphics.PixelFormat; +import android.opengl.GLSurfaceView; import android.os.Build; import java.io.File; @@ -18,7 +18,6 @@ import java.io.InputStream; public class GPUPixel { - public interface GPUPixelLandmarkCallback { public void onFaceLandmark(float[] landmarks); } @@ -40,8 +39,9 @@ private static class SingletonHolder { private static final GPUPixel INSTANCE = new GPUPixel(); } - - private GPUPixel(){ init(); } + private GPUPixel() { + init(); + } public static final GPUPixel getInstance() { GPUPixel instance = SingletonHolder.INSTANCE; if (!instance.isInited()) { @@ -132,19 +132,25 @@ public GPUPixelRenderer getRenderer() { return mRenderer; } - public boolean isPreDrawQueueEmpty() { return mRenderer.isPreDrawQueueEmpty(); } + public boolean isPreDrawQueueEmpty() { + return mRenderer.isPreDrawQueueEmpty(); + } public void runOnPreDraw(Runnable runnable) { mRenderer.runOnPreDraw(runnable); } - public boolean isDrawQueueEmpty() { return mRenderer.isDrawQueueEmpty(); } + public boolean isDrawQueueEmpty() { + return mRenderer.isDrawQueueEmpty(); + } public void runOnDraw(Runnable runnable) { mRenderer.runOnDraw(runnable); } - public boolean isPostDrawQueueEmpty() { return mRenderer.isPostDrawQueueEmpty(); } + public boolean isPostDrawQueueEmpty() { + return mRenderer.isPostDrawQueueEmpty(); + } public void runOnPostDraw(Runnable runnable) { mRenderer.runOnPostDraw(runnable); @@ -152,9 +158,6 @@ public void runOnPostDraw(Runnable runnable) { static { System.loadLibrary("gpupixel"); - System.loadLibrary("vnn_core"); - System.loadLibrary("vnn_kit"); - System.loadLibrary("vnn_face"); } public static void copyResource(Context context) { @@ -167,42 +170,41 @@ public static String getResource_path() { return resource_path; } - public static void copyAssetsToFiles(Context context, String oldPath, String newPath) { + public static void copyAssetsToFiles(Context context, String oldPath, String newPath) { try { - String fileNames[] = context.getAssets().list(oldPath);//获取assets目录下的所有文件及目录名 - if (fileNames.length > 0) {//如果是目录 + String fileNames[] = + context.getAssets().list(oldPath); // 获取assets目录下的所有文件及目录名 + if (fileNames.length > 0) { // 如果是目录 File file = new File(newPath); - if(!file.exists()) { - file.mkdirs();//如果文件夹不存在,则递归 + if (!file.exists()) { + file.mkdirs(); // 如果文件夹不存在,则递归 } for (String fileName : fileNames) { String srcPath = oldPath + "/" + fileName; - String dstPath = newPath+"/"+fileName; + String dstPath = newPath + "/" + fileName; File f = new File(dstPath); - if(f.exists()) continue; + if (f.exists()) continue; copyAssetsToFiles(context, srcPath, dstPath); } - } else {//如果是文件 + } else { // 如果是文件 File file = new File(newPath); - if(!file.exists()) { + if (!file.exists()) { InputStream is = context.getAssets().open(oldPath); FileOutputStream fos = new FileOutputStream(file); byte[] buffer = new byte[1024]; - int byteCount=0; - while((byteCount=is.read(buffer))!=-1) {//循环从输入流读取 buffer字节 - fos.write(buffer, 0, byteCount);//将读取的输入流写入到输出流 + int byteCount = 0; + while ((byteCount = is.read(buffer)) != -1) { // 循环从输入流读取 buffer字节 + fos.write(buffer, 0, byteCount); // 将读取的输入流写入到输出流 } - fos.flush();//刷新缓冲区 + fos.flush(); // 刷新缓冲区 is.close(); fos.close(); } - } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); - } } @@ -210,40 +212,51 @@ public static void copyAssetsToFiles(Context context, String oldPath, String ne public static native long nativeFilterCreate(final String filterClassName); public static native void nativeFilterDestroy(long classID); public static native void nativeFilterFinalize(long classID); - public static native void nativeFilterSetPropertyFloat(long classID, String property, float value); + public static native void nativeFilterSetPropertyFloat( + long classID, String property, float value); public static native void nativeFilterSetPropertyInt(long classID, String property, int value); - public static native void nativeFilterSetPropertyFloatArray(long classID, String property, float[] array); - public static native void nativeFilterSetPropertyString(long classID, String prooerty, String value); + public static native void nativeFilterSetPropertyFloatArray( + long classID, String property, float[] array); + public static native void nativeFilterSetPropertyString( + long classID, String prooerty, String value); // SourceImage public static native long nativeSourceImageNew(); public static native void nativeSourceImageDestroy(final long classID); public static native void nativeSourceImageFinalize(final long classID); - public static native void nativeSourceImageSetImage(final long classID, final Bitmap bitmap); + public static native void nativeSourceImageSetImage(final long classID, final Bitmap bitmap); // SourceCamera public static native long nativeSourceCameraNew(); public static native void nativeSourceCameraDestroy(final long classID); public static native void nativeSourceCameraFinalize(final long classID); - public static native void nativeSourceCameraSetFrame(final long classID, final int width, final int height, final int[] data, final int rotation); + public static native void nativeSourceCameraSetFrame(final long classID, final int width, + final int height, final int[] data, final int rotation); // SourceRawDataInput public static native long nativeSourceRawInputNew(); - public static native void nativeSourceRawInputUploadBytes(final long classID, final int[] pixel, final int width, final int height, final int stride); - public static native void nativeSourceRawInputSetRotation(final long classID, final int rotation); + public static native void nativeSourceRawInputUploadBytes(final long classID, final int[] pixel, + final int width, final int height, final int stride); + public static native void nativeSourceRawInputSetRotation( + final long classID, final int rotation); // Source - public static native long nativeSourceAddTarget(final long classID, final long targetClassID, final int texID, final boolean isFilter); - public static native void nativeSourceRemoveTarget(final long classID, final long targetClassID, final boolean isFilter); + public static native long nativeSourceAddTarget( + final long classID, final long targetClassID, final int texID, final boolean isFilter); + public static native void nativeSourceRemoveTarget( + final long classID, final long targetClassID, final boolean isFilter); public static native void nativeSourceRemoveAllTargets(final long classID); - public static native boolean nativeSourceProceed(final long classID, final boolean bUpdateTargets); + public static native boolean nativeSourceProceed( + final long classID, final boolean bUpdateTargets); public static native int nativeSourceGetRotatedFramebuferWidth(final long classID); public static native int nativeSourceGetRotatedFramebuferHeight(final long classID); - public static native byte[] nativeSourceCaptureAProcessedFrameData(final long classId, final long upToFilterClassId, final int width, final int height); + public static native byte[] nativeSourceCaptureAProcessedFrameData( + final long classId, final long upToFilterClassId, final int width, final int height); // view public static native long nativeTargetViewNew(); public static native void nativeTargetViewFinalize(final long classID); - public static native void nativeTargetViewOnSizeChanged(final long classID, final int width, final int height); + public static native void nativeTargetViewOnSizeChanged( + final long classID, final int width, final int height); public static native void nativeTargetViewSetFillMode(final long classID, final int fillMode); public static native void nativeTargetViewSetMirror(final long classID, final boolean mirror); // context @@ -255,5 +268,4 @@ public static void copyAssetsToFiles(Context context, String oldPath, String ne public static native void nativeYUVtoRBGA(byte[] yuv, int width, int height, int[] out); public static native void nativeSetLandmarkCallback(Object source, final long classID); - } diff --git a/src/android/jni/jni_gpupixel.cc b/src/android/jni/jni_gpupixel.cc index 79f26aef..04f9b011 100755 --- a/src/android/jni/jni_gpupixel.cc +++ b/src/android/jni/jni_gpupixel.cc @@ -4,7 +4,6 @@ #include #include #include -#include #include "gpupixel_context.h" #include "jni_helpers.h" #include "libyuv.h" @@ -367,21 +366,7 @@ extern "C" void Java_com_pixpark_gpupixel_GPUPixel_nativeSetLandmarkCallback ( jclass obj, jobject source, jlong classId) { - - jobject globalSourceRef = env->NewGlobalRef(source); - ((SourceCamera*)classId)->RegLandmarkCallback([=](std::vector landmarks) { - jclass cls = env->GetObjectClass(globalSourceRef); - jmethodID methodID = env->GetMethodID(cls, "onFaceLandmark", "([F)V"); - - jfloatArray arr = env->NewFloatArray(landmarks.size()); - env->SetFloatArrayRegion( arr, 0, landmarks.size(), landmarks.data()); - - env->CallVoidMethod(globalSourceRef, methodID, arr); - - env->DeleteLocalRef(arr); - - }); - + //todo }; extern "C"