Hephaestsus
Hephaestsus

Reputation: 13

How to save char* tag values in libexif

I'm having an issue with libexif saving tags string data. I'm allocating memory for string value, using strcpy and then just assiggn pointer to specific tags entry->data. Problem is - saving with exif_data_save_data and fwrite, i get my string value cutted to 7 chars. If I load all this data at first from file with longer string value for this specific exif tag (EXIF_TAG_NAME in particular), max string len coud be different.

static char* get_c_str(QString qs)
{
    QByteArray *qba = new QByteArray(qs.toLatin1());
    char* str = (char *)malloc(qba->count());
    strcpy(str,qba->data());

    return str;
}


static ExifEntry *init_tag(ExifData *exif, ExifIfd ifd, ExifTag tag)
{
    ExifEntry *entry;

    if (!((entry = exif_content_get_entry (exif->ifd[ifd], tag)))) {

        entry = exif_entry_new ();
        assert(entry != NULL); 
        entry->tag = tag;

        exif_content_add_entry (exif->ifd[ifd], entry);

        exif_entry_initialize (entry, tag);

        exif_entry_unref(entry);
    }
    return entry;
}

void MainWindow::on_writeButton_clicked()
{
    if(!buf)
        return;

    ent = init_tag(ed,ExifIfd::EXIF_IFD_0,ExifTag::EXIF_TAG_MODEL);
    ent->data = (unsigned char*)get_c_str(ui->modelL->text());

    ................................................

    exif_data_save_data(ed, &exifData, &exifDatLen);

    f = fopen(path, "wb");

    fwrite(exif_header,exif_header_len,1,f);

    fputc((exifDatLen+2)>>8,f);
    fputc((exifDatLen+2) & 0xff, f);

    fwrite(exifData,exifDatLen,1,f);
    fwrite(buf+image_data_offset,flen,1,f);

    fclose(f);
}

Expected Camera Model to be "Canon EOS 5D Mark II" but was "Canon E"

Upvotes: 0

Views: 110

Answers (0)

Related Questions