SRL Archive - OSR Help

Changing DTM back to a string


Chris

2012-12-19 05:56:48

Hello SRL!
I need your help, I'm trying to do "StringFromDTM();" but that function doesn't exist and I don't think it is possible to create one (at least not in a script).
Does anyone know how to do this? Otherwise could it be build into Simba?

This is my script:

program DTMTool;

var
BMP, DTM: Integer;

procedure setBMPString;
begin
BMP := BitmapFromString(23, 28, 'meJyN1dtrHFUYAPChaZJmLQFLjL' +
'tsSKxasUXr7aEVQ63GoE2TTZPNXHezs3M7M7Nz3Z3Z2fs1F7dtwIq' +
'KhYBQ0HffBf+APlSUIIVWa33wQUSpIio+6De7oCdvWQ7DgZnvt+e7' +
'MEPyGiUYVDZHZhAl5GjRoCWTUxwWORxy05qb1vO84fNmUbADwS2Jb' +
'kXx6ihoquWWVmnr1Y5e74JAiyYrWyCwis0pdgo5fM5L64V0rpAxB+' +
'ElwS5LbkUu1JDf0Esdo9LVYVW7VuNtp9NjRIuRQoSRLQ45KRWEomi' +
'V4ZqBA1hBKDhlOIDs1fVSCxWbKGjp5bZR6+ZqG06r53aucLIDi5Es' +
'TrZZxSWFEi3WGbG7xm8mM9tJ/spKeudS6t0E+16C+XCJ2V2kPrpI3' +
'bhAfkxK13P1DafdK2zsgMACIkMizplXPyGIfw64Tj73pd/dyXevFr' +
'feIaGkvEby+mpaeenl3YMjT5/e87o7dvMyOK+8foH4/8ccHDlx6mu' +
'zvm03e277yrn5RQxZ3f/krwRxmyC+IohbBHFzZPSLaPx+fPqbqeN3' +
'Z564c/b850Zty21dBmR2bgFDEvuRT7FbxPTjJ1S/pQVtrdTRgg4IR' +
'nXThhY3e+fmE9iDCzgyPPLZxKOxydhUbGomPn38hTOzyKurxabiNa' +
'DRueomIGZtK1fdeG1hFUPewJHY1O2sWRLCmQnEcNiqSqEBAswM8pt' +
'6uWvWts3qplpqzy0kMeQ8jkxM3ltme8vM1WXmWoJ5f5H6YGHtejgn' +
'5I2V9K5e6hqVTUgNFVtzC2sYMnvA1kTj30FZwFGLbdlrzF0kMeTsA' +
'ZHJ2Peo2FaDjhqE1/klGkNePCAyMfkD8lsDB87z5gqHIaf3P/xnf0' +
'72YE6Ghm49Er0/GbsXjd+Nz9x55vmbyGsqfhP5/ZMssxhyaj+y99+' +
'N8YePZa2qYNd4swwtk926nK/LBUBaatB9a3UdQ57CkUOHvu3PSTwa' +
'n37y5LMQ3hcq2XATOkoeOt4CZ5HMYshjOBI5+hMj2Wndzxil9VwAa' +
'+BkYG/Ae6YqOlVUaEKDlmgBQ6ZwZCzyCyVatGSlUAGElOalNH89V+' +
'yzQdaqZO2ynG8gr73ESBgSxZEjYw/gNUVJ8NJzQEhrPoSnQ8qDjES' +
'nLjo1ya1L+UaClTHkGI6MjP7GKnkOFTiUZxSXRXlO9Ti1AJrk1ACB' +
'OsMVnGVWwZBxHDk8/AcjuRm9mFI90MKF8pAaIJlcKSyyXR04l1Iqh' +
'kRwZGjoLwiEXGjRpgSTUeAjUgBkcDyodr/pVcGpraY1DBnZ3+K/GR' +
'kSgRCvH+v2w/tHUlze6HfcqohuPZnRDw8PD4+Mjh6JjEUeIogHI6O' +
'/Q0nHIj8fHf8RBFqGakB3wqT6YB423CA11eMNeFdUkhmDEhxKsMIl' +
'uvDX61pAClaSN0jRZhEEurTkUJCRaNPwaVDcPhVWhgtLHeZF8mZK8' +
'dd4Y2Vdo6U8LblrWRMECIENI7swGynVh0BYFNQHHFRgBmfTvLBKmv' +
'cv5tN+3Q==');
end;

