diff options
author | oehhar <harald.oehlmann@elmicron.de> | 2020-06-24 16:01:49 (GMT) |
---|---|---|
committer | oehhar <harald.oehlmann@elmicron.de> | 2020-06-24 16:01:49 (GMT) |
commit | 6a10411bfb5de2631d2457a85d4b6995df87d3e3 (patch) | |
tree | 0d7a38fa4e966fd44a75444fd4049927686e91fe | |
parent | e2af510d008d17dec556410202d79c52f05b6e80 (diff) | |
download | tk-6a10411bfb5de2631d2457a85d4b6995df87d3e3.zip tk-6a10411bfb5de2631d2457a85d4b6995df87d3e3.tar.gz tk-6a10411bfb5de2631d2457a85d4b6995df87d3e3.tar.bz2 |
TIP529 image metadata: remove optional feature "gif XMP metadata support".
-rw-r--r-- | generic/tkImgGIF.c | 129 | ||||
-rw-r--r-- | tests/imgPhoto.test | 228 |
2 files changed, 16 insertions, 341 deletions
diff --git a/generic/tkImgGIF.c b/generic/tkImgGIF.c index 23e02f7..7dc78d8 100644 --- a/generic/tkImgGIF.c +++ b/generic/tkImgGIF.c @@ -1049,8 +1049,6 @@ ReadColorMap( * The transparent color is set if present in current extensions * The data of the following extensions are saved to the metadata dict: * - Application extension -* - XMP data is stored in key "XMP" -* - any other under the key Application_<name><code> * - Comment extension in key "comment" * Plain text extensions are currently ignored. * @@ -1068,9 +1066,9 @@ DoExtension( { int count; /* Prepare extension name - * Maximum string size: "Application_"(12) + App(8) + Code(3) + trailing zero + * Maximum string size: "comment" + Code(3) + trailing zero */ - char extensionStreamName[24]; + char extensionStreamName[8]; extensionStreamName[0] = '\0'; switch (label) { @@ -1090,84 +1088,6 @@ DoExtension( strcpy(extensionStreamName,"comment"); /* copy the extension data below */ break; - case 0xff: /* Application Extension */ - /* Length: 11 - * Application Identifier: 8 bytes - * Application Authentication code: 3 Bytes - */ - count = GetDataBlock(gifConfPtr, chan, buf); - if (count != 11) { - return -1; - } - /* Detect XMP extension */ - if (NULL != metadataOutObj - && 0 == memcmp(buf,"XMP DataXMP",11)) { - /* XMP format does not use the block structure of GIF - * The data is utf-8 which never contains 0's - * A magic trailer of 258 bytes is added with the following data: - * 0x01 0xff 0xfe ... 0x01 0x00 0x00 - */ - Tcl_Encoding encoding; - Tcl_DString recodedDString; - Tcl_DString dataDString; - int length; - int result; - unsigned char lastbyte = 1; - Tcl_DStringInit(&dataDString); - - for (;;) { - unsigned char byte; - if (1 != Fread(gifConfPtr, &byte, 1, 1, chan)) { - /* read error */ - Tcl_DStringFree(&dataDString); - return -1; - } - Tcl_DStringAppend(&dataDString,(char *)&byte,1); - /* check for end of xmp header */ - if (byte == 0 && lastbyte == 0) { - break; - } - lastbyte = byte; - } - - /* check if trailer of 258 bytes is present */ - length = Tcl_DStringLength(&dataDString); - if (length < 258) { - Tcl_DStringFree(&dataDString); - return -1; - } - /* Remove the trailer from the data */ - length -= 258; - /* save the utf-8 data in the metadata dict key "XMP" */ - encoding = Tcl_GetEncoding(NULL, "utf-8"); - Tcl_DStringInit(&recodedDString); - Tcl_ExternalToUtfDString(encoding, Tcl_DStringValue(&dataDString), length, &recodedDString); - result = Tcl_DictObjPut(NULL, metadataOutObj, - Tcl_NewStringObj("XMP",-1), - Tcl_NewStringObj(Tcl_DStringValue(&recodedDString), - Tcl_DStringLength(&recodedDString))); - Tcl_DStringFree(&recodedDString); - Tcl_DStringFree(&dataDString); - Tcl_FreeEncoding(encoding); - if ( TCL_OK != result ) { - return -1; - } - return 0; - } else { - /* - * Other extension - * Name the extension: Application_xxxxxxxxxxx - * 012345678901234567890123 - */ - /* Untested code commented out, no use case - */ - /* - strcpy(extensionStreamName,"Application_"); - memcpy(extensionStreamName+12,buf,11); - extensionStreamName[23]='\0'; - */ - } - break; } /* Add extension to dict */ if (NULL != metadataOutObj @@ -2122,51 +2042,6 @@ CommonWriteGIF( writeProc(handle, (char *) &c, 1); } } - - /* - * Check and code XMP block - */ - - if (TCL_ERROR == Tcl_DictObjGet(interp, metadataInObj, - Tcl_NewStringObj("XMP",-1), - &itemData)) { - return TCL_ERROR; - } - if (itemData != NULL) { - Tcl_Encoding encoding; - Tcl_DString recodedDString; - char * itemString; - int itemLength; - int trailerChar; - - /* write header */ - writeProc(handle, "\x21\xff\x0bXMP DataXMP", 14); - - /* write utf-8 coded data */ - encoding = Tcl_GetEncoding(NULL, "utf-8"); - Tcl_DStringInit(&recodedDString); - itemString = Tcl_GetStringFromObj(itemData, &itemLength); - Tcl_UtfToExternalDString(encoding, itemString, itemLength, - &recodedDString); - writeProc(handle, Tcl_DStringValue(&recodedDString), - Tcl_DStringLength(&recodedDString)); - Tcl_DStringFree(&recodedDString); - Tcl_FreeEncoding(encoding); - - /* XMP format does not use the block structure of GIF - * The data is utf-8 which never contains 0's - * A magic trailer of 258 bytes is added with the following data: - * 0x01 0xff 0xfe ... 0x01 0x00 0x00 - */ - c = 1; - writeProc(handle, (char *) &c, 1); - for (trailerChar = 0xff; trailerChar >= 0; trailerChar--) { - c = (unsigned char)trailerChar; - writeProc(handle, (char *) &c, 1); - } - c = 0; - writeProc(handle, (char *) &c, 1); - } } c = GIF_TERMINATOR; writeProc(handle, (char *) &c, 1); diff --git a/tests/imgPhoto.test b/tests/imgPhoto.test index 5f71b9a..f0cd730 100644 --- a/tests/imgPhoto.test +++ b/tests/imgPhoto.test @@ -2249,170 +2249,7 @@ test imgPhoto-23.6 {Two GIF comment blocks (-file)} -setup { file delete $path } -result {comment ABCD} -test imgPhoto-23.7 {XMP comment block before image (-data)} -setup { - set data $::gifstart - # Append an XMP comment extension block (including a Unicode codepoint 2022 - set xmpdata "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\ - xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\">\ - <rdf:Description rdf:about=\"1\u2022\">\ - <xmp:Rating>3</xmp:Rating></rdf:Description></rdf:RDF>" - append data "\x21\xff\x0B" "XMP DataXMP" [encoding convertto utf-8 $xmpdata] - # Special trailer of 1 ff fe ... 02 01 00 00 - append data "\x01" - for {set i 0xff} {$i != -1} {incr i -1} { - append data [binary format c $i] - } - append data "\x00" - - append data $::gifdata - # Trailer - append data $::gifend -} -body { - image create photo gif1 -data $data - set d [dict get [gif1 cget -metadata] XMP] - expr {$d eq $xmpdata} -} -cleanup { - catch {image delete gif1} -} -result {1} - -test imgPhoto-23.8 {XMP comment block before image (-file)} -setup { - set data $::gifstart - # Append an XMP comment extension block (including a Unicode codepoint 2022 - set xmpdata "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\ - xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\">\ - <rdf:Description rdf:about=\"1\u2022\">\ - <xmp:Rating>3</xmp:Rating></rdf:Description></rdf:RDF>" - append data "\x21\xff\x0B" "XMP DataXMP" [encoding convertto utf-8 $xmpdata] - # Special trailer of 1 ff fe ... 02 01 00 00 - append data "\x01" - for {set i 0xff} {$i != -1} {incr i -1} { - append data [binary format c $i] - } - append data "\x00" - - append data $::gifdata - # Trailer - append data $::gifend - set path [file join [configure -tmpdir] test.gif] - set h [open $path "WRONLY BINARY CREAT"] - puts $h $data - close $h -} -body { - image create photo gif1 -file $path - set d [dict get [gif1 cget -metadata] XMP] - expr {$d eq $xmpdata} -} -cleanup { - catch {image delete gif1} - file delete $path -} -result {1} - -test imgPhoto-23.9 {XMP comment block after image (-data)} -setup { - set data $::gifstart - append data $::gifdata - - # Append an XMP comment extension block (including a Unicode codepoint 2022 - set xmpdata "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\ - xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\">\ - <rdf:Description rdf:about=\"1\u2022\">\ - <xmp:Rating>3</xmp:Rating></rdf:Description></rdf:RDF>" - append data "\x21\xff\x0B" "XMP DataXMP" [encoding convertto utf-8 $xmpdata] - # Special trailer of 1 ff fe ... 02 01 00 00 - append data "\x01" - for {set i 0xff} {$i != -1} {incr i -1} { - append data [binary format c $i] - } - append data "\x00" - - # Trailer - append data $::gifend -} -body { - image create photo gif1 -data $data - set d [dict get [gif1 cget -metadata] XMP] - expr {$d eq $xmpdata} -} -cleanup { - catch {image delete gif1} -} -result {1} - -test imgPhoto-23.10 {XMP comment block after image (-file)} -setup { - set data $::gifstart - append data $::gifdata - - # Append an XMP comment extension block (including a Unicode codepoint 2022 - set xmpdata "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\ - xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\">\ - <rdf:Description rdf:about=\"1\u2022\">\ - <xmp:Rating>3</xmp:Rating></rdf:Description></rdf:RDF>" - append data "\x21\xff\x0B" "XMP DataXMP" [encoding convertto utf-8 $xmpdata] - # Special trailer of 1 ff fe ... 02 01 00 00 - append data "\x01" - for {set i 0xff} {$i != -1} {incr i -1} { - append data [binary format c $i] - } - append data "\x00" - - # Trailer - append data $::gifend - - set path [file join [configure -tmpdir] test.gif] - set h [open $path "WRONLY BINARY CREAT"] - puts $h $data - close $h -} -body { - image create photo gif1 -file $path - set d [dict get [gif1 cget -metadata] XMP] - expr {$d eq $xmpdata} -} -cleanup { - catch {image delete gif1} - file delete $path -} -result {1} - -test imgPhoto-23.11 {empty XMP comment block after image (-data)} -setup { - set data $::gifstart - append data $::gifdata - - append data "\x21\xff\x0B" "XMP DataXMP" - # Special trailer of 1 ff fe ... 02 01 00 00 - append data "\x01" - for {set i 0xff} {$i != -1} {incr i -1} { - append data [binary format c $i] - } - append data "\x00" - # Trailer - append data $::gifend -} -body { - image create photo gif1 -data $data - dict get [gif1 cget -metadata] XMP -} -cleanup { - catch {image delete gif1} -} -result {} - -test imgPhoto-23.12 {empty XMP comment block after image (-file)} -setup { - set data $::gifstart - append data $::gifdata - - append data "\x21\xff\x0B" "XMP DataXMP" - # Special trailer of 1 ff fe ... 02 01 00 00 - append data "\x01" - for {set i 0xff} {$i != -1} {incr i -1} { - append data [binary format c $i] - } - append data "\x00" - # Trailer - append data $::gifend - - set path [file join [configure -tmpdir] test.gif] - set h [open $path "WRONLY BINARY CREAT"] - puts $h $data - close $h -} -body { - image create photo gif1 -file $path - dict get [gif1 cget -metadata] XMP -} -cleanup { - catch {image delete gif1} - file delete $path -} -result {} - -test imgPhoto-23.13 {create: test if shared metadata object is not preserved\ +test imgPhoto-23.7 {create: test if shared metadata object is not preserved\ (-data)}\ -setup { set data $::gifstart @@ -2429,7 +2266,7 @@ test imgPhoto-23.13 {create: test if shared metadata object is not preserved\ catch {image delete gif1} } -result {{A 1 comment ABCD} {A 1} {A 1}} -test imgPhoto-23.14 {create: test if shared metadata object is not preserved\ +test imgPhoto-23.8 {create: test if shared metadata object is not preserved\ (-file)}\ -setup { set data $::gifstart @@ -2452,7 +2289,7 @@ test imgPhoto-23.14 {create: test if shared metadata object is not preserved\ file delete $path } -result {{A 1 comment ABCD} {A 1} {A 1}} -test imgPhoto-23.15 {configure: test if shared metadata object is not\ +test imgPhoto-23.9 {configure: test if shared metadata object is not\ preserved (empty image, -data)}\ -setup { set data $::gifstart @@ -2470,7 +2307,7 @@ test imgPhoto-23.15 {configure: test if shared metadata object is not\ catch {image delete gif1} } -result {{A 1 comment ABCD} {A 1} {A 1}} -test imgPhoto-23.16 {configure: test if shared metadata object is not preserved\ +test imgPhoto-23.10 {configure: test if shared metadata object is not preserved\ (empty image, -file)}\ -setup { set data $::gifstart @@ -2494,7 +2331,7 @@ test imgPhoto-23.16 {configure: test if shared metadata object is not preserved\ file delete $path } -result {{A 1 comment ABCD} {A 1} {A 1}} -test imgPhoto-23.17 {configure: test if shared metadata object is not preserved\ +test imgPhoto-23.11 {configure: test if shared metadata object is not preserved\ (metadata replace, -data}\ -setup { set data $::gifstart @@ -2512,7 +2349,7 @@ test imgPhoto-23.17 {configure: test if shared metadata object is not preserved\ catch {image delete gif1} } -result {{A 1 comment ABCD} {A 1} {A 1}} -test imgPhoto-23.18 {configure: test if shared metadata object is not preserved\ +test imgPhoto-23.12 {configure: test if shared metadata object is not preserved\ (metadata replace, -file}\ -setup { set data $::gifstart @@ -2536,7 +2373,7 @@ test imgPhoto-23.18 {configure: test if shared metadata object is not preserved\ file delete $path } -result {{A 1 comment ABCD} {A 1} {A 1}} -test imgPhoto-23.19 {configure: test if shared metadata object is not preserved\ +test imgPhoto-23.13 {configure: test if shared metadata object is not preserved\ (-data)}\ -setup { set data $::gifstart$::gifdata$::gifend @@ -2555,7 +2392,7 @@ test imgPhoto-23.19 {configure: test if shared metadata object is not preserved\ catch {image delete gif1} } -result {{A 1 comment ABCD} {A 1} {A 1}} -test imgPhoto-23.20 {configure: test if shared metadata object is not preserved\ +test imgPhoto-23.14 {configure: test if shared metadata object is not preserved\ (-file)}\ -setup { set data $::gifstart @@ -2579,7 +2416,7 @@ test imgPhoto-23.20 {configure: test if shared metadata object is not preserved\ file delete $path } -result {{A 1 comment ABCD} {A 1} {A 1}} -test imgPhoto-23.21 {output data with comment (from -metadata argument)}\ +test imgPhoto-23.15 {output data with comment (from -metadata argument)}\ -setup { set data $::gifstart$::gifdata$::gifend } -body { @@ -2604,7 +2441,7 @@ test imgPhoto-23.22 {output file with comment (from -metadata argument)}\ file delete $path } -result {ABCD} -test imgPhoto-23.23 {output data with comment (from -metadata property)}\ +test imgPhoto-23.16 {output data with comment (from -metadata property)}\ -setup { set data $::gifstart$::gifdata$::gifend } -body { @@ -2615,7 +2452,7 @@ test imgPhoto-23.23 {output data with comment (from -metadata property)}\ catch {image delete gif1} } -match glob -result {*ABCD*} -test imgPhoto-23.24 {output file with comment (from -metadata property)}\ +test imgPhoto-23.17 {output file with comment (from -metadata property)}\ -setup { set data $::gifstart$::gifdata$::gifend set path [file join [configure -tmpdir] test.gif] @@ -2631,44 +2468,7 @@ test imgPhoto-23.24 {output file with comment (from -metadata property)}\ file delete $path } -result {ABCD} -test imgPhoto-23.25 {output data with XMP (-data)} -setup { - set data $::gifstart$::gifdata$::gifend - set XMPData\ - "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\ - xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\">\ - <rdf:Description rdf:about=\"1\u2022\">\ - <xmp:Rating>3</xmp:Rating></rdf:Description></rdf:RDF>" -} -body { - image create photo gif1 -data $data - set gifData [gif1 data -format gif -metadata [dict create\ - XMP $XMPData]] - image delete gif1 - image create photo gif1 -data $gifData - expr {[dict get [gif1 cget -metadata] XMP] eq $XMPData} -} -cleanup { - catch {image delete gif1} -} -result {1} - -test imgPhoto-23.24 {output data with XMP (-file)} -setup { - set data $::gifstart$::gifdata$::gifend - set XMPData\ - "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\ - xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\">\ - <rdf:Description rdf:about=\"1\u2022\">\ - <xmp:Rating>3</xmp:Rating></rdf:Description></rdf:RDF>" - set path [file join [configure -tmpdir] test.gif] -} -body { - image create photo gif1 -data $data - set gifData [gif1 write $path -format gif -metadata [dict create\ - XMP $XMPData]] - image delete gif1 - image create photo gif1 -file $path - expr {[dict get [gif1 cget -metadata] XMP] eq $XMPData} -} -cleanup { - catch {image delete gif1} -} -result {1} - -test imgPhoto-23.25 {configure: empty metadata parameter overwrites image metadata} -setup { +test imgPhoto-23.18 {configure: empty metadata parameter overwrites image metadata} -setup { image create photo gif1 -data $::gifstart$::gifdata$::gifend\ -metadata {foo bar} set data $::gifstart @@ -2683,7 +2483,7 @@ test imgPhoto-23.25 {configure: empty metadata parameter overwrites image metada catch {image delete gif1} } -result {comment ABCD} -test imgPhoto-23.26 {write: empty metadata parameter overwrites image metadata} -setup { +test imgPhoto-23.19 {write: empty metadata parameter overwrites image metadata} -setup { image create photo gif1 -data $::gifstart$::gifdata$::gifend\ -metadata {comment bar} set path [file join [configure -tmpdir] test.gif] @@ -2697,7 +2497,7 @@ test imgPhoto-23.26 {write: empty metadata parameter overwrites image metadata} file delete $path } -result {0} -test imgPhoto-23.27 {data: empty metadata parameter overwrites image metadata} -setup { +test imgPhoto-23.20 {data: empty metadata parameter overwrites image metadata} -setup { image create photo gif1 -data $::gifstart$::gifdata$::gifend\ -metadata {comment bar} } -body { |