2007-10-30 12:49:04 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright 2007 Edgard Lima <edgard.lima@indt.org.br>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the
|
|
|
|
* GNU Lesser General Public License Version 2.1 (the "LGPL"), in
|
|
|
|
* which case the following provisions apply instead of the ones
|
|
|
|
* mentioned above:
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "metadataparsejpeg.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2007-12-04 17:20:25 +00:00
|
|
|
#ifdef HAVE_IPTC
|
2007-10-30 12:49:04 +00:00
|
|
|
#include <libiptcdata/iptc-jpeg.h>
|
2007-12-04 17:20:25 +00:00
|
|
|
#endif
|
2007-10-30 12:49:04 +00:00
|
|
|
|
|
|
|
static int
|
2007-11-30 12:53:13 +00:00
|
|
|
metadataparse_jpeg_reading (JpegParseData * jpeg_data, guint8 ** buf,
|
2007-11-18 21:06:51 +00:00
|
|
|
guint32 * bufsize, const guint32 offset, const guint8 * step_buf,
|
|
|
|
guint8 ** next_start, guint32 * next_size);
|
2007-10-30 12:49:04 +00:00
|
|
|
|
|
|
|
static int
|
2007-11-30 12:53:13 +00:00
|
|
|
metadataparse_jpeg_exif (JpegParseData * jpeg_data, guint8 ** buf,
|
2007-10-30 12:49:04 +00:00
|
|
|
guint32 * bufsize, guint8 ** next_start, guint32 * next_size);
|
|
|
|
|
2007-12-04 17:20:25 +00:00
|
|
|
#ifdef HAVE_IPTC
|
2007-10-30 12:49:04 +00:00
|
|
|
static int
|
2007-11-30 12:53:13 +00:00
|
|
|
metadataparse_jpeg_iptc (JpegParseData * jpeg_data, guint8 ** buf,
|
2007-10-30 12:49:04 +00:00
|
|
|
guint32 * bufsize, guint8 ** next_start, guint32 * next_size);
|
2007-12-04 17:20:25 +00:00
|
|
|
#endif
|
2007-10-30 12:49:04 +00:00
|
|
|
|
2007-11-01 16:04:29 +00:00
|
|
|
static int
|
2007-11-30 12:53:13 +00:00
|
|
|
metadataparse_jpeg_xmp (JpegParseData * jpeg_data, guint8 ** buf,
|
2007-11-01 16:04:29 +00:00
|
|
|
guint32 * bufsize, guint8 ** next_start, guint32 * next_size);
|
|
|
|
|
2007-10-30 12:49:04 +00:00
|
|
|
static int
|
2007-11-30 12:53:13 +00:00
|
|
|
metadataparse_jpeg_jump (JpegParseData * jpeg_data, guint8 ** buf,
|
2007-10-30 12:49:04 +00:00
|
|
|
guint32 * bufsize, guint8 ** next_start, guint32 * next_size);
|
|
|
|
|
|
|
|
#define READ(buf, size) ( (size)--, *((buf)++) )
|
|
|
|
|
|
|
|
void
|
2007-11-30 12:53:13 +00:00
|
|
|
metadataparse_jpeg_lazy_update (JpegParseData * jpeg_data)
|
|
|
|
{
|
|
|
|
/* nothing to do */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
metadataparse_jpeg_init (JpegParseData * jpeg_data, GstAdapter ** exif_adpt,
|
2007-11-23 17:35:21 +00:00
|
|
|
GstAdapter ** iptc_adpt, GstAdapter ** xmp_adpt,
|
|
|
|
MetadataChunkArray * strip_chunks, MetadataChunkArray * inject_chunks)
|
2007-10-30 12:49:04 +00:00
|
|
|
{
|
2007-11-30 12:53:13 +00:00
|
|
|
jpeg_data->state = JPEG_PARSE_NULL;
|
2007-11-23 17:35:21 +00:00
|
|
|
jpeg_data->exif_adapter = exif_adpt;
|
|
|
|
jpeg_data->iptc_adapter = iptc_adpt;
|
|
|
|
jpeg_data->xmp_adapter = xmp_adpt;
|
2007-10-30 12:49:04 +00:00
|
|
|
jpeg_data->read = 0;
|
2007-11-18 21:06:51 +00:00
|
|
|
jpeg_data->jfif_found = FALSE;
|
2007-11-01 16:04:29 +00:00
|
|
|
|
2007-11-23 17:35:21 +00:00
|
|
|
jpeg_data->strip_chunks = strip_chunks;
|
|
|
|
jpeg_data->inject_chunks = inject_chunks;
|
|
|
|
|
2007-10-30 12:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-11-30 12:53:13 +00:00
|
|
|
metadataparse_jpeg_dispose (JpegParseData * jpeg_data)
|
2007-10-30 12:49:04 +00:00
|
|
|
{
|
2007-11-23 17:35:21 +00:00
|
|
|
jpeg_data->exif_adapter = NULL;
|
|
|
|
jpeg_data->iptc_adapter = NULL;
|
|
|
|
jpeg_data->xmp_adapter = NULL;
|
2007-10-30 12:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-11-30 12:53:13 +00:00
|
|
|
metadataparse_jpeg_parse (JpegParseData * jpeg_data, guint8 * buf,
|
2007-11-18 21:06:51 +00:00
|
|
|
guint32 * bufsize, const guint32 offset, guint8 ** next_start,
|
|
|
|
guint32 * next_size)
|
2007-10-30 12:49:04 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
int ret = 0;
|
|
|
|
guint8 mark[2] = { 0x00, 0x00 };
|
2007-11-18 21:06:51 +00:00
|
|
|
const guint8 *step_buf = buf;
|
2007-10-30 12:49:04 +00:00
|
|
|
|
|
|
|
*next_start = buf;
|
|
|
|
|
2007-11-30 12:53:13 +00:00
|
|
|
if (jpeg_data->state == JPEG_PARSE_NULL) {
|
2007-10-30 12:49:04 +00:00
|
|
|
|
|
|
|
if (*bufsize < 2) {
|
|
|
|
*next_size = (buf - *next_start) + 2;
|
|
|
|
ret = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
mark[0] = READ (buf, *bufsize);
|
|
|
|
mark[1] = READ (buf, *bufsize);
|
|
|
|
|
|
|
|
if (mark[0] != 0xFF || mark[1] != 0xD8) {
|
|
|
|
ret = -1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2007-11-30 12:53:13 +00:00
|
|
|
jpeg_data->state = JPEG_PARSE_READING;
|
2007-10-30 12:49:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
while (ret == 0) {
|
|
|
|
switch (jpeg_data->state) {
|
2007-11-30 12:53:13 +00:00
|
|
|
case JPEG_PARSE_READING:
|
2007-10-30 12:49:04 +00:00
|
|
|
ret =
|
2007-11-18 21:06:51 +00:00
|
|
|
metadataparse_jpeg_reading (jpeg_data, &buf, bufsize,
|
|
|
|
offset, step_buf, next_start, next_size);
|
2007-10-30 12:49:04 +00:00
|
|
|
break;
|
2007-11-30 12:53:13 +00:00
|
|
|
case JPEG_PARSE_JUMPING:
|
2007-10-30 12:49:04 +00:00
|
|
|
ret =
|
|
|
|
metadataparse_jpeg_jump (jpeg_data, &buf, bufsize, next_start,
|
|
|
|
next_size);
|
|
|
|
break;
|
2007-11-30 12:53:13 +00:00
|
|
|
case JPEG_PARSE_EXIF:
|
2007-10-30 12:49:04 +00:00
|
|
|
ret =
|
|
|
|
metadataparse_jpeg_exif (jpeg_data, &buf, bufsize, next_start,
|
|
|
|
next_size);
|
|
|
|
break;
|
2007-11-30 12:53:13 +00:00
|
|
|
case JPEG_PARSE_IPTC:
|
2007-12-04 17:20:25 +00:00
|
|
|
#ifdef HAVE_IPTC
|
2007-10-30 12:49:04 +00:00
|
|
|
ret =
|
|
|
|
metadataparse_jpeg_iptc (jpeg_data, &buf, bufsize, next_start,
|
|
|
|
next_size);
|
2007-12-04 17:20:25 +00:00
|
|
|
#endif
|
2007-10-30 12:49:04 +00:00
|
|
|
break;
|
2007-11-30 12:53:13 +00:00
|
|
|
case JPEG_PARSE_XMP:
|
2007-11-01 16:04:29 +00:00
|
|
|
ret =
|
|
|
|
metadataparse_jpeg_xmp (jpeg_data, &buf, bufsize, next_start,
|
|
|
|
next_size);
|
|
|
|
break;
|
2007-11-30 12:53:13 +00:00
|
|
|
case JPEG_PARSE_DONE:
|
2007-10-30 12:49:04 +00:00
|
|
|
goto done;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* look for markers */
|
|
|
|
static int
|
2007-11-30 12:53:13 +00:00
|
|
|
metadataparse_jpeg_reading (JpegParseData * jpeg_data, guint8 ** buf,
|
2007-11-18 21:06:51 +00:00
|
|
|
guint32 * bufsize, const guint32 offset, const guint8 * step_buf,
|
|
|
|
guint8 ** next_start, guint32 * next_size)
|
2007-10-30 12:49:04 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
int ret = -1;
|
|
|
|
guint8 mark[2] = { 0x00, 0x00 };
|
|
|
|
guint16 chunk_size = 0;
|
|
|
|
|
2007-11-18 21:06:51 +00:00
|
|
|
static const char JfifHeader[] = "JFIF";
|
2007-10-30 12:49:04 +00:00
|
|
|
static const unsigned char ExifHeader[] =
|
|
|
|
{ 0x45, 0x78, 0x69, 0x66, 0x00, 0x00 };
|
|
|
|
static const char IptcHeader[] = "Photoshop 3.0";
|
2007-11-01 16:04:29 +00:00
|
|
|
static const char XmpHeader[] = "http://ns.adobe.com/xap/1.0/";
|
2007-10-30 12:49:04 +00:00
|
|
|
|
|
|
|
*next_start = *buf;
|
|
|
|
|
|
|
|
if (*bufsize < 2) {
|
|
|
|
*next_size = (*buf - *next_start) + 2;
|
|
|
|
ret = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
mark[0] = READ (*buf, *bufsize);
|
|
|
|
mark[1] = READ (*buf, *bufsize);
|
|
|
|
|
|
|
|
if (mark[0] == 0xFF) {
|
|
|
|
if (mark[1] == 0xD9) { /* end of image */
|
|
|
|
ret = 0;
|
2007-11-30 12:53:13 +00:00
|
|
|
jpeg_data->state = JPEG_PARSE_DONE;
|
2007-10-30 12:49:04 +00:00
|
|
|
goto done;
|
|
|
|
} else if (mark[1] == 0xDA) { /* start of scan, lets not look behinf of this */
|
|
|
|
ret = 0;
|
2007-11-30 12:53:13 +00:00
|
|
|
jpeg_data->state = JPEG_PARSE_DONE;
|
2007-10-30 12:49:04 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*bufsize < 2) {
|
|
|
|
*next_size = (*buf - *next_start) + 2;
|
|
|
|
ret = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
chunk_size = READ (*buf, *bufsize) << 8;
|
|
|
|
chunk_size += READ (*buf, *bufsize);
|
|
|
|
|
2007-11-18 21:06:51 +00:00
|
|
|
if (mark[1] == 0xE0) { /* may be JFIF */
|
|
|
|
|
|
|
|
if (chunk_size >= 16) {
|
|
|
|
if (*bufsize < 14) {
|
|
|
|
*next_size = (*buf - *next_start) + 14;
|
|
|
|
ret = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 == memcmp (JfifHeader, *buf, 5)) {
|
|
|
|
jpeg_data->jfif_found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (mark[1] == 0xE1) { /* may be it is Exif or XMP */
|
2007-11-01 16:04:29 +00:00
|
|
|
|
2007-10-30 12:49:04 +00:00
|
|
|
if (chunk_size >= 8) { /* size2 'EXIF' 0x00 0x00 */
|
|
|
|
guint8 ch;
|
|
|
|
|
|
|
|
if (*bufsize < 6) {
|
|
|
|
*next_size = (*buf - *next_start) + 6;
|
|
|
|
ret = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2007-11-23 17:35:21 +00:00
|
|
|
if (0 == memcmp (ExifHeader, *buf, 6)) {
|
|
|
|
MetadataChunk chunk;
|
2007-11-18 21:06:51 +00:00
|
|
|
|
2007-11-23 17:35:21 +00:00
|
|
|
memset (&chunk, 0x00, sizeof (MetadataChunk));
|
|
|
|
chunk.offset_orig = (*buf - step_buf) + offset - 4; /* maker + size */
|
|
|
|
chunk.size = chunk_size + 2; /* chunk size plus app marker */
|
2007-11-30 12:53:13 +00:00
|
|
|
chunk.type = MD_CHUNK_EXIF;
|
2007-11-23 17:35:21 +00:00
|
|
|
|
|
|
|
metadata_chunk_array_append_sorted (jpeg_data->strip_chunks, &chunk);
|
|
|
|
|
|
|
|
if (!jpeg_data->jfif_found) {
|
|
|
|
/* only inject if no JFIF has been found */
|
|
|
|
|
|
|
|
static const guint8 segment[] = { 0xff, 0xe0, 0x00, 0x10,
|
|
|
|
0x4a, 0x46, 0x49, 0x46, 0x00,
|
|
|
|
0x01, 0x02,
|
|
|
|
0x00, 0x00, 0x01, 0x00, 0x01,
|
|
|
|
0x00, 0x00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
memset (&chunk, 0x00, sizeof (MetadataChunk));
|
|
|
|
chunk.offset_orig = 2;
|
|
|
|
chunk.size = 18;
|
2007-11-30 12:53:13 +00:00
|
|
|
chunk.type = MD_CHUNK_UNKNOWN;
|
2007-11-23 17:35:21 +00:00
|
|
|
chunk.data = g_new (guint8, 18);
|
|
|
|
memcpy (chunk.data, segment, 18);
|
|
|
|
|
|
|
|
metadata_chunk_array_append_sorted (jpeg_data->inject_chunks,
|
|
|
|
&chunk);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jpeg_data->exif_adapter) {
|
2007-11-18 21:06:51 +00:00
|
|
|
|
2007-11-23 17:35:21 +00:00
|
|
|
jpeg_data->read = chunk_size - 2;
|
2007-11-30 12:53:13 +00:00
|
|
|
jpeg_data->state = JPEG_PARSE_EXIF;
|
2007-11-23 17:35:21 +00:00
|
|
|
ret = 0;
|
2007-10-30 12:49:04 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
2007-11-01 16:04:29 +00:00
|
|
|
if (chunk_size >= 31) { /* size2 "http://ns.adobe.com/xap/1.0/" */
|
|
|
|
if (*bufsize < 29) {
|
|
|
|
*next_size = (*buf - *next_start) + 29;
|
|
|
|
ret = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2007-11-23 17:35:21 +00:00
|
|
|
if (0 == memcmp (XmpHeader, *buf, 29)) {
|
|
|
|
MetadataChunk chunk;
|
|
|
|
|
|
|
|
memset (&chunk, 0x00, sizeof (MetadataChunk));
|
|
|
|
chunk.offset_orig = (*buf - step_buf) + offset - 4; /* maker + size */
|
|
|
|
chunk.size = chunk_size + 2; /* chunk size plus app marker */
|
2007-11-30 12:53:13 +00:00
|
|
|
chunk.type = MD_CHUNK_XMP;
|
2007-11-23 17:35:21 +00:00
|
|
|
|
|
|
|
metadata_chunk_array_append_sorted (jpeg_data->strip_chunks,
|
|
|
|
&chunk);
|
|
|
|
|
|
|
|
/* if adapter has been provided, prepare to hold chunk */
|
|
|
|
if (jpeg_data->xmp_adapter) {
|
2007-11-02 16:50:42 +00:00
|
|
|
*buf += 29;
|
|
|
|
*bufsize -= 29;
|
|
|
|
jpeg_data->read = chunk_size - 2 - 29;
|
2007-11-30 12:53:13 +00:00
|
|
|
jpeg_data->state = JPEG_PARSE_XMP;
|
2007-11-23 17:35:21 +00:00
|
|
|
ret = 0;
|
2007-11-01 16:04:29 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-30 12:49:04 +00:00
|
|
|
}
|
2007-12-04 17:20:25 +00:00
|
|
|
}
|
|
|
|
#ifdef HAVE_IPTC
|
|
|
|
else if (mark[1] == 0xED) { /* may be it is photoshop and may be there is iptc */
|
2007-10-30 12:49:04 +00:00
|
|
|
if (chunk_size >= 16) { /* size2 "Photoshop 3.0" */
|
|
|
|
|
|
|
|
if (*bufsize < 14) {
|
|
|
|
*next_size = (*buf - *next_start) + 14;
|
|
|
|
ret = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2007-11-23 17:35:21 +00:00
|
|
|
|
|
|
|
if (0 == memcmp (IptcHeader, *buf, 14)) {
|
|
|
|
MetadataChunk chunk;
|
|
|
|
|
|
|
|
memset (&chunk, 0x00, sizeof (MetadataChunk));
|
|
|
|
chunk.offset_orig = (*buf - step_buf) + offset - 4; /* maker + size */
|
|
|
|
chunk.size = chunk_size + 2; /* chunk size plus app marker */
|
2007-11-30 12:53:13 +00:00
|
|
|
chunk.type = MD_CHUNK_IPTC;
|
2007-11-23 17:35:21 +00:00
|
|
|
|
|
|
|
metadata_chunk_array_append_sorted (jpeg_data->strip_chunks, &chunk);
|
|
|
|
|
|
|
|
/* if adapter has been provided, prepare to hold chunk */
|
|
|
|
if (jpeg_data->iptc_adapter) {
|
2007-10-30 12:49:04 +00:00
|
|
|
jpeg_data->read = chunk_size - 2;
|
2007-11-30 12:53:13 +00:00
|
|
|
jpeg_data->state = JPEG_PARSE_IPTC;
|
2007-11-23 17:35:21 +00:00
|
|
|
ret = 0;
|
2007-10-30 12:49:04 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-12-04 17:20:25 +00:00
|
|
|
#endif /* #ifdef HAVE_IPTC */
|
2007-10-30 12:49:04 +00:00
|
|
|
|
|
|
|
/* just set jump sise */
|
|
|
|
jpeg_data->read = chunk_size - 2;
|
2007-11-30 12:53:13 +00:00
|
|
|
jpeg_data->state = JPEG_PARSE_JUMPING;
|
2007-10-30 12:49:04 +00:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* invalid JPEG chunk */
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-11-30 12:53:13 +00:00
|
|
|
metadataparse_jpeg_exif (JpegParseData * jpeg_data, guint8 ** buf,
|
2007-11-02 16:50:42 +00:00
|
|
|
guint32 * bufsize, guint8 ** next_start, guint32 * next_size)
|
2007-10-30 12:49:04 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2007-11-02 16:50:42 +00:00
|
|
|
ret = metadataparse_util_hold_chunk (&jpeg_data->read, buf,
|
2007-11-23 17:35:21 +00:00
|
|
|
bufsize, next_start, next_size, jpeg_data->exif_adapter);
|
2007-11-02 16:50:42 +00:00
|
|
|
if (ret == 0) {
|
2007-11-18 21:06:51 +00:00
|
|
|
|
2007-11-30 12:53:13 +00:00
|
|
|
jpeg_data->state = JPEG_PARSE_READING;
|
2007-11-18 21:06:51 +00:00
|
|
|
|
|
|
|
/* if there is a second Exif chunk in the file it will be jumped */
|
2007-11-23 17:35:21 +00:00
|
|
|
jpeg_data->exif_adapter = NULL;
|
2007-10-30 12:49:04 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-12-04 17:20:25 +00:00
|
|
|
#ifdef HAVE_IPTC
|
2007-10-30 12:49:04 +00:00
|
|
|
static int
|
2007-11-30 12:53:13 +00:00
|
|
|
metadataparse_jpeg_iptc (JpegParseData * jpeg_data, guint8 ** buf,
|
2007-10-30 12:49:04 +00:00
|
|
|
guint32 * bufsize, guint8 ** next_start, guint32 * next_size)
|
|
|
|
{
|
|
|
|
|
|
|
|
int ret;
|
|
|
|
|
2007-11-02 16:50:42 +00:00
|
|
|
ret = metadataparse_util_hold_chunk (&jpeg_data->read, buf,
|
2007-11-23 17:35:21 +00:00
|
|
|
bufsize, next_start, next_size, jpeg_data->iptc_adapter);
|
2007-10-30 12:49:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (ret == 0) {
|
|
|
|
|
|
|
|
const guint8 *buf;
|
|
|
|
guint32 size;
|
|
|
|
unsigned int iptc_len;
|
|
|
|
int res;
|
|
|
|
|
2007-11-30 12:53:13 +00:00
|
|
|
jpeg_data->state = JPEG_PARSE_READING;
|
2007-11-02 16:50:42 +00:00
|
|
|
|
2007-11-23 17:35:21 +00:00
|
|
|
size = gst_adapter_available (*jpeg_data->iptc_adapter);
|
|
|
|
buf = gst_adapter_peek (*jpeg_data->iptc_adapter, size);
|
2007-10-30 12:49:04 +00:00
|
|
|
|
|
|
|
res = iptc_jpeg_ps3_find_iptc (buf, size, &iptc_len);
|
|
|
|
|
|
|
|
if (res < 0) {
|
|
|
|
/* error */
|
|
|
|
ret = -1;
|
|
|
|
} else if (res == 0) {
|
|
|
|
/* no iptc data found */
|
2007-11-23 17:35:21 +00:00
|
|
|
gst_adapter_clear (*jpeg_data->iptc_adapter);
|
2007-10-30 12:49:04 +00:00
|
|
|
} else {
|
2007-11-23 17:35:21 +00:00
|
|
|
gst_adapter_flush (*jpeg_data->iptc_adapter, res);
|
|
|
|
size = gst_adapter_available (*jpeg_data->iptc_adapter);
|
2007-10-30 12:49:04 +00:00
|
|
|
if (size > iptc_len) {
|
|
|
|
GstBuffer *buf;
|
|
|
|
|
2007-11-23 17:35:21 +00:00
|
|
|
buf = gst_adapter_take_buffer (*jpeg_data->iptc_adapter, iptc_len);
|
|
|
|
gst_adapter_clear (*jpeg_data->iptc_adapter);
|
|
|
|
gst_adapter_push (*jpeg_data->iptc_adapter, buf);
|
2007-10-30 12:49:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-18 21:06:51 +00:00
|
|
|
/* if there is a second Iptc chunk in the file it will be jumped */
|
2007-11-23 17:35:21 +00:00
|
|
|
jpeg_data->iptc_adapter = NULL;
|
2007-11-18 21:06:51 +00:00
|
|
|
|
2007-10-30 12:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
2007-12-04 17:20:25 +00:00
|
|
|
#endif
|
2007-10-30 12:49:04 +00:00
|
|
|
|
2007-11-01 16:04:29 +00:00
|
|
|
static int
|
2007-11-30 12:53:13 +00:00
|
|
|
metadataparse_jpeg_xmp (JpegParseData * jpeg_data, guint8 ** buf,
|
2007-11-01 16:04:29 +00:00
|
|
|
guint32 * bufsize, guint8 ** next_start, guint32 * next_size)
|
|
|
|
{
|
2007-11-02 16:50:42 +00:00
|
|
|
int ret;
|
2007-11-01 16:04:29 +00:00
|
|
|
|
2007-11-02 16:50:42 +00:00
|
|
|
ret = metadataparse_util_hold_chunk (&jpeg_data->read, buf,
|
2007-11-23 17:35:21 +00:00
|
|
|
bufsize, next_start, next_size, jpeg_data->xmp_adapter);
|
2007-11-01 16:04:29 +00:00
|
|
|
|
2007-11-02 16:50:42 +00:00
|
|
|
if (ret == 0) {
|
2007-11-30 12:53:13 +00:00
|
|
|
jpeg_data->state = JPEG_PARSE_READING;
|
2007-11-18 21:06:51 +00:00
|
|
|
/* if there is a second XMP chunk in the file it will be jumped */
|
2007-11-23 17:35:21 +00:00
|
|
|
jpeg_data->xmp_adapter = NULL;
|
2007-11-02 16:50:42 +00:00
|
|
|
}
|
|
|
|
return ret;
|
2007-11-01 16:04:29 +00:00
|
|
|
}
|
|
|
|
|
2007-10-30 12:49:04 +00:00
|
|
|
static int
|
2007-11-30 12:53:13 +00:00
|
|
|
metadataparse_jpeg_jump (JpegParseData * jpeg_data, guint8 ** buf,
|
2007-10-30 12:49:04 +00:00
|
|
|
guint32 * bufsize, guint8 ** next_start, guint32 * next_size)
|
|
|
|
{
|
2007-11-30 12:53:13 +00:00
|
|
|
jpeg_data->state = JPEG_PARSE_READING;
|
2007-11-02 16:50:42 +00:00
|
|
|
return metadataparse_util_jump_chunk (&jpeg_data->read, buf,
|
|
|
|
bufsize, next_start, next_size);
|
2007-10-30 12:49:04 +00:00
|
|
|
}
|