Jump to content

CultOfSun

Members
  • Posts

    11
  • Joined

  • Last visited

Everything posted by CultOfSun

  1. I made a few changes to the code @Andreik provided! #define AUT_MANUALSTEP 0 #define AUT_AUTOSTEP 1 bool PixelSearch(LPRECT lpRect, int nCol, int nVar, int nStep, LPPOINT pPointResult, int stepMode = AUT_MANUALSTEP, int nCoordPixelMode = AUT_COORDMODE_SCREEN) { int q, r; int col; BYTE red, green, blue; BYTE red_low, red_high, green_low, green_high, blue_low, blue_high; HDC hdc; RECT relrect; POINT ptOrigin; bool m_bColorModeBGR = false; relrect.left = lpRect->left; relrect.top = lpRect->top; relrect.right = lpRect->right; relrect.bottom = lpRect->bottom; ConvertCoords(nCoordPixelMode, ptOrigin); relrect.left += ptOrigin.x; relrect.top += ptOrigin.y; relrect.right += ptOrigin.x; relrect.bottom += ptOrigin.y; col = nCol; if (m_bColorModeBGR == false) Util_RGBtoBGR(col); red = GetRValue(col); green = GetGValue(col); blue = GetBValue(col); if (nVar < 0) nVar = 0; else if (nVar > 0xff) nVar = 0xff; if (nVar == 0) { red_low = red_high = red; green_low = green_high = green; blue_low = blue_high = blue; } else { red_low = (nVar > red) ? 0 : red - nVar; green_low = (nVar > green) ? 0 : green - nVar; blue_low = (nVar > blue) ? 0 : blue - nVar; red_high = (nVar > 0xFF - red) ? 0xFF : red + nVar; green_high = (nVar > 0xFF - green) ? 0xFF : green + nVar; blue_high = (nVar > 0xFF - blue) ? 0xFF : blue + nVar; } hdc = GetDC(NULL); if (stepMode == AUT_MANUALSTEP) { for (q = relrect.left; q <= relrect.right; q = q + nStep) { for (r = relrect.top; r <= relrect.bottom; r = r + nStep) { col = GetPixel(hdc, q, r); red = GetRValue(col); green = GetGValue(col); blue = GetBValue(col); if (red >= red_low && red <= red_high && green >= green_low && green <= green_high && blue >= blue_low && blue <= blue_high) { q -= ptOrigin.x; r -= ptOrigin.y; pPointResult->x = q; pPointResult->y = r; ReleaseDC(NULL, hdc); return 0; } } } } else if (stepMode == AUT_AUTOSTEP) { nStep = lpRect->right - lpRect->left; for (int i = nStep; i > 0; i -= (i / 2)) { for (q = relrect.left; q <= relrect.right; q = q + i) { for (r = relrect.top; r <= relrect.bottom; r = r + i) { col = GetPixel(hdc, q, r); red = GetRValue(col); green = GetGValue(col); blue = GetBValue(col); if (red >= red_low && red <= red_high && green >= green_low && green <= green_high && blue >= blue_low && blue <= blue_high) { q -= ptOrigin.x; r -= ptOrigin.y; pPointResult->x = q; pPointResult->y = r; ReleaseDC(NULL, hdc); return 0; } } } } } ReleaseDC(NULL, hdc); return 1; } Changed the return type of the PixelSearch function to return a bool. If it finds the color it returns 0, if not it returns 1. I also added a parameter stepMode, its default is AUT_MANUALSTEP or 0. The AUT_AUTOSTEP basically just takes the difference of lpRect->right - lpRect->left and uses that as the step amount. It divides the difference by 2 each time it cycles through those for loops. If anyone can add to this or make this even better that would be awesome!
  2. Thank you! You saved me a huge amount of time.
  3. Thank you! This helps me out a lot!
  4. I may ping them just to inform them, I've made a pixelsearch function it's just very slow. Thank you for your time! I'm gonna look into different ways I can speed up this pixel search function.
  5. Yeah this is autoitx for c++, you pass a pointer to the POINT struct. When I cover up the search area it prints 1 because it didn't find what it was looking for, when I uncover the area it gives an access violation for whatever reason my guess is it's not able to write the coords to the struct.
  6. AU3_API void WINAPI AU3_PixelSearch(LPRECT lpRect, int nCol, /*default 0*/int nVar, /*default 1*/int nStep, LPPOINT pPointResult); This is from the header file
  7. The version I'm using is 3.3.16.1. Also I messed around with the code again. #include <iostream> #include "AutoItX3_DLL.h" int main() { HINSTANCE dllHandle = LoadLibrary(TEXT("C:\\Users\\ccjen\\Desktop\\AutoX\\AutoItX3_x64.dll")); if (dllHandle) { POINT coords{}; RECT searchCoords{}; searchCoords.left = 688; searchCoords.top = 10; searchCoords.right = 762; searchCoords.bottom = 78; AU3_PixelSearch(&searchCoords, 0x000000, 0, 1, &coords); std::cout << AU3_error() << std::endl; //AU3_MouseMove(coords.x, coords.y); FreeLibrary(dllHandle); } } So I believed I may have narrowed it down. Every time I block the search area with visual studio it prints 1 in the console but when I unblock the search area it gives me the access violation. So could it be having trouble storing the coords in the POINT structure?
  8. #UPDATE. I removed the MouseMove and now lost more than I originally was. Still violation.
  9. Could you inform me on how to properly do that? My original belief was that the result was being sent to the POINT struct "coords". I'm new to c++ if it's something simple I apologize, I appreciate the help.
  10. #include <iostream> #include "AutoItX3_DLL.h" int main() { HINSTANCE dllHandle = LoadLibrary(TEXT("C:\\Users\\ccjen\\Desktop\\AutoX\\AutoItX3_x64.dll")); if (dllHandle) { POINT coords{}; RECT searchCoords{}; searchCoords.left = 688; searchCoords.top = 10; searchCoords.right = 762; searchCoords.bottom = 78; AU3_PixelSearch(&searchCoords, 0x000000, 0, 1, &coords); AU3_MouseMove(coords.x, coords.y); FreeLibrary(dllHandle); } }
  11. I'm trying to get the Pixel search function to work. I'm getting access violation when accessing the point struct.
×
×
  • Create New...