KSemenenko / ColorThief

Color Thief for .NET
MIT License
163 stars 28 forks source link

Color Order In GetPalette #6

Open ghost opened 7 years ago

ghost commented 7 years ago

only on Xamarin.forms nuget package: //var pal = _colorThief.GetPalette(pictureBoxSpectrum.Image, 6, 10, false).ToList(); all the colors are correct, but Red and Blue color Bytes are swapped. I was porting an app from windows forms app to Xamarin iOS, and noticed that all the colors are not the same, after some investigation turns out only instead of using RGB of your values, used them as BGR.

KSemenenko commented 7 years ago

Hi, thx for you issue! It's only for iOS?

ghost commented 7 years ago

I have tested the Windows Forms Application version and I couldn't find the same problem, my issue was only faced using Xamarin forms iOS, didn't test any other platforms, its only a matter of bytes ordering, I've confirmed the problem by testing 3 images each filled with a major single color, result is red is swapped with blue, temporarily fixed by using .R as the blue byte, . .B as the red byte. Again.. i gotta say .. great work .. and thanks for your efforts.

Sent from my iPhone

On Jun 28, 2017, at 9:27 PM, ksemenenko notifications@github.com<mailto:notifications@github.com> wrote:

Hi, thx for you issue! It's only for iOS?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/KSemenenko/ColorThief/issues/6#issuecomment-311746446, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AOHydJBc-_RZaY5H7CdOsMxI6cDeeZFDks5sIpr6gaJpZM4OIU2e.

KSemenenko commented 7 years ago

Hi @Houri93 please check it on version 1.0.0.4

ghost commented 7 years ago

hello again, just updated to the latest version via nuget, the problem still exists as it has been previously

KSemenenko commented 7 years ago

@Houri93 Thank you. I will then continue to fix this.

KSemenenko commented 7 years ago

Hello! You could give me a picture and colors that should be the result? @Houri93

ghost commented 7 years ago

@KSemenenko yes .. have a look here, also sorry for being late .. and here's the code im extracting the colors with .. all thanks to you ofcourse ..

` var pal = _colorThief.GetPalette(AlbumArtImage.Image, 10, 10, false).ToList().OrderByDescending(a => a.Population).ToList(); this.View.BackgroundColor = UIColor.FromRGBA(pal.First().Color.B, pal.First().Color.G, pal.First().Color.R, pal.First().Color.A);

        UIColor newtint = null;
        for (int i = 1; i < pal.Count; i++)
        {
            var huediff = Math.Abs(pal.First().Color.ToHsl().H - pal[i].Color.ToHsl().H);
            var lightdiff = Math.Abs(pal.First().Color.ToHsl().L - pal[i].Color.ToHsl().L);
            var satDiffer = Math.Abs(pal.First().Color.ToHsl().S - pal[i].Color.ToHsl().S);
            if (huediff * (100 / 360.0) > 5 ||
                lightdiff * 100 > 5
               || satDiffer == 0)
            {

                newtint = UIColor.FromRGBA(pal[i].Color.B, pal[i].Color.G, pal[i].Color.R, pal[i].Color.A);

                break;
            }
        }

        waveformL = new CGColor((nfloat)(pal[1].Color.B / 255.0), (nfloat)(pal[1].Color.G / 255.0), (nfloat)(pal[1].Color.R / 255.0));
        waveformR = new CGColor((nfloat)(pal[2].Color.B / 255.0), (nfloat)(pal[2].Color.G / 255.0), (nfloat)(pal[2].Color.R / 255.0));

        if (newtint != null)
        {
            this.timeLB.TextColor =
              this.titleLB1.TextColor =
              this.titleLB2.TextColor =
              this.View.TintColor =
              this.loading.Color =
                      newtint;

            if (pal.First().IsDark)
            {
                UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.LightContent, true);

            }
            else
            {
                UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.Default, true);
            }
        }`

whatsapp image 2017-08-03 at 1 57 35 pm whatsapp image 2017-08-03 at 1 57 36 pm whatsapp image 2017-08-03 at 1 57 37 pm 1 whatsapp image 2017-08-03 at 1 57 37 pm whatsapp image 2017-08-03 at 1 57 38 pm