Skip to content

Commit

Permalink
Disable radio buttons when export starts
Browse files Browse the repository at this point in the history
  • Loading branch information
calren committed Jul 22, 2024
1 parent 5e4ccde commit 0ab9efb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ The sample demonstrates the importance of having proper labels for
A sample showcasing how to handle calls with the Jetpack Telecom API
- [TextSpan](user-interface/text/src/main/java/com/example/platform/ui/text/TextSpan.kt):
buildSpannedString is useful for quickly building a rich text.
- [Transformer and TFLite integration](media/video/src/main/java/com/example/platform/media/video/TransformerTFLite.kt):
- [Transformer and TFLite](media/video/src/main/java/com/example/platform/media/video/TransformerTFLite.kt):
This sample demonstrates using Transformer with TFLite by applying a selected art style to a video.
- [UltraHDR Image Capture](camera/camera2/src/main/java/com/example/platform/camera/imagecapture/Camera2UltraHDRCapture.kt):
This sample demonstrates how to capture a 10-bit compressed still image and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@

import javax.microedition.khronos.opengles.GL10;

// TODO: Migrate this class to Kotlin
@UnstableApi
final class StyleTransferShaderProgram extends BaseGlShaderProgram {

private static final String TAG = "StyleTransferSP";
private static final String VERTEX_SHADER_PATH = "shaders/vertex_shader_transformation_es2.glsl";
private static final String FRAGMENT_SHADER_PATH = "shaders/fragment_shader_copy_es2.glsl";

Expand Down Expand Up @@ -108,7 +110,7 @@ public StyleTransferShaderProgram(Context context, String styleAssetFileName)
predictOutput = TensorBuffer.createFixedSize(outputPredictShape, DataType.FLOAT32);
predictInterpeter.run(styleTensorImage.getBuffer(), predictOutput.getBuffer());
} catch (IOException | GlUtil.GlException e) {
Log.w("DEBUG", "Error setting up TfShaderProgram", e);
Log.w(TAG, "Error setting up TfShaderProgram", e);
throw new VideoFrameProcessingException(e);
}
}
Expand Down Expand Up @@ -145,11 +147,11 @@ public void drawFrame(int inputTexId, long presentationTimeUs)
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.copyPixelsFromBuffer(pixelBuffer);

Log.w("DEBUG", "Process frame at " + (presentationTimeUs / 1000) + " ms");
Log.w(TAG, "Process frame at " + (presentationTimeUs / 1000) + " ms");
long before = System.currentTimeMillis();
TensorImage tensorImage =
getScaledTensorImage(bitmap, inputTransformTargetWidth, inputTransformTargetHeight);
Log.w("DEBUG", "- Scale " + (System.currentTimeMillis() - before) + " ms");
Log.w(TAG, "- Scale " + (System.currentTimeMillis() - before) + " ms");
TensorBuffer outputImage =
TensorBuffer.createFixedSize(outputTransformShape, DataType.FLOAT32);

Expand All @@ -158,7 +160,7 @@ public void drawFrame(int inputTexId, long presentationTimeUs)
new Object[] {tensorImage.getBuffer(), predictOutput.getBuffer()},
ImmutableMap.<Integer, Object>builder().put(0, outputImage.getBuffer()).build());

Log.w("DEBUG", "- Run " + (System.currentTimeMillis() - before) + " ms");
Log.w(TAG, "- Run " + (System.currentTimeMillis() - before) + " ms");

before = System.currentTimeMillis();
ImageProcessor imagePostProcessor =
Expand All @@ -167,11 +169,11 @@ public void drawFrame(int inputTexId, long presentationTimeUs)
.build();
TensorImage outputTensorImage = new TensorImage(DataType.FLOAT32);
outputTensorImage.load(outputImage);
Log.w("DEBUG", "- Load output " + (System.currentTimeMillis() - before) + " ms");
Log.w(TAG, "- Load output " + (System.currentTimeMillis() - before) + " ms");

before = System.currentTimeMillis();
Bitmap outputBitmap = imagePostProcessor.process(outputTensorImage).getBitmap();
Log.w("DEBUG", "- Post process output " + (System.currentTimeMillis() - before) + " ms");
Log.w(TAG, "- Post process output " + (System.currentTimeMillis() - before) + " ms");

texId =
GlUtil.createTexture(
Expand All @@ -193,7 +195,6 @@ public void drawFrame(int inputTexId, long presentationTimeUs)
float[] identityMatrix = GlUtil.create4x4IdentityMatrix();
glProgram.setFloatsUniform("uTexTransformationMatrix", identityMatrix);
glProgram.setFloatsUniform("uTransformationMatrix", identityMatrix);
// glProgram.setFloatsUniform("uRgbMatrix", identityMatrix);
glProgram.setBufferAttribute(
"aFramePosition",
GlUtil.getNormalizedCoordinateBounds(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class TransformerTFLite : Fragment() {
Log.i(TAG, "Transformation is completed")
exportStopwatch?.stop()
playOutput()
binding.exportButton.isEnabled = true
// Don't re-enable options to export with another style, because the result looks
// glitchy on subsequent exports. Consider looking into why this is the case.
}

override fun onError(
Expand All @@ -96,7 +97,6 @@ class TransformerTFLite : Fragment() {
) {
exportStopwatch?.stop()
Log.i(TAG, "Error during transformation:" + exception.errorCodeName)
binding.exportButton.isEnabled = true
}
}

Expand All @@ -121,6 +121,9 @@ class TransformerTFLite : Fragment() {
super.onViewCreated(view, savedInstanceState)
binding.exportButton.setOnClickListener {
binding.exportButton.isEnabled = false
for (i in 0..<binding.styleRadioGroup.childCount) {
binding.styleRadioGroup.getChildAt(i).isEnabled = false
}
exportComposition()
}

Expand Down

0 comments on commit 0ab9efb

Please sign in to comment.