void kv_ident(img_t *image, kv_screen_t *ksp, kv_ident_t which) { int i, ndone; double score, checkthresh; kv_mask_t *kmp; bzero(ksp, sizeof (*ksp)); for (i = 0; i < kv_nmasks; i++) { kmp = &kv_masks[i]; if (!(which & KV_IDENT_CHARS) && KV_MASK_CHAR(kmp->km_name)) continue; if (!(which & KV_IDENT_START) && KV_MASK_LAKITU(kmp->km_name)) continue; if (!(which & KV_IDENT_TRACK) && KV_MASK_TRACK(kmp->km_name)) continue; if (!(which & KV_IDENT_ITEM) && KV_MASK_ITEM(kmp->km_name)) continue; score = img_compare(image, kmp->km_image, NULL); if (kv_debug > 1) (void) printf("mask %s: %f\n", kmp->km_name, score); if (KV_MASK_CHAR(kmp->km_name)) checkthresh = KV_THRESHOLD_CHAR; else if (KV_MASK_LAKITU(kmp->km_name)) checkthresh = KV_THRESHOLD_LAKITU; else if (KV_MASK_ITEM(kmp->km_name) && strstr(kmp->km_name, "box_frame") != NULL) checkthresh = KV_THRESHOLD_ITEMFRAME; else if (KV_MASK_ITEM(kmp->km_name)) checkthresh = KV_THRESHOLD_ITEM; else checkthresh = KV_THRESHOLD_TRACK; if (score > checkthresh) continue; kv_ident_matches(ksp, kmp->km_name, score); } ndone = 0; for (i = 0; i < ksp->ks_nplayers; i++) { if (ksp->ks_players[i].kp_lapnum == 4) ndone++; } if (ndone >= ksp->ks_nplayers - 1) ksp->ks_events |= KVE_RACE_DONE; }
/* * compare image mask: compute a difference score for the given image and mask. */ static int cmd_compare(int argc, char *argv[]) { img_t *image, *mask, *dbgmask; char *dbgfile = NULL; int rv; char c; while ((c = getopt(argc, argv, "s:")) != -1) { switch (c) { case 's': dbgfile = optarg; break; default: return (EXIT_USAGE); } } if (optind + 2 > argc) return (EXIT_USAGE); image = img_read(argv[optind++]); mask = img_read(argv[optind++]); if (mask == NULL || image == NULL) { img_free(image); return (EXIT_FAILURE); } if (image->img_width != mask->img_width || image->img_height != mask->img_height) { warnx("image dimensions do not match"); rv = EXIT_FAILURE; goto done; } (void) printf("%f\n", img_compare(image, mask, dbgfile ? &dbgmask : NULL)); if (dbgfile != NULL && dbgmask != NULL) { (void) img_write(dbgmask, dbgfile); img_free(dbgmask); } rv = EXIT_SUCCESS; done: img_free(image); img_free(mask); return (rv); }
static int create_test(const char* src, const char* dst_png, const char* dst_bmp) { int rc = -1; int ret = -1; int status; size_t bsize; void* buffer = NULL; wImage* image = NULL, *image2 = NULL, *image3 = NULL, *image4 = NULL; if (!PathFileExistsA(src)) { fprintf(stderr, "File %s does not exist!", src); return -1; } image = get_image(src); /* Read from file using image methods. */ if (!image) goto cleanup; /* Write different formats to tmp. */ image->type = WINPR_IMAGE_BITMAP; status = winpr_image_write(image, dst_bmp); if (status < 0) { fprintf(stderr, "Failed to write image %s!\n", dst_bmp); goto cleanup; } image->type = WINPR_IMAGE_PNG; status = winpr_image_write(image, dst_png); if (status < 0) { fprintf(stderr, "Failed to write image %s!\n", dst_png); goto cleanup; } /* Read image from buffer, compare. */ buffer = read_image(src, &bsize); if (!buffer) { fprintf(stderr, "Failed to read image %s!\n", src); goto cleanup; } image2 = winpr_image_new(); if (!image2) { fprintf(stderr, "Failed to create image!\n"); goto cleanup; } status = winpr_image_read_buffer(image2, buffer, bsize); if (status < 0) { fprintf(stderr, "Failed to read buffer!\n"); goto cleanup; } rc = img_compare(image, image2, TRUE); if (rc) goto cleanup; image3 = get_image(dst_png); if (!image3) goto cleanup; rc = img_compare(image, image3, TRUE); if (rc) goto cleanup; image4 = get_image(dst_bmp); if (!image4) goto cleanup; rc = img_compare(image, image4, TRUE); if (rc) goto cleanup; ret = 0; cleanup: if (image) winpr_image_free(image, TRUE); if (image2) winpr_image_free(image2, TRUE); if (image3) winpr_image_free(image3, TRUE); if (image4) winpr_image_free(image4, TRUE); free(buffer); return ret; }