Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw Corner history #82

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions app/CMakeLists.txt

This file was deleted.

17 changes: 0 additions & 17 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ android {
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

externalNativeBuild {
// Encapsulates your CMake build configurations.
cmake {
// Provides a relative path to your CMake build script.
cppFlags "-std=c++11 -fexceptions"
arguments "-DANDROID_STL=c++_shared"
}
}
}

buildTypes {
Expand All @@ -42,14 +33,6 @@ android {
packagingOptions {
pickFirst '**/*.so'
}
externalNativeBuild {
// Encapsulates your CMake build configurations.
cmake {

// Provides a relative path to your CMake build script.
path "CMakeLists.txt"
}
}
}

dependencies {
Expand Down
11 changes: 0 additions & 11 deletions app/src/main/cpp/GlesHelper.c

This file was deleted.

12 changes: 0 additions & 12 deletions app/src/main/java/dk/scuffed/whiteboardapp/helper/GlesHelper.java

This file was deleted.

45 changes: 10 additions & 35 deletions app/src/main/java/dk/scuffed/whiteboardapp/opengl/GL.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package dk.scuffed.whiteboardapp.opengl

import android.opengl.GLES20
import android.opengl.GLES30

import android.util.Log
import android.util.Size
import dk.scuffed.whiteboardapp.BuildConfig
import dk.scuffed.whiteboardapp.utils.Color
import dk.scuffed.whiteboardapp.utils.Vec2Int
import java.nio.Buffer
Expand Down Expand Up @@ -201,8 +198,7 @@ fun glLinkProgram(program: Int) {
val linkStatus = IntArray(1)
GLES20.glGetProgramiv(
program,
GLES20
.GL_LINK_STATUS,
GLES20.GL_LINK_STATUS,
linkStatus,
0
)
Expand Down Expand Up @@ -476,6 +472,11 @@ fun glUniform2f(location: Int, x: Float, y: Float) {
logErrorIfAny("glUniform2f")
}

fun glUniform3f(location: Int, x: Float, y: Float, z: Float) {
GLES20.glUniform3f(location, x, y, z)
logErrorIfAny("glUniform3f")
}

fun glUniform4f(location: Int, r: Float, g: Float, b: Float, a: Float) {
GLES20.glUniform4f(location, r, g, b, a)
logErrorIfAny("glUniform4f")
Expand All @@ -486,29 +487,6 @@ fun glUniform4fv(location: Int, count: Int, buffer: FloatArray, offset: Int) {
logErrorIfAny("glUniform4fv")
}

/* OpenGLES3.0 functionality */
fun glBindBuffer(target: Int, buffer: Int) {
GLES30.glBindBuffer(target, buffer)
logErrorIfAny("glBindBuffer")
}

fun glMapBufferRange(target: Int, offset: Int, length: Int, access: Int): Buffer {
val a = GLES30.glMapBufferRange(
target,
offset,
length,
access
)
logErrorIfAny("glMapBufferRange")
return a
}

fun glUnmapBuffer(target: Int) {
GLES30.glUnmapBuffer(target)
logErrorIfAny("glUnmapBuffer")
}


/**
* Get how many bytes it takes to represent a pixel given a texture format
* @param textureFormat The texture format
Expand All @@ -520,18 +498,15 @@ fun bytesPerPixel(textureFormat: Int): Int {
GLES20.GL_RGBA -> 4
GLES20.GL_RGB -> 3
GLES20.GL_ALPHA -> 1

else -> throw InvalidParameterException("textureFormat")
}
}

private fun logErrorIfAny(funcname: String) {
if (BuildConfig.DEBUG) {
var error = GLES20.glGetError()
while (error != 0) {
Log.e("OpenGL", funcname + ": " + error + ": " + errorToString(error))
error = GLES20.glGetError()
}
var error = GLES20.glGetError()
while (error != 0) {
Log.e("OpenGL", funcname + ": " + error + ": " + errorToString(error))
error = GLES20.glGetError()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import dk.scuffed.whiteboardapp.utils.Vec2Int
class OpenGLView(context: Context) : GLSurfaceView(context) {
private val renderer: PipelinedOpenGLRenderer
init {
setEGLContextClientVersion(3)
setEGLContextClientVersion(2)

renderer = PipelinedOpenGLRenderer(context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import dk.scuffed.whiteboardapp.pipeline.stages.output_stages.DrawFramebufferSta
import dk.scuffed.whiteboardapp.pipeline.stages.pipeline_stages.SwitchablePointPipeline
import dk.scuffed.whiteboardapp.pipeline.stages.points_stages.DraggablePointsStage

const val useDoubleBuffering = true

internal class Pipeline(context: Context, private val initialResolution: Size) : IPipeline {

private var stages = mutableListOf<Stage>()
Expand Down Expand Up @@ -53,7 +51,6 @@ internal class Pipeline(context: Context, private val initialResolution: Size) :

//dumpToGalleryFull(context, entirePipeline.second.frameBufferInfo, this)


val letterbox = LetterboxingStage(context, entirePipeline.second.frameBufferInfo, this)

DrawFramebufferStage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import android.graphics.Bitmap
import dk.scuffed.whiteboardapp.pipeline.IPipeline
import dk.scuffed.whiteboardapp.pipeline.stages.GLOutputStage
import dk.scuffed.whiteboardapp.pipeline.stages.PointsOutputStage
import dk.scuffed.whiteboardapp.pipeline.stages.bitmap_process_stages.FramebufferToBitmapPBOStage
import dk.scuffed.whiteboardapp.pipeline.stages.bitmap_process_stages.FramebufferToBitmapStage
import dk.scuffed.whiteboardapp.pipeline.stages.bitmap_process_stages.OpenCVLineDetectionStage
import dk.scuffed.whiteboardapp.pipeline.stages.points_stages.BiggestQuadStage
import dk.scuffed.whiteboardapp.pipeline.stages.lines_stages.LinesAngleDiscriminatorStage
import dk.scuffed.whiteboardapp.pipeline.stages.pipeline_stages.ThreadedBitmapInputPointOutputStage
import dk.scuffed.whiteboardapp.pipeline.stages.points_stages.WeightedPointsStage
import dk.scuffed.whiteboardapp.pipeline.useDoubleBuffering
import dk.scuffed.whiteboardapp.utils.Vec2Int

/**
Expand All @@ -25,74 +23,55 @@ internal fun fullCornerDetection(
inputStage: GLOutputStage,
pipeline: IPipeline
): PointsOutputStage {
val edges = fullCannyEdgeDetection(
context,
inputStage,
pipeline
)

val threadedBitmapInputPointOutputStage = ThreadedBitmapInputPointOutputStage(
{ pipeline ->
val edges = fullCannyEdgeDetection(
context,
inputStage,
pipeline
)
val edgesBitmapStage = FramebufferToBitmapStage(
edges.frameBufferInfo,
Bitmap.Config.ARGB_8888,
pipeline
)

val edgesBitmapStage = if (useDoubleBuffering) {
FramebufferToBitmapPBOStage(
edges.frameBufferInfo,
Bitmap.Config.ARGB_8888,
pipeline
)
}
else{
FramebufferToBitmapStage(
edges.frameBufferInfo,
Bitmap.Config.ARGB_8888,
pipeline
)
}
},
{ inputBitmapStage, pipeline ->
val openCVLineDetectionStage = OpenCVLineDetectionStage(
inputBitmapStage,
150,
50,
pipeline,
1.0,
Math.PI / 180.0,
15.0,
Math.PI / 75.0
)
val openCVLineDetectionStage = OpenCVLineDetectionStage(
edgesBitmapStage,
150,
50,
pipeline,
1.0,
Math.PI / 180.0,
15.0,
Math.PI / 75.0
)

val verticalLinesAngleDiscriminatorStage = LinesAngleDiscriminatorStage(
openCVLineDetectionStage,
-(Math.PI / 4.0f).toFloat(),
(Math.PI / 4.0f).toFloat(),
pipeline
)
val verticalLinesAngleDiscriminatorStage = LinesAngleDiscriminatorStage(
openCVLineDetectionStage,
-(Math.PI / 4.0f).toFloat(),
(Math.PI / 4.0f).toFloat(),
pipeline
)

val horizontalLinesAngleDiscriminatorStage = LinesAngleDiscriminatorStage(
openCVLineDetectionStage,
(Math.PI / 4.0f).toFloat(),
(Math.PI / 2.0f + Math.PI / 4.0f).toFloat(),
pipeline
)
val horizontalLinesAngleDiscriminatorStage = LinesAngleDiscriminatorStage(
openCVLineDetectionStage,
(Math.PI / 4.0f).toFloat(),
(Math.PI / 2.0f + Math.PI / 4.0f).toFloat(),
pipeline
)

val biggestQuadStage = BiggestQuadStage(
horizontalLinesAngleDiscriminatorStage,
verticalLinesAngleDiscriminatorStage,
pipeline
)
val biggestQuadStage = BiggestQuadStage(
horizontalLinesAngleDiscriminatorStage,
verticalLinesAngleDiscriminatorStage,
pipeline
)

val weightedCornerStage = WeightedPointsStage(
biggestQuadStage,
20,
pipeline
)
},
pipeline,
Vec2Int(0,0),
Vec2Int(0,0),
Vec2Int(0,0),
Vec2Int(0,0)
val weightedCornerStage = WeightedPointsStage(
biggestQuadStage,
20,
pipeline
)

return threadedBitmapInputPointOutputStage.myOutputPointsStage
return weightedCornerStage

}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ internal fun fullCornerDetectionWithDebugDrawing(
context,
pipeline,
biggestQuadStage,
Color(0.0f, 1.0f, 0.0f, 1.0f),
inputStage.frameBufferInfo.textureSize
)

Expand Down
Loading