void copyThumbnailData(uchar* thumbnailData, int thumbnailLen) { LOGI("******************************** copyThumbnailData"); Section_t* ExifSection = FindSection(M_EXIF); if (ExifSection == NULL) { return; } int NewExifSize = ImageInfo.ThumbnailOffset+8+thumbnailLen; ExifSection->Data = (uchar *)realloc(ExifSection->Data, NewExifSize); if (ExifSection->Data == NULL) { LOGW("ExifSection->Data = NULL"); return; } uchar* ThumbnailPointer = ExifSection->Data+ImageInfo.ThumbnailOffset+8; memcpy(ThumbnailPointer, thumbnailData, thumbnailLen); ImageInfo.ThumbnailSize = thumbnailLen; Put32u(ExifSection->Data+ImageInfo.ThumbnailSizeOffset+8, thumbnailLen); ExifSection->Data[0] = (uchar)(NewExifSize >> 8); ExifSection->Data[1] = (uchar)NewExifSize; ExifSection->Size = NewExifSize; }
//-------------------------------------------------------------------------- // 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 ALOGE("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"); ALOGE("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 ALOGE("ReplaceThumbnail successful thumblen %d", ThumbLen); #endif return TRUE; }
//-------------------------------------------------------------------------- // Replace or remove exif thumbnail //-------------------------------------------------------------------------- int ReplaceThumbnail(const char * ThumbFileName) { FILE * ThumbnailFile; int ThumbLen, NewExifSize; Section_t * ExifSection; uchar * ThumbnailPointer; if (ImageInfo.ThumbnailOffset == 0 || ImageInfo.ThumbnailAtEnd == 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. printf("Image contains no thumbnail to replace - add is not possible\n"); return FALSE; } if (ThumbFileName){ ThumbnailFile = fopen(ThumbFileName,"rb"); if (ThumbnailFile == NULL){ ErrFatal("Could not read thumbnail file"); return FALSE; } // get length fseek(ThumbnailFile, 0, SEEK_END); ThumbLen = ftell(ThumbnailFile); fseek(ThumbnailFile, 0, SEEK_SET); if (ThumbLen + ImageInfo.ThumbnailOffset > 0x10000-20){ ErrFatal("Thumbnail is too large to insert into exif header"); } }else{ ThumbLen = 0; ThumbnailFile = NULL; } ExifSection = FindSection(M_EXIF); NewExifSize = ImageInfo.ThumbnailOffset+8+ThumbLen; ExifSection->Data = (uchar *)realloc(ExifSection->Data, NewExifSize); ThumbnailPointer = ExifSection->Data+ImageInfo.ThumbnailOffset+8; if (ThumbnailFile){ fread(ThumbnailPointer, ThumbLen, 1, ThumbnailFile); fclose(ThumbnailFile); } ImageInfo.ThumbnailSize = ThumbLen; Put32u(ExifSection->Data+ImageInfo.ThumbnailSizeOffset+8, ThumbLen); ExifSection->Data[0] = (uchar)(NewExifSize >> 8); ExifSection->Data[1] = (uchar)NewExifSize; ExifSection->Size = NewExifSize; return TRUE; }