Use Rapid decoder also when no regions are required

This commit is contained in:
inorichi 2016-01-30 16:10:53 +01:00
parent d0580d0df1
commit bcefc176c1
6 changed files with 41 additions and 5 deletions

View File

@ -2,8 +2,11 @@ package eu.kanade.tachiyomi.ui.reader.viewer.base;
import android.view.MotionEvent;
import com.davemorrissey.labs.subscaleview.decoder.ImageDecoder;
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.SkiaImageDecoder;
import com.davemorrissey.labs.subscaleview.decoder.SkiaImageRegionDecoder;
import java.util.List;
@ -17,6 +20,7 @@ public abstract class BaseReader extends BaseFragment {
protected int currentPage;
protected List<Page> pages;
protected Class<? extends ImageRegionDecoder> regionDecoderClass;
protected Class<? extends ImageDecoder> bitmapDecoderClass;
public static final int RAPID_DECODER = 0;
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 boolean onImageTouch(MotionEvent motionEvent);
public void setRegionDecoderClass(int value) {
public void setDecoderClass(int value) {
switch (value) {
case RAPID_DECODER:
default:
regionDecoderClass = RapidImageRegionDecoder.class;
bitmapDecoderClass = RapidImageDecoder.class;
break;
case SKIA_DECODER:
regionDecoderClass = SkiaImageRegionDecoder.class;
bitmapDecoderClass = SkiaImageDecoder.class;
break;
}
}
@ -66,6 +72,10 @@ public abstract class BaseReader extends BaseFragment {
return regionDecoderClass;
}
public Class<? extends ImageDecoder> getBitmapDecoderClass() {
return bitmapDecoderClass;
}
public ReaderActivity getReaderActivity() {
return (ReaderActivity) getActivity();
}

View File

@ -63,7 +63,7 @@ public abstract class PagerReader extends BaseReader {
subscriptions = new CompositeSubscription();
subscriptions.add(getReaderActivity().getPreferences().imageDecoder()
.asObservable()
.doOnNext(this::setRegionDecoderClass)
.doOnNext(this::setDecoderClass)
.skip(1)
.distinctUntilChanged()
.subscribe(v -> adapter.notifyDataSetChanged()));

View File

@ -66,6 +66,7 @@ public class PagerReaderFragment extends BaseFragment {
imageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE);
imageView.setMinimumScaleType(parentFragment.scaleType);
imageView.setRegionDecoderClass(parentFragment.getRegionDecoderClass());
imageView.setBitmapDecoderClass(parentFragment.getBitmapDecoderClass());
imageView.setOnTouchListener((v, motionEvent) -> parentFragment.onImageTouch(motionEvent));
imageView.setOnImageEventListener(new SubsamplingScaleImageView.DefaultOnImageEventListener() {
@Override

View File

@ -38,6 +38,8 @@ public class WebtoonHolder extends RecyclerView.ViewHolder {
imageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE);
imageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_FIT_WIDTH);
imageView.setMaxScale(10);
imageView.setRegionDecoderClass(adapter.getReader().getRegionDecoderClass());
imageView.setBitmapDecoderClass(adapter.getReader().getBitmapDecoderClass());
imageView.setOnTouchListener(touchListener);
imageView.setMaxDimensions(maxDim, maxDim);
imageView.setOnImageEventListener(new SubsamplingScaleImageView.DefaultOnImageEventListener() {
@ -99,7 +101,6 @@ public class WebtoonHolder extends RecyclerView.ViewHolder {
setErrorButtonVisible(false);
setProgressVisible(false);
setImageVisible(true);
imageView.setRegionDecoderClass(adapter.getReader().getRegionDecoderClass());
imageView.setImage(ImageSource.uri(page.getImagePath()));
}

View File

@ -45,10 +45,10 @@ public class WebtoonReader extends BaseReader {
decoderSubscription = getReaderActivity().getPreferences().imageDecoder()
.asObservable()
.doOnNext(this::setRegionDecoderClass)
.doOnNext(this::setDecoderClass)
.skip(1)
.distinctUntilChanged()
.subscribe(v -> adapter.notifyDataSetChanged());
.subscribe(v -> recycler.setAdapter(adapter));
gestureDetector = new GestureDetector(getActivity(), new SimpleOnGestureListener() {
@Override

View File

@ -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();
}
}