ColorDeep: TPixelFormat = pf16bit;
procedure ChangeDIBPixelFormat(adib:TDIB;pf:TPixelFormat);
begin
if pf=pf8bit then begin
with aDib.PixelFormat do begin
RBitMask:=$FF0000;
GBitMask:=$00FF00;
BBitMask:=$0000FF;
end;
aDib.BitCount:=8;
end else if pf=pf16bit then begin
with aDib.PixelFormat do begin
RBitMask:=$F800;
GBitMask:=$07E0;
BBitMask:=$001F;
end;
aDib.BitCount:=16;
end else if pf=pf24bit then begin
with aDib.PixelFormat do begin
RBitMask:=$FF0000;
GBitMask:=$00FF00;
BBitMask:=$0000FF;
end;
aDib.BitCount:=24;
end else if pf=pf32Bit then begin
with aDib.PixelFormat do begin
RBitMask:=$FF0000;
GBitMask:=$00FF00;
BBitMask:=$0000FF;
end;
aDib.BitCount:=32;
end;
end;
procedure TWMImages.Initialize;
var
Idxfile: String;
Header :TWMImageHeader;
begin
if not (csDesigning in ComponentState) then begin
if FFileName = '' then begin
raise Exception.Create ('FileName not assigned..');
exit;
end;
if (LibType <> ltLoadBmp) and (FDDraw = nil) then begin
raise Exception.Create ('DDraw not assigned..');
exit;
end;
if FileExists (FFileName) then begin
if m_FileStream = nil then
m_FileStream := TFileStream.Create (FFileName, fmOpenRead or fmShareDenyNone);
m_FileStream.Read (Header, SizeOf(TWMImageHeader));
if header.VerFlag = 0 then begin
btVersion:=1;
m_FileStream.Seek(-4,soFromCurrent);
end;
FImageCount := Header.ImageCount;
if header.ColorCount=256 then begin
FBitFormat:=pf8Bit; FBytesPerPixels:=1;
end else if header.ColorCount=65536 then begin
FBitFormat:=pf16bit; FBytesPerPixels:=2;
end else if header.colorcount=16777216 then begin
FBitFormat:=pf24Bit; FBytesPerPixels:=4;
end else if header.ColorCount>16777216 then begin
FBitFormat:=pf32Bit; FBytesPerPixels:=4;
end;
ChangeDIBPixelFormat(lsDIB,FBitFormat);
if (LibType = ltUseCache) then begin
m_ImgArr:=AllocMem(SizeOf(TDxImage) * FImageCount);
if m_ImgArr = nil then
raise Exception.Create (self.Name + ' ImgArr = nil');
end;
idxfile := ExtractFilePath(FFileName) + ExtractFileNameOnly(FFileName) + '.WIX';
LoadPalette;
LoadIndex (idxfile);
end else begin
end;
end;
end;
procedure TWMImages.LoadDxImage (position: integer; pdximg: PTDxImage);
var
imginfo: TWMImageInfo;
DBits: PByte;
begin
m_FileStream.Seek (position, 0);
if btVersion <> 0 then m_FileStream.Read (imginfo, SizeOf(TWMImageInfo)-4)
else m_FileStream.Read (imginfo, SizeOf(TWMImageInfo));
lsDib.Clear;
lsDib.Width := imginfo.nWidth;
lsDib.Height := imginfo.nHeight;
lsDib.ColorTable := MainPalette;
lsDib.UpdatePalette;
DBits := lsDib.PBits;
m_FileStream.Read (DBits^, imginfo.nWidth * imgInfo.nHeight * FBytesPerPixels);
pdximg.nPx := imginfo.px;
pdximg.nPy := imginfo.py;
pdximg.surface := TDirectDrawSurface.Create (FDDraw);
pdximg.surface.SystemMemory := TRUE;
pdximg.surface.SetSize (imginfo.nWidth, imginfo.nHeight);
pdximg.surface.Canvas.Draw (0, 0, lsDib);
pdximg.surface.Canvas.Release;
pdximg.surface.TransparentColor := 0;
lsDib.Clear;
end;
procedure DrawBlend(dsuf: TDirectDrawSurface; x, y: integer; ssuf:
TDirectDrawSurface; blendmode: integer);
begin
DrawBlendEx(dsuf, x, y, ssuf, 0, 0, ssuf.Width, ssuf.Height, blendmode);
end;
procedure DrawBlendEx(dsuf: TDirectDrawSurface; x, y: integer; ssuf:
TDirectDrawSurface; ssufleft, ssuftop, ssufwidth, ssufheight, blendmode:
integer);
var
Header: TWMImageHeader;
begin
if (dsuf.canvas = nil) or (ssuf.canvas = nil) then exit;
if x >= dsuf.Width then exit;
if y >= dsuf.Height then exit;
if blendMode = 1 then
begin
dsuf.DrawAdd(rect(x, y, x + ssufWidth, y + ssufHeight), rect(ssufLeft,
ssufTop, ssufLeft + ssufWidth, ssufTop + ssufHeight), ssuf, true, 225);
end
else
dsuf.DrawAlpha(rect(x, y, x + ssufWidth, y + ssufHeight), rect(ssufLeft,
ssufTop, ssufLeft + ssufWidth, ssufTop + ssufHeight), ssuf, true, 192);
end;