mirror of
https://github.com/moparisthebest/Simba
synced 2024-11-17 23:05:00 -05:00
Added CreateBitmapString which turns a bitmap into a mufasa-bitmapstring ;-). And made the Bufferstring global rather than in DTM only...
git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@460 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
parent
1fb4a6d44a
commit
73a9e15650
@ -20,6 +20,11 @@
|
||||
|
||||
Bitmap.inc for the Mufasa Macro Library
|
||||
}
|
||||
function CreateBitmapString(bmp : integer) : string;
|
||||
begin;
|
||||
result := CurrThread.Client.MBitmaps[bmp].ToString;
|
||||
end;
|
||||
|
||||
function GetMufasaBitmap(bmp : integer): TMufasaBitmap;
|
||||
begin;
|
||||
result := CurrThread.Client.MBitmaps[bmp];
|
||||
|
@ -179,6 +179,7 @@ AddFunction(@MaskFromText, 'function MaskFromText(text, font: String): TMask;');
|
||||
|
||||
{Bitmaps}
|
||||
SetCurrSection('Bitmaps');
|
||||
AddFunction(@CreateBitmapString,'function CreateBitmapString(bmp : integer) : string;');
|
||||
AddFunction(@GetMufasaBitmap,'function GetMufasaBitmap(bmp : integer) : TMufasaBitmap;');
|
||||
AddFunction(@CreateBitmap,'function CreateBitmap(w,h :integer) : integer;');
|
||||
AddFunction(@FreeBitmap,'procedure FreeBitmap(Bmp : integer);');
|
||||
|
@ -81,6 +81,7 @@ type
|
||||
procedure Posterize(Po : integer);overload;
|
||||
function Copy: TMufasaBitmap;
|
||||
function ToTBitmap: TBitmap;
|
||||
function ToString : string;
|
||||
procedure LoadFromTBitmap(bmp: TBitmap);
|
||||
procedure LoadFromRawImage(RawImage: TRawImage);
|
||||
function CreateTMask : TMask;
|
||||
@ -265,6 +266,8 @@ var
|
||||
DestLen : LongWord;
|
||||
Dest,Source : string;
|
||||
DestPoint, Point : PByte;
|
||||
MufRaw : PRGB24;
|
||||
MufDest : PRGB32;
|
||||
|
||||
|
||||
begin
|
||||
@ -272,13 +275,26 @@ begin
|
||||
if (Data <> '') and (Length(Data) <> 6) then
|
||||
begin;
|
||||
Point := Pointer(BmpArray[Result].FData);
|
||||
if Data[1] = 'b' then
|
||||
if (Data[1] = 'b') or (Data[1] = 'm') then
|
||||
begin;
|
||||
Source := Base64DecodeStr(Copy(Data,2,Length(Data) - 1));
|
||||
Destlen := Width * Height * 3;
|
||||
Setlength(Dest,DestLen);
|
||||
if uncompress(PChar(Dest),Destlen,pchar(Source), Length(Source)) = Z_OK then
|
||||
begin;
|
||||
if data[1] = 'm' then //Our encrypted bitmap! Winnor.
|
||||
begin
|
||||
MufRaw:= @Dest[1];
|
||||
MufDest:= PRGB32(Point);
|
||||
for i := width * height - 1 downto 0 do
|
||||
begin
|
||||
MufDest[i].R:= MufRaw[i].R;
|
||||
MufDest[i].G := MufRaw[i].G;
|
||||
MufDest[i].B := MufRaw[i].B;
|
||||
end;
|
||||
end else
|
||||
if Data[1] = 'b'then
|
||||
begin
|
||||
DestPoint := @Dest[1];
|
||||
i := 0;
|
||||
ii := 2;
|
||||
@ -303,6 +319,7 @@ begin
|
||||
Point[2] := DestPoint[2];
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end else if Data[1] = 'z' then
|
||||
begin;
|
||||
Destlen := Width * Height * 3 *2;
|
||||
@ -448,6 +465,31 @@ begin
|
||||
Result.LoadFromRawImage(tr, false);
|
||||
end;
|
||||
|
||||
function TMufasaBitmap.ToString: string;
|
||||
var
|
||||
i : integer;
|
||||
DestLen : longword;
|
||||
DataStr : string;
|
||||
CorrectData : PRGB24;
|
||||
begin
|
||||
SetLength(DataStr,w*h*3);
|
||||
CorrectData:= PRGB24(@DataStr[1]);
|
||||
for i := w*h - 1 downto 0 do
|
||||
begin
|
||||
CorrectData[i].R := FData[i].R;
|
||||
CorrectData[i].G := FData[i].G;
|
||||
CorrectData[i].B := FData[i].B;
|
||||
end;
|
||||
DestLen := BufferLen;
|
||||
if compress(Pchar(BufferString),destlen,PChar(DataStr),w*h*3) = Z_OK then
|
||||
begin;
|
||||
SetLength(DataStr,DestLen);
|
||||
move(bufferstring[0],dataStr[1],DestLen);
|
||||
result := 'm' + Base64EncodeStr(datastr);
|
||||
SetLength(datastr,0);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMufasaBitmap.LoadFromRawImage(RawImage: TRawImage);
|
||||
|
||||
var
|
||||
|
@ -70,10 +70,6 @@ type
|
||||
destructor Destroy; override;
|
||||
private
|
||||
Client: TObject;
|
||||
|
||||
// For decompressing.
|
||||
BufferString: String;
|
||||
|
||||
DTMList: Array Of pDTM;
|
||||
FreeSpots: Array Of Integer;
|
||||
end;
|
||||
@ -85,9 +81,7 @@ uses
|
||||
math // for max
|
||||
;
|
||||
|
||||
type
|
||||
TBufferByteArray = Array[0..524287] of Byte;
|
||||
PBufferByteArray = ^TBufferByteArray;
|
||||
|
||||
|
||||
|
||||
constructor TMDTM.Create(Owner: TObject);
|
||||
@ -97,7 +91,6 @@ begin
|
||||
|
||||
SetLength(DTMList, 0);
|
||||
SetLength(FreeSpots, 0);
|
||||
SetLength(BufferString, 524288);
|
||||
end;
|
||||
|
||||
{$DEFINE DTM_DEBUG}
|
||||
@ -126,7 +119,6 @@ begin
|
||||
end;
|
||||
SetLength(DTMList, 0);
|
||||
SetLength(FreeSpots, 0);
|
||||
SetLength(BufferString, 0);
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
@ -170,8 +162,8 @@ begin
|
||||
SetLength(Source,ii);
|
||||
for i := 1 to ii do
|
||||
Source[i] := Chr(HexToInt(S[i * 2 - 1] + S[i * 2]));
|
||||
DestLen := Length(Self.BufferString);
|
||||
if uncompress(PChar(Self.Bufferstring),Destlen,pchar(Source), ii) = Z_OK then
|
||||
DestLen := BufferLen;
|
||||
if uncompress(Bufferstring,Destlen,pchar(Source), ii) = Z_OK then
|
||||
begin;
|
||||
if (Destlen mod 36) > 0 then
|
||||
begin;
|
||||
@ -185,7 +177,7 @@ begin
|
||||
SetLength(Result.asz,DestLen);
|
||||
SetLength(Result.ash,DestLen);
|
||||
SetLength(Result.bp,DestLen);
|
||||
b := @Self.Bufferstring[1];
|
||||
b := PBufferByteArray(BufferString);
|
||||
for i := 0 to DestLen - 1 do
|
||||
begin;
|
||||
c := i * 36;
|
||||
|
@ -43,7 +43,10 @@ operator + (PT1,PT2 : TPoint) : TPoint;
|
||||
operator - (PT1,PT2 : TPoint) : TPoint;
|
||||
|
||||
type
|
||||
|
||||
TRGB24 = packed record
|
||||
B, G, R : byte;
|
||||
end;
|
||||
PRGB24 = ^TRGB24;
|
||||
TRGB32 = packed record
|
||||
B, G, R, A: Byte;
|
||||
end;
|
||||
@ -120,8 +123,13 @@ type
|
||||
Str : string;
|
||||
Key : byte;
|
||||
end;
|
||||
type
|
||||
TBufferByteArray = Array[0..524287] of Byte;
|
||||
PBufferByteArray = ^TBufferByteArray;
|
||||
|
||||
var
|
||||
BufferString : PChar;
|
||||
BufferLen : LongWord;
|
||||
VirtualKeys : array[0..173] of VirtualKeyInfo = (
|
||||
(str :'UNKNOWN'; key : 0),
|
||||
(str :'LBUTTON'; key : 1),
|
||||
@ -313,5 +321,11 @@ begin
|
||||
Result.y := Pt1.y - PT2.y;
|
||||
end;
|
||||
|
||||
initialization
|
||||
BufferString := StrAlloc(524288);
|
||||
BufferLen := 524288;
|
||||
finalization
|
||||
StrDispose(bufferstring);
|
||||
|
||||
end.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user