Author Topic: Nokia770/N800/N810 Orbiter and color of icons on the floorplan  (Read 33830 times)

nite_man

  • NEEDS to work for LinuxMCE
  • ***
  • Posts: 1019
  • Want to work with LinuxMCE
    • View Profile
    • Smart Home Blog
Hi,

I need a help with modification of Orbiter for Nokia Internet Tablets. Basically, it works fine. But when I built the Orbiter from the latest 0710 sources I found the problem with icons on floorplan. Let me first a clarify the Orbiter's logic (as I understand it). All icons on the floor plan have color pink (255, 102, 255). When the screen with floor plan is opened the Orbiter starts checking all pixels from the screen area to compare their colors with pink. If such pixel is found its color is replaced by proper color (red, yellow, black etc). There is a hack (which works fine with current version of the Orbiter) to fill icons by proper color. I just increase the maximum difference between RGB parts of pink and retrieved pixel to 10 (originally it's 3):
Code: [Select]
if ( abs(Source[0]-red)<max_diff && abs(Source[1]-green)<max_diff && abs(Source[2]-blue)<max_diff )
The problem with Nokia is that. It uses 16bit surface but on-screen Orbiter - 32bit. I solved a problem with comparison source color (pink, 32bit) with retrieved pixel color (16bit) by using  SDL_GetRGB function:
Code: [Select]
SDL_GetRGB((Uint32)Pixel, m_pScreenImage->format, &red, &green, &blue);But now I have to convert replacement color from 32bit to 16. I don't have a lot of SDL of C++ knowledge. So, any help will be very appreciated!

You can find the code in the Orbiter/SDL/OrbiterRenderer_SDL.cpp, method OrbiterRenderer_SDL::ReplaceColorInRectangle. Here is a my version of that method:
Code: [Select]
void OrbiterRenderer_SDL::ReplaceColorInRectangle(int x, int y, int width, int height, PlutoColor ColorToReplace, PlutoColor ReplacementCol
or, DesignObj_Orbiter *pObj/* = NULL*/)
{
    SDL_PixelFormat * PF = m_pScreenImage->format;
    Uint32 PlutoPixelDest, PlutoPixelSrc, Pixel;
        Uint8 red, green, blue;

#ifdef DEBUG
    LoggerWrapper::GetInstance()->Write(LV_STATUS, "ReplaceColor: ColorToReplace --> %u %u %u : ReplacementColor --> %u %u %u",
        ColorToReplace.R(), ColorToReplace.G(), ColorToReplace.B(),
        ReplacementColor.R(), ReplacementColor.G(), ReplacementColor.B());
#endif

    //PlutoPixelSrc = (ColorToReplace.R() << PF->Rshift) | (ColorToReplace.G() << PF->Gshift) | (ColorToReplace.B() << PF->Bshift); // | (C
olorToReplace.A() << PF->Ashift);
    PlutoPixelSrc = (ColorToReplace.R() << rshift) | (ColorToReplace.G() << gshift) | (ColorToReplace.B() << bshift); // | (ColorToReplace.
A() << PF->Ashift);

    unsigned char *Source = (unsigned char *) &PlutoPixelSrc;
    //PlutoPixelDest = ReplacementColor.R() << PF->Rshift | ReplacementColor.G() << PF->Gshift | ReplacementColor.B() << PF->Bshift;//  TOD
O -- this should work | ReplacementColor.A() << PF->Ashift;

// By some reason, SDL pixel format doesn't take into account byte order (for Nokia it's - little endian). As result pixel color is wrong after
// shift. I use values from the SDL_Helper/SDL_Defs.h
    PlutoPixelDest = (ReplacementColor.R() << rshift) | (ReplacementColor.G() << gshift) | (ReplacementColor.B() << bshift);//  TODO -- thi
