/* Save an exif value to a string in a way that we can restore. We only bother * for the simple formats (that a client might try to change) though. * * Keep in sync with vips_exif_from_s() below. */ static void vips_exif_to_s( ExifData *ed, ExifEntry *entry, VipsBuf *buf ) { unsigned long i; int iv; ExifRational rv; ExifSRational srv; char txt[256]; if( entry->format == EXIF_FORMAT_ASCII ) { /* libexif does not null-terminate strings. Copy out and add * the \0 ourselves. */ int len = VIPS_MIN( 254, entry->size ); memcpy( txt, entry->data, len ); txt[len] = '\0'; vips_buf_appendf( buf, "%s ", txt ); } else if( entry->components < 10 && !vips_exif_get_int( ed, entry, 0, &iv ) ) { for( i = 0; i < entry->components; i++ ) { vips_exif_get_int( ed, entry, i, &iv ); vips_buf_appendf( buf, "%d ", iv ); } } else if( entry->components < 10 && !vips_exif_get_rational( ed, entry, 0, &rv ) ) { for( i = 0; i < entry->components; i++ ) { vips_exif_get_rational( ed, entry, i, &rv ); vips_buf_appendf( buf, "%u/%u ", rv.numerator, rv.denominator ); } } else if( entry->components < 10 && !vips_exif_get_srational( ed, entry, 0, &srv ) ) { for( i = 0; i < entry->components; i++ ) { vips_exif_get_srational( ed, entry, i, &srv ); vips_buf_appendf( buf, "%d/%d ", srv.numerator, srv.denominator ); } } else vips_buf_appendf( buf, "%s ", exif_entry_get_value( entry, txt, 256 ) ); vips_buf_appendf( buf, "(%s, %s, %lu components, %d bytes)", exif_entry_get_value( entry, txt, 256 ), exif_format_get_name( entry->format ), entry->components, entry->size ); }
/* Save an exif value to a string in a way that we can restore. We only bother * for the simple formats (that a client might try to change) though. * * Keep in sync with vips_exif_from_s() in vips2jpeg. */ static void vips_exif_to_s( ExifData *ed, ExifEntry *entry, VipsBuf *buf ) { unsigned long i; int iv; ExifRational rv; ExifSRational srv; char txt[256]; if( entry->format == EXIF_FORMAT_ASCII ) vips_buf_appendf( buf, "%s ", entry->data ); else if( entry->components < 10 && !vips_exif_get_int( ed, entry, 0, &iv ) ) { for( i = 0; i < entry->components; i++ ) { vips_exif_get_int( ed, entry, i, &iv ); vips_buf_appendf( buf, "%d ", iv ); } } else if( entry->components < 10 && !vips_exif_get_rational( ed, entry, 0, &rv ) ) { for( i = 0; i < entry->components; i++ ) { vips_exif_get_rational( ed, entry, i, &rv ); vips_buf_appendf( buf, "%u/%u ", rv.numerator, rv.denominator ); } } else if( entry->components < 10 && !vips_exif_get_srational( ed, entry, 0, &srv ) ) { for( i = 0; i < entry->components; i++ ) { vips_exif_get_srational( ed, entry, i, &srv ); vips_buf_appendf( buf, "%d/%d ", srv.numerator, srv.denominator ); } } else vips_buf_appendf( buf, "%s ", exif_entry_get_value( entry, txt, 256 ) ); vips_buf_appendf( buf, "(%s, %s, %lu components, %d bytes)", exif_entry_get_value( entry, txt, 256 ), exif_format_get_name( entry->format ), entry->components, entry->size ); }
static int vips_exif_entry_get_int( ExifData *ed, int ifd, ExifTag tag, int *out ) { ExifEntry *entry; if( !(entry = exif_content_get_entry( ed->ifd[ifd], tag )) || entry->components != 1 ) return( -1 ); return( vips_exif_get_int( ed, entry, 0, out ) ); }