index fb5bd5f1946d4528c06b58a64ddf7296069a4377..9eea7180818843a5581e452b2be08036792ea845 100644 (file)
unit f_addresource_sky;
unit f_addresource_sky;
-{$MODE Delphi}
+{$INCLUDE ../shared/a_modes.inc}
interface
uses
LCLIntf, LCLType, LMessages, SysUtils, Variants, Classes,
Graphics, Controls, Forms, Dialogs, f_addresource,
interface
uses
LCLIntf, LCLType, LMessages, SysUtils, Variants, Classes,
Graphics, Controls, Forms, Dialogs, f_addresource,
- ExtCtrls, StdCtrls;
+ ExtCtrls, StdCtrls, utils, Imaging, ImagingTypes, ImagingUtility;
type
TAddSkyForm = class (TAddResourceForm)
type
TAddSkyForm = class (TAddResourceForm)
{$R *.lfm}
{$R *.lfm}
-procedure SwapRGB(data: Pointer; Size: Integer);
-asm
- mov ebx, eax
- mov ecx, size
-
-@@loop :
- mov al,[ebx+0]
- mov ah,[ebx+2]
- mov [ebx+2],al
- mov [ebx+0],ah
- add ebx,3
- dec ecx
- jnz @@loop
-end;
-
function ShowTGATexture(ResourceStr: String): TBitMap;
var
function ShowTGATexture(ResourceStr: String): TBitMap;
var
- TGAHeader: packed record // Header type for TGA images
- FileType: Byte;
- ColorMapType: Byte;
- ImageType: Byte;
- ColorMapSpec: Array[0..4] of Byte;
- OrigX: Array [0..1] of Byte;
- OrigY: Array [0..1] of Byte;
- Width: Array [0..1] of Byte;
- Height: Array [0..1] of Byte;
- BPP: Byte;
- ImageInfo: Byte;
- end;
- image: Pointer; {or PRGBTRIPLE}
+ img: TImageData;
+ clr: TColor32Rec;
+ ii: PByte;
Width,
Height: Integer;
ColorDepth: Integer;
ImageSize: Integer;
Width,
Height: Integer;
ColorDepth: Integer;
ImageSize: Integer;
- I: Integer;
+ x, y: Integer;
BitMap: TBitMap;
TextureData: Pointer;
BitMap: TBitMap;
TextureData: Pointer;
WAD.Free();
WAD.Free();
-// Заголовок TGA:
- CopyMemory(@TGAHeader, TextureData, SizeOf(TGAHeader));
-
- if TGAHeader.ImageType <> 2 then
- Exit;
- if TGAHeader.ColorMapType <> 0 then
- Exit;
- if TGAHeader.BPP < 24 then
+ InitImage(img);
+ if not LoadImageFromMemory(TextureData, ImageSize, img) then
Exit;
Exit;
- Width := TGAHeader.Width[0]+TGAHeader.Width[1]*256;
- Height := TGAHeader.Height[0]+TGAHeader.Height[1]*256;
- ColorDepth := TGAHeader.BPP;
+ Width := img.width;
+ Height := img.height;
+ ColorDepth := 24;
ImageSize := Width*Height*(ColorDepth div 8);
ImageSize := Width*Height*(ColorDepth div 8);
-// Само изображение:
- GetMem(Image, ImageSize);
-
- CopyMemory(Image, Pointer(Integer(TextureData)+SizeOf(TGAHeader)), ImageSize);
-
BitMap := TBitMap.Create();
BitMap := TBitMap.Create();
+ BitMap.PixelFormat := pf24bit;
- if TGAHeader.BPP = 24 then
- BitMap.PixelFormat := pf24bit
- else
- BitMap.PixelFormat := pf32bit;
-
BitMap.Width := Width;
BitMap.Height := Height;
BitMap.Width := Width;
BitMap.Height := Height;
-// Копируем изображение в BitMap:
- for I := Height-1 downto 0 do
- CopyMemory(BitMap.ScanLine[Height-1-I],
- Pointer(Integer(Image)+(Width*I*(TGAHeader.BPP div 8))),
- Width*(TGAHeader.BPP div 8));
+// Копируем в BitMap:
+ ii := BitMap.RawImage.Data;
+ for y := 0 to height-1 do
+ begin
+ for x := 0 to width-1 do
+ begin
+ clr := GetPixel32(img, x, y);
+ // assuming sky has no alpha
+ // TODO: check for ARGB/RGBA/BGRA/ABGR somehow?
+ ii^ := clr.b; Inc(ii);
+ ii^ := clr.g; Inc(ii);
+ ii^ := clr.r; Inc(ii);
+ end;
+ end;
- FreeMem(Image, ImageSize);
FreeMem(TextureData);
FreeMem(TextureData);
+ FreeImage(img);
Result := BitMap;
end;
Result := BitMap;
end;
SectionName := '..';
// WAD файл:
SectionName := '..';
// WAD файл:
- a := cbWADList.Items.IndexOf(FileName);
+ a := cbWADList.Items.IndexOf(win2utf(FileName));
if a <> -1 then
begin
cbWADList.ItemIndex := a;
if a <> -1 then
begin
cbWADList.ItemIndex := a;
end;
// Секция:
end;
// Секция:
- a := cbSectionsList.Items.IndexOf(SectionName);
+ a := cbSectionsList.Items.IndexOf(win2utf(SectionName));
if a <> -1 then
begin
cbSectionsList.ItemIndex := a;
if a <> -1 then
begin
cbSectionsList.ItemIndex := a;
end;
// Ресурс:
end;
// Ресурс:
- a := lbResourcesList.Items.IndexOf(ResourceName);
+ a := lbResourcesList.Items.IndexOf(win2utf(ResourceName));
if a <> -1 then
begin
lbResourcesList.ItemIndex := a;
if a <> -1 then
begin
lbResourcesList.ItemIndex := a;