From 227b47625d7482b5b47ad0e4c70ce0a246236ade Mon Sep 17 00:00:00 2001 From: Benjamin Hendricks Date: Thu, 19 Sep 2013 14:40:45 -0700 Subject: Camera2Tests: Add SmartCamera App Bug: 10818732 Change-Id: I6ac08ecab3a1e04116be2f7764d0d5d4f29c5cd9 --- tests/Camera2Tests/SmartCamera/Android.mk | 14 + tests/Camera2Tests/SmartCamera/README.txt | 60 + .../SmartCamera/SimpleCamera/.classpath | 8 + .../Camera2Tests/SmartCamera/SimpleCamera/.project | 33 + .../SmartCamera/SimpleCamera/Android.mk | 40 + .../SmartCamera/SimpleCamera/AndroidManifest.xml | 38 + .../SimpleCamera/assets/0002_000390.jpg | Bin 0 -> 124623 bytes .../frsdk_expression_modules/BCLeyesclosed_100.emd | Bin 0 -> 15152 bytes .../assets/frsdk_expression_modules/BCLjoy_100.emd | Bin 0 -> 15055 bytes .../SmartCamera/SimpleCamera/ic_launcher-web.png | Bin 0 -> 36739 bytes .../SmartCamera/SimpleCamera/jni/Android.mk | 49 + .../SmartCamera/SimpleCamera/jni/Application.mk | 16 + .../SmartCamera/SimpleCamera/jni/brightness.cpp | 52 + .../SmartCamera/SimpleCamera/jni/brightness.h | 36 + .../SmartCamera/SimpleCamera/jni/colorspace.cpp | 177 ++ .../SmartCamera/SimpleCamera/jni/colorspace.h | 50 + .../SmartCamera/SimpleCamera/jni/contrast.cpp | 51 + .../SmartCamera/SimpleCamera/jni/contrast.h | 36 + .../SmartCamera/SimpleCamera/jni/exposure.cpp | 70 + .../SmartCamera/SimpleCamera/jni/exposure.h | 39 + .../SmartCamera/SimpleCamera/jni/frametovalues.cpp | 76 + .../SmartCamera/SimpleCamera/jni/frametovalues.h | 42 + .../SmartCamera/SimpleCamera/jni/histogram.cpp | 128 ++ .../SmartCamera/SimpleCamera/jni/histogram.h | 46 + .../SmartCamera/SimpleCamera/jni/imgprocutil.h | 32 + .../SmartCamera/SimpleCamera/jni/pixelutils.cpp | 38 + .../SmartCamera/SimpleCamera/jni/pixelutils.h | 39 + .../SmartCamera/SimpleCamera/jni/sobeloperator.cpp | 116 ++ .../SmartCamera/SimpleCamera/jni/sobeloperator.h | 37 + .../SmartCamera/SimpleCamera/jni/stats_scorer.cpp | 70 + .../SmartCamera/SimpleCamera/jni/stats_scorer.h | 44 + .../SmartCamera/SimpleCamera/proguard-project.txt | 20 + .../SmartCamera/SimpleCamera/project.properties | 15 + .../res/drawable-hdpi/black_screen.jpg | Bin 0 -> 594456 bytes .../SimpleCamera/res/drawable-hdpi/ic_launcher.png | Bin 0 -> 3034 bytes .../res/drawable-hdpi/ic_menu_gallery.png | Bin 0 -> 2379 bytes .../res/drawable-hdpi/ic_menu_quill.png | Bin 0 -> 2383 bytes .../res/drawable-hdpi/ic_menu_save.png | Bin 0 -> 2050 bytes .../SimpleCamera/res/drawable-ldpi/ic_launcher.png | Bin 0 -> 1488 bytes .../SimpleCamera/res/drawable-mdpi/ic_launcher.png | Bin 0 -> 1953 bytes .../res/drawable-nodpi/android_figure.png | Bin 0 -> 14383 bytes .../SimpleCamera/res/drawable-nodpi/oldframe.png | Bin 0 -> 349543 bytes .../SimpleCamera/res/drawable-nodpi/polaroid.png | Bin 0 -> 151622 bytes .../res/drawable-xhdpi/ic_launcher.png | Bin 0 -> 3954 bytes .../SimpleCamera/res/layout/imageview.xml | 22 + .../SimpleCamera/res/layout/simplecamera.xml | 97 + .../SimpleCamera/res/raw/camera_graph.xml | 182 ++ .../SimpleCamera/res/values-v11/styles.xml | 5 + .../SimpleCamera/res/values-v14/styles.xml | 5 + .../SimpleCamera/res/values/strings.xml | 38 + .../SmartCamera/SimpleCamera/res/values/styles.xml | 5 + .../src/androidx/media/filterfw/BackingStore.java | 929 ++++++++++ .../src/androidx/media/filterfw/BranchFilter.java | 88 + .../androidx/media/filterfw/BrightnessFilter.java | 88 + .../androidx/media/filterfw/CameraStreamer.java | 1906 ++++++++++++++++++++ .../src/androidx/media/filterfw/ColorSpace.java | 137 ++ .../media/filterfw/ColorfulnessFilter.java | 93 + .../src/androidx/media/filterfw/CropFilter.java | 165 ++ .../src/androidx/media/filterfw/Filter.java | 766 ++++++++ .../src/androidx/media/filterfw/FilterFactory.java | 150 ++ .../src/androidx/media/filterfw/FilterGraph.java | 567 ++++++ .../src/androidx/media/filterfw/Frame.java | 203 +++ .../src/androidx/media/filterfw/FrameBuffer1D.java | 103 ++ .../src/androidx/media/filterfw/FrameBuffer2D.java | 48 + .../src/androidx/media/filterfw/FrameImage2D.java | 184 ++ .../src/androidx/media/filterfw/FrameManager.java | 473 +++++ .../src/androidx/media/filterfw/FrameQueue.java | 184 ++ .../androidx/media/filterfw/FrameSlotSource.java | 49 + .../androidx/media/filterfw/FrameSlotTarget.java | 43 + .../src/androidx/media/filterfw/FrameType.java | 430 +++++ .../src/androidx/media/filterfw/FrameValue.java | 50 + .../src/androidx/media/filterfw/FrameValues.java | 155 ++ .../src/androidx/media/filterfw/GLToolbox.java | 194 ++ .../src/androidx/media/filterfw/GraphExporter.java | 199 ++ .../androidx/media/filterfw/GraphInputSource.java | 58 + .../androidx/media/filterfw/GraphOutputTarget.java | 60 + .../src/androidx/media/filterfw/GraphReader.java | 576 ++++++ .../src/androidx/media/filterfw/GraphRunner.java | 1023 +++++++++++ .../src/androidx/media/filterfw/ImageShader.java | 793 ++++++++ .../src/androidx/media/filterfw/InputPort.java | 327 ++++ .../src/androidx/media/filterfw/MffContext.java | 470 +++++ .../src/androidx/media/filterfw/MotionSensor.java | 92 + .../media/filterfw/NewChromaHistogramFilter.java | 117 ++ .../src/androidx/media/filterfw/NormFilter.java | 63 + .../src/androidx/media/filterfw/OutputPort.java | 193 ++ .../src/androidx/media/filterfw/PixelUtils.java | 79 + .../src/androidx/media/filterfw/RenderTarget.java | 444 +++++ .../src/androidx/media/filterfw/ResizeFilter.java | 41 + .../src/androidx/media/filterfw/RotateFilter.java | 80 + .../src/androidx/media/filterfw/ScaleFilter.java | 66 + .../src/androidx/media/filterfw/Signature.java | 241 +++ .../src/androidx/media/filterfw/SimpleCache.java | 38 + .../src/androidx/media/filterfw/SlotFilter.java | 36 + .../src/androidx/media/filterfw/SobelFilter.java | 174 ++ .../src/androidx/media/filterfw/StatsFilter.java | 120 ++ .../media/filterfw/SurfaceHolderTarget.java | 197 ++ .../androidx/media/filterfw/TextViewTarget.java | 66 + .../src/androidx/media/filterfw/TextureSource.java | 121 ++ .../src/androidx/media/filterfw/Throughput.java | 52 + .../androidx/media/filterfw/ThroughputFilter.java | 95 + .../media/filterfw/ToGrayValuesFilter.java | 124 ++ .../androidx/media/filterfw/ToStringFilter.java | 51 + .../androidx/media/filterfw/TransformUtils.java | 78 + .../src/androidx/media/filterfw/ValueTarget.java | 81 + .../androidx/media/filterfw/VariableSource.java | 60 + .../src/androidx/media/filterfw/ViewFilter.java | 159 ++ .../media/filterfw/decoder/AudioSample.java | 31 + .../media/filterfw/decoder/AudioTrackDecoder.java | 119 ++ .../filterfw/decoder/CpuVideoTrackDecoder.java | 243 +++ .../media/filterfw/decoder/DecoderUtil.java | 33 + .../filterfw/decoder/GpuVideoTrackDecoder.java | 210 +++ .../media/filterfw/decoder/MediaDecoder.java | 426 +++++ .../media/filterfw/decoder/TrackDecoder.java | 178 ++ .../media/filterfw/decoder/VideoTrackDecoder.java | 108 ++ .../src/androidx/media/filterfw/geometry/Quad.java | 346 ++++ .../samples/simplecamera/AverageFilter.java | 72 + .../samples/simplecamera/AvgBrightnessFilter.java | 75 + .../samples/simplecamera/CSVWriterFilter.java | 147 ++ .../samples/simplecamera/Camera2Source.java | 255 +++ .../samples/simplecamera/CameraTestThread.java | 93 + .../samples/simplecamera/ContrastRatioFilter.java | 79 + .../samples/simplecamera/ExposureFilter.java | 111 ++ .../samples/simplecamera/FaceSquareFilter.java | 159 ++ .../simplecamera/FloatArrayToSizeFilter.java | 68 + .../simplecamera/FloatArrayToStrFilter.java | 69 + .../samples/simplecamera/IfElseFilter.java | 70 + .../samples/simplecamera/ImageConstants.java | 26 + .../samples/simplecamera/ImageGoodnessFilter.java | 410 +++++ .../samples/simplecamera/MotionSensorWTime.java | 118 ++ .../filterfw/samples/simplecamera/SmartCamera.java | 288 +++ .../samples/simplecamera/WaveTriggerFilter.java | 83 + .../SmartCamera/SimpleCamera/tests/Android.mk | 39 + .../SimpleCamera/tests/AndroidManifest.xml | 31 + .../SimpleCamera/tests/project.properties | 16 + .../SmartCamera/SimpleCamera/tests/res/.README | 3 + .../androidx/media/filterfw/FrameSourceFilter.java | 69 + .../androidx/media/filterfw/FrameTargetFilter.java | 58 + .../androidx/media/filterfw/MffFilterTestCase.java | 179 ++ .../src/androidx/media/filterfw/MffTestCase.java | 71 + .../samples/simplecamera/AverageFilterTest.java | 53 + .../simplecamera/AvgBrightnessFilterTest.java | 57 + .../simplecamera/ContrastRatioFilterTest.java | 67 + .../samples/simplecamera/ExposureFilterTest.java | 64 + .../samples/simplecamera/FaceSquareFilterTest.java | 172 ++ .../simplecamera/FloatArrayToSizeFilterTest.java | 49 + .../simplecamera/FloatArrayToStrFilterTest.java | 50 + .../samples/simplecamera/IfElseFilterTest.java | 111 ++ .../simplecamera/ImageGoodnessFilterTest.java | 179 ++ 148 files changed, 20290 insertions(+) create mode 100644 tests/Camera2Tests/SmartCamera/Android.mk create mode 100644 tests/Camera2Tests/SmartCamera/README.txt create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/.classpath create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/.project create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/Android.mk create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/AndroidManifest.xml create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/assets/0002_000390.jpg create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/assets/frsdk_expression_modules/BCLeyesclosed_100.emd create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/assets/frsdk_expression_modules/BCLjoy_100.emd create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/ic_launcher-web.png create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/Android.mk create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/Application.mk create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/brightness.cpp create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/brightness.h create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/colorspace.cpp create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/colorspace.h create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/contrast.cpp create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/contrast.h create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/exposure.cpp create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/exposure.h create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/frametovalues.cpp create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/frametovalues.h create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/histogram.cpp create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/histogram.h create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/imgprocutil.h create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/pixelutils.cpp create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/pixelutils.h create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/sobeloperator.cpp create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/sobeloperator.h create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/stats_scorer.cpp create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/jni/stats_scorer.h create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/proguard-project.txt create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/project.properties create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/black_screen.jpg create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/ic_launcher.png create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/ic_menu_gallery.png create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/ic_menu_quill.png create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/ic_menu_save.png create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-ldpi/ic_launcher.png create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-mdpi/ic_launcher.png create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-nodpi/android_figure.png create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-nodpi/oldframe.png create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-nodpi/polaroid.png create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-xhdpi/ic_launcher.png create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/res/layout/imageview.xml create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/res/layout/simplecamera.xml create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/res/raw/camera_graph.xml create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/res/values-v11/styles.xml create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/res/values-v14/styles.xml create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/res/values/strings.xml create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/res/values/styles.xml create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/BackingStore.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/BranchFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/BrightnessFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/CameraStreamer.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/ColorSpace.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/ColorfulnessFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/CropFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/Filter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/FilterFactory.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/FilterGraph.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/Frame.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/FrameBuffer1D.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/FrameBuffer2D.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/FrameImage2D.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/FrameManager.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/FrameQueue.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/FrameSlotSource.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/FrameSlotTarget.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/FrameType.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/FrameValue.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/FrameValues.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/GLToolbox.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/GraphExporter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/GraphInputSource.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/GraphOutputTarget.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/GraphReader.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/GraphRunner.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/ImageShader.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/InputPort.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/MffContext.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/MotionSensor.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/NewChromaHistogramFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/NormFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/OutputPort.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/PixelUtils.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/RenderTarget.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/ResizeFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/RotateFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/ScaleFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/Signature.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/SimpleCache.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/SlotFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/SobelFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/StatsFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/SurfaceHolderTarget.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/TextViewTarget.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/TextureSource.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/Throughput.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/ThroughputFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/ToGrayValuesFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/ToStringFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/TransformUtils.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/ValueTarget.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/VariableSource.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/ViewFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/decoder/AudioSample.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/decoder/AudioTrackDecoder.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/decoder/CpuVideoTrackDecoder.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/decoder/DecoderUtil.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/decoder/GpuVideoTrackDecoder.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/decoder/MediaDecoder.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/decoder/TrackDecoder.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/decoder/VideoTrackDecoder.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/geometry/Quad.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/samples/simplecamera/AverageFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/samples/simplecamera/AvgBrightnessFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/samples/simplecamera/CSVWriterFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/samples/simplecamera/Camera2Source.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/samples/simplecamera/CameraTestThread.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/samples/simplecamera/ContrastRatioFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/samples/simplecamera/ExposureFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/samples/simplecamera/FaceSquareFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/samples/simplecamera/FloatArrayToSizeFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/samples/simplecamera/FloatArrayToStrFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/samples/simplecamera/IfElseFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/samples/simplecamera/ImageConstants.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/samples/simplecamera/ImageGoodnessFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/samples/simplecamera/MotionSensorWTime.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/samples/simplecamera/SmartCamera.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx/media/filterfw/samples/simplecamera/WaveTriggerFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/tests/Android.mk create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/tests/AndroidManifest.xml create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/tests/project.properties create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/tests/res/.README create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/tests/src/androidx/media/filterfw/FrameSourceFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/tests/src/androidx/media/filterfw/FrameTargetFilter.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/tests/src/androidx/media/filterfw/MffFilterTestCase.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/tests/src/androidx/media/filterfw/MffTestCase.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/tests/src/androidx/media/filterfw/samples/simplecamera/AverageFilterTest.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/tests/src/androidx/media/filterfw/samples/simplecamera/AvgBrightnessFilterTest.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/tests/src/androidx/media/filterfw/samples/simplecamera/ContrastRatioFilterTest.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/tests/src/androidx/media/filterfw/samples/simplecamera/ExposureFilterTest.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/tests/src/androidx/media/filterfw/samples/simplecamera/FaceSquareFilterTest.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/tests/src/androidx/media/filterfw/samples/simplecamera/FloatArrayToSizeFilterTest.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/tests/src/androidx/media/filterfw/samples/simplecamera/FloatArrayToStrFilterTest.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/tests/src/androidx/media/filterfw/samples/simplecamera/IfElseFilterTest.java create mode 100644 tests/Camera2Tests/SmartCamera/SimpleCamera/tests/src/androidx/media/filterfw/samples/simplecamera/ImageGoodnessFilterTest.java (limited to 'tests/Camera2Tests') diff --git a/tests/Camera2Tests/SmartCamera/Android.mk b/tests/Camera2Tests/SmartCamera/Android.mk new file mode 100644 index 0000000..3fa8f54 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/Android.mk @@ -0,0 +1,14 @@ +# Copyright 2013 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +include $(call all-subdir-makefiles) diff --git a/tests/Camera2Tests/SmartCamera/README.txt b/tests/Camera2Tests/SmartCamera/README.txt new file mode 100644 index 0000000..1fff3ab --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/README.txt @@ -0,0 +1,60 @@ +Copyright 2013 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + +Smart Camera / Auto Snapshot (formerly named SimpleCamera) ReadMe + +Created by: Benjamin W Hendricks + +How to build the application: +From root: make SmartCamera will build the apk for generic +Otherwise, to build the application for a specific device, lunch to that device +and then run mm while in the SimpleCamera directory. +Then take the given Install path (out/target/.../SmartCamera.apk) +and run adb install out/target/.../SmartCamera.apk. The application should +then appear in the launcher of your device. +You might also need to run adb sync after building to sync the +libsmartcamera_jni library +Summarized: + make SmartCamera + adb remount + adb sync + adb install -r $ANDROID_PRODUCT_OUT/data/app/SmartCamera.apk + +How to run the application: +On a Nexus 7, open up the application from the launcher, and the camera preview +should appear. From there, you can go to the gallery with the gallery button or +press start to start capturing images. You can also change the number of images +to be captured by changing the number on the spinner (between 1-10). + +What does it do: +The application tries to take good pictures for you automatically when in the +start mode. On stop, the application will capture whatever images are in the +bottom preview and save them to the Gallery. It does this by looking at the +following image features: + - Sharpness + - Brightness + - Motion of the device + - Colorfulness + - Contrast + - Exposure (over/under) + +By comparing each of these features frame by frame, a score is calculated to +determine whether an image is better or worse than the previous few frames, +and from that score I can determine the great images from the bad ones. + +What libraries does it use: +- Mobile Filter Framework (MFF) +- Camera2 API +- Renderscript diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/.classpath b/tests/Camera2Tests/SmartCamera/SimpleCamera/.classpath new file mode 100644 index 0000000..3f9691c --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/.project b/tests/Camera2Tests/SmartCamera/SimpleCamera/.project new file mode 100644 index 0000000..2517e2d --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/.project @@ -0,0 +1,33 @@ + + + CameraShoot + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/Android.mk b/tests/Camera2Tests/SmartCamera/SimpleCamera/Android.mk new file mode 100644 index 0000000..ed0c294 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/Android.mk @@ -0,0 +1,40 @@ +# Copyright (C) 2013 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ifneq ($(TARGET_BUILD_JAVA_SUPPORT_LEVEL),) + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := tests + +LOCAL_PROGUARD_ENABLED := disabled + +# comment it out for now since we need use some hidden APIs +LOCAL_SDK_VERSION := current + +LOCAL_SRC_FILES := \ + $(call all-java-files-under, src) \ + $(call all-renderscript-files-under, src) + +LOCAL_PACKAGE_NAME := SmartCamera +LOCAL_JNI_SHARED_LIBRARIES := libsmartcamera_jni + +include $(BUILD_PACKAGE) + +# Include packages in subdirectories +include $(call all-makefiles-under,$(LOCAL_PATH)) + +endif diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/AndroidManifest.xml b/tests/Camera2Tests/SmartCamera/SimpleCamera/AndroidManifest.xml new file mode 100644 index 0000000..0681868 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/AndroidManifest.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/assets/0002_000390.jpg b/tests/Camera2Tests/SmartCamera/SimpleCamera/assets/0002_000390.jpg new file mode 100644 index 0000000..9b4bce4 Binary files /dev/null and b/tests/Camera2Tests/SmartCamera/SimpleCamera/assets/0002_000390.jpg differ diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/assets/frsdk_expression_modules/BCLeyesclosed_100.emd b/tests/Camera2Tests/SmartCamera/SimpleCamera/assets/frsdk_expression_modules/BCLeyesclosed_100.emd new file mode 100644 index 0000000..8c3d811 Binary files /dev/null and b/tests/Camera2Tests/SmartCamera/SimpleCamera/assets/frsdk_expression_modules/BCLeyesclosed_100.emd differ diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/assets/frsdk_expression_modules/BCLjoy_100.emd b/tests/Camera2Tests/SmartCamera/SimpleCamera/assets/frsdk_expression_modules/BCLjoy_100.emd new file mode 100644 index 0000000..4ae3fbd Binary files /dev/null and b/tests/Camera2Tests/SmartCamera/SimpleCamera/assets/frsdk_expression_modules/BCLjoy_100.emd differ diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/ic_launcher-web.png b/tests/Camera2Tests/SmartCamera/SimpleCamera/ic_launcher-web.png new file mode 100644 index 0000000..f142216 Binary files /dev/null and b/tests/Camera2Tests/SmartCamera/SimpleCamera/ic_launcher-web.png differ diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/Android.mk b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/Android.mk new file mode 100644 index 0000000..616a11b --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/Android.mk @@ -0,0 +1,49 @@ +# Copyright (C) 2013 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +FILTERFW_NATIVE_PATH := $(call my-dir) + + +# +# Build module libfilterframework +# +LOCAL_PATH := $(FILTERFW_NATIVE_PATH) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := tests + +LOCAL_SDK_VERSION := 14 + +LOCAL_MODULE := libsmartcamera_jni + +LOCAL_SRC_FILES := contrast.cpp \ + brightness.cpp \ + exposure.cpp \ + colorspace.cpp \ + histogram.cpp \ + frametovalues.cpp \ + pixelutils.cpp \ + sobeloperator.cpp \ + stats_scorer.cpp + +LOCAL_STATIC_LIBRARIES += \ + libcutils + +LOCAL_C_INCLUDES += \ + system/core/include \ + +LOCAL_NDK_STL_VARIANT := stlport_static + +include $(BUILD_SHARED_LIBRARY) diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/Application.mk b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/Application.mk new file mode 100644 index 0000000..2b93b3c --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/Application.mk @@ -0,0 +1,16 @@ +# Copyright (C) 2013 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +APP_STL := stlport_static diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/brightness.cpp b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/brightness.cpp new file mode 100644 index 0000000..998fd4c --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/brightness.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Native function to extract brightness from image (handed down as ByteBuffer). + +#include "brightness.h" + +#include +#include +#include +#include +#include + +jfloat +Java_androidx_media_filterfw_samples_simplecamera_AvgBrightnessFilter_brightnessOperator( + JNIEnv* env, jclass clazz, jint width, jint height, jobject imageBuffer) { + + if (imageBuffer == 0) { + return 0.0f; + } + float pixelTotals[] = { 0.0f, 0.0f, 0.0f }; + const int numPixels = width * height; + unsigned char* srcPtr = static_cast(env->GetDirectBufferAddress(imageBuffer)); + for (int i = 0; i < numPixels; i++) { + pixelTotals[0] += *(srcPtr + 4 * i); + pixelTotals[1] += *(srcPtr + 4 * i + 1); + pixelTotals[2] += *(srcPtr + 4 * i + 2); + } + float avgPixels[] = { 0.0f, 0.0f, 0.0f }; + + avgPixels[0] = pixelTotals[0] / numPixels; + avgPixels[1] = pixelTotals[1] / numPixels; + avgPixels[2] = pixelTotals[2] / numPixels; + float returnValue = sqrt(0.241f * avgPixels[0] * avgPixels[0] + + 0.691f * avgPixels[1] * avgPixels[1] + + 0.068f * avgPixels[2] * avgPixels[2]); + + return returnValue / 255; +} diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/brightness.h b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/brightness.h new file mode 100644 index 0000000..c09e3b5 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/brightness.h @@ -0,0 +1,36 @@ +/* Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Native function to extract brightness from image (handed down as ByteBuffer). + +#ifndef ANDROID_FILTERFW_JNI_BRIGHTNESS_H +#define ANDROID_FILTERFW_JNI_BRIGHTNESS_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + JNIEXPORT jfloat JNICALL + Java_androidx_media_filterfw_samples_simplecamera_AvgBrightnessFilter_brightnessOperator( + JNIEnv* env, jclass clazz, jint width, jint height, jobject imageBuffer); + +#ifdef __cplusplus +} +#endif + +#endif // ANDROID_FILTERFW_JNI_BRIGHTNESS_H + diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/colorspace.cpp b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/colorspace.cpp new file mode 100644 index 0000000..63e2ebf --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/colorspace.cpp @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "colorspace.h" + +#include +#include + +typedef uint8_t uint8; +typedef uint32_t uint32; +typedef int32_t int32; + +// RGBA helper struct allows access as int and individual channels +// WARNING: int value depends on endianness and should not be used to analyze individual channels. +union Rgba { + uint32 color; + uint8 channel[4]; +}; + +// Channel index constants +static const uint8 kRed = 0; +static const uint8 kGreen = 1; +static const uint8 kBlue = 2; +static const uint8 kAlpha = 3; + +// Clamp to range 0-255 +static inline uint32 clamp(int32 x) { + return x > 255 ? 255 : (x < 0 ? 0 : x); +} + +// Convert YUV to RGBA +// This uses the ITU-R BT.601 coefficients. +static inline Rgba convertYuvToRgba(int32 y, int32 u, int32 v) { + Rgba color; + color.channel[kRed] = clamp(y + static_cast(1.402 * v)); + color.channel[kGreen] = clamp(y - static_cast(0.344 * u + 0.714 * v)); + color.channel[kBlue] = clamp(y + static_cast(1.772 * u)); + color.channel[kAlpha] = 0xFF; + return color; +} + +// Colorspace conversion functions ///////////////////////////////////////////////////////////////// +void JNI_COLORSPACE_METHOD(nativeYuv420pToRgba8888)( + JNIEnv* env, jclass clazz, jobject input, jobject output, jint width, jint height) { + uint8* const pInput = static_cast(env->GetDirectBufferAddress(input)); + Rgba* const pOutput = static_cast(env->GetDirectBufferAddress(output)); + + const int size = width * height; + + uint8* pInY = pInput; + uint8* pInU = pInput + size; + uint8* pInV = pInput + size + size / 4; + Rgba* pOutColor = pOutput; + + const int u_offset = size; + const int v_offset = u_offset + size / 4; + + for (int y = 0; y < height; y += 2) { + for (int x = 0; x < width; x += 2) { + int u, v, y1, y2, y3, y4; + + y1 = pInY[0]; + y2 = pInY[1]; + y3 = pInY[width]; + y4 = pInY[width + 1]; + + u = *pInU - 128; + v = *pInV - 128; + + pOutColor[0] = convertYuvToRgba(y1, u, v); + pOutColor[1] = convertYuvToRgba(y2, u, v); + pOutColor[width] = convertYuvToRgba(y3, u, v); + pOutColor[width + 1] = convertYuvToRgba(y4, u, v); + + pInY += 2; + pInU++; + pInV++; + pOutColor += 2; + } + pInY += width; + pOutColor += width; + } +} + +void JNI_COLORSPACE_METHOD(nativeArgb8888ToRgba8888)( + JNIEnv* env, jclass clazz, jobject input, jobject output, jint width, jint height) { + Rgba* pInput = static_cast(env->GetDirectBufferAddress(input)); + Rgba* pOutput = static_cast(env->GetDirectBufferAddress(output)); + + for (int i = 0; i < width * height; ++i) { + Rgba color_in = *pInput++; + Rgba& color_out = *pOutput++; + color_out.channel[kRed] = color_in.channel[kGreen]; + color_out.channel[kGreen] = color_in.channel[kBlue]; + color_out.channel[kBlue] = color_in.channel[kAlpha]; + color_out.channel[kAlpha] = color_in.channel[kRed]; + } +} + +void JNI_COLORSPACE_METHOD(nativeRgba8888ToHsva8888)( + JNIEnv* env, jclass clazz, jobject input, jobject output, jint width, jint height) { + Rgba* pInput = static_cast(env->GetDirectBufferAddress(input)); + Rgba* pOutput = static_cast(env->GetDirectBufferAddress(output)); + + int r, g, b, a, h, s, v, c_max, c_min; + float delta; + for (int i = 0; i < width * height; ++i) { + Rgba color_in = *pInput++; + Rgba& color_out = *pOutput++; + r = color_in.channel[kRed]; + g = color_in.channel[kGreen]; + b = color_in.channel[kBlue]; + a = color_in.channel[kAlpha]; + + if (r > g) { + c_min = (g > b) ? b : g; + c_max = (r > b) ? r : b; + } else { + c_min = (r > b) ? b : r; + c_max = (g > b) ? g : b; + } + delta = c_max -c_min; + + float scaler = 255 * 60 / 360.0f; + if (c_max == r) { + h = (g > b) ? static_cast(scaler * (g - b) / delta) : + static_cast(scaler * ((g - b) / delta + 6)); + } else if (c_max == g) { + h = static_cast(scaler * ((b - r) / delta + 2)); + } else { // Cmax == b + h = static_cast(scaler * ((r - g) / delta + 4)); + } + s = (delta == 0.0f) ? 0 : static_cast(delta / c_max * 255); + v = c_max; + + color_out.channel[kRed] = h; + color_out.channel[kGreen] = s; + color_out.channel[kBlue] = v; + color_out.channel[kAlpha] = a; + } +} + +void JNI_COLORSPACE_METHOD(nativeRgba8888ToYcbcra8888)( + JNIEnv* env, jclass clazz, jobject input, jobject output, jint width, jint height) { + Rgba* pInput = static_cast(env->GetDirectBufferAddress(input)); + Rgba* pOutput = static_cast(env->GetDirectBufferAddress(output)); + + int r, g, b; + for (int i = 0; i < width * height; ++i) { + Rgba color_in = *pInput++; + Rgba& color_out = *pOutput++; + r = color_in.channel[kRed]; + g = color_in.channel[kGreen]; + b = color_in.channel[kBlue]; + + color_out.channel[kRed] = + static_cast((65.738 * r + 129.057 * g + 25.064 * b) / 256 + 16); + color_out.channel[kGreen] = + static_cast((-37.945 * r - 74.494 * g + 112.439 * b) / 256 + 128); + color_out.channel[kBlue] = + static_cast((112.439 * r - 94.154 * g - 18.285 * b) / 256 + 128); + color_out.channel[kAlpha] = color_in.channel[kAlpha]; + } +} diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/colorspace.h b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/colorspace.h new file mode 100644 index 0000000..c332749 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/colorspace.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_FILTERFW_JNI_COLORSPACE_H +#define ANDROID_FILTERFW_JNI_COLORSPACE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define JNI_COLORSPACE_METHOD(METHOD_NAME) \ + Java_androidx_media_filterfw_ColorSpace_ ## METHOD_NAME + +JNIEXPORT void JNICALL +JNI_COLORSPACE_METHOD(nativeYuv420pToRgba8888)( + JNIEnv* env, jclass clazz, jobject input, jobject output, jint width, jint height); + +JNIEXPORT void JNICALL +JNI_COLORSPACE_METHOD(nativeArgb8888ToRgba8888)( + JNIEnv* env, jclass clazz, jobject input, jobject output, jint width, jint height); + +JNIEXPORT void JNICALL +JNI_COLORSPACE_METHOD(nativeRgba8888ToHsva8888)( + JNIEnv* env, jclass clazz, jobject input, jobject output, jint width, jint height); + +JNIEXPORT void JNICALL +JNI_COLORSPACE_METHOD(nativeRgba8888ToYcbcra8888)( + JNIEnv* env, jclass clazz, jobject input, jobject output, jint width, jint height); + + +#ifdef __cplusplus +} +#endif + +#endif // ANDROID_FILTERFW_JNI_COLORSPACE_H diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/contrast.cpp b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/contrast.cpp new file mode 100644 index 0000000..222f738 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/contrast.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Native function to extract contrast ratio from image (handed down as ByteBuffer). + +#include "contrast.h" + +#include +#include +#include +#include +#include + +jfloat +Java_androidx_media_filterfw_samples_simplecamera_ContrastRatioFilter_contrastOperator( + JNIEnv* env, jclass clazz, jint width, jint height, jobject imageBuffer) { + + if (imageBuffer == 0) { + return 0.0f; + } + float total = 0; + const int numPixels = width * height; + unsigned char* srcPtr = static_cast(env->GetDirectBufferAddress(imageBuffer)); + float* lumArray = new float[numPixels]; + for (int i = 0; i < numPixels; i++) { + lumArray[i] = (0.2126f * *(srcPtr + 4 * i) + 0.7152f * + *(srcPtr + 4 * i + 1) + 0.0722f * *(srcPtr + 4 * i + 2)) / 255; + total += lumArray[i]; + } + const float avg = total / numPixels; + float sum = 0; + + for (int i = 0; i < numPixels; i++) { + sum += (lumArray[i] - avg) * (lumArray[i] - avg); + } + delete[] lumArray; + return ((float) sqrt(sum / numPixels)); +} diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/contrast.h b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/contrast.h new file mode 100644 index 0000000..ddcd3d4 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/contrast.h @@ -0,0 +1,36 @@ +/* Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Native function to extract contrast from image (handed down as ByteBuffer). + +#ifndef ANDROID_FILTERFW_JNI_CONTRAST_H +#define ANDROID_FILTERFW_JNI_CONTRAST_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + JNIEXPORT jfloat JNICALL + Java_androidx_media_filterfw_samples_simplecamera_ContrastRatioFilter_contrastOperator( + JNIEnv* env, jclass clazz, jint width, jint height, jobject imageBuffer); + +#ifdef __cplusplus +} +#endif + +#endif // ANDROID_FILTERFW_JNI_CONTRAST_H + diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/exposure.cpp b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/exposure.cpp new file mode 100644 index 0000000..b2853f7 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/exposure.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Native function to extract exposure from image (handed down as ByteBuffer). + +#include "exposure.h" + +#include +#include +#include +#include +#include + + +jfloat +Java_androidx_media_filterfw_samples_simplecamera_ExposureFilter_overExposureOperator( + JNIEnv* env, jclass clazz, jint width, jint height, jobject imageBuffer) { + if (imageBuffer == 0) { + return 0.0f; + } + const int numPixels = width * height; + unsigned char* srcPtr = static_cast(env->GetDirectBufferAddress(imageBuffer)); + int output = 0; + float tempLuminance = 0.0f; + + for (int i = 0; i < numPixels; i++) { + tempLuminance = (0.2126f * *(srcPtr + 4 * i) + + 0.7152f * *(srcPtr + 4 * i + 1) + + 0.0722f * *(srcPtr + 4 * i + 2)); + if (tempLuminance + 5 >= 255) { + output++; + } + } + return (static_cast(output)) / numPixels; +} + +jfloat +Java_androidx_media_filterfw_samples_simplecamera_ExposureFilter_underExposureOperator( + JNIEnv* env, jclass clazz, jint width, jint height, jobject imageBuffer) { + if (imageBuffer == 0) { + return 0.0f; + } + const int numPixels = width * height; + unsigned char* srcPtr = static_cast(env->GetDirectBufferAddress(imageBuffer)); + int output = 0; + float tempLuminance = 0.0f; + + for (int i = 0; i < numPixels; i++) { + tempLuminance = (0.2126f * *(srcPtr + 4 * i) + + 0.7152f * *(srcPtr + 4 * i + 1) + + 0.0722f * *(srcPtr + 4 * i + 2)); + if (tempLuminance - 5 <= 0) { + output++; + } + } + return (static_cast(output)) / numPixels; +} diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/exposure.h b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/exposure.h new file mode 100644 index 0000000..bc6e3b1 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/exposure.h @@ -0,0 +1,39 @@ +/* Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Native function to extract exposure from image (handed down as ByteBuffer). + +#ifndef ANDROID_FILTERFW_JNI_EXPOSURE_H +#define ANDROID_FILTERFW_JNI_EXPOSURE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + JNIEXPORT jfloat JNICALL + Java_androidx_media_filterfw_samples_simplecamera_ExposureFilter_underExposureOperator( + JNIEnv* env, jclass clazz, jint width, jint height, jobject imageBuffer); + + JNIEXPORT jfloat JNICALL + Java_androidx_media_filterfw_samples_simplecamera_ExposureFilter_overExposureOperator( + JNIEnv* env, jclass clazz, jint width, jint height, jobject imageBuffer); +#ifdef __cplusplus +} +#endif + +#endif // ANDROID_FILTERFW_JNI_EXPOSURE_H + diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/frametovalues.cpp b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/frametovalues.cpp new file mode 100644 index 0000000..2e3a0ec --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/frametovalues.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Native function to extract histogram from image (handed down as ByteBuffer). + +#include "frametovalues.h" + +#include +#include +#include +#include + +#include "imgprocutil.h" + +jboolean Java_androidx_media_filterpacks_image_ToGrayValuesFilter_toGrayValues( + JNIEnv* env, jclass clazz, jobject imageBuffer, jobject grayBuffer ) +{ + unsigned char* pixelPtr = static_cast(env->GetDirectBufferAddress(imageBuffer)); + unsigned char* grayPtr = static_cast(env->GetDirectBufferAddress(grayBuffer)); + + if (pixelPtr == 0 || grayPtr == 0) { + return JNI_FALSE; + } + + int numPixels = env->GetDirectBufferCapacity(imageBuffer) / 4; + + // TODO: the current implementation is focused on the correctness not performance. + // If performance becomes an issue, it is better to increment pixelPtr directly. + int disp = 0; + for(int idx = 0; idx < numPixels; idx++, disp+=4) { + int R = *(pixelPtr + disp); + int G = *(pixelPtr + disp + 1); + int B = *(pixelPtr + disp + 2); + int gray = getIntensityFast(R, G, B); + *(grayPtr+idx) = static_cast(gray); + } + + return JNI_TRUE; +} + +jboolean Java_androidx_media_filterpacks_image_ToRgbValuesFilter_toRgbValues( + JNIEnv* env, jclass clazz, jobject imageBuffer, jobject rgbBuffer ) +{ + unsigned char* pixelPtr = static_cast(env->GetDirectBufferAddress(imageBuffer)); + unsigned char* rgbPtr = static_cast(env->GetDirectBufferAddress(rgbBuffer)); + + if (pixelPtr == 0 || rgbPtr == 0) { + return JNI_FALSE; + } + + int numPixels = env->GetDirectBufferCapacity(imageBuffer) / 4; + + // TODO: this code could be revised to improve the performance as the TODO above. + int pixelDisp = 0; + int rgbDisp = 0; + for(int idx = 0; idx < numPixels; idx++, pixelDisp += 4, rgbDisp += 3) { + for (int c = 0; c < 3; ++c) { + *(rgbPtr + rgbDisp + c) = *(pixelPtr + pixelDisp + c); + } + } + return JNI_TRUE; +} + diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/frametovalues.h b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/frametovalues.h new file mode 100644 index 0000000..4abb848 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/frametovalues.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Native functions to pack a RGBA frame into either a one channel grayscale buffer +// or a three channel RGB buffer. + +#ifndef ANDROID_FILTERFW_JNI_TOGRAYVALUES_H +#define ANDROID_FILTERFW_JNI_TOGRAYVALUES_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +JNIEXPORT jboolean JNICALL +Java_androidx_media_filterpacks_image_ToGrayValuesFilter_toGrayValues( + JNIEnv* env, jclass clazz, jobject imageBuffer, jobject grayBuffer ); + +JNIEXPORT jboolean JNICALL +Java_androidx_media_filterpacks_image_ToRgbValuesFilter_toRgbValues( + JNIEnv* env, jclass clazz, jobject imageBuffer, jobject rgbBuffer ); + + +#ifdef __cplusplus +} +#endif + +#endif // ANDROID_FILTERFW_JNI_TOGRAYVALUES_H diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/histogram.cpp b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/histogram.cpp new file mode 100644 index 0000000..ba060d4 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/histogram.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Native function to extract histogram from image (handed down as ByteBuffer). + +#include "histogram.h" + +#include +#include +#include +#include + +#include "imgprocutil.h" + +inline void addPixelToHistogram(unsigned char*& pImg, int* pHist, int numBins) { + int R = *(pImg++); + int G = *(pImg++); + int B = *(pImg++); + ++pImg; + int i = getIntensityFast(R, G, B); + int bin = clamp(0, static_cast(static_cast(i * numBins) / 255.0f), numBins - 1); + ++pHist[bin]; +} + +void Java_androidx_media_filterpacks_histogram_GrayHistogramFilter_extractHistogram( + JNIEnv* env, jclass clazz, jobject imageBuffer, jobject maskBuffer, jobject histogramBuffer ) +{ + unsigned char* pImg = static_cast(env->GetDirectBufferAddress(imageBuffer)); + int* pHist = static_cast(env->GetDirectBufferAddress(histogramBuffer)); + int numPixels = env->GetDirectBufferCapacity(imageBuffer) / 4; // 4 bytes per pixel + int numBins = env->GetDirectBufferCapacity(histogramBuffer); + + unsigned char* pMask = NULL; + if(maskBuffer != NULL) { + pMask = static_cast(env->GetDirectBufferAddress(maskBuffer)); + } + + for(int i = 0; i < numBins; ++i) pHist[i] = 0; + + if(pMask == NULL) { + for( ; numPixels > 0; --numPixels) { + addPixelToHistogram(pImg, pHist, numBins); + } + } else { + for( ; numPixels > 0; --numPixels) { + if(*pMask == 0){ + pMask += 4; + pImg += 4; // Note that otherwise addPixelToHistogram advances pImg by 4 + continue; + } + pMask += 4; + addPixelToHistogram(pImg, pHist, numBins); + } + } +} + +void Java_androidx_media_filterpacks_histogram_ChromaHistogramFilter_extractChromaHistogram( + JNIEnv* env, jclass clazz, jobject imageBuffer, jobject histogramBuffer, jint hBins, jint sBins) +{ + unsigned char* pixelIn = static_cast(env->GetDirectBufferAddress(imageBuffer)); + float* histOut = static_cast(env->GetDirectBufferAddress(histogramBuffer)); + int numPixels = env->GetDirectBufferCapacity(imageBuffer) / 4; // 4 bytes per pixel + + for (int i = 0; i < hBins * sBins; ++i) histOut[i] = 0.0f; + + int h, s, v; + float hScaler = hBins / 256.0f; + float sScaler = sBins / 256.0f; + for( ; numPixels > 0; --numPixels) { + h = *(pixelIn++); + s = *(pixelIn++); + v = *(pixelIn++); + pixelIn++; + + int index = static_cast(s * sScaler) * hBins + static_cast(h * hScaler); + histOut[index] += 1.0f; + } +} + +void Java_androidx_media_filterpacks_histogram_NewChromaHistogramFilter_extractChromaHistogram( + JNIEnv* env, jclass clazz, jobject imageBuffer, jobject histogramBuffer, + jint hueBins, jint saturationBins, jint valueBins, + jint saturationThreshold, jint valueThreshold) { + unsigned char* pixelIn = static_cast(env->GetDirectBufferAddress(imageBuffer)); + float* histOut = static_cast(env->GetDirectBufferAddress(histogramBuffer)); + int numPixels = env->GetDirectBufferCapacity(imageBuffer) / 4; // 4 bytes per pixel + + // TODO: add check on the size of histOut + for (int i = 0; i < (hueBins * saturationBins + valueBins); ++i) { + histOut[i] = 0.0f; + } + + for( ; numPixels > 0; --numPixels) { + int h = *(pixelIn++); + int s = *(pixelIn++); + int v = *(pixelIn++); + + pixelIn++; + // If a pixel that is either too dark (less than valueThreshold) or colorless + // (less than saturationThreshold), if will be put in a 1-D value histogram instead. + + int index; + if (s > saturationThreshold && v > valueThreshold) { + int sIndex = s * saturationBins / 256; + + // Shifting hue index by 0.5 such that peaks of red, yellow, green, cyan, blue, pink + // will be at the center of some bins. + int hIndex = ((h * hueBins + 128) / 256) % hueBins; + index = sIndex * hueBins + hIndex; + } else { + index = hueBins * saturationBins + (v * valueBins / 256); + } + histOut[index] += 1.0f; + } +} diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/histogram.h b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/histogram.h new file mode 100644 index 0000000..b5e88aa --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/histogram.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Native function to extract histogram from image (handed down as ByteBuffer). + +#ifndef ANDROID_FILTERFW_JNI_HISTOGRAM_H +#define ANDROID_FILTERFW_JNI_HISTOGRAM_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +JNIEXPORT void JNICALL +Java_androidx_media_filterpacks_histogram_GrayHistogramFilter_extractHistogram( + JNIEnv* env, jclass clazz, jobject imageBuffer, jobject maskBuffer, jobject histogramBuffer ); + +JNIEXPORT void JNICALL +Java_androidx_media_filterpacks_histogram_ChromaHistogramFilter_extractChromaHistogram( + JNIEnv* env, jclass clazz, jobject imageBuffer, jobject histogramBuffer, jint hBins, jint sBins); + +JNIEXPORT void JNICALL +Java_androidx_media_filterpacks_histogram_NewChromaHistogramFilter_extractChromaHistogram( + JNIEnv* env, jclass clazz, jobject imageBuffer, jobject histogramBuffer, + jint hueBins, jint saturationBins, jint valueBins, + jint saturationThreshold, jint valueThreshold); + +#ifdef __cplusplus +} +#endif + +#endif // ANDROID_FILTERFW_JNI_HISTOGRAM_H diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/imgprocutil.h b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/imgprocutil.h new file mode 100644 index 0000000..aef67a5 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/imgprocutil.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Some native low-level image processing functions. + + +#ifndef ANDROID_FILTERFW_JNI_IMGPROCUTIL_H +#define ANDROID_FILTERFW_JNI_IMGPROCUTIL_H + +inline int getIntensityFast(int R, int G, int B) { + return (R + R + R + B + G + G + G + G) >> 3; // see http://stackoverflow.com/a/596241 +} + +inline int clamp(int min, int val, int max) { + return val < min ? min : (val > max ? max : val); + // Note that for performance reasons, this function does *not* check if min < max! +} + +#endif // ANDROID_FILTERFW_JNI_IMGPROCUTIL_H diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/pixelutils.cpp b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/pixelutils.cpp new file mode 100644 index 0000000..596c7c0 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/pixelutils.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "pixelutils.h" + +#include + +typedef uint32_t uint32; + +void JNI_PIXELUTILS_METHOD(nativeCopyPixels)( + JNIEnv* env, jclass clazz, jobject input, jobject output, jint width, jint height, jint offset, + jint pixStride, jint rowStride) { + uint32* pInPix = static_cast(env->GetDirectBufferAddress(input)); + uint32* pOutput = static_cast(env->GetDirectBufferAddress(output)); + uint32* pOutRow = pOutput + offset; + for (int y = 0; y < height; ++y) { + uint32* pOutPix = pOutRow; + for (int x = 0; x < width; ++x) { + *pOutPix = *(pInPix++); + pOutPix += pixStride; + } + pOutRow += rowStride; + } +} + diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/pixelutils.h b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/pixelutils.h new file mode 100644 index 0000000..be69009 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/pixelutils.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_FILTERFW_JNI_PIXELUTILS_H +#define ANDROID_FILTERFW_JNI_PIXELUTILS_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define JNI_PIXELUTILS_METHOD(METHOD_NAME) \ + Java_androidx_media_filterfw_PixelUtils_ ## METHOD_NAME + +JNIEXPORT void JNICALL +JNI_PIXELUTILS_METHOD(nativeCopyPixels)( + JNIEnv* env, jclass clazz, jobject input, jobject output, jint width, jint height, jint offset, + jint pixStride, jint rowStride); + +#ifdef __cplusplus +} +#endif + +#endif // ANDROID_FILTERFW_JNI_PIXELUTILS_H + diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/sobeloperator.cpp b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/sobeloperator.cpp new file mode 100644 index 0000000..dc5c305 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/sobeloperator.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Native function to extract histogram from image (handed down as ByteBuffer). + +#include "sobeloperator.h" + +#include +#include +#include +#include +#include + +#include "imgprocutil.h" + +/* + * Perform 1d convolution on 3 channel image either horizontally or vertically. + * Parameters: + * inputHead: pointer to input image + * length: the length of image in the chosen axis. + * fragments: number of lines of the image in the chosen axis. + * step: the 1d pixel distance between adjacent pixels in the chosen axis. + * shift: the 1d pixel distance between adjacent lines in the chosen axis. + * filter: pointer to 1d filter + * halfSize: the length of filter is supposed to be (2 * halfSize + 1) + * outputHead: pointer to output image + */ + +void computeGradient(unsigned char* dataPtr, int width, int height, short* gxPtr, short* gyPtr) { + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + const int left = (j > 0)? -4 : 0; + const int right = (j < width - 1) ? 4 : 0; + const int curr = (i * width + j) * 4; + const int above = (i > 0) ? curr - 4 * width : curr; + const int below = (i < height - 1) ? curr + 4 * width : curr; + const int offset = (i * width + j) * 3; + for (int c = 0; c < 3; c++) { + *(gxPtr + offset + c) = + (*(dataPtr + curr + c + right) - *(dataPtr + curr + c + left)) * 2 + + *(dataPtr + above + c + right) - *(dataPtr + above + c + left) + + *(dataPtr + below + c + right) - *(dataPtr + below + c + left); + *(gyPtr + offset + c) = + (*(dataPtr + c + below) - *(dataPtr + c + above)) * 2 + + *(dataPtr + left + c + below) - *(dataPtr + left + c + above) + + *(dataPtr + right + c + below) - *(dataPtr + right + c + above); + } + } + } +} + +jboolean Java_androidx_media_filterpacks_image_SobelFilter_sobelOperator( + JNIEnv* env, jclass clazz, jint width, jint height, jobject imageBuffer, + jobject magBuffer, jobject dirBuffer) { + + if (imageBuffer == 0) { + return JNI_FALSE; + } + unsigned char* srcPtr = static_cast(env->GetDirectBufferAddress(imageBuffer)); + unsigned char* magPtr = (magBuffer == 0) ? + 0 : static_cast(env->GetDirectBufferAddress(magBuffer)); + unsigned char* dirPtr = (dirBuffer == 0) ? + 0 : static_cast(env->GetDirectBufferAddress(dirBuffer)); + + int numPixels = width * height; + // TODO: avoid creating and deleting these buffers within this native function. + short* gxPtr = new short[3 * numPixels]; + short* gyPtr = new short[3 * numPixels]; + computeGradient(srcPtr, width, height, gxPtr, gyPtr); + + unsigned char* mag = magPtr; + unsigned char* dir = dirPtr; + for (int i = 0; i < numPixels; ++i) { + for (int c = 0; c < 3; c++) { + int gx = static_cast(*(gxPtr + 3 * i + c) / 8 + 127.5); + int gy = static_cast(*(gyPtr + 3 * i + c) / 8 + 127.5); + + // emulate arithmetic in GPU. + gx = 2 * gx - 255; + gy = 2 * gy - 255; + if (magPtr != 0) { + double value = sqrt(gx * gx + gy * gy); + *(magPtr + 4 * i + c) = static_cast(value); + } + if (dirPtr != 0) { + *(dirPtr + 4 * i + c) = static_cast( + (atan(static_cast(gy)/static_cast(gx)) + 3.14) / 6.28); + } + } + //setting alpha change to 1.0 (255) + if (magPtr != 0) { + *(magPtr + 4 * i + 3) = 255; + } + if (dirPtr != 0) { + *(dirPtr + 4 * i + 3) = 255; + } + } + + delete[] gxPtr; + delete[] gyPtr; + + return JNI_TRUE; +} diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/sobeloperator.h b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/sobeloperator.h new file mode 100644 index 0000000..c7639d2 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/sobeloperator.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Native function to extract histogram from image (handed down as ByteBuffer). + +#ifndef ANDROID_FILTERFW_JNI_SOBELOPERATOR_H +#define ANDROID_FILTERFW_JNI_SOBELOPERATOR_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +JNIEXPORT jboolean JNICALL +Java_androidx_media_filterpacks_image_SobelFilter_sobelOperator( + JNIEnv* env, jclass clazz, jint width, jint height, + jobject imageBuffer, jobject magBuffer, jobject dirBuffer); + +#ifdef __cplusplus +} +#endif + +#endif // ANDROID_FILTERFW_JNI_SOBELOPERATOR_H diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/stats_scorer.cpp b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/stats_scorer.cpp new file mode 100644 index 0000000..f282675 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/stats_scorer.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Stats (mean and stdev) scoring in the native. + +#include "stats_scorer.h" + +#include +#include + +void Java_androidx_media_filterpacks_numeric_StatsFilter_score( + JNIEnv* env, jobject thiz, jobject imageBuffer, jfloatArray statsArray) +{ + unsigned char* pImg = static_cast(env->GetDirectBufferAddress(imageBuffer)); + int numPixels = env->GetDirectBufferCapacity(imageBuffer); // 1 byte per pixel + float sum = 0.0; + float sumSquares = 0.0; + + for (int i = 0; i < numPixels; ++i) { + float val = static_cast(pImg[i]); + sum += val; + sumSquares += val * val; + } + jfloat result[2]; + result[0] = sum / numPixels; // mean + result[1] = sqrt((sumSquares - numPixels * result[0] * result[0]) / (numPixels - 1)); // stdev. + env->SetFloatArrayRegion(statsArray, 0, 2, result); +} + +void Java_androidx_media_filterpacks_numeric_StatsFilter_regionscore( + JNIEnv* env, jobject thiz, jobject imageBuffer, jint width, jint height, + jfloat left, jfloat top, jfloat right, jfloat bottom, jfloatArray statsArray) +{ + unsigned char* pImg = static_cast(env->GetDirectBufferAddress(imageBuffer)); + int xStart = static_cast(width * left); + int xEnd = static_cast(width * right); + int yStart = static_cast(height * top); + int yEnd = static_cast(height * bottom); + int numPixels = (xEnd - xStart) * (yEnd - yStart); + float sum = 0.0; + float sumSquares = 0.0; + + for (int y = yStart; y < yEnd; y++) { + int disp = width * y; + for (int x = xStart; x < xEnd; ++x) { + float val = static_cast(*(pImg + disp + x)); + sum += val; + sumSquares += val * val; + } + } + jfloat result[2]; + result[0] = sum / numPixels; // mean + result[1] = (numPixels == 1) ? + 0 : sqrt((sumSquares - numPixels * result[0] * result[0]) / (numPixels - 1)); // stdev. + env->SetFloatArrayRegion(statsArray, 0, 2, result); +} + diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/stats_scorer.h b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/stats_scorer.h new file mode 100644 index 0000000..a951ec9 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/jni/stats_scorer.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Stats (mean and stdev) scoring in the native. + +#ifndef ANDROID_FILTERFW_JNI_STATS_SCORER_H +#define ANDROID_FILTERFW_JNI_STATS_SCORER_H + +#include + +#define JNI_FES_FUNCTION(name) Java_androidx_media_filterpacks_numeric_StatsFilter_ ## name + +#ifdef __cplusplus +extern "C" { +#endif + +JNIEXPORT void JNICALL +JNI_FES_FUNCTION(score)( + JNIEnv* env, jobject thiz, jobject imageBuffer, jfloatArray statsArray); + +JNIEXPORT void JNICALL +JNI_FES_FUNCTION(regionscore)( + JNIEnv* env, jobject thiz, jobject imageBuffer, jint width, jint height, + jfloat lefp, jfloat top, jfloat right, jfloat bottom, jfloatArray statsArray); + +#ifdef __cplusplus +} +#endif + + +#endif // ANDROID_FILTERFW_JNI_STATS_SCORER_H diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/proguard-project.txt b/tests/Camera2Tests/SmartCamera/SimpleCamera/proguard-project.txt new file mode 100644 index 0000000..f2fe155 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/project.properties b/tests/Camera2Tests/SmartCamera/SimpleCamera/project.properties new file mode 100644 index 0000000..10149cb --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/project.properties @@ -0,0 +1,15 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-16 +android.library.reference.1=../../filterfw diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/black_screen.jpg b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/black_screen.jpg new file mode 100644 index 0000000..702d9fa Binary files /dev/null and b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/black_screen.jpg differ diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/ic_launcher.png b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..1c7b44a Binary files /dev/null and b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/ic_launcher.png differ diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/ic_menu_gallery.png b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/ic_menu_gallery.png new file mode 100644 index 0000000..f61bbd8 Binary files /dev/null and b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/ic_menu_gallery.png differ diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/ic_menu_quill.png b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/ic_menu_quill.png new file mode 100644 index 0000000..7ea01b7 Binary files /dev/null and b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/ic_menu_quill.png differ diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/ic_menu_save.png b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/ic_menu_save.png new file mode 100644 index 0000000..62d0b9a Binary files /dev/null and b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-hdpi/ic_menu_save.png differ diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-ldpi/ic_launcher.png b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-ldpi/ic_launcher.png new file mode 100644 index 0000000..b42e903 Binary files /dev/null and b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-ldpi/ic_launcher.png differ diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-mdpi/ic_launcher.png b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..d4b4d6b Binary files /dev/null and b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-mdpi/ic_launcher.png differ diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-nodpi/android_figure.png b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-nodpi/android_figure.png new file mode 100644 index 0000000..71c6d76 Binary files /dev/null and b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-nodpi/android_figure.png differ diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-nodpi/oldframe.png b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-nodpi/oldframe.png new file mode 100644 index 0000000..8b7ae63 Binary files /dev/null and b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-nodpi/oldframe.png differ diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-nodpi/polaroid.png b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-nodpi/polaroid.png new file mode 100644 index 0000000..5504c57 Binary files /dev/null and b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-nodpi/polaroid.png differ diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-xhdpi/ic_launcher.png b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000..3bb5454 Binary files /dev/null and b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/drawable-xhdpi/ic_launcher.png differ diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/res/layout/imageview.xml b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/layout/imageview.xml new file mode 100644 index 0000000..4e20c3f --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/layout/imageview.xml @@ -0,0 +1,22 @@ + + + + diff --git a/tests/Camera2Tests/SmartCamera/SimpleCamera/res/layout/simplecamera.xml b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/layout/simplecamera.xml new file mode 100644 index 0000000..8d8ff51 --- /dev/null +++ b/tests/Camera2Tests/SmartCamera/SimpleCamera/res/layout/simplecamera.xml @@ -0,0 +1,97 @@ + + + + + + + +