Tk Source Code

Check-in [acbeaf88]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:improved, faster implementations of XParseColor and TkParseColor
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | bug-3486474
Files: files | file ages | folders
SHA1: acbeaf88e1a8db42cf869b5128c3bd32be31f5f8
User & Date: jan.nijtmans 2012-02-12 17:46:18
Context
2012-02-15
20:33
[Bug 3486474]: Inconsistent color scaling check-in: feaff433 user: jan.nijtmans tags: core-8-4-branch
2012-02-12
17:46
improved, faster implementations of XParseColor and TkParseColor Closed-Leaf check-in: acbeaf88 user: jan.nijtmans tags: bug-3486474
2012-02-11
00:19
let Tk_NameOfColor output a shorter color-name, when possible check-in: 349169c6 user: jan.nijtmans tags: bug-3486474
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ChangeLog.








1
2
3
4
5
6
7







2012-01-25  Jan Nijtmans  <[email protected]>

	* generic/tkImgPhoto.c: [Bug 2433260]: non-critical error in
	Tk_PhotoPutBlock

2011-11-22  Jan Nijtmans  <[email protected]>

>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
2012-02-??  Jan Nijtmans  <[email protected]>

	* xlib/xcolors.c: [Bug 3486474]: Inconsistent color scaling
	* generic/tkColor.c: new internal function TkParseColor
	* generic/tkInt.h:
	* generic/tk*.c:   Change XParseColor() to TkParseColor() everywhere.

2012-01-25  Jan Nijtmans  <[email protected]>

	* generic/tkImgPhoto.c: [Bug 2433260]: non-critical error in
	Tk_PhotoPutBlock

2011-11-22  Jan Nijtmans  <[email protected]>

Changes to generic/tkColor.c.

373
374
375
376
377
378
379
380

