diff --git a/trunk/Units/MMLAddon/PSInc/Wrappers/bitmap.inc b/trunk/Units/MMLAddon/PSInc/Wrappers/bitmap.inc index 3f8336b..24ef421 100644 --- a/trunk/Units/MMLAddon/PSInc/Wrappers/bitmap.inc +++ b/trunk/Units/MMLAddon/PSInc/Wrappers/bitmap.inc @@ -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]; diff --git a/trunk/Units/MMLAddon/PSInc/psexportedmethods.inc b/trunk/Units/MMLAddon/PSInc/psexportedmethods.inc index 247d07e..b376ccf 100644 --- a/trunk/Units/MMLAddon/PSInc/psexportedmethods.inc +++ b/trunk/Units/MMLAddon/PSInc/psexportedmethods.inc @@ -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);'); diff --git a/trunk/Units/MMLCore/bitmaps.pas b/trunk/Units/MMLCore/bitmaps.pas index bed86bf..93b1c50 100644 --- a/trunk/Units/MMLCore/bitmaps.pas +++ b/trunk/Units/MMLCore/bitmaps.pas @@ -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,35 +275,49 @@ 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; - DestPoint := @Dest[1]; - i := 0; - ii := 2; - Dec(DestLen); - if DestLen > 2 then - begin; - while (ii < DestLen) do - Begin; - Point[i]:= DestPoint[ii+2]; - Point[i+1]:= DestPoint[ii+1]; - Point[i+2]:= DestPoint[ii]; - ii := ii + 3; - i := i + 4; + 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; + Dec(DestLen); + if DestLen > 2 then + begin; + while (ii < DestLen) do + Begin; + Point[i]:= DestPoint[ii+2]; + Point[i+1]:= DestPoint[ii+1]; + Point[i+2]:= DestPoint[ii]; + ii := ii + 3; + i := i + 4; + end; + Point[i] := DestPoint[1]; + Point[i+1] := DestPoint[0]; + Point[i+2] := DestPoint[ii]; + end else if (Width = 1) and (Height =1 ) then + begin; + Point[0] := DestPoint[1]; + Point[1] := DestPoint[0]; + Point[2] := DestPoint[2]; end; - Point[i] := DestPoint[1]; - Point[i+1] := DestPoint[0]; - Point[i+2] := DestPoint[ii]; - end else if (Width = 1) and (Height =1 ) then - begin; - Point[0] := DestPoint[1]; - Point[1] := DestPoint[0]; - Point[2] := DestPoint[2]; end; end; end else if Data[1] = 'z' then @@ -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 diff --git a/trunk/Units/MMLCore/dtm.pas b/trunk/Units/MMLCore/dtm.pas index 19f3128..23ff406 100644 --- a/trunk/Units/MMLCore/dtm.pas +++ b/trunk/Units/MMLCore/dtm.pas @@ -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; diff --git a/trunk/Units/MMLCore/mufasatypes.pas b/trunk/Units/MMLCore/mufasatypes.pas index 1e455e8..fc75228 100644 --- a/trunk/Units/MMLCore/mufasatypes.pas +++ b/trunk/Units/MMLCore/mufasatypes.pas @@ -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.