Coder Social home page Coder Social logo

neiljed / vtflib Goto Github PK

View Code? Open in Web Editor NEW
158.0 10.0 49.0 176 KB

VTFLib is a LGPL open source programming library that provides a C and C++ API for reading and writing Valve VTF and VMT format image files.

License: GNU Lesser General Public License v2.1

C 8.49% C++ 91.45% Batchfile 0.06%
vtf vtflib valve steam image-processing dxt

vtflib's Introduction

Warning

VTFLib project is no-longer being actively developed by the original authors and as-such:

  • The current code is unsupported and used at your own risk.
  • The original code was developed from 2005 to 2011 - it likely doesn't run out of the box on modern version of Windows.
  • There may be some basic updates or maintenance but this is strictly limited to tinkering.
  • Pull Requests are welcome so long as they bring some value, i.e. fix issues.
  • Feel free to open issues, however its unlikely much will be fixed.

VTFLib - A Valve VTF and VMT image format programming library.

VTFLib is a LGPL open source programming library that provides a C and C++ API that, with a few simple functions, can open and save .vtf and .vmt files, providing access to all known features. The library functions independent of Steam, allowing third party applications to use the library without Steam present or running on the target system.

VTFLib includes two GPL example applications, VTFCmd and VTFEdit. VTFCmd is a C command line frontend for VTFLib that can create .vtf and .vmt files from various source formats. It is similar in functionality to Valve's vtex Source SDK utility, but offers a lot more control. VTFEdit is a C++ .NET graphical frontend for VTFLib with viewing and creation capabilities. Both VTFCmd and VTFEdit support several source image formats, including, but not limited to .bmp, .dds, .gif, .jpg, .png and .tga.

A note from the authors

Between 2005 and 2011 myself and Ryan Gregg developed a number of tools and libraries to help modders and developers create content for Valve's Source game engine - VTFLib was one of them. However, as of time of writing, that was 12 years ago and we've moved onto other things. I'm shocked (and actually pleased) that people are still using VTFLib and VTFEdit despite how old it is.

Though we're not actively developing it, your welcome to make forks and develop your own version (maybe fix a few things) as per the LGPL license. I may tinker with the code from time to time though this is for my own curiosity and amusement and not any for of official work.

Thanks to everyone who supported us over the years!

Neil 'Jed' Jedrzejewski & Ryan Gregg

Project Structure

The library contains five folders:

  • Bin - Contains library and example program binaries.
  • Lib - Contains library C and C++ header and inline files.
  • Sln - Contains Solution files for Visual Studio.
  • VTFCmd - Contains C example program source code.
  • VTFEdit - Contains C++ .NET example program source code.
  • VTFLib - Contains C++ library source code.

The original project files were written for Visual Studio 2008 and have been retained for reference. A partial migration to Visual Studio 2022 has been started though at present this is for VTFLib onyl while working out some dependency issues.

nvDXTLib is required by VTFLib for DXT compression although it is current not compatible with versions of VSCode later than 2008.

Changelogs

VTFCmd Usage

