diff options
Diffstat (limited to 'generic/tkImgPhInstance.c')
-rw-r--r-- | generic/tkImgPhInstance.c | 187 |
1 files changed, 91 insertions, 96 deletions
diff --git a/generic/tkImgPhInstance.c b/generic/tkImgPhInstance.c index 81b196c..55cc226 100644 --- a/generic/tkImgPhInstance.c +++ b/generic/tkImgPhInstance.c @@ -19,9 +19,7 @@ */ #include "tkImgPhoto.h" -#ifdef MAC_OSX_TK -#define TKPUTIMAGE_CAN_BLEND -#endif +#include "tkPort.h" /* * Declaration for internal Xlib function used here: @@ -46,7 +44,7 @@ static void BlendComplexAlpha(XImage *bgImg, PhotoInstance *iPtr, #endif static int IsValidPalette(PhotoInstance *instancePtr, const char *palette); -static int CountBits(pixel mask); +static int CountBits(unsigned mask); static void GetColorTable(PhotoInstance *instancePtr); static void FreeColorTable(ColorTable *colorPtr, int force); static void AllocateColors(ColorTable *colorPtr); @@ -68,8 +66,8 @@ static int imgPhotoColorHashInitialized; * TkImgPhotoConfigureInstance -- * * This function is called to create displaying information for a photo - * image instance based on the configuration information in the master. - * It is invoked both when new instances are created and when the master + * image instance based on the configuration information in the model. + * It is invoked both when new instances are created and when the model * is reconfigured. * * Results: @@ -86,25 +84,25 @@ void TkImgPhotoConfigureInstance( PhotoInstance *instancePtr) /* Instance to reconfigure. */ { - PhotoMaster *masterPtr = instancePtr->masterPtr; + PhotoModel *modelPtr = instancePtr->modelPtr; XImage *imagePtr; int bitsPerPixel; ColorTable *colorTablePtr; XRectangle validBox; /* - * If the -palette configuration option has been set for the master, use + * If the -palette configuration option has been set for the model, use * the value specified for our palette, but only if it is a valid palette - * for our windows. Use the gamma value specified the master. + * for our windows. Use the gamma value specified the model. */ - if ((masterPtr->palette && masterPtr->palette[0]) - && IsValidPalette(instancePtr, masterPtr->palette)) { - instancePtr->palette = masterPtr->palette; + if ((modelPtr->palette && modelPtr->palette[0]) + && IsValidPalette(instancePtr, modelPtr->palette)) { + instancePtr->palette = modelPtr->palette; } else { instancePtr->palette = instancePtr->defaultPalette; } - instancePtr->gamma = masterPtr->gamma; + instancePtr->gamma = modelPtr->gamma; /* * If we don't currently have a color table, or if the one we have no @@ -168,15 +166,15 @@ TkImgPhotoConfigureInstance( } /* - * If the user has specified a width and/or height for the master which is + * If the user has specified a width and/or height for the model which is * different from our current width/height, set the size to the values * specified by the user. If we have no pixmap, we do this also, since it * has the side effect of allocating a pixmap for us. */ if ((instancePtr->pixels == None) || (instancePtr->error == NULL) - || (instancePtr->width != masterPtr->width) - || (instancePtr->height != masterPtr->height)) { + || (instancePtr->width != modelPtr->width) + || (instancePtr->height != modelPtr->height)) { TkImgPhotoInstanceSetSize(instancePtr); } @@ -184,9 +182,9 @@ TkImgPhotoConfigureInstance( * Redither this instance if necessary. */ - if ((masterPtr->flags & IMAGE_CHANGED) + if ((modelPtr->flags & IMAGE_CHANGED) || (instancePtr->colorTablePtr != colorTablePtr)) { - TkClipBox(masterPtr->validRegion, &validBox); + TkClipBox(modelPtr->validRegion, &validBox); if ((validBox.width > 0) && (validBox.height > 0)) { TkImgDitherInstance(instancePtr, validBox.x, validBox.y, validBox.width, validBox.height); @@ -216,10 +214,10 @@ ClientData TkImgPhotoGet( Tk_Window tkwin, /* Window in which the instance will be * used. */ - ClientData masterData) /* Pointer to our master structure for the + ClientData modelData) /* Pointer to our model structure for the * image. */ { - PhotoMaster *masterPtr = (PhotoMaster *)masterData; + PhotoModel *modelPtr = (PhotoModel *)modelData; PhotoInstance *instancePtr; Colormap colormap; int mono, nRed, nGreen, nBlue, numVisuals; @@ -256,7 +254,7 @@ TkImgPhotoGet( */ colormap = Tk_Colormap(tkwin); - for (instancePtr = masterPtr->instancePtr; instancePtr != NULL; + for (instancePtr = modelPtr->instancePtr; instancePtr != NULL; instancePtr = instancePtr->nextPtr) { if ((colormap == instancePtr->colormap) && (Tk_Display(tkwin) == instancePtr->display)) { @@ -286,7 +284,7 @@ TkImgPhotoGet( */ instancePtr = (PhotoInstance *)ckalloc(sizeof(PhotoInstance)); - instancePtr->masterPtr = masterPtr; + instancePtr->modelPtr = modelPtr; instancePtr->display = Tk_Display(tkwin); instancePtr->colormap = Tk_Colormap(tkwin); Tk_PreserveColormap(instancePtr->display, instancePtr->colormap); @@ -297,8 +295,8 @@ TkImgPhotoGet( instancePtr->width = 0; instancePtr->height = 0; instancePtr->imagePtr = 0; - instancePtr->nextPtr = masterPtr->instancePtr; - masterPtr->instancePtr = instancePtr; + instancePtr->nextPtr = modelPtr->instancePtr; + modelPtr->instancePtr = instancePtr; /* * Obtain information about the visual and decide on the default palette. @@ -358,8 +356,8 @@ TkImgPhotoGet( * Make a GC with background = black and foreground = white. */ - white = Tk_GetColor(masterPtr->interp, tkwin, "white"); - black = Tk_GetColor(masterPtr->interp, tkwin, "black"); + white = Tk_GetColor(modelPtr->interp, tkwin, "white"); + black = Tk_GetColor(modelPtr->interp, tkwin, "black"); gcValues.foreground = (white != NULL)? white->pixel: WhitePixelOfScreen(Tk_Screen(tkwin)); gcValues.background = (black != NULL)? black->pixel: @@ -382,8 +380,8 @@ TkImgPhotoGet( */ if (instancePtr->nextPtr == NULL) { - Tk_ImageChanged(masterPtr->tkMaster, 0, 0, 0, 0, - masterPtr->width, masterPtr->height); + Tk_ImageChanged(modelPtr->tkModel, 0, 0, 0, 0, + modelPtr->width, modelPtr->height); } return instancePtr; @@ -416,9 +414,6 @@ TkImgPhotoGet( * * Note that Win32 pre-defines those operations that we really need. * - * Note that on MacOS, if the background comes from a Retina display - * then it will be twice as wide and twice as high as the photoimage. - * *---------------------------------------------------------------------- */ #ifndef TKPUTIMAGE_CAN_BLEND @@ -446,8 +441,8 @@ BlendComplexAlpha( { int x, y, line; unsigned long pixel; - unsigned char r, g, b, alpha, unalpha, *masterPtr; - unsigned char *alphaAr = iPtr->masterPtr->pix32; + unsigned char r, g, b, alpha, unalpha, *modelPtr; + unsigned char *alphaAr = iPtr->modelPtr->pix32; /* * This blending is an integer version of the Source-Over compositing rule @@ -504,10 +499,10 @@ BlendComplexAlpha( green_mlen = 8 - CountBits(green_mask >> green_shift); blue_mlen = 8 - CountBits(blue_mask >> blue_shift); for (y = 0; y < height; y++) { - line = (y + yOffset) * iPtr->masterPtr->width; + line = (y + yOffset) * iPtr->modelPtr->width; for (x = 0; x < width; x++) { - masterPtr = alphaAr + ((line + x + xOffset) * 4); - alpha = masterPtr[3]; + modelPtr = alphaAr + ((line + x + xOffset) * 4); + alpha = modelPtr[3]; /* * Ignore pixels that are fully transparent @@ -519,9 +514,9 @@ BlendComplexAlpha( * 24 and 32 bit displays, but this seems "fast enough". */ - r = masterPtr[0]; - g = masterPtr[1]; - b = masterPtr[2]; + r = modelPtr[0]; + g = modelPtr[1]; + b = modelPtr[2]; if (alpha != 255) { /* * Only blend pixels that have some transparency @@ -547,10 +542,10 @@ BlendComplexAlpha( #endif /* !_WIN32 */ for (y = 0; y < height; y++) { - line = (y + yOffset) * iPtr->masterPtr->width; + line = (y + yOffset) * iPtr->modelPtr->width; for (x = 0; x < width; x++) { - masterPtr = alphaAr + ((line + x + xOffset) * 4); - alpha = masterPtr[3]; + modelPtr = alphaAr + ((line + x + xOffset) * 4); + alpha = modelPtr[3]; /* * Ignore pixels that are fully transparent @@ -562,9 +557,9 @@ BlendComplexAlpha( * and 32 bit displays, but this seems "fast enough". */ - r = masterPtr[0]; - g = masterPtr[1]; - b = masterPtr[2]; + r = modelPtr[0]; + g = modelPtr[1]; + b = modelPtr[2]; if (alpha != 255) { /* * Only blend pixels that have some transparency @@ -638,7 +633,7 @@ TkImgPhotoDisplay( * no need to call XGetImage or to do the Porter-Duff compositing by hand. */ - unsigned char *rgbaPixels = instancePtr->masterPtr->pix32; + unsigned char *rgbaPixels = instancePtr->modelPtr->pix32; XImage *photo = XCreateImage(display, NULL, 32, ZPixmap, 0, (char*)rgbaPixels, (unsigned int)instancePtr->width, (unsigned int)instancePtr->height, @@ -650,7 +645,7 @@ TkImgPhotoDisplay( XDestroyImage(photo); #else - if ((instancePtr->masterPtr->flags & COMPLEX_ALPHA) + if ((instancePtr->modelPtr->flags & COMPLEX_ALPHA) && visInfo.depth >= 15 && (visInfo.c_class == DirectColor || visInfo.c_class == TrueColor)) { Tk_ErrorHandler handler; @@ -691,14 +686,14 @@ TkImgPhotoDisplay( Tk_DeleteErrorHandler(handler); } else { /* - * masterPtr->region describes which parts of the image contain valid + * modelPtr->region describes which parts of the image contain valid * data. We set this region as the clip mask for the gc, setting its * origin appropriately, and use it when drawing the image. */ fallBack: TkSetRegion(display, instancePtr->gc, - instancePtr->masterPtr->validRegion); + instancePtr->modelPtr->validRegion); XSetClipOrigin(display, instancePtr->gc, drawableX - imageX, drawableY - imageY); XCopyArea(display, instancePtr->pixels, drawable, instancePtr->gc, @@ -781,23 +776,23 @@ void TkImgPhotoInstanceSetSize( PhotoInstance *instancePtr) /* Instance whose size is to be changed. */ { - PhotoMaster *masterPtr; + PhotoModel *modelPtr; schar *newError, *errSrcPtr, *errDestPtr; int h, offset; XRectangle validBox; Pixmap newPixmap; - masterPtr = instancePtr->masterPtr; - TkClipBox(masterPtr->validRegion, &validBox); + modelPtr = instancePtr->modelPtr; + TkClipBox(modelPtr->validRegion, &validBox); - if ((instancePtr->width != masterPtr->width) - || (instancePtr->height != masterPtr->height) + if ((instancePtr->width != modelPtr->width) + || (instancePtr->height != modelPtr->height) || (instancePtr->pixels == None)) { newPixmap = Tk_GetPixmap(instancePtr->display, RootWindow(instancePtr->display, instancePtr->visualInfo.screen), - (masterPtr->width > 0) ? masterPtr->width: 1, - (masterPtr->height > 0) ? masterPtr->height: 1, + (modelPtr->width > 0) ? modelPtr->width: 1, + (modelPtr->height > 0) ? modelPtr->height: 1, instancePtr->visualInfo.depth); if (!newPixmap) { Tcl_Panic("Fail to create pixmap with Tk_GetPixmap in TkImgPhotoInstanceSetSize"); @@ -827,17 +822,17 @@ TkImgPhotoInstanceSetSize( instancePtr->pixels = newPixmap; } - if ((instancePtr->width != masterPtr->width) - || (instancePtr->height != masterPtr->height) + if ((instancePtr->width != modelPtr->width) + || (instancePtr->height != modelPtr->height) || (instancePtr->error == NULL)) { - if (masterPtr->height > 0 && masterPtr->width > 0) { + if (modelPtr->height > 0 && modelPtr->width > 0) { /* * TODO: use attemptckalloc() here once there is a strategy that * will allow us to recover from failure. Right now, there's no * such possibility. */ - newError = (schar *)ckalloc(masterPtr->height * masterPtr->width + newError = (schar *)ckalloc(modelPtr->height * modelPtr->width * 3 * sizeof(schar)); /* @@ -846,21 +841,21 @@ TkImgPhotoInstanceSetSize( */ if ((instancePtr->error != NULL) - && ((instancePtr->width == masterPtr->width) - || (validBox.width == masterPtr->width))) { + && ((instancePtr->width == modelPtr->width) + || (validBox.width == modelPtr->width))) { if (validBox.y > 0) { memset(newError, 0, (size_t) - validBox.y * masterPtr->width * 3 * sizeof(schar)); + validBox.y * modelPtr->width * 3 * sizeof(schar)); } h = validBox.y + validBox.height; - if (h < masterPtr->height) { - memset(newError + h*masterPtr->width*3, 0, - (size_t) (masterPtr->height - h) - * masterPtr->width * 3 * sizeof(schar)); + if (h < modelPtr->height) { + memset(newError + h*modelPtr->width*3, 0, + (size_t) (modelPtr->height - h) + * modelPtr->width * 3 * sizeof(schar)); } } else { memset(newError, 0, (size_t) - masterPtr->height * masterPtr->width *3*sizeof(schar)); + modelPtr->height * modelPtr->width *3*sizeof(schar)); } } else { newError = NULL; @@ -872,22 +867,22 @@ TkImgPhotoInstanceSetSize( * array. */ - if (masterPtr->width == instancePtr->width) { - offset = validBox.y * masterPtr->width * 3; + if (modelPtr->width == instancePtr->width) { + offset = validBox.y * modelPtr->width * 3; memcpy(newError + offset, instancePtr->error + offset, (size_t) validBox.height - * masterPtr->width * 3 * sizeof(schar)); + * modelPtr->width * 3 * sizeof(schar)); } else if (validBox.width > 0 && validBox.height > 0) { errDestPtr = newError + - (validBox.y * masterPtr->width + validBox.x) * 3; + (validBox.y * modelPtr->width + validBox.x) * 3; errSrcPtr = instancePtr->error + (validBox.y * instancePtr->width + validBox.x) * 3; for (h = validBox.height; h > 0; --h) { memcpy(errDestPtr, errSrcPtr, validBox.width * 3 * sizeof(schar)); - errDestPtr += masterPtr->width * 3; + errDestPtr += modelPtr->width * 3; errSrcPtr += instancePtr->width * 3; } } @@ -897,8 +892,8 @@ TkImgPhotoInstanceSetSize( instancePtr->error = newError; } - instancePtr->width = masterPtr->width; - instancePtr->height = masterPtr->height; + instancePtr->width = modelPtr->width; + instancePtr->height = modelPtr->height; } /* @@ -1004,7 +999,7 @@ IsValidPalette( static int CountBits( - pixel mask) /* Value to count the 1 bits in. */ + unsigned mask) /* Value to count the 1 bits in. */ { int n; @@ -1610,10 +1605,10 @@ TkImgDisposeInstance( FreeColorTable(instancePtr->colorTablePtr, 1); } - if (instancePtr->masterPtr->instancePtr == instancePtr) { - instancePtr->masterPtr->instancePtr = instancePtr->nextPtr; + if (instancePtr->modelPtr->instancePtr == instancePtr) { + instancePtr->modelPtr->instancePtr = instancePtr->nextPtr; } else { - for (prevPtr = instancePtr->masterPtr->instancePtr; + for (prevPtr = instancePtr->modelPtr->instancePtr; prevPtr->nextPtr != instancePtr; prevPtr = prevPtr->nextPtr) { /* Empty loop body. */ } @@ -1629,7 +1624,7 @@ TkImgDisposeInstance( * TkImgDitherInstance -- * * This function is called to update an area of an instance's pixmap by - * dithering the corresponding area of the master. + * dithering the corresponding area of the model. * * Results: * None. @@ -1647,14 +1642,14 @@ TkImgDitherInstance( * block to be dithered. */ int width, int height) /* Dimensions of the block to be dithered. */ { - PhotoMaster *masterPtr = instancePtr->masterPtr; + PhotoModel *modelPtr = instancePtr->modelPtr; ColorTable *colorPtr = instancePtr->colorTablePtr; XImage *imagePtr; int nLines, bigEndian, i, c, x, y, xEnd, doDithering = 1; int bitsPerPixel, bytesPerLine, lineLength; unsigned char *srcLinePtr; schar *errLinePtr; - pixel firstBit, word, mask; + unsigned firstBit, word, mask; /* * Turn dithering off in certain cases where it is not needed (TrueColor, @@ -1705,8 +1700,8 @@ TkImgDitherInstance( bigEndian = imagePtr->bitmap_bit_order == MSBFirst; firstBit = bigEndian? (1 << (imagePtr->bitmap_unit - 1)): 1; - lineLength = masterPtr->width * 3; - srcLinePtr = masterPtr->pix32 + (yStart * masterPtr->width + xStart) * 4; + lineLength = modelPtr->width * 3; + srcLinePtr = modelPtr->pix32 + (yStart * modelPtr->width + xStart) * 4; errLinePtr = instancePtr->error + yStart * lineLength + xStart * 3; xEnd = xStart + width; @@ -1727,7 +1722,7 @@ TkImgDitherInstance( unsigned char *srcPtr = srcLinePtr; schar *errPtr = errLinePtr; unsigned char *destBytePtr = dstLinePtr; - pixel *destLongPtr = (pixel *) dstLinePtr; + unsigned *destLongPtr = (unsigned *) dstLinePtr; if (colorPtr->flags & COLOR_WINDOW) { /* @@ -1761,7 +1756,7 @@ TkImgDitherInstance( c += errPtr[-lineLength-3]; } c += errPtr[-lineLength] * 5; - if ((x + 1) < masterPtr->width) { + if ((x + 1) < modelPtr->width) { c += errPtr[-lineLength+3] * 3; } } @@ -1818,7 +1813,7 @@ TkImgDitherInstance( * sizes. */ - case NBBY * sizeof(pixel): + case NBBY * sizeof(unsigned): *destLongPtr++ = i; break; #endif @@ -1832,7 +1827,7 @@ TkImgDitherInstance( /* * Multibit monochrome window. The operation here is similar * to the color window case above, except that there is only - * one component. If the master image is in color, use the + * one component. If the model image is in color, use the * luminance computed as * 0.344 * red + 0.5 * green + 0.156 * blue. */ @@ -1844,13 +1839,13 @@ TkImgDitherInstance( c += errPtr[-lineLength-1]; } c += errPtr[-lineLength] * 5; - if (x + 1 < masterPtr->width) { + if (x + 1 < modelPtr->width) { c += errPtr[-lineLength+1] * 3; } } c = ((c + 2056) >> 4) - 128; - if (masterPtr->flags & COLOR_IMAGE) { + if (modelPtr->flags & COLOR_IMAGE) { c += (unsigned) (srcPtr[0] * 11 + srcPtr[1] * 16 + srcPtr[2] * 5 + 16) >> 5; } else { @@ -1880,7 +1875,7 @@ TkImgDitherInstance( * sizes. */ - case NBBY * sizeof(pixel): + case NBBY * sizeof(unsigned): *destLongPtr++ = i; break; #endif @@ -1917,13 +1912,13 @@ TkImgDitherInstance( c += errPtr[-lineLength-1]; } c += errPtr[-lineLength] * 5; - if (x + 1 < masterPtr->width) { + if (x + 1 < modelPtr->width) { c += errPtr[-lineLength+1] * 3; } } c = ((c + 2056) >> 4) - 128; - if (masterPtr->flags & COLOR_IMAGE) { + if (modelPtr->flags & COLOR_IMAGE) { c += (unsigned)(srcPtr[0] * 11 + srcPtr[1] * 16 + srcPtr[2] * 5 + 16) >> 5; } else { @@ -1946,7 +1941,7 @@ TkImgDitherInstance( } *destLongPtr = word; } - srcLinePtr += masterPtr->width * 4; + srcLinePtr += modelPtr->width * 4; errLinePtr += lineLength; dstLinePtr += bytesPerLine; } @@ -1990,8 +1985,8 @@ TkImgResetDither( { if (instancePtr->error) { memset(instancePtr->error, 0, - (size_t) instancePtr->masterPtr->width - * instancePtr->masterPtr->height * 3 * sizeof(schar)); + (size_t) instancePtr->modelPtr->width + * instancePtr->modelPtr->height * 3 * sizeof(schar)); } } |