diff options
author | b1indy <b1indy@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2007-06-26 14:11:20 +0000 |
---|---|---|
committer | b1indy <b1indy@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2007-06-26 14:11:20 +0000 |
commit | 1d20a6ed1de519a7167c3b53fee7f2484f2f22b1 (patch) | |
tree | 9d9a967412bdcf1591e81c224408479f8e0bcfa1 /Game | |
parent | 139918027ecdd4a1b149722eea7b578579b993f1 (diff) | |
download | usdx-1d20a6ed1de519a7167c3b53fee7f2484f2f22b1.tar.gz usdx-1d20a6ed1de519a7167c3b53fee7f2484f2f22b1.tar.xz usdx-1d20a6ed1de519a7167c3b53fee7f2484f2f22b1.zip |
Added support for transparency in PNG images - if a PNG with transparency is loaded as 'Transparent' texture type, then the alpha-channel is set according to the transparency information in the file
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@270 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Game')
-rw-r--r-- | Game/Code/Classes/UTexture.pas | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/Game/Code/Classes/UTexture.pas b/Game/Code/Classes/UTexture.pas index 0eae68a2..da603ec9 100644 --- a/Game/Code/Classes/UTexture.pas +++ b/Game/Code/Classes/UTexture.pas @@ -193,6 +193,10 @@ var TextureB: TBitmap;
TextureJ: TJPEGImage;
TexturePNG: TPNGObject;
+ TextureAlpha: array of byte;
+ AlphaPtr: PByte;
+ TransparentColor: TColor;
+ PixelColor: TColor;
Pet: integer;
Pet2: integer;
@@ -246,6 +250,27 @@ begin Exit;
end;
TextureB.Assign(TexturePNG);
+ // transparent png hack start (part 1 of 2)
+ if (Typ = 'Transparent') and (TexturePNG.TransparencyMode = ptmPartial) then
+ begin
+ setlength(TextureAlpha, TextureB.Width*TextureB.Height);
+ if (TexturePNG.Header.ColorType = COLOR_GRAYSCALEALPHA) or
+ (TexturePNG.Header.ColorType = COLOR_RGBALPHA) then
+ begin
+ // i would have preferred english variables here but i use Pet because i'm lazy
+ for Pet := 0 to TextureB.Height - 1 do
+ begin
+ AlphaPtr := PByte(TexturePNG.AlphaScanline[Pet]);
+ for Pet2 := 0 to TextureB.Width - 1 do
+ begin
+ TextureAlpha[Pet*TextureB.Width+Pet2]:= AlphaPtr^;
+ Inc(AlphaPtr);
+ end;
+ end;
+ end;
+ end else
+ setlength(TextureAlpha,0); // just no special transparency for unimplemented transparency types (ptmBit)
+ // transparent png hack end
TexturePNG.Free;
end;
@@ -357,11 +382,13 @@ begin TexNewH := Round(Power(2, Ceil(Log2(TexOrygH))));
TextureB.Width := TexNewW;
TextureB.Height := TexNewH;
+
// kopiowanie
for Pet := 0 to TexOrygH-1 do begin
for Pet2 := 0 to TexOrygW-1 do begin
Pix := TextureB.Canvas.Pixels[Pet2, Pet];
- if ((Pix = $fefefe) or (Pix = Col)) then begin //Small fix, that caused artefacts to be drawn (#fe == dec254)
+ // ,- part of transparent png hack
+ if ((Pix = $fefefe) or (Pix = Col)) and (length(TextureAlpha)=0) then begin //Small fix, that caused artefacts to be drawn (#fe == dec254)
TextureD32[Pet*TexNewW + Pet2 + 1, 1] := 0;
TextureD32[Pet*TexNewW + Pet2 + 1, 2] := 0;
TextureD32[Pet*TexNewW + Pet2 + 1, 3] := 0;
@@ -370,7 +397,12 @@ begin TextureD32[Pet*TexNewW + Pet2+1, 1] := Pix;
TextureD32[Pet*TexNewW + Pet2+1, 2] := Pix div 256;
TextureD32[Pet*TexNewW + Pet2+1, 3] := Pix div (256*256);
- TextureD32[Pet*TexNewW + Pet2+1, 4] := 255;
+ // transparent png hack start (part 2 of 2)
+ if (Format = 'PNG') and (length(TextureAlpha) <> 0) then begin
+ TextureD32[Pet*TexNewW+Pet2+1,4]:=TextureAlpha[Pet*TexOrygW+Pet2];
+ end else
+ // transparent png hack end
+ TextureD32[Pet*TexNewW + Pet2+1, 4] := 255;
end;
end;
end;
|