From 4e338039c27b1ca134bd4540623d4cb5813780d3 Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Tue, 1 Aug 2017 20:45:42 +0200 Subject: [PATCH] Add files --- .../flurgle/camerakit/ExtraProperties.java | 14 ++++ .../flurgle/camerakit/SurfaceViewPreview.java | 68 +++++++++++++++++++ .../src/main/res/layout/surface_view.xml | 10 +++ .../com/flurgle/camerakit/SessionType.java | 14 ++++ .../com/flurgle/camerakit/WhiteBalance.java | 18 +++++ .../types/com/flurgle/camerakit/ZoomMode.java | 14 ++++ .../com/flurgle/camerakit/RotationHelper.java | 43 ++++++++++++ 7 files changed, 181 insertions(+) create mode 100644 camerakit/src/main/base/com/flurgle/camerakit/ExtraProperties.java create mode 100644 camerakit/src/main/base/com/flurgle/camerakit/SurfaceViewPreview.java create mode 100644 camerakit/src/main/res/layout/surface_view.xml create mode 100644 camerakit/src/main/types/com/flurgle/camerakit/SessionType.java create mode 100644 camerakit/src/main/types/com/flurgle/camerakit/WhiteBalance.java create mode 100644 camerakit/src/main/types/com/flurgle/camerakit/ZoomMode.java create mode 100644 camerakit/src/main/utils/com/flurgle/camerakit/RotationHelper.java diff --git a/camerakit/src/main/base/com/flurgle/camerakit/ExtraProperties.java b/camerakit/src/main/base/com/flurgle/camerakit/ExtraProperties.java new file mode 100644 index 00000000..b8d16d86 --- /dev/null +++ b/camerakit/src/main/base/com/flurgle/camerakit/ExtraProperties.java @@ -0,0 +1,14 @@ +package com.flurgle.camerakit; + +/** + * Simple pojo containing various camera properties. + */ +public class ExtraProperties { + public final float verticalViewingAngle; + public final float horizontalViewingAngle; + + public ExtraProperties(float verticalViewingAngle, float horizontalViewingAngle) { + this.verticalViewingAngle = verticalViewingAngle; + this.horizontalViewingAngle = horizontalViewingAngle; + } +} diff --git a/camerakit/src/main/base/com/flurgle/camerakit/SurfaceViewPreview.java b/camerakit/src/main/base/com/flurgle/camerakit/SurfaceViewPreview.java new file mode 100644 index 00000000..1060e83a --- /dev/null +++ b/camerakit/src/main/base/com/flurgle/camerakit/SurfaceViewPreview.java @@ -0,0 +1,68 @@ +package com.flurgle.camerakit; + +import android.annotation.TargetApi; +import android.content.Context; +import android.graphics.SurfaceTexture; +import android.view.Surface; +import android.view.SurfaceHolder; +import android.view.SurfaceView; +import android.view.TextureView; +import android.view.View; +import android.view.ViewGroup; + +// This is not used. +class SurfaceViewPreview extends PreviewImpl { + + private final SurfaceView mSurfaceView; + + SurfaceViewPreview(Context context, ViewGroup parent) { + final View view = View.inflate(context, R.layout.surface_view, parent); // MATCH_PARENT + mSurfaceView = (SurfaceView) view.findViewById(R.id.surface_view); + final SurfaceHolder holder = mSurfaceView.getHolder(); + holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); + holder.addCallback(new SurfaceHolder.Callback() { + @Override + public void surfaceCreated(SurfaceHolder holder) { + setSurfaceSize(mSurfaceView.getWidth(), mSurfaceView.getHeight()); + dispatchSurfaceChanged(); + } + + @Override + public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { + setSurfaceSize(width, height); + dispatchSurfaceChanged(); + } + + @Override + public void surfaceDestroyed(SurfaceHolder holder) { + setSurfaceSize(0, 0); + } + }); + } + + @Override + Surface getSurface() { + return getSurfaceHolder().getSurface(); + } + + @Override + View getView() { + return mSurfaceView; + } + + @Override + SurfaceHolder getSurfaceHolder() { + return mSurfaceView.getHolder(); + } + + @Override + Class getOutputClass() { + return SurfaceHolder.class; + } + + @Override + boolean isReady() { + return mSurfaceView.getWidth() != 0 && mSurfaceView.getHeight() != 0; + } + +} diff --git a/camerakit/src/main/res/layout/surface_view.xml b/camerakit/src/main/res/layout/surface_view.xml new file mode 100644 index 00000000..42fb3f23 --- /dev/null +++ b/camerakit/src/main/res/layout/surface_view.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/camerakit/src/main/types/com/flurgle/camerakit/SessionType.java b/camerakit/src/main/types/com/flurgle/camerakit/SessionType.java new file mode 100644 index 00000000..ba8907e8 --- /dev/null +++ b/camerakit/src/main/types/com/flurgle/camerakit/SessionType.java @@ -0,0 +1,14 @@ +package com.flurgle.camerakit; + +import android.support.annotation.IntDef; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import static com.flurgle.camerakit.CameraKit.Constants.SESSION_TYPE_PICTURE; +import static com.flurgle.camerakit.CameraKit.Constants.SESSION_TYPE_VIDEO; + +@Retention(RetentionPolicy.SOURCE) +@IntDef({SESSION_TYPE_PICTURE, SESSION_TYPE_VIDEO}) +public @interface SessionType { +} diff --git a/camerakit/src/main/types/com/flurgle/camerakit/WhiteBalance.java b/camerakit/src/main/types/com/flurgle/camerakit/WhiteBalance.java new file mode 100644 index 00000000..8bd72097 --- /dev/null +++ b/camerakit/src/main/types/com/flurgle/camerakit/WhiteBalance.java @@ -0,0 +1,18 @@ +package com.flurgle.camerakit; + +import android.support.annotation.IntDef; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import static com.flurgle.camerakit.CameraKit.Constants.WHITE_BALANCE_AUTO; +import static com.flurgle.camerakit.CameraKit.Constants.WHITE_BALANCE_INCANDESCENT; +import static com.flurgle.camerakit.CameraKit.Constants.WHITE_BALANCE_FLUORESCENT; +import static com.flurgle.camerakit.CameraKit.Constants.WHITE_BALANCE_DAYLIGHT; +import static com.flurgle.camerakit.CameraKit.Constants.WHITE_BALANCE_CLOUDY; + +@Retention(RetentionPolicy.SOURCE) +@IntDef({WHITE_BALANCE_AUTO, WHITE_BALANCE_INCANDESCENT, WHITE_BALANCE_FLUORESCENT, + WHITE_BALANCE_DAYLIGHT, WHITE_BALANCE_CLOUDY}) +public @interface WhiteBalance { +} \ No newline at end of file diff --git a/camerakit/src/main/types/com/flurgle/camerakit/ZoomMode.java b/camerakit/src/main/types/com/flurgle/camerakit/ZoomMode.java new file mode 100644 index 00000000..53c38722 --- /dev/null +++ b/camerakit/src/main/types/com/flurgle/camerakit/ZoomMode.java @@ -0,0 +1,14 @@ +package com.flurgle.camerakit; + +import android.support.annotation.IntDef; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import static com.flurgle.camerakit.CameraKit.Constants.ZOOM_OFF; +import static com.flurgle.camerakit.CameraKit.Constants.ZOOM_PINCH; + +@Retention(RetentionPolicy.SOURCE) +@IntDef({ZOOM_OFF, ZOOM_PINCH}) +public @interface ZoomMode { +} diff --git a/camerakit/src/main/utils/com/flurgle/camerakit/RotationHelper.java b/camerakit/src/main/utils/com/flurgle/camerakit/RotationHelper.java new file mode 100644 index 00000000..dd9522d1 --- /dev/null +++ b/camerakit/src/main/utils/com/flurgle/camerakit/RotationHelper.java @@ -0,0 +1,43 @@ +package com.flurgle.camerakit; + +class RotationHelper { + + + static byte[] rotate(final byte[] yuv, final int width, final int height, final int rotation) { + if (rotation == 0) return yuv; + if (rotation % 90 != 0 || rotation < 0 || rotation > 270) { + throw new IllegalArgumentException("0 <= rotation < 360, rotation % 90 == 0"); + } + final byte[] output = new byte[yuv.length]; + final int frameSize = width * height; + final boolean swap = rotation % 180 != 0; + final boolean xflip = rotation % 270 != 0; + final boolean yflip = rotation >= 180; + + for (int j = 0; j < height; j++) { + for (int i = 0; i < width; i++) { + final int yIn = j * width + i; + final int uIn = frameSize + (j >> 1) * width + (i & ~1); + final int vIn = uIn + 1; + + final int wOut = swap ? height : width; + final int hOut = swap ? width : height; + final int iSwapped = swap ? j : i; + final int jSwapped = swap ? i : j; + final int iOut = xflip ? wOut - iSwapped - 1 : iSwapped; + final int jOut = yflip ? hOut - jSwapped - 1 : jSwapped; + + final int yOut = jOut * wOut + iOut; + final int uOut = frameSize + (jOut >> 1) * wOut + (iOut & ~1); + final int vOut = uOut + 1; + + output[yOut] = (byte) (0xff & yuv[yIn]); + output[uOut] = (byte) (0xff & yuv[uIn]); + output[vOut] = (byte) (0xff & yuv[vIn]); + } + } + + return output; + } +} +