diff options
author | Edgard Lima <edgard.lima@indt.org.br> | 2007-12-04 16:42:25 +0000 |
---|---|---|
committer | Edgard Lima <edgard.lima@indt.org.br> | 2007-12-04 16:42:25 +0000 |
commit | cf4c5c965553c2c216561e4868621b82bf0a1ab5 (patch) | |
tree | 2ab6c51be66c50014a94aeaaedab678460e27aad /ext/metadata/metadatamuxpng.c | |
parent | cef8e5fe609ea6af4beae2f84d7d3fcd62d0a62f (diff) | |
download | gst-plugins-bad-cf4c5c965553c2c216561e4868621b82bf0a1ab5.tar.gz gst-plugins-bad-cf4c5c965553c2c216561e4868621b82bf0a1ab5.tar.bz2 gst-plugins-bad-cf4c5c965553c2c216561e4868621b82bf0a1ab5.zip |
Fixed element properties and now muxer writes to png also.
Original commit message from CVS:
Fixed element properties and now muxer writes to png also.
Diffstat (limited to 'ext/metadata/metadatamuxpng.c')
-rw-r--r-- | ext/metadata/metadatamuxpng.c | 109 |
1 files changed, 98 insertions, 11 deletions
diff --git a/ext/metadata/metadatamuxpng.c b/ext/metadata/metadatamuxpng.c index afcd380b..8aa17383 100644 --- a/ext/metadata/metadatamuxpng.c +++ b/ext/metadata/metadatamuxpng.c @@ -52,30 +52,120 @@ metadatamux_png_reading (PngMuxData * png_data, guint8 ** buf, #define READ(buf, size) ( (size)--, *((buf)++) ) +static void +make_crc_table (guint32 crc_table[]) +{ + guint32 c; + guint16 n, k; + + for (n = 0; n < 256; n++) { + c = (guint32) n; + for (k = 0; k < 8; k++) { + if (c & 1) + c = 0xedb88320L ^ (c >> 1); + else + c = c >> 1; + } + crc_table[n] = c; + } +} + +static guint32 +update_crc (guint32 crc, guint8 * buf, guint32 len) +{ + guint32 c = crc; + guint32 n; + guint32 crc_table[256]; + + /* FIXME: make_crc_table should be done once in life + for speed up */ + make_crc_table (crc_table); + + for (n = 0; n < len; n++) { + c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8); + } + return c; +} + +/* Return the CRC of the bytes buf[0..len-1]. */ +static guint32 +calc_crc (guint8 * buf, guint32 len) +{ + return update_crc (0xffffffffL, buf, len) ^ 0xffffffffL; +} + + +static void +metadatamux_wrap_xmp_chunk (MetadataChunk * chunk) +{ + static const char XmpHeader[] = "XML:com.adobe.xmp"; + guint8 *data = NULL; + guint32 crc; + + data = g_new (guint8, 12 + 18 + 4 + chunk->size); + + memcpy (data + 8, XmpHeader, 18); + memset (data + 8 + 18, 0x00, 4); + memcpy (data + 8 + 18 + 4, chunk->data, chunk->size); + g_free (chunk->data); + chunk->data = data; + chunk->size += 18 + 4; + data[0] = (chunk->size >> 24) & 0xFF; + data[1] = (chunk->size >> 16) & 0xFF; + data[2] = (chunk->size >> 8) & 0xFF; + data[3] = chunk->size & 0xFF; + data[4] = 'i'; + data[5] = 'T'; + data[6] = 'X'; + data[7] = 't'; + crc = calc_crc (data + 4, chunk->size + 4 + 18); + data[chunk->size + 8] = (crc >> 24) & 0xFF; + data[chunk->size + 9] = (crc >> 16) & 0xFF; + data[chunk->size + 10] = (crc >> 8) & 0xFF; + data[chunk->size + 11] = crc & 0xFF; + chunk->size += 12; + +} + void -metadatamux_png_lazy_update (PngMuxData * jpeg_data) +metadatamux_png_lazy_update (PngMuxData * png_data) { - /* nothing to do */ + gsize i; + + for (i = 0; i < png_data->inject_chunks->len; ++i) { + if (png_data->inject_chunks->chunk[i].size > 0 && + png_data->inject_chunks->chunk[i].data) { + switch (png_data->inject_chunks->chunk[i].type) { + case MD_CHUNK_XMP: + { + metadatamux_wrap_xmp_chunk (&png_data->inject_chunks->chunk[i]); + } + break; + default: + GST_ERROR ("Unexpected chunk for PNG muxer."); + break; + } + } + } } void -metadatamux_png_init (PngMuxData * png_data, GstAdapter ** exif_adpt, - GstAdapter ** iptc_adpt, GstAdapter ** xmp_adpt, +metadatamux_png_init (PngMuxData * png_data, MetadataChunkArray * strip_chunks, MetadataChunkArray * inject_chunks) { png_data->state = PNG_MUX_NULL; - png_data->xmp_adapter = xmp_adpt; - png_data->read = 0; png_data->strip_chunks = strip_chunks; png_data->inject_chunks = inject_chunks; - } void metadatamux_png_dispose (PngMuxData * png_data) { - png_data->xmp_adapter = NULL; + png_data->strip_chunks = NULL; + png_data->inject_chunks = NULL; + + png_data->state = PNG_MUX_NULL; } int @@ -118,9 +208,6 @@ metadatamux_png_parse (PngMuxData * png_data, guint8 * buf, } - /* JUST UNTIL NOT IMPLEMENTED */ - return 0; - while (ret == 0) { switch (png_data->state) { case PNG_MUX_READING: |