s should work | ReplacementColor.A() << PF->Ashift;

    for (int j = 0; j < height; j++)
    {
        for (int i = 0; i < width; i++)
        {
            // we may need locking on the surface
            Pixel = SDLGraphic::getpixel(m_pScreenImage, i + x, j + y);
            unsigned char *pPixel = (unsigned char *) &Pixel;
#ifndef MAEMO_NOKIA770
            const int max_diff = 3;
            if ( abs(Source[0]-pPixel[0])<max_diff && abs(Source[1]-pPixel[1])<max_diff && abs(Source[2]-pPixel[2])<max_diff && abs(Source[
3]-pPixel[3])<max_diff )
            {
                SDLGraphic::putpixel(m_pScreenImage,i + x, j + y, PlutoPixelDest);
            }
#else
                const int max_diff = 5;

            //SDLGraphic::get_RGB(m_pScreenImage, Pixel);

                        SDL_GetRGB((Uint32)Pixel, m_pScreenImage->format, &red, &green, &blue);

            LoggerWrapper::GetInstance()->Write(LV_STATUS, "Source=%u %u %u - Pixel=%u %u %u \n", Source[0], Source[1], Source[2], red, gre
en, blue);
                //if ( abs(Source[0]-pPixel[0])<max_diff && abs(Source[1]-pPixel[1])<max_diff && abs(Source[2]-pPixel[2])<max_diff )
                if ( abs(Source[0]-red)<max_diff && abs(Source[1]-green)<max_diff && abs(Source[2]-blue)<max_diff )
                {
                        SDLGraphic::putpixel(m_pScreenImage,i + x, j + y, PlutoPixelDest);
                LoggerWrapper::GetInstance()->Write(LV_STATUS, "Replace pixel: %u %u %u - 0x%x\n!",
                                                        Source[0], Source[1], Source[2], PlutoPixelDest);
                }
            else
            {
                LoggerWrapper::GetInstance()->Write(LV_STATUS, "Do not do anything!");
            }
#endif
        }
    }


    PlutoRectangle rect(x, y, width, height);
}

All pixel operation are implemented in the Orbiter/SDL/SDLGraphic.cpp

« Last Edit: August 30, 2008, 07:52:52 pm by nite_man »
Michael Stepanov,
My setup: http://wiki.linuxmce.org/index.php/User:Nite_man#New_setup
Russian LinuxMCE community: http://linuxmce.ru

totallymaxed

  • LinuxMCE God
  • ****
  • Posts: 4660
  • Smart Home Consulting
    • View Profile
    • Dianemo - at home with technology
Re: Nokia770/N800/N810 Orbiter and color of icons on the floorplan
« Reply #1 on: August 30, 2008, 08:56:46 pm »
Hi,

I need a help with modification of Orbiter for Nokia Internet Tablets. Basically, it works fine. But when I built the Orbiter from the latest 0710 sources I found the problem with icons on floorplan. Let me first a clarify the Orbiter's logic (as I understand it). All icons on the floor plan have color pink (255, 102, 255). When the screen with floor plan is opened the Orbiter starts checking all pixels from the screen area to compare their colors with pink. If such pixel is found its color is replaced by proper color (red, yellow, black etc). There is a hack (which works fine with current version of the Orbiter) to fill icons by proper color. I just increase the maximum difference between RGB parts of pink and retrieved pixel to 10 (originally it's 3):
Code: [Select]
if ( abs(Source[0]-red)<max_diff && abs(Source[1]-green)<max_diff && abs(Source[2]-blue)<max_diff )
The problem with Nokia is that. It uses 16bit surface but on-screen Orbiter - 32bit. I solved a problem with comparison source color (pink, 32bit) with retrieved pixel color (16bit) by using  SDL_GetRGB function:
Code: [Select]
SDL_GetRGB((Uint32)Pixel, m_pScreenImage->format, &red, &green, &blue);But now I have to convert replacement color from 32bit to 16. I don't have a lot of SDL of C++ knowledge. So, any help will be very appreciated!

