| 2040 | } |
| 2041 | |
| 2042 | hb_image_t* hb_json_to_image(char *json_image) |
| 2043 | { |
| 2044 | int json_result; |
| 2045 | json_error_t error; |
| 2046 | hb_dict_t * dict; |
| 2047 | int pix_fmt, width, height; |
| 2048 | dict = hb_value_json(json_image); |
| 2049 | json_result = json_unpack_ex(dict, &error, 0, |
| 2050 | "{" |
| 2051 | // Format, Width, Height |
| 2052 | "s:i, s:i, s:i," |
| 2053 | "}", |
| 2054 | "Format", unpack_i(&pix_fmt), |
| 2055 | "Width", unpack_i(&width), |
| 2056 | "Height", unpack_b(&height) |
| 2057 | ); |
| 2058 | if (json_result < 0) |
| 2059 | { |
| 2060 | hb_error("image: json unpack failure: %s", error.text); |
| 2061 | hb_value_free(&dict); |
| 2062 | return NULL; |
| 2063 | } |
| 2064 | |
| 2065 | hb_image_t *image = hb_image_init(pix_fmt, width, height); |
| 2066 | if (image == NULL) |
| 2067 | { |
| 2068 | hb_value_free(&dict); |
| 2069 | return NULL; |
| 2070 | } |
| 2071 | |
| 2072 | hb_value_array_t * planes = NULL; |
| 2073 | json_result = json_unpack_ex(dict, &error, 0, |
| 2074 | "{s:o}", "Planes", unpack_o(&planes)); |
| 2075 | if (json_result < 0) |
| 2076 | { |
| 2077 | hb_error("image::planes: json unpack failure: %s", error.text); |
| 2078 | hb_value_free(&dict); |
| 2079 | return image; |
| 2080 | } |
| 2081 | if (hb_value_type(planes) == HB_VALUE_TYPE_ARRAY) |
| 2082 | { |
| 2083 | int ii, count; |
| 2084 | hb_dict_t *plane_dict; |
| 2085 | count = hb_value_array_len(planes); |
| 2086 | for (ii = 0; ii < count; ii++) |
| 2087 | { |
| 2088 | plane_dict = hb_value_array_get(planes, ii); |
| 2089 | const char *data = NULL; |
| 2090 | int size; |
| 2091 | json_result = json_unpack_ex(plane_dict, &error, 0, |
| 2092 | "{s:i, s:s}", |
| 2093 | "Size", unpack_i(&size), |
| 2094 | "Data", unpack_s(&data)); |
| 2095 | if (json_result < 0) |
| 2096 | { |
| 2097 | hb_error("image::plane::data: json unpack failure: %s", error.text); |
| 2098 | hb_value_free(&dict); |
| 2099 | return image; |
nothing calls this directly
no test coverage detected