Skip to content

Commit

Permalink
Use local divStar:ico4a so I can remove legacy appcompat dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
TuxPaper committed Aug 22, 2024
1 parent ab1072d commit a669122
Show file tree
Hide file tree
Showing 25 changed files with 2,700 additions and 1 deletion.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ dependencies {

// https://github.com/divStar/ico4a
// May have to switch to https://mvnrepository.com/artifact/org.jclarion/image4j
implementation 'divstar:ico4a:v1.0'
implementation project(':ico4a')

// https://github.com/square/okhttp
// Note: 3.13 requires API 21+
Expand Down
1 change: 1 addition & 0 deletions ico4a/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
674 changes: 674 additions & 0 deletions ico4a/LICENSE

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions ico4a/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# ico4a
This is a library to decode ICO files into a list of Bitmap-objects - based on [image4j project](https://github.com/imcdonagh/image4j "image4j") (I took the liberty to use a similar structure, classes and methods, so credits go to the authors of image4j as well!).
There is a demo android application included, which shows off the library's functionality. This app is not bullet-proofed so take everything with caution.

## Usage
### Add dependency to your project and module
The easiest way to include ico4a in your project, is to include the jcenter repository in your **project's _build.gradle_** and the following line in your **module's _build.gradle_**'s dependencies-section:
```Gradle
compile 'divstar:ico4a:v1.0'
```
Alternatively you may download the AAR from [ico4a's gitHub releases site](https://github.com/divStar/ico4a/releases), create a new module (chose "import AAR" in the following dialog) and add the dependency to your app's project manually.

### Use the ICODecoder.read(InputStream) method
After having done so, use the following line anywhere to decode an ICO-InputStream into a List of Bitmap-objects:
```Java
List<Bitmap> images = ICODecoder.read(SOME_INPUTSTREAM);
```

I suggest creating an AsyncTask to download and read the file, because while reading the file is a rather quick task, it still might result in UI thread blocking.

See the sample app included in the gitHub repository to get an idea of how to use it.

![Screenshot showing the sample application and the default icons](http://abload.de/img/screenshot_20160311-0o3oyq.png)

## Limitations
ico4a cannot write ICO files, because I did not need it myself. Some methods for writing an ICO file are already present, others are not. In particular I have avoided coding BMPEncoder and ICOEncoder, which you will find in the [image4j project](https://github.com/imcdonagh/image4j "image4j library"). Thus you will have to implement them yourself if you need them.
You can however save each of the resulting Bitmap-objects easily using Android's built-in mechanisms. Here is an example:
```Java
File file = new File(dir, "output.png");
FileOutputStream fOut = new FileOutputStream(file);

bmp.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
```

## Stability
ico4a has been tested with various single- and multi-image ICO files. It has been tested to support 1-, 4-, 8-, 24- and 32-bit uncompressed images with and without alpha transparency. In addition 24- and 32-bit PNG-compressed images with and without alpha transparency have been tested. All of them loaded without any problems.

## Final word
Please report any problems if you encounter them and I will see if I can help solve them.
29 changes: 29 additions & 0 deletions ico4a/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apply plugin: 'com.android.library'

android {
compileSdk rootProject.ext.compileSdkVersion
namespace 'divstar.icon4a'

defaultConfig {
minSdkVersion 15
}

lintOptions {
abortOnError false
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

sourceSets.test.java.srcDirs = []
buildFeatures {
buildConfig true
}
}

dependencies {
implementation "androidx.appcompat:appcompat:$appcompatVersion"
implementation "androidx.annotation:annotation:${annotationVersion}"
}
5 changes: 5 additions & 0 deletions ico4a/release_notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
In this release everything works as supposed (at least to me): ICO files can be decoded from any InputStream and one receives a List<Bitmap>.

If you need the actual release, go into the ico4a build folder and grab the AAR-library, create a new module in Android Studio, chose "import AAR" and select the file. It will create a module in your project and you should add it as a dependency to your project.

Currently it seems the file cannot be retrieved via jcenter (I have to fiddle with it some more).
1 change: 1 addition & 0 deletions ico4a/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest></manifest>
54 changes: 54 additions & 0 deletions ico4a/src/main/java/divstar/ico4a/codec/bmp/BMPConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package divstar.ico4a.codec.bmp;

/**
* Provides constants used with BMP format.
*
* @author Ian McDonagh
*/
public class BMPConstants {

/**
* The signature for the BMP format header "BM".
*/
public static final String FILE_HEADER = "BM";
/**
* Specifies no compression.
*
* @see InfoHeader#iCompression InfoHeader
*/
public static final int BI_RGB = 0; // no compression
/**
* Specifies 8-bit RLE compression.
*
* @see InfoHeader#iCompression InfoHeader
*/
public static final int BI_RLE8 = 1; // 8bit RLE compression
/**
* Specifies 4-bit RLE compression.
*
* @see InfoHeader#iCompression InfoHeader
*/
public static final int BI_RLE4 = 2; // 4bit RLE compression
/**
* Specifies 16-bit or 32-bit "bit field" compression.
*
* @see InfoHeader#iCompression InfoHeader
*/
public static final int BI_BITFIELDS = 3; // 16bit or 32bit "bit field"
/**
* Specifies JPEG compression.
*
* @see InfoHeader#iCompression InfoHeader
*/
public static final int BI_JPEG = 4; // _JPEG compression
// compression.
/**
* Specifies PNG compression.
*
* @see InfoHeader#iCompression InfoHeader
*/
public static final int BI_PNG = 5; // PNG compression

private BMPConstants() {
}
}
Loading

0 comments on commit a669122

Please sign in to comment.