Skip to content

Commit

Permalink
Add display profile
Browse files Browse the repository at this point in the history
  • Loading branch information
wwww-wwww committed Mar 10, 2024
1 parent 2e90b34 commit ddd6dc7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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

0 comments on commit ddd6dc7

Please sign in to comment.