X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Feditor%2Ff_addresource_sky.pas;h=e7b03613ddcb20db4c4f00e523db8b1647548905;hb=4cd27745126226e5e57a02f4c2a44ccbab16bbac;hp=9eea7180818843a5581e452b2be08036792ea845;hpb=66487b9264a791df057975695339448eb3d7ba2f;p=d2df-editor.git diff --git a/src/editor/f_addresource_sky.pas b/src/editor/f_addresource_sky.pas index 9eea718..e7b0361 100644 --- a/src/editor/f_addresource_sky.pas +++ b/src/editor/f_addresource_sky.pas @@ -39,15 +39,14 @@ function ShowTGATexture(ResourceStr: String): TBitMap; var img: TImageData; clr: TColor32Rec; - ii: PByte; + bgc: TColor32Rec; Width, Height: Integer; - ColorDepth: Integer; - ImageSize: Integer; x, y: Integer; BitMap: TBitMap; TextureData: Pointer; + ImageSize: Integer; WAD: TWADEditor_1; WADName: String; SectionName: String; @@ -62,40 +61,52 @@ begin WAD := TWADEditor_1.Create(); WAD.ReadFile(WADName); - WAD.GetResource(SectionName, ResourceName, TextureData, ImageSize); + WAD.GetResource(utf2win(SectionName), utf2win(ResourceName), TextureData, ImageSize); WAD.Free(); + (* !!! copypaste from f_addresource_texture.CreateBitMap *) + InitImage(img); if not LoadImageFromMemory(TextureData, ImageSize, img) then + begin + FreeMem(TextureData); Exit; + end; Width := img.width; Height := img.height; - ColorDepth := 24; - ImageSize := Width*Height*(ColorDepth div 8); - BitMap := TBitMap.Create(); BitMap.PixelFormat := pf24bit; - BitMap.Width := Width; BitMap.Height := Height; - -// Копируем в BitMap: - ii := BitMap.RawImage.Data; - for y := 0 to height-1 do + for y := 0 to height - 1 do begin - for x := 0 to width-1 do + 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; + // HACK: Lazarus's TBitMap doesn't seem to have a working 32 bit mode, so + // mix color with checkered background. Also, can't really read + // CHECKERS.tga from here. FUCK! + if UseCheckerboard then + begin + if (((x shr 3) and 1) = 0) xor (((y shr 3) and 1) = 0) then + bgc.Color := $FDFDFD + else + bgc.Color := $CBCBCB + end + else + begin + bgc.r := GetRValue(PreviewColor); + bgc.g := GetGValue(PreviewColor); + bgc.b := GetBValue(PreviewColor) + end; + clr.r := ClampToByte((Byte(255 - clr.a) * bgc.r + clr.a * clr.r) div 255); + clr.g := ClampToByte((Byte(255 - clr.a) * bgc.g + clr.a * clr.g) div 255); + clr.b := ClampToByte((Byte(255 - clr.a) * bgc.b + clr.a * clr.b) div 255); + BitMap.Canvas.Pixels[x, y] := RGBToColor(clr.r, clr.g, clr.b) + end end; - FreeMem(TextureData); FreeImage(img); Result := BitMap; @@ -105,8 +116,7 @@ procedure TAddSkyForm.bOKClick(Sender: TObject); begin Inherited; - if not FResourceSelected then - Exit; + ModalResult := mrOk; end; procedure TAddSkyForm.lbResourcesListClick(Sender: TObject); @@ -147,12 +157,12 @@ begin g_ProcessResourceStr(FSetResource, FileName, SectionName, ResourceName); if FileName = '' then - FileName := _lc[I_WAD_SPECIAL_MAP]; + FileName := MsgWadSpecialMap; if SectionName = '' then SectionName := '..'; // WAD файл: - a := cbWADList.Items.IndexOf(win2utf(FileName)); + a := cbWADList.Items.IndexOf(FileName); if a <> -1 then begin cbWADList.ItemIndex := a; @@ -160,7 +170,7 @@ begin end; // Секция: - a := cbSectionsList.Items.IndexOf(win2utf(SectionName)); + a := cbSectionsList.Items.IndexOf(SectionName); if a <> -1 then begin cbSectionsList.ItemIndex := a; @@ -168,7 +178,7 @@ begin end; // Ресурс: - a := lbResourcesList.Items.IndexOf(win2utf(ResourceName)); + a := lbResourcesList.Items.IndexOf(ResourceName); if a <> -1 then begin lbResourcesList.ItemIndex := a;