Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
void flow_interpolation_line_contributions_destroy(flow_c * context, struct flow_interpolation_line_contributions * p)
{

    if (p != NULL) {
        if (p->ContribRow != NULL) {
            FLOW_free(context, p->ContribRow[0].Weights);
        }
        FLOW_free(context, p->ContribRow);
    }
    FLOW_free(context, p);
}
Exemplo n.º 3
0
bool load_image(flow_c * c, char * checksum, struct flow_bitmap_bgra ** ref, void * bitmap_owner)
{
    char filename[2048];
    if (!create_relative_path(c, false, filename, 2048, "/visuals/%s.png", checksum)) {
        FLOW_add_to_callstack(c);
        return false;
    }

    struct flow_job * job = flow_job_create(c);
    if (job == NULL) {
        FLOW_error_return(c);
    }
    size_t bytes_count;
    uint8_t * bytes = read_all_bytes(c, &bytes_count, filename);
    if (bytes == NULL) {
        FLOW_error_return(c);
    }
    struct flow_io * input = flow_io_create_from_memory(c, flow_io_mode_read_seekable, bytes, bytes_count, job, NULL);
    if (input == NULL) {
        FLOW_error_return(c);
    }
    if (!flow_job_add_io(c, job, input, 0, FLOW_INPUT)) {
        FLOW_error_return(c);
    }

    struct flow_graph * g = flow_graph_create(c, 10, 10, 200, 2.0);
    if (g == NULL) {
        FLOW_add_to_callstack(c);
        return false;
    }
    int32_t last;
    last = flow_node_create_decoder(c, &g, -1, 0);
    last = flow_node_create_bitmap_bgra_reference(c, &g, last, ref);

    if (flow_context_has_error(c)) {
        FLOW_add_to_callstack(c);
        return false;
    }
    if (!flow_job_execute(c, job, &g)) {
        FLOW_add_to_callstack(c);
        return false;
    }

    // Let the bitmap last longer than the job
    if (!flow_set_owner(c, *ref, bitmap_owner)) {
        FLOW_add_to_callstack(c);
        return false;
    }

    if (!flow_job_destroy(c, job)) {
        FLOW_error_return(c);
    }
    FLOW_free(c, bytes);
    return true;
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
void flow_interpolation_details_destroy(flow_c * context, struct flow_interpolation_details * details)
{
    FLOW_free(context, details);
}