cvs: php4 /ext/exif exif.c /ext/exif/tests 001.phpt 003.phpt

From: Date: Fri, 12 Apr 2002 16:35:57 +0000
Subject: cvs: php4 /ext/exif exif.c /ext/exif/tests 001.phpt 003.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-11088@lists.php.net to get a copy of this message
helly Fri Apr 12 12:35:57 2002 EDT Modified files: /php4/ext/exif/tests 001.phpt 003.phpt /php4/ext/exif exif.c Log: Ini settings for internal encoding and decoding of Unicode and JIS formatted user comments. @- Ini settings for encoding/decoding Unicode/JIS user comments (Marcus)

Index: php4/ext/exif/tests/001.phpt diff -u php4/ext/exif/tests/001.phpt:1.6 php4/ext/exif/tests/001.phpt:1.7 --- php4/ext/exif/tests/001.phpt:1.6 Thu Mar 28 20:33:30 2002 +++ php4/ext/exif/tests/001.phpt Fri Apr 12 12:35:56 2002 @@ -25,4 +25,4 @@ echo $accept; ?> --EXPECT-- -ArrayFitest2.jpgFi1240Fi2SeANY_TAG, IFD0, THUMBNAIL, COMMENTArrayhtwidth="1" height="1"He1Wi1Is1UsExif test image.UsASCIICoPhoto (c) M.Boerger, Edited by M.Boerger.CoPhoto (c) M.BoergerCoEdited by M.Boerger.ArrayCoPhoto (c) M.BoergerUsASCIIArrayJP134JP523Array0Comment #1.1Comment #2.2Comment #3end \ No newline at end of file +ArrayFitest2.jpgFi1240Fi2SeANY_TAG, IFD0, THUMBNAIL, COMMENTArrayhtwidth="1" height="1"He1Wi1Is1By1UsExif test image.UsASCIICoPhoto (c) M.Boerger, Edited by M.Boerger.CoPhoto (c) M.BoergerCoEdited by M.Boerger.ArrayCoPhoto (c) M.BoergerUsASCIIArrayJP134JP523Array0Comment #1.1Comment #2.2Comment #3end \ No newline at end of file Index: php4/ext/exif/tests/003.phpt Index: php4/ext/exif/exif.c diff -u php4/ext/exif/exif.c:1.88 php4/ext/exif/exif.c:1.89 --- php4/ext/exif/exif.c:1.88 Tue Apr 9 21:18:52 2002 +++ php4/ext/exif/exif.c Fri Apr 12 12:35:56 2002 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: exif.c,v 1.88 2002/04/10 01:18:52 helly Exp $ */ +/* $Id: exif.c,v 1.89 2002/04/12 16:35:56 helly Exp $ */ /* ToDos * @@ -107,9 +107,9 @@ }; /* }}} */ -#define EXIF_VERSION "1.3 $Id: exif.c,v 1.88 2002/04/10 01:18:52 helly Exp $" +#define EXIF_VERSION "1.3 $Id: exif.c,v 1.89 2002/04/12 16:35:56 helly Exp $" -PHP_MINFO_FUNCTION(exif); +ZEND_DECLARE_MODULE_GLOBALS(exif) /* {{{ PHP_MINFO_FUNCTION */ @@ -124,13 +124,75 @@ } /* }}} */ -static char * exif_encoding_unicode = "ISO-8859-15"; -static char * exif_encoding_jis = NULL; /* default to internal encoding */ +ZEND_BEGIN_MODULE_GLOBALS(exif) + char * encode_unicode; + char * decode_unicode_be; + char * decode_unicode_le; + char * encode_jis; + char * decode_jis_be; + char * decode_jis_le; +ZEND_END_MODULE_GLOBALS(exif) + +#ifdef ZTS +#define EXIF_G(v) TSRMG(exif_globals_id, zend_exif_globals *, v) +#else +#define EXIF_G(v) (exif_globals.v) +#endif + +/* {{{ PHP_INI + */ + +ZEND_API ZEND_INI_MH(OnUpdateEncode) +{ +#ifdef HAVE_MBSTRING + if (new_value && strlen(new_value) && !php_mb_check_encoding_list(new_value TSRMLS_CC)) { + php_error(E_WARNING,"Illegal encoding ignored: '%s'", new_value); + return FAILURE; + } +#endif + return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); +} + +ZEND_API ZEND_INI_MH(OnUpdateDecode) +{ +#ifdef HAVE_MBSTRING + if (!php_mb_check_encoding_list(new_value TSRMLS_CC)) { + php_error(E_WARNING,"Illegal encoding ignored: '%s'", new_value); + return FAILURE; + } +#endif + return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); +} + +PHP_INI_BEGIN() + STD_PHP_INI_ENTRY("exif.encode_unicode", "ISO-8859-15", PHP_INI_ALL, OnUpdateEncode, encode_unicode, zend_exif_globals, exif_globals) + STD_PHP_INI_ENTRY("exif.decode_unicode_motorola", "UCS-2BE", PHP_INI_ALL, OnUpdateDecode, decode_unicode_be, zend_exif_globals, exif_globals) + STD_PHP_INI_ENTRY("exif.decode_unicode_intel", "UCS-2LE", PHP_INI_ALL, OnUpdateDecode, decode_unicode_le, zend_exif_globals, exif_globals) + STD_PHP_INI_ENTRY("exif.encode_jis", "", PHP_INI_ALL, OnUpdateEncode, encode_jis, zend_exif_globals, exif_globals) + STD_PHP_INI_ENTRY("exif.decode_jis_motorola", "JIS", PHP_INI_ALL, OnUpdateDecode, decode_jis_be, zend_exif_globals, exif_globals) + STD_PHP_INI_ENTRY("exif.decode_jis_intel", "JIS", PHP_INI_ALL, OnUpdateDecode, decode_jis_le, zend_exif_globals, exif_globals) +PHP_INI_END() +/* }}} */ + +/* {{{ php_extname_init_globals + */ +static void php_exif_init_globals(zend_exif_globals *exif_globals) +{ + exif_globals->encode_unicode = NULL; + exif_globals->decode_unicode_be = NULL; + exif_globals->decode_unicode_le = NULL; + exif_globals->encode_jis = NULL; + exif_globals->decode_jis_be = NULL; + exif_globals->decode_jis_le = NULL; +} +/* }}} */ /* {{{ PHP_MINIT_FUNCTION(exif) Get the size of an image as 4-element array */ PHP_MINIT_FUNCTION(exif) { + ZEND_INIT_MODULE_GLOBALS(exif, php_exif_init_globals, NULL); + REGISTER_INI_ENTRIES(); REGISTER_LONG_CONSTANT("IMAGETYPE_GIF", IMAGE_FILETYPE_GIF, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMAGETYPE_JPEG", IMAGE_FILETYPE_JPEG, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMAGETYPE_PNG", IMAGE_FILETYPE_PNG, CONST_CS | CONST_PERSISTENT); @@ -147,6 +209,15 @@ } /* }}} */ +/* {{{ PHP_MSHUTDOWN_FUNCTION + */ +PHP_MSHUTDOWN_FUNCTION(exif) +{ + UNREGISTER_INI_ENTRIES(); + return SUCCESS; +} +/* }}} */ + /* {{{ exif_module_entry */ zend_module_entry exif_module_entry = { @@ -155,10 +226,13 @@ #endif "exif", exif_functions, - ZEND_MODULE_STARTUP_N(exif), NULL, + PHP_MINIT(exif), + PHP_MSHUTDOWN(exif), NULL, NULL, PHP_MINFO(exif), +#if ZEND_MODULE_API_NO >= 20010901 EXIF_VERSION, +#endif STANDARD_MODULE_PROPERTIES }; /* }}} */ @@ -924,6 +998,12 @@ char *UserComment; int UserCommentLength; char *UserCommentEncoding; + char *encode_unicode; + char *decode_unicode_be; + char *decode_unicode_le; + char *encode_jis; + char *decode_jis_be; + char *decode_jis_le; char *Copyright; char *CopyrightPhotographer; char *CopyrightEditor; @@ -2029,7 +2109,7 @@ /* {{{ exif_process_user_comment * Process UserComment in IFD. */ -static int exif_process_user_comment(char **pszInfoPtr, char **pszEncoding, char *szValuePtr, int ByteCount, int motorola_intel TSRMLS_DC) +static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoPtr, char **pszEncoding, char *szValuePtr, int ByteCount TSRMLS_DC) { int a; @@ -2045,12 +2125,11 @@ szValuePtr = szValuePtr+8; ByteCount -= 8; #ifdef HAVE_MBSTRING - if (motorola_intel) { - *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, exif_encoding_unicode, "UCS-2BE", &len TSRMLS_CC); + if (ImageInfo->motorola_intel) { + *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, ImageInfo->decode_unicode_be, &len TSRMLS_CC); } else { - *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, exif_encoding_unicode, "UCS-2LE", &len TSRMLS_CC); + *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, ImageInfo->decode_unicode_le, &len TSRMLS_CC); } - /*php_error(E_NOTICE, "converted(%d,%s): %s", len, *pszEncoding, *pszInfoPtr);*/ return len; #else return exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount); @@ -2067,7 +2146,11 @@ szValuePtr = szValuePtr+8; ByteCount -= 8; #ifdef HAVE_MBSTRING - *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, exif_encoding_jis, "JIS", &len TSRMLS_CC); + if (ImageInfo->motorola_intel) { + *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_jis, ImageInfo->decode_jis_be, &len TSRMLS_CC); + } else { + *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_jis, ImageInfo->decode_jis_le, &len TSRMLS_CC); + } return len; #else return exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount); @@ -2239,7 +2322,7 @@ break; case TAG_USERCOMMENT: - ImageInfo->UserCommentLength = exif_process_user_comment(&(ImageInfo->UserComment), &(ImageInfo->UserCommentEncoding), value_ptr, byte_count, ImageInfo->motorola_intel TSRMLS_CC); + ImageInfo->UserCommentLength = exif_process_user_comment(ImageInfo, &(ImageInfo->UserComment), &(ImageInfo->UserCommentEncoding), value_ptr, byte_count TSRMLS_CC); break; case TAG_FNUMBER: @@ -3010,6 +3093,12 @@ EFREE_IF(ImageInfo->CopyrightPhotographer); EFREE_IF(ImageInfo->CopyrightEditor); EFREE_IF(ImageInfo->Thumbnail.data); + EFREE_IF(ImageInfo->encode_unicode); + EFREE_IF(ImageInfo->decode_unicode_be); + EFREE_IF(ImageInfo->decode_unicode_le); + EFREE_IF(ImageInfo->encode_jis); + EFREE_IF(ImageInfo->decode_jis_be); + EFREE_IF(ImageInfo->decode_jis_le); for (i=0; i<SECTION_COUNT; i++) { exif_iif_free(ImageInfo, i); } @@ -3029,7 +3118,7 @@ /* Start with an empty image information structure. */ memset(ImageInfo, 0, sizeof(*ImageInfo)); - ImageInfo->motorola_intel = 0; + ImageInfo->motorola_intel = -1; /* flag as unknown */ ImageInfo->infile = php_stream_open_wrapper(FileName, "rb", STREAM_MUST_SEEK|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL); if (!ImageInfo->infile) { @@ -3042,6 +3131,13 @@ ImageInfo->read_all = read_all; ImageInfo->Thumbnail.filetype = IMAGE_FILETYPE_UNKNOWN; + ImageInfo->encode_unicode = estrdup(EXIF_G(encode_unicode)); + ImageInfo->decode_unicode_be = estrdup(EXIF_G(decode_unicode_be)); + ImageInfo->decode_unicode_le = estrdup(EXIF_G(decode_unicode_le)); + ImageInfo->encode_jis = estrdup(EXIF_G(encode_jis)); + ImageInfo->decode_jis_be = estrdup(EXIF_G(decode_jis_be)); + ImageInfo->decode_jis_le = estrdup(EXIF_G(decode_jis_le)); + if (php_stream_is(ImageInfo->infile, PHP_STREAM_IS_STDIO)) { if (VCWD_STAT(FileName, &st) >= 0) { /* Store file date/time. */ @@ -3168,6 +3264,9 @@ exif_iif_add_int(&ImageInfo, SECTION_COMPUTED, "Width", ImageInfo.Width); } exif_iif_add_int(&ImageInfo, SECTION_COMPUTED, "IsColor", ImageInfo.IsColor); + if (ImageInfo.motorola_intel != -1) { + exif_iif_add_int(&ImageInfo, SECTION_COMPUTED, "ByteOrderMotorola", ImageInfo.motorola_intel); + } if (ImageInfo.FocalLength) { exif_iif_add_fmt(&ImageInfo, SECTION_COMPUTED, "FocalLength", "%4.1fmm", ImageInfo.FocalLength); if(ImageInfo.CCDWidth) {
« previous php.cvs (#11088) next »