aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2013-05-13 12:56:09 +0000
committerPaul B Mahol <onemda@gmail.com>2013-05-17 11:32:53 +0000
commit3a751eab78602bb9e3c0f371486628cd47f037ed (patch)
treeba8b7b7c5f4efd4438ae608b41fdb76c3628f68b
parent1ec578c010e74fcd899170b3fa8e4c25c4c2c479 (diff)
downloadffmpeg-3a751eab78602bb9e3c0f371486628cd47f037ed.tar.gz
lavu/opt: add AV_OPT_TYPE_COLOR
Signed-off-by: Paul B Mahol <onemda@gmail.com>
-rw-r--r--doc/APIchanges3
-rw-r--r--libavutil/opt.c25
-rw-r--r--libavutil/opt.h1
-rw-r--r--libavutil/version.h2
4 files changed, 29 insertions, 2 deletions
diff --git a/doc/APIchanges b/doc/APIchanges
index 9bb479d002..16c14750d9 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2012-10-22
API changes, most recent first:
+2013-05-17 - xxxxxxx - lavu 52.33.100 - opt.h
+ Add AV_OPT_TYPE_COLOR value to AVOptionType enum.
+
2013-05-13 - xxxxxxx - lavu 52.31.100 - mem.h
Add av_dynarray2_add().
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 0e7a3a85bb..1f0d6d0d65 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -259,7 +259,7 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
if (!val && (o->type != AV_OPT_TYPE_STRING &&
o->type != AV_OPT_TYPE_PIXEL_FMT && o->type != AV_OPT_TYPE_SAMPLE_FMT &&
o->type != AV_OPT_TYPE_IMAGE_SIZE && o->type != AV_OPT_TYPE_VIDEO_RATE &&
- o->type != AV_OPT_TYPE_DURATION))
+ o->type != AV_OPT_TYPE_DURATION && o->type != AV_OPT_TYPE_COLOR))
return AVERROR(EINVAL);
dst = ((uint8_t*)target_obj) + o->offset;
@@ -331,6 +331,16 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as duration\n", val);
return ret;
}
+ break;
+ case AV_OPT_TYPE_COLOR:
+ if (!val) {
+ return 0;
+ } else {
+ ret = av_parse_color(dst, val, -1, obj);
+ if (ret < 0)
+ av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as color\n", val);
+ return ret;
+ }
}
av_log(obj, AV_LOG_ERROR, "Invalid option type.\n");
@@ -617,6 +627,9 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
i64 / 3600000000, (int)((i64 / 60000000) % 60),
(int)((i64 / 1000000) % 60), (int)(i64 % 1000000));
break;
+ case AV_OPT_TYPE_COLOR:
+ ret = snprintf(buf, sizeof(buf), "0x%02x%02x%02x%02x", ((int *)dst)[0], ((int *)dst)[1], ((int *)dst)[2], ((int *)dst)[3]);
+ break;
default:
return AVERROR(EINVAL);
}
@@ -886,6 +899,9 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
case AV_OPT_TYPE_DURATION:
av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<duration>");
break;
+ case AV_OPT_TYPE_COLOR:
+ av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<color>");
+ break;
case AV_OPT_TYPE_CONST:
default:
av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
@@ -978,6 +994,7 @@ void av_opt_set_defaults2(void *s, int mask, int flags)
av_opt_set_q(s, opt->name, val, 0);
}
break;
+ case AV_OPT_TYPE_COLOR:
case AV_OPT_TYPE_STRING:
case AV_OPT_TYPE_IMAGE_SIZE:
case AV_OPT_TYPE_VIDEO_RATE:
@@ -1334,6 +1351,7 @@ int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const ch
case AV_OPT_TYPE_FLOAT:
case AV_OPT_TYPE_DOUBLE:
case AV_OPT_TYPE_DURATION:
+ case AV_OPT_TYPE_COLOR:
break;
case AV_OPT_TYPE_STRING:
range->component_min = 0;
@@ -1400,6 +1418,7 @@ typedef struct TestContext
enum AVPixelFormat pix_fmt;
enum AVSampleFormat sample_fmt;
int64_t duration;
+ uint8_t color[4];
} TestContext;
#define OFFSET(x) offsetof(TestContext, x)
@@ -1422,6 +1441,7 @@ static const AVOption test_options[]= {
{"sample_fmt", "set samplefmt", OFFSET(sample_fmt), AV_OPT_TYPE_SAMPLE_FMT, {.i64 = AV_SAMPLE_FMT_NONE}, -1, AV_SAMPLE_FMT_NB-1},
{"video_rate", "set videorate", OFFSET(video_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0 },
{"duration", "set duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, INT64_MAX},
+{"color", "set color", OFFSET(color), AV_OPT_TYPE_COLOR, {.str = "pink"}, 0, 0},
{NULL},
};
@@ -1480,6 +1500,9 @@ int main(void)
"duration=bogus",
"duration=123.45",
"duration=1\\:23\\:45.67",
+ "color=blue",
+ "color=0x223300",
+ "color=0x42FF07AA",
};
test_ctx.class = &test_class;
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 7f7b54e708..2344aa7b4d 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -232,6 +232,7 @@ enum AVOptionType{
AV_OPT_TYPE_SAMPLE_FMT = MKBETAG('S','F','M','T'),
AV_OPT_TYPE_VIDEO_RATE = MKBETAG('V','R','A','T'), ///< offset must point to AVRational
AV_OPT_TYPE_DURATION = MKBETAG('D','U','R',' '),
+ AV_OPT_TYPE_COLOR = MKBETAG('C','O','L','R'),
#if FF_API_OLD_AVOPTIONS
FF_OPT_TYPE_FLAGS = 0,
FF_OPT_TYPE_INT,
diff --git a/libavutil/version.h b/libavutil/version.h
index 44f4315a0c..a88247b714 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -75,7 +75,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 52
-#define LIBAVUTIL_VERSION_MINOR 32
+#define LIBAVUTIL_VERSION_MINOR 33
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \