<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://tcl.activestate.com/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Thu Feb 09 12:20:54 GMT 2012 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='14'>
<header><title>Access to Tk Photo Image Transparency</title><author address="mailto:fellowsd@cs.man.ac.uk">Donal K. Fellows</author><status type='project' state='final' tclversion="8.4.0" vote='after'>$Revision: 2.5 $</status><history></history><created day='22' month='nov' year='2000' /><keyword>Tk photo transparency internal access</keyword></header>
<abstract>It is useful for some code (both extensions and scripts) to have access to the transparency information in photo images for various reasons, but this is not currently available, even via an internal structure defined in <emph style="italic">generic/tkInt.h</emph>. This TIP is aimed at making the information available, and in such a way at the C level that backward compatibility is maintained in the future even if the internal structure definitions change.</abstract>
<body><section title="Rationale">
<para>I have been working for several years (on-and-off) on an extension for Tk that allows it to have non-rectangular windows (<url ref="http://www.cs.man.ac.uk/~fellowsd/tcl/shapeidx.html"/>) which is an effect that is great for all sorts of purposes but which comes particularly into its own when used in conjunction with drag-and-drop to make drag tokens that obscure only part of what lies underneath them. However, one of the most useful ways of specifying the shape of a window turns out to be via images of various kinds, and the natural way to do this is with the transparency data within the image. The problem is that this data is locked up entirely within structures that are completely private to <emph style="italic">generic/tkImgPhoto.c</emph>; none of it is visible at all anywhere else, even within the core. (There is code that uses colour data instead to do this sort of trick, <url ref="http://www.sys.uea.ac.uk/~fuzz/tktrans/default.html"/>, but this is a slow process and frankly a little strange if we already have transparency data available.)</para>
<para>There is also a more general need for scripts to be able to discover more about the transparent areas of a photo image; at the moment, there is no access at all to that information at the script level.</para>
</section>
<section title="Changes to the C-Level API">
<para>To get around this problem, the data member <emph style="italic">validRegion</emph> of the <emph style="italic">PhotoMaster</emph> structure needs to be made available by some mechanism. There are two ways of doing this:</para>
<enumerate><item.e index='1'><para>Placing the <emph style="italic">PhotoMaster</emph> structure, or some version of it, in <emph style="italic">generic/tkInt.h</emph>, or</para></item.e><item.e index='2'><para>Creating a function to access the data member.</para></item.e></enumerate>
<para>The first way is very cheap initially, but also very inflexible and creates yet another hidden version dependency (such as is tackled in <tipref type="text" tip="5"/>) should we decide to change the structure for any reason (we also have had problems with this sort of thing in the past in relation to the <emph style="italic">Tcl_Interp</emph> member <emph style="italic">result</emph>, direct access to which has been deprecated for years, but where there is still existing code that does it and which forms one of the largest barriers for some extensions from upgrading to Tcl 8.0 or later.) It is also unnecessary since only the core needs to know how to create new instances of the structure.</para>
<para>The second way, by contrast, is far more flexible in the future as it will allow us to completely change the internal implementation of photo image transparency without affecting any extensions at all. The cost of doing this is that a new entry in one of the stub tables must be created. Due to the fact that the type of the <emph style="italic">validRegion</emph> member is (currently) internal, I propose adding the function to the <emph style="italic">tkInt</emph> stub interface, and I propose calling the function <emph style="italic">TkPhotoGetValidRegion</emph>.</para>
</section>
<section title="Changes to the Tcl-Level API">
<para>I propose to add an extra subcommand to photo image instances which will provide all the access to and manipulation of transparency data. I propose to call this subcommand <emph style="italic">transparency</emph> and it will have subsubcommands to provide access to the various facilities it provides. Initially I will provide a <emph style="italic">get</emph> subsubcommand to allow the testing of the transparency of a single pixel (returned as a boolean value), and a <emph style="italic">set</emph> subsubcommand to allow the setting of the transparency of a single pixel. I anticipate that these will be expanded in the future to allow the manipulation of transparencies of rectangular regions (both getting and setting) but I do not supply such at this stage.</para>
<verbatim><vline encoding='base64'>ICAgaW1hZ2UgY3JlYXRlIHBob3RvIHBoSW1nIC1maWxlIHRoaW5neS5naWY=</vline><vline encoding='base64'>ICAgaWYge1twaEltZyB0cmFuc3BhcmVuY3kgZ2V0IDAgMF19IHs=</vline><vline encoding='base64'>ICAgICAgIyBUb3AtbGVmdCBwaXhlbCBpcyB0cmFuc3BhcmVudC4uLg==</vline><vline encoding='base64'>ICAgfQ==</vline><vline encoding='base64'></vline><vline encoding='base64'>ICAgIyBUb2dnbGUgdHJhbnNwYXJlbmN5Li4u</vline><vline encoding='base64'>ICAgcGhJbWcgdHJhbnNwYXJlbmN5IHNldCAwIDAgW2V4cHIgeyFbcGhJbWcgdHJhbnNwYXJlbmN5IGdldCAwIDBdfV0=</vline></verbatim>
</section>
<section title="Sample Implementation Patches">
<para>Exposing the transparency to C: <url ref="http://www.cs.man.ac.uk/~fellowsd/tcl/validRegion.patch"/></para>
<para>Exposing the transparency to Tcl: <url ref="http://www.cs.man.ac.uk/~fellowsd/tcl/patches/transCmd.patch"/></para>
</section>
<section title="Copyright">
<para>This document is placed in the public domain.</para>
</section>
</body></TIP>

