Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How it is different from avanisubbiah/material-color-utilities? #3

Closed
BoolmanO opened this issue Jan 7, 2024 · 6 comments
Closed
Labels
question Further information is requested

Comments

@BoolmanO
Copy link

BoolmanO commented Jan 7, 2024

What difference between your package and this

it was literally the sames

FE:
Your palettes/core_palette.py

from materialyoucolor.hct.hct import Hct
from materialyoucolor.palettes.tonal_palette import TonalPalette


class CorePalette:
    def __init__(self, argb):
        hct = Hct.fromInt(argb)
        hue = hct.hue
        self.a1 = TonalPalette.fromHueAndChroma(hue, max(48, hct.chroma))
        self.a2 = TonalPalette.fromHueAndChroma(hue, 16)
        self.a3 = TonalPalette.fromHueAndChroma(hue + 60, 24)
        self.n1 = TonalPalette.fromHueAndChroma(hue, 6)
        self.n2 = TonalPalette.fromHueAndChroma(hue, 8)
        self.error = TonalPalette.fromHueAndChroma(25, 84)

    @staticmethod
    def of(argb):
        return CorePalette(argb)

Two years old repo palettes/core_palette.py

from ..hct.hct import *
from ..palettes.tonal_palette import *

# /**
#  * An intermediate concept between the key color for a UI theme, and a full
#  * color scheme. 5 sets of tones are generated, all except one use the same hue
#  * as the key color, and all vary in chroma.
#  */
class CorePalette:
    def __init__(self, argb):
        hct = Hct.fromInt(argb)
        hue = hct.hue
        self.a1 = TonalPalette.fromHueAndChroma(hue, max(48, hct.chroma))
        self.a2 = TonalPalette.fromHueAndChroma(hue, 16)
        self.a3 = TonalPalette.fromHueAndChroma(hue + 60, 24)
        self.n1 = TonalPalette.fromHueAndChroma(hue, 4)
        self.n2 = TonalPalette.fromHueAndChroma(hue, 8)
        self.error = TonalPalette.fromHueAndChroma(25, 84)

    # /**
    #  * @param argb ARGB representation of a color
    #  */
    @staticmethod
    def of(argb):
        return CorePalette(argb);

I dont blame you, but maybe it would have been better to fork the repository in the first place, where did you get your inspiration from?
Correct me if im wrong, please.

@T-Dynamos
Copy link
Owner

T-Dynamos commented Jan 8, 2024

Implementation of color generation. Original implementation is not near usable (at least for me). Also I am working on c++ implementation to make it more fast #2

The reason I removed comments was : material-foundation/material-color-utilities#48 (comment). I tried to follow guidelines and thought will add them later in proper format but never added.

@T-Dynamos
Copy link
Owner

T-Dynamos commented Jan 8, 2024

Image used, size 3MB

Show machine specs
OS: Archcraft x86_64 
Machine: Aspire E3-112M V1.16 
Kernel: 6.6.10-arch1-1 
CPU: Intel Celeron N2840 (2) @ 2.582GHz 
Graphics: Intel Atom Processor Z36xxx/Z37xxx Series Graphics & Display 
RAM: 1827MiB / 7831MiB 

Results with avanisubbiah/material-color-utilities

❯ du -h /home/tdynamos/Downloads/guillaume-briard-CJp8wVjGZ88-unsplash.jpg
3.0M	/home/tdynamos/Downloads/guillaume-briard-CJp8wVjGZ88-unsplash.jpg
❯ time python3 test.py
#148296

________________________________________________________
Executed in  244.86 secs    fish           external
   usr time  220.22 secs    1.15 millis  220.22 secs
   sys time    2.69 secs    0.30 millis    2.69 secs

File used test.py:

from material_color_utilities_python import *

img = Image.open('/home/tdynamos/Downloads/guillaume-briard-CJp8wVjGZ88-unsplash.jpg')
argb = sourceColorFromImage(img)

