author | ecalot
<ecalot> 2005-07-04 03:10:25 UTC |
committer | ecalot
<ecalot> 2005-07-04 03:10:25 UTC |
parent | 879738a5c8c90a6b9921c3e872a81ab98270329d |
poprecog/Makefile | +1 | -2 |
poprecog/poprecog.c | +137 | -220 |
diff --git a/poprecog/Makefile b/poprecog/Makefile index aafe7be..af9f138 100644 --- a/poprecog/Makefile +++ b/poprecog/Makefile @@ -18,8 +18,7 @@ COPY = @ln -f INCLUDE = LIBS = `allegro-config --libs --cflags` -RELEASE = -g -#-g -Wall -pedantic +RELEASE = -g -Wall -pedantic LINKERRELEASE = MAIN = .poprecog.o diff --git a/poprecog/poprecog.c b/poprecog/poprecog.c index 0c7e11f..82606a4 100644 --- a/poprecog/poprecog.c +++ b/poprecog/poprecog.c @@ -75,16 +75,8 @@ poprecog.c: Prince of Persia Screenshots Recognizer #define POPRECOG_URL "http://www.princed.com.ar" #define POPRECOG_ABOUT "Prince of Persia Screenshots Recognizer\n(c) Copyright 2005 Princed Development Team\nProgrammed by peter_k\n" POPRECOG_URL "\n\n" -/* Types and global variables */ -struct sScreenShotList -{ - char *fileName; -} screenShotList[MAX_SCREENSHOTS]; -int screenShotsNumber; -char screenShotsDir[100]; - -typedef struct sImage -{ +/* Types */ +typedef struct sImage { BITMAP *bitmap; char *filePath; char direction; @@ -92,6 +84,26 @@ typedef struct sImage int dirID; } tImage; +typedef struct sRecognized { + int imageID; + int posX, posY; + int goodPixels; + int goodPixels2; + int layer; + int pixelsNumber; + int upperLayers; + int goodPixelsPercent; + int ownedPixels; /* for recognizeMap */ +} tRecognized; + +/* Global variables */ +struct sScreenShotList { + char *fileName; +} screenShotList[MAX_SCREENSHOTS]; + +int screenShotsNumber; +char screenShotsDir[100]; + tImage image[MAX_IMAGES]; int imagesNumber; @@ -99,8 +111,7 @@ BITMAP *screenShot, *transparentScreenShot, *DEBUGScreenShot, *DEBUGScreenShot2; int DEBUGY = 0; -struct sDirInfo -{ +struct sDirInfo { char dirName[16]; int recognizedNumber; int optTwoDirections; @@ -109,28 +120,17 @@ struct sDirInfo int optAllowTransparency; /* int optVolatile; */ } dirInfo[MAX_DIRS]; + int dirsNumber; -typedef struct sRecognized -{ - int imageID; - int posX, posY; - int goodPixels; - int goodPixels2; - int layer; - int pixelsNumber; - int upperLayers; - int goodPixelsPercent; - int ownedPixels; /* for recognizeMap */ -} tRecognized; tRecognized recognized[MAX_RECOGNIZED_ITEMS]; int recognizedNumber; int totalNumberOfRecognizedImages; int actualLayer; int recognizeMap[320][200]; /* here are stored information which 'recognize result' have this pixel */ -struct sSharedPixels -{ + +struct sSharedPixels { int recognizedID; int number; } sharedPixels[MAX_RECOGNIZED_ITEMS]; @@ -143,24 +143,21 @@ int optMaxLayers; /* Functions */ -int match(char *pat, char *str) -{ +int match(char *pat, char *str) { switch(*pat) { case '\0': return !*str; - case '*': return match(pat + 1, str) || *str && match(pat, str + 1); + case '*': return match(pat + 1, str) || (*str && match(pat, str + 1)); case '?': return *str && match(pat + 1, str + 1); - default: return *pat == *str && match(pat + 1, str + 1); + default: return (*pat == *str) && match(pat + 1, str + 1); } } -int pstrcmp(const void *p1, const void *p2) -{ +int pstrcmp(const void *p1, const void *p2) { return strcmp(*(char * const *)p1, *(char * const *)p2); } -int cmptImage(void *a, void *b) -{ +int cmptImage(void *a, void *b) { register int pxa = ((tImage*)(a))->pixelsNumber; register int pxb = ((tImage*)(b))->pixelsNumber; if (pxa > pxb) @@ -170,63 +167,49 @@ int cmptImage(void *a, void *b) return 0; } -inline int findImageOnScreenShotInPosition(int imageID, int posX, int posY) -{ - register int i, j, x, y; +inline int findImageOnScreenShotInPosition(int imageID, int posX, int posY) { + register int i, x, y; register short transparentPixel = makecol16(0, 0, 0); register short screenShotTransparentPixel = makecol16(255, 0, 255); register int goodPixels; BITMAP *bitmap = image[imageID].bitmap; - register int wPer2 = bitmap->w / 2; - register int hPer2 = bitmap->h / 2; + /*register int wPer2 = bitmap->w / 2; + register int hPer2 = bitmap->h / 2; * TODO: check unused vars */ sharedPixels[0].recognizedID = -1; goodPixels = 0; for (x = 0; x < bitmap->w; x++) - for (y = 0; y < bitmap->h; y++) - { + for (y = 0; y < bitmap->h; y++) { if ((((short *)bitmap->line[y])[x] == transparentPixel) && (dirInfo[image[imageID].dirID].optAllowTransparency)) continue; - if (((short *)bitmap->line[y])[x] == ((short *)screenShot->line[posY+y])[posX+x]) - { - if (recognizeMap[posX+x][posY+y] != -1) - { - for (i=0; sharedPixels[i].recognizedID != -1; i++) - { - if (sharedPixels[i].recognizedID == recognizeMap[posX+x][posY+y]) - { + if (((short *)bitmap->line[y])[x] == ((short *)screenShot->line[posY+y])[posX+x]) { + if (recognizeMap[posX+x][posY+y] != -1) { + for (i=0; sharedPixels[i].recognizedID != -1; i++) { + if (sharedPixels[i].recognizedID == recognizeMap[posX+x][posY+y]) { if (sharedPixels[i].number >= 0) sharedPixels[i].number++; break; } } - if (sharedPixels[i].recognizedID == -1) - { + if (sharedPixels[i].recognizedID == -1) { sharedPixels[i].recognizedID = recognizeMap[posX+x][posY+y]; sharedPixels[i].number = 1; sharedPixels[i+1].recognizedID = -1; } - } - else - { + } else { goodPixels++; } continue; } - if (((short *)transparentScreenShot->line[posY+y])[posX+x] == screenShotTransparentPixel) - { - if (recognizeMap[posX+x][posY+y] != -1) - { - for (i=0; sharedPixels[i].recognizedID != -1; i++) - { - if (sharedPixels[i].recognizedID == recognizeMap[posX+x][posY+y]) - { + if (((short *)transparentScreenShot->line[posY+y])[posX+x] == screenShotTransparentPixel) { + if (recognizeMap[posX+x][posY+y] != -1) { + for (i=0; sharedPixels[i].recognizedID != -1; i++) { + if (sharedPixels[i].recognizedID == recognizeMap[posX+x][posY+y]) { if (sharedPixels[i].number >= 0) sharedPixels[i].number = -1; break; } } - if (sharedPixels[i].recognizedID == -1) - { + if (sharedPixels[i].recognizedID == -1) { sharedPixels[i].recognizedID = recognizeMap[posX+x][posY+y]; sharedPixels[i].number = -1; sharedPixels[i+1].recognizedID = -1; @@ -237,101 +220,86 @@ inline int findImageOnScreenShotInPosition(int imageID, int posX, int posY) return 0; } - for (i=0; sharedPixels[i].recognizedID != -1; i++) - { + for (i=0; sharedPixels[i].recognizedID != -1; i++) { if (sharedPixels[i].number > 0) goodPixels += sharedPixels[i].number; } - if (((goodPixels*100)/image[imageID].pixelsNumber) < dirInfo[image[imageID].dirID].optMinImagePercent) return 0; + if (((goodPixels*100)/image[imageID].pixelsNumber) < dirInfo[image[imageID].dirID].optMinImagePercent) + return 0; return goodPixels; } -inline int putImageOnRecognizeMap(BITMAP *bitmap, int posX, int posY, int recognizedID) -{ +inline int putImageOnRecognizeMap(BITMAP *bitmap, int posX, int posY, int recognizedID) { register int x, y, value; register short transparentPixel = makecol16(0, 0, 0); - register short screenShotTransparentPixel = makecol16(255, 0, 255); + /* register short screenShotTransparentPixel = makecol16(255, 0, 255); * unused :S */ for (x = 0; x < bitmap->w; x++) - for (y = 0; y < bitmap->h; y++) - { + for (y = 0; y < bitmap->h; y++) { value = recognizeMap[posX+x][posY+y]; if (((((short *)bitmap->line[y])[x] != transparentPixel) || (!dirInfo[image[recognized[recognizedID].imageID].dirID].optAllowTransparency)) && - (((short *)bitmap->line[y])[x] == ((short *)screenShot->line[posY+y])[posX+x])) - { - if (value == -1) - { + (((short *)bitmap->line[y])[x] == ((short *)screenShot->line[posY+y])[posX+x])) { + if (value == -1) { recognizeMap[posX+x][posY+y] = recognizedID; recognized[recognizedID].ownedPixels++; - } - else - if (recognized[value].goodPixels < recognized[recognizedID].goodPixels) - { + } else if (recognized[value].goodPixels < recognized[recognizedID].goodPixels) { recognized[value].ownedPixels--; recognizeMap[posX+x][posY+y] = recognizedID; recognized[recognizedID].ownedPixels++; - } + } } } return recognized[recognizedID].ownedPixels; } -int cutImageFromTransparentScreenShot(int recognizedID, int posX, int posY) -{ - register int x, y, c; +void cutImageFromTransparentScreenShot(int recognizedID, int posX, int posY) { + register int x, y/*, c*/; register int transparentPixel = makecol16(0, 0, 0); register int screenShotTransparentPixel = makecol16(255, 0, 255); - char buf[100]; + /*char buf[100];*/ BITMAP *bitmap = image[recognized[recognizedID].imageID].bitmap; for (x = 0; x < bitmap->w; x++) - for (y = 0; y < bitmap->h; y++) - { + for (y = 0; y < bitmap->h; y++) { if (((((short *)bitmap->line[y])[x] != transparentPixel) || (!dirInfo[image[recognized[recognizedID].imageID].dirID].optAllowTransparency)) && (((short *)bitmap->line[y])[x] == ((short *)screenShot->line[posY+y])[posX+x])) ((short *)transparentScreenShot->line[posY+y])[posX+x] = screenShotTransparentPixel; } } -int cutImageFromScreenShot(int recognizedID, int posX, int posY) -{ - register int x, y, c; +void cutImageFromScreenShot(int recognizedID, int posX, int posY) { + register int x, y/*, c*/; register int transparentPixel = makecol16(0, 0, 0); register int screenShotTransparentPixel = makecol16(255, 0, 255); - char buf[100]; + /*char buf[100];*/ BITMAP *bitmap = image[recognized[recognizedID].imageID].bitmap; for (x = 0; x < bitmap->w; x++) - for (y = 0; y < bitmap->h; y++) - { + for (y = 0; y < bitmap->h; y++) { if (((((short *)bitmap->line[y])[x] != transparentPixel) || (!dirInfo[image[recognized[recognizedID].imageID].dirID].optAllowTransparency)) && (((short *)bitmap->line[y])[x] == ((short *)screenShot->line[posY+y])[posX+x])) ((short *)screenShot->line[posY+y])[posX+x] = screenShotTransparentPixel; } } -int cutImageFromDEBUGScreenShot(int recognizedID, int posX, int posY) -{ - register int x, y, c, i; +void cutImageFromDEBUGScreenShot(int recognizedID, int posX, int posY) { + register int x, y/*, c, i*/; register int transparentPixel = makecol16(0, 0, 0); register int randomColour = makecol16(128+rand()%128, 128+rand()%128, 128+rand()%128); - char buf[100]; + /*char buf[100];*/ BITMAP *bitmap = image[recognized[recognizedID].imageID].bitmap; - if (DEBUGY < 300) - { + if (DEBUGY < 300) { textprintf(DEBUGScreenShot, font, 320+2, 30+DEBUGY, makecol(255, 255, 255), "%s", image[recognized[recognizedID].imageID].filePath); textprintf(DEBUGScreenShot, font, 320+2+MIN(bitmap->w, 50)+1, 30+9+DEBUGY, makecol(255, 255, 255), "P(%d;%d) D%c L%d", recognized[recognizedID].posX, recognized[recognizedID].posY, image[recognized[recognizedID].imageID].direction, recognized[recognizedID].layer); textprintf(DEBUGScreenShot, font, 320+2+MIN(bitmap->w, 50)+1, 30+18+DEBUGY, makecol(255, 255, 255), "D(%d;%d) Per:%d%%", bitmap->w, bitmap->h, (recognized[recognizedID].goodPixels*100)/recognized[recognizedID].pixelsNumber); } for (x = 0; x < bitmap->w; x++) - for (y = 0; y < bitmap->h; y++) - { + for (y = 0; y < bitmap->h; y++) { if (((((short *)bitmap->line[y])[x] != transparentPixel) || (!dirInfo[image[recognized[recognizedID].imageID].dirID].optAllowTransparency)) && - (((short *)bitmap->line[y])[x] == ((short *)screenShot->line[posY+y])[posX+x])) - { + (((short *)bitmap->line[y])[x] == ((short *)screenShot->line[posY+y])[posX+x])) { ((short *)DEBUGScreenShot->line[posY+y])[posX+x] = randomColour; } if ((((short *)bitmap->line[y])[x] != transparentPixel) && (DEBUGY < 300) && (x < 50)) @@ -340,8 +308,7 @@ int cutImageFromDEBUGScreenShot(int recognizedID, int posX, int posY) DEBUGY += MAX(bitmap->h+20, 40); } -int findImageOnScreenShot(int imageID) -{ +int findImageOnScreenShot(int imageID) { int numberOfRecognizedImages = 0; register int x, y; int i, alreadyExist; @@ -350,6 +317,7 @@ int findImageOnScreenShot(int imageID) short transparentPixel = makecol(0, 0, 0); register short screenShotTransparentPixel = makecol(255, 0, 255); BITMAP *bitmapToFind = image[imageID].bitmap; + /* TODO: use struct cp[] .x, .y and .c and a for */ int cp1x; int cp1y; short cp1c; int cp2x; int cp2y; short cp2c; int cp3x; int cp3y; short cp3c; @@ -357,32 +325,31 @@ int findImageOnScreenShot(int imageID) int cp5x; int cp5y; short cp5c; int newRecognized; - do - { + do { cp1x = rand()%(bitmapToFind->w); cp1y = rand()%(bitmapToFind->h); cp1c = ((short *)bitmapToFind->line[cp1y])[cp1x]; } while (cp1c == transparentPixel); - do - { + + do { cp2x = rand()%(bitmapToFind->w); cp2y = rand()%(bitmapToFind->h); cp2c = ((short *)bitmapToFind->line[cp2y])[cp2x]; } while (cp2c == transparentPixel); - do - { + + do { cp3x = rand()%(bitmapToFind->w); cp3y = rand()%(bitmapToFind->h); cp3c = ((short *)bitmapToFind->line[cp3y])[cp3x]; - } while (cp3c == transparentPixel); - do - { + } while (cp3c == transparentPixel); + + do { cp4x = rand()%(bitmapToFind->w); cp4y = rand()%(bitmapToFind->h); cp4c = ((short *)bitmapToFind->line[cp4y])[cp4x]; - } while (cp4c == transparentPixel); - do - { + } while (cp4c == transparentPixel); + + do { cp5x = rand()%(bitmapToFind->w); cp5y = rand()%(bitmapToFind->h); cp5c = ((short *)bitmapToFind->line[cp5y])[cp5x]; @@ -403,8 +370,7 @@ int findImageOnScreenShot(int imageID) #endif for (x = 0; x < 321-(bitmapToFind->w); x++) - for (y = 0; y < 201-(bitmapToFind->h); y++) - { + for (y = 0; y < 201-(bitmapToFind->h); y++) { if ((((short *)screenShot->line[y+cp1y])[x+cp1x] != cp1c) && (((short *)transparentScreenShot->line[y+cp1y])[x+cp1x] != screenShotTransparentPixel)) continue; @@ -434,20 +400,17 @@ int findImageOnScreenShot(int imageID) tmp = findImageOnScreenShotInPosition(imageID, posX, posY); - if (tmp) - { + if (tmp) { newRecognized = recognizedNumber; alreadyExist = 0; - for (i = 0; i < recognizedNumber; i++) - { + for (i = 0; i < recognizedNumber; i++) { if ((recognized[i].imageID == imageID) && (recognized[i].posX == posX) && - (recognized[i].posY == posY)) - { - alreadyExist = 1; - newRecognized = i; - break; - } + (recognized[i].posY == posY)) { + alreadyExist = 1; + newRecognized = i; + break; + } } recognized[newRecognized].imageID = imageID; recognized[newRecognized].posX = posX; @@ -457,16 +420,14 @@ int findImageOnScreenShot(int imageID) recognized[newRecognized].goodPixelsPercent = (recognized[newRecognized].goodPixels*65536)/image[recognized[newRecognized].imageID].pixelsNumber; recognized[newRecognized].ownedPixels = 0; recognized[newRecognized].pixelsNumber = image[imageID].pixelsNumber; - if (!alreadyExist) - { + if (!alreadyExist) { recognized[newRecognized].layer = actualLayer; recognizedNumber++; dirInfo[image[imageID].dirID].recognizedNumber++; } if (dirInfo[image[imageID].dirID].recognizedNumber > dirInfo[image[imageID].dirID].optMaxRecognizedNumber) return 0; - if (recognizedNumber > 99900) - { + if (recognizedNumber > 99900) { printf("[ERROR] %s\n", "Too many recognized items!"); while (1) {}; } @@ -475,10 +436,9 @@ int findImageOnScreenShot(int imageID) return numberOfRecognizedImages; } -void recognizeScreenShot(int screenShotID) -{ +void recognizeScreenShot(int screenShotID) { char buf[100]; - int x, y; + int x; int i, j, k, l, tmp; short transparentPixel = makecol(0, 0, 0); register short screenShotTransparentPixel = makecol(255, 0, 255); @@ -504,15 +464,13 @@ void recognizeScreenShot(int screenShotID) DEBUGY = 0; for (i = 0; i < 320; i++) for (j = 0; j < 200; j++) - { recognizeMap[i][j] = -1; - } + for (i = 0; i < dirsNumber; i++) dirInfo[i].recognizedNumber = 0; recognizedNow = 0; - do - { + do { recognizedBefore = recognizedNow; recognizedNow = 0; if ((optMaxLayers != 0) && (actualLayer+1 > optMaxLayers)) break; @@ -520,8 +478,7 @@ void recognizeScreenShot(int screenShotID) recognizedBefore = recognizedNumber; printf(" Checking layer nr. %d ... ", actualLayer); - for (x = 0; x < imagesNumber; x++) - { + for (x = 0; x < imagesNumber; x++) { if (dirInfo[image[x].dirID].recognizedNumber < dirInfo[image[x].dirID].optMaxRecognizedNumber) printf("\b\b\b\b% 3d%%", (x*100)/imagesNumber); findImageOnScreenShot(x); @@ -530,12 +487,9 @@ void recognizeScreenShot(int screenShotID) for (i = 0; i < 320; i++) for (j = 0; j < 200; j++) - { recognizeMap[i][j] = -1; - } - for (i = 0; i < recognizedNumber; i++) - { + for (i = 0; i < recognizedNumber; i++) { cutImageFromTransparentScreenShot(i, recognized[i].posX, recognized[i].posY); putImageOnRecognizeMap(image[recognized[i].imageID].bitmap, recognized[i].posX, recognized[i].posY, i); } @@ -549,35 +503,28 @@ void recognizeScreenShot(int screenShotID) for (i = 0; i < recognizedNumber; i++) recognized[i].ownedPixels = 0; - for (;;) - { + while (1) { maxPixelsNumber = 0; maxTotalPixelsNumber = 0; maxPixelsID = -1; - for (i = 0; i < recognizedNumber; i++) - { - if (recognized[i].goodPixels > maxPixelsNumber) - { + for (i = 0; i < recognizedNumber; i++) { + if (recognized[i].goodPixels > maxPixelsNumber) { maxTotalPixelsNumber = 0; maxPixelsNumber = recognized[i].goodPixels; maxPixelsID = i; - } - else - if ((recognized[i].goodPixels == maxPixelsNumber) && (recognized[i].pixelsNumber > maxTotalPixelsNumber)) - { + } else if ((recognized[i].goodPixels == maxPixelsNumber) && (recognized[i].pixelsNumber > maxTotalPixelsNumber)) { maxTotalPixelsNumber = recognized[i].pixelsNumber; maxPixelsID = i; } } - if (maxPixelsNumber != 0) - { + if (maxPixelsNumber != 0) { tmp = findImageOnScreenShotInPosition(recognized[maxPixelsID].imageID, recognized[maxPixelsID].posX, recognized[maxPixelsID].posY); - if (recognized[maxPixelsID].goodPixels != tmp) - { + if (recognized[maxPixelsID].goodPixels != tmp) { recognized[maxPixelsID].goodPixels = tmp; continue; } - totalNumberOfRecognizedImages++; + + totalNumberOfRecognizedImages++; cutImageFromDEBUGScreenShot(maxPixelsID, recognized[maxPixelsID].posX, recognized[maxPixelsID].posY); cutImageFromScreenShot(maxPixelsID, recognized[maxPixelsID].posX, recognized[maxPixelsID].posY); putImageOnRecognizeMap(image[recognized[maxPixelsID].imageID].bitmap, recognized[maxPixelsID].posX, recognized[maxPixelsID].posY, maxPixelsID); @@ -639,8 +586,7 @@ void recognizeScreenShot(int screenShotID) destroy_bitmap(DEBUGScreenShot2); } -void sortListOfScreenShots() -{ +void sortListOfScreenShots() { char *tmpScreenShotsList[MAX_SCREENSHOTS]; int tmpScreenShotsNumber; int i; @@ -648,10 +594,8 @@ void sortListOfScreenShots() struct dirent *file; tmpScreenShotsNumber = 0; - while (file = readdir(dir)) - { - if (match("*.bmp", file->d_name) || match("*.BMP", file->d_name)) - { + while (file = readdir(dir)) { + if (match("*.bmp", file->d_name) || match("*.BMP", file->d_name)) { tmpScreenShotsList[tmpScreenShotsNumber] = (char *) malloc(strlen(file->d_name)+1); strcpy(tmpScreenShotsList[tmpScreenShotsNumber], file->d_name); tmpScreenShotsNumber++; @@ -661,41 +605,32 @@ void sortListOfScreenShots() qsort(tmpScreenShotsList, tmpScreenShotsNumber, sizeof(char *), pstrcmp); - for (i = 0; i < tmpScreenShotsNumber; i++) - { + for (i = 0; i < tmpScreenShotsNumber; i++) screenShotList[i].fileName = tmpScreenShotsList[i]; - } screenShotsNumber = tmpScreenShotsNumber; } -void freeListOfScreenShots() -{ +void freeListOfScreenShots() { int i; for (i = 0; i < screenShotsNumber; i++) - { free(screenShotList[i].fileName); - } screenShotsNumber = 0; } -int countPixels(BITMAP *bitmap) -{ +int countPixels(BITMAP *bitmap) { int x, y, number; int transparentPixel = makecol16(0, 0, 0); number = 0; for (x = 0; x < bitmap->w; x++) - for (y = 0; y < bitmap->h; y++) - { + for (y = 0; y < bitmap->h; y++) if (((short *)bitmap->line[y])[x] != transparentPixel) number++; - } return number; } -void readDir(int dirID) -{ +void readDir(int dirID) { char buf[100]; int i; DIR *dir = opendir(dirInfo[dirID].dirName); @@ -703,26 +638,21 @@ void readDir(int dirID) FILE *optFile; sprintf(buf, "%s" SEPS "bitmaps.cfg", dirInfo[dirID].dirName); - if (optFile = fopen(buf, "r")) - { + if (optFile = fopen(buf, "r")) { fscanf(optFile, "%d", &dirInfo[dirID].optTwoDirections); fscanf(optFile, "%d", &dirInfo[dirID].optMaxRecognizedNumber); fscanf(optFile, "%d", &dirInfo[dirID].optMinImagePercent); fscanf(optFile, "%d", &dirInfo[dirID].optAllowTransparency); fclose(optFile); - } - else - { + } else { dirInfo[dirID].optTwoDirections = 1; dirInfo[dirID].optMaxRecognizedNumber = 99999; dirInfo[dirID].optMinImagePercent = 30; dirInfo[dirID].optAllowTransparency = 1; } - while (file = readdir(dir)) - { - if (match("*.bmp", file->d_name) || match("*.BMP", file->d_name)) - { + while (file = readdir(dir)) { + if (match("*.bmp", file->d_name) || match("*.BMP", file->d_name)) { strcpy(buf, dirInfo[dirID].dirName); strcat(buf, SEPS); strcat(buf, file->d_name); @@ -734,8 +664,7 @@ void readDir(int dirID) image[imagesNumber].dirID = dirID; imagesNumber++; - if (dirInfo[dirID].optTwoDirections) - { + if (dirInfo[dirID].optTwoDirections) { image[imagesNumber].filePath = (char *) malloc(strlen(buf)+1); strcpy(image[imagesNumber].filePath, buf); image[imagesNumber].bitmap = create_bitmap(image[imagesNumber-1].bitmap->w, image[imagesNumber-1].bitmap->h); @@ -750,27 +679,23 @@ void readDir(int dirID) closedir(dir); } -void sortListOfImages() -{ - int i; +void sortListOfImages() { +/* int i;*/ - qsort(image, imagesNumber, sizeof(tImage), cmptImage); + qsort(image, imagesNumber, sizeof(tImage), (void*)cmptImage); } -void freeListOfImages() -{ +void freeListOfImages() { int i; - for (i = 0; i < imagesNumber; i++) - { + for (i = 0; i < imagesNumber; i++) { free(image[i].filePath); destroy_bitmap(image[i].bitmap); } imagesNumber = 0; } -void readParameters() -{ +void readParameters() { int i; strcpy(output, POPRECOG_ABOUT); @@ -782,17 +707,13 @@ void readParameters() sprintf(output, "%s%s\n", output, screenShotsDir); printf("\nStep 2. Type dirs where are stored bitmaps to recognize.\nPlease type in this format: [dirname] [max images on screenshot][ENTER].\nWhen you'll finish type END[ENTER].\n"); - strcat(output, "\nStep 2. Type dirs where are stored bitmaps to recognize.\nPlease type in this format: [dirname] [max images on screenshot][ENTER].\nWhen you'll finish type END[ENTER].\n"); - for (;;) - { + strcat(output, "\nStep 2. Type dirs where are stored bitmaps to recognize.\nPlease type in this format: [dirname] [max images on screenshot][ENTER].\nWhen you'll finish type END[ENTER].\n"); + while (1) { scanf("%s", dirInfo[dirsNumber].dirName); sprintf(output, "%s%s\n", output, dirInfo[dirsNumber].dirName); - if (strcmp(dirInfo[dirsNumber].dirName, "END")) - { + if (strcmp(dirInfo[dirsNumber].dirName, "END")) { dirsNumber++; - } - else - break; + } else break; /* TODO: use a do/while with strcmp as condition */ } printf("\nStep 3. Type number of maximum layers\nHINT:\nIf you'll type 0, poprecog will automatically detect the number of layers,\nbut it is not recommended for tiles, walls, cinematic etc.\n"); @@ -809,8 +730,7 @@ void readParameters() strcat(output, "\n"); } -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { int i; long timeBefore, timeAfter; char buf[100]; @@ -827,22 +747,19 @@ int main(int argc, char *argv[]) sprintf(buf, "%s/%s", optResultsDir, "all_results.txt"); outputFile = fopen(buf, "a"); - if (!outputFile) - { + if (!outputFile) { printf("Cannot open %s for append\n",buf); return -1; - } + } sprintf(buf, "%s/%s", optResultsDir, "small_results.txt"); outputSmallFile = fopen(buf, "a"); - if (!outputFile) - { + if (!outputFile) { printf("Cannot open %s for append\n",buf); return -1; - } + } fprintf(outputFile, output); - for (i = 0; i < dirsNumber; i++) - { + for (i = 0; i < dirsNumber; i++) { printf("Loading bitmaps from dir %s\n", dirInfo[i].dirName); fprintf(outputFile, "Loading bitmaps from dir %s\n", dirInfo[i].dirName); readDir(i);