From e0c92e08c047a8ff075da32fdf3438b3479e251c Mon Sep 17 00:00:00 2001 From: kirbylife Date: Wed, 19 May 2021 14:19:08 -0500 Subject: [PATCH] Remove Numpy dependencie (aarch64 ready) --- Makefile | 2 +- dependencies.txt | 3 +-- src/main.py | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index a0ad4fc..ebbb7a3 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ sdkpath:=$(HOME)/SailfishOS sourcePath:=$(shell pwd) dependencies=$(shell for file in `cat dependencies.txt`;do echo "-d "$${file};done;) arch:=armv7hl -version:=0.4.0 +version:=0.5.0 iteration:=1 rpmname:=$(Appname)-$(version)-$(iteration).$(arch).rpm ssh_user:=defaultuser diff --git a/dependencies.txt b/dependencies.txt index 3170fd0..b450b53 100644 --- a/dependencies.txt +++ b/dependencies.txt @@ -1,5 +1,4 @@ libsailfishapp-launcher pyotherside-qml-plugin-python3-qt5 python3-base -python3-numpy -python3-pillow +python3-imaging diff --git a/src/main.py b/src/main.py index c33a713..1217b1a 100644 --- a/src/main.py +++ b/src/main.py @@ -2,7 +2,7 @@ import pyotherside from PIL import Image, ImageOps, ImageDraw, ImageChops from io import BytesIO from glob import glob -import numpy as np +from collections import Counter import base64 import os import shutil @@ -14,16 +14,16 @@ def base64_to_img(base64_bytes: bytes) -> Image: img = img.convert("RGBA") return img -def img_to_array(img: Image) -> np.array: - img_array = np.array(img) - return img_array - def avg_colors(img): - img_array = img_to_array(img) - colors, count = np.unique(img_array.reshape(-1,img_array.shape[-1]), axis=0, return_counts=True) - - return tuple(colors[count.argmax()]) - + counter = Counter() + width, height = img.size + for x in range(width): + for y in range(height): + pixel = img.getpixel((x, y)) + if pixel[-1] > 0: # Doesn't count the transparent pixels + counter[pixel] += 1 + print(counter.most_common(4)) + return counter.most_common(1)[0][0] def add_background(img: Image, bg_tuple: tuple) -> Image: bg = Image.new("RGBA", img.size, bg_tuple)