Skip to content

Instantly share code, notes, and snippets.

View XProger's full-sized avatar

Timur Gagiev XProger

View GitHub Profile
@XProger
XProger / min_ogl.dpr
Last active June 23, 2022 08:16
Delphi minimal OpenGL application
program min_ogl;
uses
Windows, OpenGL;
var
pfd : TPixelFormatDescriptor;
DC : HDC;
begin
// Creating window
@XProger
XProger / calc.pas
Last active August 29, 2015 14:01
Delphi simple calculator
function Calc(const CalcStr: string): string;
var
v : Variant;
begin
v := CreateOleObject('MSScriptControl.ScriptControl');
v.Language := 'JScript';
Result := v.Eval(CalcStr);
v := Unassigned;
end;
@XProger
XProger / lzo.pas
Created May 23, 2014 09:24
Delphi LZO compress & decompress
function lzo_compress(const Data; Size: LongInt; var CData; var CSize: LongInt; var WorkBuf): LongInt; cdecl;
asm
{$IFDEF WIN32}
jmp lzo_compress + $2F0 + 8 + 3
{$ELSE}
pop ebp
lea eax, @dest + $2F0
jmp eax
@dest:
{$ENDIF}
@XProger
XProger / 24to16.cpp
Last active June 5, 2016 19:48
Fast convert 24-bit color to 16-bit.
// 24 to 16
unsigned short color = (r & 0xF8) << 8 | (g & 0xFC) << 3 | b >> 3;
// 16 to 24
unsigned int color = (c & 0xF800) << 8 | (c & 0x07E0) << 5 | (c & 0x001F) << 3;
@XProger
XProger / sha1.pas
Last active August 29, 2015 14:05
Calculate SHA1 digest of data
type
TSHA1Digest = array [0..4] of LongWord;
TSHA1Block = array [0..63] of Byte;
TSHA1Context = record
State : TSHA1Digest;
Block : TSHA1Block;
Len : Int64;
Pos : LongInt;
end;
@XProger
XProger / md5.pas
Created August 26, 2014 06:08
Calculate MD5 digest of data
type
TMD5Digest = array [0..3] of LongWord;
TMD5Block = array [0..63] of Byte;
TMD5Context = record
State : TMD5Digest;
Block : TMD5Block;
Len : Int64;
Pos : LongInt;
end;
@XProger
XProger / unzip.pas
Last active August 29, 2015 14:05
Inflate zlib & gzip compressed data
unit unzip;
// based on C++ core "tiny inflate" by Joergen Ibsen / Jibz
// http://www.ibsensoftware.com/
interface
type
TByteArray = array [Word] of Byte;
TWordArray = array [Word] of Word;
PByteArray = ^TByteArray;
PWordArray = ^TWordArray;
@XProger
XProger / xml.pas
Created August 26, 2014 06:19
XML parser (one pass, nondestructive, UTF-16)
unit xml;
interface
type
TXMLParam = record
Name : WideString;
Value : WideString;
end;
@XProger
XProger / resample.pas
Created August 26, 2014 06:22
Resample image
procedure Resample(const Data: PByteArray; const Width, Height: LongInt; out OutData: PByteArray; const OutWidth, OutHeight: LongInt);
var
i, j : LongInt;
f : array [0..1] of LongWord;
Row : array [0..1] of PByteArray;
Pix : array [0..3] of PByteArray;
p : array [0..1] of PLongArray;
Step : LongInt;
Buf : PByteArray;
begin
@XProger
XProger / gif.pas
Created August 26, 2014 06:25
Load static GIF image
function LoadGIF(const Stream: TStream; out Data: PByteArray; out Width, Height: LongInt): Boolean;
procedure DecompressLZW(InitCodeSize: Byte; Source, Dest: Pointer; PackedSize, UnpackedSize: LongInt);
const
NoLZWCode = 4096;
var
I: LongInt;
Data, Bits, Code : LongWord;
SourcePtr : ^Byte;
InCode : LongWord;