Delphi

ParallelFor

出来ましたよと. ブロック内の計算量が少ない場合、ループの中で関数コールするオーバーヘッドが大きくなるので、2引数の無名関数にも対応. unit ParallelUtils; interface uses Windows, SysUtils, Forms; procedure ParallelFor(Start, Stop: Integer; Blo…

GetNumberOfProcessors

そろそろ並列プログラミングの世界へってことで準備体操. function GetNumberOfProcessors(): Integer; var SystemInfo: TSystemInfo; begin GetSystemInfo(SystemInfo); Result := SystemInfo.dwNumberOfProcessors; end;

TRange

Python の yield が恋しい. unit MyUtils.Range; interface uses Generics.Collections; type TRange = record strict private FStartIndex: Integer; FEndIndex: Integer; public constructor Create(StartIndex, EndIndex: Integer); type TEnumerator = c…

PChar + Char の書き換え

Delphi 2009 では理由不明ながら PChar + Char が ShortString になる?ようだ. 更に何かまずいらしく、それを文字列変数に突っ込んで参照するとアクセスバイオレーションが起きる. (バグ???) 警告もこんな感じで出る. [DCC 警告] main.pas(33): W1057 文字列…

Char in CharSet の書き換え

Delphi 2009 では string が UnicodeString になった関係で Ch in ['0' .. '9', '.'] みたいに書くと下記のような警告が出る. [DCC 警告] main.pas(391): W1050 set 式で WideChar がバイト char に縮小されました。'CharInSet' 関数を 'SysUtils' ユニット…

文字列の SJIS での保存

Delphi 2009 では string が UnicodeString になった関係で Stream.WriteBuffer(S[1], Length(S)) ではおかしくなる. TBytes (array of Byte) に変換してから書き込む必要がある. var Stream: TStream; Buffer: TBytes; begin Stream := TFileStream.Create(…

PasJPEG で非プログレ時にもハフマン最適化する & サブサンプリングOFF

こっちも聞かれた. PasJPEG の1.1をベースにした差分. $ diff -u JPEG.PAS.old JPEG.PAS --- JPEG.PAS.old +++ JPEG.PAS @@ -54,6 +54,7 @@ FPerformance: TJPEGPerformance; FScale: TJPEGScale; FNeedRecalc: Boolean; + FSubsampling: Boolean; procedure…

TPNGImage 1.564 のパレット処理の不具合の暫定対処

メールで聞かれて需要があるのかなと思ったので $ diff -u pngimage.pas.old pngimage.pas --- pngimage.pas.old +++ pngimage.pas @@ -5196,6 +5196,7 @@ begin {Copies the handle using CopyImage API} TBitmap(Dest).PixelFormat := DetectPixelFormat; …