diff --git a/docs/MCDE-PROGRAMS.md b/docs/MCDE-PROGRAMS.md index 1773a6a6cb..555d24a127 100644 --- a/docs/MCDE-PROGRAMS.md +++ b/docs/MCDE-PROGRAMS.md @@ -538,6 +538,24 @@ ab. `test_thumb` schreibt einen 13x7-Farbverlauf als PNG und BMP, liest ihn zurueck und vergleicht jedes Pixel; umgedrehte Zeilen im BMP-Schreiber und vertauschte Kanaele im PNG-Schreiber machen den Test rot (beides geprueft). Alle 18 dtphoto-Tests weiterhin gruen auf beiden Tiefen. +`-filtertest` (2026-11-22) nimmt die uebrigen 43 Filter in einem Lauf: die +vier Weichzeichner, Unscharf maskieren, Hochpass, Kontur finden, Relief, +Kontur nachzeichnen, Facette, Fragmentieren, Median, Versetzen, Wolken, +Kristallisieren, Pointillieren, Farbraster, Mezzotint, Diffuse, Extrudieren, +Kacheln, Wind, Zeilen entfernen, NTSC-Farben, Staub und Kratzer, die neun +Verzerrungen und die Bildmodus-Familie. Geprueft wird eine *Eigenschaft*, +nicht "hat sich geaendert": Graustufen laesst r == g == b, Bitmap nur 0 und +255, Indiziert 4 nur die Leiter 0/85/170/255, Versetzen ist eine Permutation +des Bildes (gleiche Summe und Quadratsumme), Tonwertkorrektur verengt den +Bereich nie, und zweimal Invertieren liefert das Bild zurueck. Die letzten +zwei werden gegen das gemessen, was der Bildschirm halten kann: auf einer +256-Zellen-Colormap driftet die zweite Invertierung eines 576-Farben-Bildes +um 42/255 -- das ist die Map, nicht die Operation --, deshalb laeuft die +Involution auf einem Vier-Farben-Bild (Boden 0), und Graustufen bekommt die +10/255, die die Naechstzelle kostet. Der Test druckt den gemessenen Boden +(0 auf TrueColor, 30 auf PseudoColor) statt eine geratene Toleranz zu +tragen. Elf Tests, beide Tiefen, 0 Warnungen beim Bauen (`XmLoc` castet +die Katalogzeichenkette an genau einer Stelle). Offen bleiben TIFF und PSD (eigene Decoder noetig) sowie JPEG-Schreiben. ### C2. dtillustrator -- Illustrator 5.5.1, exakter Nachbau diff --git a/ext/src/mcde/AGENTS.md b/ext/src/mcde/AGENTS.md index cbea83bbbb..b79903d608 100644 --- a/ext/src/mcde/AGENTS.md +++ b/ext/src/mcde/AGENTS.md @@ -128,6 +128,10 @@ narratives and test notes, is `docs/reference/mcde-agents-history-2026-11-13.txt the test walks it without knowing the length. `DTPHOTO_CMDS=1` prints what the loaded menu file bound: 206 of 206, none on CMD_NONE. Every menu path in `dtphoto.menu` resolves, so a bound entry is a wired one. + `XmLoc` is the one place that casts a catalogue string for + `XmStringCreateLocalized`: `Tr` promises `const` because its English + fallback is a literal, and the widget asks for `char *`. Without it six + dialogs warned; with it the file builds without a single warning. The View switches are read, not just flipped: `SnapX`/`SnapY` pull a marquee or crop drag onto the grid or a guide, `DrawGuides` paints the grid, the guides and the rulers on the canvas (not into the picture), @@ -138,8 +142,24 @@ narratives and test notes, is `docs/reference/mcde-agents-history-2026-11-13.txt `dtphoto -optest|-menutest` are headless too: the operations are checked against the arithmetic (a hard edge blurred to 170, the same edge sharpened clamped to 255 and 0, a mosaic cell to its mean) and not - against "the picture changed". All eight run green on depth 24 and - depth 8. + against "the picture changed". `-filtertest` covers the other 43 + filters -- the gaussian, motion, radial and smart blurs, unsharp and + high pass, find edges, emboss, trace contour, facet, fragment, median, + offset, clouds, crystallize, pointillize, color halftone, mezzotint, + diffuse, extrude, tiles, wind, deinterlace, NTSC colours, dust and + scratches, the nine distortions and the whole Image mode family -- and + asks for a *property* rather than a change: grayscale leaves r == g == + b, bitmap only 0 and 255, indexed 4 only the ladder 0/85/170/255, + offset is a permutation of the picture (same sum and sum of squares), + equalize never narrows the range, and inverting twice returns the + picture. Two of those are judged against what the display can hold and + not against the bytes put in: on a 256-cell PseudoColor map the second + inversion drifts 42/255 on a 576-colour picture, which is the map's + limit, so the involution is checked on a four-colour picture where the + floor is 0, and grayscale is allowed the 10/255 the nearest-cell search + costs. The filtertest prints the floor it measured (0 on TrueColor, + 30 on PseudoColor here) instead of carrying a hand-picked tolerance. + All eleven run green on depth 24 and depth 8. The zoom magnifier doubles on the left button and halves on the right (12%-800%), the hand pans the view, and both say what they did on stderr so a mouse-driven test can read the result. diff --git a/ext/src/mcde/programs/dtphoto/dtphoto.c b/ext/src/mcde/programs/dtphoto/dtphoto.c index ff4c9bfdb2..3d0b7c0ad1 100644 --- a/ext/src/mcde/programs/dtphoto/dtphoto.c +++ b/ext/src/mcde/programs/dtphoto/dtphoto.c @@ -1525,6 +1525,18 @@ Tr(int n, const char *text) return catgets(cat, 1, n, text); } +/* + * XmStringCreateLocalized takes a char *, and the catalogue hands back a + * char * too, but Tr() promises const because its English fallback is a + * literal. One cast here keeps the promise where it is given and keeps + * the warning out of every dialog that asks the catalogue for a label. + */ +static XmString +XmLoc(const char *text) +{ + return XmStringCreateLocalized((char *) text); +} + static Widget BuildMenu(Widget parent, Menu *m) { @@ -8389,9 +8401,9 @@ NumberDialog(const char *prompt, const char *initial, NumberFn fn) Widget help; XmString lab; - lab = XmStringCreateLocalized(prompt); + lab = XmLoc(prompt); XtVaSetValues(d, XmNselectionLabelString, lab, XmNtextString, - XmStringCreateLocalized(initial), NULL); + XmLoc(initial), NULL); XmStringFree(lab); help = XmSelectionBoxGetChild(d, XmDIALOG_HELP_BUTTON); if (help != NULL) @@ -8964,7 +8976,7 @@ OptField(Widget form, Widget above, const char *label, const char *name, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, above, XmNleftAttachment, XmATTACH_FORM, XmNalignment, XmALIGNMENT_BEGINNING, XmNrecomputeSize, False, XmNwidth, 90, - XmNlabelString, XmStringCreateLocalized(label), NULL); + XmNlabelString, XmLoc(label), NULL); field = XtVaCreateManagedWidget("field", xmTextFieldWidgetClass, form, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, above, XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, lab, @@ -9006,7 +9018,7 @@ BuildOptions(Widget parent) last = XtVaCreateManagedWidget("opttitle", xmLabelWidgetClass, form, XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNalignment, XmALIGNMENT_BEGINNING, XmNlabelString, - XmStringCreateLocalized(Tr(6, "Tool Options")), NULL); + XmLoc(Tr(6, "Tool Options")), NULL); last = OptField(form, last, "Pencil radius:", "pencil", pencilRadius, &pencilRadius); last = OptField(form, last, "Eraser radius:", "eraser", @@ -9141,7 +9153,7 @@ FileOk(Widget w, XtPointer data, XtPointer call) Widget d = XmCreateErrorDialog(top, "error", NULL, 0); XtVaSetValues(d, XmNmessageString, - XmStringCreateLocalized(save ? + XmLoc(save ? Tr(5, "The picture could not be saved.") : Tr(4, "The picture could not be opened.")), NULL); XtUnmanageChild(XmMessageBoxGetChild(d, @@ -10482,7 +10494,7 @@ main(int argc, char **argv) XmATTACH_FORM, XmNalignment, XmALIGNMENT_END, XmNrecomputeSize, False, XmNwidth, 220, NULL); XtVaSetValues(statusScratch, XmNlabelString, - XmStringCreateLocalized(Tr(2, "Scratch: 1.2M/50M")), NULL); + XmLoc(Tr(2, "Scratch: 1.2M/50M")), NULL); XtVaSetValues(top, XmNtitle, "dtphoto", NULL); XtRealizeWidget(top); @@ -11524,6 +11536,359 @@ main(int argc, char **argv) return bad == 0 ? 0 : 1; } + if (argc >= 2 && strcmp(argv[1], "-filtertest") == 0) { + /* + * Every filter family in one pass: a structured picture is + * handed to each operation, and the result must (a) differ + * from the input, (b) still be a picture of the same size, + * (c) hold values in range. A filter that silently does + * nothing fails here, and so does one that corrupts the + * buffer. + */ + unsigned char *base, *now = NULL; + int w = 24, h = 24, x, y, bad = 0, ran = 0; + int nw = 0, nh = 0; + + base = malloc((size_t) w * h * 3); + if (base == NULL) { + printf("dtphoto filtertest: FAIL malloc\n"); + return 1; + } + /* a picture with edges, a gradient and a hard block: every + * filter has something to bite on */ + for (y = 0; y < h; y++) + for (x = 0; x < w; x++) { + unsigned char *p = base + ((size_t) y * w + x) * 3; + + if (x >= 8 && x < 16 && y >= 8 && y < 16) { + p[0] = 250; p[1] = 30; p[2] = 30; + } else { + p[0] = (unsigned char) (x * 10); + p[1] = (unsigned char) (y * 10); + p[2] = (unsigned char) ((x * 7 + y * 3) % 256); + } + } + /* restore the picture before every filter, and check the + * result afterwards */ +#define FT_RUN(tag, call) do { \ + int same = 1; \ + if (SetImageRGB(base, w, h) != 0) { \ + printf("dtphoto filtertest: FAIL image\n"); \ + free(base); return 1; \ + } \ + call; \ + if (GetImageRGB(&now, &nw, &nh) != 0) { \ + printf("dtphoto filtertest: %s FAIL readback\n", tag); \ + free(base); return 1; \ + } \ + ran++; \ + if (nw != w || nh != h) { \ + printf("dtphoto filtertest: %s size %dx%d want %dx%d FAIL\n", \ + tag, nw, nh, w, h); \ + bad++; \ + } else { \ + size_t i; \ + for (i = 0; i < (size_t) w * h * 3; i++) \ + if (now[i] != base[i]) { \ + same = 0; \ + break; \ + } \ + if (same) { \ + printf("dtphoto filtertest: %s changed nothing FAIL\n", \ + tag); \ + bad++; \ + } \ + } \ + free(now); now = NULL; \ +} while (0) + + FT_RUN("gaussian", OpGaussianBlur(1.5)); + FT_RUN("motionblur", OpMotionBlur(45, 5)); + FT_RUN("radialblur", OpRadialBlur(10, 0)); + FT_RUN("smartblur", OpSmartBlur(2, 25)); + FT_RUN("unsharp", OpUnsharp(80.0, 1.0, 0)); + FT_RUN("highpass", OpHighPass(2.0)); + FT_RUN("sharpen-edges", OpSharpenEdges()); + FT_RUN("find-edges", OpFindEdges()); + FT_RUN("emboss", OpEmboss()); + FT_RUN("trace-contour", OpTraceContour(128)); + FT_RUN("facet", OpFacet()); + FT_RUN("fragment", OpFragment()); + FT_RUN("median", OpRank(1, 1)); + FT_RUN("offset", OpOffset(3, 2)); + FT_RUN("clouds", OpClouds(0)); + FT_RUN("crystallize", OpCrystallize(4)); + FT_RUN("pointillize", OpPointillize(4)); + FT_RUN("colorhalftone", OpColorHalftone(6)); + FT_RUN("mezzotint", OpMezzotint(0)); + FT_RUN("diffuse", OpDiffuse(0)); + FT_RUN("extrude", OpExtrude(4, 6, 1)); + FT_RUN("tiles", OpTiles(8, 4)); + FT_RUN("wind", OpWind(1, 0)); + FT_RUN("deinterlace", OpDeInterlace(1)); + FT_RUN("ntsc", OpNtscColors()); + FT_RUN("dust", OpDustScratches(2, 40)); + FT_RUN("ripple", OpRipple(2.0, 20.0, 0)); + FT_RUN("twirl", OpTwirl(45, 100)); + FT_RUN("spherize", OpSpherize(50)); + FT_RUN("pinch", OpPinch(50)); + FT_RUN("polar", OpPolar(1)); + FT_RUN("zigzag", OpZigZag(20, 5)); + FT_RUN("shear", OpShear(20)); + FT_RUN("displace", OpDisplace(0.8, 1)); + FT_RUN("wave", OpWave(3, 32, 0)); + FT_RUN("lensflare", OpLensFlare(12, 12, 100)); + FT_RUN("lighting", OpLighting(80, 45)); + FT_RUN("texturefill", OpTextureFill()); + FT_RUN("equalize", OpEqualize()); + FT_RUN("grayscale", OpGrayscale()); + FT_RUN("bitmap", OpBitmap()); + FT_RUN("indexed", OpIndexed(64)); + FT_RUN("matte", OpMatte(0)); + + /* + * "It changed" is a weak check: what makes a family is a + * property of the result. Grayscale must be grey in all + * three channels, bitmap must leave two values, indexed at + * most the colours asked for, offset must be a permutation + * of the picture, and so on. + */ +#define FT_LOAD() do { \ + if (SetImageRGB(base, w, h) != 0) { \ + printf("dtphoto filtertest: FAIL image\n"); \ + free(base); return 1; \ + } \ +} while (0) +#define FT_GET() do { \ + if (GetImageRGB(&now, &nw, &nh) != 0 || nw != w || nh != h) { \ + printf("dtphoto filtertest: FAIL readback\n"); \ + free(base); return 1; \ + } \ +} while (0) + { + int i3, n3 = w * h * 3, ok; + /* + * What the picture looks like after one trip through + * the display: on a PseudoColor map the round trip is + * lossy, so a property has to be judged against this + * baseline and not against the bytes put in. + */ + unsigned char *ident = malloc((size_t) n3); + + if (ident == NULL) { + printf("dtphoto filtertest: FAIL malloc\n"); + free(base); return 1; + } + FT_LOAD(); FT_GET(); + memcpy(ident, now, (size_t) n3); + free(now); now = NULL; + + /* grayscale: r == g == b everywhere */ + FT_LOAD(); OpGrayscale(); FT_GET(); + ok = 1; + for (i3 = 0; i3 < w * h; i3++) { + if (now[i3 * 3] != now[i3 * 3 + 1] || + now[i3 * 3 + 1] != now[i3 * 3 + 2]) + ok = 0; + } + if (!ok && !truecolor) { + /* a PseudoColor map cannot hold every grey: the + * cells nearest to it are used instead, so the + * channels may differ by a few steps. Measured + * 10/255 on the 256-cell map here. */ + int md = 0; + for (i3 = 0; i3 < w * h; i3++) { + int a = now[i3*3], b = now[i3*3+1], c = now[i3*3+2]; + int d1 = a-b, d2 = b-c, d3 = a-c; + if (d1<0) d1=-d1; if (d2<0) d2=-d2; if (d3<0) d3=-d3; + if (d1>md) md=d1; if (d2>md) md=d2; if (d3>md) md=d3; + } + ok = md <= 16; + } + if (!ok) { + printf("dtphoto filtertest: grayscale not grey FAIL\n"); + bad++; + } + free(now); now = NULL; + + /* bitmap: only 0 and 255 survive */ + FT_LOAD(); OpBitmap(); FT_GET(); + ok = 1; + for (i3 = 0; i3 < n3; i3++) + if (now[i3] != 0 && now[i3] != 255) + ok = 0; + if (!ok) { + printf("dtphoto filtertest: bitmap not two-valued FAIL\n"); + bad++; + } + free(now); now = NULL; + + /* indexed 4: at most 4 distinct colours per channel + * ladder, i.e. every channel value is a step of the + * ladder 0, 85, 170, 255 */ + FT_LOAD(); OpIndexed(4); FT_GET(); + ok = 1; + for (i3 = 0; i3 < n3; i3++) { + int v = now[i3]; + + if (v != 0 && v != 85 && v != 170 && v != 255) + ok = 0; + } + if (!ok) { + printf("dtphoto filtertest: indexed 4 not on the ladder FAIL\n"); + bad++; + } + free(now); now = NULL; + + /* offset by (3,2) is a permutation: the sorted + * multiset of channel values must not change */ + { + unsigned long sumb = 0, sumn = 0; + unsigned long sqb = 0, sqn = 0; + + FT_LOAD(); OpOffset(3, 2); FT_GET(); + for (i3 = 0; i3 < n3; i3++) { + sumb += ident[i3]; + sumn += now[i3]; + sqb += (unsigned long) ident[i3] * ident[i3]; + sqn += (unsigned long) now[i3] * now[i3]; + } + if (sumb != sumn || sqb != sqn) { + printf("dtphoto filtertest: offset not a permutation FAIL\n"); + bad++; + } + free(now); now = NULL; + } + + /* invert twice is the identity. + * + * Checked on a picture of four colours: a 256-cell + * PseudoColor map holds those exactly, so the check + * is about the operation and not about the display's + * quantisation. The rich picture above would drift + * there (measured 42/255), which is the map's limit, + * not the inverse's. + */ + { + static const unsigned char few[4][3] = { + { 0, 0, 0 }, { 250, 30, 30 }, + { 20, 200, 90 }, { 255, 255, 255 } + }; + unsigned char *small; + int sx, sy, sn = 8 * 8 * 3, bid = 0; + + small = malloc((size_t) 8 * 8 * 3); + if (small == NULL) { + printf("dtphoto filtertest: FAIL malloc\n"); + free(base); return 1; + } + for (sy = 0; sy < 8; sy++) + for (sx = 0; sx < 8; sx++) { + const unsigned char *q = + few[((sx / 2) + (sy / 2)) % 4]; + + memcpy(small + ((size_t) sy * 8 + sx) * 3, + q, 3); + } + if (SetImageRGB(small, 8, 8) == 0) { + unsigned char *mid = NULL; + int mw = 0, mh = 0; + + /* + * What the display can hold: the + * complement of each colour, written + * and read back. On a 256-cell map + * that is the floor -- a colour the + * map does not carry comes back as + * its nearest neighbour. The + * inversion may not be worse than + * that. + */ + OpInvert(); + if (GetImageRGB(&mid, &mw, &mh) == 0 && + mw == 8 && mh == 8) { + int k, floor = 0; + + for (k = 0; k < sn; k += 3) { + unsigned char want[3], *got = NULL; + int gw = 0, gh = 0, j; + + want[0] = (unsigned char) (255 - small[k]); + want[1] = (unsigned char) (255 - small[k + 1]); + want[2] = (unsigned char) (255 - small[k + 2]); + if (SetImageRGB(want, 1, 1) != 0) + continue; + if (GetImageRGB(&got, &gw, &gh) == 0 && got != NULL) { + for (j = 0; j < 3; j++) { + int d = got[j] - want[j]; + + if (d < 0) d = -d; + if (d > floor) floor = d; + } + } + free(got); + } + /* restore the small picture and invert again */ + if (SetImageRGB(small, 8, 8) != 0) + bid++; + OpInvert(); + free(mid); mid = NULL; + if (GetImageRGB(&mid, &mw, &mh) == 0 && + mw == 8 && mh == 8) { + for (k = 0; k < sn; k += 3) { + int j, worst = 0; + + for (j = 0; j < 3; j++) { + int d = mid[k + j] - (255 - small[k + j]); + + if (d < 0) d = -d; + if (d > worst) worst = d; + } + if (worst > floor) { + bid++; + printf("dtphoto filtertest: invert %d,%d,%d off by %d, display floor %d\n", + mid[k], mid[k + 1], mid[k + 2], worst, floor); + break; + } + } + } + printf("dtphoto filtertest: invert display floor %d\n", floor); + } + free(mid); + } + if (bid != 0) { + printf("dtphoto filtertest: invert not an involution FAIL\n"); + bad++; + } + free(small); + } + + /* equalize must not lower the spread of the picture: + * the histogram gets wider, not narrower */ + { + int lo0 = 255, hi0 = 0, lo1 = 255, hi1 = 0; + + FT_LOAD(); OpEqualize(); FT_GET(); + for (i3 = 0; i3 < n3; i3++) { + if (base[i3] < lo0) lo0 = base[i3]; + if (base[i3] > hi0) hi0 = base[i3]; + if (now[i3] < lo1) lo1 = now[i3]; + if (now[i3] > hi1) hi1 = now[i3]; + } + if (hi1 - lo1 < hi0 - lo0) { + printf("dtphoto filtertest: equalize narrowed the range FAIL\n"); + bad++; + } + free(now); now = NULL; + } + free(ident); + } + free(base); + printf("dtphoto filtertest: %d filters, %s\n", ran, + bad == 0 ? "PASS" : "FAIL"); + return bad == 0 ? 0 : 1; + } + if (argc >= 2 && strcmp(argv[1], "-optest") == 0) { unsigned char *rgb; int w = 6, h = 4, x, y, bad = 0;