Hi meine Lieben.
Ich will ein Tool schreiben mit welchen man Steriogramme erstellen kann.
Steriogramme sind jene Bilder in welche man 3D Bilder sehen kann, täuschung des Auges.
Ich hab da einen Sorcecode gefunden der das macht, aber leider ist dieser in PHP geschrieben.
Leider kann ich kein PHP.
Könnte mir wer von euch diesen Codeteil übersetzen in Pascal ?
Delphi-Quellcode:
class StereoImage
{
// Bild in GD einlesen
function getImage($path)
{
if (ereg(".gif\$", $path)) $image=imageCreateFromGIF($path); else $image=imageCreateFromJPEG($path);
return($image);
}
// Stereogramm aus zwei GD- Bildern erzeugen
function createStereo($tileimage, $pictureimage)
{
// Tile einlesen
$tilewidth=imageSX($tileimage); if (!$tilewidth) return(false);
$tileheight=imageSY($tileimage);
for ($y=0;$y<$tileheight;$y+ + )
for ($x=0;$x<$tilewidth;$x+ + )
{
$color=imageColorAt($tileimage, $x, $y); if (!is_array($color)) $color=imageColorsForIndex($tileimage, $color);
$color=chr($color[red]).chr($color[green]).chr($color[blue]);
$tile[$y][$x]=$color;
}
// Tiefenbild einlesen
$mincolor=256;
$picturewidth=imageSX($pictureimage); if (!$picturewidth) return(false);
$pictureheight=imageSY($pictureimage);
for ($y=0;$y<$pictureheight;$y+ + )
for ($x=0;$x<$picturewidth;$x+ + )
{
$color=imageColorAt($pictureimage, $x, $y); if (!is_array($color)) $color=imageColorsForIndex($pictureimage, $color);
$color=floor(($color[red]+ $color[green]+ $color[blue])/3);
$mincolor=min($mincolor, $color);
$maxcolor=max($maxcolor, $color);
$picture[$y][$x]=$color;
}
// Höhenfaktor/- verschiebung berechnen
$space=$maxcolor- $mincolor+ 1;
$elevation=$mincolor;
$factor=$space/($tilewidth*0.1); // Max. 10% Verzerrung
// Stereobild erzeugen
$picturewidth+ =$tilewidth;
$stereoimage=imageCreateTrueColor($picturewidth, $pictureheight);
for ($x=0;$x<$picturewidth;$x+ + )
for ($y=0;$y<$pictureheight;$y+ + )
{
// Auf Tile mappen
$sx=$x % $tilewidth;
$sy=$y % $tileheight;
// Höhendiff ausrechnen
$rx=$x- $tilewidth;
$diff=floor(($picture[$y][$rx<0?0:$rx]- $elevation)/$factor)+ $diffs[$y][$rx- $tilewidth];
$diffs[$y][$x- $tilewidth]=$diff;
// Höhendiff zum X addieren und clippen
$sx+ =$diff;
if ($sx>=$tilewidth) $sx- =$tilewidth; else if ($sx<0) $sx+ =$tilewidth;
// Pixel kopieren
$sourcecolor=$tile[$sy][$sx];
$color=imageColorAllocate($stereoimage, ord($sourcecolor[0]), ord($sourcecolor[1]), ord($sourcecolor[2]));
imageSetPixel($stereoimage, $x, $y, $color);
}
// Sterebild zurückgeben
return($stereoimage);
}
}
Beschreibung zum Code, und was er machen soll:
BESCHREIBUNG
Ich bedanke mich im Voraus
lg
bundy