Thread: GetPixel tolerance

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    43

    GetPixel tolerance

    I need a GetPixel tolerance code. Here’s is what I have for searching for a pixel.

    Code:
    int findcolor(int &x1, int &y1, int &x2, int &y2, unsigned int r, unsigned int g, unsigned int b, int &x, int &y)
    {
    int XL, YL, xcount, ycount, TLXBackup;
    
    
    
               TLXBackup = x1;
    
               XL = x2 - x1;
               YL = y2 - y1;
               xcount = 0;
               ycount = 0;
    
                   POINT TR;
                   HDC hdc = GetDC(NULL);
                   Loop:
                       DWORD color2 = GetPixel(hdc, x1, y1);
                       unsigned int R = GetRValue(color2);
                       unsigned int G = GetGValue(color2);
                       unsigned int B = GetBValue(color2);
                           if ( xcount == XL)
                            {
                              y1++;
                              x1 = TLXBackup;
                              ycount++;
                              xcount = 0;
                            }
                             if ( ycount == YL )
                              {
                                ReleaseDC;
                                return 0;
                              }
                              xcount++;
                              x1++;
                                  if ((r == R) && (g == G) && (b == B))
                                   {
                                     x = x1;
                                     y = y1;
                                     ReleaseDC;
                                     return 1;
                                   }
                                   goto Loop;
    }
    i have ben searching google and still am but not finding mutch.
    I’m Dyslexic and I know that I don’t spell well so quit telling to learn my English because I do my best at it all right.

    Windows XP with Dev-C++ for now.

  2. #2
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    Unless you comment your code, no one is going to make much of an effort to figure out what you're trying to do. Add some comments that show the logic of what you are trying to accomplish. Then you may get more assistance. And above all, what is a GetPixel tolerance code??

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Why in the abyss are you using goto for such a simple loop!? Change it, please. It looks really bad.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    43
    Ok well pixel tolerance would work like.
    If tolerance = 10 than find a pixel with that color that was specified or 10 shads different from that color.
    I’m Dyslexic and I know that I don’t spell well so quit telling to learn my English because I do my best at it all right.

    Windows XP with Dev-C++ for now.

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    43
    yes ill be changing the goto in a little bit but for now it works
    I’m Dyslexic and I know that I don’t spell well so quit telling to learn my English because I do my best at it all right.

    Windows XP with Dev-C++ for now.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You shouldn't be using goto in the first place! You should not have written it at all for such a simple matter of using a loop here, where it is not complicated at all.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Get rid of that goto. a do..while(true) will work just the same.

    This all depends on what you're using it for. I recently(ish) wrote something similiar, except that it converted RGB to the HSV colourspace before doing any tolerance testing. This improved the results a little. What are you using it for?

    Btw "much" is spelt like this, and "been" has two E's.
    Being not so good at spelling is fine, but I would hope that you would not purposefuly turn down assistance.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  8. #8
    Registered User
    Join Date
    Nov 2007
    Posts
    43
    Just searching in x1, y1 and x2, y2 for a pixel with a tolerance. so if you don’t mind I think that your code might help if you could post it or send it to me.
    I’m Dyslexic and I know that I don’t spell well so quit telling to learn my English because I do my best at it all right.

    Windows XP with Dev-C++ for now.

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    I can't I'm afraid, that code is at work and belongs to my employer.

    btw I understand the description of the problem, but what do you intend to use it for? What do you plan to do once you find the pixel you are looking for?
    If you were wanting to find the pixel that is the closest match to the specified colour then you would need to keep going until you reach the end, or find a perfect match.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GetPixel and CreateDC help. (winapi)
    By OpiateDelusion in forum Windows Programming
    Replies: 6
    Last Post: 08-19-2007, 08:15 AM
  2. Need Help With GetPixel
    By Anddos in forum Windows Programming
    Replies: 1
    Last Post: 08-19-2006, 05:08 PM
  3. While loop and tolerance
    By MethodMan in forum C Programming
    Replies: 17
    Last Post: 10-06-2004, 08:29 AM
  4. SDL getPixel
    By Nova_Collision in forum Game Programming
    Replies: 1
    Last Post: 02-10-2003, 11:34 PM
  5. GetPixel return value
    By Garfield in forum Windows Programming
    Replies: 7
    Last Post: 11-14-2001, 01:18 AM