1 // Copyright 2012 Google Inc. All Rights Reserved. 2 // 3 // Use of this source code is governed by a BSD-style license 4 // that can be found in the COPYING file in the root of the source 5 // tree. An additional intellectual property rights grant can be found 6 // in the file PATENTS. All contributing project authors may 7 // be found in the AUTHORS file in the root of the source tree. 8 // ----------------------------------------------------------------------------- 9 // 10 // Metadata types and functions. 11 // 12 13 #include "./metadata.h" 14 15 #include <stdlib.h> 16 #include <string.h> 17 18 #include "webp/types.h" 19 MetadataInit(Metadata * const metadata)20void MetadataInit(Metadata* const metadata) { 21 if (metadata == NULL) return; 22 memset(metadata, 0, sizeof(*metadata)); 23 } 24 MetadataPayloadDelete(MetadataPayload * const payload)25void MetadataPayloadDelete(MetadataPayload* const payload) { 26 if (payload == NULL) return; 27 free(payload->bytes); 28 payload->bytes = NULL; 29 payload->size = 0; 30 } 31 MetadataFree(Metadata * const metadata)32void MetadataFree(Metadata* const metadata) { 33 if (metadata == NULL) return; 34 MetadataPayloadDelete(&metadata->exif); 35 MetadataPayloadDelete(&metadata->iccp); 36 MetadataPayloadDelete(&metadata->xmp); 37 } 38 MetadataCopy(const char * metadata,size_t metadata_len,MetadataPayload * const payload)39int MetadataCopy(const char* metadata, size_t metadata_len, 40 MetadataPayload* const payload) { 41 if (metadata == NULL || metadata_len == 0 || payload == NULL) return 0; 42 payload->bytes = (uint8_t*)malloc(metadata_len); 43 if (payload->bytes == NULL) return 0; 44 payload->size = metadata_len; 45 memcpy(payload->bytes, metadata, metadata_len); 46 return 1; 47 } 48 49 // ----------------------------------------------------------------------------- 50