mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2024-12-24 23:43:10 +01:00
using RapidDecoder, fixed #393
This commit is contained in:
parent
2026846829
commit
8f8955ca80
@ -62,6 +62,7 @@ android {
|
||||
repositories {
|
||||
maven { url 'https://s3.amazonaws.com/repo.commonsware.com' }
|
||||
maven { url 'https://maven.fabric.io/public' }
|
||||
maven { url 'https://github.com/suckgamony/RapidDecoder/raw/master/repository' }
|
||||
flatDir { dirs "$projectDir/lib" }
|
||||
}
|
||||
|
||||
@ -108,10 +109,14 @@ dependencies {
|
||||
compile 'com.lnikkila:extendedtouchview:0.1.0'
|
||||
compile 'com.google.dagger:dagger:2.0.2'
|
||||
compile 'org.attoparser:attoparser:1.4.0.RELEASE'
|
||||
compile 'com.github.mariotaku.MediaViewerLibrary:base:0.9.10'
|
||||
compile 'com.github.mariotaku.MediaViewerLibrary:subsample-image-view:0.9.10'
|
||||
compile 'com.github.mariotaku.MediaViewerLibrary:base:0.9.11'
|
||||
compile 'com.github.mariotaku.MediaViewerLibrary:subsample-image-view:0.9.11'
|
||||
compile 'com.github.mariotaku.SQLiteQB:library:0.9.5'
|
||||
compile 'com.github.mariotaku.ObjectCursor:core:0.9.5'
|
||||
compile 'rapid.decoder:library:0.3.0'
|
||||
compile 'rapid.decoder:jpeg-decoder:0.3.0'
|
||||
compile 'rapid.decoder:png-decoder:0.3.0'
|
||||
|
||||
compile project(':twidere.component.common')
|
||||
compile project(':twidere.component.nyan')
|
||||
|
||||
|
@ -65,6 +65,7 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.commonsware.cwac.layouts.AspectLockedFrameLayout;
|
||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
|
||||
import com.pnikosis.materialishprogress.ProgressWheel;
|
||||
import com.sprylab.android.widget.TextureVideoView;
|
||||
|
||||
@ -92,6 +93,8 @@ import org.mariotaku.twidere.util.PermissionUtils;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper;
|
||||
import org.mariotaku.twidere.util.imageviewer.RapidImageDecoder;
|
||||
import org.mariotaku.twidere.util.imageviewer.RapidImageRegionDecoder;
|
||||
import org.mariotaku.twidere.util.media.MediaExtra;
|
||||
|
||||
import java.io.File;
|
||||
@ -854,6 +857,12 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements
|
||||
activity.supportInvalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupImageView(SubsamplingScaleImageView imageView) {
|
||||
imageView.setRegionDecoderClass(RapidImageRegionDecoder.class);
|
||||
imageView.setBitmapDecoderClass(RapidImageDecoder.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static class VideoPageFragment extends CacheDownloadMediaViewerFragment
|
||||
|
@ -0,0 +1,26 @@
|
||||
package org.mariotaku.twidere.util.imageviewer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.davemorrissey.labs.subscaleview.decoder.ImageDecoder;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package org.mariotaku.twidere.util.imageviewer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.davemorrissey.labs.subscaleview.decoder.ImageRegionDecoder;
|
||||
|
||||
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.
|
||||
* <p/>
|
||||
* This is an incomplete and untested implementation provided as an example only.
|
||||
*/
|
||||
public class RapidImageRegionDecoder implements ImageRegionDecoder {
|
||||
|
||||
private BitmapDecoder decoder;
|
||||
|
||||
@Override
|
||||
public Point init(Context context, Uri uri) throws Exception {
|
||||
decoder = BitmapDecoder.from(context, uri);
|
||||
decoder.useBuiltInDecoder(true);
|
||||
return new Point(decoder.sourceWidth(), decoder.sourceHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Bitmap decodeRegion(Rect sRect, int sampleSize) {
|
||||
try {
|
||||
return decoder.reset().region(sRect).scale(sRect.width() / sampleSize, sRect.height() / sampleSize).decode();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReady() {
|
||||
return decoder != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recycle() {
|
||||
BitmapDecoder.destroyMemoryCache();
|
||||
BitmapDecoder.destroyDiskCache();
|
||||
try {
|
||||
decoder.reset();
|
||||
} catch (UnsupportedOperationException ignore) {
|
||||
|
||||
}
|
||||
decoder = null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user