diff options
author | Niklas Haas <git@haasn.xyz> | 2017-07-11 01:59:21 +0200 |
---|---|---|
committer | Niklas Haas <git@haasn.xyz> | 2017-07-27 23:51:05 +0200 |
commit | 345bb193fe75ddbf2f21bd295869276b6fa87189 (patch) | |
tree | 319f31b8bb33be3532846916da32f93dd4b8152a /misc/bstr.c | |
parent | f1af6e53f0b043cac2d3f1024d7d91785072f237 (diff) | |
download | mpv-345bb193fe75ddbf2f21bd295869276b6fa87189.tar.bz2 mpv-345bb193fe75ddbf2f21bd295869276b6fa87189.tar.xz |
vo_opengl: support loading custom user textures
Parsing the texture data as raw strings makes the textures the most
portable and self-contained. In order to facilitate different types of
shaders, the parse_user_shader interaction has been changed to instead
have it loop through blocks and call the passed functions for each valid
block parsed. This is more modular and also cleaner, with better code
separation.
Closes #4586.
Diffstat (limited to 'misc/bstr.c')
-rw-r--r-- | misc/bstr.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/misc/bstr.c b/misc/bstr.c index 8c47b447d4..09eb6af25b 100644 --- a/misc/bstr.c +++ b/misc/bstr.c @@ -454,3 +454,40 @@ struct bstr bstr_get_ext(struct bstr s) return (struct bstr){NULL, 0}; return bstr_splice(s, dotpos + 1, s.len); } + +static int h_to_i(unsigned char c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + if (c >= 'a' && c <= 'f') + return c - 'a' + 10; + if (c >= 'A' && c <= 'F') + return c - 'A' + 10; + + return -1; // invalid char +} + +bool bstr_decode_hex(void *talloc_ctx, struct bstr hex, struct bstr *out) +{ + if (!out) + return false; + + char *arr = talloc_array(talloc_ctx, char, hex.len / 2); + int len = 0; + + while (hex.len >= 2) { + int a = h_to_i(hex.start[0]); + int b = h_to_i(hex.start[1]); + hex = bstr_splice(hex, 2, hex.len); + + if (a < 0 || b < 0) { + talloc_free(arr); + return false; + } + + arr[len++] = (a << 4) | b; + } + + *out = (struct bstr){ .start = arr, .len = len }; + return true; +} |