cvs: php4 /ext/exif exif.c

From: Date: Fri, 05 Apr 2002 01:25:54 +0000
Subject: cvs: php4 /ext/exif exif.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-10880@lists.php.net to get a copy of this message
helly Thu Apr 4 20:25:54 2002 EDT Modified files: /php4/ext/exif exif.c Log: Unicode is now based on php_mb_convert_encoding if available #currently only ISO-8859-15 is supported as result #maybe this will become an ini setting Index: php4/ext/exif/exif.c diff -u php4/ext/exif/exif.c:1.82 php4/ext/exif/exif.c:1.83 --- php4/ext/exif/exif.c:1.82 Thu Apr 4 15:45:53 2002 +++ php4/ext/exif/exif.c Thu Apr 4 20:25:53 2002 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: exif.c,v 1.82 2002/04/04 20:45:53 helly Exp $ */ +/* $Id: exif.c,v 1.83 2002/04/05 01:25:53 helly Exp $ */ /* ToDos * @@ -77,7 +77,11 @@ #include "php_ini.h" #include "ext/standard/php_string.h" #include "ext/standard/php_image.h" -#include "ext/standard/info.h" +#include "ext/standard/info.h" + +#ifdef HAVE_MBSTRING +#include "ext/mbstring/mbstring.h" +#endif typedef unsigned char uchar; @@ -102,7 +106,7 @@ }; /* }}} */ -#define EXIF_VERSION "1.3 $Id: exif.c,v 1.82 2002/04/04 20:45:53 helly Exp $" +#define EXIF_VERSION "1.3 $Id: exif.c,v 1.83 2002/04/05 01:25:53 helly Exp $" PHP_MINFO_FUNCTION(exif); @@ -913,6 +917,7 @@ int motorola_intel; /* 1 Motorola; 0 Intel */ char *UserComment; + int UserCommentLength; char *UserCommentEncoding; char *Copyright; char *CopyrightPhotographer; @@ -1241,6 +1246,43 @@ } /* }}} */ +/* {{{ exif_iif_add_str + Add a string value to image_info MUST BE NUL TERMINATED +*/ +void exif_iif_add_buffer( image_info_type *image_info, int section_index, char *name, int length, char *value) +{ + image_info_data *info_data; + image_info_data *list; + + if ( value) { + list = erealloc(image_info->info_list[section_index].list,(image_info->info_list[section_index].count+1)*sizeof(image_info_data)); + if ( !list) { + EXIF_ERRLOG_EALLOC + return; + } + image_info->info_list[section_index].list = list; + info_data = &image_info->info_list[section_index].list[image_info->info_list[section_index].count]; + info_data->tag = TAG_NONE; + info_data->format = TAG_FMT_UNDEFINED; + info_data->length = length; + info_data->name = estrdup(name); + if ( !info_data->name) { + EXIF_ERRLOG_EALLOC + return; + } + info_data->value.s = emalloc(length+1); + if ( !info_data->value.s) { + EXIF_ERRLOG_EALLOC + return; + } + memcpy(info_data->value.s, value, length); + info_data->value.s[length] = 0; + image_info->sections_found |= 1<<section_index; + image_info->info_list[section_index].count++; + } +} +/* }}} */ + /* {{{ exif_iif_free Free memory allocated for image_info */ @@ -1983,17 +2025,30 @@ /* {{{ exif_process_user_comment * Process UserComment in IFD. */ -static int exif_process_user_comment(char **pszInfoPtr,char **szEncoding,char *szValuePtr,int ByteCount) +static int exif_process_user_comment(char **pszInfoPtr, char **szEncoding, char *szValuePtr, int ByteCount, int motorola_intel TSRMLS_DC) { int a; + #ifdef HAVE_MBSTRING + size_t len;; + #endif + /* Copy the comment */ if ( ByteCount>=8) { if (!memcmp(szValuePtr, "UNICODE\0", 8)) { *szEncoding= estrdup((const char*)szValuePtr); szValuePtr = szValuePtr+8; ByteCount -= 8; + #ifdef HAVE_MBSTRING + if ( motorola_intel) { + *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, "ISO-8859-15", "UCS-2BE", &len TSRMLS_CC); + } else { + *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, "ISO-8859-15", "UCS-2LE", &len TSRMLS_CC); + } + return len; + #else return exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount); + #endif } else if ( !memcmp(szValuePtr, "ASCII\0\0\0", 8)) { *szEncoding= estrdup((const char*)szValuePtr); @@ -2168,7 +2223,7 @@ break; case TAG_USERCOMMENT: - exif_process_user_comment(&(ImageInfo->UserComment),&(ImageInfo->UserCommentEncoding),value_ptr,byte_count); + ImageInfo->UserCommentLength = exif_process_user_comment(&(ImageInfo->UserComment), &(ImageInfo->UserCommentEncoding), value_ptr,byte_count, ImageInfo->motorola_intel); break; case TAG_FNUMBER: @@ -3125,7 +3180,7 @@ } } if (ImageInfo.UserComment) { - exif_iif_add_str( &ImageInfo, SECTION_COMPUTED, "UserComment", ImageInfo.UserComment); + exif_iif_add_buffer( &ImageInfo, SECTION_COMPUTED, "UserComment", ImageInfo.UserCommentLength, ImageInfo.UserComment); if ( ImageInfo.UserCommentEncoding && strlen(ImageInfo.UserCommentEncoding)) { exif_iif_add_str( &ImageInfo, SECTION_COMPUTED, "UserCommentEncoding", ImageInfo.UserCommentEncoding); }

« previous php.cvs (#10880) next »