381
382
383
384
385
386
387
    } else {
	ThreadSpecificData *tsdPtr = (ThreadSpecificData *) 
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
	sprintf(tsdPtr->rgbString, "#%04x%04x%04x", colorPtr->red, 
		colorPtr->green, colorPtr->blue);
	/* If the string has the form #RSRSTUTUVWVW (where equal
	 * letters denote equal hexdigits) then this is
	 * equivalent to #RSTUVW. Then output the shorter form */

	if ((tsdPtr->rgbString[1] == tsdPtr->rgbString[3])
		&& (tsdPtr->rgbString[2] == tsdPtr->rgbString[4])
		&& (tsdPtr->rgbString[5] == tsdPtr->rgbString[7])
		&& (tsdPtr->rgbString[6] == tsdPtr->rgbString[8])
		&& (tsdPtr->rgbString[9] == tsdPtr->rgbString[11])
		&& (tsdPtr->rgbString[10] == tsdPtr->rgbString[12])) {
	    tsdPtr->rgbString[3] = tsdPtr->rgbString[5];







|
>







373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
    } else {
	ThreadSpecificData *tsdPtr = (ThreadSpecificData *) 
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
	sprintf(tsdPtr->rgbString, "#%04x%04x%04x", colorPtr->red, 
		colorPtr->green, colorPtr->blue);
	/* If the string has the form #RSRSTUTUVWVW (where equal
	 * letters denote equal hexdigits) then this is
	 * equivalent to #RSTUVW. Then output the shorter form
	 * !!!! Only to be merged to Tcl 8.6, not earlier versions!!! */
	if ((tsdPtr->rgbString[1] == tsdPtr->rgbString[3])
		&& (tsdPtr->rgbString[2] == tsdPtr->rgbString[4])
		&& (tsdPtr->rgbString[5] == tsdPtr->rgbString[7])
		&& (tsdPtr->rgbString[6] == tsdPtr->rgbString[8])
		&& (tsdPtr->rgbString[9] == tsdPtr->rgbString[11])
		&& (tsdPtr->rgbString[10] == tsdPtr->rgbString[12])) {
	    tsdPtr->rgbString[3] = tsdPtr->rgbString[5];
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854

855
856
857
858
859
860
861
862
863
864
865
866


867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
    Colormap map;			/* Color map */
    _Xconst char* spec;     /* String to be parsed */
    XColor * colorPtr;
{
    if (*spec == '#') {
    char buf[14];
    buf[0] = '#'; buf[13] = '\0';
	if (!spec[1] || !spec[2] || !spec[3]) {
	/* Not at least 3 hex digits, so invalid */
	return 0;
	} else if (!spec[4]) {
	/* Exactly 3 hex digits */
	buf[1] = buf[2] = buf[3] = buf[4] = spec[1];
	buf[5] = buf[6] = buf[7] = buf[8] = spec[2];
	buf[9] = buf[10] = buf[11] = buf[12] = spec[3];
	return XParseColor(display, map, buf, colorPtr);
	} else if (!spec[5]	|| !spec[6]) {
	/* Not at least 6 hex digits, so invalid */
	return 0;
	} else if (!spec[7]) {
	/* Exactly 6 hex digits */

	buf[1] = buf[3] = spec[1];
	buf[2] = buf[4] = spec[2];
	buf[5] = buf[7] = spec[3];
	buf[6] = buf[8] = spec[4];
	buf[9] = buf[11] = spec[5];
	buf[10] = buf[12] = spec[6];
	return XParseColor(display, map, buf, colorPtr);
	} else if (!spec[8] || !spec[9]) {
	/* Not at least 9 hex digits, so invalid */
	return 0;
	} else if (!spec[10]) {
	/* Exactly 9 hex digits */


	buf[1] = buf[4] = spec[1];
	buf[2] = spec[2];
	buf[3] = spec[3];
	buf[5] = buf[8] = spec[4];
	buf[6] = spec[5];
	buf[7] = spec[6];
	buf[9] = buf[12] = spec[7];
	buf[10] = spec[8];
	buf[11] = spec[9];
	return XParseColor(display, map, buf, colorPtr);
	}
    }
    return XParseColor(display, map, spec, colorPtr);
}
#endif /* __WIN32__ */







|


|

|
|
|
|
|


|

>
|
|
|
|
|
|
<
|


|

>
>
|
|
|
|
|
|
|
|
<
<





835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862

863
864
865
866
867
868
869
870
871
872
873
874
875
876
877


878
879
880
881
882
    Colormap map;			/* Color map */
    _Xconst char* spec;     /* String to be parsed */
    XColor * colorPtr;
{
    if (*spec == '#') {
    char buf[14];
    buf[0] = '#'; buf[13] = '\0';
	if (!*(++spec) || !*(++spec) || !*(++spec)) {
	/* Not at least 3 hex digits, so invalid */
	return 0;
	} else if (!*(++spec)) {
	/* Exactly 3 hex digits */
	buf[9] = buf[10] = buf[11] = buf[12] = *(--spec);
	buf[5] = buf[6] = buf[7] = buf[8] = *(--spec);
	buf[1] = buf[2] = buf[3] = buf[4] = *(--spec);
	spec = buf;
	} else if (!*(++spec)	|| !*(++spec)) {
	/* Not at least 6 hex digits, so invalid */
	return 0;
	} else if (!*(++spec)) {
	/* Exactly 6 hex digits */
	buf[10] = buf[12] = *(--spec);
	buf[9] = buf[11] = *(--spec);
	buf[6] = buf[8] = *(--spec);
	buf[5] = buf[7] = *(--spec);
	buf[2] = buf[4] = *(--spec);
	buf[1] = buf[3] = *(--spec);
	spec = buf;

	} else if (!*(++spec) || !*(++spec)) {
	/* Not at least 9 hex digits, so invalid */
	return 0;
	} else if (!*(++spec)) {
	/* Exactly 9 hex digits */
	buf[11] = *(--spec);
	buf[10] = *(--spec);
	buf[9] = buf[12] = *(--spec);
	buf[7] = *(--spec);
	buf[6] = *(--spec);
	buf[5] = buf[8] = *(--spec);
	buf[3] = *(--spec);
	buf[2] = *(--spec);
	buf[1] = buf[4] = *(--spec);
	spec = buf;


	}
    }
    return XParseColor(display, map, spec, colorPtr);
}
#endif /* __WIN32__ */

Changes to generic/tkStubInit.c.

41
42
43
44
45
46
47






48
49
50
51
52
53
54
 * Remove macros that will interfere with the definitions below.
 */

#define Tk_CreateCanvasVisitor ((void (*) _ANSI_ARGS_((Tcl_Interp * interp, \
			VOID * typePtr))) NULL)
#define Tk_GetCanvasVisitor ((VOID * (*) _ANSI_ARGS_((Tcl_Interp * interp, \
			CONST char * name))) NULL)







/*
 * WARNING: The contents of this file is automatically generated by the
 * tools/genStubs.tcl script. Any modifications to the function declarations
 * below should be made in the generic/tk.decls script.
 */








>
>
>
>
>
>







41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 * Remove macros that will interfere with the definitions below.
 */

#define Tk_CreateCanvasVisitor ((void (*) _ANSI_ARGS_((Tcl_Interp * interp, \
			VOID * typePtr))) NULL)
#define Tk_GetCanvasVisitor ((VOID * (*) _ANSI_ARGS_((Tcl_Interp * interp, \
			CONST char * name))) NULL)

#ifndef __WIN32__
/* Make sure that extensions which call XParseColor through
 * the stub table, call TkParseColor in stead. See bug #3486474 */
#   define XParseColor TkParseColor
#endif

/*
 * WARNING: The contents of this file is automatically generated by the
 * tools/genStubs.tcl script. Any modifications to the function declarations
 * below should be made in the generic/tk.decls script.
 */

Changes to xlib/xcolors.c.

878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931


