mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Rename DefaultImageDecoder to BitmapFactoryImageDecoder
This reflects the documented behaviour of this class. #minor-release PiperOrigin-RevId: 569475137
This commit is contained in:
parent
34dddfe9d5
commit
8f5835c51c
6 changed files with 23 additions and 21 deletions
|
|
@ -48,7 +48,7 @@ import java.nio.ByteBuffer;
|
||||||
* alongside one timestamp)).
|
* alongside one timestamp)).
|
||||||
*/
|
*/
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public final class DefaultImageDecoder
|
public final class BitmapFactoryImageDecoder
|
||||||
extends SimpleDecoder<DecoderInputBuffer, ImageOutputBuffer, ImageDecoderException>
|
extends SimpleDecoder<DecoderInputBuffer, ImageOutputBuffer, ImageDecoderException>
|
||||||
implements ImageDecoder {
|
implements ImageDecoder {
|
||||||
|
|
||||||
|
|
@ -67,7 +67,7 @@ public final class DefaultImageDecoder
|
||||||
Bitmap decode(byte[] data, int length) throws ImageDecoderException;
|
Bitmap decode(byte[] data, int length) throws ImageDecoderException;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A factory for {@link DefaultImageDecoder} instances. */
|
/** A factory for {@link BitmapFactoryImageDecoder} instances. */
|
||||||
public static final class Factory implements ImageDecoder.Factory {
|
public static final class Factory implements ImageDecoder.Factory {
|
||||||
private static final ImmutableSet<String> SUPPORTED_IMAGE_TYPES = getSupportedMimeTypes();
|
private static final ImmutableSet<String> SUPPORTED_IMAGE_TYPES = getSupportedMimeTypes();
|
||||||
|
|
||||||
|
|
@ -77,7 +77,7 @@ public final class DefaultImageDecoder
|
||||||
* Creates an instance using a {@link BitmapFactory} implementation of {@link BitmapDecoder}.
|
* Creates an instance using a {@link BitmapFactory} implementation of {@link BitmapDecoder}.
|
||||||
*/
|
*/
|
||||||
public Factory() {
|
public Factory() {
|
||||||
this.bitmapDecoder = DefaultImageDecoder::decode;
|
this.bitmapDecoder = BitmapFactoryImageDecoder::decode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -103,8 +103,8 @@ public final class DefaultImageDecoder
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DefaultImageDecoder createImageDecoder() {
|
public BitmapFactoryImageDecoder createImageDecoder() {
|
||||||
return new DefaultImageDecoder(bitmapDecoder);
|
return new BitmapFactoryImageDecoder(bitmapDecoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ImmutableSet<String> getSupportedMimeTypes() {
|
private static ImmutableSet<String> getSupportedMimeTypes() {
|
||||||
|
|
@ -120,7 +120,7 @@ public final class DefaultImageDecoder
|
||||||
|
|
||||||
private final BitmapDecoder bitmapDecoder;
|
private final BitmapDecoder bitmapDecoder;
|
||||||
|
|
||||||
private DefaultImageDecoder(BitmapDecoder bitmapDecoder) {
|
private BitmapFactoryImageDecoder(BitmapDecoder bitmapDecoder) {
|
||||||
super(new DecoderInputBuffer[1], new ImageOutputBuffer[1]);
|
super(new DecoderInputBuffer[1], new ImageOutputBuffer[1]);
|
||||||
this.bitmapDecoder = bitmapDecoder;
|
this.bitmapDecoder = bitmapDecoder;
|
||||||
}
|
}
|
||||||
|
|
@ -140,7 +140,7 @@ public final class DefaultImageDecoder
|
||||||
return new ImageOutputBuffer() {
|
return new ImageOutputBuffer() {
|
||||||
@Override
|
@Override
|
||||||
public void release() {
|
public void release() {
|
||||||
DefaultImageDecoder.this.releaseOutputBuffer(this);
|
BitmapFactoryImageDecoder.this.releaseOutputBuffer(this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -32,7 +32,7 @@ public interface ImageDecoder
|
||||||
interface Factory {
|
interface Factory {
|
||||||
|
|
||||||
/** Default implementation of an image decoder factory. */
|
/** Default implementation of an image decoder factory. */
|
||||||
ImageDecoder.Factory DEFAULT = new DefaultImageDecoder.Factory();
|
ImageDecoder.Factory DEFAULT = new BitmapFactoryImageDecoder.Factory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the highest {@link Capabilities} of the factory's decoders for the given {@link
|
* Returns the highest {@link Capabilities} of the factory's decoders for the given {@link
|
||||||
|
|
|
||||||
|
|
@ -31,14 +31,15 @@ import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link DefaultImageDecoder} ensuring the buffer queue system operates correctly.
|
* Unit tests for {@link BitmapFactoryImageDecoder} ensuring the buffer queue system operates
|
||||||
|
* correctly.
|
||||||
*/
|
*/
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class DefaultImageDecoderBufferQueueTest {
|
public class BitmapFactoryImageDecoderBufferQueueTest {
|
||||||
|
|
||||||
private static final long TIMEOUT_MS = 5 * C.MICROS_PER_SECOND;
|
private static final long TIMEOUT_MS = 5 * C.MICROS_PER_SECOND;
|
||||||
|
|
||||||
private DefaultImageDecoder fakeImageDecoder;
|
private BitmapFactoryImageDecoder fakeImageDecoder;
|
||||||
private Bitmap decodedBitmap1;
|
private Bitmap decodedBitmap1;
|
||||||
private Bitmap decodedBitmap2;
|
private Bitmap decodedBitmap2;
|
||||||
|
|
||||||
|
|
@ -50,7 +51,7 @@ public class DefaultImageDecoderBufferQueueTest {
|
||||||
decodedBitmap1 = Bitmap.createBitmap(/* width= */ 1, /* height= */ 1, Bitmap.Config.ARGB_8888);
|
decodedBitmap1 = Bitmap.createBitmap(/* width= */ 1, /* height= */ 1, Bitmap.Config.ARGB_8888);
|
||||||
decodedBitmap2 = Bitmap.createBitmap(/* width= */ 2, /* height= */ 2, Bitmap.Config.ARGB_8888);
|
decodedBitmap2 = Bitmap.createBitmap(/* width= */ 2, /* height= */ 2, Bitmap.Config.ARGB_8888);
|
||||||
fakeImageDecoder =
|
fakeImageDecoder =
|
||||||
new DefaultImageDecoder.Factory(
|
new BitmapFactoryImageDecoder.Factory(
|
||||||
(data, length) -> ++decodeCallCount == 1 ? decodedBitmap1 : decodedBitmap2)
|
(data, length) -> ++decodeCallCount == 1 ? decodedBitmap1 : decodedBitmap2)
|
||||||
.createImageDecoder();
|
.createImageDecoder();
|
||||||
}
|
}
|
||||||
|
|
@ -26,11 +26,12 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
/** Unit tests for {@link DefaultImageDecoder.Factory}. */
|
/** Unit tests for {@link BitmapFactoryImageDecoder.Factory}. */
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class DefaultImageDecoderFactoryTest {
|
public class BitmapFactoryImageDecoderFactoryTest {
|
||||||
|
|
||||||
private final DefaultImageDecoder.Factory imageDecoderFactory = new DefaultImageDecoder.Factory();
|
private final BitmapFactoryImageDecoder.Factory imageDecoderFactory =
|
||||||
|
new BitmapFactoryImageDecoder.Factory();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void supportsFormat_validFormat_returnsFormatSupported() throws Exception {
|
public void supportsFormat_validFormat_returnsFormatSupported() throws Exception {
|
||||||
|
|
@ -34,21 +34,21 @@ import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.annotation.GraphicsMode;
|
import org.robolectric.annotation.GraphicsMode;
|
||||||
|
|
||||||
/** Unit tests for {@link DefaultImageDecoder}. */
|
/** Unit tests for {@link BitmapFactoryImageDecoder}. */
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
@GraphicsMode(value = NATIVE)
|
@GraphicsMode(value = NATIVE)
|
||||||
public class DefaultImageDecoderTest {
|
public class BitmapFactoryImageDecoderTest {
|
||||||
|
|
||||||
private static final String PNG_TEST_IMAGE_PATH = "media/png/non-motion-photo-shortened.png";
|
private static final String PNG_TEST_IMAGE_PATH = "media/png/non-motion-photo-shortened.png";
|
||||||
private static final String JPEG_TEST_IMAGE_PATH = "media/jpeg/non-motion-photo-shortened.jpg";
|
private static final String JPEG_TEST_IMAGE_PATH = "media/jpeg/non-motion-photo-shortened.jpg";
|
||||||
|
|
||||||
private DefaultImageDecoder decoder;
|
private BitmapFactoryImageDecoder decoder;
|
||||||
private DecoderInputBuffer inputBuffer;
|
private DecoderInputBuffer inputBuffer;
|
||||||
private ImageOutputBuffer outputBuffer;
|
private ImageOutputBuffer outputBuffer;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
decoder = new DefaultImageDecoder.Factory().createImageDecoder();
|
decoder = new BitmapFactoryImageDecoder.Factory().createImageDecoder();
|
||||||
inputBuffer = decoder.createInputBuffer();
|
inputBuffer = decoder.createInputBuffer();
|
||||||
outputBuffer = decoder.createOutputBuffer();
|
outputBuffer = decoder.createOutputBuffer();
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2023 The Android Open Source Project
|
* Copyright 2023 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -79,7 +79,7 @@ public class ImageRendererTest {
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
decodeCallCount = 0;
|
decodeCallCount = 0;
|
||||||
ImageDecoder.Factory fakeDecoderFactory =
|
ImageDecoder.Factory fakeDecoderFactory =
|
||||||
new DefaultImageDecoder.Factory(
|
new BitmapFactoryImageDecoder.Factory(
|
||||||
(data, length) -> ++decodeCallCount == 1 ? fakeDecodedBitmap1 : fakeDecodedBitmap2);
|
(data, length) -> ++decodeCallCount == 1 ? fakeDecodedBitmap1 : fakeDecodedBitmap2);
|
||||||
ImageOutput queuingImageOutput =
|
ImageOutput queuingImageOutput =
|
||||||
new ImageOutput() {
|
new ImageOutput() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue