|
6 | 6 |
|
7 | 7 | from materialyoucolor.hct import Hct |
8 | 8 | from materialyoucolor.palettes.tonal_palette import TonalPalette |
9 | | -from materialyoucolor.scheme.dynamic_scheme import DynamicScheme, DynamicSchemeOptions |
| 9 | +from materialyoucolor.dynamiccolor.dynamic_scheme import ( |
| 10 | + DynamicScheme, |
| 11 | +) |
| 12 | +from materialyoucolor.dynamiccolor.variant import Variant |
10 | 13 | from materialyoucolor.scheme.scheme_content import SchemeContent |
11 | 14 | from materialyoucolor.scheme.scheme_expressive import SchemeExpressive |
12 | 15 | from materialyoucolor.scheme.scheme_fidelity import SchemeFidelity |
|
16 | 19 | from materialyoucolor.scheme.scheme_rainbow import SchemeRainbow |
17 | 20 | from materialyoucolor.scheme.scheme_tonal_spot import SchemeTonalSpot |
18 | 21 | from materialyoucolor.scheme.scheme_vibrant import SchemeVibrant |
19 | | -from materialyoucolor.scheme.variant import Variant |
20 | 22 | from materialyoucolor.score.score import Score |
21 | 23 | from materialyoucolor.utils.color_utils import argb_from_rgba_01, srgb_to_argb |
22 | 24 | from materialyoucolor.utils.math_utils import sanitize_degrees_double |
23 | 25 |
|
24 | 26 | try: |
25 | | - from materialyoucolor.quantize import QuantizeCelebi |
| 27 | + from materialyoucolor.quantize import ImageQuantizeCelebi |
26 | 28 | except: |
27 | | - QuantizeCelebi = None |
| 29 | + ImageQuantizeCelebi = None |
28 | 30 |
|
29 | 31 | autoclass = None |
30 | 32 | _is_android = "ANDROID_ARGUMENT" in os.environ |
|
38 | 40 | context = mActivity.getApplicationContext() |
39 | 41 | WallpaperManager = autoclass("android.app.WallpaperManager").getInstance(mActivity) |
40 | 42 |
|
41 | | -try: |
42 | | - from PIL import Image |
43 | | -except Exception: |
44 | | - Image = None |
45 | | - |
46 | 43 | SCHEMES = { |
47 | 44 | "TONAL_SPOT": SchemeTonalSpot, |
48 | 45 | "SPRITZ": SchemeNeutral, |
@@ -171,26 +168,17 @@ def get_system_color(color_name): |
171 | 168 | color_names[color_name] = TonalPalette.from_hue_and_chroma(hct.hue, hct.chroma) |
172 | 169 |
|
173 | 170 | return DynamicScheme( |
174 | | - DynamicSchemeOptions( |
175 | | - reverse_color_from_primary( |
176 | | - get_system_color("primary_palette"), |
177 | | - selected_scheme, |
178 | | - ), |
179 | | - getattr(Variant, selected_scheme), |
180 | | - contrast, |
181 | | - dark_mode, |
182 | | - **color_names, |
183 | | - ) |
| 171 | + reverse_color_from_primary( |
| 172 | + get_system_color("primary_palette"), |
| 173 | + selected_scheme, |
| 174 | + ), |
| 175 | + getattr(Variant, selected_scheme), |
| 176 | + contrast, |
| 177 | + dark_mode, |
| 178 | + **color_names, |
184 | 179 | ) |
185 | 180 |
|
186 | 181 |
|
187 | | -def open_wallpaper_file(file_path) -> Image: |
188 | | - try: |
189 | | - return Image.open(file_path) |
190 | | - except Exception: |
191 | | - return None |
192 | | - |
193 | | - |
194 | 182 | def get_dynamic_scheme( |
195 | 183 | # Scheme options |
196 | 184 | dark_mode=True, |
@@ -277,33 +265,16 @@ def logger(message): |
277 | 265 | not selected_scheme |
278 | 266 | and not selected_color |
279 | 267 | and fallback_wallpaper_path |
280 | | - and (image := open_wallpaper_file(fallback_wallpaper_path)) |
281 | | - and QuantizeCelebi is not None |
| 268 | + and ImageQuantizeCelebi is not None |
282 | 269 | ): |
283 | 270 | timer_start = default_timer() |
284 | | - pixel_len = image.width * image.height |
285 | | - try: |
286 | | - image_data = image.get_flattened_data() |
287 | | - except: |
288 | | - image_data = image.getdata() |
289 | | - # TODO: Think about getting data from bitmap |
290 | | - pixel_array = [ |
291 | | - image_data[_] |
292 | | - for _ in range( |
293 | | - 0, pixel_len, dynamic_color_quality if not _is_android else 1 |
294 | | - ) |
295 | | - ] |
296 | | - logger( |
297 | | - f"Created an array of pixels from a " |
298 | | - f"system wallpaper file - {default_timer() - timer_start} sec." |
299 | | - ) |
300 | | - timer_start = default_timer() |
301 | | - colors = QuantizeCelebi(pixel_array, 128) |
| 271 | + colors = ImageQuantizeCelebi(fallback_wallpaper_path, dynamic_color_quality) |
302 | 272 | selected_color = Score.score(colors)[0] |
303 | 273 | WALLPAPER_CACHE[fallback_wallpaper_path] = [ |
304 | 274 | selected_color, |
305 | 275 | os.path.getsize(fallback_wallpaper_path), |
306 | 276 | ] |
| 277 | + |
307 | 278 | logger(f"Got dominant colors - {default_timer() - timer_start} sec.") |
308 | 279 |
|
309 | 280 | return ( |
|
0 commit comments