All pastes #17482 Raw Edit

Stuff

public text v1 · immutable
#17482 ·published 2005-07-11 20:49 UTC
rendered paste body
unit bmpBitmapRec;

interface

uses
  SysUtils, /// not needed
  Graphics,
  bitmapUtils;

type
  PBitmapDataRec = ^TBitmapDataRec;
  TBitmapDataRec = record
    width       : Integer;
    height      : Integer;
    bitdepth    : Integer;
    memorybase  : Pointer;
    rowoffset   : Integer;
  end;

  function bmprec_make(src : TBitmap): PBitmapDataRec; overload;
  procedure bmprec_make(src : TBitmap; datarec : PBitmapDataRec); overload;
  procedure bmprec_dispose(datarec : PBitmapDataRec);
  procedure bmprec_clear(datarec : PBitmapDataRec);
  function bmprec_scanline(datarec : PBitmapDataRec; y : Integer): Pointer; overload;
  function bmprec_scanline(datarec : PBitmapDataRec; x, y : Integer): Pointer; overload;

implementation

procedure bmprec_make(src : TBitmap; datarec : PBitmapDataRec); overload;
begin
  datarec.width := src.Width;
  datarec.height := src.Height;
  datarec.bitdepth := bmpPixelFormatToBitDepth(src.PixelFormat);

  if datarec.height = 0 then
    begin
      datarec.memorybase := nil;
      datarec.rowoffset := 0
    end
  else
    begin
      datarec.memorybase := src.Scanline[0];
      datarec.rowoffset := Integer(src.Scanline[1]) - Integer(src.Scanline[0]);
    end;
end;

function bmprec_make(src : TBitmap): PBitmapDataRec; overload;
begin
  GetMem(result, SizeOf(TBitmapDataRec));
  bmprec_make(src, result);
end;

procedure bmprec_dispose(datarec : PBitmapDataRec);
begin
  FreeMem(datarec, SizeOf(TBitmapDataRec));
end;

procedure bmprec_clear(datarec : PBitmapDataRec);
begin
  FillChar(datarec^, SizeOf(TBitmapDataRec), 0);
end;

function bmprec_scanline(datarec : PBitmapDataRec; y : Integer): Pointer; overload;
begin
  result := Pointer(Integer(datarec.memorybase) + y * datarec.rowoffset);
end;

function bmprec_scanline(datarec : PBitmapDataRec; x, y : Integer): Pointer; overload;
begin
  result := Pointer(Integer(datarec.memorybase) + y * datarec.rowoffset + x * (datarec.bitdepth shr 3));
end;

end.