From 921d37dd06604def8054df0ec76ecbadf736b470 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Tue, 29 Nov 2016 11:36:41 +0100 Subject: [PATCH] jpeg: handle Spatial RDF metadata coded as XML data Signed-off-by: Jean-Baptiste Kempf --- modules/codec/jpeg.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/modules/codec/jpeg.c b/modules/codec/jpeg.c index 62dec077fc..60f60c343b 100644 --- a/modules/codec/jpeg.c +++ b/modules/codec/jpeg.c @@ -256,11 +256,23 @@ static bool getRDFFloat(const char *psz_rdf, float *out, const char *psz_var) return false; size_t varlen = strlen(psz_var); - char *p_end = strchr(p_start + varlen, '"'); + p_start += varlen; + char *p_end = NULL; + /* XML style */ + if (p_start[0] == '>') + { + p_start += 1; + p_end = strchr(p_start, '<'); + } + else if (p_start[0] == '=' && p_start[1] == '"') + { + p_start += 2; + p_end = strchr(p_start, '"'); + } if (unlikely(p_end == NULL || p_end == p_start + 1)) return false; - *out = us_strtof(p_start + varlen, NULL); + *out = us_strtof(p_start, NULL); return true; } @@ -296,31 +308,32 @@ static void jpeg_GetProjection(j_decompress_ptr cinfo, video_format_t *fmt) /* Try to find the string "GSpherical:Spherical" because the v1 spherical video spec says the tag must be there. */ - if (strcasestr(psz_rdf, "ProjectionType=\"equirectangular\"")) + if (strcasestr(psz_rdf, "ProjectionType=\"equirectangular\"") || + strcasestr(psz_rdf, "ProjectionType>equirectangular")) fmt->projection_mode = PROJECTION_MODE_EQUIRECTANGULAR; /* pose handling */ float value; - if (getRDFFloat(psz_rdf, &value, "PoseHeadingDegrees=\"")) + if (getRDFFloat(psz_rdf, &value, "PoseHeadingDegrees")) fmt->pose.f_yaw_degrees = value; - if (getRDFFloat(psz_rdf, &value, "PosePitchDegrees=\"")) + if (getRDFFloat(psz_rdf, &value, "PosePitchDegrees")) fmt->pose.f_pitch_degrees = value; - if (getRDFFloat(psz_rdf, &value, "PoseRollDegrees=\"")) + if (getRDFFloat(psz_rdf, &value, "PoseRollDegrees")) fmt->pose.f_roll_degrees = value; /* initial view */ - if (getRDFFloat(psz_rdf, &value, "InitialViewHeadingDegrees=\"")) + if (getRDFFloat(psz_rdf, &value, "InitialViewHeadingDegrees")) fmt->pose.f_yaw_degrees = value; - if (getRDFFloat(psz_rdf, &value, "InitialViewPitchDegrees=\"")) + if (getRDFFloat(psz_rdf, &value, "InitialViewPitchDegrees")) fmt->pose.f_pitch_degrees = value; - if (getRDFFloat(psz_rdf, &value, "InitialViewRollDegrees=\"")) + if (getRDFFloat(psz_rdf, &value, "InitialViewRollDegrees")) fmt->pose.f_roll_degrees = value; - if (getRDFFloat(psz_rdf, &value, "InitialHorizontalFOVDegrees=\"")) + if (getRDFFloat(psz_rdf, &value, "InitialHorizontalFOVDegrees")) fmt->pose.f_fov_degrees = value; free(psz_rdf);