Mercurial > hg > forks > libbpg
comparison bpgenc.c @ 18:403c67bcb76a
Use bpg_insert_md() and bpg_add_md_contents() in jpeg_get_metadata() also.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 26 Apr 2017 18:24:15 +0300 |
parents | 91f27e9fdb60 |
children | a9a60da06ae3 |
comparison
equal
deleted
inserted
replaced
17:91f27e9fdb60 | 18:403c67bcb76a |
---|---|
1335 { | 1335 { |
1336 static const char app1_exif[] = "Exif"; | 1336 static const char app1_exif[] = "Exif"; |
1337 static const char app1_xmp[] = "http://ns.adobe.com/xap/1.0/"; | 1337 static const char app1_xmp[] = "http://ns.adobe.com/xap/1.0/"; |
1338 static const char app2_iccp[] = "ICC_PROFILE"; | 1338 static const char app2_iccp[] = "ICC_PROFILE"; |
1339 jpeg_saved_marker_ptr marker; | 1339 jpeg_saved_marker_ptr marker; |
1340 BPGMetaData *md, **plast_md, *first_md; | 1340 BPGMetaData *md_list; |
1341 int has_exif, has_xmp, l, iccp_chunk_count, i; | 1341 int has_exif, has_xmp, l, iccp_chunk_count, i; |
1342 jpeg_saved_marker_ptr iccp_chunks[256]; | 1342 jpeg_saved_marker_ptr iccp_chunks[256]; |
1343 | 1343 |
1344 iccp_chunk_count = 0; | 1344 iccp_chunk_count = 0; |
1345 has_exif = 0; | 1345 has_exif = 0; |
1346 has_xmp = 0; | 1346 has_xmp = 0; |
1347 first_md = NULL; | 1347 md_list = NULL; |
1348 plast_md = &first_md; | |
1349 for (marker = first_marker; marker != NULL; marker = marker->next) { | 1348 for (marker = first_marker; marker != NULL; marker = marker->next) { |
1350 #if 0 | 1349 #if 0 |
1351 printf("marker=APP%d len=%d\n", | 1350 printf("marker=APP%d len=%d\n", |
1352 marker->marker - JPEG_APP0, marker->data_length); | 1351 marker->marker - JPEG_APP0, marker->data_length); |
1353 #endif | 1352 #endif |
1354 if (!has_exif && marker->marker == JPEG_APP0 + 1 && | 1353 if (!has_exif && marker->marker == JPEG_APP0 + 1 && |
1355 marker->data_length > sizeof(app1_exif) && | 1354 marker->data_length > sizeof(app1_exif) && |
1356 !memcmp(marker->data, app1_exif, sizeof(app1_exif))) { | 1355 !memcmp(marker->data, app1_exif, sizeof(app1_exif))) { |
1357 md = bpg_md_alloc(BPG_EXTENSION_TAG_EXIF); | |
1358 l = sizeof(app1_exif); | 1356 l = sizeof(app1_exif); |
1359 md->buf_len = marker->data_length - l; | 1357 bpg_add_md_contents(&md_list, BPG_EXTENSION_TAG_EXIF, marker->data_length - l, marker->data + l); |
1360 md->buf = malloc(md->buf_len); | |
1361 memcpy(md->buf, marker->data + l, md->buf_len); | |
1362 *plast_md = md; | |
1363 plast_md = &md->next; | |
1364 has_exif = 1; | 1358 has_exif = 1; |
1365 } else if (!has_xmp && marker->marker == JPEG_APP0 + 1 && | 1359 } else if (!has_xmp && marker->marker == JPEG_APP0 + 1 && |
1366 marker->data_length > sizeof(app1_xmp) && | 1360 marker->data_length > sizeof(app1_xmp) && |
1367 !memcmp(marker->data, app1_xmp, sizeof(app1_xmp)) && | 1361 !memcmp(marker->data, app1_xmp, sizeof(app1_xmp)) && |
1368 !has_xmp) { | 1362 !has_xmp) { |
1369 md = bpg_md_alloc(BPG_EXTENSION_TAG_XMP); | |
1370 l = sizeof(app1_xmp); | 1363 l = sizeof(app1_xmp); |
1371 md->buf_len = marker->data_length - l; | 1364 bpg_add_md_contents(&md_list, BPG_EXTENSION_TAG_XMP, marker->data_length - l, marker->data + l); |
1372 md->buf = malloc(md->buf_len); | |
1373 memcpy(md->buf, marker->data + l, md->buf_len); | |
1374 *plast_md = md; | |
1375 plast_md = &md->next; | |
1376 has_xmp = 1; | 1365 has_xmp = 1; |
1377 } else if (marker->marker == JPEG_APP0 + 2 && | 1366 } else if (marker->marker == JPEG_APP0 + 2 && |
1378 marker->data_length > (sizeof(app2_iccp) + 2) && | 1367 marker->data_length > (sizeof(app2_iccp) + 2) && |
1379 !memcmp(marker->data, app2_iccp, sizeof(app2_iccp))) { | 1368 !memcmp(marker->data, app2_iccp, sizeof(app2_iccp))) { |
1380 int chunk_count, chunk_index; | 1369 int chunk_count, chunk_index; |
1407 if (!iccp_chunks[i]) | 1396 if (!iccp_chunks[i]) |
1408 break; | 1397 break; |
1409 len += iccp_chunks[i]->data_length - hlen; | 1398 len += iccp_chunks[i]->data_length - hlen; |
1410 } | 1399 } |
1411 if (i == iccp_chunk_count) { | 1400 if (i == iccp_chunk_count) { |
1412 md = bpg_md_alloc(BPG_EXTENSION_TAG_ICCP); | 1401 BPGMetaData *md = bpg_md_alloc(BPG_EXTENSION_TAG_ICCP); |
1413 md->buf_len = len; | 1402 md->buf_len = len; |
1414 md->buf = malloc(md->buf_len); | 1403 md->buf = malloc(md->buf_len); |
1415 idx = 0; | 1404 bpg_insert_md(&md_list, md); |
1416 for(i = 0; i < iccp_chunk_count; i++) { | 1405 for(i = 0, idx = 0; i < iccp_chunk_count; i++) { |
1417 l = iccp_chunks[i]->data_length - hlen; | 1406 l = iccp_chunks[i]->data_length - hlen; |
1418 memcpy(md->buf + idx, iccp_chunks[i]->data + hlen, l); | 1407 memcpy(md->buf + idx, iccp_chunks[i]->data + hlen, l); |
1419 idx += l; | 1408 idx += l; |
1420 } | 1409 } |
1421 assert(idx == len); | 1410 assert(idx == len); |
1422 *plast_md = md; | 1411 } |
1423 plast_md = &md->next; | 1412 } |
1424 } | 1413 return md_list; |
1425 } | |
1426 return first_md; | |
1427 } | 1414 } |
1428 | 1415 |
1429 Image *read_jpeg(BPGMetaData **pmd, FILE *f, | 1416 Image *read_jpeg(BPGMetaData **pmd, FILE *f, |
1430 int out_bit_depth) | 1417 int out_bit_depth) |
1431 { | 1418 { |