NO

Author Topic: SetPixel and GetPixel Problems  (Read 5313 times)

gromit

  • Guest
SetPixel and GetPixel Problems
« on: June 26, 2010, 10:39:35 pm »
Hi all
Having a very strange problem in the following function I am trying to detect the presence of pixels below a certain luminosity ( darkest)
The Setpixel part of this function works fine and i can see that the pixels are indeed being set.
However if  i try to add other code before or after the SetPixel(   ...   )
the pixels are not set
its as if the loop terminates
 found ++ never increments
Thanks for any help you may be able to give.


static int DiscoverSymbol(HDC hdc,int limit,int x,int y)
{
Byte hr,hg,hb;
int l=0;

COLORREF rgb;
int found = 0;
while (x<240)// this is screen width
{

y++;
rgb=GetPixel(hdc,x,y);

 hr = GetRValue(rgb);
hg = GetGValue(rgb);
hb = GetBValue(rgb);
l = (hr*0.3 + hg*0.59+ hb*0.11);

if (l<limit) //found a pixel by scanning up and down

SetPixel(hdc,x,y,RGB(255,255,255));

///////////////////////
  found++; // any code here results in no pixels set
/////////////////
   }
if (y==165)
{
 
x++;
y=140;
//found=0;
}


   }

   }

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1936
Re: SetPixel and GetPixel Problems
« Reply #1 on: June 27, 2010, 06:26:38 pm »
Is there missing { after if (l<limit) ?
May the source be with you

gromit

  • Guest
Re: SetPixel and GetPixel Problems
« Reply #2 on: June 27, 2010, 06:38:13 pm »
Sorry in the code that parenthisis is in
 ,{,

so its owt to do with that

Put Simply if any other code that starts any sort of count
is added it does not work

If its not a bug in pelles i am forced to conclude that it something weird to do with WM_PAINT
But Please ! Have been at this bit for a cosiderable amount of time
So any suggestions at all would be welcomed
Big Thanks Gromit

JohnF

  • Guest
Re: SetPixel and GetPixel Problems
« Reply #3 on: June 28, 2010, 11:35:34 pm »
I suggest you post the smallest example project that exhibits problem - this will make it easier for someone to check.

John

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1936
Re: SetPixel and GetPixel Problems
« Reply #4 on: June 29, 2010, 08:26:27 am »
This test program test that function but problem doesn't exists.
It works without optimization.

PellesC 6:

If i replace that
Code: [Select]
l = (hr * 0.3 + hg * 0.59 + hb * 0.11);with function
Code: [Select]
l =  Test(hr, hg, hb); that work with optimization in MS Device Emulator.

Code: [Select]
static int Test(BYTE hr, BYTE hg, BYTE hb)
{
return (hr * 0.3 + hg * 0.59 + hb * 0.11);
}
« Last Edit: June 29, 2010, 11:14:18 am by timovjl »
May the source be with you

gromit

  • Guest
Re: SetPixel and GetPixel Problems
« Reply #5 on: July 04, 2010, 12:13:24 am »
Thank You for that little app it clearly shows that the commands should indeed work so it will be a problem in other code that i am using.

I will use yor example as a basis to rebuild a test of what i am trying to acheive

Sorry not got back to you sooner will let u know further progress.

May be a while as have to go away for a holiday shortly so unless she lets me take the laptop( i doubt it)
once again big thanks

gromit

  • Guest
Re: SetPixel and GetPixel Problems
« Reply #6 on: July 07, 2010, 01:01:21 am »

Thanks for previous info

I still cannot fathom out why my prog does not work and yours does
I have slimmed my project down to its bare essentials and
I now post a main c and main h file

Not used to this uploading file stuff so please excuse if i get it wrong

Am using a windows 7 64 bit Laptop

If you run it on an emulator or pocket pc
perhaps you can fathom out why it wont count
Just will not work as long as a count is present.

The line that end the While {} before it even starts is in the ScanForSymbol Function
Any Help From Anyone Please...

 

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1936
Re: SetPixel and GetPixel Problems
« Reply #7 on: July 07, 2010, 10:00:30 am »
Bit modified version that works in MS Device Emulator.

I changes file names and add missing resource file.

Code: [Select]
// RESOURCE SCRIPT generated by "Pelles C for Windows, version 6.00".

#include <windows.h>
#include <commctrl.h>
#include "GetPixel_1.h"

LANGUAGE LANG_ENGLISH,SUBLANG_ENGLISH_US

IDR_MNU_MAIN MENU
{
  MENUITEM "Scan", IDM_SCAN
  MENUITEM "Exit", IDM_EXIT
}

I add mbi.dwFlags    = SHCMBF_HMENU; to Main_OnCreate to get it work.
May the source be with you

gromit

  • Guest
Re: SetPixel and GetPixel Problems
« Reply #8 on: July 08, 2010, 12:26:16 am »
Big Thanks  timovjl

I finally tracked down the real problem

Your latest offering of my two files combined with your tweaks still just refused to work on my Dell Axim WM5

'While' loop would not perform at all whilst count was asked to .... count. No set pixels no count no nothing.
Take count out and it worked.
Turned out that this line was the problem
     l = (hr * 0.3 + hg * 0.59 + hb * 0.11);
So-:
 Doing the multiplication seperately and it works as in ...

l =Test(hr,hg,hb);

static  int Test(BYTE hr, BYTE hg, BYTE hb)

{
hr=hr*0.3;  hg= hg* 0.59;hb=hb * 0.11;
return(hr + hg  + hb );   // seperate addition
}

Even with the function bracketed it would not work
as in
l = ((hr * 0.3) + (hg * 0.59) + (hb * 0.11));
  ??? ??? ??? ???
Assume it overwrote some memory somewhere
It does now work and is now counting pixels for me

Thanks for your help Much appreciated
Gromit.
 ;D ;D