X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Feditor%2Ff_addresource_texture.pas;h=b2551c5a661e7803d8ea043bcd1894a8bd2ab0f5;hb=ba79a3849a16e4f11382fd712708dfecdb5ad3f6;hp=32a4da1d8b8c96597489e82f5474cb9f50f438ab;hpb=8b5918f7194cae0c5cf3fb0d03e677e6d50cf7f8;p=d2df-editor.git diff --git a/src/editor/f_addresource_texture.pas b/src/editor/f_addresource_texture.pas index 32a4da1..b2551c5 100644 --- a/src/editor/f_addresource_texture.pas +++ b/src/editor/f_addresource_texture.pas @@ -61,7 +61,6 @@ var ResourceName: String; Data: Pointer; Size: Integer; - Sign: Array [0..4] of Char; Sections, Resources: SArray; a: Integer; @@ -86,16 +85,6 @@ begin WAD.FreeWAD(); -// Проверка сигнатуры. Если есть - это WAD внутри WAD: - CopyMemory(@Sign[0], Data, 5); - - if not (Sign = DFWAD_SIGNATURE) then - begin - WAD.Free(); - FreeMem(Data); - Exit; - end; - // Пробуем прочитать данные: if not WAD.ReadMemory(Data, Size) then begin @@ -162,8 +151,7 @@ begin Result := ok; end; -function GetFrame(Res: String; var Data: Pointer; var DataLen: Integer; - var Width, Height: Word): Boolean; +function GetFrame(Res: String; var Data: Pointer; var DataLen: Integer; var Width, Height: Word): Boolean; var AnimWAD: Pointer; WAD: TWADEditor_1; @@ -197,7 +185,7 @@ begin WAD.Free(); Exit; end; - + WAD.FreeWAD(); // Читаем WAD в WAD'е: @@ -242,67 +230,51 @@ begin Result := True; end; -function CreateBitMap(Data: Pointer; DataSize: Cardinal): TBitMap; +function CreateBitMap (Data: Pointer; DataSize: Cardinal): TBitMap; var - img: TImageData; - clr: TColor32Rec; - bgc: TColor32Rec; - ii: PByte; - Width, - Height: Integer; - x, y: Integer; - BitMap: TBitMap; - + img: TImageData; + clr, bgc: TColor32Rec; + Width, Height: Integer; + x, y: Integer; + BitMap: TBitMap; begin Result := nil; - InitImage(img); if not LoadImageFromMemory(Data, DataSize, img) then Exit; Width := img.width; Height := img.height; - BitMap := TBitMap.Create(); - BitMap.PixelFormat := pf24bit; - + 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); // 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 + 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; + 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); - // TODO: check for RGB/BGR somehow? - ii^ := clr.b; Inc(ii); - ii^ := clr.g; Inc(ii); - ii^ := clr.r; Inc(ii); - - (* Why this works in linux? *) - {$IFNDEF WINDOWS}Inc(ii){$ENDIF} - end; + BitMap.Canvas.Pixels[x, y] := RGBToColor(clr.r, clr.g, clr.b) + end end; FreeImage(img); Result := BitMap; @@ -319,7 +291,7 @@ var config: TConfig; TextData: Pointer; TextureData: Pointer; - + begin Result := nil; AnimWAD := nil; @@ -350,12 +322,12 @@ begin begin // Создаем BitMap из листа текстур: Result := CreateBitMap(TextureData, Len); - + // Размеры одного кадра - виден только первый кадр: Result.Height := config.ReadInt('', 'frameheight', 0); Result.Width := config.ReadInt('', 'framewidth', 0); end; - + config.Free(); WAD.Free(); @@ -404,7 +376,7 @@ begin Inherited; lStats.Caption := ''; - cbWADList.Items.Add(_lc[I_WAD_SPECIAL_TEXS]); + cbWADList.Items.Add(MsgWadSpecialTexs); eTextureName.Text := ''; iPreview.Canvas.FillRect(iPreview.Canvas.ClipRect); @@ -427,11 +399,11 @@ begin Exit; if FResourceName = '' then Exit; - if cbWADList.Text = _lc[I_WAD_SPECIAL_TEXS] then + if cbWADList.Text = MsgWadSpecialTexs then Exit; g_ProcessResourceStr(FFullResourceName, @wad, nil, nil); - if wad = _lc[I_WAD_SPECIAL_TEXS] then + if wad = MsgWadSpecialTexs then Exit; Anim := IsAnim(FFullResourceName); @@ -444,9 +416,9 @@ begin Exit; if Anim then - lStats.Caption := Format(_lc[I_CAP_ANIMATION], [Texture.Width, Texture.Height, NumFrames]) + lStats.Caption := Format(MsgCapAnimation, [Texture.Width, Texture.Height, NumFrames]) else - lStats.Caption := Format(_lc[I_CAP_TEXTURE], [Texture.Width, Texture.Height]); + lStats.Caption := Format(MsgCapTexture, [Texture.Width, Texture.Height]); iPreview.Canvas.FillRect(iPreview.Canvas.ClipRect); iPreview.Canvas.CopyRect(Texture.Canvas.ClipRect, Texture.Canvas, Texture.Canvas.ClipRect); @@ -490,7 +462,7 @@ end; procedure TAddTextureForm.cbWADListChange(Sender: TObject); begin - if cbWADList.Text = _lc[I_WAD_SPECIAL_TEXS] then + if cbWADList.Text = MsgWadSpecialTexs then begin cbSectionsList.Clear(); cbSectionsList.Items.Add('..'); @@ -502,7 +474,7 @@ end; procedure TAddTextureForm.cbSectionsListChange(Sender: TObject); begin - if cbWADList.Text = _lc[I_WAD_SPECIAL_TEXS] then + if cbWADList.Text = MsgWadSpecialTexs then begin lbResourcesList.Clear(); lbResourcesList.Items.Add(TEXTURE_NAME_WATER);