-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
90 changed files
with
1,721 additions
and
1,910 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
app/customssiv/src/main/java/me/devsaki/hentoid/customssiv/decoder/DecoderFactory.java
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
app/customssiv/src/main/java/me/devsaki/hentoid/customssiv/decoder/ImageDecoder.java
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
app/customssiv/src/main/java/me/devsaki/hentoid/customssiv/decoder/ImageDecoder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package me.devsaki.hentoid.customssiv.decoder | ||
|
||
import android.content.Context | ||
import android.graphics.Bitmap | ||
import android.net.Uri | ||
|
||
/** | ||
* Interface for image decoding classes, allowing the default {@link android.graphics.BitmapFactory} | ||
* based on the Skia library to be replaced with a custom class. | ||
*/ | ||
interface ImageDecoder { | ||
/** | ||
* Decode an image. The URI can be in one of the following formats: | ||
* <br></br> | ||
* File: `file:///scard/picture.jpg` | ||
* <br></br> | ||
* Asset: `file:///android_asset/picture.png` | ||
* <br></br> | ||
* Resource: `android.resource://com.example.app/drawable/picture` | ||
* | ||
* @param context Application context | ||
* @param uri URI of the image | ||
* @return the decoded bitmap | ||
* @throws Exception if decoding fails. | ||
*/ | ||
@Throws(Exception::class) | ||
fun decode(context: Context, uri: Uri): Bitmap | ||
} |
57 changes: 27 additions & 30 deletions
57
...ustomssiv/decoder/ImageRegionDecoder.java → .../customssiv/decoder/ImageRegionDecoder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,61 @@ | ||
package me.devsaki.hentoid.customssiv.decoder; | ||
package me.devsaki.hentoid.customssiv.decoder | ||
|
||
import android.content.Context; | ||
import android.graphics.Bitmap; | ||
import android.graphics.Point; | ||
import android.graphics.Rect; | ||
import android.net.Uri; | ||
|
||
import androidx.annotation.NonNull; | ||
import android.content.Context | ||
import android.graphics.Bitmap | ||
import android.graphics.Point | ||
import android.graphics.Rect | ||
import android.net.Uri | ||
|
||
/** | ||
* Interface for image decoding classes, allowing the default {@link android.graphics.BitmapRegionDecoder} | ||
* based on the Skia library to be replaced with a custom class. | ||
*/ | ||
public interface ImageRegionDecoder { | ||
|
||
interface ImageRegionDecoder { | ||
/** | ||
* Initialise the decoder. When possible, perform initial setup work once in this method. The | ||
* dimensions of the image must be returned. The URI can be in one of the following formats: | ||
* <br> | ||
* File: <code>file:///scard/picture.jpg</code> | ||
* <br> | ||
* Asset: <code>file:///android_asset/picture.png</code> | ||
* <br> | ||
* Resource: <code>android.resource://com.example.app/drawable/picture</code> | ||
* <br></br> | ||
* File: `file:///scard/picture.jpg` | ||
* <br></br> | ||
* Asset: `file:///android_asset/picture.png` | ||
* <br></br> | ||
* Resource: `android.resource://com.example.app/drawable/picture` | ||
* @param context Application context. A reference may be held, but must be cleared on recycle. | ||
* @param uri URI of the image. | ||
* @return Dimensions of the image. | ||
* @throws Exception if initialisation fails. | ||
*/ | ||
@NonNull | ||
Point init(Context context, @NonNull Uri uri) throws Exception; | ||
@Throws(Exception::class) | ||
fun init(context: Context, uri: Uri): Point | ||
|
||
/** | ||
* <p> | ||
* | ||
* | ||
* Decode a region of the image with the given sample size. This method is called off the UI | ||
* thread so it can safely load the image on the current thread. It is called from | ||
* {@link android.os.AsyncTask}s running in an executor that may have multiple threads, so | ||
* implementations must be thread safe. Adding <code>synchronized</code> to the method signature | ||
* is the simplest way to achieve this, but bear in mind the {@link #recycle()} method can be | ||
* [android.os.AsyncTask]s running in an executor that may have multiple threads, so | ||
* implementations must be thread safe. Adding `synchronized` to the method signature | ||
* is the simplest way to achieve this, but bear in mind the [.recycle] method can be | ||
* called concurrently. | ||
* </p><p> | ||
* See {@link SkiaImageRegionDecoder} and {@link SkiaPooledImageRegionDecoder} for examples of | ||
* | ||
* | ||
* See [SkiaImageRegionDecoder] and [SkiaPooledImageRegionDecoder] for examples of | ||
* internal locking and synchronization. | ||
* </p> | ||
* | ||
* @param sRect Source image rectangle to decode. | ||
* @param sampleSize Sample size. | ||
* @return The decoded region. It is safe to return null if decoding fails. | ||
*/ | ||
@NonNull | ||
Bitmap decodeRegion(@NonNull Rect sRect, int sampleSize); | ||
fun decodeRegion(sRect: Rect, sampleSize: Int): Bitmap | ||
|
||
/** | ||
* Status check. Should return false before initialisation and after recycle. | ||
* @return true if the decoder is ready to be used. | ||
*/ | ||
boolean isReady(); | ||
fun isReady(): Boolean | ||
|
||
/** | ||
* This method will be called when the decoder is no longer required. It should clean up any resources still in use. | ||
*/ | ||
void recycle(); | ||
|
||
fun recycle() | ||
} |
47 changes: 0 additions & 47 deletions
47
app/customssiv/src/main/java/me/devsaki/hentoid/customssiv/decoder/SkiaDecoderHelper.java
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
app/customssiv/src/main/java/me/devsaki/hentoid/customssiv/decoder/SkiaDecoderHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package me.devsaki.hentoid.customssiv.decoder | ||
|
||
import android.content.Context | ||
import android.content.pm.PackageManager | ||
import android.content.res.Resources | ||
import android.net.Uri | ||
import android.text.TextUtils | ||
|
||
@Throws(PackageManager.NameNotFoundException::class) | ||
fun getResourceId(context: Context, uri: Uri): Int { | ||
val res: Resources | ||
val packageName = uri.authority | ||
if (context.packageName == packageName) { | ||
res = context.resources | ||
} else { | ||
val pm = context.packageManager | ||
res = pm.getResourcesForApplication(packageName!!) | ||
} | ||
|
||
var result = 0 | ||
val segments = uri.pathSegments | ||
val size = segments.size | ||
if (size == 2 && segments[0] == "drawable") { | ||
val resName = segments[1] | ||
result = res.getIdentifier(resName, "drawable", packageName) | ||
} else if (size == 1 && TextUtils.isDigitsOnly(segments[0])) { | ||
try { | ||
result = segments[0].toInt() | ||
} catch (ignored: NumberFormatException) { | ||
// Ignored exception | ||
} | ||
} | ||
|
||
return result | ||
} |
Oops, something went wrong.