-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit a6e8e56
Showing
29 changed files
with
319 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Output directory | ||
out |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
Empty file.
Binary file not shown.
Empty file.
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,4 @@ | ||
## Img2Ascii | ||
|
||
An App Inventor 2 extension created using Rush. | ||
#ImageToAscii |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
This directory stores your extension's dependencies. |
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,36 @@ | ||
# For a detailed info on this file and supported fields, check out the below link: | ||
# https://github.com/ShreyashSaitwal/rush-cli/wiki/Metadata-File | ||
|
||
--- | ||
name: ImgToAscii | ||
description: Developed by Jewel Shikder Jony<br><br><a href='https://fb.com/jewelshkjony/' target='_blank'>Facebook</a> | <a href='https://m.me/jewelshkjony/' target='_blank'>Messenger</a><br><a href='https://t.me/jewelshkjony/' target='_blank'>Telegram</a> | <a href='https://wa.me/8801775668913' target='_blank'>WhatsApp</a><br><br><a href='https://github.com/jewelshkjony?tab=repositories' target='_blank'>More Extensions</a> | ||
homepage: https://github.com/jewelshkjony/ImgToAscii | ||
license: https://github.com/jewelshkjony/ImgToAscii/blob/main/LICENSE | ||
|
||
version: | ||
number: 1 | ||
name: '1.0' | ||
|
||
authors: | ||
- Jewel Shikder Jony | ||
|
||
build: | ||
release: | ||
# Optimizes the extension on every release build. | ||
optimize: true | ||
|
||
# If enabled, you will be able to use Java 8 language features in your extension. | ||
desugar: | ||
enable: true | ||
desugar_deps: false | ||
|
||
assets: | ||
# Extension icon. This can be a URL or a local image in 'assets' folder. | ||
icon: icon.png | ||
# Extension assets. | ||
# other: | ||
# - my_awesome_asset.anything | ||
|
||
# Extension dependencies (JAR). | ||
# deps: | ||
# - my_awesome_library.jar |
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,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.jewel.imgtoascii"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application> | ||
</application> | ||
|
||
</manifest> |
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,123 @@ | ||
package com.jewel.imgtoascii; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.graphics.Bitmap; | ||
import android.graphics.Color; | ||
import android.os.AsyncTask; | ||
import android.text.Spannable; | ||
import android.text.SpannableStringBuilder; | ||
import android.text.style.ForegroundColorSpan; | ||
|
||
import static java.lang.Math.round; | ||
|
||
public class Img2Ascii { | ||
|
||
private String[] chars = {"@", "#", "+", "\\", ";", ":", ",", ".", "`", " "}; | ||
private Bitmap rgbImage; | ||
private Boolean color = false; | ||
private int quality = 3; | ||
private int qualityColor = 6; | ||
private Spannable response; | ||
private Listener listener; | ||
|
||
public Img2Ascii(){ | ||
|
||
} | ||
|
||
public Img2Ascii bitmap(Bitmap rgbImage){ | ||
this.rgbImage = rgbImage; | ||
return this; | ||
} | ||
|
||
public Img2Ascii quality(int quality){ | ||
this.quality = quality; | ||
return this; | ||
} | ||
|
||
public Img2Ascii color(Boolean color){ | ||
this.color = color; | ||
return this; | ||
} | ||
|
||
public void convert(Listener listener) { | ||
this.listener = listener; | ||
new InstaApi().execute(); | ||
} | ||
|
||
@SuppressLint("StaticFieldLeak") | ||
private class InstaApi extends AsyncTask<String, Integer, Void> { | ||
|
||
private InstaApi(){ | ||
|
||
} | ||
|
||
@Override | ||
protected void onPreExecute() { | ||
super.onPreExecute(); | ||
} | ||
|
||
@Override | ||
protected Void doInBackground(String... arg0) { | ||
if(color) { | ||
quality = quality + qualityColor; | ||
if (quality > 5 + qualityColor || quality < 1 + qualityColor) | ||
quality = 3 + qualityColor; | ||
}else{ | ||
if (quality > 5 || quality < 1) | ||
quality = 3; | ||
} | ||
String tx; | ||
SpannableStringBuilder span = new SpannableStringBuilder(); | ||
int width = rgbImage.getWidth(); | ||
int height = rgbImage.getHeight(); | ||
int i = 0; | ||
for (int y = 0; y < height; y = y + quality) { | ||
for (int x = 0; x < width; x = x + quality) { | ||
int pixel = rgbImage.getPixel(x, y); | ||
int red = Color.red(pixel); | ||
int green = Color.green(pixel); | ||
int blue = Color.blue(pixel); | ||
if(color) { | ||
tx = "#"; | ||
span.append(tx); | ||
span.setSpan(new ForegroundColorSpan(Color.rgb(red, green, blue)), i, i + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); | ||
}else { | ||
int brightness = red + green + blue; | ||
brightness = round(brightness / (765 / (chars.length - 1))); | ||
tx = chars[brightness]; | ||
span.append(tx); | ||
} | ||
i++; | ||
} | ||
tx = "\n"; | ||
span.append(tx); | ||
publishProgress(y, height); | ||
i++; | ||
if(isCancelled()) break; | ||
} | ||
response = span; | ||
|
||
return null; | ||
} | ||
|
||
protected void onProgressUpdate(Integer... progress) { | ||
int current = progress[0]; | ||
int total = progress[1]; | ||
int percentage = 100 * current / total; | ||
listener.onProgress(percentage); | ||
} | ||
|
||
@Override | ||
protected void onPostExecute(Void result) { | ||
super.onPostExecute(result); | ||
listener.onResponse(response); | ||
} | ||
|
||
} | ||
|
||
public interface Listener { | ||
void onProgress(int percentage); | ||
void onResponse(Spannable response); | ||
} | ||
|
||
} |
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,77 @@ | ||
package com.jewel.imgtoascii; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
|
||
import com.google.appinventor.components.annotations.SimpleEvent; | ||
import com.google.appinventor.components.annotations.SimpleFunction; | ||
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent; | ||
import com.google.appinventor.components.runtime.AndroidViewComponent; | ||
import com.google.appinventor.components.runtime.ComponentContainer; | ||
import com.google.appinventor.components.runtime.EventDispatcher; | ||
|
||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.text.Spannable; | ||
import android.widget.TextView; | ||
|
||
public class ImgToAscii extends AndroidNonvisibleComponent { | ||
|
||
public ImgToAscii(ComponentContainer container) { | ||
super(container.$form()); | ||
} | ||
|
||
@SimpleFunction(description = "Set quality as int from 1-5. Set very small text size to view the full ascii image.") | ||
public void Create(String path, int quality, boolean isColor, AndroidViewComponent textView) { | ||
TextView view = (TextView) textView.getView(); | ||
if (path.startsWith("http://") || path.startsWith("https://")) { | ||
new Thread(() -> { | ||
try { | ||
Bitmap bitmap = BitmapFactory.decodeStream(new URL(path).openStream()); | ||
form.$context().runOnUiThread(() -> { | ||
ConvertView(view, quality, isColor, bitmap); | ||
}); | ||
} catch (IOException e) { | ||
Failed(e.getMessage()); | ||
} | ||
}).start(); | ||
} else { | ||
Bitmap bitmap = BitmapFactory.decodeFile(path); | ||
ConvertView(view, quality, isColor, bitmap); | ||
} | ||
} | ||
|
||
private void ConvertView(TextView textView, int quality, boolean isColor, Bitmap bitmap) { | ||
new Img2Ascii() | ||
.bitmap(bitmap) | ||
.quality(quality) | ||
.color(isColor) | ||
.convert(new Img2Ascii.Listener() { | ||
@Override | ||
public void onProgress(int percentage) { | ||
Progress(percentage); | ||
} | ||
|
||
@Override | ||
public void onResponse(Spannable text) { | ||
textView.setText(text); | ||
Completed(); | ||
} | ||
}); | ||
} | ||
|
||
@SimpleEvent(description = "") | ||
public void Progress(int percentage) { | ||
EventDispatcher.dispatchEvent(this, "Progress", percentage); | ||
} | ||
|
||
@SimpleEvent(description = "") | ||
public void Completed() { | ||
EventDispatcher.dispatchEvent(this, "Completed"); | ||
} | ||
|
||
@SimpleEvent(description = "") | ||
public void Failed(String message) { | ||
EventDispatcher.dispatchEvent(this, "Failed", message); | ||
} | ||
} |
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,15 @@ | ||
# Add any ProGuard configurations specific to this | ||
# extension here. | ||
|
||
-keep public class com.jewel.imgtoascii.ImgToAscii { | ||
public *; | ||
} | ||
-keeppackagenames gnu.kawa**, gnu.expr** | ||
|
||
-optimizationpasses 5 | ||
-allowaccessmodification | ||
-mergeinterfacesaggressively | ||
|
||
-repackageclasses 'com/jewel/imgtoascii/repack' | ||
-flattenpackagehierarchy | ||
-dontpreverify |