You can find the code in the Orbiter/SDL/OrbiterRenderer_SDL.cpp, method OrbiterRenderer_SDL::ReplaceColorInRectangle. Here is a my version of that method:
Code: [Select]
void OrbiterRenderer_SDL::ReplaceColorInRectangle(int x, int y, int width, int height, PlutoColor ColorToReplace, PlutoColor ReplacementCol
or, DesignObj_Orbiter *pObj/* = NULL*/)
{
    SDL_PixelFormat * PF = m_pScreenImage->format;
    Uint32 PlutoPixelDest, PlutoPixelSrc, Pixel;
        Uint8 red, green, blue;

#ifdef DEBUG
    LoggerWrapper::GetInstance()->Write(LV_STATUS, "ReplaceColor: ColorToReplace --> %u %u %u : ReplacementColor --> %u %u %u",
        ColorToReplace.R(), ColorToReplace.G(), ColorToReplace.B(),
        ReplacementColor.R(), ReplacementColor.G(), ReplacementColor.B());
#endif

    //PlutoPixelSrc = (ColorToReplace.R() << PF->Rshift) | (ColorToReplace.G() << PF->Gshift) | (ColorToReplace.B() << PF->Bshift); // | (C
olorToReplace.A() << PF->Ashift);
    PlutoPixelSrc = (ColorToReplace.R() << rshift) | (ColorToReplace.G() << gshift) | (ColorToReplace.B() << bshift); // | (ColorToReplace.
A() << PF->Ashift);

    unsigned char *Source = (unsigned char *) &PlutoPixelSrc;
    //PlutoPixelDest = ReplacementColor.R() << PF->Rshift | ReplacementColor.G() << PF->Gshift | ReplacementColor.B() << PF->Bshift;//  TOD
O -- this should work | ReplacementColor.A() << PF->Ashift;

// By some reason, SDL pixel format doesn't take into account byte order (for Nokia it's - little endian). As result pixel color is wrong after
// shift. I use values from the SDL_Helper/SDL_Defs.h
    PlutoPixelDest = (ReplacementColor.R() << rshift) | (ReplacementColor.G() << gshift) | (ReplacementColor.B() << bshift);//  TODO -- thi
s should work | ReplacementColor.A() << PF->Ashift;

    for (int j = 0; j < height; j++)
    {
        for (int i = 0; i < width; i++)
        {
            // we may need locking on the surface
            Pixel = SDLGraphic::getpixel(m_pScreenImage, i + x, j + y);
            unsigned char *pPixel = (unsigned char *) &Pixel;
#ifndef MAEMO_NOKIA770
            const int max_diff = 3;
            if ( abs(Source[0]-pPixel[0])<max_diff && abs(Source[1]-pPixel[1])<max_diff && abs(Source[2]-pPixel[2])<max_diff && abs(Source[
3]-pPixel[3])<max_diff )
            {
                SDLGraphic::putpixel(m_pScreenImage,i + x, j + y, PlutoPixelDest);
            }
#else
                const int max_diff = 5;

            //SDLGraphic::get_RGB(m_pScreenImage, Pixel);

                        SDL_GetRGB((Uint32)Pixel, m_pScreenImage->format, &red, &green, &blue);

            LoggerWrapper::GetInstance()->Write(LV_STATUS, "Source=%u %u %u - Pixel=%u %u %u \n", Source[0], Source[1], Source[2], red, gre
en, blue);
                //if ( abs(Source[0]-pPixel[0])<max_diff && abs(Source[1]-pPixel[1])<max_diff && abs(Source[2]-pPixel[2])<max_diff )
                if ( abs(Source[0]-red)<max_diff && abs(Source[1]-green)<max_diff && abs(Source[2]-blue)<max_diff )
                {
                        SDLGraphic::putpixel(m_pScreenImage,i + x, j + y, PlutoPixelDest);
                LoggerWrapper::GetInstance()->Write(LV_STATUS, "Replace pixel: %u %u %u - 0x%x\n!",
                                                        Source[0], Source[1], Source[2], PlutoPixelDest);
                }
            else
            {
                LoggerWrapper::GetInstance()->Write(LV_STATUS, "Do not do anything!");
            }
#endif
        }
    }


    PlutoRectangle rect(x, y, width, height);
}

All pixel operation are implemented in the Orbiter/SDL/SDLGraphic.cpp



Michael,

I've asked Radu if he has any ideas on this.

Andrew
Andy Herron,
CHT Ltd

For Dianemo/LinuxMCE consulting advice;
@herron on Twitter, totallymaxed+inquiries@gmail.com via email or PM me here.