print(hexFromArgb(argb))

Results with my latest PR:

The PR I am working on is not based on anything, I am rewritting it from scratch from official typescript implementation.

❯ time python3 test.py /home/tdynamos/Downloads/guillaume-briard-CJp8wVjGZ88-unsplash.jpg 1
File open took :  14.200929311999971 secs
Color generation took :  10.495095100999833 secs

All dominant colors (128) :
...

________________________________________________________
Executed in   28.63 secs    fish           external
   usr time   20.23 secs    0.00 millis   20.23 secs
   sys time    2.02 secs    1.70 millis    2.02 secs

File used : materialyoucolor-pyhton/test_color_gen.py

Show full result

image


Results with current implementation:

Generation time: 99.37897729873657 secs
Number of Generated colors  11
Default theme :  {'primary': [208, 188, 255], 'primaryContainer': [79, 55, 139], 'onPrimary': [55, 30, 115], 'onPrimaryContainer': [234, 221, 255], 'inversePrimary': [103, 80, 164], 'secondary': [204, 194, 220], 'secondaryContainer': [74, 68, 88], 'onSecondary': [51, 45, 65], 'onSecondaryContainer': [232, 222, 248], 'tertiary': [239, 184, 200], 'tertiaryContainer': [99, 59, 72], 'onTertiary': [73, 37, 50], 'onTertiaryContainer': [255, 216, 228], 'surface': [20, 18, 24], 'surfaceDim': [20, 18, 24], 'surfaceBright': [59, 56, 62], 'surfaceContainerLowest': [15, 13, 19], 'surfaceContainerLow': [29, 27, 32], 'surfaceContainer': [33, 31, 38], 'surfaceContainerHigh': [43, 41, 48], 'surfaceContainerHighest': [54, 52, 59], 'surfaceVariant': [73, 69, 79], 'onSurface': [230, 225, 229], 'onSurfaceVariant': [202, 196, 208], 'inverseSurface': [230, 225, 229], 'inverseOnSurface': [49, 48, 51], 'background': [20, 18, 24], 'onBackground': [230, 225, 229], 'error': [242, 184, 181], 'errorContainer': [140, 29, 24], 'onError': [96, 20, 16], 'onErrorContainer': [249, 222, 220], 'outline': [147, 143, 153], 'outlineVariant': [68, 71, 70], 'shadow': [0, 0, 0], 'surfaceTint': [208, 188, 255], 'scrim': [0, 0, 0]}

File used example.py from current repo.

Also my implementation has color quality option which decides from how much color chunk to choose color from. 1 -> Full quality ie. using all pixels

@BoolmanO
Copy link
Author

BoolmanO commented Jan 8, 2024

Thank you for explanation. Maybe better to implement this in C (instead of cpp), for better integration in python?

@T-Dynamos
Copy link
Owner

T-Dynamos commented Jan 8, 2024

Thank you for explanation. Maybe better to implement this in C (instead of cpp), for better integration in python?

It's already done, I am using google's offcial cpp implemention of color selection and then just patch it to make it work using pybind11. You can try use it yourself now!

@T-Dynamos T-Dynamos changed the title difference between two packages What is different from avanisubbiah/material-color-utilities? Jan 8, 2024
@T-Dynamos T-Dynamos changed the title What is different from avanisubbiah/material-color-utilities? How it is different from avanisubbiah/material-color-utilities? Jan 8, 2024
@T-Dynamos T-Dynamos pinned this issue Jan 8, 2024
@HeaTTheatR
Copy link

Great news! Literally today I wanted to suggest implementing this in Cython/C/C++ - https://discord.com/channels/566880874789076992/942839634025656390/1194118786874355793

@HeaTTheatR
Copy link

On my mobile device, rendering a palette from the current wallpaper takes 7 seconds. It's a very long time. We definitely need a faster solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants