From 9c410744b3afd6095a82987464363f80bde2ae36 Mon Sep 17 00:00:00 2001 From: xiaodi86 <51728141+xiaodi86@users.noreply.github.com> Date: Sun, 25 Dec 2022 22:01:14 +0800 Subject: [PATCH 01/20] Add files via upload --- .../jni/cge/filters/cgeHistogramFilter.cpp | 69 +++++++++++++++++++ .../jni/cge/filters/cgeWaveformFilter.cpp | 69 +++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 library/src/main/jni/cge/filters/cgeHistogramFilter.cpp create mode 100644 library/src/main/jni/cge/filters/cgeWaveformFilter.cpp diff --git a/library/src/main/jni/cge/filters/cgeHistogramFilter.cpp b/library/src/main/jni/cge/filters/cgeHistogramFilter.cpp new file mode 100644 index 00000000..d71977b2 --- /dev/null +++ b/library/src/main/jni/cge/filters/cgeHistogramFilter.cpp @@ -0,0 +1,69 @@ +#include "cgeHistogramFilter.h" + +static CGEConstString s_fshHistogram = CGE_SHADER_STRING_PRECISION_M +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform vec2 center;//坐标系原点 + + uniform float xValue;//宽度(x轴长度) + + uniform float yValue;//高度(y轴长度) + + uniform vec3 bgColor;//背景颜色 + + void main() + { + /** + 在以center为原点,宽xValue,高yValue,背景色为bgColor的矩形框中绘制亮度直方图。如何在这个库的基础上实现? + */ + gl_FragColor = texture2D(inputImageTexture, textureCoordinate); + } +); + +namespace CGE +{ + CGEConstString CGEHistogramFilter::paramCenter = "center"; + CGEConstString CGEHistogramFilter::paramXValue = "xValue"; + CGEConstString CGEHistogramFilter::paramYValue = "yValue"; + CGEConstString CGEHistogramFilter::paramColor = "bgColor"; + + bool CGEHistogramFilter::init() + { + if(initShadersFromString(g_vshDefaultWithoutTexCoord, s_fshHistogram)) + { + setCenter(0.5f, 0.5f); + setXValue(0.4f); + setYValue(0.3f); + setColor(0.0f, 0.0f, 0.0f); + return true; + } + return false; + } + + void CGEHistogramFilter::setCenter(float x, float y) + { + m_program.bind(); + m_program.sendUniformf(paramCenter, x, y); + } + + void CGEHistogramFilter::setXValue(float value) + { + m_program.bind(); + m_program.sendUniformf(paramXValue, value); + } + + void CGEHistogramFilter::setYValue(float value) + { + m_program.bind(); + m_program.sendUniformf(paramYValue, value); + } + + void CGEHistogramFilter::setColor(float r, float b, float g) + { + m_program.bind(); + m_program.sendUniformf(paramColor, r, b, g); + } +} \ No newline at end of file diff --git a/library/src/main/jni/cge/filters/cgeWaveformFilter.cpp b/library/src/main/jni/cge/filters/cgeWaveformFilter.cpp new file mode 100644 index 00000000..55a5970e --- /dev/null +++ b/library/src/main/jni/cge/filters/cgeWaveformFilter.cpp @@ -0,0 +1,69 @@ +#include "cgeWaveformFilter.h" + +static CGEConstString s_fshWaveform = CGE_SHADER_STRING_PRECISION_M +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform vec2 center;//坐标系原点 + + uniform float xValue;//宽度(x轴长度) + + uniform float yValue;//高度(y轴长度) + + uniform vec3 bgColor;//背景颜色 + + void main() + { + /** + 在以center为原点,宽xValue,高yValue,背景色为bgColor的矩形框中绘制亮度波形图。如何在这个库的基础上实现? + */ + gl_FragColor = texture2D(inputImageTexture, textureCoordinate); + } +); + +namespace CGE +{ + CGEConstString CGEWaveformFilter::paramCenter = "center"; + CGEConstString CGEWaveformFilter::paramXValue = "xValue"; + CGEConstString CGEWaveformFilter::paramYValue = "yValue"; + CGEConstString CGEWaveformFilter::paramColor = "bgColor"; + + bool CGEWaveformFilter::init() + { + if(initShadersFromString(g_vshDefaultWithoutTexCoord, s_fshWaveform)) + { + setCenter(0.5f, 0.5f); + setXValue(0.4f); + setYValue(0.3f); + setColor(0.0f, 0.0f, 0.0f); + return true; + } + return false; + } + + void CGEWaveformFilter::setCenter(float x, float y) + { + m_program.bind(); + m_program.sendUniformf(paramCenter, x, y); + } + + void CGEWaveformFilter::setXValue(float value) + { + m_program.bind(); + m_program.sendUniformf(paramXValue, value); + } + + void CGEWaveformFilter::setYValue(float value) + { + m_program.bind(); + m_program.sendUniformf(paramYValue, value); + } + + void CGEWaveformFilter::setColor(float r, float b, float g) + { + m_program.bind(); + m_program.sendUniformf(paramColor, r, b, g); + } +} \ No newline at end of file From ac383cb75865fad27f465ae8445cc8cd0ff5f0e7 Mon Sep 17 00:00:00 2001 From: xiaodi86 <51728141+xiaodi86@users.noreply.github.com> Date: Sun, 25 Dec 2022 22:02:15 +0800 Subject: [PATCH 02/20] Add files via upload --- .../jni/include/filters/cgeHistogramFilter.h | 39 +++++++++++++++++++ .../jni/include/filters/cgeWaveformFilter.h | 39 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 library/src/main/jni/include/filters/cgeHistogramFilter.h create mode 100644 library/src/main/jni/include/filters/cgeWaveformFilter.h diff --git a/library/src/main/jni/include/filters/cgeHistogramFilter.h b/library/src/main/jni/include/filters/cgeHistogramFilter.h new file mode 100644 index 00000000..cc376a3c --- /dev/null +++ b/library/src/main/jni/include/filters/cgeHistogramFilter.h @@ -0,0 +1,39 @@ +#ifndef _HISTOGRAMFILTER_H_ +#define _HISTOGRAMFILTER_H_ + +#include "cgeImageFilter.h" + +namespace CGE +{ + class CGEHistogramFilter : public CGEImageFilterInterface + { + public: + + /** + * 坐标系原点, 默认 (0.5, 0.5) + */ + void setCenter(float x, float y); + /** + * 宽度 + */ + void setXValue(float value); + /** + * 高度 + */ + void setYValue(float value); + /** + * 背景颜色 + */ + void setColor(float r, float b, float g); + + bool init(); + + protected: + static CGEConstString paramCenter; + static CGEConstString paramXValue; + static CGEConstString paramYValue; + static CGEConstString paramColor; + }; +} + +#endif \ No newline at end of file diff --git a/library/src/main/jni/include/filters/cgeWaveformFilter.h b/library/src/main/jni/include/filters/cgeWaveformFilter.h new file mode 100644 index 00000000..b8622ded --- /dev/null +++ b/library/src/main/jni/include/filters/cgeWaveformFilter.h @@ -0,0 +1,39 @@ +#ifndef _WAVEFORMFILTER_H_ +#define _WAVEFORMFILTER_H_ + +#include "cgeImageFilter.h" + +namespace CGE +{ + class CGEWaveformFilter : public CGEImageFilterInterface + { + public: + + /** + * 坐标系原点, 默认 (0.5, 0.5) + */ + void setCenter(float x, float y); + /** + * 宽度 + */ + void setXValue(float value); + /** + * 高度 + */ + void setYValue(float value); + /** + * 背景颜色 + */ + void setColor(float r, float b, float g); + + bool init(); + + protected: + static CGEConstString paramCenter; + static CGEConstString paramXValue; + static CGEConstString paramYValue; + static CGEConstString paramColor; + }; +} + +#endif \ No newline at end of file From 32cfea0036c5d4b244b4afe1dc3b88fcc0b327f0 Mon Sep 17 00:00:00 2001 From: xiaodi86 <51728141+xiaodi86@users.noreply.github.com> Date: Sun, 25 Dec 2022 22:04:12 +0800 Subject: [PATCH 03/20] Add files via upload --- .../jni/cge/filters/cgeAdvancedEffects.cpp | 289 +++++++++--------- 1 file changed, 149 insertions(+), 140 deletions(-) diff --git a/library/src/main/jni/cge/filters/cgeAdvancedEffects.cpp b/library/src/main/jni/cge/filters/cgeAdvancedEffects.cpp index e523a499..4ea0b7e6 100644 --- a/library/src/main/jni/cge/filters/cgeAdvancedEffects.cpp +++ b/library/src/main/jni/cge/filters/cgeAdvancedEffects.cpp @@ -1,140 +1,149 @@ -/* - * cgeAdvancedEffects.cpp - * - * Created on: 2013-12-13 - * Author: Wang Yang - */ - -#include "cgeAdvancedEffects.h" - -#define COMMON_FUNC(type) \ -type* proc = new type();\ -if(!proc->init())\ -{\ - delete proc;\ - proc = NULL;\ -}\ -return proc;\ - -namespace CGE -{ - CGEEmbossFilter* createEmbossFilter() - { - COMMON_FUNC(CGEEmbossFilter); - } - - CGEEdgeFilter* createEdgeFilter() - { - COMMON_FUNC(CGEEdgeFilter); - } - - CGEEdgeSobelFilter* createEdgeSobelFilter() - { - COMMON_FUNC(CGEEdgeSobelFilter); - } - - CGERandomBlurFilter* createRandomBlurFilter() - { - COMMON_FUNC(CGERandomBlurFilter); - } - - CGEBilateralBlurFilter* createBilateralBlurFilter() - { - COMMON_FUNC(CGEBilateralBlurFilter); - } - - CGEBilateralBlurBetterFilter* createBilateralBlurBetterFilter() - { - COMMON_FUNC(CGEBilateralBlurBetterFilter); - } - - CGEMosaicBlurFilter* createMosaicBlurFilter() - { - COMMON_FUNC(CGEMosaicBlurFilter); - } - - CGELiquifyFilter* getLiquidationFilter(float ratio, float stride) - { - CGELiquifyFilter* proc = new CGELiquifyFilter; - if(!proc->initWithMesh(ratio, stride)) - { - delete proc; - return nullptr; - } - return proc; - } - - CGELiquifyFilter* getLiquidationFilter(float width, float height, float stride) - { - CGELiquifyFilter* proc = new CGELiquifyFilter; - if(!proc->initWithMesh(width, height, stride)) - { - delete proc; - return nullptr; - } - return proc; - } - - CGELiquidationNicerFilter* getLiquidationNicerFilter(float ratio, float stride) - { - CGELiquidationNicerFilter* proc = new CGELiquidationNicerFilter; - if(!proc->initWithMesh(ratio, stride)) - { - delete proc; - return nullptr; - } - return proc; - } - - CGELiquidationNicerFilter* getLiquidationNicerFilter(float width, float height, float stride) - { - CGELiquidationNicerFilter* proc = new CGELiquidationNicerFilter; - if(!proc->initWithMesh(width, height, stride)) - { - delete proc; - return nullptr; - } - return proc; - } - - CGEHalftoneFilter* createHalftoneFilter() - { - COMMON_FUNC(CGEHalftoneFilter); - } - - CGEPolarPixellateFilter* createPolarPixellateFilter() - { - COMMON_FUNC(CGEPolarPixellateFilter); - } - - CGEPolkaDotFilter* createPolkaDotFilter() - { - COMMON_FUNC(CGEPolkaDotFilter); - } - - CGECrosshatchFilter* createCrosshatchFilter() - { - COMMON_FUNC(CGECrosshatchFilter); - } - - CGEHazeFilter* createHazeFilter() - { - COMMON_FUNC(CGEHazeFilter); - } - - CGELerpblurFilter* createLerpblurFilter() - { - COMMON_FUNC(CGELerpblurFilter); - } - - CGESketchFilter* createSketchFilter() - { - COMMON_FUNC(CGESketchFilter); - } - - CGEBeautifyFilter* createBeautifyFilter() - { - COMMON_FUNC(CGEBeautifyFilter); - } - - } +/* + * cgeAdvancedEffects.cpp + * + * Created on: 2013-12-13 + * Author: Wang Yang + */ + +#include "cgeAdvancedEffects.h" + +#define COMMON_FUNC(type) \ +type* proc = new type();\ +if(!proc->init())\ +{\ + delete proc;\ + proc = NULL;\ +}\ +return proc;\ + +namespace CGE +{ + CGEEmbossFilter* createEmbossFilter() + { + COMMON_FUNC(CGEEmbossFilter); + } + + CGEEdgeFilter* createEdgeFilter() + { + COMMON_FUNC(CGEEdgeFilter); + } + + CGEEdgeSobelFilter* createEdgeSobelFilter() + { + COMMON_FUNC(CGEEdgeSobelFilter); + } + + CGERandomBlurFilter* createRandomBlurFilter() + { + COMMON_FUNC(CGERandomBlurFilter); + } + + CGEBilateralBlurFilter* createBilateralBlurFilter() + { + COMMON_FUNC(CGEBilateralBlurFilter); + } + + CGEBilateralBlurBetterFilter* createBilateralBlurBetterFilter() + { + COMMON_FUNC(CGEBilateralBlurBetterFilter); + } + + CGEMosaicBlurFilter* createMosaicBlurFilter() + { + COMMON_FUNC(CGEMosaicBlurFilter); + } + + CGELiquifyFilter* getLiquidationFilter(float ratio, float stride) + { + CGELiquifyFilter* proc = new CGELiquifyFilter; + if(!proc->initWithMesh(ratio, stride)) + { + delete proc; + return nullptr; + } + return proc; + } + + CGELiquifyFilter* getLiquidationFilter(float width, float height, float stride) + { + CGELiquifyFilter* proc = new CGELiquifyFilter; + if(!proc->initWithMesh(width, height, stride)) + { + delete proc; + return nullptr; + } + return proc; + } + + CGELiquidationNicerFilter* getLiquidationNicerFilter(float ratio, float stride) + { + CGELiquidationNicerFilter* proc = new CGELiquidationNicerFilter; + if(!proc->initWithMesh(ratio, stride)) + { + delete proc; + return nullptr; + } + return proc; + } + + CGELiquidationNicerFilter* getLiquidationNicerFilter(float width, float height, float stride) + { + CGELiquidationNicerFilter* proc = new CGELiquidationNicerFilter; + if(!proc->initWithMesh(width, height, stride)) + { + delete proc; + return nullptr; + } + return proc; + } + + CGEHalftoneFilter* createHalftoneFilter() + { + COMMON_FUNC(CGEHalftoneFilter); + } + + CGEPolarPixellateFilter* createPolarPixellateFilter() + { + COMMON_FUNC(CGEPolarPixellateFilter); + } + + CGEPolkaDotFilter* createPolkaDotFilter() + { + COMMON_FUNC(CGEPolkaDotFilter); + } + + CGECrosshatchFilter* createCrosshatchFilter() + { + COMMON_FUNC(CGECrosshatchFilter); + } + + CGEHazeFilter* createHazeFilter() + { + COMMON_FUNC(CGEHazeFilter); + } + + CGELerpblurFilter* createLerpblurFilter() + { + COMMON_FUNC(CGELerpblurFilter); + } + + CGESketchFilter* createSketchFilter() + { + COMMON_FUNC(CGESketchFilter); + } + + CGEBeautifyFilter* createBeautifyFilter() + { + COMMON_FUNC(CGEBeautifyFilter); + } + + CGEHistogramFilter* createHistogramFilter() + { + COMMON_FUNC(CGEHistogramFilter); + } + + CGEWaveformFilter* createWaveformFilter() + { + COMMON_FUNC(CGEWaveformFilter); + } + } From c64c11e44fef75622100cd43805ede0bf8f17d4f Mon Sep 17 00:00:00 2001 From: xiaodi86 <51728141+xiaodi86@users.noreply.github.com> Date: Sun, 25 Dec 2022 22:05:32 +0800 Subject: [PATCH 04/20] Add files via upload --- library/src/main/jni/Android.mk | 372 ++++++++++++++++---------------- 1 file changed, 188 insertions(+), 184 deletions(-) diff --git a/library/src/main/jni/Android.mk b/library/src/main/jni/Android.mk index 144c922b..9c22e989 100644 --- a/library/src/main/jni/Android.mk +++ b/library/src/main/jni/Android.mk @@ -1,185 +1,189 @@ -# -# Created on: 2015-7-9 -# Author: Wang Yang -# Mail: admin@wysaid.org -# - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := CGE - -#*********************** CGE Library **************************** - -CGE_ROOT=$(LOCAL_PATH) - -CGE_SOURCE=$(CGE_ROOT)/cge - -CGE_INCLUDE=$(CGE_ROOT)/include - -#### CGE Library headers ########### -LOCAL_C_INCLUDES := \ - $(CGE_ROOT)/interface \ - $(CGE_INCLUDE) \ - $(CGE_INCLUDE)/filters \ - - -#### CGE Library native source ########### - -LOCAL_SRC_FILES := \ - $(CGE_SOURCE)/common/cgeCommonDefine.cpp \ - $(CGE_SOURCE)/common/cgeGLFunctions.cpp \ - $(CGE_SOURCE)/common/cgeImageFilter.cpp \ - $(CGE_SOURCE)/common/cgeImageHandler.cpp \ - $(CGE_SOURCE)/common/cgeShaderFunctions.cpp \ - $(CGE_SOURCE)/common/cgeGlobal.cpp \ - $(CGE_SOURCE)/common/cgeTextureUtils.cpp \ - \ - $(CGE_SOURCE)/filters/cgeAdvancedEffects.cpp \ - $(CGE_SOURCE)/filters/cgeAdvancedEffectsCommon.cpp \ - $(CGE_SOURCE)/filters/cgeBilateralBlurFilter.cpp \ - $(CGE_SOURCE)/filters/cgeMosaicBlurFilter.cpp \ - $(CGE_SOURCE)/filters/cgeBeautifyFilter.cpp \ - \ - $(CGE_SOURCE)/filters/cgeBrightnessAdjust.cpp \ - $(CGE_SOURCE)/filters/cgeColorLevelAdjust.cpp \ - $(CGE_SOURCE)/filters/cgeContrastAdjust.cpp \ - $(CGE_SOURCE)/filters/cgeCurveAdjust.cpp \ - $(CGE_SOURCE)/filters/cgeExposureAdjust.cpp \ - $(CGE_SOURCE)/filters/cgeFilterBasic.cpp \ - $(CGE_SOURCE)/filters/cgeHueAdjust.cpp \ - $(CGE_SOURCE)/filters/cgeMonochromeAdjust.cpp \ - $(CGE_SOURCE)/filters/cgeSaturationAdjust.cpp \ - $(CGE_SOURCE)/filters/cgeSelectiveColorAdjust.cpp \ - $(CGE_SOURCE)/filters/cgeShadowHighlightAdjust.cpp \ - $(CGE_SOURCE)/filters/cgeSharpenBlurAdjust.cpp \ - $(CGE_SOURCE)/filters/cgeTiltshiftAdjust.cpp \ - $(CGE_SOURCE)/filters/cgeVignetteAdjust.cpp \ - $(CGE_SOURCE)/filters/cgeWhiteBalanceAdjust.cpp \ - $(CGE_SOURCE)/filters/cgeColorBalanceAdjust.cpp \ - $(CGE_SOURCE)/filters/cgeLookupFilter.cpp \ - \ - $(CGE_SOURCE)/filters/cgeBlendFilter.cpp \ - \ - $(CGE_SOURCE)/filters/cgeDataParsingEngine.cpp \ - $(CGE_SOURCE)/filters/cgeMultipleEffects.cpp \ - $(CGE_SOURCE)/filters/cgeMultipleEffectsCommon.cpp \ - \ - $(CGE_SOURCE)/filters/cgeHazeFilter.cpp \ - $(CGE_SOURCE)/filters/cgePolarPixellateFilter.cpp \ - $(CGE_SOURCE)/filters/cgePolkaDotFilter.cpp \ - $(CGE_SOURCE)/filters/cgeHalftoneFilter.cpp \ - $(CGE_SOURCE)/filters/cgeEdgeFilter.cpp \ - $(CGE_SOURCE)/filters/cgeEmbossFilter.cpp \ - $(CGE_SOURCE)/filters/cgeCrosshatchFilter.cpp \ - $(CGE_SOURCE)/filters/cgeLiquifyFilter.cpp \ - $(CGE_SOURCE)/filters/cgeRandomBlurFilter.cpp \ - $(CGE_SOURCE)/filters/cgeMinValueFilter.cpp \ - $(CGE_SOURCE)/filters/cgeMaxValueFilter.cpp \ - $(CGE_SOURCE)/filters/cgeSketchFilter.cpp \ - $(CGE_SOURCE)/filters/cgeLerpblurFilter.cpp \ - \ - $(CGE_SOURCE)/filters/cgeDynamicFilters.cpp \ - $(CGE_SOURCE)/filters/cgeDynamicWaveFilter.cpp \ - $(CGE_SOURCE)/filters/cgeMotionFlowFilter.cpp \ - $(CGE_SOURCE)/filters/cgeColorMappingFilter.cpp \ - $(CGE_SOURCE)/extends/cgeThread.cpp \ - \ - $(CGE_ROOT)/interface/cgeNativeLibrary.cpp \ - $(CGE_ROOT)/interface/cgeFFmpegNativeLibrary.cpp \ - $(CGE_ROOT)/interface/cgeSharedGLContext.cpp \ - $(CGE_ROOT)/interface/cgeFrameRenderer.cpp \ - $(CGE_ROOT)/interface/cgeFrameRendererWrapper.cpp \ - $(CGE_ROOT)/interface/cgeFrameRecorder.cpp \ - $(CGE_ROOT)/interface/cgeFrameRecorderWrapper.cpp \ - $(CGE_ROOT)/interface/cgeVideoEncoder.cpp \ - $(CGE_ROOT)/interface/cgeUtilFunctions.cpp \ - $(CGE_ROOT)/interface/cgeVideoDecoder.cpp \ - $(CGE_ROOT)/interface/cgeVideoPlayer.cpp \ - $(CGE_ROOT)/interface/cgeImageHandlerAndroid.cpp \ - $(CGE_ROOT)/interface/cgeImageHandlerWrapper.cpp \ - $(CGE_ROOT)/interface/cgeDeformFilterWrapper.cpp \ - - -LOCAL_CPPFLAGS := -frtti -std=c++11 -LOCAL_LDLIBS := -llog -lEGL -lGLESv2 -ljnigraphics - -# 'CGE_USE_VIDEO_MODULE' determines if the project should compile with ffmpeg. - -ifdef CGE_USE_VIDEO_MODULE - -VIDEO_MODULE_DEFINE = -D_CGE_USE_FFMPEG_ - -endif - -ifndef CGE_RELEASE_MODE -BUILD_MODE = -D_CGE_LOGS_ -ifdef CGE_DEBUG_MODE -BUILD_MODE += -DDEBUG -endif -endif - -ifdef CGE_USE_LEAK_TEST -BUILD_MODE += -D_CGE_GENERAL_ERROR_TEST_ -endif - -LOCAL_CFLAGS := ${VIDEO_MODULE_DEFINE} ${BUILD_MODE} -DANDROID_NDK -DCGE_LOG_TAG=\"libCGE\" -DCGE_TEXTURE_PREMULTIPLIED=1 -D__STDC_CONSTANT_MACROS -D_CGE_DISABLE_GLOBALCONTEXT_ -O3 -ffast-math -D_CGE_ONLY_FILTERS_ - -ifdef CGE_USE_FACE_MODULE - -LOCAL_CFLAGS := $(LOCAL_CFLAGS) -D_CGE_USE_FACE_MODULE_ - -endif - -ifndef CGE_USE_VIDEO_MODULE - -#LOCAL_CFLAGS := $(LOCAL_CFLAGS) -D_CGE_ONLY_FILTERS_ - -include $(BUILD_SHARED_LIBRARY) - -else - -LOCAL_SHARED_LIBRARIES := ffmpeg - -include $(BUILD_SHARED_LIBRARY) - -################################ - -# include $(CLEAR_VARS) -# LOCAL_MODULE := x264 -# LOCAL_CFLAGS := -march=armv7-a -mfloat-abi=softfp -mfpu=neon -O3 -ffast-math -funroll-loops -# LOCAL_SRC_FILES := ffmpeg/libx264.142.so -# #LOCAL_EXPORT_C_INCLUDES := $(CGE_ROOT)/ffmpeg -# include $(PREBUILT_SHARED_LIBRARY) - -############################### - -include $(CLEAR_VARS) -LOCAL_MODULE := ffmpeg -LOCAL_CFLAGS := -mfloat-abi=softfp -mfpu=vfp -O3 -ffast-math -funroll-loops -fPIC -ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) -LOCAL_CFLAGS := $(LOCAL_CFLAGS) march=armv7-a -mfpu=neon -endif -LOCAL_SRC_FILES := ffmpeg/$(TARGET_ARCH_ABI)/libffmpeg.so -LOCAL_EXPORT_C_INCLUDES := $(CGE_ROOT)/ffmpeg - -# LOCAL_SHARED_LIBRARIES := x264 - -include $(PREBUILT_SHARED_LIBRARY) - -endif - -############################### - -ifdef CGE_USE_FACE_MODULE - -include $(CLEAR_VARS) -include $(CGE_ROOT)/faceTracker/jni/Android.mk - -endif -############################### - -# Call user defined module -include $(CLEAR_VARS) +# +# Created on: 2015-7-9 +# Author: Wang Yang +# Mail: admin@wysaid.org +# + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := CGE + +#*********************** CGE Library **************************** + +CGE_ROOT=$(LOCAL_PATH) + +CGE_SOURCE=$(CGE_ROOT)/cge + +CGE_INCLUDE=$(CGE_ROOT)/include + +#### CGE Library headers ########### +LOCAL_C_INCLUDES := \ + $(CGE_ROOT)/interface \ + $(CGE_INCLUDE) \ + $(CGE_INCLUDE)/filters \ + + +#### CGE Library native source ########### + +LOCAL_SRC_FILES := \ + $(CGE_SOURCE)/common/cgeCommonDefine.cpp \ + $(CGE_SOURCE)/common/cgeGLFunctions.cpp \ + $(CGE_SOURCE)/common/cgeImageFilter.cpp \ + $(CGE_SOURCE)/common/cgeImageHandler.cpp \ + $(CGE_SOURCE)/common/cgeShaderFunctions.cpp \ + $(CGE_SOURCE)/common/cgeGlobal.cpp \ + $(CGE_SOURCE)/common/cgeTextureUtils.cpp \ + \ + $(CGE_SOURCE)/filters/cgeAdvancedEffects.cpp \ + $(CGE_SOURCE)/filters/cgeAdvancedEffectsCommon.cpp \ + $(CGE_SOURCE)/filters/cgeBilateralBlurFilter.cpp \ + $(CGE_SOURCE)/filters/cgeMosaicBlurFilter.cpp \ + $(CGE_SOURCE)/filters/cgeBeautifyFilter.cpp \ + \ + $(CGE_SOURCE)/filters/cgeBrightnessAdjust.cpp \ + $(CGE_SOURCE)/filters/cgeColorLevelAdjust.cpp \ + $(CGE_SOURCE)/filters/cgeContrastAdjust.cpp \ + $(CGE_SOURCE)/filters/cgeCurveAdjust.cpp \ + $(CGE_SOURCE)/filters/cgeExposureAdjust.cpp \ + $(CGE_SOURCE)/filters/cgeFilterBasic.cpp \ + $(CGE_SOURCE)/filters/cgeHueAdjust.cpp \ + $(CGE_SOURCE)/filters/cgeMonochromeAdjust.cpp \ + $(CGE_SOURCE)/filters/cgeSaturationAdjust.cpp \ + $(CGE_SOURCE)/filters/cgeSelectiveColorAdjust.cpp \ + $(CGE_SOURCE)/filters/cgeShadowHighlightAdjust.cpp \ + $(CGE_SOURCE)/filters/cgeSharpenBlurAdjust.cpp \ + $(CGE_SOURCE)/filters/cgeTiltshiftAdjust.cpp \ + $(CGE_SOURCE)/filters/cgeVignetteAdjust.cpp \ + $(CGE_SOURCE)/filters/cgeWhiteBalanceAdjust.cpp \ + $(CGE_SOURCE)/filters/cgeColorBalanceAdjust.cpp \ + $(CGE_SOURCE)/filters/cgeLookupFilter.cpp \ + \ + $(CGE_SOURCE)/filters/cgeBlendFilter.cpp \ + \ + $(CGE_SOURCE)/filters/cgeDataParsingEngine.cpp \ + $(CGE_SOURCE)/filters/cgeMultipleEffects.cpp \ + $(CGE_SOURCE)/filters/cgeMultipleEffectsCommon.cpp \ + \ + $(CGE_SOURCE)/filters/cgeHazeFilter.cpp \ + $(CGE_SOURCE)/filters/cgePolarPixellateFilter.cpp \ + $(CGE_SOURCE)/filters/cgePolkaDotFilter.cpp \ + $(CGE_SOURCE)/filters/cgeHalftoneFilter.cpp \ + $(CGE_SOURCE)/filters/cgeEdgeFilter.cpp \ + $(CGE_SOURCE)/filters/cgeEmbossFilter.cpp \ + + $(CGE_SOURCE)/filters/cgeHistogramFilter.cpp \ + $(CGE_SOURCE)/filters/cgeWaveformFilter.cpp \ + + $(CGE_SOURCE)/filters/cgeCrosshatchFilter.cpp \ + $(CGE_SOURCE)/filters/cgeLiquifyFilter.cpp \ + $(CGE_SOURCE)/filters/cgeRandomBlurFilter.cpp \ + $(CGE_SOURCE)/filters/cgeMinValueFilter.cpp \ + $(CGE_SOURCE)/filters/cgeMaxValueFilter.cpp \ + $(CGE_SOURCE)/filters/cgeSketchFilter.cpp \ + $(CGE_SOURCE)/filters/cgeLerpblurFilter.cpp \ + \ + $(CGE_SOURCE)/filters/cgeDynamicFilters.cpp \ + $(CGE_SOURCE)/filters/cgeDynamicWaveFilter.cpp \ + $(CGE_SOURCE)/filters/cgeMotionFlowFilter.cpp \ + $(CGE_SOURCE)/filters/cgeColorMappingFilter.cpp \ + $(CGE_SOURCE)/extends/cgeThread.cpp \ + \ + $(CGE_ROOT)/interface/cgeNativeLibrary.cpp \ + $(CGE_ROOT)/interface/cgeFFmpegNativeLibrary.cpp \ + $(CGE_ROOT)/interface/cgeSharedGLContext.cpp \ + $(CGE_ROOT)/interface/cgeFrameRenderer.cpp \ + $(CGE_ROOT)/interface/cgeFrameRendererWrapper.cpp \ + $(CGE_ROOT)/interface/cgeFrameRecorder.cpp \ + $(CGE_ROOT)/interface/cgeFrameRecorderWrapper.cpp \ + $(CGE_ROOT)/interface/cgeVideoEncoder.cpp \ + $(CGE_ROOT)/interface/cgeUtilFunctions.cpp \ + $(CGE_ROOT)/interface/cgeVideoDecoder.cpp \ + $(CGE_ROOT)/interface/cgeVideoPlayer.cpp \ + $(CGE_ROOT)/interface/cgeImageHandlerAndroid.cpp \ + $(CGE_ROOT)/interface/cgeImageHandlerWrapper.cpp \ + $(CGE_ROOT)/interface/cgeDeformFilterWrapper.cpp \ + + +LOCAL_CPPFLAGS := -frtti -std=c++11 +LOCAL_LDLIBS := -llog -lEGL -lGLESv2 -ljnigraphics + +# 'CGE_USE_VIDEO_MODULE' determines if the project should compile with ffmpeg. + +ifdef CGE_USE_VIDEO_MODULE + +VIDEO_MODULE_DEFINE = -D_CGE_USE_FFMPEG_ + +endif + +ifndef CGE_RELEASE_MODE +BUILD_MODE = -D_CGE_LOGS_ +ifdef CGE_DEBUG_MODE +BUILD_MODE += -DDEBUG +endif +endif + +ifdef CGE_USE_LEAK_TEST +BUILD_MODE += -D_CGE_GENERAL_ERROR_TEST_ +endif + +LOCAL_CFLAGS := ${VIDEO_MODULE_DEFINE} ${BUILD_MODE} -DANDROID_NDK -DCGE_LOG_TAG=\"libCGE\" -DCGE_TEXTURE_PREMULTIPLIED=1 -D__STDC_CONSTANT_MACROS -D_CGE_DISABLE_GLOBALCONTEXT_ -O3 -ffast-math -D_CGE_ONLY_FILTERS_ + +ifdef CGE_USE_FACE_MODULE + +LOCAL_CFLAGS := $(LOCAL_CFLAGS) -D_CGE_USE_FACE_MODULE_ + +endif + +ifndef CGE_USE_VIDEO_MODULE + +#LOCAL_CFLAGS := $(LOCAL_CFLAGS) -D_CGE_ONLY_FILTERS_ + +include $(BUILD_SHARED_LIBRARY) + +else + +LOCAL_SHARED_LIBRARIES := ffmpeg + +include $(BUILD_SHARED_LIBRARY) + +################################ + +# include $(CLEAR_VARS) +# LOCAL_MODULE := x264 +# LOCAL_CFLAGS := -march=armv7-a -mfloat-abi=softfp -mfpu=neon -O3 -ffast-math -funroll-loops +# LOCAL_SRC_FILES := ffmpeg/libx264.142.so +# #LOCAL_EXPORT_C_INCLUDES := $(CGE_ROOT)/ffmpeg +# include $(PREBUILT_SHARED_LIBRARY) + +############################### + +include $(CLEAR_VARS) +LOCAL_MODULE := ffmpeg +LOCAL_CFLAGS := -mfloat-abi=softfp -mfpu=vfp -O3 -ffast-math -funroll-loops -fPIC +ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) +LOCAL_CFLAGS := $(LOCAL_CFLAGS) march=armv7-a -mfpu=neon +endif +LOCAL_SRC_FILES := ffmpeg/$(TARGET_ARCH_ABI)/libffmpeg.so +LOCAL_EXPORT_C_INCLUDES := $(CGE_ROOT)/ffmpeg + +# LOCAL_SHARED_LIBRARIES := x264 + +include $(PREBUILT_SHARED_LIBRARY) + +endif + +############################### + +ifdef CGE_USE_FACE_MODULE + +include $(CLEAR_VARS) +include $(CGE_ROOT)/faceTracker/jni/Android.mk + +endif +############################### + +# Call user defined module +include $(CLEAR_VARS) include $(CGE_ROOT)/source/source.mk \ No newline at end of file From 180f280cb6c821512470d6f309d2c10d8688b410 Mon Sep 17 00:00:00 2001 From: xiaodi86 <51728141+xiaodi86@users.noreply.github.com> Date: Sun, 25 Dec 2022 22:06:36 +0800 Subject: [PATCH 05/20] Add files via upload --- library/src/main/jni/include/cge.h | 260 +++++++++++++++-------------- 1 file changed, 131 insertions(+), 129 deletions(-) diff --git a/library/src/main/jni/include/cge.h b/library/src/main/jni/include/cge.h index 75c5c132..f59245a0 100644 --- a/library/src/main/jni/include/cge.h +++ b/library/src/main/jni/include/cge.h @@ -1,129 +1,131 @@ -/* - * cge.h - * - * Created on: 2014-10-16 - * Author: Wang Yang - * Mail: admin@wysaid.org - */ - -#ifndef _CGE_H_ -#define _CGE_H_ - -//umbrella header - -#ifndef IOS_SDK -#define IOS_SDK 1 -#endif - -#ifndef CGE_TEXTURE_PREMULTIPLIED -#define CGE_TEXTURE_PREMULTIPLIED 1 -#endif - -#ifndef _CGE_ONLY_FILTERS_ -#define _CGE_ONLY_FILTERS_ 1 -#endif - -#ifdef __OBJC__ - -#import - -//! Project version number for cge. -FOUNDATION_EXPORT double cgeVersionNumber; - -//! Project version string for cge. -FOUNDATION_EXPORT const unsigned char cgeVersionString[]; - -// In this header, you should import all the public headers of your framework using statements like #import - -#import -#import - -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import - -#ifdef __cplusplus - -#import -#import - -// pure cpp - -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import - - -#endif - -#endif - -#endif +/* + * cge.h + * + * Created on: 2014-10-16 + * Author: Wang Yang + * Mail: admin@wysaid.org + */ + +#ifndef _CGE_H_ +#define _CGE_H_ + +//umbrella header + +#ifndef IOS_SDK +#define IOS_SDK 1 +#endif + +#ifndef CGE_TEXTURE_PREMULTIPLIED +#define CGE_TEXTURE_PREMULTIPLIED 1 +#endif + +#ifndef _CGE_ONLY_FILTERS_ +#define _CGE_ONLY_FILTERS_ 1 +#endif + +#ifdef __OBJC__ + +#import + +//! Project version number for cge. +FOUNDATION_EXPORT double cgeVersionNumber; + +//! Project version string for cge. +FOUNDATION_EXPORT const unsigned char cgeVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + +#import +#import + +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import + +#ifdef __cplusplus + +#import +#import + +// pure cpp + +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import + +#import +#import + +#endif + +#endif + +#endif From 85c53eafb55c2a0c00eb52956ba18ea89bf1a334 Mon Sep 17 00:00:00 2001 From: xiaodi86 <51728141+xiaodi86@users.noreply.github.com> Date: Sun, 25 Dec 2022 22:08:20 +0800 Subject: [PATCH 06/20] Add files via upload --- .../jni/include/filters/cgeAdvancedEffects.h | 113 +++++++++--------- 1 file changed, 59 insertions(+), 54 deletions(-) diff --git a/library/src/main/jni/include/filters/cgeAdvancedEffects.h b/library/src/main/jni/include/filters/cgeAdvancedEffects.h index 28cce842..6bbc1b21 100644 --- a/library/src/main/jni/include/filters/cgeAdvancedEffects.h +++ b/library/src/main/jni/include/filters/cgeAdvancedEffects.h @@ -1,54 +1,59 @@ -/* - * cgeAdvancedEffects.h - * - * Created on: 2013-12-13 - * Author: Wang Yang - */ - -#ifndef _CGEADVANCEDEFFECTS_H_ -#define _CGEADVANCEDEFFECTS_H_ - -#include "cgeEmbossFilter.h" -#include "cgeEdgeFilter.h" -#include "cgeRandomBlurFilter.h" -#include "cgeBilateralBlurFilter.h" -#include "cgeMosaicBlurFilter.h" -#include "cgeLiquifyFilter.h" -#include "cgeHalftoneFilter.h" -#include "cgePolarPixellateFilter.h" -#include "cgePolkaDotFilter.h" -#include "cgeCrosshatchFilter.h" -#include "cgeHazeFilter.h" -#include "cgeLerpblurFilter.h" - -#include "cgeSketchFilter.h" -#include "cgeBeautifyFilter.h" - -namespace CGE -{ - CGEEmbossFilter* createEmbossFilter(); - CGEEdgeFilter* createEdgeFilter(); - CGEEdgeSobelFilter* createEdgeSobelFilter(); - CGERandomBlurFilter* createRandomBlurFilter(); - CGEBilateralBlurFilter* createBilateralBlurFilter(); - CGEBilateralBlurBetterFilter* createBilateralBlurBetterFilter(); - CGEMosaicBlurFilter* createMosaicBlurFilter(); - CGELiquifyFilter* getLiquidationFilter(float ratio, float stride); - CGELiquifyFilter* getLiquidationFilter(float width, float height , float stride); - - CGELiquidationNicerFilter* getLiquidationNicerFilter(float ratio, float stride); - CGELiquidationNicerFilter* getLiquidationNicerFilter(float width, float height , float stride); - - CGEHalftoneFilter* createHalftoneFilter(); - CGEPolarPixellateFilter* createPolarPixellateFilter(); - CGEPolkaDotFilter* createPolkaDotFilter(); - CGECrosshatchFilter* createCrosshatchFilter(); - CGEHazeFilter* createHazeFilter(); - CGELerpblurFilter* createLerpblurFilter(); - - CGESketchFilter* createSketchFilter(); - - CGEBeautifyFilter* createBeautifyFilter(); -} - -#endif +/* + * cgeAdvancedEffects.h + * + * Created on: 2013-12-13 + * Author: Wang Yang + */ + +#ifndef _CGEADVANCEDEFFECTS_H_ +#define _CGEADVANCEDEFFECTS_H_ + +#include "cgeEmbossFilter.h" +#include "cgeEdgeFilter.h" +#include "cgeRandomBlurFilter.h" +#include "cgeBilateralBlurFilter.h" +#include "cgeMosaicBlurFilter.h" +#include "cgeLiquifyFilter.h" +#include "cgeHalftoneFilter.h" +#include "cgePolarPixellateFilter.h" +#include "cgePolkaDotFilter.h" +#include "cgeCrosshatchFilter.h" +#include "cgeHazeFilter.h" +#include "cgeLerpblurFilter.h" + +#include "cgeSketchFilter.h" +#include "cgeBeautifyFilter.h" + +#include "cgeHistogramFilter.h" +#include "cgeWaveformFilter.h" +namespace CGE +{ + CGEEmbossFilter* createEmbossFilter(); + CGEEdgeFilter* createEdgeFilter(); + CGEEdgeSobelFilter* createEdgeSobelFilter(); + CGERandomBlurFilter* createRandomBlurFilter(); + CGEBilateralBlurFilter* createBilateralBlurFilter(); + CGEBilateralBlurBetterFilter* createBilateralBlurBetterFilter(); + CGEMosaicBlurFilter* createMosaicBlurFilter(); + CGELiquifyFilter* getLiquidationFilter(float ratio, float stride); + CGELiquifyFilter* getLiquidationFilter(float width, float height , float stride); + + CGELiquidationNicerFilter* getLiquidationNicerFilter(float ratio, float stride); + CGELiquidationNicerFilter* getLiquidationNicerFilter(float width, float height , float stride); + + CGEHalftoneFilter* createHalftoneFilter(); + CGEPolarPixellateFilter* createPolarPixellateFilter(); + CGEPolkaDotFilter* createPolkaDotFilter(); + CGECrosshatchFilter* createCrosshatchFilter(); + CGEHazeFilter* createHazeFilter(); + CGELerpblurFilter* createLerpblurFilter(); + + CGESketchFilter* createSketchFilter(); + + CGEBeautifyFilter* createBeautifyFilter(); + + CGEHistogramFilter* createHistogramFilter(); + CGEWaveformFilter* createWaveformFilter(); +} + +#endif From 439cfcc41a820b5f16241073a1872db339fe3590 Mon Sep 17 00:00:00 2001 From: xiaodi86 <51728141+xiaodi86@users.noreply.github.com> Date: Sun, 25 Dec 2022 22:09:48 +0800 Subject: [PATCH 07/20] Add files via upload --- .../jni/cge/filters/cgeDataParsingEngine.cpp | 2844 +++++++++-------- 1 file changed, 1442 insertions(+), 1402 deletions(-) diff --git a/library/src/main/jni/cge/filters/cgeDataParsingEngine.cpp b/library/src/main/jni/cge/filters/cgeDataParsingEngine.cpp index bc079bfe..925692e5 100755 --- a/library/src/main/jni/cge/filters/cgeDataParsingEngine.cpp +++ b/library/src/main/jni/cge/filters/cgeDataParsingEngine.cpp @@ -1,1403 +1,1443 @@ -/* -* cgeMultipleEffects.cpp -* -* Created on: 2013-12-13 -* Author: Wang Yang -* Mail: admin@wysaid.org -*/ - -#include "cgeDataParsingEngine.h" -#include "cgeMultipleEffectsCommon.h" -#include "cgeAdvancedEffects.h" -#include "cgeBlendFilter.h" -#include "cgeFilterBasic.h" -#include "cgeDynamicFilters.h" -#include "cgeColorMappingFilter.h" - -#include -#include -#include - -//为了加快处理速度,使用固定大小的buffer来存储Parser所需参数。 -//每个method后面的参数长度都不应该超过BUFFER_LEN。 -//如果你的Parser所需参数超过此长度,请将BUFFER_LEN增加到合适的长度。 -#define BUFFER_LEN 1024 -#define BUFFER_LEN_STR "1023" - -#define LOG_ERROR_PARAM(arg) CGE_LOG_ERROR("Invalid Parameters: %s\n", arg); - -namespace CGE -{ - extern bool g_isFastFilterImpossible; - - void tableParserHelper(std::vector& vecPnts, const char* pstr, int n) - { - const char* p = pstr; - int a, b; - - for(int i = 0; i < n;) - { - while(i < n && pstr[i] != '\0' && pstr[i] != '(') ++i; - if(pstr[i] != '(') break; - p = pstr + i + 1; - if(sscanf(p, "%d%*c%d", &a, &b) == 2) - { - vecPnts.push_back(CGECurveTexFilter::makeCurvePoint(a / 255.0f, b / 255.0f)); - } - while(i < n && pstr[i] != '\0' && pstr[i] != ')') ++i; - if(pstr[i] != ')') break; - ++i; - } - } - -#define PARSER_TABLE_COMMON_FUNC(vec) \ -{ \ -int n = i; \ -for(char c = toupper(pstr[i]); \ -c != '\0' && c != 'R' && c != 'G' && c != 'B' && c != '@'; c = toupper(pstr[++i])); \ -tableParserHelper(vec, pstr + n, i - n); \ -} - - CGEImageFilterInterface* CGEDataParsingEngine::curveParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) - { - using namespace std; - vector vecR, vecG, vecB, vecRGB; - CGEMoreCurveFilter* proc = g_isFastFilterImpossible ? nullptr : createMoreCurveTexFilter(); - - if(proc == nullptr) - { - CGE_LOG_INFO("curveParser - Curve With Texture is used!(Not error, everything is ok)\n"); - proc = createMoreCurveTexFilter(); - - if(proc == nullptr) - { - CGE_LOG_ERROR("CGEDataParsingEngine::curveParser Create Curve filter Failed!\n"); - return nullptr; - } - } - - for(int i = 0; pstr[i] != '\0' && pstr[i] != '@';) - { - switch (pstr[i]) - { - case 'R': case 'r': - if(toupper(pstr[i + 1]) == 'G' && toupper(pstr[i + 2]) == 'B') - { - vecRGB.clear(); - //RGB - i += 3; - PARSER_TABLE_COMMON_FUNC(vecRGB); - if(vecRGB.size() < 2) - { - CGE_LOG_ERROR("Not enough RGB curve points: %s\n", pstr); - } - else - { - proc->pushPointsRGB(vecRGB.data(), vecRGB.size()); - } - } - else - { - vecR.clear(); - ++i; - int n = i; - for(char c = toupper(pstr[i]); - c != '\0' && c != 'R' && c != 'G' && c != 'B' && c != '@'; c = toupper(pstr[i])) ++i; - tableParserHelper(vecR, pstr + n, i - n); - if(vecR.size() < 2) - { - CGE_LOG_ERROR("Not enough R curve points: %s\n", pstr); - } - else - { - proc->pushPointsR(vecR.data(), vecR.size()); - } - } - break; - case 'G': case 'g': - vecG.clear(); - ++i; - PARSER_TABLE_COMMON_FUNC(vecG); - if(vecG.size() < 2) - { - CGE_LOG_ERROR("Not enough G curve points: %s\n", pstr); - } - else - { - proc->pushPointsG(vecG.data(), vecG.size()); - } - break; - case 'B': case 'b': - vecB.clear(); - ++i; - PARSER_TABLE_COMMON_FUNC(vecB); - if(vecB.size() < 2) - { - CGE_LOG_ERROR("Not enough B curve points: %s\n", pstr); - } - else - { - proc->pushPointsB(vecB.data(), vecB.size()); - } - break; - default: - ++i; - break; - } - } - if(vecRGB.empty() && vecR.empty() && vecG.empty() && vecB.empty()) - { - CGE_LOG_ERROR("curveParser - Empty Curve!!\n"); - delete proc; - return nullptr; - } - - proc->flush(); - if(fatherFilter != nullptr) fatherFilter->addFilter(proc); - return proc; - } - - CGEImageFilterInterface* CGEDataParsingEngine::lomoWithCurveParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) - { - using namespace std; - using namespace CGE; - - float vignetteStart, vignetteEnd, colorScaleLow, colorScaleRange, saturation; - int isLinear = 0; - while(*pstr != '\0' && !isdigit(*pstr)) ++pstr; - if(sscanf(pstr, "%f%*c%f%*c%f%*c%f%*c%f%*c%d", - &vignetteStart, &vignetteEnd, &colorScaleLow, &colorScaleRange, &saturation, &isLinear) < 5) - { - return nullptr; - } - - CGELomoWithCurveFilter* proc = g_isFastFilterImpossible ? nullptr : (isLinear ? new CGELomoWithCurveLinearFilter : new CGELomoWithCurveFilter); - - if(proc == nullptr || !proc->init()) - { - delete proc; - proc = isLinear ? new CGELomoWithCurveTexLinearFilter : new CGELomoWithCurveTexFilter; - if(!proc->init()) - { - CGE_LOG_ERROR("CGEDataParsingEngine::lomoWithCurveParser Create filter Failed!\n"); - delete proc; - return nullptr; - } - CGE_LOG_INFO("lomoWithCurveParser - Curve With Texture is used!(Not error, everything is ok)\n"); - } - proc->setVignette(vignetteStart, vignetteEnd); - proc->setColorScale(colorScaleLow, colorScaleRange); - proc->setSaturation(saturation); - - vector vecR, vecG, vecB, vecRGB; - for(int i = 0; pstr[i] != '\0' && pstr[i] != '@';) - { - switch (pstr[i]) - { - case 'R': case 'r': - if(toupper(pstr[i + 1]) == 'G' && toupper(pstr[i + 2]) == 'B') - { - //RGB - i += 3; - PARSER_TABLE_COMMON_FUNC(vecRGB); - } - else - { - ++i; - int n = i; - for(char c = toupper(pstr[i]); - c != '\0' && c != 'R' && c != 'G' && c != 'B' && c != '@'; c = toupper(pstr[i])) ++i; - tableParserHelper(vecR, pstr + n, i - n); - } - break; - case 'G': case 'g': - ++i; - PARSER_TABLE_COMMON_FUNC(vecG); - break; - case 'B': case 'b': - ++i; - PARSER_TABLE_COMMON_FUNC(vecB); - break; - default: - - ++i; - break; - } - } - - if(vecRGB.empty() && vecR.empty() && vecG.empty() && vecB.empty()) - { - CGE_LOG_ERROR("lomoParser - Warning: Empty Curve!!\n"); - } - - proc->pushPointsRGB(vecRGB.data(), (GLuint)vecRGB.size()); - proc->pushPoints(vecR.data(), (GLuint)vecR.size(), - vecG.data(), (GLuint)vecG.size(), - vecB.data(), (GLuint)vecB.size()); - proc->flush(); - if(fatherFilter != nullptr) fatherFilter->addFilter(proc); - return proc; - } - - CGEImageFilterInterface* CGEDataParsingEngine::lomoParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) - { - using namespace std; - using CGE::CGELomoLinearFilter; - using CGE::CGELomoFilter; - - float vignetteStart, vignetteEnd, colorScaleLow, colorScaleRange, saturation; - int isLinear = 0; - while(*pstr != '\0' && !isdigit(*pstr)) ++pstr; - if(sscanf(pstr, "%f%*c%f%*c%f%*c%f%*c%f%*c%d", - &vignetteStart, &vignetteEnd, &colorScaleLow, &colorScaleRange, &saturation, &isLinear) < 5) - { - return nullptr; - } - CGELomoFilter* proc; - if(isLinear) - proc = new CGELomoLinearFilter; - else proc = new CGELomoFilter; - proc->init(); - proc->setVignette(vignetteStart, vignetteEnd); - proc->setColorScale(colorScaleLow, colorScaleRange); - proc->setSaturation(saturation); - - if(fatherFilter != nullptr) fatherFilter->addFilter(proc); - return proc; - } - -#define ADJUSTHELP_COMMON_FUNC(str, procName, setFunc) \ -do{\ - float intensity;\ - if(sscanf(str, "%f", &intensity) != 1)\ - {\ - LOG_ERROR_PARAM(str);\ - return nullptr;\ - }\ - procName* bp = new procName();\ - if(!bp->init())\ - {\ - delete bp;\ - }\ - else \ - {\ - proc = bp;\ - bp->setFunc(intensity);\ - }\ -}while(0) - -#define ADJUSTHELP_COMMON_FUNC2(str, procName, setFunc1, setFunc2) \ -do{\ - float intensity1, intensity2;\ - if(sscanf(str, "%f%*c%f", &intensity1, &intensity2) != 2)\ - {\ - LOG_ERROR_PARAM(str);\ - return nullptr;\ - }\ - procName* bp = new procName();\ - if(!bp->init())\ - {\ - delete bp;\ - }\ - else \ - {\ - proc = bp;\ - bp->setFunc1(intensity1);\ - bp->setFunc2(intensity2);\ - }\ -}while(0) - -#define ADJUSTHELP_COMMON_FUNC3(str, procName, setFunc1, setFunc2, setFunc3) \ -do{\ - float intensity1, intensity2, intensity3;\ - if(sscanf(str, "%f%*c%f%*c%f", &intensity1, &intensity2, &intensity3) != 3)\ - {\ - LOG_ERROR_PARAM(str);\ - return nullptr;\ - }\ - procName* bp = new procName();\ - if(!bp->init())\ - {\ - delete bp;\ - }\ - else \ - {\ - proc = bp;\ - bp->setFunc1(intensity1);\ - bp->setFunc2(intensity2);\ - bp->setFunc3(intensity3);\ - }\ -}while(0) - -#define ADJUSTHELP_COMMON_FUNC_ARG2(str, procName, setFunc) \ -do{\ - float intensity1, intensity2;\ - if(sscanf(str, "%f%*c%f", &intensity1, &intensity2) != 2)\ - {\ - LOG_ERROR_PARAM(str);\ - return nullptr;\ - }\ - procName* bp = new procName();\ - if(!bp->init())\ - {\ - delete bp;\ - }\ - else \ - {\ - proc = bp;\ - bp->setFunc(intensity1, intensity2);\ - }\ -}while(0) - - CGEImageFilterInterface* CGEDataParsingEngine::adjustParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) - { - while(*pstr != '\0' && (*pstr == ' ' || *pstr == '\t')) ++pstr; - CGEImageFilterInterface* proc = nullptr; - - //2015-1-29 隐患fix, 将下一条指令直接取出再进行判断 - char buffer[128], *pBuffer = buffer; - - while(*pstr != '\0' && !isspace(*pstr) && (pBuffer - buffer) < sizeof(buffer)) - { - *pBuffer++ = *pstr++; - } - - *pBuffer = '\0'; - - //Hardcode for all basic adjusts. - if(strcmp(buffer, "brightness") == 0) - { - float intensity; - if(sscanf(pstr, "%f", &intensity) != 1) - return nullptr; - CGEBrightnessFastFilter* bfp = g_isFastFilterImpossible ? nullptr : createBrightnessFastFilter(); - CGEBrightnessFilter* bp = (bfp == nullptr) ? createBrightnessFilter() : nullptr; - - if(bfp != nullptr) - { - bfp->setIntensity(intensity); - proc = bfp; - } - else if(bp != nullptr) - { - bp->setIntensity(intensity); - proc = bp; - } - else - { - CGE_LOG_ERROR("CGEDataParsingEngine::adjustParser Create Brightness filter Failed\n"); - return nullptr; - } - } - else if(strcmp(buffer, "contrast") == 0) - { - ADJUSTHELP_COMMON_FUNC(pstr, CGEContrastFilter, setIntensity); - } - else if(strcmp(buffer, "saturation") == 0) - { - ADJUSTHELP_COMMON_FUNC(pstr, CGESaturationFilter, setIntensity); - } - else if(strcmp(buffer, "sharpen") == 0) - { - ADJUSTHELP_COMMON_FUNC(pstr, CGESharpenBlurSimpleBetterFilter, setSharpenIntensity); - } - else if(strcmp(buffer, "blur") == 0) - { - ADJUSTHELP_COMMON_FUNC(pstr, CGESharpenBlurSimpleBetterFilter, setBlurIntensity); - } - else if(strcmp(buffer, "whitebalance") == 0) - { - float temp, tint; - if(sscanf(pstr, "%f%*c%f", &temp, &tint) != 2) - { - LOG_ERROR_PARAM(pstr); - return nullptr; - } - CGEWhiteBalanceFastFilter* wfp = g_isFastFilterImpossible ? nullptr : createWhiteBalanceFastFilter(); - CGEWhiteBalanceFilter* wp = (wfp == nullptr) ? createWhiteBalanceFilter() : nullptr; - if(wfp != nullptr) - { - wfp->setTempAndTint(temp, tint); - proc = wfp; - } - else if(wp != nullptr) - { - wp->setTemperature(temp); - wp->setTint(tint); - proc = wp; - } - else - { - CGE_LOG_ERROR("CGEDataParsingEngine::adjustParser Create WhiteBalance filter Failed\n"); - return nullptr; - } - } - else if(strcmp(buffer, "monochrome") == 0) - { - float arg[6]; - if(sscanf(pstr, "%f%*c%f%*c%f%*c%f%*c%f%*c%f", - arg, arg+1, arg+2, arg+3, arg+4, arg+5) != 6) - { - CGE_LOG_ERROR("adjust hsv - Invalid Parameters: %s\n", pstr); - return nullptr; - } - CGEMonochromeFilter* monoProc = new CGEMonochromeFilter; - if(!monoProc->init()) - { - delete monoProc; - return nullptr; - } - else - { - proc = monoProc; - monoProc->setRed(arg[0]); - monoProc->setGreen(arg[1]); - monoProc->setBlue(arg[2]); - monoProc->setCyan(arg[3]); - monoProc->setMagenta(arg[4]); - monoProc->setYellow(arg[5]); - } - } - else if(strcmp(buffer, "shl") == 0 || strcmp(buffer, "shadowhighlight") == 0) - { - float shadow, highlight; - if(sscanf(pstr, "%f%*c%f", &shadow, &highlight) != 2) - { - LOG_ERROR_PARAM(pstr); - return nullptr; - } - CGEShadowHighlightFastFilter* shfp = g_isFastFilterImpossible ? nullptr : createShadowHighlightFastFilter(); - CGEShadowHighlightFilter* shp = (shfp == nullptr) ? createShadowHighlightFilter() : nullptr; - if(shfp != nullptr) - { - shfp->setShadowAndHighlight(shadow, highlight); - proc = shfp; - } - else if(shp != nullptr) - { - shp->setShadow(shadow); - shp->setHighlight(highlight); - proc = shp; - } - else - { - CGE_LOG_ERROR("CGEDataParsingEngine::adjustParser Create ShadowHighlight filter Failed\n"); - return nullptr; - } - } - else if(strcmp(buffer, "hsv") == 0) - { - float arg[6]; - if(sscanf(pstr, "%f%*c%f%*c%f%*c%f%*c%f%*c%f", - arg, arg+1, arg+2, arg+3, arg+4, arg+5) != 6) - { - CGE_LOG_ERROR("adjust hsv - Invalid Parameters: %s\n", pstr); - return nullptr; - } - CGESaturationHSVFilter* hsvProc = new CGESaturationHSVFilter; - if(!hsvProc->init()) - { - delete hsvProc; - return nullptr; - } - else - { - proc = hsvProc; - hsvProc->setAdjustColors(arg[0], arg[1], arg[2], arg[3], arg[4], arg[5]); - } - } - else if(strcmp(buffer, "hsl") == 0) - { - float h, s, l; - if(sscanf(pstr, "%f%*c%f%*c%f", &h, &s, &l) != 3) - { - CGE_LOG_ERROR("adjust hsl - Invalid Parameters: %s\n", pstr); - return nullptr; - } - CGESaturationHSLFilter* hslProc = createSaturationHSLFilter(); - proc = hslProc; - if(hslProc != nullptr) - { - hslProc->setHue(h); - hslProc->setSaturation(s); - hslProc->setLum(l); - } - } - else if(strcmp(buffer, "level") == 0) - { - float dark, light, gamma; - if(sscanf(pstr, "%f%*c%f%*c%f", &dark, &light, &gamma) != 3) - { - CGE_LOG_ERROR("adjust color level - Invalid Parameters: %s\n", pstr); - return nullptr; - } - CGEColorLevelFilter* levelProc = createColorLevelFilter(); - proc = levelProc; - if(levelProc != nullptr) - { - levelProc->setLevel(dark, light); - levelProc->setGamma(gamma); - } - } - else if(strcmp(buffer, "exposure") == 0) - { - ADJUSTHELP_COMMON_FUNC(pstr, CGEExposureFilter, setIntensity); - } - else if(strcmp(buffer, "hue") == 0) - { - ADJUSTHELP_COMMON_FUNC(pstr, CGEHueAdjustFilter, setHue); - } - else if(strcmp(buffer, "colorbalance") == 0) - { - float red, green, blue; - if(sscanf(pstr, "%f%*c%f%*c%f", &red, &green, &blue) != 3) - { - LOG_ERROR_PARAM(pstr); - return nullptr; - } - - CGEColorBalanceFilter* filter = createColorBalanceFilter(); - - if(filter != nullptr) - { - proc = filter; - filter->setRedShift(red); - filter->setGreenShift(green); - filter->setBlueShift(blue); - } - else - { - CGE_LOG_ERROR("CGEDataParsingEngine::adjustParser Create ColorBalance filter Failed\n"); - return nullptr; - } - } - else if(strcmp(buffer, "lut") == 0) - { - char lutName[128]; - float intensity = 1.0f; - int paramCount = sscanf(pstr, "%127s%f", lutName, &intensity); - if(paramCount < 1) - { - LOG_ERROR_PARAM(pstr); - return nullptr; - } - - CGELookupFilter* filter = createLookupFilter(); - GLuint tex = fatherFilter->loadResources(lutName); - if(filter != nullptr && tex != 0) - { - filter->setLookupTexture(tex); - proc = filter; - - if(paramCount == 2) - { // has intensity - filter->setIntensity(intensity); - } - } - else - { - delete filter; - glDeleteTextures(1, &tex); - CGE_LOG_ERROR("CGEDataParsingEngine::adjustParser Create Lookup filter Failed\n"); - } - } - else - { - LOG_ERROR_PARAM(pstr); - return nullptr; - } - - if(fatherFilter != nullptr) fatherFilter->addFilter(proc); - return proc; - } - - CGEImageFilterInterface* CGEDataParsingEngine::blendParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) - { - using namespace CGE; - char modeName[32], textureName[128]; - int intensity; - - if(sscanf(pstr, "%31s%127s%d", modeName, textureName, &intensity) != 3) - { - CGE_LOG_ERROR("blendParser - Invalid Param: %s\n", pstr); - return nullptr; - } - CGEBlendWithResourceFilter* proc = new CGEBlendWithResourceFilter; - - if(!proc->initWithMode(modeName)) - { - delete proc; - return nullptr; - } - - int texWidth, texHeight; - GLuint texID = 0; - - if(sscanf(textureName, "[%d%*c%d%*c%d]", &texID, &texWidth, &texHeight) != 3 || texID == 0) - { - texID = fatherFilter->loadResources(textureName, &texWidth, &texHeight); - } - CGE_LOG_CODE - ( - else - { - if(!glIsTexture(texID)) - { - CGE_LOG_ERROR("Warn: special usage with texture id, but the texture id is not valid now."); - } - } - ) - - if(texID == 0) - { - CGE_LOG_ERROR("blend - %s : loadResources failed: %s\n", modeName, textureName); - delete proc; - return nullptr; - } - - proc->setSamplerID(texID); - proc->setTexSize(texWidth, texHeight); - proc->setIntensity(intensity / 100.0f); - - if(fatherFilter != nullptr) fatherFilter->addFilter(proc); - return proc; - } - - CGEImageFilterInterface* CGEDataParsingEngine::vignetteBlendParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) - { - using namespace CGE; - char blendMethod[BUFFER_LEN]; - float color[4], intensity; - float low, range, centerX, centerY; - int kind = 0; - - if(sscanf(pstr, "%" BUFFER_LEN_STR "s%f%f%f%f%f%f%f%f%f%d", blendMethod, color, color + 1, color + 2, color + 3, &intensity, &low, &range, ¢erX, ¢erY, &kind) < 10) - { - CGE_LOG_ERROR("vignetteBlendParser - Invalid parameters: %s\n", pstr); - return nullptr; - } - - CGEBlendVignetteFilter* proc = nullptr; - switch(kind) - { - case 0: - proc = new CGEBlendVignetteNoAlphaFilter; - break; - case 1: - proc = new CGEBlendVignetteFilter; - break; - case 2: - proc = new CGEBlendVignette2NoAlphaFilter; - break; - case 3: - proc = new CGEBlendVignette2Filter; - break; - default: - CGE_LOG_ERROR("vignetteBlendParser - Invalid vignette kind %d", kind); - return nullptr; - } - - if(!CGEBlendInterface::initWithModeName(blendMethod, proc)) - { - delete proc; - return nullptr; - } - - proc->setVignette(low, range); - proc->setVignetteCenter(centerX, centerY); - - if(color[3] > 1.00001f) //判断值域范围为0~1还是0~255并进行相应处理。 - { - color[0] /= 255.0f; - color[1] /= 255.0f; - color[2] /= 255.0f; - color[3] /= 255.0f; - } - proc->setBlendColor(color[0], color[1], color[2], color[3]); - proc->setIntensity(intensity / 100.0f); - - if(fatherFilter != nullptr) fatherFilter->addFilter(proc); - return proc; - } - - ////////////////////////////////////////////////////////////////////////// - - CGEImageFilterInterface* CGEDataParsingEngine::colorScaleParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) - { - using namespace CGE; - float low, range, sat; - if(sscanf(pstr, "%f%*c%f%*c%f", &low, &range, &sat) != 3) - { - CGE_LOG_ERROR("colorScaleParser - Invalid Parameters: %s\n", pstr); - return nullptr; - } - CGEColorScaleFilter* proc = new CGEColorScaleFilter; - if(!proc->init()) - { - delete proc; - return nullptr; - } - proc->setColorScale(low, range); - proc->setSaturation(sat); - if(fatherFilter != nullptr) fatherFilter->addFilter(proc); - return proc; - } - - CGEImageFilterInterface* CGEDataParsingEngine::pixblendParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) - { - using namespace CGE; - char blendMethod[BUFFER_LEN]; - float color[4], intensity; - - if(sscanf(pstr, "%" BUFFER_LEN_STR "s%f%f%f%f%f", blendMethod, color, color + 1, color + 2, color + 3, &intensity) != 6) - { - CGE_LOG_ERROR("pixblendParser - Invalid parameters: %s\n", pstr); - return nullptr; - } - - CGEPixblendFilter* proc = new CGEPixblendFilter; - if(!proc->initWithMode(blendMethod)) - { - delete proc; - return nullptr; - } - - if(color[3] > 1.00001f) //判断值域范围为0~1还是0~255并进行相应处理。 - { - color[0] /= 255.0f; - color[1] /= 255.0f; - color[2] /= 255.0f; - color[3] /= 255.0f; - } - proc->setBlendColor(color[0], color[1], color[2], color[3]); - proc->setIntensity(intensity / 100.0f); - - if(fatherFilter != nullptr) fatherFilter->addFilter(proc); - return proc; - } - - CGEImageFilterInterface* CGEDataParsingEngine::krblendParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) - { - using namespace CGE; - char modeName[32], textureName[128]; - int intensity; - if(sscanf(pstr, "%31s%127s%d", modeName, textureName, &intensity) != 3) - { - CGE_LOG_ERROR("krblendParser - Invalid Param: %s\n", pstr); - return nullptr; - } - - CGEBlendKeepRatioFilter* proc = new CGEBlendKeepRatioFilter; - if(!proc->initWithMode(modeName)) - { - delete proc; - return nullptr; - } - - int texWidth, texHeight; - GLuint texID; - - if(sscanf(textureName, "[%d%*c%d%*c%d]", &texID, &texWidth, &texHeight) != 3 || texID == 0) - { - texID = fatherFilter->loadResources(textureName, &texWidth, &texHeight); - } - CGE_LOG_CODE - ( - else - { - if(!glIsTexture(texID)) - { - CGE_LOG_ERROR("Warn: special usage with texture id, but the texture id is not valid now."); - } - } - ) - - if(texID == 0) - { - CGE_LOG_ERROR("blend - %s : loadResources failed: %s\n", modeName, textureName); - delete proc; - return nullptr; - } - - proc->setSamplerID(texID); - proc->setTexSize(texWidth, texHeight); - proc->setIntensity(intensity / 100.0f); - - if(fatherFilter != nullptr) fatherFilter->addFilter(proc); - return proc; - } - - CGEImageFilterInterface* CGEDataParsingEngine::vignetteParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) - { - float low, range, centerX, centerY; - int n = sscanf(pstr, "%f%*c%f%*c%f%*c%f", &low, &range, ¢erX, ¢erY); - if(n < 2) - { - CGE_LOG_ERROR("vignetteParser - Invalid Param: %s\n", pstr); - return nullptr; - } - - CGEVignetteFilter* proc = new CGEVignetteFilter; - if(!proc->init()) - { - delete proc; - return nullptr; - } - - proc->setVignette(low, range); - if(n == 4) proc->setVignetteCenter(centerX, centerY); - if(fatherFilter != nullptr) fatherFilter->addFilter(proc); - return proc; - } - - CGEImageFilterInterface* CGEDataParsingEngine::selfblendParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) - { - using namespace CGE; - char modeName[32]; - int intensity; - if(sscanf(pstr, "%31s%d", modeName, &intensity) != 2) - { - CGE_LOG_ERROR("selfblendParser - Invalid Param: %s\n", pstr); - return nullptr; - } - - CGEBlendWithSelfFilter* proc = new CGEBlendWithSelfFilter; - if(!proc->initWithMode(modeName)) - { - delete proc; - return nullptr; - } - proc->setIntensity(intensity / 100.0f); - if(fatherFilter != nullptr) fatherFilter->addFilter(proc); - return proc; - } - - CGEImageFilterInterface* CGEDataParsingEngine::colorMulParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) - { - using namespace CGE; - char funcName[32] = ""; - if(sscanf(pstr,"%31s", funcName) != 1) - { - CGE_LOG_ERROR("colorMulParser - Invalid Param: %s", pstr); - return nullptr; - } - - CGEColorMulFilter* proc = nullptr; - if(strncmp(funcName, "flt", 3) == 0) - { - float value; - if(sscanf(pstr, "%*s%f", &value) != 1) - { - CGE_LOG_ERROR("colorMulParser - flt - Invalid Param:%s\n", pstr); - return nullptr; - } - proc = new CGEColorMulFilter; - proc->initWithMode(CGEColorMulFilter::mulFLT); - proc->setFLT(value); - } - else if(strncmp(funcName, "vec", 3) == 0) - { - float r, g, b; - if(sscanf(pstr, "%*s%f%*c%f%*c%f", &r, &g, &b) != 3) - { - CGE_LOG_ERROR("colorMulParser - vec - Invalid Param:%s\n", pstr); - return nullptr; - } - proc = new CGEColorMulFilter; - proc->initWithMode(CGEColorMulFilter::mulVEC); - proc->setVEC(r, g, b); - } - else if(strncmp(funcName, "mat", 3) == 0) - { - float mat[9]; - if(sscanf(pstr, "%*s%f%*c%f%*c%f%*c%f%*c%f%*c%f%*c%f%*c%f%*c%f", - mat, mat + 1, mat + 2, mat + 3, mat + 4, mat + 5, mat + 6, mat + 7, mat + 8) != 9) - { - CGE_LOG_ERROR("colorMulParser - mat - Invalid Param:%s\n", pstr); - return nullptr; - } - proc = new CGEColorMulFilter; - proc->initWithMode(CGEColorMulFilter::mulMAT); - proc->setMAT(mat); - } - else - { - CGE_LOG_ERROR("colorMulParser - Invalid Param:%s\n", pstr); - return nullptr; - } - - if(fatherFilter != nullptr) fatherFilter->addFilter(proc); - return proc; - } - - CGEImageFilterInterface* CGEDataParsingEngine::selectiveColorParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) - { - CGESelectiveColorFilter* proc = createSelectiveColorFilter(); - if(proc == nullptr) - { - CGE_LOG_ERROR("selectiveColorParser - init processor failed!\n"); - return nullptr; - } - - while(pstr != nullptr && *pstr != '\0' && *pstr != '@') - { - char funcName[32]; - float cyan, magenta, yellow, key; - while(*pstr != '\0' && (isspace(*pstr) || *pstr == ',')) ++pstr; - if(*pstr == '\0' || *pstr == '@') - break; - if(sscanf(pstr, "%31[^( \t\n]%*[^-0-9.]%f%*c%f%*c%f%*c%f", funcName, &cyan, &magenta, &yellow, &key) != 5) - { - CGE_LOG_ERROR("selectiveColorParser - Invalid Param %s!\n", pstr); - break; - } - - while(*pstr != '\0' && *pstr++ != ')') ; - - if(fabsf(cyan) > 1.0f || fabsf(magenta) > 1.0f || fabsf(yellow) > 1.0f || fabsf(key) > 1.0f) - { - cyan /= 100.0f; - magenta /= 100.0f; - yellow /= 100.0f; - key /= 100.0f; - } - - if(strcmp(funcName, "red") == 0) - { - proc->setRed(cyan, magenta, yellow, key); - } - else if(strcmp(funcName, "green") == 0) - { - proc->setGreen(cyan, magenta, yellow, key); - } - else if(strcmp(funcName, "blue") == 0) - { - proc->setBlue(cyan, magenta, yellow, key); - } - else if(strcmp(funcName, "cyan") == 0) - { - proc->setCyan(cyan, magenta, yellow, key); - } - else if(strcmp(funcName, "magenta") == 0) - { - proc->setMagenta(cyan, magenta, yellow, key); - } - else if(strcmp(funcName, "yellow") == 0) - { - proc->setYellow(cyan, magenta, yellow, key); - } - else if(strcmp(funcName, "white") == 0) - { - proc->setWhite(cyan, magenta, yellow, key); - } - else if(strcmp(funcName, "gray") == 0) - { - proc->setGray(cyan, magenta, yellow, key); - } - else if(strcmp(funcName, "black") == 0) - { - proc->setBlack(cyan, magenta, yellow, key); - } - else - { - CGE_LOG_ERROR("Unknown funcName: %s!\n", funcName); - } - } - - if(fatherFilter != nullptr) fatherFilter->addFilter(proc); - return proc; - } - - CGEImageFilterInterface* CGEDataParsingEngine::blendTileParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) - { - char modeName[32], textureName[128]; - int intensity; - - if(sscanf(pstr, "%31s%127s%d", modeName, textureName, &intensity) != 3) - { - CGE_LOG_ERROR("blendTileParser - Invalid Param: %s\n", pstr); - return nullptr; - } - CGEBlendTileFilter* proc = new CGEBlendTileFilter; - - if(!proc->initWithMode(modeName)) - { - delete proc; - return nullptr; - } - - int texWidth, texHeight; - GLuint texID; - - if(sscanf(textureName, "[%d%*c%d%*c%d]", &texID, &texWidth, &texHeight) != 3 || texID == 0) - { - texID = fatherFilter->loadResources(textureName, &texWidth, &texHeight); - } - CGE_LOG_CODE - ( - else - { - if(!glIsTexture(texID)) - { - CGE_LOG_ERROR("Warn: special usage with texture id, but the texture id is not valid now."); - } - } - ) - - if(texID == 0) - { - CGE_LOG_ERROR("blend - %s : loadResources failed: %s\n", modeName, textureName); - delete proc; - return nullptr; - } - - proc->setSamplerID(texID); - proc->setTexSize(texWidth, texHeight); - proc->setIntensity(intensity / 100.0f); - - if(fatherFilter != nullptr) fatherFilter->addFilter(proc); - return proc; - } - - CGEImageFilterInterface* CGEDataParsingEngine::advancedStyleParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) - { - while(*pstr != '\0' && (*pstr == ' ' || *pstr == '\t')) ++pstr; - CGEImageFilterInterface* proc = nullptr; - - //2015-1-29 隐患fix, 将下一条指令直接取出再进行判断 - char buffer[128], *pBuffer = buffer; - - while(*pstr != '\0' && !isspace(*pstr) && (pBuffer - buffer) < sizeof(buffer)) - { - *pBuffer++ = *pstr++; - } - - *pBuffer = '\0'; - - //Hardcode for all basic adjusts. - if(strcmp(buffer, "crosshatch") == 0) - { - ADJUSTHELP_COMMON_FUNC2(pstr, CGECrosshatchFilter, setCrosshatchSpacing, setLineWidth); - } - else if(strcmp(buffer, "edge") == 0) - { - ADJUSTHELP_COMMON_FUNC2(pstr, CGEEdgeSobelFilter, setIntensity, setStride); - } - else if(strcmp(buffer, "emboss") == 0) - { - ADJUSTHELP_COMMON_FUNC3(pstr, CGEEmbossFilter, setIntensity, setStride, setAngle); - } - else if(strcmp(buffer, "halftone") == 0) - { - ADJUSTHELP_COMMON_FUNC(pstr, CGEHalftoneFilter, setDotSize); - } - else if(strcmp(buffer, "haze") == 0) - { - float dis, slope, r, g, b; - if(sscanf(pstr, "%f%*c%f%*c%f%*c%f%*c%f", &dis, &slope, &r, &g, &b) != 5) - { - LOG_ERROR_PARAM(pstr); - return nullptr; - } - CGEHazeFilter* filter = createHazeFilter(); - if(filter != nullptr) - { - proc = filter; - filter->setDistance(dis); - filter->setSlope(slope); - filter->setHazeColor(r, g, b); - } - } - else if(strcmp(buffer, "polkadot") == 0) - { - ADJUSTHELP_COMMON_FUNC(pstr, CGEPolkaDotFilter, setDotScaling); - } - else if(strcmp(buffer, "sketch") == 0) - { - ADJUSTHELP_COMMON_FUNC(pstr, CGESketchFilter, setIntensity); - } - else if(strcmp(buffer, "max") == 0) - { - proc = new CGEMaxValueFilter3x3(); - if(!proc->init()) - { - delete proc; - proc = nullptr; - } - } - else if(strcmp(buffer, "min") == 0) - { - proc = new CGEMinValueFilter3x3(); - if(!proc->init()) - { - delete proc; - proc = nullptr; - } - } - else if(strcmp(buffer, "mid") == 0) - { - CGE_LOG_ERROR("中值濾波暂无"); - return nullptr; - } - else if(strcmp(buffer, "cm") == 0 || strcmp(buffer, "colorMapping") == 0) - { - char filename[128]; - int mappingWidth, mappingHeight, unitWidth, unitHeight; - if(sscanf(pstr, "%127s%*c%d%*c%d%*c%d%*c%d", filename, &mappingWidth, &mappingHeight, &unitWidth, &unitHeight) != 5) - { - LOG_ERROR_PARAM(buffer); - return nullptr; - } - - int w, h; - GLuint texID = fatherFilter->loadResources(filename, &w, &h); - - if(texID == 0) - { - CGE_LOG_ERROR("Load texture %s failed!\n", filename); - return nullptr; - } - - CGEColorMappingFilter* filter = CGEColorMappingFilter::createWithMode(CGEColorMappingFilter::MAPINGMODE_DEFAULT); - - float weight = 0.0f; - - for(int i = 0; i != unitHeight; ++i) - { - for(int j = 0; j != unitWidth; ++j) - { - CGEColorMappingFilter::MappingArea ma = { - Vec4f(j / (float)unitWidth, i / (float)unitHeight, 1.0f / unitWidth, 1.0f / unitHeight), - weight - }; - - weight += 1.0f / (unitWidth * unitHeight - 1); - - filter->pushMapingArea(ma); - } - } - - filter->endPushing(); - filter->setupMapping(texID, w, h, mappingWidth, mappingHeight); - - proc = filter; - } - else - { - LOG_ERROR_PARAM(pstr); - return nullptr; - } - - if(fatherFilter != nullptr) fatherFilter->addFilter(proc); - return proc; - } - - CGEImageFilterInterface* CGEDataParsingEngine::beautifyParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) - { - while(*pstr != '\0' && (*pstr == ' ' || *pstr == '\t')) ++pstr; - CGEImageFilterInterface* proc = nullptr; - - char buffer[128], *pBuffer = buffer; - - while(*pstr != '\0' && !isspace(*pstr) && (pBuffer - buffer) < sizeof(buffer)) - { - *pBuffer++ = *pstr++; - } - - *pBuffer = '\0'; - - //Hardcode for all basic adjusts. - if(strcmp(buffer, "bilateral") == 0) - { - float blurScale, disFactor; - int repeatTimes = 1; - if(sscanf(pstr, "%f%*c%f%*c%d", &blurScale, &disFactor, &repeatTimes) < 2) - { - LOG_ERROR_PARAM(pstr); - return nullptr; - } - - CGEBilateralWrapperFilter* filter = new CGEBilateralWrapperFilter; - if(filter->init()) - { - proc = filter; - filter->setBlurScale(blurScale); - filter->setDistanceNormalizationFactor(disFactor); - filter->setRepeatTimes(repeatTimes); - } - else - { - LOG_ERROR_PARAM(pstr); - delete filter; - } - - } - else if(strcmp(buffer, "face") == 0) - { - float intensity, width = -1.0f, height = -1.0f; - if(sscanf(pstr, "%f%*c%f%*c%f", &intensity, &width, &height) < 1) - { - LOG_ERROR_PARAM(pstr); - return nullptr; - } - - CGEBeautifyFilter* filter = createBeautifyFilter(); - if(filter != nullptr) - { - proc = filter; - filter->setIntensity(intensity); - if(width > 0.0f && height > 0.0f) - { - filter->setImageSize(width, height); - } - } - } - - else - { - LOG_ERROR_PARAM(pstr); - return nullptr; - } - - if(fatherFilter != nullptr) fatherFilter->addFilter(proc); - return proc; - } - - CGEImageFilterInterface* CGEDataParsingEngine::blurParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) - { - while(*pstr != '\0' && (*pstr == ' ' || *pstr == '\t')) ++pstr; - CGEImageFilterInterface* proc = nullptr; - - char buffer[128], *pBuffer = buffer; - - while(*pstr != '\0' && !isspace(*pstr) && (pBuffer - buffer) < sizeof(buffer)) - { - *pBuffer++ = *pstr++; - } - - *pBuffer = '\0'; - - //Hardcode for all basic adjusts. - if(strcmp(buffer, "lerp") == 0) - { - float intensity, base; - int argNum; - if((argNum = sscanf(pstr, "%f%*c%f", &intensity, &base)) < 1) - { - LOG_ERROR_PARAM(pstr); - return nullptr; - } - - auto* filter = createLerpblurFilter(); - - if(filter != nullptr) - { - proc = filter; - if(argNum == 2) - { - filter->setBlurLevel(intensity * CGELerpblurFilter::MAX_LERP_BLUR_INTENSITY); - filter->setMipmapBase(base); - } - else - { - filter->setIntensity(intensity); - } - } - } - - else - { - LOG_ERROR_PARAM(pstr); - return nullptr; - } - - if(fatherFilter != nullptr) fatherFilter->addFilter(proc); - return proc; - } - - CGEImageFilterInterface* CGEDataParsingEngine::dynamicParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) - { - while(*pstr != '\0' && (*pstr == ' ' || *pstr == '\t')) ++pstr; - CGEImageFilterInterface* proc = nullptr; - - char buffer[128], *pBuffer = buffer; - - while(*pstr != '\0' && !isspace(*pstr) && (pBuffer - buffer) < sizeof(buffer)) - { - *pBuffer++ = tolower(*pstr++); - } - - *pBuffer = '\0'; - - //Hardcode for all basic adjusts. - if(strcmp(buffer, "wave") == 0) - { - float motion, angle, strength, motionSpeed; - int argNum = sscanf(pstr, "%f%*c%f%*c%f%*c%f", &motion, &angle, &strength, &motionSpeed); - - if(!(argNum == 3 || argNum == 4 || (argNum == 1 && motion > 0))) - { - LOG_ERROR_PARAM(pstr); - return nullptr; - } - - auto* filter = createDynamicWaveFilter(); - - if(filter != nullptr) - { - proc = filter; - - switch (argNum) - { - case 1: - filter->setAutoMotionSpeed(motion); - break; - case 3: - filter->setWaveMotion(motion); - filter->setWaveAngle(angle); - filter->setStrength(strength); - break; - case 4: - filter->setAutoMotionSpeed(motionSpeed); - filter->setWaveAngle(angle); - filter->setStrength(strength); - filter->setWaveMotion(motion); - break; - default: - CGE_LOG_ERROR("Error which should never happen, but just happened... biu biu...\n"); - delete filter; - break; - } - } - } - else if(strcmp(buffer, "mf") == 0 || strcmp(buffer, "motionflow") == 0) - { - int totalFrames, framesDelay; - if(sscanf(pstr, "%d%*c%d", &totalFrames, &framesDelay) != 2) - { - LOG_ERROR_PARAM(pstr); - return nullptr; - } - - auto* filter = createMotionFlowFilter(); - if(filter != nullptr) - { - proc = filter; - filter->setTotalFrames(totalFrames); - filter->setFrameDelay(framesDelay); - } - } - else - { - LOG_ERROR_PARAM(pstr); - return nullptr; - } - - if(fatherFilter != nullptr) fatherFilter->addFilter(proc); - return proc; - } - - -} - +/* +* cgeMultipleEffects.cpp +* +* Created on: 2013-12-13 +* Author: Wang Yang +* Mail: admin@wysaid.org +*/ + +#include "cgeDataParsingEngine.h" +#include "cgeMultipleEffectsCommon.h" +#include "cgeAdvancedEffects.h" +#include "cgeBlendFilter.h" +#include "cgeFilterBasic.h" +#include "cgeDynamicFilters.h" +#include "cgeColorMappingFilter.h" + +#include +#include +#include + +//为了加快处理速度,使用固定大小的buffer来存储Parser所需参数。 +//每个method后面的参数长度都不应该超过BUFFER_LEN。 +//如果你的Parser所需参数超过此长度,请将BUFFER_LEN增加到合适的长度。 +#define BUFFER_LEN 1024 +#define BUFFER_LEN_STR "1023" + +#define LOG_ERROR_PARAM(arg) CGE_LOG_ERROR("Invalid Parameters: %s\n", arg); + +namespace CGE +{ + extern bool g_isFastFilterImpossible; + + void tableParserHelper(std::vector& vecPnts, const char* pstr, int n) + { + const char* p = pstr; + int a, b; + + for(int i = 0; i < n;) + { + while(i < n && pstr[i] != '\0' && pstr[i] != '(') ++i; + if(pstr[i] != '(') break; + p = pstr + i + 1; + if(sscanf(p, "%d%*c%d", &a, &b) == 2) + { + vecPnts.push_back(CGECurveTexFilter::makeCurvePoint(a / 255.0f, b / 255.0f)); + } + while(i < n && pstr[i] != '\0' && pstr[i] != ')') ++i; + if(pstr[i] != ')') break; + ++i; + } + } + +#define PARSER_TABLE_COMMON_FUNC(vec) \ +{ \ +int n = i; \ +for(char c = toupper(pstr[i]); \ +c != '\0' && c != 'R' && c != 'G' && c != 'B' && c != '@'; c = toupper(pstr[++i])); \ +tableParserHelper(vec, pstr + n, i - n); \ +} + + CGEImageFilterInterface* CGEDataParsingEngine::curveParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) + { + using namespace std; + vector vecR, vecG, vecB, vecRGB; + CGEMoreCurveFilter* proc = g_isFastFilterImpossible ? nullptr : createMoreCurveTexFilter(); + + if(proc == nullptr) + { + CGE_LOG_INFO("curveParser - Curve With Texture is used!(Not error, everything is ok)\n"); + proc = createMoreCurveTexFilter(); + + if(proc == nullptr) + { + CGE_LOG_ERROR("CGEDataParsingEngine::curveParser Create Curve filter Failed!\n"); + return nullptr; + } + } + + for(int i = 0; pstr[i] != '\0' && pstr[i] != '@';) + { + switch (pstr[i]) + { + case 'R': case 'r': + if(toupper(pstr[i + 1]) == 'G' && toupper(pstr[i + 2]) == 'B') + { + vecRGB.clear(); + //RGB + i += 3; + PARSER_TABLE_COMMON_FUNC(vecRGB); + if(vecRGB.size() < 2) + { + CGE_LOG_ERROR("Not enough RGB curve points: %s\n", pstr); + } + else + { + proc->pushPointsRGB(vecRGB.data(), vecRGB.size()); + } + } + else + { + vecR.clear(); + ++i; + int n = i; + for(char c = toupper(pstr[i]); + c != '\0' && c != 'R' && c != 'G' && c != 'B' && c != '@'; c = toupper(pstr[i])) ++i; + tableParserHelper(vecR, pstr + n, i - n); + if(vecR.size() < 2) + { + CGE_LOG_ERROR("Not enough R curve points: %s\n", pstr); + } + else + { + proc->pushPointsR(vecR.data(), vecR.size()); + } + } + break; + case 'G': case 'g': + vecG.clear(); + ++i; + PARSER_TABLE_COMMON_FUNC(vecG); + if(vecG.size() < 2) + { + CGE_LOG_ERROR("Not enough G curve points: %s\n", pstr); + } + else + { + proc->pushPointsG(vecG.data(), vecG.size()); + } + break; + case 'B': case 'b': + vecB.clear(); + ++i; + PARSER_TABLE_COMMON_FUNC(vecB); + if(vecB.size() < 2) + { + CGE_LOG_ERROR("Not enough B curve points: %s\n", pstr); + } + else + { + proc->pushPointsB(vecB.data(), vecB.size()); + } + break; + default: + ++i; + break; + } + } + if(vecRGB.empty() && vecR.empty() && vecG.empty() && vecB.empty()) + { + CGE_LOG_ERROR("curveParser - Empty Curve!!\n"); + delete proc; + return nullptr; + } + + proc->flush(); + if(fatherFilter != nullptr) fatherFilter->addFilter(proc); + return proc; + } + + CGEImageFilterInterface* CGEDataParsingEngine::lomoWithCurveParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) + { + using namespace std; + using namespace CGE; + + float vignetteStart, vignetteEnd, colorScaleLow, colorScaleRange, saturation; + int isLinear = 0; + while(*pstr != '\0' && !isdigit(*pstr)) ++pstr; + if(sscanf(pstr, "%f%*c%f%*c%f%*c%f%*c%f%*c%d", + &vignetteStart, &vignetteEnd, &colorScaleLow, &colorScaleRange, &saturation, &isLinear) < 5) + { + return nullptr; + } + + CGELomoWithCurveFilter* proc = g_isFastFilterImpossible ? nullptr : (isLinear ? new CGELomoWithCurveLinearFilter : new CGELomoWithCurveFilter); + + if(proc == nullptr || !proc->init()) + { + delete proc; + proc = isLinear ? new CGELomoWithCurveTexLinearFilter : new CGELomoWithCurveTexFilter; + if(!proc->init()) + { + CGE_LOG_ERROR("CGEDataParsingEngine::lomoWithCurveParser Create filter Failed!\n"); + delete proc; + return nullptr; + } + CGE_LOG_INFO("lomoWithCurveParser - Curve With Texture is used!(Not error, everything is ok)\n"); + } + proc->setVignette(vignetteStart, vignetteEnd); + proc->setColorScale(colorScaleLow, colorScaleRange); + proc->setSaturation(saturation); + + vector vecR, vecG, vecB, vecRGB; + for(int i = 0; pstr[i] != '\0' && pstr[i] != '@';) + { + switch (pstr[i]) + { + case 'R': case 'r': + if(toupper(pstr[i + 1]) == 'G' && toupper(pstr[i + 2]) == 'B') + { + //RGB + i += 3; + PARSER_TABLE_COMMON_FUNC(vecRGB); + } + else + { + ++i; + int n = i; + for(char c = toupper(pstr[i]); + c != '\0' && c != 'R' && c != 'G' && c != 'B' && c != '@'; c = toupper(pstr[i])) ++i; + tableParserHelper(vecR, pstr + n, i - n); + } + break; + case 'G': case 'g': + ++i; + PARSER_TABLE_COMMON_FUNC(vecG); + break; + case 'B': case 'b': + ++i; + PARSER_TABLE_COMMON_FUNC(vecB); + break; + default: + + ++i; + break; + } + } + + if(vecRGB.empty() && vecR.empty() && vecG.empty() && vecB.empty()) + { + CGE_LOG_ERROR("lomoParser - Warning: Empty Curve!!\n"); + } + + proc->pushPointsRGB(vecRGB.data(), (GLuint)vecRGB.size()); + proc->pushPoints(vecR.data(), (GLuint)vecR.size(), + vecG.data(), (GLuint)vecG.size(), + vecB.data(), (GLuint)vecB.size()); + proc->flush(); + if(fatherFilter != nullptr) fatherFilter->addFilter(proc); + return proc; + } + + CGEImageFilterInterface* CGEDataParsingEngine::lomoParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) + { + using namespace std; + using CGE::CGELomoLinearFilter; + using CGE::CGELomoFilter; + + float vignetteStart, vignetteEnd, colorScaleLow, colorScaleRange, saturation; + int isLinear = 0; + while(*pstr != '\0' && !isdigit(*pstr)) ++pstr; + if(sscanf(pstr, "%f%*c%f%*c%f%*c%f%*c%f%*c%d", + &vignetteStart, &vignetteEnd, &colorScaleLow, &colorScaleRange, &saturation, &isLinear) < 5) + { + return nullptr; + } + CGELomoFilter* proc; + if(isLinear) + proc = new CGELomoLinearFilter; + else proc = new CGELomoFilter; + proc->init(); + proc->setVignette(vignetteStart, vignetteEnd); + proc->setColorScale(colorScaleLow, colorScaleRange); + proc->setSaturation(saturation); + + if(fatherFilter != nullptr) fatherFilter->addFilter(proc); + return proc; + } + +#define ADJUSTHELP_COMMON_FUNC(str, procName, setFunc) \ +do{\ + float intensity;\ + if(sscanf(str, "%f", &intensity) != 1)\ + {\ + LOG_ERROR_PARAM(str);\ + return nullptr;\ + }\ + procName* bp = new procName();\ + if(!bp->init())\ + {\ + delete bp;\ + }\ + else \ + {\ + proc = bp;\ + bp->setFunc(intensity);\ + }\ +}while(0) + +#define ADJUSTHELP_COMMON_FUNC2(str, procName, setFunc1, setFunc2) \ +do{\ + float intensity1, intensity2;\ + if(sscanf(str, "%f%*c%f", &intensity1, &intensity2) != 2)\ + {\ + LOG_ERROR_PARAM(str);\ + return nullptr;\ + }\ + procName* bp = new procName();\ + if(!bp->init())\ + {\ + delete bp;\ + }\ + else \ + {\ + proc = bp;\ + bp->setFunc1(intensity1);\ + bp->setFunc2(intensity2);\ + }\ +}while(0) + +#define ADJUSTHELP_COMMON_FUNC3(str, procName, setFunc1, setFunc2, setFunc3) \ +do{\ + float intensity1, intensity2, intensity3;\ + if(sscanf(str, "%f%*c%f%*c%f", &intensity1, &intensity2, &intensity3) != 3)\ + {\ + LOG_ERROR_PARAM(str);\ + return nullptr;\ + }\ + procName* bp = new procName();\ + if(!bp->init())\ + {\ + delete bp;\ + }\ + else \ + {\ + proc = bp;\ + bp->setFunc1(intensity1);\ + bp->setFunc2(intensity2);\ + bp->setFunc3(intensity3);\ + }\ +}while(0) + +#define ADJUSTHELP_COMMON_FUNC_ARG2(str, procName, setFunc) \ +do{\ + float intensity1, intensity2;\ + if(sscanf(str, "%f%*c%f", &intensity1, &intensity2) != 2)\ + {\ + LOG_ERROR_PARAM(str);\ + return nullptr;\ + }\ + procName* bp = new procName();\ + if(!bp->init())\ + {\ + delete bp;\ + }\ + else \ + {\ + proc = bp;\ + bp->setFunc(intensity1, intensity2);\ + }\ +}while(0) + + CGEImageFilterInterface* CGEDataParsingEngine::adjustParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) + { + while(*pstr != '\0' && (*pstr == ' ' || *pstr == '\t')) ++pstr; + CGEImageFilterInterface* proc = nullptr; + + //2015-1-29 隐患fix, 将下一条指令直接取出再进行判断 + char buffer[128], *pBuffer = buffer; + + while(*pstr != '\0' && !isspace(*pstr) && (pBuffer - buffer) < sizeof(buffer)) + { + *pBuffer++ = *pstr++; + } + + *pBuffer = '\0'; + + //Hardcode for all basic adjusts. + if(strcmp(buffer, "brightness") == 0) + { + float intensity; + if(sscanf(pstr, "%f", &intensity) != 1) + return nullptr; + CGEBrightnessFastFilter* bfp = g_isFastFilterImpossible ? nullptr : createBrightnessFastFilter(); + CGEBrightnessFilter* bp = (bfp == nullptr) ? createBrightnessFilter() : nullptr; + + if(bfp != nullptr) + { + bfp->setIntensity(intensity); + proc = bfp; + } + else if(bp != nullptr) + { + bp->setIntensity(intensity); + proc = bp; + } + else + { + CGE_LOG_ERROR("CGEDataParsingEngine::adjustParser Create Brightness filter Failed\n"); + return nullptr; + } + } + else if(strcmp(buffer, "contrast") == 0) + { + ADJUSTHELP_COMMON_FUNC(pstr, CGEContrastFilter, setIntensity); + } + else if(strcmp(buffer, "saturation") == 0) + { + ADJUSTHELP_COMMON_FUNC(pstr, CGESaturationFilter, setIntensity); + } + else if(strcmp(buffer, "sharpen") == 0) + { + ADJUSTHELP_COMMON_FUNC(pstr, CGESharpenBlurSimpleBetterFilter, setSharpenIntensity); + } + else if(strcmp(buffer, "blur") == 0) + { + ADJUSTHELP_COMMON_FUNC(pstr, CGESharpenBlurSimpleBetterFilter, setBlurIntensity); + } + else if(strcmp(buffer, "whitebalance") == 0) + { + float temp, tint; + if(sscanf(pstr, "%f%*c%f", &temp, &tint) != 2) + { + LOG_ERROR_PARAM(pstr); + return nullptr; + } + CGEWhiteBalanceFastFilter* wfp = g_isFastFilterImpossible ? nullptr : createWhiteBalanceFastFilter(); + CGEWhiteBalanceFilter* wp = (wfp == nullptr) ? createWhiteBalanceFilter() : nullptr; + if(wfp != nullptr) + { + wfp->setTempAndTint(temp, tint); + proc = wfp; + } + else if(wp != nullptr) + { + wp->setTemperature(temp); + wp->setTint(tint); + proc = wp; + } + else + { + CGE_LOG_ERROR("CGEDataParsingEngine::adjustParser Create WhiteBalance filter Failed\n"); + return nullptr; + } + } + else if(strcmp(buffer, "monochrome") == 0) + { + float arg[6]; + if(sscanf(pstr, "%f%*c%f%*c%f%*c%f%*c%f%*c%f", + arg, arg+1, arg+2, arg+3, arg+4, arg+5) != 6) + { + CGE_LOG_ERROR("adjust hsv - Invalid Parameters: %s\n", pstr); + return nullptr; + } + CGEMonochromeFilter* monoProc = new CGEMonochromeFilter; + if(!monoProc->init()) + { + delete monoProc; + return nullptr; + } + else + { + proc = monoProc; + monoProc->setRed(arg[0]); + monoProc->setGreen(arg[1]); + monoProc->setBlue(arg[2]); + monoProc->setCyan(arg[3]); + monoProc->setMagenta(arg[4]); + monoProc->setYellow(arg[5]); + } + } + else if(strcmp(buffer, "shl") == 0 || strcmp(buffer, "shadowhighlight") == 0) + { + float shadow, highlight; + if(sscanf(pstr, "%f%*c%f", &shadow, &highlight) != 2) + { + LOG_ERROR_PARAM(pstr); + return nullptr; + } + CGEShadowHighlightFastFilter* shfp = g_isFastFilterImpossible ? nullptr : createShadowHighlightFastFilter(); + CGEShadowHighlightFilter* shp = (shfp == nullptr) ? createShadowHighlightFilter() : nullptr; + if(shfp != nullptr) + { + shfp->setShadowAndHighlight(shadow, highlight); + proc = shfp; + } + else if(shp != nullptr) + { + shp->setShadow(shadow); + shp->setHighlight(highlight); + proc = shp; + } + else + { + CGE_LOG_ERROR("CGEDataParsingEngine::adjustParser Create ShadowHighlight filter Failed\n"); + return nullptr; + } + } + else if(strcmp(buffer, "hsv") == 0) + { + float arg[6]; + if(sscanf(pstr, "%f%*c%f%*c%f%*c%f%*c%f%*c%f", + arg, arg+1, arg+2, arg+3, arg+4, arg+5) != 6) + { + CGE_LOG_ERROR("adjust hsv - Invalid Parameters: %s\n", pstr); + return nullptr; + } + CGESaturationHSVFilter* hsvProc = new CGESaturationHSVFilter; + if(!hsvProc->init()) + { + delete hsvProc; + return nullptr; + } + else + { + proc = hsvProc; + hsvProc->setAdjustColors(arg[0], arg[1], arg[2], arg[3], arg[4], arg[5]); + } + } + else if(strcmp(buffer, "hsl") == 0) + { + float h, s, l; + if(sscanf(pstr, "%f%*c%f%*c%f", &h, &s, &l) != 3) + { + CGE_LOG_ERROR("adjust hsl - Invalid Parameters: %s\n", pstr); + return nullptr; + } + CGESaturationHSLFilter* hslProc = createSaturationHSLFilter(); + proc = hslProc; + if(hslProc != nullptr) + { + hslProc->setHue(h); + hslProc->setSaturation(s); + hslProc->setLum(l); + } + } + else if(strcmp(buffer, "level") == 0) + { + float dark, light, gamma; + if(sscanf(pstr, "%f%*c%f%*c%f", &dark, &light, &gamma) != 3) + { + CGE_LOG_ERROR("adjust color level - Invalid Parameters: %s\n", pstr); + return nullptr; + } + CGEColorLevelFilter* levelProc = createColorLevelFilter(); + proc = levelProc; + if(levelProc != nullptr) + { + levelProc->setLevel(dark, light); + levelProc->setGamma(gamma); + } + } + else if(strcmp(buffer, "exposure") == 0) + { + ADJUSTHELP_COMMON_FUNC(pstr, CGEExposureFilter, setIntensity); + } + else if(strcmp(buffer, "hue") == 0) + { + ADJUSTHELP_COMMON_FUNC(pstr, CGEHueAdjustFilter, setHue); + } + else if(strcmp(buffer, "colorbalance") == 0) + { + float red, green, blue; + if(sscanf(pstr, "%f%*c%f%*c%f", &red, &green, &blue) != 3) + { + LOG_ERROR_PARAM(pstr); + return nullptr; + } + + CGEColorBalanceFilter* filter = createColorBalanceFilter(); + + if(filter != nullptr) + { + proc = filter; + filter->setRedShift(red); + filter->setGreenShift(green); + filter->setBlueShift(blue); + } + else + { + CGE_LOG_ERROR("CGEDataParsingEngine::adjustParser Create ColorBalance filter Failed\n"); + return nullptr; + } + } + else if(strcmp(buffer, "lut") == 0) + { + char lutName[128]; + float intensity = 1.0f; + int paramCount = sscanf(pstr, "%127s%f", lutName, &intensity); + if(paramCount < 1) + { + LOG_ERROR_PARAM(pstr); + return nullptr; + } + + CGELookupFilter* filter = createLookupFilter(); + GLuint tex = fatherFilter->loadResources(lutName); + if(filter != nullptr && tex != 0) + { + filter->setLookupTexture(tex); + proc = filter; + + if(paramCount == 2) + { // has intensity + filter->setIntensity(intensity); + } + } + else + { + delete filter; + glDeleteTextures(1, &tex); + CGE_LOG_ERROR("CGEDataParsingEngine::adjustParser Create Lookup filter Failed\n"); + } + } + else + { + LOG_ERROR_PARAM(pstr); + return nullptr; + } + + if(fatherFilter != nullptr) fatherFilter->addFilter(proc); + return proc; + } + + CGEImageFilterInterface* CGEDataParsingEngine::blendParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) + { + using namespace CGE; + char modeName[32], textureName[128]; + int intensity; + + if(sscanf(pstr, "%31s%127s%d", modeName, textureName, &intensity) != 3) + { + CGE_LOG_ERROR("blendParser - Invalid Param: %s\n", pstr); + return nullptr; + } + CGEBlendWithResourceFilter* proc = new CGEBlendWithResourceFilter; + + if(!proc->initWithMode(modeName)) + { + delete proc; + return nullptr; + } + + int texWidth, texHeight; + GLuint texID = 0; + + if(sscanf(textureName, "[%d%*c%d%*c%d]", &texID, &texWidth, &texHeight) != 3 || texID == 0) + { + texID = fatherFilter->loadResources(textureName, &texWidth, &texHeight); + } + CGE_LOG_CODE + ( + else + { + if(!glIsTexture(texID)) + { + CGE_LOG_ERROR("Warn: special usage with texture id, but the texture id is not valid now."); + } + } + ) + + if(texID == 0) + { + CGE_LOG_ERROR("blend - %s : loadResources failed: %s\n", modeName, textureName); + delete proc; + return nullptr; + } + + proc->setSamplerID(texID); + proc->setTexSize(texWidth, texHeight); + proc->setIntensity(intensity / 100.0f); + + if(fatherFilter != nullptr) fatherFilter->addFilter(proc); + return proc; + } + + CGEImageFilterInterface* CGEDataParsingEngine::vignetteBlendParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) + { + using namespace CGE; + char blendMethod[BUFFER_LEN]; + float color[4], intensity; + float low, range, centerX, centerY; + int kind = 0; + + if(sscanf(pstr, "%" BUFFER_LEN_STR "s%f%f%f%f%f%f%f%f%f%d", blendMethod, color, color + 1, color + 2, color + 3, &intensity, &low, &range, ¢erX, ¢erY, &kind) < 10) + { + CGE_LOG_ERROR("vignetteBlendParser - Invalid parameters: %s\n", pstr); + return nullptr; + } + + CGEBlendVignetteFilter* proc = nullptr; + switch(kind) + { + case 0: + proc = new CGEBlendVignetteNoAlphaFilter; + break; + case 1: + proc = new CGEBlendVignetteFilter; + break; + case 2: + proc = new CGEBlendVignette2NoAlphaFilter; + break; + case 3: + proc = new CGEBlendVignette2Filter; + break; + default: + CGE_LOG_ERROR("vignetteBlendParser - Invalid vignette kind %d", kind); + return nullptr; + } + + if(!CGEBlendInterface::initWithModeName(blendMethod, proc)) + { + delete proc; + return nullptr; + } + + proc->setVignette(low, range); + proc->setVignetteCenter(centerX, centerY); + + if(color[3] > 1.00001f) //判断值域范围为0~1还是0~255并进行相应处理。 + { + color[0] /= 255.0f; + color[1] /= 255.0f; + color[2] /= 255.0f; + color[3] /= 255.0f; + } + proc->setBlendColor(color[0], color[1], color[2], color[3]); + proc->setIntensity(intensity / 100.0f); + + if(fatherFilter != nullptr) fatherFilter->addFilter(proc); + return proc; + } + + ////////////////////////////////////////////////////////////////////////// + + CGEImageFilterInterface* CGEDataParsingEngine::colorScaleParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) + { + using namespace CGE; + float low, range, sat; + if(sscanf(pstr, "%f%*c%f%*c%f", &low, &range, &sat) != 3) + { + CGE_LOG_ERROR("colorScaleParser - Invalid Parameters: %s\n", pstr); + return nullptr; + } + CGEColorScaleFilter* proc = new CGEColorScaleFilter; + if(!proc->init()) + { + delete proc; + return nullptr; + } + proc->setColorScale(low, range); + proc->setSaturation(sat); + if(fatherFilter != nullptr) fatherFilter->addFilter(proc); + return proc; + } + + CGEImageFilterInterface* CGEDataParsingEngine::pixblendParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) + { + using namespace CGE; + char blendMethod[BUFFER_LEN]; + float color[4], intensity; + + if(sscanf(pstr, "%" BUFFER_LEN_STR "s%f%f%f%f%f", blendMethod, color, color + 1, color + 2, color + 3, &intensity) != 6) + { + CGE_LOG_ERROR("pixblendParser - Invalid parameters: %s\n", pstr); + return nullptr; + } + + CGEPixblendFilter* proc = new CGEPixblendFilter; + if(!proc->initWithMode(blendMethod)) + { + delete proc; + return nullptr; + } + + if(color[3] > 1.00001f) //判断值域范围为0~1还是0~255并进行相应处理。 + { + color[0] /= 255.0f; + color[1] /= 255.0f; + color[2] /= 255.0f; + color[3] /= 255.0f; + } + proc->setBlendColor(color[0], color[1], color[2], color[3]); + proc->setIntensity(intensity / 100.0f); + + if(fatherFilter != nullptr) fatherFilter->addFilter(proc); + return proc; + } + + CGEImageFilterInterface* CGEDataParsingEngine::krblendParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) + { + using namespace CGE; + char modeName[32], textureName[128]; + int intensity; + if(sscanf(pstr, "%31s%127s%d", modeName, textureName, &intensity) != 3) + { + CGE_LOG_ERROR("krblendParser - Invalid Param: %s\n", pstr); + return nullptr; + } + + CGEBlendKeepRatioFilter* proc = new CGEBlendKeepRatioFilter; + if(!proc->initWithMode(modeName)) + { + delete proc; + return nullptr; + } + + int texWidth, texHeight; + GLuint texID; + + if(sscanf(textureName, "[%d%*c%d%*c%d]", &texID, &texWidth, &texHeight) != 3 || texID == 0) + { + texID = fatherFilter->loadResources(textureName, &texWidth, &texHeight); + } + CGE_LOG_CODE + ( + else + { + if(!glIsTexture(texID)) + { + CGE_LOG_ERROR("Warn: special usage with texture id, but the texture id is not valid now."); + } + } + ) + + if(texID == 0) + { + CGE_LOG_ERROR("blend - %s : loadResources failed: %s\n", modeName, textureName); + delete proc; + return nullptr; + } + + proc->setSamplerID(texID); + proc->setTexSize(texWidth, texHeight); + proc->setIntensity(intensity / 100.0f); + + if(fatherFilter != nullptr) fatherFilter->addFilter(proc); + return proc; + } + + CGEImageFilterInterface* CGEDataParsingEngine::vignetteParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) + { + float low, range, centerX, centerY; + int n = sscanf(pstr, "%f%*c%f%*c%f%*c%f", &low, &range, ¢erX, ¢erY); + if(n < 2) + { + CGE_LOG_ERROR("vignetteParser - Invalid Param: %s\n", pstr); + return nullptr; + } + + CGEVignetteFilter* proc = new CGEVignetteFilter; + if(!proc->init()) + { + delete proc; + return nullptr; + } + + proc->setVignette(low, range); + if(n == 4) proc->setVignetteCenter(centerX, centerY); + if(fatherFilter != nullptr) fatherFilter->addFilter(proc); + return proc; + } + + CGEImageFilterInterface* CGEDataParsingEngine::selfblendParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) + { + using namespace CGE; + char modeName[32]; + int intensity; + if(sscanf(pstr, "%31s%d", modeName, &intensity) != 2) + { + CGE_LOG_ERROR("selfblendParser - Invalid Param: %s\n", pstr); + return nullptr; + } + + CGEBlendWithSelfFilter* proc = new CGEBlendWithSelfFilter; + if(!proc->initWithMode(modeName)) + { + delete proc; + return nullptr; + } + proc->setIntensity(intensity / 100.0f); + if(fatherFilter != nullptr) fatherFilter->addFilter(proc); + return proc; + } + + CGEImageFilterInterface* CGEDataParsingEngine::colorMulParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) + { + using namespace CGE; + char funcName[32] = ""; + if(sscanf(pstr,"%31s", funcName) != 1) + { + CGE_LOG_ERROR("colorMulParser - Invalid Param: %s", pstr); + return nullptr; + } + + CGEColorMulFilter* proc = nullptr; + if(strncmp(funcName, "flt", 3) == 0) + { + float value; + if(sscanf(pstr, "%*s%f", &value) != 1) + { + CGE_LOG_ERROR("colorMulParser - flt - Invalid Param:%s\n", pstr); + return nullptr; + } + proc = new CGEColorMulFilter; + proc->initWithMode(CGEColorMulFilter::mulFLT); + proc->setFLT(value); + } + else if(strncmp(funcName, "vec", 3) == 0) + { + float r, g, b; + if(sscanf(pstr, "%*s%f%*c%f%*c%f", &r, &g, &b) != 3) + { + CGE_LOG_ERROR("colorMulParser - vec - Invalid Param:%s\n", pstr); + return nullptr; + } + proc = new CGEColorMulFilter; + proc->initWithMode(CGEColorMulFilter::mulVEC); + proc->setVEC(r, g, b); + } + else if(strncmp(funcName, "mat", 3) == 0) + { + float mat[9]; + if(sscanf(pstr, "%*s%f%*c%f%*c%f%*c%f%*c%f%*c%f%*c%f%*c%f%*c%f", + mat, mat + 1, mat + 2, mat + 3, mat + 4, mat + 5, mat + 6, mat + 7, mat + 8) != 9) + { + CGE_LOG_ERROR("colorMulParser - mat - Invalid Param:%s\n", pstr); + return nullptr; + } + proc = new CGEColorMulFilter; + proc->initWithMode(CGEColorMulFilter::mulMAT); + proc->setMAT(mat); + } + else + { + CGE_LOG_ERROR("colorMulParser - Invalid Param:%s\n", pstr); + return nullptr; + } + + if(fatherFilter != nullptr) fatherFilter->addFilter(proc); + return proc; + } + + CGEImageFilterInterface* CGEDataParsingEngine::selectiveColorParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) + { + CGESelectiveColorFilter* proc = createSelectiveColorFilter(); + if(proc == nullptr) + { + CGE_LOG_ERROR("selectiveColorParser - init processor failed!\n"); + return nullptr; + } + + while(pstr != nullptr && *pstr != '\0' && *pstr != '@') + { + char funcName[32]; + float cyan, magenta, yellow, key; + while(*pstr != '\0' && (isspace(*pstr) || *pstr == ',')) ++pstr; + if(*pstr == '\0' || *pstr == '@') + break; + if(sscanf(pstr, "%31[^( \t\n]%*[^-0-9.]%f%*c%f%*c%f%*c%f", funcName, &cyan, &magenta, &yellow, &key) != 5) + { + CGE_LOG_ERROR("selectiveColorParser - Invalid Param %s!\n", pstr); + break; + } + + while(*pstr != '\0' && *pstr++ != ')') ; + + if(fabsf(cyan) > 1.0f || fabsf(magenta) > 1.0f || fabsf(yellow) > 1.0f || fabsf(key) > 1.0f) + { + cyan /= 100.0f; + magenta /= 100.0f; + yellow /= 100.0f; + key /= 100.0f; + } + + if(strcmp(funcName, "red") == 0) + { + proc->setRed(cyan, magenta, yellow, key); + } + else if(strcmp(funcName, "green") == 0) + { + proc->setGreen(cyan, magenta, yellow, key); + } + else if(strcmp(funcName, "blue") == 0) + { + proc->setBlue(cyan, magenta, yellow, key); + } + else if(strcmp(funcName, "cyan") == 0) + { + proc->setCyan(cyan, magenta, yellow, key); + } + else if(strcmp(funcName, "magenta") == 0) + { + proc->setMagenta(cyan, magenta, yellow, key); + } + else if(strcmp(funcName, "yellow") == 0) + { + proc->setYellow(cyan, magenta, yellow, key); + } + else if(strcmp(funcName, "white") == 0) + { + proc->setWhite(cyan, magenta, yellow, key); + } + else if(strcmp(funcName, "gray") == 0) + { + proc->setGray(cyan, magenta, yellow, key); + } + else if(strcmp(funcName, "black") == 0) + { + proc->setBlack(cyan, magenta, yellow, key); + } + else + { + CGE_LOG_ERROR("Unknown funcName: %s!\n", funcName); + } + } + + if(fatherFilter != nullptr) fatherFilter->addFilter(proc); + return proc; + } + + CGEImageFilterInterface* CGEDataParsingEngine::blendTileParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) + { + char modeName[32], textureName[128]; + int intensity; + + if(sscanf(pstr, "%31s%127s%d", modeName, textureName, &intensity) != 3) + { + CGE_LOG_ERROR("blendTileParser - Invalid Param: %s\n", pstr); + return nullptr; + } + CGEBlendTileFilter* proc = new CGEBlendTileFilter; + + if(!proc->initWithMode(modeName)) + { + delete proc; + return nullptr; + } + + int texWidth, texHeight; + GLuint texID; + + if(sscanf(textureName, "[%d%*c%d%*c%d]", &texID, &texWidth, &texHeight) != 3 || texID == 0) + { + texID = fatherFilter->loadResources(textureName, &texWidth, &texHeight); + } + CGE_LOG_CODE + ( + else + { + if(!glIsTexture(texID)) + { + CGE_LOG_ERROR("Warn: special usage with texture id, but the texture id is not valid now."); + } + } + ) + + if(texID == 0) + { + CGE_LOG_ERROR("blend - %s : loadResources failed: %s\n", modeName, textureName); + delete proc; + return nullptr; + } + + proc->setSamplerID(texID); + proc->setTexSize(texWidth, texHeight); + proc->setIntensity(intensity / 100.0f); + + if(fatherFilter != nullptr) fatherFilter->addFilter(proc); + return proc; + } + + CGEImageFilterInterface* CGEDataParsingEngine::advancedStyleParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) + { + while(*pstr != '\0' && (*pstr == ' ' || *pstr == '\t')) ++pstr; + CGEImageFilterInterface* proc = nullptr; + + //2015-1-29 隐患fix, 将下一条指令直接取出再进行判断 + char buffer[128], *pBuffer = buffer; + + while(*pstr != '\0' && !isspace(*pstr) && (pBuffer - buffer) < sizeof(buffer)) + { + *pBuffer++ = *pstr++; + } + + *pBuffer = '\0'; + + //Hardcode for all basic adjusts. + if(strcmp(buffer, "crosshatch") == 0) + { + ADJUSTHELP_COMMON_FUNC2(pstr, CGECrosshatchFilter, setCrosshatchSpacing, setLineWidth); + } + else if(strcmp(buffer, "hist") == 0) + { + float x, y, value1, value2, r, g, b; + if(sscanf(pstr, "%f%*c%f%*c%f%*c%f%*c%f%*c%f%*c%f",&x, &y, &value1, &value2, &r, &g, &b) != 7) + { + LOG_ERROR_PARAM(pstr); + return nullptr; + } + + CGEHistogramFilter* filter = createHistogramFilter(); + if(filter != nullptr) + { + proc = filter; + filter->setCenter(x,y); + filter->setXValue(value1); + filter->setYValue(value2); + filter->setColor(r,g,b); + } + } + + + else if(strcmp(buffer, "waveform") == 0) + { + float x, y, value1, value2, r, g, b; + if(sscanf(pstr, "%f%*c%f%*c%f%*c%f%*c%f%*c%f%*c%f",&x, &y, &value1, &value2, &r, &g, &b) != 7) + { + LOG_ERROR_PARAM(pstr); + return nullptr; + } + + CGEWaveformFilter* filter = createWaveformFilter(); + if(filter != nullptr) + { + proc = filter; + filter->setCenter(x,y); + filter->setXValue(value1); + filter->setYValue(value2); + filter->setColor(r,g,b); + } + } + else if(strcmp(buffer, "edge") == 0) + { + ADJUSTHELP_COMMON_FUNC2(pstr, CGEEdgeSobelFilter, setIntensity, setStride); + } + else if(strcmp(buffer, "emboss") == 0) + { + ADJUSTHELP_COMMON_FUNC3(pstr, CGEEmbossFilter, setIntensity, setStride, setAngle); + } + else if(strcmp(buffer, "halftone") == 0) + { + ADJUSTHELP_COMMON_FUNC(pstr, CGEHalftoneFilter, setDotSize); + } + else if(strcmp(buffer, "haze") == 0) + { + float dis, slope, r, g, b; + if(sscanf(pstr, "%f%*c%f%*c%f%*c%f%*c%f", &dis, &slope, &r, &g, &b) != 5) + { + LOG_ERROR_PARAM(pstr); + return nullptr; + } + CGEHazeFilter* filter = createHazeFilter(); + if(filter != nullptr) + { + proc = filter; + filter->setDistance(dis); + filter->setSlope(slope); + filter->setHazeColor(r, g, b); + } + } + else if(strcmp(buffer, "polkadot") == 0) + { + ADJUSTHELP_COMMON_FUNC(pstr, CGEPolkaDotFilter, setDotScaling); + } + else if(strcmp(buffer, "sketch") == 0) + { + ADJUSTHELP_COMMON_FUNC(pstr, CGESketchFilter, setIntensity); + } + else if(strcmp(buffer, "max") == 0) + { + proc = new CGEMaxValueFilter3x3(); + if(!proc->init()) + { + delete proc; + proc = nullptr; + } + } + else if(strcmp(buffer, "min") == 0) + { + proc = new CGEMinValueFilter3x3(); + if(!proc->init()) + { + delete proc; + proc = nullptr; + } + } + else if(strcmp(buffer, "mid") == 0) + { + CGE_LOG_ERROR("中值濾波暂无"); + return nullptr; + } + else if(strcmp(buffer, "cm") == 0 || strcmp(buffer, "colorMapping") == 0) + { + char filename[128]; + int mappingWidth, mappingHeight, unitWidth, unitHeight; + if(sscanf(pstr, "%127s%*c%d%*c%d%*c%d%*c%d", filename, &mappingWidth, &mappingHeight, &unitWidth, &unitHeight) != 5) + { + LOG_ERROR_PARAM(buffer); + return nullptr; + } + + int w, h; + GLuint texID = fatherFilter->loadResources(filename, &w, &h); + + if(texID == 0) + { + CGE_LOG_ERROR("Load texture %s failed!\n", filename); + return nullptr; + } + + CGEColorMappingFilter* filter = CGEColorMappingFilter::createWithMode(CGEColorMappingFilter::MAPINGMODE_DEFAULT); + + float weight = 0.0f; + + for(int i = 0; i != unitHeight; ++i) + { + for(int j = 0; j != unitWidth; ++j) + { + CGEColorMappingFilter::MappingArea ma = { + Vec4f(j / (float)unitWidth, i / (float)unitHeight, 1.0f / unitWidth, 1.0f / unitHeight), + weight + }; + + weight += 1.0f / (unitWidth * unitHeight - 1); + + filter->pushMapingArea(ma); + } + } + + filter->endPushing(); + filter->setupMapping(texID, w, h, mappingWidth, mappingHeight); + + proc = filter; + } + else + { + LOG_ERROR_PARAM(pstr); + return nullptr; + } + + if(fatherFilter != nullptr) fatherFilter->addFilter(proc); + return proc; + } + + CGEImageFilterInterface* CGEDataParsingEngine::beautifyParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) + { + while(*pstr != '\0' && (*pstr == ' ' || *pstr == '\t')) ++pstr; + CGEImageFilterInterface* proc = nullptr; + + char buffer[128], *pBuffer = buffer; + + while(*pstr != '\0' && !isspace(*pstr) && (pBuffer - buffer) < sizeof(buffer)) + { + *pBuffer++ = *pstr++; + } + + *pBuffer = '\0'; + + //Hardcode for all basic adjusts. + if(strcmp(buffer, "bilateral") == 0) + { + float blurScale, disFactor; + int repeatTimes = 1; + if(sscanf(pstr, "%f%*c%f%*c%d", &blurScale, &disFactor, &repeatTimes) < 2) + { + LOG_ERROR_PARAM(pstr); + return nullptr; + } + + CGEBilateralWrapperFilter* filter = new CGEBilateralWrapperFilter; + if(filter->init()) + { + proc = filter; + filter->setBlurScale(blurScale); + filter->setDistanceNormalizationFactor(disFactor); + filter->setRepeatTimes(repeatTimes); + } + else + { + LOG_ERROR_PARAM(pstr); + delete filter; + } + + } + else if(strcmp(buffer, "face") == 0) + { + float intensity, width = -1.0f, height = -1.0f; + if(sscanf(pstr, "%f%*c%f%*c%f", &intensity, &width, &height) < 1) + { + LOG_ERROR_PARAM(pstr); + return nullptr; + } + + CGEBeautifyFilter* filter = createBeautifyFilter(); + if(filter != nullptr) + { + proc = filter; + filter->setIntensity(intensity); + if(width > 0.0f && height > 0.0f) + { + filter->setImageSize(width, height); + } + } + } + + else + { + LOG_ERROR_PARAM(pstr); + return nullptr; + } + + if(fatherFilter != nullptr) fatherFilter->addFilter(proc); + return proc; + } + + CGEImageFilterInterface* CGEDataParsingEngine::blurParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) + { + while(*pstr != '\0' && (*pstr == ' ' || *pstr == '\t')) ++pstr; + CGEImageFilterInterface* proc = nullptr; + + char buffer[128], *pBuffer = buffer; + + while(*pstr != '\0' && !isspace(*pstr) && (pBuffer - buffer) < sizeof(buffer)) + { + *pBuffer++ = *pstr++; + } + + *pBuffer = '\0'; + + //Hardcode for all basic adjusts. + if(strcmp(buffer, "lerp") == 0) + { + float intensity, base; + int argNum; + if((argNum = sscanf(pstr, "%f%*c%f", &intensity, &base)) < 1) + { + LOG_ERROR_PARAM(pstr); + return nullptr; + } + + auto* filter = createLerpblurFilter(); + + if(filter != nullptr) + { + proc = filter; + if(argNum == 2) + { + filter->setBlurLevel(intensity * CGELerpblurFilter::MAX_LERP_BLUR_INTENSITY); + filter->setMipmapBase(base); + } + else + { + filter->setIntensity(intensity); + } + } + } + + else + { + LOG_ERROR_PARAM(pstr); + return nullptr; + } + + if(fatherFilter != nullptr) fatherFilter->addFilter(proc); + return proc; + } + + CGEImageFilterInterface* CGEDataParsingEngine::dynamicParser(const char* pstr, CGEMutipleEffectFilter* fatherFilter) + { + while(*pstr != '\0' && (*pstr == ' ' || *pstr == '\t')) ++pstr; + CGEImageFilterInterface* proc = nullptr; + + char buffer[128], *pBuffer = buffer; + + while(*pstr != '\0' && !isspace(*pstr) && (pBuffer - buffer) < sizeof(buffer)) + { + *pBuffer++ = tolower(*pstr++); + } + + *pBuffer = '\0'; + + //Hardcode for all basic adjusts. + if(strcmp(buffer, "wave") == 0) + { + float motion, angle, strength, motionSpeed; + int argNum = sscanf(pstr, "%f%*c%f%*c%f%*c%f", &motion, &angle, &strength, &motionSpeed); + + if(!(argNum == 3 || argNum == 4 || (argNum == 1 && motion > 0))) + { + LOG_ERROR_PARAM(pstr); + return nullptr; + } + + auto* filter = createDynamicWaveFilter(); + + if(filter != nullptr) + { + proc = filter; + + switch (argNum) + { + case 1: + filter->setAutoMotionSpeed(motion); + break; + case 3: + filter->setWaveMotion(motion); + filter->setWaveAngle(angle); + filter->setStrength(strength); + break; + case 4: + filter->setAutoMotionSpeed(motionSpeed); + filter->setWaveAngle(angle); + filter->setStrength(strength); + filter->setWaveMotion(motion); + break; + default: + CGE_LOG_ERROR("Error which should never happen, but just happened... biu biu...\n"); + delete filter; + break; + } + } + } + else if(strcmp(buffer, "mf") == 0 || strcmp(buffer, "motionflow") == 0) + { + int totalFrames, framesDelay; + if(sscanf(pstr, "%d%*c%d", &totalFrames, &framesDelay) != 2) + { + LOG_ERROR_PARAM(pstr); + return nullptr; + } + + auto* filter = createMotionFlowFilter(); + if(filter != nullptr) + { + proc = filter; + filter->setTotalFrames(totalFrames); + filter->setFrameDelay(framesDelay); + } + } + else + { + LOG_ERROR_PARAM(pstr); + return nullptr; + } + + if(fatherFilter != nullptr) fatherFilter->addFilter(proc); + return proc; + } + + +} + \ No newline at end of file From 5b5af402a045835682ce930ea49885df07eabc8d Mon Sep 17 00:00:00 2001 From: xiaodi86 <51728141+xiaodi86@users.noreply.github.com> Date: Mon, 26 Dec 2022 09:22:51 +0800 Subject: [PATCH 08/20] Update MainActivity.java --- cgeDemo/src/main/java/org/wysaid/cgeDemo/MainActivity.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cgeDemo/src/main/java/org/wysaid/cgeDemo/MainActivity.java b/cgeDemo/src/main/java/org/wysaid/cgeDemo/MainActivity.java index e6e42404..95277940 100644 --- a/cgeDemo/src/main/java/org/wysaid/cgeDemo/MainActivity.java +++ b/cgeDemo/src/main/java/org/wysaid/cgeDemo/MainActivity.java @@ -27,6 +27,8 @@ public class MainActivity extends AppCompatActivity { public static final String LOG_TAG = "wysaid"; public static final String EFFECT_CONFIGS[] = { + "@style waveform 0.5 0.5 200. 150. 0.0 0.0 0.0 ", + "@style hist 0.5 0.5 200. 150. 0.0 0.0 0.0 ", "", "@curve RGB(0,255)(255,0) @style cm mapping0.jpg 80 80 8 3", // ASCII art (字符画效果) "@beautify face 1 480 640", //Beautify From bae643209e4f1f5df87c089bf2e81a8589725fce Mon Sep 17 00:00:00 2001 From: xiaodi86 <51728141+xiaodi86@users.noreply.github.com> Date: Thu, 29 Dec 2022 11:18:25 +0800 Subject: [PATCH 09/20] Add files via upload --- .../org/wysaid/cgeDemo/ChartGLRenderer.java | 67 ++ .../wysaid/cgeDemo/ChartGLSurfaceView.java | 111 +++ .../org/wysaid/cgeDemo/ChartWaveForm.java | 89 +++ .../org/wysaid/cgeDemo/HistogramView.java | 96 +++ .../cgeDemo/VideoPlayerGLSurfaceView.java | 694 ++++++++++++++++++ 5 files changed, 1057 insertions(+) create mode 100644 cgeDemo/src/main/java/org/wysaid/cgeDemo/ChartGLRenderer.java create mode 100644 cgeDemo/src/main/java/org/wysaid/cgeDemo/ChartGLSurfaceView.java create mode 100644 cgeDemo/src/main/java/org/wysaid/cgeDemo/ChartWaveForm.java create mode 100644 cgeDemo/src/main/java/org/wysaid/cgeDemo/HistogramView.java create mode 100644 cgeDemo/src/main/java/org/wysaid/cgeDemo/VideoPlayerGLSurfaceView.java diff --git a/cgeDemo/src/main/java/org/wysaid/cgeDemo/ChartGLRenderer.java b/cgeDemo/src/main/java/org/wysaid/cgeDemo/ChartGLRenderer.java new file mode 100644 index 00000000..79a5b63b --- /dev/null +++ b/cgeDemo/src/main/java/org/wysaid/cgeDemo/ChartGLRenderer.java @@ -0,0 +1,67 @@ +package org.wysaid.cgeDemo.view; + +import android.content.Context; +import android.opengl.GLSurfaceView; +import android.opengl.GLU; +import android.util.Log; + +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.opengles.GL10; + +public class ChartGLRenderer implements GLSurfaceView.Renderer { + + public volatile float[] chartData = new float[ChartWaveForm.BUFFER_SIZE]; + private int width; + private int height; + private Context context; + private ChartWaveForm lineChart; + + public ChartGLRenderer(Context context) { + this.context = context; + lineChart = new ChartWaveForm(); + } + + @Override + public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) { + //lineChart = new LineChart(); + } + + @Override + public void onSurfaceChanged(GL10 gl, int width, int height) { + this.width = width; + this.height = height; + //Prevent a divide by 0 by making height =1 + if (height == 0) { + height = 1; + } + Log.d("执行到这", "ChartSurfaceView---Width =="+width+"----Height =="+height); + //Reset current viewport + gl.glViewport(0, 0, width, height); + //Select Projection Matrix + gl.glMatrixMode(GL10.GL_PROJECTION); + //Reset Projection Matrix + gl.glLoadIdentity(); + //Calculate The Aspect Ratio Of The Window + //Log.d("Chart Ratio2 "," width " +width + " H " + height); + //void gluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) + //fovy是眼睛上下睁开的幅度,角度值,值越小,视野范围越狭小(眯眼),值越大,视野范围越宽阔(睁开铜铃般的大眼); + //zNear表示近裁剪面到眼睛的距离,zFar表示远裁剪面到眼睛的距离,注意zNear和zFar不能设置设置为负值(你怎么看到眼睛后面的东西)。 + //aspect表示裁剪面的宽w高h比,这个影响到视野的截面有多大。 + GLU.gluPerspective(gl, 50.0f, (float) height * 2.0f / (float) width, 0.1f, 100.0f); + gl.glMatrixMode(GL10.GL_MODELVIEW); //Select The Modelview Matrix + gl.glLoadIdentity(); //Reset The Modelview Matrix + } + + @Override + public void onDrawFrame(GL10 gl) { + // clear Screen and Depth Buffer + gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); + // Reset the Modelview Matrix + gl.glLoadIdentity(); + //Move 5 units into the screen is the same as moving the camera 5 units away + gl.glTranslatef(0.0f, 0.0f, -3.0f); + this.lineChart.setResolution(width, height); + this.lineChart.setChartData(chartData); + lineChart.draw(gl); + } +} diff --git a/cgeDemo/src/main/java/org/wysaid/cgeDemo/ChartGLSurfaceView.java b/cgeDemo/src/main/java/org/wysaid/cgeDemo/ChartGLSurfaceView.java new file mode 100644 index 00000000..315c074e --- /dev/null +++ b/cgeDemo/src/main/java/org/wysaid/cgeDemo/ChartGLSurfaceView.java @@ -0,0 +1,111 @@ +package org.wysaid.cgeDemo.view; + +import android.content.Context; +import android.graphics.PixelFormat; +import android.opengl.GLSurfaceView; + +public class ChartGLSurfaceView extends GLSurfaceView { + + //线程标志位 + private boolean isUpdating = false; + //渲染Renderer + private ChartGLRenderer mRenderer; + //y坐标数组 + private float[] datapoints = new float[ChartWaveForm.BUFFER_SIZE]; + + public ChartGLSurfaceView(Context context) { + super(context); + //设置EGL配置选择 + setEGLConfigChooser(8, 8, 8, 8, 16, 0); + //设置处于屏幕最前边 + this.setZOrderOnTop(true); //necessary + getHolder().setFormat(PixelFormat.TRANSLUCENT); + // Set the Renderer for drawing on the GLSurfaceView + mRenderer = new ChartGLRenderer(context); + setRenderer(mRenderer); + //初始化 + for (int i = 0; i < datapoints.length; i++) { + datapoints[i] = 0; + } + setChartData(datapoints); + // Render the view only when there is a change in the drawing data,有变化时绘制 + //setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); + new Thread(new Task()).start(); + } + + /** + * 设置数据源 + * @param datapoints + */ + public void setChartData(float[] datapoints) { +// L.d("执行到这","decodeThread---02"); + if (datapoints != null && datapoints.length > 0) { + isUpdating = true; + this.datapoints = datapoints.clone(); +// float gMaxValue = getMax(datapoints); +// float gMinValue = getMin(datapoints); +// for (int i = 0; i < this.datapoints.length; i++) { +// this.datapoints[i] = (((datapoints[i] - gMinValue) * (1.0f - (-1.0f)) / (gMaxValue - gMinValue)) + (-1)); +//// L.d("执行到这","this.datapoints[i]=="+String.valueOf(this.datapoints[i])); +// } + isUpdating = false; +// L.d("执行到这","gMaxValue==="+gMaxValue+"---gMinValue==="+gMinValue); + } + } + + /** + * 获取数组最大值 + * @param array + * @return + */ + private float getMax(float[] array) { + if(array != null && array.length > 0){ + float max = array[0]; + for (int i = 1; i < array.length; i++) { + if (array[i] > max) { + max = array[i]; + } + } + return max; + } else { + return 0f; + } + } + + /** + * 获取数组最小值 + * @param array + * @return + */ + private float getMin(float[] array) { + if(array != null && array.length > 0){ + float min = array[0]; + for (int i = 1; i < array.length; i++) { + if (array[i] < min) { + min = array[i]; + } + } + return min; + } else { + return 0f; + } + } + + class Task implements Runnable { + @Override + public void run() { + while (true) { + if (!isUpdating) { + mRenderer.chartData = datapoints; + requestRender(); + } +// try { +// Thread.sleep(30); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } + } + } + } + +} diff --git a/cgeDemo/src/main/java/org/wysaid/cgeDemo/ChartWaveForm.java b/cgeDemo/src/main/java/org/wysaid/cgeDemo/ChartWaveForm.java new file mode 100644 index 00000000..8a6da829 --- /dev/null +++ b/cgeDemo/src/main/java/org/wysaid/cgeDemo/ChartWaveForm.java @@ -0,0 +1,89 @@ +package org.wysaid.cgeDemo.view; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; + +import javax.microedition.khronos.opengles.GL10; + +public class ChartWaveForm { + + //缓冲区长度,点数 + public final static int BUFFER_SIZE = 1570464;//VideoPlayerGLSurfaceView.mViewWidth*VideoPlayerGLSurfaceView.mViewHeight=984*1596=1570464 + //缓冲区数组 + private float[] mChartDatas = new float[BUFFER_SIZE]; + //缓冲区缓存 + private FloatBuffer vertexBuffer; + //顶点坐标数组 + private float[] vertices = new float[BUFFER_SIZE * 3]; + //绘图区域 + private int width, height; + + public ChartWaveForm() { + + } + + /** + * 根据缓冲区数组 封装 顶点坐标数组 + */ + private void drawRealtimeChart() { + //坐标系xyz,屏幕中心为原点坐标(0,0,0),左上角为(-1,1,0),右下角(1,-1,0),坐标值有问题?好窄 + float span = 20.0f / 984;//VideoPlayerGLSurfaceView.mViewWidth=984 + //vertices的0,3,6……位置放x坐标值 + //vertices的1,4,7……位置放y坐标值 + //vertices的2,5,8……位置放z坐标值,平面图,默认为0 + for (int i = 0; i < BUFFER_SIZE; i++) { + + vertices[i * 3] = -10 + (i % 984) * span;//VideoPlayerGLSurfaceView.mViewWidth=984 +// vertices[i * 3] = -10 + i * span; +// L.d("执行到这", "X轴坐标==" + vertices[i * 3]); + + vertices[i * 3 + 1] = mChartDatas[i]; + + vertices[i * 3 + 2] = 0.0f; + } + } + + /** + * 开辟对应的缓冲区存放顶点坐标数组 + */ + private void vertexGenerate() { + //一个浮点数在内存中占4个字节,在内存中开辟指定长度的缓冲区,用来存放顶点坐标数组 + ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(vertices.length * 4); + //设置字节处理规则,大端模式或者小端模式,设置为默认 + vertexByteBuffer.order(ByteOrder.nativeOrder()); + //将内存中分配的字节缓冲区转换成浮点数缓冲区 + vertexBuffer = vertexByteBuffer.asFloatBuffer(); + //存放顶点坐标数组 + vertexBuffer.put(vertices); + //复位缓冲区,position指向0,第一个数据 + vertexBuffer.position(0); + } + + public void setResolution(int width, int height) { + this.width = width; + this.height = height; + } + + public void setChartData(float[] chartData) { + this.mChartDatas = chartData; + drawRealtimeChart(); + vertexGenerate(); + } + + public void draw(GL10 gl) { + gl.glViewport(0, 0, width, height); + // bind the previously generated texture 顶点绘图 + gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); + // set the color for the triangle 设置绘图颜色 + gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + // Point to our vertex buffer 设置顶点数据,3代表XYZ坐标系 + gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); + // Line width + gl.glPointSize(2.5f); + // Draw the vertices as triangle strip,顶点之间的连接模式 + gl.glDrawArrays(GL10.GL_POINTS, 0, vertices.length / 3); + //Disable the client state before leaving 关闭顶点设置 + gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); + } +} diff --git a/cgeDemo/src/main/java/org/wysaid/cgeDemo/HistogramView.java b/cgeDemo/src/main/java/org/wysaid/cgeDemo/HistogramView.java new file mode 100644 index 00000000..931d03bd --- /dev/null +++ b/cgeDemo/src/main/java/org/wysaid/cgeDemo/HistogramView.java @@ -0,0 +1,96 @@ + +package org.wysaid.cgeDemo.view; + +import android.content.Context; +import android.content.res.Configuration; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.os.Handler; +import android.os.Message; +import android.view.View; + +public class HistogramView extends View implements Handler.Callback { + static final private String TAG = "HistogramView"; + + private static final int HISTOGRAM = 0; + + private Paint paint; + private Handler handler; + // private Converter converter; + private Configuration config; + + private int width; + private int height; + private float max; + + private float[] histogram; + private long count; + + // HistogramView + public HistogramView(Context context) { + super(context); + paint = new Paint(); + handler = new Handler(this); +// converter = new Converter(getContext()); + } + + // onSizeChanged + @Override + public void onSizeChanged(int w, int h, int oldw, int oldh) { + width = w; + height = h; + + config = getResources().getConfiguration(); + } + + // onDraw + @Override + public void onDraw(Canvas canvas) { + if (histogram == null) return; + + canvas.drawColor(Color.BLACK); + + float xscale = (float) width / 256; + float yscale = (float) height / 10000; + + paint.setStrokeWidth(xscale); + paint.setColor(Color.WHITE); + + for (int x = 0; x < 256; x++) { + float xpos = x * xscale; + float ypos; + if (histogram[x] < 100000) { + ypos = histogram[x] * yscale; + } else { + ypos = 100000 * yscale; + } + canvas.drawLine(xpos, height, xpos + xscale, height - ypos, paint); + } + } + + public void onPreviewFrame(float[] data, VideoPlayerGLSurfaceView view) { + if (data != null) { +// if (count++ % 2 == 0) { + Message message = handler.obtainMessage(HISTOGRAM, view.getViewWidth(), view.getViewheight(), data); + message.sendToTarget(); +// } + } + } + + @Override + public boolean handleMessage(Message message) { + // process incoming messages here + histogram = (float[]) message.obj; +// int width = message.arg1; +// int height = message.arg2; +// byte[] data = (byte[]) message.obj; +// +// byte[] pixels = converter.convertToRGB(data, width, height); +// histogram = +// converter.luminanceHistogram(data, width, height); +// converter.histogram(pixels, width, height); + invalidate(); + return true; + } +} diff --git a/cgeDemo/src/main/java/org/wysaid/cgeDemo/VideoPlayerGLSurfaceView.java b/cgeDemo/src/main/java/org/wysaid/cgeDemo/VideoPlayerGLSurfaceView.java new file mode 100644 index 00000000..faa65267 --- /dev/null +++ b/cgeDemo/src/main/java/org/wysaid/cgeDemo/VideoPlayerGLSurfaceView.java @@ -0,0 +1,694 @@ +package org.wysaid.cgeDemo.view; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Matrix; +import android.graphics.PixelFormat; +import android.graphics.SurfaceTexture; +import android.media.MediaPlayer; +import android.net.Uri; +import android.opengl.GLES20; +import android.opengl.GLSurfaceView; +import android.os.Message; +import android.util.AttributeSet; +import android.util.Log; +import android.view.Surface; + +import org.wysaid.cgeDemo.VideoPlayerDemoActivity; +import org.wysaid.common.Common; +import org.wysaid.nativePort.CGEFrameRenderer; +import org.wysaid.texUtils.TextureRenderer; + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; + +import javax.microedition.khronos.egl.EGLConfig; +import javax.microedition.khronos.opengles.GL10; + +/** + * Created by wangyang on 15/11/26. + */ + +public class VideoPlayerGLSurfaceView extends GLSurfaceView implements GLSurfaceView.Renderer, SurfaceTexture.OnFrameAvailableListener { + + public static final String LOG_TAG = Common.LOG_TAG; + + private SurfaceTexture mSurfaceTexture; + private int mVideoTextureID; + private CGEFrameRenderer mFrameRenderer; + + + private TextureRenderer.Viewport mRenderViewport = new TextureRenderer.Viewport(); + private float[] mTransformMatrix = new float[16]; + private boolean mIsUsingMask = false; + + public boolean isUsingMask() { + return mIsUsingMask; + } + + private float mMaskAspectRatio = 1.0f; + + private int mViewWidth = 1000; + private int mViewHeight = 1000; + + public int getViewWidth() { + return mViewWidth; + } + + public int getViewheight() { + return mViewHeight; + } + + private int mVideoWidth = 1000; + private int mVideoHeight = 1000; + + private boolean mFitFullView = false; + + public void setFitFullView(boolean fit) { + mFitFullView = fit; + if (mFrameRenderer != null) + calcViewport(); + } + + private MediaPlayer mPlayer; + + private Uri mVideoUri; + + public interface PlayerInitializeCallback { + + //对player 进行初始化设置, 设置未默认启动的listener, 比如 bufferupdateListener. + void initPlayer(MediaPlayer player); + } + + public void setPlayerInitializeCallback(PlayerInitializeCallback callback) { + mPlayerInitCallback = callback; + } + + PlayerInitializeCallback mPlayerInitCallback; + + public interface PlayPreparedCallback { + void playPrepared(MediaPlayer player); + } + + PlayPreparedCallback mPreparedCallback; + + public interface PlayCompletionCallback { + void playComplete(MediaPlayer player); + + + /* + + what 取值: MEDIA_ERROR_UNKNOWN, + MEDIA_ERROR_SERVER_DIED + + extra 取值 MEDIA_ERROR_IO + MEDIA_ERROR_MALFORMED + MEDIA_ERROR_UNSUPPORTED + MEDIA_ERROR_TIMED_OUT + + returning false would cause the 'playComplete' to be called + */ + boolean playFailed(MediaPlayer mp, int what, int extra); + } + + PlayCompletionCallback mPlayCompletionCallback; + + public synchronized void setVideoUri(final Uri uri, final PlayPreparedCallback preparedCallback, final PlayCompletionCallback completionCallback) { + + mVideoUri = uri; + mPreparedCallback = preparedCallback; + mPlayCompletionCallback = completionCallback; + + if (mFrameRenderer != null) { + + queueEvent(new Runnable() { + @Override + public void run() { + Log.i(LOG_TAG, "setVideoUri..."); + + if (mSurfaceTexture == null || mVideoTextureID == 0) { + mVideoTextureID = Common.genSurfaceTextureID(); + mSurfaceTexture = new SurfaceTexture(mVideoTextureID); + mSurfaceTexture.setOnFrameAvailableListener(VideoPlayerGLSurfaceView.this); + } + _useUri(); + } + }); + } + } + + public synchronized void setFilterWithConfig(final String config) { + queueEvent(new Runnable() { + @Override + public void run() { + + if (mFrameRenderer != null) { + mFrameRenderer.setFilterWidthConfig(config); + } else { + Log.e(LOG_TAG, "setFilterWithConfig after release!!"); + } + } + }); + } + + public void setFilterIntensity(final float intensity) { + queueEvent(new Runnable() { + @Override + public void run() { + if (mFrameRenderer != null) { + mFrameRenderer.setFilterIntensity(intensity); + } else { + Log.e(LOG_TAG, "setFilterIntensity after release!!"); + } + } + }); + } + + public interface SetMaskBitmapCallback { + void setMaskOK(CGEFrameRenderer recorder); + } + + public void setMaskBitmap(final Bitmap bmp, final boolean shouldRecycle) { + setMaskBitmap(bmp, shouldRecycle, null); + } + + //注意, 当传入的bmp为null时, SetMaskBitmapCallback 不会执行. + public void setMaskBitmap(final Bitmap bmp, final boolean shouldRecycle, final SetMaskBitmapCallback callback) { + + queueEvent(new Runnable() { + @Override + public void run() { + + if (mFrameRenderer == null) { + Log.e(LOG_TAG, "setMaskBitmap after release!!"); + return; + } + + if (bmp == null) { + mFrameRenderer.setMaskTexture(0, 1.0f); + mIsUsingMask = false; + calcViewport(); + return; + } + + int texID = Common.genNormalTextureID(bmp, GLES20.GL_NEAREST, GLES20.GL_CLAMP_TO_EDGE); + + mFrameRenderer.setMaskTexture(texID, bmp.getWidth() / (float) bmp.getHeight()); + mIsUsingMask = true; + mMaskAspectRatio = bmp.getWidth() / (float) bmp.getHeight(); + + if (callback != null) { + callback.setMaskOK(mFrameRenderer); + } + + if (shouldRecycle) + bmp.recycle(); + + calcViewport(); + } + }); + } + + public synchronized MediaPlayer getPlayer() { + if (mPlayer == null) { + Log.e(LOG_TAG, "Player is not initialized!"); + } + return mPlayer; + } + + public interface OnCreateCallback { + void createOK(); + } + + private OnCreateCallback mOnCreateCallback; + + //定制一些初始化操作 + public void setOnCreateCallback(final OnCreateCallback callback) { + + assert callback != null : "无意义操作!"; + + if (mFrameRenderer == null) { + mOnCreateCallback = callback; + } else { + // 已经创建完毕, 直接执行 + queueEvent(new Runnable() { + @Override + public void run() { + callback.createOK(); + } + }); + } + } + + public VideoPlayerGLSurfaceView(Context context, AttributeSet attrs) { + super(context, attrs); + + Log.i(LOG_TAG, "MyGLSurfaceView Construct..."); + + setEGLContextClientVersion(2); + setEGLConfigChooser(8, 8, 8, 8, 8, 0); + getHolder().setFormat(PixelFormat.RGBA_8888); + setRenderer(this); + setRenderMode(RENDERMODE_WHEN_DIRTY); + setZOrderOnTop(true); + + Log.i(LOG_TAG, "MyGLSurfaceView Construct OK..."); + } + + @Override + public void onSurfaceCreated(GL10 gl, EGLConfig config) { + + Log.i(LOG_TAG, "video player onSurfaceCreated..."); + + GLES20.glDisable(GLES20.GL_DEPTH_TEST); + GLES20.glDisable(GLES20.GL_STENCIL_TEST); + + if (mOnCreateCallback != null) { + mOnCreateCallback.createOK(); + } + + if (mVideoUri != null && (mSurfaceTexture == null || mVideoTextureID == 0)) { + mVideoTextureID = Common.genSurfaceTextureID(); + mSurfaceTexture = new SurfaceTexture(mVideoTextureID); + mSurfaceTexture.setOnFrameAvailableListener(VideoPlayerGLSurfaceView.this); + _useUri(); + } + + } + + @Override + public void onSurfaceChanged(GL10 gl, int width, int height) { + GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + + mViewWidth = width; + mViewHeight = height; + + Log.i("执行到这", "mViewWidth=="+mViewWidth+"---mViewHeight=="+mViewHeight); + bufferByte = new byte[mViewWidth * mViewHeight * 4]; + byteBuffer = ByteBuffer.wrap(bufferByte); + + calcViewport(); + } + + //must be in the OpenGL thread! + public void release() { + + Log.i(LOG_TAG, "Video player view release..."); + + if (mPlayer != null) { + queueEvent(new Runnable() { + @Override + public void run() { + + Log.i(LOG_TAG, "Video player view release run..."); + + if (mPlayer != null) { + + mPlayer.setSurface(null); + if (mPlayer.isPlaying()) + mPlayer.stop(); + mPlayer.release(); + mPlayer = null; + } + + if (mFrameRenderer != null) { + mFrameRenderer.release(); + mFrameRenderer = null; + } + + if (mSurfaceTexture != null) { + mSurfaceTexture.release(); + mSurfaceTexture = null; + } + + if (mVideoTextureID != 0) { + GLES20.glDeleteTextures(1, new int[]{mVideoTextureID}, 0); + mVideoTextureID = 0; + } + + mIsUsingMask = false; + mPreparedCallback = null; + mPlayCompletionCallback = null; + + Log.i(LOG_TAG, "Video player view release OK"); + } + }); + } + } + + @Override + public void onPause() { + Log.i(LOG_TAG, "surfaceview onPause ..."); + + super.onPause(); + } + + @Override + public void onDrawFrame(GL10 gl) { + + if (mSurfaceTexture == null || mFrameRenderer == null) { + return; + } + + mSurfaceTexture.updateTexImage(); + + if (!mPlayer.isPlaying()) { + return; + } + + mSurfaceTexture.getTransformMatrix(mTransformMatrix); + mFrameRenderer.update(mVideoTextureID, mTransformMatrix); + + mFrameRenderer.runProc(); + + GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); + GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); + + GLES20.glEnable(GLES20.GL_BLEND); + mFrameRenderer.render(mRenderViewport.x, mRenderViewport.y, mRenderViewport.width, mRenderViewport.height); + GLES20.glDisable(GLES20.GL_BLEND); + + +// if (waveFormSwitch || lumFormSwitch) { +// byteBuffer.position(0); +// GLES20.glReadPixels(0, 0, mViewWidth, mViewHeight, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, byteBuffer); +// } + + } + + private long mTimeCount2 = 0; + private long mFramesCount2 = 0; + private long mLastTimestamp2 = 0; + + @Override + public void onFrameAvailable(SurfaceTexture surfaceTexture) { + requestRender(); + + if(waveFormSwitch ||lumFormSwitch){ + queueEvent(new Runnable() { + @Override + public void run() { + byteBuffer.position(0); + GLES20.glReadPixels(0, 0, mViewWidth, mViewHeight, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, byteBuffer); + } + }); + } + if (mLastTimestamp2 == 0) + mLastTimestamp2 = System.currentTimeMillis(); + + long currentTimestamp = System.currentTimeMillis(); + + ++mFramesCount2; + mTimeCount2 += currentTimestamp - mLastTimestamp2; + mLastTimestamp2 = currentTimestamp; + if (mTimeCount2 >= 1e3) { + Log.i(LOG_TAG, String.format("播放帧率: %d", mFramesCount2)); + mTimeCount2 -= 1e3; + mFramesCount2 = 0; + } + } + + private void calcViewport() { + float scaling; + + if (mIsUsingMask) { + scaling = mMaskAspectRatio; + } else { + scaling = mVideoWidth / (float) mVideoHeight; + } + + float viewRatio = mViewWidth / (float) mViewHeight; + float s = scaling / viewRatio; + + int w, h; + + if (mFitFullView) { + //撑满全部view(内容大于view) + if (s > 1.0) { + w = (int) (mViewHeight * scaling); + h = mViewHeight; + } else { + w = mViewWidth; + h = (int) (mViewWidth / scaling); + } + } else { + //显示全部内容(内容小于view) + if (s > 1.0) { + w = mViewWidth; + h = (int) (mViewWidth / scaling); + } else { + h = mViewHeight; + w = (int) (mViewHeight * scaling); + } + } + + mRenderViewport.width = w; + mRenderViewport.height = h; + mRenderViewport.x = (mViewWidth - mRenderViewport.width) / 2; + mRenderViewport.y = (mViewHeight - mRenderViewport.height) / 2; + Log.i(LOG_TAG, String.format("View port: %d, %d, %d, %d", mRenderViewport.x, mRenderViewport.y, mRenderViewport.width, mRenderViewport.height)); + } + + private void _useUri() { + + if (mPlayer != null) { + + mPlayer.stop(); + mPlayer.reset(); + + } else { + mPlayer = new MediaPlayer(); + } + + try { + mPlayer.setDataSource(getContext(), mVideoUri); + mPlayer.setSurface(new Surface(mSurfaceTexture)); + + } catch (Exception e) { + e.printStackTrace(); + Log.e(LOG_TAG, "useUri failed"); + + if (mPlayCompletionCallback != null) { + this.post(new Runnable() { + @Override + public void run() { + if (mPlayCompletionCallback != null) { + if (!mPlayCompletionCallback.playFailed(mPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, MediaPlayer.MEDIA_ERROR_UNSUPPORTED)) + mPlayCompletionCallback.playComplete(mPlayer); + } + } + }); + } + return; + } + + if (mPlayerInitCallback != null) { + mPlayerInitCallback.initPlayer(mPlayer); + } + + mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { + @Override + public void onCompletion(MediaPlayer mp) { + if (mPlayCompletionCallback != null) { + mPlayCompletionCallback.playComplete(mPlayer); + } + Log.i(LOG_TAG, "Video Play Over"); + } + }); + + mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { + @Override + public void onPrepared(MediaPlayer mp) { + mVideoWidth = mp.getVideoWidth(); + mVideoHeight = mp.getVideoHeight(); + + queueEvent(new Runnable() { + @Override + public void run() { + + if (mFrameRenderer == null) { + mFrameRenderer = new CGEFrameRenderer(); + } + + if (mFrameRenderer.init(mVideoWidth, mVideoHeight, mVideoWidth, mVideoHeight)) { + //Keep right orientation for source texture blending + mFrameRenderer.setSrcFlipScale(1.0f, -1.0f); + mFrameRenderer.setRenderFlipScale(1.0f, -1.0f); + } else { + Log.e(LOG_TAG, "Frame Recorder init failed!"); + } + + calcViewport(); + } + }); + + if (mPreparedCallback != null) { + mPreparedCallback.playPrepared(mPlayer); + } else { + mp.start(); + } + + Log.i(LOG_TAG, String.format("Video resolution 1: %d x %d", mVideoWidth, mVideoHeight)); + } + }); + + mPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { + @Override + public boolean onError(MediaPlayer mp, int what, int extra) { + + if (mPlayCompletionCallback != null) + return mPlayCompletionCallback.playFailed(mp, what, extra); + return false; + } + }); + + try { + mPlayer.prepareAsync(); + } catch (Exception e) { + Log.i(LOG_TAG, String.format("Error handled: %s, play failure handler would be called!", e.toString())); + if (mPlayCompletionCallback != null) { + this.post(new Runnable() { + @Override + public void run() { + if (mPlayCompletionCallback != null) { + if (!mPlayCompletionCallback.playFailed(mPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, MediaPlayer.MEDIA_ERROR_UNSUPPORTED)) + mPlayCompletionCallback.playComplete(mPlayer); + } + } + }); + } + } + + } + + public interface TakeShotCallback { + //传入的bmp可以由接收者recycle + void takeShotOK(Bitmap bmp); + } + + public synchronized void takeShot(final TakeShotCallback callback) { + assert callback != null : "callback must not be null!"; + + if (mFrameRenderer == null) { + Log.e(LOG_TAG, "Drawer not initialized!"); + callback.takeShotOK(null); + return; + } + + queueEvent(new Runnable() { + @Override + public void run() { + + IntBuffer buffer = IntBuffer.allocate(mRenderViewport.width * mRenderViewport.height); + + GLES20.glReadPixels(mRenderViewport.x, mRenderViewport.y, mRenderViewport.width, mRenderViewport.height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buffer); + Bitmap bmp = Bitmap.createBitmap(mRenderViewport.width, mRenderViewport.height, Bitmap.Config.ARGB_8888); + bmp.copyPixelsFromBuffer(buffer); + + Bitmap bmp2 = Bitmap.createBitmap(mRenderViewport.width, mRenderViewport.height, Bitmap.Config.ARGB_8888); + + Canvas canvas = new Canvas(bmp2); + Matrix mat = new Matrix(); + mat.setTranslate(0.0f, -mRenderViewport.height / 2.0f); + mat.postScale(1.0f, -1.0f); + mat.postTranslate(0.0f, mRenderViewport.height / 2.0f); + + canvas.drawBitmap(bmp, mat, null); + bmp.recycle(); + + callback.takeShotOK(bmp2); + } + }); + + } + + + private boolean waveFormSwitch = false; + private boolean lumFormSwitch = false; + private Thread dataThread; + private Thread lumThread; + private byte[] bufferByte; + private ByteBuffer byteBuffer; + + public void switchWaveform(boolean sw) { + waveFormSwitch = sw; + if (waveFormSwitch) { + dataThread = new Thread(new Runnable() { + @Override + public void run() { + while (waveFormSwitch) { + Message message = new Message(); + message.what = 0; + message.obj = byteToFloat(bufferByte); + VideoPlayerDemoActivity.getInstance().mHandler.sendMessage(message); + } + } + }); + dataThread.start(); + } else { + if (dataThread != null && dataThread.isAlive()) dataThread.interrupt(); + } + } + + public void switchLumForm(boolean sl) { + lumFormSwitch = sl; + if (lumFormSwitch) { + lumThread = new Thread(new Runnable() { + @Override + public void run() { + while (lumFormSwitch) { + Message message = new Message(); + message.what = 1; + message.obj = byteToFormFloat(bufferByte); + VideoPlayerDemoActivity.getInstance().mHandler.sendMessage(message); + } + } + }); + lumThread.start(); + } else { + if (lumThread != null && lumThread.isAlive()) lumThread.interrupt(); + } + } + + public float[] byteToFormFloat(byte[] bytes) { + float[] fGroup = new float[256]; + for (int i = 0; i < bytes.length; i += 4) { + + String hex = Integer.toHexString(bytes[i] & 0xFF); + + if (hex.length() == 1) { + fGroup[toInt(hex)] += 1; + } else if (hex.length() == 2) { + fGroup[toInt(hex.substring(0, 1)) * 16 + toInt(hex.substring(1, 2))] += 1; + } + + } + return fGroup; + } + + public float[] byteToFloat(byte[] bytes) { + float[] fGroup = new float[bytes.length / 4]; + int j = 0; + for (int i = 0; i < bytes.length; i += 4) { +// for (int i = 0; i < bytes.length; i++) { + String hex = Integer.toHexString(bytes[i] & 0xFF); + + if (hex.length() == 1) { + fGroup[j] = (((toInt(hex) - 0.0f) * (1.0f - (-1.0f)) / (255.0f - 0.0f)) + (-1f)); + } else if (hex.length() == 2) { + fGroup[j] = (((toInt(hex.substring(0, 1)) * 16 + toInt(hex.substring(1, 2)) - 0.0f) * (1.0f - (-1.0f)) / (255.0f - 0.0f)) + (-1f)); + + } + + j++; + } + return fGroup; + } + + private static int toInt(String c) { + int b = "0123456789abcdef".indexOf(c); + return b; + } + +} From 4eb0cd21e52ecaf4b8c7fc4201ce70e673b77be3 Mon Sep 17 00:00:00 2001 From: xiaodi86 <51728141+xiaodi86@users.noreply.github.com> Date: Thu, 29 Dec 2022 11:21:57 +0800 Subject: [PATCH 10/20] Add files via upload --- .../java/org/wysaid/cgeDemo/MainActivity.java | 116 +++++++++++++++--- .../cgeDemo/VideoPlayerDemoActivity.java | 101 ++++++++++++++- 2 files changed, 197 insertions(+), 20 deletions(-) diff --git a/cgeDemo/src/main/java/org/wysaid/cgeDemo/MainActivity.java b/cgeDemo/src/main/java/org/wysaid/cgeDemo/MainActivity.java index 95277940..8f61b0d8 100644 --- a/cgeDemo/src/main/java/org/wysaid/cgeDemo/MainActivity.java +++ b/cgeDemo/src/main/java/org/wysaid/cgeDemo/MainActivity.java @@ -14,25 +14,89 @@ import android.widget.Button; import android.widget.LinearLayout; -import java.io.IOException; -import java.io.InputStream; - import org.wysaid.common.Common; -import org.wysaid.myUtils.MsgUtil; import org.wysaid.nativePort.CGENativeLibrary; +import java.io.IOException; +import java.io.InputStream; + public class MainActivity extends AppCompatActivity { +// uniform float radius; +// uniform vec2 center; +// uniform vec4 borderColor; +// uniform float borderThickness; +// +// void main() +// { +// vec2 textureCoordinateToUse = textureCoordinate; +// float dist = distance(center, textureCoordinate); +// +// if (dist < radius && factor > 0.0) { +// textureCoordinateToUse -= center; +// textureCoordinateToUse = textureCoordinateToUse / factor; +// textureCoordinateToUse += center; +// } +// +// gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse); +// } +// +// void main() +// { +// vec4 color = texture2D(inputImageTexture, textureCoordinate); +// +// //vec4 color = vec4(255.0,255.0,255.0,1.0); +// +// vec2 uv = textureCoordinate.xy - center; +// +// float d = sqrt(dot(uv,uv)); +// +// //float t = 1.0 - smoothstep(radius-borderThickness,radius, d); +// float t = 1.0 - smoothstep(0.0, borderThickness, abs(radius-d)); +// gl_FragColor = vec4(color.rgb,color.a*t); +// } public static final String LOG_TAG = "wysaid"; public static final String EFFECT_CONFIGS[] = { + "@style waveform 0.5 0.5 200. 150. 0.0 0.0 0.0 ", "@style hist 0.5 0.5 200. 150. 0.0 0.0 0.0 ", - "", + + "@style 3x3Texture 0.0002 0.0002 ", +// "@pixblend cl 1 0 0 0 90", +// "@pixblend cl 255 0 0 255 100", +// "@blend colorbw 255 0 0 255 100", +// "@style stroke 255.0 0.0 0.0 0.2 2. 3. ", + "@style histogram 255.0 255.0 255.0", + + //"@style waveform 255.0 0.0 0.0 0.02", + "@style drawbg 0.5 0.5 0.2 0.2 0.02", + "@style waveform 0.5 0.5 0.5 0.5 255.0 0.0 0.0 0.1", + "@style drawbg 0.05 0.8 0.35 0.4 0.02 @style waveform 0.05 0.8 0.35 0.4 255.0 0.0 0.0 0.02", + + "@adjust level 0.66 0.23 0.44 ", + //"@blend overlay histogram_bg.png 100", + "@style zebraCrossing histogram_bg.png", + + "@style lumrange 0.6", "@curve RGB(0,255)(255,0) @style cm mapping0.jpg 80 80 8 3", // ASCII art (字符画效果) "@beautify face 1 480 640", //Beautify - "@adjust lut edgy_amber.png", + + "@style falsecolor 1.0", + +// "@style falsecolor colorscale_hsv.jpg", +// "@style falsecolor colorscale_jet.jpg", +// "@style falsecolor colorscale_rainbow.jpg", +// "@style falsecolor colorscale_spring.jpg", +// "@style lut colorscale_autumn.jpg", +// "@style lut colorscale_bone.jpg", +// "@style lut colorscale_cool.jpg", +// "@style lut colorscale_hot.jpg", +// "@style lut colorscale_summer.jpg", +// "@style lut colorscale_winter.jpg", + //11 + "@style fcolor 1.0 ", "@adjust lut filmstock.png", "@adjust lut foggy_night.png", "@adjust lut late_sunset.png", @@ -42,26 +106,46 @@ public class MainActivity extends AppCompatActivity { "@blur lerp 1", //can adjust blur mix "#unpack @dynamic wave 1", //can adjust speed "@dynamic wave 0.5", //can adjust wave mix + //21 "#unpack @style sketch 0.9", "#unpack @krblend sr hehe.jpg 100 ", "#unpack @krblend ol hehe.jpg 100", "#unpack @krblend add hehe.jpg 100", + "#unpack @krblend add histogram_bg.png 100", "#unpack @krblend darken hehe.jpg 100", "@beautify bilateral 100 3.5 2 ", - "@style crosshatch 0.01 0.003 ", - "@style edge 1 2 ", - "@style edge 1 2 @curve RGB(0, 255)(255, 0) ", + //27 + "", + "@style edge 0.2 2 1 ", + "@style edge 0.5 2 1", + "@style edge 1 1 1", + "@style sobel 0.1 2 ", + "@style sobel 0.5 2", + "@style sobel 1 1", + "@style drawround 0.5 0.5 0.05 0.02 255.0 0.0 0.0", + "@style magnifier 0.5 0.5 1.5 0.2 @style drawsquare 0.5 0.5 255.0 0.0 0.0 0.003 0.2",// @style drawround 0.5 0.5 0.003 0.2 255.0 0.0 0.0 + //36 + "@style singlecolor 255.0 0.0 0.0 0.2", + "@pixblend cb 255 0 0 255 100", +// "@pixblend ol 255 0 0 255 100", + "@style drawround 0.5 0.5 0.5 0.2 255.0 0.0 0.0", + "@style drawsquare 0.5 0.5 255.0 0.0 0.0 0.003 0.2", + "@style drawcross 0.5 0.5 255.0 0.0 0.0", +// "@style toon 0.2 10.0 ", "@style edge 1 2 @curve RGB(0, 255)(255, 0) @adjust saturation 0 @adjust level 0.33 0.71 0.93 ", "@adjust level 0.31 0.54 0.13 ", - "#unpack @style emboss 1 2 2 ", - "@style halftone 1.2 ", + //43 + "#unpack @style emboss 1 1 1 ", + "@style halftone 1.5 ", "@vigblend overlay 255 0 0 255 100 0.12 0.54 0.5 0.5 3 ", "@curve R(0, 0)(63, 101)(200, 84)(255, 255)G(0, 0)(86, 49)(180, 183)(255, 255)B(0, 0)(19, 17)(66, 41)(97, 92)(137, 156)(194, 211)(255, 255)RGB(0, 0)(82, 36)(160, 183)(255, 255) ", "@adjust exposure 0.98 ", "@adjust shadowhighlight -200 200 ", "@adjust sharpen 10 1.5 ", + //50 颜色平衡 "@adjust colorbalance 0.99 0.52 -0.31 ", - "@adjust level 0.66 0.23 0.44 ", + "@style crosshatch 0.03 0.002", + "@style min", "@style max", "@style haze 0.5 -0.14 1 0.8 1 ", @@ -193,7 +277,7 @@ public static class DemoClassDescription { new DemoClassDescription("TestCaseActivity", "Test Cases") }; - public class DemoButton extends Button implements View.OnClickListener { + public class DemoButton extends android.support.v7.widget.AppCompatButton implements View.OnClickListener { private DemoClassDescription mDemo; public void setDemo(DemoClassDescription demo) { @@ -209,12 +293,6 @@ public void setDemo(DemoClassDescription demo) { @Override public void onClick(final View v) { - - if (mDemo.activityName == "FaceTrackingDemoActivity") { - MsgUtil.toastMsg(v.getContext(), "Error: Please checkout the branch 'face_features' for this demo!"); - return; - } - Log.i(LOG_TAG, String.format("%s is clicked!", mDemo.title)); Class cls; try { diff --git a/cgeDemo/src/main/java/org/wysaid/cgeDemo/VideoPlayerDemoActivity.java b/cgeDemo/src/main/java/org/wysaid/cgeDemo/VideoPlayerDemoActivity.java index c48ec892..6968bea2 100755 --- a/cgeDemo/src/main/java/org/wysaid/cgeDemo/VideoPlayerDemoActivity.java +++ b/cgeDemo/src/main/java/org/wysaid/cgeDemo/VideoPlayerDemoActivity.java @@ -1,11 +1,14 @@ package org.wysaid.cgeDemo; +import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.media.MediaPlayer; import android.net.Uri; +import android.os.Handler; +import android.os.Message; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; @@ -14,14 +17,17 @@ import android.view.View; import android.widget.Button; import android.widget.LinearLayout; +import android.widget.RelativeLayout; import android.widget.SeekBar; +import org.wysaid.cgeDemo.view.ChartGLSurfaceView; +import org.wysaid.cgeDemo.view.HistogramView; +import org.wysaid.cgeDemo.view.VideoPlayerGLSurfaceView; import org.wysaid.common.Common; import org.wysaid.myUtils.FileUtil; import org.wysaid.myUtils.ImageUtil; import org.wysaid.myUtils.MsgUtil; import org.wysaid.nativePort.CGEFrameRenderer; -import org.wysaid.view.VideoPlayerGLSurfaceView; public class VideoPlayerDemoActivity extends AppCompatActivity { @@ -34,6 +40,36 @@ public class VideoPlayerDemoActivity extends AppCompatActivity { public static final int REQUEST_CODE_PICK_VIDEO = 1; + public static VideoPlayerDemoActivity instance = null; + private ChartGLSurfaceView chartView; + private HistogramView histogram; + RelativeLayout mGLViewGroup; + Button mHistBtn; + Button mWaveBtn; + + public Handler mHandler = new Handler(new Handler.Callback() { + @Override + public boolean handleMessage(Message msg) { + switch (msg.what) { + case 0: + if (chartView != null) { + chartView.setChartData((float[]) msg.obj); + } + break; + + case 1: + + if (histogram != null) { + histogram.onPreviewFrame((float[]) msg.obj, mPlayerView); + } + break; + default: + break; + } + return false; + } + }); + private VideoPlayerGLSurfaceView.PlayCompletionCallback playCompletionCallback = new VideoPlayerGLSurfaceView.PlayCompletionCallback() { @Override public void playComplete(MediaPlayer player) { @@ -48,6 +84,7 @@ public boolean playFailed(MediaPlayer player, final int what, final int extra) { } }; + @SuppressLint("AppCompatCustomView") class MyVideoButton extends Button implements View.OnClickListener { Uri videoUri; @@ -78,6 +115,35 @@ public void run() { } } + public static VideoPlayerDemoActivity getInstance() { + return instance; + } + + public void setWStatue(boolean statue) { + mPlayerView.switchWaveform(statue); + } + + //隐藏波形图 + public void hideWaveform() { + if (chartView != null) { + setWStatue(false); + mGLViewGroup.removeView(chartView); + chartView = null; + } + } + + public void setHStatue(boolean statue) { + mPlayerView.switchLumForm(statue); + } + + public void hideBrightness() { + if (histogram != null) { + setHStatue(false); + mGLViewGroup.removeView(histogram); + histogram = null; + } + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -86,6 +152,38 @@ protected void onCreate(Bundle savedInstanceState) { mPlayerView.setZOrderOnTop(false); mPlayerView.setZOrderMediaOverlay(true); + instance = this; + + mGLViewGroup = (RelativeLayout) findViewById(R.id.sv_device_group); + mHistBtn = (Button) findViewById(R.id.histgramBtn); + mHistBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + if (histogram == null) { + histogram = new HistogramView(VideoPlayerDemoActivity.this); + mGLViewGroup.addView(histogram); + setHStatue(true); + } else { + hideBrightness(); + } + } + }); + + mWaveBtn = (Button) findViewById(R.id.waveformBtn); + mWaveBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (chartView == null) { + chartView = new ChartGLSurfaceView(VideoPlayerDemoActivity.this); + mGLViewGroup.addView(chartView); + setWStatue(true); + } else { + hideWaveform(); + } + } + }); + mShapeBtn = (Button) findViewById(R.id.switchShapeBtn); mShapeBtn.setOnClickListener(new View.OnClickListener() { @@ -318,4 +416,5 @@ public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } + } From be80cb761036834398c3378fa3675078df1c6d4d Mon Sep 17 00:00:00 2001 From: xiaodi86 <51728141+xiaodi86@users.noreply.github.com> Date: Thu, 29 Dec 2022 11:24:05 +0800 Subject: [PATCH 11/20] Update activity_video_player_demo.xml --- .../res/layout/activity_video_player_demo.xml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cgeDemo/src/main/res/layout/activity_video_player_demo.xml b/cgeDemo/src/main/res/layout/activity_video_player_demo.xml index a74ddf00..9f378f4a 100644 --- a/cgeDemo/src/main/res/layout/activity_video_player_demo.xml +++ b/cgeDemo/src/main/res/layout/activity_video_player_demo.xml @@ -21,6 +21,12 @@ android:layout_height="match_parent"/> + + + +