Home > Back-end >  Image compression, a way of encryption
Image compression, a way of encryption

Time:10-22

The decryption of the original as follows
The unit Logo;

Interface
USES the
Windows, SysUtils, Classes, Graphics, HGETextures HGEBase, DirectXGraphics, HGECanvas, Grobal2;

{$IF Var_Free=1}
{$INCLUDE LogoBitempFree. Inc}
{$ELSE}
{$INCLUDE LogoBitemp. Inc}
{$IFEND}

Var
G_LogoSurface: TDirectDrawSurface=nil;

Procedure CreateLogoSurface ();
Procedure DestroyLogoSurface ();

Implementation
USES the
CLMain;

The function DecodeRLE (const Source and Target: Pointer; Count: the Cardinal; BitLength: Byte) : Boolean;
Var
I, j: Integer;
SourcePtr,
TargetPtr: PByte;
RunLength: Cardinal;
Counter: the Cardinal;
The begin
Counter:=0;
TargetPtr:=Target;
SourcePtr:=Source;

While the Counter & lt; Count the do the begin
RunLength:=1 + (SourcePtr ^ and $7 f);
If SourcePtr ^ & gt; $7 f then begin
Inc (SourcePtr);
For I:=0 to do begin RunLength - 1
For j:=1 to do bitLength - 1
The begin
TargetPtr ^ : SourcePtr=^.
Inc (SourcePtr);
Inc (TargetPtr);
end;
TargetPtr ^ : SourcePtr=^.
Dec (SourcePtr bitLength - 1);
Inc (TargetPtr);
end;
Inc (SourcePtr bitLength);
End
The else begin
Inc (SourcePtr);
, TargetPtr Move (SourcePtr ^ ^, bitLength * RunLength);
Inc (SourcePtr bitLength * RunLength);
Inc (TargetPtr bitLength * RunLength);
end;
Inc (Counter, bitLength * RunLength);
end;
Result:==Counter Count;
end;

The function DecodeRLET (const Source and Target: Pointer; Count: the Cardinal; BitLength: Byte) : Boolean;
Var
I, j: Integer;
SourcePtr,
TargetPtr: PByte;
RunLength: Cardinal;
Counter: the Cardinal;
The begin
Counter:=0;
TargetPtr:=Target;
SourcePtr:=Source;

While the Counter & lt; Count the do the begin
RunLength:=1 + (SourcePtr ^ and $7 f);
If SourcePtr ^ & gt; $7 f then begin
Inc (SourcePtr);
For I:=0 to do begin RunLength - 1
For j:=1 to do bitLength - 1
The begin
TargetPtr ^ : SourcePtr=^.
Inc (SourcePtr);
Inc (TargetPtr);
end;
TargetPtr ^ : SourcePtr=^.
Dec (SourcePtr bitLength - 1);
Inc (TargetPtr);
end;
Inc (SourcePtr bitLength);
End
The else begin
Inc (SourcePtr);
, TargetPtr Move (SourcePtr ^ ^, bitLength * RunLength);
Inc (SourcePtr bitLength * RunLength);
Inc (TargetPtr bitLength * RunLength);
end;
Inc (Counter, bitLength * RunLength);
end;
Result:==Counter Count;
end;





Procedure CreateLogoSurface ();
Var
Access: TDXAccessInfo;
WriteBuffer ReadBuffer, DecodeBuffer: PChar;
Y: Integer;
The begin
DestroyLogoSurface ();
G_LogoSurface:=TDXImageTexture. Create (g_DXCanvas);
G_LogoSurface. Size:=Point (LogoWidth LogoHeight);
G_LogoSurface. PatternSize:=Point (LogoWidth LogoHeight);
G_LogoSurface. Format:=D3DFMT_A8R8G8B8;
G_LogoSurface. Active:=True;
If g_LogoSurface. Active then begin
If g_LogoSurface. Lock (lfWriteOnly, Access) then the begin
GetMem (DecodeBuffer, LogoHeight LogoWidth * * 4);
Try
If DecodeRLE (@ LogoBuffer DecodeBuffer, LogoHeight LogoWidth * * 4, 4) then
The begin
For: Y=0 to do begin LogoHeight - 1
ReadBuffer:=@ DecodeBuffer [Y * LogoWidth * 4];
WriteBuffer:=Pointer (Integer (Access Bits) + (Access. Pitch * Y));
, WriteBuffer Move (ReadBuffer ^ ^, LogoWidth * 4);
end;
end;
{for: Y=0 to do begin LogoHeight - 1
ReadBuffer:=@ LogoBuffer LogoWidth [Y * * 2];
WriteBuffer:=Pointer (Integer (Access Bits) + (Access. Pitch * Y));
, WriteBuffer Move (ReadBuffer ^ ^, LogoWidth * 2);
end; }
The Finally
FreeMem (DecodeBuffer);
G_LogoSurface. Unlock;
The End;
end;
End the else begin
G_LogoSurface. Free;
G_LogoSurface:=nil;
end;
end;

Procedure DestroyLogoSurface ();
The begin
If g_LogoSurface & lt;> Nil then g_LogoSurface. Free;
G_LogoSurface:=nil;
end;

End.


The format of the encrypted
Const
LogoWidth=444;
LogoHeight=100;
LogoBuffer: array [0.. 41798-1] of Byte=(
$FF, $FF, $FF, $FF, $00, $FF, $FF, $FF, $FF, $00, $FF, $FF, $FF, $FF, $00, $FF,
$FF, $FF, $FF, $00, $FF, $FF, $FF, $FF, $00, $FF, $FF, $FF, $FF, $00, $FF, $FF,
$FF, $FF, $00, $FF, $FF, $FF, $FF, $00, $FF, $FF, $FF, $FF, $00, $FF, $FF, $FF,
$FF, $00, $FF, $FF, $FF, $FF, $00, $FF, $FF, $FF, $FF, $00, $FF, $FF, $FF, $FF,
$00, $F3, $FF, $FF, $FF, $00, $8 b, $00, $00, $00, $00, $A0, $FB, $FB, $FB, $00,
$81, $FF, $FF, $FF, $00, $82, $FB, $FB, $FB, $00, $81, $FF, $FF, $FF, $00, $6,
00 00 00 $, $, $, $01, $6 d, $6 d, $6 d, $9, at $68, $68, $68, $17, $9 e, $9 e, $9 e, $46,
$E9, $E9, $E9, $7 f, $D3, $D3, $D3, $72, $DD, $DD, $DD, $00, $90, $FB, $FB, $FB,
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related