Get Dianemo-Rpi2 ARM Licenses http://forum.linuxmce.org/index.php?topic=14026.0

Get RaspSqueeze-CEC or Raspbmc-CEC for Dianemo/LinuxMCE: http://wp.me/P4KgIc-5P

Facebook: https://www.facebook.com/pages/Dianemo-Home-Automation/226019387454465

http://www.dianemo.co.uk

nite_man

  • NEEDS to work for LinuxMCE
  • ***
  • Posts: 1019
  • Want to work with LinuxMCE
    • View Profile
    • Smart Home Blog
Re: Nokia770/N800/N810 Orbiter and color of icons on the floorplan
« Reply #2 on: August 31, 2008, 11:10:07 am »
Thanks, Andrew. I found one example how to create a 16bit pixel using RGB:

Code: [Select]
Uint16 value = ((red >> fmt->Rloss) << fmt->Rshift) +
        ((green >> fmt->Gloss) << fmt->Gshift) +
        ((blue >> fmt->Bloss) << fmt->Bshift);

where fmt is SDL pixel format. But as I already mentioned, it seems that pixel format doesn't take into account byte order. I found RGB shifts for little endian in the SDL_Helper/SDL_Defs.h. But I have no idea where can get appropriate loss values.
Michael Stepanov,
My setup: http://wiki.linuxmce.org/index.php/User:Nite_man#New_setup
Russian LinuxMCE community: http://linuxmce.ru

hari

  • Administrator
  • LinuxMCE God
  • *****
  • Posts: 2428
    • View Profile
    • ago control
Re: Nokia770/N800/N810 Orbiter and color of icons on the floorplan
« Reply #3 on: August 31, 2008, 12:52:00 pm »
i'd assume you want no loss.

just shift the byte to the left 8 times. If you have endian issues swap them.

best regards,
Hari
rock your home - http://www.agocontrol.com home automation

nite_man

  • NEEDS to work for LinuxMCE
  • ***
  • Posts: 1019
  • Want to work with LinuxMCE
    • View Profile
    • Smart Home Blog
Re: Nokia770/N800/N810 Orbiter and color of icons on the floorplan
« Reply #4 on: August 31, 2008, 04:29:31 pm »
Thanks, Hari. Will try it.
Michael Stepanov,
My setup: http://wiki.linuxmce.org/index.php/User:Nite_man#New_setup
Russian LinuxMCE community: http://linuxmce.ru

hari

  • Administrator
  • LinuxMCE God
  • *****
  • Posts: 2428
    • View Profile
    • ago control
Re: Nokia770/N800/N810 Orbiter and color of icons on the floorplan
« Reply #5 on: August 31, 2008, 04:53:40 pm »
oh i think i told BS. From your posted code I take you want to store all three values in 16bit?
rock your home - http://www.agocontrol.com home automation

hari

  • Administrator
  • LinuxMCE God
  • *****
  • Posts: 2428
    • View Profile
    • ago control
Re: Nokia770/N800/N810 Orbiter and color of icons on the floorplan
« Reply #6 on: August 31, 2008, 04:58:27 pm »
oh i think i told BS. From your posted code I take you want to store all three values in 16bit?

so if yes, you have to divide the 16 bits on three colors, so i'd assume it is sth like 5+6+5 (giving green an additional bit). So you have to "loose" 3 bits for R & B and 2 for G. EDIT: (starting with 8 bits per color)

but this is just guessing..

best regards,
Hari
« Last Edit: August 31, 2008, 05:00:05 pm by hari »
rock your home - http://www.agocontrol.com home automation

nite_man

  • NEEDS to work for LinuxMCE
  • ***
  • Posts: 1019
  • Want to work with LinuxMCE
    • View Profile
    • Smart Home Blog
Re: Nokia770/N800/N810 Orbiter and color of icons on the floorplan
« Reply #7 on: September 02, 2008, 08:38:17 am »
Thanks to all for your suggestions. Finally I solved the problem with color of icons. Now all icons are displayed correctly including MD (it was a long time issue). The only one issue which still exists is olive color of pressed button (some lighting scenario, for example). It happens because all Oriter's colors are 32bit but Nokia supports 16bit. So, the color light blue - #7387BC (115, 135, 188 in RGB) becomes to olive - #738700 because it looses last two bytes.

