X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Feditor%2Ff_addresource_texture.pas;h=0ab28a5586e623ebc0580fdfca4cff372e36e060;hb=6fb9c23afad22a71679525dc44ea32675d73609f;hp=d1210cd5b38a793ae3ecc53e803bd8c39db462aa;hpb=6869d799c63b2909e4e0c3b2cd0b486903518ae2;p=d2df-editor.git diff --git a/src/editor/f_addresource_texture.pas b/src/editor/f_addresource_texture.pas index d1210cd..0ab28a5 100644 --- a/src/editor/f_addresource_texture.pas +++ b/src/editor/f_addresource_texture.pas @@ -5,7 +5,7 @@ unit f_addresource_texture; interface uses - LCLIntf, LCLType, LMessages, SysUtils, Variants, Classes, + LCLIntf, LCLType, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, f_addresource, StdCtrls, ExtCtrls, utils, Imaging, ImagingTypes, ImagingUtility; @@ -46,20 +46,6 @@ uses BinEditor, WADEDITOR, WADSTRUCT, f_main, g_textures, CONFIG, g_map, g_language; -type - TTGAHeader = packed record - 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; - {$R *.lfm} function IsAnim(Res: String): Boolean; @@ -78,6 +64,8 @@ var begin Result := False; + Data := nil; + Size := 0; // Читаем файл и ресурс в нем: g_ProcessResourceStr(Res, WADName, SectionName, ResourceName); @@ -85,7 +73,7 @@ begin WAD := TWADEditor_1.Create(); if (not WAD.ReadFile(WADName)) or - (not WAD.GetResource(SectionName, ResourceName, Data, Size)) then + (not WAD.GetResource(utf2win(SectionName), utf2win(ResourceName), Data, Size)) then begin WAD.Free(); Exit; @@ -183,6 +171,9 @@ var begin Result := False; + AnimWAD := nil; + Len := 0; + TextData := nil; // Читаем WAD: g_ProcessResourceStr(Res, WADName, SectionName, ResourceName); @@ -196,7 +187,7 @@ begin end; // Читаем WAD-ресурс из WAD: - if not WAD.GetResource(SectionName, ResourceName, AnimWAD, Len) then + if not WAD.GetResource(utf2win(SectionName), utf2win(ResourceName), AnimWAD, Len) then begin WAD.Free(); Exit; @@ -247,19 +238,14 @@ begin end; function CreateBitMap(Data: Pointer; DataSize: Cardinal): TBitMap; -const - BG_R: Byte = 255; - BG_G: Byte = 0; - BG_B: Byte = 255; var img: TImageData; clr: TColor32Rec; + bgc: Byte; ii: PByte; Width, Height: Integer; - ColorDepth: Integer; - ImageSize: Integer; - i, x, y: Integer; + x, y: Integer; BitMap: TBitMap; begin @@ -271,8 +257,6 @@ begin Width := img.width; Height := img.height; - ColorDepth := 24; - ImageSize := Width*Height*(ColorDepth div 8); BitMap := TBitMap.Create(); BitMap.PixelFormat := pf24bit; @@ -288,15 +272,19 @@ begin begin clr := GetPixel32(img, x, y); // HACK: Lazarus's TBitMap doesn't seem to have a working 32 bit mode, so - // mix color with pink background. FUCK! - clr.r := ClampToByte(((255 - clr.a) * BG_R + clr.a * clr.r) div 255); - clr.g := ClampToByte(((255 - clr.a) * BG_G + clr.a * clr.g) div 255); - clr.b := ClampToByte(((255 - clr.a) * BG_B + clr.a * clr.b) div 255); - // TODO: check for ARGB/RGBA/BGRA/ABGR somehow? + // mix color with checkered background. Also, can't really read + // CHECKERS.tga from here. FUCK! + if (((x shr 3) and 1) = 0) xor (((y shr 3) and 1) = 0) then + bgc := 255 + else + bgc := 200; + clr.r := ClampToByte((Byte(255 - clr.a) * bgc + clr.a * clr.r) div 255); + clr.g := ClampToByte((Byte(255 - clr.a) * bgc + clr.a * clr.g) div 255); + clr.b := ClampToByte((Byte(255 - clr.a) * bgc + clr.a * clr.b) div 255); + // TODO: check for RGB/BGR somehow? ii^ := clr.b; Inc(ii); ii^ := clr.g; Inc(ii); ii^ := clr.r; Inc(ii); - // ii^ := clr.a; Inc(ii); end; end; FreeImage(img); @@ -317,13 +305,17 @@ var begin Result := nil; + AnimWAD := nil; + Len := 0; + TextData := nil; + TextureData := nil; // Читаем WAD файл и ресурс в нем: g_ProcessResourceStr(Res, WADName, SectionName, ResourceName); WAD := TWADEditor_1.Create(); WAD.ReadFile(WADName); - WAD.GetResource(SectionName, ResourceName, AnimWAD, Len); + WAD.GetResource(utf2win(SectionName), utf2win(ResourceName), AnimWAD, Len); WAD.FreeWAD(); // Читаем описание анимации: @@ -365,6 +357,8 @@ var begin Result := nil; + TextureData := nil; + Len := 0; // Читаем WAD: g_ProcessResourceStr(ResourceStr, WADName, SectionName, ResourceName); @@ -377,7 +371,7 @@ begin end; // Читаем ресурс текстуры в нем: - WAD.GetResource(SectionName, ResourceName, TextureData, Len); + WAD.GetResource(utf2win(SectionName), utf2win(ResourceName), TextureData, Len); WAD.Free(); @@ -505,8 +499,8 @@ begin for i := 0 to lbResourcesList.Count-1 do if lbResourcesList.Selected[i] then begin - AddTexture(utf2win(cbWADlist.Text), utf2win(cbSectionsList.Text), - utf2win(lbResourcesList.Items[i]), False); + AddTexture(cbWADlist.Text, cbSectionsList.Text, + lbResourcesList.Items[i], False); lbResourcesList.Selected[i] := False; end; end;