summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
Diffstat (limited to 'generic')
-rw-r--r--generic/tkFont.c15
-rw-r--r--generic/tkImgPPM.c58
-rw-r--r--generic/tkOption.c25
3 files changed, 71 insertions, 27 deletions
diff --git a/generic/tkFont.c b/generic/tkFont.c
index ad009b9..cbc4cf4 100644
--- a/generic/tkFont.c
+++ b/generic/tkFont.c
@@ -421,7 +421,7 @@ TkFontPkgFree(
fontsLeft++;
#ifdef DEBUG_FONTS
fprintf(stderr, "Font %s still in cache.\n",
- Tcl_GetHashKey(&fiPtr->fontCache, searchPtr));
+ (char *) Tcl_GetHashKey(&fiPtr->fontCache, searchPtr));
#endif
}
@@ -1093,7 +1093,8 @@ Tk_AllocFontFromObj(
int isNew, descent;
NamedFont *nfPtr;
- if (objPtr->typePtr != &tkFontObjType) {
+ if (objPtr->typePtr != &tkFontObjType
+ || objPtr->internalRep.twoPtrValue.ptr2 != fiPtr) {
SetFontFromAny(interp, objPtr);
}
@@ -1133,6 +1134,7 @@ Tk_AllocFontFromObj(
fontPtr->resourceRefCount++;
fontPtr->objRefCount++;
objPtr->internalRep.twoPtrValue.ptr1 = fontPtr;
+ objPtr->internalRep.twoPtrValue.ptr2 = fiPtr;
return (Tk_Font) fontPtr;
}
}
@@ -1243,6 +1245,7 @@ Tk_AllocFontFromObj(
}
objPtr->internalRep.twoPtrValue.ptr1 = fontPtr;
+ objPtr->internalRep.twoPtrValue.ptr2 = fiPtr;
return (Tk_Font) fontPtr;
}
@@ -1275,7 +1278,8 @@ Tk_GetFontFromObj(
TkFont *fontPtr;
Tcl_HashEntry *hashPtr;
- if (objPtr->typePtr != &tkFontObjType) {
+ if (objPtr->typePtr != &tkFontObjType
+ || objPtr->internalRep.twoPtrValue.ptr2 != fiPtr) {
SetFontFromAny(NULL, objPtr);
}
@@ -1311,6 +1315,7 @@ Tk_GetFontFromObj(
if (Tk_Screen(tkwin) == fontPtr->screen) {
fontPtr->objRefCount++;
objPtr->internalRep.twoPtrValue.ptr1 = fontPtr;
+ objPtr->internalRep.twoPtrValue.ptr2 = fiPtr;
return (Tk_Font) fontPtr;
}
}
@@ -1356,6 +1361,7 @@ SetFontFromAny(
}
objPtr->typePtr = &tkFontObjType;
objPtr->internalRep.twoPtrValue.ptr1 = NULL;
+ objPtr->internalRep.twoPtrValue.ptr2 = NULL;
return TCL_OK;
}
@@ -1519,6 +1525,7 @@ FreeFontObj(
ckfree(fontPtr);
}
objPtr->internalRep.twoPtrValue.ptr1 = NULL;
+ objPtr->internalRep.twoPtrValue.ptr2 = NULL;
}
}
@@ -1549,6 +1556,8 @@ DupFontObjProc(
dupObjPtr->typePtr = srcObjPtr->typePtr;
dupObjPtr->internalRep.twoPtrValue.ptr1 = fontPtr;
+ dupObjPtr->internalRep.twoPtrValue.ptr2
+ = srcObjPtr->internalRep.twoPtrValue.ptr2;
if (fontPtr != NULL) {
fontPtr->objRefCount++;
diff --git a/generic/tkImgPPM.c b/generic/tkImgPPM.c
index edd1b71..6f084f0 100644
--- a/generic/tkImgPPM.c
+++ b/generic/tkImgPPM.c
@@ -141,7 +141,7 @@ FileReadPPM(
* image being read. */
{
int fileWidth, fileHeight, maxIntensity;
- int nLines, nBytes, h, type, count;
+ int nLines, nBytes, h, type, count, bytesPerChannel = 1;
unsigned char *pixelPtr;
Tk_PhotoImageBlock block;
@@ -158,12 +158,14 @@ FileReadPPM(
Tcl_SetErrorCode(interp, "TK", "IMAGE", "PPM", "DIMENSIONS", NULL);
return TCL_ERROR;
}
- if ((maxIntensity <= 0) || (maxIntensity >= 256)) {
+ if ((maxIntensity <= 0) || (maxIntensity > 0xffff)) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"PPM image file \"%s\" has bad maximum intensity value %d",
fileName, maxIntensity));
Tcl_SetErrorCode(interp, "TK", "IMAGE", "PPM", "INTENSITY", NULL);
return TCL_ERROR;
+ } else if (maxIntensity > 0x00ff) {
+ bytesPerChannel = 2;
}
if ((srcX + width) > fileWidth) {
@@ -173,20 +175,20 @@ FileReadPPM(
height = fileHeight - srcY;
}
if ((width <= 0) || (height <= 0)
- || (srcX >= fileWidth) || (srcY >= fileHeight)) {
+ || (srcX >= fileWidth) || (srcY >= fileHeight)) {
return TCL_OK;
}
if (type == PGM) {
- block.pixelSize = 1;
+ block.pixelSize = 1 * bytesPerChannel;
block.offset[0] = 0;
block.offset[1] = 0;
block.offset[2] = 0;
} else {
- block.pixelSize = 3;
+ block.pixelSize = 3 * bytesPerChannel;
block.offset[0] = 0;
- block.offset[1] = 1;
- block.offset[2] = 2;
+ block.offset[1] = 1 * bytesPerChannel;
+ block.offset[2] = 2 * bytesPerChannel;
}
block.offset[3] = 0;
block.width = width;
@@ -228,12 +230,21 @@ FileReadPPM(
ckfree(pixelPtr);
return TCL_ERROR;
}
- if (maxIntensity != 255) {
+ if (maxIntensity < 0x00ff) {
unsigned char *p;
for (p = pixelPtr; count > 0; count--, p++) {
*p = (((int) *p) * 255)/maxIntensity;
}
+ } else if (maxIntensity > 0x00ff) {
+ unsigned char *p;
+ unsigned int value;
+
+ for (p = pixelPtr; count > 0; count--, p += 2) {
+ value = ((unsigned int) p[0]) * 256 + ((unsigned int) p[1]);
+ value = value * 255 / maxIntensity;
+ p[0] = p[1] = (unsigned char) value;
+ }
}
block.height = nLines;
if (Tk_PhotoPutBlock(interp, imageHandle, &block, destX, destY,
@@ -478,7 +489,7 @@ StringReadPPM(
* image being read. */
{
int fileWidth, fileHeight, maxIntensity;
- int nLines, nBytes, h, type, count, dataSize;
+ int nLines, nBytes, h, type, count, dataSize, bytesPerChannel = 1;
unsigned char *pixelPtr, *dataBuffer;
Tk_PhotoImageBlock block;
@@ -496,12 +507,14 @@ StringReadPPM(
Tcl_SetErrorCode(interp, "TK", "IMAGE", "PPM", "DIMENSIONS", NULL);
return TCL_ERROR;
}
- if ((maxIntensity <= 0) || (maxIntensity >= 256)) {
+ if ((maxIntensity <= 0) || (maxIntensity > 0xffff)) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"PPM image data has bad maximum intensity value %d",
maxIntensity));
Tcl_SetErrorCode(interp, "TK", "IMAGE", "PPM", "INTENSITY", NULL);
return TCL_ERROR;
+ } else if (maxIntensity > 0x00ff) {
+ bytesPerChannel = 2;
}
if ((srcX + width) > fileWidth) {
@@ -516,15 +529,15 @@ StringReadPPM(
}
if (type == PGM) {
- block.pixelSize = 1;
+ block.pixelSize = 1 * bytesPerChannel;
block.offset[0] = 0;
block.offset[1] = 0;
block.offset[2] = 0;
} else {
- block.pixelSize = 3;
+ block.pixelSize = 3 * bytesPerChannel;
block.offset[0] = 0;
- block.offset[1] = 1;
- block.offset[2] = 2;
+ block.offset[1] = 1 * bytesPerChannel;
+ block.offset[2] = 2 * bytesPerChannel;
}
block.offset[3] = 0;
block.width = width;
@@ -535,7 +548,7 @@ StringReadPPM(
dataSize -= srcY * block.pitch;
}
- if (maxIntensity == 255) {
+ if (maxIntensity == 0x00ff) {
/*
* We have all the data in memory, so write everything in one go.
*/
@@ -582,8 +595,19 @@ StringReadPPM(
Tcl_SetErrorCode(interp, "TK", "IMAGE", "PPM", "TRUNCATED", NULL);
return TCL_ERROR;
}
- for (p=pixelPtr,count=nBytes ; count>0 ; count--,p++,dataBuffer++) {
- *p = (((int) *dataBuffer) * 255)/maxIntensity;
+ if (maxIntensity < 0x00ff) {
+ for (p=pixelPtr,count=nBytes ; count>0 ; count--,p++,dataBuffer++) {
+ *p = (((int) *dataBuffer) * 255)/maxIntensity;
+ }
+ } else {
+ unsigned char *p;
+ unsigned int value;
+
+ for (p = pixelPtr,count=nBytes; count > 1; count-=2, p += 2) {
+ value = ((unsigned int) p[0]) * 256 + ((unsigned int) p[1]);
+ value = value * 255 / maxIntensity;
+ p[0] = p[1] = (unsigned char) value;
+ }
}
dataSize -= nBytes;
block.height = nLines;
diff --git a/generic/tkOption.c b/generic/tkOption.c
index 2a8d501..75dc3b9 100644
--- a/generic/tkOption.c
+++ b/generic/tkOption.c
@@ -1016,14 +1016,25 @@ AddFromString(
Tcl_SetErrorCode(interp, "TK", "OPTIONDB", "NEWLINE", NULL);
return TCL_ERROR;
}
- if ((src[0] == '\\') && (src[1] == '\n')) {
- src += 2;
- lineNum++;
- } else {
- *dst = *src;
- dst++;
- src++;
+ if (*src == '\\'){
+ if (src[1] == '\n') {
+ src += 2;
+ lineNum++;
+ continue;
+ } else if (src[1] == 'n') {
+ src += 2;
+ *dst++ = '\n';
+ continue;
+ } else if (src[1] == '\t' || src[1] == ' ' || src[1] == '\\') {
+ ++src;
+ } else if (src[1] >= '0' && src[1] <= '3' && src[2] >= '0' &&
+ src[2] <= '9' && src[3] >= '0' && src[3] <= '9') {
+ *dst++ = ((src[1]&7)<<6) | ((src[2]&7)<<3) | (src[3]&7);
+ src += 4;
+ continue;
+ }
}
+ *dst++ = *src++;
}
*dst = 0;