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"},
102 {
"writeGD",
tclGdWriteCmd, 2, 2, 0, 1, 3,
"gdhandle filehandle"},
104 {
"writeGD2",
tclGdWriteCmd, 2, 2, 0, 1, 3,
"gdhandle filehandle"},
107 {
"writeGIF",
tclGdWriteCmd, 2, 2, 0, 1, 3,
"gdhandle filehandle"},
110 {
"writeJPEG",
tclGdWriteCmd, 2, 2, 0, 1, 3,
"gdhandle filehandle"},
113 {
"writePNG",
tclGdWriteCmd, 2, 2, 0, 1, 3,
"gdhandle filehandle"},
115 {
"writeWBMP",
tclGdWriteCmd, 2, 2, 0, 1, 3,
"gdhandle filehandle"},
117 {
"writeXBM",
tclGdWriteCmd, 2, 2, 0, 1, 3,
"gdhandle filehandle"},
124 {
"brush",
tclGdBrushCmd, 2, 2, 0, 2, 0,
"gdhandle brushhandle"},
125 {
"style",
tclGdStyleCmd, 2, 999, 0, 1, 0,
"gdhandle color..."},
126 {
"tile",
tclGdTileCmd, 2, 2, 0, 2, 0,
"gdhandle tilehandle"},
127 {
"set",
tclGdSetCmd, 4, 4, 0, 1, 0,
"gdhandle color x y"},
128 {
"line",
tclGdLineCmd, 6, 6, 0, 1, 0,
"gdhandle color x1 y1 x2 y2"},
129 {
"rectangle",
tclGdRectCmd, 6, 6, 0, 1, 0,
"gdhandle color x1 y1 x2 y2"},
131 "gdhandle color x1 y1 x2 y2"},
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 cx cy width height start end"},
149 "gdhandle color cx cy width height start end"},
151 "gdhandle color x1 y1 x2 y2 x3 y3 ..."},
153 "gdhandle color x1 y1 x2 y2 x3 y3 ..."},
154 {
"fill",
tclGdFillCmd, 4, 5, 0, 1, 0,
"gdhandle color x y ?bordercolor?"},
161 "gdhandle color fontname size angle x y string"},
163 "desthandle srchandle destx desty srcx srcy destw desth ?srcw srch?"},
164 {
"get",
tclGdGetCmd, 3, 3, 0, 1, 0,
"gdhandle x y"},
185 if (Tcl_GetIntFromObj(interp, obj,
color) == TCL_OK)
188 Tcl_ResetResult(interp);
190 if (Tcl_ListObjGetElements(interp, obj, &nlist, &theList) != TCL_OK)
192 if (nlist < 1 || nlist > 2)
195 char *firsttag = Tcl_GetString(theList[0]);
196 switch (firsttag[0]) {
200 char *secondtag = Tcl_GetString(theList[1]);
201 if (secondtag[0] ==
's') {
202 *
color = gdStyledBrushed;
212 char *secondtag = Tcl_GetString(theList[1]);
213 if (secondtag[0] ==
'b') {
214 *
color = gdStyledBrushed;
230 if (retval == TCL_ERROR)
231 Tcl_SetResult(interp,
"Malformed special color value", TCL_STATIC);
351static int gdCmd(ClientData clientData, Tcl_Interp *interp,
int argc,
352 Tcl_Obj *
const objv[]) {
355 Tcl_SetResult(interp,
"wrong # args: should be \"gd option ...\"",
367 (unsigned)argc - 2 >
subcmdVec[subi].maxargs) {
377 Tcl_SetResult(interp,
"GD handle(s) not specified", TCL_STATIC);
380 for (
unsigned argi = 2 +
subcmdVec[subi].subcmds;
394 const char *
fname = Tcl_GetString(objv[
subcmdVec[subi].unsafearg]);
395 if (!Tcl_IsChannelExisting(
fname)) {
396 Tcl_AppendResult(interp,
"Access to ",
fname,
397 " not allowed in safe interpreter",
NULL);
407 Tcl_AppendResult(interp,
"bad option \"", Tcl_GetString(objv[1]),
408 "\": should be ", 0);
410 Tcl_AppendResult(interp, (subi > 0 ?
", " :
""),
subcmdVec[subi].
cmd, 0);
416 gdImagePtr im =
NULL;
419 char *
cmd = Tcl_GetString(objv[1]);
422 if (Tcl_GetIntFromObj(interp, objv[2], &w) != TCL_OK)
424 if (Tcl_GetIntFromObj(interp, objv[3], &h) != TCL_OK)
428 Tcl_GetBooleanFromObj(interp, objv[4], &trueColor) == TCL_ERROR)
431 im = gdImageCreateTrueColor(w, h);
433 im = gdImageCreate(w, h);
436 snprintf(buf,
sizeof(buf),
"GD unable to allocate %d X %d image", w, h);
437 Tcl_SetResult(interp, buf, TCL_VOLATILE);
440 }
else if (
streq(
cmd,
"createTrueColor")) {
441 if (Tcl_GetIntFromObj(interp, objv[2], &w) != TCL_OK)
443 if (Tcl_GetIntFromObj(interp, objv[3], &h) != TCL_OK)
445 im = gdImageCreateTrueColor(w, h);
448 snprintf(buf,
sizeof(buf),
"GD unable to allocate %d X %d image", w, h);
449 Tcl_SetResult(interp, buf, TCL_VOLATILE);
453 char *arg2 = Tcl_GetString(objv[2]);
455 FILE *filePtr =
NULL;
457 ClientData clientdata;
458 if (Tcl_GetOpenFile(interp, arg2, 0, 1, &clientdata) == TCL_OK) {
459 filePtr = (FILE *)clientdata;
462 if (filePtr ==
NULL) {
466 if ((filePtr = fopen(arg2,
"rb")) ==
NULL) {
470 Tcl_ResetResult(interp);
475 im = gdImageCreateFromGd(filePtr);
477 }
else if (
streq(&
cmd[10],
"GD2")) {
478 im = gdImageCreateFromGd2(filePtr);
481 }
else if (
streq(&
cmd[10],
"GIF")) {
482 im = gdImageCreateFromGif(filePtr);
485 }
else if (
streq(&
cmd[10],
"JPEG")) {
486 im = gdImageCreateFromJpeg(filePtr);
489 }
else if (
streq(&
cmd[10],
"PNG")) {
490 im = gdImageCreateFromPng(filePtr);
492 }
else if (
streq(&
cmd[10],
"WBMP")) {
493 im = gdImageCreateFromWBMP(filePtr);
495 }
else if (
streq(&
cmd[10],
"XBM")) {
496 im = gdImageCreateFromXbm(filePtr);
499 Tcl_AppendResult(interp,
cmd + 10,
"unrecognizable format requested",
510 Tcl_AppendResult(interp,
"GD unable to read image file '", arg2,
"` as ",
516 Tcl_Obj *result = Tcl_NewObj();
519 result->bytes =
NULL;
520 Tcl_SetObjResult(interp, result);
525 Tcl_Obj *
const objv[]) {
530 gdImagePtr im =
IMGPTR(objv[2]);
536static int tclGdWriteCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
539 const char *
cmd = Tcl_GetString(objv[1]);
540 if (
cmd[5] ==
'J' ||
cmd[5] ==
'W') {
546 Tcl_SetResult(interp,
"WBMP saving requires the foreground pixel value",
550 }
else if (Tcl_GetIntFromObj(interp, objv[4], &arg4) != TCL_OK)
553 if (
cmd[5] ==
'J' && argc > 4 && (arg4 > 100 || arg4 < 1)) {
554 Tcl_SetObjResult(interp, objv[4]);
555 Tcl_AppendResult(interp,
556 ": JPEG image quality, if specified, must be an integer "
557 "from 1 to 100, or -1 for default",
564 gdImagePtr im =
IMGPTR(objv[2]);
565 const char *
fname = Tcl_GetString(objv[3]);
569 FILE *filePtr =
NULL;
571 ClientData clientdata;
572 if (Tcl_GetOpenFile(interp,
fname, 1, 1, &clientdata) == TCL_OK) {
573 filePtr = (FILE *)clientdata;
576 if (filePtr ==
NULL) {
581 if ((filePtr = fopen(
fname,
"wb")) ==
NULL) {
582 Tcl_AppendResult(interp,
"could not open :",
fname,
583 "': ", strerror(errno),
NULL);
586 Tcl_ResetResult(interp);
599 gdImageGd(im, filePtr);
602#define GD2_CHUNKSIZE 128
603#define GD2_COMPRESSED 2
604 gdImageGd2(im, filePtr, GD2_CHUNKSIZE, GD2_COMPRESSED);
608 gdImageGif(im, filePtr);
611 }
else if (
streq(&
cmd[5],
"JPEG")) {
612#define JPEG_QUALITY -1
613 gdImageJpeg(im, filePtr, JPEG_QUALITY);
617 gdImagePng(im, filePtr);
619 }
else if (
streq(&
cmd[5],
"WBMP")) {
622 int foreground = gdImageColorClosest(im, 0, 0, 0);
623 gdImageWBMP(im, foreground, filePtr);
636 Tcl_Obj *
const objv[]) {
640 gdImagePtr im =
IMGPTR(objv[2]);
644 if (Tcl_GetBooleanFromObj(interp, objv[3], &on_off) != TCL_OK)
648 gdImageInterlace(im, on_off);
651 on_off = gdImageGetInterlaced(im);
653 Tcl_SetObjResult(interp, Tcl_NewBooleanObj(on_off));
657static int tclGdColorCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
663 for (
int subi = 0; subi < nsub; subi++) {
673 gdImagePtr im =
IMGPTR(objv[3]);
678 for (
int i = 0; i < argc - 4; i++) {
679 if (Tcl_GetIntFromObj(interp, objv[i + 4], &args[i]) != TCL_OK) {
682 if (args[i] < -255 || args[i] > 255) {
683 Tcl_SetResult(interp,
"argument out of range 0-255", TCL_STATIC);
697 Tcl_AppendResult(interp,
"bad option \"", Tcl_GetString(objv[2]),
700 Tcl_AppendResult(interp,
"wrong # args: ", 0);
702 Tcl_AppendResult(interp,
"should be ", 0);
703 for (
int subi = 0; subi < nsub; subi++)
704 Tcl_AppendResult(interp, subi > 0 ?
", " :
"",
colorCmdVec[subi].
cmd, 0);
713 int color = gdImageColorAllocate(im, args[0], args[1], args[2]);
714 Tcl_SetObjResult(interp, Tcl_NewIntObj(
color));
722 int color = gdImageColorExact(im, args[0], args[1], args[2]);
723 Tcl_SetObjResult(interp, Tcl_NewIntObj(
color));
731 int color = gdImageColorClosest(im, args[0], args[1], args[2]);
732 Tcl_SetObjResult(interp, Tcl_NewIntObj(
color));
740 int color = gdImageColorResolve(im, args[0], args[1], args[2]);
741 Tcl_SetObjResult(interp, Tcl_NewIntObj(
color));
750 gdImageColorDeallocate(im, args[0]);
760 gdImageColorTransparent(im,
color);
762 color = gdImageGetTransparent(im);
764 Tcl_SetObjResult(interp, Tcl_NewIntObj(
color));
772 int ncolors = gdImageColorsTotal(im);
776 if (i >= ncolors || im->open[i]) {
777 Tcl_SetResult(interp,
"No such color", TCL_STATIC);
780 Tcl_Obj *tuple[] = {Tcl_NewIntObj(i), Tcl_NewIntObj(gdImageRed(im, i)),
781 Tcl_NewIntObj(gdImageGreen(im, i)),
782 Tcl_NewIntObj(gdImageBlue(im, i))};
783 const Tcl_Size tuple_size =
sizeof(tuple) /
sizeof(tuple[0]);
784 Tcl_SetObjResult(interp, Tcl_NewListObj(tuple_size, tuple));
786 result = Tcl_NewListObj(0,
NULL);
787 for (
int i = 0; i < ncolors; i++) {
790 Tcl_Obj *tuple[] = {Tcl_NewIntObj(i), Tcl_NewIntObj(gdImageRed(im, i)),
791 Tcl_NewIntObj(gdImageGreen(im, i)),
792 Tcl_NewIntObj(gdImageBlue(im, i))};
793 const Tcl_Size tuple_size =
sizeof(tuple) /
sizeof(tuple[0]);
794 Tcl_ListObjAppendElement(
NULL, result, Tcl_NewListObj(tuple_size, tuple));
796 Tcl_SetObjResult(interp, result);
802static int tclGdBrushCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
807 gdImagePtr im =
IMGPTR(objv[2]);
808 gdImagePtr imbrush =
IMGPTR(objv[3]);
811 gdImageSetBrush(im, imbrush);
816static int tclGdTileCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
821 gdImagePtr im =
IMGPTR(objv[2]);
822 gdImagePtr tile =
IMGPTR(objv[3]);
825 gdImageSetTile(im, tile);
830static int tclGdStyleCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
831 Tcl_Obj *
const *colorObjv = &objv[3];
835 gdImagePtr im =
IMGPTR(objv[2]);
842 if (Tcl_ListObjGetElements(interp, objv[3], &ncolor, &colorObjp) != TCL_OK)
844 colorObjv = colorObjp;
847 int *colors = (
int *)Tcl_Alloc((
size_t)ncolor *
sizeof(int));
849 for (
Tcl_Size i = 0; i < ncolor; i++)
850 if (Tcl_GetIntFromObj(interp, colorObjv[i], &colors[i]) != TCL_OK) {
856 if (retval == TCL_OK)
857 gdImageSetStyle(im, colors, (
int)ncolor);
861 Tcl_Free((
char *)colors);
866static int tclGdSetCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
878 if (Tcl_GetIntFromObj(interp, objv[4], &x) != TCL_OK)
880 if (Tcl_GetIntFromObj(interp, objv[5], &y) != TCL_OK)
884 gdImageSetPixel(im, x, y,
color);
889static int tclGdLineCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
893 int color, x1, y1, x2, y2;
901 if (Tcl_GetIntFromObj(interp, objv[4], &x1) != TCL_OK)
903 if (Tcl_GetIntFromObj(interp, objv[5], &y1) != TCL_OK)
905 if (Tcl_GetIntFromObj(interp, objv[6], &x2) != TCL_OK)
907 if (Tcl_GetIntFromObj(interp, objv[7], &y2) != TCL_OK)
911 gdImageLine(im, x1, y1, x2, y2,
color);
916static int tclGdRectCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
920 int color, x1, y1, x2, y2;
929 if (Tcl_GetIntFromObj(interp, objv[4], &x1) != TCL_OK)
931 if (Tcl_GetIntFromObj(interp, objv[5], &y1) != TCL_OK)
933 if (Tcl_GetIntFromObj(interp, objv[6], &x2) != TCL_OK)
935 if (Tcl_GetIntFromObj(interp, objv[7], &y2) != TCL_OK)
939 cmd = Tcl_GetString(objv[1]);
941 gdImageRectangle(im, x1, y1, x2, y2,
color);
943 gdImageFilledRectangle(im, x1, y1, x2, y2,
color);
948static int tclGdArcCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
952 int color, cx, cy, width, height, start, end;
961 if (Tcl_GetIntFromObj(interp, objv[4], &cx) != TCL_OK)
963 if (Tcl_GetIntFromObj(interp, objv[5], &cy) != TCL_OK)
965 if (Tcl_GetIntFromObj(interp, objv[6], &width) != TCL_OK)
967 if (Tcl_GetIntFromObj(interp, objv[7], &height) != TCL_OK)
969 if (Tcl_GetIntFromObj(interp, objv[8], &start) != TCL_OK)
971 if (Tcl_GetIntFromObj(interp, objv[9], &end) != TCL_OK)
975 cmd = Tcl_GetString(objv[1]);
977 gdImageArc(im, cx, cy, width, height, start, end,
color);
980 else if (
cmd[0] ==
'f' &&
cmd[4] ==
'a')
981 gdImageFilledArc(im, cx, cy, width, height, start, end,
color, gdArc);
983 else if (
cmd[0] ==
'o' &&
cmd[4] ==
'a') {
984 gdImageArc(im, cx, cy, width, height, start, end,
color);
985 gdImageFilledArc(im, cx, cy, width, height, start, end,
color,
987 }
else if (
cmd[0] ==
'c')
988 gdImageFilledArc(im, cx, cy, width, height, start, end,
color,
990 else if (
cmd[0] ==
'f' &&
cmd[4] ==
'c')
991 gdImageFilledArc(im, cx, cy, width, height, start, end,
color, gdChord);
992 else if (
cmd[0] ==
'o' &&
cmd[4] ==
'c')
993 gdImageFilledArc(im, cx, cy, width, height, start, end,
color,
994 gdChord | gdEdged | gdNoFill);
995 else if (
cmd[0] ==
'p' ||
996 (
cmd[0] ==
'f' &&
cmd[4] ==
'p'))
997 gdImageFilledArc(im, cx, cy, width, height, start, end,
color, gdPie);
998 else if (
cmd[0] ==
'o' &&
cmd[4] ==
'p')
999 gdImageFilledArc(im, cx, cy, width, height, start, end,
color,
1000 gdPie | gdEdged | gdNoFill);
1006 Tcl_Obj *
const objv[]) {
1009 Tcl_Obj *
const *pointObjv = &objv[4];
1011 int retval = TCL_OK;
1025 Tcl_Obj **pointObjp;
1026 if (Tcl_ListObjGetElements(interp, objv[4], &npoints, &pointObjp) != TCL_OK)
1028 pointObjv = pointObjp;
1032 if (npoints % 2 != 0) {
1033 Tcl_SetResult(interp,
"Number of coordinates must be even", TCL_STATIC);
1041 Tcl_SetResult(interp,
"Must specify at least 3 points.", TCL_STATIC);
1046 points = (gdPointPtr)Tcl_Alloc((
size_t)npoints *
sizeof(gdPoint));
1049 for (
Tcl_Size i = 0; i < npoints; i++)
1050 if (Tcl_GetIntFromObj(interp, pointObjv[i * 2], &
points[i].x) != TCL_OK ||
1051 Tcl_GetIntFromObj(interp, pointObjv[i * 2 + 1], &
points[i].y) !=
1058 cmd = Tcl_GetString(objv[1]);
1062 gdImageFilledPolygon(im,
points, (
int)npoints,
color);
1067 Tcl_Free((
char *)
points);
1073static int tclGdFillCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
1075 int color, x, y, border;
1083 if (Tcl_GetIntFromObj(interp, objv[4], &x) != TCL_OK)
1085 if (Tcl_GetIntFromObj(interp, objv[5], &y) != TCL_OK)
1089 if (argc - 2 == 5) {
1090 if (Tcl_GetIntFromObj(interp, objv[6], &border) != TCL_OK)
1092 gdImageFillToBorder(im, x, y, border,
color);
1094 gdImageFill(im, x, y,
color);
1100static int tclGdCopyCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
1101 gdImagePtr imdest, imsrc;
1102 int destx, desty, srcx, srcy, destw, desth, srcw, srch;
1105 imdest =
IMGPTR(objv[2]);
1109 if (Tcl_GetIntFromObj(interp, objv[4], &destx) != TCL_OK)
1111 if (Tcl_GetIntFromObj(interp, objv[5], &desty) != TCL_OK)
1113 if (Tcl_GetIntFromObj(interp, objv[6], &srcx) != TCL_OK)
1115 if (Tcl_GetIntFromObj(interp, objv[7], &srcy) != TCL_OK)
1117 if (Tcl_GetIntFromObj(interp, objv[8], &destw) != TCL_OK)
1119 if (Tcl_GetIntFromObj(interp, objv[9], &desth) != TCL_OK)
1123 if (argc - 2 == 10) {
1124 if (Tcl_GetIntFromObj(interp, objv[10], &srcw) != TCL_OK)
1126 if (Tcl_GetIntFromObj(interp, objv[11], &srch) != TCL_OK)
1129 gdImageCopyResized(imdest, imsrc, destx, desty, srcx, srcy, destw, desth,
1132 gdImageCopy(imdest, imsrc, destx, desty, srcx, srcy, destw, desth);
1137static int tclGdGetCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
1147 if (Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK)
1149 if (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)
1153 color = gdImageGetPixel(im, x, y);
1154 Tcl_SetObjResult(interp, Tcl_NewIntObj(
color));
1158static int tclGdSizeCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
1162 Tcl_Obj *answers[2];
1167 answers[0] = Tcl_NewIntObj(gdImageSX(im));
1168 answers[1] = Tcl_NewIntObj(gdImageSY(im));
1169 Tcl_SetObjResult(interp, Tcl_NewListObj(2, answers));
1173static int tclGdTextCmd(Tcl_Interp *interp,
int argc, Tcl_Obj *
const objv[]) {
1177 double ptsize, angle;
1178 char *
error, *fontname;
1185 if (argc == 2 || (objv[2]->typePtr != &
GdPtrType &&
1198 if (Tcl_GetDoubleFromObj(interp, objv[5], &ptsize) != TCL_OK) {
1203 if (Tcl_GetDoubleFromObj(interp, objv[6], &angle) != TCL_OK) {
1208 if (Tcl_GetIntFromObj(interp, objv[7], &x) != TCL_OK) {
1211 if (Tcl_GetIntFromObj(interp, objv[8], &y) != TCL_OK) {
1215 str = Tcl_GetStringFromObj(objv[9],
NULL);
1216 fontname = Tcl_GetString(objv[4]);
1218 gdFTUseFontConfig(1);
1219 error = gdImageStringFT(im, brect,
color, fontname, ptsize, angle, x, y,
str);
1222 Tcl_SetResult(interp,
error, TCL_VOLATILE);
1225 for (i = 0; i < 8; i++) {
1226 orect[i] = Tcl_NewIntObj(brect[i]);
1228 Tcl_SetObjResult(interp, Tcl_NewListObj(8, orect));
1237 if (Tcl_InitStubs(interp, TCL_VERSION, 0) ==
NULL) {
1241 if (Tcl_PkgRequire(interp,
"Tcl", TCL_VERSION, 0) ==
NULL) {
1247 char adjusted_version[
sizeof(PACKAGE_VERSION)] = PACKAGE_VERSION;
1248 char *tilde_dev = strstr(adjusted_version,
"~dev.");
1249 if (tilde_dev !=
NULL) {
1251 memmove(tilde_dev + 1, tilde_dev + strlen(
"~dev."),
1252 strlen(tilde_dev + strlen(
"~dev.")) + 1);
1254 if (Tcl_PkgProvide(interp,
"Gdtclft", adjusted_version) != TCL_OK) {
1257 Tcl_CreateObjCommand(interp,
"gd",
gdCmd,
NULL, (Tcl_CmdDeleteProc *)
NULL);
1264 Tcl_GetCommandInfo(interp,
"gd", &
info) != 1)
1266 info.objClientData = (
char *)
info.objClientData + 1;
1267 if (Tcl_SetCommandInfo(interp,
"gd", &
info) != 1)
1298BOOL APIENTRY DllEntryPoint(HINSTANCE hInst, DWORD reason, LPVOID reserved);
1299BOOL APIENTRY DllEntryPoint(HINSTANCE hInst, DWORD reason, LPVOID reserved) {
1310static int BufferSinkFunc(
void *context,
const char *buffer,
int len) {
1319 Tcl_Obj *
const objv[]) {
1323 gdSink buffsink = {.sink = BufferSinkFunc, .context = &buffer};
1325 gdImagePtr im =
IMGPTR(objv[2]);
1327 gdImagePngToSink(im, &buffsink);
1329 const size_t buffer_length =
agxblen(&buffer);
1330 void *
const result =
agxbuse(&buffer);
1332 assert(buffer_length <= INT_MAX);
1333 Tcl_Obj *output = Tcl_NewByteArrayObj(result, (
Tcl_Size)buffer_length);
1338 Tcl_IncrRefCount(output);
1340 if (Tcl_ObjSetVar2(interp, objv[3],
NULL, output, 0) ==
NULL)
1347 size_t len = strlen(
GdPtrType.name) + (
sizeof(
void *) + 1) * 2 + 1;
1348 O->bytes = Tcl_Alloc(
len);
1353 if (
O->bytes ==
NULL ||
O->bytes[0] ==
'\0' ||
1357 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.
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?