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 display profile #2

Merged
merged 1 commit into from
Mar 15, 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 @@ -32,6 +32,7 @@
import com.davemorrissey.labs.subscaleview.decoder.ImageRegionDecoder;
import com.davemorrissey.labs.subscaleview.provider.InputProvider;

import java.io.ByteArrayOutputStream;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -137,6 +138,8 @@ public class SubsamplingScaleImageView extends View {
private static final int MESSAGE_LONG_CLICK = 1;
// A global preference for bitmap format, available to decoder classes that respect it
private static Bitmap.Config preferredBitmapConfig;
// Optional display profile for CMS
private static ByteArrayOutputStream displayProfile = new ByteArrayOutputStream();
private final ReadWriteLock decoderLock = new ReentrantReadWriteLock(true);
// Current quickscale state
private final float quickScaleThreshold;
Expand Down Expand Up @@ -324,6 +327,16 @@ public static void setPreferredBitmapConfig(Bitmap.Config preferredBitmapConfig)
SubsamplingScaleImageView.preferredBitmapConfig = preferredBitmapConfig;
}

/**
* Set to use a display profile for color management.
*
* @param displayProfile Profile to use.
*/
public static void setDisplayProfile(byte[] displayProfile) {
SubsamplingScaleImageView.displayProfile.reset();
SubsamplingScaleImageView.displayProfile.write(displayProfile, 0, displayProfile.length);
}

/**
* Set the image source from a bitmap, resource, asset, file or other URI.
*
Expand Down Expand Up @@ -2670,7 +2683,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);
decoder = new Decoder(view.cropBorders, 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 @@ -11,6 +11,7 @@ import tachiyomi.decoder.ImageDecoder.Companion.newInstance

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

private var decoder: ImageDecoder? = null
Expand All @@ -27,7 +28,7 @@ class Decoder(
override fun init(context: Context, provider: InputProvider): Point {
try {
provider.openStream().use { inputStream ->
decoder = newInstance(inputStream!!, cropBorders)
decoder = newInstance(inputStream!!, cropBorders, displayProfile)
}
} catch (e: Exception) {
Log.e(TAG, "Failed to init decoder", e)
Expand Down