Pillow/Tk/booster.txt

109 lines
3.8 KiB
Plaintext
Raw Normal View History

2010-07-31 06:52:47 +04:00
====================================================================
The Photoimage Booster Patch (for Windows 95/NT)
====================================================================
This patch kit boosts performance for 16/24-bit displays. The
first patch is required on Tk 4.2 (where it fixes the problems for
16-bit displays) and later versions, with the exception for Tk 8.0b1
where Sun added something similar themselves, only to remove it in
8.0b2. By installing both patches, Tk's PhotoImage handling becomes
much faster on both 16-bit and 24-bit displays. The patch has been
tested with Tk 4.2 and 8.0.
Here's a benchmark, made with a sample program which loads two
512x512 greyscale PGM's, and two 512x512 colour PPM's, and displays
each of them in a separate toplevel windows. Tcl/Tk was compiled
with Visual C 4.0, and run on a P100 under Win95. Image load times
are not included in the timings:
8-bit 16-bit 24-bit
--------------------------------------------------------------------
1. original 4.2 code 5.52 s 8.57 s 3.79 s
2. booster patch 5.49 s 1.87 s 1.82 s
speedup None 4.6x 2.1x
====================================================================
Here's the patches:
1. For portability and speed, the best thing under Windows is to
treat 16-bit displays as if they were 24-bit. The Windows device
drivers take care of the rest.
----------------------------------------------------------------
If you have Tk 4.1 or Tk 8.0b1, you don't have to apply this
patch! It only applies to Tk 4.2, Tk 8.0a[12] and Tk 8.0b2.
----------------------------------------------------------------
In win/tkWinImage.c, change the following line in XCreateImage:
imagePtr->bits_per_pixel = depth;
to
/* ==================================================================== */
/* The tk photo image booster patch -- patch section 1 */
/* ==================================================================== */
if (visual->class == TrueColor)
/* true colour is stored as 3 bytes: (blue, green, red) */
imagePtr->bits_per_pixel = 24;
else
imagePtr->bits_per_pixel = depth;
/* ==================================================================== */
2. The DitherInstance implementation is not good. It's especially
bad on highend truecolour displays. IMO, it should be rewritten from
scratch (some other day...).
Anyway, the following band-aid makes the situation a little bit
better under Windows. This hack trades some marginal quality (no
dithering on 16-bit displays) for a dramatic performance boost.
Requires patch 1, unless you're using Tk 4.1 or Tk 8.0b1.
In generic/tkImgPhoto.c, add the #ifdef section to the DitherInstance
function:
for (; height > 0; height -= nLines) {
if (nLines > height) {
nLines = height;
}
dstLinePtr = (unsigned char *) imagePtr->data;
yEnd = yStart + nLines;
/* ==================================================================== */
/* The tk photo image booster patch -- patch section 2 */
/* ==================================================================== */
#ifdef __WIN32__
if (colorPtr->visualInfo.class == TrueColor
&& instancePtr->gamma == 1.0) {
/* Windows hicolor/truecolor booster */
for (y = yStart; y < yEnd; ++y) {
destBytePtr = dstLinePtr;
srcPtr = srcLinePtr;
for (x = xStart; x < xEnd; ++x) {
destBytePtr[0] = srcPtr[2];
destBytePtr[1] = srcPtr[1];
destBytePtr[2] = srcPtr[0];
destBytePtr += 3; srcPtr += 3;
}
srcLinePtr += lineLength;
dstLinePtr += bytesPerLine;
}
} else
#endif
/* ==================================================================== */
for (y = yStart; y < yEnd; ++y) {
srcPtr = srcLinePtr;
errPtr = errLinePtr;
destBytePtr = dstLinePtr;
====================================================================
last updated: 97-07-03/fl