mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 19:11:50 +01:00
Use Rapid decoder also when no regions are required
This commit is contained in:
parent
d0580d0df1
commit
bcefc176c1
@ -2,8 +2,11 @@ package eu.kanade.tachiyomi.ui.reader.viewer.base;
|
|||||||
|
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
|
import com.davemorrissey.labs.subscaleview.decoder.ImageDecoder;
|
||||||
import com.davemorrissey.labs.subscaleview.decoder.ImageRegionDecoder;
|
import com.davemorrissey.labs.subscaleview.decoder.ImageRegionDecoder;
|
||||||
|
import com.davemorrissey.labs.subscaleview.decoder.RapidImageDecoder;
|
||||||
import com.davemorrissey.labs.subscaleview.decoder.RapidImageRegionDecoder;
|
import com.davemorrissey.labs.subscaleview.decoder.RapidImageRegionDecoder;
|
||||||
|
import com.davemorrissey.labs.subscaleview.decoder.SkiaImageDecoder;
|
||||||
import com.davemorrissey.labs.subscaleview.decoder.SkiaImageRegionDecoder;
|
import com.davemorrissey.labs.subscaleview.decoder.SkiaImageRegionDecoder;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -17,6 +20,7 @@ public abstract class BaseReader extends BaseFragment {
|
|||||||
protected int currentPage;
|
protected int currentPage;
|
||||||
protected List<Page> pages;
|
protected List<Page> pages;
|
||||||
protected Class<? extends ImageRegionDecoder> regionDecoderClass;
|
protected Class<? extends ImageRegionDecoder> regionDecoderClass;
|
||||||
|
protected Class<? extends ImageDecoder> bitmapDecoderClass;
|
||||||
|
|
||||||
public static final int RAPID_DECODER = 0;
|
public static final int RAPID_DECODER = 0;
|
||||||
public static final int SKIA_DECODER = 1;
|
public static final int SKIA_DECODER = 1;
|
||||||
@ -50,14 +54,16 @@ public abstract class BaseReader extends BaseFragment {
|
|||||||
public abstract void onPageListReady(List<Page> pages, int currentPage);
|
public abstract void onPageListReady(List<Page> pages, int currentPage);
|
||||||
public abstract boolean onImageTouch(MotionEvent motionEvent);
|
public abstract boolean onImageTouch(MotionEvent motionEvent);
|
||||||
|
|
||||||
public void setRegionDecoderClass(int value) {
|
public void setDecoderClass(int value) {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case RAPID_DECODER:
|
case RAPID_DECODER:
|
||||||
default:
|
default:
|
||||||
regionDecoderClass = RapidImageRegionDecoder.class;
|
regionDecoderClass = RapidImageRegionDecoder.class;
|
||||||
|
bitmapDecoderClass = RapidImageDecoder.class;
|
||||||
break;
|
break;
|
||||||
case SKIA_DECODER:
|
case SKIA_DECODER:
|
||||||
regionDecoderClass = SkiaImageRegionDecoder.class;
|
regionDecoderClass = SkiaImageRegionDecoder.class;
|
||||||
|
bitmapDecoderClass = SkiaImageDecoder.class;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,6 +72,10 @@ public abstract class BaseReader extends BaseFragment {
|
|||||||
return regionDecoderClass;
|
return regionDecoderClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Class<? extends ImageDecoder> getBitmapDecoderClass() {
|
||||||
|
return bitmapDecoderClass;
|
||||||
|
}
|
||||||
|
|
||||||
public ReaderActivity getReaderActivity() {
|
public ReaderActivity getReaderActivity() {
|
||||||
return (ReaderActivity) getActivity();
|
return (ReaderActivity) getActivity();
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ public abstract class PagerReader extends BaseReader {
|
|||||||
subscriptions = new CompositeSubscription();
|
subscriptions = new CompositeSubscription();
|
||||||
subscriptions.add(getReaderActivity().getPreferences().imageDecoder()
|
subscriptions.add(getReaderActivity().getPreferences().imageDecoder()
|
||||||
.asObservable()
|
.asObservable()
|
||||||
.doOnNext(this::setRegionDecoderClass)
|
.doOnNext(this::setDecoderClass)
|
||||||
.skip(1)
|
.skip(1)
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.subscribe(v -> adapter.notifyDataSetChanged()));
|
.subscribe(v -> adapter.notifyDataSetChanged()));
|
||||||
|
@ -66,6 +66,7 @@ public class PagerReaderFragment extends BaseFragment {
|
|||||||
imageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE);
|
imageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE);
|
||||||
imageView.setMinimumScaleType(parentFragment.scaleType);
|
imageView.setMinimumScaleType(parentFragment.scaleType);
|
||||||
imageView.setRegionDecoderClass(parentFragment.getRegionDecoderClass());
|
imageView.setRegionDecoderClass(parentFragment.getRegionDecoderClass());
|
||||||
|
imageView.setBitmapDecoderClass(parentFragment.getBitmapDecoderClass());
|
||||||
imageView.setOnTouchListener((v, motionEvent) -> parentFragment.onImageTouch(motionEvent));
|
imageView.setOnTouchListener((v, motionEvent) -> parentFragment.onImageTouch(motionEvent));
|
||||||
imageView.setOnImageEventListener(new SubsamplingScaleImageView.DefaultOnImageEventListener() {
|
imageView.setOnImageEventListener(new SubsamplingScaleImageView.DefaultOnImageEventListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -38,6 +38,8 @@ public class WebtoonHolder extends RecyclerView.ViewHolder {
|
|||||||
imageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE);
|
imageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE);
|
||||||
imageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_FIT_WIDTH);
|
imageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_FIT_WIDTH);
|
||||||
imageView.setMaxScale(10);
|
imageView.setMaxScale(10);
|
||||||
|
imageView.setRegionDecoderClass(adapter.getReader().getRegionDecoderClass());
|
||||||
|
imageView.setBitmapDecoderClass(adapter.getReader().getBitmapDecoderClass());
|
||||||
imageView.setOnTouchListener(touchListener);
|
imageView.setOnTouchListener(touchListener);
|
||||||
imageView.setMaxDimensions(maxDim, maxDim);
|
imageView.setMaxDimensions(maxDim, maxDim);
|
||||||
imageView.setOnImageEventListener(new SubsamplingScaleImageView.DefaultOnImageEventListener() {
|
imageView.setOnImageEventListener(new SubsamplingScaleImageView.DefaultOnImageEventListener() {
|
||||||
@ -99,7 +101,6 @@ public class WebtoonHolder extends RecyclerView.ViewHolder {
|
|||||||
setErrorButtonVisible(false);
|
setErrorButtonVisible(false);
|
||||||
setProgressVisible(false);
|
setProgressVisible(false);
|
||||||
setImageVisible(true);
|
setImageVisible(true);
|
||||||
imageView.setRegionDecoderClass(adapter.getReader().getRegionDecoderClass());
|
|
||||||
imageView.setImage(ImageSource.uri(page.getImagePath()));
|
imageView.setImage(ImageSource.uri(page.getImagePath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,10 +45,10 @@ public class WebtoonReader extends BaseReader {
|
|||||||
|
|
||||||
decoderSubscription = getReaderActivity().getPreferences().imageDecoder()
|
decoderSubscription = getReaderActivity().getPreferences().imageDecoder()
|
||||||
.asObservable()
|
.asObservable()
|
||||||
.doOnNext(this::setRegionDecoderClass)
|
.doOnNext(this::setDecoderClass)
|
||||||
.skip(1)
|
.skip(1)
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.subscribe(v -> adapter.notifyDataSetChanged());
|
.subscribe(v -> recycler.setAdapter(adapter));
|
||||||
|
|
||||||
gestureDetector = new GestureDetector(getActivity(), new SimpleOnGestureListener() {
|
gestureDetector = new GestureDetector(getActivity(), new SimpleOnGestureListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.davemorrissey.labs.subscaleview.decoder;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import rapid.decoder.BitmapDecoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A very simple implementation of {@link com.davemorrissey.labs.subscaleview.decoder.ImageRegionDecoder}
|
||||||
|
* using the RapidDecoder library (https://github.com/suckgamony/RapidDecoder). For PNGs, this can
|
||||||
|
* give more reliable decoding and better performance. For JPGs, it is slower and can run out of
|
||||||
|
* memory with large images, but has better support for grayscale and CMYK images.
|
||||||
|
*
|
||||||
|
* This is an incomplete and untested implementation provided as an example only.
|
||||||
|
*/
|
||||||
|
public class RapidImageDecoder implements ImageDecoder {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Bitmap decode(Context context, Uri uri) throws Exception {
|
||||||
|
return BitmapDecoder.from(context, uri).useBuiltInDecoder(true).config(Bitmap.Config.RGB_565).decode();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user