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; }
bool load_image(flow_c * c, char * checksum, struct flow_bitmap_bgra ** ref, void * bitmap_owner, const char * storage_relative_to) { char filename[2048]; if (!create_path_from_relative(c, storage_relative_to, false, filename, 2048, "/visuals/%s.png", checksum)) { FLOW_add_to_callstack(c); return false; } // load PNG if (!flow_bitmap_bgra_load_png(c, ref, filename)) { 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; } return true; }