diff options
author | Tyler Luu <tluu@ti.com> | 2011-09-27 20:04:35 -0500 |
---|---|---|
committer | Iliyan Malchev <malchev@google.com> | 2011-10-07 10:39:58 -0700 |
commit | 13714f28c615c0cf1be4907aa6fe86f0cb5b28b8 (patch) | |
tree | 1b82c2a768500f0539abff8c757f82e38d35b35b /jpgfile.c | |
parent | 0aba81d4c228ec0681f030ef77a583a8fd9f555a (diff) | |
download | jhead-13714f28c615c0cf1be4907aa6fe86f0cb5b28b8.tar.gz |
Add API for jhead to use a thumbnail buffer
Extend jhead API to allow passing of thumbnail
buffer. Previously, jhead only supported replacing
thumbnails from file.
Change-Id: I9783473effbbebdfb13ef10d4974a89122d9b000
Signed-off-by: Tyler Luu <tluu@ti.com>
Diffstat (limited to 'jpgfile.c')
-rwxr-xr-x | jpgfile.c | 64 |
1 files changed, 64 insertions, 0 deletions
@@ -586,6 +586,70 @@ int SaveThumbnail(char * ThumbFileName) //-------------------------------------------------------------------------- // Replace or remove exif thumbnail //-------------------------------------------------------------------------- +int ReplaceThumbnailFromBuffer(const char * Thumb, int ThumbLen) +{ + int NewExifSize; + Section_t * ExifSection; + uchar * ThumbnailPointer; + + if (ImageInfo.ThumbnailOffset == 0 || ImageInfo.ThumbnailAtEnd == FALSE){ + if (Thumb == NULL){ + // Delete of nonexistent thumbnail (not even pointers present) + // No action, no error. + return FALSE; + } + + // Adding or removing of thumbnail is not possible - that would require rearranging + // of the exif header, which is risky, and jhad doesn't know how to do. + fprintf(stderr,"Image contains no thumbnail to replace - add is not possible\n"); +#ifdef SUPERDEBUG + LOGE("Image contains no thumbnail to replace - add is not possible\n"); +#endif + return FALSE; + } + + if (Thumb) { + if (ThumbLen + ImageInfo.ThumbnailOffset > 0x10000-20){ + //ErrFatal("Thumbnail is too large to insert into exif header"); + LOGE("Thumbnail is too large to insert into exif header"); + return FALSE; + } + } else { + if (ImageInfo.ThumbnailSize == 0){ + return FALSE; + } + + ThumbLen = 0; + } + + ExifSection = FindSection(M_EXIF); + + NewExifSize = ImageInfo.ThumbnailOffset+8+ThumbLen; + ExifSection->Data = (uchar *)realloc(ExifSection->Data, NewExifSize); + + ThumbnailPointer = ExifSection->Data+ImageInfo.ThumbnailOffset+8; + + if (Thumb){ + memcpy(ThumbnailPointer, Thumb, ThumbLen); + } + + ImageInfo.ThumbnailSize = ThumbLen; + + Put32u(ExifSection->Data+ImageInfo.ThumbnailSizeOffset+8, ThumbLen); + + ExifSection->Data[0] = (uchar)(NewExifSize >> 8); + ExifSection->Data[1] = (uchar)NewExifSize; + ExifSection->Size = NewExifSize; + +#ifdef SUPERDEBUG + LOGE("ReplaceThumbnail successful thumblen %d", ThumbLen); +#endif + return TRUE; +} + +//-------------------------------------------------------------------------- +// Replace or remove exif thumbnail +//-------------------------------------------------------------------------- int ReplaceThumbnail(const char * ThumbFileName) { FILE * ThumbnailFile; |