Cleanup ImageDecoder Wrapper
We have removed all user of these No logical changes
This commit is contained in:
1 parent
e2e0562719
commit
069d7e2382
7 files changed
+10
-78
No files matched your search
@@ -335,7 +335,7 @@ public class ArchiveGalleryProvider extends GalleryProvider2 {
|
||||
Image image = null;
|
||||
if (buffer != null) {
|
||||
try {
|
||||
image = Image.decode(buffer, false, () -> {
|
||||
image = Image.decode(buffer, () -> {
|
||||
archiveAccessor.releaseByteBuffer(buffer);
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -259,7 +259,7 @@ public class DirGalleryProvider extends GalleryProvider2 implements Runnable {
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = files[index].openInputStream();
|
||||
Image image = Image.decode((FileInputStream) is, false);
|
||||
Image image = Image.decode((FileInputStream) is);
|
||||
mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
notifyPageSucceed(index, image);
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -1679,7 +1679,7 @@ public final class SpiderQueen implements Runnable {
|
||||
|
||||
if (is != null) {
|
||||
try {
|
||||
image = Image.decode(((FileInputStream) is), false);
|
||||
image = Image.decode(((FileInputStream) is));
|
||||
} catch (ImageDecoder.DecodeException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
|
||||
@@ -122,15 +122,6 @@ public class ImageWrapper {
|
||||
return mCut.height();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Image#render(int, int, Bitmap, int, int, int, int)
|
||||
*/
|
||||
public void render(int srcX, int srcY, Bitmap dst, int dstX, int dstY,
|
||||
int width, int height, boolean fillBlank, int defaultColor) {
|
||||
mImage.render(srcX + mCut.left, srcY + mCut.top, dst, dstX, dstY,
|
||||
width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Image#texImage(boolean, int, int, int, int)
|
||||
*/
|
||||
|
||||
@@ -21,7 +21,6 @@ import android.content.res.Resources
|
||||
import android.graphics.Bitmap
|
||||
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
|
||||
@@ -39,10 +38,9 @@ import kotlin.math.max
|
||||
|
||||
class Image private constructor(
|
||||
source: Source?, drawable: Drawable? = null,
|
||||
val hardware: Boolean = true,
|
||||
val release: () -> Unit? = {}
|
||||
) {
|
||||
internal var mObtainedDrawable: Drawable?
|
||||
private var mObtainedDrawable: Drawable?
|
||||
private var mBitmap: Bitmap? = null
|
||||
private var mCanvas: Canvas? = null
|
||||
|
||||
@@ -51,7 +49,7 @@ class Image private constructor(
|
||||
source?.let {
|
||||
mObtainedDrawable =
|
||||
ImageDecoder.decodeDrawable(source) { decoder: ImageDecoder, info: ImageInfo, src: Source ->
|
||||
decoder.allocator = if (hardware) ALLOCATOR_DEFAULT else ALLOCATOR_SOFTWARE
|
||||
decoder.allocator = ALLOCATOR_SOFTWARE
|
||||
// Sadly we must use software memory since we need copy it to tile buffer, fuck glgallery
|
||||
// Idk it will cause how much performance regression
|
||||
|
||||
@@ -63,7 +61,6 @@ class Image private constructor(
|
||||
), 1
|
||||
)
|
||||
)
|
||||
// Don't
|
||||
} // Should we lazy decode it?
|
||||
}
|
||||
if (mObtainedDrawable == null) {
|
||||
@@ -105,31 +102,7 @@ class Image private constructor(
|
||||
mObtainedDrawable!!.draw(mCanvas!!)
|
||||
}
|
||||
|
||||
fun render(
|
||||
srcX: Int, srcY: Int, dst: Bitmap, dstX: Int, dstY: Int,
|
||||
width: Int, height: Int
|
||||
) {
|
||||
check(!hardware) { "Hardware buffer cannot be used in glgallery" }
|
||||
val bitmap: Bitmap = if (animated) {
|
||||
updateBitmap()
|
||||
mBitmap!!
|
||||
} else {
|
||||
(mObtainedDrawable as BitmapDrawable).bitmap
|
||||
}
|
||||
nativeRender(
|
||||
bitmap,
|
||||
srcX,
|
||||
srcY,
|
||||
dst,
|
||||
dstX,
|
||||
dstY,
|
||||
width,
|
||||
height
|
||||
)
|
||||
}
|
||||
|
||||
fun texImage(init: Boolean, offsetX: Int, offsetY: Int, width: Int, height: Int) {
|
||||
check(!hardware) { "Hardware buffer cannot be used in glgallery" }
|
||||
val bitmap: Bitmap? = if (animated) {
|
||||
updateBitmap()
|
||||
mBitmap
|
||||
@@ -177,37 +150,30 @@ class Image private constructor(
|
||||
|
||||
@Throws(DecodeException::class)
|
||||
@JvmStatic
|
||||
fun decode(stream: FileInputStream, hardware: Boolean = true): Image {
|
||||
fun decode(stream: FileInputStream): Image {
|
||||
val src = ImageDecoder.createSource(
|
||||
stream.channel.map(
|
||||
FileChannel.MapMode.READ_ONLY, 0,
|
||||
stream.available().toLong()
|
||||
)
|
||||
)
|
||||
return Image(src, hardware = hardware)
|
||||
return Image(src)
|
||||
}
|
||||
|
||||
@Throws(DecodeException::class)
|
||||
@JvmStatic
|
||||
fun decode(buffer: ByteBuffer, hardware: Boolean = true, release: () -> Unit? = {}): Image {
|
||||
fun decode(buffer: ByteBuffer, release: () -> Unit? = {}): Image {
|
||||
val src = ImageDecoder.createSource(buffer)
|
||||
return Image(src, hardware = hardware) {
|
||||
return Image(src) {
|
||||
release()
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun create(bitmap: Bitmap): Image {
|
||||
return Image(null, bitmap.toDrawable(Resources.getSystem()), false)
|
||||
return Image(null, bitmap.toDrawable(Resources.getSystem()))
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
private external fun nativeRender(
|
||||
bitmap: Bitmap,
|
||||
srcX: Int, srcY: Int, dst: Bitmap, dstX: Int, dstY: Int,
|
||||
width: Int, height: Int
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
private external fun nativeTexImage(
|
||||
bitmap: Bitmap,
|
||||
|
||||
Reference in new issue
Block a user