openjpeg: Add support for the colorspace field in the caps

This commit is contained in:
Sebastian Dröge 2012-12-15 11:25:36 +01:00
parent e9fc332e25
commit 8547618f96
3 changed files with 27 additions and 1 deletions

View file

@ -187,11 +187,14 @@ gst_openjpeg_dec_set_format (GstVideoDecoder * decoder,
{
GstOpenJPEGDec *self = GST_OPENJPEG_DEC (decoder);
GstStructure *s;
const gchar *color_space;
GST_DEBUG_OBJECT (self, "Setting format: %" GST_PTR_FORMAT, state->caps);
s = gst_caps_get_structure (state->caps, 0);
self->color_space = CLRSPC_UNKNOWN;
if (gst_structure_has_name (s, "image/jp2")) {
self->codec_format = CODEC_JP2;
self->is_jp2c = FALSE;
@ -205,6 +208,14 @@ gst_openjpeg_dec_set_format (GstVideoDecoder * decoder,
g_return_val_if_reached (FALSE);
}
color_space = gst_structure_get_string (s, "colorspace");
if (g_str_equal (color_space, "sRGB"))
self->color_space = CLRSPC_SRGB;
else if (g_str_equal (color_space, "GRAY"))
self->color_space = CLRSPC_GRAY;
else if (g_str_equal (color_space, "sYUV"))
self->color_space = CLRSPC_SYCC;
if (self->input_state)
gst_video_codec_state_unref (self->input_state);
self->input_state = gst_video_codec_state_ref (state);
@ -541,6 +552,9 @@ gst_openjpeg_dec_negotiate (GstOpenJPEGDec * self, opj_image_t * image)
GstVideoFormat format;
gint width, height;
if (image->color_space == CLRSPC_UNKNOWN)
image->color_space = self->color_space;
switch (image->color_space) {
case CLRSPC_SRGB:
if (image->numcomps == 4) {

View file

@ -53,6 +53,7 @@ struct _GstOpenJPEGDec
OPJ_CODEC_FORMAT codec_format;
gboolean is_jp2c;
OPJ_COLOR_SPACE color_space;
void (*fill_frame) (GstVideoFrame *frame, opj_image_t * image);

View file

@ -354,6 +354,7 @@ gst_openjpeg_enc_set_format (GstVideoEncoder * encoder,
GstOpenJPEGEnc *self = GST_OPENJPEG_ENC (encoder);
GstCaps *allowed_caps, *caps;
GstStructure *s;
const gchar *colorspace;
GST_DEBUG_OBJECT (self, "Setting format: %" GST_PTR_FORMAT, state->caps);
@ -419,7 +420,17 @@ gst_openjpeg_enc_set_format (GstVideoEncoder * encoder,
g_assert_not_reached ();
}
caps = gst_caps_new_empty_simple (gst_structure_get_name (s));
if ((state->info.finfo->flags & GST_VIDEO_FORMAT_FLAG_YUV))
colorspace = "sYUV";
else if ((state->info.finfo->flags & GST_VIDEO_FORMAT_FLAG_RGB))
colorspace = "sRGB";
else if ((state->info.finfo->flags & GST_VIDEO_FORMAT_FLAG_GRAY))
colorspace = "GRAY";
else
g_return_val_if_reached (FALSE);
caps = gst_caps_new_simple (gst_structure_get_name (s),
"colorspace", G_TYPE_STRING, colorspace, NULL);
gst_caps_unref (allowed_caps);
if (self->output_state)