function MakeDTM(BMP: Integer): Integer;
var
DtmMainPoint: TSDTMPointDef;
DtmPoints: array of TSDTMPointDef;
TempTDTM: TSDTM;
TPA: TPointArray;
i, idx, BMPW, BMPH: Integer;
begin
Result := 0;
GetBitmapSize(BMP, BMPW, BMPH);
Writeln('Making DDTM');
idx := SetTargetBitmap(BMP);
if not FindColors(TPA, 255, 0, 0, BMPW - 1, BMPH - 1) then
TerminateScript;
FreeTarget(idx);
FreeBitmap(BMP);

DtmMainPoint.x := TPA[0].x;
DtmMainPoint.y := TPA[0].y;
DtmMainPoint.AreaSize := 1;
DtmMainPoint.AreaShape := 0;
DtmMainPoint.Color := 255;
DtmMainPoint.Tolerance := 0;

SetLength(DtmPoints, Length(TPA));
for i := 1 to High(TPA) do
begin
DtmPoints[i].x := TPA[i].x;
DtmPoints[i].y := TPA[i].y;
DtmPoints[i].AreaSize := 0;
DtmPoints[i].AreaShape := 0;
DtmPoints[i].Color := 255;
DtmPoints[i].Tolerance := 0;
end;

TempTDTM.MainPoint := DtmMainPoint;
TempTDTM.SubPoints := DtmPoints;
Result := AddSDTM(TempTDTM);
end;

begin
SetBMPString;
DTM := MakeDTM(BMP);
// Writeln(StringFromDTM(DTM))?
FreeDTM(DTM);
end.

Thanks for even looking at this thread :D

Rezozo

2012-12-19 06:30:35

Im a bit slow in the morning, but if you have the points, or know where it goes, or have the DTM, then couldn't you just use the tool?

Like give an example of when you would need it.
~Rez

Chris

2012-12-19 06:38:10

From: Rezozo
Im a bit slow in the morning, but if you have the points, or know where it goes, or have the DTM, then couldn't you just use the tool?

Like give an example of when you would need it.
~Rez


Yes. I could save the TPA and use that in my script to assemble the DTM. Though it should be possible to print the DTM as a string imo. (That will be faster in run-time)

KingKong

2012-12-19 06:59:24

dtmtostring?

Chris

2012-12-19 07:05:00

From: KingKong
dtmtostring?


Doesn't exist..

Wardancer

2012-12-19 11:11:06

Is the code for DTMFromString available anywhere? I can't find it, but if it's somewhere out there, it shouldn't be too difficult to just reverse engineer it and write your own DTMToString function.

J J

2012-12-22 14:48:43

Hey Chris,

I did some research and it is possible :) I have never seen someone using it though but it does work.

Example:
program Test;
{$i srl/srl.simba}


function DTMToString(DTM: Integer): String;
begin
Result := GetDTM(DTM).ToString;
writeln('Result: ' + Result);
end;

procedure DTMTest;
var
DTM: Integer;
Test: TMDTM;

begin
DTM := DTMFromString('mWAAAAHicY2FgYOhgZGDIBOKzQDwFiI8Cxb4C8T8gfg3E////R8HogBENgwAAsaUR9g==');
DTMToString(DTM);
FreeDTM(DTM);
end;

begin
SetupSRL;
DTMTest;
end.

After running:
SRL Compiled in 16 msec
Result: mWAAAAHicY2GAgIf///93BdI8UL4BEFsCsRoQA6VQMDpgRMMgAACE7xC7
Successfully executed.

You convert the DTM to a TMDTM. That is a type like a DTM but you can do some fun stuff with it such as converting it to a String.

EDIT: We might have overlooked something in the documents, but I don't think this existed yet. Might be nice to add to SRL.

Chris

2012-12-24 07:54:22

Thanks J J, that's exactly what I need!