13#include "../tcl-compat.h"
36#define IMGPTR(O) (O->internalRep.otherValuePtr)
49 Tcl_Obj *
const objv[]);
50typedef int(
GdImgFunction)(Tcl_Interp *interp, gdImagePtr gdImg,
int argc,
82 {
"createTrueColor",
tclGdCreateCmd, 2, 2, 0, 0, 2,
"width height"},
100 {
"writeGD",
tclGdWriteCmd, 2, 2, 0, 1, 3,
"gdhandle filehandle"},
102 {
"writeGD2",
tclGdWriteCmd, 2, 2, 0, 1, 3,
"gdhandle filehandle"},
104 {
"writeGIF",
tclGdWriteCmd, 2, 2, 0, 1, 3,
"gdhandle filehandle"},
106 {
"writeJPEG",
tclGdWriteCmd, 2, 2, 0, 1, 3,
"gdhandle filehandle"},
109 {
"writePNG",
tclGdWriteCmd, 2, 2, 0, 1, 3,
"gdhandle filehandle"},
111 {
"writeWBMP",
tclGdWriteCmd, 2, 2, 0, 1, 3,
"gdhandle filehandle"},
113 {
"writeXBM",
tclGdWriteCmd, 2, 2, 0, 1, 3,
"gdhandle filehandle"},
120 {
"brush",
tclGdBrushCmd, 2, 2, 0, 2, 0,
"gdhandle brushhandle"},
121 {
"style",
tclGdStyleCmd, 2, 999, 0, 1, 0,
"gdhandle color..."},
122 {
"tile",
tclGdTileCmd, 2, 2, 0, 2, 0,
"gdhandle tilehandle"},
123 {
"set",
tclGdSetCmd, 4, 4, 0, 1, 0,
"gdhandle color x y"},
124 {
"line",
tclGdLineCmd, 6, 6, 0, 1, 0,
"gdhandle color x1 y1 x2 y2"},
125 {
"rectangle",
tclGdRectCmd, 6, 6, 0, 1, 0,
"gdhandle color x1 y1 x2 y2"},
127 "gdhandle color x1 y1 x2 y2"},
129 "gdhandle color cx cy width height start end"},
131 "gdhandle color cx cy width height start end"},
133 "gdhandle color cx cy width height start end"},
135 "gdhandle color cx cy width height start end"},
137 "gdhandle color cx cy width height start end"},
139 "gdhandle color cx cy width height start end"},
141 "gdhandle color cx cy width height start end"},
143 "gdhandle color cx cy width height start end"},
145 "gdhandle color cx cy width height start end"},
147 "gdhandle color x1 y1 x2 y2 x3 y3 ..."},
149 "gdhandle color x1 y1 x2 y2 x3 y3 ..."},
150 {
"fill",
tclGdFillCmd, 4, 5, 0, 1, 0,
"gdhandle color x y ?bordercolor?"},
157 "gdhandle color fontname size angle x y string"},
159 "desthandle srchandle destx desty srcx srcy destw desth ?srcw srch?"},
160 {
"get",
tclGdGetCmd, 3, 3, 0, 1, 0,
"gdhandle x y"},
181 if (Tcl_GetIntFromObj(interp, obj,
color) == TCL_OK)
184 Tcl_ResetResult(interp);
186 if (Tcl_ListObjGetElements(interp, obj, &nlist, &theList) != TCL_OK)
188 if (nlist < 1 || nlist > 2)
191 char *firsttag = Tcl_GetString(theList[0]);
192 switch (firsttag[0]) {
196 char *secondtag = Tcl_GetString(theList[1]);
197 if (secondtag[0] ==
's') {
198 *
color = gdStyledBrushed;
208 char *secondtag = Tcl_GetString(theList[1]);
209 if (secondtag[0] ==
'b') {
210 *
color = gdStyledBrushed;
226 if (retval == TCL_ERROR)
227 Tcl_SetResult(interp,
"Malformed special color value", TCL_STATIC);
347static int gdCmd(ClientData clientData, Tcl_Interp *interp,
int argc,
348 Tcl_Obj *
const objv[]) {
351 Tcl_SetResult(interp,
"wrong # args: should be \"gd option ...\"",
363 (unsigned)argc - 2 >
subcmdVec[subi].maxargs) {
373 Tcl_SetResult(interp,
"GD handle(s) not specified", TCL_STATIC);
376 for (
unsigned argi = 2 +
subcmdVec[subi].subcmds;
390 const char *
fname = Tcl_GetString(objv[
subcmdVec[subi].unsafearg]);
391 if (!Tcl_IsChannelExisting(
fname)) {
392 Tcl_AppendResult(interp,
"Access to ",
fname,
393 " not allowed in safe interpreter",
NULL);
403 Tcl_AppendResult(interp,
"bad option \"", Tcl_GetString(objv[1]),
404 "\": should be ", 0);
406 Tcl_AppendResult(interp, (subi > 0 ?
", " :
""),
subcmdVec[subi].
cmd, 0);
412 gdImagePtr im =
NULL;
415 char *
cmd = Tcl_GetString(objv[1]);
418 if (Tcl_GetIntFromObj(interp, objv[2], &w) != TCL_OK)
420 if (Tcl_GetIntFromObj(interp, objv[3], &h) != TCL_OK)
424 Tcl_GetBooleanFromObj(interp, objv[4], &trueColor) == TCL_ERROR)
427 im = gdImageCreateTrueColor(w, h);
429 im = gdImageCreate(w, h);
432 snprintf(buf,
sizeof(buf),
"GD unable to allocate %d X %d image", w, h);
433 Tcl_SetResult(interp, buf, TCL_VOLATILE);
436 }
else if (
streq(
cmd,
"createTrueColor")) {
437 if (Tcl_GetIntFromObj(interp, objv[2], &w) != TCL_OK)
439 if (Tcl_GetIntFromObj(interp, objv[3], &h) != TCL_OK)
441 im = gdImageCreateTrueColor(w, h);
444 snprintf(buf,
sizeof(buf),
"GD unable to allocate %d X %d image", w, h);
445 Tcl_SetResult(interp, buf, TCL_VOLATILE);
449 char *arg2 = Tcl_GetString(objv[2]);
451 FILE *filePtr =
NULL;
453 ClientData clientdata;
454 if (Tcl_GetOpenFile(interp, arg2, 0, 1, &clientdata) == TCL_OK) {
455 filePtr = (FILE *)clientdata;
458 if (filePtr ==
NULL) {
462 if ((filePtr = fopen(arg2,
"rb")) ==
NULL) {
466 Tcl_ResetResult(interp);
471 im = gdImageCreateFromGd(filePtr);
473 }
else if (
streq(&
cmd[10],
"GD2")) {
474 im = gdImageCreateFromGd2(filePtr);
476 }
else if (
streq(&
cmd[10],
"GIF")) {
477 im = gdImageCreateFromGif(filePtr);
479 }
else if (
streq(&
cmd[10],
"JPEG")) {
480 im = gdImageCreateFromJpeg(filePtr);
483 }
else if (
streq(&
cmd[10],
"PNG")) {
484 im = gdImageCreateFromPng(filePtr);
486 }
else if (
streq(&
cmd[10],
"WBMP")) {
487 im = gdImageCreateFromWBMP(filePtr);
489 }
else if (
streq(&
cmd[10],
"XBM")) {
490 im = gdImageCreateFromXbm(filePtr);
493 Tcl_AppendResult(interp,
cmd + 10,
"unrecognizable format requested",
504 Tcl_AppendResult(interp,
"GD unable to read image file '", arg2,
"` as ",
510 Tcl_Obj *result = Tcl_NewObj();
513 result->bytes =
NULL;
514 Tcl_SetObjResult(interp, result);
519 Tcl_Obj *
const objv[]) {
524 gdImagePtr im =
IMGPTR(objv[2]);
530static int tclGdWriteCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
533 const char *
cmd = Tcl_GetString(objv[1]);
534 if (
cmd[5] ==
'J' ||
cmd[5] ==
'W') {
540 Tcl_SetResult(interp,
"WBMP saving requires the foreground pixel value",
544 }
else if (Tcl_GetIntFromObj(interp, objv[4], &arg4) != TCL_OK)
547 if (
cmd[5] ==
'J' && argc > 4 && (arg4 > 100 || arg4 < 1)) {
548 Tcl_SetObjResult(interp, objv[4]);
549 Tcl_AppendResult(interp,
550 ": JPEG image quality, if specified, must be an integer "
551 "from 1 to 100, or -1 for default",
558 gdImagePtr im =
IMGPTR(objv[2]);
559 const char *
fname = Tcl_GetString(objv[3]);
563 FILE *filePtr =
NULL;
565 ClientData clientdata;
566 if (Tcl_GetOpenFile(interp,
fname, 1, 1, &clientdata) == TCL_OK) {
567 filePtr = (FILE *)clientdata;
570 if (filePtr ==
NULL) {
575 if ((filePtr = fopen(
fname,
"wb")) ==
NULL) {
576 Tcl_AppendResult(interp,
"could not open :",
fname,
577 "': ", strerror(errno),
NULL);
580 Tcl_ResetResult(interp);
593 gdImageGd(im, filePtr);
596#define GD2_CHUNKSIZE 128
597#define GD2_COMPRESSED 2
598 gdImageGd2(im, filePtr, GD2_CHUNKSIZE, GD2_COMPRESSED);
601 gdImageGif(im, filePtr);
603 }
else if (
streq(&
cmd[5],
"JPEG")) {
604#define JPEG_QUALITY -1
605 gdImageJpeg(im, filePtr, JPEG_QUALITY);
609 gdImagePng(im, filePtr);
611 }
else if (
streq(&
cmd[5],
"WBMP")) {
614 int foreground = gdImageColorClosest(im, 0, 0, 0);
615 gdImageWBMP(im, foreground, filePtr);
628 Tcl_Obj *
const objv[]) {
632 gdImagePtr im =
IMGPTR(objv[2]);
636 if (Tcl_GetBooleanFromObj(interp, objv[3], &on_off) != TCL_OK)
640 gdImageInterlace(im, on_off);
643 on_off = gdImageGetInterlaced(im);
645 Tcl_SetObjResult(interp, Tcl_NewBooleanObj(on_off));
649static int tclGdColorCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
655 for (
int subi = 0; subi < nsub; subi++) {
665 gdImagePtr im =
IMGPTR(objv[3]);
670 for (
int i = 0; i < argc - 4; i++) {
671 if (Tcl_GetIntFromObj(interp, objv[i + 4], &args[i]) != TCL_OK) {
674 if (args[i] < -255 || args[i] > 255) {
675 Tcl_SetResult(interp,
"argument out of range 0-255", TCL_STATIC);
689 Tcl_AppendResult(interp,
"bad option \"", Tcl_GetString(objv[2]),
692 Tcl_AppendResult(interp,
"wrong # args: ", 0);
694 Tcl_AppendResult(interp,
"should be ", 0);
695 for (
int subi = 0; subi < nsub; subi++)
696 Tcl_AppendResult(interp, subi > 0 ?
", " :
"",
colorCmdVec[subi].
cmd, 0);
705 int color = gdImageColorAllocate(im, args[0], args[1], args[2]);
706 Tcl_SetObjResult(interp, Tcl_NewIntObj(
color));
714 int color = gdImageColorExact(im, args[0], args[1], args[2]);
715 Tcl_SetObjResult(interp, Tcl_NewIntObj(
color));
723 int color = gdImageColorClosest(im, args[0], args[1], args[2]);
724 Tcl_SetObjResult(interp, Tcl_NewIntObj(
color));
732 int color = gdImageColorResolve(im, args[0], args[1], args[2]);
733 Tcl_SetObjResult(interp, Tcl_NewIntObj(
color));
742 gdImageColorDeallocate(im, args[0]);
752 gdImageColorTransparent(im,
color);
754 color = gdImageGetTransparent(im);
756 Tcl_SetObjResult(interp, Tcl_NewIntObj(
color));
764 int ncolors = gdImageColorsTotal(im);
768 if (i >= ncolors || im->open[i]) {
769 Tcl_SetResult(interp,
"No such color", TCL_STATIC);
772 Tcl_Obj *tuple[] = {Tcl_NewIntObj(i), Tcl_NewIntObj(gdImageRed(im, i)),
773 Tcl_NewIntObj(gdImageGreen(im, i)),
774 Tcl_NewIntObj(gdImageBlue(im, i))};
775 const Tcl_Size tuple_size =
sizeof(tuple) /
sizeof(tuple[0]);
776 Tcl_SetObjResult(interp, Tcl_NewListObj(tuple_size, tuple));
778 result = Tcl_NewListObj(0,
NULL);
779 for (
int i = 0; i < ncolors; i++) {
782 Tcl_Obj *tuple[] = {Tcl_NewIntObj(i), Tcl_NewIntObj(gdImageRed(im, i)),
783 Tcl_NewIntObj(gdImageGreen(im, i)),
784 Tcl_NewIntObj(gdImageBlue(im, i))};
785 const Tcl_Size tuple_size =
sizeof(tuple) /
sizeof(tuple[0]);
786 Tcl_ListObjAppendElement(
NULL, result, Tcl_NewListObj(tuple_size, tuple));
788 Tcl_SetObjResult(interp, result);
794static int tclGdBrushCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
799 gdImagePtr im =
IMGPTR(objv[2]);
800 gdImagePtr imbrush =
IMGPTR(objv[3]);
803 gdImageSetBrush(im, imbrush);
808static int tclGdTileCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
813 gdImagePtr im =
IMGPTR(objv[2]);
814 gdImagePtr tile =
IMGPTR(objv[3]);
817 gdImageSetTile(im, tile);
822static int tclGdStyleCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
823 Tcl_Obj *
const *colorObjv = &objv[3];
827 gdImagePtr im =
IMGPTR(objv[2]);
834 if (Tcl_ListObjGetElements(interp, objv[3], &ncolor, &colorObjp) != TCL_OK)
836 colorObjv = colorObjp;
839 int *colors = (
int *)Tcl_Alloc((
size_t)ncolor *
sizeof(int));
841 for (
Tcl_Size i = 0; i < ncolor; i++)
842 if (Tcl_GetIntFromObj(interp, colorObjv[i], &colors[i]) != TCL_OK) {
848 if (retval == TCL_OK)
849 gdImageSetStyle(im, colors, (
int)ncolor);
853 Tcl_Free((
char *)colors);
858static int tclGdSetCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
870 if (Tcl_GetIntFromObj(interp, objv[4], &x) != TCL_OK)
872 if (Tcl_GetIntFromObj(interp, objv[5], &y) != TCL_OK)
876 gdImageSetPixel(im, x, y,
color);
881static int tclGdLineCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
885 int color, x1, y1, x2, y2;
893 if (Tcl_GetIntFromObj(interp, objv[4], &x1) != TCL_OK)
895 if (Tcl_GetIntFromObj(interp, objv[5], &y1) != TCL_OK)
897 if (Tcl_GetIntFromObj(interp, objv[6], &x2) != TCL_OK)
899 if (Tcl_GetIntFromObj(interp, objv[7], &y2) != TCL_OK)
903 gdImageLine(im, x1, y1, x2, y2,
color);
908static int tclGdRectCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
912 int color, x1, y1, x2, y2;
921 if (Tcl_GetIntFromObj(interp, objv[4], &x1) != TCL_OK)
923 if (Tcl_GetIntFromObj(interp, objv[5], &y1) != TCL_OK)
925 if (Tcl_GetIntFromObj(interp, objv[6], &x2) != TCL_OK)
927 if (Tcl_GetIntFromObj(interp, objv[7], &y2) != TCL_OK)
931 cmd = Tcl_GetString(objv[1]);
933 gdImageRectangle(im, x1, y1, x2, y2,
color);
935 gdImageFilledRectangle(im, x1, y1, x2, y2,
color);
940static int tclGdArcCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
944 int color, cx, cy, width, height, start, end;
953 if (Tcl_GetIntFromObj(interp, objv[4], &cx) != TCL_OK)
955 if (Tcl_GetIntFromObj(interp, objv[5], &cy) != TCL_OK)
957 if (Tcl_GetIntFromObj(interp, objv[6], &width) != TCL_OK)
959 if (Tcl_GetIntFromObj(interp, objv[7], &height) != TCL_OK)
961 if (Tcl_GetIntFromObj(interp, objv[8], &start) != TCL_OK)
963 if (Tcl_GetIntFromObj(interp, objv[9], &end) != TCL_OK)
967 cmd = Tcl_GetString(objv[1]);
969 gdImageArc(im, cx, cy, width, height, start, end,
color);
972 else if (
cmd[0] ==
'f' &&
cmd[4] ==
'a')
973 gdImageFilledArc(im, cx, cy, width, height, start, end,
color, gdArc);
975 else if (
cmd[0] ==
'o' &&
cmd[4] ==
'a') {
976 gdImageArc(im, cx, cy, width, height, start, end,
color);
977 gdImageFilledArc(im, cx, cy, width, height, start, end,
color,
979 }
else if (
cmd[0] ==
'c')
980 gdImageFilledArc(im, cx, cy, width, height, start, end,
color,
982 else if (
cmd[0] ==
'f' &&
cmd[4] ==
'c')
983 gdImageFilledArc(im, cx, cy, width, height, start, end,
color, gdChord);
984 else if (
cmd[0] ==
'o' &&
cmd[4] ==
'c')
985 gdImageFilledArc(im, cx, cy, width, height, start, end,
color,
986 gdChord | gdEdged | gdNoFill);
987 else if (
cmd[0] ==
'p' ||
988 (
cmd[0] ==
'f' &&
cmd[4] ==
'p'))
989 gdImageFilledArc(im, cx, cy, width, height, start, end,
color, gdPie);
990 else if (
cmd[0] ==
'o' &&
cmd[4] ==
'p')
991 gdImageFilledArc(im, cx, cy, width, height, start, end,
color,
992 gdPie | gdEdged | gdNoFill);
998 Tcl_Obj *
const objv[]) {
1001 Tcl_Obj *
const *pointObjv = &objv[4];
1003 int retval = TCL_OK;
1017 Tcl_Obj **pointObjp;
1018 if (Tcl_ListObjGetElements(interp, objv[4], &npoints, &pointObjp) != TCL_OK)
1020 pointObjv = pointObjp;
1024 if (npoints % 2 != 0) {
1025 Tcl_SetResult(interp,
"Number of coordinates must be even", TCL_STATIC);
1033 Tcl_SetResult(interp,
"Must specify at least 3 points.", TCL_STATIC);
1038 points = (gdPointPtr)Tcl_Alloc((
size_t)npoints *
sizeof(gdPoint));
1041 for (
Tcl_Size i = 0; i < npoints; i++)
1042 if (Tcl_GetIntFromObj(interp, pointObjv[i * 2], &
points[i].x) != TCL_OK ||
1043 Tcl_GetIntFromObj(interp, pointObjv[i * 2 + 1], &
points[i].y) !=
1050 cmd = Tcl_GetString(objv[1]);
1054 gdImageFilledPolygon(im,
points, (
int)npoints,
color);
1059 Tcl_Free((
char *)
points);
1065static int tclGdFillCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
1067 int color, x, y, border;
1075 if (Tcl_GetIntFromObj(interp, objv[4], &x) != TCL_OK)
1077 if (Tcl_GetIntFromObj(interp, objv[5], &y) != TCL_OK)
1081 if (argc - 2 == 5) {
1082 if (Tcl_GetIntFromObj(interp, objv[6], &border) != TCL_OK)
1084 gdImageFillToBorder(im, x, y, border,
color);
1086 gdImageFill(im, x, y,
color);
1092static int tclGdCopyCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
1093 gdImagePtr imdest, imsrc;
1094 int destx, desty, srcx, srcy, destw, desth, srcw, srch;
1097 imdest =
IMGPTR(objv[2]);
1101 if (Tcl_GetIntFromObj(interp, objv[4], &destx) != TCL_OK)
1103 if (Tcl_GetIntFromObj(interp, objv[5], &desty) != TCL_OK)
1105 if (Tcl_GetIntFromObj(interp, objv[6], &srcx) != TCL_OK)
1107 if (Tcl_GetIntFromObj(interp, objv[7], &srcy) != TCL_OK)
1109 if (Tcl_GetIntFromObj(interp, objv[8], &destw) != TCL_OK)
1111 if (Tcl_GetIntFromObj(interp, objv[9], &desth) != TCL_OK)
1115 if (argc - 2 == 10) {
1116 if (Tcl_GetIntFromObj(interp, objv[10], &srcw) != TCL_OK)
1118 if (Tcl_GetIntFromObj(interp, objv[11], &srch) != TCL_OK)
1121 gdImageCopyResized(imdest, imsrc, destx, desty, srcx, srcy, destw, desth,
1124 gdImageCopy(imdest, imsrc, destx, desty, srcx, srcy, destw, desth);
1129static int tclGdGetCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
1139 if (Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK)
1141 if (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)
1145 color = gdImageGetPixel(im, x, y);
1146 Tcl_SetObjResult(interp, Tcl_NewIntObj(
color));
1150static int tclGdSizeCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
1154 Tcl_Obj *answers[2];
1159 answers[0] = Tcl_NewIntObj(gdImageSX(im));
1160 answers[1] = Tcl_NewIntObj(gdImageSY(im));
1161 Tcl_SetObjResult(interp, Tcl_NewListObj(2, answers));
1165static int tclGdTextCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
1169 double ptsize, angle;
1170 char *
error, *fontname;
1177 if (argc == 2 || (objv[2]->typePtr != &
GdPtrType &&
1190 if (Tcl_GetDoubleFromObj(interp, objv[5], &ptsize) != TCL_OK) {
1195 if (Tcl_GetDoubleFromObj(interp, objv[6], &angle) != TCL_OK) {
1200 if (Tcl_GetIntFromObj(interp, objv[7], &x) != TCL_OK) {
1203 if (Tcl_GetIntFromObj(interp, objv[8], &y) != TCL_OK) {
1207 str = Tcl_GetStringFromObj(objv[9],
NULL);
1208 fontname = Tcl_GetString(objv[4]);
1210 gdFTUseFontConfig(1);
1211 error = gdImageStringFT(im, brect,
color, fontname, ptsize, angle, x, y,
str);
1214 Tcl_SetResult(interp,
error, TCL_VOLATILE);
1217 for (i = 0; i < 8; i++) {
1218 orect[i] = Tcl_NewIntObj(brect[i]);
1220 Tcl_SetObjResult(interp, Tcl_NewListObj(8, orect));
1229 if (Tcl_InitStubs(interp, TCL_VERSION, 0) ==
NULL) {
1233 if (Tcl_PkgRequire(interp,
"Tcl", TCL_VERSION, 0) ==
NULL) {
1239 char adjusted_version[
sizeof(PACKAGE_VERSION)] = PACKAGE_VERSION;
1240 char *tilde_dev = strstr(adjusted_version,
"~dev.");
1241 if (tilde_dev !=
NULL) {
1243 memmove(tilde_dev + 1, tilde_dev + strlen(
"~dev."),
1244 strlen(tilde_dev + strlen(
"~dev.")) + 1);
1246 if (Tcl_PkgProvide(interp,
"Gdtclft", adjusted_version) != TCL_OK) {
1249 Tcl_CreateObjCommand(interp,
"gd",
gdCmd,
NULL, (Tcl_CmdDeleteProc *)
NULL);
1256 Tcl_GetCommandInfo(interp,
"gd", &
info) != 1)
1258 info.objClientData = (
char *)
info.objClientData + 1;
1259 if (Tcl_SetCommandInfo(interp,
"gd", &
info) != 1)
1290BOOL APIENTRY DllEntryPoint(HINSTANCE hInst, DWORD reason, LPVOID reserved);
1291BOOL APIENTRY DllEntryPoint(HINSTANCE hInst, DWORD reason, LPVOID reserved) {
1302static int BufferSinkFunc(
void *context,
const char *buffer,
int len) {
1311 Tcl_Obj *
const objv[]) {
1315 gdSink buffsink = {.sink = BufferSinkFunc, .context = &buffer};
1317 gdImagePtr im =
IMGPTR(objv[2]);
1319 gdImagePngToSink(im, &buffsink);
1321 const size_t buffer_length =
agxblen(&buffer);
1322 void *
const result =
agxbuse(&buffer);
1324 assert(buffer_length <= INT_MAX);
1325 Tcl_Obj *output = Tcl_NewByteArrayObj(result, (
Tcl_Size)buffer_length);
1330 Tcl_IncrRefCount(output);
1332 if (Tcl_ObjSetVar2(interp, objv[3],
NULL, output, 0) ==
NULL)
1339 size_t len = strlen(
GdPtrType.name) + (
sizeof(
void *) + 1) * 2 + 1;
1340 O->bytes = Tcl_Alloc(
len);
1345 if (
O->bytes ==
NULL ||
O->bytes[0] ==
'\0' ||
1349 Tcl_AppendResult(
I,
O->bytes,
" is not a ",
GdPtrType.name,
"-handle",
static void out(agerrlevel_t level, const char *fmt, va_list args)
Report messages using a user-supplied or default write function.
Dynamically expanding string buffers.
static void agxbfree(agxbuf *xb)
free any malloced resources
static size_t agxbput_n(agxbuf *xb, const char *s, size_t ssz)
append string s of length ssz into xb
static WUR char * agxbuse(agxbuf *xb)
static size_t agxblen(const agxbuf *xb)
return number of characters currently stored
static GdDataFunction tclGdCopyCmd
static Tcl_ObjType GdPtrType
static GdImgFunction tclGdColorGetCmd
static GdDataFunction tclGdInterlaceCmd
static cmdDataOptions subcmdVec[]
static GdImgFunction tclGdColorTranspCmd
static GdDataFunction tclGdSetCmd
Tcl_AppInitProc Gdtclft_SafeInit
static GdDataFunction tclGdRectCmd
static GdDataFunction tclGdLineCmd
static Tcl_UpdateStringProc GdPtrTypeUpdate
static GdDataFunction tclGdStyleCmd
static GdDataFunction tclGdBrushCmd
static GdImgFunction tclGdColorResolveCmd
static GdImgFunction tclGdColorNewCmd
static GdDataFunction tclGdCreateCmd
static GdImgFunction tclGdColorFreeCmd
static GdImgFunction tclGdColorExactCmd
static GdDataFunction tclGdDestroyCmd
int() GdImgFunction(Tcl_Interp *interp, gdImagePtr gdImg, int argc, const int args[])
static GdDataFunction tclGdArcCmd
static int gdCmd(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const objv[])
static GdDataFunction tclGdPolygonCmd
static GdDataFunction tclGdSizeCmd
static GdDataFunction tclGdWriteBufCmd
Tcl_AppInitProc Gdtclft_Init
static GdDataFunction tclGdWriteCmd
static GdDataFunction tclGdGetCmd
static GdDataFunction tclGdTextCmd
static int tclGd_GetColor(Tcl_Interp *interp, Tcl_Obj *obj, int *color)
static GdImgFunction tclGdColorClosestCmd
static GdDataFunction tclGdTileCmd
static cmdImgOptions colorCmdVec[]
static Tcl_SetFromAnyProc GdPtrTypeSet
static GdDataFunction tclGdFillCmd
int() GdDataFunction(Tcl_Interp *interp, int argc, Tcl_Obj *const objv[])
static GdDataFunction tclGdColorCmd
static double len(glCompPoint p)
static void color(Agraph_t *g)
static const char * usage
textitem scanner parser str
static bool startswith(const char *s, const char *prefix)
does the string s begin with the string prefix?
static bool streq(const char *a, const char *b)
are a and b equal?