From 3e3817a83d7419543ef4c54943034b387b5264ac Mon Sep 17 00:00:00 2001 From: lotherk Date: Sun, 22 Nov 2026 13:59:18 +0000 Subject: [PATCH] MCDE dtphoto: the colour-model and layer entries under test, affine centre fixed -filtertest now also covers the six entry points that sat outside every test: CMYK Preview (must not flatten the picture to one colour), Gamut Warning (saturated ink -> warning grey 128, printable pixel untouched), the 5x5 Custom identity kernel, Perspective (0% identity, 50% reads the top-left from inside the picture), a 90 degree Affine rotation as a permutation, and Drop Shadow leaving the picture's own pixels alone. That permutation check found a real bug: OpAffine mapped around w/2 instead of (w-1)/2, so a 90 degree turn of a 24-wide picture lost a whole row to the background -- 552 of 576 pixels hit. Every sampler that maps by inverse mapping now uses the same centre. Measured: 12 test modes x depth 24 and depth 8 = 24/24 green, build with 0 warnings (make dtphoto, forced rebuild). The three false expectations I wrote first were my arithmetic, not the code: gamut marks by ink above 0.9 (250,30,30 is 0.88), perspective squeezes towards the top so the corner reads from inside, and (9,4) is 2 px from the edge. --- docs/MCDE-PROGRAMS.md | 25 ++- ext/src/mcde/AGENTS.md | 18 +- ext/src/mcde/programs/dtphoto/dtphoto.c | 217 +++++++++++++++++++++++- 3 files changed, 254 insertions(+), 6 deletions(-) diff --git a/docs/MCDE-PROGRAMS.md b/docs/MCDE-PROGRAMS.md index 555d24a127..e384fcdac2 100644 --- a/docs/MCDE-PROGRAMS.md +++ b/docs/MCDE-PROGRAMS.md @@ -537,7 +537,10 @@ die Colormap, nicht der Leser, und derselbe Verlauf weicht auf Tiefe 24 um 0 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. +Alle dtphoto-Testmodi weiterhin gruen auf beiden Tiefen -- 12 Modi mal +zwei Tiefen, 24 Laeufe (menutest, viewtest, optest, selmodtest, +retouchtest, selecttest, movetest, croptest, typetest, filtertest, +drawtest und der Datei-Rundlauf `-selftest`). `-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, @@ -554,7 +557,25 @@ 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 +tragen. +Im selben Lauf liegen jetzt die Farbmodell- und Ebeneneintraege, die vorher +in keinem Test standen: CMYK-Vorschau darf das Bild nicht auf eine Farbe +plattdruecken (mindestens 8 verschiedene), Farbumfangswarnung malt eine +gesaettigte Farbe in das Warngrau 128 und laesst eine druckbare in Ruhe -- +geprueft auf einem eigens gebauten Bild (reines Rot neben neutralem Grau), +weil das Strukturbild keine Farbe am Rand des Farbumfangs hat --, der 5x5- +Filter "Benutzerdefiniert" mit einer einzelnen 1 in der Mitte ist die +Identitaet, Perspektive bei 0 % ist die Identitaet und liest bei 50 % die +linke obere Ecke aus dem Bildinneren, eine 90-Grad-Drehung per Affin ist +eine Permutation (gleiche Summe und Quadratsumme) und die Einheitsmatrix +aendert nichts, und Schlagschatten laesst die eigenen Pixel des Bildes in +Ruhe. +Dabei fiel ein echter Fehler auf: `OpAffine` rechnete um `w/2` statt um +`(w-1)/2` und verlor bei einer 90-Grad-Drehung eines 24 Pixel breiten Bildes +eine ganze Pixelreihe an den Hintergrund (552 von 576 Pixeln trafen, der +Test meldete "keine Permutation"). Jede inverse Abtastung braucht denselben +Mittelpunkt, sonst faellt eine Kante weg. +Zwoelf 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. diff --git a/ext/src/mcde/AGENTS.md b/ext/src/mcde/AGENTS.md index b79903d608..c681804bd7 100644 --- a/ext/src/mcde/AGENTS.md +++ b/ext/src/mcde/AGENTS.md @@ -159,7 +159,23 @@ narratives and test notes, is `docs/reference/mcde-agents-history-2026-11-13.txt 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 same run covers the colour-model and layer entry points that used + to sit outside every test: CMYK Preview must not flatten the picture + to one colour, Gamut Warning paints a saturated ink in the warning + grey 128 and leaves a printable pixel alone (checked on a picture built + for it -- pure red beside neutral grey -- because the structure picture + holds no colour at the edge of the gamut), the 5x5 Custom kernel with a + single 1 in the middle is the identity, Perspective at 0% is the + identity and at 50% reads the top-left from inside the picture, a 90 + degree Affine rotation is a permutation (same sum and sum of squares) + and the identity matrix changes nothing, and Drop Shadow leaves the + picture's own pixels alone. All twelve run green on depth 24 and + depth 8. + `OpAffine` maps around (w-1)/2, not w/2: with the half-open centre a + 90-degree turn of a 24-wide picture lost a whole row to the background + (552 of 576 pixels hit), which `-filtertest` caught as "not a + permutation" before the fix. Every sampler that maps by inverse + mapping needs the same centre, or an edge falls off. 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 3d0b7c0ad1..c0b57102b3 100644 --- a/ext/src/mcde/programs/dtphoto/dtphoto.c +++ b/ext/src/mcde/programs/dtphoto/dtphoto.c @@ -3786,7 +3786,7 @@ OpAffine(double m[6]) for (x = 0; x < w; x++) { unsigned char *d = out + ((size_t) y * w + x) * 3; /* inverse mapping: where did this pixel come from */ - double rx = x - w / 2.0, ry = y - h / 2.0; + double rx = x - (w - 1) / 2.0, ry = y - (h - 1) / 2.0; double det = m[0] * m[3] - m[1] * m[2]; double sx, sy; int ix, iy; @@ -3795,8 +3795,8 @@ OpAffine(double m[6]) d[0] = br; d[1] = bg; d[2] = bb; continue; } - sx = w / 2.0 + (m[3] * rx - m[2] * ry) / det; - sy = h / 2.0 + (-m[1] * rx + m[0] * ry) / det; + sx = (w - 1) / 2.0 + (m[3] * rx - m[2] * ry) / det; + sy = (h - 1) / 2.0 + (-m[1] * rx + m[0] * ry) / det; ix = (int) (sx + 0.5); iy = (int) (sy + 0.5); if (ix < 0 || iy < 0 || ix >= w || iy >= h) { @@ -11881,6 +11881,217 @@ main(int argc, char **argv) } free(now); now = NULL; } + + /* + * Colour model and layer effects: the rest of the + * menu whose result has a property and not only a + * difference. + */ + + /* CMYK preview keeps the shape of the picture: a + * pixel that equals the background stays there. The + * corner of the test picture is the background's + * colour only by accident, so the check is that the + * result stays in range and does not turn the whole + * picture into one colour, which a broken separation + * would. */ + { + int distinct = 0, seen[768]; + + memset(seen, 0, sizeof seen); + FT_LOAD(); OpCMYKPreview(); FT_GET(); + for (i3 = 0; i3 < n3; i3 += 3) { + int key = (now[i3] >> 4) << 8 | + (now[i3 + 1] >> 4) << 4 | + (now[i3 + 2] >> 4); + + if (!seen[key & 767]) { + seen[key & 767] = 1; + distinct++; + } + } + if (distinct < 8) { + printf("dtphoto filtertest: cmyk preview flattened the picture to %d colours FAIL\n", + distinct); + bad++; + } + free(now); now = NULL; + } + + /* gamut warning: a saturated ink is painted in the warning + * grey 128, a colour the press can print is left alone. + * The check runs on a picture built for it -- pure red + * (m = y = 1.0, unprintable) beside a neutral grey + * (c = m = y = 0, printable) -- because the structure + * picture above holds no colour at the edge of the gamut. */ + { + unsigned char wide[6] = { 255, 0, 0, 128, 128, 128 }; + unsigned char *wnow = NULL; + int ww = 0, wh = 0; + + if (SetImageRGB(wide, 2, 1) != 0) { + printf("dtphoto filtertest: FAIL image\n"); + free(base); return 1; + } + OpGamutWarning(1); + if (GetImageRGB(&wnow, &ww, &wh) != 0 || + ww != 2 || wh != 1) { + printf("dtphoto filtertest: gamut warning readback FAIL\n"); + free(wnow); + free(base); return 1; + } + if (!(wnow[0] == 128 && wnow[1] == 128 && wnow[2] == 128)) { + printf("dtphoto filtertest: gamut warning left pure red unmarked (%d,%d,%d) FAIL\n", + wnow[0], wnow[1], wnow[2]); + bad++; + } + if (!(wnow[3] == 128 && wnow[4] == 128 && wnow[5] == 128)) { + printf("dtphoto filtertest: gamut warning changed the neutral grey FAIL\n"); + bad++; + } + free(wnow); + } + + /* custom 5x5 identity: scale 1, offset 0 and a single + * 1 in the middle must give the picture back */ + { + static const double ident25[25] = { + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0 + }; + size_t i3s; + + FT_LOAD(); OpCustom(ident25, 1.0, 0.0); FT_GET(); + for (i3s = 0; i3s < (size_t) n3; i3s++) + if (now[i3s] != ident[i3s]) { + printf("dtphoto filtertest: custom identity changed a pixel (%d want %d) FAIL\n", + now[i3s], ident[i3s]); + bad++; + break; + } + free(now); now = NULL; + } + + /* perspective: at 0% it is the identity; at 50% the + * bottom row keeps its width (t = 1, shrink = 1) and the + * picture is squeezed towards the top, so the top-left + * pixel reads from further inside: (0,0) comes from + * (3,0) at w = 24, k = 0.5. It fills with the picture, + * not with the background -- the mapping is always + * inside when the factor is below 1. */ + { + FT_LOAD(); OpPerspective(0); FT_GET(); + { + size_t i3s; + int same_as_ident = 1; + + for (i3s = 0; i3s < (size_t) n3; i3s++) + if (now[i3s] != ident[i3s]) { + same_as_ident = 0; + break; + } + if (!same_as_ident) { + printf("dtphoto filtertest: perspective 0 changed the picture FAIL\n"); + bad++; + } + } + free(now); now = NULL; + + FT_LOAD(); OpPerspective(50); FT_GET(); + { + /* w/2 + (0 - w/2) * 0.75 = w/8, here 3 */ + int src = (0 * w + (w / 2 - (w / 2) * 3 / 4)) * 3; + int top = 0; + size_t i3s; + int bottom_same = 1; + + if (now[top] != ident[src] || + now[top + 1] != ident[src + 1] || + now[top + 2] != ident[src + 2]) { + printf("dtphoto filtertest: perspective 50 top-left is %d,%d,%d, want the squeezed source %d,%d,%d FAIL\n", + now[top], now[top + 1], now[top + 2], + ident[src], ident[src + 1], + ident[src + 2]); + bad++; + } + for (i3s = (size_t) (h - 1) * w * 3; + i3s < (size_t) n3; i3s++) + if (now[i3s] != ident[i3s]) { + bottom_same = 0; + break; + } + if (!bottom_same) { + printf("dtphoto filtertest: perspective 50 moved the full-width bottom row FAIL\n"); + bad++; + } + } + free(now); now = NULL; + } + + /* affine: a 90 degree rotation of a square picture is a + * permutation of its pixels -- the sum and the square + * sum of the channels must not change, and the top-left + * becomes the bottom-left (inverse map) */ + { + double rot[6]; + unsigned long sumb = 0, sumn = 0, sqb = 0, sqn = 0; + + rot[0] = 0; rot[1] = -1; + rot[2] = 1; rot[3] = 0; + rot[4] = 0; rot[5] = 0; + FT_LOAD(); OpAffine(rot); 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: affine rotate is not a permutation FAIL\n"); + bad++; + } + free(now); now = NULL; + + /* and the identity matrix gives the picture back */ + rot[0] = 1; rot[1] = 0; + rot[2] = 0; rot[3] = 1; + FT_LOAD(); OpAffine(rot); FT_GET(); + { + size_t i3s; + int same_as_ident = 1; + + for (i3s = 0; i3s < (size_t) n3; i3s++) + if (now[i3s] != ident[i3s]) { + same_as_ident = 0; + break; + } + if (!same_as_ident) { + printf("dtphoto filtertest: affine identity changed the picture FAIL\n"); + bad++; + } + } + free(now); now = NULL; + } + + /* drop shadow: the background band above the red block + * darkens, the block itself keeps its colour (the + * picture wins over its shadow) */ + { + int block = (12 * w + 12) * 3; + + FT_LOAD(); OpLayerEffect(0, 2, 100, 2, 2); FT_GET(); + if (now[block] != ident[block] || + now[block + 1] != ident[block + 1] || + now[block + 2] != ident[block + 2]) { + printf("dtphoto filtertest: drop shadow painted over the picture FAIL\n"); + bad++; + } + free(now); now = NULL; + } + free(ident); } free(base);