mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-05 11:54:38 -05:00
* Bitmap: Use provided config * Bitmap: implement copy * Bitmap: Simplify getPixels This also fixes a bug where the returned data may not be in the correct format Android getPixels(): > The returned colors are non-premultiplied ARGB values in the sRGB color space. BufferedImage getRGB(): > Returns an array of integer pixels in the default RGB color model (TYPE_INT_ARGB) and default sRGB color space * Stub TextPaint and Paint * Paint: Implement some required functions * Stub StaticLayout and Layout * Implement some Paint support * Draw Bounds * WebP write support * First text rendering * Paint: Fix text size, font metrics * Paint: Fix not copying new properties Fixes font size in draw * Canvas: Stroke add cap/join for better aliasing Otherwise we get bad artifacts on sharp corners Based on https://stackoverflow.com/a/35222059/ * Remove logs * Canvas: Implement other drawText methods * Bitmap: support erase * Layout: Fix text direction Should be LTR, otherwise 0 is read, which is automatically interpreted as RTL without explicit check * Bitmap: scale to destination rectangle * Canvas: drawBitmap with just x/y * Bitmap: Convert image on JPEG export to RGB JPEG does not support alpha, so will throw "bogus color space" * Switch to newer fork
156 lines
5.6 KiB
Java
156 lines
5.6 KiB
Java
/*
|
|
* Copyright (C) 2014 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
package com.android.internal.util;
|
|
|
|
public final class GrowingArrayUtils {
|
|
|
|
public static <T> T[] append(T[] array, int currentSize, T element) {
|
|
assert currentSize <= array.length;
|
|
|
|
if (currentSize + 1 > array.length) {
|
|
@SuppressWarnings("unchecked")
|
|
T[] newArray = ArrayUtils.newUnpaddedArray(
|
|
(Class<T>) array.getClass().getComponentType(), growSize(currentSize));
|
|
System.arraycopy(array, 0, newArray, 0, currentSize);
|
|
array = newArray;
|
|
}
|
|
array[currentSize] = element;
|
|
return array;
|
|
}
|
|
|
|
public static int[] append(int[] array, int currentSize, int element) {
|
|
assert currentSize <= array.length;
|
|
|
|
if (currentSize + 1 > array.length) {
|
|
int[] newArray = ArrayUtils.newUnpaddedIntArray(growSize(currentSize));
|
|
System.arraycopy(array, 0, newArray, 0, currentSize);
|
|
array = newArray;
|
|
}
|
|
array[currentSize] = element;
|
|
return array;
|
|
}
|
|
|
|
public static long[] append(long[] array, int currentSize, long element) {
|
|
assert currentSize <= array.length;
|
|
|
|
if (currentSize + 1 > array.length) {
|
|
long[] newArray = ArrayUtils.newUnpaddedLongArray(growSize(currentSize));
|
|
System.arraycopy(array, 0, newArray, 0, currentSize);
|
|
array = newArray;
|
|
}
|
|
array[currentSize] = element;
|
|
return array;
|
|
}
|
|
|
|
public static boolean[] append(boolean[] array, int currentSize, boolean element) {
|
|
assert currentSize <= array.length;
|
|
|
|
if (currentSize + 1 > array.length) {
|
|
boolean[] newArray = ArrayUtils.newUnpaddedBooleanArray(growSize(currentSize));
|
|
System.arraycopy(array, 0, newArray, 0, currentSize);
|
|
array = newArray;
|
|
}
|
|
array[currentSize] = element;
|
|
return array;
|
|
}
|
|
|
|
public static float[] append(float[] array, int currentSize, float element) {
|
|
assert currentSize <= array.length;
|
|
|
|
if (currentSize + 1 > array.length) {
|
|
float[] newArray = ArrayUtils.newUnpaddedFloatArray(growSize(currentSize));
|
|
System.arraycopy(array, 0, newArray, 0, currentSize);
|
|
array = newArray;
|
|
}
|
|
array[currentSize] = element;
|
|
return array;
|
|
}
|
|
|
|
public static <T> T[] insert(T[] array, int currentSize, int index, T element) {
|
|
assert currentSize <= array.length;
|
|
|
|
if (currentSize + 1 <= array.length) {
|
|
System.arraycopy(array, index, array, index + 1, currentSize - index);
|
|
array[index] = element;
|
|
return array;
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
T[] newArray = ArrayUtils.newUnpaddedArray((Class<T>)array.getClass().getComponentType(),
|
|
growSize(currentSize));
|
|
System.arraycopy(array, 0, newArray, 0, index);
|
|
newArray[index] = element;
|
|
System.arraycopy(array, index, newArray, index + 1, array.length - index);
|
|
return newArray;
|
|
}
|
|
|
|
public static int[] insert(int[] array, int currentSize, int index, int element) {
|
|
assert currentSize <= array.length;
|
|
|
|
if (currentSize + 1 <= array.length) {
|
|
System.arraycopy(array, index, array, index + 1, currentSize - index);
|
|
array[index] = element;
|
|
return array;
|
|
}
|
|
|
|
int[] newArray = ArrayUtils.newUnpaddedIntArray(growSize(currentSize));
|
|
System.arraycopy(array, 0, newArray, 0, index);
|
|
newArray[index] = element;
|
|
System.arraycopy(array, index, newArray, index + 1, array.length - index);
|
|
return newArray;
|
|
}
|
|
|
|
public static long[] insert(long[] array, int currentSize, int index, long element) {
|
|
assert currentSize <= array.length;
|
|
|
|
if (currentSize + 1 <= array.length) {
|
|
System.arraycopy(array, index, array, index + 1, currentSize - index);
|
|
array[index] = element;
|
|
return array;
|
|
}
|
|
|
|
long[] newArray = ArrayUtils.newUnpaddedLongArray(growSize(currentSize));
|
|
System.arraycopy(array, 0, newArray, 0, index);
|
|
newArray[index] = element;
|
|
System.arraycopy(array, index, newArray, index + 1, array.length - index);
|
|
return newArray;
|
|
}
|
|
|
|
public static boolean[] insert(boolean[] array, int currentSize, int index, boolean element) {
|
|
assert currentSize <= array.length;
|
|
|
|
if (currentSize + 1 <= array.length) {
|
|
System.arraycopy(array, index, array, index + 1, currentSize - index);
|
|
array[index] = element;
|
|
return array;
|
|
}
|
|
|
|
boolean[] newArray = ArrayUtils.newUnpaddedBooleanArray(growSize(currentSize));
|
|
System.arraycopy(array, 0, newArray, 0, index);
|
|
newArray[index] = element;
|
|
System.arraycopy(array, index, newArray, index + 1, array.length - index);
|
|
return newArray;
|
|
}
|
|
|
|
public static int growSize(int currentSize) {
|
|
return currentSize <= 4 ? 8 : currentSize * 2;
|
|
}
|
|
|
|
// Uninstantiable
|
|
private GrowingArrayUtils() {}
|
|
}
|