Tk Source Code

View Ticket
Login
Ticket UUID: 957190f13edebc32864d9feaa21e253c7b04a2b7
Title: Handle writing photo image with more than 256 colors to GIF proper
Type: Bug Version: current
Submitter: chw Created on: 2024-07-25 08:45:09
Subsystem: 41. Photo Images Assigned To: nobody
Priority: 5 Medium Severity: Important
Status: Open Last Modified: 2024-07-28 04:16:03
Resolution: None Closed By: nobody
    Closed on:
Description:
Please find a patch attached (against trunk) which deals with writing
photo images with more than 256 distinct colors as a GIF by reducing
the color bits. Not sure if this solution is ideal but at least it
allows for writing any photo image to a GIF.
User Comments: chw added on 2024-07-28 04:16:03:
Harald,

the "(char *) NULL" casts are needed for maximum C portability at
all call sites of Tcl_SetErrorCode() and Tcl_AppendResult().
There was a ticket regarding this fact in the Tcl repo. AFAIR, this
was done for the entire Tcl source tree plus explicitly mentioned
in the doc of the aforementioned APIs. It should be done for the
entire Tk source tree, too (ideally in a single huge commit).

oehhar added on 2024-07-27 17:50:54:

Merged the "(char *) NULL" to all branches, starting with commit [a9d63ce5]. No idea what this does, but the change does not cause any compiler warnings on MS-VC6 and MS-VS 2015. I suppose, some other compilers are happier now...

Thanks for all, Harald


obermeier added on 2024-07-26 20:21:13:
I tend to "off" because of backwards compatibility to 8.X as well as the Img extension, which also has a GIF writer throwing an error in that case.
Also I do not want to have the effect, where an algorithm does unexpected things, in that case store the photo with reduced resolution, but give the impression everything went fine.

chw added on 2024-07-26 18:51:12:
The current algo cuts as many bits as needed to constrain the
color table to at most 256 elements. I agree with Paul, that
a simple on/off flag should do the Right Thing(tm) for most
use cases. But then the next question arises: which is the
default, the "on" or the "off" state? I tend to "on" since it
eliminates run-time errors when writing GIFs.

obermeier added on 2024-07-26 17:51:59:
The color reduction should be made optional by using a format parameter.
Isn't a simple flag "-cutoff" or "-usecutoff" enough? The algorithm should know how much bits to reduce to fit into the GIF color range.

oehhar added on 2024-07-26 12:29:42:

Yes, the maximum bit cut-off level 0-6 may be set by a format parameter.

$image write -format "gif -maxcutoff 6" -file a.gif

Would you provide code for this? I would also love to get the opinion of Paul.

Thanks for all, Harald


chw added on 2024-07-26 12:16:47:
Regarding the "(char *) NULL": this should consequently be
done throughout the entire Tk source tree, ideally in a single
huge commit.

Regarding the color bit fiddling: maybe this should be made
optional per inspecting some magic flag in the format parameter
to the CommonWriteGIF() function.

oehhar added on 2024-07-25 13:33:14:

Christian, great work, looks reasonable, compiles with MS-VC6, passes the test suite.

Now in branch [957190f13-gif-export-more-colors] starting with commit [dd4205f4].

I have left out the correct "(char*)NULL" casts. They should go directly to the main branches.

Any opinions on this?

Thanks, Harald


chw added on 2024-07-25 08:46:28:
Correction: the patch is against core-8-6-branch.

Attachments: