임베디드 프로그래밍  

         
전체 기타 | WinCE | Delphi | VisualC | ARM | Media | SE | 마리오네트 | Java | wdm | JTAG | 영상처리 | 인증 | 질문/답변 | H/W | 알고리즘 | Platform | .net | VB | PPC | Network | android | QT | WWW | Linux |
[매직포토스] DIB 사용 예제
하창호02-05 03:05 | HIT : 5,093
unit Image;

interface

uses Windows, SysUtils, Graphics;

type
  Bitmap = class
  private
    Bits, C1Bits, C2Bits, C3Bits: PByteArray; //RBits, GBits, BBits: PByteArray;
  public
    BPP: Byte;
    Width, Height, BitsSize: DWord;
    procedure SetBits(DIBits: PByteArray);
    function GetBits: PByteArray;
    function GetC1Bits: PByteArray;
    function GetC2Bits: PByteArray;
    function GetC3Bits: PByteArray;
    procedure RGBToBits(Channel: Byte);
    procedure BitsToRGB;
    procedure LoadRGBImage(TempBitmap: TBitmap; Channel: Byte);
    procedure LoadBitsImage(TempBitmap: TBitmap);
    constructor Create(biBitCount: Byte; biWidth, biHeight, biSizeImage: DWord; biBits: PByteArray);
end;

implementation

constructor Bitmap.Create(biBitCount: Byte; biWidth, biHeight, biSizeImage: DWord; biBits: PByteArray);
begin
  inherited Create;
  BPP := biBitCount;
  Width := biWidth;
  Height := biHeight;
  BitsSize := biSizeImage;
  SetBits(biBits);
end;

procedure Bitmap.SetBits(DIBits: PByteArray);
var
  i: Integer;
begin
  if DIBits = Nil then Exit;

  i := 0;

  if not (Bits = Nil) then FreeMem(Bits);

  GetMem(Bits, BitsSize);

  while i < BitsSize do
  begin
    Bits[i] := DIBits[i];
    inc(i);
  end;

  BitsToRGB;
end;

function Bitmap.GetBits: PByteArray;
begin
  GetBits := Bits;
end;

function Bitmap.GetC1Bits: PByteArray;
begin
  GetC1Bits := C1Bits;
end;

function Bitmap.GetC2Bits: PByteArray;
begin
  GetC2Bits := C2Bits;
end;

function Bitmap.GetC3Bits: PByteArray;
begin
  GetC3Bits := C3Bits;
end;

procedure Bitmap.RGBToBits(Channel: Byte);
var
  i, j: Integer;
begin
  if C1Bits = Nil then Exit;
  if C2Bits = Nil then Exit;
  if C3Bits = Nil then Exit;

  i := 0;
  j := 0;

  if not (Bits = Nil) then FreeMem(Bits);

  GetMem(Bits, BitsSize);

  while BitsSize > i  do
  begin
    if ((Channel = 0) or (Channel = 3)) then Bits[i] := C3Bits[j]
    else if ((Channel = 4) or (Channel = 7)) then Bits[i] := 255 - C3Bits[j]
    else Bits[i] := 0;
    if ((Channel = 0) or (Channel = 2)) then Bits[i+1] := C2Bits[j]
    else if ((Channel = 4) or (Channel = 6)) then Bits[i+1] := 255 - C2Bits[j]
    else Bits[i+1] := 0;
    if ((Channel = 0) or (Channel = 1)) then Bits[i+2] := C1Bits[j]
    else if ((Channel = 4) or (Channel = 5)) then Bits[i+2] := 255 - C1Bits[j]
    else Bits[i+2] := 0;
    inc(i,3);
    inc(j);
  end;
end;


procedure Bitmap.BitsToRGB;
var
  i, j: Integer;