932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
XParseColor(display, map, spec, colorPtr)
    Display *display;
    Colormap map;
    const char* spec;
    XColor *colorPtr;
{
    if (spec[0] == '#') {
    char rstr[5], gstr[5], bstr[5];

    if (!isxdigit((unsigned char) spec[1])
	    || !isxdigit((unsigned char) spec[2])
	    || !isxdigit((unsigned char) spec[3])) {
	/* Not at least 3 hex digits, so invalid */
	return 0;
    } else if (!spec[4]) {
	/* Exactly 3 hex digits */
	rstr[0] = rstr[1] = rstr[2] = rstr[3] = spec[1];
	gstr[0] = gstr[1] = gstr[2] = gstr[3] = spec[2];
	bstr[0] = bstr[1] = bstr[2] = bstr[3] = spec[3];
    } else if (!isxdigit((unsigned char) spec[4])
	    || !isxdigit((unsigned char) spec[5])
	    || !isxdigit((unsigned char) spec[6])) {
	/* Not at least 6 hex digits, so invalid */
	return 0;
    } else if (!spec[7]) {
	/* Exactly 6 hex digits */
	rstr[0] = rstr[2] = spec[1];
	rstr[1] = rstr[3] = spec[2];
	gstr[0] = gstr[2] = spec[3];
	gstr[1] = gstr[3] = spec[4];
	bstr[0] = bstr[2] = spec[5];
	bstr[1] = bstr[3] = spec[6];
    } else if (!isxdigit((unsigned char) spec[7])
	    || !isxdigit((unsigned char) spec[8])
	    || !isxdigit((unsigned char) spec[9])) {
	/* Not at least 9 hex digits, so invalid */
	return 0;
    } else if (!spec[10]) {
	/* Exactly 9 hex digits */
	rstr[0] = rstr[3] = spec[1];
	rstr[1] = spec[2];
	rstr[2] = spec[3];
	gstr[0] = gstr[3] = spec[4];
	gstr[1] = spec[5];
	gstr[2] = spec[6];
	bstr[0] = bstr[3] = spec[7];
	bstr[1] = spec[8];
	bstr[2] = spec[9];
    } else if (!isxdigit((unsigned char) spec[10])
	    || !isxdigit((unsigned char) spec[11])
	    || !isxdigit((unsigned char) spec[12]) || spec[13]) {
	/* Not exactly 12 hex digits, so invalid */
	return 0;
    } else {


	/* Exactly 12 hex digits */
	rstr[0] = spec[1];
	rstr[1] = spec[2];
	rstr[2] = spec[3];
	rstr[3] = spec[4];
	gstr[0] = spec[5];
	gstr[1] = spec[6];
	gstr[2] = spec[7];
	gstr[3] = spec[8];
	bstr[0] = spec[9];
	bstr[1] = spec[10];
	bstr[2] = spec[11];
	bstr[3] = spec[12];
    }
    rstr[4] = gstr[4] = bstr[4] = '\0';
    colorPtr->red = strtol(rstr, NULL, 16);
    colorPtr->green = strtol(gstr, NULL, 16);
    colorPtr->blue = strtol(bstr, NULL, 16);
    } else {
	if (!FindColor(spec, colorPtr)) {
	    return 0;
	}
    }
    colorPtr->pixel = TkpGetPixel(colorPtr);
    colorPtr->flags = DoRed|DoGreen|DoBlue;







|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
|
|
|
|
|
|
<
|
|
|
<
|
|
>
>
|
|
|
|
|
|
|
|
|
<
<
<
<
|
<
<
<
<







878
879
880
881
882
883
884
885
886






























887
888
889
890
891
892
893
894

895
896
897

898
899
900
901
902
903
904
905
906
907
908
909
910




911




912
913
914
915
916
917
918
XParseColor(display, map, spec, colorPtr)
    Display *display;
    Colormap map;
    const char* spec;
    XColor *colorPtr;
{
    if (spec[0] == '#') {
	char *p;
	Tcl_WideInt value = _strtoi64(++spec, &p, 16);































	switch ((int)(p-spec)) {
	case 3:
	    colorPtr->red = (unsigned short) (((value >> 8) & 0xf) * 0x1111);
	    colorPtr->green = (unsigned short) (((value >> 4) & 0xf) * 0x1111);
	    colorPtr->blue = (unsigned short) ((value & 0xf) * 0x1111);
	    break;
	case 6:

	    colorPtr->red = (unsigned short) (((value >> 16) & 0xff) | ((value >> 8) & 0xff00));
	    colorPtr->green = (unsigned short) (((value >> 8) & 0xff) | (value & 0xff00));
	    colorPtr->blue = (unsigned short) ((value & 0xff) | (value << 8));

	    break;
	case 9:
	    colorPtr->red = (unsigned short) (((value >> 32) & 0xf) | ((value >> 20) & 0xfff0));
	    colorPtr->green = (unsigned short) (((value >> 20) & 0xf) | ((value >> 8) & 0xfff0));
	    colorPtr->blue = (unsigned short) (((value >> 8) & 0xf) | (value << 4));
	    break;
	case 12:
	    colorPtr->red = (unsigned short) (value >> 32);
	    colorPtr->green = (unsigned short) (value >> 16);
	    colorPtr->blue = (unsigned short) value;
	    break;
	default:
	    return 0;




	}




    } else {
	if (!FindColor(spec, colorPtr)) {
	    return 0;
	}
    }
    colorPtr->pixel = TkpGetPixel(colorPtr);
    colorPtr->flags = DoRed|DoGreen|DoBlue;