I have no idea where those buttons are rendered. Does somebody can point me?

TIA
Michael Stepanov,
My setup: http://wiki.linuxmce.org/index.php/User:Nite_man#New_setup
Russian LinuxMCE community: http://linuxmce.ru

totallymaxed

  • LinuxMCE God
  • ****
  • Posts: 4660
  • Smart Home Consulting
    • View Profile
    • Dianemo - at home with technology
Re: Nokia770/N800/N810 Orbiter and color of icons on the floorplan
« Reply #8 on: September 02, 2008, 10:34:42 am »
Thanks to all for your suggestions. Finally I solved the problem with color of icons. Now all icons are displayed correctly including MD (it was a long time issue). The only one issue which still exists is olive color of pressed button (some lighting scenario, for example). It happens because all Oriter's colors are 32bit but Nokia supports 16bit. So, the color light blue - #7387BC (115, 135, 188 in RGB) becomes to olive - #738700 because it looses last two bytes.

I have no idea where those buttons are rendered. Does somebody can point me?

TIA

Hey thats great Michael... nice work ;-)

I'll see if Radu has any info on the button colour issue later.

Andrew
Andy Herron,
CHT Ltd

For Dianemo/LinuxMCE consulting advice;
@herron on Twitter, totallymaxed+inquiries@gmail.com via email or PM me here.

Get Dianemo-Rpi2 ARM Licenses http://forum.linuxmce.org/index.php?topic=14026.0

Get RaspSqueeze-CEC or Raspbmc-CEC for Dianemo/LinuxMCE: http://wp.me/P4KgIc-5P

Facebook: https://www.facebook.com/pages/Dianemo-Home-Automation/226019387454465

http://www.dianemo.co.uk

bulek

  • Administrator
  • wants to work for LinuxMCE
  • *****
  • Posts: 909
  • Living with LMCE
    • View Profile
Re: Nokia770/N800/N810 Orbiter and color of icons on the floorplan
« Reply #9 on: September 02, 2008, 10:55:26 am »
Thanks to all for your suggestions. Finally I solved the problem with color of icons. Now all icons are displayed correctly including MD (it was a long time issue). The only one issue which still exists is olive color of pressed button (some lighting scenario, for example). It happens because all Oriter's colors are 32bit but Nokia supports 16bit. So, the color light blue - #7387BC (115, 135, 188 in RGB) becomes to olive - #738700 because it looses last two bytes.

I have no idea where those buttons are rendered. Does somebody can point me?

TIA
Cool effort. Thanks very much for this one  ;D... How can we get the update ?

Regards,

Bulek.
Thanks in advance,

regards,

Bulek.

nite_man

  • NEEDS to work for LinuxMCE
  • ***
  • Posts: 1019
  • Want to work with LinuxMCE
    • View Profile
    • Smart Home Blog
Re: Nokia770/N800/N810 Orbiter and color of icons on the floorplan
« Reply #10 on: September 02, 2008, 11:11:21 am »
The package is available  here. I'm gonna to test it tonight and if it'll be ok I'll upload it to the http://diapub.com/~michael/ to provide one-click-installation and upgrade.
« Last Edit: September 02, 2008, 11:01:22 pm by nite_man »
Michael Stepanov,
My setup: http://wiki.linuxmce.org/index.php/User:Nite_man#New_setup
Russian LinuxMCE community: http://linuxmce.ru

totallymaxed

  • LinuxMCE God
  • ****
  • Posts: 4660
  • Smart Home Consulting
    • View Profile
    • Dianemo - at home with technology
Re: Nokia770/N800/N810 Orbiter and color of icons on the floorplan
« Reply #11 on: September 02, 2008, 11:53:19 am »
The package is available here - https://garage.maemo.org/frs/download.php/4520/lmceorbiter-os2008-0710-04_armel.deb. I'm gonna to test it tonight and if it'll be ok I'll upload it to the http://diapub.com/~michael/ to provide one-click-installation and upgrade.

Michael,

Just installed it here on Diablo and it seems to be working fine. We'll use it for 'real' today and post any issues here later.

