Skip to content

Commit

Permalink
Don't use -encoding "binary" any more in Tk. Backport some more forma…
Browse files Browse the repository at this point in the history
…tting changes
  • Loading branch information
jan.nijtmans committed Jun 25, 2024
1 parent 1c3ec31 commit 2de66fa
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 183 deletions.
46 changes: 21 additions & 25 deletions generic/tkImgBmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ static int GetByte(Tcl_Channel chan);
static int ImgBmapCreate(Tcl_Interp *interp,
const char *name, int objc, Tcl_Obj *const objv[],
const Tk_ImageType *typePtr, Tk_ImageModel model,
ClientData *clientDataPtr);
static ClientData ImgBmapGet(Tk_Window tkwin, ClientData clientData);
static void ImgBmapDisplay(ClientData clientData,
void **clientDataPtr);
static void *ImgBmapGet(Tk_Window tkwin, void *clientData);
static void ImgBmapDisplay(void *clientData,
Display *display, Drawable drawable,
int imageX, int imageY, int width, int height,
int drawableX, int drawableY);
static void ImgBmapFree(ClientData clientData, Display *display);
static void ImgBmapDelete(ClientData clientData);
static int ImgBmapPostscript(ClientData clientData,
static void ImgBmapFree(void *clientData, Display *display);
static void ImgBmapDelete(void *clientData);
static int ImgBmapPostscript(void *clientData,
Tcl_Interp *interp, Tk_Window tkwin,
Tk_PostscriptInfo psinfo, int x, int y,
int width, int height, int prepass);
Expand Down Expand Up @@ -145,9 +145,9 @@ typedef struct ParseInfo {
* Prototypes for procedures used only locally in this file:
*/

static int ImgBmapCmd(ClientData clientData, Tcl_Interp *interp,
static int ImgBmapCmd(void *clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *const objv[]);
static void ImgBmapCmdDeletedProc(ClientData clientData);
static void ImgBmapCmdDeletedProc(void *clientData);
static void ImgBmapConfigureInstance(BitmapInstance *instancePtr);
static int ImgBmapConfigureModel(BitmapModel *modelPtr,
int objc, Tcl_Obj *const objv[], int flags);
Expand Down Expand Up @@ -180,7 +180,7 @@ ImgBmapCreate(
TCL_UNUSED(const Tk_ImageType *),/* Pointer to our type record (not used). */
Tk_ImageModel model, /* Token for image, to be used by us in later
* callbacks. */
ClientData *clientDataPtr) /* Store manager's token for image here; it
void **clientDataPtr) /* Store manager's token for image here; it
* will be returned in later callbacks. */
{
BitmapModel *modelPtr = (BitmapModel *)ckalloc(sizeof(BitmapModel));
Expand Down Expand Up @@ -513,10 +513,6 @@ TkGetBitmapData(
!= TCL_OK) {
return NULL;
}
if (Tcl_SetChannelOption(interp, pi.chan, "-encoding", "binary")
!= TCL_OK) {
return NULL;
}
} else {
pi.chan = NULL;
}
Expand Down Expand Up @@ -744,7 +740,7 @@ NextBitmapWord(

static int
ImgBmapCmd(
ClientData clientData, /* Information about the image model. */
void *clientData, /* Information about the image model. */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument objects. */
Expand All @@ -768,14 +764,14 @@ ImgBmapCmd(
return TCL_ERROR;
}
return Tk_ConfigureValue(interp, Tk_MainWindow(interp), configSpecs,
(char *) modelPtr, Tcl_GetString(objv[2]), 0);
(char *)modelPtr, Tcl_GetString(objv[2]), 0);
case 1: /* configure */
if (objc == 2) {
return Tk_ConfigureInfo(interp, Tk_MainWindow(interp),
configSpecs, (char *) modelPtr, NULL, 0);
configSpecs, (char *)modelPtr, NULL, 0);
} else if (objc == 3) {
return Tk_ConfigureInfo(interp, Tk_MainWindow(interp),
configSpecs, (char *) modelPtr,
configSpecs, (char *)modelPtr,
Tcl_GetString(objv[2]), 0);
} else {
return ImgBmapConfigureModel(modelPtr, objc-2, objv+2,
Expand Down Expand Up @@ -805,11 +801,11 @@ ImgBmapCmd(
*----------------------------------------------------------------------
*/

static ClientData
static void *
ImgBmapGet(
Tk_Window tkwin, /* Window in which the instance will be
* used. */
ClientData modelData) /* Pointer to our model structure for the
void *modelData) /* Pointer to our model structure for the
* image. */
{
BitmapModel *modelPtr = (BitmapModel *)modelData;
Expand Down Expand Up @@ -876,7 +872,7 @@ ImgBmapGet(

static void
ImgBmapDisplay(
ClientData clientData, /* Pointer to BitmapInstance structure for
void *clientData, /* Pointer to BitmapInstance structure for
* instance to be displayed. */
Display *display, /* Display on which to draw image. */
Drawable drawable, /* Pixmap or window in which to draw image. */
Expand Down Expand Up @@ -937,7 +933,7 @@ ImgBmapDisplay(

static void
ImgBmapFree(
ClientData clientData, /* Pointer to BitmapInstance structure for
void *clientData, /* Pointer to BitmapInstance structure for
* instance to be displayed. */
Display *display) /* Display containing window that used image. */
{
Expand Down Expand Up @@ -999,7 +995,7 @@ ImgBmapFree(

static void
ImgBmapDelete(
ClientData modelData) /* Pointer to BitmapModel structure for
void *modelData) /* Pointer to BitmapModel structure for
* image. Must not have any more instances. */
{
BitmapModel *modelPtr = (BitmapModel *)modelData;
Expand All @@ -1017,7 +1013,7 @@ ImgBmapDelete(
if (modelPtr->maskData != NULL) {
ckfree(modelPtr->maskData);
}
Tk_FreeOptions(configSpecs, (char *) modelPtr, NULL, 0);
Tk_FreeOptions(configSpecs, (char *)modelPtr, NULL, 0);
ckfree(modelPtr);
}

Expand All @@ -1040,7 +1036,7 @@ ImgBmapDelete(

static void
ImgBmapCmdDeletedProc(
ClientData clientData) /* Pointer to BitmapModel structure for
void *clientData) /* Pointer to BitmapModel structure for
* image. */
{
BitmapModel *modelPtr = (BitmapModel *)clientData;
Expand Down Expand Up @@ -1181,7 +1177,7 @@ ImgBmapPsImagemask(

static int
ImgBmapPostscript(
ClientData clientData,
void *clientData,
Tcl_Interp *interp,
Tk_Window tkwin,
Tk_PostscriptInfo psinfo,
Expand Down
45 changes: 23 additions & 22 deletions generic/tkImgGIF.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ typedef struct {
* serializing in the GIF format.
*/

typedef int (WriteBytesFunc) (ClientData clientData, const char *bytes,
typedef int (WriteBytesFunc) (void *clientData, const char *bytes,
int byteCount);

/*
Expand All @@ -135,7 +135,7 @@ static int FileWriteGIF(Tcl_Interp *interp, const char *filename,
Tcl_Obj *format, Tk_PhotoImageBlock *blockPtr);
static int StringWriteGIF(Tcl_Interp *interp, Tcl_Obj *format,
Tk_PhotoImageBlock *blockPtr);
static int CommonWriteGIF(Tcl_Interp *interp, ClientData clientData,
static int CommonWriteGIF(Tcl_Interp *interp, void *clientData,
WriteBytesFunc *writeProc, Tcl_Obj *format,
Tk_PhotoImageBlock *blockPtr);

Expand Down Expand Up @@ -280,7 +280,7 @@ typedef struct {
*/

int initialBits;
ClientData destination;
void *destination;
WriteBytesFunc *writeProc;

int clearCode;
Expand Down Expand Up @@ -308,7 +308,7 @@ typedef struct {

static int ColorNumber(GifWriterState *statePtr,
int red, int green, int blue);
static void Compress(int initBits, ClientData handle,
static void Compress(int initBits, void *handle,
WriteBytesFunc *writeProc, ifunptr readValue,
GifWriterState *statePtr);
static int IsNewColor(GifWriterState *statePtr,
Expand Down Expand Up @@ -351,7 +351,7 @@ FileMatchGIF(
int *widthPtr, int *heightPtr,
/* The dimensions of the image are returned
* here if the file is a valid raw GIF file. */
Tcl_Interp *interp) /* not used */
TCL_UNUSED(Tcl_Interp *), /* not used */
{
GIFImageConfig gifConf;

Expand Down Expand Up @@ -603,7 +603,7 @@ FileReadGIF(
goto error;
}
nBytes = fileWidth * fileHeight * 3;
trashBuffer = ckalloc(nBytes);
trashBuffer = (unsigned char *)ckalloc(nBytes);
if (trashBuffer) {
memset(trashBuffer, 0, nBytes);
}
Expand Down Expand Up @@ -706,7 +706,7 @@ FileReadGIF(
goto error;
}
nBytes = block.pitch * imageHeight;
pixelPtr = ckalloc(nBytes);
pixelPtr = (unsigned char*)ckalloc(nBytes);
if (pixelPtr) {
memset(pixelPtr, 0, nBytes);
}
Expand Down Expand Up @@ -1050,7 +1050,8 @@ ReadImage(
Tcl_Channel chan,
int len, int rows,
unsigned char cmap[MAXCOLORMAPSIZE][4],
int srcX, int srcY,
TCL_UNUSED(int),
TCL_UNUSED(int),
int interlace,
int transparent)
{
Expand Down Expand Up @@ -1446,8 +1447,8 @@ Mread(
size_t numChunks, /* number of chunks */
MFile *handle) /* mmdecode "file" handle */
{
int i, c;
int count = chunkSize * numChunks;
int c;
int i, count = chunkSize * numChunks;

for (i=0; i<count && (c=Mgetc(handle)) != GIF_DONE; i++) {
*dst++ = c;
Expand Down Expand Up @@ -1602,20 +1603,20 @@ Fread(
if (gifConfPtr->fromData == INLINE_DATA_BINARY) {
MFile *handle = (MFile *) chan;

if (handle->length <= 0 || (size_t) handle->length < hunk*count) {
if ((handle->length <= 0) || ((size_t)handle->length < hunk*count)) {
return -1;
}
memcpy(dst, handle->data, (size_t) (hunk * count));
memcpy(dst, handle->data, hunk * count);
handle->data += hunk * count;
handle->length -= hunk * count;
return (int)(hunk * count);
return hunk * count;
}

/*
* Otherwise we've got a real file to read.
*/

return Tcl_Read(chan, (char *) dst, (int) (hunk * count));
return Tcl_Read(chan, (char *) dst, hunk * count);
}

/*
Expand Down Expand Up @@ -1660,8 +1661,8 @@ FileWriteGIF(
if (!chan) {
return TCL_ERROR;
}
if (Tcl_SetChannelOption(interp, chan, "-translation",
"binary") != TCL_OK) {
if (Tcl_SetChannelOption(interp, chan, "-translation", "binary")
!= TCL_OK) {
Tcl_Close(NULL, chan);
return TCL_ERROR;
}
Expand Down Expand Up @@ -1696,22 +1697,22 @@ StringWriteGIF(

static int
WriteToChannel(
ClientData clientData,
void *clientData,
const char *bytes,
int byteCount)
{
Tcl_Channel handle = clientData;
Tcl_Channel handle = (Tcl_Channel)clientData;

return Tcl_Write(handle, bytes, byteCount);
}

static int
WriteToByteArray(
ClientData clientData,
void *clientData,
const char *bytes,
int byteCount)
{
Tcl_Obj *objPtr = clientData;
Tcl_Obj *objPtr = (Tcl_Obj *)clientData;
Tcl_Obj *tmpObj = Tcl_NewByteArrayObj((unsigned char *) bytes, byteCount);

Tcl_IncrRefCount(tmpObj);
Expand All @@ -1723,7 +1724,7 @@ WriteToByteArray(
static int
CommonWriteGIF(
Tcl_Interp *interp,
ClientData handle,
void *handle,
WriteBytesFunc *writeProc,
Tcl_Obj *format,
Tk_PhotoImageBlock *blockPtr)
Expand Down Expand Up @@ -1979,7 +1980,7 @@ ReadValue(
static void
Compress(
int initialBits,
ClientData handle,
void *handle,
WriteBytesFunc *writeProc,
ifunptr readValue,
GifWriterState *statePtr)
Expand Down
21 changes: 9 additions & 12 deletions generic/tkImgPNG.c
Original file line number Diff line number Diff line change
Expand Up @@ -2387,7 +2387,8 @@ DecodePNG(
* image being read. */
{
unsigned long chunkType;
int result, chunkSz;
int result;
int chunkSz;
unsigned long crc;

/*
Expand Down Expand Up @@ -2525,11 +2526,11 @@ DecodePNG(
pngPtr->thisLineObj = Tcl_NewObj();
Tcl_IncrRefCount(pngPtr->thisLineObj);

pngPtr->block.pixelPtr = attemptckalloc(pngPtr->blockLen);
pngPtr->block.pixelPtr = (unsigned char *)attemptckalloc(pngPtr->blockLen);
if (!pngPtr->block.pixelPtr) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
"memory allocation failed", -1));
Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL);
Tcl_SetErrorCode(interp, "TK", "MALLOC", (char *)NULL);
return TCL_ERROR;
}

Expand Down Expand Up @@ -2852,7 +2853,7 @@ WriteData(
int srcSz,
unsigned long *crcPtr)
{
if (!srcPtr || !srcSz) {
if (!srcPtr || srcSz <= 0) {
return TCL_OK;
}

Expand Down Expand Up @@ -3135,9 +3136,10 @@ WriteIDAT(
PNGImage *pngPtr,
Tk_PhotoImageBlock *blockPtr)
{
int rowNum, flush = TCL_ZLIB_NO_FLUSH, outputSize, result;
int rowNum, flush = TCL_ZLIB_NO_FLUSH, result;
Tcl_Obj *outputObj;
unsigned char *outputBytes;
int outputSize;

/*
* Filter and compress each row one at a time.
Expand Down Expand Up @@ -3483,13 +3485,8 @@ FileWritePNG(
goto cleanup;
}

/*
* Set the translation mode to binary so that CR and LF are not to the
* platform's EOL sequence.
*/

if (Tcl_SetChannelOption(interp, chan, "-translation",
"binary") != TCL_OK) {
if (Tcl_SetChannelOption(interp, chan, "-translation", "binary")
!= TCL_OK) {
goto cleanup;
}

Expand Down
Loading

0 comments on commit 2de66fa

Please sign in to comment.