Correct vtfcmd usage:
 -file <path>             (Input file path.)
 -folder <path>           (Input directory search string.)
 -output <path>           (Output directory.)
 -prefix <string>         (Output file prefix.)
 -postfix <string>        (Output file postfix.)
 -version <string>        (Ouput version.)
 -format <string>         (Ouput format to use on non-alpha textures.)
 -alphaformat <string>    (Ouput format to use on alpha textures.)
 -flag <string>           (Output flags to set.)
 -resize                  (Resize the input to a power of 2.)
 -rmethod <string>        (Resize method to use.)
 -rfilter <string>        (Resize filter to use.)
 -rsharpen <string>       (Resize sharpen filter to use.)
 -rwidth <integer>        (Resize to specific width.)
 -rheight <integer>       (Resize to specific height.)
 -rclampwidth <integer>   (Maximum width to resize to.)
 -rclampheight <integer>  (Maximum height to resize to.)
 -gamma                   (Gamma correct image.)
 -gcorrection <single>    (Gamma correction to use.)
 -nomipmaps               (Don't generate mipmaps.)
 -mfilter <string>        (Mipmap filter to use.)
 -msharpen <string>       (Mipmap sharpen filter to use.)
 -normal                  (Convert input file to normal map.)
 -nkernel <string>        (Normal map generation kernel to use.)
 -nheight <string>        (Normal map height calculation to use.)
 -nalpha <string>         (Normal map alpha result to set.)
 -nscale <single>         (Normal map scale to use.)
 -nwrap                   (Wrap the normal map for tiled textures.)
 -bumpscale <single>      (Engine bump mapping scale to use.)
 -nothumbnail             (Don't generate thumbnail image.)
 -noreflectivity          (Don't calculate reflectivity.)
 -shader <string>         (Create a material for the texture.)
 -param <string> <string> (Add a parameter to the material.)
 -recurse                 (Process directories recursively.)
 -exportformat <string>   (Convert VTF files to the format of this extension.)
 -silent                  (Silent mode.)
 -pause                   (Pause when done.)
 -help                    (Display vtfcmd help.)

Example vtfcmd usage:
vtfcmd.exe -file "C:\texture1.bmp" -file "C:\texture2.bmp" -format "dxt1"
vtfcmd.exe -file "C:\texture.bmp" -format "bgr888" -normal -postfix "normal_"
vtfcmd.exe -folder "C:\input\*.tga" -output "C:\output" -recurse -pause
vtfcmd.exe -folder "C:\output\*.vtf" -output "C:\input" -exportformat "jpg"

Program Copyright-Permissions

This software is Copyright *Neil 'Jed' Jedrzejewski & Ryan Gregg and is released under the terms of LGPL. Please see the LICENSE file for details.

vtflib's People

Contributors

jaroslucky avatar neiljed avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vtflib's Issues

Errors compiling with nvDXT

nvDXT is a legacy library compiled with an older version of Visual Studio. Due to "breaking changes" introduced in Visual Studio 2015 there are a large number of errors that occur when trying to link it.

These needs to be fixed or, more practically, the legacy nvDXT library needs to be replaced.

[Feature request] Conversion between DDS and VTF, without reencoding

The DDS file format supports all of the same image formats as VTF (plus more), so there should be an option when importing a DDS file to retain source format or something along those lines (as long as the source DDS uses a compatible format and is a power of 2). Such an option would copy the image data and any mipmaps over to a VTF file (and create thumbnails, info resources, etc. if the user requests), while avoiding introducing green tint to DXTn or BGR565 textures and other lossy conversion issues.

Additionally, there could be an option to export as DDS, using the same image format as the source VTF.

I'm pretty sure this would be possible; while I am not familiar with the nitty gritty, I'd imagine that the image data itself can just be copied over, since both file formats encode the image using little endian with the same image formats designed for the GPU.

Can't open it

For some reason, The app won't open for me I tried to re-install it twice and it still won't launch.

Its not my first time using it but after my last format for the PC I'm trying to open it and it won't launch.
Please help.

Unhandled exception on Import

Error report:
See the end of this message for details on invoking \njust-in-time (JIT) debugging instead of this dialog box.\n\n************** Exception Text *************\nSystem.PlatformNotSupportedException: Operation is not supported on this platform.
at VTFEdit.CVTFEdit.SetVTFFile (VTFLib.CVTFFile
VTFFile) [0x006d8] in <5171360439d041378fa6d6fbba48e202>:0
at VTFEdit.CVTFEdit.Import (System.String[] sFileNames) [0x00291] in <5171360439d041378fa6d6fbba48e202>:0
at VTFEdit.CVTFEdit.btnImport_Click (System.Object sender, System.EventArgs e) [0x0001a] in <5171360439d041378fa6d6fbba48e202>:0
at System.Windows.Forms.MenuItem.OnClick (System.EventArgs e) [0x00078] in :0
at System.Windows.Forms.MenuItem+MenuItemData.Execute () [0x0000b] in :0
at System.Windows.Forms.Command.Invoke () [0x0001c] in :0
at System.Windows.Forms.Command.DispatchID (System.Int32 id) [0x00014] in :0
at System.Windows.Forms.Control.WmCommand (System.Windows.Forms.Message& m) [0x00021] in :0
at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message& m) [0x00357] in :0
at System.Windows.Forms.ScrollableControl.WndProc (System.Windows.Forms.Message& m) [0x00043] in :0
at System.Windows.Forms.ContainerControl.WndProc (System.Windows.Forms.Message& m) [0x0001a] in :0
at System.Windows.Forms.Form.WndProc (System.Windows.Forms.Message& m) [0x00318] in :0
at VTFEdit.CVTFEdit.WndProc (System.Windows.Forms.Message& e) [0x00032] in <5171360439d041378fa6d6fbba48e202>:0
at System.Windows.Forms.Control+ControlNativeWindow.OnMessage (System.Windows.Forms.Message& m) [0x00001] in :0
at System.Windows.Forms.Control+ControlNativeWindow.WndProc (System.Windows.Forms.Message& m) [0x000b3] in :0
at System.Windows.Forms.NativeWindow.Callback (System.Windows.Forms.Message& m) [0x00025] in :0

\n************** Loaded Assemblies \nmscorlib\n Assembly Version: 4.0.0.0\n Win32 Version: 4.6.57.0\n CodeBase: file:///C:/windows/mono/mono-2.0/lib/mono/4.5/mscorlib.dll\n----------------------------------------\nVTFEdit\n Assembly Version: 0.0.0.0\n Win32 Version: 1.3.3\n CodeBase: file:///Z:/home/REDACTED/Documents/source/tools/vtfedit/VTFEdit.exe\n----------------------------------------\nmsvcm80\n Assembly Version: 8.0.50727.6195\n Win32 Version: 8.00.50727.6195\n CodeBase: file:///C:/windows/winsxs/amd64_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.6195_none_deadbeef/msvcm80.dll\n----------------------------------------\nSystem.Windows.Forms\n Assembly Version: 4.0.0.0\n Win32 Version: 4.6.57.0\n CodeBase: file:///C:/windows/mono/mono-2.0/lib/mono/gac/System.Windows.Forms/4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll\n----------------------------------------\nSystem\n Assembly Version: 4.0.0.0\n Win32 Version: 4.6.57.0\n CodeBase: file:///C:/windows/mono/mono-2.0/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll\n----------------------------------------\nSystem.Drawing\n Assembly Version: 4.0.0.0\n Win32 Version: 4.6.57.0\n CodeBase: file:///C:/windows/mono/mono-2.0/lib/mono/gac/System.Drawing/4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll\n----------------------------------------\nAccessibility\n Assembly Version: 4.0.0.0\n Win32 Version: \n CodeBase: file:///C:/windows/mono/mono-2.0/lib/mono/gac/Accessibility/4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll\n----------------------------------------\nSystem.Configuration\n Assembly Version: 4.0.0.0\n Win32 Version: 4.6.57.0\n CodeBase: file:///C:/windows/mono/mono-2.0/lib/mono/gac/System.Configuration/4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll\n----------------------------------------\nI18N\n Assembly Version: 4.0.0.0\n Win32 Version: 4.0.0.0\n CodeBase: file:///C:/windows/mono/mono-2.0/lib/mono/gac/I18N/4.0.0.0__0738eb9f132ed756/I18N.dll\n----------------------------------------\nI18N.West\n Assembly Version: 4.0.0.0\n Win32 Version: 4.0.0.0\n CodeBase: file:///C:/windows/mono/mono-2.0/lib/mono/gac/I18N.West/4.0.0.0__0738eb9f132ed756/I18N.West.dll\n----------------------------------------\n\n JIT Debugging **************\n

DevIL library is out of date.

VTFEdit and VTFCmd expect an old version of DevIL which is no longer available. Newer versions have vastly changed codewise and don't work as a direct drop-in replacement.

VTFEdit and VTFCmd need to be updated to either use a newer version of DevIL or switch to a different image input/output library.

Support for .xtf

It would be nice to have support for .xtf (.vtf equivalent used in the Original Xbox port of HL2) with VTFLib.

I'm providing some info of .xtf:

Discussion on the format: https://forum.xentax.com/viewtopic.php?t=2101

Some header files from ancient Source SDK code, that include .xtf file header information and various other info on .xtf (check _XBOX defines, and also XTF lines):

vtf.h: https://pastebin.com/4mtE8zdj
imageformat.h: https://pastebin.com/VHjfxc3f
swizzler.h: https://pastebin.com/Km8Dc4fj

Example .xtf file: https://anonfiles.com/NfG7Ie5cpd/alyx_sheet_xtf

Currently I am able to to convert .xtf to .dds using gssmt (linked in the xentax forum, it's the last post), and then I am able to convert .dds to .xtf by hex editing the .dds, replacing the first bytes from an original .xtf file. This obviously has issues, as there's no room for any changes (like resolution and such)

VTFEdit does not open

I try to open the program and it does not open, I use x86 architecture and I installed what is necessary for x86 and it still does not open

i use exagear emulator :v

Fix Memory Leak

https://github.com/NeilJed/VTFLib/blob/master/VTFLib/VTFFile.cpp#L659-L679

If the result is successful, then the allocated memory is not cleared. This adds deallocate memory if the result is successful.

Visual Studio solution is out of date.

The Visual Studio Solution in VTFLIb 1.3.2 is out of date for current editions of Visual Studio.

A new version needs to be created with the relevant settings.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.