Re: [maemo-developers] Nokia SDL color format for pixels
Thanks a lot, guys, for your help. Finally I managed to get correct RGB from the 16bit pixel using SDL_GetRGB. First I get a pixel and then retrieve RGB from it: Uint8 red, green, blue; Uint32 pixel; for(int y = 0; y 480; y++) { for(int x = 0; x 640; x++) { pixel = getpixel(surface, x, y); SDL_GetRGB((Uint32)pixel, surface-format, red, green, blue); } } But now I have another problem. There is a transformation of color: PixelSrc = (ColorToReplace.R() PF-Rshift) | (ColorToReplace.G() PF-Gshift) | (ColorToReplace.B() PF-Bshift); Where ColorToReplace is (255,102,155) But after that transformation it becomes (255, 252, 7). Could somebody tell me where is a mistake? TIA P. S. Sorry for not clever questions. I don't have a big C++ and SDL practice. -- Cheers, Michael ___ maemo-developers mailing list maemo-developers@maemo.org https://lists.maemo.org/mailman/listinfo/maemo-developers
Re: [maemo-developers] Nokia SDL color format for pixels
On Tue, Apr 15, 2008 at 3:50 PM, Frantisek Dufka [EMAIL PROTECTED] wrote: Michael Stepanov wrote: So, how in that situation I can get correct color? It is already correct. The color format is RGB565. What 'correct' means to you in this context? If you need the value in different format you need to convert it. Yes, I need to convert RGB565 to RGB888 to compare two values - actual pixel color and pink color. Could you suggest me, please, some way to do that? -- Cheers, Michael ___ maemo-developers mailing list maemo-developers@maemo.org https://lists.maemo.org/mailman/listinfo/maemo-developers
Re: [maemo-developers] Nokia SDL color format for pixels
On Thu, 28 Aug 2008, Michael Stepanov wrote: On Tue, Apr 15, 2008 at 3:50 PM, Frantisek Dufka [EMAIL PROTECTED] wrote: Michael Stepanov wrote: So, how in that situation I can get correct color? It is already correct. The color format is RGB565. What 'correct' means to you in this context? If you need the value in different format you need to convert it. Yes, I need to convert RGB565 to RGB888 to compare two values - actual pixel color and pink color. Could you suggest me, please, some way to do that? If you converts 565 to 888 you should do some and() to 888 also because three less meaning bits are missing from red and blue, and two bits from green. so I recommend to do 888-565 conversion. Following example should work. /* convert RGB888 to RGB565 */ ... #define R_RGB888_OFFSET 16 #define G_RGB888_OFFSET 8 #define R_RGB565_OFFSET 11 #define G_RGB565_OFFSET 5 ... /* get rgb888:s r,g and b */ uint8 r8 = (rgb888 0xff) R_RGB888_OFFSET; uint8 g8 = (rgb888 0xff00) G_RGB888_OFFSET; uint8 b8 = rgb888 0xff; /* creates rgb565 from r8, g8 and b8 */ uint8 r5 = (r8 (8-5)) R_RGB565_OFFSET; uint8 g6 = (g8 (8-6)) G_RGB565_OFFSET; uint8 b5 = (b8 (8-5)); uint16 rgb565 = (r5|g6|b5); uint16 rgb565_from_sdl = get_pixel_rgb565_from_sdl (...); if (rgb565 == rgb565_from_sdl) { /* same value */ } ... - Joni Valtanen ___ maemo-developers mailing list maemo-developers@maemo.org https://lists.maemo.org/mailman/listinfo/maemo-developers
Re: [maemo-developers] Nokia SDL color format for pixels
Hi, ext Michael Stepanov wrote: On Tue, Apr 15, 2008 at 3:50 PM, Frantisek Dufka [EMAIL PROTECTED] wrote: So, how in that situation I can get correct color? It is already correct. The color format is RGB565. What 'correct' means to you in this context? If you need the value in different format you need to convert it. Yes, I need to convert RGB565 to RGB888 to compare two values - actual pixel color and pink color. Could you suggest me, please, some way to do that? SDL_Surface pixel format structure contains the necessary shift mask values already for this conversion and SDL documentation has an example on how to use them. SDL automatically does the conversion in the other direction (e.g.) RGB888 - display format, but for performance reasons it's usually best to do that conversion when loading images etc. (SDL offers a separate function for this conversion) - Eero ___ maemo-developers mailing list maemo-developers@maemo.org https://lists.maemo.org/mailman/listinfo/maemo-developers
Re: [maemo-developers] Nokia SDL color format for pixels
HI, Long time ago I tried to investigated the problem of replacing pixel's colors. So, I faced with that problem again. But the problem is in the result of getpixel() method. I use the similar one: Uint32 getpixel(SDL_Surface *surface, int x, int y) { int bpp = surface-format-BytesPerPixel; /* Here p is the address to the pixel we want to retrieve */ Uint8 *p = (Uint8 *)surface-pixels + y * surface-pitch + x * bpp; switch(bpp) { case 1: return *p; case 2: return *(Uint16 *)p; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) return p[0] 16 | p[1] 8 | p[2]; else return p[0] | p[1] 8 | p[2] 16; case 4: return *(Uint32 *)p; default: return 0; /* shouldn't happen, but avoids warnings */ } } In case of Nokia that method returns *(Uint16 *)p. But instead of 6 hexadecimals it returns only 4. For example, for white color it returns instead of F. The same, for the rest of colors. Any idea why? On Mon, Feb 12, 2007 at 11:35 AM, Tapani Pälli [EMAIL PROTECTED] wrote: ext Michael Stepanov wrote: Thanks for your answer, Tarani. On 2/12/07, *Tapani Pälli* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: ext Michael Stepanov wrote: Well, there is a open source system for home automation - Plutohome (www.plutohome.com http://www.plutohome.com http://www.plutohome.com http://www.plutohome.com). This system can use Nokia770/800 as a control panel - Orbiter. The Orbiter is based on SDL. So, after some hack it started work on Nokia (os2005/os2006) but there is a problem. Icons on the Orbiter should change their color according to some events. Are you missing icon 'highlight' effect when mouse is moved on top of icon? Please specify exactly what the 'some events' are. The color of icon should be changed according to status of real device which represented by this icon. For example, there is a lighting switch and its icon. If switch is ON icon should be yellow, otherwise it should be black. But in real device icon every time is pink. I suspect that something wrong with pixels coloring using SDL. There is a method Ah ok, pink might be colorkey for 1-bit transparency and shouldn't be displayed. OrbiterRenderer_SDL::ReplaceColorInRectangle in the OrbiterRenderer_SDL.cpp which changes colors of icons. Maybe SDL for nokia 770 uses different color format for pixels? Yep, you could try a simple hack to find out wheter bug is here by replacing putpixel call in loop to paint only red : SDLGraphic::putpixel(m_pScreenImage,i + x, j + y, SDL_MapRGB(PF, 255, 0, 0); ... it seems algorithm is checking wheter destination color differs from source enough and if so it paints. However I don't see anything wrong in getpixel or putpixel, they should OK. Initially they are pink. Using SDL functionality their color can be changed. It works fine for Debian but it didn't work for Nokia (either scratchbox emulator or real device). All icons are pink every time. I'm not developer. I'm integrator. So, it's difficult for me to understand where is the problem. Have a look attached files. Maybe you can help me. I couldn't spot bugs in the code you sent, maybe OrbiterLogic has some calls to renderer to change icon colors?. One thing which should be changed in renderer class is the colordepth used for surfaces. Right now it seems to be hardcoded to certain places as 32. Code should read the correct depth using SDL_GetVideoInfo and make sure all the newly created surfaces use the same depth to avoid amount of needed conversions. Thanks, I check it. Thanks in advanced. On 2/9/07, * [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED]* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Hello, Could you be more specific what are you trying todo and how? Are you going through pixelvalues and accessing them? See surface-format-BytesPerPixel. SDL_GetRGB and SDL_MapRGB should work allright. // Tapani --- 8 - // T -- Cheers, Michael // Tapani -- Cheers, Michael ___ maemo-developers mailing list maemo-developers@maemo.org https://lists.maemo.org/mailman/listinfo/maemo-developers
Re: [maemo-developers] Nokia SDL color format for pixels
Michael Stepanov wrote: In case of Nokia that method returns *(Uint16 *)p. But instead of 6 hexadecimals it returns only 4. For example, for white color it returns instead of F. The same, for the rest of colors. Any idea why? Some typo in your mail? Uint16 is 16 bit value, you really can't fit more than there :-) ___ maemo-developers mailing list maemo-developers@maemo.org https://lists.maemo.org/mailman/listinfo/maemo-developers
Re: [maemo-developers] Nokia SDL color format for pixels
On Tue, Apr 15, 2008 at 3:30 PM, Frantisek Dufka [EMAIL PROTECTED] wrote: Michael Stepanov wrote: In case of Nokia that method returns *(Uint16 *)p. But instead of 6 hexadecimals it returns only 4. For example, for white color it returns instead of F. The same, for the rest of colors. Any idea why? Some typo in your mail? Uint16 is 16 bit value, you really can't fit more than there :-) You're right. I'm not C++ developer. Just try to port some application to maemo :) So, how in that situation I can get correct color? -- Cheers, Michael ___ maemo-developers mailing list maemo-developers@maemo.org https://lists.maemo.org/mailman/listinfo/maemo-developers
Re: [maemo-developers] Nokia SDL color format for pixels
Michael Stepanov wrote: So, how in that situation I can get correct color? It is already correct. The color format is RGB565. What 'correct' means to you in this context? If you need the value in different format you need to convert it. ___ maemo-developers mailing list maemo-developers@maemo.org https://lists.maemo.org/mailman/listinfo/maemo-developers
Re: [maemo-developers] Nokia SDL color format for pixels
Michael Stepanov wrote: int bpp = surface-format-BytesPerPixel; You can check also other fields of SDL_PixelFormat structure to get R,G,B color components. Interesting field names are Uint8 Rloss; Uint8 Gloss; Uint8 Bloss; Uint8 Rshift; Uint8 Gshift; Uint8 Bshift; Uint32 Rmask; Uint32 Gmask; Uint32 Bmask; Or you can use SDL_GetRGB(Uint32 pixel, SDL_PixelFormat *fmt, Uint8 *r, Uint8 *g, Uint8 *b) function which will probably do the dirty bit shifting and masking work for you. http://www.google.com/search?q=SDL_GetRGB ___ maemo-developers mailing list maemo-developers@maemo.org https://lists.maemo.org/mailman/listinfo/maemo-developers
Re: [maemo-developers] Nokia SDL color format for pixels
Thanks for your answer, Tarani. On 2/12/07, Tapani Pälli [EMAIL PROTECTED] wrote: ext Michael Stepanov wrote: Well, there is a open source system for home automation - Plutohome (www.plutohome.com http://www.plutohome.com). This system can use Nokia770/800 as a control panel - Orbiter. The Orbiter is based on SDL. So, after some hack it started work on Nokia (os2005/os2006) but there is a problem. Icons on the Orbiter should change their color according to some events. Are you missing icon 'highlight' effect when mouse is moved on top of icon? Please specify exactly what the 'some events' are. The color of icon should be changed according to status of real device which represented by this icon. For example, there is a lighting switch and its icon. If switch is ON icon should be yellow, otherwise it should be black. But in real device icon every time is pink. I suspect that something wrong with pixels coloring using SDL. There is a method OrbiterRenderer_SDL::ReplaceColorInRectangle in the OrbiterRenderer_SDL.cpp which changes colors of icons. Maybe SDL for nokia 770 uses different color format for pixels? Initially they are pink. Using SDL functionality their color can be changed. It works fine for Debian but it didn't work for Nokia (either scratchbox emulator or real device). All icons are pink every time. I'm not developer. I'm integrator. So, it's difficult for me to understand where is the problem. Have a look attached files. Maybe you can help me. I couldn't spot bugs in the code you sent, maybe OrbiterLogic has some calls to renderer to change icon colors?. One thing which should be changed in renderer class is the colordepth used for surfaces. Right now it seems to be hardcoded to certain places as 32. Code should read the correct depth using SDL_GetVideoInfo and make sure all the newly created surfaces use the same depth to avoid amount of needed conversions. Thanks, I check it. Thanks in advanced. On 2/9/07, [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Hello, Could you be more specific what are you trying todo and how? Are you going through pixelvalues and accessing them? See surface-format-BytesPerPixel. SDL_GetRGB and SDL_MapRGB should work allright. // Tapani --- 8 - // T -- Cheers, Michael ___ maemo-developers mailing list maemo-developers@maemo.org https://maemo.org/mailman/listinfo/maemo-developers
Re: [maemo-developers] Nokia SDL color format for pixels
ext Michael Stepanov wrote: Thanks for your answer, Tarani. On 2/12/07, *Tapani Pälli* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: ext Michael Stepanov wrote: Well, there is a open source system for home automation - Plutohome (www.plutohome.com http://www.plutohome.com http://www.plutohome.com http://www.plutohome.com). This system can use Nokia770/800 as a control panel - Orbiter. The Orbiter is based on SDL. So, after some hack it started work on Nokia (os2005/os2006) but there is a problem. Icons on the Orbiter should change their color according to some events. Are you missing icon 'highlight' effect when mouse is moved on top of icon? Please specify exactly what the 'some events' are. The color of icon should be changed according to status of real device which represented by this icon. For example, there is a lighting switch and its icon. If switch is ON icon should be yellow, otherwise it should be black. But in real device icon every time is pink. I suspect that something wrong with pixels coloring using SDL. There is a method Ah ok, pink might be colorkey for 1-bit transparency and shouldn't be displayed. OrbiterRenderer_SDL::ReplaceColorInRectangle in the OrbiterRenderer_SDL.cpp which changes colors of icons. Maybe SDL for nokia 770 uses different color format for pixels? Yep, you could try a simple hack to find out wheter bug is here by replacing putpixel call in loop to paint only red : SDLGraphic::putpixel(m_pScreenImage,i + x, j + y, SDL_MapRGB(PF, 255, 0, 0); ... it seems algorithm is checking wheter destination color differs from source enough and if so it paints. However I don't see anything wrong in getpixel or putpixel, they should OK. Initially they are pink. Using SDL functionality their color can be changed. It works fine for Debian but it didn't work for Nokia (either scratchbox emulator or real device). All icons are pink every time. I'm not developer. I'm integrator. So, it's difficult for me to understand where is the problem. Have a look attached files. Maybe you can help me. I couldn't spot bugs in the code you sent, maybe OrbiterLogic has some calls to renderer to change icon colors?. One thing which should be changed in renderer class is the colordepth used for surfaces. Right now it seems to be hardcoded to certain places as 32. Code should read the correct depth using SDL_GetVideoInfo and make sure all the newly created surfaces use the same depth to avoid amount of needed conversions. Thanks, I check it. Thanks in advanced. On 2/9/07, * [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED]* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Hello, Could you be more specific what are you trying todo and how? Are you going through pixelvalues and accessing them? See surface-format-BytesPerPixel. SDL_GetRGB and SDL_MapRGB should work allright. // Tapani --- 8 - // T -- Cheers, Michael // Tapani ___ maemo-developers mailing list maemo-developers@maemo.org https://maemo.org/mailman/listinfo/maemo-developers
Re: [maemo-developers] Nokia SDL color format for pixels
Well, there is a open source system for home automation - Plutohome ( www.plutohome.com). This system can use Nokia770/800 as a control panel - Orbiter. The Orbiter is based on SDL. So, after some hack it started work on Nokia (os2005/os2006) but there is a problem. Icons on the Orbiter should change their color according to some events. Initially they are pink. Using SDL functionality their color can be changed. It works fine for Debian but it didn't work for Nokia (either scratchbox emulator or real device). All icons are pink every time. I'm not developer. I'm integrator. So, it's difficult for me to understand where is the problem. Have a look attached files. Maybe you can help me. Thanks in advanced. On 2/9/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hello, Could you be more specific what are you trying todo and how? Are you going through pixelvalues and accessing them? See surface-format-BytesPerPixel. SDL_GetRGB and SDL_MapRGB should work allright. // Tapani From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of ext Michael Stepanov Sent: 09 February, 2007 11:03 To: maemo-developers@maemo.org Subject: [maemo-developers] Nokia SDL color format for pixels Hi, I have a question about SDL realization for Nokia770/800. Does it use some different format to fill a pixel by some color? Because in my application SDL is used to change color of icons according to some conditions. It works fine under Linux (Debian) but it didn't work under Nokia 770 (I tried for both os2005 and os2006). The color of icon is not changed. Any ideas why? Is there some manual about Nokia port of SDL? Thanks in advance. -- Cheers, Michael -- Cheers, Michael /* OrbiterRenderer_SDL Copyright (C) 2004 Pluto, Inc., a Florida Corporation www.plutohome.com Phone: +1 (877) 758-8648 This program is distributed according to the terms of the Pluto Public License, available at: http://plutohome.com/index.php?section=public_license This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Pluto Public License for more details. */ #include OrbiterRenderer_SDL.h #include PlutoUtils/CommonIncludes.h #include PlutoUtils/MultiThreadIncludes.h #include DCE/Logger.h #include SerializeClass/ShapesColors.h #include ../../SDL_Helpers/SDL_Defs.h #include ../RendererOCG.h #include SDLRendererOCGHelper.h #include pluto_main/Define_Effect.h #include pluto_main/Define_DesignObj.h #include pluto_main/Define_Text.h #include pluto_main/Define_DeviceCategory.h #include Gen_Devices/AllCommandsRequests.h #include DataGrid.h #include SDLGraphic.h #include Splitter/TextWrapper.h #include ../ScreenHistory.h #include ../Orbiter.h #ifdef WIN32 #include ../Win32/MainDialog.h #endif #include SDL_rotozoom.h #include SDL_ttf.h #include SDL_image.h #include sge.h #include sge_surface.h #ifdef WIN32 #include SDL_syswm.h #else #include SDL/SDL_syswm.h #endif #if !defined(WIN32) !defined(BLUETOOTH_DONGLE) !defined(PROXY_ORBITER) #include utilities/linux/transparency/transparency.h #include utilities/linux/wrapper/wrapper_x11.h #endif #if !defined(BLUETOOTH_DONGLE) !defined(PROXY_ORBITER) #define USE_ONLY_SCREEN_SURFACE #endif #ifdef WINCE #include wince.h #endif using namespace DCE; bool g_bResettingVideoMode; void *SetVideoModeWatchDogThread(void *p) { OrbiterRenderer_SDL *pOrbiterRenderer_SDL = (OrbiterRenderer_SDL *) p; g_pPlutoLogger-Write(LV_STATUS,Inside WatchDogThread); Sleep(2000); if( g_bResettingVideoMode ) { g_pPlutoLogger-Write(LV_CRITICAL, SDL_SetVideoMode hangs on init. Xorg is not initialized yet? Restarting...); #ifndef WIN32 kill(getpid(), SIGKILL); #endif } return NULL; } //- OrbiterRenderer_SDL::OrbiterRenderer_SDL(Orbiter *pOrbiter) : OrbiterRenderer(pOrbiter) { m_bRelativeMode = false; m_pScreenImage = NULL; } OrbiterRenderer_SDL::~OrbiterRenderer_SDL() { // We need to do this before freeing the surface. It's a repeat of what's in Orbiter's destructor g_pPlutoLogger-Write(LV_STATUS, about to free surface); #ifndef USE_ONLY_SCREEN_SURFACE SDL_FreeSurface(m_pScreenImage); #endif m_pScreenImage = NULL; g_pPlutoLogger-Write(LV_STATUS, ~OrbiterRenderer_SDL finished); } void OrbiterRenderer_SDL::Configure() { /// SDL 2D code, creates the SDL window //initializing the engine... Uint32 uSDLInitFlags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE; if(m_bFullScreen) uSDLInitFlags |= SDL_FULLSCREEN; if (SDL_Init(uSDLInitFlags) == -1) { #ifndef WINCE cerr Failed initializing SDL: SDL_GetError() endl; #else printf(Failed to initialize SDL %s\n, SDL_GetError()); #endif //WINCE #ifndef