1 parent
68e3bb8d66
commit
85c7829636
5 files changed
+20
-10
No files matched your search
@@ -17,9 +17,9 @@
|
||||
package com.hippo.ehviewer.gallery;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.ImageDecoder;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.Process;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -36,7 +36,6 @@ import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.thread.PVLock;
|
||||
import com.hippo.yorozuya.thread.PriorityThread;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -335,10 +334,15 @@ public class ArchiveGalleryProvider extends GalleryProvider2 {
|
||||
|
||||
Image image = null;
|
||||
if (buffer != null) {
|
||||
image = Image.decode(buffer, false, () -> {
|
||||
try {
|
||||
image = Image.decode(buffer, false, () -> {
|
||||
archiveAccessor.releaseByteBuffer(buffer);
|
||||
return null;
|
||||
});
|
||||
} catch (ImageDecoder.DecodeException e) {
|
||||
archiveAccessor.releaseByteBuffer(buffer);
|
||||
return null;
|
||||
});
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (image != null) {
|
||||
notifyPageSucceed(index, image);
|
||||
|
||||
@@ -261,11 +261,7 @@ public class DirGalleryProvider extends GalleryProvider2 implements Runnable {
|
||||
is = files[index].openInputStream();
|
||||
Image image = Image.decode((FileInputStream) is, false);
|
||||
mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
if (image != null) {
|
||||
notifyPageSucceed(index, image);
|
||||
} else {
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_decoding_failed));
|
||||
}
|
||||
notifyPageSucceed(index, image);
|
||||
} catch (IOException e) {
|
||||
mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_reading_failed));
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.hippo.ehviewer.spider;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.ImageDecoder;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Process;
|
||||
import android.text.TextUtils;
|
||||
@@ -1679,6 +1680,8 @@ public final class SpiderQueen implements Runnable {
|
||||
if (is != null) {
|
||||
try {
|
||||
image = Image.decode(((FileInputStream) is), false);
|
||||
} catch (ImageDecoder.DecodeException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.graphics.Canvas
|
||||
import android.graphics.ImageDecoder
|
||||
import android.graphics.ImageDecoder.ALLOCATOR_DEFAULT
|
||||
import android.graphics.ImageDecoder.ALLOCATOR_SOFTWARE
|
||||
import android.graphics.ImageDecoder.DecodeException
|
||||
import android.graphics.ImageDecoder.ImageInfo
|
||||
import android.graphics.ImageDecoder.Source
|
||||
import android.graphics.PixelFormat
|
||||
@@ -34,6 +35,7 @@ import androidx.core.graphics.drawable.toDrawable
|
||||
import java.io.FileInputStream
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.channels.FileChannel
|
||||
import kotlin.jvm.Throws
|
||||
import kotlin.math.max
|
||||
|
||||
class Image private constructor(
|
||||
@@ -170,6 +172,7 @@ class Image private constructor(
|
||||
screenHeight = context.resources.displayMetrics.heightPixels
|
||||
}
|
||||
|
||||
@Throws(DecodeException::class)
|
||||
@JvmStatic
|
||||
fun decode(stream: FileInputStream, hardware: Boolean = true): Image {
|
||||
val src = ImageDecoder.createSource(
|
||||
@@ -181,6 +184,7 @@ class Image private constructor(
|
||||
return Image(src, hardware = hardware)
|
||||
}
|
||||
|
||||
@Throws(DecodeException::class)
|
||||
@JvmStatic
|
||||
fun decode(buffer: ByteBuffer, hardware: Boolean = true, release: () -> Unit? = {}): Image {
|
||||
val src = ImageDecoder.createSource(buffer)
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
*/
|
||||
package com.hippo.image
|
||||
|
||||
import android.graphics.ImageDecoder
|
||||
import android.graphics.drawable.Drawable
|
||||
import java.io.FileInputStream
|
||||
import kotlin.jvm.Throws
|
||||
|
||||
class ImageBitmap private constructor(image: Image) {
|
||||
private var mImage: Image? = image
|
||||
@@ -55,6 +57,7 @@ class ImageBitmap private constructor(image: Image) {
|
||||
get() = mImage!!.height
|
||||
|
||||
companion object {
|
||||
@Throws(ImageDecoder.DecodeException::class)
|
||||
@JvmStatic
|
||||
fun decode(stream: FileInputStream): ImageBitmap {
|
||||
val image = Image.decode(stream)
|
||||
|
||||
Reference in new issue
Block a user