FineView Software Labs


雑技

コード断片、備忘録、etc..

Paint Shop Pro のスクリーンショット
psp_clip.png

□ PSPの画面を構成するコード Part I
// 透過部分のクロスストライプを描くコード
procedure CreateCrossStripesPSP(SrcBmp: TBitmap; Width, Height: Integer);
var
  i,j: Integer;
  Row: PByte;
begin
  SrcBmp.PixelFormat := pf24bit;
  SrcBmp.Width := Width;
  SrcBmp.Height := Height;

  for i:=0 to SrcBmp.Height-1 do
  begin
    Row := SrcBmp.ScanLine[i];
    for j:=0 to SrcBmp.Width-1 do
    begin
      if ((i xor j) and 16) = 0 then
      begin
        Row^ := 253; Inc(Row);
        Row^ := 253; Inc(Row);
        Row^ := 253; Inc(Row);
      end else begin
        Row^ := 203; Inc(Row);
        Row^ := 204; Inc(Row);
        Row^ := 203; Inc(Row);
      end;
    end;
  end;
end;


□ PSPの画面を構成するコード Part II
// 背景の外側(編集対称でないエリア)を描くコード
procedure CreateDiagCrossPSP(SrcBmp: TBitmap; Width, Height: Integer);
var
  i,j: Integer;
  Row: PByte;
begin
  SrcBmp.PixelFormat := pf24bit;
  SrcBmp.Width := Width;
  SrcBmp.Height := Height;

  for i:=0 to SrcBmp.Height-1 do
  begin
    Row := SrcBmp.ScanLine[i];
    for j:=0 to SrcBmp.Width-1 do
    begin
      if ((i + j) and $7=5) or ((i xor j) and $7=0) then
      begin
        Row^ := $C0; Inc(Row);
        Row^ := $C0; Inc(Row);
        Row^ := $C0; Inc(Row);
      end else begin
        Row^ := $FF; Inc(Row);
        Row^ := $FF; Inc(Row);
        Row^ := $FF; Inc(Row);
      end;
    end;
  end;
end;


□ DCT関連の処理
// u と v を掛け合わせた値を求める処理
const
  uv_tbl: array[0..2] of double=(0.500000000, 0.707106781, 1.000000000);
var
  uv: double;
begin
  uv := uv_tbl[ ((u shr 31) or (-u shr 31)) + ((v shr 31) or (-v shr 31)) ];
end;


□ サムネイル表示部などに収まりきらない長いファイル名を切り詰めるコード
// 長いファイル名を短く切り詰める関数
// ※ パスを含む場合に短く切り詰める場合は、MinimizeName()を使用すること
function MinceJPStr(filename: string; Canvas: TCanvas;
 canvas_width: Integer): string;
var
  org_filename: string;
  dot_width: Integer;
  len: Integer;
  cutpos: Integer;
begin
  Result := filename;

  if Canvas.TextWidth(filename) <= canvas_width then
    exit;

  org_filename := filename;

  dot_width := Canvas.TextWidth('...');

  while dot_width + Canvas.TextWidth(filename) > canvas_width do
  begin
    len := Length(filename);
    cutpos := len div 2;
    // 日本語の文字化け防止
    // マルチバイトの1バイト目、2バイト目をチェック
    case ByteType(filename, cutpos) of
      mbSingleByte:
        Delete(filename, cutpos, 1);
      mbLeadByte:
        Delete(filename, cutpos, 2);
      mbTrailByte:
        begin
          Dec(cutpos);
          Delete(filename, cutpos, 2);
        end;
    end;
  end;

  Result := Copy(filename, 1, cutpos-1) + '...' + Copy(filename,
 cutpos, Length(filename));
end;

□ カーソルキーのホットスポットを指定する

例えばホットスポット(X,Y)=(8,8)にしたい場合は、 バイナリーエディタでアドレス0x0Aと0x0Cを8にする。