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

Fix ALPHA_8 format support for bitmap in Cue. #2058

Open
wants to merge 1 commit into
base: release
Choose a base branch
from

Conversation

peerless2012
Copy link

@peerless2012 peerless2012 commented Jan 20, 2025

Bitmap.compress not support ALPHA_8 format, so we just copy the pixel buffer.

This should fix #2054

Copy link

google-cla bot commented Jan 20, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@peerless2012 peerless2012 changed the title Add ALPHA_8 format support for bitmap in Cue. Fix ALPHA_8 format support for bitmap in Cue. Jan 20, 2025
@@ -835,6 +837,9 @@ public Cue build() {
private static final String FIELD_MULTI_ROW_ALIGNMENT = Util.intToStringMaxRadix(2);
private static final String FIELD_BITMAP_PARCELABLE = Util.intToStringMaxRadix(3);
private static final String FIELD_BITMAP_BYTES = Util.intToStringMaxRadix(18);
private static final String FIELD_BITMAP_ORIGIN_WIDTH = Util.intToStringMaxRadix(19);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the meaning of the word 'origin' here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bitmap compress don't support ALPHA_8, so we have to store the bitmap original size and buffer, then when read cue, we need use the bitmap size.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bitmap compress don't support ALPHA_8, so we have to store the bitmap original size and buffer, then when read cue, we need use the bitmap size.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand why you need to transfer the size and width separately to the bytes. I don't understand what the meaning of the word 'origin' is. My first assumption is that this means the (0,0) point: https://en.wikipedia.org/wiki/Origin_(mathematics), but I'm not sure that really makes sense. So what is the intended meaning?


/** Tests for {@link Cue}. */
@RunWith(AndroidJUnit4.class)
public class CueTest {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's just move the whole of CueTest to androidTest instead of splitting it like this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The robolectric test suite not support ALPHA_8 bitmap, so we have to use AndroidTest.
See Request support bitmap with ALPHA_8.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand.

I'm asking you to move the existing CueTest from libraries/common/src/test/java/androidx/media3/common/text to libraries/common/src/androidTest/java/androidx/media3/common/text and then add this new test method to it.

The current change results in two classes called androidx.media3.common.text.CueTest which results in undefined behaviour when debugging in Android Studio, and having to look in two places when checking what parts of Cue are tested.

bitmap = Bitmap.createBitmap(bitmapWidth,bitmapHeight, Bitmap.Config.ALPHA_8);
Buffer buffer = ByteBuffer.wrap(bitmapBytes);
bitmap.copyPixelsFromBuffer(buffer);
builder.setBitmap(bitmap);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: de-duplicate the 3 builder.setBitmap lines, so the code is instead:

@Nullable Bitmap bitmap = bundle.getParcelable(FIELD_BITMAP_PARCELABLE);
if (bitmap == null) {
  // handle bytes case (both compressed and uncompressed) with 
  // existing code, but assigning `bitmap` each time instead of setting
  // it on the builder.
}
builder.setBitmap(bitmap); // Passing null is fine here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cue encode error when use bitmap and config is ALPHA_8.
2 participants