diff --git a/android/build.gradle b/android/build.gradle index 32e19960..a3273df1 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -44,6 +44,9 @@ android { testImplementation deps.mockitoCore testImplementation deps.robolectric } + lintOptions { + abortOnError false + } } apply plugin: 'com.vanniktech.maven.publish' diff --git a/android/sample/build.gradle b/android/sample/build.gradle index 578eacf5..e05500f8 100644 --- a/android/sample/build.gradle +++ b/android/sample/build.gradle @@ -12,7 +12,7 @@ android { buildToolsVersion rootProject.buildToolsVersion defaultConfig { - minSdkVersion rootProject.minSdkVersion + minSdkVersion 19 targetSdkVersion rootProject.targetSdkVersion multiDexEnabled = true } @@ -30,6 +30,10 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro' } } + + lintOptions { + abortOnError false + } } dependencies { diff --git a/android/spectrumtests/build.gradle b/android/spectrumtests/build.gradle index 95996274..af3f6e70 100644 --- a/android/spectrumtests/build.gradle +++ b/android/spectrumtests/build.gradle @@ -34,6 +34,10 @@ android { } } } + + lintOptions { + abortOnError false + } } dependencies { diff --git a/android/spectrumtestutils/build.gradle b/android/spectrumtestutils/build.gradle index da1eaa7b..087c0e0e 100644 --- a/android/spectrumtestutils/build.gradle +++ b/android/spectrumtestutils/build.gradle @@ -53,6 +53,10 @@ android { exclude "**/libspectrumfbjni.so" exclude "**/libspectrum.so" } + + lintOptions { + abortOnError false + } } dependencies { diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/ExecutingAssertion.java b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/ExecutingAssertion.java deleted file mode 100644 index 12180a7b..00000000 --- a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/ExecutingAssertion.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum.testutils; - -import static org.assertj.core.api.Assertions.assertThat; - -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import androidx.exifinterface.media.ExifInterface; -import com.facebook.spectrum.BitmapTarget; -import com.facebook.spectrum.EncodedImageSink; -import com.facebook.spectrum.EncodedImageSource; -import com.facebook.spectrum.Spectrum; -import com.facebook.spectrum.SpectrumResult; -import com.facebook.spectrum.options.DecodeOptions; -import com.facebook.spectrum.options.EncodeOptions; -import com.facebook.spectrum.options.TranscodeOptions; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -public interface ExecutingAssertion { - String CALLER_CONTEXT = "ExecutingAssertion"; - - ExecutionResult execute(final Spectrum spectrum, final SpectrumAssertUtils.Builder builder) - throws Exception; - - class Transcode implements ExecutingAssertion { - private final TranscodeOptions options; - - /*package*/ Transcode(final TranscodeOptions options) { - this.options = options; - } - - @Override - public ExecutionResult execute( - final Spectrum spectrum, final SpectrumAssertUtils.Builder builder) throws Exception { - final EncodedImageSource source = - EncodedImageSource.from(TestData.getInputStream(builder.inputPath)); - final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - final EncodedImageSink sink = EncodedImageSink.from(outputStream); - - final SpectrumResult spectrumResult = - spectrum.transcode(source, sink, options, CALLER_CONTEXT); - - if (builder.assertOutputExifOrientation != null) { - Utils.assertExifOrientation(builder, outputStream); - } - - return new ExecutionResult(spectrumResult, Utils.byteArrayStreamToBitmap(outputStream)); - } - } - - class Decode implements ExecutingAssertion { - private final DecodeOptions options; - - /*package*/ Decode(final DecodeOptions options) { - this.options = options; - } - - @Override - public ExecutionResult execute( - final Spectrum spectrum, final SpectrumAssertUtils.Builder builder) throws Exception { - final EncodedImageSource source = - EncodedImageSource.from(TestData.getInputStream(builder.inputPath)); - final BitmapTarget bitmapTarget = new BitmapTarget(); - - final SpectrumResult spectrumResult = - spectrum.decode(source, bitmapTarget, options, CALLER_CONTEXT); - - assertThat(bitmapTarget.getBitmap()).isNotNull(); - - return new ExecutionResult(spectrumResult, bitmapTarget.getBitmap()); - } - } - - class Encode implements ExecutingAssertion { - private final EncodeOptions options; - - /*package*/ Encode(final EncodeOptions options) { - this.options = options; - } - - @Override - public ExecutionResult execute( - final Spectrum spectrum, final SpectrumAssertUtils.Builder builder) throws Exception { - final Bitmap inputBitmap = TestData.getBitmap(builder.inputPath); - final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - final EncodedImageSink sink = EncodedImageSink.from(outputStream); - - final SpectrumResult spectrumResult = - spectrum.encode(inputBitmap, sink, options, CALLER_CONTEXT); - - if (builder.assertOutputExifOrientation != null) { - Utils.assertExifOrientation(builder, outputStream); - } - - return new ExecutionResult(spectrumResult, Utils.byteArrayStreamToBitmap(outputStream)); - } - } - - class ExecutionResult { - final SpectrumResult spectrumResult; - final Bitmap outputBitmap; - - ExecutionResult(final SpectrumResult spectrumResult, final Bitmap outputBitmap) { - this.spectrumResult = spectrumResult; - this.outputBitmap = outputBitmap; - } - } - - class Utils { - private static Bitmap byteArrayStreamToBitmap(final ByteArrayOutputStream outputStream) { - final byte[] outputData = outputStream.toByteArray(); - return BitmapFactory.decodeByteArray(outputData, 0, outputData.length); - } - - private static void assertExifOrientation( - final SpectrumAssertUtils.Builder builder, final ByteArrayOutputStream outputStream) - throws IOException { - final ByteArrayInputStream byteArrayInputStream = - new ByteArrayInputStream(outputStream.toByteArray()); - final ExifInterface exifInterface = new ExifInterface(byteArrayInputStream); - - final int actualOrientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0); - - assertThat(actualOrientation).isEqualTo(builder.assertOutputExifOrientation); - } - } -} diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/FailingInputStream.java b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/FailingInputStream.java deleted file mode 100644 index 1864a819..00000000 --- a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/FailingInputStream.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum.testutils; - -import java.io.IOException; -import java.io.InputStream; - -/** - * Input stream that will throw once a certain number of bytes have been read. The thrown exception - * be a {@link IOException} with the message {@link #EXCEPTION_MESSAGE}. - */ -public class FailingInputStream extends InputStream { - - public static final String EXCEPTION_MESSAGE = "Flux compensator implosion"; - - private final InputStream underlyingInputStream; - private long bytesBeforeFail; - - public FailingInputStream(final InputStream underlyingInputStream, final long bytesBeforeFail) { - this.underlyingInputStream = underlyingInputStream; - this.bytesBeforeFail = bytesBeforeFail; - } - - @Override - public int read() throws IOException { - if (bytesBeforeFail == 0) { - throw new IOException(EXCEPTION_MESSAGE); - } - bytesBeforeFail--; - return underlyingInputStream.read(); - } - - @Override - public int available() throws IOException { - return underlyingInputStream.available(); - } -} diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/ImageComparison.java b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/ImageComparison.java deleted file mode 100644 index ec4d398e..00000000 --- a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/ImageComparison.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum.testutils; - -import android.graphics.Bitmap; -import java.util.Locale; - -/** - * Simple implementations of image comparison algorithms for instrumentation test purposes. As these - * are naive and unoptimized implementations do not use them in production code. - */ -public final class ImageComparison { - - public enum ImageComparisonMethod { - SSIM - } - - public static float compare(Bitmap a, Bitmap b, ImageComparisonMethod comparisonMethod) { - if (a.getHeight() != b.getHeight() - || a.getWidth() != b.getWidth() - || a.getConfig() != b.getConfig()) { - throw new IllegalArgumentException( - String.format( - (Locale) null, - "Bitmaps must match in size and configuration a=(%d %d) does not match b=(%d %d)", - a.getWidth(), - a.getHeight(), - b.getWidth(), - b.getHeight())); - } - - switch (comparisonMethod) { - case SSIM: - return ImageComparisonSsim.compareSsim(a, b); - default: - throw new IllegalArgumentException("Not yet implemented: " + comparisonMethod); - } - } -} diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/ImageComparisonSsim.java b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/ImageComparisonSsim.java deleted file mode 100644 index 6782bbf9..00000000 --- a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/ImageComparisonSsim.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum.testutils; - -import android.graphics.Bitmap; -import com.facebook.spectrum.utils.Preconditions; - -/** Simple (approximate) implementation of the SSIM image similarity metric. */ -/* package */ final class ImageComparisonSsim { - - private static final float SSIM_K1 = 0.01f; - private static final float SSIM_K2 = 0.03f; - private static final float SSIM_MAX_VALUE = 256f; - - private static final float SSIM_C1 = (SSIM_K1 * SSIM_MAX_VALUE) * (SSIM_K1 * SSIM_MAX_VALUE); - private static final float SSIM_C2 = (SSIM_K2 * SSIM_MAX_VALUE) * (SSIM_K2 * SSIM_MAX_VALUE); - - private static final int SSIM_WINDOW_SIZE = 8; - private static final int SSIM_WINDOW_STEP = 4; - - private static final int MASK_RIGHT_MOST_CHANNEL = 0x000000FF; - - /** - * Complexity: O(channels * w/stepSize * h/stepSize * windowsSize^2) - * - *

Given that channels=3, stepSize=4 and windowSize=8 this results in O(bitmapSize) with a - * large constant factor. This is usually too slow for large images in production scenarios, but - * it works fine for tests. - * - *

Memory complexity is O(windowSize^2) - */ - /* package */ static float compareSsim(final Bitmap a, final Bitmap b) { - Preconditions.checkArgument(a.getWidth() == b.getWidth()); - Preconditions.checkArgument(a.getHeight() == b.getHeight()); - - final int w = a.getWidth(); - final int h = a.getHeight(); - Preconditions.checkArgument(w >= SSIM_WINDOW_SIZE); - Preconditions.checkArgument(h >= SSIM_WINDOW_SIZE); - - final int l = SSIM_WINDOW_SIZE * SSIM_WINDOW_SIZE; - int[] pixelsA = new int[l]; - int[] pixelsB = new int[l]; - int[] channelA = new int[l]; - int[] channelB = new int[l]; - - float ssimSum = 0.0f; - int ssimRuns = 0; - - for (int x = 0; x < w - SSIM_WINDOW_SIZE; x += SSIM_WINDOW_STEP) { - for (int y = 0; y < h - SSIM_WINDOW_SIZE; y += SSIM_WINDOW_STEP) { - a.getPixels(pixelsA, 0, SSIM_WINDOW_SIZE, x, y, SSIM_WINDOW_SIZE, SSIM_WINDOW_SIZE); - b.getPixels(pixelsB, 0, SSIM_WINDOW_SIZE, x, y, SSIM_WINDOW_SIZE, SSIM_WINDOW_SIZE); - - for (int channel = 0; channel < 2; channel++) { - final int shift = channel * 8; - - for (int i = 0; i < l; i++) { - channelA[i] = (pixelsA[i] >> shift) & MASK_RIGHT_MOST_CHANNEL; - channelB[i] = (pixelsB[i] >> shift) & MASK_RIGHT_MOST_CHANNEL; - } - - final float ssim = ssimForWindow(l, channelA, channelB); - ssimSum += ssim; - ssimRuns += 1; - } - } - } - - return ssimSum / (float) ssimRuns; - } - - /** - * Complexity: O(l) - * - *

l usually is ~windowSize^2 - */ - private static float ssimForWindow(final int l, final int[] a, final int[] b) { - Preconditions.checkArgument(l == a.length); - Preconditions.checkArgument(l == b.length); - - // calculate avg - float avgA = 0.0f, avgB = 0.0f; - for (int i = 0; i < l; i++) { - avgA += a[i]; - avgB += b[i]; - } - avgA /= (float) l; - avgB /= (float) l; - - // calculate variance - float varA = 0.0f, varB = 0.0f; - for (int i = 0; i < l; i++) { - final float ta = a[i] - avgA; - final float tb = b[i] - avgB; - varA += ta * ta; - varB += tb * tb; - } - varA /= (float) l; - varB /= (float) l; - - // calculate co-variance - float covAB = 0.0f; - for (int i = 0; i < l; i++) { - covAB += (a[i] - avgA) * (b[i] - avgB); - } - covAB /= (float) l; - - // combine in SSIM formula - final float t1 = 2 * avgA * avgB + SSIM_C1; - final float t2 = 2 * covAB + SSIM_C2; - final float t3 = avgA * avgA + avgB * avgB + SSIM_C1; - final float t4 = varA + varB + SSIM_C2; - return (t1 * t2) / (t3 * t4); - } -} diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/SpectrumAssertUtils.java b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/SpectrumAssertUtils.java deleted file mode 100644 index 95d31907..00000000 --- a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/SpectrumAssertUtils.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum.testutils; - -import static com.facebook.spectrum.testutils.ImageComparison.ImageComparisonMethod.SSIM; -import static org.assertj.core.api.Assertions.assertThat; - -import android.graphics.Bitmap; -import com.facebook.spectrum.Spectrum; -import com.facebook.spectrum.image.ImageFormat; -import com.facebook.spectrum.image.ImageSpecification; -import com.facebook.spectrum.options.DecodeOptions; -import com.facebook.spectrum.options.EncodeOptions; -import com.facebook.spectrum.options.TranscodeOptions; -import com.facebook.spectrum.testutils.ExecutingAssertion.ExecutionResult; -import com.facebook.spectrum.utils.Preconditions; -import java.io.IOException; -import javax.annotation.Nullable; -import org.assertj.core.data.Offset; - -public class SpectrumAssertUtils { - - public static void executeAndAssert(final Spectrum spectrum, final Builder builder) - throws Exception { - builder.validate(); // throws if ill-configured - - final ExecutionResult executionResult = builder.executingAssertion.execute(spectrum, builder); - assertThat(executionResult.spectrumResult.isSuccessful()).isTrue(); - - if (builder.assertOutputFormat != null) { - final ImageSpecification outputImageSpecification = - executionResult.spectrumResult.getOutputImageSpecification(); - - assertThat(outputImageSpecification.format).isEqualTo(builder.assertOutputFormat); - } - - if (builder.comparisionBitmap != null) { - final float similarity = - ImageComparison.compare(builder.comparisionBitmap, executionResult.outputBitmap, SSIM); - - assertThat(similarity).isEqualTo(builder.ssimTarget, builder.ssimTolerance); - } - } - - public static class Builder { - final String inputPath; - - @Nullable Bitmap comparisionBitmap = null; - Offset ssimTolerance = Offset.offset(0.05f); - float ssimTarget = 1.0f; - - ExecutingAssertion executingAssertion = null; - @Nullable ImageFormat assertOutputFormat; - @Nullable Integer assertOutputExifOrientation; - - private Builder(final String inputPath) { - this.inputPath = inputPath; - } - - public static Builder withTestImage(final String testImagePath) { - return new Builder(testImagePath); - } - - public Builder transcoding(final TranscodeOptions options) { - this.executingAssertion = new ExecutingAssertion.Transcode(options); - return this; - } - - public Builder decoding(final DecodeOptions options) { - this.executingAssertion = new ExecutingAssertion.Decode(options); - return this; - } - - public Builder encoding(final EncodeOptions options) { - this.executingAssertion = new ExecutingAssertion.Encode(options); - return this; - } - - public Builder comparingAgainst(final Bitmap bitmap) { - this.comparisionBitmap = bitmap; - return this; - } - - public Builder comparingAgainstTestFile(final String testImagePath) throws IOException { - this.comparisionBitmap = TestData.getBitmap(testImagePath); - return this; - } - - public Builder usingSsimTarget(final float ssimTarget) { - Preconditions.checkArgument(ssimTarget >= 0f && ssimTarget <= 1f); - this.ssimTarget = ssimTarget; - return this; - } - - public Builder usingSsimTolerance(final Offset ssimTolerance) { - Preconditions.checkArgument(ssimTolerance.value >= 0f && ssimTolerance.value <= 1f); - this.ssimTolerance = ssimTolerance; - return this; - } - - public Builder usingSsimTolerance(final float offset) { - return usingSsimTolerance(Offset.offset(offset)); - } - - public Builder assertingOutputFormat(final ImageFormat imageFormat) { - this.assertOutputFormat = imageFormat; - return this; - } - - public Builder assertingOutputExifOrientation(final int exifOrientation) { - this.assertOutputExifOrientation = exifOrientation; - return this; - } - - void validate() { - if (executingAssertion == null) { - throw new IllegalArgumentException( - "When using TestCaseUtil.Builder, " - + "one must specify the intended operation using either " - + ".transcoding(...), .decoding(...), or .encoding(...)"); - } - if (assertOutputExifOrientation != null) { - if (executingAssertion instanceof ExecutingAssertion.Decode) { - throw new IllegalArgumentException( - "The assertOutputExifOrientation(...) option can only be applied to encoding and " - + "transcoding operations."); - } - } - } - } -} diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/TestData.java b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/TestData.java deleted file mode 100644 index eaaaf24c..00000000 --- a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/TestData.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum.testutils; - -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import androidx.test.InstrumentationRegistry; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; - -public class TestData { - - public interface JPEG { - String PATH_85x128_Q15 = "sample_85x128_q15.jpg"; - String PATH_85x128_Q85 = "sample_85x128_q85.jpg"; - - String PATH_128x85_Q75_BASELINE = "128x85_q75_baseline.jpg"; - String PATH_128x85_Q75_GRAYSCALE = "128x85_q75_grayscale.jpg"; - String PATH_128x85_Q75_PROGRESSIVE = "128x85_q75_progressive.jpg"; - String PATH_800x530_Q75_BASELINE = "800x530_q75_baseline.jpg"; - String PATH_800x530_Q75_GRAYSCALE = "800x530_q75_grayscale.jpg"; - String PATH_800x530_Q75_PROGRESSIVE = "800x530_q75_progressive.jpg"; - - String PATH_128x85_Q75_PROGRESSIVE_R90 = "128x85_q75_progressive_r90.jpg"; - - String PATH_CROPPED_200x100_100_50_Q95 = "c200x100_o100_50_q95.jpg"; - String PATH_CROPPED_RELATIVE_50Px60P_CENTER_Q95 = "c50px60p_center_q95.jpg"; - - // jpegtran -trim -crop 128x64+32+16 800x530_q75_baseline.jpg > - // jpegtran_800x530_c128x64ox32oy16.jpg - String PATH_JPEGTRAN_800x530_C128X64_OX32_OY16 = "jpegtran_800x530_c128x64ox32oy16.jpg"; - - // jpegtran -trim -rotate 90 -crop 128x64+32+16 800x530_q75_baseline.jpg > - // jpegtran_800x530_c128x64ox32oy16.jpg - String PATH_JPEGTRAN_800x530_ROTATE90_C128X64_OX32_OY16 = - "jpegtran_800x530_rotate90_c128x64ox32oy16.jpg"; - - String PATH_4096x2713_BENCHMARK_LARGE = "4096x2713_benchmark_large.jpg"; - - String PATH_16x16_WHITE_Q75 = "16x16_white_q75.jpg"; - String PATH_16x16_BLACK_Q75 = "16x16_black_q75.jpg"; - String PATH_16x16_WHITE_Q75_GRAYSCALE = "16x16_white_q75_grayscale.jpg"; - String PATH_16x16_BLACK_Q75_GRAYSCALE = "16x16_black_q75_grayscale.jpg"; - String PATH_16x16_cABCDF0_Q75 = "16x16_cABCDF0_q75.jpg"; - } - - public interface PNG { - String PATH_128x85 = "128x85.png"; - String PATH_128x85_ARGB = "128x85_argb.png"; - String PATH_800x530 = "800x530.png"; - String PATH_16x16_ARGB_TRANSPARENT = "16x16_transparent_argb.png"; - String PATH_341x512_R90_CROPPED_MIRRORED = "341x512_r90_cropped_mirrored.png"; - } - - public interface WEBP { - String PATH_128x85_LOSSLESS = "128x85_rgb_lossless.webp"; - String PATH_128x85_LOSSY = "128x85_rgb_lossy.webp"; - String PATH_16x16_a50_cABCDEF = "16x16_a_50_cABCDEF_lossless.webp"; - } - - public interface IVFAV1 { - String PATH_256_170_RAV1E_S420_IVFAV1 = "256_170_rav1e_s420.ivf"; - String PATH_256_170_RAV1E_S420_IVFAV1_PNG = "256_170_rav1e_s420.ivf.png"; - } - - public interface GIF { - String PATH_128x85 = "128x85.gif"; - } - - public static InputStream getInputStream(final String path) throws IOException { - return getContext().getResources().getAssets().open(path); - } - - public static byte[] getInputBytes(final String path) throws IOException { - final InputStream is = getInputStream(path); - final ByteArrayOutputStream bos = new ByteArrayOutputStream(is.available()); - - final byte[] buffer = new byte[16 * 1024]; - int readBytes; - while ((readBytes = is.read(buffer)) > 0) { - bos.write(buffer, 0, readBytes); - } - return bos.toByteArray(); - } - - static Bitmap getBitmap(final String path) throws IOException { - InputStream inputStream = null; - //noinspection TryFinallyCanBeTryWithResources - try { - inputStream = getInputStream(path); - Bitmap bitmap = BitmapFactory.decodeStream(inputStream); - if (bitmap.getConfig() == null) { - // HACK: Fixing issue with GIF on Android 7 API 24 where the decoded bitmap is missing - // bitmap config - // @see - // https://android.googlesource.com/platform/frameworks/base/+/android-9.0.0_r8/graphics/java/android/graphics/Bitmap.java#833 - bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, false); - } - return bitmap; - } finally { - if (inputStream != null) { - inputStream.close(); - } - } - } - - private static Context getContext() { - return InstrumentationRegistry.getContext(); - } -} diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/TestSoLoader.java b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/TestSoLoader.java deleted file mode 100644 index 55f0f104..00000000 --- a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/TestSoLoader.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum.testutils; - -import androidx.test.InstrumentationRegistry; -import com.facebook.spectrum.SpectrumSoLoader; -import java.util.concurrent.atomic.AtomicBoolean; - -public class TestSoLoader { - - private static AtomicBoolean sAlreadyInitialized = new AtomicBoolean(false); - - public static void init() { - if (sAlreadyInitialized.getAndSet(true)) { - // In test environments it is more convenient to call init() before each test case and only - // have the first one be effective. This is safe as we use the same configuration in every - // call. - return; - } - SpectrumSoLoader.init( - InstrumentationRegistry.getContext(), new SpectrumSoLoader.FacebookSoLoaderImpl()); - } - - public static void loadLibrary(final String shortName) { - SpectrumSoLoader.loadLibrary(shortName); - } -} diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/gif/128x85.gif b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/gif/128x85.gif deleted file mode 100644 index bc78995a..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/gif/128x85.gif and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/ivfav1/256_170_rav1e_s420.ivf b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/ivfav1/256_170_rav1e_s420.ivf deleted file mode 100644 index 3cbb0eb4..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/ivfav1/256_170_rav1e_s420.ivf and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/ivfav1/256_170_rav1e_s420.ivf.png b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/ivfav1/256_170_rav1e_s420.ivf.png deleted file mode 100644 index e49ad703..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/ivfav1/256_170_rav1e_s420.ivf.png and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/128x85_q75_baseline.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/128x85_q75_baseline.jpg deleted file mode 100644 index 7ade71e1..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/128x85_q75_baseline.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/128x85_q75_grayscale.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/128x85_q75_grayscale.jpg deleted file mode 100644 index 7f9073ac..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/128x85_q75_grayscale.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/128x85_q75_progressive.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/128x85_q75_progressive.jpg deleted file mode 100644 index f8328c84..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/128x85_q75_progressive.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/128x85_q75_progressive_r90.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/128x85_q75_progressive_r90.jpg deleted file mode 100644 index 88f60e55..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/128x85_q75_progressive_r90.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/16x16_black_q75.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/16x16_black_q75.jpg deleted file mode 100644 index 68198e34..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/16x16_black_q75.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/16x16_black_q75_grayscale.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/16x16_black_q75_grayscale.jpg deleted file mode 100644 index 6510cac5..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/16x16_black_q75_grayscale.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/16x16_cABCDF0_q75.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/16x16_cABCDF0_q75.jpg deleted file mode 100644 index 7a510d02..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/16x16_cABCDF0_q75.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/16x16_white_q75.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/16x16_white_q75.jpg deleted file mode 100644 index badfb8eb..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/16x16_white_q75.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/16x16_white_q75_grayscale.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/16x16_white_q75_grayscale.jpg deleted file mode 100644 index f000942b..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/16x16_white_q75_grayscale.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/4096x2713_benchmark_large.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/4096x2713_benchmark_large.jpg deleted file mode 100644 index f6495049..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/4096x2713_benchmark_large.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/800x530_q75_baseline.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/800x530_q75_baseline.jpg deleted file mode 100644 index 8ce19cb3..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/800x530_q75_baseline.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/800x530_q75_grayscale.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/800x530_q75_grayscale.jpg deleted file mode 100644 index 91727c47..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/800x530_q75_grayscale.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/800x530_q75_progressive.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/800x530_q75_progressive.jpg deleted file mode 100644 index 339cfc91..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/800x530_q75_progressive.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/c200x100_o100_50_q95.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/c200x100_o100_50_q95.jpg deleted file mode 100644 index cc92aa75..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/c200x100_o100_50_q95.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/c50px60p_center_q95.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/c50px60p_center_q95.jpg deleted file mode 100644 index 98879653..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/c50px60p_center_q95.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/jpegtran_800x530_c128x64ox32oy16.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/jpegtran_800x530_c128x64ox32oy16.jpg deleted file mode 100644 index ebbd1d2b..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/jpegtran_800x530_c128x64ox32oy16.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/jpegtran_800x530_rotate90_c128x64ox32oy16.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/jpegtran_800x530_rotate90_c128x64ox32oy16.jpg deleted file mode 100644 index 28139df6..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/jpegtran_800x530_rotate90_c128x64ox32oy16.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/sample_85x128_q15.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/sample_85x128_q15.jpg deleted file mode 100644 index ff522540..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/sample_85x128_q15.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/sample_85x128_q85.jpg b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/sample_85x128_q85.jpg deleted file mode 100644 index 598a1f54..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/jpeg/sample_85x128_q85.jpg and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/png/128x85.png b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/png/128x85.png deleted file mode 100644 index a31aa7f0..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/png/128x85.png and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/png/128x85_argb.png b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/png/128x85_argb.png deleted file mode 100644 index 897b1020..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/png/128x85_argb.png and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/png/16x16_transparent_argb.png b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/png/16x16_transparent_argb.png deleted file mode 100644 index 76135866..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/png/16x16_transparent_argb.png and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/png/341x512_r90_cropped_mirrored.png b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/png/341x512_r90_cropped_mirrored.png deleted file mode 100644 index 17bbe515..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/png/341x512_r90_cropped_mirrored.png and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/png/800x530.png b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/png/800x530.png deleted file mode 100644 index 26a074a5..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/png/800x530.png and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/webp/128x85_rgb_lossless.webp b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/webp/128x85_rgb_lossless.webp deleted file mode 100644 index 22d0462b..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/webp/128x85_rgb_lossless.webp and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/webp/128x85_rgb_lossy.webp b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/webp/128x85_rgb_lossy.webp deleted file mode 100644 index f8457db3..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/webp/128x85_rgb_lossy.webp and /dev/null differ diff --git a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/webp/16x16_a_50_cABCDEF_lossless.webp b/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/webp/16x16_a_50_cABCDEF_lossless.webp deleted file mode 100644 index 24f7be6a..00000000 Binary files a/android/spectrumtestutils/src/main/java/com/facebook/spectrum/testutils/assets/webp/16x16_a_50_cABCDEF_lossless.webp and /dev/null differ diff --git a/android/src/test/java/com/facebook/spectrum/ConfigurationTest.java b/android/src/test/java/com/facebook/spectrum/ConfigurationTest.java deleted file mode 100644 index 7d73876b..00000000 --- a/android/src/test/java/com/facebook/spectrum/ConfigurationTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.facebook.spectrum.image.ImageChromaSamplingMode; -import com.facebook.spectrum.image.ImageColor; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; - -@RunWith(RobolectricTestRunner.class) -public class ConfigurationTest { - - @Test - public void testConfiguration_whenConfigurationDefault_thenAllNull() { - final Configuration configuration = Configuration.Builder().build(); - - assertThat(configuration).isNotNull(); - assertThat(configuration.interpretMetadata).isNull(); - assertThat(configuration.samplingMethod).isNull(); - assertThat(configuration.propagateChromaSamplingModeFromSource).isNull(); - assertThat(configuration.useTrellis).isNull(); - assertThat(configuration.useProgressive).isNull(); - assertThat(configuration.useOptimizeScan).isNull(); - assertThat(configuration.useCompatibleDcScanOpt).isNull(); - assertThat(configuration.chromaSamplingModeOverride).isNull(); - assertThat(configuration.usePsnrQuantTable).isNull(); - assertThat(configuration.useInterlacing).isNull(); - assertThat(configuration.compressionLevel).isNull(); - assertThat(configuration.defaultBackgroundColor).isNull(); - assertThat(configuration.webpMethod).isNull(); - assertThat(configuration.webpImageHint).isNull(); - } - - @Test - public void testConfiguration_whenConfigurationSpecified_thenStored() { - final Configuration configuration = - Configuration.Builder() - .setDefaultBackgroundColor(new ImageColor(12, 34, 56)) - .setInterpretMetadata(true) - .setSamplingMethod(Configuration.SamplingMethod.Bicubic) - .setPropagateChromaSamplingModeFromSource(true) - .setUseTrellis(true) - .setUseProgressive(true) - .setUseOptimizeScan(true) - .setUseCompatibleDcScanOpt(true) - .setChromaSamplingModeOverride(ImageChromaSamplingMode.S444) - .setUsePsnrQuantTable(true) - .setUseInterlacing(true) - .setCompressionLevel(9) - .setWebpMethod(1) - .setWebpImageHint(Configuration.ImageHint.DEFAULT) - .build(); - - assertThat(configuration).isNotNull(); - assertThat(configuration.interpretMetadata).isTrue(); - assertThat(configuration.samplingMethod).isEqualTo(Configuration.SamplingMethod.Bicubic); - assertThat(configuration.propagateChromaSamplingModeFromSource).isTrue(); - assertThat(configuration.useTrellis).isTrue(); - assertThat(configuration.useProgressive).isTrue(); - assertThat(configuration.useOptimizeScan).isTrue(); - assertThat(configuration.useCompatibleDcScanOpt).isTrue(); - assertThat(configuration.chromaSamplingModeOverride).isEqualTo(ImageChromaSamplingMode.S444); - assertThat(configuration.usePsnrQuantTable).isTrue(); - assertThat(configuration.useInterlacing).isTrue(); - assertThat(configuration.compressionLevel).isEqualTo(9); - assertThat(configuration.defaultBackgroundColor).isNotNull(); - assertThat(configuration.defaultBackgroundColor.red).isEqualTo(12); - assertThat(configuration.defaultBackgroundColor.green).isEqualTo(34); - assertThat(configuration.defaultBackgroundColor.blue).isEqualTo(56); - assertThat(configuration.webpImageHint).isEqualTo(Configuration.ImageHint.DEFAULT); - assertThat(configuration.webpMethod).isEqualTo(1); - } - - @Test - public void testConfiguration_whenConfigurationForGraphicalImages_thenGraphicalOptionsTrue() { - final Configuration configuration = Configuration.makeForImageContainingGraphics(); - - assertThat(configuration).isNotNull(); - assertThat(configuration.useTrellis).isTrue(); - assertThat(configuration.chromaSamplingModeOverride).isEqualTo(ImageChromaSamplingMode.S444); - assertThat(configuration.usePsnrQuantTable).isTrue(); - } -} diff --git a/android/src/test/java/com/facebook/spectrum/SpectrumExceptionTest.java b/android/src/test/java/com/facebook/spectrum/SpectrumExceptionTest.java deleted file mode 100644 index c326848d..00000000 --- a/android/src/test/java/com/facebook/spectrum/SpectrumExceptionTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; - -@RunWith(RobolectricTestRunner.class) -public class SpectrumExceptionTest { - - public static final String EXCEPTION_MESSAGE = "Flux compensator implosion"; - public static final SpectrumException EXCEPTION_CAUSE = new SpectrumException("time drift"); - - @Test - public void testSpectrumException_whenGivenMessage_thenContainsMessage() { - final SpectrumException spectrumException = new SpectrumException(EXCEPTION_MESSAGE); - assertThat(spectrumException.getMessage()).isEqualTo(EXCEPTION_MESSAGE); - } - - @Test - public void testSpectrumException_whenGivenCause_thenContainsCause() { - final SpectrumException spectrumException = new SpectrumException(EXCEPTION_CAUSE); - assertThat(spectrumException.getCause()).isEqualTo(EXCEPTION_CAUSE); - } - - @Test - public void testSpectrumException_whenGivenMessageAndCause_thenContainsMessageAndCause() { - final SpectrumException spectrumException = - new SpectrumException(EXCEPTION_MESSAGE, EXCEPTION_CAUSE); - assertThat(spectrumException.getMessage()).isEqualTo(EXCEPTION_MESSAGE); - assertThat(spectrumException.getCause()).isEqualTo(EXCEPTION_CAUSE); - } -} diff --git a/android/src/test/java/com/facebook/spectrum/SpectrumLogcatLoggerTest.java b/android/src/test/java/com/facebook/spectrum/SpectrumLogcatLoggerTest.java deleted file mode 100644 index 08c9efe9..00000000 --- a/android/src/test/java/com/facebook/spectrum/SpectrumLogcatLoggerTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum; - -import android.util.Log; -import com.facebook.spectrum.logging.SpectrumLogcatLogger; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; - -@RunWith(RobolectricTestRunner.class) -public class SpectrumLogcatLoggerTest { - - private static final int[] VALID_LOGCAT_LEVELS = - new int[] { - Log.VERBOSE, // = 2 - Log.DEBUG, // = 3 - Log.INFO, // = 4 - Log.WARN, // = 5 - Log.ERROR, // = 6 - Log.ASSERT // = 7 - }; - - @Test - public void testLogcatLogger_whenValidLevel_thenConstructionSucceeds() { - for (int level : VALID_LOGCAT_LEVELS) { - new SpectrumLogcatLogger(level); - } - } - - @Test(expected = IllegalArgumentException.class) - public void testLogcatLogger_whenLevelBelowValid_thenThrow() { - new SpectrumLogcatLogger(1); // lowest valid level is 2 - } - - @Test(expected = IllegalArgumentException.class) - public void testLogcatLogger_whenLevelAboveValid_thenThrow() { - new SpectrumLogcatLogger(8); // highest valid level is 7 - } -} diff --git a/android/src/test/java/com/facebook/spectrum/SpectrumResultsTest.java b/android/src/test/java/com/facebook/spectrum/SpectrumResultsTest.java deleted file mode 100644 index 31084208..00000000 --- a/android/src/test/java/com/facebook/spectrum/SpectrumResultsTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.facebook.spectrum.image.EncodedImageFormat; -import com.facebook.spectrum.image.ImagePixelSpecification; -import com.facebook.spectrum.image.ImageSize; -import com.facebook.spectrum.image.ImageSpecification; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; - -@RunWith(RobolectricTestRunner.class) -public class SpectrumResultsTest { - - @Test - public void testTranscodeOptions_whenConstructed_thenValuesSet() { - final ImageSpecification inputImageSpecification = - new ImageSpecification( - new ImageSize(1000, 1000), EncodedImageFormat.PNG, ImagePixelSpecification.ARGB); - final ImageSpecification outputImageSpecification = - new ImageSpecification( - new ImageSize(100, 100), EncodedImageFormat.JPEG, ImagePixelSpecification.RGB); - - final SpectrumResult result = - new SpectrumResult("ruleName", inputImageSpecification, outputImageSpecification, 100, 200); - - assertThat(result.getRuleName()).isEqualTo("ruleName"); - assertThat(result.getInputImageSpecification()).isEqualTo(inputImageSpecification); - assertThat(result.getOutputImageSpecification()).isEqualTo(outputImageSpecification); - assertThat(result.getTotalBytesRead()).isEqualTo(100); - assertThat(result.getTotalBytesWritten()).isEqualTo(200); - } -} diff --git a/android/src/test/java/com/facebook/spectrum/image/ImageFormatTest.java b/android/src/test/java/com/facebook/spectrum/image/ImageFormatTest.java deleted file mode 100644 index 3696d4a2..00000000 --- a/android/src/test/java/com/facebook/spectrum/image/ImageFormatTest.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum.image; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; - -@RunWith(RobolectricTestRunner.class) -public class ImageFormatTest { - - @Test - public void testImageFormat_whenComparingTwoEqualInstances_thenEquals() { - final ImageFormat format = ImageFormat.BITMAP; - final ImageFormat format2 = new ImageFormat("bitmap"); - - assertThat(format).isEqualTo(format2); - } -} diff --git a/android/src/test/java/com/facebook/spectrum/image/ImagePixelSpecificationTest.java b/android/src/test/java/com/facebook/spectrum/image/ImagePixelSpecificationTest.java deleted file mode 100644 index e59c7af2..00000000 --- a/android/src/test/java/com/facebook/spectrum/image/ImagePixelSpecificationTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum.image; - -import static org.assertj.core.api.Assertions.assertThat; - -import android.graphics.Bitmap; -import com.facebook.spectrum.image.ImagePixelSpecification.AlphaInfo; -import com.facebook.spectrum.image.ImagePixelSpecification.ColorModel; -import com.facebook.spectrum.image.ImagePixelSpecification.ComponentsOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; - -@RunWith(RobolectricTestRunner.class) -public class ImagePixelSpecificationTest { - - @Test - public void testPixelColorModel_whenMadeFromArgument_thenReturnsEnumInstance() { - final ColorModel actual = ColorModel.from("rgb", 3, true); - assertThat(actual).isSameAs(ColorModel.RGB); - } - - @Test - public void testImagePixelSpecification_whenMadeFromArgument_thenReturnsEnumInstance() { - final ImagePixelSpecification actual = - ImagePixelSpecification.from(ColorModel.RGB, 4, AlphaInfo.FIRST, ComponentsOrder.NATURAL); - assertThat(actual).isSameAs(ImagePixelSpecification.ARGB); - } - - @Test - public void testImagePixelSpecification_whenFromBitmapArgb_thenReturnsRgba() { - // Android's ARGB is actually RGBA - assertThat(ImagePixelSpecification.from(Bitmap.Config.ARGB_8888)) - .isSameAs(ImagePixelSpecification.RGBA); - } - - @Test - public void testImagePixelSpecification_whenFromBitmapAlpha_thenReturnsGray() { - // Android's ALPHA_8 is usually used for gray scale use cases - assertThat(ImagePixelSpecification.from(Bitmap.Config.ALPHA_8)) - .isSameAs(ImagePixelSpecification.GRAY); - } -} diff --git a/android/src/test/java/com/facebook/spectrum/options/BaseOptionsTest.java b/android/src/test/java/com/facebook/spectrum/options/BaseOptionsTest.java deleted file mode 100644 index 47a686c3..00000000 --- a/android/src/test/java/com/facebook/spectrum/options/BaseOptionsTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum.options; - -import static org.mockito.Mockito.mock; - -import com.facebook.spectrum.Configuration; -import com.facebook.spectrum.image.ImageMetadata; -import com.facebook.spectrum.image.ImagePixelSpecification; -import com.facebook.spectrum.image.ImageSpecification; -import com.facebook.spectrum.requirements.CropRequirement; -import com.facebook.spectrum.requirements.EncodeRequirement; -import com.facebook.spectrum.requirements.ResizeRequirement; -import com.facebook.spectrum.requirements.RotateRequirement; - -/** Provides common mocked instances of parameter classes for the other options tests */ -abstract class BaseOptionsTest { - - protected EncodeRequirement mockEncodeRequirement = mock(EncodeRequirement.class); - protected ResizeRequirement mockResizeRequirement = mock(ResizeRequirement.class); - protected CropRequirement mockCropRequirement = mock(CropRequirement.class); - protected RotateRequirement mockRotateRequirement = mock(RotateRequirement.class); - protected ImageMetadata mockMetadata = mock(ImageMetadata.class); - protected Configuration mockConfiguration = mock(Configuration.class); - protected ImageSpecification mockImageSpecification = mock(ImageSpecification.class); - - protected ImagePixelSpecification mockOutputPixelSpecification = - ImagePixelSpecification.RGB; // enum types cannot be mocked -} diff --git a/android/src/test/java/com/facebook/spectrum/options/DecodeOptionsTest.java b/android/src/test/java/com/facebook/spectrum/options/DecodeOptionsTest.java deleted file mode 100644 index bc1b5286..00000000 --- a/android/src/test/java/com/facebook/spectrum/options/DecodeOptionsTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum.options; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; - -@RunWith(RobolectricTestRunner.class) -public class DecodeOptionsTest extends BaseOptionsTest { - - @Test - public void testSetters_whenEverythingSet_thenBuiltObjectConforms() { - final DecodeOptions options = - DecodeOptions.Builder() - .outputPixelSpecification(mockOutputPixelSpecification) - .configuration(mockConfiguration) - .crop(mockCropRequirement) - .resize(mockResizeRequirement) - .rotate(mockRotateRequirement) - .build(); - - assertThat(options.outputPixelSpecification).isEqualTo(mockOutputPixelSpecification); - assertThat(options.configuration).isEqualTo(mockConfiguration); - assertThat(options.transformations.cropRequirement).isEqualTo(mockCropRequirement); - assertThat(options.transformations.resizeRequirement).isEqualTo(mockResizeRequirement); - assertThat(options.transformations.rotateRequirement).isEqualTo(mockRotateRequirement); - } - - @Test - public void testToString_whenToString_thenContainsDecodeOptions() { - final DecodeOptions options = DecodeOptions.Builder().build(); - assertThat(options.toString()).contains("DecodeOptions"); - } -} diff --git a/android/src/test/java/com/facebook/spectrum/options/EncodeOptionsTest.java b/android/src/test/java/com/facebook/spectrum/options/EncodeOptionsTest.java deleted file mode 100644 index 5ffd3a94..00000000 --- a/android/src/test/java/com/facebook/spectrum/options/EncodeOptionsTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum.options; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; - -@RunWith(RobolectricTestRunner.class) -public class EncodeOptionsTest extends BaseOptionsTest { - - @Test - public void testSetters_whenEverythingSet_thenBuiltObjectConforms() { - final EncodeOptions options = - EncodeOptions.Builder(mockEncodeRequirement) - .metadata(mockMetadata) - .configuration(mockConfiguration) - .crop(mockCropRequirement) - .resize(mockResizeRequirement) - .rotate(mockRotateRequirement) - .build(); - - assertThat(options.encodeRequirement).isEqualTo(mockEncodeRequirement); - assertThat(options.metadata).isEqualTo(mockMetadata); - assertThat(options.configuration).isEqualTo(mockConfiguration); - assertThat(options.transformations.cropRequirement).isEqualTo(mockCropRequirement); - assertThat(options.transformations.resizeRequirement).isEqualTo(mockResizeRequirement); - assertThat(options.transformations.rotateRequirement).isEqualTo(mockRotateRequirement); - } - - @Test - public void testToString_whenToString_thenContainsDecodeOptions() { - final EncodeOptions options = EncodeOptions.Builder(mockEncodeRequirement).build(); - assertThat(options.toString()).contains("EncodeOptions"); - } -} diff --git a/android/src/test/java/com/facebook/spectrum/options/TranscodeOptionsTest.java b/android/src/test/java/com/facebook/spectrum/options/TranscodeOptionsTest.java deleted file mode 100644 index 6a2ceb53..00000000 --- a/android/src/test/java/com/facebook/spectrum/options/TranscodeOptionsTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum.options; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; - -@RunWith(RobolectricTestRunner.class) -public class TranscodeOptionsTest extends BaseOptionsTest { - - @Test - public void testSetters_whenEverythingSet_thenBuiltObjectConforms() { - final TranscodeOptions options = - TranscodeOptions.Builder(mockEncodeRequirement) - .metadata(mockMetadata) - .configuration(mockConfiguration) - .crop(mockCropRequirement) - .resize(mockResizeRequirement) - .rotate(mockRotateRequirement) - .build(); - - assertThat(options.encodeRequirement).isEqualTo(mockEncodeRequirement); - assertThat(options.metadata).isEqualTo(mockMetadata); - assertThat(options.configuration).isEqualTo(mockConfiguration); - assertThat(options.transformations.cropRequirement).isEqualTo(mockCropRequirement); - assertThat(options.transformations.resizeRequirement).isEqualTo(mockResizeRequirement); - assertThat(options.transformations.rotateRequirement).isEqualTo(mockRotateRequirement); - } - - @Test - public void testToString_whenToString_thenContainsDecodeOptions() { - final TranscodeOptions options = TranscodeOptions.Builder(mockEncodeRequirement).build(); - assertThat(options.toString()).contains("TranscodeOptions"); - } -} diff --git a/android/src/test/java/com/facebook/spectrum/options/TransformOptionsTest.java b/android/src/test/java/com/facebook/spectrum/options/TransformOptionsTest.java deleted file mode 100644 index ef6b56ef..00000000 --- a/android/src/test/java/com/facebook/spectrum/options/TransformOptionsTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum.options; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; - -@RunWith(RobolectricTestRunner.class) -public class TransformOptionsTest extends BaseOptionsTest { - - @Test - public void testSetters_whenEverythingSet_thenBuiltObjectConforms() { - final TransformOptions options = - TransformOptions.Builder(mockOutputPixelSpecification) - .configuration(mockConfiguration) - .crop(mockCropRequirement) - .resize(mockResizeRequirement) - .rotate(mockRotateRequirement) - .build(); - - assertThat(options.outputPixelSpecification).isEqualTo(mockOutputPixelSpecification); - assertThat(options.configuration).isEqualTo(mockConfiguration); - assertThat(options.transformations.cropRequirement).isEqualTo(mockCropRequirement); - assertThat(options.transformations.resizeRequirement).isEqualTo(mockResizeRequirement); - assertThat(options.transformations.rotateRequirement).isEqualTo(mockRotateRequirement); - } - - @Test - public void testToString_whenToString_thenContainsDecodeOptions() { - final TransformOptions options = TransformOptions.Builder(mockOutputPixelSpecification).build(); - assertThat(options.toString()).contains("TransformOptions"); - } -} diff --git a/android/src/test/java/com/facebook/spectrum/requirements/CropRequirementTest.java b/android/src/test/java/com/facebook/spectrum/requirements/CropRequirementTest.java deleted file mode 100644 index 7be4b60b..00000000 --- a/android/src/test/java/com/facebook/spectrum/requirements/CropRequirementTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum.requirements; - -import static org.assertj.core.api.Assertions.assertThat; - -import android.graphics.Rect; -import android.graphics.RectF; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; - -@RunWith(RobolectricTestRunner.class) -public class CropRequirementTest { - - @Test - public void testCropRequirement_whenAbsoluteConstructed_thenCorrectValuesAreSet() { - final CropRequirement cropRequirement = CropRequirement.makeAbsoluteToOrigin(1, 2, 3, 4, true); - assertAbsoluteCropping(cropRequirement); - } - - @Test - public void testCropRequirement_whenAbsoluteConstructedFromRect_thenCorrectValuesAreSet() { - final Rect rect = new Rect(1, 2, 3, 4); - final CropRequirement cropRequirement = CropRequirement.makeAbsoluteToOrigin(rect, true); - assertAbsoluteCropping(cropRequirement); - } - - private static void assertAbsoluteCropping(final CropRequirement cropRequirement) { - assertThat(cropRequirement) - .isExactlyInstanceOf(CropRequirement.CropAbsoluteToOriginRequirement.class); - - final CropRequirement.CropAbsoluteToOriginRequirement cropAbsoluteToOriginRequirement = - (CropRequirement.CropAbsoluteToOriginRequirement) cropRequirement; - - assertThat(cropAbsoluteToOriginRequirement.left).isEqualTo(1); - assertThat(cropAbsoluteToOriginRequirement.top).isEqualTo(2); - assertThat(cropAbsoluteToOriginRequirement.right).isEqualTo(3); - assertThat(cropAbsoluteToOriginRequirement.bottom).isEqualTo(4); - - assertThat(cropRequirement.mustBeExact).isTrue(); - } - - @Test - public void testCropRequirement_whenRelativeConstructed_thenCorrectValuesAreSet() { - final CropRequirement cropRequirement = - CropRequirement.makeRelativeToOrigin(.1f, .2f, .3f, .4f, false); - assertRelativeCropping(cropRequirement); - } - - @Test - public void testCropRequirement_whenRelativeConstructedFromRectF_thenCorrectValuesAreSet() { - final RectF rect = new RectF(.1f, .2f, .3f, .4f); - final CropRequirement cropRequirement = CropRequirement.makeRelativeToOrigin(rect, false); - assertRelativeCropping(cropRequirement); - } - - private static void assertRelativeCropping(final CropRequirement cropRequirement) { - assertThat(cropRequirement) - .isExactlyInstanceOf(CropRequirement.CropRelativeToOriginRequirement.class); - - final CropRequirement.CropRelativeToOriginRequirement cropRelativeToOriginRequirement = - (CropRequirement.CropRelativeToOriginRequirement) cropRequirement; - - assertThat(cropRelativeToOriginRequirement.left).isEqualTo(.1f); - assertThat(cropRelativeToOriginRequirement.top).isEqualTo(.2f); - assertThat(cropRelativeToOriginRequirement.right).isEqualTo(.3f); - assertThat(cropRelativeToOriginRequirement.bottom).isEqualTo(.4f); - - assertThat(cropRequirement.mustBeExact).isFalse(); - } -} diff --git a/android/src/test/java/com/facebook/spectrum/types/ImageSizeTest.java b/android/src/test/java/com/facebook/spectrum/types/ImageSizeTest.java deleted file mode 100644 index 416c6968..00000000 --- a/android/src/test/java/com/facebook/spectrum/types/ImageSizeTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.spectrum.types; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.facebook.spectrum.image.ImageSize; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; - -@RunWith(RobolectricTestRunner.class) -public class ImageSizeTest { - - @Test - public void testImageSize_whenBoundsSet_thenStoredCorrectly() { - ImageSize imageSize = new ImageSize(640, 480); - assertThat(imageSize.width).isEqualTo(640); - assertThat(imageSize.height).isEqualTo(480); - } - - @Test(expected = IllegalArgumentException.class) - public void testImageSize_whenWidthNegative_thenThrows() { - new ImageSize(-1, 480); - } - - @Test(expected = IllegalArgumentException.class) - public void testImageSize_whenHeightNegative_thenThrows() { - new ImageSize(640, -1); - } - - @Test(expected = IllegalArgumentException.class) - public void testImageSize_whenWidthTooLarge_thenThrows() { - new ImageSize(65537, 480); - } - - @Test(expected = IllegalArgumentException.class) - public void testImageSize_whenHeightTooLarge_thenThrows() { - new ImageSize(640, 65537); - } - - @Test - public void testImageSize_whenToString_thenStringContainsAllInfo() { - final ImageSize imageSize = new ImageSize(640, 480); - final String toString = imageSize.toString(); - - assertThat(toString).containsIgnoringCase("width=640"); - assertThat(toString).containsIgnoringCase("height=480"); - } -} diff --git a/androidLibs/third-party/libpng/build.gradle b/androidLibs/third-party/libpng/build.gradle index dd6d39c5..2683ff11 100644 --- a/androidLibs/third-party/libpng/build.gradle +++ b/androidLibs/third-party/libpng/build.gradle @@ -21,12 +21,12 @@ apply plugin: SpectrumDownloadAndMergePlugin import org.apache.tools.ant.filters.ReplaceTokens downloadAndMergeNativeLibrary { - externalSourceUri 'https://github.com/glennrp/libpng/archive/v1.6.35.tar.gz' - externalSourceInclude 'libpng-1.6.35/**' + externalSourceUri 'https://github.com/glennrp/libpng/archive/v1.6.37.tar.gz' + externalSourceInclude 'libpng-1.6.37/**' overrideInclude '**' filesMatchingPattern '**' filesMatchingAction { - it.path = it.path - "libpng-1.6.35" + it.path = it.path - "libpng-1.6.37" } cacheRevision = 1 } diff --git a/androidLibs/third-party/libpng/override/CMakeLists.txt b/androidLibs/third-party/libpng/override/CMakeLists.txt index 4bb5ecd2..3fe2dc95 100644 --- a/androidLibs/third-party/libpng/override/CMakeLists.txt +++ b/androidLibs/third-party/libpng/override/CMakeLists.txt @@ -20,6 +20,7 @@ add_library(libpng STATIC arm/arm_init.c arm/filter_neon_intrinsics.c arm/filter_neon.S + arm/palette_neon_intrinsics.c ) target_compile_options(libpng PRIVATE diff --git a/androidLibs/third-party/mozjpeg/build.gradle b/androidLibs/third-party/mozjpeg/build.gradle index aaf92b6a..7da21121 100644 --- a/androidLibs/third-party/mozjpeg/build.gradle +++ b/androidLibs/third-party/mozjpeg/build.gradle @@ -21,12 +21,12 @@ apply plugin: SpectrumDownloadAndMergePlugin import org.apache.tools.ant.filters.ReplaceTokens downloadAndMergeNativeLibrary { - externalSourceUri 'https://github.com/mozilla/mozjpeg/archive/v3.3.1.tar.gz' - externalSourceInclude 'mozjpeg-3.3.1/**' + externalSourceUri 'https://github.com/mozilla/mozjpeg/archive/v4.1.1.tar.gz' + externalSourceInclude 'mozjpeg-4.1.1/**' overrideInclude '**' filesMatchingPattern '**' filesMatchingAction { - it.path = it.path - "mozjpeg-3.3.1" + it.path = it.path - "mozjpeg-4.1.1" } cacheRevision = 1 } diff --git a/androidLibs/third-party/mozjpeg/override/CMakeLists.txt b/androidLibs/third-party/mozjpeg/override/CMakeLists.txt index 34b96352..7bcc767d 100644 --- a/androidLibs/third-party/mozjpeg/override/CMakeLists.txt +++ b/androidLibs/third-party/mozjpeg/override/CMakeLists.txt @@ -56,21 +56,9 @@ list(APPEND mozjpegsources jdarith.c transupp.c jmemnobs.c + jsimd_none.c ) -if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7-a") - message(STATUS "Building mozjpeg with armv7-a SIMD support") - list(APPEND mozjpegsources - simd/jsimd_arm.c - simd/jsimd_arm_neon.S - ) -else() - message(STATUS "Building mozjpeg without SIMD support") - list(APPEND mozjpegsources - jsimd_none.c - ) -endif() - add_library(mozjpeg STATIC ${mozjpegsources}) diff --git a/androidLibs/third-party/mozjpeg/override/config.h b/androidLibs/third-party/mozjpeg/override/config.h index d0c025f6..771c3452 100644 --- a/androidLibs/third-party/mozjpeg/override/config.h +++ b/androidLibs/third-party/mozjpeg/override/config.h @@ -73,7 +73,7 @@ #define JPEG_LIB_VERSION 80 /* libjpeg-turbo version */ -#define LIBJPEG_TURBO_VERSION 1.5.3 +#define LIBJPEG_TURBO_VERSION 2.1.3 /* libjpeg-turbo version in integer form */ #define LIBJPEG_TURBO_VERSION_NUMBER 1005003 @@ -101,7 +101,7 @@ #define PACKAGE_NAME "libjpeg-turbo" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "libjpeg-turbo 1.5.3" +#define PACKAGE_STRING "libjpeg-turbo 2.1.3" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "libjpeg-turbo" @@ -110,7 +110,7 @@ #define PACKAGE_URL "" /* Define to the version of this package. */ -#define PACKAGE_VERSION "1.5.3" +#define PACKAGE_VERSION "2.1.3" /* Define if your (broken) compiler shifts signed values as if they were unsigned. */ @@ -127,7 +127,7 @@ #define STDC_HEADERS 1 /* Version number of package */ -#define VERSION "1.5.3" +#define VERSION "2.1.3" /* Use accelerated SIMD routines. */ #define WITH_SIMD 1 diff --git a/androidLibs/third-party/mozjpeg/override/jconfig.h b/androidLibs/third-party/mozjpeg/override/jconfig.h index 01c76cc0..39400e5a 100644 --- a/androidLibs/third-party/mozjpeg/override/jconfig.h +++ b/androidLibs/third-party/mozjpeg/override/jconfig.h @@ -4,7 +4,7 @@ #define JPEG_LIB_VERSION 80 /* Version 6b */ /* libjpeg-turbo version */ -#define LIBJPEG_TURBO_VERSION 1.5.3 +#define LIBJPEG_TURBO_VERSION 2.1.3 /* libjpeg-turbo version in integer form */ #define LIBJPEG_TURBO_VERSION_NUMBER 1005003 diff --git a/androidLibs/third-party/mozjpeg/override/jconfigint.h b/androidLibs/third-party/mozjpeg/override/jconfigint.h index 6fdee647..9616cc90 100644 --- a/androidLibs/third-party/mozjpeg/override/jconfigint.h +++ b/androidLibs/third-party/mozjpeg/override/jconfigint.h @@ -11,7 +11,7 @@ #define PACKAGE_NAME "libjpeg-turbo" /* Version number of package */ -#define VERSION "1.5.3" +#define VERSION "2.1.3" /* The size of `size_t', as computed by sizeof. */ #ifdef __LP64__ @@ -19,3 +19,21 @@ #else # define SIZEOF_SIZE_T 4 #endif + +#if defined(_MSC_VER) && defined(HAVE_INTRIN_H) +#if (SIZEOF_SIZE_T == 8) +#define HAVE_BITSCANFORWARD64 +#elif (SIZEOF_SIZE_T == 4) +#define HAVE_BITSCANFORWARD +#endif +#endif + +#if defined(__has_attribute) +#if __has_attribute(fallthrough) +#define FALLTHROUGH __attribute__((fallthrough)); +#else +#define FALLTHROUGH +#endif +#else +#define FALLTHROUGH +#endif diff --git a/androidLibs/third-party/mozjpeg/override/jversion.h b/androidLibs/third-party/mozjpeg/override/jversion.h new file mode 100644 index 00000000..6e4b01f4 --- /dev/null +++ b/androidLibs/third-party/mozjpeg/override/jversion.h @@ -0,0 +1,56 @@ +/* + * jversion.h + * + * This file was part of the Independent JPEG Group's software: + * Copyright (C) 1991-2020, Thomas G. Lane, Guido Vollbeding. + * libjpeg-turbo Modifications: + * Copyright (C) 2010, 2012-2023, D. R. Commander. + * For conditions of distribution and use, see the accompanying README.ijg + * file. + * mozjpeg Modifications: + * Copyright (C) 2014, Mozilla Corporation. + * + * This file contains software version identification. + */ + + +#if JPEG_LIB_VERSION >= 80 + +#define JVERSION "8d 15-Jan-2012" + +#elif JPEG_LIB_VERSION >= 70 + +#define JVERSION "7 27-Jun-2009" + +#else + +#define JVERSION "6b 27-Mar-1998" + +#endif + +/* + * NOTE: It is our convention to place the authors in the following order: + * - libjpeg-turbo authors (2009-) in descending order of the date of their + * most recent contribution to the project, then in ascending order of the + * date of their first contribution to the project, then in alphabetical + * order + * - Upstream authors in descending order of the date of the first inclusion of + * their code + */ + +#define JCOPYRIGHT \ + "Copyright (C) 2009-2023 D. R. Commander\n" \ + "Copyright (C) 2015, 2020 Google, Inc.\n" \ + "Copyright (C) 2019-2020 Arm Limited\n" \ + "Copyright (C) 2015-2016, 2018 Matthieu Darbois\n" \ + "Copyright (C) 2011-2016 Siarhei Siamashka\n" \ + "Copyright (C) 2015 Intel Corporation\n" \ + "Copyright (C) 2013-2014 Linaro Limited\n" \ + "Copyright (C) 2013-2014 MIPS Technologies, Inc.\n" \ + "Copyright (C) 2009, 2012 Pierre Ossman for Cendio AB\n" \ + "Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)\n" \ + "Copyright (C) 1999-2006 MIYASAKA Masaru\n" \ + "Copyright (C) 1991-2020 Thomas G. Lane, Guido Vollbeding" + +#define JCOPYRIGHT_SHORT \ + "Copyright (C) @COPYRIGHT_YEAR@ The libjpeg-turbo Project and many others" diff --git a/androidLibs/third-party/mozjpeg/override/transupp.h b/androidLibs/third-party/mozjpeg/override/transupp.h deleted file mode 100644 index d192937a..00000000 --- a/androidLibs/third-party/mozjpeg/override/transupp.h +++ /dev/null @@ -1,219 +0,0 @@ -/* - * transupp.h - * - * This file was part of the Independent JPEG Group's software: - * Copyright (C) 1997-2011, Thomas G. Lane, Guido Vollbeding. - * It was modified by The libjpeg-turbo Project to include only code relevant - * to libjpeg-turbo. - * For conditions of distribution and use, see the accompanying README.ijg - * file. - * - * This file contains declarations for image transformation routines and - * other utility code used by the jpegtran sample application. These are - * NOT part of the core JPEG library. But we keep these routines separate - * from jpegtran.c to ease the task of maintaining jpegtran-like programs - * that have other user interfaces. - * - * NOTE: all the routines declared here have very specific requirements - * about when they are to be executed during the reading and writing of the - * source and destination files. See the comments in transupp.c, or see - * jpegtran.c for an example of correct usage. - */ - -#ifdef __cplusplus -#ifndef DONT_USE_EXTERN_C -extern "C" { -#endif -#endif - -/* If you happen not to want the image transform support, disable it here */ -#ifndef TRANSFORMS_SUPPORTED -#define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */ -#endif - -/* - * Although rotating and flipping data expressed as DCT coefficients is not - * hard, there is an asymmetry in the JPEG format specification for images - * whose dimensions aren't multiples of the iMCU size. The right and bottom - * image edges are padded out to the next iMCU boundary with junk data; but - * no padding is possible at the top and left edges. If we were to flip - * the whole image including the pad data, then pad garbage would become - * visible at the top and/or left, and real pixels would disappear into the - * pad margins --- perhaps permanently, since encoders & decoders may not - * bother to preserve DCT blocks that appear to be completely outside the - * nominal image area. So, we have to exclude any partial iMCUs from the - * basic transformation. - * - * Transpose is the only transformation that can handle partial iMCUs at the - * right and bottom edges completely cleanly. flip_h can flip partial iMCUs - * at the bottom, but leaves any partial iMCUs at the right edge untouched. - * Similarly flip_v leaves any partial iMCUs at the bottom edge untouched. - * The other transforms are defined as combinations of these basic transforms - * and process edge blocks in a way that preserves the equivalence. - * - * The "trim" option causes untransformable partial iMCUs to be dropped; - * this is not strictly lossless, but it usually gives the best-looking - * result for odd-size images. Note that when this option is active, - * the expected mathematical equivalences between the transforms may not hold. - * (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim - * followed by -rot 180 -trim trims both edges.) - * - * We also offer a lossless-crop option, which discards data outside a given - * image region but losslessly preserves what is inside. Like the rotate and - * flip transforms, lossless crop is restricted by the JPEG format: the upper - * left corner of the selected region must fall on an iMCU boundary. If this - * does not hold for the given crop parameters, we silently move the upper left - * corner up and/or left to make it so, simultaneously increasing the region - * dimensions to keep the lower right crop corner unchanged. (Thus, the - * output image covers at least the requested region, but may cover more.) - * The adjustment of the region dimensions may be optionally disabled. - * - * We also provide a lossless-resize option, which is kind of a lossless-crop - * operation in the DCT coefficient block domain - it discards higher-order - * coefficients and losslessly preserves lower-order coefficients of a - * sub-block. - * - * Rotate/flip transform, resize, and crop can be requested together in a - * single invocation. The crop is applied last --- that is, the crop region - * is specified in terms of the destination image after transform/resize. - * - * We also offer a "force to grayscale" option, which simply discards the - * chrominance channels of a YCbCr image. This is lossless in the sense that - * the luminance channel is preserved exactly. It's not the same kind of - * thing as the rotate/flip transformations, but it's convenient to handle it - * as part of this package, mainly because the transformation routines have to - * be aware of the option to know how many components to work on. - */ - - -/* - * Codes for supported types of image transformations. - */ - -typedef enum { - JXFORM_NONE, /* no transformation */ - JXFORM_FLIP_H, /* horizontal flip */ - JXFORM_FLIP_V, /* vertical flip */ - JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */ - JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */ - JXFORM_ROT_90, /* 90-degree clockwise rotation */ - JXFORM_ROT_180, /* 180-degree rotation */ - JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */ -} JXFORM_CODE; - -/* - * Codes for crop parameters, which can individually be unspecified, - * positive or negative for xoffset or yoffset, - * positive or forced for width or height. - */ - -typedef enum { - JCROP_UNSET, - JCROP_POS, - JCROP_NEG, - JCROP_FORCE -} JCROP_CODE; - -/* - * Transform parameters struct. - * NB: application must not change any elements of this struct after - * calling jtransform_request_workspace. - */ - -typedef struct { - /* Options: set by caller */ - JXFORM_CODE transform; /* image transform operator */ - boolean perfect; /* if TRUE, fail if partial MCUs are requested */ - boolean trim; /* if TRUE, trim partial MCUs as needed */ - boolean force_grayscale; /* if TRUE, convert color image to grayscale */ - boolean crop; /* if TRUE, crop source image */ - boolean slow_hflip; /* For best performance, the JXFORM_FLIP_H transform - normally modifies the source coefficients in place. - Setting this to TRUE will instead use a slower, - double-buffered algorithm, which leaves the source - coefficients in tact (necessary if other transformed - images must be generated from the same set of - coefficients. */ - - /* Crop parameters: application need not set these unless crop is TRUE. - * These can be filled in by jtransform_parse_crop_spec(). - */ - JDIMENSION crop_width; /* Width of selected region */ - JCROP_CODE crop_width_set; /* (forced disables adjustment) */ - JDIMENSION crop_height; /* Height of selected region */ - JCROP_CODE crop_height_set; /* (forced disables adjustment) */ - JDIMENSION crop_xoffset; /* X offset of selected region */ - JCROP_CODE crop_xoffset_set; /* (negative measures from right edge) */ - JDIMENSION crop_yoffset; /* Y offset of selected region */ - JCROP_CODE crop_yoffset_set; /* (negative measures from bottom edge) */ - - /* Internal workspace: caller should not touch these */ - int num_components; /* # of components in workspace */ - jvirt_barray_ptr *workspace_coef_arrays; /* workspace for transformations */ - JDIMENSION output_width; /* cropped destination dimensions */ - JDIMENSION output_height; - JDIMENSION x_crop_offset; /* destination crop offsets measured in iMCUs */ - JDIMENSION y_crop_offset; - int iMCU_sample_width; /* destination iMCU size */ - int iMCU_sample_height; -} jpeg_transform_info; - - -#if TRANSFORMS_SUPPORTED - -/* Parse a crop specification (written in X11 geometry style) */ -EXTERN(boolean) jtransform_parse_crop_spec - (jpeg_transform_info *info, const char *spec); -/* Request any required workspace */ -EXTERN(boolean) jtransform_request_workspace - (j_decompress_ptr srcinfo, jpeg_transform_info *info); -/* Adjust output image parameters */ -EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters - (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - jvirt_barray_ptr *src_coef_arrays, jpeg_transform_info *info); -/* Execute the actual transformation, if any */ -EXTERN(void) jtransform_execute_transform - (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - jvirt_barray_ptr *src_coef_arrays, jpeg_transform_info *info); -/* Determine whether lossless transformation is perfectly - * possible for a specified image and transformation. - */ -EXTERN(boolean) jtransform_perfect_transform - (JDIMENSION image_width, JDIMENSION image_height, int MCU_width, - int MCU_height, JXFORM_CODE transform); - -/* jtransform_execute_transform used to be called - * jtransform_execute_transformation, but some compilers complain about - * routine names that long. This macro is here to avoid breaking any - * old source code that uses the original name... - */ -#define jtransform_execute_transformation jtransform_execute_transform - -#endif /* TRANSFORMS_SUPPORTED */ - - -/* - * Support for copying optional markers from source to destination file. - */ - -typedef enum { - JCOPYOPT_NONE, /* copy no optional markers */ - JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */ - JCOPYOPT_ALL /* copy all optional markers */ -} JCOPY_OPTION; - -#define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */ - -/* Setup decompression object to save desired markers in memory */ -EXTERN(void) jcopy_markers_setup - (j_decompress_ptr srcinfo, JCOPY_OPTION option); -/* Copy markers saved in the given source object to the destination object */ -EXTERN(void) jcopy_markers_execute - (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - JCOPY_OPTION option); - -#ifdef __cplusplus -#ifndef DONT_USE_EXTERN_C -} -#endif -#endif diff --git a/build.gradle b/build.gradle index afb6728e..b7d01cbf 100644 --- a/build.gradle +++ b/build.gradle @@ -38,6 +38,7 @@ subprojects { } } + ext.isRelease = { ['publish', 'publishToMaven'].any { gradle.startParameter.taskNames.contains(it) } } ext.deps = [ @@ -51,7 +52,7 @@ ext.deps = [ jsr305: 'com.google.code.findbugs:jsr305:3.0.1', // First-party - soloader: 'com.facebook.soloader:soloader:0.10.4', + soloader: 'com.facebook.soloader:soloader:0.10.5', // Third-party dexmaker: 'com.google.dexmaker:dexmaker:1.2', diff --git a/cpp/spectrum/image/Orientation.cpp b/cpp/spectrum/image/Orientation.cpp index 9784833d..338c297f 100644 --- a/cpp/spectrum/image/Orientation.cpp +++ b/cpp/spectrum/image/Orientation.cpp @@ -19,7 +19,7 @@ Orientation orientationFromValue(const std::uint16_t value) { if (value < static_cast(Orientation::Up) || value > static_cast(Orientation::Left)) { - SPECTRUM_UNREACHABLE_IMAGE_ORIENTATION(orientation); + return static_cast(Orientation::Up); } else { return orientation; } diff --git a/cpp/spectrum/image/metadata/Entry.cpp b/cpp/spectrum/image/metadata/Entry.cpp index 1cf25997..bd605d1b 100644 --- a/cpp/spectrum/image/metadata/Entry.cpp +++ b/cpp/spectrum/image/metadata/Entry.cpp @@ -150,7 +150,7 @@ std::vector Entry::MemoryLayout::extractValue( case Entry::SRATIONAL: return extractTypedValue(context); default: - SPECTRUM_UNREACHABLE_METADATA_ENTRY_TYPE(type); + throw std::runtime_error("type is not valid"); } } @@ -364,6 +364,8 @@ void Entry::parseFromAddressIntoTagMap( } catch (const SpectrumException& e) { // TODO T30954248: WARN } + catch (const std::exception& e) { + } } } diff --git a/cpp/spectrum/plugins/jpeg/LibJpegDecompressor.cpp b/cpp/spectrum/plugins/jpeg/LibJpegDecompressor.cpp index bbb25d93..44b58fc2 100644 --- a/cpp/spectrum/plugins/jpeg/LibJpegDecompressor.cpp +++ b/cpp/spectrum/plugins/jpeg/LibJpegDecompressor.cpp @@ -172,18 +172,27 @@ image::Specification LibJpegDecompressor::_imageSpecification( const image::pixel::Specification& pixelSpecification) { ensureHeaderIsRead(); - const auto metadata = readMetadata(libJpegDecompressInfo); - const auto orientation = - metadata.entries().orientation().value_or(image::Orientation::Up); - - return image::Specification{ - .size = size, - .format = image::formats::Jpeg, - .pixelSpecification = pixelSpecification, - .orientation = orientation, - .chromaSamplingMode = _chromaSamplingMode(), - .metadata = metadata, - }; + try { + return image::Specification{ + .size = size, + .format = image::formats::Jpeg, + .pixelSpecification = pixelSpecification, + .orientation = image::Orientation::Up, + .chromaSamplingMode = _chromaSamplingMode(), + .metadata = {}, + }; + } catch (const SpectrumException& e) { + return image::Specification{ + .size = size, + .format = image::formats::Jpeg, + .pixelSpecification = pixelSpecification, + .orientation = image::Orientation::Up, + .chromaSamplingMode = _chromaSamplingMode(), + .metadata = {}, + }; + } catch (const std::exception& e) { + + } } std::unique_ptr LibJpegDecompressor::readScanline() {