all the best

Andrew
Andy Herron,
CHT Ltd

For Dianemo/LinuxMCE consulting advice;
@herron on Twitter, totallymaxed+inquiries@gmail.com via email or PM me here.

Get Dianemo-Rpi2 ARM Licenses http://forum.linuxmce.org/index.php?topic=14026.0

Get RaspSqueeze-CEC or Raspbmc-CEC for Dianemo/LinuxMCE: http://wp.me/P4KgIc-5P

Facebook: https://www.facebook.com/pages/Dianemo-Home-Automation/226019387454465

http://www.dianemo.co.uk

nite_man

  • NEEDS to work for LinuxMCE
  • ***
  • Posts: 1019
  • Want to work with LinuxMCE
    • View Profile
    • Smart Home Blog
Re: Nokia770/N800/N810 Orbiter and color of icons on the floorplan
« Reply #12 on: September 02, 2008, 12:10:28 pm »
Quote
Just installed it here on Diablo and it seems to be working fine. We'll use it for 'real' today and post any issues here later.

Great! I attached patches for the Nokia's Orbiter - http://www.mediafire.com/?14nicedkntt. They are made from 0710 branch. Have a look on it and if they're ok let's put them into LMCE repository.



Michael Stepanov,
My setup: http://wiki.linuxmce.org/index.php/User:Nite_man#New_setup
Russian LinuxMCE community: http://linuxmce.ru

totallymaxed

  • LinuxMCE God
  • ****
  • Posts: 4660
  • Smart Home Consulting
    • View Profile
    • Dianemo - at home with technology
Re: Nokia770/N800/N810 Orbiter and color of icons on the floorplan
« Reply #13 on: September 02, 2008, 12:25:27 pm »
Quote
Just installed it here on Diablo and it seems to be working fine. We'll use it for 'real' today and post any issues here later.

Great! I attached patches for the Nokia's Orbiter - http://www.mediafire.com/?14nicedkntt. They are made from 0710 branch. Have a look on it and if they're ok let's put them into LMCE repository.

Your new rev is being used for a demo now... so that will give it a good 'workout' ;-)

So the only remaining issues are the button highlights and making it possible to switch to another N800 app and then back to the Orbiter without the Orbiter crashing. By the way is the screen-saver disabled in this version?

Great work!

All the best

Andrew
Andy Herron,
CHT Ltd

For Dianemo/LinuxMCE consulting advice;
@herron on Twitter, totallymaxed+inquiries@gmail.com via email or PM me here.

Get Dianemo-Rpi2 ARM Licenses http://forum.linuxmce.org/index.php?topic=14026.0

Get RaspSqueeze-CEC or Raspbmc-CEC for Dianemo/LinuxMCE: http://wp.me/P4KgIc-5P

Facebook: https://www.facebook.com/pages/Dianemo-Home-Automation/226019387454465

http://www.dianemo.co.uk

nite_man

  • NEEDS to work for LinuxMCE
  • ***
  • Posts: 1019
  • Want to work with LinuxMCE
    • View Profile
    • Smart Home Blog
Re: Nokia770/N800/N810 Orbiter and color of icons on the floorplan
« Reply #14 on: September 02, 2008, 01:44:44 pm »
Quote
By the way is the screen-saver disabled in this version?
Yes, there is a disabled screen-saver. I applied Oliver's path before build the Orbiter.
Quote
So the only remaining issues are the button highlights and making it possible to switch to another N800 app and then back to the Orbiter without the Orbiter crashing.
Yes, I'm working on it.

Another thing which can be done with the floorplan icons is that. To use color with different intensity according to value came with ON. For example, if some dimmer has is set ON with 50% its color will be rgb(255,255,96) and not rgb(255,255,0). In that case it'll be more visible what intensity has each lighting object.

For each object on the floorplan is returned a string with its properties. For example, dimmer information looks like that:
Code: [Select]
-256|On|ON/10|2275|where 10 is its intensity.

Michael Stepanov,
My setup: http://wiki.linuxmce.org/index.php/User:Nite_man#New_setup
Russian LinuxMCE community: http://linuxmce.ru