begin
  if Bits = Nil then Exit;

  i := 0;
  j := 0;

  if not (C1Bits = Nil) then FreeMem(C1Bits);
  if not (C2Bits = Nil) then FreeMem(C2Bits);
  if not (C3Bits = Nil) then FreeMem(C3Bits);

  GetMem(C1Bits, BitsSize div 3);
  GetMem(C2Bits, BitsSize div 3);
  GetMem(C3Bits, BitsSize div 3);

  while BitsSize > i  do
  begin
    C3Bits[j] := Bits[i];
    C2Bits[j] := Bits[i+1];
    C1Bits[j] := Bits[i+2];
    inc(i,3);
    inc(j);
  end;
end;

procedure Bitmap.LoadRGBImage(TempBitmap: TBitmap; Channel: Byte);
var
  BitsInfo: PBitmapInfo;
begin
  if C1Bits = Nil then Exit;
  if C2Bits = Nil then Exit;
  if C3Bits = Nil then Exit;

  TempBitmap.Height := Height;
  TempBitmap.Width := Width;
  GetMem(BitsInfo, 40);

  With BitsInfo^.bmiHeader do
  begin
    BitsInfo^.bmiHeader.biSize := 40;
    biWidth := Width;
    biHeight := Height;
    biPlanes := 1;
    biBitCount := BPP;
    biCompression := 0;
    biSizeImage := BitsSize;
    biXPelsPerMeter := 0;
    biYPelsPerMeter := 0;
    biClrUsed := 0;
    biClrImportant := 0;
  end;

  RGBToBits(Channel);

  SetDIBits(TempBitmap.Canvas.Handle
           ,TempBitmap.Handle
           ,0
           ,Height
           ,Bits
           ,BitsInfo^
           ,DIB_RGB_COLORS);
  FreeMem(BitsInfo);
end;

procedure Bitmap.LoadBitsImage(TempBitmap: TBitmap);
var
  BitsSize: Integer;
  BitsInfo: PBitmapInfo;
begin
  if Bits = Nil then Exit;

  TempBitmap.Height := Height;
  TempBitmap.Width := Width;
  BitsSize := Height * Width * 3;
  GetMem(BitsInfo, 40);

  With BitsInfo^.bmiHeader do
  begin
    BitsInfo^.bmiHeader.biSize := 40;
    biWidth := Width;
    biHeight := Height;
    biPlanes := 1;
    biBitCount := BPP;
    biCompression := 0;
    biSizeImage := BitsSize;
    biXPelsPerMeter := 0;
    biYPelsPerMeter := 0;
    biClrUsed := 0;
    biClrImportant := 0;
  end;

  SetDIBits(TempBitmap.Canvas.Handle
           ,TempBitmap.Handle
           ,0
           ,Height
           ,Bits
           ,BitsInfo^
           ,DIB_RGB_COLORS);
  FreeMem(BitsInfo);
end;

end.


11  Delphi :: 동적 Database 연결과 동적 Table 생성 예제    하창호 2008·04·24 5501
10  Delphi :: MSSQL 2005 와 연동시 ntwdblib.DLL 에러에...    하창호 2008·04·24 5871
9  Delphi :: MS SQL Free 2005 Download    하창호 2008·04·23 3624
8  Delphi :: SQL DDI 문중 CREATE TABLE 예제  …1  하창호 2008·02·29 3383
7  Delphi :: 증권 관련 업체코드 검색 및 파일 로딩 예제    하창호 2005·05·02 4383
 Delphi :: [매직포토스] DIB 사용 예제    하창호 2005·02·05 5093
5  Delphi :: AssignFile, OpenDialog, Readln, Clo...    하창호 2004·03·24 5047
4  Delphi :: Auto Keyboard & Auto Mouse  …1  하창호 2004·03·18 4953
3  Delphi :: Little Endian과 Big Endian 간의 변환 함...  …2  하창호 2004·03·18 7145
2  Delphi :: idHttp Control 사용시 403 Forbidden er...  …2  하창호 2004·03·08 7813
1  Delphi :: [URL] Internet Direct (Indy) Open S...    하창호 2004·02·10 3539
1
   
Copyright 1999-2018 Zeroboard / skin by GGAMBO
....