I try to insert some EXIF Data in a JPEG stream. I am using libexif for that.
The libexif example shows how to open a file -> add the data -> and then save the file. What I have is a pointer (void * JPEGPointer
) to a JPEG stream. So I want to just add the from libexif generated data to this pointer for sending it via FTP. Not saving to a file. The following code is basically the example from libexif with some not working memcpy()
attempts from myself. The JPG File is corrupted after the memcpy so i can not open it with any Software. I think i am copying the exif to the wrong position. I can not use any aditional library unfortunately.
// Set the image options
exif_data_set_option(exif, EXIF_DATA_OPTION_FOLLOW_SPECIFICATION);
exif_data_set_data_type(exif, EXIF_DATA_TYPE_COMPRESSED);
exif_data_set_byte_order(exif, FILE_BYTE_ORDER);
// Create the mandatory EXIF fields with default data
exif_data_fix(exif);
/* Create a EXIF_TAG_USER_COMMENT tag. This one must be handled
* differently because that tag isn't automatically created and
* allocated by exif_data_fix(), nor can it be created using
* exif_entry_initialize() so it must be explicitly allocated here.
*/
entry = createTag(exif, EXIF_IFD_EXIF, EXIF_TAG_USER_COMMENT,
sizeof(ASCII_COMMENT) + sizeof(FILE_COMMENT) - 2);
/* Write the special header needed for a comment tag */
memcpy(entry->data, ASCII_COMMENT, sizeof(ASCII_COMMENT)-1);
/* Write the actual comment text, without the trailing NUL character */
memcpy(entry->data+8, FILE_COMMENT, sizeof(FILE_COMMENT)-1);
/* createTag() happens to set the format and components correctly for
* EXIF_TAG_USER_COMMENT, so there is nothing more to do. */
/* Get a pointer to the EXIF data block we just created */
exif_data_save_data(exif, &exif_data, &exif_data_len);
assert(exif_data != NULL);
//copy exif data to my JPEGPointer...not working like that
memcpy(JPEGPointer+ exif_data_len * sizeof(uint8_t), JPEGPointer, sizeof(JPEGPointer)+exif_data_len);
free(exif_data);
exif_data_unref(exif);
Any ideas how to put that EXIF data to the correct position in the JPEG data?