static struct flow_interpolation_line_contributions * LineContributions_alloc(flow_c * context, const uint32_t line_length, const uint32_t windows_size) { struct flow_interpolation_line_contributions * res = (struct flow_interpolation_line_contributions *)FLOW_malloc( context, sizeof(struct flow_interpolation_line_contributions)); if (res == NULL) { FLOW_error(context, flow_status_Out_of_memory); return NULL; } res->WindowSize = windows_size; res->LineLength = line_length; res->ContribRow = (struct flow_interpolation_pixel_contributions *)FLOW_malloc( context, line_length * sizeof(struct flow_interpolation_pixel_contributions)); if (!res->ContribRow) { FLOW_free(context, res); FLOW_error(context, flow_status_Out_of_memory); return NULL; } float * allWeights = FLOW_calloc_array(context, windows_size * line_length, float); if (!allWeights) { FLOW_free(context, res->ContribRow); FLOW_free(context, res); FLOW_error(context, flow_status_Out_of_memory); return NULL; } for (uint32_t i = 0; i < line_length; i++) res->ContribRow[i].Weights = allWeights + (i * windows_size); return res; }
static double get_dssim_from_command(flow_c * c, const char * command) { FILE * fd; #ifdef _MSC_VER fd = _popen(command, "r"); #else fd = popen(command, "r"); #endif if (!fd) return 200; char buffer[256]; size_t chread; /* String to store entire command contents in */ size_t comalloc = 256; size_t comlen = 0; char * comout = (char *)FLOW_malloc(c, comalloc); /* Use fread so binary data is dealt with correctly */ while ((chread = fread(buffer, 1, sizeof(buffer), fd)) != 0) { if (comlen + chread >= comalloc) { comalloc *= 2; comout = (char *)FLOW_realloc(c, comout, comalloc); } memmove(comout + comlen, buffer, chread); comlen += chread; } #ifdef _MSC_VER int exit_code = _pclose(fd); #else int exit_code = pclose(fd); #endif /* We can now work with the output as we please. Just print * out to confirm output is as expected */ // fwrite(comout, 1, comlen, stdout); double result = 125; if (exit_code == 0) { result = strtold(comout, NULL); } FLOW_free(c, comout); return result; }