Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option for whether to use hardware bitmap config #6

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ public class SubsamplingScaleImageView extends View {
private int minimumScaleType = SCALE_TYPE_CENTER_INSIDE;
// Whether to crop borders.
private boolean cropBorders = false;
// Whether to decode to hardware bitmap
private boolean hardwareConfig = true;
private int maxTileWidth = TILE_SIZE_AUTO;
private int maxTileHeight = TILE_SIZE_AUTO;
// An executor service for loading of images
Expand Down Expand Up @@ -1541,6 +1543,15 @@ public void setCropBorders(boolean cropBorders) {
this.cropBorders = cropBorders;
}

/**
* Set if we want to use hardware bitmap config for decoded bitmap regions.
*
* @param hardwareConfig Whether to use hardware bitmap config.
*/
public void setHardwareConfig(boolean hardwareConfig) {
this.hardwareConfig = hardwareConfig;
}

/**
* By default the View automatically calculates the optimal tile size. Set this to override this, and force an upper limit to the dimensions of the generated tiles. Passing {@link #TILE_SIZE_AUTO} will re-enable the default behaviour.
*
Expand Down Expand Up @@ -2760,7 +2771,7 @@ protected int[] doInBackground(Void... params) {
InputProvider provider = providerRef.get();
if (context != null && view != null && provider == view.provider) {
view.debug("TilesInitTask.doInBackground");
decoder = new Decoder(view.cropBorders, view.displayProfile.toByteArray());
decoder = new Decoder(view.cropBorders, view.hardwareConfig, view.displayProfile.toByteArray());
Point dimensions = decoder.init(context, provider);
int sWidth = dimensions.x;
int sHeight = dimensions.y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import tachiyomi.decoder.ImageDecoder.Companion.newInstance

class Decoder(
private val cropBorders: Boolean,
private val hardwareConfig: Boolean,
private val displayProfile: ByteArray,
) : ImageRegionDecoder {

Expand Down Expand Up @@ -53,11 +54,16 @@ class Decoder(
* @return The decoded region. It is safe to return null if decoding fails.
*/
override fun decodeRegion(sRect: Rect, sampleSize: Int): Bitmap {
val bitmap = decoder?.decode(sRect, sampleSize)
if (Build.VERSION.SDK_INT >= 26) {
bitmap?.copy(Bitmap.Config.HARDWARE, false)?.let { return it; }
var bitmap = decoder?.decode(sRect, sampleSize)
check(bitmap != null) { "Failed to decode region" }
if (hardwareConfig && Build.VERSION.SDK_INT >= 26) {
val hwBitmap = bitmap.copy(Bitmap.Config.HARDWARE, false)
if (hwBitmap != null) {
bitmap.recycle()
bitmap = hwBitmap
}
}
return bitmap ?: error("Null region bitmap")
return bitmap
}

/**
Expand Down