Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Imaging/Tk/booster.txt
blob: 2d787983b7589fac766ae888c75f1d0d1516e7bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
====================================================================
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